@independo/inderun-contracts 0.3.3 → 0.4.0-rc.2

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 (41) hide show
  1. package/dist/generated/execution-provenance.d.ts +95 -0
  2. package/dist/generated/execution-provenance.d.ts.map +1 -0
  3. package/dist/generated/execution-provenance.js +2 -0
  4. package/dist/generated/inderun-error.d.ts +102 -0
  5. package/dist/generated/inderun-error.d.ts.map +1 -1
  6. package/dist/generated/index.d.ts +1 -0
  7. package/dist/generated/index.d.ts.map +1 -1
  8. package/dist/generated/route-plan.d.ts +5 -3
  9. package/dist/generated/route-plan.d.ts.map +1 -1
  10. package/dist/generated/route-planner-input.d.ts +26 -0
  11. package/dist/generated/route-planner-input.d.ts.map +1 -1
  12. package/dist/generated/schemas.d.ts +169 -2
  13. package/dist/generated/schemas.d.ts.map +1 -1
  14. package/dist/generated/schemas.js +214 -2
  15. package/dist/generated/stream-event.d.ts +109 -0
  16. package/dist/generated/stream-event.d.ts.map +1 -1
  17. package/dist/generated/stream-terminal-outcome.d.ts +108 -0
  18. package/dist/generated/stream-terminal-outcome.d.ts.map +1 -1
  19. package/dist/generated/task-request.d.ts +8 -0
  20. package/dist/generated/task-request.d.ts.map +1 -1
  21. package/dist/generated/task-result.d.ts +114 -6
  22. package/dist/generated/task-result.d.ts.map +1 -1
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +2 -2
  26. package/dist/validators.d.ts +3 -0
  27. package/dist/validators.d.ts.map +1 -1
  28. package/dist/validators.js +12 -1
  29. package/package.json +1 -1
  30. package/src/generated/execution-provenance.ts +102 -0
  31. package/src/generated/inderun-error.ts +108 -0
  32. package/src/generated/index.ts +1 -0
  33. package/src/generated/route-plan.ts +5 -3
  34. package/src/generated/route-planner-input.ts +27 -0
  35. package/src/generated/schemas.ts +215 -2
  36. package/src/generated/stream-event.ts +122 -7
  37. package/src/generated/stream-terminal-outcome.ts +114 -0
  38. package/src/generated/task-request.ts +8 -0
  39. package/src/generated/task-result.ts +121 -7
  40. package/src/index.ts +3 -0
  41. package/src/validators.ts +15 -0
@@ -21,6 +21,12 @@ export type TaskResult = {
21
21
  * The normalized content returned from the selected provider.
22
22
  */
23
23
  output: Output;
24
+ /**
25
+ * Normalized execution provenance: which target ran, its declared locality, the configured
26
+ * and reported model, and how fallback and routing played out. See
27
+ * execution-provenance.schema.json.
28
+ */
29
+ provenance?: ExecutionProvenance;
24
30
  /**
25
31
  * A unique, opaque identifier assigned by the engine for this specific execution attempt.
26
32
  */
@@ -64,6 +70,115 @@ export type Output = {
64
70
  [property: string]: unknown;
65
71
  }
66
72
 
73
+ /**
74
+ * Normalized execution provenance: which target ran, its declared locality, the configured
75
+ * and reported model, and how fallback and routing played out. See
76
+ * execution-provenance.schema.json.
77
+ *
78
+ * Provider-neutral record of how an execution was carried out: the target the outcome is
79
+ * attributed to, its declared locality, the configured and provider-reported model, every
80
+ * attempt, and why other candidates were rejected. Carried on TaskResult, on every
81
+ * StreamTerminalOutcome branch, and on IndeRunError. It reports what the engine observed
82
+ * and what providers declared or reported; it never infers a model or locality a provider
83
+ * did not state, and it never contains request content, credentials, or provider payloads.
84
+ */
85
+ export type ExecutionProvenance = {
86
+ /**
87
+ * How many providers were attempted. 0 when the request failed validation or routing, or
88
+ * was cancelled before any attempt started.
89
+ */
90
+ attemptCount: number;
91
+ /**
92
+ * Every attempted provider, in attempt order, with how its attempt ended.
93
+ */
94
+ attempts: ExecutionProvenanceAttempt[];
95
+ /**
96
+ * The model providerId is bound to, as its descriptor declares it. Absent when the provider
97
+ * cannot name its model or no provider is attributed.
98
+ */
99
+ configuredModel?: string;
100
+ /**
101
+ * Whether more than one provider was attempted (attemptCount > 1).
102
+ */
103
+ fallbackOccurred: boolean;
104
+ /**
105
+ * Where providerId declares it executes: 'on_device' for a local provider, 'edge', or
106
+ * 'cloud'. A declaration by the provider's descriptor, not a measurement. 'unknown' when
107
+ * providerId is absent.
108
+ */
109
+ locality: Locality;
110
+ /**
111
+ * The model profile the request routed within; 'auto' when the request named none.
112
+ */
113
+ modelProfile: string;
114
+ /**
115
+ * The target the outcome is attributed to: the provider that produced the result, the
116
+ * provider a stream had committed to when it ended, or the provider that was running when
117
+ * it was cancelled. Absent when no provider was reached or when every attempted provider
118
+ * failed before one was committed to.
119
+ */
120
+ providerId?: string;
121
+ /**
122
+ * The model identifier the provider reported in its own response. Absent means the provider
123
+ * did not report one; it is never inferred from configuration.
124
+ */
125
+ reportedModel?: string;
126
+ /**
127
+ * Providers the route planner rejected before any attempt, with the normalized RoutePlan
128
+ * reason codes. Codes only: no provider-supplied messages.
129
+ */
130
+ routeRejections: ExecutionProvenanceRouteRejection[];
131
+ /**
132
+ * Contract schema version used to interpret this provenance record.
133
+ */
134
+ schemaVersion: "1.0";
135
+ [property: string]: unknown;
136
+ }
137
+
138
+ export type ExecutionProvenanceAttempt = {
139
+ /**
140
+ * Normalized error class of a failed attempt.
141
+ */
142
+ errorClass?: ErrorClass;
143
+ /**
144
+ * 'succeeded' (produced the result or was committed to and completed), 'failed', or
145
+ * 'cancelled'.
146
+ */
147
+ outcome: AttemptOutcome;
148
+ providerId: string;
149
+ [property: string]: unknown;
150
+ }
151
+
152
+ /**
153
+ * Normalized error class of a failed attempt.
154
+ *
155
+ * Present only if a provider reports a degraded outcome on an otherwise-successful result;
156
+ * no provider in this codebase currently sets this. Distinct from run() throwing — a thrown
157
+ * IndeRunError never produces a TaskResult at all.
158
+ */
159
+ export type ErrorClass = "CapabilityMismatch" | "Offline" | "AuthError" | "RateLimited" | "Timeout" | "Unavailable" | "Internal";
160
+
161
+ /**
162
+ * 'succeeded' (produced the result or was committed to and completed), 'failed', or
163
+ * 'cancelled'.
164
+ */
165
+ export type AttemptOutcome = "succeeded" | "failed" | "cancelled";
166
+
167
+ /**
168
+ * Where providerId declares it executes: 'on_device' for a local provider, 'edge', or
169
+ * 'cloud'. A declaration by the provider's descriptor, not a measurement. 'unknown' when
170
+ * providerId is absent.
171
+ */
172
+ export type Locality = "on_device" | "edge" | "cloud" | "unknown";
173
+
174
+ export type ExecutionProvenanceRouteRejection = {
175
+ codes: Code[];
176
+ providerId: string;
177
+ [property: string]: unknown;
178
+ }
179
+
180
+ export type Code = "task_not_supported" | "run_not_supported" | "streaming_not_supported" | "streaming_unavailable" | "privacy_constraint" | "cloud_constraint" | "offline" | "capability_unavailable" | "not_in_model_profile";
181
+
67
182
  /**
68
183
  * Required metadata providing an overview of the execution result and performance metrics.
69
184
  */
@@ -79,6 +194,12 @@ export type Telemetry = {
79
194
  * 'openai_compatible_cloud').
80
195
  */
81
196
  providerUsed: string;
197
+ /**
198
+ * The model identifier the provider reported in its own response, set by the provider when
199
+ * its backend reports one. The engine carries it into provenance.reportedModel; it is never
200
+ * inferred from configuration.
201
+ */
202
+ reportedModel?: string;
82
203
  /**
83
204
  * Measured execution duration in milliseconds, including route selection and result
84
205
  * processing.
@@ -87,13 +208,6 @@ export type Telemetry = {
87
208
  [property: string]: unknown;
88
209
  }
89
210
 
90
- /**
91
- * Present only if a provider reports a degraded outcome on an otherwise-successful result;
92
- * no provider in this codebase currently sets this. Distinct from run() throwing — a thrown
93
- * IndeRunError never produces a TaskResult at all.
94
- */
95
- export type ErrorClass = "CapabilityMismatch" | "Offline" | "AuthError" | "RateLimited" | "Timeout" | "Unavailable" | "Internal";
96
-
97
211
  /**
98
212
  * Optional metadata regarding the quantity of tokens processed by the provider.
99
213
  */
package/src/index.ts CHANGED
@@ -17,6 +17,7 @@ export type * from "./generated/index.js";
17
17
 
18
18
  /** The JSON Schemas those models were generated from, for runtime use. */
19
19
  export {
20
+ executionProvenanceSchema,
20
21
  httpRequestSchema,
21
22
  httpResponseSchema,
22
23
  inderunErrorSchema,
@@ -36,6 +37,7 @@ export {
36
37
  * boolean type guard.
37
38
  */
38
39
  export {
40
+ getExecutionProvenanceValidationIssues,
39
41
  getHttpRequestValidationIssues,
40
42
  getHttpResponseValidationIssues,
41
43
  getIndeRunErrorValidationIssues,
@@ -48,6 +50,7 @@ export {
48
50
  getTaskRequestValidationIssues,
49
51
  getTaskResultValidationIssues,
50
52
  getTelemetryEventValidationIssues,
53
+ validateExecutionProvenance,
51
54
  validateHttpRequest,
52
55
  validateHttpResponse,
53
56
  validateIndeRunError,
package/src/validators.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import Ajv2020 from "ajv/dist/2020.js";
2
2
  import type { ErrorObject, ValidateFunction } from "ajv";
3
3
 
4
+ import type { ExecutionProvenance } from "./generated/execution-provenance.js";
4
5
  import type { IndeRunError } from "./generated/inderun-error.js";
5
6
  import type { HttpRequest } from "./generated/http-request.js";
6
7
  import type { HttpResponse } from "./generated/http-response.js";
@@ -8,6 +9,7 @@ import type { ModelPackage } from "./generated/model-package.js";
8
9
  import type { RoutePlan } from "./generated/route-plan.js";
9
10
  import type { RoutePlannerInput } from "./generated/route-planner-input.js";
10
11
  import {
12
+ executionProvenanceSchema,
11
13
  httpRequestSchema,
12
14
  httpResponseSchema,
13
15
  inderunErrorSchema,
@@ -45,6 +47,9 @@ const ajv = new Ajv2020Constructor({
45
47
  validateSchema: true
46
48
  });
47
49
 
50
+ // Referenced by `$ref` from every schema that carries provenance, so it has to be known
51
+ // to Ajv before any of them compiles. Compiling it registers it under its `$id`.
52
+ const validateExecutionProvenanceSchema = ajv.compile(executionProvenanceSchema);
48
53
  const validateTaskRequestSchema = ajv.compile(taskRequestSchema);
49
54
  const validateTaskResultSchema = ajv.compile(taskResultSchema);
50
55
  const validateIndeRunErrorSchema = ajv.compile(inderunErrorSchema);
@@ -127,6 +132,16 @@ export function getIndeRunErrorValidationIssues(value: unknown): ValidationIssue
127
132
  });
128
133
  }
129
134
 
135
+ export function validateExecutionProvenance(value: unknown): value is ExecutionProvenance {
136
+ return getExecutionProvenanceValidationIssues(value).length === 0;
137
+ }
138
+
139
+ export function getExecutionProvenanceValidationIssues(value: unknown): ValidationIssue[] {
140
+ return getValidationIssues(validateExecutionProvenanceSchema, value, {
141
+ forbidInlineSecrets: true
142
+ });
143
+ }
144
+
130
145
  export function getHttpRequestValidationIssues(value: unknown): ValidationIssue[] {
131
146
  return getValidationIssues(validateHttpRequestSchema, value);
132
147
  }