@independo/inderun-web 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.
- package/README.md +46 -9
- package/dist/core/engine.d.ts +26 -2
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +78 -34
- package/dist/core/errors.d.ts +13 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +32 -0
- package/dist/core/model-profiles.d.ts +34 -0
- package/dist/core/model-profiles.d.ts.map +1 -0
- package/dist/core/model-profiles.js +49 -0
- package/dist/core/provenance.d.ts +32 -0
- package/dist/core/provenance.d.ts.map +1 -0
- package/dist/core/provenance.js +71 -0
- package/dist/core/provider.d.ts +13 -0
- package/dist/core/provider.d.ts.map +1 -1
- package/dist/core/route-planner.d.ts +1 -1
- package/dist/core/route-planner.d.ts.map +1 -1
- package/dist/core/route-planner.js +2 -1
- package/dist/core/router.d.ts +4 -3
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/router.js +4 -3
- package/dist/facade/text.d.ts +123 -0
- package/dist/facade/text.d.ts.map +1 -0
- package/dist/facade/text.js +234 -0
- package/dist/index.d.ts +36 -45
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -38
- package/dist/provider.d.ts +34 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +33 -0
- package/dist/providers/onnx/provider.d.ts.map +1 -1
- package/dist/providers/onnx/provider.js +1 -0
- package/dist/providers/openai/provider.d.ts +41 -11
- package/dist/providers/openai/provider.d.ts.map +1 -1
- package/dist/providers/openai/provider.js +168 -58
- package/dist/web-sdk.d.ts +21 -3
- package/dist/web-sdk.d.ts.map +1 -1
- package/dist/web-sdk.js +23 -6
- package/package.json +7 -3
- package/src/core/engine.ts +114 -35
- package/src/core/errors.ts +35 -1
- package/src/core/model-profiles.ts +70 -0
- package/src/core/provenance.ts +90 -0
- package/src/core/provider.ts +13 -0
- package/src/core/route-planner.ts +3 -1
- package/src/core/router.ts +12 -3
- package/src/facade/text.ts +349 -0
- package/src/index.ts +49 -95
- package/src/provider.ts +77 -0
- package/src/providers/onnx/provider.ts +1 -0
- package/src/providers/openai/provider.ts +232 -68
- package/src/web-sdk.ts +47 -10
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExecutionProvenance,
|
|
3
|
+
StreamEvent,
|
|
4
|
+
StreamTerminalOutcome,
|
|
5
|
+
TaskRequest,
|
|
6
|
+
TaskResult
|
|
7
|
+
} from "@independo/inderun-contracts";
|
|
8
|
+
import { IndeRunException } from "../core/errors.js";
|
|
9
|
+
import type { IndeRunApi } from "../core/generated/inderun-api.js";
|
|
10
|
+
import { AUTO_MODEL_PROFILE } from "../core/model-profiles.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The primary text API: `generateText()` and `streamText()`.
|
|
14
|
+
*
|
|
15
|
+
* Both are translation only. Each call compiles to exactly one canonical `TaskRequest`
|
|
16
|
+
* ({@link toTaskRequest}) and calls `run()` or `stream()` on the `IndeRunApi` it is given, so
|
|
17
|
+
* routing, fallback, cancellation, credentials, telemetry, and error normalization are the
|
|
18
|
+
* engine's and identical to a direct call. Written against the generated interface rather than
|
|
19
|
+
* the engine class, so anything that implements `IndeRunApi` -- a bridge included -- gets the
|
|
20
|
+
* same facade. See `docs/architecture/api-layering.md`.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
type Message = NonNullable<TaskRequest["messages"]>[number];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Compact execution policy. Reuses the canonical enum values, so moving a call between the
|
|
27
|
+
* facade and `run()` never changes what a constraint means.
|
|
28
|
+
*/
|
|
29
|
+
export interface TextExecutionOptions {
|
|
30
|
+
/** `constraints.privacy`: how strict placement is, e.g. `"local_required"`. */
|
|
31
|
+
privacy?: NonNullable<TaskRequest["constraints"]>["privacy"];
|
|
32
|
+
/** `constraints.cloud`: `"forbidden"`, `"allowed"`, or `"required"`. */
|
|
33
|
+
cloud?: NonNullable<TaskRequest["constraints"]>["cloud"];
|
|
34
|
+
/** `constraints.timeoutMs`. */
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
/** `preferences.optimizeFor`. */
|
|
37
|
+
optimizeFor?: NonNullable<TaskRequest["preferences"]>["optimizeFor"];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface TextGenerationCommonOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Model profile to route within, as configured on the engine. Omitted or `"auto"` routes
|
|
43
|
+
* across every registered target. Never a vendor model id.
|
|
44
|
+
*/
|
|
45
|
+
model?: string;
|
|
46
|
+
/** Instructions sent as a leading `system` message. */
|
|
47
|
+
system?: string;
|
|
48
|
+
maxOutputTokens?: number;
|
|
49
|
+
temperature?: number;
|
|
50
|
+
topP?: number;
|
|
51
|
+
stop?: string[];
|
|
52
|
+
seed?: number;
|
|
53
|
+
execution?: TextExecutionOptions;
|
|
54
|
+
/** Secure-storage slot for provider credentials. Never a raw secret. */
|
|
55
|
+
authContextRef?: string;
|
|
56
|
+
telemetry?: TaskRequest["telemetry"];
|
|
57
|
+
/** Fixes the run id, for correlation. */
|
|
58
|
+
requestId?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Options for {@link generateText} and {@link streamText}: a prompt or a message list. */
|
|
62
|
+
export type TextGenerationOptions = TextGenerationCommonOptions &
|
|
63
|
+
({ prompt: string; messages?: never } | { messages: Message[]; prompt?: never });
|
|
64
|
+
|
|
65
|
+
/** What {@link generateText} returns. */
|
|
66
|
+
export interface GeneratedText {
|
|
67
|
+
text: string;
|
|
68
|
+
finishReason: TaskResult["finishReason"];
|
|
69
|
+
usage?: TaskResult["usage"];
|
|
70
|
+
runId: string;
|
|
71
|
+
/** How the run played out; see `ExecutionProvenance`. */
|
|
72
|
+
provenance?: ExecutionProvenance;
|
|
73
|
+
/** The canonical result, for anything the summary above leaves out. */
|
|
74
|
+
taskResult: TaskResult;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** How a {@link streamText} run ended, when it did not fail. */
|
|
78
|
+
export interface StreamedText {
|
|
79
|
+
/** The full text, or the partial text a cancelled run had delivered. */
|
|
80
|
+
text: string;
|
|
81
|
+
/** `"cancelled"` when the run was cancelled; otherwise as the provider reported it. */
|
|
82
|
+
finishReason?: TaskResult["finishReason"];
|
|
83
|
+
usage?: TaskResult["usage"];
|
|
84
|
+
runId: string;
|
|
85
|
+
provenance?: ExecutionProvenance;
|
|
86
|
+
/** The canonical terminal outcome. */
|
|
87
|
+
outcome: StreamTerminalOutcome;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** What {@link streamText} returns. */
|
|
91
|
+
export interface TextStream {
|
|
92
|
+
runId: string;
|
|
93
|
+
/**
|
|
94
|
+
* Text increments, in order. Ends when the run completes or is cancelled; throws the run's
|
|
95
|
+
* `IndeRunException` when it fails, and {@link TextStreamRetractedError} when the provider
|
|
96
|
+
* replaces delivered text (use `fullStream` to render retractions).
|
|
97
|
+
*/
|
|
98
|
+
textStream: AsyncIterable<string>;
|
|
99
|
+
/** The canonical `StreamEvent` sequence, terminal included. */
|
|
100
|
+
fullStream: AsyncIterable<StreamEvent>;
|
|
101
|
+
/**
|
|
102
|
+
* Settles with the run's ending: resolves on completion or cancellation, rejects with the
|
|
103
|
+
* run's `IndeRunException` on failure.
|
|
104
|
+
*/
|
|
105
|
+
result: Promise<StreamedText>;
|
|
106
|
+
/** Cancels the run; idempotent. */
|
|
107
|
+
cancel(reason?: string): void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Thrown by `textStream` when the provider replaces text it already delivered with text that
|
|
112
|
+
* does not extend it, which an append-only text view cannot represent.
|
|
113
|
+
*/
|
|
114
|
+
export class TextStreamRetractedError extends Error {
|
|
115
|
+
constructor(readonly runId: string) {
|
|
116
|
+
super(
|
|
117
|
+
`Run ${runId} replaced text it had already delivered; read fullStream to render retractions.`
|
|
118
|
+
);
|
|
119
|
+
this.name = "TextStreamRetractedError";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The canonical `TaskRequest` a facade call compiles to. */
|
|
124
|
+
export function toTaskRequest(options: TextGenerationOptions): TaskRequest {
|
|
125
|
+
const request: TaskRequest = { schemaVersion: "1.0", task: { kind: "text_to_text" } };
|
|
126
|
+
|
|
127
|
+
if (options.system !== undefined) {
|
|
128
|
+
const conversation =
|
|
129
|
+
options.messages ??
|
|
130
|
+
(options.prompt !== undefined ? [{ role: "user" as const, content: options.prompt }] : []);
|
|
131
|
+
request.messages = [{ role: "system", content: options.system }, ...conversation];
|
|
132
|
+
} else if (options.messages !== undefined) {
|
|
133
|
+
// An empty list is the engine's to reject, with the same validation error as run().
|
|
134
|
+
request.messages = options.messages as NonNullable<TaskRequest["messages"]>;
|
|
135
|
+
} else if (options.prompt !== undefined) {
|
|
136
|
+
request.prompt = options.prompt;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (options.model !== undefined && options.model !== AUTO_MODEL_PROFILE) {
|
|
140
|
+
request.modelProfile = options.model;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const generation: NonNullable<TaskRequest["generation"]> = {};
|
|
144
|
+
if (options.maxOutputTokens !== undefined) generation.maxOutputTokens = options.maxOutputTokens;
|
|
145
|
+
if (options.temperature !== undefined) generation.temperature = options.temperature;
|
|
146
|
+
if (options.topP !== undefined) generation.topP = options.topP;
|
|
147
|
+
if (options.stop !== undefined) generation.stop = options.stop;
|
|
148
|
+
if (options.seed !== undefined) generation.seed = options.seed;
|
|
149
|
+
if (Object.keys(generation).length > 0) request.generation = generation;
|
|
150
|
+
|
|
151
|
+
const execution = options.execution ?? {};
|
|
152
|
+
const constraints: NonNullable<TaskRequest["constraints"]> = {};
|
|
153
|
+
if (execution.privacy !== undefined) constraints.privacy = execution.privacy;
|
|
154
|
+
if (execution.cloud !== undefined) constraints.cloud = execution.cloud;
|
|
155
|
+
if (execution.timeoutMs !== undefined) constraints.timeoutMs = execution.timeoutMs;
|
|
156
|
+
if (Object.keys(constraints).length > 0) request.constraints = constraints;
|
|
157
|
+
if (execution.optimizeFor !== undefined) {
|
|
158
|
+
request.preferences = { optimizeFor: execution.optimizeFor };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (options.authContextRef !== undefined) request.authContextRef = options.authContextRef;
|
|
162
|
+
if (options.telemetry !== undefined) request.telemetry = options.telemetry;
|
|
163
|
+
if (options.requestId !== undefined) request.requestId = options.requestId;
|
|
164
|
+
|
|
165
|
+
return request;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Generates text in one call: `run()` over the canonical request. Not cancellable, for the same
|
|
170
|
+
* reason `run()` is not; use {@link streamText} when cancellation matters.
|
|
171
|
+
* @throws {IndeRunException} Exactly as `run()` does.
|
|
172
|
+
*/
|
|
173
|
+
export async function generateText(
|
|
174
|
+
inderun: IndeRunApi,
|
|
175
|
+
options: TextGenerationOptions
|
|
176
|
+
): Promise<GeneratedText> {
|
|
177
|
+
const taskResult = await inderun.run(toTaskRequest(options));
|
|
178
|
+
return {
|
|
179
|
+
text: taskResult.output.text,
|
|
180
|
+
finishReason: taskResult.finishReason,
|
|
181
|
+
...(taskResult.usage !== undefined ? { usage: taskResult.usage } : {}),
|
|
182
|
+
runId: taskResult.runId,
|
|
183
|
+
...(taskResult.provenance !== undefined ? { provenance: taskResult.provenance } : {}),
|
|
184
|
+
taskResult
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Streams text: `stream()` over the canonical request. The run starts immediately and is read
|
|
190
|
+
* once, into a replay buffer, so `textStream`, `fullStream`, and `result` can each be consumed
|
|
191
|
+
* in any order (or not at all) without stalling the others.
|
|
192
|
+
* @throws {IndeRunException} Exactly as `stream()` does: validation and routing refusals reject
|
|
193
|
+
* here, before there is a run.
|
|
194
|
+
*/
|
|
195
|
+
export async function streamText(
|
|
196
|
+
inderun: IndeRunApi,
|
|
197
|
+
options: TextGenerationOptions
|
|
198
|
+
): Promise<TextStream> {
|
|
199
|
+
const run = await inderun.stream(toTaskRequest(options));
|
|
200
|
+
const runId = run.handle.runId;
|
|
201
|
+
const replay = new ReplayBuffer<StreamEvent>();
|
|
202
|
+
|
|
203
|
+
const result = (async (): Promise<StreamedText> => {
|
|
204
|
+
// The terminal event is the last one a run delivers, so it settles everything; a source
|
|
205
|
+
// that stays open after it (a bridge subscription, say) must not hold the result back.
|
|
206
|
+
// Releasing the source is not awaited for the same reason.
|
|
207
|
+
const events = run.events[Symbol.asyncIterator]();
|
|
208
|
+
try {
|
|
209
|
+
for (let next = await events.next(); next.done !== true; next = await events.next()) {
|
|
210
|
+
replay.push(next.value);
|
|
211
|
+
if (next.value.type === "terminal") {
|
|
212
|
+
void events.return?.()?.catch(() => undefined);
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
replay.close();
|
|
217
|
+
} catch (error) {
|
|
218
|
+
replay.fail(error);
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
const terminal = replay.items.find((event) => event.type === "terminal");
|
|
222
|
+
if (terminal === undefined) {
|
|
223
|
+
throw new IndeRunException({
|
|
224
|
+
errorClass: "Internal",
|
|
225
|
+
message: `Run ${runId} ended without a terminal event.`,
|
|
226
|
+
runId
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return settle(terminal.payload as unknown as StreamTerminalOutcome);
|
|
230
|
+
})();
|
|
231
|
+
// Consumers may read only one view; an unread rejection must not surface as unhandled.
|
|
232
|
+
result.catch(() => undefined);
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
runId,
|
|
236
|
+
fullStream: { [Symbol.asyncIterator]: () => replay.iterate() },
|
|
237
|
+
textStream: { [Symbol.asyncIterator]: () => textIncrements(replay.iterate(), runId) },
|
|
238
|
+
result,
|
|
239
|
+
cancel: (reason?: string) => run.cancel(reason)
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function settle(outcome: StreamTerminalOutcome): StreamedText {
|
|
244
|
+
const provenance = outcome.provenance !== undefined ? { provenance: outcome.provenance } : {};
|
|
245
|
+
switch (outcome.outcome) {
|
|
246
|
+
case "completed":
|
|
247
|
+
return {
|
|
248
|
+
text: outcome.finalText ?? "",
|
|
249
|
+
...(outcome.finishReason !== undefined ? { finishReason: outcome.finishReason } : {}),
|
|
250
|
+
...(outcome.usage !== undefined ? { usage: outcome.usage } : {}),
|
|
251
|
+
runId: outcome.runId,
|
|
252
|
+
...provenance,
|
|
253
|
+
outcome
|
|
254
|
+
};
|
|
255
|
+
case "cancelled":
|
|
256
|
+
return {
|
|
257
|
+
text: outcome.partialText ?? "",
|
|
258
|
+
finishReason: "cancelled",
|
|
259
|
+
runId: outcome.runId,
|
|
260
|
+
...provenance,
|
|
261
|
+
outcome
|
|
262
|
+
};
|
|
263
|
+
case "error": {
|
|
264
|
+
const error = outcome.error!;
|
|
265
|
+
throw new IndeRunException({
|
|
266
|
+
errorClass: error.errorClass,
|
|
267
|
+
message: error.message,
|
|
268
|
+
runId: outcome.runId,
|
|
269
|
+
...(error.providerId !== undefined ? { providerId: error.providerId } : {}),
|
|
270
|
+
...(error.retryable !== undefined ? { retryable: error.retryable } : {}),
|
|
271
|
+
...(error.retryAfterMs !== undefined ? { retryAfterMs: error.retryAfterMs } : {}),
|
|
272
|
+
...(error.details !== undefined ? { details: error.details } : {}),
|
|
273
|
+
...(outcome.provenance !== undefined ? { provenance: outcome.provenance } : {})
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async function* textIncrements(
|
|
280
|
+
events: AsyncIterable<StreamEvent>,
|
|
281
|
+
runId: string
|
|
282
|
+
): AsyncGenerator<string> {
|
|
283
|
+
let text = "";
|
|
284
|
+
for await (const event of events) {
|
|
285
|
+
if (event.type === "content_delta") {
|
|
286
|
+
const delta = (event.payload as { text: string }).text;
|
|
287
|
+
text += delta;
|
|
288
|
+
yield delta;
|
|
289
|
+
} else if (event.type === "content_snapshot") {
|
|
290
|
+
const snapshot = (event.payload as { text: string }).text;
|
|
291
|
+
if (!snapshot.startsWith(text)) {
|
|
292
|
+
throw new TextStreamRetractedError(runId);
|
|
293
|
+
}
|
|
294
|
+
const suffix = snapshot.slice(text.length);
|
|
295
|
+
text = snapshot;
|
|
296
|
+
if (suffix.length > 0) yield suffix;
|
|
297
|
+
} else if (event.type === "terminal") {
|
|
298
|
+
settle(event.payload as unknown as StreamTerminalOutcome);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Holds every item read from a single-use source so any number of readers can iterate it from
|
|
306
|
+
* the start, each at its own pace. Readers that catch up wait for the next item.
|
|
307
|
+
*/
|
|
308
|
+
class ReplayBuffer<T> {
|
|
309
|
+
readonly items: T[] = [];
|
|
310
|
+
private done = false;
|
|
311
|
+
private failure: { error: unknown } | undefined;
|
|
312
|
+
private waiters: (() => void)[] = [];
|
|
313
|
+
|
|
314
|
+
push(item: T): void {
|
|
315
|
+
this.items.push(item);
|
|
316
|
+
this.wake();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
close(): void {
|
|
320
|
+
this.done = true;
|
|
321
|
+
this.wake();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
fail(error: unknown): void {
|
|
325
|
+
this.failure = { error };
|
|
326
|
+
this.close();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async *iterate(): AsyncGenerator<T> {
|
|
330
|
+
let index = 0;
|
|
331
|
+
while (true) {
|
|
332
|
+
if (index < this.items.length) {
|
|
333
|
+
yield this.items[index++]!;
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (this.done) {
|
|
337
|
+
if (this.failure !== undefined) throw this.failure.error;
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
await new Promise<void>((resolve) => this.waiters.push(resolve));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
private wake(): void {
|
|
345
|
+
const waiters = this.waiters;
|
|
346
|
+
this.waiters = [];
|
|
347
|
+
for (const wake of waiters) wake();
|
|
348
|
+
}
|
|
349
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,94 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Application entry point for the IndeRun Web SDK (`@independo/inderun-web`).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* It leads with the primary text API (`generateText` / `streamText`) and the
|
|
5
|
+
* factory that builds a ready engine, then carries the advanced task API
|
|
6
|
+
* (`run()` / `stream()` / `checkCapabilities()`) and the contract, error and
|
|
7
|
+
* telemetry types those signatures use. See `docs/architecture/api-layering.md`.
|
|
8
|
+
*
|
|
9
|
+
* Two kinds of export live elsewhere on purpose:
|
|
10
|
+
* - provider-authoring and host-integration APIs ship from
|
|
11
|
+
* `@independo/inderun-web/provider`;
|
|
12
|
+
* - provider adapters ship from their own subpaths (`/openai`, `/onnx`,
|
|
13
|
+
* `/system-model`), so this surface stays provider-agnostic.
|
|
14
|
+
*
|
|
15
|
+
* The engine's internals (router, route planner bindings, Event Gate) are not
|
|
16
|
+
* exported at all.
|
|
9
17
|
*/
|
|
10
18
|
|
|
11
19
|
/**
|
|
12
|
-
*
|
|
13
|
-
* and the seams an embedder overrides to supply its own (custom transport,
|
|
14
|
-
* credential storage, clock).
|
|
20
|
+
* The primary text API: one canonical request per call, over any `IndeRunApi`.
|
|
15
21
|
*/
|
|
16
22
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type
|
|
22
|
-
type
|
|
23
|
-
type
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
|
|
27
|
-
type HostServices,
|
|
28
|
-
type ThermalState
|
|
29
|
-
} from "./core/host.js";
|
|
23
|
+
generateText,
|
|
24
|
+
streamText,
|
|
25
|
+
toTaskRequest,
|
|
26
|
+
TextStreamRetractedError,
|
|
27
|
+
type GeneratedText,
|
|
28
|
+
type StreamedText,
|
|
29
|
+
type TextExecutionOptions,
|
|
30
|
+
type TextGenerationOptions,
|
|
31
|
+
type TextStream
|
|
32
|
+
} from "./facade/text.js";
|
|
30
33
|
|
|
31
34
|
/**
|
|
32
|
-
* The
|
|
33
|
-
*
|
|
34
|
-
* router plans against.
|
|
35
|
+
* The recommended way in: builds host services, registers the providers named in
|
|
36
|
+
* the options, and returns a ready engine.
|
|
35
37
|
*/
|
|
36
38
|
export {
|
|
37
|
-
|
|
38
|
-
type
|
|
39
|
-
type
|
|
40
|
-
|
|
41
|
-
type ProviderAdapter,
|
|
42
|
-
type ProviderStreamContext,
|
|
43
|
-
type ProviderStreamEvent,
|
|
44
|
-
type StreamRun
|
|
45
|
-
} from "./core/provider.js";
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Per-run gatekeeper for a Mode 2 stream: assigns the sequence numbers callers
|
|
49
|
-
* order by, and enforces that exactly one terminal outcome is produced with
|
|
50
|
-
* nothing admitted after it. Exported for embedders driving a stream themselves.
|
|
51
|
-
*/
|
|
52
|
-
export { EventGate } from "./core/event-gate.js";
|
|
53
|
-
|
|
54
|
-
/** Holds the provider adapters a given engine instance can route to. */
|
|
55
|
-
export { ProviderRegistry } from "./core/registry.js";
|
|
39
|
+
createIndeRunWeb,
|
|
40
|
+
type CreateIndeRunWebOptions,
|
|
41
|
+
type OpenAIFactoryOptions
|
|
42
|
+
} from "./web-sdk.js";
|
|
56
43
|
|
|
57
44
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* the only planner the Web SDK has — there is no JavaScript fallback.
|
|
45
|
+
* Model profiles: application-defined names for ordered sets of targets that a
|
|
46
|
+
* request can route within. `"auto"` is built in.
|
|
61
47
|
*/
|
|
62
|
-
export { type
|
|
63
|
-
export {
|
|
64
|
-
type RoutePlanner,
|
|
65
|
-
type PlannerOutcome,
|
|
66
|
-
type WasmUnavailableReason,
|
|
67
|
-
type SharedPlannerInput,
|
|
68
|
-
type SharedPlannerRoutePlan,
|
|
69
|
-
WasmRoutePlanner
|
|
70
|
-
} from "./core/route-planner.js";
|
|
48
|
+
export { AUTO_MODEL_PROFILE, type ModelProfiles } from "./core/model-profiles.js";
|
|
71
49
|
|
|
72
50
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
51
|
+
* The advanced task API. `IndeRun` implements `IndeRunApi`; constructing one by
|
|
52
|
+
* hand takes a `ProviderRegistry` and `HostServices` from
|
|
53
|
+
* `@independo/inderun-web/provider`.
|
|
75
54
|
*/
|
|
76
|
-
export {
|
|
77
|
-
type IndeRunExceptionParams,
|
|
78
|
-
IndeRunException,
|
|
79
|
-
createCapabilityMismatch,
|
|
80
|
-
createOffline,
|
|
81
|
-
createAuthError,
|
|
82
|
-
createRateLimited,
|
|
83
|
-
createTimeout,
|
|
84
|
-
createUnavailable,
|
|
85
|
-
createInternal,
|
|
86
|
-
toIndeRunException
|
|
87
|
-
} from "./core/errors.js";
|
|
88
|
-
|
|
89
|
-
/** The engine itself, and the app-facing API surface it implements. */
|
|
90
|
-
export { IndeRun, type StreamHandleResult } from "./core/engine.js";
|
|
55
|
+
export { IndeRun, type IndeRunOptions, type StreamHandleResult } from "./core/engine.js";
|
|
91
56
|
export type { IndeRunApi } from "./core/generated/inderun-api.js";
|
|
57
|
+
export type { ProviderCapabilitySnapshot, StreamRun } from "./core/provider.js";
|
|
92
58
|
|
|
93
59
|
/**
|
|
94
60
|
* The contract types this SDK's own signatures take and return.
|
|
@@ -99,13 +65,14 @@ export type { IndeRunApi } from "./core/generated/inderun-api.js";
|
|
|
99
65
|
* This is the npm counterpart of Gradle `api(...)` on Android and `@_exported
|
|
100
66
|
* import` on Swift — see
|
|
101
67
|
* {@link https://github.com/independo-gmbh/inderun/issues/189 | #189}. The
|
|
102
|
-
*
|
|
103
|
-
* same contract surface for the same reason.
|
|
68
|
+
* telemetry block below and the host-service block of the `/provider` entry
|
|
69
|
+
* point re-export their halves of the same contract surface for the same reason.
|
|
104
70
|
*
|
|
105
71
|
* Depend on `@independo/inderun-contracts` directly only for what is not
|
|
106
72
|
* re-exported here: the JSON Schemas and the `get*ValidationIssues` validators.
|
|
107
73
|
*/
|
|
108
74
|
export type {
|
|
75
|
+
ExecutionProvenance,
|
|
109
76
|
IndeRunError,
|
|
110
77
|
IndeRunErrorClass,
|
|
111
78
|
StreamEvent,
|
|
@@ -115,6 +82,13 @@ export type {
|
|
|
115
82
|
TaskResult
|
|
116
83
|
} from "@independo/inderun-contracts";
|
|
117
84
|
|
|
85
|
+
/**
|
|
86
|
+
* The normalized error taxonomy. Every failure the SDK surfaces is an
|
|
87
|
+
* `IndeRunException` in one of these classes, whatever the provider raised.
|
|
88
|
+
* Provider authors create them with the `create*` helpers from `/provider`.
|
|
89
|
+
*/
|
|
90
|
+
export { IndeRunException, toIndeRunException } from "./core/errors.js";
|
|
91
|
+
|
|
118
92
|
/**
|
|
119
93
|
* Telemetry. Pass a `TelemetryService` to observe routing decisions and attempt
|
|
120
94
|
* outcomes; the engine defaults to `NoOpTelemetryService`.
|
|
@@ -125,23 +99,3 @@ export {
|
|
|
125
99
|
type TelemetryService,
|
|
126
100
|
NoOpTelemetryService
|
|
127
101
|
} from "./core/telemetry.js";
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* The browser implementations of the host services above, and the factory that
|
|
131
|
-
* assembles them. Use these directly only when constructing `IndeRun` by hand.
|
|
132
|
-
*/
|
|
133
|
-
export {
|
|
134
|
-
BrowserConnectivityService,
|
|
135
|
-
FetchHttpClient,
|
|
136
|
-
FetchStreamingHttpClient,
|
|
137
|
-
SystemClockService,
|
|
138
|
-
createBrowserHostServices,
|
|
139
|
-
type CreateBrowserHostServicesOptions,
|
|
140
|
-
type FetchHttpClientOptions
|
|
141
|
-
} from "./core/browser-host.js";
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* The recommended way in: builds host services, registers the providers named in
|
|
145
|
-
* the options, and returns a ready engine.
|
|
146
|
-
*/
|
|
147
|
-
export { createIndeRunWeb, type CreateIndeRunWebOptions } from "./web-sdk.js";
|
package/src/provider.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-authoring and host-integration entry point
|
|
3
|
+
* (`@independo/inderun-web/provider`).
|
|
4
|
+
*
|
|
5
|
+
* For code that extends the engine rather than calls it: custom provider
|
|
6
|
+
* adapters, custom host services (transport, credential storage, clock), and
|
|
7
|
+
* assembling an `IndeRun` by hand from a `ProviderRegistry`. Applications that
|
|
8
|
+
* only call `generateText` / `streamText` or `run()` / `stream()` need nothing
|
|
9
|
+
* from here. Changes to this surface are called out in release notes.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Host services: the platform capabilities the engine reads and calls through,
|
|
14
|
+
* and the seams an embedder overrides to supply its own.
|
|
15
|
+
*/
|
|
16
|
+
export {
|
|
17
|
+
type AbortSignalLike,
|
|
18
|
+
type ConnectivityService,
|
|
19
|
+
type DeviceConstraintsService,
|
|
20
|
+
type SecureStorageService,
|
|
21
|
+
type ClockService,
|
|
22
|
+
type HttpClientService,
|
|
23
|
+
type HttpRequest,
|
|
24
|
+
type HttpResponse,
|
|
25
|
+
type HttpStreamResponse,
|
|
26
|
+
type HttpStreamingClientService,
|
|
27
|
+
type HostServices,
|
|
28
|
+
type ThermalState
|
|
29
|
+
} from "./core/host.js";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The browser implementations of the host services above, and the factory that
|
|
33
|
+
* assembles them. Use these directly only when constructing `IndeRun` by hand.
|
|
34
|
+
*/
|
|
35
|
+
export {
|
|
36
|
+
BrowserConnectivityService,
|
|
37
|
+
FetchHttpClient,
|
|
38
|
+
FetchStreamingHttpClient,
|
|
39
|
+
SystemClockService,
|
|
40
|
+
createBrowserHostServices,
|
|
41
|
+
type CreateBrowserHostServicesOptions,
|
|
42
|
+
type FetchHttpClientOptions
|
|
43
|
+
} from "./core/browser-host.js";
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The provider contract. Implement `ProviderAdapter` for a Mode 1 backend and add
|
|
47
|
+
* a `stream` for Mode 2; the descriptor and dynamic capability check are what the
|
|
48
|
+
* router plans against.
|
|
49
|
+
*/
|
|
50
|
+
export {
|
|
51
|
+
type ProviderDescriptor,
|
|
52
|
+
type ProviderDynamicCapabilities,
|
|
53
|
+
type ProviderCapabilitySnapshot,
|
|
54
|
+
type RunContext,
|
|
55
|
+
type ProviderAdapter,
|
|
56
|
+
type ProviderStreamContext,
|
|
57
|
+
type ProviderStreamEvent,
|
|
58
|
+
type StreamRun
|
|
59
|
+
} from "./core/provider.js";
|
|
60
|
+
|
|
61
|
+
/** Holds the provider adapters a given engine instance can route to. */
|
|
62
|
+
export { ProviderRegistry } from "./core/registry.js";
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Constructors for the normalized error taxonomy. A provider maps every failure
|
|
66
|
+
* onto one of these classes; the engine does the rest.
|
|
67
|
+
*/
|
|
68
|
+
export {
|
|
69
|
+
type IndeRunExceptionParams,
|
|
70
|
+
createCapabilityMismatch,
|
|
71
|
+
createOffline,
|
|
72
|
+
createAuthError,
|
|
73
|
+
createRateLimited,
|
|
74
|
+
createTimeout,
|
|
75
|
+
createUnavailable,
|
|
76
|
+
createInternal
|
|
77
|
+
} from "./core/errors.js";
|