@pentoshi/clai 4.8.3 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -3
- package/dist/agent/finalize-gate.js +0 -9
- package/dist/agent/finalize-gate.js.map +1 -1
- package/dist/agent/plan-mode-reminders.js +5 -5
- package/dist/agent/plan-mode-reminders.js.map +1 -1
- package/dist/agent/plan-tool.d.ts +1 -0
- package/dist/agent/plan-tool.js +50 -21
- package/dist/agent/plan-tool.js.map +1 -1
- package/dist/agent/reliability-policy.d.ts +9 -0
- package/dist/agent/reliability-policy.js +36 -1
- package/dist/agent/reliability-policy.js.map +1 -1
- package/dist/agent/runner.d.ts +4 -0
- package/dist/agent/runner.js +193 -116
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/task-analyzer.d.ts +8 -18
- package/dist/agent/task-analyzer.js +75 -182
- package/dist/agent/task-analyzer.js.map +1 -1
- package/dist/agent/task-evidence.js +10 -0
- package/dist/agent/task-evidence.js.map +1 -1
- package/dist/agent/tool-call-parser.js +14 -13
- package/dist/agent/tool-call-parser.js.map +1 -1
- package/dist/app/adapters/current-agent-adapter.d.ts +5 -1
- package/dist/app/adapters/current-agent-adapter.js +2 -1
- package/dist/app/adapters/current-agent-adapter.js.map +1 -1
- package/dist/app/commands/catalog.js +5 -0
- package/dist/app/commands/catalog.js.map +1 -1
- package/dist/app/controllers/session-compact-helper.js +3 -6
- package/dist/app/controllers/session-compact-helper.js.map +1 -1
- package/dist/app/ports/transcript-item.d.ts +4 -0
- package/dist/classic/app/ClassicApp.js +1 -1
- package/dist/classic/app/ClassicApp.js.map +1 -1
- package/dist/classic/app/action-handlers.js +4 -0
- package/dist/classic/app/action-handlers.js.map +1 -1
- package/dist/classic/app/app-wiring.js +1 -0
- package/dist/classic/app/app-wiring.js.map +1 -1
- package/dist/classic/app/wiring-lifecycle.js +1 -0
- package/dist/classic/app/wiring-lifecycle.js.map +1 -1
- package/dist/classic/blocks/compacted-lines.js +3 -0
- package/dist/classic/blocks/compacted-lines.js.map +1 -1
- package/dist/classic/blocks/thinking-lines.js +11 -2
- package/dist/classic/blocks/thinking-lines.js.map +1 -1
- package/dist/classic/bootstrap/start-classic.js +3 -0
- package/dist/classic/bootstrap/start-classic.js.map +1 -1
- package/dist/classic/chrome/Composer.d.ts +6 -0
- package/dist/classic/chrome/Composer.js +2 -3
- package/dist/classic/chrome/Composer.js.map +1 -1
- package/dist/classic/chrome/composer-controller.d.ts +6 -1
- package/dist/classic/chrome/composer-controller.js +18 -8
- package/dist/classic/chrome/composer-controller.js.map +1 -1
- package/dist/classic/chrome/editor-view.d.ts +2 -1
- package/dist/classic/chrome/editor-view.js +1 -1
- package/dist/classic/chrome/editor-view.js.map +1 -1
- package/dist/classic/chrome/status-rows.js +3 -2
- package/dist/classic/chrome/status-rows.js.map +1 -1
- package/dist/classic/panels/TextEditorPanel.d.ts +3 -0
- package/dist/classic/panels/TextEditorPanel.js +7 -0
- package/dist/classic/panels/TextEditorPanel.js.map +1 -0
- package/dist/classic/panels/panel-controller.js +28 -1
- package/dist/classic/panels/panel-controller.js.map +1 -1
- package/dist/classic/panels/panel-effect.d.ts +3 -0
- package/dist/classic/panels/panel-effect.js.map +1 -1
- package/dist/classic/panels/panel-effects.js +3 -0
- package/dist/classic/panels/panel-effects.js.map +1 -1
- package/dist/classic/panels/panel-host.js +3 -0
- package/dist/classic/panels/panel-host.js.map +1 -1
- package/dist/classic/panels/panel-types.d.ts +2 -0
- package/dist/classic/panels/secret-panel.d.ts +1 -1
- package/dist/classic/panels/secret-panel.js +4 -2
- package/dist/classic/panels/secret-panel.js.map +1 -1
- package/dist/classic/panels/text-editor-panel.d.ts +33 -0
- package/dist/classic/panels/text-editor-panel.js +101 -0
- package/dist/classic/panels/text-editor-panel.js.map +1 -0
- package/dist/llm/adapters/anthropic-tools.d.ts +2 -1
- package/dist/llm/adapters/anthropic-tools.js +55 -4
- package/dist/llm/adapters/anthropic-tools.js.map +1 -1
- package/dist/llm/anthropic.js +1 -1
- package/dist/llm/anthropic.js.map +1 -1
- package/dist/llm/aws-mantle.js +2 -0
- package/dist/llm/aws-mantle.js.map +1 -1
- package/dist/llm/meta.js +62 -68
- package/dist/llm/meta.js.map +1 -1
- package/dist/llm/provider.js +7 -7
- package/dist/llm/request-plan.js +7 -2
- package/dist/llm/request-plan.js.map +1 -1
- package/dist/llm/tool-protocol.d.ts +1 -0
- package/dist/llm/tool-protocol.js +7 -0
- package/dist/llm/tool-protocol.js.map +1 -1
- package/dist/mcp/client.d.ts +27 -0
- package/dist/mcp/client.js +119 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/config-file.d.ts +35 -0
- package/dist/mcp/config-file.js +217 -0
- package/dist/mcp/config-file.js.map +1 -0
- package/dist/mcp/discovery.d.ts +4 -0
- package/dist/mcp/discovery.js +409 -0
- package/dist/mcp/discovery.js.map +1 -0
- package/dist/mcp/format.d.ts +17 -0
- package/dist/mcp/format.js +122 -0
- package/dist/mcp/format.js.map +1 -0
- package/dist/mcp/index.d.ts +15 -0
- package/dist/mcp/index.js +16 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/jsonrpc.d.ts +40 -0
- package/dist/mcp/jsonrpc.js +175 -0
- package/dist/mcp/jsonrpc.js.map +1 -0
- package/dist/mcp/manager.d.ts +36 -0
- package/dist/mcp/manager.js +300 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/mentions.d.ts +9 -0
- package/dist/mcp/mentions.js +44 -0
- package/dist/mcp/mentions.js.map +1 -0
- package/dist/mcp/names.d.ts +15 -0
- package/dist/mcp/names.js +59 -0
- package/dist/mcp/names.js.map +1 -0
- package/dist/mcp/results.d.ts +6 -0
- package/dist/mcp/results.js +182 -0
- package/dist/mcp/results.js.map +1 -0
- package/dist/mcp/runtime.d.ts +107 -0
- package/dist/mcp/runtime.js +505 -0
- package/dist/mcp/runtime.js.map +1 -0
- package/dist/mcp/substitution.d.ts +13 -0
- package/dist/mcp/substitution.js +74 -0
- package/dist/mcp/substitution.js.map +1 -0
- package/dist/mcp/transport-http.d.ts +53 -0
- package/dist/mcp/transport-http.js +433 -0
- package/dist/mcp/transport-http.js.map +1 -0
- package/dist/mcp/transport-stdio.d.ts +39 -0
- package/dist/mcp/transport-stdio.js +268 -0
- package/dist/mcp/transport-stdio.js.map +1 -0
- package/dist/mcp/transport.d.ts +20 -0
- package/dist/mcp/transport.js +44 -0
- package/dist/mcp/transport.js.map +1 -0
- package/dist/mcp/types.d.ts +179 -0
- package/dist/mcp/types.js +30 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/mcp/validation.d.ts +16 -0
- package/dist/mcp/validation.js +222 -0
- package/dist/mcp/validation.js.map +1 -0
- package/dist/modes/agent.d.ts +2 -0
- package/dist/modes/agent.js.map +1 -1
- package/dist/noninteractive/start-noninteractive.js +4 -0
- package/dist/noninteractive/start-noninteractive.js.map +1 -1
- package/dist/prompts/embedded.js +2 -2
- package/dist/prompts/embedded.js.map +1 -1
- package/dist/prompts/index.d.ts +3 -0
- package/dist/prompts/index.js +70 -55
- package/dist/prompts/index.js.map +1 -1
- package/dist/prompts/system.agent.md +34 -10
- package/dist/prompts/system.ask.md +8 -0
- package/dist/safety/classifier.js +4 -0
- package/dist/safety/classifier.js.map +1 -1
- package/dist/store/logs.js +17 -6
- package/dist/store/logs.js.map +1 -1
- package/dist/store/plan.d.ts +2 -0
- package/dist/store/plan.js +12 -13
- package/dist/store/plan.js.map +1 -1
- package/dist/store/session-workspace.js +2 -1
- package/dist/store/session-workspace.js.map +1 -1
- package/dist/tools/definitions.js +18 -0
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/external-tools.d.ts +30 -0
- package/dist/tools/external-tools.js +52 -0
- package/dist/tools/external-tools.js.map +1 -0
- package/dist/tools/registry.js +36 -5
- package/dist/tools/registry.js.map +1 -1
- package/dist/tui-v2/bootstrap/start-tui-v2.js +3 -0
- package/dist/tui-v2/bootstrap/start-tui-v2.js.map +1 -1
- package/dist/tui-v2/components/completion/completion-menu.d.ts +4 -6
- package/dist/tui-v2/components/completion/completion-menu.js +34 -16
- package/dist/tui-v2/components/completion/completion-menu.js.map +1 -1
- package/dist/tui-v2/components/composer/composer-input-box.js +3 -1
- package/dist/tui-v2/components/composer/composer-input-box.js.map +1 -1
- package/dist/tui-v2/components/modal/secret-modal.js +6 -4
- package/dist/tui-v2/components/modal/secret-modal.js.map +1 -1
- package/dist/tui-v2/components/modal/text-editor-modal.d.ts +19 -0
- package/dist/tui-v2/components/modal/text-editor-modal.js +85 -0
- package/dist/tui-v2/components/modal/text-editor-modal.js.map +1 -0
- package/dist/tui-v2/components/overlay/overlay-host.js +2 -1
- package/dist/tui-v2/components/overlay/overlay-host.js.map +1 -1
- package/dist/tui-v2/components/transcript/compacted-row.js +12 -3
- package/dist/tui-v2/components/transcript/compacted-row.js.map +1 -1
- package/dist/tui-v2/components/transcript/thinking-block.d.ts +9 -1
- package/dist/tui-v2/components/transcript/thinking-block.js +253 -49
- package/dist/tui-v2/components/transcript/thinking-block.js.map +1 -1
- package/dist/tui-v2/components/transcript/thinking-presentation.d.ts +46 -0
- package/dist/tui-v2/components/transcript/thinking-presentation.js +84 -0
- package/dist/tui-v2/components/transcript/thinking-presentation.js.map +1 -0
- package/dist/tui-v2/components/transcript/transcript-row.d.ts +2 -0
- package/dist/tui-v2/components/transcript/transcript-row.js +7 -2
- package/dist/tui-v2/components/transcript/transcript-row.js.map +1 -1
- package/dist/tui-v2/components/transcript/transcript-view.js +195 -83
- package/dist/tui-v2/components/transcript/transcript-view.js.map +1 -1
- package/dist/tui-v2/composer/composer-editor.js +54 -39
- package/dist/tui-v2/composer/composer-editor.js.map +1 -1
- package/dist/tui-v2/composer/composer-highlight.d.ts +20 -0
- package/dist/tui-v2/composer/composer-highlight.js +97 -0
- package/dist/tui-v2/composer/composer-highlight.js.map +1 -0
- package/dist/tui-v2/composer/textarea-keybindings.d.ts +5 -0
- package/dist/tui-v2/composer/textarea-keybindings.js +12 -0
- package/dist/tui-v2/composer/textarea-keybindings.js.map +1 -1
- package/dist/ui/mentions.js +4 -1
- package/dist/ui/mentions.js.map +1 -1
- package/dist/ui-core/actions/action-id.d.ts +1 -1
- package/dist/ui-core/actions/action-id.js +1 -0
- package/dist/ui-core/actions/action-id.js.map +1 -1
- package/dist/ui-core/actions/format-shortcuts.js +5 -0
- package/dist/ui-core/actions/format-shortcuts.js.map +1 -1
- package/dist/ui-core/actions/keymap.js +3 -0
- package/dist/ui-core/actions/keymap.js.map +1 -1
- package/dist/ui-core/bootstrap/composition-root.d.ts +3 -0
- package/dist/ui-core/bootstrap/composition-root.js +5 -1
- package/dist/ui-core/bootstrap/composition-root.js.map +1 -1
- package/dist/ui-core/commands/command-handlers.js +2 -0
- package/dist/ui-core/commands/command-handlers.js.map +1 -1
- package/dist/ui-core/commands/mcp-commands.d.ts +3 -0
- package/dist/ui-core/commands/mcp-commands.js +310 -0
- package/dist/ui-core/commands/mcp-commands.js.map +1 -0
- package/dist/ui-core/commands/picker-commands.d.ts +1 -1
- package/dist/ui-core/commands/picker-commands.js +2 -2
- package/dist/ui-core/commands/picker-commands.js.map +1 -1
- package/dist/ui-core/commands/session-commands.js +1 -0
- package/dist/ui-core/commands/session-commands.js.map +1 -1
- package/dist/ui-core/composer/completion-viewport.d.ts +40 -0
- package/dist/ui-core/composer/completion-viewport.js +105 -0
- package/dist/ui-core/composer/completion-viewport.js.map +1 -0
- package/dist/ui-core/controllers/overlay-controller.d.ts +24 -3
- package/dist/ui-core/controllers/overlay-controller.js +35 -4
- package/dist/ui-core/controllers/overlay-controller.js.map +1 -1
- package/dist/ui-core/rendering/artifact-pager-source.d.ts +1 -0
- package/dist/ui-core/rendering/artifact-pager-source.js +67 -1
- package/dist/ui-core/rendering/artifact-pager-source.js.map +1 -1
- package/dist/ui-core/rendering/duration.d.ts +3 -1
- package/dist/ui-core/rendering/duration.js +14 -0
- package/dist/ui-core/rendering/duration.js.map +1 -1
- package/dist/ui-core/rendering/exit-summary.js +4 -4
- package/dist/ui-core/rendering/format-help.js +4 -0
- package/dist/ui-core/rendering/format-help.js.map +1 -1
- package/dist/ui-core/rendering/intro-header.js +4 -4
- package/dist/ui-core/rendering/open-tool-output.js +90 -32
- package/dist/ui-core/rendering/open-tool-output.js.map +1 -1
- package/dist/ui-core/rendering/theme.d.ts +5 -3
- package/dist/ui-core/rendering/theme.js +8 -4
- package/dist/ui-core/rendering/theme.js.map +1 -1
- package/dist/ui-core/rendering/wordmark.d.ts +2 -2
- package/dist/ui-core/rendering/wordmark.js +62 -62
- package/dist/ui-core/rendering/wordmark.js.map +1 -1
- package/dist/ui-core/state/thinking-copy.d.ts +13 -0
- package/dist/ui-core/state/thinking-copy.js +33 -0
- package/dist/ui-core/state/thinking-copy.js.map +1 -0
- package/dist/ui-core/state/transcript-hydrate.js +20 -0
- package/dist/ui-core/state/transcript-hydrate.js.map +1 -1
- package/dist/ui-core/state/transcript-reducer.js +140 -62
- package/dist/ui-core/state/transcript-reducer.js.map +1 -1
- package/dist/ui-core/state/transcript-store.d.ts +10 -0
- package/dist/ui-core/state/transcript-store.js +235 -31
- package/dist/ui-core/state/transcript-store.js.map +1 -1
- package/dist/ui-core/state/transcript-types.d.ts +10 -0
- package/dist/ui-core/state/transcript-types.js +1 -0
- package/dist/ui-core/state/transcript-types.js.map +1 -1
- package/dist/ui-core/state/transcript-window.d.ts +32 -0
- package/dist/ui-core/state/transcript-window.js +63 -0
- package/dist/ui-core/state/transcript-window.js.map +1 -0
- package/dist/version.generated.d.ts +2 -2
- package/dist/version.generated.js +2 -2
- package/package.json +1 -1
- package/dist/tui-v2/composer/skill-highlight.d.ts +0 -3
- package/dist/tui-v2/composer/skill-highlight.js +0 -63
- package/dist/tui-v2/composer/skill-highlight.js.map +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
export const MCP_CANONICAL_PREFIX = "mcp.";
|
|
3
|
+
export const MCP_WIRE_PREFIX = "mcp_";
|
|
4
|
+
export const MCP_WIRE_MAX_LENGTH = 64;
|
|
5
|
+
const MIN_HASH_LENGTH = 8;
|
|
6
|
+
const NON_WIRE_CHAR = /[^A-Za-z0-9]+/g;
|
|
7
|
+
const IDENTITY_SEPARATOR = "\u0000";
|
|
8
|
+
export function canonicalToolName(serverName, toolName) {
|
|
9
|
+
return `${MCP_CANONICAL_PREFIX}${serverName}.${toolName}`;
|
|
10
|
+
}
|
|
11
|
+
export function isCanonicalToolName(value) {
|
|
12
|
+
return value.startsWith(MCP_CANONICAL_PREFIX) && value.length > MCP_CANONICAL_PREFIX.length;
|
|
13
|
+
}
|
|
14
|
+
export function toolIdentity(serverName, toolName) {
|
|
15
|
+
return `${serverName}${IDENTITY_SEPARATOR}${toolName}`;
|
|
16
|
+
}
|
|
17
|
+
function sanitizeSegment(raw) {
|
|
18
|
+
const replaced = raw.replace(NON_WIRE_CHAR, "_").replace(/^_+|_+$/g, "");
|
|
19
|
+
const value = replaced.length > 0 ? replaced : "x";
|
|
20
|
+
return { value, normalized: value !== raw };
|
|
21
|
+
}
|
|
22
|
+
function hashFor(identity, length) {
|
|
23
|
+
return createHash("sha256").update(identity).digest("hex").slice(0, length);
|
|
24
|
+
}
|
|
25
|
+
function withHash(base, identity, length) {
|
|
26
|
+
const suffix = `_${hashFor(identity, length)}`;
|
|
27
|
+
const room = Math.max(MCP_WIRE_PREFIX.length, MCP_WIRE_MAX_LENGTH - suffix.length);
|
|
28
|
+
const head = base.length > room ? base.slice(0, room) : base;
|
|
29
|
+
return `${head}${suffix}`;
|
|
30
|
+
}
|
|
31
|
+
export class WireNameAllocator {
|
|
32
|
+
used = new Map();
|
|
33
|
+
assign(input) {
|
|
34
|
+
const identity = toolIdentity(input.serverName, input.toolName);
|
|
35
|
+
const server = sanitizeSegment(input.serverName);
|
|
36
|
+
const tool = sanitizeSegment(input.toolName);
|
|
37
|
+
const base = `${MCP_WIRE_PREFIX}${server.value}_${tool.value}`;
|
|
38
|
+
const collides = this.used.has(base) && this.used.get(base) !== identity;
|
|
39
|
+
const mustHash = server.normalized || tool.normalized || base.length > MCP_WIRE_MAX_LENGTH || collides;
|
|
40
|
+
let hashLength = MIN_HASH_LENGTH;
|
|
41
|
+
let candidate = mustHash ? withHash(base, identity, hashLength) : base;
|
|
42
|
+
while (this.used.has(candidate) && this.used.get(candidate) !== identity) {
|
|
43
|
+
hashLength += 4;
|
|
44
|
+
candidate = withHash(base, identity, hashLength);
|
|
45
|
+
}
|
|
46
|
+
this.used.set(candidate, identity);
|
|
47
|
+
return candidate;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function allocateWireNames(inputs) {
|
|
51
|
+
const sorted = [...inputs].sort((a, b) => toolIdentity(a.serverName, a.toolName).localeCompare(toolIdentity(b.serverName, b.toolName)));
|
|
52
|
+
const allocator = new WireNameAllocator();
|
|
53
|
+
const byIdentity = new Map();
|
|
54
|
+
for (const input of sorted) {
|
|
55
|
+
byIdentity.set(toolIdentity(input.serverName, input.toolName), allocator.assign(input));
|
|
56
|
+
}
|
|
57
|
+
return byIdentity;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","sourceRoot":"","sources":["../../src/mcp/names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAe,CAAC;AACpD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAe,CAAC;AAC/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,aAAa,GAAG,gBAAgB,CAAC;AACvC,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAEpC,MAAM,UAAU,iBAAiB,CAAC,UAAkB,EAAE,QAAgB;IACpE,OAAO,GAAG,oBAAoB,GAAG,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IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACnC,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAgC;IAChE,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACvC,YAAY,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAC7F,CAAC;IACF,MAAM,SAAS,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAC1C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC7C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RiskLevel } from "../types.js";
|
|
2
|
+
import type { McpNormalizedResult, McpToolAnnotations, McpToolDescriptor, McpToolMetadata } from "./types.js";
|
|
3
|
+
export declare function deriveRisk(annotations: McpToolAnnotations): RiskLevel;
|
|
4
|
+
export declare function parseToolDescriptor(value: unknown): McpToolDescriptor | undefined;
|
|
5
|
+
export declare function toToolMetadata(serverName: string, descriptor: McpToolDescriptor, wireName: string): McpToolMetadata;
|
|
6
|
+
export declare function normalizeToolResult(raw: unknown): McpNormalizedResult;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { canonicalToolName } from "./names.js";
|
|
2
|
+
function coerceSchema(schema) {
|
|
3
|
+
if (typeof schema === "object" &&
|
|
4
|
+
schema !== null &&
|
|
5
|
+
schema.type === "object") {
|
|
6
|
+
const record = schema;
|
|
7
|
+
const properties = typeof record.properties === "object" && record.properties !== null
|
|
8
|
+
? record.properties
|
|
9
|
+
: {};
|
|
10
|
+
const required = Array.isArray(record.required)
|
|
11
|
+
? record.required.filter((entry) => typeof entry === "string")
|
|
12
|
+
: undefined;
|
|
13
|
+
const additionalProperties = typeof record.additionalProperties === "boolean"
|
|
14
|
+
? record.additionalProperties
|
|
15
|
+
: undefined;
|
|
16
|
+
return {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties,
|
|
19
|
+
...(required !== undefined ? { required } : {}),
|
|
20
|
+
...(additionalProperties !== undefined ? { additionalProperties } : {}),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return { type: "object", properties: {} };
|
|
24
|
+
}
|
|
25
|
+
function readAnnotations(value) {
|
|
26
|
+
if (typeof value !== "object" || value === null)
|
|
27
|
+
return {};
|
|
28
|
+
const record = value;
|
|
29
|
+
const result = {};
|
|
30
|
+
if (typeof record.title === "string")
|
|
31
|
+
result.title = record.title;
|
|
32
|
+
if (typeof record.readOnlyHint === "boolean")
|
|
33
|
+
result.readOnlyHint = record.readOnlyHint;
|
|
34
|
+
if (typeof record.destructiveHint === "boolean")
|
|
35
|
+
result.destructiveHint = record.destructiveHint;
|
|
36
|
+
if (typeof record.idempotentHint === "boolean")
|
|
37
|
+
result.idempotentHint = record.idempotentHint;
|
|
38
|
+
if (typeof record.openWorldHint === "boolean")
|
|
39
|
+
result.openWorldHint = record.openWorldHint;
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
export function deriveRisk(annotations) {
|
|
43
|
+
if (annotations.readOnlyHint === true)
|
|
44
|
+
return "safe";
|
|
45
|
+
return "confirm";
|
|
46
|
+
}
|
|
47
|
+
export function parseToolDescriptor(value) {
|
|
48
|
+
if (typeof value !== "object" || value === null)
|
|
49
|
+
return undefined;
|
|
50
|
+
const record = value;
|
|
51
|
+
if (typeof record.name !== "string" || record.name.length === 0)
|
|
52
|
+
return undefined;
|
|
53
|
+
const descriptor = { name: record.name };
|
|
54
|
+
if (typeof record.title === "string")
|
|
55
|
+
descriptor.title = record.title;
|
|
56
|
+
if (typeof record.description === "string")
|
|
57
|
+
descriptor.description = record.description;
|
|
58
|
+
if (typeof record.inputSchema === "object" && record.inputSchema !== null) {
|
|
59
|
+
descriptor.inputSchema = record.inputSchema;
|
|
60
|
+
}
|
|
61
|
+
if ("annotations" in record)
|
|
62
|
+
descriptor.annotations = readAnnotations(record.annotations);
|
|
63
|
+
return descriptor;
|
|
64
|
+
}
|
|
65
|
+
export function toToolMetadata(serverName, descriptor, wireName) {
|
|
66
|
+
const annotations = descriptor.annotations ?? {};
|
|
67
|
+
const readOnly = annotations.readOnlyHint === true;
|
|
68
|
+
const destructive = readOnly ? false : annotations.destructiveHint ?? true;
|
|
69
|
+
const idempotent = annotations.idempotentHint ?? false;
|
|
70
|
+
const openWorld = annotations.openWorldHint ?? false;
|
|
71
|
+
const title = descriptor.title ?? annotations.title;
|
|
72
|
+
const base = {
|
|
73
|
+
canonicalName: canonicalToolName(serverName, descriptor.name),
|
|
74
|
+
wireName,
|
|
75
|
+
serverName,
|
|
76
|
+
toolName: descriptor.name,
|
|
77
|
+
description: descriptor.description ?? "",
|
|
78
|
+
inputSchema: coerceSchema(descriptor.inputSchema),
|
|
79
|
+
risk: deriveRisk(annotations),
|
|
80
|
+
readOnly,
|
|
81
|
+
destructive,
|
|
82
|
+
idempotent,
|
|
83
|
+
openWorld,
|
|
84
|
+
annotations,
|
|
85
|
+
};
|
|
86
|
+
return title !== undefined ? { ...base, title } : base;
|
|
87
|
+
}
|
|
88
|
+
function readContentImages(content) {
|
|
89
|
+
const images = [];
|
|
90
|
+
for (const entry of content) {
|
|
91
|
+
if (typeof entry !== "object" || entry === null)
|
|
92
|
+
continue;
|
|
93
|
+
const record = entry;
|
|
94
|
+
if (record.type !== "image")
|
|
95
|
+
continue;
|
|
96
|
+
const data = record.data;
|
|
97
|
+
const mimeType = record.mimeType;
|
|
98
|
+
if (typeof data === "string" && typeof mimeType === "string") {
|
|
99
|
+
images.push({ mediaType: mimeType, dataBase64: data });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return images;
|
|
103
|
+
}
|
|
104
|
+
function readContentResources(content) {
|
|
105
|
+
const resources = [];
|
|
106
|
+
for (const entry of content) {
|
|
107
|
+
if (typeof entry !== "object" || entry === null)
|
|
108
|
+
continue;
|
|
109
|
+
const record = entry;
|
|
110
|
+
if (record.type !== "resource")
|
|
111
|
+
continue;
|
|
112
|
+
const resource = record.resource;
|
|
113
|
+
if (typeof resource !== "object" || resource === null)
|
|
114
|
+
continue;
|
|
115
|
+
const res = resource;
|
|
116
|
+
const uri = typeof res.uri === "string" ? res.uri : "";
|
|
117
|
+
const normalized = { uri };
|
|
118
|
+
if (typeof res.mimeType === "string")
|
|
119
|
+
normalized.mimeType = res.mimeType;
|
|
120
|
+
if (typeof res.text === "string")
|
|
121
|
+
normalized.text = res.text;
|
|
122
|
+
if (typeof res.blob === "string")
|
|
123
|
+
normalized.blobBase64 = res.blob;
|
|
124
|
+
resources.push(normalized);
|
|
125
|
+
}
|
|
126
|
+
return resources;
|
|
127
|
+
}
|
|
128
|
+
function readContentText(content) {
|
|
129
|
+
const parts = [];
|
|
130
|
+
for (const entry of content) {
|
|
131
|
+
if (typeof entry !== "object" || entry === null)
|
|
132
|
+
continue;
|
|
133
|
+
const record = entry;
|
|
134
|
+
if (record.type === "text" && typeof record.text === "string") {
|
|
135
|
+
parts.push(record.text);
|
|
136
|
+
}
|
|
137
|
+
else if (record.type === "resource") {
|
|
138
|
+
const resource = record.resource;
|
|
139
|
+
if (resource && typeof resource.text === "string") {
|
|
140
|
+
const uri = typeof resource.uri === "string" ? resource.uri : "resource";
|
|
141
|
+
parts.push(`[${uri}]\n${resource.text}`);
|
|
142
|
+
}
|
|
143
|
+
else if (resource && typeof resource.uri === "string") {
|
|
144
|
+
parts.push(`[resource ${resource.uri}]`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (record.type === "image") {
|
|
148
|
+
const mime = typeof record.mimeType === "string" ? record.mimeType : "image";
|
|
149
|
+
parts.push(`[image ${mime}]`);
|
|
150
|
+
}
|
|
151
|
+
else if (record.type === "audio") {
|
|
152
|
+
const mime = typeof record.mimeType === "string" ? record.mimeType : "audio";
|
|
153
|
+
parts.push(`[audio ${mime}]`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return parts.join("\n");
|
|
157
|
+
}
|
|
158
|
+
export function normalizeToolResult(raw) {
|
|
159
|
+
const record = typeof raw === "object" && raw !== null ? raw : {};
|
|
160
|
+
const isError = record.isError === true;
|
|
161
|
+
const content = Array.isArray(record.content) ? record.content : [];
|
|
162
|
+
const images = readContentImages(content);
|
|
163
|
+
const resources = readContentResources(content);
|
|
164
|
+
const chatImages = images.map((image) => ({
|
|
165
|
+
mediaType: image.mediaType,
|
|
166
|
+
dataBase64: image.dataBase64,
|
|
167
|
+
}));
|
|
168
|
+
let text = readContentText(content);
|
|
169
|
+
if (text.length === 0 && typeof record.structuredContent === "object" && record.structuredContent !== null) {
|
|
170
|
+
text = JSON.stringify(record.structuredContent);
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
ok: !isError,
|
|
174
|
+
isError,
|
|
175
|
+
text,
|
|
176
|
+
images,
|
|
177
|
+
resources,
|
|
178
|
+
chatImages,
|
|
179
|
+
raw,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../../src/mcp/results.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAU/C,SAAS,YAAY,CAAC,MAAe;IACnC,IACE,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,KAAK,IA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,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,UAAU,GAAgB,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACrD,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,UAAU,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC,CAAC,CAAC;IACJ,IAAI,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,MAAM,CAAC,iBAAiB,KAAK,QAAQ,IAAI,MAAM,CAAC,iBAAiB,KAAK,IAAI,EAAE,CAAC;QAC3G,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAClD,CAAC;IACD,OAAO;QACL,EAAE,EAAE,CAAC,OAAO;QACZ,OAAO;QACP,IAAI;QACJ,MAAM;QACN,SAAS;QACT,UAAU;QACV,GAAG;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { RiskDecision } from "../safety/classifier.js";
|
|
2
|
+
import type { ToolDefinition, ToolResult } from "../types.js";
|
|
3
|
+
import { McpManager, type McpManagerOptions } from "./manager.js";
|
|
4
|
+
import type { McpSnapshot, McpToolMetadata } from "./types.js";
|
|
5
|
+
export type McpRuntimeSelection = {
|
|
6
|
+
readonly mode: "all";
|
|
7
|
+
} | {
|
|
8
|
+
readonly mode: "off";
|
|
9
|
+
} | {
|
|
10
|
+
readonly mode: "servers";
|
|
11
|
+
readonly serverNames: readonly string[];
|
|
12
|
+
};
|
|
13
|
+
export type McpBaseSelection = {
|
|
14
|
+
readonly mode: "all";
|
|
15
|
+
} | {
|
|
16
|
+
readonly mode: "off";
|
|
17
|
+
};
|
|
18
|
+
export interface McpRuntimeState {
|
|
19
|
+
readonly snapshot: McpSnapshot;
|
|
20
|
+
readonly selection: McpRuntimeSelection;
|
|
21
|
+
readonly refreshing: boolean;
|
|
22
|
+
readonly activeToolCount: number;
|
|
23
|
+
readonly catalogSignature: string;
|
|
24
|
+
readonly error?: string | undefined;
|
|
25
|
+
}
|
|
26
|
+
export interface McpRuntimeOptions {
|
|
27
|
+
readonly manager?: McpManager | undefined;
|
|
28
|
+
readonly managerOptions?: McpManagerOptions | undefined;
|
|
29
|
+
}
|
|
30
|
+
export declare function mcpSelectionLabel(selection: McpRuntimeSelection): string;
|
|
31
|
+
/**
|
|
32
|
+
* A turn's pinned view of the catalog. Tool schemas are advertised once per
|
|
33
|
+
* turn, so dispatch, classification and prompt context must keep resolving
|
|
34
|
+
* against that same catalog even if a refresh, reconnect or selection edit
|
|
35
|
+
* lands mid-turn — otherwise an advertised tool becomes "unknown" halfway
|
|
36
|
+
* through and the model is told its tools disappeared.
|
|
37
|
+
*/
|
|
38
|
+
export interface McpTurnLease {
|
|
39
|
+
release(): void;
|
|
40
|
+
}
|
|
41
|
+
export declare class McpRuntime {
|
|
42
|
+
private readonly manager;
|
|
43
|
+
private readonly listeners;
|
|
44
|
+
private refreshPromise;
|
|
45
|
+
private started;
|
|
46
|
+
private closed;
|
|
47
|
+
private state;
|
|
48
|
+
private base;
|
|
49
|
+
private readonly leases;
|
|
50
|
+
private readonly unregisterDispatcher;
|
|
51
|
+
constructor(options?: McpRuntimeOptions);
|
|
52
|
+
readonly subscribe: (listener: () => void) => (() => void);
|
|
53
|
+
readonly getState: () => McpRuntimeState;
|
|
54
|
+
private emit;
|
|
55
|
+
private publish;
|
|
56
|
+
private registerSnapshotTools;
|
|
57
|
+
start(): Promise<McpRuntimeState>;
|
|
58
|
+
ensureReady(): Promise<McpRuntimeState>;
|
|
59
|
+
refresh(options?: {
|
|
60
|
+
force?: boolean;
|
|
61
|
+
}): Promise<McpRuntimeState>;
|
|
62
|
+
reconnect(serverName: string): Promise<McpRuntimeState>;
|
|
63
|
+
selectAll(): McpRuntimeState;
|
|
64
|
+
selectOff(): McpRuntimeState;
|
|
65
|
+
serverNames(): ReadonlySet<string>;
|
|
66
|
+
selectServers(serverNames: readonly string[]): McpRuntimeState;
|
|
67
|
+
selectServer(serverName: string): McpRuntimeState;
|
|
68
|
+
applyMentionSelection(text: string): McpRuntimeState;
|
|
69
|
+
beginTurn(): McpTurnLease;
|
|
70
|
+
private liveView;
|
|
71
|
+
/** Newest pinned turn view, or the live one when no turn is in flight. */
|
|
72
|
+
private view;
|
|
73
|
+
private views;
|
|
74
|
+
toolDefinitions(options?: {
|
|
75
|
+
askMode?: boolean;
|
|
76
|
+
}): ToolDefinition[];
|
|
77
|
+
toolNames(options?: {
|
|
78
|
+
askMode?: boolean;
|
|
79
|
+
}): string[];
|
|
80
|
+
/**
|
|
81
|
+
* Tolerant lookup: exact canonical / wire hit first, then a punctuation- and
|
|
82
|
+
* case-insensitive match, then an unambiguous suffix match. Models routinely
|
|
83
|
+
* rewrite `mcp.docs.resolve-library-id` as `mcp_docs_resolve_library_id` or
|
|
84
|
+
* drop the server segment; a live tool must not be reported missing for a
|
|
85
|
+
* cosmetic difference.
|
|
86
|
+
*/
|
|
87
|
+
private resolveMetadata;
|
|
88
|
+
getTool(name: string, options?: {
|
|
89
|
+
includeUnselected?: boolean;
|
|
90
|
+
}): McpToolMetadata | undefined;
|
|
91
|
+
unavailableToolMessage(name: string): string;
|
|
92
|
+
canonicalizeToolName(name: string): string;
|
|
93
|
+
classify(name: string): RiskDecision | undefined;
|
|
94
|
+
isParallelSafe(name: string): boolean;
|
|
95
|
+
private secretsFor;
|
|
96
|
+
private normalizeResult;
|
|
97
|
+
callTool(name: string, args: Record<string, unknown>, options?: {
|
|
98
|
+
signal?: AbortSignal | undefined;
|
|
99
|
+
timeoutMs?: number | undefined;
|
|
100
|
+
}): Promise<ToolResult>;
|
|
101
|
+
promptContext(options: {
|
|
102
|
+
nativeTools: boolean;
|
|
103
|
+
askMode?: boolean;
|
|
104
|
+
}): string | undefined;
|
|
105
|
+
statusLabel(): string | undefined;
|
|
106
|
+
closeAll(): Promise<void>;
|
|
107
|
+
}
|