@tencent-ai/agent-sdk 0.3.229 → 0.3.230-dev.80d16dd.202607272156

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.
Files changed (72) hide show
  1. package/cli/CHANGELOG.md +10 -0
  2. package/cli/dist/codebuddy-headless.js +309 -291
  3. package/cli/package.json +3 -2
  4. package/cli/product.cloudhosted.json +2 -2
  5. package/cli/product.internal.json +2 -2
  6. package/cli/product.ioa.json +2 -2
  7. package/cli/product.json +2 -2
  8. package/cli/product.selfhosted.json +2 -2
  9. package/lib/_internal/query-controller.d.ts +48 -2
  10. package/lib/_internal/query-controller.d.ts.map +1 -1
  11. package/lib/_internal/query-controller.js +335 -2
  12. package/lib/_internal/query-controller.js.map +1 -1
  13. package/lib/_internal/remote-extensions-options.d.ts +3 -0
  14. package/lib/_internal/remote-extensions-options.d.ts.map +1 -0
  15. package/lib/_internal/remote-extensions-options.js +37 -0
  16. package/lib/_internal/remote-extensions-options.js.map +1 -0
  17. package/lib/_internal/session-mirror.d.ts +53 -0
  18. package/lib/_internal/session-mirror.d.ts.map +1 -0
  19. package/lib/_internal/session-mirror.js +156 -0
  20. package/lib/_internal/session-mirror.js.map +1 -0
  21. package/lib/_internal/session-store-runtime.d.ts +52 -0
  22. package/lib/_internal/session-store-runtime.d.ts.map +1 -0
  23. package/lib/_internal/session-store-runtime.js +283 -0
  24. package/lib/_internal/session-store-runtime.js.map +1 -0
  25. package/lib/in-memory-session-store.d.ts +31 -0
  26. package/lib/in-memory-session-store.d.ts.map +1 -0
  27. package/lib/in-memory-session-store.js +127 -0
  28. package/lib/in-memory-session-store.js.map +1 -0
  29. package/lib/index.d.ts +13 -1
  30. package/lib/index.d.ts.map +1 -1
  31. package/lib/index.js +16 -1
  32. package/lib/index.js.map +1 -1
  33. package/lib/mcp/delegated-redaction.d.ts +47 -0
  34. package/lib/mcp/delegated-redaction.d.ts.map +1 -0
  35. package/lib/mcp/delegated-redaction.js +362 -0
  36. package/lib/mcp/delegated-redaction.js.map +1 -0
  37. package/lib/mcp/index.d.ts +4 -0
  38. package/lib/mcp/index.d.ts.map +1 -1
  39. package/lib/mcp/index.js +8 -1
  40. package/lib/mcp/index.js.map +1 -1
  41. package/lib/mcp/managed-remote-mcp-bridge.d.ts +49 -0
  42. package/lib/mcp/managed-remote-mcp-bridge.d.ts.map +1 -0
  43. package/lib/mcp/managed-remote-mcp-bridge.js +303 -0
  44. package/lib/mcp/managed-remote-mcp-bridge.js.map +1 -0
  45. package/lib/query.d.ts +14 -1
  46. package/lib/query.d.ts.map +1 -1
  47. package/lib/query.js +320 -28
  48. package/lib/query.js.map +1 -1
  49. package/lib/remote-error-codes.d.ts +8 -0
  50. package/lib/remote-error-codes.d.ts.map +1 -0
  51. package/lib/remote-error-codes.js +23 -0
  52. package/lib/remote-error-codes.js.map +1 -0
  53. package/lib/session-store-protocol.d.ts +19 -0
  54. package/lib/session-store-protocol.d.ts.map +1 -0
  55. package/lib/session-store-protocol.js +125 -0
  56. package/lib/session-store-protocol.js.map +1 -0
  57. package/lib/session.d.ts +8 -1
  58. package/lib/session.d.ts.map +1 -1
  59. package/lib/session.js +132 -11
  60. package/lib/session.js.map +1 -1
  61. package/lib/transport/index.d.ts +53 -3
  62. package/lib/transport/index.d.ts.map +1 -1
  63. package/lib/transport/index.js.map +1 -1
  64. package/lib/transport/process-transport.d.ts +81 -4
  65. package/lib/transport/process-transport.d.ts.map +1 -1
  66. package/lib/transport/process-transport.js +295 -15
  67. package/lib/transport/process-transport.js.map +1 -1
  68. package/lib/types.d.ts +629 -6
  69. package/lib/types.d.ts.map +1 -1
  70. package/lib/types.js +14 -1
  71. package/lib/types.js.map +1 -1
  72. package/package.json +3 -2
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemorySessionStore = exports.DEFAULT_SESSION_STORE_KEY_BYTES = exports.DEFAULT_SESSION_STORE_EVENT_BYTES = void 0;
4
+ const session_store_protocol_1 = require("./session-store-protocol");
5
+ exports.DEFAULT_SESSION_STORE_EVENT_BYTES = 1024 * 1024;
6
+ exports.DEFAULT_SESSION_STORE_KEY_BYTES = 16 * 1024 * 1024;
7
+ function recordKey(key) {
8
+ return `${key.projectKey}\u0000${key.sessionId}\u0000${key.subpath ?? ''}`;
9
+ }
10
+ function mainKey(key) {
11
+ return `${key.projectKey}\u0000${key.sessionId}`;
12
+ }
13
+ class InMemorySessionStore {
14
+ constructor(options = {}) {
15
+ this.records = new Map();
16
+ this.mainTombstones = new Set();
17
+ this.subTombstones = new Set();
18
+ this.maxEventBytes = options.maxEventBytes ?? exports.DEFAULT_SESSION_STORE_EVENT_BYTES;
19
+ this.maxKeyBytes = options.maxKeyBytes ?? exports.DEFAULT_SESSION_STORE_KEY_BYTES;
20
+ this.now = options.now ?? Date.now;
21
+ }
22
+ async append(key, events) {
23
+ if (events.length === 0) {
24
+ return;
25
+ }
26
+ const normalized = (0, session_store_protocol_1.normalizeSessionStoreEvents)(events);
27
+ this.assertNotDeleted(key);
28
+ const id = recordKey(key);
29
+ const record = this.records.get(id);
30
+ const additions = [];
31
+ for (const candidate of normalized) {
32
+ const digest = record?.digests.get(candidate.event.eventId);
33
+ if (digest !== undefined && digest !== candidate.payloadDigest) {
34
+ throw (0, session_store_protocol_1.sessionStoreProtocolError)('EVENT_CONFLICT', `SessionStore eventId ${candidate.event.eventId} conflicts with the stored payload`);
35
+ }
36
+ if (digest === undefined) {
37
+ additions.push(candidate);
38
+ }
39
+ }
40
+ for (const candidate of additions) {
41
+ if (candidate.bytes > this.maxEventBytes) {
42
+ throw (0, session_store_protocol_1.sessionStoreProtocolError)('ENTRY_TOO_LARGE', `SessionStore event exceeds ${this.maxEventBytes} bytes`);
43
+ }
44
+ }
45
+ const addedBytes = additions.reduce((sum, candidate) => sum + candidate.bytes, 0);
46
+ if ((record?.bytes ?? 0) + addedBytes > this.maxKeyBytes) {
47
+ throw (0, session_store_protocol_1.sessionStoreProtocolError)('SESSION_TOO_LARGE', `SessionStore key exceeds ${this.maxKeyBytes} bytes`);
48
+ }
49
+ if (additions.length === 0) {
50
+ return;
51
+ }
52
+ const target = record ?? {
53
+ events: [],
54
+ digests: new Map(),
55
+ bytes: 0,
56
+ mtime: 0,
57
+ };
58
+ for (const candidate of additions) {
59
+ target.events.push(structuredClone(candidate.event));
60
+ target.digests.set(candidate.event.eventId, candidate.payloadDigest);
61
+ target.bytes += candidate.bytes;
62
+ }
63
+ if (!key.subpath) {
64
+ target.mtime = this.now();
65
+ }
66
+ this.records.set(id, target);
67
+ }
68
+ async load(key) {
69
+ if (this.isDeleted(key)) {
70
+ return null;
71
+ }
72
+ const record = this.records.get(recordKey(key));
73
+ return record ? structuredClone(record.events) : null;
74
+ }
75
+ async listSessions(projectKey) {
76
+ const sessions = [];
77
+ for (const [id, record] of this.records) {
78
+ const [project, sessionId, subpath] = id.split('\u0000');
79
+ if (project === projectKey && subpath === '' && !this.mainTombstones.has(`${project}\u0000${sessionId}`)) {
80
+ sessions.push({ sessionId, mtime: record.mtime });
81
+ }
82
+ }
83
+ return sessions;
84
+ }
85
+ async delete(key) {
86
+ if (key.subpath) {
87
+ this.subTombstones.add(recordKey(key));
88
+ this.records.delete(recordKey(key));
89
+ return;
90
+ }
91
+ const root = mainKey(key);
92
+ this.mainTombstones.add(root);
93
+ const prefix = `${root}\u0000`;
94
+ for (const id of [...this.records.keys()]) {
95
+ if (id.startsWith(prefix)) {
96
+ this.records.delete(id);
97
+ }
98
+ }
99
+ }
100
+ async listSubkeys(key) {
101
+ if (this.mainTombstones.has(mainKey(key))) {
102
+ return [];
103
+ }
104
+ const prefix = `${mainKey(key)}\u0000`;
105
+ const subkeys = [];
106
+ for (const id of this.records.keys()) {
107
+ if (id.startsWith(prefix) && !this.subTombstones.has(id)) {
108
+ const subpath = id.slice(prefix.length);
109
+ if (subpath !== '') {
110
+ subkeys.push(subpath);
111
+ }
112
+ }
113
+ }
114
+ return subkeys;
115
+ }
116
+ assertNotDeleted(key) {
117
+ if (this.isDeleted(key)) {
118
+ throw (0, session_store_protocol_1.sessionStoreProtocolError)('SESSION_DELETED', 'SessionStore key has been deleted');
119
+ }
120
+ }
121
+ isDeleted(key) {
122
+ return this.mainTombstones.has(mainKey(key))
123
+ || (!!key.subpath && this.subTombstones.has(recordKey(key)));
124
+ }
125
+ }
126
+ exports.InMemorySessionStore = InMemorySessionStore;
127
+ //# sourceMappingURL=in-memory-session-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory-session-store.js","sourceRoot":"","sources":["../src/in-memory-session-store.ts"],"names":[],"mappings":";;;AAAA,qEAIkC;AAGrB,QAAA,iCAAiC,GAAG,IAAI,GAAG,IAAI,CAAC;AAChD,QAAA,+BAA+B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAehE,SAAS,SAAS,CAAC,GAAe;IAC9B,OAAO,GAAG,GAAG,CAAC,UAAU,SAAS,GAAG,CAAC,SAAS,SAAS,GAAG,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;AAC/E,CAAC;AAED,SAAS,OAAO,CAAC,GAAiD;IAC9D,OAAO,GAAG,GAAG,CAAC,UAAU,SAAS,GAAG,CAAC,SAAS,EAAE,CAAC;AACrD,CAAC;AAED;IAQI,YAAY,OAAO,GAAgC,EAAE;QAPpC,YAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;QAC1C,mBAAc,GAAG,IAAI,GAAG,EAAU,CAAC;QACnC,kBAAa,GAAG,IAAI,GAAG,EAAU,CAAC;QAM/C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,QAAA,iCAAiC,CAAC;QAChF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,QAAA,+BAA+B,CAAC;QAC1E,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAe,E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dkMcpServer, tool } from './mcp';
24
24
  export type { SdkMcpServerOptions, SdkMcpServerResult, SdkMcpToolDefinition, AnyZodRawShape, InferShape, ToolHandler, } from './mcp';
25
25
  export { HOOK_EVENTS, EXIT_REASONS } from './types';
26
26
  export { AbortError, CLIStartupError, ExecutionError } from './errors';
27
+ export { RemoteProtocolError, } from './remote-error-codes';
28
+ export type { RemoteErrorCode } from './remote-error-codes';
27
29
  export { installMarketplace, removeMarketplace, installPlugin, enablePlugin, disablePlugin, } from './plugin';
28
30
  export type { InstallMarketplaceOptions, RemoveMarketplaceOptions, InstallPluginOptions, SettingsOperationResult, } from './plugin';
29
- export type { Options, SessionOptions } from './types';
31
+ export { InMemorySessionStore } from './in-memory-session-store';
32
+ export { canonicalizeSessionStoreItem, digestSessionStoreItem, normalizeSessionStoreEvents, sessionStoreProtocolError, SessionStoreProtocolError, toSessionStoreWireItem, } from './session-store-protocol';
33
+ export type { NormalizedSessionStoreEvent, SessionStoreErrorCode } from './session-store-protocol';
34
+ export type { SessionKey, SessionStore, SessionStoreEntry, SessionStoreEvent, SessionStoreCapability, SessionStoreInitializeResult, SessionStoreMirrorNotificationData, MirrorErrorMessage, } from './types';
35
+ export type { Options, RemoteOperationContext, SessionOptions, } from './types';
36
+ export type { FileSystemHandler, FileSystemHandlerOptions, FileSystemModuleName, FileSystemOptions, FsPathInfo, } from './types';
37
+ export type { ChannelHandler, ChannelOptions, ChannelOpenConfig, ChannelEvent } from './types';
38
+ export type { ExecRunHandler, ExecRunHandlerRequest, ExecOptions, ExecPathInfo, ExecRequestContext, ExecRunArgs, ExecRunResult, ExecExitReason, ExecErrorCode, ExecUnsupportedFeature, } from './types';
39
+ export type { LocalExecutionModuleName, LocalExecutionDeny } from './types';
40
+ export { REMOTE_EXTENSION_HOOK_EVENTS } from './types';
41
+ export type { RemoteExtensionScope, RemoteExtensionErrorCode, JsonValue, RemoteResourceMetadata, RemoteHookMetadata, RemoteExtensionComponentMetadata, RemoteSkillMetadata, RemoteCommandMetadata, RemoteAgentMetadata, RemoteOutputStyleMetadata, RemotePluginMetadata, RemoteExtensionMetadata, RemoteExtensionContent, ExtensionResourceContent, RemoteHookEvent, RemoteHookInput, RemoteHookRawResult, RemoteExtensionHandler, RemoteExtensionsOptions, } from './types';
30
42
  export type { PermissionMode, PermissionBehavior, PermissionResult, PermissionUpdate, CanUseTool, CanUseToolOptions, } from './types';
31
43
  export type { ElicitationHandler, ElicitationCreateRequest, ElicitationCreateResponse, ElicitationCompleteNotification, } from './types';
32
44
  export type { HookEvent, HookCallback, HookCallbackMatcher, HookInput, HookJSONOutput, SyncHookJSONOutput, AsyncHookJSONOutput, BaseHookInput, PreToolUseHookInput, PostToolUseHookInput, PostToolUseFailureHookInput, NotificationHookInput, UserPromptSubmitHookInput, SessionStartHookInput, SessionEndHookInput, StopHookInput, SubagentStartHookInput, SubagentStopHookInput, PreCompactHookInput, PermissionRequestHookInput, } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EACH,aAAa,IAAI,yBAAyB,EAC1C,aAAa,IAAI,yBAAyB,EAC1C,MAAM,IAAI,kBAAkB,GAC/B,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,YAAY,IAAI,wBAAwB,EAAE,MAAM,IAAI,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAChG,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAIlF,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AACjD,YAAY,EACR,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,WAAW,GACd,MAAM,OAA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AY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
package/lib/index.js CHANGED
@@ -17,7 +17,7 @@
17
17
  * ```
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.disablePlugin = exports.enablePlugin = exports.installPlugin = exports.removeMarketplace = exports.installMarketplace = exports.ExecutionError = exports.CLIStartupError = exports.AbortError = exports.EXIT_REASONS = exports.HOOK_EVENTS = exports.tool = exports.createSdkMcpServer = exports.unstable_v2_logout = exports.unstable_v2_authenticate = exports.unstable_v2_resumeSession = exports.unstable_v2_createSession = exports.Query = exports.query = void 0;
20
+ exports.REMOTE_EXTENSION_HOOK_EVENTS = exports.toSessionStoreWireItem = exports.SessionStoreProtocolError = exports.sessionStoreProtocolError = exports.normalizeSessionStoreEvents = exports.digestSessionStoreItem = exports.canonicalizeSessionStoreItem = exports.InMemorySessionStore = exports.disablePlugin = exports.enablePlugin = exports.installPlugin = exports.removeMarketplace = exports.installMarketplace = exports.RemoteProtocolError = exports.ExecutionError = exports.CLIStartupError = exports.AbortError = exports.EXIT_REASONS = exports.HOOK_EVENTS = exports.tool = exports.createSdkMcpServer = exports.unstable_v2_logout = exports.unstable_v2_authenticate = exports.unstable_v2_resumeSession = exports.unstable_v2_createSession = exports.Query = exports.query = void 0;
21
21
  // ============= Main API =============
22
22
  var query_1 = require("./query");
23
23
  Object.defineProperty(exports, "query", { enumerable: true, get: function () { return query_1.query; } });
@@ -45,6 +45,8 @@ var errors_1 = require("./errors");
45
45
  Object.defineProperty(exports, "AbortError", { enumerable: true, get: function () { return errors_1.AbortError; } });
46
46
  Object.defineProperty(exports, "CLIStartupError", { enumerable: true, get: function () { return errors_1.CLIStartupError; } });
47
47
  Object.defineProperty(exports, "ExecutionError", { enumerable: true, get: function () { return errors_1.ExecutionError; } });
48
+ var remote_error_codes_1 = require("./remote-error-codes");
49
+ Object.defineProperty(exports, "RemoteProtocolError", { enumerable: true, get: function () { return remote_error_codes_1.RemoteProtocolError; } });
48
50
  // ============= Plugin API =============
49
51
  var plugin_1 = require("./plugin");
50
52
  Object.defineProperty(exports, "installMarketplace", { enumerable: true, get: function () { return plugin_1.installMarketplace; } });
@@ -52,4 +54,17 @@ Object.defineProperty(exports, "removeMarketplace", { enumerable: true, get: fun
52
54
  Object.defineProperty(exports, "installPlugin", { enumerable: true, get: function () { return plugin_1.installPlugin; } });
53
55
  Object.defineProperty(exports, "enablePlugin", { enumerable: true, get: function () { return plugin_1.enablePlugin; } });
54
56
  Object.defineProperty(exports, "disablePlugin", { enumerable: true, get: function () { return plugin_1.disablePlugin; } });
57
+ // ============= Session Store =============
58
+ var in_memory_session_store_1 = require("./in-memory-session-store");
59
+ Object.defineProperty(exports, "InMemorySessionStore", { enumerable: true, get: function () { return in_memory_session_store_1.InMemorySessionStore; } });
60
+ var session_store_protocol_1 = require("./session-store-protocol");
61
+ Object.defineProperty(exports, "canonicalizeSessionStoreItem", { enumerable: true, get: function () { return session_store_protocol_1.canonicalizeSessionStoreItem; } });
62
+ Object.defineProperty(exports, "digestSessionStoreItem", { enumerable: true, get: function () { return session_store_protocol_1.digestSessionStoreItem; } });
63
+ Object.defineProperty(exports, "normalizeSessionStoreEvents", { enumerable: true, get: function () { return session_store_protocol_1.normalizeSessionStoreEvents; } });
64
+ Object.defineProperty(exports, "sessionStoreProtocolError", { enumerable: true, get: function () { return session_store_protocol_1.sessionStoreProtocolError; } });
65
+ Object.defineProperty(exports, "SessionStoreProtocolError", { enumerable: true, get: function () { return session_store_protocol_1.SessionStoreProtocolError; } });
66
+ Object.defineProperty(exports, "toSessionStoreWireItem", { enumerable: true, get: function () { return session_store_protocol_1.toSessionStoreWireItem; } });
67
+ // Remote extensions
68
+ var types_2 = require("./types");
69
+ Object.defineProperty(exports, "REMOTE_EXTENSION_HOOK_EVENTS", { enumerable: true, get: function () { return types_2.REMOTE_EXTENSION_HOOK_EVENTS; } });
55
70
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAEH,uCAAuC;AAEvC,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AAEd,oBAAoB;AACpB,qCAImB;AAHf,oHAAA,aAAa,OAA6B;AAC1C,oHAAA,aAAa,OAA6B;AAC1C,6GAAA,MAAM,OAAsB;AAGhC,gCAAgC;AAChC,+BAAgG;AAAvF,gHAAA,YAAY,OAA4B;AAAE,0GAAA,MAAM,OAAsB;AAG/E,6CAA6C;AAE7C,6BAAiD;AAAxC,yGAAA,kBAAkB,OAAA;AAAE,2FAAA,IAAI,OAAA;AAUjC,wCAAwC;AAExC,iCAAoD;AAA3C,oGAAA,WAAW,OAAA;AAAE,qGAAA,YAAY,OAAA;AAElC,qCAAqC;AAErC,mCAAuE;AAA9D,oGAAA,UAAU,OAAA;AAAE,yGAAA,eAAe,OAAA;AAAE,wGAAA,cAAc,OAAA;AAEpD,yCAAyC;AAEzC,mCAMkB;AALd,4GAAA,kBAAkB,OAAA;AAClB,2GAAA,iBAAiB,OAAA;AACjB,uGAAA,aAAa,OAAA;AACb,sGAAA,YAAY,OAAA;AACZ,uGAAA,aAAa,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAEH,uCAAuC;AAEvC,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AAEd,oBAAoB;AACpB,qCAImB;AAHf,oHAAA,aAAa,OAA6B;AAC1C,oHAAA,aAAa,OAA6B;AAC1C,6GAAA,MAAM,OAAsB;AAGhC,gCAAgC;AAChC,+BAAgG;AAAvF,gHAAA,YAAY,OAA4B;AAAE,0GAAA,MAAM,OAAsB;AAG/E,6CAA6C;AAE7C,6BAAiD;AAAxC,yGAAA,kBAAkB,OAAA;AAAE,2FAAA,IAAI,OAAA;AAUjC,wCAAwC;AAExC,iCAAoD;AAA3C,oGAAA,WAAW,OAAA;AAAE,qGAAA,YAAY,OAAA;AAElC,qCAAqC;AAErC,mCAAuE;AAA9D,oGAAA,UAAU,OAAA;AAAE,yGAAA,eAAe,OAAA;AAAE,wGAAA,cAAc,OAAA;AACpD,2DAE8B;AAD1B,yHAAA,mBAAmB,OAAA;AAIvB,yCAAyC;AAEzC,mCAMkB;AALd,4GAAA,kBAAkB,OAAA;AAClB,2GAAA,iBAAiB,OAAA;AACjB,uGAAA,aAAa,OAAA;AACb,sGAAA,YAAY,OAAA;AACZ,uGAAA,aAAa,OAAA;AAUjB,4CAA4C;AAE5C,qEAAiE;AAAxD,+HAAA,oBAAoB,OAAA;AAC7B,mEAOkC;AAN9B,sIAAA,4BAA4B,OAAA;AAC5B,gIAAA,sBAAsB,OAAA;AACtB,qIAAA,2BAA2B,OAAA;AAC3B,mIAAA,yBAAyB,OAAA;AACzB,mIAAA,yBAAyB,OAAA;AACzB,gIAAA,sBAAsB,OAAA;AA6C1B,oBAAoB;AACpB,iCAAuD;AAA9C,qHAAA,4BAA4B,OAAA"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 委托响应策略化脱敏
3
+ *
4
+ * 宿主在把 tools/list response 与 tools/call result 传回 CLI 之前,必须先做脱敏。
5
+ * 这里提供两类能力:
6
+ * 1. redactDelegatedResponse:对 result 值做递归字段名脱敏 + URL 凭证脱敏;
7
+ * 2. screenToolListForSecretParams:对 tools/list 的 schema 做 fail-closed 筛查,
8
+ * 只拒绝含凭证形参的整个 tool,绝不改写 schema 结构。
9
+ */
10
+ import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
11
+ export type ConnectorRedactionHook = (message: JSONRPCMessage) => JSONRPCMessage;
12
+ export interface DelegatedRedactionOptions {
13
+ connectorHooks?: ConnectorRedactionHook[];
14
+ }
15
+ export interface ToolListScreenResult {
16
+ message: JSONRPCMessage;
17
+ rejected: Array<{
18
+ tool: string;
19
+ param: string;
20
+ }>;
21
+ }
22
+ export declare function sanitizeDelegatedErrorData(value: unknown): Record<string, unknown> | undefined;
23
+ /**
24
+ * 对委托响应的 result / error 做策略化脱敏。
25
+ *
26
+ * result 递归脱敏;error 仅保留数值 code 和安全分类字段,不透传不可信文本。
27
+ * notification 原样返回。不修改入参,返回新对象。schema 结构不在这里处理,见
28
+ * screenToolListForSecretParams。
29
+ */
30
+ export declare function redactDelegatedResponse(message: JSONRPCMessage, options?: DelegatedRedactionOptions): JSONRPCMessage;
31
+ /**
32
+ * 对 tools/list response 做 schema fail-closed 筛查。
33
+ *
34
+ * 递归遍历每个 tool 的 inputSchema / outputSchema(含嵌套 properties / items / oneOf /
35
+ * anyOf / allOf / prefixItems),若任一层出现凭证形参名,或某个 property 的 default 是
36
+ * token 形态字符串,则整个 tool 被拒绝(从 tools 数组移除)并记入 rejected 供审计。绝不
37
+ * 打码字段、绝不删 schema node —— 只做整 tool 拒绝。非 tools/list 结构原样返回。
38
+ */
39
+ export declare function screenToolListForSecretParams(message: JSONRPCMessage): ToolListScreenResult;
40
+ /**
41
+ * 组合脱敏:先做 schema fail-close 筛查(移除含凭证形参的 tool),再对筛查后的 message
42
+ * 做值级脱敏。顺序不可换 —— 先剔除 secret-schema tool,再脱敏残留值。
43
+ * 非 tools/list 的 message 在筛查阶段是透传,因此对所有响应都安全。
44
+ * rejected 一并返回供调用方审计,本函数自身不抛异常。
45
+ */
46
+ export declare function redactAndScreenDelegatedResponse(message: JSONRPCMessage, options?: DelegatedRedactionOptions): ToolListScreenResult;
47
+ //# sourceMappingURL=delegated-redaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegated-redaction.d.ts","sourceRoot":"","sources":["../../src/mcp/delegated-redaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAuEzE,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,cAAc,KAAK,cAAc,CAAC;AAEjF,MAAM,WAAW,yBAAyB;IACtC,cAAc,CAAC,EAAE,sBAAsB,EAAE,CAAC;CAC7C;AAED,MAAM,WAAW,oBAAoB;IACjC,OAAO,EAAE,cAAc,CAAC;IACxB,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpD;AAuGD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CA6B9F;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,yBAAyB,GACpC,cAAc,CAkChB;AA4ED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,cAAc,GAAG,oBAAoB,CAgC3F;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC5C,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,yBAAyB,GACpC,oBAAoB,CAGtB"}
@@ -0,0 +1,362 @@
1
+ "use strict";
2
+ /**
3
+ * 委托响应策略化脱敏
4
+ *
5
+ * 宿主在把 tools/list response 与 tools/call result 传回 CLI 之前,必须先做脱敏。
6
+ * 这里提供两类能力:
7
+ * 1. redactDelegatedResponse:对 result 值做递归字段名脱敏 + URL 凭证脱敏;
8
+ * 2. screenToolListForSecretParams:对 tools/list 的 schema 做 fail-closed 筛查,
9
+ * 只拒绝含凭证形参的整个 tool,绝不改写 schema 结构。
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.sanitizeDelegatedErrorData = sanitizeDelegatedErrorData;
13
+ exports.redactDelegatedResponse = redactDelegatedResponse;
14
+ exports.screenToolListForSecretParams = screenToolListForSecretParams;
15
+ exports.redactAndScreenDelegatedResponse = redactAndScreenDelegatedResponse;
16
+ // 脱敏后的占位串
17
+ const MASK = '[REDACTED]';
18
+ // 需要脱敏的字段名清单,已按归一化形式(小写 + 去 _ / -)存放。
19
+ // 归一化后 camelCase / snake_case / kebab-case / SCREAMING_SNAKE 变体都会命中同一项。
20
+ const SECRET_KEYS_NORMALIZED = new Set([
21
+ 'authorization',
22
+ 'cookie',
23
+ 'setcookie',
24
+ 'wwwauthenticate',
25
+ 'token',
26
+ 'accesstoken',
27
+ 'refreshtoken',
28
+ 'clientsecret',
29
+ 'apikey',
30
+ 'privatekey',
31
+ 'secret',
32
+ 'password',
33
+ 'passwd',
34
+ 'pwd',
35
+ ]);
36
+ // schema 中视为凭证形参的名字,同样以归一化形式存放。
37
+ const SECRET_PARAM_NAMES_NORMALIZED = new Set([
38
+ 'password',
39
+ 'token',
40
+ 'secret',
41
+ 'apikey',
42
+ 'clientsecret',
43
+ 'privatekey',
44
+ 'refreshtoken',
45
+ ]);
46
+ // 凭证字段名词根(子串匹配):用于命中 sessionToken / authToken / userPassword / githubToken /
47
+ // xApiKey / bearerToken 等复合名,弥补精确集只能命中完整名的漏洞。
48
+ // 不含裸 key,避免误伤 publicKey / keyName / keyboard;apikey / accesskey / privatekey 覆盖 key 场景。
49
+ // 注意:子串匹配是安全 denylist,方向是宁可多脱敏也不漏(如 tokenizer 含 token 会被脱敏),
50
+ // 这是可接受的 false-positive,不做白名单例外。
51
+ const SECRET_KEY_STEMS = [
52
+ 'token',
53
+ 'secret',
54
+ 'password',
55
+ 'passwd',
56
+ 'apikey',
57
+ 'authorization',
58
+ 'cookie',
59
+ 'credential',
60
+ 'privatekey',
61
+ 'accesskey',
62
+ ];
63
+ // 递归深度上限:防止恶意 / 异常的深嵌套上游输入导致栈溢出。
64
+ const MAX_REDACT_DEPTH = 64;
65
+ const SAFE_ERROR_CODES = new Set([
66
+ 'MCP_NOT_ALLOWED',
67
+ 'MCP_AUTH_REQUIRED',
68
+ 'MCP_AUTH_FAILED',
69
+ 'MCP_UPSTREAM_UNAVAILABLE',
70
+ 'MCP_TIMEOUT',
71
+ 'MCP_CANCELLED',
72
+ 'MCP_MESSAGE_ERROR',
73
+ ]);
74
+ const SAFE_REQUIRED_ACTIONS = new Set(['authorize']);
75
+ // URL query 中需要移除的凭证参数名(小写比较)。
76
+ const SECRET_QUERY_PARAMS = new Set(['token', 'access_token', 'api_key', 'code', 'state', 'session']);
77
+ // 归一化 key:小写并去掉下划线 / 短横线,使各种命名风格收敛到同一形式。
78
+ function normalizeKey(key) {
79
+ return key.toLowerCase().replace(/[_-]/g, '');
80
+ }
81
+ // 归一化后的 key 是否命中任一词根(子串匹配)。
82
+ function matchesSecretStem(normalized) {
83
+ return SECRET_KEY_STEMS.some(stem => normalized.includes(stem));
84
+ }
85
+ // 两级判定:归一化 key 属于精确敏感集,或包含任一词根。
86
+ function isSecretFieldName(key) {
87
+ const normalized = normalizeKey(key);
88
+ return SECRET_KEYS_NORMALIZED.has(normalized) || matchesSecretStem(normalized);
89
+ }
90
+ // 两级判定:归一化 param 名属于精确凭证形参集,或包含任一词根。
91
+ function isSecretParamName(param) {
92
+ const normalized = normalizeKey(param);
93
+ return SECRET_PARAM_NAMES_NORMALIZED.has(normalized) || matchesSecretStem(normalized);
94
+ }
95
+ // 判断字符串是否为带 scheme 的 URL(形如 xxx://...),避免把 c:\path、a:b 之类误判为 URL。
96
+ function looksLikeUrl(value) {
97
+ return /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(value);
98
+ }
99
+ // 对 URL 字符串剥离 user:pass@ 并移除凭证 query 参数,保留 scheme + host + path。
100
+ function redactUrlString(value) {
101
+ if (!looksLikeUrl(value)) {
102
+ return value;
103
+ }
104
+ let url;
105
+ try {
106
+ url = new URL(value);
107
+ }
108
+ catch {
109
+ return value;
110
+ }
111
+ url.username = '';
112
+ url.password = '';
113
+ for (const name of [...url.searchParams.keys()]) {
114
+ if (SECRET_QUERY_PARAMS.has(name.toLowerCase())) {
115
+ url.searchParams.delete(name);
116
+ }
117
+ }
118
+ return url.toString();
119
+ }
120
+ // 递归脱敏:命中敏感字段名直接替换为 MASK,其余对象/数组继续深入,字符串走 URL 脱敏。
121
+ // depth 达到上限时屏蔽整棵剩余子树,避免深嵌套输入绕过检查。
122
+ //
123
+ // 判定 value 是否为 JSON Schema 节点:必须同时有 `type`(字符串)与 `properties` / `items` /
124
+ // `oneOf` / `anyOf` / `allOf` / `prefixItems` 之一。仅 `type` 不够(MCP `content[].type='text'`
125
+ // 不是 schema),仅 `properties` 也不够(业务对象可能用 `properties` 作普通字段名)。
126
+ function isSchemaLike(value) {
127
+ if (!value || typeof value !== 'object') {
128
+ return false;
129
+ }
130
+ const v = value;
131
+ const hasType = typeof v.type === 'string';
132
+ const hasStruct = 'properties' in v || 'items' in v
133
+ || 'oneOf' in v || 'anyOf' in v || 'allOf' in v || 'prefixItems' in v;
134
+ return hasType && hasStruct;
135
+ }
136
+ function redactValue(value, depth = 0) {
137
+ if (depth >= MAX_REDACT_DEPTH) {
138
+ return MASK;
139
+ }
140
+ if (typeof value === 'string') {
141
+ return redactUrlString(value);
142
+ }
143
+ if (Array.isArray(value)) {
144
+ return value.map(item => redactValue(item, depth + 1));
145
+ }
146
+ if (value && typeof value === 'object') {
147
+ const source = value;
148
+ const schemaMode = isSchemaLike(source);
149
+ const out = {};
150
+ for (const [key, child] of Object.entries(source)) {
151
+ if (schemaMode && key === 'properties' && child && typeof child === 'object') {
152
+ // schema 形参名键不脱敏:形参名由 screenToolListForSecretParams fail-closed 把关,
153
+ // 这里若再脱敏会把 schema 节点改坏成 [REDACTED](设计明令禁止改写 schema 结构)。
154
+ // 仅递归处理每个 param 的 def(含 default 兜底等)。
155
+ const props = child;
156
+ const safeProps = {};
157
+ for (const [param, def] of Object.entries(props)) {
158
+ safeProps[param] = redactValue(def, depth + 1);
159
+ }
160
+ out[key] = safeProps;
161
+ }
162
+ else if (!schemaMode && isSecretFieldName(key)) {
163
+ out[key] = MASK;
164
+ }
165
+ else {
166
+ out[key] = redactValue(child, depth + 1);
167
+ }
168
+ }
169
+ return out;
170
+ }
171
+ return value;
172
+ }
173
+ function sanitizeDelegatedErrorData(value) {
174
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
175
+ return undefined;
176
+ }
177
+ const source = value;
178
+ const safe = {};
179
+ if (typeof source.code === 'string' && SAFE_ERROR_CODES.has(source.code)) {
180
+ safe.code = source.code;
181
+ }
182
+ if (typeof source.serverName === 'string'
183
+ && /^[A-Za-z0-9_-]{1,63}$/.test(source.serverName)
184
+ && !looksLikeToken(source.serverName)) {
185
+ safe.serverName = source.serverName;
186
+ }
187
+ if (typeof source.capabilityId === 'string'
188
+ && source.capabilityId.length <= 256
189
+ && /^[A-Za-z0-9][A-Za-z0-9._:/-]*$/.test(source.capabilityId)
190
+ && !looksLikeToken(source.capabilityId)) {
191
+ safe.capabilityId = source.capabilityId;
192
+ }
193
+ if (Array.isArray(source.requiredActions)) {
194
+ const requiredActions = source.requiredActions.filter((action) => typeof action === 'string' && SAFE_REQUIRED_ACTIONS.has(action));
195
+ if (requiredActions.length > 0) {
196
+ safe.requiredActions = requiredActions;
197
+ }
198
+ }
199
+ return Object.keys(safe).length > 0 ? safe : undefined;
200
+ }
201
+ /**
202
+ * 对委托响应的 result / error 做策略化脱敏。
203
+ *
204
+ * result 递归脱敏;error 仅保留数值 code 和安全分类字段,不透传不可信文本。
205
+ * notification 原样返回。不修改入参,返回新对象。schema 结构不在这里处理,见
206
+ * screenToolListForSecretParams。
207
+ */
208
+ function redactDelegatedResponse(message, options) {
209
+ if (!message || typeof message !== 'object') {
210
+ return message;
211
+ }
212
+ let cloned;
213
+ if ('result' in message) {
214
+ cloned = {
215
+ ...message,
216
+ result: redactValue(message.result),
217
+ };
218
+ }
219
+ else if ('error' in message) {
220
+ const sourceError = message.error;
221
+ const error = sourceError && typeof sourceError === 'object'
222
+ ? sourceError
223
+ : {};
224
+ const data = sanitizeDelegatedErrorData(error.data);
225
+ cloned = {
226
+ ...message,
227
+ error: {
228
+ code: typeof error.code === 'number' ? error.code : -32603,
229
+ message: 'Delegated MCP request failed',
230
+ ...(data ? { data } : {}),
231
+ },
232
+ };
233
+ }
234
+ else {
235
+ return message;
236
+ }
237
+ let result = cloned;
238
+ for (const hook of options?.connectorHooks ?? []) {
239
+ result = hook(result);
240
+ }
241
+ return result;
242
+ }
243
+ // 判断 default 值是否像凭证 token:常见前缀,或较长且仅由 token 字符集组成。
244
+ function looksLikeToken(value) {
245
+ if (typeof value !== 'string') {
246
+ return false;
247
+ }
248
+ if (/^(gh[pousr]_|sk-|xox[baprs]-|Bearer\s+)/i.test(value)) {
249
+ return true;
250
+ }
251
+ return value.length >= 20 && /^[A-Za-z0-9._+/=-]+$/.test(value);
252
+ }
253
+ // 检查 schema 的 properties,递归下探嵌套形参:
254
+ // - 顶层 properties 的每个 param 名直接判 secret;
255
+ // - 形参 def 自身若也是 schema(含 properties/items/oneOf/anyOf/allOf/prefixItems),
256
+ // 继续递归,捕获 `config.apiKey` 这类嵌套 secret 形参;
257
+ // - default 值若是 token 形态字符串,同样视为 secret 形参(兜底)。
258
+ // 深度上限避免恶意 / 异常深嵌套 schema 栈溢出。
259
+ const MAX_SCHEMA_DEPTH = 32;
260
+ function findSecretParam(schema, depth = 0) {
261
+ if (!schema || typeof schema !== 'object' || depth >= MAX_SCHEMA_DEPTH) {
262
+ return undefined;
263
+ }
264
+ const node = schema;
265
+ const properties = node.properties;
266
+ if (properties && typeof properties === 'object') {
267
+ for (const [param, def] of Object.entries(properties)) {
268
+ if (isSecretParamName(param)) {
269
+ return param;
270
+ }
271
+ if (def && typeof def === 'object') {
272
+ const defNode = def;
273
+ if (looksLikeToken(defNode.default)) {
274
+ return param;
275
+ }
276
+ // 嵌套 schema:递归查 sub-properties / items / oneOf / anyOf / allOf / prefixItems
277
+ const nested = findSecretParam(defNode, depth + 1);
278
+ if (nested) {
279
+ return nested;
280
+ }
281
+ }
282
+ }
283
+ }
284
+ // 复合 schema 关键字:每个分支都是子 schema,递归判定
285
+ for (const key of ['items', 'prefixItems']) {
286
+ const child = node[key];
287
+ if (Array.isArray(child)) {
288
+ for (const item of child) {
289
+ const hit = findSecretParam(item, depth + 1);
290
+ if (hit) {
291
+ return hit;
292
+ }
293
+ }
294
+ }
295
+ else if (child && typeof child === 'object') {
296
+ const hit = findSecretParam(child, depth + 1);
297
+ if (hit) {
298
+ return hit;
299
+ }
300
+ }
301
+ }
302
+ for (const key of ['oneOf', 'anyOf', 'allOf']) {
303
+ const child = node[key];
304
+ if (Array.isArray(child)) {
305
+ for (const item of child) {
306
+ const hit = findSecretParam(item, depth + 1);
307
+ if (hit) {
308
+ return hit;
309
+ }
310
+ }
311
+ }
312
+ }
313
+ return undefined;
314
+ }
315
+ /**
316
+ * 对 tools/list response 做 schema fail-closed 筛查。
317
+ *
318
+ * 递归遍历每个 tool 的 inputSchema / outputSchema(含嵌套 properties / items / oneOf /
319
+ * anyOf / allOf / prefixItems),若任一层出现凭证形参名,或某个 property 的 default 是
320
+ * token 形态字符串,则整个 tool 被拒绝(从 tools 数组移除)并记入 rejected 供审计。绝不
321
+ * 打码字段、绝不删 schema node —— 只做整 tool 拒绝。非 tools/list 结构原样返回。
322
+ */
323
+ function screenToolListForSecretParams(message) {
324
+ const rejected = [];
325
+ const result = message.result;
326
+ const tools = result?.tools;
327
+ if (!Array.isArray(tools)) {
328
+ return { message, rejected };
329
+ }
330
+ const kept = [];
331
+ for (const tool of tools) {
332
+ const name = tool?.name;
333
+ const toolName = typeof name === 'string' ? name : '';
334
+ const offending = findSecretParam(tool?.inputSchema) ??
335
+ findSecretParam(tool?.outputSchema);
336
+ if (offending) {
337
+ rejected.push({ tool: toolName, param: offending });
338
+ }
339
+ else {
340
+ kept.push(tool);
341
+ }
342
+ }
343
+ if (rejected.length === 0) {
344
+ return { message, rejected };
345
+ }
346
+ const screened = {
347
+ ...message,
348
+ result: { ...result, tools: kept },
349
+ };
350
+ return { message: screened, rejected };
351
+ }
352
+ /**
353
+ * 组合脱敏:先做 schema fail-close 筛查(移除含凭证形参的 tool),再对筛查后的 message
354
+ * 做值级脱敏。顺序不可换 —— 先剔除 secret-schema tool,再脱敏残留值。
355
+ * 非 tools/list 的 message 在筛查阶段是透传,因此对所有响应都安全。
356
+ * rejected 一并返回供调用方审计,本函数自身不抛异常。
357
+ */
358
+ function redactAndScreenDelegatedResponse(message, options) {
359
+ const { message: screened, rejected } = screenToolListForSecretParams(message);
360
+ return { message: redactDelegatedResponse(screened, options), rejected };
361
+ }
362
+ //# sourceMappingURL=delegated-redaction.js.map