@independo/inderun-web 0.4.0-rc.1 → 0.4.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 CHANGED
@@ -10,7 +10,18 @@ TypeScript/Web SDK for IndeRun.
10
10
 
11
11
  This package provides the Web SDK entrypoint, the engine core, routing, telemetry, error normalization, the OpenAI-compatible cloud provider, the Web ONNX Runtime provider for developer-supplied local models, and the Web system-model provider for browser-managed on-device models.
12
12
 
13
- The contract types this SDK's own signatures take and return — `TaskRequest`, `TaskResult`, `StreamEvent`, `StreamRunHandle`, `StreamTerminalOutcome`, `IndeRunError`, the host-service and telemetry interfaces, and (from the `/onnx` subpath) `ModelPackage` — are re-exported here, so a fully typed app does not need to depend on `@independo/inderun-contracts` separately. Import that package directly only if you want the JSON Schemas or the `get*ValidationIssues` validators.
13
+ The contract types this SDK's own signatures take and return — `TaskRequest`, `TaskResult`, `StreamEvent`, `StreamRunHandle`, `StreamTerminalOutcome`, `IndeRunError`, `ExecutionProvenance`, the telemetry interfaces, the host-service interfaces (from `/provider`), and (from the `/onnx` subpath) `ModelPackage` — are re-exported here, so a fully typed app does not need to depend on `@independo/inderun-contracts` separately. Import that package directly only if you want the JSON Schemas or the `get*ValidationIssues` validators.
14
+
15
+ ## Entry points
16
+
17
+ | Import | For | Contains |
18
+ | --- | --- | --- |
19
+ | `@independo/inderun-web` | Applications | `generateText` / `streamText`, `createIndeRunWeb`, the advanced task API (`IndeRun`, `run()` / `stream()` / `checkCapabilities()`), model profiles, contract types, `IndeRunException`, telemetry |
20
+ | `@independo/inderun-web/provider` | Provider authors and host integrators | `ProviderAdapter` and the descriptor/capability types, `ProviderRegistry`, `HostServices` and the browser host services, the `create*` error constructors |
21
+ | `@independo/inderun-web/openai`, `/onnx`, `/system-model` | Registering a provider by hand | One provider adapter each |
22
+
23
+ The router, the route planner bindings and the Event Gate are engine internals and are not exported. Moving from 0.3?
24
+ See the [migration guide](https://github.com/independo-gmbh/inderun/blob/main/docs/migration.md).
14
25
 
15
26
  ## Basic Usage
16
27
 
@@ -41,6 +52,13 @@ default `"auto"`), the usual sampling options, and an `execution` policy that re
41
52
  constraint values. Each call compiles to one `TaskRequest` — `toTaskRequest(options)` shows which —
42
53
  and runs through the engine below, so errors, fallback, and cancellation match the advanced API.
43
54
 
55
+ ## Advanced: the task API
56
+
57
+ Use `TaskRequest` with `run()` / `stream()` when you need the raw event sequence, build requests in code (for example
58
+ with your own `requestId`), or check capabilities before offering an option —
59
+ `await inderun.checkCapabilities()` reports every registered target's live availability. Both layers run through the
60
+ same engine.
61
+
44
62
  ## Streaming
45
63
 
46
64
  For the full event sequence, use the advanced API. `stream()` returns the run handle, its canonical `StreamEvent` sequence, and a `cancel()` hook:
@@ -75,6 +93,9 @@ accept `"stream": true` and emit `text/event-stream` with the Responses event ty
75
93
  response object. Unknown event types are ignored, so an endpoint that emits extra events is
76
94
  fine; one that emits a different vocabulary entirely is not.
77
95
 
96
+ [OpenRouter](https://github.com/independo-gmbh/inderun/blob/main/docs/openrouter.md) is reached this way: point
97
+ `endpointUrl` at its Responses endpoint (through a proxy in browser apps) and list `vendor/model` ids as `models`.
98
+
78
99
  ## Security Model
79
100
 
80
101
  Browser apps should use a proxy endpoint and keep provider credentials server-side. `createIndeRunWeb` rejects direct calls to the public OpenAI Responses endpoint unless `allowDirectOpenAIEndpoint: true` is set for a controlled environment.
@@ -87,10 +108,17 @@ distributed client code — put it behind a trusted backend proxy and point `end
87
108
  ## Advanced: registering the OpenAI provider directly
88
109
 
89
110
  `createIndeRunWeb` wires the OpenAI Responses provider for you. To register it
90
- manually (e.g. alongside other providers), import it from the provider subpath:
111
+ manually (e.g. alongside other providers), import it from the provider subpath and build the engine from
112
+ the `/provider` entry point:
91
113
 
92
114
  ```ts
115
+ import { IndeRun } from "@independo/inderun-web";
93
116
  import { OpenAIResponsesProvider } from "@independo/inderun-web/openai";
117
+ import { ProviderRegistry, createBrowserHostServices } from "@independo/inderun-web/provider";
118
+
119
+ const registry = new ProviderRegistry();
120
+ registry.register(new OpenAIResponsesProvider({ model: "gpt-5.2", endpointUrl: "/api/inderun/openai-responses", auth: "none" }));
121
+ const inderun = new IndeRun(registry, createBrowserHostServices());
94
122
  ```
95
123
 
96
124
  The provider normalizes OpenAI transport and API failures into the IndeRun error
package/dist/index.d.ts CHANGED
@@ -1,52 +1,42 @@
1
1
  /**
2
- * Unified entry point for the IndeRun Web SDK (`@independo/inderun-web`).
2
+ * Application entry point for the IndeRun Web SDK (`@independo/inderun-web`).
3
3
  *
4
- * Everything a browser app needs to run and stream tasks is exported from here:
5
- * the engine, the routing and provider seams, host services, error and telemetry
6
- * types, and the contract types the SDK's own signatures use. Provider adapters
7
- * are the deliberate exception — each ships from its own subpath
8
- * (`/openai`, `/onnx`, `/system-model`) so this surface stays provider-agnostic.
9
- */
10
- /**
11
- * Host services: the platform capabilities the engine reads and calls through,
12
- * and the seams an embedder overrides to supply its own (custom transport,
13
- * credential storage, clock).
14
- */
15
- export { type AbortSignalLike, type ConnectivityService, type DeviceConstraintsService, type SecureStorageService, type ClockService, type HttpClientService, type HttpRequest, type HttpResponse, type HttpStreamResponse, type HttpStreamingClientService, type HostServices, type ThermalState } from "./core/host.js";
16
- /**
17
- * The provider contract. Implement `ProviderAdapter` for a Mode 1 backend and add
18
- * a `stream` for Mode 2; the descriptor and dynamic capability check are what the
19
- * router plans against.
20
- */
21
- export { type ProviderDescriptor, type ProviderDynamicCapabilities, type ProviderCapabilitySnapshot, type RunContext, type ProviderAdapter, type ProviderStreamContext, type ProviderStreamEvent, type StreamRun } from "./core/provider.js";
22
- /**
23
- * Per-run gatekeeper for a Mode 2 stream: assigns the sequence numbers callers
24
- * order by, and enforces that exactly one terminal outcome is produced with
25
- * nothing admitted after it. Exported for embedders driving a stream themselves.
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.
26
17
  */
27
- export { EventGate } from "./core/event-gate.js";
28
- /** Holds the provider adapters a given engine instance can route to. */
29
- export { ProviderRegistry } from "./core/registry.js";
30
18
  /**
31
- * Route selection. `Router` turns a request plus a host capability snapshot into
32
- * a provider chain; `WasmRoutePlanner` is the shared Rust planner behind it, and
33
- * the only planner the Web SDK has — there is no JavaScript fallback.
19
+ * The primary text API: one canonical request per call, over any `IndeRunApi`.
34
20
  */
35
- export { type RouteSelection, Router } from "./core/router.js";
36
- export { type RoutePlanner, type PlannerOutcome, type WasmUnavailableReason, type SharedPlannerInput, type SharedPlannerRoutePlan, WasmRoutePlanner } from "./core/route-planner.js";
21
+ export { generateText, streamText, toTaskRequest, TextStreamRetractedError, type GeneratedText, type StreamedText, type TextExecutionOptions, type TextGenerationOptions, type TextStream } from "./facade/text.js";
37
22
  /**
38
- * The normalized error taxonomy. Every failure the SDK surfaces is an
39
- * `IndeRunException` in one of these classes, whatever the provider raised.
23
+ * The recommended way in: builds host services, registers the providers named in
24
+ * the options, and returns a ready engine.
40
25
  */
41
- export { type IndeRunExceptionParams, IndeRunException, createCapabilityMismatch, createOffline, createAuthError, createRateLimited, createTimeout, createUnavailable, createInternal, toIndeRunException } from "./core/errors.js";
42
- /** The engine itself, and the app-facing API surface it implements. */
43
- export { IndeRun, type IndeRunOptions, type StreamHandleResult } from "./core/engine.js";
26
+ export { createIndeRunWeb, type CreateIndeRunWebOptions, type OpenAIFactoryOptions } from "./web-sdk.js";
44
27
  /**
45
28
  * Model profiles: application-defined names for ordered sets of targets that a
46
29
  * request can route within. `"auto"` is built in.
47
30
  */
48
31
  export { AUTO_MODEL_PROFILE, type ModelProfiles } from "./core/model-profiles.js";
32
+ /**
33
+ * The advanced task API. `IndeRun` implements `IndeRunApi`; constructing one by
34
+ * hand takes a `ProviderRegistry` and `HostServices` from
35
+ * `@independo/inderun-web/provider`.
36
+ */
37
+ export { IndeRun, type IndeRunOptions, type StreamHandleResult } from "./core/engine.js";
49
38
  export type { IndeRunApi } from "./core/generated/inderun-api.js";
39
+ export type { ProviderCapabilitySnapshot, StreamRun } from "./core/provider.js";
50
40
  /**
51
41
  * The contract types this SDK's own signatures take and return.
52
42
  *
@@ -56,31 +46,22 @@ export type { IndeRunApi } from "./core/generated/inderun-api.js";
56
46
  * This is the npm counterpart of Gradle `api(...)` on Android and `@_exported
57
47
  * import` on Swift — see
58
48
  * {@link https://github.com/independo-gmbh/inderun/issues/189 | #189}. The
59
- * host-service and telemetry blocks in this file re-export their halves of the
60
- * same contract surface for the same reason.
49
+ * telemetry block below and the host-service block of the `/provider` entry
50
+ * point re-export their halves of the same contract surface for the same reason.
61
51
  *
62
52
  * Depend on `@independo/inderun-contracts` directly only for what is not
63
53
  * re-exported here: the JSON Schemas and the `get*ValidationIssues` validators.
64
54
  */
65
- export type { IndeRunError, IndeRunErrorClass, StreamEvent, StreamRunHandle, StreamTerminalOutcome, TaskRequest, TaskResult } from "@independo/inderun-contracts";
55
+ export type { ExecutionProvenance, IndeRunError, IndeRunErrorClass, StreamEvent, StreamRunHandle, StreamTerminalOutcome, TaskRequest, TaskResult } from "@independo/inderun-contracts";
56
+ /**
57
+ * The normalized error taxonomy. Every failure the SDK surfaces is an
58
+ * `IndeRunException` in one of these classes, whatever the provider raised.
59
+ * Provider authors create them with the `create*` helpers from `/provider`.
60
+ */
61
+ export { IndeRunException, toIndeRunException } from "./core/errors.js";
66
62
  /**
67
63
  * Telemetry. Pass a `TelemetryService` to observe routing decisions and attempt
68
64
  * outcomes; the engine defaults to `NoOpTelemetryService`.
69
65
  */
70
66
  export { type TelemetryEventType, type TelemetryEvent, type TelemetryService, NoOpTelemetryService } from "./core/telemetry.js";
71
- /**
72
- * The browser implementations of the host services above, and the factory that
73
- * assembles them. Use these directly only when constructing `IndeRun` by hand.
74
- */
75
- export { BrowserConnectivityService, FetchHttpClient, FetchStreamingHttpClient, SystemClockService, createBrowserHostServices, type CreateBrowserHostServicesOptions, type FetchHttpClientOptions } from "./core/browser-host.js";
76
- /**
77
- * The primary text API: one canonical request per call, over any `IndeRunApi`.
78
- * See `docs/architecture/api-layering.md`.
79
- */
80
- export { generateText, streamText, toTaskRequest, TextStreamRetractedError, type GeneratedText, type StreamedText, type TextExecutionOptions, type TextGenerationOptions, type TextStream } from "./facade/text.js";
81
- /**
82
- * The recommended way in: builds host services, registers the providers named in
83
- * the options, and returns a ready engine.
84
- */
85
- export { createIndeRunWeb, type CreateIndeRunWebOptions, type OpenAIFactoryOptions } from "./web-sdk.js";
86
67
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;GAIG;AACH,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;AAE5B;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAA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ACH,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,68 +1,48 @@
1
1
  /**
2
- * Unified entry point for the IndeRun Web SDK (`@independo/inderun-web`).
2
+ * Application entry point for the IndeRun Web SDK (`@independo/inderun-web`).
3
3
  *
4
- * Everything a browser app needs to run and stream tasks is exported from here:
5
- * the engine, the routing and provider seams, host services, error and telemetry
6
- * types, and the contract types the SDK's own signatures use. Provider adapters
7
- * are the deliberate exception — each ships from its own subpath
8
- * (`/openai`, `/onnx`, `/system-model`) so this surface stays provider-agnostic.
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
- * Host services: the platform capabilities the engine reads and calls through,
12
- * and the seams an embedder overrides to supply its own (custom transport,
13
- * credential storage, clock).
19
+ * The primary text API: one canonical request per call, over any `IndeRunApi`.
14
20
  */
15
- export {} from "./core/host.js";
21
+ export { generateText, streamText, toTaskRequest, TextStreamRetractedError } from "./facade/text.js";
16
22
  /**
17
- * The provider contract. Implement `ProviderAdapter` for a Mode 1 backend and add
18
- * a `stream` for Mode 2; the descriptor and dynamic capability check are what the
19
- * router plans against.
23
+ * The recommended way in: builds host services, registers the providers named in
24
+ * the options, and returns a ready engine.
20
25
  */
21
- export {} from "./core/provider.js";
26
+ export { createIndeRunWeb } from "./web-sdk.js";
22
27
  /**
23
- * Per-run gatekeeper for a Mode 2 stream: assigns the sequence numbers callers
24
- * order by, and enforces that exactly one terminal outcome is produced with
25
- * nothing admitted after it. Exported for embedders driving a stream themselves.
28
+ * Model profiles: application-defined names for ordered sets of targets that a
29
+ * request can route within. `"auto"` is built in.
26
30
  */
27
- export { EventGate } from "./core/event-gate.js";
28
- /** Holds the provider adapters a given engine instance can route to. */
29
- export { ProviderRegistry } from "./core/registry.js";
31
+ export { AUTO_MODEL_PROFILE } from "./core/model-profiles.js";
30
32
  /**
31
- * Route selection. `Router` turns a request plus a host capability snapshot into
32
- * a provider chain; `WasmRoutePlanner` is the shared Rust planner behind it, and
33
- * the only planner the Web SDK has — there is no JavaScript fallback.
33
+ * The advanced task API. `IndeRun` implements `IndeRunApi`; constructing one by
34
+ * hand takes a `ProviderRegistry` and `HostServices` from
35
+ * `@independo/inderun-web/provider`.
34
36
  */
35
- export { Router } from "./core/router.js";
36
- export { WasmRoutePlanner } from "./core/route-planner.js";
37
+ export { IndeRun } from "./core/engine.js";
37
38
  /**
38
39
  * The normalized error taxonomy. Every failure the SDK surfaces is an
39
40
  * `IndeRunException` in one of these classes, whatever the provider raised.
41
+ * Provider authors create them with the `create*` helpers from `/provider`.
40
42
  */
41
- export { IndeRunException, createCapabilityMismatch, createOffline, createAuthError, createRateLimited, createTimeout, createUnavailable, createInternal, toIndeRunException } from "./core/errors.js";
42
- /** The engine itself, and the app-facing API surface it implements. */
43
- export { IndeRun } from "./core/engine.js";
44
- /**
45
- * Model profiles: application-defined names for ordered sets of targets that a
46
- * request can route within. `"auto"` is built in.
47
- */
48
- export { AUTO_MODEL_PROFILE } from "./core/model-profiles.js";
43
+ export { IndeRunException, toIndeRunException } from "./core/errors.js";
49
44
  /**
50
45
  * Telemetry. Pass a `TelemetryService` to observe routing decisions and attempt
51
46
  * outcomes; the engine defaults to `NoOpTelemetryService`.
52
47
  */
53
48
  export { NoOpTelemetryService } from "./core/telemetry.js";
54
- /**
55
- * The browser implementations of the host services above, and the factory that
56
- * assembles them. Use these directly only when constructing `IndeRun` by hand.
57
- */
58
- export { BrowserConnectivityService, FetchHttpClient, FetchStreamingHttpClient, SystemClockService, createBrowserHostServices } from "./core/browser-host.js";
59
- /**
60
- * The primary text API: one canonical request per call, over any `IndeRunApi`.
61
- * See `docs/architecture/api-layering.md`.
62
- */
63
- export { generateText, streamText, toTaskRequest, TextStreamRetractedError } from "./facade/text.js";
64
- /**
65
- * The recommended way in: builds host services, registers the providers named in
66
- * the options, and returns a ready engine.
67
- */
68
- export { createIndeRunWeb } from "./web-sdk.js";
@@ -0,0 +1,34 @@
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
+ * Host services: the platform capabilities the engine reads and calls through,
13
+ * and the seams an embedder overrides to supply its own.
14
+ */
15
+ export { type AbortSignalLike, type ConnectivityService, type DeviceConstraintsService, type SecureStorageService, type ClockService, type HttpClientService, type HttpRequest, type HttpResponse, type HttpStreamResponse, type HttpStreamingClientService, type HostServices, type ThermalState } from "./core/host.js";
16
+ /**
17
+ * The browser implementations of the host services above, and the factory that
18
+ * assembles them. Use these directly only when constructing `IndeRun` by hand.
19
+ */
20
+ export { BrowserConnectivityService, FetchHttpClient, FetchStreamingHttpClient, SystemClockService, createBrowserHostServices, type CreateBrowserHostServicesOptions, type FetchHttpClientOptions } from "./core/browser-host.js";
21
+ /**
22
+ * The provider contract. Implement `ProviderAdapter` for a Mode 1 backend and add
23
+ * a `stream` for Mode 2; the descriptor and dynamic capability check are what the
24
+ * router plans against.
25
+ */
26
+ export { type ProviderDescriptor, type ProviderDynamicCapabilities, type ProviderCapabilitySnapshot, type RunContext, type ProviderAdapter, type ProviderStreamContext, type ProviderStreamEvent, type StreamRun } from "./core/provider.js";
27
+ /** Holds the provider adapters a given engine instance can route to. */
28
+ export { ProviderRegistry } from "./core/registry.js";
29
+ /**
30
+ * Constructors for the normalized error taxonomy. A provider maps every failure
31
+ * onto one of these classes; the engine does the rest.
32
+ */
33
+ export { type IndeRunExceptionParams, createCapabilityMismatch, createOffline, createAuthError, createRateLimited, createTimeout, createUnavailable, createInternal } from "./core/errors.js";
34
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;GAGG;AACH,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AAExB;;;GAGG;AACH,OAAO,EACL,0BAA0B,EAC1B,eAAe,EACf,wBAAwB,EACxB,kBAAkB,EAClB,yBAAyB,EACzB,KAAK,gCAAgC,EACrC,KAAK,sBAAsB,EAC5B,MAAM,wBAAwB,CAAC;AAEhC;;;;GAIG;AACH,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;AAE5B,wEAAwE;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;GAGG;AACH,OAAO,EACL,KAAK,sBAAsB,EAC3B,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,cAAc,EACf,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,33 @@
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
+ * Host services: the platform capabilities the engine reads and calls through,
13
+ * and the seams an embedder overrides to supply its own.
14
+ */
15
+ export {} from "./core/host.js";
16
+ /**
17
+ * The browser implementations of the host services above, and the factory that
18
+ * assembles them. Use these directly only when constructing `IndeRun` by hand.
19
+ */
20
+ export { BrowserConnectivityService, FetchHttpClient, FetchStreamingHttpClient, SystemClockService, createBrowserHostServices } from "./core/browser-host.js";
21
+ /**
22
+ * The provider contract. Implement `ProviderAdapter` for a Mode 1 backend and add
23
+ * a `stream` for Mode 2; the descriptor and dynamic capability check are what the
24
+ * router plans against.
25
+ */
26
+ export {} from "./core/provider.js";
27
+ /** Holds the provider adapters a given engine instance can route to. */
28
+ export { ProviderRegistry } from "./core/registry.js";
29
+ /**
30
+ * Constructors for the normalized error taxonomy. A provider maps every failure
31
+ * onto one of these classes; the engine does the rest.
32
+ */
33
+ export { createCapabilityMismatch, createOffline, createAuthError, createRateLimited, createTimeout, createUnavailable, createInternal } from "./core/errors.js";
@@ -101,7 +101,9 @@ export declare class OpenAIResponsesProvider implements ProviderAdapter {
101
101
  * - `response.completed` and `response.incomplete` become the terminal done,
102
102
  * with `finalText`, `usage`, and `finishReason` read off the embedded
103
103
  * response object by the same helpers Mode 1 uses — it has the same shape;
104
- * - `response.failed` and `error` become a terminal error;
104
+ * - `response.failed`, `response.error` and `error` become a terminal error,
105
+ * as does an untyped event carrying an `error` object (OpenRouter's
106
+ * documented mid-stream failure shape);
105
107
  * - every other event type is ignored, since the set is open and additive.
106
108
  *
107
109
  * @param request - Canonical IndeRun task request.
@@ -109,17 +111,31 @@ export declare class OpenAIResponsesProvider implements ProviderAdapter {
109
111
  */
110
112
  stream(request: TaskRequest, context: ProviderStreamContext): AsyncGenerator<ProviderStreamEvent>;
111
113
  /**
112
- * Maps a `response.failed` / `error` stream event onto the error taxonomy.
113
- * These arrive over an HTTP 200 body, so there is no status code to classify
114
- * from; OpenAI reports rate limiting and auth failures here with the same
115
- * `code` values it uses in unary error bodies.
114
+ * Maps a `response.failed` / `response.error` / `error` stream event onto the
115
+ * error taxonomy. These arrive over an HTTP 200 body, so there is no status
116
+ * code to classify from; the event's own `code` is classified instead.
116
117
  *
117
118
  * Two payload shapes exist and both are accepted: the standalone `error`
118
119
  * event carries `code`/`message` at its root, while `response.failed` nests
119
- * them under `response.error`. The root `type` is the event name rather than
120
- * an error type, so it is never read as one.
120
+ * them under `response.error` and some servers nest them under `error`. The
121
+ * root `type` is the event name rather than an error type, so it is never
122
+ * read as one. OpenRouter's typed classification comes from the embedded
123
+ * response (`response.failed`) or the error's metadata (untyped events).
121
124
  */
122
125
  private mapStreamError;
126
+ /**
127
+ * Classifies a failure reported in a body rather than by the HTTP status: a
128
+ * failed stream event or a 2xx run body whose status is `failed`. The most
129
+ * specific signal wins:
130
+ * 1. OpenRouter's typed `error_type`, classified by the HTTP status it
131
+ * documents for that type (see `openRouterErrorTypeStatus`);
132
+ * 2. an integer `code`, which is an HTTP status (OpenRouter's convention) and
133
+ * is classified exactly as `mapHttpError` classifies that status;
134
+ * 3. a string code, by OpenAI's names.
135
+ * Anything unrecognized is a transient `Unavailable`, since the server did
136
+ * accept the request.
137
+ */
138
+ private mapReportedError;
123
139
  /**
124
140
  * Resolves the request headers, including the bearer token behind
125
141
  * `authContextRef`. Shared by `run` and `stream`: the credential never travels
@@ -129,13 +145,27 @@ export declare class OpenAIResponsesProvider implements ProviderAdapter {
129
145
  private resolveHeaders;
130
146
  private createRequestBody;
131
147
  /**
132
- * Maps an OpenAI HTTP error response onto the IndeRun error taxonomy:
148
+ * Maps an OpenAI HTTP error response onto the IndeRun error taxonomy by its
149
+ * status (see `errorForStatus`), honoring `Retry-After` on whichever status
150
+ * carries it.
151
+ */
152
+ private mapHttpError;
153
+ /**
154
+ * The status classification shared by HTTP errors and numeric in-body codes:
133
155
  * - `401` / `403` → `AuthError`
134
- * - `429` → `RateLimited` (honors `Retry-After` when present)
156
+ * - `402` → `Unavailable`, not retryable: the account is out of credits, so
157
+ * this target cannot serve until someone tops it up. A 402 that carries
158
+ * `Retry-After` is the exception — OpenRouter documents it for its
159
+ * in-flight budget limit, a wait-and-retry case — and is `RateLimited`. Fallback is unaffected
160
+ * either way: the engine moves on to the next target whatever the class.
161
+ * - `429` → `RateLimited`
135
162
  * - `408` / `504` → `Timeout`
136
163
  * - `409` / `5xx` → `Unavailable`
137
- * - any other non-2xx status → `Internal`
164
+ * - any other status → `Internal`
165
+ *
166
+ * `retryAfterMs` travels on every retryable class; it is absent for numeric
167
+ * in-body codes, which have no header to read it from.
138
168
  */
139
- private mapHttpError;
169
+ private errorForStatus;
140
170
  }
141
171
  //# sourceMappingURL=provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAQ5E,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,2BAA2B,EAC3B,qBAAqB,EACrB,mBAAmB,EACnB,UAAU,EACX,MAAM,wBAAwB,CAAC;AA4BhC,eAAO,MAAM,iCAAiC,wCAAwC,CAAC;AAKvF;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,EAAE,CA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