@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/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 raw napi API (`index.js` / `index.d.ts`, auto-generated) is untouched.
14
- // This is purely an extra TypeScript 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,307 +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.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.mockReplay = exports.listSessions = exports.sessionCalls = exports.initSessionInfer = exports.initSessionStore = exports.initLogging = exports.AbortBridge = exports.StreamTextGenerator = exports.Model = exports.withAimuxError = exports.OtherError = exports.RequestAbortedError = exports.TimeoutError = exports.NoSuchProviderError = exports.NoSuchModelError = exports.UnsupportedFunctionalityError = exports.TokenExpiredError = exports.InvalidPromptError = exports.InvalidArgumentError = exports.ToolError = exports.InvalidResponseDataError = exports.JSONParseError = 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("../index.js"));
59
- const index_js_1 = require("../index.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, "JSONParseError", { enumerable: true, get: function () { return error_ts_1.JSONParseError; } });
65
- Object.defineProperty(exports, "InvalidResponseDataError", { enumerable: true, get: function () { return error_ts_1.InvalidResponseDataError; } });
66
- Object.defineProperty(exports, "ToolError", { enumerable: true, get: function () { return error_ts_1.ToolError; } });
67
- Object.defineProperty(exports, "InvalidArgumentError", { enumerable: true, get: function () { return error_ts_1.InvalidArgumentError; } });
68
- Object.defineProperty(exports, "InvalidPromptError", { enumerable: true, get: function () { return error_ts_1.InvalidPromptError; } });
69
- Object.defineProperty(exports, "TokenExpiredError", { enumerable: true, get: function () { return error_ts_1.TokenExpiredError; } });
70
- Object.defineProperty(exports, "UnsupportedFunctionalityError", { enumerable: true, get: function () { return error_ts_1.UnsupportedFunctionalityError; } });
71
- Object.defineProperty(exports, "NoSuchModelError", { enumerable: true, get: function () { return error_ts_1.NoSuchModelError; } });
72
- Object.defineProperty(exports, "NoSuchProviderError", { enumerable: true, get: function () { return error_ts_1.NoSuchProviderError; } });
73
- Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return error_ts_1.TimeoutError; } });
74
- Object.defineProperty(exports, "RequestAbortedError", { enumerable: true, get: function () { return error_ts_1.RequestAbortedError; } });
75
- Object.defineProperty(exports, "OtherError", { enumerable: true, get: function () { return error_ts_1.OtherError; } });
76
- Object.defineProperty(exports, "withAimuxError", { enumerable: true, get: function () { return error_ts_1.withAimuxError; } });
77
- const error_ts_2 = require("./error.js");
78
- // Re-export the raw napi constructors/factories so consumers can do everything
79
- // from a single import: `import { openai, generateText } from 'aimux'`.
80
- // Rust fn names are snake_case; napi-rs exposes them camelCased (like
81
- // `init_logging` → `initLogging`).
82
- //
83
- // Infallible items (classes + void initializers) pass through untouched.
84
- var index_js_2 = require("../index.js");
85
- Object.defineProperty(exports, "Model", { enumerable: true, get: function () { return index_js_2.Model; } });
86
- Object.defineProperty(exports, "StreamTextGenerator", { enumerable: true, get: function () { return index_js_2.StreamTextGenerator; } });
87
- Object.defineProperty(exports, "AbortBridge", { enumerable: true, get: function () { return index_js_2.AbortBridge; } });
88
- Object.defineProperty(exports, "initLogging", { enumerable: true, get: function () { return index_js_2.initLogging; } });
89
- Object.defineProperty(exports, "initSessionStore", { enumerable: true, get: function () { return index_js_2.initSessionStore; } });
90
- Object.defineProperty(exports, "initSessionInfer", { enumerable: true, get: function () { return index_js_2.initSessionInfer; } });
91
- // Fallible raw functions are wrapped so their throws are typed `AimuxError`
92
- // subclasses (`instanceof` works); generic wrappers preserve the signatures.
93
- function wrapSync(fn) {
94
- return (...args) => {
95
- try {
96
- return fn(...args);
97
- }
98
- catch (e) {
99
- throw error_ts_2.AimuxError.fromNative(e);
100
- }
101
- };
102
- }
103
- function wrapAsync(fn) {
104
- return (...args) => (0, error_ts_2.withAimuxError)(() => fn(...args));
105
- }
106
- exports.sessionCalls = wrapSync(native.sessionCalls);
107
- exports.listSessions = wrapSync(native.listSessions);
108
- exports.mockReplay = wrapSync(native.mockReplay);
109
- exports.router = wrapSync(native.router);
110
- exports.moa = wrapSync(native.moa);
111
- exports.openai = wrapAsync(native.openai);
112
- exports.anthropic = wrapAsync(native.anthropic);
113
- exports.deepseek = wrapAsync(native.deepseek);
114
- exports.google = wrapAsync(native.google);
115
- exports.cohere = wrapAsync(native.cohere);
116
- exports.mistral = wrapAsync(native.mistral);
117
- exports.xai = wrapAsync(native.xai);
118
- exports.bedrock = wrapAsync(native.bedrock);
119
- exports.vertex = wrapAsync(native.vertex);
120
- exports.anthropicAws = wrapAsync(native.anthropicAws);
121
- exports.azure = wrapAsync(native.azure);
122
- exports.provider = wrapAsync(native.provider);
123
- // Both meanings: the `ProviderName` const object (runtime, for `ProviderName.groq`)
124
- // and the derived string-union type. A value export resolves at runtime, so the
125
- // specifier needs the real `.ts` extension for Node's type-stripping test runs;
126
- // tsc rewrites it to `.js` on emit (rewriteRelativeImportExtensions).
127
- var ProviderName_ts_1 = require("./types/ProviderName.js");
128
- Object.defineProperty(exports, "ProviderName", { enumerable: true, get: function () { return ProviderName_ts_1.ProviderName; } });
129
- /**
130
- * Generate text (non-streaming). Returns a typed {@link GenerateTextResult}.
131
- *
132
- * @param model - A raw model instance from `openai()`, `anthropic()`, etc.
133
- * @param prompt - A plain string or an array of typed chat messages.
134
- * @param options - Optional typed generation options (tools, tool_choice,
135
- * temperature, response_format, …).
136
- * @param signal - Optional `AbortSignal`; aborting it cancels the call.
137
- *
138
- * Internally calls the raw
139
- * `model.generateText(JSON.stringify(prompt), options ? JSON.stringify(options) : undefined)`
140
- * and `JSON.parse`s the returned JSON into a typed object.
141
- *
142
- * @example
143
- * ```ts
144
- * import { openai, generateText } from 'aimux'
145
- * const model = await openai(apiKey, 'gpt-4o')
146
- * const result = await generateText(model, 'What is Rust?')
147
- * console.log(result.text, result.usage)
148
- * ```
149
- */
150
- async function generateText(model, prompt, options, signal) {
151
- return (0, error_ts_2.withAimuxError)(async () => {
152
- const optsJson = options ? JSON.stringify(options) : undefined;
153
- const bridge = signal ? new index_js_1.AbortBridge(signal) : undefined;
154
- const resultJson = await model.generateText(JSON.stringify(prompt), optsJson, bridge);
155
- return JSON.parse(resultJson);
156
- });
157
- }
158
- /**
159
- * Stream text from a model. Yields typed {@link StreamPart}s.
160
- *
161
- * @param model - A raw model instance from `openai()`, `anthropic()`, etc.
162
- * @param prompt - A plain string or an array of typed chat messages.
163
- * @param options - Optional typed generation options (tools, tool_choice, …).
164
- * @param signal - Optional `AbortSignal`; aborting it cancels the stream.
165
- *
166
- * Internally drives the raw `model.streamText(JSON.stringify(prompt), …)`
167
- * async generator and `JSON.parse`s each JSON-string chunk before yielding it
168
- * as a typed `StreamPart`.
169
- *
170
- * @example
171
- * ```ts
172
- * import { openai, streamText } from 'aimux'
173
- * const model = await openai(apiKey, 'gpt-4o')
174
- * for await (const part of streamText(model, 'Write a haiku about Rust.')) {
175
- * if ('TextDelta' in part) process.stdout.write(part.TextDelta.delta)
176
- * }
177
- * ```
178
- */
179
- async function* streamText(model, prompt, options, signal) {
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"));
54
+ const native_ts_1 = require("./native.js");
55
+ const error_ts_1 = require("./error.js");
56
+ __exportStar(require("./error.js"), exports);
57
+ function json(value) {
180
58
  try {
181
- const optsJson = options ? JSON.stringify(options) : undefined;
182
- const bridge = signal ? new index_js_1.AbortBridge(signal) : undefined;
183
- const gen = await model.streamText(JSON.stringify(prompt), optsJson, bridge);
184
- for await (const json of gen) {
185
- yield JSON.parse(json);
186
- }
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;
187
67
  }
188
- catch (e) {
189
- throw error_ts_2.AimuxError.fromNative(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;
190
74
  }
191
75
  }
192
- /**
193
- * All calls of a session, ordered by step (RFC-0024). Empty if the session
194
- * is unknown or no store is registered.
195
- *
196
- * `initSessionStore()` / `initSessionInfer(enabled)` (raw napi, re-exported
197
- * above) must be called first to register the store / opt-in inferer.
198
- */
199
- function getSessionCalls(sessionId) {
200
- try {
201
- return JSON.parse(native.sessionCalls(sessionId));
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));
84
+ }
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());
202
89
  }
203
- catch (e) {
204
- throw error_ts_2.AimuxError.fromNative(e);
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;
95
+ }
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 }));
205
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')); }
206
118
  }
207
- /**
208
- * All known sessions (RFC-0024).
209
- */
210
- function getSessions() {
119
+ exports.Client = Client;
120
+ // Finalization is a fallback. Explicit close/flush remains the normal protocol.
121
+ const finalizer = new FinalizationRegistry(held => {
211
122
  try {
212
- return JSON.parse(native.listSessions());
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");
213
139
  }
214
- catch (e) {
215
- throw error_ts_2.AimuxError.fromNative(e);
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);
216
147
  }
148
+ call(op, params = {}, options) { return this.client.call(this.handle, op, params, options); }
217
149
  }
218
- /**
219
- * Generate text and return an OpenAI Chat Completion (non-streaming).
220
- *
221
- * Works with **any** provider — the result is always a standard OpenAI
222
- * `ChatCompletion` object.
223
- *
224
- * @example
225
- * ```ts
226
- * import { openai, generateTextAsOpenai } from 'aimux'
227
- * const model = await openai(apiKey, 'gpt-4o')
228
- * const completion = await generateTextAsOpenai(model, 'What is Rust?')
229
- * console.log(completion.choices[0].message.content)
230
- * ```
231
- */
232
- async function generateTextAsOpenai(model, prompt, options, signal) {
233
- return (0, error_ts_2.withAimuxError)(async () => {
234
- const optsJson = options ? JSON.stringify(options) : undefined;
235
- const bridge = signal ? new index_js_1.AbortBridge(signal) : undefined;
236
- const resultJson = await model.generateTextAsOpenai(JSON.stringify(prompt), optsJson, bridge);
237
- return JSON.parse(resultJson);
238
- });
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(); }
239
158
  }
240
- /**
241
- * Stream text as OpenAI Chat Completion chunks.
242
- *
243
- * Works with **any** provider — yields standard OpenAI `ChatCompletionChunk`
244
- * objects. Pass `streamOptions` via `providerOptions.openai.stream_options`:
245
- * `{ include_usage: true, include_reasoning: true }` (both default true).
246
- *
247
- * @example
248
- * ```ts
249
- * import { openai, streamTextAsOpenai } from 'aimux'
250
- * const model = await openai(apiKey, 'gpt-4o')
251
- * for await (const chunk of streamTextAsOpenai(model, 'Write a haiku.')) {
252
- * const delta = chunk.choices[0]?.delta?.content
253
- * if (delta) process.stdout.write(delta)
254
- * }
255
- * ```
256
- */
257
- async function* streamTextAsOpenai(model, prompt, options, signal) {
258
- try {
259
- const optsJson = options ? JSON.stringify(options) : undefined;
260
- const bridge = signal ? new index_js_1.AbortBridge(signal) : undefined;
261
- const gen = await model.streamTextAsOpenai(JSON.stringify(prompt), optsJson, bridge);
262
- for await (const json of gen) {
263
- yield JSON.parse(json);
264
- }
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 } : {}) }));
265
163
  }
266
- catch (e) {
267
- throw error_ts_2.AimuxError.fromNative(e);
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) }));
268
168
  }
269
169
  }
270
- // ─────────────────────────────────────────────────────────────────────────────
271
- // Provider handles (RFC-0027) — createProvider / listModels / model
272
- // ─────────────────────────────────────────────────────────────────────────────
273
- /**
274
- * A typed wrapper around the raw napi `ProviderHandle` class. Created by
275
- * {@link createProvider}, supports {@link ProviderHandleTyped.listModels} and
276
- * {@link ProviderHandleTyped.model}.
277
- *
278
- * @example
279
- * ```ts
280
- * import { createProvider, generateText } from 'aimux'
281
- * const p = await createProvider('deepseek', apiKey)
282
- * const models = await p.listModels()
283
- * const model = await p.model(models[0].id)
284
- * const result = await generateText(model, 'Hello')
285
- * ```
286
- */
287
- class ProviderHandleTyped {
288
- constructor(raw) {
289
- 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) }));
290
180
  }
291
- /** List models available on this provider (runtime discovery + anya2a spec). */
292
- async listModels() {
293
- return (0, error_ts_2.withAimuxError)(async () => {
294
- return JSON.parse(await this.raw.listModels());
295
- });
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}`);
296
249
  }
297
- /** Build a language model from a discovered model id. */
298
- async model(modelId) {
299
- return (0, error_ts_2.withAimuxError)(() => 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
+ };
300
287
  }
301
288
  }
302
- exports.ProviderHandleTyped = ProviderHandleTyped;
303
- /**
304
- * Create a **provider handle** (RFC-0027) for a registry-backed provider.
305
- *
306
- * Unlike `provider()` (which binds to a single modelId), this returns a handle
307
- * that supports `listModels()` (runtime discovery) and `model()`.
308
- *
309
- * @param name - Provider name (e.g. `"deepseek"`, `"groq"`).
310
- * @param apiKey - API key; omit/null to read the provider's env var.
311
- * @param config - Optional provider config (baseUrl, headers, …).
312
- *
313
- * @example
314
- * ```ts
315
- * import { createProvider, generateText } from 'aimux'
316
- * const p = await createProvider('deepseek', process.env.DEEPSEEK_API_KEY)
317
- * const models = await p.listModels()
318
- * const model = await p.model(models[0].id)
319
- * const result = await generateText(model, 'Hello')
320
- * ```
321
- */
322
- async function createProvider(name, apiKey, config) {
323
- return (0, error_ts_2.withAimuxError)(async () => {
324
- const raw = await (0, index_js_1.createProvider)(name, apiKey ?? null, config ?? null);
325
- return new ProviderHandleTyped(raw);
326
- });
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); }
296
+ }
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
+ };
327
349
  }
328
- /**
329
- * Fetch the community model catalogue (anya2a). Returns a `Catalogue` object
330
- * with a `lookup(provider, modelId)` method. Thin fetch — no caching; the host
331
- * decides how to persist/reuse the result.
332
- *
333
- * @param sourceUrl - Optional URL override (default = anya2a endpoint).
334
- *
335
- * @example
336
- * ```ts
337
- * import { createProvider, getModelSpecs, generateText } from 'aimux'
338
- * const [p, catalogue] = await Promise.all([
339
- * createProvider('deepseek', apiKey),
340
- * getModelSpecs(),
341
- * ])
342
- * const models = await p.listModels()
343
- * const model = await p.model(models[0].id)
344
- * const spec = catalogue.specs?.['deepseek']?.[models[0].id] // community portrait
345
- * ```
346
- */
347
- async function getModelSpecs(sourceUrl) {
348
- return (0, error_ts_2.withAimuxError)(async () => {
349
- return JSON.parse(await (0, index_js_1.getModelSpecs)(sourceUrl ?? null));
350
- });
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 });
351
370
  }