@arcships/aimux 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/LICENSE +21 -0
  2. package/dist/error.d.ts +71 -0
  3. package/dist/error.js +173 -0
  4. package/dist/index.d.ts +132 -5
  5. package/dist/index.js +282 -24
  6. package/dist/types/AiMuxError.d.ts +29 -15
  7. package/dist/types/AiMuxError.js +0 -1
  8. package/dist/types/ApiCallError.d.ts +65 -0
  9. package/dist/types/ApiCallError.js +3 -0
  10. package/dist/types/BreakKind.d.ts +1 -0
  11. package/dist/types/BreakKind.js +3 -0
  12. package/dist/types/CallOptions.d.ts +27 -1
  13. package/dist/types/CatalogueSource.d.ts +4 -0
  14. package/dist/types/CatalogueSource.js +3 -0
  15. package/dist/types/ChatCompletion.d.ts +16 -0
  16. package/dist/types/ChatCompletion.js +2 -0
  17. package/dist/types/ChatCompletionChoice.d.ts +8 -0
  18. package/dist/types/ChatCompletionChoice.js +2 -0
  19. package/dist/types/ChatCompletionChunk.d.ts +15 -0
  20. package/dist/types/ChatCompletionChunk.js +2 -0
  21. package/dist/types/ChatCompletionChunkChoice.d.ts +8 -0
  22. package/dist/types/ChatCompletionChunkChoice.js +2 -0
  23. package/dist/types/ChatCompletionChunkFunction.d.ts +4 -0
  24. package/dist/types/ChatCompletionChunkFunction.js +3 -0
  25. package/dist/types/ChatCompletionChunkToolCall.d.ts +7 -0
  26. package/dist/types/ChatCompletionChunkToolCall.js +2 -0
  27. package/dist/types/ChatCompletionDelta.d.ts +7 -0
  28. package/dist/types/ChatCompletionDelta.js +2 -0
  29. package/dist/types/ChatCompletionFunction.d.ts +4 -0
  30. package/dist/types/ChatCompletionFunction.js +3 -0
  31. package/dist/types/ChatCompletionMessage.d.ts +9 -0
  32. package/dist/types/ChatCompletionMessage.js +2 -0
  33. package/dist/types/ChatCompletionToolCall.d.ts +6 -0
  34. package/dist/types/ChatCompletionToolCall.js +2 -0
  35. package/dist/types/ChatCompletionUsage.d.ts +9 -0
  36. package/dist/types/ChatCompletionUsage.js +2 -0
  37. package/dist/types/CompletionTokensDetails.d.ts +3 -0
  38. package/dist/types/CompletionTokensDetails.js +3 -0
  39. package/dist/types/FilePart.d.ts +8 -0
  40. package/dist/types/FilePart.js +2 -0
  41. package/dist/types/Fingerprint.d.ts +21 -0
  42. package/dist/types/Fingerprint.js +3 -0
  43. package/dist/types/GenerateObjectResult.d.ts +48 -0
  44. package/dist/types/GenerateObjectResult.js +2 -0
  45. package/dist/types/GenerateTextOptions.d.ts +12 -1
  46. package/dist/types/GenerateTextResult.d.ts +47 -0
  47. package/dist/types/HttpExchange.d.ts +23 -0
  48. package/dist/types/HttpExchange.js +2 -0
  49. package/dist/types/HttpRecord.d.ts +12 -0
  50. package/dist/types/HttpRecord.js +3 -0
  51. package/dist/types/ImageCallOptions.d.ts +1 -1
  52. package/dist/types/InputRecord.d.ts +16 -0
  53. package/dist/types/InputRecord.js +2 -0
  54. package/dist/types/Modality.d.ts +4 -0
  55. package/dist/types/Modality.js +3 -0
  56. package/dist/types/ModelCapabilities.d.ts +21 -0
  57. package/dist/types/ModelCapabilities.js +3 -0
  58. package/dist/types/ModelCost.d.ts +10 -0
  59. package/dist/types/ModelCost.js +3 -0
  60. package/dist/types/ModelLimits.d.ts +17 -0
  61. package/dist/types/ModelLimits.js +3 -0
  62. package/dist/types/ModelModalities.d.ts +8 -0
  63. package/dist/types/ModelModalities.js +2 -0
  64. package/dist/types/ModelSpec.d.ts +33 -0
  65. package/dist/types/ModelSpec.js +2 -0
  66. package/dist/types/ModelType.d.ts +4 -0
  67. package/dist/types/ModelType.js +3 -0
  68. package/dist/types/OutcomeRecord.d.ts +14 -0
  69. package/dist/types/OutcomeRecord.js +2 -0
  70. package/dist/types/OutcomeStatus.d.ts +4 -0
  71. package/dist/types/OutcomeStatus.js +3 -0
  72. package/dist/types/PrefixBreak.d.ts +11 -0
  73. package/dist/types/PrefixBreak.js +2 -0
  74. package/dist/types/PromptTokensDetails.d.ts +4 -0
  75. package/dist/types/PromptTokensDetails.js +3 -0
  76. package/dist/types/ProviderAuditSpec.d.ts +33 -0
  77. package/dist/types/ProviderAuditSpec.js +2 -0
  78. package/dist/types/ProviderFamily.d.ts +5 -0
  79. package/dist/types/ProviderFamily.js +3 -0
  80. package/dist/types/ProviderName.d.ts +1 -0
  81. package/dist/types/ProviderName.js +1 -0
  82. package/dist/types/ProviderRecord.d.ts +30 -0
  83. package/dist/types/ProviderRecord.js +2 -0
  84. package/dist/types/ReasoningMode.d.ts +4 -0
  85. package/dist/types/ReasoningMode.js +3 -0
  86. package/dist/types/ReasoningPart.d.ts +9 -0
  87. package/dist/types/ReasoningPart.js +3 -0
  88. package/dist/types/ReasoningSpec.d.ts +39 -0
  89. package/dist/types/ReasoningSpec.js +2 -0
  90. package/dist/types/ReasoningVisibility.d.ts +4 -0
  91. package/dist/types/ReasoningVisibility.js +3 -0
  92. package/dist/types/Recording.d.ts +56 -0
  93. package/dist/types/Recording.js +2 -0
  94. package/dist/types/RequestCacheHints.d.ts +9 -0
  95. package/dist/types/RequestCacheHints.js +3 -0
  96. package/dist/types/ResponseRecord.d.ts +13 -0
  97. package/dist/types/ResponseRecord.js +3 -0
  98. package/dist/types/RuntimeModel.d.ts +22 -0
  99. package/dist/types/RuntimeModel.js +3 -0
  100. package/dist/types/SessionCall.d.ts +20 -0
  101. package/dist/types/SessionCall.js +3 -0
  102. package/dist/types/SessionChainView.d.ts +10 -0
  103. package/dist/types/SessionChainView.js +2 -0
  104. package/dist/types/SessionSource.d.ts +4 -0
  105. package/dist/types/SessionSource.js +3 -0
  106. package/dist/types/SessionStepStat.d.ts +27 -0
  107. package/dist/types/SessionStepStat.js +2 -0
  108. package/dist/types/SessionView.d.ts +16 -0
  109. package/dist/types/SessionView.js +2 -0
  110. package/dist/types/SourcePart.d.ts +9 -0
  111. package/dist/types/SourcePart.js +3 -0
  112. package/dist/types/StreamTextResultAggregated.d.ts +74 -0
  113. package/dist/types/StreamTextResultAggregated.js +2 -0
  114. package/dist/types/TimeoutConfiguration.d.ts +10 -0
  115. package/dist/types/TimeoutConfiguration.js +1 -0
  116. package/dist/types/TimingRecord.d.ts +7 -0
  117. package/dist/types/TimingRecord.js +3 -0
  118. package/dist/types/TraceFilter.d.ts +9 -0
  119. package/dist/types/TraceFilter.js +3 -0
  120. package/dist/types/TraceRecord.d.ts +54 -0
  121. package/dist/types/TraceRecord.js +2 -0
  122. package/dist/types/TraceStats.d.ts +20 -0
  123. package/dist/types/TraceStats.js +3 -0
  124. package/dist/types/TranscriptionCallOptions.d.ts +29 -0
  125. package/dist/types/TranscriptionCallOptions.js +2 -0
  126. package/dist/types/TranscriptionRequest.d.ts +9 -0
  127. package/dist/types/TranscriptionRequest.js +3 -0
  128. package/dist/types/TranscriptionResponse.d.ts +24 -0
  129. package/dist/types/TranscriptionResponse.js +2 -0
  130. package/dist/types/TranscriptionResult.d.ts +46 -0
  131. package/dist/types/TranscriptionResult.js +2 -0
  132. package/dist/types/TranscriptionSegment.d.ts +17 -0
  133. package/dist/types/TranscriptionSegment.js +3 -0
  134. package/dist/types/TranscriptionStreamPart.d.ts +70 -0
  135. package/dist/types/TranscriptionStreamPart.js +2 -0
  136. package/dist/types/UsageSnapshot.d.ts +18 -0
  137. package/dist/types/UsageSnapshot.js +2 -0
  138. package/dist/types/Verdict.d.ts +23 -0
  139. package/dist/types/Verdict.js +2 -0
  140. package/dist/types/VerdictConfidence.d.ts +4 -0
  141. package/dist/types/VerdictConfidence.js +3 -0
  142. package/dist/types/VerdictKind.d.ts +4 -0
  143. package/dist/types/VerdictKind.js +3 -0
  144. package/dist/types/VideoCallOptions.d.ts +1 -1
  145. package/dist/types.d.ts +66 -1
  146. package/dist/types.js +3 -3
  147. package/index.d.ts +322 -53
  148. package/index.js +81 -54
  149. package/package.json +9 -8
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; failures reject/throw a structured error (see src/error.ts). */
4
+ export type AimuxResult<T> = T
5
+ /** Stream yield — a StreamPart JSON string at runtime; failures reject `next()` with a structured 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>>
@@ -9,6 +13,25 @@ declare global {
9
13
  }
10
14
  }
11
15
 
16
+ /**
17
+ * A bridge from a JS `AbortSignal` to the core's runtime cancellation.
18
+ *
19
+ * napi's own `AbortSignal` is not `Send` (it holds `Rc`), so it cannot be a
20
+ * parameter of an async napi method. This class is created synchronously
21
+ * (registering the abort callback on the JS thread) and then passed to
22
+ * `generateText` / `streamText` — it only holds an `Arc` and is `Send`.
23
+ *
24
+ * ```ts
25
+ * const bridge = signal ? new AbortBridge(signal) : undefined
26
+ * await model.generateText(prompt, options, bridge)
27
+ * ```
28
+ */
29
+ export declare class AbortBridge {
30
+ constructor(signal: AbortSignal)
31
+ /** Returns `true` once the underlying JS signal has been aborted. */
32
+ aborted(): boolean
33
+ }
34
+
12
35
  export declare class EmbeddingModel {
13
36
  /**
14
37
  * Generate embeddings. `values_json` is a JSON array of strings.
@@ -30,31 +53,73 @@ export declare class Files {
30
53
  export declare class ImageModel {
31
54
  /**
32
55
  * Generate images. `opts_json` is JSON-serialized ImageCallOptions.
33
- * Returns JSON-serialized ImageResult (images as base64 in JSON).
56
+ * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
57
+ * the call. Returns JSON-serialized ImageResult (images as base64 in JSON).
34
58
  */
35
59
  generate(optsJson: string, bridge?: AbortBridge | undefined | null): Promise<string>
36
60
  }
37
61
 
38
- export declare class AbortBridge {
62
+ export declare class Model {
39
63
  /**
40
- * Bridge a JS `AbortSignal` to the core's runtime cancellation.
41
- * Pass the result to `Model.generateText` / `Model.streamText`.
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.
42
68
  */
43
- constructor(signal: AbortSignal)
44
- /** Returns `true` once the underlying JS signal has been aborted. */
45
- aborted(): boolean
46
- }
47
-
48
- export declare class Model {
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
49
96
  /**
50
97
  * Generate text (non-streaming).
51
98
  *
52
99
  * `prompt` — a JSON string: bare prompt (`"text"` or `[{...}]`) or `{"prompt": ...}`.
53
100
  * `options` — optional JSON-serialized `GenerateTextOptions`.
54
- * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels the call.
101
+ * `bridge` — optional `AbortBridge` (wrap a JS `AbortSignal` in one);
102
+ * aborting the signal cancels the call.
55
103
  * Returns a JSON-serialized `GenerateTextResult`.
56
104
  */
57
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>
58
123
  /**
59
124
  * Stream text from the model.
60
125
  *
@@ -62,13 +127,54 @@ export declare class Model {
62
127
  * Use `for await (const part of model.streamText(...))` to consume.
63
128
  */
64
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
+ * Stream text as OpenAI Chat Completion chunks.
138
+ *
139
+ * Returns an `AsyncGenerator<string>` yielding `ChatCompletionChunk` JSON
140
+ * strings. Works with any provider.
141
+ */
142
+ streamTextAsOpenai(prompt: string, options?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<AsyncGenerator<string>>
143
+ }
144
+
145
+ /**
146
+ * A provider handle — created by `createProvider`, supports `listModels()`
147
+ * (runtime discovery) and `model()` (build a model from a discovered id).
148
+ *
149
+ * ```ts
150
+ * const p = await createProvider('deepseek', apiKey)
151
+ * const models = await p.listModels()
152
+ * const model = await p.model(models[0].id)
153
+ * const result = await generateText(model, 'Hello')
154
+ * ```
155
+ */
156
+ export declare class ProviderHandle {
157
+ /**
158
+ * List models available on this provider (runtime discovery via the
159
+ * provider's `/models` endpoint). Returns a JSON array of sparse
160
+ * `RuntimeModel` (id / owned_by / created) — **no community enrichment**.
161
+ * To supplement with model specs (context length, capabilities, reasoning),
162
+ * call `getModelSpecs` separately and merge in the host (RFC-0027).
163
+ */
164
+ listModels(): Promise<AimuxResult<string>>
165
+ /**
166
+ * Build a language model from a discovered model id. Returns a `Model`
167
+ * usable with `generateText` / `streamText`.
168
+ */
169
+ model(modelId: string): Promise<AimuxResult<Model>>
65
170
  }
66
171
 
67
172
  export declare class RerankingModel {
68
173
  /**
69
174
  * Rerank documents. `query` is the search query, `docs_json` is a JSON
70
175
  * array of documents, `opts_json` is optional JSON options.
71
- * Returns JSON-serialized RerankingResult.
176
+ * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
177
+ * the call. Returns JSON-serialized RerankingResult.
72
178
  */
73
179
  rerank(query: string, docsJson: string, optsJson?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
74
180
  }
@@ -76,7 +182,8 @@ export declare class RerankingModel {
76
182
  export declare class SearchModel {
77
183
  /**
78
184
  * Search. `query` is the search query, `opts_json` is optional JSON options.
79
- * Returns JSON-serialized SearchResult.
185
+ * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
186
+ * the call. Returns JSON-serialized SearchResult.
80
187
  */
81
188
  search(query: string, optsJson?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
82
189
  }
@@ -84,7 +191,8 @@ export declare class SearchModel {
84
191
  export declare class SpeechModel {
85
192
  /**
86
193
  * Generate speech audio. `opts_json` is JSON-serialized SpeechCallOptions.
87
- * Returns JSON-serialized SpeechResult (audio as base64 in JSON).
194
+ * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
195
+ * the call. Returns JSON-serialized SpeechResult (audio as base64 in JSON).
88
196
  */
89
197
  generate(optsJson: string, bridge?: AbortBridge | undefined | null): Promise<string>
90
198
  }
@@ -103,91 +211,212 @@ export declare class SpeechModel {
103
211
  */
104
212
  export declare class StreamTextGenerator {
105
213
 
106
- [globalThis.Symbol.asyncIterator](): globalThis.__NapiRsAsyncGenerator<StreamTextGenerator, string, void, undefined>
214
+ [globalThis.Symbol.asyncIterator](): globalThis.__NapiRsAsyncGenerator<StreamTextGenerator, StreamItem, void, undefined>
107
215
  }
108
216
 
109
217
  export declare class TranscriptionModel {
110
218
  /**
111
219
  * Transcribe audio. `audio_base64` is base64-encoded audio data.
112
220
  * `media_type` is e.g. "audio/mp3". `opts_json` is optional JSON options.
113
- * Returns JSON-serialized TranscriptionResult.
221
+ * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
222
+ * the call. Returns JSON-serialized TranscriptionResult.
114
223
  */
115
224
  generate(audioBase64: string, mediaType: string, optsJson?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
116
225
  }
117
226
 
227
+ /**
228
+ * A live streaming-transcription session (RFC-0028). Push audio chunks with
229
+ * `pushAudio`, mark end-of-audio with `inputDone`, then pull transcription
230
+ * parts with `nextPart`. Mirrors the C-ABI session shape, built natively on
231
+ * core channels.
232
+ */
233
+ export declare class TranscriptionSession {
234
+ /**
235
+ * Push one binary audio chunk. Awaits while the internal channel is
236
+ * full (backpressure).
237
+ */
238
+ pushAudio(data: Buffer): Promise<void>
239
+ /** Signal end-of-audio (idempotent). */
240
+ inputDone(): void
241
+ /**
242
+ * Pull the next transcription part (JSON string). Resolves `null` when
243
+ * the stream ended normally. Rejects on error — including a timeout
244
+ * (no part within `timeoutMs`; the session stays live, call again).
245
+ * `timeoutMs`: >0 wait at most; 0 immediate poll; negative OR omitted
246
+ * = wait indefinitely.
247
+ */
248
+ nextPart(timeoutMs?: number | undefined | null): Promise<AimuxResult<string | undefined | null>>
249
+ /**
250
+ * Terminate the session (aborts the driver). The object becomes inert;
251
+ * further `pushAudio`/`nextPart` fail. Call this promptly — GC teardown
252
+ * drops the channels (which eventually tears the driver down) but never
253
+ * fires the abort token.
254
+ */
255
+ close(): void
256
+ }
257
+
118
258
  export declare class VideoModel {
119
259
  /**
120
260
  * Generate video. `opts_json` is JSON-serialized VideoCallOptions.
121
- * Returns JSON-serialized VideoResult (typically contains a URL).
261
+ * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
262
+ * the call. Returns JSON-serialized VideoResult (typically contains a URL).
122
263
  */
123
264
  generate(optsJson: string, bridge?: AbortBridge | undefined | null): Promise<string>
124
265
  }
125
266
 
126
267
  /** Create an Anthropic model instance. */
127
- export declare function anthropic(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
128
-
129
- /** Create an Anthropic-on-AWS model instance (API key + region). */
130
- export declare function anthropicAws(apiKey: string, region: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
131
-
132
- /** Create an Azure OpenAI model instance (API key + resource name). */
133
- export declare function azure(apiKey: string, resourceName: string, deployment: string, apiVersion?: string | undefined | null, config?: string | ProviderConfig | undefined | null): Promise<Model>
268
+ export declare function anthropic(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
134
269
 
135
- /** Create a Bedrock model instance (AWS SigV4 credentials). */
136
- export declare function bedrock(accessKeyId: string, secretAccessKey: string, region: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
270
+ /** Create an Anthropic-on-AWS language model instance (API key + region). */
271
+ export declare function anthropicAws(apiKey: string, region: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
137
272
 
138
- /** Create a Cohere model instance. */
139
- export declare function cohere(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
140
-
141
- /** Create a Mistral model instance. */
142
- export declare function mistral(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
273
+ /**
274
+ * Create an Azure OpenAI language model instance (API key + resource name).
275
+ *
276
+ * The deployment name is passed as `model_id`; `api_version` is optional.
277
+ */
278
+ export declare function azure(apiKey: string, resourceName: string, deployment: string, apiVersion?: string | undefined | null, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
143
279
 
144
- /** Create a Vertex AI model instance (GCP bearer token). */
145
- export declare function vertex(accessToken: string, project: string, location: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
280
+ /** Create a Bedrock language model instance (AWS SigV4 credentials). */
281
+ export declare function bedrock(accessKeyId: string, secretAccessKey: string, region: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
146
282
 
147
- /** Create an xAI model instance. */
148
- export declare function xai(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
283
+ /** Create a Cohere language model instance. */
284
+ export declare function cohere(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
149
285
 
150
286
  /** Create a Cohere embedding model instance. */
151
- export declare function cohereEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<EmbeddingModel>
287
+ export declare function cohereEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<EmbeddingModel>>
152
288
 
153
289
  /** Create a Cohere reranking model instance. */
154
- export declare function cohereReranking(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<RerankingModel>
290
+ export declare function cohereReranking(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<RerankingModel>>
155
291
 
156
- /** Create a DeepSeek model instance. */
157
- export declare function deepseek(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
292
+ /**
293
+ * Create a **provider handle** (RFC-0027) for a registry-backed provider.
294
+ *
295
+ * Unlike `provider()` (which binds to a single model_id), this returns a
296
+ * `ProviderHandle` that supports `listModels()` and `model()`.
297
+ *
298
+ * `api_key` may be empty/null to read the provider's env var from the
299
+ * registry entry.
300
+ */
301
+ export declare function createProvider(name: string, apiKey?: string | undefined | null, config?: ProviderConfig | undefined | null): Promise<AimuxResult<ProviderHandle>>
158
302
 
159
- /** Create a Google Gemini language model instance (native generateContent protocol — not registry-backed). */
160
- export declare function google(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
303
+ /** Create a DeepSeek model instance (registry-backed since RFC-0017 phase 4). */
304
+ export declare function deepseek(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
161
305
 
162
- /** Create a language model from the built-in registry by provider name (RFC-0017 phase 4). */
163
- export declare function provider(name: string, apiKey?: string | undefined | null, modelId: string, config?: ProviderConfig | undefined | null): Promise<Model>
306
+ /**
307
+ * Fetch the community model catalogue (anya2a). Returns a JSON-serialized
308
+ * `Catalogue` (provider → model_id → ModelSpec). Thin fetch — no caching.
309
+ * `source_url` may be null for the default endpoint.
310
+ */
311
+ export declare function getModelSpecs(sourceUrl?: string | undefined | null): Promise<AimuxResult<string>>
312
+
313
+ /**
314
+ * Create a Google Gemini language model instance.
315
+ *
316
+ * Google speaks the native `generateContent` protocol (not OpenAI-compatible),
317
+ * so it is **not** registry-backed — `provider("google", ...)` fails with
318
+ * `NoSuchProvider`. This factory is the only entry point.
319
+ */
320
+ export declare function google(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
164
321
 
165
322
  /** Create a Google embedding model instance. */
166
- export declare function googleEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<EmbeddingModel>
323
+ export declare function googleEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<EmbeddingModel>>
167
324
 
168
325
  /** Create a Google image model instance. */
169
- export declare function googleImage(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<ImageModel>
326
+ export declare function googleImage(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<ImageModel>>
170
327
 
171
328
  /** Create a Google video model instance. */
172
- export declare function googleVideo(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<VideoModel>
329
+ export declare function googleVideo(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<VideoModel>>
330
+
331
+ /**
332
+ * 初始化全局日志(RFC-0014)。幂等:多次调用无副作用;宿主已自建
333
+ * subscriber 时 no-op。级别:off|error|warn|info|debug|trace(空串回退
334
+ * warn)。`AIMUX_LOG` / `AIMUX_LOG_LEVEL` 环境变量优先级更高。
335
+ * 日志输出到 stderr。
336
+ */
337
+ export declare function initLogging(level: string): void
338
+
339
+ /**
340
+ * Set the global proxy configuration (M6, RFC-0016). Must be called before
341
+ * the first `generateText` / `streamText` call; a no-op if the shared HTTP
342
+ * client is already initialised (the shared client is lazily built on first
343
+ * use and locked for the process lifetime).
344
+ *
345
+ * `configJson` shape: `{ "http_url": "...", "https_url": "...", "all_url":
346
+ * "...", "no_proxy": "..." }` (all fields optional; omitting all is equivalent
347
+ * to relying on the `HTTP_PROXY` / `HTTPS_PROXY` / `ALL_PROXY` / `NO_PROXY`
348
+ * env vars).
349
+ *
350
+ * Throws on invalid JSON.
351
+ */
352
+ export declare function initProxy(configJson: string): AimuxResult<undefined>
353
+
354
+ /**
355
+ * 启动录制(RFC-0023 P1/P2):把完整 `Recording` 写 JSONL 到 `{dir}/recordings.jsonl`
356
+ * (目录自动创建)。录制 **opt-in**;再次调用(不同 dir)替换 recorder。
357
+ */
358
+ export declare function initRecording(dir: string): void
359
+
360
+ /**
361
+ * 启动内存有界录制(RFC-0023 P6):`RingRecorder`,FIFO 淘汰,丢弃计数可查。
362
+ *
363
+ * `cap` 可省略:省略时使用库默认容量(等价于 FFI `aimux_init_recording_ring_default()`;
364
+ * 本绑定直接依赖 aimux-core 而非 aimux-ffi,故调用等价 core API `RingRecorder::default()`)。
365
+ * 显式传 `cap == 0` 抛错(与其余语言一致),`cap > 0` 启动指定容量的有界 ring。
366
+ */
367
+ export declare function initRecordingRing(cap?: number | undefined | null): AimuxResult<undefined>
368
+
369
+ /**
370
+ * Enable/disable the global session inferer (RFC-0024, opt-in, off by
371
+ * default). Explicit `sessionId` values always win regardless of this.
372
+ */
373
+ export declare function initSessionInfer(enabled: boolean): void
374
+
375
+ /**
376
+ * Register the global session store (RFC-0024). Replaces any previous one.
377
+ * Until called, calls are not grouped and the session query functions return
378
+ * empty results.
379
+ */
380
+ export declare function initSessionStore(): void
381
+
382
+ /** Query: all known sessions (RFC-0024), as a JSON-serialized `SessionView[]`. */
383
+ export declare function listSessions(): AimuxResult<string>
384
+
385
+ /** Create a Mistral language model instance. */
386
+ export declare function mistral(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
387
+
388
+ export declare function moa(references: Array<Model>, aggregator: Model, configJson?: string | undefined | null): AimuxResult<Model>
389
+
390
+ /**
391
+ * 从录制 JSONL 创建 mock 回放模型(RFC-0023 P3):按输入匹配录制响应,
392
+ * **不发真实 API**。返回的 `Model` 可用于 `generateText` / `streamText`。
393
+ */
394
+ export declare function mockReplay(recordingsJsonl: string): AimuxResult<Model>
173
395
 
174
396
  /** Create an OpenAI model instance. */
175
- export declare function openai(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<Model>
397
+ export declare function openai(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
176
398
 
177
399
  /** Create an OpenAI embedding model instance. */
178
- export declare function openaiEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<EmbeddingModel>
400
+ export declare function openaiEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<EmbeddingModel>>
179
401
 
180
402
  /** Create OpenAI files manager. */
181
- export declare function openaiFiles(apiKey: string, baseUrl?: string | undefined | null): Promise<Files>
403
+ export declare function openaiFiles(apiKey: string, baseUrl?: string | undefined | null): Promise<AimuxResult<Files>>
182
404
 
183
405
  /** Create an OpenAI image model instance. */
184
- export declare function openaiImage(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<ImageModel>
406
+ export declare function openaiImage(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<ImageModel>>
185
407
 
186
408
  /** Create an OpenAI speech (TTS) model instance. */
187
- export declare function openaiSpeech(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<SpeechModel>
409
+ export declare function openaiSpeech(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<SpeechModel>>
188
410
 
189
411
  /** Create an OpenAI transcription model instance. */
190
- export declare function openaiTranscription(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<TranscriptionModel>
412
+ export declare function openaiTranscription(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<TranscriptionModel>>
413
+
414
+ /**
415
+ * Create a language model from the built-in registry by provider name
416
+ * (RFC-0017 phase 4). `api_key` may be empty/null to read the provider's env
417
+ * var from the registry entry.
418
+ */
419
+ export declare function provider(name: string, apiKey: string | undefined | null, modelId: string, config?: ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
191
420
 
192
421
  /**
193
422
  * Optional provider configuration accepted by factory functions.
@@ -219,5 +448,45 @@ export interface ProviderConfig {
219
448
  bodyOverrides?: string
220
449
  }
221
450
 
451
+ /** 刷盘全局 recorder(阻塞至 JSONL 落盘;ring 模式为 no-op)。 */
452
+ export declare function recordingFlush(): void
453
+
454
+ /** 停止录制:全局 recorder = None(新调用不再录制)。 */
455
+ export declare function recordingStop(): void
456
+
457
+ /**
458
+ * Register external OpenAI-compatible providers from a JSON config string
459
+ * (RFC-0020). Entries override same-named built-ins or add new ones.
460
+ *
461
+ * `configJson` shape: `{ "providers": [ { "name": "...", "base_url": "...", ... } ] }`.
462
+ * Throws on invalid JSON or validation failure (bad base_url scheme, empty
463
+ * name, unsupported protocol).
464
+ */
465
+ export declare function registerProviders(configJson: string): AimuxResult<undefined>
466
+
467
+ export declare function router(models: Array<Model>, configJson?: string | undefined | null): AimuxResult<Model>
468
+
469
+ /**
470
+ * Query: all calls of a session (RFC-0024), as a JSON-serialized
471
+ * `SessionCall[]` (ordered by step). Empty array if the session is unknown
472
+ * or no store is registered.
473
+ */
474
+ export declare function sessionCalls(sessionId: string): AimuxResult<string>
475
+
476
+ /**
477
+ * Start a streaming transcription session. `opts_json` (optional):
478
+ * `{ "input_audio_format": {"format_type","rate"}, "provider_options",
479
+ * "headers", "include_raw_chunks" }`. `bridge` — optional AbortSignal; firing
480
+ * it aborts the session. The returned parts are JSON-serialized
481
+ * `TranscriptionStreamPart`s.
482
+ */
483
+ export declare function startTranscriptionSession(model: TranscriptionModel, optsJson?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<AimuxResult<TranscriptionSession>>
484
+
222
485
  /** Create a Tavily search model instance. */
223
- export declare function tavilySearch(apiKey: string, baseUrl?: string | undefined | null): Promise<SearchModel>
486
+ export declare function tavilySearch(apiKey: string, baseUrl?: string | undefined | null): Promise<AimuxResult<SearchModel>>
487
+
488
+ /** Create a Vertex AI language model instance (GCP bearer token). */
489
+ export declare function vertex(accessToken: string, project: string, location: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
490
+
491
+ /** Create an xAI language model instance. */
492
+ export declare function xai(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>