@herbertgao/pi-extensions 2026.9.11 → 2026.9.13
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 +4 -4
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +8 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +5 -4
- package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +39 -16
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +2 -2
- package/node_modules/@narumitw/pi-btw/README.md +21 -4
- package/node_modules/@narumitw/pi-btw/dist/index.ts +1668 -958
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +4 -4
- package/node_modules/@narumitw/pi-btw/docs/workflows.md +10 -2
- package/node_modules/@narumitw/pi-btw/package.json +1 -1
- package/node_modules/@narumitw/pi-btw/src/btw.ts +17 -79
- package/node_modules/@narumitw/pi-btw/src/conversation-context.ts +74 -0
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +196 -7
- package/node_modules/@narumitw/pi-btw/src/main-thread-updates.ts +40 -0
- package/node_modules/@narumitw/pi-btw/src/menu.ts +34 -2
- package/node_modules/@narumitw/pi-btw/src/settings.ts +49 -0
- package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +9 -1
- package/node_modules/@narumitw/pi-btw/src/workspace-layout.ts +559 -0
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +62 -0
- package/node_modules/pi-mcp-adapter/README.md +75 -7
- package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +193 -0
- package/node_modules/pi-mcp-adapter/cli.js +56 -5
- package/node_modules/pi-mcp-adapter/commands.ts +96 -5
- package/node_modules/pi-mcp-adapter/config.ts +73 -6
- package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +22 -28
- package/node_modules/pi-mcp-adapter/direct-tools.ts +13 -5
- package/node_modules/pi-mcp-adapter/dist/abort.d.ts +2 -0
- package/node_modules/pi-mcp-adapter/dist/abort.js +36 -0
- package/node_modules/pi-mcp-adapter/dist/abort.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +6 -0
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +194 -0
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/config.d.ts +5 -0
- package/node_modules/pi-mcp-adapter/dist/config.js +75 -6
- package/node_modules/pi-mcp-adapter/dist/config.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +18 -0
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js +88 -0
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +17 -0
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +316 -0
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/errors.d.ts +131 -0
- package/node_modules/pi-mcp-adapter/dist/errors.js +278 -0
- package/node_modules/pi-mcp-adapter/dist/errors.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +8 -0
- package/node_modules/pi-mcp-adapter/dist/http-ca.js +88 -0
- package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +15 -0
- package/node_modules/pi-mcp-adapter/dist/jev-client.js +340 -0
- package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +77 -0
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +2 -0
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +22 -0
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +85 -0
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +2 -0
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +55 -0
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +56 -0
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js +410 -0
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/logger.d.ts +51 -0
- package/node_modules/pi-mcp-adapter/dist/logger.js +131 -0
- package/node_modules/pi-mcp-adapter/dist/logger.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +26 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +103 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +118 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +1098 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +168 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +1117 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +7 -140
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +53 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +441 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +148 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +689 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +6 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +166 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +102 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +369 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +95 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +242 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +2 -11
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +6 -0
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +505 -0
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +10 -0
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +312 -0
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +13 -0
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +97 -0
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +17 -0
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +203 -0
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +11 -0
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +172 -0
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +157 -0
- package/node_modules/pi-mcp-adapter/dist/server-manager.js +1743 -0
- package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +34 -0
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js +140 -0
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +26 -0
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js +142 -0
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/state.d.ts +73 -0
- package/node_modules/pi-mcp-adapter/dist/state.js +2 -0
- package/node_modules/pi-mcp-adapter/dist/state.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/types.d.ts +36 -0
- package/node_modules/pi-mcp-adapter/dist/types.js +18 -0
- package/node_modules/pi-mcp-adapter/dist/types.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +17 -0
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +219 -0
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +15 -0
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +85 -0
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/utils.d.ts +1 -0
- package/node_modules/pi-mcp-adapter/dist/utils.js +13 -0
- package/node_modules/pi-mcp-adapter/dist/utils.js.map +1 -1
- package/node_modules/pi-mcp-adapter/elicitation-handler.ts +29 -19
- package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +85 -0
- package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +34 -0
- package/node_modules/pi-mcp-adapter/index.ts +129 -6
- package/node_modules/pi-mcp-adapter/init.ts +6 -19
- package/node_modules/pi-mcp-adapter/jev-client.ts +273 -0
- package/node_modules/pi-mcp-adapter/jev-contracts.ts +53 -0
- package/node_modules/pi-mcp-adapter/jev-key-store.ts +79 -0
- package/node_modules/pi-mcp-adapter/lifecycle.ts +14 -3
- package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +7 -142
- package/node_modules/pi-mcp-adapter/mcp-code.ts +119 -11
- package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +4 -0
- package/node_modules/pi-mcp-adapter/mcp-references.ts +5 -3
- package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +5 -0
- package/node_modules/pi-mcp-adapter/mcp-tasks.ts +467 -0
- package/node_modules/pi-mcp-adapter/metadata-cache.ts +2 -13
- package/node_modules/pi-mcp-adapter/namespace-tools.ts +1 -1
- package/node_modules/pi-mcp-adapter/package.json +17 -9
- package/node_modules/pi-mcp-adapter/proxy-modes.ts +319 -166
- package/node_modules/pi-mcp-adapter/request-headers-command.ts +6 -3
- package/node_modules/pi-mcp-adapter/search-ranking.ts +38 -7
- package/node_modules/pi-mcp-adapter/secure-keyring.ts +170 -0
- package/node_modules/pi-mcp-adapter/semantic-search.ts +186 -0
- package/node_modules/pi-mcp-adapter/server-manager.ts +293 -50
- package/node_modules/pi-mcp-adapter/session-approvals.ts +14 -0
- package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +2 -0
- package/node_modules/pi-mcp-adapter/state.ts +3 -1
- package/node_modules/pi-mcp-adapter/tool-approval.ts +26 -4
- package/node_modules/pi-mcp-adapter/tool-metadata.ts +6 -14
- package/node_modules/pi-mcp-adapter/tool-registrar.ts +8 -6
- package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +4 -1
- package/node_modules/pi-mcp-adapter/types.ts +53 -0
- package/node_modules/pi-mcp-adapter/ui-server.ts +17 -9
- package/node_modules/pi-mcp-adapter/utils.ts +16 -0
- package/node_modules/pi-multi-account/CHANGELOG.md +23 -0
- package/node_modules/pi-multi-account/README.md +38 -11
- package/node_modules/pi-multi-account/index.ts +371 -96
- package/node_modules/pi-multi-account/package.json +5 -4
- package/node_modules/pi-multi-account/provider-payload-stream.ts +36 -28
- package/node_modules/pi-multi-account/usage.ts +31 -2
- package/node_modules/pi-typesafe/README.md +3 -1
- package/node_modules/pi-typesafe/dist/auth.d.ts +10 -3
- package/node_modules/pi-typesafe/dist/auth.js +13 -7
- package/node_modules/pi-typesafe/dist/backends.d.ts +31 -0
- package/node_modules/pi-typesafe/dist/backends.js +33 -0
- package/node_modules/pi-typesafe/dist/client.d.ts +3 -9
- package/node_modules/pi-typesafe/dist/client.js +63 -39
- package/node_modules/pi-typesafe/dist/credentials.d.ts +11 -5
- package/node_modules/pi-typesafe/dist/credentials.js +15 -8
- package/node_modules/pi-typesafe/dist/extension.js +4 -1
- package/node_modules/pi-typesafe/dist/index.d.ts +1 -1
- package/node_modules/pi-typesafe/dist/index.js +1 -1
- package/node_modules/pi-typesafe/dist/login.d.ts +13 -7
- package/node_modules/pi-typesafe/dist/login.js +17 -8
- package/node_modules/pi-typesafe/dist/schema.js +19 -13
- package/node_modules/pi-typesafe/package.json +1 -1
- package/package.json +11 -10
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error types for MCP UI operations.
|
|
3
|
+
* Provides structured errors with context and recovery hints.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base error class for MCP UI errors.
|
|
7
|
+
*/
|
|
8
|
+
export class McpUiError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
context;
|
|
11
|
+
recoveryHint;
|
|
12
|
+
cause;
|
|
13
|
+
constructor(message, options) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "McpUiError";
|
|
16
|
+
this.code = options.code;
|
|
17
|
+
this.context = options.context ?? {};
|
|
18
|
+
this.recoveryHint = options.recoveryHint;
|
|
19
|
+
this.cause = options.cause;
|
|
20
|
+
// Maintain proper stack trace
|
|
21
|
+
if (Error.captureStackTrace) {
|
|
22
|
+
Error.captureStackTrace(this, this.constructor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
toJSON() {
|
|
26
|
+
return {
|
|
27
|
+
name: this.name,
|
|
28
|
+
code: this.code,
|
|
29
|
+
message: this.message,
|
|
30
|
+
context: this.context,
|
|
31
|
+
recoveryHint: this.recoveryHint,
|
|
32
|
+
stack: this.stack,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Error fetching a UI resource from the MCP server.
|
|
38
|
+
*/
|
|
39
|
+
export class ResourceFetchError extends McpUiError {
|
|
40
|
+
constructor(uri, reason, options) {
|
|
41
|
+
super(`Failed to fetch UI resource "${uri}": ${reason}`, {
|
|
42
|
+
code: "RESOURCE_FETCH_ERROR",
|
|
43
|
+
context: { uri, ...(options?.server !== undefined ? { server: options.server } : {}) },
|
|
44
|
+
recoveryHint: "Check that the MCP server is connected and the resource URI is valid.",
|
|
45
|
+
...(options?.cause !== undefined ? { cause: options.cause } : {}),
|
|
46
|
+
});
|
|
47
|
+
this.name = "ResourceFetchError";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Error parsing or validating UI resource content.
|
|
52
|
+
*/
|
|
53
|
+
export class ResourceParseError extends McpUiError {
|
|
54
|
+
constructor(uri, reason, options) {
|
|
55
|
+
super(`Invalid UI resource "${uri}": ${reason}`, {
|
|
56
|
+
code: "RESOURCE_PARSE_ERROR",
|
|
57
|
+
context: {
|
|
58
|
+
uri,
|
|
59
|
+
...(options?.server !== undefined ? { server: options.server } : {}),
|
|
60
|
+
...(options?.mimeType !== undefined ? { mimeType: options.mimeType } : {}),
|
|
61
|
+
},
|
|
62
|
+
recoveryHint: "Ensure the resource returns valid HTML with the correct MIME type.",
|
|
63
|
+
});
|
|
64
|
+
this.name = "ResourceParseError";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Error connecting to the AppBridge.
|
|
69
|
+
*/
|
|
70
|
+
export class BridgeConnectionError extends McpUiError {
|
|
71
|
+
constructor(reason, options) {
|
|
72
|
+
super(`AppBridge connection failed: ${reason}`, {
|
|
73
|
+
code: "BRIDGE_CONNECTION_ERROR",
|
|
74
|
+
context: options?.session !== undefined ? { session: options.session } : {},
|
|
75
|
+
recoveryHint: "Check browser console for detailed errors. The iframe may have failed to load.",
|
|
76
|
+
...(options?.cause !== undefined ? { cause: options.cause } : {}),
|
|
77
|
+
});
|
|
78
|
+
this.name = "BridgeConnectionError";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Error related to user consent for tool calls.
|
|
83
|
+
*/
|
|
84
|
+
export class ConsentError extends McpUiError {
|
|
85
|
+
denied;
|
|
86
|
+
constructor(server, options) {
|
|
87
|
+
const message = options.denied
|
|
88
|
+
? `Tool calls for "${server}" were denied for this session`
|
|
89
|
+
: `Tool call approval required for "${server}"`;
|
|
90
|
+
super(message, {
|
|
91
|
+
code: options.denied ? "CONSENT_DENIED" : "CONSENT_REQUIRED",
|
|
92
|
+
context: { server },
|
|
93
|
+
recoveryHint: options.denied
|
|
94
|
+
? "The user denied tool access. Start a new session to try again."
|
|
95
|
+
: "Prompt the user for consent before calling tools.",
|
|
96
|
+
});
|
|
97
|
+
this.name = "ConsentError";
|
|
98
|
+
this.denied = options.denied ?? false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Error with UI server session management.
|
|
103
|
+
*/
|
|
104
|
+
export class SessionError extends McpUiError {
|
|
105
|
+
constructor(reason, options) {
|
|
106
|
+
super(`Session error: ${reason}`, {
|
|
107
|
+
code: "SESSION_ERROR",
|
|
108
|
+
context: options?.session !== undefined ? { session: options.session } : {},
|
|
109
|
+
recoveryHint: "The session may have expired or been closed. Try opening the UI again.",
|
|
110
|
+
...(options?.cause !== undefined ? { cause: options.cause } : {}),
|
|
111
|
+
});
|
|
112
|
+
this.name = "SessionError";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Error starting or operating the UI server.
|
|
117
|
+
*/
|
|
118
|
+
export class ServerError extends McpUiError {
|
|
119
|
+
constructor(reason, options) {
|
|
120
|
+
super(`UI server error: ${reason}`, {
|
|
121
|
+
code: "SERVER_ERROR",
|
|
122
|
+
context: options?.port !== undefined ? { port: options.port } : {},
|
|
123
|
+
recoveryHint: "Check if the port is available. Another process may be using it.",
|
|
124
|
+
...(options?.cause !== undefined ? { cause: options.cause } : {}),
|
|
125
|
+
});
|
|
126
|
+
this.name = "ServerError";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Error communicating with the MCP server.
|
|
131
|
+
*/
|
|
132
|
+
export class McpServerError extends McpUiError {
|
|
133
|
+
constructor(server, reason, options) {
|
|
134
|
+
super(`MCP server "${server}" error: ${reason}`, {
|
|
135
|
+
code: "MCP_SERVER_ERROR",
|
|
136
|
+
context: { server, ...(options?.tool !== undefined ? { tool: options.tool } : {}) },
|
|
137
|
+
recoveryHint: "Check that the MCP server is running and responsive.",
|
|
138
|
+
...(options?.cause !== undefined ? { cause: options.cause } : {}),
|
|
139
|
+
});
|
|
140
|
+
this.name = "McpServerError";
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Wrap an unknown error into an McpUiError.
|
|
145
|
+
*/
|
|
146
|
+
export function wrapError(error, context) {
|
|
147
|
+
if (error instanceof McpUiError) {
|
|
148
|
+
// Merge contexts
|
|
149
|
+
return new McpUiError(error.message, {
|
|
150
|
+
code: error.code,
|
|
151
|
+
context: { ...error.context, ...context },
|
|
152
|
+
...(error.recoveryHint !== undefined ? { recoveryHint: error.recoveryHint } : {}),
|
|
153
|
+
...(error.cause !== undefined ? { cause: error.cause } : {}),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const cause = error instanceof Error ? error : undefined;
|
|
157
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
158
|
+
return new McpUiError(message, {
|
|
159
|
+
code: "UNKNOWN_ERROR",
|
|
160
|
+
...(context !== undefined ? { context } : {}),
|
|
161
|
+
...(cause !== undefined ? { cause } : {}),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Check if an error is a specific MCP UI error type.
|
|
166
|
+
*/
|
|
167
|
+
export function isErrorCode(error, code) {
|
|
168
|
+
return error instanceof McpUiError && error.code === code;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Stable adapter error code for an SDK-native input_required result that the
|
|
172
|
+
* current client cannot fulfil because its embedded-request handler is not
|
|
173
|
+
* registered. The SDK keeps the request key/method in `SdkError.data`; this
|
|
174
|
+
* adapter detail intentionally copies only bounded, actionable fields.
|
|
175
|
+
*/
|
|
176
|
+
export const INPUT_REQUIRED_NEEDS_UI = "input_required_needs_ui";
|
|
177
|
+
const INPUT_REQUIRED_METHODS = new Set([
|
|
178
|
+
"elicitation/create",
|
|
179
|
+
"sampling/createMessage",
|
|
180
|
+
]);
|
|
181
|
+
const MAX_INPUT_REQUIRED_SERVER_LENGTH = 96;
|
|
182
|
+
const MAX_INPUT_REQUIRED_TARGET_LENGTH = 160;
|
|
183
|
+
const MAX_INPUT_REQUIRED_DETAIL_LENGTH = 128;
|
|
184
|
+
function asRecord(value) {
|
|
185
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
186
|
+
? value
|
|
187
|
+
: undefined;
|
|
188
|
+
}
|
|
189
|
+
function boundedText(value, maxLength) {
|
|
190
|
+
if (typeof value !== "string" || value.length === 0)
|
|
191
|
+
return undefined;
|
|
192
|
+
return value.length <= maxLength ? value : `${value.slice(0, maxLength - 1)}…`;
|
|
193
|
+
}
|
|
194
|
+
function findEmbeddedInputRequest(error) {
|
|
195
|
+
let current = error;
|
|
196
|
+
const seen = new Set();
|
|
197
|
+
for (let depth = 0; depth < 8 && current !== undefined && current !== null; depth++) {
|
|
198
|
+
if (seen.has(current))
|
|
199
|
+
return undefined;
|
|
200
|
+
seen.add(current);
|
|
201
|
+
const record = asRecord(current);
|
|
202
|
+
if (!record)
|
|
203
|
+
return undefined;
|
|
204
|
+
if (record.code === INPUT_REQUIRED_NEEDS_UI) {
|
|
205
|
+
const details = asRecord(record.details);
|
|
206
|
+
const inputKey = boundedText(details?.inputKey, MAX_INPUT_REQUIRED_DETAIL_LENGTH);
|
|
207
|
+
const inputMethod = boundedText(details?.inputMethod, MAX_INPUT_REQUIRED_DETAIL_LENGTH);
|
|
208
|
+
if (inputKey && inputMethod && INPUT_REQUIRED_METHODS.has(inputMethod)) {
|
|
209
|
+
const server = boundedText(details?.server, MAX_INPUT_REQUIRED_SERVER_LENGTH);
|
|
210
|
+
const tool = boundedText(details?.tool, MAX_INPUT_REQUIRED_TARGET_LENGTH);
|
|
211
|
+
const resourceUri = boundedText(details?.resourceUri, MAX_INPUT_REQUIRED_TARGET_LENGTH);
|
|
212
|
+
return {
|
|
213
|
+
inputKey,
|
|
214
|
+
inputMethod,
|
|
215
|
+
...(server ? { server } : {}),
|
|
216
|
+
...(tool ? { tool } : {}),
|
|
217
|
+
...(resourceUri ? { resourceUri } : {}),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (record.code === "CAPABILITY_NOT_SUPPORTED") {
|
|
222
|
+
const data = asRecord(record.data);
|
|
223
|
+
const inputKey = boundedText(data?.key, MAX_INPUT_REQUIRED_DETAIL_LENGTH);
|
|
224
|
+
const inputMethod = boundedText(data?.method, MAX_INPUT_REQUIRED_DETAIL_LENGTH);
|
|
225
|
+
if (inputKey && inputMethod && INPUT_REQUIRED_METHODS.has(inputMethod)) {
|
|
226
|
+
return { inputKey, inputMethod };
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
current = record.cause;
|
|
230
|
+
}
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Convert a missing embedded-input handler into an adapter-owned result
|
|
235
|
+
* detail. Matching requires the SDK's typed code/data shape (or this module's
|
|
236
|
+
* typed wrapper), rather than arbitrary error-message text.
|
|
237
|
+
*/
|
|
238
|
+
export function getInputRequiredNeedsUiDetails(error, identity) {
|
|
239
|
+
const request = findEmbeddedInputRequest(error);
|
|
240
|
+
if (!request)
|
|
241
|
+
return undefined;
|
|
242
|
+
const server = boundedText(request.server ?? identity.server, MAX_INPUT_REQUIRED_SERVER_LENGTH) ?? "unknown";
|
|
243
|
+
const tool = boundedText(request.tool ?? identity.tool, MAX_INPUT_REQUIRED_TARGET_LENGTH);
|
|
244
|
+
const resourceUri = boundedText(request.resourceUri ?? identity.resourceUri, MAX_INPUT_REQUIRED_TARGET_LENGTH);
|
|
245
|
+
const target = resourceUri
|
|
246
|
+
? `read resource "${resourceUri}"`
|
|
247
|
+
: tool
|
|
248
|
+
? `call tool "${tool}"`
|
|
249
|
+
: "complete the MCP request";
|
|
250
|
+
const guidance = request.inputMethod === "elicitation/create"
|
|
251
|
+
? "Run this call in an interactive Pi session with elicitation enabled, then retry."
|
|
252
|
+
: "Run this call in an interactive Pi session with the required MCP capability enabled, then retry.";
|
|
253
|
+
const message = `MCP server "${server}" requested input to ${target}, but this session has no handler for "${request.inputMethod}" (input "${request.inputKey}"). ${guidance}`;
|
|
254
|
+
return {
|
|
255
|
+
error: INPUT_REQUIRED_NEEDS_UI,
|
|
256
|
+
server,
|
|
257
|
+
...(tool ? { tool } : {}),
|
|
258
|
+
...(resourceUri ? { resourceUri } : {}),
|
|
259
|
+
inputKey: request.inputKey,
|
|
260
|
+
inputMethod: request.inputMethod,
|
|
261
|
+
message,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/** Error form used by UiResourceHandler so an outer tool call can preserve the classification. */
|
|
265
|
+
export class InputRequiredNeedsUiError extends McpUiError {
|
|
266
|
+
details;
|
|
267
|
+
constructor(details, cause) {
|
|
268
|
+
super(details.message, {
|
|
269
|
+
code: INPUT_REQUIRED_NEEDS_UI,
|
|
270
|
+
context: { ...details },
|
|
271
|
+
recoveryHint: "Run this call in an interactive Pi session with the required MCP input handler enabled, then retry.",
|
|
272
|
+
...(cause ? { cause } : {}),
|
|
273
|
+
});
|
|
274
|
+
this.details = details;
|
|
275
|
+
this.name = "InputRequiredNeedsUiError";
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC1B,IAAI,CAAS;IACb,OAAO,CAAoB;IAC3B,YAAY,CAAqB;IACjC,KAAK,CAAoB;IAElC,YACE,OAAe,EACf,OAKC;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE3B,8BAA8B;QAC9B,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI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ts";
|
|
2
|
+
/** Validate at the connection boundary, including callers that bypass JSON config. */
|
|
3
|
+
export declare function validateCaFile(definition: ServerEntry): void;
|
|
4
|
+
/** One connection owner, shared across transport/auth retries; never process-wide. */
|
|
5
|
+
export declare function createCaFetch(definition: ServerEntry): {
|
|
6
|
+
fetch: (input: URL | RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
7
|
+
close: () => Promise<void>;
|
|
8
|
+
} | undefined;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { X509Certificate } from "node:crypto";
|
|
3
|
+
import { Agent, Request as UndiciRequest, fetch as undiciFetch } from "undici";
|
|
4
|
+
import { getMissingEnvVars, resolveConfigPath, resolveServerUrl } from "./utils.js";
|
|
5
|
+
/** Validate at the connection boundary, including callers that bypass JSON config. */
|
|
6
|
+
export function validateCaFile(definition) {
|
|
7
|
+
if (definition.caFile === undefined)
|
|
8
|
+
return;
|
|
9
|
+
if (typeof definition.caFile !== "string" || !definition.caFile.trim()) {
|
|
10
|
+
throw new Error("MCP caFile must be a non-empty path string");
|
|
11
|
+
}
|
|
12
|
+
if (definition.command !== undefined || definition.socket !== undefined
|
|
13
|
+
|| !definition.url || new URL(resolveServerUrl(definition)).protocol !== "https:") {
|
|
14
|
+
throw new Error("MCP caFile is only supported for HTTPS HTTP servers");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** One connection owner, shared across transport/auth retries; never process-wide. */
|
|
18
|
+
export function createCaFetch(definition) {
|
|
19
|
+
validateCaFile(definition);
|
|
20
|
+
if (definition.caFile === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
const origin = new URL(resolveServerUrl(definition)).origin;
|
|
23
|
+
if (getMissingEnvVars(definition.caFile).length)
|
|
24
|
+
throw new Error("Missing environment variable in MCP caFile");
|
|
25
|
+
let ca;
|
|
26
|
+
try {
|
|
27
|
+
ca = readFileSync(resolveConfigPath(definition.caFile), "utf8");
|
|
28
|
+
const certificates = ca.match(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g);
|
|
29
|
+
if (!certificates?.length || ca.replace(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g, "").trim()) {
|
|
30
|
+
throw new Error("expected a PEM certificate bundle");
|
|
31
|
+
}
|
|
32
|
+
for (const certificate of certificates)
|
|
33
|
+
new X509Certificate(certificate);
|
|
34
|
+
}
|
|
35
|
+
catch (cause) {
|
|
36
|
+
throw new Error("Failed to load MCP caFile PEM certificate bundle", { cause });
|
|
37
|
+
}
|
|
38
|
+
const dispatcher = new Agent({ connect: { ca } });
|
|
39
|
+
let closed;
|
|
40
|
+
return {
|
|
41
|
+
fetch: (input, init) => {
|
|
42
|
+
const url = new URL(input instanceof Request ? input.url : input.toString());
|
|
43
|
+
if (url.origin !== origin)
|
|
44
|
+
return globalThis.fetch(input, init);
|
|
45
|
+
// The Agent comes from the bundled undici copy, whose internals do not
|
|
46
|
+
// match the global fetch dispatcher contract on newer Node releases
|
|
47
|
+
// (Node 26 ships undici v8; the dependency pins undici v6). Route
|
|
48
|
+
// same-origin requests through the bundled fetch so dispatcher and
|
|
49
|
+
// Agent share an implementation. Never follow a redirect with this
|
|
50
|
+
// dispatcher, even to the same origin (no trust-bearing redirect hops).
|
|
51
|
+
// Attach after header-command Request reconstruction.
|
|
52
|
+
try {
|
|
53
|
+
const bundledInput = input instanceof Request
|
|
54
|
+
? new UndiciRequest(input.url, {
|
|
55
|
+
method: input.method,
|
|
56
|
+
headers: [...input.headers],
|
|
57
|
+
// Defer acquiring the source stream until bundled Request validation
|
|
58
|
+
// succeeds. An overriding body never consumes the original body.
|
|
59
|
+
...(init?.body == null && input.body ? { body: (async function* () {
|
|
60
|
+
yield* input.body;
|
|
61
|
+
})(), duplex: "half" } : {}),
|
|
62
|
+
cache: input.cache,
|
|
63
|
+
credentials: input.credentials,
|
|
64
|
+
integrity: input.integrity,
|
|
65
|
+
keepalive: input.keepalive,
|
|
66
|
+
mode: input.mode,
|
|
67
|
+
redirect: input.redirect,
|
|
68
|
+
referrer: input.referrer,
|
|
69
|
+
referrerPolicy: input.referrerPolicy,
|
|
70
|
+
signal: input.signal,
|
|
71
|
+
})
|
|
72
|
+
: input;
|
|
73
|
+
const options = {
|
|
74
|
+
...init,
|
|
75
|
+
...(init?.headers !== undefined ? { headers: [...new Headers(init.headers)] } : {}),
|
|
76
|
+
dispatcher,
|
|
77
|
+
redirect: "error",
|
|
78
|
+
};
|
|
79
|
+
return undiciFetch(bundledInput, options);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return Promise.reject(error);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
close: () => closed ??= dispatcher.destroy(),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=http-ca.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-ca.js","sourceRoot":"","sources":["../http-ca.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,OAAO,IAAI,aAAa,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AAG/E,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpF,sFAAsF;AACtF,MAAM,UAAU,cAAc,CAAC,UAAuB;IACpD,IAAI,UAAU,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO;IAC5C,IAAI,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS,IA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,KAAK,CAAC,QAAQ;wBACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;wBACxB,cAAc,EAAE,KAAK,CAAC,cAAc;wBACpC,MAAM,EAAE,KAAK,CAAC,MAAM;qBACW,CAAC;oBAClC,CAAC,CAAC,KAAK,CAAC;gBACV,MAAM,OAAO,GAAG;oBACd,GAAG,IAAI;oBACP,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnF,UAAU;oBACV,QAAQ,EAAE,OAAgB;iBACK,CAAC;gBAClC,OAAO,WAAW,CAAC,YAAY,EAAE,OAAO,CAAiC,CAAC;YAC5E,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QACD,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,KAAK,UAAU,CAAC,OAAO,EAAE;KAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { McpExtensionState } from "./state.ts";
|
|
2
|
+
import { TYPESAFE_API_ORIGIN, type JevCredentialResolution } from "./jev-key-store.ts";
|
|
3
|
+
import type { JevBudget, JevEvaluateInput, JevEvaluationEnvelope, ResolvedJevSettings } from "./jev-contracts.ts";
|
|
4
|
+
export { TYPESAFE_API_ORIGIN };
|
|
5
|
+
export type { ResolvedJevSettings } from "./jev-contracts.ts";
|
|
6
|
+
export declare function areJevSourcesAllowed(state: McpExtensionState, settings: ResolvedJevSettings, sources: Iterable<string>): boolean;
|
|
7
|
+
export declare function validateJevSettings(value: unknown): ResolvedJevSettings;
|
|
8
|
+
export declare function resolveSemanticJevSettings(state: McpExtensionState, credentialResolver?: () => JevCredentialResolution): ResolvedJevSettings;
|
|
9
|
+
export declare function validateJevEvaluateInput(value: unknown, limits: ResolvedJevSettings): JevEvaluateInput;
|
|
10
|
+
export declare function evaluateJev(state: McpExtensionState, value: JevEvaluateInput, options: {
|
|
11
|
+
purpose: "script" | "semantic-search";
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
budget?: JevBudget;
|
|
14
|
+
observedSources?: readonly string[];
|
|
15
|
+
}): Promise<JevEvaluationEnvelope>;
|