@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.
Files changed (84) hide show
  1. package/README.md +42 -11
  2. package/dist/agent-bearer-token-DCtpDPCZ.js +59 -0
  3. package/dist/agent-bearer-token-DCtpDPCZ.js.map +1 -0
  4. package/dist/bin/mcp-portal.d.ts +28 -0
  5. package/dist/bin/mcp-portal.d.ts.map +1 -0
  6. package/dist/bin/mcp-portal.js +318 -0
  7. package/dist/bin/mcp-portal.js.map +1 -0
  8. package/dist/{catalog-types--gUGFPpN.d.ts → catalog-types-BVuB4Ynx.d.ts} +1 -1
  9. package/dist/{catalog-types--gUGFPpN.d.ts.map → catalog-types-BVuB4Ynx.d.ts.map} +1 -1
  10. package/dist/cli/index.d.ts +101 -0
  11. package/dist/cli/index.d.ts.map +1 -0
  12. package/dist/cli/index.js +2 -0
  13. package/dist/core/index.d.ts +40 -0
  14. package/dist/core/index.d.ts.map +1 -0
  15. package/dist/core/index.js +5 -0
  16. package/dist/hmac-env-B4shpRRB.js +20 -0
  17. package/dist/hmac-env-B4shpRRB.js.map +1 -0
  18. package/dist/hmac-token-DBqWY3-w.js +100 -0
  19. package/dist/hmac-token-DBqWY3-w.js.map +1 -0
  20. package/dist/index.d.ts +5 -485
  21. package/dist/index.js +4 -5
  22. package/dist/mcp-proxy/index.d.ts +24 -0
  23. package/dist/mcp-proxy/index.d.ts.map +1 -0
  24. package/dist/mcp-proxy/index.js +2 -0
  25. package/dist/portal-auth/agent-bearer-token.d.ts +22 -0
  26. package/dist/portal-auth/agent-bearer-token.d.ts.map +1 -0
  27. package/dist/portal-auth/agent-bearer-token.js +2 -0
  28. package/dist/portal-auth/hmac-env.d.ts +6 -0
  29. package/dist/portal-auth/hmac-env.d.ts.map +1 -0
  30. package/dist/portal-auth/hmac-env.js +2 -0
  31. package/dist/portal-auth/hmac-token.d.ts +40 -0
  32. package/dist/portal-auth/hmac-token.d.ts.map +1 -0
  33. package/dist/portal-auth/hmac-token.js +2 -0
  34. package/dist/portal-config/index.d.ts +11 -0
  35. package/dist/portal-config/index.d.ts.map +1 -0
  36. package/dist/{tool-vm → portal-config}/index.js +2 -3
  37. package/dist/portal-core-CZQI7Ob6.d.ts +264 -0
  38. package/dist/portal-core-CZQI7Ob6.d.ts.map +1 -0
  39. package/dist/portal-core-Cgu714CL.js +416 -0
  40. package/dist/portal-core-Cgu714CL.js.map +1 -0
  41. package/dist/portal-session-DG2CUjIo.d.ts +184 -0
  42. package/dist/portal-session-DG2CUjIo.d.ts.map +1 -0
  43. package/dist/portal-tools-DKci1szO.js +528 -0
  44. package/dist/portal-tools-DKci1szO.js.map +1 -0
  45. package/dist/resolve-agent-identity-DnC_Pmnh.js +550 -0
  46. package/dist/resolve-agent-identity-DnC_Pmnh.js.map +1 -0
  47. package/dist/resolve-agent-identity-FQL02YdW.d.ts +81 -0
  48. package/dist/resolve-agent-identity-FQL02YdW.d.ts.map +1 -0
  49. package/dist/serve-command-CnSMUybd.js +358 -0
  50. package/dist/serve-command-CnSMUybd.js.map +1 -0
  51. package/dist/testing/fake-upstream-mcp-server.d.ts +5 -2
  52. package/dist/testing/fake-upstream-mcp-server.d.ts.map +1 -1
  53. package/dist/testing/fake-upstream-mcp-server.js +14 -4
  54. package/dist/testing/fake-upstream-mcp-server.js.map +1 -1
  55. package/dist/typescript-artifact-BVLt3Ifd.js +60 -0
  56. package/dist/typescript-artifact-BVLt3Ifd.js.map +1 -0
  57. package/dist/upstream-mcp-client-runtime-JlsfTm7_.js +760 -0
  58. package/dist/upstream-mcp-client-runtime-JlsfTm7_.js.map +1 -0
  59. package/dist/upstream-response-middleware-1MZnAD9C.d.ts +115 -0
  60. package/dist/upstream-response-middleware-1MZnAD9C.d.ts.map +1 -0
  61. package/dist/upstream-response-middleware-BjUWZ2G8.js +172 -0
  62. package/dist/upstream-response-middleware-BjUWZ2G8.js.map +1 -0
  63. package/dist/{index-BcI9c8sg.d.ts → zod-schema-loader-DLGQpYFD.d.ts} +3 -9
  64. package/dist/zod-schema-loader-DLGQpYFD.d.ts.map +1 -0
  65. package/dist/{typescript-artifact-BqU8okQy.js → zod-schema-loader-yNekKNpm.js} +85 -55
  66. package/dist/zod-schema-loader-yNekKNpm.js.map +1 -0
  67. package/package.json +30 -13
  68. package/dist/bin/agent-vm-mcp-portal.d.ts +0 -10
  69. package/dist/bin/agent-vm-mcp-portal.d.ts.map +0 -1
  70. package/dist/bin/agent-vm-mcp-portal.js +0 -56
  71. package/dist/bin/agent-vm-mcp-portal.js.map +0 -1
  72. package/dist/bin/portal-server.d.ts +0 -55
  73. package/dist/bin/portal-server.d.ts.map +0 -1
  74. package/dist/bin/portal-server.js +0 -289
  75. package/dist/bin/portal-server.js.map +0 -1
  76. package/dist/index-BcI9c8sg.d.ts.map +0 -1
  77. package/dist/index.d.ts.map +0 -1
  78. package/dist/tool-vm/index.d.ts +0 -2
  79. package/dist/tool-vm-ihnzDyjJ.js +0 -3
  80. package/dist/typescript-artifact-BqU8okQy.js.map +0 -1
  81. package/dist/upstream-mcp-client-runtime-DiBCBsDj.js +0 -1729
  82. package/dist/upstream-mcp-client-runtime-DiBCBsDj.js.map +0 -1
  83. package/dist/zod-schema-loader-CDDtoRE1.js +0 -90
  84. package/dist/zod-schema-loader-CDDtoRE1.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-core-Cgu714CL.js","names":[],"sources":["../src/core/provider-runtime.ts","../src/core/portal-core.ts"],"sourcesContent":["import {\n\tmcpConfigToResolvedProviders,\n\ttype McpConfig,\n\ttype ResolvedMcpProvider,\n\ttype SecretValue,\n} from '@agent-vm/config-contracts';\n\nimport type { NormalizedUpstreamMcpServer } from '../upstream-mcp-client-runtime.js';\n\nexport interface ResolveUpstreamServersProps {\n\treadonly config: McpConfig;\n\treadonly resolveSecret: (secret: SecretValue) => Promise<string>;\n}\n\nasync function resolveProviderSecretRecord(\n\tsecrets: Readonly<Record<string, SecretValue>>,\n\tresolveSecret: (secret: SecretValue) => Promise<string>,\n): Promise<Readonly<Record<string, string>>> {\n\tconst resolvedEntries = await Promise.all(\n\t\tObject.entries(secrets).map(\n\t\t\tasync ([name, secret]) => [name, await resolveSecret(secret)] as const,\n\t\t),\n\t);\n\treturn Object.fromEntries(resolvedEntries);\n}\n\nasync function resolveUpstreamServer(\n\tprovider: ResolvedMcpProvider,\n\tresolveSecret: (secret: SecretValue) => Promise<string>,\n): Promise<NormalizedUpstreamMcpServer> {\n\tif (provider.transport === 'stdio') {\n\t\treturn {\n\t\t\targs: provider.args,\n\t\t\tcommand: provider.command,\n\t\t\t...(provider.cwd === undefined ? {} : { cwd: provider.cwd }),\n\t\t\tenv: await resolveProviderSecretRecord(provider.env, resolveSecret),\n\t\t\tnamespace: provider.namespace,\n\t\t\ttransport: 'stdio',\n\t\t};\n\t}\n\n\treturn {\n\t\theaders: await resolveProviderSecretRecord(provider.headers, resolveSecret),\n\t\tnamespace: provider.namespace,\n\t\ttransport: provider.transport,\n\t\turl: provider.url,\n\t};\n}\n\nexport async function resolveUpstreamServers(\n\tprops: ResolveUpstreamServersProps,\n): Promise<readonly NormalizedUpstreamMcpServer[]> {\n\treturn await Promise.all(\n\t\tmcpConfigToResolvedProviders(props.config).map(async (provider) =>\n\t\t\tresolveUpstreamServer(provider, props.resolveSecret),\n\t\t),\n\t);\n}\n","import type { Tool } from '@modelcontextprotocol/sdk/types.js';\nimport { z } from 'zod';\n\nimport { jsonObjectSchema } from '../json-schema.js';\nimport {\n\tcreatePortalAgentIdentity,\n\tresolvePortalAccessPolicy,\n\ttype PortalAccessPolicyConfig,\n\ttype PortalAgentIdentity,\n\ttype PortalAgentScopeSource,\n} from '../portal-access-policy.js';\nimport {\n\tcreatePortalSessionManager,\n\ttype PortalSessionManager,\n\ttype PortalSessionRuntime,\n} from '../portal-session.js';\nimport type { SkillGraphInput } from '../tool-graph.js';\nimport {\n\tcreatePortalToolHandlers,\n\tportalToolInputSchemas,\n\ttype PortalApprovalCall,\n\ttype PortalBatchDiagnostic,\n\ttype PortalBatchResult,\n\ttype PortalToolResult,\n\ttype PortalToolRuntime,\n} from './portal-tools.js';\n\nexport type PortalAgentScope = PortalAgentIdentity;\n\nexport type PortalCoreToolName =\n\t| 'mcp_portal_list'\n\t| 'mcp_portal_search'\n\t| 'mcp_portal_describe'\n\t| 'mcp_portal_call';\n\nexport interface PortalAuditEvent {\n\treadonly kind: string;\n\treadonly message: string;\n\treadonly namespace?: string;\n}\n\nexport interface PortalCoreResult {\n\treadonly auditEvents?: readonly PortalAuditEvent[];\n\treadonly content: readonly PortalCoreContentBlock[];\n\treadonly items: readonly PortalCoreItemResult[];\n\treadonly structuredContent?: unknown;\n}\n\nexport type PortalCoreItemResult =\n\t| {\n\t\t\treadonly content: readonly PortalCoreContentBlock[];\n\t\t\treadonly requestId: string;\n\t\t\treadonly status: 'success';\n\t\t\treadonly structuredContent?: unknown;\n\t }\n\t| {\n\t\t\treadonly error: PortalCoreItemError;\n\t\t\treadonly requestId: string;\n\t\t\treadonly status: 'failed';\n\t };\n\nexport interface PortalCoreItemError {\n\treadonly code: string;\n\treadonly message: string;\n\treadonly namespace?: string;\n\treadonly toolName?: string;\n}\n\nexport type PortalCoreContentBlock =\n\t| { readonly text: string; readonly type: 'text' }\n\t| { readonly type: 'json'; readonly value: unknown };\n\nexport type PortalCoreEvent =\n\t| {\n\t\t\treadonly kind: 'started';\n\t\t\treadonly toolName: PortalCoreToolName;\n\t }\n\t| {\n\t\t\treadonly kind: 'item_started';\n\t\t\treadonly namespace?: string;\n\t\t\treadonly requestId: string;\n\t\t\treadonly toolName?: string;\n\t }\n\t| {\n\t\t\treadonly kind: 'progress';\n\t\t\treadonly message?: string;\n\t\t\treadonly progress?: number;\n\t\t\treadonly requestId?: string;\n\t\t\treadonly total?: number;\n\t }\n\t| {\n\t\t\treadonly kind: 'upstream_notification';\n\t\t\treadonly method: string;\n\t\t\treadonly params: unknown;\n\t\t\treadonly requestId?: string;\n\t }\n\t| {\n\t\t\treadonly content: PortalCoreContentBlock;\n\t\t\treadonly kind: 'partial_content';\n\t\t\treadonly requestId?: string;\n\t }\n\t| {\n\t\t\treadonly kind: 'item_completed';\n\t\t\treadonly requestId: string;\n\t\t\treadonly result: Extract<PortalCoreItemResult, { readonly status: 'success' }>;\n\t }\n\t| {\n\t\t\treadonly error: PortalCoreItemError;\n\t\t\treadonly kind: 'item_failed';\n\t\t\treadonly requestId: string;\n\t }\n\t| {\n\t\t\treadonly kind: 'completed';\n\t\t\treadonly result: PortalCoreResult;\n\t }\n\t| {\n\t\t\treadonly error: unknown;\n\t\t\treadonly kind: 'failed';\n\t };\n\nexport interface PortalCoreStreamCall {\n\treadonly input: unknown;\n\treadonly scope: PortalAgentScope;\n\treadonly signal?: AbortSignal;\n\treadonly toolName: PortalCoreToolName;\n}\n\nconst maxQueuedPortalCoreEvents = 1_024;\nconst maxPortalCoreEventBytes = 256 * 1_024;\n\nexport interface PortalCoreCollectOptions {\n\treadonly onEvent?: (event: PortalCoreEvent) => Promise<void> | void;\n}\n\nexport interface PortalCoreRuntime extends PortalSessionRuntime {\n\treadonly callUpstreamTool: PortalToolRuntime['callUpstreamTool'];\n}\n\nexport type PortalApprovalEvaluator = NonNullable<PortalToolRuntime['approval']>;\n\ninterface CreatePortalCoreBaseProps {\n\treadonly accessPolicy: PortalAccessPolicyConfig;\n\treadonly catalogTtlMs: number;\n\treadonly runtime: PortalCoreRuntime;\n\treadonly skills?: readonly SkillGraphInput[];\n\treadonly upstreamNamespaces: readonly string[];\n}\n\nexport type CreatePortalCoreProps =\n\t| (CreatePortalCoreBaseProps & {\n\t\t\treadonly approval: PortalApprovalEvaluator;\n\t\t\treadonly approvalTrustBoundary?: never;\n\t })\n\t| (CreatePortalCoreBaseProps & {\n\t\t\treadonly approval?: never;\n\t\t\treadonly approvalTrustBoundary: 'openclaw-before-tool-call-hook';\n\t });\n\nexport interface PortalCore {\n\treadonly approval: {\n\t\treadonly evaluateCalls: (\n\t\t\tcalls: readonly PortalApprovalCall[],\n\t\t\tscope: PortalAgentScope,\n\t\t\tapprovalToken: string | undefined,\n\t\t) => ReturnType<PortalApprovalEvaluator>;\n\t};\n\treadonly callStream: (call: PortalCoreStreamCall) => AsyncIterable<PortalCoreEvent>;\n\treadonly close: () => Promise<void>;\n\treadonly collectPortalCoreResult: typeof collectPortalCoreResult;\n\treadonly createAgentScope: (input: {\n\t\treadonly agentId: string;\n\t\treadonly agentScopeId: string;\n\t\treadonly authSubject?: string;\n\t\treadonly sessionId?: string;\n\t\treadonly sessionKey?: string;\n\t\treadonly source: PortalAgentScopeSource;\n\t}) => PortalAgentScope;\n\treadonly describeTools: (scope: PortalAgentScope) => readonly PortalCoreToolDescriptor[];\n\treadonly invalidateAgentScope: (agentScopeId: string) => Promise<void>;\n\treadonly invalidateSession: (scope: PortalAgentScope) => Promise<void>;\n\treadonly upstreamNamespaces: readonly string[];\n}\n\nexport interface PortalCoreToolDescriptor {\n\treadonly description: string;\n\treadonly inputSchema: Tool['inputSchema'];\n\treadonly name: PortalCoreToolName;\n}\n\nconst portalCallRequestSchema = z\n\t.object({\n\t\targuments: jsonObjectSchema,\n\t\tid: z.string().min(1),\n\t\tnamespace: z.string().min(1),\n\t\ttoolName: z.string().min(1),\n\t})\n\t.strict();\nconst portalCallInputSchema = z\n\t.object({\n\t\tcalls: z.array(portalCallRequestSchema).min(1),\n\t\tportalApprovalToken: z.string().min(1).optional(),\n\t})\n\t.strict();\n\nfunction diagnosticsToAuditEvents(\n\tdiagnostics: readonly PortalBatchDiagnostic[],\n): readonly PortalAuditEvent[] {\n\treturn diagnostics.map((diagnostic) => ({\n\t\tkind: diagnostic.kind,\n\t\tmessage: diagnostic.message,\n\t\t...(diagnostic.namespace !== undefined ? { namespace: diagnostic.namespace } : {}),\n\t}));\n}\n\nfunction isUnknownRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction errorRecordFromUnknown(error: unknown): Record<string, unknown> {\n\treturn isUnknownRecord(error) ? error : {};\n}\n\nfunction messageFromUnknown(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\tconst record = errorRecordFromUnknown(error);\n\tconst message = record.message;\n\treturn typeof message === 'string' ? message : String(error);\n}\n\nfunction errorFromAbortSignal(signal: AbortSignal): Error {\n\tconst reason: unknown = signal.reason;\n\treturn reason instanceof Error ? reason : new Error('MCP Portal core stream aborted.');\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n\tif (signal?.aborted) {\n\t\tthrow errorFromAbortSignal(signal);\n\t}\n}\n\nfunction assertPortalCoreEventSize(event: PortalCoreEvent): void {\n\tconst serialized = JSON.stringify(event);\n\tif (serialized === undefined) {\n\t\treturn;\n\t}\n\tconst byteLength = Buffer.byteLength(serialized, 'utf8');\n\tif (byteLength > maxPortalCoreEventBytes) {\n\t\tthrow new Error(\n\t\t\t`MCP Portal core event exceeded ${String(maxPortalCoreEventBytes)} bytes (${String(byteLength)} bytes).`,\n\t\t);\n\t}\n}\n\nfunction waitForQueuedCoreEvent(props: {\n\treadonly setNotifyQueuedEvent: (notify: (() => void) | undefined) => void;\n\treadonly signal?: AbortSignal;\n}): Promise<void> {\n\tif (props.signal === undefined) {\n\t\treturn new Promise<void>((resolve) => {\n\t\t\tprops.setNotifyQueuedEvent(resolve);\n\t\t});\n\t}\n\tconst signal = props.signal;\n\treturn new Promise<void>((resolve, reject) => {\n\t\tlet settled = false;\n\t\tconst settle = (complete: () => void): void => {\n\t\t\tif (settled) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsettled = true;\n\t\t\tsignal.removeEventListener('abort', onAbort);\n\t\t\tprops.setNotifyQueuedEvent(undefined);\n\t\t\tcomplete();\n\t\t};\n\t\tconst onNotify = (): void => {\n\t\t\tsettle(resolve);\n\t\t};\n\t\tconst onAbort = (): void => {\n\t\t\tsettle(() => reject(errorFromAbortSignal(signal)));\n\t\t};\n\t\tprops.setNotifyQueuedEvent(onNotify);\n\t\tsignal.addEventListener('abort', onAbort, { once: true });\n\t\tif (signal.aborted) {\n\t\t\tonAbort();\n\t\t}\n\t});\n}\n\nfunction itemErrorFromPortalResult(result: PortalToolResult): PortalCoreItemError {\n\tif (result.ok) {\n\t\tthrow new Error('Cannot convert successful portal result into an item error.');\n\t}\n\tconst errorRecord = errorRecordFromUnknown(result.error);\n\tconst kind = errorRecord.kind;\n\tconst namespace = errorRecord.namespace;\n\tconst toolName = errorRecord.toolName;\n\n\treturn {\n\t\tcode: typeof kind === 'string' ? kind : 'portal_item_failed',\n\t\tmessage: messageFromUnknown(result.error),\n\t\t...(typeof namespace === 'string' ? { namespace } : {}),\n\t\t...(typeof toolName === 'string' ? { toolName } : {}),\n\t};\n}\n\nfunction itemResultFromPortalToolResult(\n\trequestId: string,\n\tresult: PortalToolResult,\n): PortalCoreItemResult {\n\tif (!result.ok) {\n\t\treturn {\n\t\t\terror: itemErrorFromPortalResult(result),\n\t\t\trequestId,\n\t\t\tstatus: 'failed',\n\t\t};\n\t}\n\n\treturn {\n\t\tcontent: [{ type: 'json', value: result.output }],\n\t\trequestId,\n\t\tstatus: 'success',\n\t\tstructuredContent: result.output,\n\t};\n}\n\nfunction scalarBatchResultToCoreResult(batchResult: PortalBatchResult): PortalCoreResult {\n\treturn {\n\t\tauditEvents: diagnosticsToAuditEvents(batchResult.diagnostics),\n\t\tcontent: [{ type: 'json', value: batchResult }],\n\t\titems: [],\n\t\tstructuredContent: batchResult,\n\t};\n}\n\nfunction batchItemsToCoreResult(props: {\n\treadonly diagnostics: readonly PortalBatchDiagnostic[];\n\treadonly items: readonly PortalCoreItemResult[];\n}): PortalCoreResult {\n\treturn {\n\t\tauditEvents: diagnosticsToAuditEvents(props.diagnostics),\n\t\tcontent: [],\n\t\titems: props.items,\n\t};\n}\n\nfunction namespaceDescription(namespaces: readonly string[]): string {\n\treturn namespaces.length === 0\n\t\t? 'No upstream MCP namespaces are authorized for this agent scope.'\n\t\t: `Authorized MCP namespaces for this agent scope: ${namespaces.join(', ')}.`;\n}\n\nexport function listPortalCoreToolDescriptors(\n\tnamespaces: readonly string[] = [],\n): readonly PortalCoreToolDescriptor[] {\n\tconst scopeDescription = namespaceDescription(namespaces);\n\treturn [\n\t\t{\n\t\t\tdescription: `List authorized MCP namespaces and compact tool summaries. ${scopeDescription}`,\n\t\t\tinputSchema: portalToolInputSchemas.mcp_portal_list,\n\t\t\tname: 'mcp_portal_list',\n\t\t},\n\t\t{\n\t\t\tdescription: `Search the caller scoped MCP Portal index. ${scopeDescription}`,\n\t\t\tinputSchema: portalToolInputSchemas.mcp_portal_search,\n\t\t\tname: 'mcp_portal_search',\n\t\t},\n\t\t{\n\t\t\tdescription: `Describe exact MCP tool schemas and optional TypeScript/Zod helpers. ${scopeDescription}`,\n\t\t\tinputSchema: portalToolInputSchemas.mcp_portal_describe,\n\t\t\tname: 'mcp_portal_describe',\n\t\t},\n\t\t{\n\t\t\tdescription: `Validate and call an authorized upstream MCP tool by namespace and toolName. ${scopeDescription}`,\n\t\t\tinputSchema: portalToolInputSchemas.mcp_portal_call,\n\t\t\tname: 'mcp_portal_call',\n\t\t},\n\t];\n}\n\nexport async function collectPortalCoreResult(\n\tevents: AsyncIterable<PortalCoreEvent>,\n\toptions: PortalCoreCollectOptions = {},\n): Promise<PortalCoreResult> {\n\tlet result: PortalCoreResult | undefined;\n\tfor await (const event of events) {\n\t\tawait options.onEvent?.(event);\n\t\tif (event.kind === 'completed') {\n\t\t\tresult = event.result;\n\t\t}\n\t\tif (event.kind === 'failed') {\n\t\t\tthrow event.error;\n\t\t}\n\t}\n\tif (result === undefined) {\n\t\tthrow new Error('MCP Portal core stream ended without a completed event.');\n\t}\n\treturn result;\n}\n\nasync function* scalarToolStream(props: {\n\treadonly input: unknown;\n\treadonly scope: PortalAgentScope;\n\treadonly signal?: AbortSignal;\n\treadonly sessionManager: PortalSessionManager;\n\treadonly toolName: Exclude<PortalCoreToolName, 'mcp_portal_call'>;\n\treadonly toolRuntime: PortalToolRuntime;\n}): AsyncIterable<PortalCoreEvent> {\n\tconst handlers = createPortalToolHandlers(props.toolRuntime);\n\tconst handler =\n\t\tprops.toolName === 'mcp_portal_list'\n\t\t\t? handlers.list\n\t\t\t: props.toolName === 'mcp_portal_search'\n\t\t\t\t? handlers.search\n\t\t\t\t: handlers.describe;\n\tthrowIfAborted(props.signal);\n\tconst batchResult = await handler({ identity: props.scope, input: props.input });\n\tthrowIfAborted(props.signal);\n\tyield { kind: 'completed', result: scalarBatchResultToCoreResult(batchResult) };\n}\n\nasync function* callToolStream(props: {\n\treadonly input: unknown;\n\treadonly scope: PortalAgentScope;\n\treadonly signal?: AbortSignal;\n\treadonly toolRuntime: PortalToolRuntime;\n}): AsyncIterable<PortalCoreEvent> {\n\tconst parsedInput = portalCallInputSchema.safeParse(props.input);\n\tconst queuedEvents: PortalCoreEvent[] = [];\n\tlet notifyQueuedEvent: (() => void) | undefined;\n\tlet executionDone = false;\n\tconst pushEvent = (event: PortalCoreEvent): void => {\n\t\tassertPortalCoreEventSize(event);\n\t\tif (queuedEvents.length >= maxQueuedPortalCoreEvents) {\n\t\t\tthrow new Error(`MCP Portal core event queue exceeded ${maxQueuedPortalCoreEvents} events.`);\n\t\t}\n\t\tqueuedEvents.push(event);\n\t\tnotifyQueuedEvent?.();\n\t\tnotifyQueuedEvent = undefined;\n\t};\n\tconst streamingToolRuntime: PortalToolRuntime = {\n\t\t...props.toolRuntime,\n\t\tcallUpstreamTool: async (call) => {\n\t\t\tthrowIfAborted(props.signal);\n\t\t\tpushEvent({\n\t\t\t\tkind: 'item_started',\n\t\t\t\tnamespace: call.namespace,\n\t\t\t\trequestId: call.requestId,\n\t\t\t\ttoolName: call.toolName,\n\t\t\t});\n\t\t\tpushEvent({\n\t\t\t\tkind: 'progress',\n\t\t\t\tmessage: `Calling upstream MCP tool ${call.namespace}.${call.toolName}.`,\n\t\t\t\trequestId: call.requestId,\n\t\t\t});\n\t\t\treturn await props.toolRuntime.callUpstreamTool({\n\t\t\t\t...call,\n\t\t\t\t...(props.signal !== undefined ? { signal: props.signal } : {}),\n\t\t\t\tonEvent: (event) => {\n\t\t\t\t\tif (event.kind === 'progress') {\n\t\t\t\t\t\tpushEvent({\n\t\t\t\t\t\t\tkind: 'progress',\n\t\t\t\t\t\t\t...(event.message !== undefined ? { message: event.message } : {}),\n\t\t\t\t\t\t\t...(event.progress !== undefined ? { progress: event.progress } : {}),\n\t\t\t\t\t\t\trequestId: call.requestId,\n\t\t\t\t\t\t\t...(event.total !== undefined ? { total: event.total } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (event.kind === 'partial_content') {\n\t\t\t\t\t\tpushEvent({\n\t\t\t\t\t\t\tcontent: event.content,\n\t\t\t\t\t\t\tkind: 'partial_content',\n\t\t\t\t\t\t\trequestId: call.requestId,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tpushEvent({\n\t\t\t\t\t\tkind: 'upstream_notification',\n\t\t\t\t\t\tmethod: event.method,\n\t\t\t\t\t\tparams: event.params,\n\t\t\t\t\t\trequestId: call.requestId,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n\tconst handlers = createPortalToolHandlers(streamingToolRuntime);\n\tif (!parsedInput.success) {\n\t\tconst batchResult = await handlers.call({ identity: props.scope, input: props.input });\n\t\tyield { kind: 'completed', result: scalarBatchResultToCoreResult(batchResult) };\n\t\treturn;\n\t}\n\n\tconst itemResults: PortalCoreItemResult[] = [];\n\tconst batchResultPromise = handlers\n\t\t.call({\n\t\t\tidentity: props.scope,\n\t\t\tinput: props.input,\n\t\t})\n\t\t.finally(() => {\n\t\t\texecutionDone = true;\n\t\t\tnotifyQueuedEvent?.();\n\t\t\tnotifyQueuedEvent = undefined;\n\t\t});\n\tconst hasPendingExecutionEvents = (): boolean => !executionDone || queuedEvents.length > 0;\n\twhile (hasPendingExecutionEvents()) {\n\t\tconst event = queuedEvents.shift();\n\t\tif (event !== undefined) {\n\t\t\tyield event;\n\t\t\tcontinue;\n\t\t}\n\t\tthrowIfAborted(props.signal);\n\t\t// Streaming consumes events as they arrive; there is no parallel work to collect here.\n\t\t// eslint-disable-next-line no-await-in-loop\n\t\tawait waitForQueuedCoreEvent({\n\t\t\tsetNotifyQueuedEvent: (notify) => {\n\t\t\t\tnotifyQueuedEvent = notify;\n\t\t\t},\n\t\t\t...(props.signal !== undefined ? { signal: props.signal } : {}),\n\t\t});\n\t}\n\tconst batchResult = await batchResultPromise;\n\tthrowIfAborted(props.signal);\n\tif (batchResult.errors.length > 0) {\n\t\tyield { kind: 'completed', result: scalarBatchResultToCoreResult(batchResult) };\n\t\treturn;\n\t}\n\tfor (const request of parsedInput.data.calls) {\n\t\tconst portalResult = batchResult.results[request.id];\n\t\tconst itemResult =\n\t\t\tportalResult === undefined\n\t\t\t\t? ({\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tcode: 'portal_item_missing',\n\t\t\t\t\t\t\tmessage: `MCP Portal did not return a result for request \"${request.id}\".`,\n\t\t\t\t\t\t\tnamespace: request.namespace,\n\t\t\t\t\t\t\ttoolName: request.toolName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\trequestId: request.id,\n\t\t\t\t\t\tstatus: 'failed',\n\t\t\t\t\t} satisfies PortalCoreItemResult)\n\t\t\t\t: itemResultFromPortalToolResult(request.id, portalResult);\n\t\titemResults.push(itemResult);\n\t\tif (itemResult.status === 'success') {\n\t\t\tyield { kind: 'item_completed', requestId: request.id, result: itemResult };\n\t\t} else {\n\t\t\tyield { error: itemResult.error, kind: 'item_failed', requestId: request.id };\n\t\t}\n\t}\n\n\tyield {\n\t\tkind: 'completed',\n\t\tresult: batchItemsToCoreResult({ diagnostics: batchResult.diagnostics, items: itemResults }),\n\t};\n}\n\nexport function createPortalCore(props: CreatePortalCoreProps): PortalCore {\n\tconst sessionManager = createPortalSessionManager({\n\t\taccessPolicy: props.accessPolicy,\n\t\tcatalogTtlMs: props.catalogTtlMs,\n\t\truntime: props.runtime,\n\t\t...(props.skills !== undefined ? { skills: props.skills } : {}),\n\t\tupstreamNamespaces: props.upstreamNamespaces,\n\t});\n\tconst createdAgentScopeIds = new Set<string>();\n\tconst approval: PortalApprovalEvaluator =\n\t\tprops.approval ??\n\t\t(() => {\n\t\t\tif (props.approvalTrustBoundary === 'openclaw-before-tool-call-hook') {\n\t\t\t\treturn { kind: 'allow' };\n\t\t\t}\n\t\t\tthrow new Error('MCP Portal approval evaluation is not configured.');\n\t\t});\n\tconst toolRuntime: PortalToolRuntime = {\n\t\tapproval,\n\t\tcallUpstreamTool: props.runtime.callUpstreamTool,\n\t\tgetSession: sessionManager.getSession,\n\t};\n\n\tasync function* callStream(call: PortalCoreStreamCall): AsyncIterable<PortalCoreEvent> {\n\t\ttry {\n\t\t\tthrowIfAborted(call.signal);\n\t\t\tyield { kind: 'started', toolName: call.toolName };\n\t\t\tthrowIfAborted(call.signal);\n\t\t\tif (call.toolName === 'mcp_portal_call') {\n\t\t\t\tyield* callToolStream({\n\t\t\t\t\tinput: call.input,\n\t\t\t\t\tscope: call.scope,\n\t\t\t\t\t...(call.signal !== undefined ? { signal: call.signal } : {}),\n\t\t\t\t\ttoolRuntime,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tyield* scalarToolStream({\n\t\t\t\tinput: call.input,\n\t\t\t\tscope: call.scope,\n\t\t\t\t...(call.signal !== undefined ? { signal: call.signal } : {}),\n\t\t\t\tsessionManager,\n\t\t\t\ttoolName: call.toolName,\n\t\t\t\ttoolRuntime,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tyield { error, kind: 'failed' };\n\t\t}\n\t}\n\n\treturn {\n\t\tapproval: {\n\t\t\tevaluateCalls: (calls, scope, approvalToken) => approval(calls, scope, approvalToken),\n\t\t},\n\t\tcallStream,\n\t\tclose: async () => {\n\t\t\tawait Promise.all(\n\t\t\t\t[...createdAgentScopeIds].map((agentScopeId) =>\n\t\t\t\t\tsessionManager.invalidateAgentScope(agentScopeId),\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t\tcollectPortalCoreResult,\n\t\tcreateAgentScope: (input) => {\n\t\t\tconst scope = createPortalAgentIdentity(input);\n\t\t\tcreatedAgentScopeIds.add(scope.agentScopeId);\n\t\t\treturn scope;\n\t\t},\n\t\tdescribeTools: (scope) => {\n\t\t\tconst policy = resolvePortalAccessPolicy({\n\t\t\t\tconfig: props.accessPolicy,\n\t\t\t\tidentity: scope,\n\t\t\t\tupstreamNamespaces: props.upstreamNamespaces,\n\t\t\t});\n\t\t\treturn listPortalCoreToolDescriptors(policy.allowedNamespaces);\n\t\t},\n\t\tinvalidateAgentScope: async (agentScopeId) => {\n\t\t\tcreatedAgentScopeIds.delete(agentScopeId);\n\t\t\tawait sessionManager.invalidateAgentScope(agentScopeId);\n\t\t},\n\t\tinvalidateSession: async (scope) => {\n\t\t\tawait sessionManager.invalidateSession(scope);\n\t\t},\n\t\tupstreamNamespaces: props.upstreamNamespaces,\n\t};\n}\n"],"mappings":";;;;;;;AAcA,eAAe,4BACd,SACA,eAC4C;CAC5C,MAAM,kBAAkB,MAAM,QAAQ,IACrC,OAAO,QAAQ,QAAQ,CAAC,IACvB,OAAO,CAAC,MAAM,YAAY,CAAC,MAAM,MAAM,cAAc,OAAO,CAAC,CAC7D,CACD;CACD,OAAO,OAAO,YAAY,gBAAgB;;AAG3C,eAAe,sBACd,UACA,eACuC;CACvC,IAAI,SAAS,cAAc,SAC1B,OAAO;EACN,MAAM,SAAS;EACf,SAAS,SAAS;EAClB,GAAI,SAAS,QAAQ,KAAA,IAAY,EAAE,GAAG,EAAE,KAAK,SAAS,KAAK;EAC3D,KAAK,MAAM,4BAA4B,SAAS,KAAK,cAAc;EACnE,WAAW,SAAS;EACpB,WAAW;EACX;CAGF,OAAO;EACN,SAAS,MAAM,4BAA4B,SAAS,SAAS,cAAc;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I,KAAK,WAAW,KAAA,IAAY,EAAE,QAAQ,KAAK,QAAQ,GAAG,EAAE;KAC5D;KACA,CAAC;IACF;;GAED,OAAO,iBAAiB;IACvB,OAAO,KAAK;IACZ,OAAO,KAAK;IACZ,GAAI,KAAK,WAAW,KAAA,IAAY,EAAE,QAAQ,KAAK,QAAQ,GAAG,EAAE;IAC5D;IACA,UAAU,KAAK;IACf;IACA,CAAC;WACM,OAAO;GACf,MAAM;IAAE;IAAO,MAAM;IAAU;;;CAIjC,OAAO;EACN,UAAU,EACT,gBAAgB,OAAO,OAAO,kBAAkB,SAAS,OAAO,OAAO,cAAc,EACrF;EACD;EACA,OAAO,YAAY;GAClB,MAAM,QAAQ,IACb,CAAC,GAAG,qBAAqB,CAAC,KAAK,iBAC9B,eAAe,qBAAqB,aAAa,CACjD,CACD;;EAEF;EACA,mBAAmB,UAAU;GAC5B,MAAM,QAAQ,0BAA0B,MAAM;GAC9C,qBAAqB,IAAI,MAAM,aAAa;GAC5C,OAAO;;EAER,gBAAgB,UAAU;GAMzB,OAAO,8BALQ,0BAA0B;IACxC,QAAQ,MAAM;IACd,UAAU;IACV,oBAAoB,MAAM;IAC1B,CAC0C,CAAC,kBAAkB;;EAE/D,sBAAsB,OAAO,iBAAiB;GAC7C,qBAAqB,OAAO,aAAa;GACzC,MAAM,eAAe,qBAAqB,aAAa;;EAExD,mBAAmB,OAAO,UAAU;GACnC,MAAM,eAAe,kBAAkB,MAAM;;EAE9C,oBAAoB,MAAM;EAC1B"}
@@ -0,0 +1,184 @@
1
+ import { n as PortalToolRecord, s as JsonObject } from "./catalog-types-BVuB4Ynx.js";
2
+ import { z } from "zod";
3
+ import { Tool } from "@modelcontextprotocol/sdk/types.js";
4
+
5
+ //#region src/portal-access-policy.d.ts
6
+ declare const portalAgentIdentityBrand: unique symbol;
7
+ type PortalAgentIdentity = {
8
+ readonly agentId: string;
9
+ readonly agentScopeId: string;
10
+ readonly authSubject?: string;
11
+ readonly sessionId?: string;
12
+ readonly sessionKey?: string;
13
+ readonly source: PortalAgentScopeSource;
14
+ readonly [portalAgentIdentityBrand]: true;
15
+ };
16
+ type PortalAgentScopeSource = 'cli-operator' | 'mcp-proxy-bearer' | 'openclaw-trusted';
17
+ interface PortalToolSelector {
18
+ readonly namespace: string;
19
+ readonly toolName: string;
20
+ }
21
+ type PortalDefaultPolicy = 'allow-all' | 'deny-all';
22
+ interface PortalAccessPolicyConfig {
23
+ readonly defaultPolicy?: PortalDefaultPolicy;
24
+ readonly enabledNamespaces?: readonly string[];
25
+ readonly enabledNamespacesByAgent: Readonly<Record<string, readonly string[]>>;
26
+ readonly enabledToolsByAgent?: Readonly<Record<string, readonly PortalToolSelector[]>>;
27
+ readonly hiddenToolsByAgent: Readonly<Record<string, readonly PortalToolSelector[]>>;
28
+ }
29
+ interface ResolvedPortalAccessPolicy {
30
+ readonly allowedNamespaces: readonly string[];
31
+ readonly enabledTools: readonly PortalToolSelector[];
32
+ readonly hiddenTools: readonly PortalToolSelector[];
33
+ }
34
+ declare function createPortalAgentIdentity(input: {
35
+ readonly agentId: string;
36
+ readonly agentScopeId: string;
37
+ readonly authSubject?: string;
38
+ readonly sessionId?: string;
39
+ readonly sessionKey?: string;
40
+ readonly source: PortalAgentScopeSource;
41
+ }): PortalAgentIdentity;
42
+ declare function portalAgentScopeKey(identity: PortalAgentIdentity): string;
43
+ declare function resolvePortalAccessPolicy(props: {
44
+ readonly config: PortalAccessPolicyConfig;
45
+ readonly identity: PortalAgentIdentity;
46
+ readonly upstreamNamespaces: readonly string[];
47
+ }): ResolvedPortalAccessPolicy;
48
+ //#endregion
49
+ //#region src/tool-ref.d.ts
50
+ interface ToolIdentity {
51
+ readonly namespace: string;
52
+ readonly toolName: string;
53
+ }
54
+ declare const toolRefSchema: z.core.$ZodBranded<z.ZodString, "ToolRef", "out">;
55
+ type ToolRef = z.infer<typeof toolRefSchema>;
56
+ declare function encodeToolRef(identity: ToolIdentity): ToolRef;
57
+ declare function decodeToolRef(toolRef: string | ToolRef): ToolIdentity;
58
+ //#endregion
59
+ //#region src/tool-graph.d.ts
60
+ type ToolRelationshipType = 'entity' | 'schema-field' | 'skill';
61
+ interface ToolRelationshipEndpoint extends ToolIdentity {
62
+ readonly toolRef: string;
63
+ }
64
+ interface ToolRelationship {
65
+ readonly field?: string;
66
+ readonly from: ToolRelationshipEndpoint;
67
+ readonly reason: string;
68
+ readonly to: ToolRelationshipEndpoint;
69
+ readonly type: ToolRelationshipType;
70
+ }
71
+ interface SkillGraphInput {
72
+ readonly description?: string;
73
+ readonly tags?: readonly string[];
74
+ readonly title: string;
75
+ readonly toolRefs: readonly string[];
76
+ }
77
+ interface ScopedSkillGraphEntry {
78
+ readonly description?: string;
79
+ readonly tags: readonly string[];
80
+ readonly title: string;
81
+ readonly toolRefs: readonly string[];
82
+ }
83
+ interface ToolGraphInput {
84
+ readonly skills?: readonly SkillGraphInput[];
85
+ readonly tools: readonly PortalToolRecord[];
86
+ }
87
+ interface ToolGraph {
88
+ readonly relationships: readonly ToolRelationship[];
89
+ readonly skills: readonly ScopedSkillGraphEntry[];
90
+ }
91
+ declare function buildToolGraph(input: ToolGraphInput): ToolGraph;
92
+ //#endregion
93
+ //#region src/tool-summary.d.ts
94
+ interface ToolSchemaSummary {
95
+ readonly optional: readonly string[];
96
+ readonly propertyCount: number;
97
+ readonly required: readonly string[];
98
+ readonly type: string;
99
+ }
100
+ interface ToolSafetySummary {
101
+ readonly destructiveHint?: boolean;
102
+ readonly readOnlyHint?: boolean;
103
+ }
104
+ interface ToolSummary {
105
+ readonly description?: string;
106
+ readonly input: ToolSchemaSummary;
107
+ readonly namespace: string;
108
+ readonly output?: ToolSchemaSummary;
109
+ readonly safety: ToolSafetySummary;
110
+ readonly title?: string;
111
+ readonly toolName: string;
112
+ readonly toolRef: string;
113
+ }
114
+ declare function summarizeJsonSchema(schema: JsonObject): ToolSchemaSummary;
115
+ declare function createToolSummary(tool: PortalToolRecord): ToolSummary;
116
+ //#endregion
117
+ //#region src/search-index.d.ts
118
+ interface SearchQuery {
119
+ readonly limit: number;
120
+ readonly namespaces?: readonly string[];
121
+ readonly query?: string;
122
+ }
123
+ interface SearchResultSet {
124
+ readonly results: readonly ToolSearchResult[];
125
+ }
126
+ interface SearchIndex {
127
+ readonly search: (query: SearchQuery) => SearchResultSet;
128
+ }
129
+ interface ToolRelationshipHint {
130
+ readonly field?: string;
131
+ readonly reason: string;
132
+ readonly sourceToolRef: string;
133
+ readonly type: ToolRelationship['type'];
134
+ }
135
+ interface ToolSearchResult extends ToolSummary {
136
+ readonly relationshipHints?: readonly ToolRelationshipHint[];
137
+ readonly schemaFieldMatches?: readonly string[];
138
+ }
139
+ declare function createSearchIndex(tools: readonly PortalToolRecord[], graph?: ToolGraph): SearchIndex;
140
+ //#endregion
141
+ //#region src/portal-session.d.ts
142
+ interface PortalCatalogSnapshot {
143
+ readonly agentScopeId: string;
144
+ readonly discoveryFailures: readonly PortalDiscoveryFailure[];
145
+ readonly generatedAt: string;
146
+ readonly sourceHash: string;
147
+ readonly tools: readonly PortalToolRecord[];
148
+ }
149
+ interface PortalDiscoveryFailure {
150
+ readonly message: string;
151
+ readonly namespace: string;
152
+ }
153
+ interface PortalSession {
154
+ readonly catalog: PortalCatalogSnapshot;
155
+ readonly graph: ToolGraph;
156
+ readonly identity: PortalAgentIdentity;
157
+ readonly searchIndex: SearchIndex;
158
+ }
159
+ interface PortalSessionRuntime {
160
+ readonly closeAgentScope: (agentScopeId: string) => Promise<void> | void;
161
+ readonly closeSession?: (scopeKey: string) => Promise<void> | void;
162
+ readonly listTools: (call: {
163
+ readonly agentScopeId: string;
164
+ readonly namespace: string;
165
+ }) => Promise<readonly Tool[]>;
166
+ }
167
+ interface PortalSessionManagerOptions {
168
+ readonly accessPolicy: PortalAccessPolicyConfig;
169
+ readonly catalogTtlMs: number;
170
+ readonly discoveryFailures?: readonly PortalDiscoveryFailure[];
171
+ readonly now?: () => number;
172
+ readonly runtime: PortalSessionRuntime;
173
+ readonly skills?: readonly SkillGraphInput[];
174
+ readonly upstreamNamespaces: readonly string[];
175
+ }
176
+ interface PortalSessionManager {
177
+ readonly getSession: (identity: PortalAgentIdentity) => Promise<PortalSession>;
178
+ readonly invalidateAgentScope: (agentScopeId: string) => Promise<void>;
179
+ readonly invalidateSession: (identity: PortalAgentIdentity) => Promise<void>;
180
+ }
181
+ declare function createPortalSessionManager(options: PortalSessionManagerOptions): PortalSessionManager;
182
+ //#endregion
183
+ export { encodeToolRef as A, ToolRelationship as C, ToolIdentity as D, buildToolGraph as E, PortalToolSelector as F, ResolvedPortalAccessPolicy as I, createPortalAgentIdentity as L, PortalAgentIdentity as M, PortalAgentScopeSource as N, ToolRef as O, PortalDefaultPolicy as P, portalAgentScopeKey as R, ToolGraphInput as S, ToolRelationshipType as T, createToolSummary as _, PortalSessionManagerOptions as a, SkillGraphInput as b, SearchIndex as c, ToolRelationshipHint as d, ToolSearchResult as f, ToolSummary as g, ToolSchemaSummary as h, PortalSessionManager as i, PortalAccessPolicyConfig as j, decodeToolRef as k, SearchQuery as l, ToolSafetySummary as m, PortalDiscoveryFailure as n, PortalSessionRuntime as o, createSearchIndex as p, PortalSession as r, createPortalSessionManager as s, PortalCatalogSnapshot as t, SearchResultSet as u, summarizeJsonSchema as v, ToolRelationshipEndpoint as w, ToolGraph as x, ScopedSkillGraphEntry as y, resolvePortalAccessPolicy as z };
184
+ //# sourceMappingURL=portal-session-DG2CUjIo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portal-session-DG2CUjIo.d.ts","names":[],"sources":["../src/portal-access-policy.ts","../src/tool-ref.ts","../src/tool-graph.ts","../src/tool-summary.ts","../src/search-index.ts","../src/portal-session.ts"],"mappings":";;;;;cAAM,wBAAA;AAAA,KAEM,mBAAA;EAAA,SACF,OAAA;EAAA,SAIA,YAAA;EAAA,SACA,WAAA;EAAA,SACA,SAAA;EAAA,SACA,UAAA;EAAA,SACA,MAAA,EAAQ,sBAAA;EAAA,UACP,wBAAA;AAAA;A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