@independo/inderun-contracts 0.3.0-dev.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/generated/schemas.d.ts +4 -4
- package/dist/generated/schemas.js +4 -4
- package/dist/generated/stream-event.d.ts +9 -3
- package/dist/generated/stream-event.d.ts.map +1 -1
- package/dist/generated/task-result.d.ts +8 -5
- package/dist/generated/task-result.d.ts.map +1 -1
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/package.json +12 -6
- package/src/generated/http-request.ts +34 -0
- package/src/generated/http-response.ts +24 -0
- package/src/generated/inderun-error.ts +55 -0
- package/src/generated/index.ts +15 -0
- package/src/generated/model-package.ts +191 -0
- package/src/generated/route-plan.ts +78 -0
- package/src/generated/route-planner-input.ts +161 -0
- package/src/generated/schemas.ts +1691 -0
- package/src/generated/stream-event.ts +154 -0
- package/src/generated/stream-run.ts +32 -0
- package/src/generated/stream-terminal-outcome.ts +186 -0
- package/src/generated/task-request.ts +183 -0
- package/src/generated/task-result.ts +114 -0
- package/src/generated/telemetry-event.ts +29 -0
- package/src/host.ts +205 -0
- package/src/index.ts +100 -0
- package/src/types.ts +32 -0
- package/src/validators.ts +288 -0
|
@@ -0,0 +1,1691 @@
|
|
|
1
|
+
/* This file was generated from JSON Schema. Do not edit by hand. */
|
|
2
|
+
|
|
3
|
+
export const taskRequestSchema = {
|
|
4
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
5
|
+
"$id": "https://schemas.inderun.dev/1.0/task-request.schema.json",
|
|
6
|
+
"title": "TaskRequest",
|
|
7
|
+
"description": "The request payload for a Mode 1 (request/response) text-to-text execution. At least one of `prompt` (single-turn) or `messages` (multi-turn) must be present — both may be present together, though callers should typically supply just one; `constraints`/`preferences` steer routing but never select a provider directly.",
|
|
8
|
+
"type": "object",
|
|
9
|
+
"additionalProperties": true,
|
|
10
|
+
"required": [
|
|
11
|
+
"schemaVersion",
|
|
12
|
+
"task"
|
|
13
|
+
],
|
|
14
|
+
"anyOf": [
|
|
15
|
+
{
|
|
16
|
+
"required": [
|
|
17
|
+
"prompt"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"required": [
|
|
22
|
+
"messages"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"properties": {
|
|
27
|
+
"schemaVersion": {
|
|
28
|
+
"description": "Contract schema version used to interpret the request payload.",
|
|
29
|
+
"const": "1.0"
|
|
30
|
+
},
|
|
31
|
+
"requestId": {
|
|
32
|
+
"description": "Optional identifier for tracking or correlating this specific execution attempt.",
|
|
33
|
+
"type": "string",
|
|
34
|
+
"minLength": 1
|
|
35
|
+
},
|
|
36
|
+
"task": {
|
|
37
|
+
"description": "A descriptor specifying the type of work to be performed. For text-to-text, the kind must be 'text_to_text'.",
|
|
38
|
+
"type": "object",
|
|
39
|
+
"additionalProperties": true,
|
|
40
|
+
"required": [
|
|
41
|
+
"kind"
|
|
42
|
+
],
|
|
43
|
+
"properties": {
|
|
44
|
+
"kind": {
|
|
45
|
+
"description": "The standard task category. Currently supports 'text_to_text' for prompt-based interactions.",
|
|
46
|
+
"const": "text_to_text"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"prompt": {
|
|
51
|
+
"description": "A simple, single-turn text prompt used to trigger a response from the AI model.",
|
|
52
|
+
"type": "string",
|
|
53
|
+
"minLength": 1
|
|
54
|
+
},
|
|
55
|
+
"messages": {
|
|
56
|
+
"description": "A list of interaction messages for multi-turn conversation or chat-style execution.",
|
|
57
|
+
"type": "array",
|
|
58
|
+
"minItems": 1,
|
|
59
|
+
"items": {
|
|
60
|
+
"description": "An individual message in a conversation.",
|
|
61
|
+
"type": "object",
|
|
62
|
+
"additionalProperties": true,
|
|
63
|
+
"required": [
|
|
64
|
+
"role",
|
|
65
|
+
"content"
|
|
66
|
+
],
|
|
67
|
+
"properties": {
|
|
68
|
+
"role": {
|
|
69
|
+
"description": "The role of the author (e.g., 'user', 'assistant').",
|
|
70
|
+
"enum": [
|
|
71
|
+
"system",
|
|
72
|
+
"user",
|
|
73
|
+
"assistant"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
"content": {
|
|
77
|
+
"description": "The actual text content of the message.",
|
|
78
|
+
"type": "string",
|
|
79
|
+
"minLength": 1
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"generation": {
|
|
85
|
+
"description": "Optional configuration for fine-tuning how the AI model generates its response.",
|
|
86
|
+
"type": "object",
|
|
87
|
+
"additionalProperties": true,
|
|
88
|
+
"properties": {
|
|
89
|
+
"maxOutputTokens": {
|
|
90
|
+
"description": "The maximum number of tokens to generate in a single response.",
|
|
91
|
+
"type": "integer",
|
|
92
|
+
"minimum": 1
|
|
93
|
+
},
|
|
94
|
+
"temperature": {
|
|
95
|
+
"description": "Controls the randomness of the output. Range: 0 (most deterministic) to 2 (highest variance).",
|
|
96
|
+
"type": "number",
|
|
97
|
+
"minimum": 0,
|
|
98
|
+
"maximum": 2
|
|
99
|
+
},
|
|
100
|
+
"topP": {
|
|
101
|
+
"description": "Nucleus sampling parameter for controlling diversity vs focus in the output.",
|
|
102
|
+
"type": "number",
|
|
103
|
+
"minimum": 0,
|
|
104
|
+
"maximum": 1
|
|
105
|
+
},
|
|
106
|
+
"seed": {
|
|
107
|
+
"description": "A fixed seed for deterministic generation (where supported by the underlying provider).",
|
|
108
|
+
"type": "integer"
|
|
109
|
+
},
|
|
110
|
+
"stop": {
|
|
111
|
+
"description": "Sequence tokens that should terminate the generation process.",
|
|
112
|
+
"type": "array",
|
|
113
|
+
"items": {
|
|
114
|
+
"type": "string"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"constraints": {
|
|
120
|
+
"description": "Request-level routing constraints used by the planner.",
|
|
121
|
+
"type": "object",
|
|
122
|
+
"additionalProperties": true,
|
|
123
|
+
"properties": {
|
|
124
|
+
"privacy": {
|
|
125
|
+
"description": "Privacy requirement or preference for execution placement.",
|
|
126
|
+
"enum": [
|
|
127
|
+
"local_required",
|
|
128
|
+
"local_preferred",
|
|
129
|
+
"cloud_allowed",
|
|
130
|
+
"cloud_required"
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
"cloud": {
|
|
134
|
+
"description": "Cloud execution constraint.",
|
|
135
|
+
"enum": [
|
|
136
|
+
"forbidden",
|
|
137
|
+
"allowed",
|
|
138
|
+
"required"
|
|
139
|
+
]
|
|
140
|
+
},
|
|
141
|
+
"timeoutMs": {
|
|
142
|
+
"description": "Optional routing timeout budget in milliseconds.",
|
|
143
|
+
"type": "integer",
|
|
144
|
+
"minimum": 1
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
"preferences": {
|
|
149
|
+
"description": "Soft routing preferences used for deterministic provider ordering.",
|
|
150
|
+
"type": "object",
|
|
151
|
+
"additionalProperties": true,
|
|
152
|
+
"properties": {
|
|
153
|
+
"optimizeFor": {
|
|
154
|
+
"description": "Primary optimization goal when multiple providers remain eligible.",
|
|
155
|
+
"enum": [
|
|
156
|
+
"privacy",
|
|
157
|
+
"latency",
|
|
158
|
+
"cost",
|
|
159
|
+
"balanced"
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"telemetry": {
|
|
165
|
+
"description": "Execution preferences for tracking usage and performance metrics.",
|
|
166
|
+
"type": "object",
|
|
167
|
+
"additionalProperties": true,
|
|
168
|
+
"properties": {
|
|
169
|
+
"consent": {
|
|
170
|
+
"description": "Whether the user consents to telemetry collection for this specific request.",
|
|
171
|
+
"type": "boolean"
|
|
172
|
+
},
|
|
173
|
+
"level": {
|
|
174
|
+
"description": "The granularity of the collected metrics (off, minimal, or debug).",
|
|
175
|
+
"enum": [
|
|
176
|
+
"off",
|
|
177
|
+
"minimal",
|
|
178
|
+
"debug"
|
|
179
|
+
]
|
|
180
|
+
},
|
|
181
|
+
"tags": {
|
|
182
|
+
"description": "Optional key-value pairs for correlating telemetry data with specific features or users.",
|
|
183
|
+
"type": "object",
|
|
184
|
+
"additionalProperties": {
|
|
185
|
+
"type": "string"
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
"authContextRef": {
|
|
191
|
+
"description": "A unique identifier used to retrieve credentials from a secure local storage. Raw sensitive keys (API keys, etc.) should NEVER be placed directly in the request payload.",
|
|
192
|
+
"type": "string",
|
|
193
|
+
"minLength": 1
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} as const;
|
|
197
|
+
|
|
198
|
+
export const taskResultSchema = {
|
|
199
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
200
|
+
"$id": "https://schemas.inderun.dev/1.0/task-result.schema.json",
|
|
201
|
+
"title": "TaskResult",
|
|
202
|
+
"description": "The response payload for a completed text-to-text execution. A full execution failure (validation, routing, or every attempted provider failing) is surfaced by run() throwing an IndeRunError instead of returning a TaskResult; finishReason and telemetry.errorClass are reserved for a provider reporting a non-fatal, degraded outcome on an otherwise-successful result (finishReason 'error' is produced by the Android ML Kit GenAI provider; telemetry.errorClass is not currently set by any provider in this codebase).",
|
|
203
|
+
"type": "object",
|
|
204
|
+
"additionalProperties": true,
|
|
205
|
+
"required": [
|
|
206
|
+
"schemaVersion",
|
|
207
|
+
"runId",
|
|
208
|
+
"output",
|
|
209
|
+
"finishReason",
|
|
210
|
+
"telemetry"
|
|
211
|
+
],
|
|
212
|
+
"properties": {
|
|
213
|
+
"schemaVersion": {
|
|
214
|
+
"description": "Contract schema version used to interpret the result payload.",
|
|
215
|
+
"const": "1.0"
|
|
216
|
+
},
|
|
217
|
+
"runId": {
|
|
218
|
+
"description": "A unique, opaque identifier assigned by the engine for this specific execution attempt.",
|
|
219
|
+
"type": "string",
|
|
220
|
+
"minLength": 1
|
|
221
|
+
},
|
|
222
|
+
"output": {
|
|
223
|
+
"description": "The normalized content returned from the selected provider.",
|
|
224
|
+
"type": "object",
|
|
225
|
+
"additionalProperties": true,
|
|
226
|
+
"required": [
|
|
227
|
+
"type",
|
|
228
|
+
"text"
|
|
229
|
+
],
|
|
230
|
+
"properties": {
|
|
231
|
+
"type": {
|
|
232
|
+
"description": "Output payload category (e.g., 'text' for Mode 1 text-to-text).",
|
|
233
|
+
"const": "text"
|
|
234
|
+
},
|
|
235
|
+
"text": {
|
|
236
|
+
"description": "The actual text generated by the execution.",
|
|
237
|
+
"type": "string"
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
"finishReason": {
|
|
242
|
+
"description": "How generation ended: 'stop' (natural end), 'length' (hit maxOutputTokens), or 'cancelled'. 'error' is reserved for a provider reporting a non-fatal issue on an otherwise-returned result — the Android ML Kit GenAI provider produces it when Gemini Nano reports a finish reason that is neither a natural stop nor the token limit. A full execution failure is instead surfaced by run() throwing an IndeRunError.",
|
|
243
|
+
"enum": [
|
|
244
|
+
"stop",
|
|
245
|
+
"length",
|
|
246
|
+
"cancelled",
|
|
247
|
+
"error"
|
|
248
|
+
]
|
|
249
|
+
},
|
|
250
|
+
"usage": {
|
|
251
|
+
"description": "Optional metadata regarding the quantity of tokens processed by the provider.",
|
|
252
|
+
"type": "object",
|
|
253
|
+
"additionalProperties": true,
|
|
254
|
+
"properties": {
|
|
255
|
+
"inputTokens": {
|
|
256
|
+
"description": "Number of input tokens consumed, as reported by the provider.",
|
|
257
|
+
"type": "integer",
|
|
258
|
+
"minimum": 0
|
|
259
|
+
},
|
|
260
|
+
"outputTokens": {
|
|
261
|
+
"description": "Number of output tokens generated, as reported by the provider.",
|
|
262
|
+
"type": "integer",
|
|
263
|
+
"minimum": 0
|
|
264
|
+
},
|
|
265
|
+
"totalTokens": {
|
|
266
|
+
"description": "Aggregated token count for this request, as reported by the provider.",
|
|
267
|
+
"type": "integer",
|
|
268
|
+
"minimum": 0
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
"telemetry": {
|
|
273
|
+
"description": "Required metadata providing an overview of the execution result and performance metrics.",
|
|
274
|
+
"type": "object",
|
|
275
|
+
"additionalProperties": true,
|
|
276
|
+
"required": [
|
|
277
|
+
"providerUsed",
|
|
278
|
+
"totalMs"
|
|
279
|
+
],
|
|
280
|
+
"properties": {
|
|
281
|
+
"providerUsed": {
|
|
282
|
+
"description": "The identifier for the specific provider that handled the request (e.g., 'openai_compatible_cloud').",
|
|
283
|
+
"type": "string",
|
|
284
|
+
"minLength": 1
|
|
285
|
+
},
|
|
286
|
+
"totalMs": {
|
|
287
|
+
"description": "Measured execution duration in milliseconds, including route selection and result processing.",
|
|
288
|
+
"type": "number",
|
|
289
|
+
"minimum": 0
|
|
290
|
+
},
|
|
291
|
+
"errorClass": {
|
|
292
|
+
"description": "Present only if a provider reports a degraded outcome on an otherwise-successful result; no provider in this codebase currently sets this. Distinct from run() throwing — a thrown IndeRunError never produces a TaskResult at all.",
|
|
293
|
+
"enum": [
|
|
294
|
+
"CapabilityMismatch",
|
|
295
|
+
"Offline",
|
|
296
|
+
"AuthError",
|
|
297
|
+
"RateLimited",
|
|
298
|
+
"Timeout",
|
|
299
|
+
"Unavailable",
|
|
300
|
+
"Internal"
|
|
301
|
+
]
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
} as const;
|
|
307
|
+
|
|
308
|
+
export const inderunErrorSchema = {
|
|
309
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
310
|
+
"$id": "https://schemas.inderun.dev/1.0/inderun-error.schema.json",
|
|
311
|
+
"title": "IndeRunError",
|
|
312
|
+
"description": "The error shape thrown by run() (wrapped in an IndeRunException) when execution fails — via validation, routing (no eligible provider), or every attempted provider failing. Never returned as part of a successful TaskResult.",
|
|
313
|
+
"type": "object",
|
|
314
|
+
"additionalProperties": true,
|
|
315
|
+
"required": [
|
|
316
|
+
"schemaVersion",
|
|
317
|
+
"errorClass",
|
|
318
|
+
"message"
|
|
319
|
+
],
|
|
320
|
+
"properties": {
|
|
321
|
+
"schemaVersion": {
|
|
322
|
+
"description": "Contract schema version used to interpret the error payload.",
|
|
323
|
+
"const": "1.0"
|
|
324
|
+
},
|
|
325
|
+
"errorClass": {
|
|
326
|
+
"description": "Normalized error taxonomy, shared with TaskResult.telemetry.errorClass: CapabilityMismatch (request needs something no eligible provider supports), Offline/Unavailable (provider unreachable or not ready), AuthError (credential/auth failure), RateLimited (provider throttled the request), Timeout (provider exceeded its execution budget), Internal (unexpected engine-side failure).",
|
|
327
|
+
"enum": [
|
|
328
|
+
"CapabilityMismatch",
|
|
329
|
+
"Offline",
|
|
330
|
+
"AuthError",
|
|
331
|
+
"RateLimited",
|
|
332
|
+
"Timeout",
|
|
333
|
+
"Unavailable",
|
|
334
|
+
"Internal"
|
|
335
|
+
]
|
|
336
|
+
},
|
|
337
|
+
"message": {
|
|
338
|
+
"description": "Human-readable error message suitable for logs and developer diagnostics.",
|
|
339
|
+
"type": "string",
|
|
340
|
+
"minLength": 1
|
|
341
|
+
},
|
|
342
|
+
"runId": {
|
|
343
|
+
"description": "Opaque run identifier associated with the failed execution, if available.",
|
|
344
|
+
"type": "string",
|
|
345
|
+
"minLength": 1
|
|
346
|
+
},
|
|
347
|
+
"providerId": {
|
|
348
|
+
"description": "Identifier of the provider associated with the failure, if execution reached a provider.",
|
|
349
|
+
"type": "string",
|
|
350
|
+
"minLength": 1
|
|
351
|
+
},
|
|
352
|
+
"retryable": {
|
|
353
|
+
"description": "Whether retrying the same request may succeed.",
|
|
354
|
+
"type": "boolean"
|
|
355
|
+
},
|
|
356
|
+
"retryAfterMs": {
|
|
357
|
+
"description": "Optional suggested delay before retrying, in milliseconds.",
|
|
358
|
+
"type": "integer",
|
|
359
|
+
"minimum": 0
|
|
360
|
+
},
|
|
361
|
+
"details": {
|
|
362
|
+
"description": "Optional structured diagnostic details. It must not contain raw secrets.",
|
|
363
|
+
"type": "object",
|
|
364
|
+
"additionalProperties": true
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
} as const;
|
|
368
|
+
|
|
369
|
+
export const httpRequestSchema = {
|
|
370
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
371
|
+
"$id": "https://schemas.inderun.dev/1.0/http-request.schema.json",
|
|
372
|
+
"title": "HttpRequest",
|
|
373
|
+
"description": "Normalized HTTP request payload for host-provided cloud transport.",
|
|
374
|
+
"type": "object",
|
|
375
|
+
"additionalProperties": true,
|
|
376
|
+
"required": [
|
|
377
|
+
"method",
|
|
378
|
+
"url"
|
|
379
|
+
],
|
|
380
|
+
"properties": {
|
|
381
|
+
"method": {
|
|
382
|
+
"description": "HTTP method to use for the request.",
|
|
383
|
+
"enum": [
|
|
384
|
+
"GET",
|
|
385
|
+
"POST",
|
|
386
|
+
"PUT",
|
|
387
|
+
"DELETE",
|
|
388
|
+
"PATCH"
|
|
389
|
+
]
|
|
390
|
+
},
|
|
391
|
+
"url": {
|
|
392
|
+
"description": "Absolute target URL for the provider transport request.",
|
|
393
|
+
"type": "string",
|
|
394
|
+
"minLength": 1
|
|
395
|
+
},
|
|
396
|
+
"headers": {
|
|
397
|
+
"description": "HTTP headers to send after the provider adapter has applied any required transport-level credentials.",
|
|
398
|
+
"type": "object",
|
|
399
|
+
"additionalProperties": {
|
|
400
|
+
"type": "string"
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
"body": {
|
|
404
|
+
"description": "Optional serialized request body. For JSON APIs this should be a JSON string.",
|
|
405
|
+
"type": "string"
|
|
406
|
+
},
|
|
407
|
+
"timeoutMs": {
|
|
408
|
+
"description": "Optional maximum duration for the host transport attempt in milliseconds.",
|
|
409
|
+
"type": "integer",
|
|
410
|
+
"minimum": 1
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
} as const;
|
|
414
|
+
|
|
415
|
+
export const httpResponseSchema = {
|
|
416
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
417
|
+
"$id": "https://schemas.inderun.dev/1.0/http-response.schema.json",
|
|
418
|
+
"title": "HttpResponse",
|
|
419
|
+
"description": "Normalized HTTP response payload returned by host-provided cloud transport.",
|
|
420
|
+
"type": "object",
|
|
421
|
+
"additionalProperties": true,
|
|
422
|
+
"required": [
|
|
423
|
+
"status",
|
|
424
|
+
"statusText",
|
|
425
|
+
"headers",
|
|
426
|
+
"body"
|
|
427
|
+
],
|
|
428
|
+
"properties": {
|
|
429
|
+
"status": {
|
|
430
|
+
"description": "HTTP status code returned by the provider transport.",
|
|
431
|
+
"type": "integer",
|
|
432
|
+
"minimum": 100,
|
|
433
|
+
"maximum": 599
|
|
434
|
+
},
|
|
435
|
+
"statusText": {
|
|
436
|
+
"description": "HTTP status text returned by the provider transport.",
|
|
437
|
+
"type": "string"
|
|
438
|
+
},
|
|
439
|
+
"headers": {
|
|
440
|
+
"description": "HTTP response headers normalized to string key-value pairs.",
|
|
441
|
+
"type": "object",
|
|
442
|
+
"additionalProperties": {
|
|
443
|
+
"type": "string"
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
"body": {
|
|
447
|
+
"description": "Serialized response body returned by the provider transport.",
|
|
448
|
+
"type": "string"
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
} as const;
|
|
452
|
+
|
|
453
|
+
export const telemetryEventSchema = {
|
|
454
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
455
|
+
"$id": "https://schemas.inderun.dev/1.0/telemetry-event.schema.json",
|
|
456
|
+
"title": "TelemetryEvent",
|
|
457
|
+
"description": "Normalized telemetry event emitted by the orchestrator and providers.",
|
|
458
|
+
"type": "object",
|
|
459
|
+
"additionalProperties": true,
|
|
460
|
+
"required": [
|
|
461
|
+
"type",
|
|
462
|
+
"runId",
|
|
463
|
+
"timestamp",
|
|
464
|
+
"payload"
|
|
465
|
+
],
|
|
466
|
+
"properties": {
|
|
467
|
+
"type": {
|
|
468
|
+
"description": "Telemetry event kind emitted by the orchestrator or provider integration.",
|
|
469
|
+
"enum": [
|
|
470
|
+
"route_decided",
|
|
471
|
+
"attempt_succeeded",
|
|
472
|
+
"attempt_failed",
|
|
473
|
+
"stream_attempt_started",
|
|
474
|
+
"stream_attempt_succeeded",
|
|
475
|
+
"stream_attempt_failed",
|
|
476
|
+
"stream_completed",
|
|
477
|
+
"stream_failed",
|
|
478
|
+
"stream_cancelled"
|
|
479
|
+
]
|
|
480
|
+
},
|
|
481
|
+
"runId": {
|
|
482
|
+
"description": "Opaque run identifier associated with this execution event.",
|
|
483
|
+
"type": "string",
|
|
484
|
+
"minLength": 1
|
|
485
|
+
},
|
|
486
|
+
"timestamp": {
|
|
487
|
+
"description": "Wall-clock event timestamp in Unix epoch milliseconds.",
|
|
488
|
+
"type": "number",
|
|
489
|
+
"minimum": 0
|
|
490
|
+
},
|
|
491
|
+
"payload": {
|
|
492
|
+
"description": "Event-specific metadata. It must not contain prompt payloads or raw secrets.",
|
|
493
|
+
"type": "object",
|
|
494
|
+
"additionalProperties": true
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
} as const;
|
|
498
|
+
|
|
499
|
+
export const routePlannerInputSchema = {
|
|
500
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
501
|
+
"$id": "https://schemas.inderun.dev/1.0/route-planner-input.schema.json",
|
|
502
|
+
"title": "RoutePlannerInput",
|
|
503
|
+
"description": "Pure data input contract for deterministic shared-core route planning.",
|
|
504
|
+
"type": "object",
|
|
505
|
+
"additionalProperties": true,
|
|
506
|
+
"required": [
|
|
507
|
+
"task",
|
|
508
|
+
"constraints",
|
|
509
|
+
"preferences",
|
|
510
|
+
"providers"
|
|
511
|
+
],
|
|
512
|
+
"properties": {
|
|
513
|
+
"task": {
|
|
514
|
+
"description": "Minimal task descriptor for provider task matching.",
|
|
515
|
+
"type": "object",
|
|
516
|
+
"additionalProperties": true,
|
|
517
|
+
"required": [
|
|
518
|
+
"kind"
|
|
519
|
+
],
|
|
520
|
+
"properties": {
|
|
521
|
+
"kind": {
|
|
522
|
+
"type": "string",
|
|
523
|
+
"minLength": 1
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
"interactionMode": {
|
|
528
|
+
"description": "Interaction mode the caller is requesting. Absent means 'run' (Mode 1), so planner inputs produced before this field existed keep their exact Mode-1 semantics. The mode filters eligible providers; it never changes candidate ordering.",
|
|
529
|
+
"enum": [
|
|
530
|
+
"run",
|
|
531
|
+
"stream"
|
|
532
|
+
]
|
|
533
|
+
},
|
|
534
|
+
"constraints": {
|
|
535
|
+
"description": "Hard routing constraints evaluated before provider selection.",
|
|
536
|
+
"type": "object",
|
|
537
|
+
"additionalProperties": true,
|
|
538
|
+
"properties": {
|
|
539
|
+
"privacy": {
|
|
540
|
+
"description": "Privacy requirement or preference for execution placement.",
|
|
541
|
+
"enum": [
|
|
542
|
+
"local_required",
|
|
543
|
+
"local_preferred",
|
|
544
|
+
"cloud_allowed",
|
|
545
|
+
"cloud_required"
|
|
546
|
+
]
|
|
547
|
+
},
|
|
548
|
+
"cloud": {
|
|
549
|
+
"description": "Cloud execution constraint.",
|
|
550
|
+
"enum": [
|
|
551
|
+
"forbidden",
|
|
552
|
+
"allowed",
|
|
553
|
+
"required"
|
|
554
|
+
]
|
|
555
|
+
},
|
|
556
|
+
"networkOnline": {
|
|
557
|
+
"description": "Current connectivity snapshot used for cloud route planning.",
|
|
558
|
+
"type": "boolean"
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
"preferences": {
|
|
563
|
+
"description": "Soft route ordering preferences applied after hard filtering.",
|
|
564
|
+
"type": "object",
|
|
565
|
+
"additionalProperties": true,
|
|
566
|
+
"properties": {
|
|
567
|
+
"optimizeFor": {
|
|
568
|
+
"description": "Primary optimization goal when multiple providers remain eligible.",
|
|
569
|
+
"enum": [
|
|
570
|
+
"privacy",
|
|
571
|
+
"latency",
|
|
572
|
+
"cost",
|
|
573
|
+
"balanced"
|
|
574
|
+
]
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
},
|
|
578
|
+
"providers": {
|
|
579
|
+
"description": "Static descriptors plus dynamic capability snapshots for planning.",
|
|
580
|
+
"type": "array",
|
|
581
|
+
"items": {
|
|
582
|
+
"type": "object",
|
|
583
|
+
"additionalProperties": true,
|
|
584
|
+
"required": [
|
|
585
|
+
"descriptor",
|
|
586
|
+
"capabilities"
|
|
587
|
+
],
|
|
588
|
+
"properties": {
|
|
589
|
+
"descriptor": {
|
|
590
|
+
"type": "object",
|
|
591
|
+
"additionalProperties": true,
|
|
592
|
+
"required": [
|
|
593
|
+
"id",
|
|
594
|
+
"type",
|
|
595
|
+
"supports",
|
|
596
|
+
"tasks"
|
|
597
|
+
],
|
|
598
|
+
"properties": {
|
|
599
|
+
"id": {
|
|
600
|
+
"type": "string",
|
|
601
|
+
"minLength": 1
|
|
602
|
+
},
|
|
603
|
+
"type": {
|
|
604
|
+
"enum": [
|
|
605
|
+
"local",
|
|
606
|
+
"edge",
|
|
607
|
+
"cloud"
|
|
608
|
+
]
|
|
609
|
+
},
|
|
610
|
+
"supports": {
|
|
611
|
+
"type": "object",
|
|
612
|
+
"additionalProperties": true,
|
|
613
|
+
"required": [
|
|
614
|
+
"run"
|
|
615
|
+
],
|
|
616
|
+
"properties": {
|
|
617
|
+
"run": {
|
|
618
|
+
"type": "boolean"
|
|
619
|
+
},
|
|
620
|
+
"streaming": {
|
|
621
|
+
"description": "Whether the provider statically declares Mode-2 streaming. Absent is treated as false: a descriptor that predates this field cannot be assumed to stream.",
|
|
622
|
+
"type": "boolean"
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
"cancel": {
|
|
627
|
+
"description": "Cancellation guarantee the provider offers. Carried for route explanations and telemetry; the planner does not filter on it.",
|
|
628
|
+
"enum": [
|
|
629
|
+
"hard",
|
|
630
|
+
"soft",
|
|
631
|
+
"none"
|
|
632
|
+
]
|
|
633
|
+
},
|
|
634
|
+
"tasks": {
|
|
635
|
+
"type": "array",
|
|
636
|
+
"items": {
|
|
637
|
+
"type": "string",
|
|
638
|
+
"minLength": 1
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
"privacy": {
|
|
642
|
+
"description": "Descriptor privacy metadata used to enforce local/cloud routing rules.",
|
|
643
|
+
"type": "object",
|
|
644
|
+
"additionalProperties": true,
|
|
645
|
+
"required": [
|
|
646
|
+
"dataLeavesDevice"
|
|
647
|
+
],
|
|
648
|
+
"properties": {
|
|
649
|
+
"dataLeavesDevice": {
|
|
650
|
+
"type": "boolean"
|
|
651
|
+
},
|
|
652
|
+
"regions": {
|
|
653
|
+
"type": "array",
|
|
654
|
+
"items": {
|
|
655
|
+
"type": "string",
|
|
656
|
+
"minLength": 1
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
"capabilities": {
|
|
664
|
+
"type": "object",
|
|
665
|
+
"additionalProperties": true,
|
|
666
|
+
"required": [
|
|
667
|
+
"available"
|
|
668
|
+
],
|
|
669
|
+
"properties": {
|
|
670
|
+
"available": {
|
|
671
|
+
"type": "boolean"
|
|
672
|
+
},
|
|
673
|
+
"reason": {
|
|
674
|
+
"type": "string",
|
|
675
|
+
"minLength": 1
|
|
676
|
+
},
|
|
677
|
+
"streamingAvailable": {
|
|
678
|
+
"description": "Whether the provider can stream right now in this host environment. Absent inherits the static descriptor.supports.streaming value.",
|
|
679
|
+
"type": "boolean"
|
|
680
|
+
},
|
|
681
|
+
"streamingUnavailableReason": {
|
|
682
|
+
"description": "Human-readable explanation used when streamingAvailable is false. Absent lets the planner synthesize a default message.",
|
|
683
|
+
"type": "string",
|
|
684
|
+
"minLength": 1
|
|
685
|
+
},
|
|
686
|
+
"cancellationAvailable": {
|
|
687
|
+
"description": "Whether cancellation is honored right now in this host environment. Absent inherits the static descriptor.cancel value (any value other than 'none' means available).",
|
|
688
|
+
"type": "boolean"
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
} as const;
|
|
697
|
+
|
|
698
|
+
export const routePlanSchema = {
|
|
699
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
700
|
+
"$id": "https://schemas.inderun.dev/1.0/route-plan.schema.json",
|
|
701
|
+
"title": "RoutePlan",
|
|
702
|
+
"description": "Deterministic shared-core Mode-1 route planning result.",
|
|
703
|
+
"type": "object",
|
|
704
|
+
"additionalProperties": true,
|
|
705
|
+
"required": [
|
|
706
|
+
"fallbackProviderIds",
|
|
707
|
+
"candidates",
|
|
708
|
+
"rejectedProviders",
|
|
709
|
+
"explanation"
|
|
710
|
+
],
|
|
711
|
+
"properties": {
|
|
712
|
+
"selectedProviderId": {
|
|
713
|
+
"description": "Chosen primary provider ID, if any.",
|
|
714
|
+
"type": "string",
|
|
715
|
+
"minLength": 1
|
|
716
|
+
},
|
|
717
|
+
"fallbackProviderIds": {
|
|
718
|
+
"description": "Fallback provider IDs ordered after the primary selection.",
|
|
719
|
+
"type": "array",
|
|
720
|
+
"items": {
|
|
721
|
+
"type": "string",
|
|
722
|
+
"minLength": 1
|
|
723
|
+
}
|
|
724
|
+
},
|
|
725
|
+
"candidates": {
|
|
726
|
+
"description": "Eligible candidates in deterministic order.",
|
|
727
|
+
"type": "array",
|
|
728
|
+
"items": {
|
|
729
|
+
"type": "object",
|
|
730
|
+
"additionalProperties": true,
|
|
731
|
+
"required": [
|
|
732
|
+
"providerId",
|
|
733
|
+
"order"
|
|
734
|
+
],
|
|
735
|
+
"properties": {
|
|
736
|
+
"providerId": {
|
|
737
|
+
"type": "string",
|
|
738
|
+
"minLength": 1
|
|
739
|
+
},
|
|
740
|
+
"order": {
|
|
741
|
+
"type": "integer",
|
|
742
|
+
"minimum": 0
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
"rejectedProviders": {
|
|
748
|
+
"description": "Providers filtered out during planning together with machine-readable reasons.",
|
|
749
|
+
"type": "array",
|
|
750
|
+
"items": {
|
|
751
|
+
"type": "object",
|
|
752
|
+
"additionalProperties": true,
|
|
753
|
+
"required": [
|
|
754
|
+
"providerId",
|
|
755
|
+
"reasons"
|
|
756
|
+
],
|
|
757
|
+
"properties": {
|
|
758
|
+
"providerId": {
|
|
759
|
+
"type": "string",
|
|
760
|
+
"minLength": 1
|
|
761
|
+
},
|
|
762
|
+
"reasons": {
|
|
763
|
+
"type": "array",
|
|
764
|
+
"items": {
|
|
765
|
+
"type": "object",
|
|
766
|
+
"additionalProperties": true,
|
|
767
|
+
"required": [
|
|
768
|
+
"code",
|
|
769
|
+
"message"
|
|
770
|
+
],
|
|
771
|
+
"properties": {
|
|
772
|
+
"code": {
|
|
773
|
+
"description": "Normalized rejection reason. 'streaming_not_supported' means the descriptor does not statically declare Mode-2 streaming; 'streaming_unavailable' means it declares streaming but the dynamic capability snapshot reports it cannot stream in the current host environment.",
|
|
774
|
+
"enum": [
|
|
775
|
+
"task_not_supported",
|
|
776
|
+
"run_not_supported",
|
|
777
|
+
"streaming_not_supported",
|
|
778
|
+
"streaming_unavailable",
|
|
779
|
+
"privacy_constraint",
|
|
780
|
+
"cloud_constraint",
|
|
781
|
+
"offline",
|
|
782
|
+
"capability_unavailable"
|
|
783
|
+
]
|
|
784
|
+
},
|
|
785
|
+
"message": {
|
|
786
|
+
"type": "string",
|
|
787
|
+
"minLength": 1
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
},
|
|
795
|
+
"failureCode": {
|
|
796
|
+
"description": "Normalized routing failure class when no provider is selected.",
|
|
797
|
+
"enum": [
|
|
798
|
+
"capability_mismatch",
|
|
799
|
+
"offline",
|
|
800
|
+
"unavailable"
|
|
801
|
+
]
|
|
802
|
+
},
|
|
803
|
+
"explanation": {
|
|
804
|
+
"description": "Human-readable selection or failure explanation suitable for telemetry/debugging.",
|
|
805
|
+
"type": "object",
|
|
806
|
+
"additionalProperties": true,
|
|
807
|
+
"required": [
|
|
808
|
+
"summary"
|
|
809
|
+
],
|
|
810
|
+
"properties": {
|
|
811
|
+
"summary": {
|
|
812
|
+
"type": "string",
|
|
813
|
+
"minLength": 1
|
|
814
|
+
},
|
|
815
|
+
"selectedProviderId": {
|
|
816
|
+
"type": "string",
|
|
817
|
+
"minLength": 1
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
} as const;
|
|
823
|
+
|
|
824
|
+
export const modelPackageSchema = {
|
|
825
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
826
|
+
"$id": "https://schemas.inderun.dev/1.0/model-package.schema.json",
|
|
827
|
+
"title": "ModelPackage",
|
|
828
|
+
"description": "Provider-neutral descriptor for a developer-supplied/custom local model made available to an IndeRun local-model provider family (for example, the ONNX Runtime family). It describes model identity, format, task support, source, files, integrity, licensing, and resource expectations. It is bootstrap/configuration metadata resolved before execution; it is not part of the public TaskRequest/TaskResult surface, and it must not carry raw secrets.",
|
|
829
|
+
"type": "object",
|
|
830
|
+
"additionalProperties": true,
|
|
831
|
+
"required": [
|
|
832
|
+
"id",
|
|
833
|
+
"format"
|
|
834
|
+
],
|
|
835
|
+
"properties": {
|
|
836
|
+
"id": {
|
|
837
|
+
"description": "Stable application-scoped identifier for the model package.",
|
|
838
|
+
"type": "string",
|
|
839
|
+
"minLength": 1
|
|
840
|
+
},
|
|
841
|
+
"version": {
|
|
842
|
+
"description": "Optional application-defined version for the model package, used for cache invalidation and compatibility checks.",
|
|
843
|
+
"type": "string",
|
|
844
|
+
"minLength": 1
|
|
845
|
+
},
|
|
846
|
+
"format": {
|
|
847
|
+
"description": "Model packaging format the target runtime family must understand. 'onnx' is a plain ONNX graph, 'ort' is an ONNX Runtime optimized/mobile format, 'genai' is an ONNX Runtime GenAI model package.",
|
|
848
|
+
"enum": [
|
|
849
|
+
"onnx",
|
|
850
|
+
"ort",
|
|
851
|
+
"genai"
|
|
852
|
+
]
|
|
853
|
+
},
|
|
854
|
+
"tasks": {
|
|
855
|
+
"description": "IndeRun task kinds this model package can serve (for example 'text_to_text'). Used by dynamic capability checks and route matching.",
|
|
856
|
+
"type": "array",
|
|
857
|
+
"items": {
|
|
858
|
+
"type": "string",
|
|
859
|
+
"minLength": 1
|
|
860
|
+
}
|
|
861
|
+
},
|
|
862
|
+
"runtime": {
|
|
863
|
+
"description": "Optional runtime compatibility expectations. Fields are advisory hints for capability checks; the provider adapter owns exact enforcement.",
|
|
864
|
+
"type": "object",
|
|
865
|
+
"additionalProperties": true,
|
|
866
|
+
"properties": {
|
|
867
|
+
"minOpset": {
|
|
868
|
+
"description": "Minimum ONNX opset version the model requires, where known.",
|
|
869
|
+
"type": "integer",
|
|
870
|
+
"minimum": 1
|
|
871
|
+
},
|
|
872
|
+
"minRuntimeVersion": {
|
|
873
|
+
"description": "Minimum runtime package version required to load the model, where known.",
|
|
874
|
+
"type": "string",
|
|
875
|
+
"minLength": 1
|
|
876
|
+
},
|
|
877
|
+
"platforms": {
|
|
878
|
+
"description": "Platforms the package is expected to run on (for example 'web', 'android', 'apple'). Absence means unconstrained.",
|
|
879
|
+
"type": "array",
|
|
880
|
+
"items": {
|
|
881
|
+
"type": "string",
|
|
882
|
+
"minLength": 1
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
},
|
|
887
|
+
"files": {
|
|
888
|
+
"description": "Files that make up the model package, expressed as source-relative names/paths. The provider adapter and model source resolve these to concrete bytes per platform.",
|
|
889
|
+
"type": "object",
|
|
890
|
+
"additionalProperties": true,
|
|
891
|
+
"properties": {
|
|
892
|
+
"required": {
|
|
893
|
+
"description": "Files that must be present for the package to load (for example the model graph).",
|
|
894
|
+
"type": "array",
|
|
895
|
+
"items": {
|
|
896
|
+
"type": "string",
|
|
897
|
+
"minLength": 1
|
|
898
|
+
}
|
|
899
|
+
},
|
|
900
|
+
"tokenizer": {
|
|
901
|
+
"description": "Optional tokenizer file, where the model requires one.",
|
|
902
|
+
"type": "string",
|
|
903
|
+
"minLength": 1
|
|
904
|
+
},
|
|
905
|
+
"config": {
|
|
906
|
+
"description": "Optional model/generation config file, where the model requires one.",
|
|
907
|
+
"type": "string",
|
|
908
|
+
"minLength": 1
|
|
909
|
+
},
|
|
910
|
+
"external": {
|
|
911
|
+
"description": "Optional external data files referenced by the model graph (for example ONNX external weights).",
|
|
912
|
+
"type": "array",
|
|
913
|
+
"items": {
|
|
914
|
+
"type": "string",
|
|
915
|
+
"minLength": 1
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
},
|
|
920
|
+
"integrity": {
|
|
921
|
+
"description": "Optional integrity metadata used to validate resolved files before load.",
|
|
922
|
+
"type": "object",
|
|
923
|
+
"additionalProperties": true,
|
|
924
|
+
"properties": {
|
|
925
|
+
"checksums": {
|
|
926
|
+
"description": "Map of file name to expected checksum (for example 'sha256:...'). Absence means integrity is not verified by IndeRun.",
|
|
927
|
+
"type": "object",
|
|
928
|
+
"additionalProperties": {
|
|
929
|
+
"type": "string",
|
|
930
|
+
"minLength": 1
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
},
|
|
935
|
+
"license": {
|
|
936
|
+
"description": "Optional license/source metadata for the model, for developer transparency. Free-form.",
|
|
937
|
+
"type": "object",
|
|
938
|
+
"additionalProperties": true,
|
|
939
|
+
"properties": {
|
|
940
|
+
"spdx": {
|
|
941
|
+
"description": "SPDX license identifier where known (for example 'Apache-2.0').",
|
|
942
|
+
"type": "string",
|
|
943
|
+
"minLength": 1
|
|
944
|
+
},
|
|
945
|
+
"url": {
|
|
946
|
+
"description": "License or model card URL where available.",
|
|
947
|
+
"type": "string",
|
|
948
|
+
"minLength": 1
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
},
|
|
952
|
+
"source": {
|
|
953
|
+
"description": "Where the model files are obtained from. Availability of each source type is platform-dependent; see the ONNX Runtime provider-family specification for the per-platform support matrix.",
|
|
954
|
+
"type": "object",
|
|
955
|
+
"additionalProperties": true,
|
|
956
|
+
"required": [
|
|
957
|
+
"sourceType"
|
|
958
|
+
],
|
|
959
|
+
"properties": {
|
|
960
|
+
"sourceType": {
|
|
961
|
+
"description": "Discriminator for how the host makes model files available. 'registry' is a web repository/registry reference (for example a Hugging Face-style repo), 'bundled' is an app asset/resource, 'programmatic' is supplied directly by application code, 'filesystem' is a local path where the platform allows it, 'app_managed' is an app-managed cache/storage location, 'remote' is a host-managed download.",
|
|
962
|
+
"enum": [
|
|
963
|
+
"registry",
|
|
964
|
+
"bundled",
|
|
965
|
+
"programmatic",
|
|
966
|
+
"filesystem",
|
|
967
|
+
"app_managed",
|
|
968
|
+
"remote"
|
|
969
|
+
]
|
|
970
|
+
},
|
|
971
|
+
"ref": {
|
|
972
|
+
"description": "Optional source-specific reference (for example a registry repo id or a bundled asset base path). Interpretation depends on 'sourceType'. Must not contain credentials: URL userinfo (for example 'https://user:pass@host/...') is rejected, and credentials must be supplied via authContextRef instead.",
|
|
973
|
+
"type": "string",
|
|
974
|
+
"minLength": 1,
|
|
975
|
+
"pattern": "^(?![\\s\\S]*://[^/@]*@)[\\s\\S]*$"
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
},
|
|
979
|
+
"limits": {
|
|
980
|
+
"description": "Optional known resource expectations, used by capability checks to reject on constrained devices before load.",
|
|
981
|
+
"type": "object",
|
|
982
|
+
"additionalProperties": true,
|
|
983
|
+
"properties": {
|
|
984
|
+
"diskBytes": {
|
|
985
|
+
"description": "Approximate on-disk size of the resolved package, where known.",
|
|
986
|
+
"type": "integer",
|
|
987
|
+
"minimum": 0
|
|
988
|
+
},
|
|
989
|
+
"memBytes": {
|
|
990
|
+
"description": "Approximate peak memory required to run the model, where known.",
|
|
991
|
+
"type": "integer",
|
|
992
|
+
"minimum": 0
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
} as const;
|
|
998
|
+
|
|
999
|
+
export const streamRunSchema = {
|
|
1000
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1001
|
+
"$id": "https://schemas.inderun.dev/1.0/stream-run.schema.json",
|
|
1002
|
+
"title": "StreamRunHandle",
|
|
1003
|
+
"description": "The serializable acknowledgment returned when a Mode 2 stream is opened, before any StreamEvent has arrived. This is the identity/correlation contract only: the live, consumable stream itself is a platform-idiomatic construct (an AsyncIterable<StreamEvent> in TypeScript, a Flow<StreamEvent> in Kotlin, an AsyncThrowingStream<StreamEvent, Error> in Swift) that is never serialized and is out of scope for this schema. Design seam only; no engine or provider implementation exists yet (see docs/architecture/architecture.md).",
|
|
1004
|
+
"type": "object",
|
|
1005
|
+
"additionalProperties": true,
|
|
1006
|
+
"required": [
|
|
1007
|
+
"schemaVersion",
|
|
1008
|
+
"runId",
|
|
1009
|
+
"startedAt"
|
|
1010
|
+
],
|
|
1011
|
+
"properties": {
|
|
1012
|
+
"schemaVersion": {
|
|
1013
|
+
"description": "Contract schema version used to interpret this handle payload.",
|
|
1014
|
+
"const": "1.0"
|
|
1015
|
+
},
|
|
1016
|
+
"runId": {
|
|
1017
|
+
"description": "A unique, opaque identifier assigned by the engine for this stream run. Every StreamEvent and the terminal StreamTerminalOutcome for this run carry the same runId, matching the identity convention used by TaskResult.runId and IndeRunError.runId.",
|
|
1018
|
+
"type": "string",
|
|
1019
|
+
"minLength": 1
|
|
1020
|
+
},
|
|
1021
|
+
"startedAt": {
|
|
1022
|
+
"description": "Wall-clock time the stream run was opened, in Unix epoch milliseconds.",
|
|
1023
|
+
"type": "number",
|
|
1024
|
+
"minimum": 0
|
|
1025
|
+
},
|
|
1026
|
+
"providerId": {
|
|
1027
|
+
"description": "Identifier of the provider selected to service this stream, if routing has completed by the time the handle is returned. Absent while route selection is still pending.",
|
|
1028
|
+
"type": "string",
|
|
1029
|
+
"minLength": 1
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
} as const;
|
|
1033
|
+
|
|
1034
|
+
export const streamEventSchema = {
|
|
1035
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1036
|
+
"$id": "https://schemas.inderun.dev/1.0/stream-event.schema.json",
|
|
1037
|
+
"title": "StreamEvent",
|
|
1038
|
+
"description": "The canonical Mode 2 streaming event union, discriminated by 'type'. Every variant shares an envelope of schemaVersion, runId, sequence, timestamp, and type. 'sequence' is the ordering authority for events within a run (a monotonically increasing integer starting at 0 per runId) — consumers must order by 'sequence', not by arrival order, since a bridge hop (e.g. a future Capacitor bridge) could reorder delivery. Known event types are split into user-visible content ('content_delta', 'content_snapshot') and mechanical/diagnostic types ('lifecycle', 'diagnostic', 'terminal') so SDKs can distinguish what belongs in a chat UI from what is orchestration detail. Forward compatibility: this union closes with an open 'unknown_event' branch so a consumer built against an older revision of this schema does not hard-fail when a newer, additive minor revision introduces a new known type; per contracts/README.md's schema evolution policy, SDKs must treat an unrecognized 'type' as ignore-or-pass-through-for-diagnostics, never as a hard error. All three engines implement this union (see docs/architecture/architecture.md).",
|
|
1039
|
+
"oneOf": [
|
|
1040
|
+
{
|
|
1041
|
+
"type": "object",
|
|
1042
|
+
"additionalProperties": true,
|
|
1043
|
+
"required": [
|
|
1044
|
+
"schemaVersion",
|
|
1045
|
+
"runId",
|
|
1046
|
+
"sequence",
|
|
1047
|
+
"timestamp",
|
|
1048
|
+
"type",
|
|
1049
|
+
"payload"
|
|
1050
|
+
],
|
|
1051
|
+
"properties": {
|
|
1052
|
+
"schemaVersion": {
|
|
1053
|
+
"description": "Contract schema version used to interpret this event payload.",
|
|
1054
|
+
"const": "1.0"
|
|
1055
|
+
},
|
|
1056
|
+
"runId": {
|
|
1057
|
+
"description": "Opaque run identifier this event belongs to, matching StreamRunHandle.runId.",
|
|
1058
|
+
"type": "string",
|
|
1059
|
+
"minLength": 1
|
|
1060
|
+
},
|
|
1061
|
+
"sequence": {
|
|
1062
|
+
"description": "Zero-based, monotonically increasing event index within this run. The ordering authority; do not rely on delivery/arrival order.",
|
|
1063
|
+
"type": "integer",
|
|
1064
|
+
"minimum": 0
|
|
1065
|
+
},
|
|
1066
|
+
"timestamp": {
|
|
1067
|
+
"description": "Wall-clock event timestamp in Unix epoch milliseconds.",
|
|
1068
|
+
"type": "number",
|
|
1069
|
+
"minimum": 0
|
|
1070
|
+
},
|
|
1071
|
+
"type": {
|
|
1072
|
+
"description": "User-visible content: an incremental text increment since the previous content_delta or content_snapshot event. Mirrors ProviderDescriptor.streamingStyle 'tokens'/'chunks' (packages/inderun-web/src/core/provider.ts) — providers reporting either style normalize to content_delta.",
|
|
1073
|
+
"const": "content_delta"
|
|
1074
|
+
},
|
|
1075
|
+
"payload": {
|
|
1076
|
+
"type": "object",
|
|
1077
|
+
"additionalProperties": true,
|
|
1078
|
+
"required": [
|
|
1079
|
+
"text"
|
|
1080
|
+
],
|
|
1081
|
+
"properties": {
|
|
1082
|
+
"text": {
|
|
1083
|
+
"description": "The incremental text produced since the previous content event.",
|
|
1084
|
+
"type": "string"
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
},
|
|
1090
|
+
{
|
|
1091
|
+
"type": "object",
|
|
1092
|
+
"additionalProperties": true,
|
|
1093
|
+
"required": [
|
|
1094
|
+
"schemaVersion",
|
|
1095
|
+
"runId",
|
|
1096
|
+
"sequence",
|
|
1097
|
+
"timestamp",
|
|
1098
|
+
"type",
|
|
1099
|
+
"payload"
|
|
1100
|
+
],
|
|
1101
|
+
"properties": {
|
|
1102
|
+
"schemaVersion": {
|
|
1103
|
+
"description": "Contract schema version used to interpret this event payload.",
|
|
1104
|
+
"const": "1.0"
|
|
1105
|
+
},
|
|
1106
|
+
"runId": {
|
|
1107
|
+
"description": "Opaque run identifier this event belongs to, matching StreamRunHandle.runId.",
|
|
1108
|
+
"type": "string",
|
|
1109
|
+
"minLength": 1
|
|
1110
|
+
},
|
|
1111
|
+
"sequence": {
|
|
1112
|
+
"description": "Zero-based, monotonically increasing event index within this run. The ordering authority; do not rely on delivery/arrival order.",
|
|
1113
|
+
"type": "integer",
|
|
1114
|
+
"minimum": 0
|
|
1115
|
+
},
|
|
1116
|
+
"timestamp": {
|
|
1117
|
+
"description": "Wall-clock event timestamp in Unix epoch milliseconds.",
|
|
1118
|
+
"type": "number",
|
|
1119
|
+
"minimum": 0
|
|
1120
|
+
},
|
|
1121
|
+
"type": {
|
|
1122
|
+
"description": "User-visible content: the full cumulative text produced so far. Mirrors ProviderDescriptor.streamingStyle 'snapshots' (packages/inderun-web/src/core/provider.ts) — providers reporting that style normalize to content_snapshot rather than content_delta. Retraction: a provider of any streamingStyle may additionally emit a content_snapshot to withdraw content it has already delivered, since a snapshot replaces the run's cumulative text rather than appending to it; an empty one therefore resets that text to nothing. This is how a provider whose backend rejects an in-flight response after partial delivery — an on-device safety/policy check, for example — tells consumers to discard what they have, so a consumer must handle content_snapshot even when the provider's declared style is 'tokens' or 'chunks'.",
|
|
1123
|
+
"const": "content_snapshot"
|
|
1124
|
+
},
|
|
1125
|
+
"payload": {
|
|
1126
|
+
"type": "object",
|
|
1127
|
+
"additionalProperties": true,
|
|
1128
|
+
"required": [
|
|
1129
|
+
"text"
|
|
1130
|
+
],
|
|
1131
|
+
"properties": {
|
|
1132
|
+
"text": {
|
|
1133
|
+
"description": "The full cumulative text produced by the run so far.",
|
|
1134
|
+
"type": "string"
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
},
|
|
1140
|
+
{
|
|
1141
|
+
"type": "object",
|
|
1142
|
+
"additionalProperties": true,
|
|
1143
|
+
"required": [
|
|
1144
|
+
"schemaVersion",
|
|
1145
|
+
"runId",
|
|
1146
|
+
"sequence",
|
|
1147
|
+
"timestamp",
|
|
1148
|
+
"type",
|
|
1149
|
+
"payload"
|
|
1150
|
+
],
|
|
1151
|
+
"properties": {
|
|
1152
|
+
"schemaVersion": {
|
|
1153
|
+
"description": "Contract schema version used to interpret this event payload.",
|
|
1154
|
+
"const": "1.0"
|
|
1155
|
+
},
|
|
1156
|
+
"runId": {
|
|
1157
|
+
"description": "Opaque run identifier this event belongs to, matching StreamRunHandle.runId.",
|
|
1158
|
+
"type": "string",
|
|
1159
|
+
"minLength": 1
|
|
1160
|
+
},
|
|
1161
|
+
"sequence": {
|
|
1162
|
+
"description": "Zero-based, monotonically increasing event index within this run. The ordering authority; do not rely on delivery/arrival order.",
|
|
1163
|
+
"type": "integer",
|
|
1164
|
+
"minimum": 0
|
|
1165
|
+
},
|
|
1166
|
+
"timestamp": {
|
|
1167
|
+
"description": "Wall-clock event timestamp in Unix epoch milliseconds.",
|
|
1168
|
+
"type": "number",
|
|
1169
|
+
"minimum": 0
|
|
1170
|
+
},
|
|
1171
|
+
"type": {
|
|
1172
|
+
"description": "Mechanical/diagnostic: a run lifecycle transition (e.g. provider selection, execution start). Not user-visible content; not part of the generated text.",
|
|
1173
|
+
"const": "lifecycle"
|
|
1174
|
+
},
|
|
1175
|
+
"payload": {
|
|
1176
|
+
"type": "object",
|
|
1177
|
+
"additionalProperties": true,
|
|
1178
|
+
"required": [
|
|
1179
|
+
"phase"
|
|
1180
|
+
],
|
|
1181
|
+
"properties": {
|
|
1182
|
+
"phase": {
|
|
1183
|
+
"description": "The lifecycle phase reached.",
|
|
1184
|
+
"enum": [
|
|
1185
|
+
"provider_selected",
|
|
1186
|
+
"started"
|
|
1187
|
+
]
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
},
|
|
1193
|
+
{
|
|
1194
|
+
"type": "object",
|
|
1195
|
+
"additionalProperties": true,
|
|
1196
|
+
"required": [
|
|
1197
|
+
"schemaVersion",
|
|
1198
|
+
"runId",
|
|
1199
|
+
"sequence",
|
|
1200
|
+
"timestamp",
|
|
1201
|
+
"type",
|
|
1202
|
+
"payload"
|
|
1203
|
+
],
|
|
1204
|
+
"properties": {
|
|
1205
|
+
"schemaVersion": {
|
|
1206
|
+
"description": "Contract schema version used to interpret this event payload.",
|
|
1207
|
+
"const": "1.0"
|
|
1208
|
+
},
|
|
1209
|
+
"runId": {
|
|
1210
|
+
"description": "Opaque run identifier this event belongs to, matching StreamRunHandle.runId.",
|
|
1211
|
+
"type": "string",
|
|
1212
|
+
"minLength": 1
|
|
1213
|
+
},
|
|
1214
|
+
"sequence": {
|
|
1215
|
+
"description": "Zero-based, monotonically increasing event index within this run. The ordering authority; do not rely on delivery/arrival order.",
|
|
1216
|
+
"type": "integer",
|
|
1217
|
+
"minimum": 0
|
|
1218
|
+
},
|
|
1219
|
+
"timestamp": {
|
|
1220
|
+
"description": "Wall-clock event timestamp in Unix epoch milliseconds.",
|
|
1221
|
+
"type": "number",
|
|
1222
|
+
"minimum": 0
|
|
1223
|
+
},
|
|
1224
|
+
"type": {
|
|
1225
|
+
"description": "Mechanical/diagnostic: free-form orchestration or provider diagnostic detail. Not user-visible content.",
|
|
1226
|
+
"const": "diagnostic"
|
|
1227
|
+
},
|
|
1228
|
+
"payload": {
|
|
1229
|
+
"description": "Event-specific diagnostic metadata. It must not contain prompt payloads or raw secrets, matching the same guardrail as TelemetryEvent.payload.",
|
|
1230
|
+
"type": "object",
|
|
1231
|
+
"additionalProperties": true
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
},
|
|
1235
|
+
{
|
|
1236
|
+
"type": "object",
|
|
1237
|
+
"additionalProperties": true,
|
|
1238
|
+
"required": [
|
|
1239
|
+
"schemaVersion",
|
|
1240
|
+
"runId",
|
|
1241
|
+
"sequence",
|
|
1242
|
+
"timestamp",
|
|
1243
|
+
"type",
|
|
1244
|
+
"payload"
|
|
1245
|
+
],
|
|
1246
|
+
"properties": {
|
|
1247
|
+
"schemaVersion": {
|
|
1248
|
+
"description": "Contract schema version used to interpret this event payload.",
|
|
1249
|
+
"const": "1.0"
|
|
1250
|
+
},
|
|
1251
|
+
"runId": {
|
|
1252
|
+
"description": "Opaque run identifier this event belongs to, matching StreamRunHandle.runId.",
|
|
1253
|
+
"type": "string",
|
|
1254
|
+
"minLength": 1
|
|
1255
|
+
},
|
|
1256
|
+
"sequence": {
|
|
1257
|
+
"description": "Zero-based, monotonically increasing event index within this run. This is always the highest sequence number for the run: the terminal event.",
|
|
1258
|
+
"type": "integer",
|
|
1259
|
+
"minimum": 0
|
|
1260
|
+
},
|
|
1261
|
+
"timestamp": {
|
|
1262
|
+
"description": "Wall-clock event timestamp in Unix epoch milliseconds.",
|
|
1263
|
+
"type": "number",
|
|
1264
|
+
"minimum": 0
|
|
1265
|
+
},
|
|
1266
|
+
"type": {
|
|
1267
|
+
"description": "Terminal: the last event of the run, carrying the mutually-exclusive completion/error/cancellation outcome. No further StreamEvent is delivered for this runId after this event.",
|
|
1268
|
+
"const": "terminal"
|
|
1269
|
+
},
|
|
1270
|
+
"payload": {
|
|
1271
|
+
"description": "Structurally identical to StreamTerminalOutcome (contracts/schemas/stream-terminal-outcome.schema.json), duplicated by value here rather than by $ref, matching this repo's schema convention of no cross-file references. Keep both shapes in sync; a cross-check test asserts a shared fixture validates against both schemas.",
|
|
1272
|
+
"oneOf": [
|
|
1273
|
+
{
|
|
1274
|
+
"type": "object",
|
|
1275
|
+
"additionalProperties": true,
|
|
1276
|
+
"required": [
|
|
1277
|
+
"schemaVersion",
|
|
1278
|
+
"runId",
|
|
1279
|
+
"outcome",
|
|
1280
|
+
"finalText"
|
|
1281
|
+
],
|
|
1282
|
+
"properties": {
|
|
1283
|
+
"schemaVersion": {
|
|
1284
|
+
"const": "1.0"
|
|
1285
|
+
},
|
|
1286
|
+
"runId": {
|
|
1287
|
+
"type": "string",
|
|
1288
|
+
"minLength": 1
|
|
1289
|
+
},
|
|
1290
|
+
"outcome": {
|
|
1291
|
+
"const": "completed"
|
|
1292
|
+
},
|
|
1293
|
+
"finalText": {
|
|
1294
|
+
"type": "string"
|
|
1295
|
+
},
|
|
1296
|
+
"finishReason": {
|
|
1297
|
+
"enum": [
|
|
1298
|
+
"stop",
|
|
1299
|
+
"length",
|
|
1300
|
+
"cancelled",
|
|
1301
|
+
"error"
|
|
1302
|
+
]
|
|
1303
|
+
},
|
|
1304
|
+
"usage": {
|
|
1305
|
+
"type": "object",
|
|
1306
|
+
"additionalProperties": true,
|
|
1307
|
+
"properties": {
|
|
1308
|
+
"inputTokens": {
|
|
1309
|
+
"type": "integer",
|
|
1310
|
+
"minimum": 0
|
|
1311
|
+
},
|
|
1312
|
+
"outputTokens": {
|
|
1313
|
+
"type": "integer",
|
|
1314
|
+
"minimum": 0
|
|
1315
|
+
},
|
|
1316
|
+
"totalTokens": {
|
|
1317
|
+
"type": "integer",
|
|
1318
|
+
"minimum": 0
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
},
|
|
1322
|
+
"telemetry": {
|
|
1323
|
+
"type": "object",
|
|
1324
|
+
"additionalProperties": true,
|
|
1325
|
+
"required": [
|
|
1326
|
+
"providerUsed",
|
|
1327
|
+
"totalMs"
|
|
1328
|
+
],
|
|
1329
|
+
"properties": {
|
|
1330
|
+
"providerUsed": {
|
|
1331
|
+
"type": "string",
|
|
1332
|
+
"minLength": 1
|
|
1333
|
+
},
|
|
1334
|
+
"totalMs": {
|
|
1335
|
+
"type": "number",
|
|
1336
|
+
"minimum": 0
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
},
|
|
1342
|
+
{
|
|
1343
|
+
"type": "object",
|
|
1344
|
+
"additionalProperties": true,
|
|
1345
|
+
"required": [
|
|
1346
|
+
"schemaVersion",
|
|
1347
|
+
"runId",
|
|
1348
|
+
"outcome",
|
|
1349
|
+
"error"
|
|
1350
|
+
],
|
|
1351
|
+
"properties": {
|
|
1352
|
+
"schemaVersion": {
|
|
1353
|
+
"const": "1.0"
|
|
1354
|
+
},
|
|
1355
|
+
"runId": {
|
|
1356
|
+
"type": "string",
|
|
1357
|
+
"minLength": 1
|
|
1358
|
+
},
|
|
1359
|
+
"outcome": {
|
|
1360
|
+
"const": "error"
|
|
1361
|
+
},
|
|
1362
|
+
"error": {
|
|
1363
|
+
"type": "object",
|
|
1364
|
+
"additionalProperties": true,
|
|
1365
|
+
"required": [
|
|
1366
|
+
"schemaVersion",
|
|
1367
|
+
"errorClass",
|
|
1368
|
+
"message"
|
|
1369
|
+
],
|
|
1370
|
+
"properties": {
|
|
1371
|
+
"schemaVersion": {
|
|
1372
|
+
"const": "1.0"
|
|
1373
|
+
},
|
|
1374
|
+
"errorClass": {
|
|
1375
|
+
"enum": [
|
|
1376
|
+
"CapabilityMismatch",
|
|
1377
|
+
"Offline",
|
|
1378
|
+
"AuthError",
|
|
1379
|
+
"RateLimited",
|
|
1380
|
+
"Timeout",
|
|
1381
|
+
"Unavailable",
|
|
1382
|
+
"Internal"
|
|
1383
|
+
]
|
|
1384
|
+
},
|
|
1385
|
+
"message": {
|
|
1386
|
+
"type": "string",
|
|
1387
|
+
"minLength": 1
|
|
1388
|
+
},
|
|
1389
|
+
"providerId": {
|
|
1390
|
+
"type": "string",
|
|
1391
|
+
"minLength": 1
|
|
1392
|
+
},
|
|
1393
|
+
"retryable": {
|
|
1394
|
+
"type": "boolean"
|
|
1395
|
+
},
|
|
1396
|
+
"retryAfterMs": {
|
|
1397
|
+
"type": "integer",
|
|
1398
|
+
"minimum": 0
|
|
1399
|
+
},
|
|
1400
|
+
"details": {
|
|
1401
|
+
"type": "object",
|
|
1402
|
+
"additionalProperties": true
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
},
|
|
1408
|
+
{
|
|
1409
|
+
"type": "object",
|
|
1410
|
+
"additionalProperties": true,
|
|
1411
|
+
"required": [
|
|
1412
|
+
"schemaVersion",
|
|
1413
|
+
"runId",
|
|
1414
|
+
"outcome",
|
|
1415
|
+
"partialText"
|
|
1416
|
+
],
|
|
1417
|
+
"properties": {
|
|
1418
|
+
"schemaVersion": {
|
|
1419
|
+
"const": "1.0"
|
|
1420
|
+
},
|
|
1421
|
+
"runId": {
|
|
1422
|
+
"type": "string",
|
|
1423
|
+
"minLength": 1
|
|
1424
|
+
},
|
|
1425
|
+
"outcome": {
|
|
1426
|
+
"const": "cancelled"
|
|
1427
|
+
},
|
|
1428
|
+
"partialText": {
|
|
1429
|
+
"type": "string"
|
|
1430
|
+
},
|
|
1431
|
+
"reason": {
|
|
1432
|
+
"type": "string"
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
]
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
},
|
|
1440
|
+
{
|
|
1441
|
+
"type": "object",
|
|
1442
|
+
"additionalProperties": true,
|
|
1443
|
+
"required": [
|
|
1444
|
+
"schemaVersion",
|
|
1445
|
+
"runId",
|
|
1446
|
+
"sequence",
|
|
1447
|
+
"timestamp",
|
|
1448
|
+
"type"
|
|
1449
|
+
],
|
|
1450
|
+
"properties": {
|
|
1451
|
+
"schemaVersion": {
|
|
1452
|
+
"description": "Contract schema version used to interpret this event payload.",
|
|
1453
|
+
"const": "1.0"
|
|
1454
|
+
},
|
|
1455
|
+
"runId": {
|
|
1456
|
+
"description": "Opaque run identifier this event belongs to, matching StreamRunHandle.runId.",
|
|
1457
|
+
"type": "string",
|
|
1458
|
+
"minLength": 1
|
|
1459
|
+
},
|
|
1460
|
+
"sequence": {
|
|
1461
|
+
"description": "Zero-based, monotonically increasing event index within this run. The ordering authority; do not rely on delivery/arrival order.",
|
|
1462
|
+
"type": "integer",
|
|
1463
|
+
"minimum": 0
|
|
1464
|
+
},
|
|
1465
|
+
"timestamp": {
|
|
1466
|
+
"description": "Wall-clock event timestamp in Unix epoch milliseconds.",
|
|
1467
|
+
"type": "number",
|
|
1468
|
+
"minimum": 0
|
|
1469
|
+
},
|
|
1470
|
+
"type": {
|
|
1471
|
+
"description": "Forward-compatibility catch-all: any event type not among the known constants above. Exists so a consumer validating against this revision of the schema does not hard-fail when a future additive revision introduces a new known event type; SDKs must ignore or pass through such events for diagnostics rather than treating them as an error.",
|
|
1472
|
+
"type": "string",
|
|
1473
|
+
"not": {
|
|
1474
|
+
"enum": [
|
|
1475
|
+
"content_delta",
|
|
1476
|
+
"content_snapshot",
|
|
1477
|
+
"lifecycle",
|
|
1478
|
+
"diagnostic",
|
|
1479
|
+
"terminal"
|
|
1480
|
+
]
|
|
1481
|
+
}
|
|
1482
|
+
},
|
|
1483
|
+
"payload": {
|
|
1484
|
+
"description": "Optional event-specific payload for the unrecognized type. It must not contain prompt payloads or raw secrets.",
|
|
1485
|
+
"type": "object",
|
|
1486
|
+
"additionalProperties": true
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
]
|
|
1491
|
+
} as const;
|
|
1492
|
+
|
|
1493
|
+
export const streamTerminalOutcomeSchema = {
|
|
1494
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1495
|
+
"$id": "https://schemas.inderun.dev/1.0/stream-terminal-outcome.schema.json",
|
|
1496
|
+
"title": "StreamTerminalOutcome",
|
|
1497
|
+
"description": "How a Mode 2 stream run ended. Completion, error, and cancellation are mutually exclusive terminal outcomes, enforced here as a closed set of three oneOf branches discriminated by 'outcome' (unlike StreamEvent.type, this set is not open-ended: the three-way terminal outcome is a fixed architectural guarantee, not something new outcome kinds get added to). Exactly one StreamTerminalOutcome is produced per run, and no further StreamEvent is delivered after it (see docs/architecture/architecture.md, 'Cancellation And Fallback'). This shape is also embedded by value as the payload of the terminal StreamEvent (stream-event.schema.json) so it can additionally be exposed standalone, e.g. as a completion future/promise a stream handle resolves independently of consuming the full event sequence; the two copies must stay structurally identical. Note on additionalProperties: per this repo's forward-compatible convention every branch permits unknown extra fields, so mutual exclusivity is enforced via the required 'outcome' discriminator plus each branch's own required peer field (finalText/error/partialText) being present, not by forbidding a payload from also carrying an unrelated stray field from another branch's vocabulary.",
|
|
1498
|
+
"oneOf": [
|
|
1499
|
+
{
|
|
1500
|
+
"type": "object",
|
|
1501
|
+
"additionalProperties": true,
|
|
1502
|
+
"required": [
|
|
1503
|
+
"schemaVersion",
|
|
1504
|
+
"runId",
|
|
1505
|
+
"outcome",
|
|
1506
|
+
"finalText"
|
|
1507
|
+
],
|
|
1508
|
+
"properties": {
|
|
1509
|
+
"schemaVersion": {
|
|
1510
|
+
"description": "Contract schema version used to interpret this outcome payload.",
|
|
1511
|
+
"const": "1.0"
|
|
1512
|
+
},
|
|
1513
|
+
"runId": {
|
|
1514
|
+
"description": "The stream run this outcome terminates, matching StreamRunHandle.runId and every StreamEvent.runId for the run.",
|
|
1515
|
+
"type": "string",
|
|
1516
|
+
"minLength": 1
|
|
1517
|
+
},
|
|
1518
|
+
"outcome": {
|
|
1519
|
+
"description": "The stream completed normally: every provider-generated event was delivered before this outcome was produced.",
|
|
1520
|
+
"const": "completed"
|
|
1521
|
+
},
|
|
1522
|
+
"finalText": {
|
|
1523
|
+
"description": "The full, cumulative text produced by the run. Equivalent in role to TaskResult.output.text for Mode 1.",
|
|
1524
|
+
"type": "string"
|
|
1525
|
+
},
|
|
1526
|
+
"finishReason": {
|
|
1527
|
+
"description": "How generation ended, mirroring TaskResult.finishReason for Mode 1: 'stop' (natural end), 'length' (hit maxOutputTokens), 'error' (provider reported a non-fatal issue on an otherwise completed run). 'cancelled' is included so this enum stays identical to TaskResult.finishReason, but it is unreachable here: cancellation is its own terminal outcome branch. Optional: providers that do not report a finish reason omit it.",
|
|
1528
|
+
"enum": [
|
|
1529
|
+
"stop",
|
|
1530
|
+
"length",
|
|
1531
|
+
"cancelled",
|
|
1532
|
+
"error"
|
|
1533
|
+
]
|
|
1534
|
+
},
|
|
1535
|
+
"usage": {
|
|
1536
|
+
"description": "Optional metadata regarding the quantity of tokens processed by the provider. Same shape as TaskResult.usage.",
|
|
1537
|
+
"type": "object",
|
|
1538
|
+
"additionalProperties": true,
|
|
1539
|
+
"properties": {
|
|
1540
|
+
"inputTokens": {
|
|
1541
|
+
"description": "Number of input tokens consumed, as reported by the provider.",
|
|
1542
|
+
"type": "integer",
|
|
1543
|
+
"minimum": 0
|
|
1544
|
+
},
|
|
1545
|
+
"outputTokens": {
|
|
1546
|
+
"description": "Number of output tokens generated, as reported by the provider.",
|
|
1547
|
+
"type": "integer",
|
|
1548
|
+
"minimum": 0
|
|
1549
|
+
},
|
|
1550
|
+
"totalTokens": {
|
|
1551
|
+
"description": "Aggregated token count for this request, as reported by the provider.",
|
|
1552
|
+
"type": "integer",
|
|
1553
|
+
"minimum": 0
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
},
|
|
1557
|
+
"telemetry": {
|
|
1558
|
+
"description": "Required metadata providing an overview of the execution result and performance metrics. Same shape as TaskResult.telemetry.",
|
|
1559
|
+
"type": "object",
|
|
1560
|
+
"additionalProperties": true,
|
|
1561
|
+
"required": [
|
|
1562
|
+
"providerUsed",
|
|
1563
|
+
"totalMs"
|
|
1564
|
+
],
|
|
1565
|
+
"properties": {
|
|
1566
|
+
"providerUsed": {
|
|
1567
|
+
"description": "The identifier for the specific provider that handled the request (e.g., 'openai_compatible_cloud').",
|
|
1568
|
+
"type": "string",
|
|
1569
|
+
"minLength": 1
|
|
1570
|
+
},
|
|
1571
|
+
"totalMs": {
|
|
1572
|
+
"description": "Measured execution duration in milliseconds, including route selection and result processing.",
|
|
1573
|
+
"type": "number",
|
|
1574
|
+
"minimum": 0
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
},
|
|
1580
|
+
{
|
|
1581
|
+
"type": "object",
|
|
1582
|
+
"additionalProperties": true,
|
|
1583
|
+
"required": [
|
|
1584
|
+
"schemaVersion",
|
|
1585
|
+
"runId",
|
|
1586
|
+
"outcome",
|
|
1587
|
+
"error"
|
|
1588
|
+
],
|
|
1589
|
+
"properties": {
|
|
1590
|
+
"schemaVersion": {
|
|
1591
|
+
"description": "Contract schema version used to interpret this outcome payload.",
|
|
1592
|
+
"const": "1.0"
|
|
1593
|
+
},
|
|
1594
|
+
"runId": {
|
|
1595
|
+
"description": "The stream run this outcome terminates, matching StreamRunHandle.runId and every StreamEvent.runId for the run.",
|
|
1596
|
+
"type": "string",
|
|
1597
|
+
"minLength": 1
|
|
1598
|
+
},
|
|
1599
|
+
"outcome": {
|
|
1600
|
+
"description": "The stream ended in failure: validation, routing (no eligible provider), or every attempted provider failing.",
|
|
1601
|
+
"const": "error"
|
|
1602
|
+
},
|
|
1603
|
+
"error": {
|
|
1604
|
+
"description": "The normalized error for this failure. Structurally identical to IndeRunError (contracts/schemas/inderun-error.schema.json), duplicated by value here rather than by $ref, matching this repo's schema convention of no cross-file references. Keep both shapes in sync; a cross-check test asserts a shared fixture validates against both schemas.",
|
|
1605
|
+
"type": "object",
|
|
1606
|
+
"additionalProperties": true,
|
|
1607
|
+
"required": [
|
|
1608
|
+
"schemaVersion",
|
|
1609
|
+
"errorClass",
|
|
1610
|
+
"message"
|
|
1611
|
+
],
|
|
1612
|
+
"properties": {
|
|
1613
|
+
"schemaVersion": {
|
|
1614
|
+
"description": "Contract schema version used to interpret the error payload.",
|
|
1615
|
+
"const": "1.0"
|
|
1616
|
+
},
|
|
1617
|
+
"errorClass": {
|
|
1618
|
+
"description": "Normalized error taxonomy, identical to IndeRunError.errorClass: CapabilityMismatch (request needs something no eligible provider supports), Offline/Unavailable (provider unreachable or not ready), AuthError (credential/auth failure), RateLimited (provider throttled the request), Timeout (provider exceeded its execution budget), Internal (unexpected engine-side failure).",
|
|
1619
|
+
"enum": [
|
|
1620
|
+
"CapabilityMismatch",
|
|
1621
|
+
"Offline",
|
|
1622
|
+
"AuthError",
|
|
1623
|
+
"RateLimited",
|
|
1624
|
+
"Timeout",
|
|
1625
|
+
"Unavailable",
|
|
1626
|
+
"Internal"
|
|
1627
|
+
]
|
|
1628
|
+
},
|
|
1629
|
+
"message": {
|
|
1630
|
+
"description": "Human-readable error message suitable for logs and developer diagnostics.",
|
|
1631
|
+
"type": "string",
|
|
1632
|
+
"minLength": 1
|
|
1633
|
+
},
|
|
1634
|
+
"providerId": {
|
|
1635
|
+
"description": "Identifier of the provider associated with the failure, if execution reached a provider.",
|
|
1636
|
+
"type": "string",
|
|
1637
|
+
"minLength": 1
|
|
1638
|
+
},
|
|
1639
|
+
"retryable": {
|
|
1640
|
+
"description": "Whether retrying the same request may succeed.",
|
|
1641
|
+
"type": "boolean"
|
|
1642
|
+
},
|
|
1643
|
+
"retryAfterMs": {
|
|
1644
|
+
"description": "Optional suggested delay before retrying, in milliseconds.",
|
|
1645
|
+
"type": "integer",
|
|
1646
|
+
"minimum": 0
|
|
1647
|
+
},
|
|
1648
|
+
"details": {
|
|
1649
|
+
"description": "Optional structured diagnostic details. It must not contain raw secrets.",
|
|
1650
|
+
"type": "object",
|
|
1651
|
+
"additionalProperties": true
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
},
|
|
1657
|
+
{
|
|
1658
|
+
"type": "object",
|
|
1659
|
+
"additionalProperties": true,
|
|
1660
|
+
"required": [
|
|
1661
|
+
"schemaVersion",
|
|
1662
|
+
"runId",
|
|
1663
|
+
"outcome",
|
|
1664
|
+
"partialText"
|
|
1665
|
+
],
|
|
1666
|
+
"properties": {
|
|
1667
|
+
"schemaVersion": {
|
|
1668
|
+
"description": "Contract schema version used to interpret this outcome payload.",
|
|
1669
|
+
"const": "1.0"
|
|
1670
|
+
},
|
|
1671
|
+
"runId": {
|
|
1672
|
+
"description": "The stream run this outcome terminates, matching StreamRunHandle.runId and every StreamEvent.runId for the run.",
|
|
1673
|
+
"type": "string",
|
|
1674
|
+
"minLength": 1
|
|
1675
|
+
},
|
|
1676
|
+
"outcome": {
|
|
1677
|
+
"description": "The stream was cancelled. No further StreamEvent is delivered after this outcome, and no further fallback attempt is made, per the engine's cancellation guarantee.",
|
|
1678
|
+
"const": "cancelled"
|
|
1679
|
+
},
|
|
1680
|
+
"partialText": {
|
|
1681
|
+
"description": "Whatever cumulative text had already been delivered via content_delta/content_snapshot StreamEvents before the cancellation point. May be empty if cancellation occurred before any content was produced.",
|
|
1682
|
+
"type": "string"
|
|
1683
|
+
},
|
|
1684
|
+
"reason": {
|
|
1685
|
+
"description": "Optional human-readable reason the run was cancelled (e.g. caller-initiated abort). Not a machine-taxonomy field; use errorClass on the 'error' outcome branch for failure classification.",
|
|
1686
|
+
"type": "string"
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
]
|
|
1691
|
+
} as const;
|