@independo/inderun-web 0.2.0-dev.1 → 0.2.0-dev.10
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 +187 -1
- package/dist/core/browser-host.d.ts.map +1 -0
- package/dist/{engine.d.ts → core/engine.d.ts} +6 -0
- package/dist/core/engine.d.ts.map +1 -0
- package/dist/{engine.js → core/engine.js} +14 -1
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/host.d.ts.map +1 -0
- package/dist/{provider.d.ts → core/provider.d.ts} +9 -0
- package/dist/core/provider.d.ts.map +1 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/{route-planner.d.ts → core/route-planner.d.ts} +31 -8
- package/dist/core/route-planner.d.ts.map +1 -0
- package/dist/{route-planner.js → core/route-planner.js} +46 -17
- package/dist/{router.d.ts → core/router.d.ts} +11 -1
- package/dist/core/router.d.ts.map +1 -0
- package/dist/{router.js → core/router.js} +26 -20
- package/dist/core/telemetry.d.ts.map +1 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/onnx.d.ts +13 -0
- package/dist/onnx.d.ts.map +1 -0
- package/dist/onnx.js +12 -0
- package/dist/openai.d.ts +1 -1
- package/dist/openai.d.ts.map +1 -1
- package/dist/openai.js +1 -1
- package/dist/providers/onnx/provider.d.ts +78 -0
- package/dist/providers/onnx/provider.d.ts.map +1 -0
- package/dist/providers/onnx/provider.js +217 -0
- package/dist/providers/onnx/runtime.d.ts +110 -0
- package/dist/providers/onnx/runtime.d.ts.map +1 -0
- package/dist/providers/onnx/runtime.js +76 -0
- package/dist/providers/onnx/transformers-runtime.d.ts +72 -0
- package/dist/providers/onnx/transformers-runtime.d.ts.map +1 -0
- package/dist/providers/onnx/transformers-runtime.js +210 -0
- package/dist/{openai-provider.d.ts → providers/openai/provider.d.ts} +21 -3
- package/dist/providers/openai/provider.d.ts.map +1 -0
- package/dist/{openai-provider.js → providers/openai/provider.js} +42 -2
- package/dist/providers/system-model/chrome-runtime.d.ts +48 -0
- package/dist/providers/system-model/chrome-runtime.d.ts.map +1 -0
- package/dist/providers/system-model/chrome-runtime.js +137 -0
- package/dist/providers/system-model/provider.d.ts +67 -0
- package/dist/providers/system-model/provider.d.ts.map +1 -0
- package/dist/providers/system-model/provider.js +190 -0
- package/dist/providers/system-model/runtime.d.ts +110 -0
- package/dist/providers/system-model/runtime.d.ts.map +1 -0
- package/dist/providers/system-model/runtime.js +73 -0
- package/dist/system-model.d.ts +13 -0
- package/dist/system-model.d.ts.map +1 -0
- package/dist/system-model.js +12 -0
- package/dist/web-sdk.d.ts +23 -6
- package/dist/web-sdk.d.ts.map +1 -1
- package/dist/web-sdk.js +29 -12
- package/package.json +21 -5
- package/dist/browser-host.d.ts.map +0 -1
- package/dist/engine.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/host.d.ts.map +0 -1
- package/dist/openai-provider.d.ts.map +0 -1
- package/dist/provider.d.ts.map +0 -1
- package/dist/registry.d.ts.map +0 -1
- package/dist/route-planner.d.ts.map +0 -1
- package/dist/router.d.ts.map +0 -1
- package/dist/telemetry.d.ts.map +0 -1
- /package/dist/{browser-host.d.ts → core/browser-host.d.ts} +0 -0
- /package/dist/{browser-host.js → core/browser-host.js} +0 -0
- /package/dist/{errors.d.ts → core/errors.d.ts} +0 -0
- /package/dist/{errors.js → core/errors.js} +0 -0
- /package/dist/{host.d.ts → core/host.d.ts} +0 -0
- /package/dist/{host.js → core/host.js} +0 -0
- /package/dist/{provider.js → core/provider.js} +0 -0
- /package/dist/{registry.d.ts → core/registry.d.ts} +0 -0
- /package/dist/{registry.js → core/registry.js} +0 -0
- /package/dist/{telemetry.d.ts → core/telemetry.d.ts} +0 -0
- /package/dist/{telemetry.js → core/telemetry.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export {} from "./host.js";
|
|
2
|
-
export {} from "./provider.js";
|
|
3
|
-
export { ProviderRegistry } from "./registry.js";
|
|
4
|
-
export { Router } from "./router.js";
|
|
5
|
-
export { WasmRoutePlanner } from "./route-planner.js";
|
|
6
|
-
export { IndeRunException, createCapabilityMismatch, createOffline, createAuthError, createRateLimited, createTimeout, createUnavailable, createInternal, toIndeRunException } from "./errors.js";
|
|
7
|
-
export { IndeRun } from "./engine.js";
|
|
8
|
-
export { NoOpTelemetryService } from "./telemetry.js";
|
|
9
|
-
export { BrowserConnectivityService, FetchHttpClient, SystemClockService, createBrowserHostServices } from "./browser-host.js";
|
|
1
|
+
export {} from "./core/host.js";
|
|
2
|
+
export {} from "./core/provider.js";
|
|
3
|
+
export { ProviderRegistry } from "./core/registry.js";
|
|
4
|
+
export { Router } from "./core/router.js";
|
|
5
|
+
export { WasmRoutePlanner } from "./core/route-planner.js";
|
|
6
|
+
export { IndeRunException, createCapabilityMismatch, createOffline, createAuthError, createRateLimited, createTimeout, createUnavailable, createInternal, toIndeRunException } from "./core/errors.js";
|
|
7
|
+
export { IndeRun } from "./core/engine.js";
|
|
8
|
+
export { NoOpTelemetryService } from "./core/telemetry.js";
|
|
9
|
+
export { BrowserConnectivityService, FetchHttpClient, SystemClockService, createBrowserHostServices } from "./core/browser-host.js";
|
|
10
10
|
export { createIndeRunWeb } from "./web-sdk.js";
|
|
11
11
|
// The OpenAI Responses adapter is provider-specific and intentionally excluded
|
|
12
12
|
// from this unified index. Import it from "@independo/inderun-web/openai".
|
package/dist/onnx.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-specific entry point for the Web member of the ONNX Runtime provider family.
|
|
3
|
+
*
|
|
4
|
+
* Kept out of the unified SDK index (`@independo/inderun-web`) so the top-level
|
|
5
|
+
* surface stays provider-agnostic. Import from `@independo/inderun-web/onnx`
|
|
6
|
+
* when registering the adapter manually or when implementing a custom
|
|
7
|
+
* `OnnxTextGenerationRuntime`; most browser apps should pass `onnx` to
|
|
8
|
+
* `createIndeRunWeb` from the main entry point instead.
|
|
9
|
+
*/
|
|
10
|
+
export { OnnxRuntimeWebProvider, DEFAULT_ONNX_WEB_PROVIDER_ID, SUPPORTED_WEB_MODEL_SOURCE_TYPES, type OnnxProviderOptions } from "./providers/onnx/provider.js";
|
|
11
|
+
export { OnnxRuntimeError, createFixtureOnnxRuntime, type FixtureOnnxRuntimeOptions, type OnnxGenerationInput, type OnnxGenerationMessage, type OnnxGenerationOutput, type OnnxRuntimeAvailability, type OnnxRuntimeErrorKind, type OnnxTextGenerationRuntime } from "./providers/onnx/runtime.js";
|
|
12
|
+
export { createTransformersJsRuntime, type TransformersJsRuntimeOptions, type TransformersModule, type TransformersTextGenerator } from "./providers/onnx/transformers-runtime.js";
|
|
13
|
+
//# sourceMappingURL=onnx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onnx.d.ts","sourceRoot":"","sources":["../src/onnx.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,gCAAgC,EAChC,KAAK,mBAAmB,EACzB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC/B,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,2BAA2B,EAC3B,KAAK,4BAA4B,EACjC,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC/B,MAAM,0CAA0C,CAAC"}
|
package/dist/onnx.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-specific entry point for the Web member of the ONNX Runtime provider family.
|
|
3
|
+
*
|
|
4
|
+
* Kept out of the unified SDK index (`@independo/inderun-web`) so the top-level
|
|
5
|
+
* surface stays provider-agnostic. Import from `@independo/inderun-web/onnx`
|
|
6
|
+
* when registering the adapter manually or when implementing a custom
|
|
7
|
+
* `OnnxTextGenerationRuntime`; most browser apps should pass `onnx` to
|
|
8
|
+
* `createIndeRunWeb` from the main entry point instead.
|
|
9
|
+
*/
|
|
10
|
+
export { OnnxRuntimeWebProvider, DEFAULT_ONNX_WEB_PROVIDER_ID, SUPPORTED_WEB_MODEL_SOURCE_TYPES } from "./providers/onnx/provider.js";
|
|
11
|
+
export { OnnxRuntimeError, createFixtureOnnxRuntime } from "./providers/onnx/runtime.js";
|
|
12
|
+
export { createTransformersJsRuntime } from "./providers/onnx/transformers-runtime.js";
|
package/dist/openai.d.ts
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* when registering the adapter manually; most browser apps should use
|
|
7
7
|
* `createIndeRunWeb` from the main entry point instead.
|
|
8
8
|
*/
|
|
9
|
-
export { OpenAIResponsesProvider, type OpenAIProviderOptions, DEFAULT_OPENAI_RESPONSES_ENDPOINT } from "./openai
|
|
9
|
+
export { OpenAIResponsesProvider, type OpenAIProviderOptions, DEFAULT_OPENAI_RESPONSES_ENDPOINT } from "./providers/openai/provider.js";
|
|
10
10
|
//# sourceMappingURL=openai.d.ts.map
|
package/dist/openai.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../src/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,iCAAiC,EAClC,MAAM,
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../src/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,iCAAiC,EAClC,MAAM,gCAAgC,CAAC"}
|
package/dist/openai.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* when registering the adapter manually; most browser apps should use
|
|
7
7
|
* `createIndeRunWeb` from the main entry point instead.
|
|
8
8
|
*/
|
|
9
|
-
export { OpenAIResponsesProvider, DEFAULT_OPENAI_RESPONSES_ENDPOINT } from "./openai
|
|
9
|
+
export { OpenAIResponsesProvider, DEFAULT_OPENAI_RESPONSES_ENDPOINT } from "./providers/openai/provider.js";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type ModelPackage, type ModelSourceType, type TaskRequest, type TaskResult } from "@independo/inderun-contracts";
|
|
2
|
+
import type { HostServices } from "../../core/host.js";
|
|
3
|
+
import { type OnnxTextGenerationRuntime } from "./runtime.js";
|
|
4
|
+
import type { ProviderAdapter, ProviderDescriptor, ProviderDynamicCapabilities, RunContext } from "../../core/provider.js";
|
|
5
|
+
/** Default provider id of the Web member of the ONNX Runtime provider family. */
|
|
6
|
+
export declare const DEFAULT_ONNX_WEB_PROVIDER_ID = "local.onnx.genai.web";
|
|
7
|
+
/**
|
|
8
|
+
* Model source types the Web member of the ONNX Runtime provider family can honor.
|
|
9
|
+
*
|
|
10
|
+
* `filesystem` is unsupported because browsers do not expose arbitrary local paths, and `remote`
|
|
11
|
+
* is deferred: hosts download model files themselves and then supply them as `bundled`,
|
|
12
|
+
* `app_managed`, or `programmatic`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const SUPPORTED_WEB_MODEL_SOURCE_TYPES: readonly ModelSourceType[];
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for the Web ONNX Runtime provider.
|
|
17
|
+
*/
|
|
18
|
+
export interface OnnxProviderOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Provider id exposed in telemetry and routing explanations.
|
|
21
|
+
*/
|
|
22
|
+
id?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Provider-neutral bootstrap metadata describing the developer-supplied model.
|
|
25
|
+
*/
|
|
26
|
+
modelPackage: ModelPackage;
|
|
27
|
+
/**
|
|
28
|
+
* Runtime implementation used to execute generation. Defaults to the Transformers.js-backed
|
|
29
|
+
* runtime; applications can inject their own implementation of the seam.
|
|
30
|
+
*/
|
|
31
|
+
runtime?: OnnxTextGenerationRuntime;
|
|
32
|
+
/**
|
|
33
|
+
* Optional generation timeout in milliseconds. A request-level `constraints.timeoutMs` wins.
|
|
34
|
+
*/
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Local provider adapter that executes Mode-1 text-to-text requests with a developer-supplied ONNX
|
|
39
|
+
* model in the browser.
|
|
40
|
+
*
|
|
41
|
+
* The adapter owns the IndeRun-facing contract (descriptor, capability checks, error taxonomy) and
|
|
42
|
+
* delegates execution to an injectable {@link OnnxTextGenerationRuntime}. ONNX Runtime execution
|
|
43
|
+
* backends (WASM, WebGPU, WebNN) stay behind that seam and are never public routing concepts.
|
|
44
|
+
*/
|
|
45
|
+
export declare class OnnxRuntimeWebProvider implements ProviderAdapter {
|
|
46
|
+
private readonly options;
|
|
47
|
+
private readonly id;
|
|
48
|
+
private readonly modelPackage;
|
|
49
|
+
private readonly runtime;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a Web ONNX Runtime provider.
|
|
52
|
+
* @param options - Model package plus optional id, runtime, and timeout overrides.
|
|
53
|
+
*/
|
|
54
|
+
constructor(options: OnnxProviderOptions);
|
|
55
|
+
/**
|
|
56
|
+
* Returns static metadata used by the router for deterministic provider selection.
|
|
57
|
+
*/
|
|
58
|
+
describe(): ProviderDescriptor;
|
|
59
|
+
/**
|
|
60
|
+
* Reports dynamic provider availability for the current host.
|
|
61
|
+
*
|
|
62
|
+
* Every failure below is provider-internal detail: the shared route planner flattens it into a
|
|
63
|
+
* single `capability_unavailable` rejection carrying the returned reason.
|
|
64
|
+
*
|
|
65
|
+
* @param _host - Host services available to the engine (unused; ONNX runs in-process).
|
|
66
|
+
*/
|
|
67
|
+
capabilities(_host: HostServices): Promise<ProviderDynamicCapabilities>;
|
|
68
|
+
/**
|
|
69
|
+
* Executes a normalized text-to-text task on the developer-supplied local ONNX model.
|
|
70
|
+
* @param request - Canonical IndeRun task request.
|
|
71
|
+
* @param context - Engine execution context containing run id and host services.
|
|
72
|
+
* @returns Normalized IndeRun task result.
|
|
73
|
+
* @throws IndeRunException mapped to the standard error taxonomy.
|
|
74
|
+
*/
|
|
75
|
+
run(request: TaskRequest, context: RunContext): Promise<TaskResult>;
|
|
76
|
+
private mapRuntimeError;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/providers/onnx/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,8BAA8B,CAAC;AAStC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAIL,KAAK,yBAAyB,EAC/B,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,2BAA2B,EAC3B,UAAU,EACX,MAAM,wBAAwB,CAAC;AAEhC,iFAAiF;AACjF,eAAO,MAAM,4BAA4B,yBAAyB,CAAC;AAKnE;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,EAAE,SAAS,eAAe,EAKtE,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,yBAAyB,CAAC;IACpC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IAShD,OAAO,CAAC,QAAQ,CAAC,OAAO;IARpC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IAEpD;;;OAGG;gBAC0B,OAAO,EAAE,mBAAmB;IAMzD;;OAEG;IACH,QAAQ,IAAI,kBAAkB;IAsB9B;;;;;;;OAOG;IACG,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAoC7E;;;;;;OAMG;IACG,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAoEzE,OAAO,CAAC,eAAe;CA2BxB"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { getModelPackageValidationIssues } from "@independo/inderun-contracts";
|
|
2
|
+
import { createCapabilityMismatch, createInternal, createTimeout, createUnavailable, toIndeRunException } from "../../core/errors.js";
|
|
3
|
+
import { OnnxRuntimeError } from "./runtime.js";
|
|
4
|
+
import { createTransformersJsRuntime } from "./transformers-runtime.js";
|
|
5
|
+
/** Default provider id of the Web member of the ONNX Runtime provider family. */
|
|
6
|
+
export const DEFAULT_ONNX_WEB_PROVIDER_ID = "local.onnx.genai.web";
|
|
7
|
+
/** Task kind this provider implements in Milestone 2 (Mode 1 only). */
|
|
8
|
+
const TEXT_TO_TEXT = "text_to_text";
|
|
9
|
+
/**
|
|
10
|
+
* Model source types the Web member of the ONNX Runtime provider family can honor.
|
|
11
|
+
*
|
|
12
|
+
* `filesystem` is unsupported because browsers do not expose arbitrary local paths, and `remote`
|
|
13
|
+
* is deferred: hosts download model files themselves and then supply them as `bundled`,
|
|
14
|
+
* `app_managed`, or `programmatic`.
|
|
15
|
+
*/
|
|
16
|
+
export const SUPPORTED_WEB_MODEL_SOURCE_TYPES = [
|
|
17
|
+
"registry",
|
|
18
|
+
"bundled",
|
|
19
|
+
"programmatic",
|
|
20
|
+
"app_managed"
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Local provider adapter that executes Mode-1 text-to-text requests with a developer-supplied ONNX
|
|
24
|
+
* model in the browser.
|
|
25
|
+
*
|
|
26
|
+
* The adapter owns the IndeRun-facing contract (descriptor, capability checks, error taxonomy) and
|
|
27
|
+
* delegates execution to an injectable {@link OnnxTextGenerationRuntime}. ONNX Runtime execution
|
|
28
|
+
* backends (WASM, WebGPU, WebNN) stay behind that seam and are never public routing concepts.
|
|
29
|
+
*/
|
|
30
|
+
export class OnnxRuntimeWebProvider {
|
|
31
|
+
options;
|
|
32
|
+
id;
|
|
33
|
+
modelPackage;
|
|
34
|
+
runtime;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a Web ONNX Runtime provider.
|
|
37
|
+
* @param options - Model package plus optional id, runtime, and timeout overrides.
|
|
38
|
+
*/
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.options = options;
|
|
41
|
+
this.id = options.id ?? DEFAULT_ONNX_WEB_PROVIDER_ID;
|
|
42
|
+
this.modelPackage = options.modelPackage;
|
|
43
|
+
this.runtime = options.runtime ?? createTransformersJsRuntime();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns static metadata used by the router for deterministic provider selection.
|
|
47
|
+
*/
|
|
48
|
+
describe() {
|
|
49
|
+
return {
|
|
50
|
+
id: this.id,
|
|
51
|
+
type: "local",
|
|
52
|
+
transport: "in_process",
|
|
53
|
+
supports: {
|
|
54
|
+
run: true,
|
|
55
|
+
streaming: false,
|
|
56
|
+
realtime: false,
|
|
57
|
+
tools: false,
|
|
58
|
+
reasoningEvents: false,
|
|
59
|
+
structuredOutput: false,
|
|
60
|
+
multimodal: false
|
|
61
|
+
},
|
|
62
|
+
cancel: "soft",
|
|
63
|
+
tasks: getDeclaredTasks(this.modelPackage),
|
|
64
|
+
privacy: {
|
|
65
|
+
dataLeavesDevice: false
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Reports dynamic provider availability for the current host.
|
|
71
|
+
*
|
|
72
|
+
* Every failure below is provider-internal detail: the shared route planner flattens it into a
|
|
73
|
+
* single `capability_unavailable` rejection carrying the returned reason.
|
|
74
|
+
*
|
|
75
|
+
* @param _host - Host services available to the engine (unused; ONNX runs in-process).
|
|
76
|
+
*/
|
|
77
|
+
async capabilities(_host) {
|
|
78
|
+
const issues = getModelPackageValidationIssues(this.modelPackage);
|
|
79
|
+
if (issues.length > 0) {
|
|
80
|
+
const summary = issues.map((issue) => `${issue.path} ${issue.message}`).join("; ");
|
|
81
|
+
return { available: false, reason: `model package malformed: ${summary}` };
|
|
82
|
+
}
|
|
83
|
+
const sourceType = this.modelPackage.source?.sourceType;
|
|
84
|
+
if (sourceType !== undefined && !SUPPORTED_WEB_MODEL_SOURCE_TYPES.includes(sourceType)) {
|
|
85
|
+
return {
|
|
86
|
+
available: false,
|
|
87
|
+
reason: sourceType === "filesystem"
|
|
88
|
+
? "model source unavailable: 'filesystem' model sources are unsupported on Web because browsers cannot read arbitrary local paths."
|
|
89
|
+
: `model source unavailable: '${sourceType}' model sources are deferred on Web; supply model files as ${SUPPORTED_WEB_MODEL_SOURCE_TYPES.join(", ")}.`
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const platforms = this.modelPackage.runtime?.platforms;
|
|
93
|
+
if (Array.isArray(platforms) && platforms.length > 0 && !platforms.includes("web")) {
|
|
94
|
+
return {
|
|
95
|
+
available: false,
|
|
96
|
+
reason: `platform unsupported: the model package targets ${platforms.join(", ")} and does not list 'web'.`
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (!getDeclaredTasks(this.modelPackage).includes(TEXT_TO_TEXT)) {
|
|
100
|
+
return {
|
|
101
|
+
available: false,
|
|
102
|
+
reason: `unsupported task: the model package declares ${getDeclaredTasks(this.modelPackage).join(", ")} and does not support '${TEXT_TO_TEXT}'.`
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return this.runtime.prepare(this.modelPackage);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Executes a normalized text-to-text task on the developer-supplied local ONNX model.
|
|
109
|
+
* @param request - Canonical IndeRun task request.
|
|
110
|
+
* @param context - Engine execution context containing run id and host services.
|
|
111
|
+
* @returns Normalized IndeRun task result.
|
|
112
|
+
* @throws IndeRunException mapped to the standard error taxonomy.
|
|
113
|
+
*/
|
|
114
|
+
async run(request, context) {
|
|
115
|
+
const availability = await this.capabilities(context.hostServices);
|
|
116
|
+
if (!availability.available) {
|
|
117
|
+
throw createCapabilityMismatch(availability.reason ?? "ONNX Runtime Web provider is unavailable on this host.", { providerId: this.id, runId: context.runId });
|
|
118
|
+
}
|
|
119
|
+
const messages = createMessages(request);
|
|
120
|
+
if (messages.length === 0) {
|
|
121
|
+
throw createInternal("ONNX Runtime Web provider requires a prompt or messages.", {
|
|
122
|
+
providerId: this.id,
|
|
123
|
+
runId: context.runId
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const timeoutMs = request.constraints?.timeoutMs ?? this.options.timeoutMs;
|
|
127
|
+
const controller = new AbortController();
|
|
128
|
+
const timer = timeoutMs !== undefined && timeoutMs > 0
|
|
129
|
+
? setTimeout(() => controller.abort(), timeoutMs)
|
|
130
|
+
: undefined;
|
|
131
|
+
let output;
|
|
132
|
+
try {
|
|
133
|
+
output = await this.runtime.generate({
|
|
134
|
+
modelPackage: this.modelPackage,
|
|
135
|
+
messages,
|
|
136
|
+
...(request.generation !== undefined ? { generation: request.generation } : {})
|
|
137
|
+
}, controller.signal);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
throw this.mapRuntimeError(err, context);
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
if (timer !== undefined)
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
}
|
|
146
|
+
if (typeof output.text !== "string" || output.text.length === 0) {
|
|
147
|
+
throw createInternal("ONNX Runtime Web provider returned no text output.", {
|
|
148
|
+
providerId: this.id,
|
|
149
|
+
runId: context.runId
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
const result = {
|
|
153
|
+
schemaVersion: "1.0",
|
|
154
|
+
runId: context.runId,
|
|
155
|
+
output: {
|
|
156
|
+
type: "text",
|
|
157
|
+
text: output.text
|
|
158
|
+
},
|
|
159
|
+
finishReason: output.finishReason ?? "stop",
|
|
160
|
+
telemetry: {
|
|
161
|
+
providerUsed: this.id,
|
|
162
|
+
totalMs: 0
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
if (output.usage) {
|
|
166
|
+
result.usage = output.usage;
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
mapRuntimeError(error, context) {
|
|
171
|
+
const extra = { providerId: this.id, runId: context.runId };
|
|
172
|
+
if (error instanceof OnnxRuntimeError) {
|
|
173
|
+
const details = error.originalError !== undefined
|
|
174
|
+
? { details: { originalError: getErrorSummary(error.originalError) } }
|
|
175
|
+
: {};
|
|
176
|
+
switch (error.kind) {
|
|
177
|
+
case "capability":
|
|
178
|
+
return createCapabilityMismatch(error.message, { ...extra, ...details });
|
|
179
|
+
case "unavailable":
|
|
180
|
+
return createUnavailable(error.message, { ...extra, ...details });
|
|
181
|
+
case "timeout":
|
|
182
|
+
return createTimeout(error.message, { ...extra, ...details });
|
|
183
|
+
default:
|
|
184
|
+
return createInternal(error.message, { ...extra, ...details });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (isAbortError(error)) {
|
|
188
|
+
return createTimeout("ONNX Runtime Web generation timed out.", extra);
|
|
189
|
+
}
|
|
190
|
+
return toIndeRunException(error, extra);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function getDeclaredTasks(modelPackage) {
|
|
194
|
+
const tasks = modelPackage.tasks;
|
|
195
|
+
return Array.isArray(tasks) && tasks.length > 0 ? tasks : [TEXT_TO_TEXT];
|
|
196
|
+
}
|
|
197
|
+
function createMessages(request) {
|
|
198
|
+
if (request.messages && request.messages.length > 0) {
|
|
199
|
+
return request.messages.map((message) => ({
|
|
200
|
+
role: message.role,
|
|
201
|
+
content: message.content
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
const prompt = request.prompt;
|
|
205
|
+
return prompt !== undefined && prompt.length > 0 ? [{ role: "user", content: prompt }] : [];
|
|
206
|
+
}
|
|
207
|
+
function isAbortError(error) {
|
|
208
|
+
return (typeof error === "object" &&
|
|
209
|
+
error !== null &&
|
|
210
|
+
error.name === "AbortError");
|
|
211
|
+
}
|
|
212
|
+
function getErrorSummary(error) {
|
|
213
|
+
if (error instanceof Error) {
|
|
214
|
+
return { name: error.name, message: error.message, stack: error.stack };
|
|
215
|
+
}
|
|
216
|
+
return { message: String(error) };
|
|
217
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { ModelPackage, TaskRequest, TaskResult } from "@independo/inderun-contracts";
|
|
2
|
+
/**
|
|
3
|
+
* Availability snapshot reported by an ONNX text generation runtime.
|
|
4
|
+
*
|
|
5
|
+
* The `reason` string uses the provider-internal capability vocabulary documented in
|
|
6
|
+
* `docs/architecture/onnx-runtime-provider-family.md`. It is not a public enum: the provider
|
|
7
|
+
* flattens every failure into a single `capability_unavailable` route rejection and carries the
|
|
8
|
+
* reason as human-readable text.
|
|
9
|
+
*/
|
|
10
|
+
export interface OnnxRuntimeAvailability {
|
|
11
|
+
/** Whether the runtime can execute the given model package on this host right now. */
|
|
12
|
+
available: boolean;
|
|
13
|
+
/** Human-readable detail describing why the runtime is unavailable. */
|
|
14
|
+
reason?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Normalized conversation turn handed to an ONNX text generation runtime.
|
|
18
|
+
*/
|
|
19
|
+
export interface OnnxGenerationMessage {
|
|
20
|
+
/** The role of the author of this turn. */
|
|
21
|
+
role: "system" | "user" | "assistant";
|
|
22
|
+
/** Plain-text content of this turn. */
|
|
23
|
+
content: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Normalized generation request handed to an ONNX text generation runtime.
|
|
27
|
+
*/
|
|
28
|
+
export interface OnnxGenerationInput {
|
|
29
|
+
/** The model package the provider was configured with. */
|
|
30
|
+
modelPackage: ModelPackage;
|
|
31
|
+
/** Conversation turns, normalized from `prompt` or `messages` by the provider. */
|
|
32
|
+
messages: OnnxGenerationMessage[];
|
|
33
|
+
/** Optional generation controls copied from the task request. */
|
|
34
|
+
generation?: NonNullable<TaskRequest["generation"]>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Normalized generation result returned by an ONNX text generation runtime.
|
|
38
|
+
*/
|
|
39
|
+
export interface OnnxGenerationOutput {
|
|
40
|
+
/** The generated text. */
|
|
41
|
+
text: string;
|
|
42
|
+
/** Optional normalized finish reason; the provider defaults to `stop`. */
|
|
43
|
+
finishReason?: TaskResult["finishReason"];
|
|
44
|
+
/** Optional token accounting, when the runtime reports it. */
|
|
45
|
+
usage?: TaskResult["usage"];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Failure category a runtime can signal so the provider maps it onto the IndeRun error taxonomy.
|
|
49
|
+
*
|
|
50
|
+
* - `capability`: model or runtime cannot serve this request (`CapabilityMismatch`).
|
|
51
|
+
* - `unavailable`: runtime initialization failure or resource exhaustion (`Unavailable`).
|
|
52
|
+
* - `timeout`: generation exceeded its budget or was aborted (`Timeout`).
|
|
53
|
+
* - `internal`: unexpected runtime failure (`Internal`).
|
|
54
|
+
*/
|
|
55
|
+
export type OnnxRuntimeErrorKind = "capability" | "unavailable" | "timeout" | "internal";
|
|
56
|
+
/**
|
|
57
|
+
* Error type ONNX runtime implementations throw to steer IndeRun error normalization.
|
|
58
|
+
*
|
|
59
|
+
* Anything else thrown by a runtime is normalized to `Internal`.
|
|
60
|
+
*/
|
|
61
|
+
export declare class OnnxRuntimeError extends Error {
|
|
62
|
+
/** Failure category used by the provider to select an IndeRun error class. */
|
|
63
|
+
readonly kind: OnnxRuntimeErrorKind;
|
|
64
|
+
/** Optional underlying error captured for telemetry details. */
|
|
65
|
+
readonly originalError?: unknown;
|
|
66
|
+
constructor(kind: OnnxRuntimeErrorKind, message: string, originalError?: unknown);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Injectable seam between the IndeRun ONNX Web provider and the actual on-device runtime.
|
|
70
|
+
*
|
|
71
|
+
* IndeRun ships a Transformers.js-backed implementation as the default and a deterministic
|
|
72
|
+
* fixture for tests, but applications can supply their own implementation (for example a
|
|
73
|
+
* hand-rolled `onnxruntime-web` pipeline) without touching the provider.
|
|
74
|
+
*/
|
|
75
|
+
export interface OnnxTextGenerationRuntime {
|
|
76
|
+
/**
|
|
77
|
+
* Checks runtime package availability, execution backend availability, and model readiness.
|
|
78
|
+
* Implementations must resolve with an availability snapshot rather than throwing.
|
|
79
|
+
*/
|
|
80
|
+
prepare(modelPackage: ModelPackage): Promise<OnnxRuntimeAvailability>;
|
|
81
|
+
/**
|
|
82
|
+
* Runs one Mode-1 generation. Implementations should honor `signal` where the underlying
|
|
83
|
+
* runtime allows it; ONNX inference is not hard-interruptible, so cancellation is best effort.
|
|
84
|
+
*/
|
|
85
|
+
generate(input: OnnxGenerationInput, signal?: AbortSignal): Promise<OnnxGenerationOutput>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Configuration for the deterministic fixture runtime.
|
|
89
|
+
*/
|
|
90
|
+
export interface FixtureOnnxRuntimeOptions {
|
|
91
|
+
/** Availability snapshot returned by `prepare`. Defaults to `{ available: true }`. */
|
|
92
|
+
availability?: OnnxRuntimeAvailability;
|
|
93
|
+
/** Text or full output produced by `generate`. Defaults to a deterministic echo. */
|
|
94
|
+
respond?: (input: OnnxGenerationInput) => string | OnnxGenerationOutput;
|
|
95
|
+
/** Error thrown by `generate` instead of producing output. */
|
|
96
|
+
failWith?: unknown;
|
|
97
|
+
/** Artificial generation delay in milliseconds, used to exercise timeouts. */
|
|
98
|
+
delayMs?: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a deterministic in-memory ONNX runtime.
|
|
102
|
+
*
|
|
103
|
+
* This is the test seam mandated by the ONNX Runtime provider family specification: it proves the
|
|
104
|
+
* model package contract, capability checks, routing, and error normalization without depending on
|
|
105
|
+
* a real ONNX runtime, and it lets demos exercise the on-device route offline.
|
|
106
|
+
*
|
|
107
|
+
* @param options - Scripted availability, response, failure, and delay behavior.
|
|
108
|
+
*/
|
|
109
|
+
export declare function createFixtureOnnxRuntime(options?: FixtureOnnxRuntimeOptions): OnnxTextGenerationRuntime;
|
|
110
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/providers/onnx/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1F;;;;;;;GAOG;AACH,MAAM,WAAW,uBAAuB;IACtC,sFAAsF;IACtF,SAAS,EAAE,OAAO,CAAC;IACnB,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,2CAA2C;IAC3C,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IACtC,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,YAAY,EAAE,YAAY,CAAC;IAC3B,kFAAkF;IAClF,QAAQ,EAAE,qBAAqB,EAAE,CAAC;IAClC,iEAAiE;IACjE,UAAU,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,YAAY,CAAC,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC;IAC1C,8DAA8D;IAC9D,KAAK,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,aAAa,GAAG,SAAS,GAAG,UAAU,CAAC;AAEzF;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,gEAAgE;IAChE,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;gBAErB,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO;CAQjF;AAED;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,OAAO,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtE;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,mBAAmB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAC3F;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,sFAAsF;IACtF,YAAY,CAAC,EAAE,uBAAuB,CAAC;IACvC,oFAAoF;IACpF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,MAAM,GAAG,oBAAoB,CAAC;IACxE,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,yBAA8B,GACtC,yBAAyB,CA4B3B"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error type ONNX runtime implementations throw to steer IndeRun error normalization.
|
|
3
|
+
*
|
|
4
|
+
* Anything else thrown by a runtime is normalized to `Internal`.
|
|
5
|
+
*/
|
|
6
|
+
export class OnnxRuntimeError extends Error {
|
|
7
|
+
/** Failure category used by the provider to select an IndeRun error class. */
|
|
8
|
+
kind;
|
|
9
|
+
/** Optional underlying error captured for telemetry details. */
|
|
10
|
+
originalError;
|
|
11
|
+
constructor(kind, message, originalError) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "OnnxRuntimeError";
|
|
14
|
+
this.kind = kind;
|
|
15
|
+
if (originalError !== undefined)
|
|
16
|
+
this.originalError = originalError;
|
|
17
|
+
Object.setPrototypeOf(this, OnnxRuntimeError.prototype);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a deterministic in-memory ONNX runtime.
|
|
22
|
+
*
|
|
23
|
+
* This is the test seam mandated by the ONNX Runtime provider family specification: it proves the
|
|
24
|
+
* model package contract, capability checks, routing, and error normalization without depending on
|
|
25
|
+
* a real ONNX runtime, and it lets demos exercise the on-device route offline.
|
|
26
|
+
*
|
|
27
|
+
* @param options - Scripted availability, response, failure, and delay behavior.
|
|
28
|
+
*/
|
|
29
|
+
export function createFixtureOnnxRuntime(options = {}) {
|
|
30
|
+
const availability = options.availability ?? { available: true };
|
|
31
|
+
return {
|
|
32
|
+
async prepare() {
|
|
33
|
+
return availability;
|
|
34
|
+
},
|
|
35
|
+
async generate(input, signal) {
|
|
36
|
+
if (options.delayMs !== undefined && options.delayMs > 0) {
|
|
37
|
+
await delay(options.delayMs, signal);
|
|
38
|
+
}
|
|
39
|
+
throwIfAborted(signal);
|
|
40
|
+
if (options.failWith !== undefined) {
|
|
41
|
+
throw options.failWith;
|
|
42
|
+
}
|
|
43
|
+
const response = options.respond
|
|
44
|
+
? options.respond(input)
|
|
45
|
+
: createFixtureText(input.modelPackage, input.messages);
|
|
46
|
+
return typeof response === "string" ? { text: response } : response;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function createFixtureText(modelPackage, messages) {
|
|
51
|
+
const lastUserMessage = [...messages].reverse().find((message) => message.role === "user");
|
|
52
|
+
const prompt = lastUserMessage?.content ?? "";
|
|
53
|
+
return `[fixture:${modelPackage.id}] ${prompt}`;
|
|
54
|
+
}
|
|
55
|
+
function delay(ms, signal) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const timer = setTimeout(() => {
|
|
58
|
+
signal?.removeEventListener("abort", onAbort);
|
|
59
|
+
resolve();
|
|
60
|
+
}, ms);
|
|
61
|
+
function onAbort() {
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
reject(new OnnxRuntimeError("timeout", "Fixture ONNX generation was aborted."));
|
|
64
|
+
}
|
|
65
|
+
if (signal?.aborted) {
|
|
66
|
+
onAbort();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function throwIfAborted(signal) {
|
|
73
|
+
if (signal?.aborted) {
|
|
74
|
+
throw new OnnxRuntimeError("timeout", "Fixture ONNX generation was aborted.");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ModelPackage } from "@independo/inderun-contracts";
|
|
2
|
+
import { type OnnxTextGenerationRuntime } from "./runtime.js";
|
|
3
|
+
/**
|
|
4
|
+
* Structural view of the `@huggingface/transformers` entry points this runtime uses.
|
|
5
|
+
*
|
|
6
|
+
* The dependency is optional, so the module is typed structurally instead of imported for types.
|
|
7
|
+
*/
|
|
8
|
+
export interface TransformersModule {
|
|
9
|
+
/** Builds a task pipeline, downloading or loading model assets as needed. */
|
|
10
|
+
pipeline: (task: string, model?: string, options?: Record<string, unknown>) => Promise<TransformersTextGenerator>;
|
|
11
|
+
/** Global Transformers.js environment used to point the loader at local model assets. */
|
|
12
|
+
env?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Structural view of a Transformers.js `text-generation` pipeline.
|
|
16
|
+
*/
|
|
17
|
+
export type TransformersTextGenerator = (input: unknown, options?: Record<string, unknown>) => Promise<unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for the Transformers.js-backed ONNX runtime.
|
|
20
|
+
*/
|
|
21
|
+
export interface TransformersJsRuntimeOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Overrides how the `@huggingface/transformers` module is loaded. Tests inject a fake module;
|
|
24
|
+
* production uses a lazy dynamic import so the dependency stays optional.
|
|
25
|
+
*/
|
|
26
|
+
load?: () => Promise<TransformersModule>;
|
|
27
|
+
/**
|
|
28
|
+
* Execution backend passed to Transformers.js. Defaults to `webgpu` when `navigator.gpu`
|
|
29
|
+
* exists and `wasm` otherwise. This is an ONNX Runtime execution backend, not an IndeRun
|
|
30
|
+
* routing concept.
|
|
31
|
+
*/
|
|
32
|
+
device?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Weight quantization passed to Transformers.js (for example `q4`, `q4f16`, `q8`, `fp16`,
|
|
35
|
+
* `fp32`).
|
|
36
|
+
*
|
|
37
|
+
* Defaults to a quantized variant (`q4f16` on WebGPU, `q4` otherwise) because Transformers.js
|
|
38
|
+
* would otherwise load full `fp32` weights, which exhausts browser memory for all but the
|
|
39
|
+
* smallest models. Set explicitly when the model does not publish the default variant.
|
|
40
|
+
*/
|
|
41
|
+
dtype?: string;
|
|
42
|
+
/** Base path or URL for locally served model assets (`bundled` / `app_managed` sources). */
|
|
43
|
+
localModelPath?: string;
|
|
44
|
+
/** Extra options merged into the Transformers.js `pipeline()` call. */
|
|
45
|
+
pipelineOptions?: Record<string, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* Supplies a pre-built generator instead of letting this runtime construct one. Required for
|
|
48
|
+
* `programmatic` model sources, where the application owns model resolution.
|
|
49
|
+
*/
|
|
50
|
+
createGenerator?: (context: {
|
|
51
|
+
modelPackage: ModelPackage;
|
|
52
|
+
module: TransformersModule;
|
|
53
|
+
device: string;
|
|
54
|
+
}) => Promise<TransformersTextGenerator>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates the default Web ONNX runtime, backed by Transformers.js (which runs ONNX models through
|
|
58
|
+
* `onnxruntime-web`).
|
|
59
|
+
*
|
|
60
|
+
* ONNX Runtime GenAI has no browser build, so Transformers.js fills the generative-loop role
|
|
61
|
+
* (tokenization, sampling, KV cache) behind the `OnnxTextGenerationRuntime` seam. Applications that
|
|
62
|
+
* need a different runtime implement the seam themselves and pass it to the provider.
|
|
63
|
+
*
|
|
64
|
+
* `@huggingface/transformers` is an optional dependency the application installs: when it is absent
|
|
65
|
+
* the runtime
|
|
66
|
+
* reports itself unavailable instead of throwing, so routing degrades to an explainable
|
|
67
|
+
* `capability_unavailable` rejection.
|
|
68
|
+
*
|
|
69
|
+
* @param options - Loader, backend, and model-resolution overrides.
|
|
70
|
+
*/
|
|
71
|
+
export declare function createTransformersJsRuntime(options?: TransformersJsRuntimeOptions): OnnxTextGenerationRuntime;
|
|
72
|
+
//# sourceMappingURL=transformers-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformers-runtime.d.ts","sourceRoot":"","sources":["../../../src/providers/onnx/transformers-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAKL,KAAK,yBAAyB,EAC/B,MAAM,cAAc,CAAC;AAEtB;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,6EAA6E;IAC7E,QAAQ,EAAE,CACR,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACxC,yFAAyF;IACzF,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,CACtC,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACzC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4FAA4F;IAC5F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uEAAuE;IACvE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAC1B,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,EAAE,kBAAkB,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC;KAChB,KAAK,OAAO,CAAC,yBAAyB,CAAC,CAAC;CAC1C;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,GAAE,4BAAiC,GACzC,yBAAyB,CAyI3B"}
|