@independo/inderun-web 0.4.0 → 0.5.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.
- package/dist/core/artifacts.d.ts +110 -0
- package/dist/core/artifacts.d.ts.map +1 -0
- package/dist/core/artifacts.js +190 -0
- package/dist/core/engine.d.ts +28 -1
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +232 -28
- package/dist/core/generated/inderun-api.d.ts +12 -4
- package/dist/core/generated/inderun-api.d.ts.map +1 -1
- package/dist/core/host.d.ts +1 -1
- package/dist/core/host.d.ts.map +1 -1
- package/dist/core/provenance.d.ts +5 -2
- package/dist/core/provenance.d.ts.map +1 -1
- package/dist/core/provenance.js +6 -2
- package/dist/core/provider.d.ts +50 -130
- package/dist/core/provider.d.ts.map +1 -1
- package/dist/core/route-planner.d.ts +5 -5
- package/dist/core/route-planner.d.ts.map +1 -1
- package/dist/core/route-planner.js +15 -29
- package/dist/core/router.d.ts +16 -0
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/router.js +14 -5
- package/dist/core/task-profiles.d.ts +54 -0
- package/dist/core/task-profiles.d.ts.map +1 -0
- package/dist/core/task-profiles.js +92 -0
- package/dist/facade/text.d.ts.map +1 -1
- package/dist/facade/text.js +5 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/providers/onnx/runtime.d.ts +2 -2
- package/dist/providers/onnx/runtime.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/core/artifacts.ts +280 -0
- package/src/core/engine.ts +281 -27
- package/src/core/generated/inderun-api.ts +12 -4
- package/src/core/host.ts +1 -0
- package/src/core/provenance.ts +7 -2
- package/src/core/provider.ts +64 -135
- package/src/core/route-planner.ts +20 -36
- package/src/core/router.ts +30 -7
- package/src/core/task-profiles.ts +145 -0
- package/src/facade/text.ts +5 -3
- package/src/index.ts +6 -1
- package/src/providers/onnx/runtime.ts +2 -2
package/src/core/provider.ts
CHANGED
|
@@ -1,149 +1,36 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
ProviderDescriptor,
|
|
3
|
+
ProviderDynamicCapabilities,
|
|
4
|
+
SharedRoutePlan,
|
|
2
5
|
StreamEvent,
|
|
3
6
|
StreamRunHandle,
|
|
7
|
+
TaskOutput,
|
|
4
8
|
TaskRequest,
|
|
5
9
|
TaskResult
|
|
6
10
|
} from "@independo/inderun-contracts";
|
|
7
11
|
import type { HostServices } from "./host.js";
|
|
12
|
+
import type { ArtifactSink } from "./artifacts.js";
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
id: string;
|
|
18
|
-
/**
|
|
19
|
-
* Execution target type: 'local' (on-device), 'edge', or 'cloud'.
|
|
20
|
-
*/
|
|
21
|
-
type: "local" | "edge" | "cloud";
|
|
22
|
-
/**
|
|
23
|
-
* The model this provider instance is bound to, when it can name one. A provider
|
|
24
|
-
* instance bound to one model is a *target* that model profiles list by `id`.
|
|
25
|
-
* Cloud providers report the model id they send; platform-managed models report
|
|
26
|
-
* an opaque platform alias rather than a guessed weight name. Absent means the
|
|
27
|
-
* provider cannot name its model.
|
|
28
|
-
*/
|
|
29
|
-
model?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Connection transport layer protocol.
|
|
32
|
-
*/
|
|
33
|
-
transport: "in_process" | "system_service" | "http" | "sse" | "realtime";
|
|
34
|
-
/**
|
|
35
|
-
* Optional streaming style, if token or chunk streaming is supported.
|
|
36
|
-
*/
|
|
37
|
-
streamingStyle?: "tokens" | "chunks" | "snapshots";
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Flags representing the features and modes supported by this provider.
|
|
41
|
-
*/
|
|
42
|
-
supports: {
|
|
43
|
-
/** Whether the provider supports Mode 1 run (request/response). */
|
|
44
|
-
run: boolean;
|
|
45
|
-
/** Whether the provider supports Mode 2 stream. */
|
|
46
|
-
streaming: boolean;
|
|
47
|
-
/** Whether the provider supports Mode 3 realtime session. */
|
|
48
|
-
realtime: boolean;
|
|
49
|
-
/** Whether the provider supports tool calling definition. */
|
|
50
|
-
tools: boolean;
|
|
51
|
-
/** Whether the provider outputs reasoning events alongside contents. */
|
|
52
|
-
reasoningEvents: boolean;
|
|
53
|
-
/** Whether the provider supports structured outputs (JSON schema constraints). */
|
|
54
|
-
structuredOutput: boolean;
|
|
55
|
-
/** Whether the provider supports multimodal inputs (images, audio, etc.). */
|
|
56
|
-
multimodal: boolean;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Cancellation capabilities support:
|
|
61
|
-
* - 'hard': fully stops processing and interrupts remote operations.
|
|
62
|
-
* - 'soft': stops reading the stream locally, but the remote execution continues.
|
|
63
|
-
* - 'none': cancellation is unsupported.
|
|
64
|
-
*/
|
|
65
|
-
cancel: "hard" | "soft" | "none";
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* List of supported task kinds (e.g., 'text_to_text', 'embeddings').
|
|
69
|
-
*/
|
|
70
|
-
tasks: string[];
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Optional input/output resource boundaries.
|
|
74
|
-
*/
|
|
75
|
-
limits?: {
|
|
76
|
-
maxInputTokens?: number;
|
|
77
|
-
maxOutputTokens?: number;
|
|
78
|
-
maxImageBytes?: number;
|
|
79
|
-
maxAudioSeconds?: number;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Privacy settings regarding data egress.
|
|
84
|
-
*/
|
|
85
|
-
privacy?: {
|
|
86
|
-
/** Set to true if the model input leaves the host device. */
|
|
87
|
-
dataLeavesDevice: boolean;
|
|
88
|
-
/** Geographic regions where the cloud service executes. */
|
|
89
|
-
regions?: string[];
|
|
90
|
-
};
|
|
91
|
-
}
|
|
14
|
+
export type {
|
|
15
|
+
ArtifactChunk,
|
|
16
|
+
ArtifactLimits,
|
|
17
|
+
ArtifactSink,
|
|
18
|
+
ArtifactSpec,
|
|
19
|
+
ArtifactWriter
|
|
20
|
+
} from "./artifacts.js";
|
|
92
21
|
|
|
93
22
|
/**
|
|
94
|
-
*
|
|
23
|
+
* A provider's static declaration, live capability check, and the pair as
|
|
24
|
+
* `checkCapabilities()` returns it. All three are schema-backed contracts
|
|
25
|
+
* (`contracts/schemas/provider-*.schema.json`), shared with the Swift and Kotlin
|
|
26
|
+
* SDKs and with the route planner, so they are re-exported here rather than
|
|
27
|
+
* declared.
|
|
95
28
|
*/
|
|
96
|
-
export
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Detail message if availability check fails.
|
|
103
|
-
*/
|
|
104
|
-
reason?: string;
|
|
105
|
-
/**
|
|
106
|
-
* Whether the provider can stream (Mode 2) right now on this host. Leave
|
|
107
|
-
* undefined to inherit the static `descriptor.supports.streaming` value —
|
|
108
|
-
* only set it when the runtime environment can take streaming away from a
|
|
109
|
-
* provider that otherwise declares it (e.g. the host has no chunked HTTP
|
|
110
|
-
* capability).
|
|
111
|
-
*/
|
|
112
|
-
streamingAvailable?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Detail message used when `streamingAvailable` is false. Omit to let the
|
|
115
|
-
* route planner synthesize a generic message.
|
|
116
|
-
*/
|
|
117
|
-
streamingUnavailableReason?: string;
|
|
118
|
-
/**
|
|
119
|
-
* Whether cancellation is honored right now on this host. Leave undefined to
|
|
120
|
-
* inherit the static `descriptor.cancel` value (anything other than `"none"`
|
|
121
|
-
* means available).
|
|
122
|
-
*/
|
|
123
|
-
cancellationAvailable?: boolean;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* One registered provider's identity, fixed capabilities, and live availability,
|
|
128
|
-
* as of the moment checkCapabilities() was called.
|
|
129
|
-
*/
|
|
130
|
-
export interface ProviderCapabilitySnapshot {
|
|
131
|
-
/**
|
|
132
|
-
* Stable identifier for this provider, matching the value used in routing
|
|
133
|
-
* preferences/constraints.
|
|
134
|
-
*/
|
|
135
|
-
providerId: string;
|
|
136
|
-
/**
|
|
137
|
-
* The provider's static, unchanging capability declaration (supported modes,
|
|
138
|
-
* privacy posture, model info).
|
|
139
|
-
*/
|
|
140
|
-
descriptor: ProviderDescriptor;
|
|
141
|
-
/**
|
|
142
|
-
* The provider's current dynamic availability (e.g. whether it's reachable/loaded
|
|
143
|
-
* right now) — this is the part that can change between calls.
|
|
144
|
-
*/
|
|
145
|
-
capabilities: ProviderDynamicCapabilities;
|
|
146
|
-
}
|
|
29
|
+
export type {
|
|
30
|
+
ProviderCapabilitySnapshot,
|
|
31
|
+
ProviderDescriptor,
|
|
32
|
+
ProviderDynamicCapabilities
|
|
33
|
+
} from "@independo/inderun-contracts";
|
|
147
34
|
|
|
148
35
|
/**
|
|
149
36
|
* Execution context passed to provider run commands.
|
|
@@ -158,6 +45,37 @@ export interface RunContext {
|
|
|
158
45
|
* resolve authContextRef through secure storage and dispatch HTTP requests.
|
|
159
46
|
*/
|
|
160
47
|
hostServices: HostServices;
|
|
48
|
+
/**
|
|
49
|
+
* The voice the route plan bound this provider to for a speech task: provider-neutral
|
|
50
|
+
* traits the provider must honour when it picks the voice that speaks. Absent for tasks
|
|
51
|
+
* without a voice and for providers that do not list their voices, which then choose
|
|
52
|
+
* under the same rule (ADR 016 §4). The engine has re-checked it against the request's
|
|
53
|
+
* privacy policy immediately before the attempt.
|
|
54
|
+
*/
|
|
55
|
+
voice?: NonNullable<SharedRoutePlan["candidates"][number]["voice"]>;
|
|
56
|
+
/**
|
|
57
|
+
* Commits the run to this provider. Call it immediately before the attempt's first
|
|
58
|
+
* externally observable effect — for managed playback, no later than the first moment
|
|
59
|
+
* sound may reach the user. After commit, a failure ends the run instead of falling back
|
|
60
|
+
* to another provider, because a second provider would repeat what the user may already
|
|
61
|
+
* have heard.
|
|
62
|
+
*
|
|
63
|
+
* Returns `false` when the run can no longer commit (it was cancelled or has already
|
|
64
|
+
* ended) and when this attempt is over, e.g. a late callback after the engine fell back to
|
|
65
|
+
* another provider; the provider must then not start the effect and should end the attempt.
|
|
66
|
+
* Idempotent: calling it again after a successful commit returns `true`.
|
|
67
|
+
*
|
|
68
|
+
* Providers whose output is only delivered at the end (text from `run()`) need not call
|
|
69
|
+
* it. Text streams commit implicitly on their first content event.
|
|
70
|
+
*/
|
|
71
|
+
commit(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Where the provider writes retrievable media for an `artifact` request (ADR 017). The
|
|
74
|
+
* engine holds the bytes; the provider returns the reference `finish()` gives it in an
|
|
75
|
+
* `artifact` output. Finishing commits the run. Artifacts this attempt does not return,
|
|
76
|
+
* or that a failed or cancelled attempt wrote, are discarded by the engine.
|
|
77
|
+
*/
|
|
78
|
+
artifacts: ArtifactSink;
|
|
161
79
|
}
|
|
162
80
|
|
|
163
81
|
/**
|
|
@@ -202,6 +120,17 @@ export type ProviderStreamEvent =
|
|
|
202
120
|
*/
|
|
203
121
|
reportedModel?: string;
|
|
204
122
|
}
|
|
123
|
+
| {
|
|
124
|
+
/**
|
|
125
|
+
* The run's normalized output, for tasks whose output is not streamed text
|
|
126
|
+
* (playback completion, a media artifact). Ends the stream like `done`; handing it
|
|
127
|
+
* over commits the run if the provider has not already called `commit()`.
|
|
128
|
+
*/
|
|
129
|
+
kind: "result";
|
|
130
|
+
output: TaskOutput;
|
|
131
|
+
finishReason?: TaskResult["finishReason"];
|
|
132
|
+
reportedModel?: string;
|
|
133
|
+
}
|
|
205
134
|
| { kind: "error"; error: unknown };
|
|
206
135
|
|
|
207
136
|
/**
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
TaskRequest
|
|
5
5
|
} from "@independo/inderun-contracts";
|
|
6
6
|
import type { HostServices } from "./host.js";
|
|
7
|
+
import { taskProfileFor } from "./task-profiles.js";
|
|
7
8
|
import type {
|
|
8
9
|
ProviderAdapter,
|
|
9
10
|
ProviderDescriptor,
|
|
@@ -55,13 +56,13 @@ export interface RoutePlanner {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
|
-
* A provider paired with
|
|
59
|
-
* planner consumes.
|
|
59
|
+
* A provider paired with its descriptor and the dynamic capabilities the shared
|
|
60
|
+
* route planner consumes (already folded by {@link toSharedPlannerCapabilities}).
|
|
60
61
|
*/
|
|
61
62
|
export interface ProviderRuntimeSnapshot {
|
|
62
63
|
provider: ProviderAdapter;
|
|
63
|
-
descriptor:
|
|
64
|
-
capabilities:
|
|
64
|
+
descriptor: ProviderDescriptor;
|
|
65
|
+
capabilities: ProviderDynamicCapabilities;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
/**
|
|
@@ -161,7 +162,7 @@ export async function collectProviderRuntimeSnapshots(
|
|
|
161
162
|
|
|
162
163
|
return {
|
|
163
164
|
provider,
|
|
164
|
-
descriptor
|
|
165
|
+
descriptor,
|
|
165
166
|
capabilities: toSharedPlannerCapabilities(capabilities, descriptor, provider)
|
|
166
167
|
};
|
|
167
168
|
})
|
|
@@ -184,9 +185,7 @@ export function buildSharedPlannerInput(
|
|
|
184
185
|
const preferences = request.preferences ?? {};
|
|
185
186
|
|
|
186
187
|
return {
|
|
187
|
-
task:
|
|
188
|
-
kind: request.task.kind
|
|
189
|
-
},
|
|
188
|
+
task: plannerTask(request),
|
|
190
189
|
interactionMode,
|
|
191
190
|
constraints: {
|
|
192
191
|
privacy: constraints.privacy ?? "cloud_allowed",
|
|
@@ -205,27 +204,13 @@ export function buildSharedPlannerInput(
|
|
|
205
204
|
};
|
|
206
205
|
}
|
|
207
206
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
run: descriptor.supports.run,
|
|
216
|
-
streaming: descriptor.supports.streaming
|
|
217
|
-
},
|
|
218
|
-
cancel: descriptor.cancel,
|
|
219
|
-
tasks: descriptor.tasks,
|
|
220
|
-
...(descriptor.privacy
|
|
221
|
-
? {
|
|
222
|
-
privacy: {
|
|
223
|
-
dataLeavesDevice: descriptor.privacy.dataLeavesDevice,
|
|
224
|
-
...(descriptor.privacy.regions ? { regions: descriptor.privacy.regions } : {})
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
: {})
|
|
228
|
-
};
|
|
207
|
+
/**
|
|
208
|
+
* Projects the request's task onto the requirements the planner can check, through the
|
|
209
|
+
* kind's task profile. A kind without a profile carries the kind alone, which the planner
|
|
210
|
+
* matches against declarations and nothing else.
|
|
211
|
+
*/
|
|
212
|
+
function plannerTask(request: TaskRequest): SharedPlannerInput["task"] {
|
|
213
|
+
return taskProfileFor(request.task.kind)?.plannerTask(request) ?? { kind: request.task.kind };
|
|
229
214
|
}
|
|
230
215
|
|
|
231
216
|
/**
|
|
@@ -241,7 +226,7 @@ function toSharedPlannerCapabilities(
|
|
|
241
226
|
capabilities: ProviderDynamicCapabilities,
|
|
242
227
|
descriptor: ProviderDescriptor,
|
|
243
228
|
provider: ProviderAdapter
|
|
244
|
-
):
|
|
229
|
+
): ProviderDynamicCapabilities {
|
|
245
230
|
const declaresStreaming = capabilities.streamingAvailable ?? descriptor.supports.streaming;
|
|
246
231
|
const implementsStream = typeof provider.stream === "function";
|
|
247
232
|
const streamingAvailable = declaresStreaming && implementsStream;
|
|
@@ -251,13 +236,12 @@ function toSharedPlannerCapabilities(
|
|
|
251
236
|
? `Provider '${descriptor.id}' declares streaming but does not implement stream().`
|
|
252
237
|
: undefined);
|
|
253
238
|
|
|
239
|
+
// Spread rather than pick, so a field added to the schema reaches the planner
|
|
240
|
+
// without touching this function.
|
|
241
|
+
const { streamingUnavailableReason: _declaredReason, ...rest } = capabilities;
|
|
254
242
|
return {
|
|
255
|
-
|
|
256
|
-
...(capabilities.reason ? { reason: capabilities.reason } : {}),
|
|
243
|
+
...rest,
|
|
257
244
|
streamingAvailable,
|
|
258
|
-
...(!streamingAvailable && streamingUnavailableReason ? { streamingUnavailableReason } : {})
|
|
259
|
-
...(capabilities.cancellationAvailable !== undefined
|
|
260
|
-
? { cancellationAvailable: capabilities.cancellationAvailable }
|
|
261
|
-
: {})
|
|
245
|
+
...(!streamingAvailable && streamingUnavailableReason ? { streamingUnavailableReason } : {})
|
|
262
246
|
};
|
|
263
247
|
}
|
package/src/core/router.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { TaskRequest } from "@independo/inderun-contracts";
|
|
|
2
2
|
import type { HostServices } from "./host.js";
|
|
3
3
|
import type { ProviderAdapter } from "./provider.js";
|
|
4
4
|
import type { ProviderRegistry } from "./registry.js";
|
|
5
|
+
import type { BoundVoice } from "./task-profiles.js";
|
|
5
6
|
import {
|
|
6
7
|
createCapabilityMismatch,
|
|
7
8
|
createInternal,
|
|
@@ -19,6 +20,18 @@ import {
|
|
|
19
20
|
WasmRoutePlanner
|
|
20
21
|
} from "./route-planner.js";
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
* One provider in the planned chain, with the voice the plan bound it to (speech only).
|
|
25
|
+
*/
|
|
26
|
+
export interface RouteCandidate {
|
|
27
|
+
provider: ProviderAdapter;
|
|
28
|
+
/**
|
|
29
|
+
* The voice this provider must use, chosen by the planner within the request's privacy
|
|
30
|
+
* policy. Absent when the task has no voice or the provider does not list its voices.
|
|
31
|
+
*/
|
|
32
|
+
voice?: BoundVoice;
|
|
33
|
+
}
|
|
34
|
+
|
|
22
35
|
/**
|
|
23
36
|
* Output structure from the Router containing the chosen provider and a route selection description.
|
|
24
37
|
*/
|
|
@@ -31,6 +44,10 @@ export interface RouteSelection {
|
|
|
31
44
|
* Ordered fallback providers to try if the primary provider fails before producing a final result.
|
|
32
45
|
*/
|
|
33
46
|
fallbackProviders: ProviderAdapter[];
|
|
47
|
+
/**
|
|
48
|
+
* The whole chain in attempt order (`provider` first), each with its bound voice.
|
|
49
|
+
*/
|
|
50
|
+
candidates: RouteCandidate[];
|
|
34
51
|
/**
|
|
35
52
|
* The shared route plan used to select this provider chain.
|
|
36
53
|
*/
|
|
@@ -113,20 +130,26 @@ export class Router {
|
|
|
113
130
|
snapshots: ProviderRuntimeSnapshot[],
|
|
114
131
|
routePlan: SharedPlannerRoutePlan
|
|
115
132
|
): RouteSelection {
|
|
116
|
-
const
|
|
117
|
-
.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
133
|
+
const candidates = routePlan.candidates.flatMap((candidate): RouteCandidate[] => {
|
|
134
|
+
const snapshot = snapshots.find((s) => s.descriptor.id === candidate.providerId);
|
|
135
|
+
if (snapshot === undefined) return [];
|
|
136
|
+
return [
|
|
137
|
+
{
|
|
138
|
+
provider: snapshot.provider,
|
|
139
|
+
...(candidate.voice !== undefined ? { voice: candidate.voice } : {})
|
|
140
|
+
}
|
|
141
|
+
];
|
|
142
|
+
});
|
|
121
143
|
|
|
122
|
-
const selected =
|
|
144
|
+
const selected = candidates[0];
|
|
123
145
|
if (!selected) {
|
|
124
146
|
throw createInternal("Route plan selected a provider that is no longer registered.");
|
|
125
147
|
}
|
|
126
148
|
|
|
127
149
|
return {
|
|
128
150
|
provider: selected.provider,
|
|
129
|
-
fallbackProviders:
|
|
151
|
+
fallbackProviders: candidates.slice(1).map((candidate) => candidate.provider),
|
|
152
|
+
candidates,
|
|
130
153
|
routePlan,
|
|
131
154
|
explanation: routePlan.explanation.summary
|
|
132
155
|
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SharedRoutePlan,
|
|
3
|
+
SharedRoutePlannerInput,
|
|
4
|
+
TaskOutput,
|
|
5
|
+
TaskRequest
|
|
6
|
+
} from "@independo/inderun-contracts";
|
|
7
|
+
import { createCapabilityMismatch, createInternal, type IndeRunException } from "./errors.js";
|
|
8
|
+
|
|
9
|
+
/** How a task's result reaches the application: `inline`, `playback` or `artifact`. */
|
|
10
|
+
export type OutputDelivery = NonNullable<TaskRequest["delivery"]>["mode"];
|
|
11
|
+
/** The provider-neutral voice a route candidate is bound to. */
|
|
12
|
+
export type BoundVoice = NonNullable<SharedRoutePlan["candidates"][number]["voice"]>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* What the engine needs to know about one task kind (ADR 016). This table is the only
|
|
16
|
+
* place the engine branches on `task.kind`: which kinds it executes, the projection onto
|
|
17
|
+
* the planner's task requirements, and the output delivery a result must have. (Per-kind
|
|
18
|
+
* request requirements are the schema's `if`/`then` branches, checked by the validator.) Everything else — routing, fallback, cancellation, provenance — is task-agnostic,
|
|
19
|
+
* so a new task adds an entry here rather than a second execution path.
|
|
20
|
+
*
|
|
21
|
+
* The Swift (`TaskProfiles.swift`) and Kotlin (`TaskProfiles.kt`) engines keep the same
|
|
22
|
+
* table; `contracts/fixtures/task-contracts/` holds the planner projection all three must
|
|
23
|
+
* produce for each request.
|
|
24
|
+
*/
|
|
25
|
+
export interface TaskProfile {
|
|
26
|
+
/** The `task.kind` this profile describes. */
|
|
27
|
+
readonly kind: string;
|
|
28
|
+
/** Projects the request onto the requirements the shared planner can check. */
|
|
29
|
+
plannerTask(request: TaskRequest): SharedRoutePlannerInput["task"];
|
|
30
|
+
/** The output delivery the request asks for: `inline` for text, else `delivery.mode`. */
|
|
31
|
+
delivery(request: TaskRequest): OutputDelivery;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const textToText: TaskProfile = {
|
|
35
|
+
kind: "text_to_text",
|
|
36
|
+
plannerTask: () => ({ kind: "text_to_text", inputs: ["text"] }),
|
|
37
|
+
delivery: () => "inline"
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const textToSpeech: TaskProfile = {
|
|
41
|
+
kind: "text_to_speech",
|
|
42
|
+
plannerTask: (request) => {
|
|
43
|
+
// The schema requires both for this kind; validation runs before projection.
|
|
44
|
+
const speech = request.speech!;
|
|
45
|
+
const delivery = request.delivery!;
|
|
46
|
+
return {
|
|
47
|
+
kind: "text_to_speech",
|
|
48
|
+
inputs: ["text"],
|
|
49
|
+
delivery: {
|
|
50
|
+
mode: delivery.mode,
|
|
51
|
+
...(delivery.mediaTypes !== undefined ? { mediaTypes: [...delivery.mediaTypes] } : {})
|
|
52
|
+
},
|
|
53
|
+
locale: { tag: speech.locale, match: speech.localeMatch ?? "language" },
|
|
54
|
+
...(speech.voice !== undefined
|
|
55
|
+
? {
|
|
56
|
+
voice: {
|
|
57
|
+
...(speech.voice.gender !== undefined ? { gender: speech.voice.gender } : {}),
|
|
58
|
+
requirement: speech.voice.requirement ?? "preferred"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
: {})
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
delivery: (request) => request.delivery!.mode
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const taskProfiles = new Map<string, TaskProfile>([
|
|
68
|
+
[textToText.kind, textToText],
|
|
69
|
+
[textToSpeech.kind, textToSpeech]
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Adds a task profile. Internal and not exported from the package: a real task needs its
|
|
74
|
+
* schema kind and payload first (ADR 016). It exists so a test can prove a third task runs
|
|
75
|
+
* through routing, execution and output normalization without changing the engine.
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
export function registerTaskProfile(profile: TaskProfile): void {
|
|
79
|
+
taskProfiles.set(profile.kind, profile);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The profile for `kind`, or `undefined` when this engine cannot execute the task. */
|
|
83
|
+
export function taskProfileFor(kind: string): TaskProfile | undefined {
|
|
84
|
+
return taskProfiles.get(kind);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Re-checks, immediately before an attempt, that the voice the plan bound for this
|
|
89
|
+
* provider still satisfies the request's privacy policy. The planner already chose the
|
|
90
|
+
* voice inside that policy; repeating the check here keeps privacy enforceable at the
|
|
91
|
+
* last point before data reaches the provider, independent of how the plan was produced.
|
|
92
|
+
* A violation fails the attempt before commit, so the run may fall back.
|
|
93
|
+
*
|
|
94
|
+
* @returns The exception to fail the attempt with, or `undefined` when the voice is allowed.
|
|
95
|
+
*/
|
|
96
|
+
export function recheckBoundVoice(
|
|
97
|
+
request: TaskRequest,
|
|
98
|
+
providerId: string,
|
|
99
|
+
voice: BoundVoice | undefined
|
|
100
|
+
): IndeRunException | undefined {
|
|
101
|
+
if (voice?.networkRequired !== true || request.constraints?.privacy !== "local_required") {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
return createCapabilityMismatch(
|
|
105
|
+
`Provider '${providerId}' was bound to a voice that sends data off the device, which privacy=local_required forbids.`,
|
|
106
|
+
{ providerId, details: { code: "privacy_recheck_failed" } }
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Checks a provider's output against the delivery the request asked for: inline text for
|
|
112
|
+
* `inline`, a playback completion for `playback`, a media artifact for `artifact` whose
|
|
113
|
+
* media type is one the request accepts. A provider never substitutes one for another
|
|
114
|
+
* (ADR 016 §4), so a mismatch is a provider fault, not a result.
|
|
115
|
+
*
|
|
116
|
+
* @returns The exception to fail the attempt with, or `undefined` when the output matches.
|
|
117
|
+
*/
|
|
118
|
+
export function checkOutput(
|
|
119
|
+
request: TaskRequest,
|
|
120
|
+
delivery: OutputDelivery,
|
|
121
|
+
output: TaskOutput | undefined,
|
|
122
|
+
providerId: string
|
|
123
|
+
): IndeRunException | undefined {
|
|
124
|
+
const expected = { inline: "text", playback: "playback", artifact: "artifact" }[delivery];
|
|
125
|
+
const matches =
|
|
126
|
+
output?.type === expected &&
|
|
127
|
+
(expected === "text"
|
|
128
|
+
? typeof output.text === "string"
|
|
129
|
+
: expected === "playback"
|
|
130
|
+
? output.playback !== undefined
|
|
131
|
+
: output.artifact !== undefined && acceptsMediaType(request, output.artifact.mediaType));
|
|
132
|
+
if (matches) return undefined;
|
|
133
|
+
return createInternal(
|
|
134
|
+
`Provider '${providerId}' returned ${output === undefined ? "no output" : `a '${output.type}' output`} for a '${delivery}' request.`,
|
|
135
|
+
{ providerId, details: { code: "output_mismatch" } }
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Whether `mediaType` (parameters ignored, case-insensitive) is one the request accepts. */
|
|
140
|
+
function acceptsMediaType(request: TaskRequest, mediaType: string): boolean {
|
|
141
|
+
const accepted = request.delivery?.mediaTypes;
|
|
142
|
+
if (accepted === undefined) return true;
|
|
143
|
+
const base = (type: string) => type.split(";")[0]!.trim().toLowerCase();
|
|
144
|
+
return accepted.some((type) => base(type) === base(mediaType));
|
|
145
|
+
}
|
package/src/facade/text.ts
CHANGED
|
@@ -176,7 +176,9 @@ export async function generateText(
|
|
|
176
176
|
): Promise<GeneratedText> {
|
|
177
177
|
const taskResult = await inderun.run(toTaskRequest(options));
|
|
178
178
|
return {
|
|
179
|
-
text
|
|
179
|
+
// A text run always produces text output; the generated type is optional only because
|
|
180
|
+
// TaskOutput also describes playback and artifacts (ADR 016).
|
|
181
|
+
text: taskResult.output.text ?? "",
|
|
180
182
|
finishReason: taskResult.finishReason,
|
|
181
183
|
...(taskResult.usage !== undefined ? { usage: taskResult.usage } : {}),
|
|
182
184
|
runId: taskResult.runId,
|
|
@@ -245,7 +247,7 @@ function settle(outcome: StreamTerminalOutcome): StreamedText {
|
|
|
245
247
|
switch (outcome.outcome) {
|
|
246
248
|
case "completed":
|
|
247
249
|
return {
|
|
248
|
-
text: outcome.finalText ?? "",
|
|
250
|
+
text: outcome.finalText ?? outcome.output?.text ?? "",
|
|
249
251
|
...(outcome.finishReason !== undefined ? { finishReason: outcome.finishReason } : {}),
|
|
250
252
|
...(outcome.usage !== undefined ? { usage: outcome.usage } : {}),
|
|
251
253
|
runId: outcome.runId,
|
|
@@ -254,7 +256,7 @@ function settle(outcome: StreamTerminalOutcome): StreamedText {
|
|
|
254
256
|
};
|
|
255
257
|
case "cancelled":
|
|
256
258
|
return {
|
|
257
|
-
text: outcome.partialText ?? "",
|
|
259
|
+
text: outcome.partialText ?? outcome.output?.text ?? "",
|
|
258
260
|
finishReason: "cancelled",
|
|
259
261
|
runId: outcome.runId,
|
|
260
262
|
...provenance,
|
package/src/index.ts
CHANGED
|
@@ -54,7 +54,12 @@ export { AUTO_MODEL_PROFILE, type ModelProfiles } from "./core/model-profiles.js
|
|
|
54
54
|
*/
|
|
55
55
|
export { IndeRun, type IndeRunOptions, type StreamHandleResult } from "./core/engine.js";
|
|
56
56
|
export type { IndeRunApi } from "./core/generated/inderun-api.js";
|
|
57
|
-
export type {
|
|
57
|
+
export type {
|
|
58
|
+
ArtifactChunk,
|
|
59
|
+
ArtifactLimits,
|
|
60
|
+
ProviderCapabilitySnapshot,
|
|
61
|
+
StreamRun
|
|
62
|
+
} from "./core/provider.js";
|
|
58
63
|
|
|
59
64
|
/**
|
|
60
65
|
* The contract types this SDK's own signatures take and return.
|
|
@@ -8,12 +8,12 @@ import type { ModelPackage, TaskRequest, TaskResult } from "@independo/inderun-c
|
|
|
8
8
|
* flattens every failure into a single `capability_unavailable` route rejection and carries the
|
|
9
9
|
* reason as human-readable text.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type OnnxRuntimeAvailability = {
|
|
12
12
|
/** Whether the runtime can execute the given model package on this host right now. */
|
|
13
13
|
available: boolean;
|
|
14
14
|
/** Human-readable detail describing why the runtime is unavailable. */
|
|
15
15
|
reason?: string;
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Normalized conversation turn handed to an ONNX text generation runtime.
|