@spine-event-engine/ai 0.0.0-stage → 2.0.0-snapshot.24

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 (53) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +73 -2
  3. package/REFERENCE.md +238 -0
  4. package/dist/index.d.ts +31 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +26 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/internal/contracts.d.ts +648 -0
  9. package/dist/internal/contracts.d.ts.map +1 -0
  10. package/dist/internal/contracts.js +15 -0
  11. package/dist/internal/contracts.js.map +1 -0
  12. package/dist/internal/decision.d.ts +54 -0
  13. package/dist/internal/decision.d.ts.map +1 -0
  14. package/dist/internal/decision.js +197 -0
  15. package/dist/internal/decision.js.map +1 -0
  16. package/dist/internal/execution.d.ts +309 -0
  17. package/dist/internal/execution.d.ts.map +1 -0
  18. package/dist/internal/execution.js +143 -0
  19. package/dist/internal/execution.js.map +1 -0
  20. package/dist/internal/mcp-protocol.d.ts +282 -0
  21. package/dist/internal/mcp-protocol.d.ts.map +1 -0
  22. package/dist/internal/mcp-protocol.js +32 -0
  23. package/dist/internal/mcp-protocol.js.map +1 -0
  24. package/dist/internal/mcp.d.ts +36 -0
  25. package/dist/internal/mcp.d.ts.map +1 -0
  26. package/dist/internal/mcp.js +144 -0
  27. package/dist/internal/mcp.js.map +1 -0
  28. package/dist/internal/model.d.ts +103 -0
  29. package/dist/internal/model.d.ts.map +1 -0
  30. package/dist/internal/model.js +292 -0
  31. package/dist/internal/model.js.map +1 -0
  32. package/dist/internal/registration.d.ts +102 -0
  33. package/dist/internal/registration.d.ts.map +1 -0
  34. package/dist/internal/registration.js +65 -0
  35. package/dist/internal/registration.js.map +1 -0
  36. package/dist/internal/registry.d.ts +102 -0
  37. package/dist/internal/registry.d.ts.map +1 -0
  38. package/dist/internal/registry.js +250 -0
  39. package/dist/internal/registry.js.map +1 -0
  40. package/dist/internal/schema.d.ts +70 -0
  41. package/dist/internal/schema.d.ts.map +1 -0
  42. package/dist/internal/schema.js +329 -0
  43. package/dist/internal/schema.js.map +1 -0
  44. package/dist/spi/adapter.d.ts +11 -0
  45. package/dist/spi/adapter.d.ts.map +1 -0
  46. package/dist/spi/adapter.js +21 -0
  47. package/dist/spi/adapter.js.map +1 -0
  48. package/dist/spi/runtime.d.ts +10 -0
  49. package/dist/spi/runtime.d.ts.map +1 -0
  50. package/dist/spi/runtime.js +20 -0
  51. package/dist/spi/runtime.js.map +1 -0
  52. package/dist/tsconfig.tsbuildinfo +1 -0
  53. package/package.json +37 -3
@@ -0,0 +1,103 @@
1
+ import type { MessageShape } from "@bufbuild/protobuf";
2
+ import type { MessageSchema } from "@spine-event-engine/core";
3
+ import { type ModelRef as ModelRefMessage } from "@spine-event-engine/proto/agent";
4
+ import type { AiLimits, AiModelDefinition } from "./contracts.js";
5
+ declare const aiModelBrand: unique symbol;
6
+ /**
7
+ * Normalized model definition with an empty limits object when limits are omitted.
8
+ *
9
+ * @typeParam I Input message descriptor.
10
+ * @typeParam O Output message descriptor.
11
+ */
12
+ type NormalizedAiModelDefinition<I extends MessageSchema, O extends MessageSchema> = AiModelDefinition<I, O> & {
13
+ readonly limits: AiLimits;
14
+ };
15
+ /**
16
+ * Factory-created typed capability accepted by the Agent runtime.
17
+ *
18
+ * @typeParam I - Input message descriptor.
19
+ * @typeParam O - Output message descriptor.
20
+ */
21
+ export interface AiModel<I extends MessageSchema, O extends MessageSchema> {
22
+ /**
23
+ * Private marker carried only by a factory-created capability.
24
+ */
25
+ readonly [aiModelBrand]: true;
26
+ /**
27
+ * Validated immutable capability definition.
28
+ */
29
+ readonly definition: Readonly<NormalizedAiModelDefinition<I, O>>;
30
+ }
31
+ /**
32
+ * Checks whether a value came from the capability factory.
33
+ *
34
+ * @param value Untrusted candidate.
35
+ * @returns True only for an original factory result.
36
+ */
37
+ export declare const isAiModel: (value: unknown) => value is AiModel<MessageSchema, MessageSchema>;
38
+ /**
39
+ * Validates a nonblank application-supplied identifier.
40
+ *
41
+ * @param value Text to check.
42
+ * @param field Field named in failures.
43
+ * @returns Validated text without changing its identity.
44
+ */
45
+ export declare const nonblank: (value: string, field: string) => string;
46
+ /**
47
+ * Validates a bounded safe integer.
48
+ *
49
+ * @param value Number to check.
50
+ * @param field Field named in failures.
51
+ * @param allowZero Whether zero is valid.
52
+ * @returns Validated integer.
53
+ */
54
+ export declare const positiveInteger: (value: number, field: string, allowZero?: boolean) => number;
55
+ /**
56
+ * Creates credential-free, semantically validated deployment references.
57
+ */
58
+ export declare const ModelRef: {
59
+ /**
60
+ * Creates a canonical Protobuf deployment reference.
61
+ *
62
+ * @param name Registry deployment name.
63
+ * @param revision Configuration revision.
64
+ * @returns New typed deployment reference.
65
+ */
66
+ of(name: string, revision: string): ModelRefMessage;
67
+ };
68
+ /**
69
+ * Checks a Protobuf deployment reference by value.
70
+ *
71
+ * @param candidate Reference supplied to registration or selection.
72
+ * @returns Key formed from the model name and revision.
73
+ */
74
+ export declare const modelRefKey: (candidate: ModelRefMessage) => string;
75
+ /**
76
+ * Defines factory-created capabilities independent of model connections.
77
+ */
78
+ export declare const AiModel: {
79
+ /**
80
+ * Validates and snapshots a typed application capability.
81
+ *
82
+ * @typeParam I - Input message descriptor.
83
+ * @typeParam O - Output message descriptor.
84
+ * @param definition Generation or decision configuration.
85
+ * @returns Immutable factory-created capability.
86
+ */
87
+ define<I extends MessageSchema, O extends MessageSchema>(definition: AiModelDefinition<I, O>): AiModel<I, O>;
88
+ };
89
+ /**
90
+ * Maps a validated decision result with its declared pure function.
91
+ *
92
+ * @typeParam I - Input message descriptor.
93
+ * @typeParam O - Output message descriptor.
94
+ * @param model Decision capability.
95
+ * @param answers Validated answers.
96
+ * @param input Validated typed input.
97
+ * @returns Typed application output.
98
+ */
99
+ export declare const mapDecision: <I extends MessageSchema, O extends MessageSchema>(model: AiModel<I, O>, answers: Parameters<Extract<AiModelDefinition<I, O>, {
100
+ kind: "decision";
101
+ }>["mapping"]["toMessage"]>[0], input: MessageShape<I>) => MessageShape<O>;
102
+ export {};
103
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/internal/model.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAIL,KAAK,QAAQ,IAAI,eAAe,EACjC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAyB,MAAM,gBAAgB,CAAC;AAGzF,QAAA,MAAM,YAAY,EAAE,OAAO,MAA+B,CAAC;AAG3D;;;;;GAKG;AACH,KAAK,2BAA2B,CAC9B,CAAC,SAAS,aAAa,EACvB,CAAC,SAAS,aAAa,IACrB,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,aAAa,EAAE,CAAC,SAAS,aAAa;IACvE;;OAEG;IACH,QAAQ,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,2BAA2B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CAClE;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,OAAO,CAAC,aAAa,EAAE,aAAa,CAEvF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,MAIvD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,EAAE,mBAAiB,KAAG,MAMjF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ;IACnB;;;;;;OAMG;aACM,MAAM,YAAY,MAAM,GAAG,eAAe;CAMpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,WAAW,eAAe,KAAG,MAWxD,CAAC;AAwLF;;GAEG;AACH,eAAO,MAAM,OAAO;IAClB;;;;;;;OAOG;WACI,CAAC,SAAS,aAAa,EAAE,CAAC,SAAS,aAAa,cACzC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GAClC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;CAQjB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,EAAE,CAAC,SAAS,aAAa,EAC1E,OAAO,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EACpB,SAAS,UAAU,CACjB,OAAO,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,CAC/E,CAAC,CAAC,CAAC,EACJ,OAAO,YAAY,CAAC,CAAC,CAAC,KACrB,YAAY,CAAC,CAAC,CAIhB,CAAC"}
@@ -0,0 +1,292 @@
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 { create } from "@bufbuild/protobuf";
15
+ import { ModelNameSchema, ModelRefSchema, ModelRevisionSchema, } from "@spine-event-engine/proto/agent";
16
+ import { deriveOutputSchema } from "./schema.js";
17
+ const aiModelBrand = Symbol("SpineAiModel");
18
+ const models = new WeakSet();
19
+ /**
20
+ * Checks whether a value came from the capability factory.
21
+ *
22
+ * @param value Untrusted candidate.
23
+ * @returns True only for an original factory result.
24
+ */
25
+ export const isAiModel = (value) => {
26
+ return typeof value === "object" && value !== null && models.has(value);
27
+ };
28
+ /**
29
+ * Validates a nonblank application-supplied identifier.
30
+ *
31
+ * @param value Text to check.
32
+ * @param field Field named in failures.
33
+ * @returns Validated text without changing its identity.
34
+ */
35
+ export const nonblank = (value, field) => {
36
+ if (typeof value !== "string" || value.trim().length === 0)
37
+ throw new TypeError(`${field} must be nonblank`);
38
+ return value;
39
+ };
40
+ /**
41
+ * Validates a bounded safe integer.
42
+ *
43
+ * @param value Number to check.
44
+ * @param field Field named in failures.
45
+ * @param allowZero Whether zero is valid.
46
+ * @returns Validated integer.
47
+ */
48
+ export const positiveInteger = (value, field, allowZero = false) => {
49
+ if (!Number.isSafeInteger(value) || value < (allowZero ? 0 : 1))
50
+ throw new TypeError(`${field} must be a ${allowZero ? "nonnegative" : "positive"} safe integer`);
51
+ return value;
52
+ };
53
+ /**
54
+ * Creates credential-free, semantically validated deployment references.
55
+ */
56
+ export const ModelRef = {
57
+ /**
58
+ * Creates a canonical Protobuf deployment reference.
59
+ *
60
+ * @param name Registry deployment name.
61
+ * @param revision Configuration revision.
62
+ * @returns New typed deployment reference.
63
+ */
64
+ of(name, revision) {
65
+ return create(ModelRefSchema, {
66
+ name: create(ModelNameSchema, { value: nonblank(name, "name") }),
67
+ revision: create(ModelRevisionSchema, { value: nonblank(revision, "revision") }),
68
+ });
69
+ },
70
+ };
71
+ /**
72
+ * Checks a Protobuf deployment reference by value.
73
+ *
74
+ * @param candidate Reference supplied to registration or selection.
75
+ * @returns Key formed from the model name and revision.
76
+ */
77
+ export const modelRefKey = (candidate) => {
78
+ const supplied = candidate;
79
+ if (typeof supplied !== "object" ||
80
+ supplied === null ||
81
+ supplied.$typeName !== ModelRefSchema.typeName)
82
+ throw new TypeError("ModelRef must be a Protobuf deployment reference");
83
+ const name = nonblank(candidate.name?.value ?? "", "ModelRef.name");
84
+ const revision = nonblank(candidate.revision?.value ?? "", "ModelRef.revision");
85
+ return `${String(name.length)}:${name}${String(revision.length)}:${revision}`;
86
+ };
87
+ /**
88
+ * Copies validated, explicitly configured operation limits.
89
+ *
90
+ * @param limits Caller-supplied mutable limits.
91
+ * @param kind Capability kind.
92
+ * @returns Immutable configured limits with absent ceilings preserved.
93
+ */
94
+ const copyLimits = (limits, kind) => {
95
+ if (limits === undefined)
96
+ return Object.freeze({});
97
+ const supplied = limits;
98
+ if (typeof supplied !== "object" || supplied === null)
99
+ throw new TypeError("limits must be an object");
100
+ const copy = {
101
+ ...(limits.modelRequests === undefined
102
+ ? {}
103
+ : { modelRequests: positiveInteger(limits.modelRequests, "modelRequests") }),
104
+ ...(limits.toolCalls === undefined
105
+ ? {}
106
+ : { toolCalls: positiveInteger(limits.toolCalls, "toolCalls", true) }),
107
+ ...(limits.deadlineMs === undefined
108
+ ? {}
109
+ : { deadlineMs: positiveInteger(limits.deadlineMs, "deadlineMs") }),
110
+ ...(limits.maxInputBytes === undefined
111
+ ? {}
112
+ : { maxInputBytes: positiveInteger(limits.maxInputBytes, "maxInputBytes") }),
113
+ ...(limits.maxOutputBytes === undefined
114
+ ? {}
115
+ : { maxOutputBytes: positiveInteger(limits.maxOutputBytes, "maxOutputBytes") }),
116
+ ...(limits.maxOutputTokens !== undefined
117
+ ? { maxOutputTokens: positiveInteger(limits.maxOutputTokens, "maxOutputTokens") }
118
+ : {}),
119
+ };
120
+ if (kind === "decision" && copy.maxOutputTokens !== undefined)
121
+ throw new TypeError("decision maxOutputTokens is unsupported");
122
+ if (kind === "decision" && copy.toolCalls !== undefined && copy.toolCalls !== 0)
123
+ throw new TypeError("decision toolCalls must be zero");
124
+ return Object.freeze(copy);
125
+ };
126
+ /**
127
+ * Copies application tool references without retaining mutable arrays.
128
+ *
129
+ * @param tools Configured references, if any.
130
+ * @returns Immutable deduplicated references.
131
+ */
132
+ const copyTools = (tools) => {
133
+ const keys = new Set();
134
+ return Object.freeze((tools ?? []).map((tool) => {
135
+ const server = nonblank(tool.server, "tool.server");
136
+ const name = nonblank(tool.tool, "tool.tool");
137
+ const key = `${String(server.length)}:${server}${String(name.length)}:${name}`;
138
+ if (keys.has(key))
139
+ throw new TypeError("Duplicate tool reference");
140
+ keys.add(key);
141
+ return Object.freeze({ server, tool: name });
142
+ }));
143
+ };
144
+ /**
145
+ * Copies one declared decision question.
146
+ *
147
+ * @param id Question key.
148
+ * @param question Caller-supplied question.
149
+ * @returns Immutable question and criteria.
150
+ */
151
+ const copyQuestion = (id, question) => {
152
+ nonblank(id, "question ID");
153
+ const instructions = nonblank(question.instructions, `question ${id} instructions`);
154
+ if (question.type === "boolean")
155
+ return Object.freeze({ type: "boolean", instructions });
156
+ if (question.type === "choice") {
157
+ const criteria = Object.fromEntries(Object.entries(question.criteria).map(([key, meaning]) => [
158
+ nonblank(key, `question ${id} choice`),
159
+ nonblank(meaning, `question ${id} meaning`),
160
+ ]));
161
+ if (Object.keys(criteria).length < 2)
162
+ throw new TypeError(`question ${id} needs two choices`);
163
+ return Object.freeze({ type: "choice", instructions, criteria: Object.freeze(criteria) });
164
+ }
165
+ const kind = question.type;
166
+ if (kind !== "score")
167
+ throw new TypeError(`question ${id} has unsupported kind`);
168
+ const criteria = question.criteria.map((level) => nonblank(level, `question ${id} rubric`));
169
+ if (criteria.length < 2)
170
+ throw new TypeError(`question ${id} needs two rubric levels`);
171
+ return Object.freeze({ type: "score", instructions, criteria: Object.freeze(criteria) });
172
+ };
173
+ /**
174
+ * Copies and validates shared definition fields.
175
+ *
176
+ * @typeParam I - Input message descriptor.
177
+ * @typeParam O - Output message descriptor.
178
+ * @param definition Caller-supplied capability.
179
+ * @returns Shared immutable values.
180
+ */
181
+ const copyBase = (definition) => {
182
+ const input = definition.input;
183
+ const output = definition.output;
184
+ if (input?.kind !== "message" ||
185
+ output?.kind !== "message")
186
+ throw new TypeError("input and output must be Protobuf message schemas");
187
+ const validation = definition.validation;
188
+ if (validation && (typeof validation.check !== "function" || !validation.version.trim()))
189
+ throw new TypeError("validation needs a version and check callback");
190
+ return {
191
+ name: nonblank(definition.name, "name"),
192
+ version: nonblank(definition.version, "version"),
193
+ input: definition.input,
194
+ output: definition.output,
195
+ limits: copyLimits(definition.limits, definition.kind),
196
+ ...(validation ? { validation: Object.freeze({ ...validation }) } : {}),
197
+ };
198
+ };
199
+ /**
200
+ * Copies one validated generation or decision declaration.
201
+ *
202
+ * @typeParam I - Input message descriptor.
203
+ * @typeParam O - Output message descriptor.
204
+ * @param definition Caller-supplied capability.
205
+ * @returns Immutable definition snapshot.
206
+ */
207
+ const copyDecision = (definition) => {
208
+ const mapping = definition.mapping;
209
+ if (typeof mapping !== "object" ||
210
+ mapping === null ||
211
+ typeof mapping.toMessage !== "function")
212
+ throw new TypeError("decision mapping is required");
213
+ const questions = Object.fromEntries(Object.entries(definition.questions).map(([id, question]) => [id, copyQuestion(id, question)]));
214
+ if (Object.keys(questions).length === 0)
215
+ throw new TypeError("decision questions are required");
216
+ return Object.freeze({
217
+ ...copyBase(definition),
218
+ kind: "decision",
219
+ questions: Object.freeze(questions),
220
+ requireProbabilities: definition.requireProbabilities ?? false,
221
+ requireIndependentQuestions: definition.requireIndependentQuestions ?? false,
222
+ mapping: Object.freeze({
223
+ version: nonblank(definition.mapping.version, "mapping.version"),
224
+ toMessage: definition.mapping.toMessage,
225
+ }),
226
+ });
227
+ };
228
+ /**
229
+ * Copies a validated capability definition.
230
+ *
231
+ * @typeParam I - Input message descriptor.
232
+ * @typeParam O - Output message descriptor.
233
+ * @param definition Caller-supplied capability.
234
+ * @returns Immutable definition snapshot.
235
+ */
236
+ const copyDefinition = (definition) => {
237
+ if (definition.kind === "generation") {
238
+ const mode = definition.outputMode;
239
+ if (mode !== "native-schema" && mode !== "prompt-and-validate")
240
+ throw new TypeError("outputMode is unsupported");
241
+ deriveOutputSchema(definition.output);
242
+ return Object.freeze({
243
+ ...copyBase(definition),
244
+ kind: "generation",
245
+ instructions: nonblank(definition.instructions, "instructions"),
246
+ outputMode: definition.outputMode,
247
+ tools: copyTools(definition.tools),
248
+ });
249
+ }
250
+ const kind = definition.kind;
251
+ if (kind !== "decision")
252
+ throw new TypeError("model kind is unsupported");
253
+ return copyDecision(definition);
254
+ };
255
+ /**
256
+ * Defines factory-created capabilities independent of model connections.
257
+ */
258
+ export const AiModel = {
259
+ /**
260
+ * Validates and snapshots a typed application capability.
261
+ *
262
+ * @typeParam I - Input message descriptor.
263
+ * @typeParam O - Output message descriptor.
264
+ * @param definition Generation or decision configuration.
265
+ * @returns Immutable factory-created capability.
266
+ */
267
+ define(definition) {
268
+ const model = Object.freeze({
269
+ [aiModelBrand]: true,
270
+ definition: copyDefinition(definition),
271
+ });
272
+ models.add(model);
273
+ return model;
274
+ },
275
+ };
276
+ /**
277
+ * Maps a validated decision result with its declared pure function.
278
+ *
279
+ * @typeParam I - Input message descriptor.
280
+ * @typeParam O - Output message descriptor.
281
+ * @param model Decision capability.
282
+ * @param answers Validated answers.
283
+ * @param input Validated typed input.
284
+ * @returns Typed application output.
285
+ */
286
+ export const mapDecision = (model, answers, input) => {
287
+ const definition = model.definition;
288
+ if (definition.kind !== "decision")
289
+ throw new TypeError("decision capability required");
290
+ return definition.mapping.toMessage(answers, input);
291
+ };
292
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/internal/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,GAEpB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,kBAAkB,E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-engine/core";
2
+ import type { ModelRef } from "@spine-event-engine/proto/agent";
3
+ import type { AiConnectionIdentity, AiControl, AiModelDefinition, AiScope } from "./contracts.js";
4
+ import type { AiBackendExecution, AiBackendOutcome, AiExecutionControl } from "./execution.js";
5
+ import type { AiMcpProtocolFactory } from "./mcp-protocol.js";
6
+ declare const aiBackendBrand: unique symbol;
7
+ /**
8
+ * Adapter-created deployment admitted to an application registry.
9
+ */
10
+ export interface AiBackendRegistration {
11
+ /**
12
+ * Private marker carried only by an adapter-created backend registration.
13
+ */
14
+ readonly [aiBackendBrand]: true;
15
+ /**
16
+ * Credential-free deployment reference.
17
+ */
18
+ readonly ref: ModelRef;
19
+ /**
20
+ * Declared generation or decision kind.
21
+ */
22
+ readonly kind: "generation" | "decision";
23
+ }
24
+ /**
25
+ * SDK-free adapter registration boundary used by optional integrations.
26
+ */
27
+ export interface AiBackendDefinition {
28
+ /**
29
+ * Optional protocol factory used by this backend's registered MCP tools.
30
+ */
31
+ readonly mcp?: AiMcpProtocolFactory;
32
+ /**
33
+ * Credential-free deployment reference.
34
+ */
35
+ readonly ref: ModelRef;
36
+ /**
37
+ * Declared generation or decision kind.
38
+ */
39
+ readonly kind: "generation" | "decision";
40
+ /**
41
+ * Checks whether a deployment supports the declared capability.
42
+ *
43
+ * @param definition Typed capability requested by this registration.
44
+ * @returns Whether the deployment can perform the capability.
45
+ */
46
+ readonly supports: (definition: Readonly<AiModelDefinition<MessageSchema, MessageSchema>>) => boolean;
47
+ /**
48
+ * Resolves the credential-free identity before dispatch.
49
+ *
50
+ * @param scope Authenticated application scope.
51
+ * @param control Deadline and cancellation controls.
52
+ * @returns Credential-free backend identity.
53
+ */
54
+ resolveIdentity(scope: AiScope, control: AiControl): AiConnectionIdentity | Promise<AiConnectionIdentity>;
55
+ /**
56
+ * Checks authorization for one use of the resolved backend identity.
57
+ *
58
+ * @param scope Authenticated application scope.
59
+ * @param identity Resolved backend identity.
60
+ * @param control Deadline and cancellation controls.
61
+ * @returns Whether the backend use is authorized.
62
+ */
63
+ authorizeUse(scope: AiScope, identity: AiConnectionIdentity, control: AiControl): boolean | Promise<boolean>;
64
+ /**
65
+ * Connects after identity and policy checks.
66
+ *
67
+ * @param scope Authenticated application scope.
68
+ * @param expectedIdentity Previously resolved backend identity.
69
+ * @param control Deadline and cancellation controls.
70
+ * @returns Opaque model and checked connection identity.
71
+ */
72
+ connect(scope: AiScope, expectedIdentity: AiConnectionIdentity, control: AiExecutionControl): {
73
+ readonly model: unknown;
74
+ readonly identity: AiConnectionIdentity;
75
+ } | Promise<{
76
+ readonly model: unknown;
77
+ readonly identity: AiConnectionIdentity;
78
+ }>;
79
+ /**
80
+ * Executes one selected capability through fenced runtime controls.
81
+ *
82
+ * @param request Authenticated connection, typed capability, and runtime controls.
83
+ * @returns Admitted output or safe operational failure.
84
+ */
85
+ execute(request: AiBackendExecution): Promise<AiBackendOutcome>;
86
+ }
87
+ /**
88
+ * Creates a factory-proven deployment for the optional adapter.
89
+ *
90
+ * @param definition Static capability and trusted connection callbacks.
91
+ * @returns Immutable registration.
92
+ */
93
+ export declare const createBackendRegistration: (definition: AiBackendDefinition) => AiBackendRegistration;
94
+ /**
95
+ * Reads the original adapter definition after runtime provenance validation.
96
+ *
97
+ * @param registration Candidate registration.
98
+ * @returns Frozen adapter callbacks and reference.
99
+ */
100
+ export declare const backendDefinition: (registration: AiBackendRegistration) => AiBackendDefinition;
101
+ export {};
102
+ //# sourceMappingURL=registration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../src/internal/registration.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAElG,OAAO,KAAK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QAAC,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAA;KAAE,GACpE,OAAO,CAAC;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAA;KAAE,CAAC,CAAC;IAElF;;;;;OAKG;IACH,OAAO,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACjE;AAED;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,GACpC,YAAY,mBAAmB,KAC9B,qBAyBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,cAAc,qBAAqB,KAAG,mBAQvE,CAAC"}
@@ -0,0 +1,65 @@
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 { modelRefKey, nonblank } from "./model.js";
15
+ const aiBackendBrand = Symbol("SpineAiBackend");
16
+ const backendDefinitions = new WeakMap();
17
+ /**
18
+ * Creates a factory-proven deployment for the optional adapter.
19
+ *
20
+ * @param definition Static capability and trusted connection callbacks.
21
+ * @returns Immutable registration.
22
+ */
23
+ export const createBackendRegistration = (definition) => {
24
+ modelRefKey(definition.ref);
25
+ const kind = definition.kind;
26
+ if (kind !== "generation" && kind !== "decision")
27
+ throw new TypeError("backend kind is unsupported");
28
+ for (const name of ["supports", "resolveIdentity", "authorizeUse", "connect", "execute"])
29
+ if (typeof definition[name] !== "function")
30
+ throw new TypeError(`${name} callback is required`);
31
+ const ref = Object.freeze({
32
+ ...definition.ref,
33
+ name: Object.freeze({
34
+ ...definition.ref.name,
35
+ value: nonblank(definition.ref.name?.value ?? "", "name"),
36
+ }),
37
+ revision: Object.freeze({
38
+ ...definition.ref.revision,
39
+ value: nonblank(definition.ref.revision?.value ?? "", "revision"),
40
+ }),
41
+ });
42
+ const registration = Object.freeze({
43
+ [aiBackendBrand]: true,
44
+ ref,
45
+ kind: definition.kind,
46
+ });
47
+ backendDefinitions.set(registration, Object.freeze({ ...definition, ref }));
48
+ return registration;
49
+ };
50
+ /**
51
+ * Reads the original adapter definition after runtime provenance validation.
52
+ *
53
+ * @param registration Candidate registration.
54
+ * @returns Frozen adapter callbacks and reference.
55
+ */
56
+ export const backendDefinition = (registration) => {
57
+ const candidate = registration;
58
+ const definition = typeof candidate === "object" && candidate !== null
59
+ ? backendDefinitions.get(candidate)
60
+ : undefined;
61
+ if (!definition)
62
+ throw new TypeError("backend registration must come from a factory");
63
+ return definition;
64
+ };
65
+ //# sourceMappingURL=registration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registration.js","sourceRoot":"","sources":["../../src/internal/registration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAInD,MAAM,cAAc,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC/D,MAAM,kBAAkB,GAAG,IAAI,OAAO,EAA+B,CAAC;AAsGtE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,UAA+B,EACR,EAAE;IACzB,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,IAAI,GAAY,UAAU,CAAC,IAAI,CAAC;IACtC,IAAI,IAAI,KAAK,YAAY,IAAI,IAAI,KAAK,UAAU;QAC9C,MAAM,IAAI,SAAS,CAAC,6BAA6B,CAAC,CAAC;IACrD,KAAK,MAAM,IAAI,IAAI,CAAC,UAAU,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