@independo/inderun-web 0.3.0-dev.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -10
- package/dist/core/engine.d.ts +11 -0
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +38 -42
- package/dist/core/route-planner.d.ts +16 -13
- package/dist/core/route-planner.d.ts.map +1 -1
- package/dist/core/route-planner.js +22 -19
- package/dist/core/router.d.ts +1 -39
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/router.js +12 -206
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -2
- package/dist/onnx.d.ts +21 -0
- package/dist/onnx.d.ts.map +1 -1
- package/dist/onnx.js +15 -0
- package/dist/openai.d.ts +7 -0
- package/dist/openai.d.ts.map +1 -1
- package/dist/openai.js +7 -0
- package/dist/system-model.d.ts +13 -0
- package/dist/system-model.d.ts.map +1 -1
- package/dist/system-model.js +13 -0
- package/package.json +22 -8
- package/src/core/browser-host.ts +339 -0
- package/src/core/engine.ts +540 -0
- package/src/core/errors.ts +220 -0
- package/src/core/event-gate.ts +71 -0
- package/src/core/generated/inderun-api.ts +19 -0
- package/src/core/host.ts +15 -0
- package/src/core/provider.ts +231 -0
- package/src/core/registry.ts +48 -0
- package/src/core/route-planner.ts +261 -0
- package/src/core/router.ts +149 -0
- package/src/core/sse.ts +134 -0
- package/src/core/telemetry.ts +20 -0
- package/src/index.ts +147 -0
- package/src/onnx.ts +57 -0
- package/src/openai.ts +21 -0
- package/src/providers/onnx/provider.ts +300 -0
- package/src/providers/onnx/runtime.ts +188 -0
- package/src/providers/onnx/transformers-runtime.ts +345 -0
- package/src/providers/openai/provider.ts +765 -0
- package/src/providers/system-model/chrome-runtime.ts +221 -0
- package/src/providers/system-model/provider.ts +260 -0
- package/src/providers/system-model/runtime.ts +202 -0
- package/src/system-model.ts +49 -0
- package/src/web-sdk.ts +114 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-specific entry point for the Web member of the system-model 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/system-model`
|
|
6
|
+
* when registering the adapter manually or when implementing a custom
|
|
7
|
+
* `SystemModelRuntime`; most browser apps should pass `systemModel` to
|
|
8
|
+
* `createIndeRunWeb` from the main entry point instead.
|
|
9
|
+
*
|
|
10
|
+
* "System model" means a model the browser itself manages, so availability is a
|
|
11
|
+
* richer answer than a boolean: it may be present, downloadable, mid-download, or
|
|
12
|
+
* blocked for a browser, device, or policy reason. The provider flattens every
|
|
13
|
+
* non-available state into one route rejection and carries the detail as text.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** The adapter itself, plus the default id the router plans against. */
|
|
17
|
+
export {
|
|
18
|
+
DEFAULT_SYSTEM_MODEL_WEB_PROVIDER_ID,
|
|
19
|
+
SystemModelWebProvider,
|
|
20
|
+
type SystemModelProviderOptions
|
|
21
|
+
} from "./providers/system-model/provider.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The runtime seam. The provider delegates generation to a `SystemModelRuntime`,
|
|
25
|
+
* so an app can target a different browser API, or use
|
|
26
|
+
* `createFixtureSystemModelRuntime()` in demos and tests where no system model
|
|
27
|
+
* exists.
|
|
28
|
+
*/
|
|
29
|
+
export {
|
|
30
|
+
SystemModelRuntimeError,
|
|
31
|
+
createFixtureSystemModelRuntime,
|
|
32
|
+
type FixtureSystemModelRuntimeOptions,
|
|
33
|
+
type SystemModelAvailability,
|
|
34
|
+
type SystemModelAvailabilityKind,
|
|
35
|
+
type SystemModelGenerationInput,
|
|
36
|
+
type SystemModelGenerationOutput,
|
|
37
|
+
type SystemModelPromptMessage,
|
|
38
|
+
type SystemModelRuntime,
|
|
39
|
+
type SystemModelRuntimeErrorKind
|
|
40
|
+
} from "./providers/system-model/runtime.js";
|
|
41
|
+
|
|
42
|
+
/** The default runtime, backed by Chrome's built-in Prompt API. */
|
|
43
|
+
export {
|
|
44
|
+
createChromePromptApiRuntime,
|
|
45
|
+
type ChromePromptApiGenerationOptions,
|
|
46
|
+
type ChromePromptApiRuntimeOptions,
|
|
47
|
+
type PromptApiLanguageModel,
|
|
48
|
+
type PromptApiSession
|
|
49
|
+
} from "./providers/system-model/chrome-runtime.js";
|
package/src/web-sdk.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBrowserHostServices,
|
|
3
|
+
type CreateBrowserHostServicesOptions
|
|
4
|
+
} from "./core/browser-host.js";
|
|
5
|
+
import { IndeRun } from "./core/engine.js";
|
|
6
|
+
import { OnnxRuntimeWebProvider, type OnnxProviderOptions } from "./providers/onnx/provider.js";
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_OPENAI_RESPONSES_ENDPOINT,
|
|
9
|
+
OpenAIResponsesProvider,
|
|
10
|
+
type OpenAIProviderOptions
|
|
11
|
+
} from "./providers/openai/provider.js";
|
|
12
|
+
import { ProviderRegistry } from "./core/registry.js";
|
|
13
|
+
import {
|
|
14
|
+
SystemModelWebProvider,
|
|
15
|
+
type SystemModelProviderOptions
|
|
16
|
+
} from "./providers/system-model/provider.js";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for the default Web SDK factory.
|
|
20
|
+
*/
|
|
21
|
+
export interface CreateIndeRunWebOptions {
|
|
22
|
+
/**
|
|
23
|
+
* OpenAI Responses provider configuration registered by the factory.
|
|
24
|
+
*/
|
|
25
|
+
openAI?: OpenAIProviderOptions;
|
|
26
|
+
/**
|
|
27
|
+
* Web ONNX Runtime provider configuration registered by the factory, for developer-supplied
|
|
28
|
+
* local models. Registering it is what makes `constraints.privacy = "local_required"` routable.
|
|
29
|
+
*/
|
|
30
|
+
onnx?: OnnxProviderOptions;
|
|
31
|
+
/**
|
|
32
|
+
* Web system-model provider configuration registered by the factory, for browser-managed
|
|
33
|
+
* on-device models (for example Chrome's Prompt API). Unlike `onnx`, this provider takes no
|
|
34
|
+
* developer-supplied model: the browser owns model availability, download, and execution.
|
|
35
|
+
*/
|
|
36
|
+
systemModel?: SystemModelProviderOptions;
|
|
37
|
+
/**
|
|
38
|
+
* Optional browser host service overrides.
|
|
39
|
+
*/
|
|
40
|
+
hostServices?: CreateBrowserHostServicesOptions;
|
|
41
|
+
/**
|
|
42
|
+
* Explicit opt-in for calling the public OpenAI endpoint directly from this Web SDK factory.
|
|
43
|
+
*
|
|
44
|
+
* Browser apps should leave this unset and use a proxy endpoint with `openAI.auth = "none"` instead.
|
|
45
|
+
* Direct calls can expose credentials to client-side code and are appropriate only for controlled
|
|
46
|
+
* non-production environments.
|
|
47
|
+
*/
|
|
48
|
+
allowDirectOpenAIEndpoint?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates a Web SDK instance with the configured providers registered.
|
|
53
|
+
*
|
|
54
|
+
* Pass `openAI` for cloud execution, `onnx` for developer-supplied local models, `systemModel` for
|
|
55
|
+
* browser-managed on-device models, or any combination to let routing choose between them; at
|
|
56
|
+
* least one is required.
|
|
57
|
+
*
|
|
58
|
+
* Use `openAI.auth = "none"` with a proxy endpoint for production browser apps so the OpenAI API key never ships
|
|
59
|
+
* to the client. Direct OpenAI calls require `allowDirectOpenAIEndpoint` and should resolve credentials through
|
|
60
|
+
* `authContextRef` and `SecureStorageService`.
|
|
61
|
+
*
|
|
62
|
+
* @param options - Provider configuration and optional host service overrides.
|
|
63
|
+
*/
|
|
64
|
+
export function createIndeRunWeb(options: CreateIndeRunWebOptions): IndeRun {
|
|
65
|
+
if (!options.openAI && !options.onnx && !options.systemModel) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
"createIndeRunWeb requires at least one provider configuration (openAI, onnx, and/or systemModel)."
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const registry = new ProviderRegistry();
|
|
72
|
+
|
|
73
|
+
if (options.openAI) {
|
|
74
|
+
assertSafeOpenAIEndpoint(options.openAI, options.allowDirectOpenAIEndpoint);
|
|
75
|
+
registry.register(new OpenAIResponsesProvider(options.openAI));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (options.onnx) {
|
|
79
|
+
registry.register(new OnnxRuntimeWebProvider(options.onnx));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (options.systemModel) {
|
|
83
|
+
registry.register(new SystemModelWebProvider(options.systemModel));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return new IndeRun(registry, createBrowserHostServices(options.hostServices));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function assertSafeOpenAIEndpoint(
|
|
90
|
+
openAI: OpenAIProviderOptions,
|
|
91
|
+
allowDirectOpenAIEndpoint?: boolean
|
|
92
|
+
): void {
|
|
93
|
+
const endpointUrl = openAI.endpointUrl ?? DEFAULT_OPENAI_RESPONSES_ENDPOINT;
|
|
94
|
+
const auth = openAI.auth ?? "authContextRef";
|
|
95
|
+
const isDirectOpenAIEndpoint = isOpenAIResponsesEndpoint(endpointUrl);
|
|
96
|
+
|
|
97
|
+
if (isDirectOpenAIEndpoint && auth !== "none" && !allowDirectOpenAIEndpoint) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
'createIndeRunWeb is proxy-first for browser safety. Configure openAI.endpointUrl to a server-side proxy with auth: "none", or set allowDirectOpenAIEndpoint: true for controlled direct OpenAI calls.'
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function isOpenAIResponsesEndpoint(endpointUrl: string): boolean {
|
|
105
|
+
let parsed: URL;
|
|
106
|
+
try {
|
|
107
|
+
parsed = new URL(endpointUrl);
|
|
108
|
+
} catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const pathname = parsed.pathname.replace(/\/+$/u, "");
|
|
113
|
+
return parsed.hostname.toLowerCase() === "api.openai.com" && pathname === "/v1/responses";
|
|
114
|
+
}
|