@arcships/aimux 0.3.0 → 0.6.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 (295) hide show
  1. package/README.md +92 -0
  2. package/dist/error.d.ts +28 -69
  3. package/dist/error.js +72 -160
  4. package/dist/generated/ops.d.ts +75 -0
  5. package/dist/generated/ops.js +80 -0
  6. package/dist/generated/types.d.ts +5607 -0
  7. package/dist/{types/CallOptions.js → generated/types.js} +1 -0
  8. package/dist/index.d.ts +144 -184
  9. package/dist/index.js +314 -295
  10. package/dist/native.d.ts +30 -0
  11. package/dist/native.js +116 -0
  12. package/dist/types.d.ts +1 -139
  13. package/dist/types.js +0 -3
  14. package/index.d.ts +21 -469
  15. package/index.js +57 -107
  16. package/package.json +20 -17
  17. package/dist/types/AiMuxError.d.ts +0 -48
  18. package/dist/types/AiMuxError.js +0 -2
  19. package/dist/types/ApiCallError.d.ts +0 -65
  20. package/dist/types/ApiCallError.js +0 -3
  21. package/dist/types/AspectRatio.d.ts +0 -11
  22. package/dist/types/AspectRatio.js +0 -3
  23. package/dist/types/AudioChunk.d.ts +0 -8
  24. package/dist/types/AudioChunk.js +0 -3
  25. package/dist/types/AudioData.d.ts +0 -11
  26. package/dist/types/AudioData.js +0 -3
  27. package/dist/types/AudioInput.d.ts +0 -8
  28. package/dist/types/AudioInput.js +0 -3
  29. package/dist/types/BreakKind.d.ts +0 -1
  30. package/dist/types/BreakKind.js +0 -3
  31. package/dist/types/CallOptions.d.ts +0 -117
  32. package/dist/types/CatalogueSource.d.ts +0 -4
  33. package/dist/types/CatalogueSource.js +0 -3
  34. package/dist/types/ChatCompletion.d.ts +0 -16
  35. package/dist/types/ChatCompletion.js +0 -2
  36. package/dist/types/ChatCompletionChoice.d.ts +0 -8
  37. package/dist/types/ChatCompletionChoice.js +0 -2
  38. package/dist/types/ChatCompletionChunk.d.ts +0 -15
  39. package/dist/types/ChatCompletionChunk.js +0 -2
  40. package/dist/types/ChatCompletionChunkChoice.d.ts +0 -8
  41. package/dist/types/ChatCompletionChunkChoice.js +0 -2
  42. package/dist/types/ChatCompletionChunkFunction.d.ts +0 -4
  43. package/dist/types/ChatCompletionChunkFunction.js +0 -3
  44. package/dist/types/ChatCompletionChunkToolCall.d.ts +0 -7
  45. package/dist/types/ChatCompletionChunkToolCall.js +0 -2
  46. package/dist/types/ChatCompletionDelta.d.ts +0 -7
  47. package/dist/types/ChatCompletionDelta.js +0 -2
  48. package/dist/types/ChatCompletionFunction.d.ts +0 -4
  49. package/dist/types/ChatCompletionFunction.js +0 -3
  50. package/dist/types/ChatCompletionMessage.d.ts +0 -9
  51. package/dist/types/ChatCompletionMessage.js +0 -2
  52. package/dist/types/ChatCompletionToolCall.d.ts +0 -6
  53. package/dist/types/ChatCompletionToolCall.js +0 -2
  54. package/dist/types/ChatCompletionUsage.d.ts +0 -9
  55. package/dist/types/ChatCompletionUsage.js +0 -2
  56. package/dist/types/CompletionTokensDetails.d.ts +0 -3
  57. package/dist/types/CompletionTokensDetails.js +0 -3
  58. package/dist/types/ContentPart.d.ts +0 -106
  59. package/dist/types/ContentPart.js +0 -2
  60. package/dist/types/EmbeddingCallOptions.d.ts +0 -24
  61. package/dist/types/EmbeddingCallOptions.js +0 -2
  62. package/dist/types/EmbeddingResponse.d.ts +0 -16
  63. package/dist/types/EmbeddingResponse.js +0 -2
  64. package/dist/types/EmbeddingResult.d.ts +0 -33
  65. package/dist/types/EmbeddingResult.js +0 -2
  66. package/dist/types/EmbeddingUsage.d.ts +0 -9
  67. package/dist/types/EmbeddingUsage.js +0 -3
  68. package/dist/types/FileBytes.d.ts +0 -12
  69. package/dist/types/FileBytes.js +0 -3
  70. package/dist/types/FileData.d.ts +0 -25
  71. package/dist/types/FileData.js +0 -2
  72. package/dist/types/FilePart.d.ts +0 -8
  73. package/dist/types/FilePart.js +0 -2
  74. package/dist/types/Fingerprint.d.ts +0 -21
  75. package/dist/types/Fingerprint.js +0 -3
  76. package/dist/types/FinishReason.d.ts +0 -14
  77. package/dist/types/FinishReason.js +0 -2
  78. package/dist/types/FinishReasonUnified.d.ts +0 -4
  79. package/dist/types/FinishReasonUnified.js +0 -3
  80. package/dist/types/FunctionTool.d.ts +0 -35
  81. package/dist/types/FunctionTool.js +0 -2
  82. package/dist/types/GenerateContent.d.ts +0 -77
  83. package/dist/types/GenerateContent.js +0 -2
  84. package/dist/types/GenerateObjectResult.d.ts +0 -48
  85. package/dist/types/GenerateObjectResult.js +0 -2
  86. package/dist/types/GenerateResult.d.ts +0 -45
  87. package/dist/types/GenerateResult.js +0 -2
  88. package/dist/types/GenerateTextOptions.d.ts +0 -62
  89. package/dist/types/GenerateTextOptions.js +0 -2
  90. package/dist/types/GenerateTextResult.d.ts +0 -81
  91. package/dist/types/GenerateTextResult.js +0 -2
  92. package/dist/types/HttpExchange.d.ts +0 -23
  93. package/dist/types/HttpExchange.js +0 -2
  94. package/dist/types/HttpRecord.d.ts +0 -12
  95. package/dist/types/HttpRecord.js +0 -3
  96. package/dist/types/ImageCallOptions.d.ts +0 -54
  97. package/dist/types/ImageCallOptions.js +0 -2
  98. package/dist/types/ImageFile.d.ts +0 -25
  99. package/dist/types/ImageFile.js +0 -2
  100. package/dist/types/ImageFileData.d.ts +0 -8
  101. package/dist/types/ImageFileData.js +0 -3
  102. package/dist/types/ImageOutputs.d.ts +0 -14
  103. package/dist/types/ImageOutputs.js +0 -3
  104. package/dist/types/ImageResponse.d.ts +0 -19
  105. package/dist/types/ImageResponse.js +0 -3
  106. package/dist/types/ImageResult.d.ts +0 -34
  107. package/dist/types/ImageResult.js +0 -2
  108. package/dist/types/ImageUsage.d.ts +0 -19
  109. package/dist/types/ImageUsage.js +0 -3
  110. package/dist/types/InputAudioFormat.d.ts +0 -13
  111. package/dist/types/InputAudioFormat.js +0 -3
  112. package/dist/types/InputRecord.d.ts +0 -16
  113. package/dist/types/InputRecord.js +0 -2
  114. package/dist/types/LanguageModelPromptMessage.d.ts +0 -20
  115. package/dist/types/LanguageModelPromptMessage.js +0 -2
  116. package/dist/types/MessageContent.d.ts +0 -5
  117. package/dist/types/MessageContent.js +0 -2
  118. package/dist/types/Modality.d.ts +0 -4
  119. package/dist/types/Modality.js +0 -3
  120. package/dist/types/ModelCapabilities.d.ts +0 -21
  121. package/dist/types/ModelCapabilities.js +0 -3
  122. package/dist/types/ModelCost.d.ts +0 -10
  123. package/dist/types/ModelCost.js +0 -3
  124. package/dist/types/ModelId.d.ts +0 -7
  125. package/dist/types/ModelId.js +0 -3
  126. package/dist/types/ModelLimits.d.ts +0 -17
  127. package/dist/types/ModelLimits.js +0 -3
  128. package/dist/types/ModelMessage.d.ts +0 -9
  129. package/dist/types/ModelMessage.js +0 -2
  130. package/dist/types/ModelModalities.d.ts +0 -8
  131. package/dist/types/ModelModalities.js +0 -2
  132. package/dist/types/ModelPrompt.d.ts +0 -7
  133. package/dist/types/ModelPrompt.js +0 -2
  134. package/dist/types/ModelSpec.d.ts +0 -33
  135. package/dist/types/ModelSpec.js +0 -2
  136. package/dist/types/ModelType.d.ts +0 -4
  137. package/dist/types/ModelType.js +0 -3
  138. package/dist/types/OutcomeRecord.d.ts +0 -14
  139. package/dist/types/OutcomeRecord.js +0 -2
  140. package/dist/types/OutcomeStatus.d.ts +0 -4
  141. package/dist/types/OutcomeStatus.js +0 -3
  142. package/dist/types/PrefixBreak.d.ts +0 -11
  143. package/dist/types/PrefixBreak.js +0 -2
  144. package/dist/types/PromptTokensDetails.d.ts +0 -4
  145. package/dist/types/PromptTokensDetails.js +0 -3
  146. package/dist/types/ProviderAuditSpec.d.ts +0 -33
  147. package/dist/types/ProviderAuditSpec.js +0 -2
  148. package/dist/types/ProviderFamily.d.ts +0 -5
  149. package/dist/types/ProviderFamily.js +0 -3
  150. package/dist/types/ProviderName.d.ts +0 -258
  151. package/dist/types/ProviderName.js +0 -262
  152. package/dist/types/ProviderRecord.d.ts +0 -30
  153. package/dist/types/ProviderRecord.js +0 -2
  154. package/dist/types/ProviderTool.d.ts +0 -24
  155. package/dist/types/ProviderTool.js +0 -2
  156. package/dist/types/ReasoningEffort.d.ts +0 -7
  157. package/dist/types/ReasoningEffort.js +0 -3
  158. package/dist/types/ReasoningMode.d.ts +0 -4
  159. package/dist/types/ReasoningMode.js +0 -3
  160. package/dist/types/ReasoningPart.d.ts +0 -9
  161. package/dist/types/ReasoningPart.js +0 -3
  162. package/dist/types/ReasoningSpec.d.ts +0 -39
  163. package/dist/types/ReasoningSpec.js +0 -2
  164. package/dist/types/ReasoningVisibility.d.ts +0 -4
  165. package/dist/types/ReasoningVisibility.js +0 -3
  166. package/dist/types/Recording.d.ts +0 -56
  167. package/dist/types/Recording.js +0 -2
  168. package/dist/types/RequestCacheHints.d.ts +0 -9
  169. package/dist/types/RequestCacheHints.js +0 -3
  170. package/dist/types/RequestInfo.d.ts +0 -12
  171. package/dist/types/RequestInfo.js +0 -2
  172. package/dist/types/RerankingCallOptions.d.ts +0 -33
  173. package/dist/types/RerankingCallOptions.js +0 -2
  174. package/dist/types/RerankingDocuments.d.ts +0 -15
  175. package/dist/types/RerankingDocuments.js +0 -2
  176. package/dist/types/RerankingRank.d.ts +0 -13
  177. package/dist/types/RerankingRank.js +0 -3
  178. package/dist/types/RerankingResponse.d.ts +0 -28
  179. package/dist/types/RerankingResponse.js +0 -2
  180. package/dist/types/RerankingResult.d.ts +0 -31
  181. package/dist/types/RerankingResult.js +0 -2
  182. package/dist/types/ResponseFormat.d.ts +0 -11
  183. package/dist/types/ResponseFormat.js +0 -2
  184. package/dist/types/ResponseInfo.d.ts +0 -30
  185. package/dist/types/ResponseInfo.js +0 -2
  186. package/dist/types/ResponseMetadata.d.ts +0 -8
  187. package/dist/types/ResponseMetadata.js +0 -3
  188. package/dist/types/ResponseRecord.d.ts +0 -13
  189. package/dist/types/ResponseRecord.js +0 -3
  190. package/dist/types/Role.d.ts +0 -4
  191. package/dist/types/Role.js +0 -3
  192. package/dist/types/RuntimeModel.d.ts +0 -22
  193. package/dist/types/RuntimeModel.js +0 -3
  194. package/dist/types/SearchCallOptions.d.ts +0 -46
  195. package/dist/types/SearchCallOptions.js +0 -2
  196. package/dist/types/SearchResponse.d.ts +0 -16
  197. package/dist/types/SearchResponse.js +0 -2
  198. package/dist/types/SearchResult.d.ts +0 -32
  199. package/dist/types/SearchResult.js +0 -2
  200. package/dist/types/SearchResultItem.d.ts +0 -33
  201. package/dist/types/SearchResultItem.js +0 -2
  202. package/dist/types/SessionCall.d.ts +0 -20
  203. package/dist/types/SessionCall.js +0 -3
  204. package/dist/types/SessionChainView.d.ts +0 -10
  205. package/dist/types/SessionChainView.js +0 -2
  206. package/dist/types/SessionSource.d.ts +0 -4
  207. package/dist/types/SessionSource.js +0 -3
  208. package/dist/types/SessionStepStat.d.ts +0 -27
  209. package/dist/types/SessionStepStat.js +0 -2
  210. package/dist/types/SessionView.d.ts +0 -16
  211. package/dist/types/SessionView.js +0 -2
  212. package/dist/types/Size.d.ts +0 -11
  213. package/dist/types/Size.js +0 -3
  214. package/dist/types/SourcePart.d.ts +0 -9
  215. package/dist/types/SourcePart.js +0 -3
  216. package/dist/types/SpeechCallOptions.d.ts +0 -47
  217. package/dist/types/SpeechCallOptions.js +0 -2
  218. package/dist/types/SpeechRequest.d.ts +0 -10
  219. package/dist/types/SpeechRequest.js +0 -2
  220. package/dist/types/SpeechResponse.d.ts +0 -24
  221. package/dist/types/SpeechResponse.js +0 -2
  222. package/dist/types/SpeechResult.d.ts +0 -34
  223. package/dist/types/SpeechResult.js +0 -2
  224. package/dist/types/StreamPart.d.ts +0 -161
  225. package/dist/types/StreamPart.js +0 -2
  226. package/dist/types/StreamTextResultAggregated.d.ts +0 -74
  227. package/dist/types/StreamTextResultAggregated.js +0 -2
  228. package/dist/types/TimeoutConfiguration.d.ts +0 -23
  229. package/dist/types/TimeoutConfiguration.js +0 -3
  230. package/dist/types/TimingRecord.d.ts +0 -7
  231. package/dist/types/TimingRecord.js +0 -3
  232. package/dist/types/TokenUsage.d.ts +0 -29
  233. package/dist/types/TokenUsage.js +0 -3
  234. package/dist/types/Tool.d.ts +0 -12
  235. package/dist/types/Tool.js +0 -2
  236. package/dist/types/ToolCall.d.ts +0 -33
  237. package/dist/types/ToolCall.js +0 -2
  238. package/dist/types/ToolChoice.d.ts +0 -12
  239. package/dist/types/ToolChoice.js +0 -3
  240. package/dist/types/ToolResult.d.ts +0 -22
  241. package/dist/types/ToolResult.js +0 -2
  242. package/dist/types/TraceFilter.d.ts +0 -9
  243. package/dist/types/TraceFilter.js +0 -3
  244. package/dist/types/TraceRecord.d.ts +0 -54
  245. package/dist/types/TraceRecord.js +0 -2
  246. package/dist/types/TraceStats.d.ts +0 -20
  247. package/dist/types/TraceStats.js +0 -3
  248. package/dist/types/TranscriptionCallOptions.d.ts +0 -29
  249. package/dist/types/TranscriptionCallOptions.js +0 -2
  250. package/dist/types/TranscriptionRequest.d.ts +0 -9
  251. package/dist/types/TranscriptionRequest.js +0 -3
  252. package/dist/types/TranscriptionResponse.d.ts +0 -24
  253. package/dist/types/TranscriptionResponse.js +0 -2
  254. package/dist/types/TranscriptionResult.d.ts +0 -46
  255. package/dist/types/TranscriptionResult.js +0 -2
  256. package/dist/types/TranscriptionSegment.d.ts +0 -17
  257. package/dist/types/TranscriptionSegment.js +0 -3
  258. package/dist/types/TranscriptionStreamPart.d.ts +0 -70
  259. package/dist/types/TranscriptionStreamPart.js +0 -2
  260. package/dist/types/UploadFileCallOptions.d.ts +0 -27
  261. package/dist/types/UploadFileCallOptions.js +0 -2
  262. package/dist/types/UploadFileData.d.ts +0 -17
  263. package/dist/types/UploadFileData.js +0 -2
  264. package/dist/types/UploadFileResult.d.ts +0 -35
  265. package/dist/types/UploadFileResult.js +0 -2
  266. package/dist/types/Usage.d.ts +0 -13
  267. package/dist/types/Usage.js +0 -2
  268. package/dist/types/UsageSnapshot.d.ts +0 -18
  269. package/dist/types/UsageSnapshot.js +0 -2
  270. package/dist/types/Verdict.d.ts +0 -23
  271. package/dist/types/Verdict.js +0 -2
  272. package/dist/types/VerdictConfidence.d.ts +0 -4
  273. package/dist/types/VerdictConfidence.js +0 -3
  274. package/dist/types/VerdictKind.d.ts +0 -4
  275. package/dist/types/VerdictKind.js +0 -3
  276. package/dist/types/VideoCallOptions.d.ts +0 -69
  277. package/dist/types/VideoCallOptions.js +0 -2
  278. package/dist/types/VideoData.d.ts +0 -22
  279. package/dist/types/VideoData.js +0 -3
  280. package/dist/types/VideoFile.d.ts +0 -29
  281. package/dist/types/VideoFile.js +0 -2
  282. package/dist/types/VideoFileData.d.ts +0 -8
  283. package/dist/types/VideoFileData.js +0 -3
  284. package/dist/types/VideoFrameImage.d.ts +0 -17
  285. package/dist/types/VideoFrameImage.js +0 -2
  286. package/dist/types/VideoFrameType.d.ts +0 -6
  287. package/dist/types/VideoFrameType.js +0 -3
  288. package/dist/types/VideoResponse.d.ts +0 -19
  289. package/dist/types/VideoResponse.js +0 -3
  290. package/dist/types/VideoResult.d.ts +0 -29
  291. package/dist/types/VideoResult.js +0 -2
  292. package/dist/types/Warning.d.ts +0 -23
  293. package/dist/types/Warning.js +0 -3
  294. package/dist/types/serde_json/JsonValue.d.ts +0 -3
  295. package/dist/types/serde_json/JsonValue.js +0 -3
package/index.d.ts CHANGED
@@ -1,9 +1,6 @@
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
+ export type WireResult<T> = T
7
4
  declare global {
8
5
  interface __NapiRsAsyncGenerator<TOwner, T, TReturn, TNext> {
9
6
  next(...[value]: [] | [TNext]): globalThis.Promise<globalThis.IteratorResult<T, TReturn | undefined>>
@@ -13,480 +10,35 @@ declare global {
13
10
  }
14
11
  }
15
12
 
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
-
35
- export declare class EmbeddingModel {
36
- /**
37
- * Generate embeddings. `values_json` is a JSON array of strings.
38
- * Returns JSON-serialized EmbeddingResult.
39
- */
40
- embed(valuesJson: string, optsJson?: string | undefined | null): Promise<string>
41
- }
42
-
43
- export declare class Files {
44
- /**
45
- * Upload a file. `data_base64` is base64-encoded file content,
46
- * `media_type` is e.g. "application/pdf", `opts_json` is optional
47
- * (may contain filename, provider_options).
48
- * Returns JSON-serialized UploadFileResult (contains provider file ID).
49
- */
50
- uploadFile(dataBase64: string, mediaType: string, optsJson?: string | undefined | null): Promise<string>
51
- }
52
-
53
- export declare class ImageModel {
54
- /**
55
- * Generate images. `opts_json` is JSON-serialized ImageCallOptions.
56
- * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
57
- * the call. Returns JSON-serialized ImageResult (images as base64 in JSON).
58
- */
59
- generate(optsJson: string, bridge?: AbortBridge | undefined | null): Promise<string>
60
- }
61
-
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
96
- /**
97
- * Generate text (non-streaming).
98
- *
99
- * `prompt` — a JSON string: bare prompt (`"text"` or `[{...}]`) or `{"prompt": ...}`.
100
- * `options` — optional JSON-serialized `GenerateTextOptions`.
101
- * `bridge` — optional `AbortBridge` (wrap a JS `AbortSignal` in one);
102
- * aborting the signal cancels the call.
103
- * Returns a JSON-serialized `GenerateTextResult`.
104
- */
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>
123
- /**
124
- * Stream text from the model.
125
- *
126
- * Returns an `AsyncGenerator<string>` yielding `StreamPart` JSON strings.
127
- * Use `for await (const part of model.streamText(...))` to consume.
128
- */
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>>
170
- }
171
-
172
- export declare class RerankingModel {
173
- /**
174
- * Rerank documents. `query` is the search query, `docs_json` is a JSON
175
- * array of documents, `opts_json` is optional JSON options.
176
- * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
177
- * the call. Returns JSON-serialized RerankingResult.
178
- */
179
- rerank(query: string, docsJson: string, optsJson?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
180
- }
181
-
182
- export declare class SearchModel {
183
- /**
184
- * Search. `query` is the search query, `opts_json` is optional JSON options.
185
- * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
186
- * the call. Returns JSON-serialized SearchResult.
187
- */
188
- search(query: string, optsJson?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
189
- }
190
-
191
- export declare class SpeechModel {
192
- /**
193
- * Generate speech audio. `opts_json` is JSON-serialized SpeechCallOptions.
194
- * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
195
- * the call. Returns JSON-serialized SpeechResult (audio as base64 in JSON).
196
- */
197
- generate(optsJson: string, bridge?: AbortBridge | undefined | null): Promise<string>
13
+ /** An Abort handle; dropping it releases the handle without signalling shared work. */
14
+ export declare class Abort {
15
+ constructor(runtime: Runtime, signal?: AbortSignal)
16
+ get handle(): string
17
+ signal(): void
18
+ close(): void
19
+ get aborted(): boolean
198
20
  }
199
21
 
200
22
  /**
201
- * AsyncGenerator that yields StreamPart JSON strings.
202
- *
203
- * The stream is started eagerly in `stream_text()` — a tokio task drives
204
- * the Rust Stream and sends each chunk through a channel. `next()` simply
205
- * receives from the channel.
206
- *
207
23
  * This type implements JavaScript's async iterable protocol.
208
24
  * It can be used with `for await...of` loops.
209
25
  *
210
26
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols
211
27
  */
212
- export declare class StreamTextGenerator {
213
-
214
- [globalThis.Symbol.asyncIterator](): globalThis.__NapiRsAsyncGenerator<StreamTextGenerator, StreamItem, void, undefined>
215
- }
216
-
217
- export declare class TranscriptionModel {
218
- /**
219
- * Transcribe audio. `audio_base64` is base64-encoded audio data.
220
- * `media_type` is e.g. "audio/mp3". `opts_json` is optional JSON options.
221
- * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
222
- * the call. Returns JSON-serialized TranscriptionResult.
223
- */
224
- generate(audioBase64: string, mediaType: string, optsJson?: string | undefined | null, bridge?: AbortBridge | undefined | null): Promise<string>
225
- }
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
- }
28
+ export declare class FrameIterator {
257
29
 
258
- export declare class VideoModel {
259
- /**
260
- * Generate video. `opts_json` is JSON-serialized VideoCallOptions.
261
- * `bridge` — optional `AbortBridge`; aborting the wrapped signal cancels
262
- * the call. Returns JSON-serialized VideoResult (typically contains a URL).
263
- */
264
- generate(optsJson: string, bridge?: AbortBridge | undefined | null): Promise<string>
30
+ [globalThis.Symbol.asyncIterator](): globalThis.__NapiRsAsyncGenerator<FrameIterator, WireResult<string>, void, undefined>
265
31
  }
266
32
 
267
- /** Create an Anthropic model instance. */
268
- export declare function anthropic(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
269
-
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>>
272
-
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>>
279
-
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>>
282
-
283
- /** Create a Cohere language model instance. */
284
- export declare function cohere(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
285
-
286
- /** Create a Cohere embedding model instance. */
287
- export declare function cohereEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<EmbeddingModel>>
288
-
289
- /** Create a Cohere reranking model instance. */
290
- export declare function cohereReranking(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<RerankingModel>>
291
-
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>>
302
-
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>>
305
-
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>>
321
-
322
- /** Create a Google embedding model instance. */
323
- export declare function googleEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<EmbeddingModel>>
324
-
325
- /** Create a Google image model instance. */
326
- export declare function googleImage(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<ImageModel>>
327
-
328
- /** Create a Google video model instance. */
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>
395
-
396
- /** Create an OpenAI model instance. */
397
- export declare function openai(apiKey: string, modelId: string, config?: string | ProviderConfig | undefined | null): Promise<AimuxResult<Model>>
398
-
399
- /** Create an OpenAI embedding model instance. */
400
- export declare function openaiEmbedding(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<EmbeddingModel>>
401
-
402
- /** Create OpenAI files manager. */
403
- export declare function openaiFiles(apiKey: string, baseUrl?: string | undefined | null): Promise<AimuxResult<Files>>
404
-
405
- /** Create an OpenAI image model instance. */
406
- export declare function openaiImage(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<ImageModel>>
407
-
408
- /** Create an OpenAI speech (TTS) model instance. */
409
- export declare function openaiSpeech(apiKey: string, modelId: string, baseUrl?: string | undefined | null): Promise<AimuxResult<SpeechModel>>
410
-
411
- /** Create an OpenAI transcription model instance. */
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>>
420
-
421
- /**
422
- * Optional provider configuration accepted by factory functions.
423
- *
424
- * Passed as the 3rd argument to `openai()` / `anthropic()` / `deepseek()`.
425
- * For backward compatibility a bare string is still accepted (treated as
426
- * `baseUrl`). See RFC-0017.
427
- */
428
- export interface ProviderConfig {
429
- /** Base URL for API calls (e.g. a relay/proxy endpoint). */
430
- baseUrl?: string
431
- /**
432
- * Extra HTTP headers merged into every request, as a JSON object string
433
- * (e.g. `'{"X-Custom":"value"}'`).
434
- */
435
- headers?: string
436
- /** OpenAI organization ID (sent via `OpenAI-Organization` header). */
437
- organization?: string
438
- /** OpenAI project ID (sent via `OpenAI-Project` header). */
439
- project?: string
440
- /** Override the provider's retry count. `0` disables retries. */
441
- maxRetries?: number
442
- /**
443
- * Provider-level request body overrides as a JSON string (deep-merged
444
- * into every request). Per-call `bodyOverrides` in GenerateTextOptions
445
- * takes precedence. Pass a JSON object string, e.g.
446
- * `'{"enable_thinking": false}'`.
447
- */
448
- bodyOverrides?: string
33
+ /** All Runtime instances in one napi Env share one unforgeable Owner::Node. */
34
+ export declare class Runtime {
35
+ constructor()
36
+ /** Nonblocking release for explicit disposal and JS finalization. */
37
+ dropHandle(id: string): WireResult<undefined>
38
+ manifestJson(): WireResult<string>
39
+ manifestDigest(): string
40
+ call(id: string, op: string, paramsJson: string, abort?: Abort | undefined | null): Promise<string>
41
+ /** Copy the caller's buffer on the JS thread before returning the Promise. */
42
+ operationPush(id: string, data: Uint8Array): Promise<void>
43
+ stream(id: string, op: string, paramsJson: string, abort?: Abort | undefined | null): Promise<FrameIterator>
449
44
  }
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
-
485
- /** Create a Tavily search model instance. */
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>>