@independo/inderun-contracts 0.3.0-dev.9 → 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.
@@ -0,0 +1,154 @@
1
+ /* This file was generated from JSON Schema using quicktype. Do not edit by hand. */
2
+
3
+ /**
4
+ * The canonical Mode 2 streaming event union, discriminated by 'type'. Every variant shares
5
+ * an envelope of schemaVersion, runId, sequence, timestamp, and type. 'sequence' is the
6
+ * ordering authority for events within a run (a monotonically increasing integer starting
7
+ * at 0 per runId) — consumers must order by 'sequence', not by arrival order, since a
8
+ * bridge hop (e.g. a future Capacitor bridge) could reorder delivery. Known event types are
9
+ * split into user-visible content ('content_delta', 'content_snapshot') and
10
+ * mechanical/diagnostic types ('lifecycle', 'diagnostic', 'terminal') so SDKs can
11
+ * distinguish what belongs in a chat UI from what is orchestration detail. Forward
12
+ * compatibility: this union closes with an open 'unknown_event' branch so a consumer built
13
+ * against an older revision of this schema does not hard-fail when a newer, additive minor
14
+ * revision introduces a new known type; per contracts/README.md's schema evolution policy,
15
+ * SDKs must treat an unrecognized 'type' as ignore-or-pass-through-for-diagnostics, never
16
+ * as a hard error. All three engines implement this union (see
17
+ * docs/architecture/architecture.md).
18
+ */
19
+ export type StreamEvent = {
20
+ /**
21
+ * Event-specific diagnostic metadata. It must not contain prompt payloads or raw secrets,
22
+ * matching the same guardrail as TelemetryEvent.payload.
23
+ *
24
+ * Structurally identical to StreamTerminalOutcome
25
+ * (contracts/schemas/stream-terminal-outcome.schema.json), duplicated by value here rather
26
+ * than by $ref, matching this repo's schema convention of no cross-file references. Keep
27
+ * both shapes in sync; a cross-check test asserts a shared fixture validates against both
28
+ * schemas.
29
+ *
30
+ * Optional event-specific payload for the unrecognized type. It must not contain prompt
31
+ * payloads or raw secrets.
32
+ */
33
+ payload?: Payload;
34
+ /**
35
+ * Opaque run identifier this event belongs to, matching StreamRunHandle.runId.
36
+ */
37
+ runId: string;
38
+ /**
39
+ * Contract schema version used to interpret this event payload.
40
+ */
41
+ schemaVersion: "1.0";
42
+ /**
43
+ * Zero-based, monotonically increasing event index within this run. The ordering authority;
44
+ * do not rely on delivery/arrival order.
45
+ *
46
+ * Zero-based, monotonically increasing event index within this run. This is always the
47
+ * highest sequence number for the run: the terminal event.
48
+ */
49
+ sequence: number;
50
+ /**
51
+ * Wall-clock event timestamp in Unix epoch milliseconds.
52
+ */
53
+ timestamp: number;
54
+ /**
55
+ * User-visible content: an incremental text increment since the previous content_delta or
56
+ * content_snapshot event. Mirrors ProviderDescriptor.streamingStyle 'tokens'/'chunks'
57
+ * (packages/inderun-web/src/core/provider.ts) — providers reporting either style normalize
58
+ * to content_delta.
59
+ *
60
+ * User-visible content: the full cumulative text produced so far. Mirrors
61
+ * ProviderDescriptor.streamingStyle 'snapshots' (packages/inderun-web/src/core/provider.ts)
62
+ * — providers reporting that style normalize to content_snapshot rather than content_delta.
63
+ * Retraction: a provider of any streamingStyle may additionally emit a content_snapshot to
64
+ * withdraw content it has already delivered, since a snapshot replaces the run's cumulative
65
+ * text rather than appending to it; an empty one therefore resets that text to nothing.
66
+ * This is how a provider whose backend rejects an in-flight response after partial delivery
67
+ * — an on-device safety/policy check, for example — tells consumers to discard what they
68
+ * have, so a consumer must handle content_snapshot even when the provider's declared style
69
+ * is 'tokens' or 'chunks'.
70
+ *
71
+ * Mechanical/diagnostic: a run lifecycle transition (e.g. provider selection, execution
72
+ * start). Not user-visible content; not part of the generated text.
73
+ *
74
+ * Mechanical/diagnostic: free-form orchestration or provider diagnostic detail. Not
75
+ * user-visible content.
76
+ *
77
+ * Terminal: the last event of the run, carrying the mutually-exclusive
78
+ * completion/error/cancellation outcome. No further StreamEvent is delivered for this runId
79
+ * after this event.
80
+ *
81
+ * Forward-compatibility catch-all: any event type not among the known constants above.
82
+ * Exists so a consumer validating against this revision of the schema does not hard-fail
83
+ * when a future additive revision introduces a new known event type; SDKs must ignore or
84
+ * pass through such events for diagnostics rather than treating them as an error.
85
+ */
86
+ type: string;
87
+ [property: string]: unknown;
88
+ }
89
+
90
+ /**
91
+ * Event-specific diagnostic metadata. It must not contain prompt payloads or raw secrets,
92
+ * matching the same guardrail as TelemetryEvent.payload.
93
+ *
94
+ * Optional event-specific payload for the unrecognized type. It must not contain prompt
95
+ * payloads or raw secrets.
96
+ */
97
+ export type Payload = {
98
+ /**
99
+ * The incremental text produced since the previous content event.
100
+ *
101
+ * The full cumulative text produced by the run so far.
102
+ */
103
+ text?: string;
104
+ /**
105
+ * The lifecycle phase reached.
106
+ */
107
+ phase?: Phase;
108
+ finalText?: string;
109
+ finishReason?: FinishReason;
110
+ outcome?: Outcome;
111
+ runId?: string;
112
+ schemaVersion?: "1.0";
113
+ telemetry?: Telemetry;
114
+ usage?: Usage;
115
+ error?: Error;
116
+ partialText?: string;
117
+ reason?: string;
118
+ [property: string]: unknown;
119
+ }
120
+
121
+ export type Error = {
122
+ details?: { [key: string]: unknown };
123
+ errorClass: ErrorClass;
124
+ message: string;
125
+ providerId?: string;
126
+ retryable?: boolean;
127
+ retryAfterMs?: number;
128
+ schemaVersion: "1.0";
129
+ [property: string]: unknown;
130
+ }
131
+
132
+ export type ErrorClass = "CapabilityMismatch" | "Offline" | "AuthError" | "RateLimited" | "Timeout" | "Unavailable" | "Internal";
133
+
134
+ export type FinishReason = "stop" | "length" | "cancelled" | "error";
135
+
136
+ export type Outcome = "completed" | "error" | "cancelled";
137
+
138
+ /**
139
+ * The lifecycle phase reached.
140
+ */
141
+ export type Phase = "provider_selected" | "started";
142
+
143
+ export type Telemetry = {
144
+ providerUsed: string;
145
+ totalMs: number;
146
+ [property: string]: unknown;
147
+ }
148
+
149
+ export type Usage = {
150
+ inputTokens?: number;
151
+ outputTokens?: number;
152
+ totalTokens?: number;
153
+ [property: string]: unknown;
154
+ }
@@ -0,0 +1,32 @@
1
+ /* This file was generated from JSON Schema using quicktype. Do not edit by hand. */
2
+
3
+ /**
4
+ * The serializable acknowledgment returned when a Mode 2 stream is opened, before any
5
+ * StreamEvent has arrived. This is the identity/correlation contract only: the live,
6
+ * consumable stream itself is a platform-idiomatic construct (an AsyncIterable<StreamEvent>
7
+ * in TypeScript, a Flow<StreamEvent> in Kotlin, an AsyncThrowingStream<StreamEvent, Error>
8
+ * in Swift) that is never serialized and is out of scope for this schema. Design seam only;
9
+ * no engine or provider implementation exists yet (see docs/architecture/architecture.md).
10
+ */
11
+ export type StreamRunHandle = {
12
+ /**
13
+ * Identifier of the provider selected to service this stream, if routing has completed by
14
+ * the time the handle is returned. Absent while route selection is still pending.
15
+ */
16
+ providerId?: string;
17
+ /**
18
+ * A unique, opaque identifier assigned by the engine for this stream run. Every StreamEvent
19
+ * and the terminal StreamTerminalOutcome for this run carry the same runId, matching the
20
+ * identity convention used by TaskResult.runId and IndeRunError.runId.
21
+ */
22
+ runId: string;
23
+ /**
24
+ * Contract schema version used to interpret this handle payload.
25
+ */
26
+ schemaVersion: "1.0";
27
+ /**
28
+ * Wall-clock time the stream run was opened, in Unix epoch milliseconds.
29
+ */
30
+ startedAt: number;
31
+ [property: string]: unknown;
32
+ }
@@ -0,0 +1,186 @@
1
+ /* This file was generated from JSON Schema using quicktype. Do not edit by hand. */
2
+
3
+ /**
4
+ * How a Mode 2 stream run ended. Completion, error, and cancellation are mutually exclusive
5
+ * terminal outcomes, enforced here as a closed set of three oneOf branches discriminated by
6
+ * 'outcome' (unlike StreamEvent.type, this set is not open-ended: the three-way terminal
7
+ * outcome is a fixed architectural guarantee, not something new outcome kinds get added
8
+ * to). Exactly one StreamTerminalOutcome is produced per run, and no further StreamEvent is
9
+ * delivered after it (see docs/architecture/architecture.md, 'Cancellation And Fallback').
10
+ * This shape is also embedded by value as the payload of the terminal StreamEvent
11
+ * (stream-event.schema.json) so it can additionally be exposed standalone, e.g. as a
12
+ * completion future/promise a stream handle resolves independently of consuming the full
13
+ * event sequence; the two copies must stay structurally identical. Note on
14
+ * additionalProperties: per this repo's forward-compatible convention every branch permits
15
+ * unknown extra fields, so mutual exclusivity is enforced via the required 'outcome'
16
+ * discriminator plus each branch's own required peer field (finalText/error/partialText)
17
+ * being present, not by forbidding a payload from also carrying an unrelated stray field
18
+ * from another branch's vocabulary.
19
+ */
20
+ export type StreamTerminalOutcome = {
21
+ /**
22
+ * The full, cumulative text produced by the run. Equivalent in role to
23
+ * TaskResult.output.text for Mode 1.
24
+ */
25
+ finalText?: string;
26
+ /**
27
+ * How generation ended, mirroring TaskResult.finishReason for Mode 1: 'stop' (natural end),
28
+ * 'length' (hit maxOutputTokens), 'error' (provider reported a non-fatal issue on an
29
+ * otherwise completed run). 'cancelled' is included so this enum stays identical to
30
+ * TaskResult.finishReason, but it is unreachable here: cancellation is its own terminal
31
+ * outcome branch. Optional: providers that do not report a finish reason omit it.
32
+ */
33
+ finishReason?: FinishReason;
34
+ /**
35
+ * The stream completed normally: every provider-generated event was delivered before this
36
+ * outcome was produced.
37
+ *
38
+ * The stream ended in failure: validation, routing (no eligible provider), or every
39
+ * attempted provider failing.
40
+ *
41
+ * The stream was cancelled. No further StreamEvent is delivered after this outcome, and no
42
+ * further fallback attempt is made, per the engine's cancellation guarantee.
43
+ */
44
+ outcome: Outcome;
45
+ /**
46
+ * The stream run this outcome terminates, matching StreamRunHandle.runId and every
47
+ * StreamEvent.runId for the run.
48
+ */
49
+ runId: string;
50
+ /**
51
+ * Contract schema version used to interpret this outcome payload.
52
+ */
53
+ schemaVersion: "1.0";
54
+ /**
55
+ * Required metadata providing an overview of the execution result and performance metrics.
56
+ * Same shape as TaskResult.telemetry.
57
+ */
58
+ telemetry?: Telemetry;
59
+ /**
60
+ * Optional metadata regarding the quantity of tokens processed by the provider. Same shape
61
+ * as TaskResult.usage.
62
+ */
63
+ usage?: Usage;
64
+ /**
65
+ * The normalized error for this failure. Structurally identical to IndeRunError
66
+ * (contracts/schemas/inderun-error.schema.json), duplicated by value here rather than by
67
+ * $ref, matching this repo's schema convention of no cross-file references. Keep both
68
+ * shapes in sync; a cross-check test asserts a shared fixture validates against both
69
+ * schemas.
70
+ */
71
+ error?: Error;
72
+ /**
73
+ * Whatever cumulative text had already been delivered via content_delta/content_snapshot
74
+ * StreamEvents before the cancellation point. May be empty if cancellation occurred before
75
+ * any content was produced.
76
+ */
77
+ partialText?: string;
78
+ /**
79
+ * Optional human-readable reason the run was cancelled (e.g. caller-initiated abort). Not a
80
+ * machine-taxonomy field; use errorClass on the 'error' outcome branch for failure
81
+ * classification.
82
+ */
83
+ reason?: string;
84
+ [property: string]: unknown;
85
+ }
86
+
87
+ /**
88
+ * The normalized error for this failure. Structurally identical to IndeRunError
89
+ * (contracts/schemas/inderun-error.schema.json), duplicated by value here rather than by
90
+ * $ref, matching this repo's schema convention of no cross-file references. Keep both
91
+ * shapes in sync; a cross-check test asserts a shared fixture validates against both
92
+ * schemas.
93
+ */
94
+ export type Error = {
95
+ /**
96
+ * Optional structured diagnostic details. It must not contain raw secrets.
97
+ */
98
+ details?: { [key: string]: unknown };
99
+ /**
100
+ * Normalized error taxonomy, identical to IndeRunError.errorClass: CapabilityMismatch
101
+ * (request needs something no eligible provider supports), Offline/Unavailable (provider
102
+ * unreachable or not ready), AuthError (credential/auth failure), RateLimited (provider
103
+ * throttled the request), Timeout (provider exceeded its execution budget), Internal
104
+ * (unexpected engine-side failure).
105
+ */
106
+ errorClass: ErrorClass;
107
+ /**
108
+ * Human-readable error message suitable for logs and developer diagnostics.
109
+ */
110
+ message: string;
111
+ /**
112
+ * Identifier of the provider associated with the failure, if execution reached a provider.
113
+ */
114
+ providerId?: string;
115
+ /**
116
+ * Whether retrying the same request may succeed.
117
+ */
118
+ retryable?: boolean;
119
+ /**
120
+ * Optional suggested delay before retrying, in milliseconds.
121
+ */
122
+ retryAfterMs?: number;
123
+ /**
124
+ * Contract schema version used to interpret the error payload.
125
+ */
126
+ schemaVersion: "1.0";
127
+ [property: string]: unknown;
128
+ }
129
+
130
+ /**
131
+ * Normalized error taxonomy, identical to IndeRunError.errorClass: CapabilityMismatch
132
+ * (request needs something no eligible provider supports), Offline/Unavailable (provider
133
+ * unreachable or not ready), AuthError (credential/auth failure), RateLimited (provider
134
+ * throttled the request), Timeout (provider exceeded its execution budget), Internal
135
+ * (unexpected engine-side failure).
136
+ */
137
+ export type ErrorClass = "CapabilityMismatch" | "Offline" | "AuthError" | "RateLimited" | "Timeout" | "Unavailable" | "Internal";
138
+
139
+ /**
140
+ * How generation ended, mirroring TaskResult.finishReason for Mode 1: 'stop' (natural end),
141
+ * 'length' (hit maxOutputTokens), 'error' (provider reported a non-fatal issue on an
142
+ * otherwise completed run). 'cancelled' is included so this enum stays identical to
143
+ * TaskResult.finishReason, but it is unreachable here: cancellation is its own terminal
144
+ * outcome branch. Optional: providers that do not report a finish reason omit it.
145
+ */
146
+ export type FinishReason = "stop" | "length" | "cancelled" | "error";
147
+
148
+ export type Outcome = "completed" | "error" | "cancelled";
149
+
150
+ /**
151
+ * Required metadata providing an overview of the execution result and performance metrics.
152
+ * Same shape as TaskResult.telemetry.
153
+ */
154
+ export type Telemetry = {
155
+ /**
156
+ * The identifier for the specific provider that handled the request (e.g.,
157
+ * 'openai_compatible_cloud').
158
+ */
159
+ providerUsed: string;
160
+ /**
161
+ * Measured execution duration in milliseconds, including route selection and result
162
+ * processing.
163
+ */
164
+ totalMs: number;
165
+ [property: string]: unknown;
166
+ }
167
+
168
+ /**
169
+ * Optional metadata regarding the quantity of tokens processed by the provider. Same shape
170
+ * as TaskResult.usage.
171
+ */
172
+ export type Usage = {
173
+ /**
174
+ * Number of input tokens consumed, as reported by the provider.
175
+ */
176
+ inputTokens?: number;
177
+ /**
178
+ * Number of output tokens generated, as reported by the provider.
179
+ */
180
+ outputTokens?: number;
181
+ /**
182
+ * Aggregated token count for this request, as reported by the provider.
183
+ */
184
+ totalTokens?: number;
185
+ [property: string]: unknown;
186
+ }
@@ -0,0 +1,183 @@
1
+ /* This file was generated from JSON Schema using quicktype. Do not edit by hand. */
2
+
3
+ /**
4
+ * The request payload for a Mode 1 (request/response) text-to-text execution. At least one
5
+ * of `prompt` (single-turn) or `messages` (multi-turn) must be present — both may be
6
+ * present together, though callers should typically supply just one;
7
+ * `constraints`/`preferences` steer routing but never select a provider directly.
8
+ */
9
+ export type TaskRequest = {
10
+ /**
11
+ * A unique identifier used to retrieve credentials from a secure local storage. Raw
12
+ * sensitive keys (API keys, etc.) should NEVER be placed directly in the request payload.
13
+ */
14
+ authContextRef?: string;
15
+ /**
16
+ * Request-level routing constraints used by the planner.
17
+ */
18
+ constraints?: Constraints;
19
+ /**
20
+ * Optional configuration for fine-tuning how the AI model generates its response.
21
+ */
22
+ generation?: Generation;
23
+ /**
24
+ * A list of interaction messages for multi-turn conversation or chat-style execution.
25
+ */
26
+ messages?: [Message, ...Message[]];
27
+ /**
28
+ * Soft routing preferences used for deterministic provider ordering.
29
+ */
30
+ preferences?: Preferences;
31
+ /**
32
+ * A simple, single-turn text prompt used to trigger a response from the AI model.
33
+ */
34
+ prompt?: string;
35
+ /**
36
+ * Optional identifier for tracking or correlating this specific execution attempt.
37
+ */
38
+ requestId?: string;
39
+ /**
40
+ * Contract schema version used to interpret the request payload.
41
+ */
42
+ schemaVersion: "1.0";
43
+ /**
44
+ * A descriptor specifying the type of work to be performed. For text-to-text, the kind must
45
+ * be 'text_to_text'.
46
+ */
47
+ task: Task;
48
+ /**
49
+ * Execution preferences for tracking usage and performance metrics.
50
+ */
51
+ telemetry?: Telemetry;
52
+ [property: string]: unknown;
53
+ }
54
+
55
+ /**
56
+ * Request-level routing constraints used by the planner.
57
+ */
58
+ export type Constraints = {
59
+ /**
60
+ * Cloud execution constraint.
61
+ */
62
+ cloud?: Cloud;
63
+ /**
64
+ * Privacy requirement or preference for execution placement.
65
+ */
66
+ privacy?: Privacy;
67
+ /**
68
+ * Optional routing timeout budget in milliseconds.
69
+ */
70
+ timeoutMs?: number;
71
+ [property: string]: unknown;
72
+ }
73
+
74
+ /**
75
+ * Cloud execution constraint.
76
+ */
77
+ export type Cloud = "forbidden" | "allowed" | "required";
78
+
79
+ /**
80
+ * Privacy requirement or preference for execution placement.
81
+ */
82
+ export type Privacy = "local_required" | "local_preferred" | "cloud_allowed" | "cloud_required";
83
+
84
+ /**
85
+ * Optional configuration for fine-tuning how the AI model generates its response.
86
+ */
87
+ export type Generation = {
88
+ /**
89
+ * The maximum number of tokens to generate in a single response.
90
+ */
91
+ maxOutputTokens?: number;
92
+ /**
93
+ * A fixed seed for deterministic generation (where supported by the underlying provider).
94
+ */
95
+ seed?: number;
96
+ /**
97
+ * Sequence tokens that should terminate the generation process.
98
+ */
99
+ stop?: string[];
100
+ /**
101
+ * Controls the randomness of the output. Range: 0 (most deterministic) to 2 (highest
102
+ * variance).
103
+ */
104
+ temperature?: number;
105
+ /**
106
+ * Nucleus sampling parameter for controlling diversity vs focus in the output.
107
+ */
108
+ topP?: number;
109
+ [property: string]: unknown;
110
+ }
111
+
112
+ /**
113
+ * An individual message in a conversation.
114
+ */
115
+ export type Message = {
116
+ /**
117
+ * The actual text content of the message.
118
+ */
119
+ content: string;
120
+ /**
121
+ * The role of the author (e.g., 'user', 'assistant').
122
+ */
123
+ role: Role;
124
+ [property: string]: unknown;
125
+ }
126
+
127
+ /**
128
+ * The role of the author (e.g., 'user', 'assistant').
129
+ */
130
+ export type Role = "system" | "user" | "assistant";
131
+
132
+ /**
133
+ * Soft routing preferences used for deterministic provider ordering.
134
+ */
135
+ export type Preferences = {
136
+ /**
137
+ * Primary optimization goal when multiple providers remain eligible.
138
+ */
139
+ optimizeFor?: OptimizeFor;
140
+ [property: string]: unknown;
141
+ }
142
+
143
+ /**
144
+ * Primary optimization goal when multiple providers remain eligible.
145
+ */
146
+ export type OptimizeFor = "privacy" | "latency" | "cost" | "balanced";
147
+
148
+ /**
149
+ * A descriptor specifying the type of work to be performed. For text-to-text, the kind must
150
+ * be 'text_to_text'.
151
+ */
152
+ export type Task = {
153
+ /**
154
+ * The standard task category. Currently supports 'text_to_text' for prompt-based
155
+ * interactions.
156
+ */
157
+ kind: "text_to_text";
158
+ [property: string]: unknown;
159
+ }
160
+
161
+ /**
162
+ * Execution preferences for tracking usage and performance metrics.
163
+ */
164
+ export type Telemetry = {
165
+ /**
166
+ * Whether the user consents to telemetry collection for this specific request.
167
+ */
168
+ consent?: boolean;
169
+ /**
170
+ * The granularity of the collected metrics (off, minimal, or debug).
171
+ */
172
+ level?: Level;
173
+ /**
174
+ * Optional key-value pairs for correlating telemetry data with specific features or users.
175
+ */
176
+ tags?: { [key: string]: string };
177
+ [property: string]: unknown;
178
+ }
179
+
180
+ /**
181
+ * The granularity of the collected metrics (off, minimal, or debug).
182
+ */
183
+ export type Level = "off" | "minimal" | "debug";
@@ -0,0 +1,114 @@
1
+ /* This file was generated from JSON Schema using quicktype. Do not edit by hand. */
2
+
3
+ /**
4
+ * The response payload for a completed text-to-text execution. A full execution failure
5
+ * (validation, routing, or every attempted provider failing) is surfaced by run() throwing
6
+ * an IndeRunError instead of returning a TaskResult; finishReason and telemetry.errorClass
7
+ * are reserved for a provider reporting a non-fatal, degraded outcome on an
8
+ * otherwise-successful result (finishReason 'error' is produced by the Android ML Kit GenAI
9
+ * provider; telemetry.errorClass is not currently set by any provider in this codebase).
10
+ */
11
+ export type TaskResult = {
12
+ /**
13
+ * How generation ended: 'stop' (natural end), 'length' (hit maxOutputTokens), or
14
+ * 'cancelled'. 'error' is reserved for a provider reporting a non-fatal issue on an
15
+ * otherwise-returned result — the Android ML Kit GenAI provider produces it when Gemini
16
+ * Nano reports a finish reason that is neither a natural stop nor the token limit. A full
17
+ * execution failure is instead surfaced by run() throwing an IndeRunError.
18
+ */
19
+ finishReason: FinishReason;
20
+ /**
21
+ * The normalized content returned from the selected provider.
22
+ */
23
+ output: Output;
24
+ /**
25
+ * A unique, opaque identifier assigned by the engine for this specific execution attempt.
26
+ */
27
+ runId: string;
28
+ /**
29
+ * Contract schema version used to interpret the result payload.
30
+ */
31
+ schemaVersion: "1.0";
32
+ /**
33
+ * Required metadata providing an overview of the execution result and performance metrics.
34
+ */
35
+ telemetry: Telemetry;
36
+ /**
37
+ * Optional metadata regarding the quantity of tokens processed by the provider.
38
+ */
39
+ usage?: Usage;
40
+ [property: string]: unknown;
41
+ }
42
+
43
+ /**
44
+ * How generation ended: 'stop' (natural end), 'length' (hit maxOutputTokens), or
45
+ * 'cancelled'. 'error' is reserved for a provider reporting a non-fatal issue on an
46
+ * otherwise-returned result — the Android ML Kit GenAI provider produces it when Gemini
47
+ * Nano reports a finish reason that is neither a natural stop nor the token limit. A full
48
+ * execution failure is instead surfaced by run() throwing an IndeRunError.
49
+ */
50
+ export type FinishReason = "stop" | "length" | "cancelled" | "error";
51
+
52
+ /**
53
+ * The normalized content returned from the selected provider.
54
+ */
55
+ export type Output = {
56
+ /**
57
+ * The actual text generated by the execution.
58
+ */
59
+ text: string;
60
+ /**
61
+ * Output payload category (e.g., 'text' for Mode 1 text-to-text).
62
+ */
63
+ type: "text";
64
+ [property: string]: unknown;
65
+ }
66
+
67
+ /**
68
+ * Required metadata providing an overview of the execution result and performance metrics.
69
+ */
70
+ export type Telemetry = {
71
+ /**
72
+ * Present only if a provider reports a degraded outcome on an otherwise-successful result;
73
+ * no provider in this codebase currently sets this. Distinct from run() throwing — a thrown
74
+ * IndeRunError never produces a TaskResult at all.
75
+ */
76
+ errorClass?: ErrorClass;
77
+ /**
78
+ * The identifier for the specific provider that handled the request (e.g.,
79
+ * 'openai_compatible_cloud').
80
+ */
81
+ providerUsed: string;
82
+ /**
83
+ * Measured execution duration in milliseconds, including route selection and result
84
+ * processing.
85
+ */
86
+ totalMs: number;
87
+ [property: string]: unknown;
88
+ }
89
+
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
+ /**
98
+ * Optional metadata regarding the quantity of tokens processed by the provider.
99
+ */
100
+ export type Usage = {
101
+ /**
102
+ * Number of input tokens consumed, as reported by the provider.
103
+ */
104
+ inputTokens?: number;
105
+ /**
106
+ * Number of output tokens generated, as reported by the provider.
107
+ */
108
+ outputTokens?: number;
109
+ /**
110
+ * Aggregated token count for this request, as reported by the provider.
111
+ */
112
+ totalTokens?: number;
113
+ [property: string]: unknown;
114
+ }