@arcships/aimux 0.5.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.
- package/README.md +92 -0
- package/dist/error.d.ts +28 -137
- package/dist/error.js +71 -100
- package/dist/generated/ops.d.ts +75 -0
- package/dist/generated/ops.js +80 -0
- package/dist/generated/types.d.ts +5607 -0
- package/dist/{types/CallOptions.js → generated/types.js} +1 -0
- package/dist/index.d.ts +144 -211
- package/dist/index.js +314 -344
- package/dist/native.d.ts +29 -1
- package/dist/native.js +99 -29
- package/dist/types.d.ts +1 -144
- package/dist/types.js +0 -3
- package/index.d.ts +21 -545
- package/index.js +57 -112
- package/package.json +16 -13
- package/dist/types/AiMuxError.d.ts +0 -66
- package/dist/types/AiMuxError.js +0 -2
- package/dist/types/ApiCallError.d.ts +0 -75
- package/dist/types/ApiCallError.js +0 -2
- package/dist/types/AspectRatio.d.ts +0 -11
- package/dist/types/AspectRatio.js +0 -3
- package/dist/types/AudioChunk.d.ts +0 -8
- package/dist/types/AudioChunk.js +0 -3
- package/dist/types/AudioData.d.ts +0 -11
- package/dist/types/AudioData.js +0 -3
- package/dist/types/AudioInput.d.ts +0 -8
- package/dist/types/AudioInput.js +0 -3
- package/dist/types/BreakKind.d.ts +0 -1
- package/dist/types/BreakKind.js +0 -3
- package/dist/types/CallOptions.d.ts +0 -117
- package/dist/types/CatalogueSource.d.ts +0 -4
- package/dist/types/CatalogueSource.js +0 -3
- package/dist/types/ChatCompletion.d.ts +0 -16
- package/dist/types/ChatCompletion.js +0 -2
- package/dist/types/ChatCompletionChoice.d.ts +0 -8
- package/dist/types/ChatCompletionChoice.js +0 -2
- package/dist/types/ChatCompletionChunk.d.ts +0 -15
- package/dist/types/ChatCompletionChunk.js +0 -2
- package/dist/types/ChatCompletionChunkChoice.d.ts +0 -8
- package/dist/types/ChatCompletionChunkChoice.js +0 -2
- package/dist/types/ChatCompletionChunkFunction.d.ts +0 -4
- package/dist/types/ChatCompletionChunkFunction.js +0 -3
- package/dist/types/ChatCompletionChunkToolCall.d.ts +0 -7
- package/dist/types/ChatCompletionChunkToolCall.js +0 -2
- package/dist/types/ChatCompletionDelta.d.ts +0 -7
- package/dist/types/ChatCompletionDelta.js +0 -2
- package/dist/types/ChatCompletionFunction.d.ts +0 -4
- package/dist/types/ChatCompletionFunction.js +0 -3
- package/dist/types/ChatCompletionMessage.d.ts +0 -9
- package/dist/types/ChatCompletionMessage.js +0 -2
- package/dist/types/ChatCompletionToolCall.d.ts +0 -6
- package/dist/types/ChatCompletionToolCall.js +0 -2
- package/dist/types/ChatCompletionUsage.d.ts +0 -9
- package/dist/types/ChatCompletionUsage.js +0 -2
- package/dist/types/CompletionTokensDetails.d.ts +0 -3
- package/dist/types/CompletionTokensDetails.js +0 -3
- package/dist/types/ContentPart.d.ts +0 -112
- package/dist/types/ContentPart.js +0 -2
- package/dist/types/EmbeddingCallOptions.d.ts +0 -33
- package/dist/types/EmbeddingCallOptions.js +0 -2
- package/dist/types/EmbeddingResponse.d.ts +0 -16
- package/dist/types/EmbeddingResponse.js +0 -2
- package/dist/types/EmbeddingResult.d.ts +0 -33
- package/dist/types/EmbeddingResult.js +0 -2
- package/dist/types/EmbeddingUsage.d.ts +0 -9
- package/dist/types/EmbeddingUsage.js +0 -3
- package/dist/types/FileBytes.d.ts +0 -12
- package/dist/types/FileBytes.js +0 -3
- package/dist/types/FileData.d.ts +0 -25
- package/dist/types/FileData.js +0 -2
- package/dist/types/FilePart.d.ts +0 -8
- package/dist/types/FilePart.js +0 -2
- package/dist/types/Fingerprint.d.ts +0 -21
- package/dist/types/Fingerprint.js +0 -3
- package/dist/types/FinishReason.d.ts +0 -14
- package/dist/types/FinishReason.js +0 -2
- package/dist/types/FinishReasonUnified.d.ts +0 -4
- package/dist/types/FinishReasonUnified.js +0 -3
- package/dist/types/FunctionTool.d.ts +0 -35
- package/dist/types/FunctionTool.js +0 -2
- package/dist/types/GenerateContent.d.ts +0 -88
- package/dist/types/GenerateContent.js +0 -2
- package/dist/types/GenerateObjectResult.d.ts +0 -48
- package/dist/types/GenerateObjectResult.js +0 -2
- package/dist/types/GenerateResult.d.ts +0 -45
- package/dist/types/GenerateResult.js +0 -2
- package/dist/types/GenerateTextOptions.d.ts +0 -62
- package/dist/types/GenerateTextOptions.js +0 -2
- package/dist/types/GenerateTextResult.d.ts +0 -81
- package/dist/types/GenerateTextResult.js +0 -2
- package/dist/types/HttpExchange.d.ts +0 -34
- package/dist/types/HttpExchange.js +0 -2
- package/dist/types/HttpRecord.d.ts +0 -12
- package/dist/types/HttpRecord.js +0 -3
- package/dist/types/ImageCallOptions.d.ts +0 -63
- package/dist/types/ImageCallOptions.js +0 -2
- package/dist/types/ImageFile.d.ts +0 -25
- package/dist/types/ImageFile.js +0 -2
- package/dist/types/ImageFileData.d.ts +0 -8
- package/dist/types/ImageFileData.js +0 -3
- package/dist/types/ImageOutputs.d.ts +0 -14
- package/dist/types/ImageOutputs.js +0 -3
- package/dist/types/ImageResponse.d.ts +0 -19
- package/dist/types/ImageResponse.js +0 -3
- package/dist/types/ImageResult.d.ts +0 -34
- package/dist/types/ImageResult.js +0 -2
- package/dist/types/ImageUsage.d.ts +0 -19
- package/dist/types/ImageUsage.js +0 -3
- package/dist/types/InputAudioFormat.d.ts +0 -13
- package/dist/types/InputAudioFormat.js +0 -3
- package/dist/types/InputRecord.d.ts +0 -16
- package/dist/types/InputRecord.js +0 -2
- package/dist/types/LanguageModelPromptMessage.d.ts +0 -20
- package/dist/types/LanguageModelPromptMessage.js +0 -2
- package/dist/types/MessageContent.d.ts +0 -5
- package/dist/types/MessageContent.js +0 -2
- package/dist/types/Modality.d.ts +0 -4
- package/dist/types/Modality.js +0 -3
- package/dist/types/ModelCapabilities.d.ts +0 -21
- package/dist/types/ModelCapabilities.js +0 -3
- package/dist/types/ModelCost.d.ts +0 -10
- package/dist/types/ModelCost.js +0 -3
- package/dist/types/ModelId.d.ts +0 -7
- package/dist/types/ModelId.js +0 -3
- package/dist/types/ModelLimits.d.ts +0 -17
- package/dist/types/ModelLimits.js +0 -3
- package/dist/types/ModelMessage.d.ts +0 -9
- package/dist/types/ModelMessage.js +0 -2
- package/dist/types/ModelModalities.d.ts +0 -8
- package/dist/types/ModelModalities.js +0 -2
- package/dist/types/ModelPrompt.d.ts +0 -7
- package/dist/types/ModelPrompt.js +0 -2
- package/dist/types/ModelSpec.d.ts +0 -33
- package/dist/types/ModelSpec.js +0 -2
- package/dist/types/ModelType.d.ts +0 -4
- package/dist/types/ModelType.js +0 -3
- package/dist/types/OutcomeRecord.d.ts +0 -19
- package/dist/types/OutcomeRecord.js +0 -2
- package/dist/types/OutcomeStatus.d.ts +0 -4
- package/dist/types/OutcomeStatus.js +0 -3
- package/dist/types/PrefixBreak.d.ts +0 -11
- package/dist/types/PrefixBreak.js +0 -2
- package/dist/types/PromptTokensDetails.d.ts +0 -4
- package/dist/types/PromptTokensDetails.js +0 -3
- package/dist/types/ProviderAuditSpec.d.ts +0 -33
- package/dist/types/ProviderAuditSpec.js +0 -2
- package/dist/types/ProviderFamily.d.ts +0 -5
- package/dist/types/ProviderFamily.js +0 -3
- package/dist/types/ProviderName.d.ts +0 -258
- package/dist/types/ProviderName.js +0 -262
- package/dist/types/ProviderRecord.d.ts +0 -30
- package/dist/types/ProviderRecord.js +0 -2
- package/dist/types/ProviderTool.d.ts +0 -24
- package/dist/types/ProviderTool.js +0 -2
- package/dist/types/RawToolCall.d.ts +0 -16
- package/dist/types/RawToolCall.js +0 -2
- package/dist/types/ReasoningEffort.d.ts +0 -7
- package/dist/types/ReasoningEffort.js +0 -3
- package/dist/types/ReasoningMode.d.ts +0 -4
- package/dist/types/ReasoningMode.js +0 -3
- package/dist/types/ReasoningPart.d.ts +0 -9
- package/dist/types/ReasoningPart.js +0 -3
- package/dist/types/ReasoningSpec.d.ts +0 -39
- package/dist/types/ReasoningSpec.js +0 -2
- package/dist/types/ReasoningVisibility.d.ts +0 -4
- package/dist/types/ReasoningVisibility.js +0 -3
- package/dist/types/Recording.d.ts +0 -56
- package/dist/types/Recording.js +0 -2
- package/dist/types/RequestCacheHints.d.ts +0 -9
- package/dist/types/RequestCacheHints.js +0 -3
- package/dist/types/RequestInfo.d.ts +0 -12
- package/dist/types/RequestInfo.js +0 -2
- package/dist/types/RerankingCallOptions.d.ts +0 -42
- package/dist/types/RerankingCallOptions.js +0 -2
- package/dist/types/RerankingDocuments.d.ts +0 -15
- package/dist/types/RerankingDocuments.js +0 -2
- package/dist/types/RerankingRank.d.ts +0 -13
- package/dist/types/RerankingRank.js +0 -3
- package/dist/types/RerankingResponse.d.ts +0 -28
- package/dist/types/RerankingResponse.js +0 -2
- package/dist/types/RerankingResult.d.ts +0 -31
- package/dist/types/RerankingResult.js +0 -2
- package/dist/types/ResponseFormat.d.ts +0 -11
- package/dist/types/ResponseFormat.js +0 -2
- package/dist/types/ResponseInfo.d.ts +0 -30
- package/dist/types/ResponseInfo.js +0 -2
- package/dist/types/ResponseMetadata.d.ts +0 -8
- package/dist/types/ResponseMetadata.js +0 -3
- package/dist/types/ResponseRecord.d.ts +0 -13
- package/dist/types/ResponseRecord.js +0 -3
- package/dist/types/RetryError.d.ts +0 -9
- package/dist/types/RetryError.js +0 -2
- package/dist/types/RetryErrorReason.d.ts +0 -4
- package/dist/types/RetryErrorReason.js +0 -3
- package/dist/types/Role.d.ts +0 -4
- package/dist/types/Role.js +0 -3
- package/dist/types/RuntimeModel.d.ts +0 -22
- package/dist/types/RuntimeModel.js +0 -3
- package/dist/types/SearchCallOptions.d.ts +0 -55
- package/dist/types/SearchCallOptions.js +0 -2
- package/dist/types/SearchResponse.d.ts +0 -16
- package/dist/types/SearchResponse.js +0 -2
- package/dist/types/SearchResult.d.ts +0 -32
- package/dist/types/SearchResult.js +0 -2
- package/dist/types/SearchResultItem.d.ts +0 -33
- package/dist/types/SearchResultItem.js +0 -2
- package/dist/types/SessionCall.d.ts +0 -20
- package/dist/types/SessionCall.js +0 -3
- package/dist/types/SessionChainView.d.ts +0 -10
- package/dist/types/SessionChainView.js +0 -2
- package/dist/types/SessionSource.d.ts +0 -4
- package/dist/types/SessionSource.js +0 -3
- package/dist/types/SessionStepStat.d.ts +0 -27
- package/dist/types/SessionStepStat.js +0 -2
- package/dist/types/SessionView.d.ts +0 -16
- package/dist/types/SessionView.js +0 -2
- package/dist/types/Size.d.ts +0 -11
- package/dist/types/Size.js +0 -3
- package/dist/types/SourcePart.d.ts +0 -9
- package/dist/types/SourcePart.js +0 -3
- package/dist/types/SpeechCallOptions.d.ts +0 -56
- package/dist/types/SpeechCallOptions.js +0 -2
- package/dist/types/SpeechRequest.d.ts +0 -10
- package/dist/types/SpeechRequest.js +0 -2
- package/dist/types/SpeechResponse.d.ts +0 -24
- package/dist/types/SpeechResponse.js +0 -2
- package/dist/types/SpeechResult.d.ts +0 -34
- package/dist/types/SpeechResult.js +0 -2
- package/dist/types/StreamPart.d.ts +0 -173
- package/dist/types/StreamPart.js +0 -2
- package/dist/types/StreamTextResultAggregated.d.ts +0 -74
- package/dist/types/StreamTextResultAggregated.js +0 -2
- package/dist/types/TimeoutConfiguration.d.ts +0 -32
- package/dist/types/TimeoutConfiguration.js +0 -3
- package/dist/types/TimingRecord.d.ts +0 -7
- package/dist/types/TimingRecord.js +0 -3
- package/dist/types/TokenUsage.d.ts +0 -29
- package/dist/types/TokenUsage.js +0 -3
- package/dist/types/Tool.d.ts +0 -12
- package/dist/types/Tool.js +0 -2
- package/dist/types/ToolCall.d.ts +0 -48
- package/dist/types/ToolCall.js +0 -2
- package/dist/types/ToolCallRepairReply.d.ts +0 -19
- package/dist/types/ToolCallRepairReply.js +0 -2
- package/dist/types/ToolChoice.d.ts +0 -12
- package/dist/types/ToolChoice.js +0 -3
- package/dist/types/ToolResult.d.ts +0 -22
- package/dist/types/ToolResult.js +0 -2
- package/dist/types/TraceFilter.d.ts +0 -9
- package/dist/types/TraceFilter.js +0 -3
- package/dist/types/TraceRecord.d.ts +0 -54
- package/dist/types/TraceRecord.js +0 -2
- package/dist/types/TraceStats.d.ts +0 -20
- package/dist/types/TraceStats.js +0 -3
- package/dist/types/TranscriptionCallOptions.d.ts +0 -38
- package/dist/types/TranscriptionCallOptions.js +0 -2
- package/dist/types/TranscriptionRequest.d.ts +0 -9
- package/dist/types/TranscriptionRequest.js +0 -3
- package/dist/types/TranscriptionResponse.d.ts +0 -24
- package/dist/types/TranscriptionResponse.js +0 -2
- package/dist/types/TranscriptionResult.d.ts +0 -46
- package/dist/types/TranscriptionResult.js +0 -2
- package/dist/types/TranscriptionSegment.d.ts +0 -17
- package/dist/types/TranscriptionSegment.js +0 -3
- package/dist/types/TranscriptionStreamPart.d.ts +0 -70
- package/dist/types/TranscriptionStreamPart.js +0 -2
- package/dist/types/UploadFileCallOptions.d.ts +0 -27
- package/dist/types/UploadFileCallOptions.js +0 -2
- package/dist/types/UploadFileData.d.ts +0 -17
- package/dist/types/UploadFileData.js +0 -2
- package/dist/types/UploadFileResult.d.ts +0 -35
- package/dist/types/UploadFileResult.js +0 -2
- package/dist/types/Usage.d.ts +0 -13
- package/dist/types/Usage.js +0 -2
- package/dist/types/UsageSnapshot.d.ts +0 -18
- package/dist/types/UsageSnapshot.js +0 -2
- package/dist/types/Verdict.d.ts +0 -23
- package/dist/types/Verdict.js +0 -2
- package/dist/types/VerdictConfidence.d.ts +0 -4
- package/dist/types/VerdictConfidence.js +0 -3
- package/dist/types/VerdictKind.d.ts +0 -4
- package/dist/types/VerdictKind.js +0 -3
- package/dist/types/VideoCallOptions.d.ts +0 -84
- package/dist/types/VideoCallOptions.js +0 -2
- package/dist/types/VideoData.d.ts +0 -22
- package/dist/types/VideoData.js +0 -3
- package/dist/types/VideoFile.d.ts +0 -29
- package/dist/types/VideoFile.js +0 -2
- package/dist/types/VideoFileData.d.ts +0 -8
- package/dist/types/VideoFileData.js +0 -3
- package/dist/types/VideoFrameImage.d.ts +0 -17
- package/dist/types/VideoFrameImage.js +0 -2
- package/dist/types/VideoFrameType.d.ts +0 -6
- package/dist/types/VideoFrameType.js +0 -3
- package/dist/types/VideoPollOptions.d.ts +0 -13
- package/dist/types/VideoPollOptions.js +0 -3
- package/dist/types/VideoResponse.d.ts +0 -19
- package/dist/types/VideoResponse.js +0 -3
- package/dist/types/VideoResult.d.ts +0 -29
- package/dist/types/VideoResult.js +0 -2
- package/dist/types/Warning.d.ts +0 -23
- package/dist/types/Warning.js +0 -3
- package/dist/types/serde_json/JsonValue.d.ts +0 -3
- 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.
|
|
50
|
-
exports.
|
|
51
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
150
|
-
|
|
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 (
|
|
153
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
async
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
*/
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
298
|
-
return
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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.
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
async
|
|
399
|
-
|
|
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
|
}
|