@arcships/aimux 0.5.0 → 0.6.1

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 (305) hide show
  1. package/README.md +92 -0
  2. package/dist/error.d.ts +28 -137
  3. package/dist/error.js +71 -100
  4. package/dist/generated/ops.d.ts +75 -0
  5. package/dist/generated/ops.js +80 -0
  6. package/dist/generated/types.d.ts +5613 -0
  7. package/dist/{types/CallOptions.js → generated/types.js} +1 -0
  8. package/dist/index.d.ts +144 -211
  9. package/dist/index.js +314 -344
  10. package/dist/native.d.ts +29 -1
  11. package/dist/native.js +99 -29
  12. package/dist/types.d.ts +1 -144
  13. package/dist/types.js +0 -3
  14. package/index.d.ts +21 -545
  15. package/index.js +57 -112
  16. package/package.json +16 -13
  17. package/dist/types/AiMuxError.d.ts +0 -66
  18. package/dist/types/AiMuxError.js +0 -2
  19. package/dist/types/ApiCallError.d.ts +0 -75
  20. package/dist/types/ApiCallError.js +0 -2
  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 -112
  59. package/dist/types/ContentPart.js +0 -2
  60. package/dist/types/EmbeddingCallOptions.d.ts +0 -33
  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 -88
  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 -34
  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 -63
  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 -19
  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/RawToolCall.d.ts +0 -16
  157. package/dist/types/RawToolCall.js +0 -2
  158. package/dist/types/ReasoningEffort.d.ts +0 -7
  159. package/dist/types/ReasoningEffort.js +0 -3
  160. package/dist/types/ReasoningMode.d.ts +0 -4
  161. package/dist/types/ReasoningMode.js +0 -3
  162. package/dist/types/ReasoningPart.d.ts +0 -9
  163. package/dist/types/ReasoningPart.js +0 -3
  164. package/dist/types/ReasoningSpec.d.ts +0 -39
  165. package/dist/types/ReasoningSpec.js +0 -2
  166. package/dist/types/ReasoningVisibility.d.ts +0 -4
  167. package/dist/types/ReasoningVisibility.js +0 -3
  168. package/dist/types/Recording.d.ts +0 -56
  169. package/dist/types/Recording.js +0 -2
  170. package/dist/types/RequestCacheHints.d.ts +0 -9
  171. package/dist/types/RequestCacheHints.js +0 -3
  172. package/dist/types/RequestInfo.d.ts +0 -12
  173. package/dist/types/RequestInfo.js +0 -2
  174. package/dist/types/RerankingCallOptions.d.ts +0 -42
  175. package/dist/types/RerankingCallOptions.js +0 -2
  176. package/dist/types/RerankingDocuments.d.ts +0 -15
  177. package/dist/types/RerankingDocuments.js +0 -2
  178. package/dist/types/RerankingRank.d.ts +0 -13
  179. package/dist/types/RerankingRank.js +0 -3
  180. package/dist/types/RerankingResponse.d.ts +0 -28
  181. package/dist/types/RerankingResponse.js +0 -2
  182. package/dist/types/RerankingResult.d.ts +0 -31
  183. package/dist/types/RerankingResult.js +0 -2
  184. package/dist/types/ResponseFormat.d.ts +0 -11
  185. package/dist/types/ResponseFormat.js +0 -2
  186. package/dist/types/ResponseInfo.d.ts +0 -30
  187. package/dist/types/ResponseInfo.js +0 -2
  188. package/dist/types/ResponseMetadata.d.ts +0 -8
  189. package/dist/types/ResponseMetadata.js +0 -3
  190. package/dist/types/ResponseRecord.d.ts +0 -13
  191. package/dist/types/ResponseRecord.js +0 -3
  192. package/dist/types/RetryError.d.ts +0 -9
  193. package/dist/types/RetryError.js +0 -2
  194. package/dist/types/RetryErrorReason.d.ts +0 -4
  195. package/dist/types/RetryErrorReason.js +0 -3
  196. package/dist/types/Role.d.ts +0 -4
  197. package/dist/types/Role.js +0 -3
  198. package/dist/types/RuntimeModel.d.ts +0 -22
  199. package/dist/types/RuntimeModel.js +0 -3
  200. package/dist/types/SearchCallOptions.d.ts +0 -55
  201. package/dist/types/SearchCallOptions.js +0 -2
  202. package/dist/types/SearchResponse.d.ts +0 -16
  203. package/dist/types/SearchResponse.js +0 -2
  204. package/dist/types/SearchResult.d.ts +0 -32
  205. package/dist/types/SearchResult.js +0 -2
  206. package/dist/types/SearchResultItem.d.ts +0 -33
  207. package/dist/types/SearchResultItem.js +0 -2
  208. package/dist/types/SessionCall.d.ts +0 -20
  209. package/dist/types/SessionCall.js +0 -3
  210. package/dist/types/SessionChainView.d.ts +0 -10
  211. package/dist/types/SessionChainView.js +0 -2
  212. package/dist/types/SessionSource.d.ts +0 -4
  213. package/dist/types/SessionSource.js +0 -3
  214. package/dist/types/SessionStepStat.d.ts +0 -27
  215. package/dist/types/SessionStepStat.js +0 -2
  216. package/dist/types/SessionView.d.ts +0 -16
  217. package/dist/types/SessionView.js +0 -2
  218. package/dist/types/Size.d.ts +0 -11
  219. package/dist/types/Size.js +0 -3
  220. package/dist/types/SourcePart.d.ts +0 -9
  221. package/dist/types/SourcePart.js +0 -3
  222. package/dist/types/SpeechCallOptions.d.ts +0 -56
  223. package/dist/types/SpeechCallOptions.js +0 -2
  224. package/dist/types/SpeechRequest.d.ts +0 -10
  225. package/dist/types/SpeechRequest.js +0 -2
  226. package/dist/types/SpeechResponse.d.ts +0 -24
  227. package/dist/types/SpeechResponse.js +0 -2
  228. package/dist/types/SpeechResult.d.ts +0 -34
  229. package/dist/types/SpeechResult.js +0 -2
  230. package/dist/types/StreamPart.d.ts +0 -173
  231. package/dist/types/StreamPart.js +0 -2
  232. package/dist/types/StreamTextResultAggregated.d.ts +0 -74
  233. package/dist/types/StreamTextResultAggregated.js +0 -2
  234. package/dist/types/TimeoutConfiguration.d.ts +0 -32
  235. package/dist/types/TimeoutConfiguration.js +0 -3
  236. package/dist/types/TimingRecord.d.ts +0 -7
  237. package/dist/types/TimingRecord.js +0 -3
  238. package/dist/types/TokenUsage.d.ts +0 -29
  239. package/dist/types/TokenUsage.js +0 -3
  240. package/dist/types/Tool.d.ts +0 -12
  241. package/dist/types/Tool.js +0 -2
  242. package/dist/types/ToolCall.d.ts +0 -48
  243. package/dist/types/ToolCall.js +0 -2
  244. package/dist/types/ToolCallRepairReply.d.ts +0 -19
  245. package/dist/types/ToolCallRepairReply.js +0 -2
  246. package/dist/types/ToolChoice.d.ts +0 -12
  247. package/dist/types/ToolChoice.js +0 -3
  248. package/dist/types/ToolResult.d.ts +0 -22
  249. package/dist/types/ToolResult.js +0 -2
  250. package/dist/types/TraceFilter.d.ts +0 -9
  251. package/dist/types/TraceFilter.js +0 -3
  252. package/dist/types/TraceRecord.d.ts +0 -54
  253. package/dist/types/TraceRecord.js +0 -2
  254. package/dist/types/TraceStats.d.ts +0 -20
  255. package/dist/types/TraceStats.js +0 -3
  256. package/dist/types/TranscriptionCallOptions.d.ts +0 -38
  257. package/dist/types/TranscriptionCallOptions.js +0 -2
  258. package/dist/types/TranscriptionRequest.d.ts +0 -9
  259. package/dist/types/TranscriptionRequest.js +0 -3
  260. package/dist/types/TranscriptionResponse.d.ts +0 -24
  261. package/dist/types/TranscriptionResponse.js +0 -2
  262. package/dist/types/TranscriptionResult.d.ts +0 -46
  263. package/dist/types/TranscriptionResult.js +0 -2
  264. package/dist/types/TranscriptionSegment.d.ts +0 -17
  265. package/dist/types/TranscriptionSegment.js +0 -3
  266. package/dist/types/TranscriptionStreamPart.d.ts +0 -70
  267. package/dist/types/TranscriptionStreamPart.js +0 -2
  268. package/dist/types/UploadFileCallOptions.d.ts +0 -27
  269. package/dist/types/UploadFileCallOptions.js +0 -2
  270. package/dist/types/UploadFileData.d.ts +0 -17
  271. package/dist/types/UploadFileData.js +0 -2
  272. package/dist/types/UploadFileResult.d.ts +0 -35
  273. package/dist/types/UploadFileResult.js +0 -2
  274. package/dist/types/Usage.d.ts +0 -13
  275. package/dist/types/Usage.js +0 -2
  276. package/dist/types/UsageSnapshot.d.ts +0 -18
  277. package/dist/types/UsageSnapshot.js +0 -2
  278. package/dist/types/Verdict.d.ts +0 -23
  279. package/dist/types/Verdict.js +0 -2
  280. package/dist/types/VerdictConfidence.d.ts +0 -4
  281. package/dist/types/VerdictConfidence.js +0 -3
  282. package/dist/types/VerdictKind.d.ts +0 -4
  283. package/dist/types/VerdictKind.js +0 -3
  284. package/dist/types/VideoCallOptions.d.ts +0 -84
  285. package/dist/types/VideoCallOptions.js +0 -2
  286. package/dist/types/VideoData.d.ts +0 -22
  287. package/dist/types/VideoData.js +0 -3
  288. package/dist/types/VideoFile.d.ts +0 -29
  289. package/dist/types/VideoFile.js +0 -2
  290. package/dist/types/VideoFileData.d.ts +0 -8
  291. package/dist/types/VideoFileData.js +0 -3
  292. package/dist/types/VideoFrameImage.d.ts +0 -17
  293. package/dist/types/VideoFrameImage.js +0 -2
  294. package/dist/types/VideoFrameType.d.ts +0 -6
  295. package/dist/types/VideoFrameType.js +0 -3
  296. package/dist/types/VideoPollOptions.d.ts +0 -13
  297. package/dist/types/VideoPollOptions.js +0 -3
  298. package/dist/types/VideoResponse.d.ts +0 -19
  299. package/dist/types/VideoResponse.js +0 -3
  300. package/dist/types/VideoResult.d.ts +0 -29
  301. package/dist/types/VideoResult.js +0 -2
  302. package/dist/types/Warning.d.ts +0 -23
  303. package/dist/types/Warning.js +0 -3
  304. package/dist/types/serde_json/JsonValue.d.ts +0 -3
  305. package/dist/types/serde_json/JsonValue.js +0 -3
package/dist/index.js CHANGED
@@ -1,17 +1,4 @@
1
1
  "use strict";
2
- // aimux — Typed wrapper layer for the Node.js (napi-rs) binding.
3
- //
4
- // The native binding speaks JSON strings:
5
- // generateText(prompt: string, options?: string): Promise<string>
6
- // streamText(prompt: string, options?: string): Promise<AsyncGenerator<string>>
7
- // Users would otherwise have to JSON.stringify every input and JSON.parse every
8
- // output, with no static types. This wrapper erases that JSON boundary: inputs
9
- // and outputs are typed objects, using the ts-rs generated types from
10
- // `./types.ts` (ts-rs exports directly into `./types/` — single source of
11
- // truth in the Rust core, packaged with the npm tarball).
12
- //
13
- // The generated napi loader stays untouched. `native.ts` registers the canonical
14
- // JS Error constructors; this file adds the typed JSON layer on top.
15
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
3
  if (k2 === undefined) k2 = k;
17
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -45,356 +32,339 @@ var __importStar = (this && this.__importStar) || (function () {
45
32
  return result;
46
33
  };
47
34
  })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
39
+ if (kind === "m") throw new TypeError("Private method is not writable");
40
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
41
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
42
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
43
+ };
44
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
45
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
46
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
47
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
48
+ };
49
+ var _Resource_handle;
48
50
  Object.defineProperty(exports, "__esModule", { value: true });
49
- exports.ProviderHandleTyped = exports.ProviderName = exports.initRecording = exports.recordingTryFlush = exports.provider = exports.azure = exports.anthropicAws = exports.vertex = exports.bedrock = exports.xai = exports.mistral = exports.cohere = exports.google = exports.deepseek = exports.anthropic = exports.openai = exports.moa = exports.router = exports.initRecordingRing = exports.mockReplay = exports.listSessions = exports.sessionCalls = exports.initSessionInfer = exports.initSessionStore = exports.recordingStop = exports.recordingFlush = exports.initLogging = exports.AbortBridge = exports.StreamTextGenerator = exports.Model = exports.RecordingError = exports.OtherError = exports.RequestAbortedError = exports.TimeoutError = exports.NoSuchProviderError = exports.NoSuchModelError = exports.UnsupportedFunctionalityError = exports.TokenExpiredError = exports.InvalidPromptError = exports.InvalidArgumentError = exports.ToolCallRepairError = exports.InvalidToolInputError = exports.NoSuchToolError = exports.InvalidResponseDataError = exports.JSONParseError = exports.RetryError = exports.APICallError = exports.AimuxError = void 0;
50
- exports.generateText = generateText;
51
- exports.streamText = streamText;
52
- exports.getSessionCalls = getSessionCalls;
53
- exports.getSessions = getSessions;
54
- exports.generateTextAsOpenai = generateTextAsOpenai;
55
- exports.streamTextAsOpenai = streamTextAsOpenai;
56
- exports.createProvider = createProvider;
57
- exports.getModelSpecs = getModelSpecs;
58
- const native = __importStar(require("./native.js"));
51
+ exports.ReplaySession = exports.SessionStore = exports.Recorder = exports.TraceStore = exports.Operation = exports.Middleware = exports.Files = exports.DecisionModel = exports.SearchModel = exports.VideoModel = exports.RerankingModel = exports.TranscriptionModel = exports.SpeechModel = exports.ImageModel = exports.EmbeddingModel = exports.LanguageModel = exports.Model = exports.Registry = exports.Provider = exports.Abort = exports.Resource = exports.Client = void 0;
52
+ exports.readable = readable;
53
+ const ops = __importStar(require("./generated/ops.js"));
59
54
  const native_ts_1 = require("./native.js");
60
- // Error hierarchy (throw/catch). Wire payload type `AiMuxError` lives under StreamPart only.
61
- var error_ts_1 = require("./error.js");
62
- Object.defineProperty(exports, "AimuxError", { enumerable: true, get: function () { return error_ts_1.AimuxError; } });
63
- Object.defineProperty(exports, "APICallError", { enumerable: true, get: function () { return error_ts_1.APICallError; } });
64
- Object.defineProperty(exports, "RetryError", { enumerable: true, get: function () { return error_ts_1.RetryError; } });
65
- Object.defineProperty(exports, "JSONParseError", { enumerable: true, get: function () { return error_ts_1.JSONParseError; } });
66
- Object.defineProperty(exports, "InvalidResponseDataError", { enumerable: true, get: function () { return error_ts_1.InvalidResponseDataError; } });
67
- Object.defineProperty(exports, "NoSuchToolError", { enumerable: true, get: function () { return error_ts_1.NoSuchToolError; } });
68
- Object.defineProperty(exports, "InvalidToolInputError", { enumerable: true, get: function () { return error_ts_1.InvalidToolInputError; } });
69
- Object.defineProperty(exports, "ToolCallRepairError", { enumerable: true, get: function () { return error_ts_1.ToolCallRepairError; } });
70
- Object.defineProperty(exports, "InvalidArgumentError", { enumerable: true, get: function () { return error_ts_1.InvalidArgumentError; } });
71
- Object.defineProperty(exports, "InvalidPromptError", { enumerable: true, get: function () { return error_ts_1.InvalidPromptError; } });
72
- Object.defineProperty(exports, "TokenExpiredError", { enumerable: true, get: function () { return error_ts_1.TokenExpiredError; } });
73
- Object.defineProperty(exports, "UnsupportedFunctionalityError", { enumerable: true, get: function () { return error_ts_1.UnsupportedFunctionalityError; } });
74
- Object.defineProperty(exports, "NoSuchModelError", { enumerable: true, get: function () { return error_ts_1.NoSuchModelError; } });
75
- Object.defineProperty(exports, "NoSuchProviderError", { enumerable: true, get: function () { return error_ts_1.NoSuchProviderError; } });
76
- Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return error_ts_1.TimeoutError; } });
77
- Object.defineProperty(exports, "RequestAbortedError", { enumerable: true, get: function () { return error_ts_1.RequestAbortedError; } });
78
- Object.defineProperty(exports, "OtherError", { enumerable: true, get: function () { return error_ts_1.OtherError; } });
79
- Object.defineProperty(exports, "RecordingError", { enumerable: true, get: function () { return error_ts_1.RecordingError; } });
80
- // Re-export the raw napi constructors/factories so consumers can do everything
81
- // from a single import: `import { openai, generateText } from 'aimux'`.
82
- // Rust fn names are snake_case; napi-rs exposes them camelCased (like
83
- // `init_logging` → `initLogging`).
84
- //
85
- // Native functions pass through unchanged: Rust already constructs the
86
- // registered JavaScript error subclasses before throwing.
87
- var native_ts_2 = require("./native.js");
88
- Object.defineProperty(exports, "Model", { enumerable: true, get: function () { return native_ts_2.Model; } });
89
- Object.defineProperty(exports, "StreamTextGenerator", { enumerable: true, get: function () { return native_ts_2.StreamTextGenerator; } });
90
- Object.defineProperty(exports, "AbortBridge", { enumerable: true, get: function () { return native_ts_2.AbortBridge; } });
91
- Object.defineProperty(exports, "initLogging", { enumerable: true, get: function () { return native_ts_2.initLogging; } });
92
- Object.defineProperty(exports, "recordingFlush", { enumerable: true, get: function () { return native_ts_2.recordingFlush; } });
93
- Object.defineProperty(exports, "recordingStop", { enumerable: true, get: function () { return native_ts_2.recordingStop; } });
94
- Object.defineProperty(exports, "initSessionStore", { enumerable: true, get: function () { return native_ts_2.initSessionStore; } });
95
- Object.defineProperty(exports, "initSessionInfer", { enumerable: true, get: function () { return native_ts_2.initSessionInfer; } });
96
- Object.defineProperty(exports, "sessionCalls", { enumerable: true, get: function () { return native_ts_2.sessionCalls; } });
97
- Object.defineProperty(exports, "listSessions", { enumerable: true, get: function () { return native_ts_2.listSessions; } });
98
- Object.defineProperty(exports, "mockReplay", { enumerable: true, get: function () { return native_ts_2.mockReplay; } });
99
- Object.defineProperty(exports, "initRecordingRing", { enumerable: true, get: function () { return native_ts_2.initRecordingRing; } });
100
- Object.defineProperty(exports, "router", { enumerable: true, get: function () { return native_ts_2.router; } });
101
- Object.defineProperty(exports, "moa", { enumerable: true, get: function () { return native_ts_2.moa; } });
102
- Object.defineProperty(exports, "openai", { enumerable: true, get: function () { return native_ts_2.openai; } });
103
- Object.defineProperty(exports, "anthropic", { enumerable: true, get: function () { return native_ts_2.anthropic; } });
104
- Object.defineProperty(exports, "deepseek", { enumerable: true, get: function () { return native_ts_2.deepseek; } });
105
- Object.defineProperty(exports, "google", { enumerable: true, get: function () { return native_ts_2.google; } });
106
- Object.defineProperty(exports, "cohere", { enumerable: true, get: function () { return native_ts_2.cohere; } });
107
- Object.defineProperty(exports, "mistral", { enumerable: true, get: function () { return native_ts_2.mistral; } });
108
- Object.defineProperty(exports, "xai", { enumerable: true, get: function () { return native_ts_2.xai; } });
109
- Object.defineProperty(exports, "bedrock", { enumerable: true, get: function () { return native_ts_2.bedrock; } });
110
- Object.defineProperty(exports, "vertex", { enumerable: true, get: function () { return native_ts_2.vertex; } });
111
- Object.defineProperty(exports, "anthropicAws", { enumerable: true, get: function () { return native_ts_2.anthropicAws; } });
112
- Object.defineProperty(exports, "azure", { enumerable: true, get: function () { return native_ts_2.azure; } });
113
- Object.defineProperty(exports, "provider", { enumerable: true, get: function () { return native_ts_2.provider; } });
114
- // Spell these as `void` in the public wrapper instead of leaking the generated
115
- // `AimuxResult<undefined>` implementation type.
116
- exports.recordingTryFlush = native.recordingTryFlush;
117
- exports.initRecording = native.initRecording;
118
- // Both meanings: the `ProviderName` const object (runtime, for `ProviderName.groq`)
119
- // and the derived string-union type. A value export resolves at runtime, so the
120
- // specifier needs the real `.ts` extension for Node's type-stripping test runs;
121
- // tsc rewrites it to `.js` on emit (rewriteRelativeImportExtensions).
122
- var ProviderName_ts_1 = require("./types/ProviderName.js");
123
- Object.defineProperty(exports, "ProviderName", { enumerable: true, get: function () { return ProviderName_ts_1.ProviderName; } });
124
- /**
125
- * The AI SDK's `getErrorMessage`, so a thrown value renders exactly as it
126
- * would in the SDK's own `ToolCallRepairError` message: strings verbatim,
127
- * `Error` instances via `toString()` (name included), anything else as JSON.
128
- */
129
- function errorMessage(e) {
130
- if (e == null)
131
- return 'unknown error';
132
- if (typeof e === 'string')
133
- return e;
134
- if (e instanceof Error)
135
- return e.toString();
136
- return JSON.stringify(e);
137
- }
138
- /**
139
- * Run the user's repair function for one invalid call and turn its outcome
140
- * into the wire reply. Returns `null` when the call is not repairable at all
141
- * (no tool set — the AI SDK rule, decided in core).
142
- */
143
- async function repairReplyFor(call, promptJson, optsJson, repair) {
144
- const context = JSON.parse((0, native_ts_1.toolCallRepairContext)(JSON.stringify(call), promptJson, optsJson));
145
- if (context === null)
146
- return null;
147
- let reply;
55
+ const error_ts_1 = require("./error.js");
56
+ __exportStar(require("./error.js"), exports);
57
+ function json(value) {
148
58
  try {
149
- const replacement = await repair(context);
150
- reply = replacement ? { type: 'repaired', tool_call: replacement } : { type: 'unchanged' };
59
+ const serialized = JSON.stringify(value, (_key, item) => {
60
+ if (typeof item === 'function' || typeof item === 'symbol')
61
+ throw new TypeError('Ops parameters must contain JSON data only');
62
+ return item;
63
+ });
64
+ if (serialized === undefined)
65
+ throw new TypeError('Parameters must be JSON data');
66
+ return serialized;
151
67
  }
152
- catch (e) {
153
- reply = { type: 'failed', message: errorMessage(e) };
68
+ catch (error) {
69
+ // The payload carries the serializer's error as the native decoder does;
70
+ // `Error.cause` is that error itself, with its stack.
71
+ const wire = new error_ts_1.AimuxError({ kind: 'binding', code: 202, message: `params: ${String(error)}`, error: { name: 'InvalidWireJson', argument: 'params', message: String(error), cause: { message: String(error) } } });
72
+ Object.defineProperty(wire, 'cause', { value: error, writable: true, configurable: true });
73
+ throw wire;
154
74
  }
155
- return JSON.stringify(reply);
156
75
  }
157
- /**
158
- * Repair every invalid call in a serialized result, before it is decoded.
159
- * `tool_calls` sits at the top level of a generate-text result and under `raw`
160
- * in a generate-object one.
161
- */
162
- async function repairResultJson(resultJson, promptJson, optsJson, repair) {
163
- const result = JSON.parse(resultJson);
164
- const calls = result.tool_calls ?? result.raw?.tool_calls ?? [];
165
- let patched = resultJson;
166
- for (const call of calls) {
167
- if (call.invalid !== true)
168
- continue;
169
- const reply = await repairReplyFor(call, promptJson, optsJson, repair);
170
- if (reply === null)
171
- continue;
172
- patched = (0, native_ts_1.applyToolCallRepairToResult)(patched, optsJson, call.tool_call_id, reply);
76
+ /** A Client owns a realm-local runtime; IDs must never be transferred to workers. */
77
+ class Client {
78
+ constructor() { this.raw = new native_ts_1.Runtime(); }
79
+ get manifest() { return this.raw.manifest; }
80
+ get manifestDigest() { return this.raw.manifestDigest; }
81
+ async call(handle, op, params = {}, options = {}) {
82
+ const abort = this.bridge(options);
83
+ return JSON.parse(await this.raw.call(handle, op, json(params), abort));
173
84
  }
174
- return patched;
175
- }
176
- /**
177
- * Generate text (non-streaming). Returns a typed {@link GenerateTextResult}.
178
- *
179
- * @param model - A raw model instance from `openai()`, `anthropic()`, etc.
180
- * @param prompt - A plain string or an array of typed chat messages.
181
- * @param options - Optional typed generation options (tools, tool_choice,
182
- * temperature, response_format, …). Invalid tool calls arrive
183
- * with `invalid`/`error` set on the tool call; pass
184
- * {@link RepairToolCall | `repairToolCall`} to fix them up
185
- * before the result is decoded.
186
- * @param signal - Optional `AbortSignal`; aborting it cancels the call.
187
- *
188
- * Internally calls the raw
189
- * `model.generateText(JSON.stringify(prompt), options ? JSON.stringify(options) : undefined)`
190
- * and `JSON.parse`s the returned JSON into a typed object.
191
- *
192
- * @example
193
- * ```ts
194
- * import { openai, generateText } from 'aimux'
195
- * const model = await openai(apiKey, 'gpt-4o')
196
- * const result = await generateText(model, 'What is Rust?')
197
- * console.log(result.text, result.usage)
198
- * ```
199
- */
200
- async function generateText(model, prompt, options, signal) {
201
- const promptJson = JSON.stringify(prompt);
202
- const optsJson = options ? JSON.stringify(options) : undefined;
203
- const bridge = signal ? new native_ts_1.AbortBridge(signal) : undefined;
204
- let resultJson = await model.generateText(promptJson, optsJson, bridge);
205
- if (options?.repairToolCall) {
206
- resultJson = await repairResultJson(resultJson, promptJson, optsJson, options.repairToolCall);
85
+ async stream(handle, op, params = {}, options = {}) {
86
+ const abort = this.bridge(options);
87
+ const inner = await this.raw.stream(handle, op, json(params), abort);
88
+ return mapIterator(inner, value => JSON.parse(value), () => abort?.signal());
207
89
  }
208
- return JSON.parse(resultJson);
209
- }
210
- /**
211
- * Stream text from a model. Yields typed {@link StreamPart}s.
212
- *
213
- * @param model - A raw model instance from `openai()`, `anthropic()`, etc.
214
- * @param prompt - A plain string or an array of typed chat messages.
215
- * @param options - Optional typed generation options (tools, tool_choice, …).
216
- * @param signal - Optional `AbortSignal`; aborting it cancels the stream.
217
- *
218
- * Internally drives the raw `model.streamText(JSON.stringify(prompt), …)`
219
- * async generator and `JSON.parse`s each JSON-string chunk before yielding it
220
- * as a typed `StreamPart`.
221
- *
222
- * @example
223
- * ```ts
224
- * import { openai, streamText } from 'aimux'
225
- * const model = await openai(apiKey, 'gpt-4o')
226
- * for await (const part of streamText(model, 'Write a haiku about Rust.')) {
227
- * if ('TextDelta' in part) process.stdout.write(part.TextDelta.delta)
228
- * }
229
- * ```
230
- */
231
- async function* streamText(model, prompt, options, signal) {
232
- const promptJson = JSON.stringify(prompt);
233
- const optsJson = options ? JSON.stringify(options) : undefined;
234
- const bridge = signal ? new native_ts_1.AbortBridge(signal) : undefined;
235
- const repair = options?.repairToolCall;
236
- const gen = await model.streamText(promptJson, optsJson, bridge);
237
- for await (const json of gen) {
238
- const part = JSON.parse(json);
239
- // Only the settled ToolCall part is repairable; ToolInputDelta parts are
240
- // the provider's raw text and pass through immediately (AI SDK behaviour).
241
- if (repair && 'ToolCall' in part && part.ToolCall.invalid === true) {
242
- const reply = await repairReplyFor(part.ToolCall, promptJson, optsJson, repair);
243
- if (reply !== null) {
244
- yield {
245
- ToolCall: JSON.parse((0, native_ts_1.applyToolCallRepair)(JSON.stringify(part.ToolCall), optsJson, reply)),
246
- };
247
- continue;
248
- }
90
+ bridge(options) {
91
+ if (options.abort) {
92
+ if (options.signal)
93
+ throw (0, error_ts_1.protocolError)(301, 'InvalidParams', 'Pass either signal or abort');
94
+ return options.abort.native;
249
95
  }
250
- yield part;
96
+ return options.signal ? this.raw.abort(options.signal) : undefined;
97
+ }
98
+ async provider(params) { return new Provider(this, await this.call('0', ops.OP_PROVIDER_CREATE, params)); }
99
+ async defaultProvider(params) { return new Provider(this, await this.call('0', ops.OP_PROVIDER_DEFAULT, params)); }
100
+ async customProvider(params) { return new Provider(this, await this.call('0', ops.OP_PROVIDER_CUSTOM, params)); }
101
+ async registry(entries, namespace = '') {
102
+ const refs = Object.entries(entries).map(([key, provider]) => ({ key, provider: provider.handle }));
103
+ return new Registry(this, await this.call('0', ops.OP_REGISTRY_CREATE, { namespace, entries: refs }));
251
104
  }
105
+ abort(signal) { return new Abort(this, signal); }
106
+ async configure(params) { return this.call('0', ops.OP_RUNTIME_CONFIGURE, params); }
107
+ async describe() { return this.call('0', ops.OP_RUNTIME_DESCRIBE); }
108
+ async trace(params = {}) { return new TraceStore(this, handleRef(await this.call('0', ops.OP_TRACE_CREATE, params), 'TraceStore')); }
109
+ async recorder(params) { return new Recorder(this, handleRef(await this.call('0', ops.OP_RECORDER_CREATE, params), 'Recorder')); }
110
+ async sessionStore(params) { return new SessionStore(this, handleRef(await this.call('0', ops.OP_SESSION_STORE_CREATE, params), 'SessionStore')); }
111
+ async replay(params) { return new ReplaySession(this, handleRef(await this.call('0', ops.OP_REPLAY_CREATE, params), 'ReplaySession')); }
112
+ async middleware(params) { return new Middleware(this, await this.call('0', ops.OP_MIDDLEWARE_CREATE, params)); }
113
+ async transport(params) { return new Resource(this, await this.call('0', ops.OP_TRANSPORT_CREATE, params)); }
114
+ async credential(params) { return new Resource(this, await this.call('0', ops.OP_CREDENTIAL_CREATE, params)); }
115
+ async catalogue(params) { return this.call('0', ops.OP_CATALOGUE_FETCH, params); }
116
+ async router(params) { return new LanguageModel(this, handleRef(await this.call('0', ops.OP_COMPOSITE_ROUTER, params), 'Language')); }
117
+ async moa(params) { return new LanguageModel(this, handleRef(await this.call('0', ops.OP_COMPOSITE_MOA, params), 'Language')); }
252
118
  }
253
- /**
254
- * All calls of a session, ordered by step (RFC-0024). Empty if the session
255
- * is unknown or no store is registered.
256
- *
257
- * `initSessionStore()` / `initSessionInfer(enabled)` (raw napi, re-exported
258
- * above) must be called first to register the store / opt-in inferer.
259
- */
260
- function getSessionCalls(sessionId) {
261
- return JSON.parse(native.sessionCalls(sessionId));
119
+ exports.Client = Client;
120
+ // Finalization is a fallback. Explicit close/flush remains the normal protocol.
121
+ const finalizer = new FinalizationRegistry(held => {
122
+ try {
123
+ held.client.raw.drop(held.handle);
124
+ }
125
+ catch { /* Env cleanup owns remaining resources. */ }
126
+ });
127
+ class Resource {
128
+ constructor(client, ref) {
129
+ _Resource_handle.set(this, void 0);
130
+ this.client = client;
131
+ this.kind = ref.kind;
132
+ __classPrivateFieldSet(this, _Resource_handle, ref.handle, "f");
133
+ finalizer.register(this, { client, handle: ref.handle }, this);
134
+ }
135
+ get handle() {
136
+ if (__classPrivateFieldGet(this, _Resource_handle, "f") === undefined)
137
+ throw new error_ts_1.AimuxError({ kind: 'binding', code: 203, message: 'Handle is closed', error: { name: 'InvalidHandle', expected: [this.kind] } });
138
+ return __classPrivateFieldGet(this, _Resource_handle, "f");
139
+ }
140
+ async close() {
141
+ const handle = __classPrivateFieldGet(this, _Resource_handle, "f");
142
+ if (handle === undefined)
143
+ return;
144
+ __classPrivateFieldSet(this, _Resource_handle, undefined, "f");
145
+ finalizer.unregister(this);
146
+ this.client.raw.drop(handle);
147
+ }
148
+ call(op, params = {}, options) { return this.client.call(this.handle, op, params, options); }
262
149
  }
263
- /**
264
- * All known sessions (RFC-0024).
265
- */
266
- function getSessions() {
267
- return JSON.parse(native.listSessions());
150
+ exports.Resource = Resource;
151
+ _Resource_handle = new WeakMap();
152
+ class Abort {
153
+ constructor(client, signal) { this.client = client; this.native = client.raw.abort(signal); }
154
+ get handle() { return this.native.handle; }
155
+ get aborted() { return this.native.aborted; }
156
+ signal() { this.native.signal(); }
157
+ close() { this.native.close(); }
268
158
  }
269
- /**
270
- * Generate text and return an OpenAI Chat Completion (non-streaming).
271
- *
272
- * Works with **any** provider — the result is always a standard OpenAI
273
- * `ChatCompletion` object.
274
- *
275
- * With {@link RepairToolCall | `repairToolCall`}, invalid calls are repaired
276
- * on the native result first and the completion is converted from it, so its
277
- * `tool_calls` carry the repaired arguments (a `ChatCompletion` has no
278
- * `invalid` marker to repair from).
279
- *
280
- * @example
281
- * ```ts
282
- * import { openai, generateTextAsOpenai } from 'aimux'
283
- * const model = await openai(apiKey, 'gpt-4o')
284
- * const completion = await generateTextAsOpenai(model, 'What is Rust?')
285
- * console.log(completion.choices[0].message.content)
286
- * ```
287
- */
288
- async function generateTextAsOpenai(model, prompt, options, signal) {
289
- const promptJson = JSON.stringify(prompt);
290
- const optsJson = options ? JSON.stringify(options) : undefined;
291
- const bridge = signal ? new native_ts_1.AbortBridge(signal) : undefined;
292
- if (options?.repairToolCall) {
293
- let resultJson = await model.generateText(promptJson, optsJson, bridge);
294
- resultJson = await repairResultJson(resultJson, promptJson, optsJson, options.repairToolCall);
295
- return JSON.parse(model.generateTextResultAsOpenai(resultJson));
159
+ exports.Abort = Abort;
160
+ class Provider extends Resource {
161
+ async model(modelId, method) {
162
+ return model(this.client, await this.call(ops.OP_PROVIDER_MODEL, { modelId, ...(method ? { method } : {}) }));
296
163
  }
297
- const resultJson = await model.generateTextAsOpenai(promptJson, optsJson, bridge);
298
- return JSON.parse(resultJson);
299
- }
300
- /**
301
- * Stream text as OpenAI Chat Completion chunks.
302
- *
303
- * Works with **any** provider — yields standard OpenAI `ChatCompletionChunk`
304
- * objects. Pass `streamOptions` via `providerOptions.openai.stream_options`:
305
- * `{ include_usage: true, include_reasoning: true }` (both default true).
306
- *
307
- * @example
308
- * ```ts
309
- * import { openai, streamTextAsOpenai } from 'aimux'
310
- * const model = await openai(apiKey, 'gpt-4o')
311
- * for await (const chunk of streamTextAsOpenai(model, 'Write a haiku.')) {
312
- * const delta = chunk.choices[0]?.delta?.content
313
- * if (delta) process.stdout.write(delta)
314
- * }
315
- * ```
316
- */
317
- async function* streamTextAsOpenai(model, prompt, options, signal) {
318
- const optsJson = options ? JSON.stringify(options) : undefined;
319
- const bridge = signal ? new native_ts_1.AbortBridge(signal) : undefined;
320
- const gen = await model.streamTextAsOpenai(JSON.stringify(prompt), optsJson, bridge);
321
- for await (const json of gen) {
322
- yield JSON.parse(json);
164
+ async invoke(method, call) { return this.call(ops.OP_PROVIDER_INVOKE, { method }, call); }
165
+ async files() { return new Files(this.client, handleRef(await this.call(ops.OP_PROVIDER_FILES), 'Files')); }
166
+ async wrap(language = [], image = []) {
167
+ return new Provider(this.client, await this.call(ops.OP_PROVIDER_WRAP, { languageModelMiddleware: language.map(value => value.handle), imageModelMiddleware: image.map(value => value.handle) }));
323
168
  }
324
169
  }
325
- // ─────────────────────────────────────────────────────────────────────────────
326
- // Provider handles (RFC-0027) — createProvider / listModels / model
327
- // ─────────────────────────────────────────────────────────────────────────────
328
- /**
329
- * A typed wrapper around the raw napi `ProviderHandle` class. Created by
330
- * {@link createProvider}, supports {@link ProviderHandleTyped.listModels} and
331
- * {@link ProviderHandleTyped.model}.
332
- *
333
- * @example
334
- * ```ts
335
- * import { createProvider, generateText } from 'aimux'
336
- * const p = await createProvider('deepseek', apiKey)
337
- * const models = await p.listModels()
338
- * const model = await p.model(models[0].id)
339
- * const result = await generateText(model, 'Hello')
340
- * ```
341
- */
342
- class ProviderHandleTyped {
343
- constructor(raw) {
344
- this.raw = raw;
170
+ exports.Provider = Provider;
171
+ class Registry extends Resource {
172
+ async provider(key) { return new Provider(this.client, await this.call(ops.OP_REGISTRY_PROVIDER, { key })); }
173
+ async resolve(modelRef) { return model(this.client, await this.call(ops.OP_MODEL_RESOLVE, { modelRef })); }
174
+ }
175
+ exports.Registry = Registry;
176
+ class Model extends Resource {
177
+ async info() { return this.call(ops.OP_MODEL_INFO); }
178
+ async wrap(middleware) {
179
+ return model(this.client, await this.call(ops.OP_MODEL_WRAP, { middleware: middleware.map(value => value.handle) }));
345
180
  }
346
- /** List models available on this provider (runtime discovery + anya2a spec). */
347
- async listModels() {
348
- return JSON.parse(await this.raw.listModels());
181
+ }
182
+ exports.Model = Model;
183
+ class LanguageModel extends Model {
184
+ async generate(prompt, options = {}, call) { return this.call(ops.OP_TEXT_GENERATE, { prompt, options }, call); }
185
+ async generateObject(params, call) { return this.call(ops.OP_TEXT_GENERATE_OBJECT, params, call); }
186
+ async consume(params, call) { return this.call(ops.OP_TEXT_CONSUME, params, call); }
187
+ async generateOpenAI(params, call) { return this.call(ops.OP_TEXT_GENERATE_OPEN_AI, params, call); }
188
+ async stream(prompt, options = {}, call) { return this.client.stream(this.handle, ops.OP_TEXT_STREAM, { prompt, options }, call); }
189
+ async streamOpenAI(params, call) { return this.client.stream(this.handle, ops.OP_TEXT_STREAM_OPEN_AI, params, call); }
190
+ }
191
+ exports.LanguageModel = LanguageModel;
192
+ class EmbeddingModel extends Model {
193
+ async embed(params, call) { return this.call(ops.OP_EMBEDDING_EMBED, params, call); }
194
+ async embedMany(params, call) { return this.call(ops.OP_EMBEDDING_EMBED_MANY, params, call); }
195
+ }
196
+ exports.EmbeddingModel = EmbeddingModel;
197
+ class ImageModel extends Model {
198
+ async generate(params, call) { return this.call(ops.OP_IMAGE_GENERATE, params, call); }
199
+ }
200
+ exports.ImageModel = ImageModel;
201
+ class SpeechModel extends Model {
202
+ async generate(params, call) { return this.call(ops.OP_SPEECH_GENERATE, params, call); }
203
+ }
204
+ exports.SpeechModel = SpeechModel;
205
+ class TranscriptionModel extends Model {
206
+ async generate(params, call) { return this.call(ops.OP_TRANSCRIPTION_GENERATE, params, call); }
207
+ async start(params, call) { return new Operation(this.client, handleRef(await this.call(ops.OP_TRANSCRIPTION_START, params, call), 'Operation')); }
208
+ }
209
+ exports.TranscriptionModel = TranscriptionModel;
210
+ class RerankingModel extends Model {
211
+ async rerank(params, call) { return this.call(ops.OP_RERANKING_RERANK, params, call); }
212
+ }
213
+ exports.RerankingModel = RerankingModel;
214
+ class VideoModel extends Model {
215
+ async generate(params, call) { return this.call(ops.OP_VIDEO_GENERATE, params, call); }
216
+ }
217
+ exports.VideoModel = VideoModel;
218
+ class SearchModel extends Model {
219
+ async search(params, call) { return this.call(ops.OP_SEARCH_SEARCH, params, call); }
220
+ }
221
+ exports.SearchModel = SearchModel;
222
+ class DecisionModel extends Model {
223
+ async decide(options, call) { return this.call(ops.OP_DECISION_DECIDE, { options }, call); }
224
+ async capabilities() { return this.call(ops.OP_DECISION_CAPABILITIES); }
225
+ }
226
+ exports.DecisionModel = DecisionModel;
227
+ class Files extends Resource {
228
+ async upload(params, call) { return this.call(ops.OP_FILES_UPLOAD, params, call); }
229
+ }
230
+ exports.Files = Files;
231
+ class Middleware extends Resource {
232
+ }
233
+ exports.Middleware = Middleware;
234
+ function handleRef(value, kind) {
235
+ return { handle: typeof value === 'string' ? value : value.handle, kind };
236
+ }
237
+ function model(client, ref) {
238
+ switch (ref.kind) {
239
+ case 'Language': return new LanguageModel(client, ref);
240
+ case 'Embedding': return new EmbeddingModel(client, ref);
241
+ case 'Image': return new ImageModel(client, ref);
242
+ case 'Speech': return new SpeechModel(client, ref);
243
+ case 'Transcription': return new TranscriptionModel(client, ref);
244
+ case 'Reranking': return new RerankingModel(client, ref);
245
+ case 'Video': return new VideoModel(client, ref);
246
+ case 'Search': return new SearchModel(client, ref);
247
+ case 'Decision': return new DecisionModel(client, ref);
248
+ default: throw (0, error_ts_1.protocolError)(304, 'InvalidState', `Invalid model kind: ${ref.kind}`);
349
249
  }
350
- /** Build a language model from a discovered model id. */
351
- async model(modelId) {
352
- return this.raw.model(modelId);
250
+ }
251
+ class Operation extends Resource {
252
+ async push(data) { await this.client.raw.operationPush(this.handle, data); }
253
+ async inputDone() { await this.call(ops.OP_OPERATION_INPUT_DONE); }
254
+ async next(timeoutMs = 1000) { return this.call(ops.OP_OPERATION_NEXT, { timeoutMs }); }
255
+ async status() { return this.call(ops.OP_OPERATION_STATUS); }
256
+ async cancel() { return this.call(ops.OP_OPERATION_CANCEL); }
257
+ events() {
258
+ const operation = this;
259
+ let ended = false;
260
+ return {
261
+ async next() {
262
+ if (ended)
263
+ return { done: true, value: undefined };
264
+ try {
265
+ for (;;) {
266
+ const next = await operation.next();
267
+ if (ended)
268
+ return { done: true, value: undefined };
269
+ if (next.type === 'part')
270
+ return { done: false, value: next.part };
271
+ if (next.type === 'ended') {
272
+ ended = true;
273
+ return { done: true, value: undefined };
274
+ }
275
+ }
276
+ }
277
+ catch (error) {
278
+ if (!(error instanceof error_ts_1.AimuxError && error.code === 303))
279
+ ended = true;
280
+ throw error;
281
+ }
282
+ },
283
+ async return() { ended = true; await operation.cancel(); return { done: true, value: undefined }; },
284
+ async throw(error) { ended = true; await operation.cancel(); throw error; },
285
+ [Symbol.asyncIterator]() { return this; },
286
+ };
353
287
  }
354
288
  }
355
- exports.ProviderHandleTyped = ProviderHandleTyped;
356
- /**
357
- * Create a **provider handle** (RFC-0027) for a registry-backed provider.
358
- *
359
- * Unlike `provider()` (which binds to a single modelId), this returns a handle
360
- * that supports `listModels()` (runtime discovery) and `model()`.
361
- *
362
- * @param name - Provider name (e.g. `"deepseek"`, `"groq"`).
363
- * @param apiKey - API key; omit/null to read the provider's env var.
364
- * @param config - Optional provider config (baseUrl, headers, …).
365
- *
366
- * @example
367
- * ```ts
368
- * import { createProvider, generateText } from 'aimux'
369
- * const p = await createProvider('deepseek', process.env.DEEPSEEK_API_KEY)
370
- * const models = await p.listModels()
371
- * const model = await p.model(models[0].id)
372
- * const result = await generateText(model, 'Hello')
373
- * ```
374
- */
375
- async function createProvider(name, apiKey, config) {
376
- const raw = await (0, native_ts_1.createProvider)(name, apiKey ?? null, config ?? null);
377
- return new ProviderHandleTyped(raw);
289
+ exports.Operation = Operation;
290
+ class TraceStore extends Resource {
291
+ async aggregate(filter = {}) { return this.call(ops.OP_TRACE_AGGREGATE, { filter }); }
292
+ async sessionChain(sessionId) { return this.call(ops.OP_TRACE_SESSION_CHAIN, { sessionId }); }
293
+ async sessionTrajectory(sessionId) { return this.call(ops.OP_TRACE_SESSION_TRAJECTORY, { sessionId }); }
294
+ async export() { return this.call(ops.OP_TRACE_EXPORT); }
295
+ async clear() { await this.call(ops.OP_TRACE_CLEAR); }
378
296
  }
379
- /**
380
- * Fetch the community model catalogue (anya2a). Returns a `Catalogue` object
381
- * with a `lookup(provider, modelId)` method. Thin fetch — no caching; the host
382
- * decides how to persist/reuse the result.
383
- *
384
- * @param sourceUrl - Optional URL override (default = anya2a endpoint).
385
- *
386
- * @example
387
- * ```ts
388
- * import { createProvider, getModelSpecs, generateText } from 'aimux'
389
- * const [p, catalogue] = await Promise.all([
390
- * createProvider('deepseek', apiKey),
391
- * getModelSpecs(),
392
- * ])
393
- * const models = await p.listModels()
394
- * const model = await p.model(models[0].id)
395
- * const spec = catalogue.specs?.['deepseek']?.[models[0].id] // community portrait
396
- * ```
397
- */
398
- async function getModelSpecs(sourceUrl) {
399
- return JSON.parse(await (0, native_ts_1.getModelSpecs)(sourceUrl ?? null));
297
+ exports.TraceStore = TraceStore;
298
+ class Recorder extends Resource {
299
+ async attach() { return this.call(ops.OP_RECORDER_ATTACH); }
300
+ async stop() { return this.call(ops.OP_RECORDER_STOP); }
301
+ async flush() { return this.call(ops.OP_RECORDER_FLUSH); }
302
+ async stats() { return this.call(ops.OP_RECORDER_STATS); }
303
+ async export() { return this.call(ops.OP_RECORDER_EXPORT); }
304
+ }
305
+ exports.Recorder = Recorder;
306
+ class SessionStore extends Resource {
307
+ async attach() { return this.call(ops.OP_SESSION_STORE_ATTACH); }
308
+ async list(params = {}) { return this.call(ops.OP_SESSION_STORE_LIST, params); }
309
+ async calls(sessionId) { return this.call(ops.OP_SESSION_STORE_CALLS, { sessionId }); }
310
+ }
311
+ exports.SessionStore = SessionStore;
312
+ class ReplaySession extends Resource {
313
+ async capabilities() { return this.call(ops.OP_REPLAY_CAPABILITIES); }
314
+ async inspect() { return this.call(ops.OP_REPLAY_INSPECT); }
315
+ async dryRun(params = {}) { return this.call(ops.OP_REPLAY_DRY_RUN, params); }
316
+ async live(params) { return this.call(ops.OP_REPLAY_LIVE, params); }
317
+ }
318
+ exports.ReplaySession = ReplaySession;
319
+ function mapIterator(inner, map, cancel) {
320
+ let ended = false;
321
+ return {
322
+ async next() {
323
+ if (ended)
324
+ return { done: true, value: undefined };
325
+ try {
326
+ const result = await inner.next();
327
+ if (ended || result.done) {
328
+ ended = true;
329
+ return { done: true, value: undefined };
330
+ }
331
+ return { done: false, value: map(result.value) };
332
+ }
333
+ catch (error) {
334
+ if (error instanceof error_ts_1.AimuxError && error.code === 303)
335
+ throw error;
336
+ ended = true;
337
+ cancel();
338
+ if (inner.return)
339
+ await inner.return().catch(() => { });
340
+ throw error;
341
+ }
342
+ },
343
+ async return() { ended = true; cancel(); if (inner.return)
344
+ await inner.return(); return { done: true, value: undefined }; },
345
+ async throw(error) { ended = true; cancel(); if (inner.return)
346
+ await inner.return(); throw error; },
347
+ [Symbol.asyncIterator]() { return this; },
348
+ };
349
+ }
350
+ /** A pull source with zero prefetch; reader.cancel() immediately invokes return(). */
351
+ function readable(iterator) {
352
+ return new ReadableStream({
353
+ async pull(controller) {
354
+ try {
355
+ const result = await iterator.next();
356
+ if (result.done)
357
+ controller.close();
358
+ else
359
+ controller.enqueue(result.value);
360
+ }
361
+ catch (error) {
362
+ controller.error(error);
363
+ if (iterator.return)
364
+ await iterator.return().catch(() => { });
365
+ }
366
+ },
367
+ async cancel() { if (iterator.return)
368
+ await iterator.return(); },
369
+ }, { highWaterMark: 0 });
400
370
  }