@spine-event-engine/ai 0.0.0-stage → 2.0.0-snapshot.23
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/LICENSE +201 -0
- package/README.md +73 -2
- package/REFERENCE.md +238 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/contracts.d.ts +648 -0
- package/dist/internal/contracts.d.ts.map +1 -0
- package/dist/internal/contracts.js +15 -0
- package/dist/internal/contracts.js.map +1 -0
- package/dist/internal/decision.d.ts +54 -0
- package/dist/internal/decision.d.ts.map +1 -0
- package/dist/internal/decision.js +197 -0
- package/dist/internal/decision.js.map +1 -0
- package/dist/internal/execution.d.ts +309 -0
- package/dist/internal/execution.d.ts.map +1 -0
- package/dist/internal/execution.js +143 -0
- package/dist/internal/execution.js.map +1 -0
- package/dist/internal/mcp-protocol.d.ts +282 -0
- package/dist/internal/mcp-protocol.d.ts.map +1 -0
- package/dist/internal/mcp-protocol.js +32 -0
- package/dist/internal/mcp-protocol.js.map +1 -0
- package/dist/internal/mcp.d.ts +36 -0
- package/dist/internal/mcp.d.ts.map +1 -0
- package/dist/internal/mcp.js +144 -0
- package/dist/internal/mcp.js.map +1 -0
- package/dist/internal/model.d.ts +103 -0
- package/dist/internal/model.d.ts.map +1 -0
- package/dist/internal/model.js +292 -0
- package/dist/internal/model.js.map +1 -0
- package/dist/internal/registration.d.ts +102 -0
- package/dist/internal/registration.d.ts.map +1 -0
- package/dist/internal/registration.js +65 -0
- package/dist/internal/registration.js.map +1 -0
- package/dist/internal/registry.d.ts +102 -0
- package/dist/internal/registry.d.ts.map +1 -0
- package/dist/internal/registry.js +250 -0
- package/dist/internal/registry.js.map +1 -0
- package/dist/internal/schema.d.ts +70 -0
- package/dist/internal/schema.d.ts.map +1 -0
- package/dist/internal/schema.js +329 -0
- package/dist/internal/schema.js.map +1 -0
- package/dist/spi/adapter.d.ts +11 -0
- package/dist/spi/adapter.d.ts.map +1 -0
- package/dist/spi/adapter.js +21 -0
- package/dist/spi/adapter.js.map +1 -0
- package/dist/spi/runtime.d.ts +10 -0
- package/dist/spi/runtime.d.ts.map +1 -0
- package/dist/spi/runtime.js +20 -0
- package/dist/spi/runtime.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +37 -3
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, CodeMatters. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
5
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
10
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
11
|
+
* or implied. See the License for the specific language governing permissions and limitations under
|
|
12
|
+
* the License.
|
|
13
|
+
*/
|
|
14
|
+
import { AiOutcome } from "@spine-event-engine/proto/agent";
|
|
15
|
+
/**
|
|
16
|
+
* Rejects a nonterminal tool proposal in incompatible conversation/event contexts.
|
|
17
|
+
*
|
|
18
|
+
* @param content Typed response or terminal System event.
|
|
19
|
+
*/
|
|
20
|
+
export const assertAiOutcomeContext = (content) => {
|
|
21
|
+
if (content.$typeName !== "spine.ts.agent.GenerationResponse") {
|
|
22
|
+
if (content.outcome === AiOutcome.TOOL_REQUESTED)
|
|
23
|
+
throw new TypeError("TOOL_REQUESTED is only a generation response outcome");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const hasCalls = content.toolCalls.length > 0;
|
|
27
|
+
const hasOutput = content.admittedOutput !== undefined;
|
|
28
|
+
if (content.outcome === AiOutcome.TOOL_REQUESTED && (!hasCalls || hasOutput))
|
|
29
|
+
throw new TypeError("TOOL_REQUESTED requires proposals without admitted output");
|
|
30
|
+
if (content.outcome === AiOutcome.ADMITTED && (!hasOutput || hasCalls))
|
|
31
|
+
throw new TypeError("ADMITTED requires output without outstanding proposals");
|
|
32
|
+
if (content.outcome !== AiOutcome.ADMITTED && hasOutput)
|
|
33
|
+
throw new TypeError("Only ADMITTED may carry application output");
|
|
34
|
+
if (content.anthropicContent && content.openaiContent)
|
|
35
|
+
throw new TypeError("Generation response has multiple provider content envelopes");
|
|
36
|
+
if (content.anthropicContent)
|
|
37
|
+
assertAnthropicProjection(content);
|
|
38
|
+
if (content.openaiContent)
|
|
39
|
+
assertOpenAiProjection(content);
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Checks the typed Responses projection without depending on provider SDK data.
|
|
43
|
+
*
|
|
44
|
+
* @param content Generation response with ordered Responses items.
|
|
45
|
+
*/
|
|
46
|
+
const assertOpenAiProjection = (content) => {
|
|
47
|
+
const receipt = content.openaiContent;
|
|
48
|
+
if (!receipt)
|
|
49
|
+
return;
|
|
50
|
+
if ((content.outcome === AiOutcome.ADMITTED || content.outcome === AiOutcome.TOOL_REQUESTED) &&
|
|
51
|
+
!receipt.complete)
|
|
52
|
+
throw new TypeError("Responses receipt incomplete");
|
|
53
|
+
const { text, calls } = projectOpenAiItems(receipt);
|
|
54
|
+
const partialFailure = !receipt.complete &&
|
|
55
|
+
(content.outcome === AiOutcome.FAILED || content.outcome === AiOutcome.REFUSED);
|
|
56
|
+
const savedText = text.join("");
|
|
57
|
+
const textMatches = partialFailure
|
|
58
|
+
? content.rawOutput.startsWith(savedText)
|
|
59
|
+
: savedText === content.rawOutput;
|
|
60
|
+
const callCountMatches = partialFailure
|
|
61
|
+
? calls.length <= content.toolCalls.length
|
|
62
|
+
: calls.length === content.toolCalls.length;
|
|
63
|
+
if (!textMatches ||
|
|
64
|
+
!callCountMatches ||
|
|
65
|
+
calls.some((call, index) => call.providerCallId !== content.toolCalls[index]?.providerCallId ||
|
|
66
|
+
call.toolName !== content.toolCalls[index].toolName ||
|
|
67
|
+
call.argumentsJson !== content.toolCalls[index].argumentsJson))
|
|
68
|
+
throw new TypeError("Responses projection differs from standard fields");
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* @param receipt Ordered typed Responses items.
|
|
72
|
+
* @returns Standard text and tool projection.
|
|
73
|
+
*/
|
|
74
|
+
const projectOpenAiItems = (receipt) => {
|
|
75
|
+
const text = [];
|
|
76
|
+
const calls = [];
|
|
77
|
+
for (const item of receipt.items) {
|
|
78
|
+
if (item.content.case === "message") {
|
|
79
|
+
for (const part of item.content.value.parts) {
|
|
80
|
+
if (part.content.case === "outputText")
|
|
81
|
+
text.push(part.content.value);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if (item.content.case === "functionCall") {
|
|
85
|
+
if (!item.content.value.call)
|
|
86
|
+
throw new TypeError("Responses call missing");
|
|
87
|
+
calls.push(item.content.value.call);
|
|
88
|
+
}
|
|
89
|
+
else if (item.content.case !== "reasoning")
|
|
90
|
+
throw new TypeError("Responses item kind missing");
|
|
91
|
+
}
|
|
92
|
+
return { text, calls };
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Checks that ordered Anthropic blocks project to the journal's standard fields.
|
|
96
|
+
*
|
|
97
|
+
* @param content Generation response with ordered Anthropic content.
|
|
98
|
+
*/
|
|
99
|
+
const assertAnthropicProjection = (content) => {
|
|
100
|
+
const text = [];
|
|
101
|
+
const calls = [];
|
|
102
|
+
for (const block of content.anthropicContent?.blocks ?? [])
|
|
103
|
+
collectAnthropicBlock(content.outcome, block, text, calls);
|
|
104
|
+
if (text.join("") !== content.rawOutput)
|
|
105
|
+
throw new TypeError("Anthropic text projection differs from raw output");
|
|
106
|
+
if (calls.length !== content.toolCalls.length ||
|
|
107
|
+
calls.some((call, index) => {
|
|
108
|
+
const saved = content.toolCalls[index];
|
|
109
|
+
if (saved === undefined)
|
|
110
|
+
return true;
|
|
111
|
+
return (call.providerCallId !== saved.providerCallId ||
|
|
112
|
+
call.toolName !== saved.toolName ||
|
|
113
|
+
call.argumentsJson !== saved.argumentsJson);
|
|
114
|
+
}))
|
|
115
|
+
throw new TypeError("Anthropic tool projection differs from proposals");
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Projects a block while requiring complete reasoning for terminal proposals.
|
|
119
|
+
*
|
|
120
|
+
* @param outcome Saved generation outcome.
|
|
121
|
+
* @param block Ordered Anthropic block.
|
|
122
|
+
* @param text Mutable projected text segments.
|
|
123
|
+
* @param calls Mutable projected tool proposals.
|
|
124
|
+
*/
|
|
125
|
+
const collectAnthropicBlock = (outcome, block, text, calls) => {
|
|
126
|
+
if (block.content.case === "text")
|
|
127
|
+
text.push(block.content.value);
|
|
128
|
+
else if (block.content.case === "toolCall")
|
|
129
|
+
calls.push(block.content.value);
|
|
130
|
+
else if (block.content.case === "thinking") {
|
|
131
|
+
if ((outcome === AiOutcome.TOOL_REQUESTED || outcome === AiOutcome.ADMITTED) &&
|
|
132
|
+
!block.content.value.signature)
|
|
133
|
+
throw new TypeError("Complete Anthropic thinking requires a signature");
|
|
134
|
+
}
|
|
135
|
+
else if (block.content.case === "redactedThinking") {
|
|
136
|
+
if ((outcome === AiOutcome.TOOL_REQUESTED || outcome === AiOutcome.ADMITTED) &&
|
|
137
|
+
!block.content.value.data)
|
|
138
|
+
throw new TypeError("Complete Anthropic redacted thinking requires data");
|
|
139
|
+
}
|
|
140
|
+
else
|
|
141
|
+
throw new TypeError("Anthropic content block kind missing");
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=execution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/internal/execution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAeH,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AA6C5D;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAC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AM,IAAI,SAAS,CAAC,kDAAkD,CAAC,CAAC;IAC5E,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;QACrD,IACE,CAAC,OAAO,KAAK,SAAS,CAAC,cAAc,IAAI,OAAO,KAAK,SAAS,CAAC,QAAQ,CAAC;YACxE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI;YAEzB,MAAM,IAAI,SAAS,CAAC,oDAAoD,CAAC,CAAC;IAC9E,CAAC;;QAAM,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;AACrE,CAAC,CAAC"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import type { AiScope, McpServerDefinition } from "./contracts.js";
|
|
2
|
+
/**
|
|
3
|
+
* Safe, nonretryable failure while preparing a selected MCP catalog.
|
|
4
|
+
*/
|
|
5
|
+
export declare class AiMcpSetupFailure extends Error {
|
|
6
|
+
readonly code: "AUTHENTICATION_REQUIRED" | "UNSUPPORTED_CAPABILITY";
|
|
7
|
+
/**
|
|
8
|
+
* Creates one fixed category without retaining provider or credential text.
|
|
9
|
+
*
|
|
10
|
+
* @param code Supported safe setup failure category.
|
|
11
|
+
*/
|
|
12
|
+
constructor(code: "AUTHENTICATION_REQUIRED" | "UNSUPPORTED_CAPABILITY");
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Durable admission for one physical MCP protocol send.
|
|
16
|
+
*/
|
|
17
|
+
export interface AiMcpMessageTicket {
|
|
18
|
+
/**
|
|
19
|
+
* Runtime-assigned reservation identifier.
|
|
20
|
+
*/
|
|
21
|
+
readonly id: string;
|
|
22
|
+
/**
|
|
23
|
+
* Fenced cancellation signal.
|
|
24
|
+
*/
|
|
25
|
+
readonly signal: AbortSignal;
|
|
26
|
+
/**
|
|
27
|
+
* Absolute send deadline.
|
|
28
|
+
*/
|
|
29
|
+
readonly deadlineEpochMs?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Full decoded response credit, when configured, reserved before dispatch.
|
|
32
|
+
*/
|
|
33
|
+
readonly maxOutputBytes?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Materialized protocol message submitted for durable reservation.
|
|
37
|
+
*/
|
|
38
|
+
export interface AiMcpMessageRequest {
|
|
39
|
+
/**
|
|
40
|
+
* Setup or tool-call phase.
|
|
41
|
+
*/
|
|
42
|
+
readonly phase: "setup" | "call";
|
|
43
|
+
/**
|
|
44
|
+
* Actual MCP JSON-RPC method or HTTP method.
|
|
45
|
+
*/
|
|
46
|
+
readonly method: string;
|
|
47
|
+
/**
|
|
48
|
+
* Exact serialized request-body bytes.
|
|
49
|
+
*/
|
|
50
|
+
readonly inputBytes: number;
|
|
51
|
+
/**
|
|
52
|
+
* Optional full response credit requested for this message.
|
|
53
|
+
*/
|
|
54
|
+
readonly maxOutputBytes?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Runtime-assigned tool call identity, present only for tool dispatch.
|
|
57
|
+
*/
|
|
58
|
+
readonly toolCallId?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Fenced runtime controls for all MCP setup and tool sends.
|
|
62
|
+
*/
|
|
63
|
+
export interface AiMcpProtocolControl {
|
|
64
|
+
/**
|
|
65
|
+
* Invocation cancellation.
|
|
66
|
+
*/
|
|
67
|
+
readonly signal: AbortSignal;
|
|
68
|
+
/**
|
|
69
|
+
* Invocation deadline.
|
|
70
|
+
*/
|
|
71
|
+
readonly deadlineEpochMs?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Reads current epoch milliseconds from the runtime clock.
|
|
74
|
+
*
|
|
75
|
+
* @returns Current epoch milliseconds from the runtime clock.
|
|
76
|
+
*/
|
|
77
|
+
readonly nowEpochMs: () => number;
|
|
78
|
+
/**
|
|
79
|
+
* Checks whether the active execution fence still admits sends.
|
|
80
|
+
*
|
|
81
|
+
* @returns Whether the active execution fence still admits sends.
|
|
82
|
+
*/
|
|
83
|
+
readonly hasAuthority: () => boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Acquires request bytes and full output credit before physical send.
|
|
86
|
+
*
|
|
87
|
+
* @param request Exact physical message and requested credit.
|
|
88
|
+
* @returns Fenced reservation ticket after persistence.
|
|
89
|
+
*/
|
|
90
|
+
readonly reserveMessage: (request: AiMcpMessageRequest) => Promise<AiMcpMessageTicket>;
|
|
91
|
+
/**
|
|
92
|
+
* Records each received chunk, including a crossing chunk, synchronously.
|
|
93
|
+
*
|
|
94
|
+
* @param ticketId Reservation receiving bytes.
|
|
95
|
+
* @param bytes Decoded bytes in this chunk.
|
|
96
|
+
*/
|
|
97
|
+
readonly onReceived: (ticketId: string, bytes: number) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Persists known receipt once a send settles; absent bytes retain uncertain credit.
|
|
100
|
+
*
|
|
101
|
+
* @param ticketId Settled reservation.
|
|
102
|
+
* @param receivedBytes Complete measured decoded bytes; absent after an incomplete response.
|
|
103
|
+
* @returns Completion after durable receipt recording.
|
|
104
|
+
*/
|
|
105
|
+
readonly finishMessage: (ticketId: string, receivedBytes?: number) => Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Credentials resolved by runtime callbacks before protocol construction.
|
|
109
|
+
*/
|
|
110
|
+
export interface AiMcpResolvedConnection {
|
|
111
|
+
/**
|
|
112
|
+
* Scoped HTTP headers; never included in recorded identity.
|
|
113
|
+
*/
|
|
114
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
115
|
+
/**
|
|
116
|
+
* Scoped child environment; never included in recorded identity.
|
|
117
|
+
*/
|
|
118
|
+
readonly environment?: Readonly<Record<string, string>>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Credential-free configured endpoint pinned before protocol dispatch.
|
|
122
|
+
*/
|
|
123
|
+
export interface AiMcpConnectionIdentity {
|
|
124
|
+
/**
|
|
125
|
+
* Registered server identifier.
|
|
126
|
+
*/
|
|
127
|
+
readonly serverId: string;
|
|
128
|
+
/**
|
|
129
|
+
* Registered server revision.
|
|
130
|
+
*/
|
|
131
|
+
readonly revision: string;
|
|
132
|
+
/**
|
|
133
|
+
* `sha256:` followed by the SHA-256 hex digest of the configured HTTP URL, or of
|
|
134
|
+
* JSON.stringify([executable, args, cwd]) for stdio. Resolved headers and
|
|
135
|
+
* environment are excluded. The digest is compared before discovery.
|
|
136
|
+
*/
|
|
137
|
+
readonly endpoint: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Accepted remote tool definition advertised to the selected model.
|
|
141
|
+
*/
|
|
142
|
+
export interface AiMcpToolDefinition {
|
|
143
|
+
/**
|
|
144
|
+
* Exact configured MCP tool name.
|
|
145
|
+
*/
|
|
146
|
+
readonly name: string;
|
|
147
|
+
/**
|
|
148
|
+
* Bounded discovered description.
|
|
149
|
+
*/
|
|
150
|
+
readonly description: string;
|
|
151
|
+
/**
|
|
152
|
+
* Accepted input schema serialized as JSON.
|
|
153
|
+
*/
|
|
154
|
+
readonly inputSchemaJson: string;
|
|
155
|
+
/**
|
|
156
|
+
* Canonical supported output schema, when advertised by the server.
|
|
157
|
+
*/
|
|
158
|
+
readonly outputSchemaJson?: string;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Runtime-selected discovered definition tied to one configured tool reference.
|
|
162
|
+
*/
|
|
163
|
+
export interface AiMcpAdvertisedTool {
|
|
164
|
+
/**
|
|
165
|
+
* Configured MCP server identifier.
|
|
166
|
+
*/
|
|
167
|
+
readonly server: string;
|
|
168
|
+
/**
|
|
169
|
+
* Configured tool name within that server.
|
|
170
|
+
*/
|
|
171
|
+
readonly tool: string;
|
|
172
|
+
/**
|
|
173
|
+
* Bounded discovered description.
|
|
174
|
+
*/
|
|
175
|
+
readonly description: string;
|
|
176
|
+
/**
|
|
177
|
+
* Canonical accepted JSON input schema.
|
|
178
|
+
*/
|
|
179
|
+
readonly inputSchemaJson: string;
|
|
180
|
+
/**
|
|
181
|
+
* Canonical supported output schema retained for request replay comparison.
|
|
182
|
+
*/
|
|
183
|
+
readonly outputSchemaJson?: string;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Bounded MCP result content admitted into a tool response.
|
|
187
|
+
*/
|
|
188
|
+
export type AiMcpResultContent = {
|
|
189
|
+
/**
|
|
190
|
+
* Text result discriminant.
|
|
191
|
+
*/
|
|
192
|
+
readonly kind: "text";
|
|
193
|
+
/**
|
|
194
|
+
* Bounded UTF-8 text.
|
|
195
|
+
*/
|
|
196
|
+
readonly text: string;
|
|
197
|
+
} | {
|
|
198
|
+
/**
|
|
199
|
+
* Structured JSON result discriminant.
|
|
200
|
+
*/
|
|
201
|
+
readonly kind: "json";
|
|
202
|
+
/**
|
|
203
|
+
* Bounded canonical JSON text.
|
|
204
|
+
*/
|
|
205
|
+
readonly json: string;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* One response from an externally dispatched MCP tool.
|
|
209
|
+
*/
|
|
210
|
+
export interface AiMcpToolResult {
|
|
211
|
+
/**
|
|
212
|
+
* Text or structured JSON, without resource or binary content.
|
|
213
|
+
*/
|
|
214
|
+
readonly content: readonly AiMcpResultContent[];
|
|
215
|
+
/**
|
|
216
|
+
* MCP application error flag, distinct from an uncertain transport failure.
|
|
217
|
+
*/
|
|
218
|
+
readonly isError: boolean;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* One registered-server MCP connection; it cannot bypass runtime call intent.
|
|
222
|
+
*/
|
|
223
|
+
export interface AiMcpProtocolSession {
|
|
224
|
+
/**
|
|
225
|
+
* Credential-free server identity for persisted reconnection checks.
|
|
226
|
+
*/
|
|
227
|
+
readonly identity: AiMcpConnectionIdentity;
|
|
228
|
+
/**
|
|
229
|
+
* Lists and validates only configured tool names. A bounded schema or catalog
|
|
230
|
+
* rejection uses AiMcpSetupFailure("UNSUPPORTED_CAPABILITY"). Raw transport,
|
|
231
|
+
* cancellation, storage, and fencing failures reject without that classification.
|
|
232
|
+
*
|
|
233
|
+
* @param allowedNames Registered names allowed for this invocation.
|
|
234
|
+
* @returns Bounded accepted definitions.
|
|
235
|
+
*/
|
|
236
|
+
discover(allowedNames: readonly string[]): Promise<readonly AiMcpToolDefinition[]>;
|
|
237
|
+
/**
|
|
238
|
+
* Validates canonical JSON arguments locally before runtime authorization.
|
|
239
|
+
*
|
|
240
|
+
* @param name Advertised tool name.
|
|
241
|
+
* @param canonicalJson Serialized argument object.
|
|
242
|
+
*/
|
|
243
|
+
validateArguments(name: string, canonicalJson: string): void;
|
|
244
|
+
/**
|
|
245
|
+
* Dispatches one already-authorized and journaled tool call.
|
|
246
|
+
*
|
|
247
|
+
* @param name Advertised tool name.
|
|
248
|
+
* @param canonicalJson Locally validated argument object.
|
|
249
|
+
* @param options Runtime tool identity and call bounds.
|
|
250
|
+
* @returns Bounded text or structured JSON result.
|
|
251
|
+
*/
|
|
252
|
+
call(name: string, canonicalJson: string, options: {
|
|
253
|
+
readonly toolCallId: string;
|
|
254
|
+
readonly signal: AbortSignal;
|
|
255
|
+
readonly deadlineEpochMs?: number;
|
|
256
|
+
readonly maxResultBytes?: number;
|
|
257
|
+
}): Promise<AiMcpToolResult>;
|
|
258
|
+
/**
|
|
259
|
+
* Closes protocol sends and resources.
|
|
260
|
+
*
|
|
261
|
+
* @returns Completion after protocol sends and resources close.
|
|
262
|
+
*/
|
|
263
|
+
close(): Promise<void>;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Optional registration-scoped MCP protocol implementation.
|
|
267
|
+
*/
|
|
268
|
+
export interface AiMcpProtocolFactory {
|
|
269
|
+
/**
|
|
270
|
+
* Creates one selected server connection after runtime authorization.
|
|
271
|
+
*
|
|
272
|
+
* @param options Registered server, scoped credentials, and runtime controls.
|
|
273
|
+
* @returns Negotiated session with credential-free identity.
|
|
274
|
+
*/
|
|
275
|
+
connect(options: {
|
|
276
|
+
readonly server: McpServerDefinition;
|
|
277
|
+
readonly scope: AiScope;
|
|
278
|
+
readonly resolved: AiMcpResolvedConnection;
|
|
279
|
+
readonly control: AiMcpProtocolControl;
|
|
280
|
+
}): Promise<AiMcpProtocolSession>;
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=mcp-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-protocol.d.ts","sourceRoot":"","sources":["../../src/internal/mcp-protocol.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEnE;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAM9B,QAAQ,CAAC,IAAI,EAAE,yBAAyB,GAAG,wBAAwB;IAL/E;;;;OAIG;gBACkB,IAAI,EAAE,yBAAyB,GAAG,wBAAwB;CAQhF;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IAEjC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAEjC;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAE7B;;O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AAE,MAAM,EACZ,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE;QACP,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;QAC7B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;QAClC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;KAClC,GACA,OAAO,CAAC,eAAe,CAAC,CAAC;IAE5B;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,OAAO,CAAC,OAAO,EAAE;QACf,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;QACrC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QACxB,QAAQ,CAAC,QAAQ,EAAE,uBAAuB,CAAC;QAC3C,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;KACxC,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACnC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, CodeMatters. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
5
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
10
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
11
|
+
* or implied. See the License for the specific language governing permissions and limitations under
|
|
12
|
+
* the License.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Safe, nonretryable failure while preparing a selected MCP catalog.
|
|
16
|
+
*/
|
|
17
|
+
export class AiMcpSetupFailure extends Error {
|
|
18
|
+
code;
|
|
19
|
+
/**
|
|
20
|
+
* Creates one fixed category without retaining provider or credential text.
|
|
21
|
+
*
|
|
22
|
+
* @param code Supported safe setup failure category.
|
|
23
|
+
*/
|
|
24
|
+
constructor(code) {
|
|
25
|
+
super(code === "AUTHENTICATION_REQUIRED"
|
|
26
|
+
? "MCP connection authorization denied."
|
|
27
|
+
: "MCP tool capability is unsupported.");
|
|
28
|
+
this.code = code;
|
|
29
|
+
this.name = "AiMcpSetupFailure";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=mcp-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-protocol.js","sourceRoot":"","sources":["../../src/internal/mcp-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAMrB;IALrB;;;;OAIG;IACH,YAAqB,IAA0D;QAC7E,KAAK,CACH,IAAI,KAAK,yBAAyB;YAChC,CAAC,CAAC,sCAAsC;YACxC,CAAC,CAAC,qCAAqC,CAC1C,CAAC;QALiB,SAAI,GAAJ,IAAI,CAAsD;QAM7E,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { McpServerDefinition } from "./contracts.js";
|
|
2
|
+
declare const mcpServerBrand: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* Factory-created MCP server configuration accepted by the registry.
|
|
5
|
+
*/
|
|
6
|
+
export interface McpServerRegistration {
|
|
7
|
+
/**
|
|
8
|
+
* Private marker carried only by a factory-created MCP registration.
|
|
9
|
+
*/
|
|
10
|
+
readonly [mcpServerBrand]: true;
|
|
11
|
+
/**
|
|
12
|
+
* Validated MCP server identifier.
|
|
13
|
+
*/
|
|
14
|
+
readonly id: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Defines application-approved MCP servers without creating a connection.
|
|
18
|
+
*/
|
|
19
|
+
export declare const Mcp: {
|
|
20
|
+
/**
|
|
21
|
+
* Validates and snapshots explicit connection and tool policy.
|
|
22
|
+
*
|
|
23
|
+
* @param definition Application MCP configuration.
|
|
24
|
+
* @returns Factory-created registry entry.
|
|
25
|
+
*/
|
|
26
|
+
server(definition: McpServerDefinition): McpServerRegistration;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Reads a validated MCP policy after checking runtime provenance.
|
|
30
|
+
*
|
|
31
|
+
* @param registration Candidate configuration.
|
|
32
|
+
* @returns Original frozen settings.
|
|
33
|
+
*/
|
|
34
|
+
export declare const mcpDefinition: (registration: McpServerRegistration) => McpServerDefinition;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/internal/mcp.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,mBAAmB,EAA+B,MAAM,gBAAgB,CAAC;AAGvF,QAAA,MAAM,cAAc,EAAE,OAAO,MAAiC,CAAC;AAG/D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE,IAAI,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAuFD;;GAEG;AACH,eAAO,MAAM,GAAG;IACd;;;;;OAKG;uBACgB,mBAAmB,GAAG,qBAAqB;CAoB/D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,cAAc,qBAAqB,KAAG,mBAMnE,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, CodeMatters. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
5
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
10
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
11
|
+
* or implied. See the License for the specific language governing permissions and limitations under
|
|
12
|
+
* the License.
|
|
13
|
+
*/
|
|
14
|
+
import { nonblank, positiveInteger } from "./model.js";
|
|
15
|
+
const mcpServerBrand = Symbol("SpineMcpServer");
|
|
16
|
+
const mcpDefinitions = new WeakMap();
|
|
17
|
+
/**
|
|
18
|
+
* Copies an application-defined transport without retaining mutable arrays.
|
|
19
|
+
*
|
|
20
|
+
* @param transport Streamable HTTP or local stdio configuration.
|
|
21
|
+
* @returns Immutable transport options.
|
|
22
|
+
*/
|
|
23
|
+
const copyTransport = (transport) => {
|
|
24
|
+
if (transport.kind === "streamable-http") {
|
|
25
|
+
let url;
|
|
26
|
+
try {
|
|
27
|
+
url = new URL(nonblank(transport.url, "transport.url"));
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new TypeError("transport.url must be absolute HTTP URL");
|
|
31
|
+
}
|
|
32
|
+
if (!["http:", "https:"].includes(url.protocol))
|
|
33
|
+
throw new TypeError("transport.url must be HTTP or HTTPS");
|
|
34
|
+
if (url.username || url.password)
|
|
35
|
+
throw new TypeError("transport.url cannot embed credentials");
|
|
36
|
+
if (url.hash)
|
|
37
|
+
throw new TypeError("transport.url cannot contain a fragment");
|
|
38
|
+
return Object.freeze({
|
|
39
|
+
kind: "streamable-http",
|
|
40
|
+
url: url.href,
|
|
41
|
+
...(transport.headers ? { headers: transport.headers } : {}),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const kind = transport.kind;
|
|
45
|
+
if (kind !== "stdio")
|
|
46
|
+
throw new TypeError("MCP transport kind is unsupported");
|
|
47
|
+
const executable = nonblank(transport.executable, "transport.executable");
|
|
48
|
+
if (!absolutePath(executable))
|
|
49
|
+
throw new TypeError("transport.executable must be absolute");
|
|
50
|
+
if (transport.cwd && !absolutePath(transport.cwd))
|
|
51
|
+
throw new TypeError("transport.cwd must be absolute");
|
|
52
|
+
if (!Array.isArray(transport.args) || transport.args.some((arg) => typeof arg !== "string"))
|
|
53
|
+
throw new TypeError("transport.args must be fixed strings");
|
|
54
|
+
return Object.freeze({
|
|
55
|
+
kind: "stdio",
|
|
56
|
+
executable,
|
|
57
|
+
args: Object.freeze(Array.from(transport.args, (argument) => argument)),
|
|
58
|
+
...(transport.cwd ? { cwd: transport.cwd } : {}),
|
|
59
|
+
...(transport.environment ? { environment: transport.environment } : {}),
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Checks a configured executable or directory path.
|
|
64
|
+
*
|
|
65
|
+
* @param path Application-supplied path.
|
|
66
|
+
* @returns Whether the path is absolute on POSIX or Windows.
|
|
67
|
+
*/
|
|
68
|
+
const absolutePath = (path) => {
|
|
69
|
+
return path.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(path);
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Copies one bounded authorization policy.
|
|
73
|
+
*
|
|
74
|
+
* @param name Advertised exact tool name.
|
|
75
|
+
* @param policy Application policy.
|
|
76
|
+
* @returns Frozen validated policy.
|
|
77
|
+
*/
|
|
78
|
+
const copyPolicy = (name, policy) => {
|
|
79
|
+
nonblank(name, "tool name");
|
|
80
|
+
const effect = policy.effect;
|
|
81
|
+
if (effect !== "read" && effect !== "write")
|
|
82
|
+
throw new TypeError(`tool ${name} effect is unsupported`);
|
|
83
|
+
if (typeof policy.authorize !== "function")
|
|
84
|
+
throw new TypeError(`tool ${name} authorize is required`);
|
|
85
|
+
return Object.freeze({
|
|
86
|
+
effect: policy.effect,
|
|
87
|
+
...(policy.timeoutMs === undefined
|
|
88
|
+
? {}
|
|
89
|
+
: { timeoutMs: positiveInteger(policy.timeoutMs, `tool ${name} timeoutMs`) }),
|
|
90
|
+
...(policy.maxArgumentBytes === undefined
|
|
91
|
+
? {}
|
|
92
|
+
: {
|
|
93
|
+
maxArgumentBytes: positiveInteger(policy.maxArgumentBytes, `tool ${name} maxArgumentBytes`),
|
|
94
|
+
}),
|
|
95
|
+
...(policy.maxResultBytes === undefined
|
|
96
|
+
? {}
|
|
97
|
+
: { maxResultBytes: positiveInteger(policy.maxResultBytes, `tool ${name} maxResultBytes`) }),
|
|
98
|
+
authorize: policy.authorize,
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Defines application-approved MCP servers without creating a connection.
|
|
103
|
+
*/
|
|
104
|
+
export const Mcp = {
|
|
105
|
+
/**
|
|
106
|
+
* Validates and snapshots explicit connection and tool policy.
|
|
107
|
+
*
|
|
108
|
+
* @param definition Application MCP configuration.
|
|
109
|
+
* @returns Factory-created registry entry.
|
|
110
|
+
*/
|
|
111
|
+
server(definition) {
|
|
112
|
+
const id = nonblank(definition.id, "MCP server id");
|
|
113
|
+
const revision = nonblank(definition.revision, "MCP server revision");
|
|
114
|
+
if (typeof definition.authorizeConnect !== "function")
|
|
115
|
+
throw new TypeError("authorizeConnect callback is required");
|
|
116
|
+
const tools = Object.fromEntries(Object.entries(definition.tools).map(([name, policy]) => [name, copyPolicy(name, policy)]));
|
|
117
|
+
if (Object.keys(tools).length === 0)
|
|
118
|
+
throw new TypeError("MCP server tools are required");
|
|
119
|
+
const copy = Object.freeze({
|
|
120
|
+
id,
|
|
121
|
+
revision,
|
|
122
|
+
transport: copyTransport(definition.transport),
|
|
123
|
+
authorizeConnect: definition.authorizeConnect,
|
|
124
|
+
tools: Object.freeze(tools),
|
|
125
|
+
});
|
|
126
|
+
const registration = Object.freeze({ [mcpServerBrand]: true, id });
|
|
127
|
+
mcpDefinitions.set(registration, copy);
|
|
128
|
+
return registration;
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Reads a validated MCP policy after checking runtime provenance.
|
|
133
|
+
*
|
|
134
|
+
* @param registration Candidate configuration.
|
|
135
|
+
* @returns Original frozen settings.
|
|
136
|
+
*/
|
|
137
|
+
export const mcpDefinition = (registration) => {
|
|
138
|
+
const candidate = registration;
|
|
139
|
+
const definition = typeof candidate === "object" && candidate !== null ? mcpDefinitions.get(candidate) : undefined;
|
|
140
|
+
if (!definition)
|
|
141
|
+
throw new TypeError("MCP registration must come from a factory");
|
|
142
|
+
return definition;
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/internal/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,cAAc,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC/D,MAAM,cAAc,GAAG,IAAI,OAAO,EAA+B,CAAC;AAiBlE;;;;;GAKG;AACH,MAAM,aAAa,GAAG,CAAC,SAAuB,EAAgB,EAAE;IAC9D,IAAI,SAAS,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;QACzC,IAAI,GAAQ,CAAC;QACb,IAAI,CAAC;YACH,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC;QAC1D,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,SAAS,CAAC,yCAAyC,CAAC,CAAC;QACjE,CAAC;QACD,IAAI,CAAE,CAAC,OAAO,EAAE,QAAQ,CAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC;YAC3D,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC,CAAC;QAC7D,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAA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