@arcships/aimux 0.2.1 → 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.
Files changed (167) hide show
  1. package/dist/error.d.ts +139 -0
  2. package/dist/error.js +114 -0
  3. package/dist/index.d.ts +162 -8
  4. package/dist/index.js +334 -28
  5. package/dist/native.d.ts +2 -0
  6. package/dist/native.js +46 -0
  7. package/dist/types/AiMuxError.d.ts +45 -13
  8. package/dist/types/AiMuxError.js +0 -1
  9. package/dist/types/ApiCallError.d.ts +75 -0
  10. package/dist/types/ApiCallError.js +2 -0
  11. package/dist/types/BreakKind.d.ts +1 -0
  12. package/dist/types/BreakKind.js +3 -0
  13. package/dist/types/CallOptions.d.ts +28 -2
  14. package/dist/types/CatalogueSource.d.ts +4 -0
  15. package/dist/types/CatalogueSource.js +3 -0
  16. package/dist/types/ChatCompletion.d.ts +16 -0
  17. package/dist/types/ChatCompletion.js +2 -0
  18. package/dist/types/ChatCompletionChoice.d.ts +8 -0
  19. package/dist/types/ChatCompletionChoice.js +2 -0
  20. package/dist/types/ChatCompletionChunk.d.ts +15 -0
  21. package/dist/types/ChatCompletionChunk.js +2 -0
  22. package/dist/types/ChatCompletionChunkChoice.d.ts +8 -0
  23. package/dist/types/ChatCompletionChunkChoice.js +2 -0
  24. package/dist/types/ChatCompletionChunkFunction.d.ts +4 -0
  25. package/dist/types/ChatCompletionChunkFunction.js +3 -0
  26. package/dist/types/ChatCompletionChunkToolCall.d.ts +7 -0
  27. package/dist/types/ChatCompletionChunkToolCall.js +2 -0
  28. package/dist/types/ChatCompletionDelta.d.ts +7 -0
  29. package/dist/types/ChatCompletionDelta.js +2 -0
  30. package/dist/types/ChatCompletionFunction.d.ts +4 -0
  31. package/dist/types/ChatCompletionFunction.js +3 -0
  32. package/dist/types/ChatCompletionMessage.d.ts +9 -0
  33. package/dist/types/ChatCompletionMessage.js +2 -0
  34. package/dist/types/ChatCompletionToolCall.d.ts +6 -0
  35. package/dist/types/ChatCompletionToolCall.js +2 -0
  36. package/dist/types/ChatCompletionUsage.d.ts +9 -0
  37. package/dist/types/ChatCompletionUsage.js +2 -0
  38. package/dist/types/CompletionTokensDetails.d.ts +3 -0
  39. package/dist/types/CompletionTokensDetails.js +3 -0
  40. package/dist/types/ContentPart.d.ts +6 -0
  41. package/dist/types/EmbeddingCallOptions.d.ts +9 -0
  42. package/dist/types/FilePart.d.ts +8 -0
  43. package/dist/types/FilePart.js +2 -0
  44. package/dist/types/Fingerprint.d.ts +21 -0
  45. package/dist/types/Fingerprint.js +3 -0
  46. package/dist/types/GenerateContent.d.ts +12 -1
  47. package/dist/types/GenerateObjectResult.d.ts +48 -0
  48. package/dist/types/GenerateObjectResult.js +2 -0
  49. package/dist/types/GenerateTextOptions.d.ts +12 -1
  50. package/dist/types/GenerateTextResult.d.ts +47 -0
  51. package/dist/types/HttpExchange.d.ts +34 -0
  52. package/dist/types/HttpExchange.js +2 -0
  53. package/dist/types/HttpRecord.d.ts +12 -0
  54. package/dist/types/HttpRecord.js +3 -0
  55. package/dist/types/ImageCallOptions.d.ts +10 -1
  56. package/dist/types/InputRecord.d.ts +16 -0
  57. package/dist/types/InputRecord.js +2 -0
  58. package/dist/types/Modality.d.ts +4 -0
  59. package/dist/types/Modality.js +3 -0
  60. package/dist/types/ModelCapabilities.d.ts +21 -0
  61. package/dist/types/ModelCapabilities.js +3 -0
  62. package/dist/types/ModelCost.d.ts +10 -0
  63. package/dist/types/ModelCost.js +3 -0
  64. package/dist/types/ModelLimits.d.ts +17 -0
  65. package/dist/types/ModelLimits.js +3 -0
  66. package/dist/types/ModelModalities.d.ts +8 -0
  67. package/dist/types/ModelModalities.js +2 -0
  68. package/dist/types/ModelSpec.d.ts +33 -0
  69. package/dist/types/ModelSpec.js +2 -0
  70. package/dist/types/ModelType.d.ts +4 -0
  71. package/dist/types/ModelType.js +3 -0
  72. package/dist/types/OutcomeRecord.d.ts +19 -0
  73. package/dist/types/OutcomeRecord.js +2 -0
  74. package/dist/types/OutcomeStatus.d.ts +4 -0
  75. package/dist/types/OutcomeStatus.js +3 -0
  76. package/dist/types/PrefixBreak.d.ts +11 -0
  77. package/dist/types/PrefixBreak.js +2 -0
  78. package/dist/types/PromptTokensDetails.d.ts +4 -0
  79. package/dist/types/PromptTokensDetails.js +3 -0
  80. package/dist/types/ProviderAuditSpec.d.ts +33 -0
  81. package/dist/types/ProviderAuditSpec.js +2 -0
  82. package/dist/types/ProviderFamily.d.ts +5 -0
  83. package/dist/types/ProviderFamily.js +3 -0
  84. package/dist/types/ProviderRecord.d.ts +30 -0
  85. package/dist/types/ProviderRecord.js +2 -0
  86. package/dist/types/RawToolCall.d.ts +16 -0
  87. package/dist/types/RawToolCall.js +2 -0
  88. package/dist/types/ReasoningMode.d.ts +4 -0
  89. package/dist/types/ReasoningMode.js +3 -0
  90. package/dist/types/ReasoningPart.d.ts +9 -0
  91. package/dist/types/ReasoningPart.js +3 -0
  92. package/dist/types/ReasoningSpec.d.ts +39 -0
  93. package/dist/types/ReasoningSpec.js +2 -0
  94. package/dist/types/ReasoningVisibility.d.ts +4 -0
  95. package/dist/types/ReasoningVisibility.js +3 -0
  96. package/dist/types/Recording.d.ts +56 -0
  97. package/dist/types/Recording.js +2 -0
  98. package/dist/types/RequestCacheHints.d.ts +9 -0
  99. package/dist/types/RequestCacheHints.js +3 -0
  100. package/dist/types/RerankingCallOptions.d.ts +9 -0
  101. package/dist/types/ResponseRecord.d.ts +13 -0
  102. package/dist/types/ResponseRecord.js +3 -0
  103. package/dist/types/RetryError.d.ts +9 -0
  104. package/dist/types/RetryError.js +2 -0
  105. package/dist/types/RetryErrorReason.d.ts +4 -0
  106. package/dist/types/RetryErrorReason.js +3 -0
  107. package/dist/types/RuntimeModel.d.ts +22 -0
  108. package/dist/types/RuntimeModel.js +3 -0
  109. package/dist/types/SearchCallOptions.d.ts +9 -0
  110. package/dist/types/SessionCall.d.ts +20 -0
  111. package/dist/types/SessionCall.js +3 -0
  112. package/dist/types/SessionChainView.d.ts +10 -0
  113. package/dist/types/SessionChainView.js +2 -0
  114. package/dist/types/SessionSource.d.ts +4 -0
  115. package/dist/types/SessionSource.js +3 -0
  116. package/dist/types/SessionStepStat.d.ts +27 -0
  117. package/dist/types/SessionStepStat.js +2 -0
  118. package/dist/types/SessionView.d.ts +16 -0
  119. package/dist/types/SessionView.js +2 -0
  120. package/dist/types/SourcePart.d.ts +9 -0
  121. package/dist/types/SourcePart.js +3 -0
  122. package/dist/types/SpeechCallOptions.d.ts +9 -0
  123. package/dist/types/StreamPart.d.ts +12 -0
  124. package/dist/types/StreamTextResultAggregated.d.ts +74 -0
  125. package/dist/types/StreamTextResultAggregated.js +2 -0
  126. package/dist/types/TimeoutConfiguration.d.ts +19 -0
  127. package/dist/types/TimeoutConfiguration.js +1 -0
  128. package/dist/types/TimingRecord.d.ts +7 -0
  129. package/dist/types/TimingRecord.js +3 -0
  130. package/dist/types/ToolCall.d.ts +16 -1
  131. package/dist/types/ToolCallRepairReply.d.ts +19 -0
  132. package/dist/types/ToolCallRepairReply.js +2 -0
  133. package/dist/types/TraceFilter.d.ts +9 -0
  134. package/dist/types/TraceFilter.js +3 -0
  135. package/dist/types/TraceRecord.d.ts +54 -0
  136. package/dist/types/TraceRecord.js +2 -0
  137. package/dist/types/TraceStats.d.ts +20 -0
  138. package/dist/types/TraceStats.js +3 -0
  139. package/dist/types/TranscriptionCallOptions.d.ts +38 -0
  140. package/dist/types/TranscriptionCallOptions.js +2 -0
  141. package/dist/types/TranscriptionRequest.d.ts +9 -0
  142. package/dist/types/TranscriptionRequest.js +3 -0
  143. package/dist/types/TranscriptionResponse.d.ts +24 -0
  144. package/dist/types/TranscriptionResponse.js +2 -0
  145. package/dist/types/TranscriptionResult.d.ts +46 -0
  146. package/dist/types/TranscriptionResult.js +2 -0
  147. package/dist/types/TranscriptionSegment.d.ts +17 -0
  148. package/dist/types/TranscriptionSegment.js +3 -0
  149. package/dist/types/TranscriptionStreamPart.d.ts +70 -0
  150. package/dist/types/TranscriptionStreamPart.js +2 -0
  151. package/dist/types/UsageSnapshot.d.ts +18 -0
  152. package/dist/types/UsageSnapshot.js +2 -0
  153. package/dist/types/Verdict.d.ts +23 -0
  154. package/dist/types/Verdict.js +2 -0
  155. package/dist/types/VerdictConfidence.d.ts +4 -0
  156. package/dist/types/VerdictConfidence.js +3 -0
  157. package/dist/types/VerdictKind.d.ts +4 -0
  158. package/dist/types/VerdictKind.js +3 -0
  159. package/dist/types/VideoCallOptions.d.ts +17 -2
  160. package/dist/types/VideoPollOptions.d.ts +13 -0
  161. package/dist/types/VideoPollOptions.js +3 -0
  162. package/dist/types/VideoResult.d.ts +1 -1
  163. package/dist/types.d.ts +71 -1
  164. package/dist/types.js +3 -3
  165. package/index.d.ts +332 -25
  166. package/index.js +77 -54
  167. package/package.json +13 -12
package/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
+ /** Fallible native return — unwraps to `T` at runtime; core failures reject/throw the registered `AimuxError` subclass, while binding faults remain napi-rs plain `Error`s. */
4
+ export type AimuxResult<T> = T
5
+ /** Stream yield — a StreamPart JSON string at runtime; failures reject `next()` with a typed error. */
6
+ export type StreamItem = string
3
7
  declare global {
4
8
  interface __NapiRsAsyncGenerator<TOwner, T, TReturn, TNext> {
5
9
  next(...[value]: [] | [TNext]): globalThis.Promise<globalThis.IteratorResult<T, TReturn | undefined>>
@@ -56,6 +60,39 @@ export declare class ImageModel {
56
60
  }
57
61
 
58
62
  export declare class Model {
63
+ /**
64
+ * Wrap this model in a cache-probe layer (RFC-0015). The returned
65
+ * model records fingerprints/verdicts on every call and exposes the
66
+ * `traceAggregate` / `traceSessionChain` / `traceExportJsonl` /
67
+ * `traceClear` queries.
68
+ */
69
+ trace(): Model
70
+ /**
71
+ * Wrap this model in a cache-probe layer with the built-in rules
72
+ * auditor (RFC-0015 §4). `strict` = strict mode (self-hosted single
73
+ * instance); `false` = shared mode (safe default).
74
+ */
75
+ traceAudited(strict: boolean): Model
76
+ /**
77
+ * Aggregated probe statistics (RFC-0015 §5.3), filtered by a JSON
78
+ * `TraceFilter` (optional). Returns a JSON `TraceStats[]` string.
79
+ */
80
+ traceAggregate(filterJson?: string | undefined | null): AimuxResult<string>
81
+ /**
82
+ * One session's chain view (RFC-0015 §5.3). Returns a JSON
83
+ * `SessionChainView` string or an error when the session is unknown.
84
+ */
85
+ traceSessionChain(sessionId: string): AimuxResult<string>
86
+ /**
87
+ * One session's per-step cache-hit trajectory (RFC-0024 §4.3). Returns
88
+ * a JSON array of `SessionStepStat` (empty when the session is unknown
89
+ * or the model is not traced).
90
+ */
91
+ traceSessionTrajectory(sessionId: string): AimuxResult<string>
92
+ /** Export all probe records as JSONL (one `TraceRecord` per line). */
93
+ traceExportJsonl(): AimuxResult<string>
94
+ /** Clear all probe records of this traced model. */
95
+ traceClear(): void
59
96
  /**
60
97
  * Generate text (non-streaming).
61
98
  *
@@ -66,6 +103,23 @@ export declare class Model {
66
103
  * Returns a JSON-serialized `GenerateTextResult`.
67
104
  */
68
105
  generateText(prompt: string, options?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
106
+ /**
107
+ * Generate a structured JSON object from the model (M12, RFC-0016).
108
+ *
109
+ * Same signature as [`Model::generate_text`]; returns a JSON-serialized
110
+ * `GenerateObjectResult`. Pass `response_format: { "Json": { ... } }`
111
+ * via `options` for schema control; the function applies JSON repair
112
+ * before parsing.
113
+ */
114
+ generateObject(prompt: string, options?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
115
+ /**
116
+ * Consume a stream to completion and return the aggregated result
117
+ * (M11, RFC-0016).
118
+ *
119
+ * Drives `streamText` to completion and returns a JSON-serialized
120
+ * `StreamTextResultAggregated` (the fully-consumed stream summary).
121
+ */
122
+ consumeStreamText(prompt: string, options?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
69
123
  /**
70
124
  * Stream text from the model.
71
125
  *
@@ -73,6 +127,55 @@ export declare class Model {
73
127
  * Use `for await (const part of model.streamText(...))` to consume.
74
128
  */
75
129
  streamText(prompt: string, options?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<AsyncGenerator<string>>
130
+ /**
131
+ * Generate text and return an OpenAI Chat Completion (non-streaming).
132
+ *
133
+ * Returns a JSON-serialized `ChatCompletion`. Works with any provider.
134
+ */
135
+ generateTextAsOpenai(prompt: string, options?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
136
+ /**
137
+ * Convert a serialized `GenerateTextResult` into a serialized
138
+ * `ChatCompletion` — the conversion half of `generateTextAsOpenai`.
139
+ *
140
+ * For repairing on the host (RFC-0035): patch the native result, then
141
+ * convert it, so the completion's tool calls are the repaired ones. This
142
+ * model only supplies the fallback model id.
143
+ */
144
+ generateTextResultAsOpenai(resultJson: string): AimuxResult<string>
145
+ /**
146
+ * Stream text as OpenAI Chat Completion chunks.
147
+ *
148
+ * Returns an `AsyncGenerator<string>` yielding `ChatCompletionChunk` JSON
149
+ * strings. Works with any provider.
150
+ */
151
+ streamTextAsOpenai(prompt: string, options?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<AsyncGenerator<string>>
152
+ }
153
+
154
+ /**
155
+ * A provider handle — created by `createProvider`, supports `listModels()`
156
+ * (runtime discovery) and `model()` (build a model from a discovered id).
157
+ *
158
+ * ```ts
159
+ * const p = await createProvider('deepseek', apiKey)
160
+ * const models = await p.listModels()
161
+ * const model = await p.model(models[0].id)
162
+ * const result = await generateText(model, 'Hello')
163
+ * ```
164
+ */
165
+ export declare class ProviderHandle {
166
+ /**
167
+ * List models available on this provider (runtime discovery via the
168
+ * provider's `/models` endpoint). Returns a JSON array of sparse
169
+ * `RuntimeModel` (id / owned_by / created) — **no community enrichment**.
170
+ * To supplement with model specs (context length, capabilities, reasoning),
171
+ * call `getModelSpecs` separately and merge in the host (RFC-0027).
172
+ */
173
+ listModels(): Promise<AimuxResult<string>>
174
+ /**
175
+ * Build a language model from a discovered model id. Returns a `Model`
176
+ * usable with `generateText` / `streamText`.
177
+ */
178
+ model(modelId: string): Promise<AimuxResult<Model>>
76
179
  }
77
180
 
78
181
  export declare class RerankingModel {
@@ -117,7 +220,7 @@ export declare class SpeechModel {
117
220
  */
118
221
  export declare class StreamTextGenerator {
119
222
 
120
- [globalThis.Symbol.asyncIterator](): globalThis.__NapiRsAsyncGenerator<StreamTextGenerator, string, void, undefined>
223
+ [globalThis.Symbol.asyncIterator](): globalThis.__NapiRsAsyncGenerator<StreamTextGenerator, StreamItem, void, undefined>
121
224
  }
122
225
 
123
226
  export declare class TranscriptionModel {
@@ -130,6 +233,37 @@ export declare class TranscriptionModel {
130
233
  generate(audioBase64: string, mediaType: string, optsJson?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
131
234
  }
132
235
 
236
+ /**
237
+ * A live streaming-transcription session (RFC-0028). Push audio chunks with
238
+ * `pushAudio`, mark end-of-audio with `inputDone`, then pull transcription
239
+ * parts with `nextPart`. Mirrors the C-ABI session shape, built natively on
240
+ * core channels.
241
+ */
242
+ export declare class TranscriptionSession {
243
+ /**
244
+ * Push one binary audio chunk. Awaits while the internal channel is
245
+ * full (backpressure).
246
+ */
247
+ pushAudio(data: Buffer): Promise<AimuxResult<undefined>>
248
+ /** Signal end-of-audio (idempotent). */
249
+ inputDone(): AimuxResult<undefined>
250
+ /**
251
+ * Pull the next transcription part (JSON string). Resolves `null` when
252
+ * the stream ended normally. Rejects on error — including a timeout
253
+ * (no part within `timeoutMs`; the session stays live, call again).
254
+ * `timeoutMs`: >0 wait at most; 0 immediate poll; negative OR omitted
255
+ * = wait indefinitely.
256
+ */
257
+ nextPart(timeoutMs?: number | undefined | null): Promise<AimuxResult<string | undefined | null>>
258
+ /**
259
+ * Terminate the session (aborts the driver). The object becomes inert;
260
+ * further `pushAudio`/`nextPart` fail. Call this promptly — GC teardown
261
+ * drops the channels (which eventually tears the driver down) but never
262
+ * fires the abort token.
263
+ */
264
+ close(): void
265
+ }
266
+
133
267
  export declare class VideoModel {
134
268
  /**
135
269
  * Generate video. `opts_json` is JSON-serialized VideoCallOptions.
@@ -139,51 +273,104 @@ export declare class VideoModel {
139
273
  generate(optsJson: string, bridge?: AbortBridge | undefined | null): Promise<string>
140
274
  }
141
275
 
276
+ /**
277
+ * Register the canonical JS error constructors for this Node environment.
278
+ *
279
+ * Keeping the constructors in the environment, rather than a process-global,
280
+ * preserves class identity and keeps Worker environments isolated.
281
+ */
282
+ export declare function __registerErrorClasses(constructors: object): void
283
+
142
284
  /** Create an Anthropic model instance. */
143
- export declare function anthropic(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
285
+ export declare function anthropic(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
144
286
 
145
287
  /** Create an Anthropic-on-AWS language model instance (API key + region). */
146
- export declare function anthropicAws(apiKey: string, region: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
288
+ export declare function anthropicAws(apiKey: string, region: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
289
+
290
+ /**
291
+ * Resolve one invalid tool call against a host's repair reply.
292
+ *
293
+ * `optsJson` is the same string the call was generated with; the tool set
294
+ * comes from it. `replyJson` is `{"type":"repaired","tool_call":{…}}`,
295
+ * `{"type":"unchanged"}`, or `{"type":"failed","message":"…"}`. Returns the
296
+ * resulting `ToolCall` JSON — valid, or invalid carrying a nested
297
+ * `ToolCallRepairError`.
298
+ *
299
+ * Options carrying no tools throw `InvalidArgumentError`: such a call is not
300
+ * repairable, and `toolCallRepairContext` already said so by returning
301
+ * `"null"`.
302
+ */
303
+ export declare function applyToolCallRepair(toolCallJson: string, optsJson: string | undefined | null, replyJson: string): AimuxResult<string>
304
+
305
+ /**
306
+ * Apply a repair reply to a serialized `GenerateTextResult` or
307
+ * `GenerateObjectResult`, rewriting both `tool_calls` and the matching
308
+ * `response_messages` tool-call part. `optsJson` is the same string the call
309
+ * was generated with.
310
+ *
311
+ * The OpenAI-shaped result has no equivalent: it carries no `invalid` /
312
+ * `error`, so repair is driven from the native result, which
313
+ * `Model.generateTextResultAsOpenai` then converts.
314
+ */
315
+ export declare function applyToolCallRepairToResult(resultJson: string, optsJson: string | undefined | null, toolCallId: string, replyJson: string): AimuxResult<string>
147
316
 
148
317
  /**
149
318
  * Create an Azure OpenAI language model instance (API key + resource name).
150
319
  *
151
320
  * The deployment name is passed as `model_id`; `api_version` is optional.
152
321
  */
153
- export declare function azure(apiKey: string, resourceName: string, deployment: string, apiVersion?: string | undefined | null, config?: string | ProviderConfig | undefined | null): Promise<Model>
322
+ export declare function azure(apiKey: string, resourceName: string, deployment: string, apiVersion?: string | undefined | null, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
154
323
 
155
324
  /** Create a Bedrock language model instance (AWS SigV4 credentials). */
156
- export declare function bedrock(accessKeyId: string, secretAccessKey: string, region: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
325
+ export declare function bedrock(accessKeyId: string, secretAccessKey: string, region: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
157
326
 
158
327
  /** Create a Cohere language model instance. */
159
- export declare function cohere(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
328
+ export declare function cohere(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
160
329
 
161
330
  /** Create a Cohere embedding model instance. */
162
- export declare function cohereEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<EmbeddingModel>
331
+ export declare function cohereEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<EmbeddingModel>>
163
332
 
164
333
  /** Create a Cohere reranking model instance. */
165
- export declare function cohereReranking(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<RerankingModel>
334
+ export declare function cohereReranking(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<RerankingModel>>
335
+
336
+ /**
337
+ * Create a **provider handle** (RFC-0027) for a registry-backed provider.
338
+ *
339
+ * Unlike `provider()` (which binds to a single model_id), this returns a
340
+ * `ProviderHandle` that supports `listModels()` and `model()`.
341
+ *
342
+ * `api_key` may be empty/null to read the provider's env var from the
343
+ * registry entry.
344
+ */
345
+ export declare function createProvider(name: string, apiKey?: string | undefined | null, config?: ProviderConfig | undefined | null): Promise<AimuxResult<ProviderHandle>>
166
346
 
167
347
  /** Create a DeepSeek model instance (registry-backed since RFC-0017 phase 4). */
168
- export declare function deepseek(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
348
+ export declare function deepseek(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
349
+
350
+ /**
351
+ * Fetch the community model catalogue (anya2a). Returns a JSON-serialized
352
+ * `Catalogue` (provider → model_id → ModelSpec). Thin fetch — no caching.
353
+ * `source_url` may be null for the default endpoint.
354
+ */
355
+ export declare function getModelSpecs(sourceUrl?: string | undefined | null): Promise<AimuxResult<string>>
169
356
 
170
357
  /**
171
358
  * Create a Google Gemini language model instance.
172
359
  *
173
360
  * Google speaks the native `generateContent` protocol (not OpenAI-compatible),
174
361
  * so it is **not** registry-backed — `provider("google", ...)` fails with
175
- * `UnknownProvider`. This factory is the only entry point.
362
+ * `NoSuchProvider`. This factory is the only entry point.
176
363
  */
177
- export declare function google(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
364
+ export declare function google(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
178
365
 
179
366
  /** Create a Google embedding model instance. */
180
- export declare function googleEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<EmbeddingModel>
367
+ export declare function googleEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<EmbeddingModel>>
181
368
 
182
369
  /** Create a Google image model instance. */
183
- export declare function googleImage(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<ImageModel>
370
+ export declare function googleImage(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<ImageModel>>
184
371
 
185
372
  /** Create a Google video model instance. */
186
- export declare function googleVideo(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<VideoModel>
373
+ export declare function googleVideo(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<VideoModel>>
187
374
 
188
375
  /**
189
376
  * 初始化全局日志(RFC-0014)。幂等:多次调用无副作用;宿主已自建
@@ -193,33 +380,89 @@ export declare function googleVideo(apiKey: string, modelId: string, baseUrl?: s
193
380
  */
194
381
  export declare function initLogging(level: string): void
195
382
 
383
+ /**
384
+ * Set the global proxy configuration (M6, RFC-0016). Must be called before
385
+ * the first `generateText` / `streamText` call; a no-op if the shared HTTP
386
+ * client is already initialised (the shared client is lazily built on first
387
+ * use and locked for the process lifetime).
388
+ *
389
+ * `configJson` shape: `{ "http_url": "...", "https_url": "...", "all_url":
390
+ * "...", "no_proxy": "..." }` (all fields optional; omitting all is equivalent
391
+ * to relying on the `HTTP_PROXY` / `HTTPS_PROXY` / `ALL_PROXY` / `NO_PROXY`
392
+ * env vars).
393
+ *
394
+ * Throws on invalid JSON.
395
+ */
396
+ export declare function initProxy(configJson: string): AimuxResult<undefined>
397
+
398
+ /**
399
+ * 启动录制(RFC-0023 P1/P2):把完整 `Recording` 写 JSONL 到 `{dir}/recordings.jsonl`
400
+ * (目录自动创建)。录制 **opt-in**;再次调用(不同 dir)替换 recorder。
401
+ * Throws `RecordingError` (`code` = `Init` / `OpenFile` / `Spawn`) when the
402
+ * recorder cannot be set up; the previous recorder, if any, stays in place.
403
+ */
404
+ export declare function initRecording(dir: string): AimuxResult<undefined>
405
+
406
+ /**
407
+ * 启动内存有界录制(RFC-0023 P6):`RingRecorder`,FIFO 淘汰,丢弃计数可查。
408
+ *
409
+ * `cap` 可省略:省略时使用库默认容量(等价于 FFI `aimux_init_recording_ring_default()`;
410
+ * 本绑定直接依赖 aimux-core 而非 aimux-ffi,故调用等价 core API `RingRecorder::default()`)。
411
+ * 显式传 `cap == 0` 抛错(与其余语言一致),`cap > 0` 启动指定容量的有界 ring。
412
+ */
413
+ export declare function initRecordingRing(cap?: number | undefined | null): AimuxResult<undefined>
414
+
415
+ /**
416
+ * Enable/disable the global session inferer (RFC-0024, opt-in, off by
417
+ * default). Explicit `sessionId` values always win regardless of this.
418
+ */
419
+ export declare function initSessionInfer(enabled: boolean): void
420
+
421
+ /**
422
+ * Register the global session store (RFC-0024). Replaces any previous one.
423
+ * Until called, calls are not grouped and the session query functions return
424
+ * empty results.
425
+ */
426
+ export declare function initSessionStore(): void
427
+
428
+ /** Query: all known sessions (RFC-0024), as a JSON-serialized `SessionView[]`. */
429
+ export declare function listSessions(): AimuxResult<string>
430
+
196
431
  /** Create a Mistral language model instance. */
197
- export declare function mistral(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
432
+ export declare function mistral(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
433
+
434
+ export declare function moa(references: Array<Model>, aggregator: Model, configJson?: string | undefined | null): AimuxResult<Model>
435
+
436
+ /**
437
+ * 从录制 JSONL 创建 mock 回放模型(RFC-0023 P3):按输入匹配录制响应,
438
+ * **不发真实 API**。返回的 `Model` 可用于 `generateText` / `streamText`。
439
+ */
440
+ export declare function mockReplay(recordingsJsonl: string): AimuxResult<Model>
198
441
 
199
442
  /** Create an OpenAI model instance. */
200
- export declare function openai(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
443
+ export declare function openai(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
201
444
 
202
445
  /** Create an OpenAI embedding model instance. */
203
- export declare function openaiEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<EmbeddingModel>
446
+ export declare function openaiEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<EmbeddingModel>>
204
447
 
205
448
  /** Create OpenAI files manager. */
206
- export declare function openaiFiles(apiKey: string, baseUrl?: string | undefined | null): Promise<Files>
449
+ export declare function openaiFiles(apiKey: string, baseUrl?: string | undefined | null): Promise<AimuxResult<Files>>
207
450
 
208
451
  /** Create an OpenAI image model instance. */
209
- export declare function openaiImage(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<ImageModel>
452
+ export declare function openaiImage(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<ImageModel>>
210
453
 
211
454
  /** Create an OpenAI speech (TTS) model instance. */
212
- export declare function openaiSpeech(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<SpeechModel>
455
+ export declare function openaiSpeech(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<SpeechModel>>
213
456
 
214
457
  /** Create an OpenAI transcription model instance. */
215
- export declare function openaiTranscription(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<TranscriptionModel>
458
+ export declare function openaiTranscription(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<TranscriptionModel>>
216
459
 
217
460
  /**
218
461
  * Create a language model from the built-in registry by provider name
219
462
  * (RFC-0017 phase 4). `api_key` may be empty/null to read the provider's env
220
463
  * var from the registry entry.
221
464
  */
222
- export declare function provider(name: string, apiKey: string | undefined | null, modelId: string, config?: ProviderConfig | undefined | null): Promise<Model>
465
+ export declare function provider(name: string, apiKey: string | undefined | null, modelId: string, config?: ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
223
466
 
224
467
  /**
225
468
  * Optional provider configuration accepted by factory functions.
@@ -251,11 +494,75 @@ export interface ProviderConfig {
251
494
  bodyOverrides?: string
252
495
  }
253
496
 
497
+ /** 刷盘全局 recorder(阻塞至 JSONL 落盘;ring 模式为 no-op)。 */
498
+ export declare function recordingFlush(): void
499
+
500
+ /** 停止录制:全局 recorder = None(新调用不再录制)。 */
501
+ export declare function recordingStop(): void
502
+
503
+ /**
504
+ * Flush the global recorder and **report write failures**: throws
505
+ * `RecordingError` (`code` = `WriterGone` / `FlushTimeout` / `Write`) when the
506
+ * data could not be confirmed on disk. `RecordingError` is its own class,
507
+ * not an `AimuxError`. Resolves normally when nothing is recording. The
508
+ * legacy `recordingFlush` stays and never reports.
509
+ */
510
+ export declare function recordingTryFlush(): AimuxResult<undefined>
511
+
512
+ /**
513
+ * Register external OpenAI-compatible providers from a JSON config string
514
+ * (RFC-0020). Entries override same-named built-ins or add new ones.
515
+ *
516
+ * `configJson` shape: `{ "providers": [ { "name": "...", "base_url": "...", ... } ] }`.
517
+ * Malformed JSON text throws a plain `Error` (napi `InvalidArg`); a
518
+ * well-formed document the registry rejects (bad base_url scheme, empty
519
+ * name, unsupported protocol, wrong shape) throws `InvalidArgumentError`.
520
+ */
521
+ export declare function registerProviders(configJson: string): AimuxResult<undefined>
522
+
523
+ export declare function router(models: Array<Model>, configJson?: string | undefined | null): AimuxResult<Model>
524
+
525
+ /**
526
+ * Query: all calls of a session (RFC-0024), as a JSON-serialized
527
+ * `SessionCall[]` (ordered by step). Empty array if the session is unknown
528
+ * or no store is registered.
529
+ */
530
+ export declare function sessionCalls(sessionId: string): AimuxResult<string>
531
+
532
+ /**
533
+ * Start a streaming transcription session. `opts_json` (optional):
534
+ * `{ "input_audio_format": {"format_type","rate"}, "provider_options",
535
+ * "headers", "include_raw_chunks" }`. `bridge` — optional AbortSignal; firing
536
+ * it aborts the session. The returned parts are JSON-serialized
537
+ * `TranscriptionStreamPart`s.
538
+ */
539
+ export declare function startTranscriptionSession(model: TranscriptionModel, optsJson?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<AimuxResult<TranscriptionSession>>
540
+
254
541
  /** Create a Tavily search model instance. */
255
- export declare function tavilySearch(apiKey: string, baseUrl?: string | undefined | null): Promise<SearchModel>
542
+ export declare function tavilySearch(apiKey: string, baseUrl?: string | undefined | null): Promise<AimuxResult<SearchModel>>
543
+
544
+ /**
545
+ * Build the repair argument for one invalid tool call.
546
+ *
547
+ * `toolCallJson` is a `GenerateTextResult.tool_calls` entry with
548
+ * `invalid: true`. `prompt` and `optsJson` are **the same two strings the
549
+ * call was generated with** (`generateText` / `streamText`); messages,
550
+ * instructions, and the tool set are derived from them here, so no caller
551
+ * repeats that derivation.
552
+ *
553
+ * Returns `{tool_call, error, input_schema, tools, messages, instructions}`
554
+ * — the AI SDK `repairToolCall` argument, with `tool_call.input` the
555
+ * provider's raw argument text — or the JSON literal `"null"` when the
556
+ * options carried no tools: as in the AI SDK, a call made without a tool set
557
+ * is never repaired, and the caller skips it. `"null"` is a success.
558
+ *
559
+ * Pure and synchronous: no model, no network. Throws `InvalidArgumentError`
560
+ * when the call is not an invalid one.
561
+ */
562
+ export declare function toolCallRepairContext(toolCallJson: string, prompt: string, optsJson?: string | undefined | null): AimuxResult<string>
256
563
 
257
564
  /** Create a Vertex AI language model instance (GCP bearer token). */
258
- export declare function vertex(accessToken: string, project: string, location: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
565
+ export declare function vertex(accessToken: string, project: string, location: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
259
566
 
260
567
  /** Create an xAI language model instance. */
261
- export declare function xai(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
568
+ export declare function xai(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>