blazen 0.1.161 → 0.5.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/index.d.ts CHANGED
@@ -52,6 +52,67 @@ export declare class AnthropicProvider {
52
52
  }
53
53
  export type JsAnthropicProvider = AnthropicProvider
54
54
 
55
+ /**
56
+ * Selects how a custom provider talks to its backend for completion
57
+ * calls.
58
+ *
59
+ * ```javascript
60
+ * import { ApiProtocol } from "blazen";
61
+ *
62
+ * const p1 = ApiProtocol.openai({
63
+ * providerName: "my-host",
64
+ * baseUrl: "https://api.example.com/v1",
65
+ * apiKey: "sk-...",
66
+ * defaultModel: "my-model",
67
+ * });
68
+ * console.log(p1.kind); // "openai"
69
+ *
70
+ * const p2 = ApiProtocol.custom();
71
+ * console.log(p2.kind); // "custom"
72
+ * ```
73
+ */
74
+ export declare class ApiProtocol {
75
+ /**
76
+ * Build an OpenAI-compatible API protocol wrapping the supplied
77
+ * configuration.
78
+ */
79
+ static openai(config: JsOpenAiCompatConfig): ApiProtocol
80
+ /**
81
+ * Build a custom (user-defined) API protocol. The completion
82
+ * dispatch path is handled by the host-language object passed to
83
+ * `CustomProvider`.
84
+ */
85
+ static custom(): ApiProtocol
86
+ /** Discriminator string: `"openai"` or `"custom"`. */
87
+ get kind(): string
88
+ /**
89
+ * The wrapped [`JsOpenAiCompatConfig`] when `kind === "openai"`,
90
+ * otherwise `null`.
91
+ */
92
+ get config(): JsOpenAiCompatConfig | null
93
+ }
94
+ export type JsApiProtocol = ApiProtocol
95
+
96
+ export declare class AudioMusicProviderDefaults {
97
+ /** Construct role-specific defaults. */
98
+ constructor(base?: BaseProviderDefaults | undefined | null, before?: BeforeRoleTsfn | undefined | null)
99
+ /** Returns `true` when a `before` hook is configured. */
100
+ get hasBefore(): boolean
101
+ /** Replace the typed `before` hook. Pass `null` to clear. */
102
+ set before(hook: BeforeRoleTsfn | undefined | null)
103
+ }
104
+ export type JsAudioMusicProviderDefaults = AudioMusicProviderDefaults
105
+
106
+ export declare class AudioSpeechProviderDefaults {
107
+ /** Construct role-specific defaults. */
108
+ constructor(base?: BaseProviderDefaults | undefined | null, before?: BeforeRoleTsfn | undefined | null)
109
+ /** Returns `true` when a `before` hook is configured. */
110
+ get hasBefore(): boolean
111
+ /** Replace the typed `before` hook. Pass `null` to clear. */
112
+ set before(hook: BeforeRoleTsfn | undefined | null)
113
+ }
114
+ export type JsAudioSpeechProviderDefaults = AudioSpeechProviderDefaults
115
+
55
116
  /**
56
117
  * An Azure `OpenAI` chat completion provider.
57
118
  *
@@ -99,6 +160,158 @@ export declare class BackgroundRemovalProvider {
99
160
  }
100
161
  export type JsBackgroundRemovalProvider = BackgroundRemovalProvider
101
162
 
163
+ export declare class BackgroundRemovalProviderDefaults {
164
+ /** Construct role-specific defaults. */
165
+ constructor(base?: BaseProviderDefaults | undefined | null, before?: BeforeRoleTsfn | undefined | null)
166
+ /** Returns `true` when a `before` hook is configured. */
167
+ get hasBefore(): boolean
168
+ /** Replace the typed `before` hook. Pass `null` to clear. */
169
+ set before(hook: BeforeRoleTsfn | undefined | null)
170
+ }
171
+ export type JsBackgroundRemovalProviderDefaults = BackgroundRemovalProviderDefaults
172
+
173
+ /**
174
+ * A completion provider wrapper that applies a
175
+ * [`JsCompletionProviderDefaults`] to every completion request before
176
+ * delegating to the inner model.
177
+ *
178
+ * `BaseProvider` is intended to be subclassed from JavaScript:
179
+ *
180
+ * ```javascript
181
+ * import { BaseProvider, CompletionModel } from "blazen";
182
+ *
183
+ * class TerseLlm extends BaseProvider {
184
+ * constructor() {
185
+ * const inner = CompletionModel.openai({ apiKey: "sk-..." });
186
+ * super(inner);
187
+ * this.withSystemPrompt("Be terse.");
188
+ * }
189
+ * }
190
+ * ```
191
+ *
192
+ * Today (V1) the constructor stores an opaque reference to the inner
193
+ * object — Phase D will wire `class extends` to fire the JS `complete`
194
+ * override before falling back to the inner Rust model.
195
+ */
196
+ export declare class BaseProvider {
197
+ /**
198
+ * Construct a new [`BaseProvider`].
199
+ *
200
+ * `inner` is the underlying completion model — pass a
201
+ * [`JsCompletionModel`] instance. JS subclasses that fully
202
+ * override `complete` may pass `null` here (Phase D will wire
203
+ * subclass dispatch end-to-end; today calls to `complete` on a
204
+ * subclass-only provider report unsupported).
205
+ *
206
+ * `defaults` optionally seeds the
207
+ * [`JsCompletionProviderDefaults`]; when omitted, an empty
208
+ * defaults bag is created.
209
+ */
210
+ constructor(inner?: JsCompletionModel | undefined | null, defaults?: JsCompletionProviderDefaults | undefined | null)
211
+ /**
212
+ * Set the default system prompt prepended to requests when no
213
+ * system message is already present.
214
+ */
215
+ withSystemPrompt(prompt: string): BaseProvider
216
+ /** Replace the default tools appended to every completion request. */
217
+ withTools(tools: Array<JsToolDefinition>): BaseProvider
218
+ /** Set the default `responseFormat` (JSON Schema object). */
219
+ withResponseFormat(format: any): BaseProvider
220
+ /**
221
+ * Set the universal `beforeRequest` hook (fires for any request
222
+ * type). V1: stored only — Phase B wires dispatch.
223
+ */
224
+ withBeforeRequest(hook: BeforeRequestTsfn): BaseProvider
225
+ /**
226
+ * Set the typed `beforeCompletion` hook (fires after the universal
227
+ * hook, with a typed completion request). V1: stored only — Phase
228
+ * B wires dispatch.
229
+ */
230
+ withBeforeCompletion(hook: BeforeCompletionTsfn): BaseProvider
231
+ /** Replace the entire defaults bag. */
232
+ withDefaults(defaults: JsCompletionProviderDefaults): BaseProvider
233
+ /** The currently-configured defaults. */
234
+ get defaults(): JsCompletionProviderDefaults
235
+ /**
236
+ * The inner model's `modelId`. Returns the empty string when the
237
+ * provider was constructed without a Rust-side `inner` (JS subclass
238
+ * path).
239
+ */
240
+ get modelId(): string
241
+ /**
242
+ * The provider identifier used for logging. Defaults to the inner
243
+ * model's `modelId` when present, otherwise `"base"`. Subclasses
244
+ * may override.
245
+ */
246
+ get providerId(): string
247
+ /**
248
+ * Typed structured extraction.
249
+ *
250
+ * Sends a completion request with a JSON Schema `response_format`
251
+ * envelope and parses the model's response as JSON. The schema
252
+ * argument is a plain JSON Schema object (callers using zod can
253
+ * convert with `zodToJsonSchema(zSchema)` from the `zod-to-json-schema`
254
+ * package).
255
+ *
256
+ * The `response_format` is wired up as the `OpenAI`-style
257
+ * `{"type":"json_schema","json_schema":{"name":"Extract","schema":...,"strict":true}}`
258
+ * envelope; provider implementations that don't natively support
259
+ * structured outputs fall back to a system-instruction shim (see
260
+ * `crates/blazen-llm/src/providers/anthropic.rs::build_json_schema_system_instruction`).
261
+ *
262
+ * Returns the parsed JSON value. The TypeScript surface declares
263
+ * the return as `any` because the schema shape is only known at
264
+ * runtime; callers can narrow via TS generics on their wrapper.
265
+ *
266
+ * ```typescript
267
+ * const schema = {
268
+ * type: "object",
269
+ * properties: {
270
+ * name: { type: "string" },
271
+ * age: { type: "integer" },
272
+ * },
273
+ * required: ["name", "age"],
274
+ * };
275
+ * const result = await provider.extract(schema, [
276
+ * ChatMessage.user("My name is Alice and I am 30."),
277
+ * ]);
278
+ * // -> { name: "Alice", age: 30 }
279
+ * ```
280
+ */
281
+ extract(schema: any, messages: Array<JsChatMessage>): Promise<any>
282
+ }
283
+ export type JsBaseProvider = BaseProvider
284
+
285
+ /**
286
+ * Universal provider defaults applicable to every provider role.
287
+ *
288
+ * Carries cross-cutting fields (currently just the `beforeRequest`
289
+ * hook). Embedded as a `base` field on every role-specific defaults
290
+ * class.
291
+ *
292
+ * ```javascript
293
+ * import { BaseProviderDefaults } from "blazen";
294
+ *
295
+ * const d = new BaseProviderDefaults(async (method, request) => {
296
+ * console.log("request via", method);
297
+ * });
298
+ * ```
299
+ */
300
+ export declare class BaseProviderDefaults {
301
+ /**
302
+ * Construct a new [`BaseProviderDefaults`].
303
+ *
304
+ * `beforeRequest` is an optional async callback fired before any
305
+ * provider request (V1: stored only, not yet dispatched).
306
+ */
307
+ constructor(beforeRequest?: BeforeRequestTsfn | undefined | null)
308
+ /** Returns `true` when a `beforeRequest` hook is configured. */
309
+ get hasBeforeRequest(): boolean
310
+ /** Replace the `beforeRequest` hook. Pass `null` to clear. */
311
+ set beforeRequest(hook: BeforeRequestTsfn | undefined | null)
312
+ }
313
+ export type JsBaseProviderDefaults = BaseProviderDefaults
314
+
102
315
  /**
103
316
  * Typed configuration for a batch completion run.
104
317
  *
@@ -754,6 +967,59 @@ export declare class CompletionModel {
754
967
  static cohere(options?: JsProviderOptions | undefined | null): CompletionModel
755
968
  /** Create an AWS Bedrock completion model. */
756
969
  static bedrock(options: JsBedrockOptions): CompletionModel
970
+ /**
971
+ * Create a local Ollama completion model.
972
+ *
973
+ * Talks to a running Ollama server (defaults to `http://host:port/v1`).
974
+ * No API key is required.
975
+ *
976
+ * ```javascript
977
+ * const model = CompletionModel.ollama("localhost", 11434, "llama3.1:8b");
978
+ * ```
979
+ */
980
+ static ollama(host: string, port: number, model: string): CompletionModel
981
+ /**
982
+ * Create a local LM Studio completion model.
983
+ *
984
+ * Talks to a running LM Studio server's OpenAI-compatible endpoint.
985
+ *
986
+ * ```javascript
987
+ * const model = CompletionModel.lmStudio("localhost", 1234, "my-model");
988
+ * ```
989
+ */
990
+ static lmStudio(host: string, port: number, model: string): CompletionModel
991
+ /**
992
+ * Create a generic OpenAI-compatible completion model.
993
+ *
994
+ * Drives any OpenAI-compatible chat-completions endpoint with the
995
+ * supplied [`JsOpenAiCompatConfig`].
996
+ *
997
+ * ```javascript
998
+ * const model = CompletionModel.openaiCompat("my-host", {
999
+ * providerName: "my-host",
1000
+ * baseUrl: "https://api.example.com/v1",
1001
+ * apiKey: "sk-...",
1002
+ * defaultModel: "my-model",
1003
+ * });
1004
+ * ```
1005
+ */
1006
+ static openaiCompat(providerId: string, config: JsOpenAiCompatConfig): CompletionModel
1007
+ /**
1008
+ * Create a fully user-defined completion model backed by a JavaScript
1009
+ * host object.
1010
+ *
1011
+ * `hostObject` must expose Blazen capability methods (e.g.
1012
+ * `complete`, `stream`) using the camelCase trait-method names. The
1013
+ * optional `providerId` is used for logging; defaults to `"custom"`.
1014
+ *
1015
+ * ```javascript
1016
+ * class MyProvider {
1017
+ * async complete(request) { /* ... *\/ }
1018
+ * }
1019
+ * const model = CompletionModel.custom(new MyProvider(), "my-provider");
1020
+ * ```
1021
+ */
1022
+ static custom(hostObject: object, providerId?: string | undefined | null): CompletionModel
757
1023
  /** Get the model ID. */
758
1024
  get modelId(): string
759
1025
  /**
@@ -901,6 +1167,47 @@ export declare class CompletionModel {
901
1167
  }
902
1168
  export type JsCompletionModel = CompletionModel
903
1169
 
1170
+ /**
1171
+ * Completion-role provider defaults: system prompt, default tools,
1172
+ * `responseFormat`, and a typed `beforeCompletion` hook.
1173
+ *
1174
+ * ```javascript
1175
+ * import { BaseProviderDefaults, CompletionProviderDefaults } from "blazen";
1176
+ *
1177
+ * const d = new CompletionProviderDefaults(
1178
+ * new BaseProviderDefaults(),
1179
+ * "Be terse.",
1180
+ * [], // default tools
1181
+ * { type: "json_object" },
1182
+ * async (request) => { /* mutate request *\/ },
1183
+ * );
1184
+ * ```
1185
+ */
1186
+ export declare class CompletionProviderDefaults {
1187
+ /** Construct completion-role defaults. */
1188
+ constructor(base?: BaseProviderDefaults | undefined | null, systemPrompt?: string | undefined | null, tools?: Array<JsToolDefinition> | undefined | null, responseFormat?: any | undefined | null, beforeCompletion?: BeforeCompletionTsfn | undefined | null)
1189
+ /**
1190
+ * The system prompt prepended to requests when the request itself
1191
+ * carries no system message.
1192
+ */
1193
+ get systemPrompt(): string | null
1194
+ /** Replace the system prompt. Pass `null` to clear. */
1195
+ set systemPrompt(value: string | undefined | null)
1196
+ /** The default tools appended to every completion request. */
1197
+ get tools(): Array<JsToolDefinition>
1198
+ /** Replace the default tools. */
1199
+ set tools(value: Array<JsToolDefinition> | undefined | null)
1200
+ /** Default `response_format` (JSON Schema or similar object). */
1201
+ get responseFormat(): any | null
1202
+ /** Replace the default `responseFormat`. Pass `null` to clear. */
1203
+ set responseFormat(value: any | undefined | null)
1204
+ /** Returns `true` when a `beforeCompletion` hook is configured. */
1205
+ get hasBeforeCompletion(): boolean
1206
+ /** Replace the typed `beforeCompletion` hook. Pass `null` to clear. */
1207
+ set beforeCompletion(hook: BeforeCompletionTsfn | undefined | null)
1208
+ }
1209
+ export type JsCompletionProviderDefaults = CompletionProviderDefaults
1210
+
904
1211
  /**
905
1212
  * Pluggable registry for multimodal content. Wraps
906
1213
  * [`Arc<dyn blazen_llm::content::ContentStore>`].
@@ -1124,75 +1431,125 @@ export declare class Context {
1124
1431
  export type JsContext = Context
1125
1432
 
1126
1433
  /**
1127
- * A user-defined Blazen provider backed by a JavaScript class instance.
1434
+ * A user-defined Blazen provider exposed to JavaScript.
1128
1435
  *
1129
- * Wraps an arbitrary object whose async methods match Blazen's
1130
- * capability trait names (`textToSpeech`, `cloneVoice`,
1131
- * `generateImage`, etc.) and exposes them as a first-class provider.
1132
- * The workflow engine treats the result as implementing every
1133
- * capability trait whose methods the wrapped object provides; missing
1134
- * methods return `UnsupportedError` when called.
1436
+ * `CustomProvider` is designed for two complementary use cases:
1135
1437
  *
1136
- * Request/response shapes use Blazen's typed request/result types on
1137
- * the JavaScript side and get serialized through napi's
1138
- * `serde_json::Value` bridge to the wrapped object's methods, which
1139
- * receive/return plain objects.
1438
+ * 1. **Subclass from JavaScript** to plug an arbitrary backend into
1439
+ * Blazen. Override any combination of the typed methods
1440
+ * (`textToSpeech`, `generateImage`, `cloneVoice`, …). When the
1441
+ * framework dispatches a capability, the override fires; methods
1442
+ * you did not override report `UnsupportedError`.
1443
+ * 2. **Use a static factory** ([`Self::ollama`], [`Self::lm_studio`],
1444
+ * [`Self::openai_compat`]) to get a ready-made handle that speaks
1445
+ * the `OpenAI` Chat Completions wire format.
1140
1446
  *
1141
1447
  * ```typescript
1142
- * import { CustomProvider } from "blazen";
1448
+ * import { ApiProtocol, CustomProvider } from "blazen";
1143
1449
  *
1144
- * class MyElevenLabsProvider {
1145
- * constructor(apiKey: string) {
1146
- * this.client = new ElevenLabs({ apiKey });
1147
- * }
1450
+ * class MyElevenLabsProvider extends CustomProvider {
1451
+ * constructor(apiKey: string) {
1452
+ * super("elevenlabs", ApiProtocol.custom());
1453
+ * this.client = new ElevenLabs({ apiKey });
1454
+ * }
1148
1455
  *
1149
- * async textToSpeech(request: { text: string; voice?: string }) {
1150
- * const audio = await this.client.textToSpeech.convert({
1151
- * voiceId: request.voice ?? "default",
1152
- * text: request.text,
1153
- * modelId: "eleven_multilingual_v2",
1154
- * });
1155
- * return {
1156
- * audio: [{
1157
- * media: {
1158
- * base64: Buffer.from(audio).toString("base64"),
1159
- * mediaType: "mpeg",
1160
- * },
1161
- * }],
1162
- * timing: { totalMs: 0, queueMs: null, executionMs: null },
1163
- * metadata: {},
1164
- * };
1165
- * }
1456
+ * async textToSpeech(request: { text: string; voice?: string }) {
1457
+ * const audio = await this.client.textToSpeech.convert({
1458
+ * voiceId: request.voice ?? "default",
1459
+ * text: request.text,
1460
+ * modelId: "eleven_multilingual_v2",
1461
+ * });
1462
+ * return {
1463
+ * audio: [{
1464
+ * media: {
1465
+ * base64: Buffer.from(audio).toString("base64"),
1466
+ * mediaType: "mpeg",
1467
+ * },
1468
+ * }],
1469
+ * timing: { totalMs: 0, queueMs: null, executionMs: null },
1470
+ * metadata: {},
1471
+ * };
1472
+ * }
1166
1473
  * }
1167
1474
  *
1168
- * const provider = new CustomProvider(
1169
- * new MyElevenLabsProvider("..."),
1170
- * { providerId: "elevenlabs" },
1171
- * );
1475
+ * const provider = new MyElevenLabsProvider("sk-...");
1172
1476
  * const audio = await provider.textToSpeech({
1173
- * text: "hello",
1174
- * voice: "rachel",
1477
+ * text: "hello",
1478
+ * voice: "rachel",
1175
1479
  * });
1176
1480
  * ```
1177
1481
  */
1178
1482
  export declare class CustomProvider {
1179
1483
  /**
1180
- * Wrap a JavaScript host object as a Blazen [`CustomProvider`].
1484
+ * Construct a `CustomProvider`.
1485
+ *
1486
+ * Takes an options object:
1487
+ *
1488
+ * ```typescript
1489
+ * interface CustomProviderOptions {
1490
+ * providerId: string; // required: short identifier for logging
1491
+ * protocol?: ApiProtocol; // optional: defaults to ApiProtocol.custom()
1492
+ * }
1493
+ * ```
1494
+ *
1495
+ * ```javascript
1496
+ * // Direct construction (every typed method reports Unsupported).
1497
+ * const provider = new CustomProvider({ providerId: "my-provider" });
1498
+ *
1499
+ * // Subclass with capability overrides.
1500
+ * class MyTts extends CustomProvider {
1501
+ * constructor() {
1502
+ * super({ providerId: "my-tts" });
1503
+ * }
1504
+ * async textToSpeech(request) { ... }
1505
+ * }
1506
+ * ```
1507
+ *
1508
+ * When the constructor is invoked via `new (class extends
1509
+ * CustomProvider) { … }`, the prototype of the JS instance
1510
+ * differs from `CustomProvider.prototype`. The Rust constructor
1511
+ * detects that case and installs a [`JsCustomProviderAdapter`]
1512
+ * wrapping the JS instance so every overridden method dispatches
1513
+ * through the JS side.
1514
+ *
1515
+ * When the constructor is invoked directly as
1516
+ * `new CustomProvider({ providerId })` (no subclass), the
1517
+ * resulting handle reports every typed method as `Unsupported`
1518
+ * unless built via one of the static factories
1519
+ * ([`Self::ollama`] / [`Self::lm_studio`] / [`Self::openai_compat`]).
1520
+ */
1521
+ constructor(options: { providerId: string; protocol?: ApiProtocol })
1522
+ /**
1523
+ * Convenience constructor for a local Ollama server.
1524
+ *
1525
+ * Equivalent to building a `CustomProvider` whose protocol is
1526
+ * `ApiProtocol.openai({ baseUrl: "http://<host>:<port>/v1", … })`.
1527
+ *
1528
+ * ```typescript
1529
+ * const provider = CustomProvider.ollama("llama3.1");
1530
+ * const provider = CustomProvider.ollama("llama3.1", "192.168.1.50", 11434);
1531
+ * ```
1532
+ */
1533
+ static ollama(model: string, host?: string | undefined | null, port?: number | undefined | null): CustomProvider
1534
+ /**
1535
+ * Convenience constructor for a local LM Studio server.
1181
1536
  *
1182
- * `hostObject` is a class instance (or plain object) whose async
1183
- * methods match Blazen capability trait method names
1184
- * (`textToSpeech`, `generateImage`, `cloneVoice`, ...). Host
1185
- * methods should be `async` and accept a single object argument
1186
- * shaped like the corresponding Blazen request type. Synchronous
1187
- * host methods are supported as long as they return a `Promise`
1188
- * explicitly -- the ordinary async dispatch path awaits the
1189
- * returned `Promise`.
1537
+ * Equivalent to building a `CustomProvider` whose protocol is
1538
+ * `ApiProtocol.openai({ baseUrl: "http://<host>:<port>/v1", })`.
1190
1539
  *
1191
- * `options.providerId` is an optional short identifier used for
1192
- * logging and returned from [`JsCustomProvider::provider_id`].
1193
- * Defaults to `"custom"`.
1540
+ * ```typescript
1541
+ * const provider = CustomProvider.lmStudio("my-model");
1542
+ * const provider = CustomProvider.lmStudio("my-model", "127.0.0.1", 1234);
1543
+ * ```
1194
1544
  */
1195
- constructor(hostObject: object, options?: CustomProviderOptions | undefined | null)
1545
+ static lmStudio(model: string, host?: string | undefined | null, port?: number | undefined | null): CustomProvider
1546
+ /**
1547
+ * Build a `CustomProvider` that speaks the `OpenAI` Chat
1548
+ * Completions protocol. Use for any OpenAI-compatible HTTP
1549
+ * endpoint that is not already covered by [`Self::ollama`] /
1550
+ * [`Self::lm_studio`].
1551
+ */
1552
+ static openaiCompat(providerId: string, config: JsOpenAiCompatConfig): CustomProvider
1196
1553
  /** The provider identifier used for logging (e.g. `"elevenlabs"`). */
1197
1554
  get providerId(): string
1198
1555
  /**
@@ -1413,6 +1770,16 @@ export declare class EmbeddingModel {
1413
1770
  }
1414
1771
  export type JsEmbeddingModel = EmbeddingModel
1415
1772
 
1773
+ /**
1774
+ * Embedding-role provider defaults. V1 just wraps a
1775
+ * [`JsBaseProviderDefaults`].
1776
+ */
1777
+ export declare class EmbeddingProviderDefaults {
1778
+ /** Construct embedding-role defaults. */
1779
+ constructor(base?: BaseProviderDefaults | undefined | null)
1780
+ }
1781
+ export type JsEmbeddingProviderDefaults = EmbeddingProviderDefaults
1782
+
1416
1783
  /**
1417
1784
  * A local embedding provider.
1418
1785
  *
@@ -1778,32 +2145,6 @@ export declare class HistoryEventKind {
1778
2145
  }
1779
2146
  export type JsHistoryEventKind = HistoryEventKind
1780
2147
 
1781
- /**
1782
- * Base class for user-extendable host dispatchers.
1783
- *
1784
- * Mirrors [`blazen_llm::HostDispatch`]. Subclasses override `call(method,
1785
- * request)` to plug a JS-side capability table into a Blazen
1786
- * [`CustomProvider`](crate::providers::JsCustomProvider). Most users
1787
- * will reach for [`crate::providers::JsCustomProvider`] directly with a
1788
- * plain JS object; this class exists so users can subclass with shared
1789
- * state and override `hasMethod` independently from `call`.
1790
- */
1791
- export declare class HostDispatch {
1792
- /** Create a new host dispatch base instance. */
1793
- constructor()
1794
- /**
1795
- * Dispatch a Rust-side capability call to the JavaScript host.
1796
- * Subclasses **must** override.
1797
- */
1798
- call(method: string, request: any): Promise<any>
1799
- /**
1800
- * Whether this dispatcher implements `method`. Subclasses **must**
1801
- * override.
1802
- */
1803
- hasMethod(method: string): boolean
1804
- }
1805
- export type JsHostDispatch = HostDispatch
1806
-
1807
2148
  /**
1808
2149
  * Abstract base class for custom HTTP transports.
1809
2150
  *
@@ -1907,6 +2248,16 @@ export declare class HttpPeerClient {
1907
2248
  }
1908
2249
  export type JsHttpPeerClient = HttpPeerClient
1909
2250
 
2251
+ export declare class ImageGenerationProviderDefaults {
2252
+ /** Construct role-specific defaults. */
2253
+ constructor(base?: BaseProviderDefaults | undefined | null, before?: BeforeRoleTsfn | undefined | null)
2254
+ /** Returns `true` when a `before` hook is configured. */
2255
+ get hasBefore(): boolean
2256
+ /** Replace the typed `before` hook. Pass `null` to clear. */
2257
+ set before(hook: BeforeRoleTsfn | undefined | null)
2258
+ }
2259
+ export type JsImageGenerationProviderDefaults = ImageGenerationProviderDefaults
2260
+
1910
2261
  /**
1911
2262
  * Base class for custom image-generation providers.
1912
2263
  *
@@ -1969,6 +2320,16 @@ export declare class ImageProvider {
1969
2320
  }
1970
2321
  export type JsImageProvider = ImageProvider
1971
2322
 
2323
+ export declare class ImageUpscaleProviderDefaults {
2324
+ /** Construct role-specific defaults. */
2325
+ constructor(base?: BaseProviderDefaults | undefined | null, before?: BeforeRoleTsfn | undefined | null)
2326
+ /** Returns `true` when a `before` hook is configured. */
2327
+ get hasBefore(): boolean
2328
+ /** Replace the typed `before` hook. Pass `null` to clear. */
2329
+ set before(hook: BeforeRoleTsfn | undefined | null)
2330
+ }
2331
+ export type JsImageUpscaleProviderDefaults = ImageUpscaleProviderDefaults
2332
+
1972
2333
  /** A single chunk from a streaming local inference call. */
1973
2334
  export declare class InferenceChunk {
1974
2335
  /** Incremental text content for this chunk, if any. */
@@ -4199,6 +4560,16 @@ export declare class ThreeDProvider {
4199
4560
  }
4200
4561
  export type JsThreeDProvider = ThreeDProvider
4201
4562
 
4563
+ export declare class ThreeDProviderDefaults {
4564
+ /** Construct role-specific defaults. */
4565
+ constructor(base?: BaseProviderDefaults | undefined | null, before?: BeforeRoleTsfn | undefined | null)
4566
+ /** Returns `true` when a `before` hook is configured. */
4567
+ get hasBefore(): boolean
4568
+ /** Replace the typed `before` hook. Pass `null` to clear. */
4569
+ set before(hook: BeforeRoleTsfn | undefined | null)
4570
+ }
4571
+ export type JsThreeDProviderDefaults = ThreeDProviderDefaults
4572
+
4202
4573
  /**
4203
4574
  * Exact BPE token counter backed by `tiktoken-rs`.
4204
4575
  *
@@ -4505,6 +4876,16 @@ export declare class Transcription {
4505
4876
  }
4506
4877
  export type JsTranscription = Transcription
4507
4878
 
4879
+ export declare class TranscriptionProviderDefaults {
4880
+ /** Construct role-specific defaults. */
4881
+ constructor(base?: BaseProviderDefaults | undefined | null, before?: BeforeRoleTsfn | undefined | null)
4882
+ /** Returns `true` when a `before` hook is configured. */
4883
+ get hasBefore(): boolean
4884
+ /** Replace the typed `before` hook. Pass `null` to clear. */
4885
+ set before(hook: BeforeRoleTsfn | undefined | null)
4886
+ }
4887
+ export type JsTranscriptionProviderDefaults = TranscriptionProviderDefaults
4888
+
4508
4889
  /**
4509
4890
  * r" Base class for text-to-speech providers.
4510
4891
  * r"
@@ -4743,6 +5124,26 @@ export declare class VideoProvider {
4743
5124
  }
4744
5125
  export type JsVideoProvider = VideoProvider
4745
5126
 
5127
+ export declare class VideoProviderDefaults {
5128
+ /** Construct role-specific defaults. */
5129
+ constructor(base?: BaseProviderDefaults | undefined | null, before?: BeforeRoleTsfn | undefined | null)
5130
+ /** Returns `true` when a `before` hook is configured. */
5131
+ get hasBefore(): boolean
5132
+ /** Replace the typed `before` hook. Pass `null` to clear. */
5133
+ set before(hook: BeforeRoleTsfn | undefined | null)
5134
+ }
5135
+ export type JsVideoProviderDefaults = VideoProviderDefaults
5136
+
5137
+ export declare class VoiceCloningProviderDefaults {
5138
+ /** Construct role-specific defaults. */
5139
+ constructor(base?: BaseProviderDefaults | undefined | null, before?: BeforeRoleTsfn | undefined | null)
5140
+ /** Returns `true` when a `before` hook is configured. */
5141
+ get hasBefore(): boolean
5142
+ /** Replace the typed `before` hook. Pass `null` to clear. */
5143
+ set before(hook: BeforeRoleTsfn | undefined | null)
5144
+ }
5145
+ export type JsVoiceCloningProviderDefaults = VoiceCloningProviderDefaults
5146
+
4746
5147
  /**
4747
5148
  * r" Base class for voice cloning providers.
4748
5149
  * r"
@@ -5146,43 +5547,6 @@ export declare class WorkflowCheckpoint {
5146
5547
  }
5147
5548
  export type JsWorkflowCheckpoint = WorkflowCheckpoint
5148
5549
 
5149
- /**
5150
- * A handle to a running workflow.
5151
- *
5152
- * Returned by `Workflow.runWithHandler()`. Provides methods to:
5153
- *
5154
- * - **`result()`** -- await the final workflow result (consumes the handler).
5155
- * - **`pause()`** -- signal the workflow to pause.
5156
- * - **`snapshot()`** -- get a serializable snapshot as a JSON string.
5157
- * - **`resumeInPlace()`** -- resume a paused workflow without creating a new one.
5158
- * - **`respondToInput(requestId, response)`** -- respond to an input request.
5159
- * - **`abort()`** -- abort the running workflow.
5160
- * - **`streamEvents(callback)`** -- subscribe to intermediate events
5161
- * published via `ctx.writeEventToStream()`.
5162
- *
5163
- * **Important:** `result()` consumes the handler internally. You can only
5164
- * call it once. The other control methods (`pause`, `resumeInPlace`,
5165
- * `abort`, `respondToInput`, `snapshot`) borrow the handler and can be
5166
- * called multiple times.
5167
- *
5168
- * ```javascript
5169
- * const handler = await workflow.runWithHandler({ message: "hello" });
5170
- *
5171
- * // Option A: just get the result
5172
- * const result = await handler.result();
5173
- *
5174
- * // Option B: pause, snapshot, then resume
5175
- * await handler.pause();
5176
- * const snap = await handler.snapshot();
5177
- * fs.writeFileSync("snapshot.json", snap);
5178
- * await handler.resumeInPlace();
5179
- * const result = await handler.result();
5180
- *
5181
- * // Option C: stream events, then get the result
5182
- * handler.streamEvents((event) => console.log(event));
5183
- * const result = await handler.result();
5184
- * ```
5185
- */
5186
5550
  export declare class WorkflowHandler {
5187
5551
  /**
5188
5552
  * Await the final workflow result.
@@ -5247,7 +5611,10 @@ export declare class WorkflowHandler {
5247
5611
  * The `onEvent` callback receives each event as a plain object.
5248
5612
  * This must be called **before** `result()` or `pause()`.
5249
5613
  *
5250
- * Events published before this call are not replayed.
5614
+ * The first call drains the pre-subscribed stream that was set up
5615
+ * before the event loop spawned, so the very first step's events
5616
+ * are captured. Subsequent calls subscribe a fresh stream that
5617
+ * starts from the current point in time.
5251
5618
  */
5252
5619
  streamEvents(onEvent: StreamCallbackTsfn): Promise<void>
5253
5620
  }
@@ -5718,14 +6085,18 @@ export interface CustomContentStoreOptions {
5718
6085
  name?: string
5719
6086
  }
5720
6087
 
5721
- /** Optional configuration for a [`JsCustomProvider`]. */
5722
- export interface CustomProviderOptions {
5723
- /**
5724
- * Short identifier used for logging and returned from
5725
- * [`ComputeProvider::provider_id`]. Defaults to `"custom"`.
5726
- */
5727
- providerId?: string
5728
- }
6088
+ /**
6089
+ * Per-model endpoint base URL (mirrors
6090
+ * [`blazen_llm::DEFAULT_MODEL_PRICING_URL_BASE`]). Append a normalized model
6091
+ * ID to fetch a single entry.
6092
+ */
6093
+ export const DEFAULT_MODEL_PRICING_URL_BASE: string
6094
+
6095
+ /**
6096
+ * Bulk endpoint URL for the default pricing catalog (mirrors
6097
+ * [`blazen_llm::DEFAULT_PRICING_URL`]).
6098
+ */
6099
+ export const DEFAULT_PRICING_URL: string
5729
6100
 
5730
6101
  /** Build a default [`JsHttpClientConfig`] (60s request, 10s connect, no UA). */
5731
6102
  export declare function defaultHttpClientConfig(): HttpClientConfig
@@ -5815,6 +6186,30 @@ export interface EventEnvelope {
5815
6186
  */
5816
6187
  export declare function extractInlineArtifacts(content: string): Array<JsArtifact>
5817
6188
 
6189
+ /**
6190
+ * Fetch a single model's pricing from `DEFAULT_MODEL_PRICING_URL_BASE` using
6191
+ * the platform-default HTTP client and register it. Resolves to the registered
6192
+ * pricing entry, or `null` on a 404 (so callers can distinguish "no such
6193
+ * model" from a transport failure). Direct parity with
6194
+ * [`blazen_llm::fetch_one_default`].
6195
+ *
6196
+ * # Errors
6197
+ * Returns a JS error if the HTTP fetch fails, returns a non-(2xx|404)
6198
+ * status, or the response body cannot be parsed as a `PricingEntry`.
6199
+ */
6200
+ export declare function fetchOneDefault(modelId: string): Promise<JsModelPricing | null>
6201
+
6202
+ /**
6203
+ * Fetch a single model's pricing from `{urlBase}{modelId}` using the
6204
+ * platform-default HTTP client and register it. Resolves to `null` on a 404.
6205
+ * Direct parity with [`blazen_llm::fetch_one_default_with_url_base`].
6206
+ *
6207
+ * # Errors
6208
+ * Returns a JS error if the HTTP fetch fails, returns a non-(2xx|404)
6209
+ * status, or the response body cannot be parsed as a `PricingEntry`.
6210
+ */
6211
+ export declare function fetchOneDefaultWithUrlBase(urlBase: string, modelId: string): Promise<JsModelPricing | null>
6212
+
5818
6213
  /**
5819
6214
  * File / document content (PDF, generic file, etc.) for multimodal
5820
6215
  * messages. Mirrors [`blazen_llm::types::FileContent`].
@@ -7925,6 +8320,50 @@ export declare const enum RefLifetime {
7925
8320
  UntilParentFinish = 'UntilParentFinish'
7926
8321
  }
7927
8322
 
8323
+ /**
8324
+ * Bulk refresh the pricing registry from `DEFAULT_PRICING_URL` using the
8325
+ * platform-default HTTP client. Resolves to the number of entries registered.
8326
+ * Direct parity with [`blazen_llm::refresh_default`].
8327
+ *
8328
+ * # Errors
8329
+ * Returns a JS error if the HTTP fetch fails, returns a non-2xx status, or
8330
+ * the response body cannot be parsed as the expected pricing schema.
8331
+ */
8332
+ export declare function refreshDefault(): Promise<number>
8333
+
8334
+ /**
8335
+ * Bulk refresh the pricing registry from `url` using the platform-default
8336
+ * HTTP client. Resolves to the number of entries registered. Direct parity
8337
+ * with [`blazen_llm::refresh_default_with_url`].
8338
+ *
8339
+ * # Errors
8340
+ * Returns a JS error if the HTTP fetch fails, returns a non-2xx status, or
8341
+ * the response body cannot be parsed as the expected pricing schema.
8342
+ */
8343
+ export declare function refreshDefaultWithUrl(url: string): Promise<number>
8344
+
8345
+ /**
8346
+ * Refresh the pricing registry from a remote catalog (defaults to the
8347
+ * blazen.dev Cloudflare Worker, which mirrors models.dev plus live
8348
+ * `OpenRouter` / Together pricing on a daily cron).
8349
+ *
8350
+ * Resolves to the number of entries registered. Call once at app startup
8351
+ * to populate pricing for the ~1600+ models the build-time baked baseline
8352
+ * doesn't carry. Misses still resolve to `null` from the cost lookups;
8353
+ * no automatic retry / cache layer beyond the global registry.
8354
+ *
8355
+ * ```javascript
8356
+ * const count = await refreshPricing(); // bulk fetch
8357
+ * // or:
8358
+ * await refreshPricing("https://my-mirror.example/pricing.json");
8359
+ * ```
8360
+ *
8361
+ * # Errors
8362
+ * Returns a JS error if the HTTP fetch fails, returns a non-2xx status,
8363
+ * or the response body cannot be parsed as the expected pricing schema.
8364
+ */
8365
+ export declare function refreshPricing(url?: string | undefined | null): Promise<number>
8366
+
7928
8367
  /**
7929
8368
  * All step IDs registered in the process-global registry. Order is
7930
8369
  * unspecified.
@@ -8038,7 +8477,7 @@ export declare function resolveApiKey(provider: string, explicit?: string | unde
8038
8477
  * Returns `null` when the env var (see [`peer_token_env`]) is unset
8039
8478
  * or empty.
8040
8479
  */
8041
- export declare function resolveBeerToken(): string | null
8480
+ export declare function resolvePeerToken(): string | null
8042
8481
 
8043
8482
  /**
8044
8483
  * Resolve the effective [`JsRetryConfig`] for the given stack and an