MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / normalizeExternalCommand

Function normalizeExternalCommand

src/cm/commandRegistry.js:1652–1688  ·  view source on GitHub ↗
(descriptor)

Source from the content-addressed store, hash-verified

1650}
1651
1652function normalizeExternalCommand(descriptor) {
1653 const name =
1654 typeof descriptor?.name === "string" ? descriptor.name.trim() : "";
1655 if (!name) {
1656 console.warn("Command registration skipped: missing name", descriptor);
1657 return null;
1658 }
1659 const exec = typeof descriptor?.exec === "function" ? descriptor.exec : null;
1660 if (!exec) {
1661 console.warn(
1662 `Command registration skipped for "${name}": exec must be a function.`,
1663 );
1664 return null;
1665 }
1666
1667 const requiresView = descriptor?.requiresView ?? true;
1668 const key = normalizeExternalKey(descriptor?.bindKey);
1669
1670 return {
1671 name,
1672 description: descriptor?.description || humanizeCommandName(name),
1673 readOnly: descriptor?.readOnly ?? true,
1674 requiresView,
1675 key,
1676 run(view, args) {
1677 try {
1678 const resolvedView = resolveView(view);
1679 if (requiresView && !resolvedView) return false;
1680 const result = exec(resolvedView || null, args);
1681 return result !== false;
1682 } catch (error) {
1683 console.error(`Command \"${name}\" failed`, error);
1684 return false;
1685 }
1686 },
1687 };
1688}
1689
1690function normalizeExternalKey(bindKey) {
1691 if (!bindKey) return null;

Callers 1

registerExternalCommandFunction · 0.85

Calls 2

normalizeExternalKeyFunction · 0.85
humanizeCommandNameFunction · 0.70

Tested by

no test coverage detected