@agent-vm/mcp-portal 0.0.68 → 0.0.70
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 +42 -11
- package/dist/agent-bearer-token-DCtpDPCZ.js +59 -0
- package/dist/agent-bearer-token-DCtpDPCZ.js.map +1 -0
- package/dist/bin/mcp-portal.d.ts +28 -0
- package/dist/bin/mcp-portal.d.ts.map +1 -0
- package/dist/bin/mcp-portal.js +318 -0
- package/dist/bin/mcp-portal.js.map +1 -0
- package/dist/{catalog-types--gUGFPpN.d.ts → catalog-types-BVuB4Ynx.d.ts} +1 -1
- package/dist/{catalog-types--gUGFPpN.d.ts.map → catalog-types-BVuB4Ynx.d.ts.map} +1 -1
- package/dist/cli/index.d.ts +101 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +2 -0
- package/dist/core/index.d.ts +40 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/hmac-env-B4shpRRB.js +20 -0
- package/dist/hmac-env-B4shpRRB.js.map +1 -0
- package/dist/hmac-token-DBqWY3-w.js +100 -0
- package/dist/hmac-token-DBqWY3-w.js.map +1 -0
- package/dist/index.d.ts +5 -485
- package/dist/index.js +4 -5
- package/dist/mcp-proxy/index.d.ts +24 -0
- package/dist/mcp-proxy/index.d.ts.map +1 -0
- package/dist/mcp-proxy/index.js +2 -0
- package/dist/portal-auth/agent-bearer-token.d.ts +22 -0
- package/dist/portal-auth/agent-bearer-token.d.ts.map +1 -0
- package/dist/portal-auth/agent-bearer-token.js +2 -0
- package/dist/portal-auth/hmac-env.d.ts +6 -0
- package/dist/portal-auth/hmac-env.d.ts.map +1 -0
- package/dist/portal-auth/hmac-env.js +2 -0
- package/dist/portal-auth/hmac-token.d.ts +40 -0
- package/dist/portal-auth/hmac-token.d.ts.map +1 -0
- package/dist/portal-auth/hmac-token.js +2 -0
- package/dist/portal-config/index.d.ts +11 -0
- package/dist/portal-config/index.d.ts.map +1 -0
- package/dist/{tool-vm → portal-config}/index.js +2 -3
- package/dist/portal-core-CZQI7Ob6.d.ts +264 -0
- package/dist/portal-core-CZQI7Ob6.d.ts.map +1 -0
- package/dist/portal-core-Cgu714CL.js +416 -0
- package/dist/portal-core-Cgu714CL.js.map +1 -0
- package/dist/portal-session-DG2CUjIo.d.ts +184 -0
- package/dist/portal-session-DG2CUjIo.d.ts.map +1 -0
- package/dist/portal-tools-DKci1szO.js +528 -0
- package/dist/portal-tools-DKci1szO.js.map +1 -0
- package/dist/resolve-agent-identity-DnC_Pmnh.js +550 -0
- package/dist/resolve-agent-identity-DnC_Pmnh.js.map +1 -0
- package/dist/resolve-agent-identity-FQL02YdW.d.ts +81 -0
- package/dist/resolve-agent-identity-FQL02YdW.d.ts.map +1 -0
- package/dist/serve-command-CnSMUybd.js +358 -0
- package/dist/serve-command-CnSMUybd.js.map +1 -0
- package/dist/testing/fake-upstream-mcp-server.d.ts +5 -2
- package/dist/testing/fake-upstream-mcp-server.d.ts.map +1 -1
- package/dist/testing/fake-upstream-mcp-server.js +14 -4
- package/dist/testing/fake-upstream-mcp-server.js.map +1 -1
- package/dist/typescript-artifact-BVLt3Ifd.js +60 -0
- package/dist/typescript-artifact-BVLt3Ifd.js.map +1 -0
- package/dist/upstream-mcp-client-runtime-JlsfTm7_.js +760 -0
- package/dist/upstream-mcp-client-runtime-JlsfTm7_.js.map +1 -0
- package/dist/upstream-response-middleware-1MZnAD9C.d.ts +115 -0
- package/dist/upstream-response-middleware-1MZnAD9C.d.ts.map +1 -0
- package/dist/upstream-response-middleware-BjUWZ2G8.js +172 -0
- package/dist/upstream-response-middleware-BjUWZ2G8.js.map +1 -0
- package/dist/{index-BcI9c8sg.d.ts → zod-schema-loader-DLGQpYFD.d.ts} +3 -9
- package/dist/zod-schema-loader-DLGQpYFD.d.ts.map +1 -0
- package/dist/{typescript-artifact-BqU8okQy.js → zod-schema-loader-yNekKNpm.js} +85 -55
- package/dist/zod-schema-loader-yNekKNpm.js.map +1 -0
- package/package.json +30 -13
- package/dist/bin/agent-vm-mcp-portal.d.ts +0 -10
- package/dist/bin/agent-vm-mcp-portal.d.ts.map +0 -1
- package/dist/bin/agent-vm-mcp-portal.js +0 -56
- package/dist/bin/agent-vm-mcp-portal.js.map +0 -1
- package/dist/bin/portal-server.d.ts +0 -55
- package/dist/bin/portal-server.d.ts.map +0 -1
- package/dist/bin/portal-server.js +0 -289
- package/dist/bin/portal-server.js.map +0 -1
- package/dist/index-BcI9c8sg.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/tool-vm/index.d.ts +0 -2
- package/dist/tool-vm-ihnzDyjJ.js +0 -3
- package/dist/typescript-artifact-BqU8okQy.js.map +0 -1
- package/dist/upstream-mcp-client-runtime-DiBCBsDj.js +0 -1729
- package/dist/upstream-mcp-client-runtime-DiBCBsDj.js.map +0 -1
- package/dist/zod-schema-loader-CDDtoRE1.js +0 -90
- package/dist/zod-schema-loader-CDDtoRE1.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { t as
|
|
3
|
-
import "../tool-vm-ihnzDyjJ.js";
|
|
1
|
+
import { t as buildZodValidatorFromJsonSchema } from "../zod-schema-loader-yNekKNpm.js";
|
|
2
|
+
import { t as generateTypescriptCatalogArtifact } from "../typescript-artifact-BVLt3Ifd.js";
|
|
4
3
|
export { buildZodValidatorFromJsonSchema, generateTypescriptCatalogArtifact };
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { n as PortalToolRecord, s as JsonObject } from "./catalog-types-BVuB4Ynx.js";
|
|
2
|
+
import { M as PortalAgentIdentity, N as PortalAgentScopeSource, b as SkillGraphInput, j as PortalAccessPolicyConfig, o as PortalSessionRuntime, r as PortalSession } from "./portal-session-DG2CUjIo.js";
|
|
3
|
+
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
|
|
5
|
+
//#region src/core/portal-tools.d.ts
|
|
6
|
+
interface PortalToolSuccess {
|
|
7
|
+
readonly input: Readonly<Record<string, unknown>>;
|
|
8
|
+
readonly ok: true;
|
|
9
|
+
readonly output: Readonly<Record<string, unknown>>;
|
|
10
|
+
}
|
|
11
|
+
interface PortalToolFailure {
|
|
12
|
+
readonly error: unknown;
|
|
13
|
+
readonly input: Readonly<Record<string, unknown>>;
|
|
14
|
+
readonly ok: false;
|
|
15
|
+
}
|
|
16
|
+
type PortalToolResult = PortalToolFailure | PortalToolSuccess;
|
|
17
|
+
type PortalToolResultMap = Readonly<Record<string, PortalToolResult>>;
|
|
18
|
+
interface PortalBatchError {
|
|
19
|
+
readonly id?: string;
|
|
20
|
+
readonly kind: string;
|
|
21
|
+
readonly message: string;
|
|
22
|
+
}
|
|
23
|
+
interface PortalBatchDiagnostic {
|
|
24
|
+
readonly kind: string;
|
|
25
|
+
readonly message: string;
|
|
26
|
+
readonly namespace?: string;
|
|
27
|
+
}
|
|
28
|
+
interface PortalBatchResult {
|
|
29
|
+
readonly diagnostics: readonly PortalBatchDiagnostic[];
|
|
30
|
+
readonly errors: readonly PortalBatchError[];
|
|
31
|
+
readonly ok: boolean;
|
|
32
|
+
readonly results: PortalToolResultMap;
|
|
33
|
+
}
|
|
34
|
+
interface PortalApprovalCall {
|
|
35
|
+
readonly arguments: JsonObject;
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly namespace: string;
|
|
38
|
+
readonly tool: PortalToolRecord;
|
|
39
|
+
readonly toolName: string;
|
|
40
|
+
}
|
|
41
|
+
declare const portalToolInputSchemas: {
|
|
42
|
+
readonly mcp_portal_call: {
|
|
43
|
+
[x: string]: unknown;
|
|
44
|
+
type: "object";
|
|
45
|
+
properties?: {
|
|
46
|
+
[x: string]: object;
|
|
47
|
+
} | undefined;
|
|
48
|
+
required?: string[] | undefined;
|
|
49
|
+
};
|
|
50
|
+
readonly mcp_portal_describe: {
|
|
51
|
+
[x: string]: unknown;
|
|
52
|
+
type: "object";
|
|
53
|
+
properties?: {
|
|
54
|
+
[x: string]: object;
|
|
55
|
+
} | undefined;
|
|
56
|
+
required?: string[] | undefined;
|
|
57
|
+
};
|
|
58
|
+
readonly mcp_portal_list: {
|
|
59
|
+
[x: string]: unknown;
|
|
60
|
+
type: "object";
|
|
61
|
+
properties?: {
|
|
62
|
+
[x: string]: object;
|
|
63
|
+
} | undefined;
|
|
64
|
+
required?: string[] | undefined;
|
|
65
|
+
};
|
|
66
|
+
readonly mcp_portal_search: {
|
|
67
|
+
[x: string]: unknown;
|
|
68
|
+
type: "object";
|
|
69
|
+
properties?: {
|
|
70
|
+
[x: string]: object;
|
|
71
|
+
} | undefined;
|
|
72
|
+
required?: string[] | undefined;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
interface PortalToolHandlerCall {
|
|
76
|
+
readonly identity: PortalAgentIdentity;
|
|
77
|
+
readonly input: unknown;
|
|
78
|
+
}
|
|
79
|
+
interface PortalCallUpstreamTool {
|
|
80
|
+
readonly arguments: JsonObject;
|
|
81
|
+
readonly agentScopeId: string;
|
|
82
|
+
readonly namespace: string;
|
|
83
|
+
readonly onEvent?: (event: PortalUpstreamEvent) => Promise<void> | void;
|
|
84
|
+
readonly requestId: string;
|
|
85
|
+
readonly signal?: AbortSignal;
|
|
86
|
+
readonly toolName: string;
|
|
87
|
+
}
|
|
88
|
+
type PortalUpstreamEvent = {
|
|
89
|
+
readonly kind: 'progress';
|
|
90
|
+
readonly message?: string;
|
|
91
|
+
readonly progress?: number;
|
|
92
|
+
readonly total?: number;
|
|
93
|
+
} | {
|
|
94
|
+
readonly kind: 'upstream_notification';
|
|
95
|
+
readonly method: string;
|
|
96
|
+
readonly params: unknown;
|
|
97
|
+
} | {
|
|
98
|
+
readonly content: {
|
|
99
|
+
readonly text: string;
|
|
100
|
+
readonly type: 'text';
|
|
101
|
+
} | {
|
|
102
|
+
readonly type: 'json';
|
|
103
|
+
readonly value: unknown;
|
|
104
|
+
};
|
|
105
|
+
readonly kind: 'partial_content';
|
|
106
|
+
};
|
|
107
|
+
interface PortalToolRuntime {
|
|
108
|
+
readonly approval?: (calls: readonly PortalApprovalCall[], identity: PortalAgentIdentity, approvalToken: string | undefined) => {
|
|
109
|
+
readonly kind: 'allow';
|
|
110
|
+
} | {
|
|
111
|
+
readonly kind: 'approval_token_invalid';
|
|
112
|
+
readonly reason: string;
|
|
113
|
+
} | {
|
|
114
|
+
readonly kind: 'approval_token_missing';
|
|
115
|
+
} | {
|
|
116
|
+
readonly kind: 'approval_required';
|
|
117
|
+
readonly level: 'critical' | 'standard';
|
|
118
|
+
};
|
|
119
|
+
readonly callUpstreamTool: (call: PortalCallUpstreamTool) => Promise<unknown>;
|
|
120
|
+
readonly getSession: (identity: PortalAgentIdentity) => Promise<PortalSession>;
|
|
121
|
+
}
|
|
122
|
+
interface PortalToolHandlers {
|
|
123
|
+
readonly call: (call: PortalToolHandlerCall) => Promise<PortalBatchResult>;
|
|
124
|
+
readonly describe: (call: PortalToolHandlerCall) => Promise<PortalBatchResult>;
|
|
125
|
+
readonly list: (call: PortalToolHandlerCall) => Promise<PortalBatchResult>;
|
|
126
|
+
readonly search: (call: PortalToolHandlerCall) => Promise<PortalBatchResult>;
|
|
127
|
+
}
|
|
128
|
+
declare function createPortalToolHandlers(runtime: PortalToolRuntime): PortalToolHandlers;
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/core/portal-core.d.ts
|
|
131
|
+
type PortalAgentScope = PortalAgentIdentity;
|
|
132
|
+
type PortalCoreToolName = 'mcp_portal_list' | 'mcp_portal_search' | 'mcp_portal_describe' | 'mcp_portal_call';
|
|
133
|
+
interface PortalAuditEvent {
|
|
134
|
+
readonly kind: string;
|
|
135
|
+
readonly message: string;
|
|
136
|
+
readonly namespace?: string;
|
|
137
|
+
}
|
|
138
|
+
interface PortalCoreResult {
|
|
139
|
+
readonly auditEvents?: readonly PortalAuditEvent[];
|
|
140
|
+
readonly content: readonly PortalCoreContentBlock[];
|
|
141
|
+
readonly items: readonly PortalCoreItemResult[];
|
|
142
|
+
readonly structuredContent?: unknown;
|
|
143
|
+
}
|
|
144
|
+
type PortalCoreItemResult = {
|
|
145
|
+
readonly content: readonly PortalCoreContentBlock[];
|
|
146
|
+
readonly requestId: string;
|
|
147
|
+
readonly status: 'success';
|
|
148
|
+
readonly structuredContent?: unknown;
|
|
149
|
+
} | {
|
|
150
|
+
readonly error: PortalCoreItemError;
|
|
151
|
+
readonly requestId: string;
|
|
152
|
+
readonly status: 'failed';
|
|
153
|
+
};
|
|
154
|
+
interface PortalCoreItemError {
|
|
155
|
+
readonly code: string;
|
|
156
|
+
readonly message: string;
|
|
157
|
+
readonly namespace?: string;
|
|
158
|
+
readonly toolName?: string;
|
|
159
|
+
}
|
|
160
|
+
type PortalCoreContentBlock = {
|
|
161
|
+
readonly text: string;
|
|
162
|
+
readonly type: 'text';
|
|
163
|
+
} | {
|
|
164
|
+
readonly type: 'json';
|
|
165
|
+
readonly value: unknown;
|
|
166
|
+
};
|
|
167
|
+
type PortalCoreEvent = {
|
|
168
|
+
readonly kind: 'started';
|
|
169
|
+
readonly toolName: PortalCoreToolName;
|
|
170
|
+
} | {
|
|
171
|
+
readonly kind: 'item_started';
|
|
172
|
+
readonly namespace?: string;
|
|
173
|
+
readonly requestId: string;
|
|
174
|
+
readonly toolName?: string;
|
|
175
|
+
} | {
|
|
176
|
+
readonly kind: 'progress';
|
|
177
|
+
readonly message?: string;
|
|
178
|
+
readonly progress?: number;
|
|
179
|
+
readonly requestId?: string;
|
|
180
|
+
readonly total?: number;
|
|
181
|
+
} | {
|
|
182
|
+
readonly kind: 'upstream_notification';
|
|
183
|
+
readonly method: string;
|
|
184
|
+
readonly params: unknown;
|
|
185
|
+
readonly requestId?: string;
|
|
186
|
+
} | {
|
|
187
|
+
readonly content: PortalCoreContentBlock;
|
|
188
|
+
readonly kind: 'partial_content';
|
|
189
|
+
readonly requestId?: string;
|
|
190
|
+
} | {
|
|
191
|
+
readonly kind: 'item_completed';
|
|
192
|
+
readonly requestId: string;
|
|
193
|
+
readonly result: Extract<PortalCoreItemResult, {
|
|
194
|
+
readonly status: 'success';
|
|
195
|
+
}>;
|
|
196
|
+
} | {
|
|
197
|
+
readonly error: PortalCoreItemError;
|
|
198
|
+
readonly kind: 'item_failed';
|
|
199
|
+
readonly requestId: string;
|
|
200
|
+
} | {
|
|
201
|
+
readonly kind: 'completed';
|
|
202
|
+
readonly result: PortalCoreResult;
|
|
203
|
+
} | {
|
|
204
|
+
readonly error: unknown;
|
|
205
|
+
readonly kind: 'failed';
|
|
206
|
+
};
|
|
207
|
+
interface PortalCoreStreamCall {
|
|
208
|
+
readonly input: unknown;
|
|
209
|
+
readonly scope: PortalAgentScope;
|
|
210
|
+
readonly signal?: AbortSignal;
|
|
211
|
+
readonly toolName: PortalCoreToolName;
|
|
212
|
+
}
|
|
213
|
+
interface PortalCoreCollectOptions {
|
|
214
|
+
readonly onEvent?: (event: PortalCoreEvent) => Promise<void> | void;
|
|
215
|
+
}
|
|
216
|
+
interface PortalCoreRuntime extends PortalSessionRuntime {
|
|
217
|
+
readonly callUpstreamTool: PortalToolRuntime['callUpstreamTool'];
|
|
218
|
+
}
|
|
219
|
+
type PortalApprovalEvaluator = NonNullable<PortalToolRuntime['approval']>;
|
|
220
|
+
interface CreatePortalCoreBaseProps {
|
|
221
|
+
readonly accessPolicy: PortalAccessPolicyConfig;
|
|
222
|
+
readonly catalogTtlMs: number;
|
|
223
|
+
readonly runtime: PortalCoreRuntime;
|
|
224
|
+
readonly skills?: readonly SkillGraphInput[];
|
|
225
|
+
readonly upstreamNamespaces: readonly string[];
|
|
226
|
+
}
|
|
227
|
+
type CreatePortalCoreProps = (CreatePortalCoreBaseProps & {
|
|
228
|
+
readonly approval: PortalApprovalEvaluator;
|
|
229
|
+
readonly approvalTrustBoundary?: never;
|
|
230
|
+
}) | (CreatePortalCoreBaseProps & {
|
|
231
|
+
readonly approval?: never;
|
|
232
|
+
readonly approvalTrustBoundary: 'openclaw-before-tool-call-hook';
|
|
233
|
+
});
|
|
234
|
+
interface PortalCore {
|
|
235
|
+
readonly approval: {
|
|
236
|
+
readonly evaluateCalls: (calls: readonly PortalApprovalCall[], scope: PortalAgentScope, approvalToken: string | undefined) => ReturnType<PortalApprovalEvaluator>;
|
|
237
|
+
};
|
|
238
|
+
readonly callStream: (call: PortalCoreStreamCall) => AsyncIterable<PortalCoreEvent>;
|
|
239
|
+
readonly close: () => Promise<void>;
|
|
240
|
+
readonly collectPortalCoreResult: typeof collectPortalCoreResult;
|
|
241
|
+
readonly createAgentScope: (input: {
|
|
242
|
+
readonly agentId: string;
|
|
243
|
+
readonly agentScopeId: string;
|
|
244
|
+
readonly authSubject?: string;
|
|
245
|
+
readonly sessionId?: string;
|
|
246
|
+
readonly sessionKey?: string;
|
|
247
|
+
readonly source: PortalAgentScopeSource;
|
|
248
|
+
}) => PortalAgentScope;
|
|
249
|
+
readonly describeTools: (scope: PortalAgentScope) => readonly PortalCoreToolDescriptor[];
|
|
250
|
+
readonly invalidateAgentScope: (agentScopeId: string) => Promise<void>;
|
|
251
|
+
readonly invalidateSession: (scope: PortalAgentScope) => Promise<void>;
|
|
252
|
+
readonly upstreamNamespaces: readonly string[];
|
|
253
|
+
}
|
|
254
|
+
interface PortalCoreToolDescriptor {
|
|
255
|
+
readonly description: string;
|
|
256
|
+
readonly inputSchema: Tool['inputSchema'];
|
|
257
|
+
readonly name: PortalCoreToolName;
|
|
258
|
+
}
|
|
259
|
+
declare function listPortalCoreToolDescriptors(namespaces?: readonly string[]): readonly PortalCoreToolDescriptor[];
|
|
260
|
+
declare function collectPortalCoreResult(events: AsyncIterable<PortalCoreEvent>, options?: PortalCoreCollectOptions): Promise<PortalCoreResult>;
|
|
261
|
+
declare function createPortalCore(props: CreatePortalCoreProps): PortalCore;
|
|
262
|
+
//#endregion
|
|
263
|
+
export { PortalToolSuccess as A, PortalCallUpstreamTool as C, PortalToolResult as D, PortalToolHandlers as E, createPortalToolHandlers as M, portalToolInputSchemas as N, PortalToolResultMap as O, PortalBatchResult as S, PortalToolHandlerCall as T, createPortalCore as _, PortalCore as a, PortalBatchDiagnostic as b, PortalCoreEvent as c, PortalCoreResult as d, PortalCoreRuntime as f, collectPortalCoreResult as g, PortalCoreToolName as h, PortalAuditEvent as i, PortalUpstreamEvent as j, PortalToolRuntime as k, PortalCoreItemError as l, PortalCoreToolDescriptor as m, PortalAgentScope as n, PortalCoreCollectOptions as o, PortalCoreStreamCall as p, PortalApprovalEvaluator as r, PortalCoreContentBlock as s, CreatePortalCoreProps as t, PortalCoreItemResult as u, listPortalCoreToolDescriptors as v, PortalToolFailure as w, PortalBatchError as x, PortalApprovalCall as y };
|
|
264
|
+
//# sourceMappingURL=portal-core-CZQI7Ob6.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal-core-CZQI7Ob6.d.ts","names":[],"sources":["../src/core/portal-tools.ts","../src/core/portal-core.ts"],"mappings":";;;;;UAiBiB,iBAAA;EAAA,SACP,KAAA,EAAO,QAAA,CAAS,MAAA;EAAA,SAChB,EAAA;EAAA,SACA,MAAA,EAAQ,QAAA,CAAS,MAAA;AAAA;AAAA,UAGV,iBAAA;EAAA,SACP,KAAA;EAAA,SACA,KAAA,EAAO,QAAA,CAAS,MAAA;EAAA,SAChB,EAAA;AAAA;AAAA,KAGE,gBAAA,GAAmB,iBAAA,GAAoB,iBAAA;AAAA,KACvC,mBAAA,GAAsB,QAAA,CAAS,MAAA,SAAe,gBAAA;AAAA,UAEzC,gBAAA;EAAA,SACP,EAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA;AAAA;AAAA,UAGO,qBAAA;EAAA,SACP,IAAA;EAAA,SACA,OAAA;EAAA,SACA,SAAA;AAAA;AAAA,UAGO,iBAAA;EAAA,SACP,WAAA,WAAsB,qBAAA;EAAA,SACtB,MAAA,WAAiB,gBAAA;EAAA,SACjB,EAAA;EAAA,SACA,OAAA,EAAS,mBAAA;AAAA;AAAA,UAGF,kBAAA;EAAA,SACP,SAAA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mB,KAAA;IAAA,SAClB,OAAA;IAAA,SACA,YAAA;IAAA,SACA,WAAA;IAAA,SACA,SAAA;IAAA,SACA,UAAA;IAAA,SACA,MAAA,EAAQ,sBAAA;EAAA,MACZ,gBAAA;EAAA,SACG,aAAA,GAAgB,KAAA,EAAO,gBAAA,cAA8B,wBAAA;EAAA,SACrD,oBAAA,GAAuB,YAAA,aAAyB,OAAA;EAAA,SAChD,iBAAA,GAAoB,KAAA,EAAO,gBAAA,KAAqB,OAAA;EAAA,SAChD,kBAAA;AAAA;AAAA,UAGO,wBAAA;EAAA,SACP,WAAA;EAAA,SACA,WAAA,EAAa,IAAA;EAAA,SACb,IAAA,EAAM,kBAAA;AAAA;AAAA,iBAuKA,6BAAA,CACf,UAAA,gCACW,wBAAA;AAAA,iBA0BU,uBAAA,CACrB,MAAA,EAAQ,aAAA,CAAc,eAAA,GACtB,OAAA,GAAS,wBAAA,GACP,OAAA,CAAQ,gBAAA;AAAA,iBA8KK,gBAAA,CAAiB,KAAA,EAAO,qBAAA,GAAwB,UAAA"}
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { l as jsonObjectSchema } from "./zod-schema-loader-yNekKNpm.js";
|
|
2
|
+
import { f as resolvePortalAccessPolicy, u as createPortalAgentIdentity } from "./upstream-response-middleware-BjUWZ2G8.js";
|
|
3
|
+
import { n as createPortalSessionManager } from "./upstream-mcp-client-runtime-JlsfTm7_.js";
|
|
4
|
+
import { n as portalToolInputSchemas, t as createPortalToolHandlers } from "./portal-tools-DKci1szO.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { mcpConfigToResolvedProviders } from "@agent-vm/config-contracts";
|
|
7
|
+
//#region src/core/provider-runtime.ts
|
|
8
|
+
async function resolveProviderSecretRecord(secrets, resolveSecret) {
|
|
9
|
+
const resolvedEntries = await Promise.all(Object.entries(secrets).map(async ([name, secret]) => [name, await resolveSecret(secret)]));
|
|
10
|
+
return Object.fromEntries(resolvedEntries);
|
|
11
|
+
}
|
|
12
|
+
async function resolveUpstreamServer(provider, resolveSecret) {
|
|
13
|
+
if (provider.transport === "stdio") return {
|
|
14
|
+
args: provider.args,
|
|
15
|
+
command: provider.command,
|
|
16
|
+
...provider.cwd === void 0 ? {} : { cwd: provider.cwd },
|
|
17
|
+
env: await resolveProviderSecretRecord(provider.env, resolveSecret),
|
|
18
|
+
namespace: provider.namespace,
|
|
19
|
+
transport: "stdio"
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
headers: await resolveProviderSecretRecord(provider.headers, resolveSecret),
|
|
23
|
+
namespace: provider.namespace,
|
|
24
|
+
transport: provider.transport,
|
|
25
|
+
url: provider.url
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function resolveUpstreamServers(props) {
|
|
29
|
+
return await Promise.all(mcpConfigToResolvedProviders(props.config).map(async (provider) => resolveUpstreamServer(provider, props.resolveSecret)));
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/core/portal-core.ts
|
|
33
|
+
const maxQueuedPortalCoreEvents = 1024;
|
|
34
|
+
const maxPortalCoreEventBytes = 256 * 1024;
|
|
35
|
+
const portalCallRequestSchema = z.object({
|
|
36
|
+
arguments: jsonObjectSchema,
|
|
37
|
+
id: z.string().min(1),
|
|
38
|
+
namespace: z.string().min(1),
|
|
39
|
+
toolName: z.string().min(1)
|
|
40
|
+
}).strict();
|
|
41
|
+
const portalCallInputSchema = z.object({
|
|
42
|
+
calls: z.array(portalCallRequestSchema).min(1),
|
|
43
|
+
portalApprovalToken: z.string().min(1).optional()
|
|
44
|
+
}).strict();
|
|
45
|
+
function diagnosticsToAuditEvents(diagnostics) {
|
|
46
|
+
return diagnostics.map((diagnostic) => ({
|
|
47
|
+
kind: diagnostic.kind,
|
|
48
|
+
message: diagnostic.message,
|
|
49
|
+
...diagnostic.namespace !== void 0 ? { namespace: diagnostic.namespace } : {}
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
function isUnknownRecord(value) {
|
|
53
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
54
|
+
}
|
|
55
|
+
function errorRecordFromUnknown(error) {
|
|
56
|
+
return isUnknownRecord(error) ? error : {};
|
|
57
|
+
}
|
|
58
|
+
function messageFromUnknown(error) {
|
|
59
|
+
if (error instanceof Error) return error.message;
|
|
60
|
+
const message = errorRecordFromUnknown(error).message;
|
|
61
|
+
return typeof message === "string" ? message : String(error);
|
|
62
|
+
}
|
|
63
|
+
function errorFromAbortSignal(signal) {
|
|
64
|
+
const reason = signal.reason;
|
|
65
|
+
return reason instanceof Error ? reason : /* @__PURE__ */ new Error("MCP Portal core stream aborted.");
|
|
66
|
+
}
|
|
67
|
+
function throwIfAborted(signal) {
|
|
68
|
+
if (signal?.aborted) throw errorFromAbortSignal(signal);
|
|
69
|
+
}
|
|
70
|
+
function assertPortalCoreEventSize(event) {
|
|
71
|
+
const serialized = JSON.stringify(event);
|
|
72
|
+
if (serialized === void 0) return;
|
|
73
|
+
const byteLength = Buffer.byteLength(serialized, "utf8");
|
|
74
|
+
if (byteLength > maxPortalCoreEventBytes) throw new Error(`MCP Portal core event exceeded ${String(maxPortalCoreEventBytes)} bytes (${String(byteLength)} bytes).`);
|
|
75
|
+
}
|
|
76
|
+
function waitForQueuedCoreEvent(props) {
|
|
77
|
+
if (props.signal === void 0) return new Promise((resolve) => {
|
|
78
|
+
props.setNotifyQueuedEvent(resolve);
|
|
79
|
+
});
|
|
80
|
+
const signal = props.signal;
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
let settled = false;
|
|
83
|
+
const settle = (complete) => {
|
|
84
|
+
if (settled) return;
|
|
85
|
+
settled = true;
|
|
86
|
+
signal.removeEventListener("abort", onAbort);
|
|
87
|
+
props.setNotifyQueuedEvent(void 0);
|
|
88
|
+
complete();
|
|
89
|
+
};
|
|
90
|
+
const onNotify = () => {
|
|
91
|
+
settle(resolve);
|
|
92
|
+
};
|
|
93
|
+
const onAbort = () => {
|
|
94
|
+
settle(() => reject(errorFromAbortSignal(signal)));
|
|
95
|
+
};
|
|
96
|
+
props.setNotifyQueuedEvent(onNotify);
|
|
97
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
98
|
+
if (signal.aborted) onAbort();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function itemErrorFromPortalResult(result) {
|
|
102
|
+
if (result.ok) throw new Error("Cannot convert successful portal result into an item error.");
|
|
103
|
+
const errorRecord = errorRecordFromUnknown(result.error);
|
|
104
|
+
const kind = errorRecord.kind;
|
|
105
|
+
const namespace = errorRecord.namespace;
|
|
106
|
+
const toolName = errorRecord.toolName;
|
|
107
|
+
return {
|
|
108
|
+
code: typeof kind === "string" ? kind : "portal_item_failed",
|
|
109
|
+
message: messageFromUnknown(result.error),
|
|
110
|
+
...typeof namespace === "string" ? { namespace } : {},
|
|
111
|
+
...typeof toolName === "string" ? { toolName } : {}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function itemResultFromPortalToolResult(requestId, result) {
|
|
115
|
+
if (!result.ok) return {
|
|
116
|
+
error: itemErrorFromPortalResult(result),
|
|
117
|
+
requestId,
|
|
118
|
+
status: "failed"
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
content: [{
|
|
122
|
+
type: "json",
|
|
123
|
+
value: result.output
|
|
124
|
+
}],
|
|
125
|
+
requestId,
|
|
126
|
+
status: "success",
|
|
127
|
+
structuredContent: result.output
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function scalarBatchResultToCoreResult(batchResult) {
|
|
131
|
+
return {
|
|
132
|
+
auditEvents: diagnosticsToAuditEvents(batchResult.diagnostics),
|
|
133
|
+
content: [{
|
|
134
|
+
type: "json",
|
|
135
|
+
value: batchResult
|
|
136
|
+
}],
|
|
137
|
+
items: [],
|
|
138
|
+
structuredContent: batchResult
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function batchItemsToCoreResult(props) {
|
|
142
|
+
return {
|
|
143
|
+
auditEvents: diagnosticsToAuditEvents(props.diagnostics),
|
|
144
|
+
content: [],
|
|
145
|
+
items: props.items
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function namespaceDescription(namespaces) {
|
|
149
|
+
return namespaces.length === 0 ? "No upstream MCP namespaces are authorized for this agent scope." : `Authorized MCP namespaces for this agent scope: ${namespaces.join(", ")}.`;
|
|
150
|
+
}
|
|
151
|
+
function listPortalCoreToolDescriptors(namespaces = []) {
|
|
152
|
+
const scopeDescription = namespaceDescription(namespaces);
|
|
153
|
+
return [
|
|
154
|
+
{
|
|
155
|
+
description: `List authorized MCP namespaces and compact tool summaries. ${scopeDescription}`,
|
|
156
|
+
inputSchema: portalToolInputSchemas.mcp_portal_list,
|
|
157
|
+
name: "mcp_portal_list"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
description: `Search the caller scoped MCP Portal index. ${scopeDescription}`,
|
|
161
|
+
inputSchema: portalToolInputSchemas.mcp_portal_search,
|
|
162
|
+
name: "mcp_portal_search"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
description: `Describe exact MCP tool schemas and optional TypeScript/Zod helpers. ${scopeDescription}`,
|
|
166
|
+
inputSchema: portalToolInputSchemas.mcp_portal_describe,
|
|
167
|
+
name: "mcp_portal_describe"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
description: `Validate and call an authorized upstream MCP tool by namespace and toolName. ${scopeDescription}`,
|
|
171
|
+
inputSchema: portalToolInputSchemas.mcp_portal_call,
|
|
172
|
+
name: "mcp_portal_call"
|
|
173
|
+
}
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
async function collectPortalCoreResult(events, options = {}) {
|
|
177
|
+
let result;
|
|
178
|
+
for await (const event of events) {
|
|
179
|
+
await options.onEvent?.(event);
|
|
180
|
+
if (event.kind === "completed") result = event.result;
|
|
181
|
+
if (event.kind === "failed") throw event.error;
|
|
182
|
+
}
|
|
183
|
+
if (result === void 0) throw new Error("MCP Portal core stream ended without a completed event.");
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
async function* scalarToolStream(props) {
|
|
187
|
+
const handlers = createPortalToolHandlers(props.toolRuntime);
|
|
188
|
+
const handler = props.toolName === "mcp_portal_list" ? handlers.list : props.toolName === "mcp_portal_search" ? handlers.search : handlers.describe;
|
|
189
|
+
throwIfAborted(props.signal);
|
|
190
|
+
const batchResult = await handler({
|
|
191
|
+
identity: props.scope,
|
|
192
|
+
input: props.input
|
|
193
|
+
});
|
|
194
|
+
throwIfAborted(props.signal);
|
|
195
|
+
yield {
|
|
196
|
+
kind: "completed",
|
|
197
|
+
result: scalarBatchResultToCoreResult(batchResult)
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
async function* callToolStream(props) {
|
|
201
|
+
const parsedInput = portalCallInputSchema.safeParse(props.input);
|
|
202
|
+
const queuedEvents = [];
|
|
203
|
+
let notifyQueuedEvent;
|
|
204
|
+
let executionDone = false;
|
|
205
|
+
const pushEvent = (event) => {
|
|
206
|
+
assertPortalCoreEventSize(event);
|
|
207
|
+
if (queuedEvents.length >= maxQueuedPortalCoreEvents) throw new Error(`MCP Portal core event queue exceeded ${maxQueuedPortalCoreEvents} events.`);
|
|
208
|
+
queuedEvents.push(event);
|
|
209
|
+
notifyQueuedEvent?.();
|
|
210
|
+
notifyQueuedEvent = void 0;
|
|
211
|
+
};
|
|
212
|
+
const handlers = createPortalToolHandlers({
|
|
213
|
+
...props.toolRuntime,
|
|
214
|
+
callUpstreamTool: async (call) => {
|
|
215
|
+
throwIfAborted(props.signal);
|
|
216
|
+
pushEvent({
|
|
217
|
+
kind: "item_started",
|
|
218
|
+
namespace: call.namespace,
|
|
219
|
+
requestId: call.requestId,
|
|
220
|
+
toolName: call.toolName
|
|
221
|
+
});
|
|
222
|
+
pushEvent({
|
|
223
|
+
kind: "progress",
|
|
224
|
+
message: `Calling upstream MCP tool ${call.namespace}.${call.toolName}.`,
|
|
225
|
+
requestId: call.requestId
|
|
226
|
+
});
|
|
227
|
+
return await props.toolRuntime.callUpstreamTool({
|
|
228
|
+
...call,
|
|
229
|
+
...props.signal !== void 0 ? { signal: props.signal } : {},
|
|
230
|
+
onEvent: (event) => {
|
|
231
|
+
if (event.kind === "progress") {
|
|
232
|
+
pushEvent({
|
|
233
|
+
kind: "progress",
|
|
234
|
+
...event.message !== void 0 ? { message: event.message } : {},
|
|
235
|
+
...event.progress !== void 0 ? { progress: event.progress } : {},
|
|
236
|
+
requestId: call.requestId,
|
|
237
|
+
...event.total !== void 0 ? { total: event.total } : {}
|
|
238
|
+
});
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (event.kind === "partial_content") {
|
|
242
|
+
pushEvent({
|
|
243
|
+
content: event.content,
|
|
244
|
+
kind: "partial_content",
|
|
245
|
+
requestId: call.requestId
|
|
246
|
+
});
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
pushEvent({
|
|
250
|
+
kind: "upstream_notification",
|
|
251
|
+
method: event.method,
|
|
252
|
+
params: event.params,
|
|
253
|
+
requestId: call.requestId
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
if (!parsedInput.success) {
|
|
260
|
+
yield {
|
|
261
|
+
kind: "completed",
|
|
262
|
+
result: scalarBatchResultToCoreResult(await handlers.call({
|
|
263
|
+
identity: props.scope,
|
|
264
|
+
input: props.input
|
|
265
|
+
}))
|
|
266
|
+
};
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const itemResults = [];
|
|
270
|
+
const batchResultPromise = handlers.call({
|
|
271
|
+
identity: props.scope,
|
|
272
|
+
input: props.input
|
|
273
|
+
}).finally(() => {
|
|
274
|
+
executionDone = true;
|
|
275
|
+
notifyQueuedEvent?.();
|
|
276
|
+
notifyQueuedEvent = void 0;
|
|
277
|
+
});
|
|
278
|
+
const hasPendingExecutionEvents = () => !executionDone || queuedEvents.length > 0;
|
|
279
|
+
while (hasPendingExecutionEvents()) {
|
|
280
|
+
const event = queuedEvents.shift();
|
|
281
|
+
if (event !== void 0) {
|
|
282
|
+
yield event;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
throwIfAborted(props.signal);
|
|
286
|
+
await waitForQueuedCoreEvent({
|
|
287
|
+
setNotifyQueuedEvent: (notify) => {
|
|
288
|
+
notifyQueuedEvent = notify;
|
|
289
|
+
},
|
|
290
|
+
...props.signal !== void 0 ? { signal: props.signal } : {}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const batchResult = await batchResultPromise;
|
|
294
|
+
throwIfAborted(props.signal);
|
|
295
|
+
if (batchResult.errors.length > 0) {
|
|
296
|
+
yield {
|
|
297
|
+
kind: "completed",
|
|
298
|
+
result: scalarBatchResultToCoreResult(batchResult)
|
|
299
|
+
};
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
for (const request of parsedInput.data.calls) {
|
|
303
|
+
const portalResult = batchResult.results[request.id];
|
|
304
|
+
const itemResult = portalResult === void 0 ? {
|
|
305
|
+
error: {
|
|
306
|
+
code: "portal_item_missing",
|
|
307
|
+
message: `MCP Portal did not return a result for request "${request.id}".`,
|
|
308
|
+
namespace: request.namespace,
|
|
309
|
+
toolName: request.toolName
|
|
310
|
+
},
|
|
311
|
+
requestId: request.id,
|
|
312
|
+
status: "failed"
|
|
313
|
+
} : itemResultFromPortalToolResult(request.id, portalResult);
|
|
314
|
+
itemResults.push(itemResult);
|
|
315
|
+
if (itemResult.status === "success") yield {
|
|
316
|
+
kind: "item_completed",
|
|
317
|
+
requestId: request.id,
|
|
318
|
+
result: itemResult
|
|
319
|
+
};
|
|
320
|
+
else yield {
|
|
321
|
+
error: itemResult.error,
|
|
322
|
+
kind: "item_failed",
|
|
323
|
+
requestId: request.id
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
yield {
|
|
327
|
+
kind: "completed",
|
|
328
|
+
result: batchItemsToCoreResult({
|
|
329
|
+
diagnostics: batchResult.diagnostics,
|
|
330
|
+
items: itemResults
|
|
331
|
+
})
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function createPortalCore(props) {
|
|
335
|
+
const sessionManager = createPortalSessionManager({
|
|
336
|
+
accessPolicy: props.accessPolicy,
|
|
337
|
+
catalogTtlMs: props.catalogTtlMs,
|
|
338
|
+
runtime: props.runtime,
|
|
339
|
+
...props.skills !== void 0 ? { skills: props.skills } : {},
|
|
340
|
+
upstreamNamespaces: props.upstreamNamespaces
|
|
341
|
+
});
|
|
342
|
+
const createdAgentScopeIds = /* @__PURE__ */ new Set();
|
|
343
|
+
const approval = props.approval ?? (() => {
|
|
344
|
+
if (props.approvalTrustBoundary === "openclaw-before-tool-call-hook") return { kind: "allow" };
|
|
345
|
+
throw new Error("MCP Portal approval evaluation is not configured.");
|
|
346
|
+
});
|
|
347
|
+
const toolRuntime = {
|
|
348
|
+
approval,
|
|
349
|
+
callUpstreamTool: props.runtime.callUpstreamTool,
|
|
350
|
+
getSession: sessionManager.getSession
|
|
351
|
+
};
|
|
352
|
+
async function* callStream(call) {
|
|
353
|
+
try {
|
|
354
|
+
throwIfAborted(call.signal);
|
|
355
|
+
yield {
|
|
356
|
+
kind: "started",
|
|
357
|
+
toolName: call.toolName
|
|
358
|
+
};
|
|
359
|
+
throwIfAborted(call.signal);
|
|
360
|
+
if (call.toolName === "mcp_portal_call") {
|
|
361
|
+
yield* callToolStream({
|
|
362
|
+
input: call.input,
|
|
363
|
+
scope: call.scope,
|
|
364
|
+
...call.signal !== void 0 ? { signal: call.signal } : {},
|
|
365
|
+
toolRuntime
|
|
366
|
+
});
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
yield* scalarToolStream({
|
|
370
|
+
input: call.input,
|
|
371
|
+
scope: call.scope,
|
|
372
|
+
...call.signal !== void 0 ? { signal: call.signal } : {},
|
|
373
|
+
sessionManager,
|
|
374
|
+
toolName: call.toolName,
|
|
375
|
+
toolRuntime
|
|
376
|
+
});
|
|
377
|
+
} catch (error) {
|
|
378
|
+
yield {
|
|
379
|
+
error,
|
|
380
|
+
kind: "failed"
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
approval: { evaluateCalls: (calls, scope, approvalToken) => approval(calls, scope, approvalToken) },
|
|
386
|
+
callStream,
|
|
387
|
+
close: async () => {
|
|
388
|
+
await Promise.all([...createdAgentScopeIds].map((agentScopeId) => sessionManager.invalidateAgentScope(agentScopeId)));
|
|
389
|
+
},
|
|
390
|
+
collectPortalCoreResult,
|
|
391
|
+
createAgentScope: (input) => {
|
|
392
|
+
const scope = createPortalAgentIdentity(input);
|
|
393
|
+
createdAgentScopeIds.add(scope.agentScopeId);
|
|
394
|
+
return scope;
|
|
395
|
+
},
|
|
396
|
+
describeTools: (scope) => {
|
|
397
|
+
return listPortalCoreToolDescriptors(resolvePortalAccessPolicy({
|
|
398
|
+
config: props.accessPolicy,
|
|
399
|
+
identity: scope,
|
|
400
|
+
upstreamNamespaces: props.upstreamNamespaces
|
|
401
|
+
}).allowedNamespaces);
|
|
402
|
+
},
|
|
403
|
+
invalidateAgentScope: async (agentScopeId) => {
|
|
404
|
+
createdAgentScopeIds.delete(agentScopeId);
|
|
405
|
+
await sessionManager.invalidateAgentScope(agentScopeId);
|
|
406
|
+
},
|
|
407
|
+
invalidateSession: async (scope) => {
|
|
408
|
+
await sessionManager.invalidateSession(scope);
|
|
409
|
+
},
|
|
410
|
+
upstreamNamespaces: props.upstreamNamespaces
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
//#endregion
|
|
414
|
+
export { resolveUpstreamServers as i, createPortalCore as n, listPortalCoreToolDescriptors as r, collectPortalCoreResult as t };
|
|
415
|
+
|
|
416
|
+
//# sourceMappingURL=portal-core-Cgu714CL.js.map
|