@arcships/aimux 0.2.1 → 0.5.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 (167) hide show
  1. package/dist/error.d.ts +139 -0
  2. package/dist/error.js +114 -0
  3. package/dist/index.d.ts +162 -8
  4. package/dist/index.js +334 -28
  5. package/dist/native.d.ts +2 -0
  6. package/dist/native.js +46 -0
  7. package/dist/types/AiMuxError.d.ts +45 -13
  8. package/dist/types/AiMuxError.js +0 -1
  9. package/dist/types/ApiCallError.d.ts +75 -0
  10. package/dist/types/ApiCallError.js +2 -0
  11. package/dist/types/BreakKind.d.ts +1 -0
  12. package/dist/types/BreakKind.js +3 -0
  13. package/dist/types/CallOptions.d.ts +28 -2
  14. package/dist/types/CatalogueSource.d.ts +4 -0
  15. package/dist/types/CatalogueSource.js +3 -0
  16. package/dist/types/ChatCompletion.d.ts +16 -0
  17. package/dist/types/ChatCompletion.js +2 -0
  18. package/dist/types/ChatCompletionChoice.d.ts +8 -0
  19. package/dist/types/ChatCompletionChoice.js +2 -0
  20. package/dist/types/ChatCompletionChunk.d.ts +15 -0
  21. package/dist/types/ChatCompletionChunk.js +2 -0
  22. package/dist/types/ChatCompletionChunkChoice.d.ts +8 -0
  23. package/dist/types/ChatCompletionChunkChoice.js +2 -0
  24. package/dist/types/ChatCompletionChunkFunction.d.ts +4 -0
  25. package/dist/types/ChatCompletionChunkFunction.js +3 -0
  26. package/dist/types/ChatCompletionChunkToolCall.d.ts +7 -0
  27. package/dist/types/ChatCompletionChunkToolCall.js +2 -0
  28. package/dist/types/ChatCompletionDelta.d.ts +7 -0
  29. package/dist/types/ChatCompletionDelta.js +2 -0
  30. package/dist/types/ChatCompletionFunction.d.ts +4 -0
  31. package/dist/types/ChatCompletionFunction.js +3 -0
  32. package/dist/types/ChatCompletionMessage.d.ts +9 -0
  33. package/dist/types/ChatCompletionMessage.js +2 -0
  34. package/dist/types/ChatCompletionToolCall.d.ts +6 -0
  35. package/dist/types/ChatCompletionToolCall.js +2 -0
  36. package/dist/types/ChatCompletionUsage.d.ts +9 -0
  37. package/dist/types/ChatCompletionUsage.js +2 -0
  38. package/dist/types/CompletionTokensDetails.d.ts +3 -0
  39. package/dist/types/CompletionTokensDetails.js +3 -0
  40. package/dist/types/ContentPart.d.ts +6 -0
  41. package/dist/types/EmbeddingCallOptions.d.ts +9 -0
  42. package/dist/types/FilePart.d.ts +8 -0
  43. package/dist/types/FilePart.js +2 -0
  44. package/dist/types/Fingerprint.d.ts +21 -0
  45. package/dist/types/Fingerprint.js +3 -0
  46. package/dist/types/GenerateContent.d.ts +12 -1
  47. package/dist/types/GenerateObjectResult.d.ts +48 -0
  48. package/dist/types/GenerateObjectResult.js +2 -0
  49. package/dist/types/GenerateTextOptions.d.ts +12 -1
  50. package/dist/types/GenerateTextResult.d.ts +47 -0
  51. package/dist/types/HttpExchange.d.ts +34 -0
  52. package/dist/types/HttpExchange.js +2 -0
  53. package/dist/types/HttpRecord.d.ts +12 -0
  54. package/dist/types/HttpRecord.js +3 -0
  55. package/dist/types/ImageCallOptions.d.ts +10 -1
  56. package/dist/types/InputRecord.d.ts +16 -0
  57. package/dist/types/InputRecord.js +2 -0
  58. package/dist/types/Modality.d.ts +4 -0
  59. package/dist/types/Modality.js +3 -0
  60. package/dist/types/ModelCapabilities.d.ts +21 -0
  61. package/dist/types/ModelCapabilities.js +3 -0
  62. package/dist/types/ModelCost.d.ts +10 -0
  63. package/dist/types/ModelCost.js +3 -0
  64. package/dist/types/ModelLimits.d.ts +17 -0
  65. package/dist/types/ModelLimits.js +3 -0
  66. package/dist/types/ModelModalities.d.ts +8 -0
  67. package/dist/types/ModelModalities.js +2 -0
  68. package/dist/types/ModelSpec.d.ts +33 -0
  69. package/dist/types/ModelSpec.js +2 -0
  70. package/dist/types/ModelType.d.ts +4 -0
  71. package/dist/types/ModelType.js +3 -0
  72. package/dist/types/OutcomeRecord.d.ts +19 -0
  73. package/dist/types/OutcomeRecord.js +2 -0
  74. package/dist/types/OutcomeStatus.d.ts +4 -0
  75. package/dist/types/OutcomeStatus.js +3 -0
  76. package/dist/types/PrefixBreak.d.ts +11 -0
  77. package/dist/types/PrefixBreak.js +2 -0
  78. package/dist/types/PromptTokensDetails.d.ts +4 -0
  79. package/dist/types/PromptTokensDetails.js +3 -0
  80. package/dist/types/ProviderAuditSpec.d.ts +33 -0
  81. package/dist/types/ProviderAuditSpec.js +2 -0
  82. package/dist/types/ProviderFamily.d.ts +5 -0
  83. package/dist/types/ProviderFamily.js +3 -0
  84. package/dist/types/ProviderRecord.d.ts +30 -0
  85. package/dist/types/ProviderRecord.js +2 -0
  86. package/dist/types/RawToolCall.d.ts +16 -0
  87. package/dist/types/RawToolCall.js +2 -0
  88. package/dist/types/ReasoningMode.d.ts +4 -0
  89. package/dist/types/ReasoningMode.js +3 -0
  90. package/dist/types/ReasoningPart.d.ts +9 -0
  91. package/dist/types/ReasoningPart.js +3 -0
  92. package/dist/types/ReasoningSpec.d.ts +39 -0
  93. package/dist/types/ReasoningSpec.js +2 -0
  94. package/dist/types/ReasoningVisibility.d.ts +4 -0
  95. package/dist/types/ReasoningVisibility.js +3 -0
  96. package/dist/types/Recording.d.ts +56 -0
  97. package/dist/types/Recording.js +2 -0
  98. package/dist/types/RequestCacheHints.d.ts +9 -0
  99. package/dist/types/RequestCacheHints.js +3 -0
  100. package/dist/types/RerankingCallOptions.d.ts +9 -0
  101. package/dist/types/ResponseRecord.d.ts +13 -0
  102. package/dist/types/ResponseRecord.js +3 -0
  103. package/dist/types/RetryError.d.ts +9 -0
  104. package/dist/types/RetryError.js +2 -0
  105. package/dist/types/RetryErrorReason.d.ts +4 -0
  106. package/dist/types/RetryErrorReason.js +3 -0
  107. package/dist/types/RuntimeModel.d.ts +22 -0
  108. package/dist/types/RuntimeModel.js +3 -0
  109. package/dist/types/SearchCallOptions.d.ts +9 -0
  110. package/dist/types/SessionCall.d.ts +20 -0
  111. package/dist/types/SessionCall.js +3 -0
  112. package/dist/types/SessionChainView.d.ts +10 -0
  113. package/dist/types/SessionChainView.js +2 -0
  114. package/dist/types/SessionSource.d.ts +4 -0
  115. package/dist/types/SessionSource.js +3 -0
  116. package/dist/types/SessionStepStat.d.ts +27 -0
  117. package/dist/types/SessionStepStat.js +2 -0
  118. package/dist/types/SessionView.d.ts +16 -0
  119. package/dist/types/SessionView.js +2 -0
  120. package/dist/types/SourcePart.d.ts +9 -0
  121. package/dist/types/SourcePart.js +3 -0
  122. package/dist/types/SpeechCallOptions.d.ts +9 -0
  123. package/dist/types/StreamPart.d.ts +12 -0
  124. package/dist/types/StreamTextResultAggregated.d.ts +74 -0
  125. package/dist/types/StreamTextResultAggregated.js +2 -0
  126. package/dist/types/TimeoutConfiguration.d.ts +19 -0
  127. package/dist/types/TimeoutConfiguration.js +1 -0
  128. package/dist/types/TimingRecord.d.ts +7 -0
  129. package/dist/types/TimingRecord.js +3 -0
  130. package/dist/types/ToolCall.d.ts +16 -1
  131. package/dist/types/ToolCallRepairReply.d.ts +19 -0
  132. package/dist/types/ToolCallRepairReply.js +2 -0
  133. package/dist/types/TraceFilter.d.ts +9 -0
  134. package/dist/types/TraceFilter.js +3 -0
  135. package/dist/types/TraceRecord.d.ts +54 -0
  136. package/dist/types/TraceRecord.js +2 -0
  137. package/dist/types/TraceStats.d.ts +20 -0
  138. package/dist/types/TraceStats.js +3 -0
  139. package/dist/types/TranscriptionCallOptions.d.ts +38 -0
  140. package/dist/types/TranscriptionCallOptions.js +2 -0
  141. package/dist/types/TranscriptionRequest.d.ts +9 -0
  142. package/dist/types/TranscriptionRequest.js +3 -0
  143. package/dist/types/TranscriptionResponse.d.ts +24 -0
  144. package/dist/types/TranscriptionResponse.js +2 -0
  145. package/dist/types/TranscriptionResult.d.ts +46 -0
  146. package/dist/types/TranscriptionResult.js +2 -0
  147. package/dist/types/TranscriptionSegment.d.ts +17 -0
  148. package/dist/types/TranscriptionSegment.js +3 -0
  149. package/dist/types/TranscriptionStreamPart.d.ts +70 -0
  150. package/dist/types/TranscriptionStreamPart.js +2 -0
  151. package/dist/types/UsageSnapshot.d.ts +18 -0
  152. package/dist/types/UsageSnapshot.js +2 -0
  153. package/dist/types/Verdict.d.ts +23 -0
  154. package/dist/types/Verdict.js +2 -0
  155. package/dist/types/VerdictConfidence.d.ts +4 -0
  156. package/dist/types/VerdictConfidence.js +3 -0
  157. package/dist/types/VerdictKind.d.ts +4 -0
  158. package/dist/types/VerdictKind.js +3 -0
  159. package/dist/types/VideoCallOptions.d.ts +17 -2
  160. package/dist/types/VideoPollOptions.d.ts +13 -0
  161. package/dist/types/VideoPollOptions.js +3 -0
  162. package/dist/types/VideoResult.d.ts +1 -1
  163. package/dist/types.d.ts +71 -1
  164. package/dist/types.js +3 -3
  165. package/index.d.ts +332 -25
  166. package/index.js +77 -54
  167. package/package.json +13 -12
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Aimux error hierarchy (aligned with Vercel AI SDK style).
3
+ *
4
+ * ```ts
5
+ * try {
6
+ * await generateText(model, '...')
7
+ * } catch (e) {
8
+ * if (e instanceof APICallError) {
9
+ * // e.status === 429 → rate limited (e.retryMs), 401 → auth, 404 → model
10
+ * } else if (e instanceof RetryError) {
11
+ * // every retry attempt failed — e.errors is the per-attempt history
12
+ * } else if (e instanceof AimuxError) {
13
+ * // any AiMuxError
14
+ * } else if (e instanceof Error && (e as { code?: string }).code === 'InvalidArg') {
15
+ * // the binding rejected an argument (plain Error, napi code)
16
+ * }
17
+ * }
18
+ * ```
19
+ *
20
+ * Distinct from the ts-rs wire type `AiMuxError` used inside `StreamPart`.
21
+ */
22
+ export declare class AimuxError extends Error {
23
+ protected constructor(message: string);
24
+ }
25
+ /**
26
+ * A call that reached (or tried to reach) the provider. Classification is
27
+ * `status`; everything below is what that exchange produced, and lives on this
28
+ * class alone — the core fills these for no other variant (AI SDK likewise
29
+ * keeps `isRetryable` / `responseBody` / `data` on `APICallError`).
30
+ */
31
+ export declare class APICallError extends AimuxError {
32
+ /** Whether retrying this provider call may help. */
33
+ readonly retryable: boolean;
34
+ /** HTTP status observed from the provider; absent for transport failures. */
35
+ readonly status?: number;
36
+ /** Rate-limit hint in ms; absent if none; `0` means retry immediately. */
37
+ readonly retryMs?: number;
38
+ /** Sanitized request URL; absent when unknown. */
39
+ readonly url?: string;
40
+ /** Sanitized request body values sent to the provider. */
41
+ readonly requestBodyValues?: unknown;
42
+ /** Provider's machine-readable error code (e.g. `'rate_limit_exceeded'`). */
43
+ readonly providerCode?: string;
44
+ /** Provider's failure text without Aimux's composed prefix. */
45
+ readonly providerMessage?: string;
46
+ /** Raw error response body, verbatim. */
47
+ readonly responseBody?: string;
48
+ /** Sanitized response headers. */
49
+ readonly responseHeaders?: Record<string, string>;
50
+ /** Parsed provider error data (AI SDK `APICallError.data`). */
51
+ readonly data?: unknown;
52
+ }
53
+ /** Why a {@link RetryError} stopped retrying (core serde wire names). */
54
+ export type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable';
55
+ /**
56
+ * A retried model operation gave up. `errors` is the complete per-attempt
57
+ * history, oldest first; each entry is itself a full member of this hierarchy
58
+ * (typically {@link APICallError} with its provider detail).
59
+ */
60
+ export declare class RetryError extends AimuxError {
61
+ /** Why retrying stopped. */
62
+ readonly reason: RetryErrorReason;
63
+ /** Per-attempt errors, oldest first. */
64
+ readonly errors: AimuxError[];
65
+ /** The final attempt's error (`undefined` only for a deserialized empty history). */
66
+ get lastError(): AimuxError | undefined;
67
+ }
68
+ export declare class JSONParseError extends AimuxError {
69
+ }
70
+ export declare class InvalidResponseDataError extends AimuxError {
71
+ }
72
+ /** The model called a tool that was not provided (AI SDK `NoSuchToolError`). */
73
+ export declare class NoSuchToolError extends AimuxError {
74
+ /** The tool name the model tried to call. */
75
+ readonly toolName: string;
76
+ /** Tools that were available; absent if none were. */
77
+ readonly availableTools?: string[];
78
+ /** Original argument text, when available. */
79
+ readonly toolInput?: string;
80
+ }
81
+ /** A tool call's input failed to parse or violated the tool's schema (AI SDK `InvalidToolInputError`). */
82
+ export declare class InvalidToolInputError extends AimuxError {
83
+ /** The tool whose input was invalid. */
84
+ readonly toolName: string;
85
+ /** The raw input text the model produced. */
86
+ readonly toolInput: string;
87
+ }
88
+ /** The repair callback failed or returned a call that was still invalid. */
89
+ export declare class ToolCallRepairError extends AimuxError {
90
+ /** The failure that triggered repair (a {@link NoSuchToolError} or {@link InvalidToolInputError}). */
91
+ readonly originalError: NoSuchToolError | InvalidToolInputError;
92
+ }
93
+ export declare class InvalidArgumentError extends AimuxError {
94
+ }
95
+ export declare class InvalidPromptError extends AimuxError {
96
+ }
97
+ export declare class TokenExpiredError extends AimuxError {
98
+ /** Token expiry is produced only from an observed 401 response. */
99
+ readonly status: 401;
100
+ }
101
+ export declare class UnsupportedFunctionalityError extends AimuxError {
102
+ }
103
+ /** Registry lookup failed for a model id (AI SDK `NoSuchModelError`). */
104
+ export declare class NoSuchModelError extends AimuxError {
105
+ /** The model id that did not resolve. */
106
+ readonly modelId: string;
107
+ /** Model category requested (`'languageModel'`, `'imageModel'`, …). */
108
+ readonly modelType?: string;
109
+ }
110
+ /** Registry lookup failed for a provider name (AI SDK `NoSuchProviderError`). */
111
+ export declare class NoSuchProviderError extends AimuxError {
112
+ /** The provider name that did not resolve. */
113
+ readonly providerId: string;
114
+ }
115
+ export declare class TimeoutError extends AimuxError {
116
+ }
117
+ /** Request aborted (not DOM `AbortError`); `message` is the abort payload. */
118
+ export declare class RequestAbortedError extends AimuxError {
119
+ }
120
+ export declare class OtherError extends AimuxError {
121
+ }
122
+ /**
123
+ * Which recording failure a {@link RecordingError} reports — the core's
124
+ * `recording::RecordingError` variant name. Only `WriterGone`, `FlushTimeout`
125
+ * and `Write` can come out of a flush today.
126
+ */
127
+ export type RecordingErrorCode = 'Init' | 'OpenFile' | 'Spawn' | 'WriterGone' | 'FlushTimeout' | 'Write';
128
+ /**
129
+ * The recorder could not confirm data on disk (`recordingTryFlush`).
130
+ *
131
+ * The core has two unrelated error types — `AiMuxError` and
132
+ * `recording::RecordingError` — and so does this binding: this class extends
133
+ * `Error` directly, not {@link AimuxError}. Catch it separately.
134
+ */
135
+ export declare class RecordingError extends Error {
136
+ /** Which recording failure. */
137
+ readonly code: RecordingErrorCode;
138
+ private constructor();
139
+ }
package/dist/error.js ADDED
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /**
3
+ * Aimux error hierarchy (aligned with Vercel AI SDK style).
4
+ *
5
+ * ```ts
6
+ * try {
7
+ * await generateText(model, '...')
8
+ * } catch (e) {
9
+ * if (e instanceof APICallError) {
10
+ * // e.status === 429 → rate limited (e.retryMs), 401 → auth, 404 → model
11
+ * } else if (e instanceof RetryError) {
12
+ * // every retry attempt failed — e.errors is the per-attempt history
13
+ * } else if (e instanceof AimuxError) {
14
+ * // any AiMuxError
15
+ * } else if (e instanceof Error && (e as { code?: string }).code === 'InvalidArg') {
16
+ * // the binding rejected an argument (plain Error, napi code)
17
+ * }
18
+ * }
19
+ * ```
20
+ *
21
+ * Distinct from the ts-rs wire type `AiMuxError` used inside `StreamPart`.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.RecordingError = exports.OtherError = exports.RequestAbortedError = exports.TimeoutError = exports.NoSuchProviderError = exports.NoSuchModelError = exports.UnsupportedFunctionalityError = exports.TokenExpiredError = exports.InvalidPromptError = exports.InvalidArgumentError = exports.ToolCallRepairError = exports.InvalidToolInputError = exports.NoSuchToolError = exports.InvalidResponseDataError = exports.JSONParseError = exports.RetryError = exports.APICallError = exports.AimuxError = void 0;
25
+ class AimuxError extends Error {
26
+ constructor(message) {
27
+ super(message);
28
+ this.name = new.target.name;
29
+ }
30
+ }
31
+ exports.AimuxError = AimuxError;
32
+ /**
33
+ * A call that reached (or tried to reach) the provider. Classification is
34
+ * `status`; everything below is what that exchange produced, and lives on this
35
+ * class alone — the core fills these for no other variant (AI SDK likewise
36
+ * keeps `isRetryable` / `responseBody` / `data` on `APICallError`).
37
+ */
38
+ class APICallError extends AimuxError {
39
+ }
40
+ exports.APICallError = APICallError;
41
+ /**
42
+ * A retried model operation gave up. `errors` is the complete per-attempt
43
+ * history, oldest first; each entry is itself a full member of this hierarchy
44
+ * (typically {@link APICallError} with its provider detail).
45
+ */
46
+ class RetryError extends AimuxError {
47
+ /** The final attempt's error (`undefined` only for a deserialized empty history). */
48
+ get lastError() {
49
+ return this.errors[this.errors.length - 1];
50
+ }
51
+ }
52
+ exports.RetryError = RetryError;
53
+ class JSONParseError extends AimuxError {
54
+ }
55
+ exports.JSONParseError = JSONParseError;
56
+ class InvalidResponseDataError extends AimuxError {
57
+ }
58
+ exports.InvalidResponseDataError = InvalidResponseDataError;
59
+ /** The model called a tool that was not provided (AI SDK `NoSuchToolError`). */
60
+ class NoSuchToolError extends AimuxError {
61
+ }
62
+ exports.NoSuchToolError = NoSuchToolError;
63
+ /** A tool call's input failed to parse or violated the tool's schema (AI SDK `InvalidToolInputError`). */
64
+ class InvalidToolInputError extends AimuxError {
65
+ }
66
+ exports.InvalidToolInputError = InvalidToolInputError;
67
+ /** The repair callback failed or returned a call that was still invalid. */
68
+ class ToolCallRepairError extends AimuxError {
69
+ }
70
+ exports.ToolCallRepairError = ToolCallRepairError;
71
+ class InvalidArgumentError extends AimuxError {
72
+ }
73
+ exports.InvalidArgumentError = InvalidArgumentError;
74
+ class InvalidPromptError extends AimuxError {
75
+ }
76
+ exports.InvalidPromptError = InvalidPromptError;
77
+ class TokenExpiredError extends AimuxError {
78
+ }
79
+ exports.TokenExpiredError = TokenExpiredError;
80
+ class UnsupportedFunctionalityError extends AimuxError {
81
+ }
82
+ exports.UnsupportedFunctionalityError = UnsupportedFunctionalityError;
83
+ /** Registry lookup failed for a model id (AI SDK `NoSuchModelError`). */
84
+ class NoSuchModelError extends AimuxError {
85
+ }
86
+ exports.NoSuchModelError = NoSuchModelError;
87
+ /** Registry lookup failed for a provider name (AI SDK `NoSuchProviderError`). */
88
+ class NoSuchProviderError extends AimuxError {
89
+ }
90
+ exports.NoSuchProviderError = NoSuchProviderError;
91
+ class TimeoutError extends AimuxError {
92
+ }
93
+ exports.TimeoutError = TimeoutError;
94
+ /** Request aborted (not DOM `AbortError`); `message` is the abort payload. */
95
+ class RequestAbortedError extends AimuxError {
96
+ }
97
+ exports.RequestAbortedError = RequestAbortedError;
98
+ class OtherError extends AimuxError {
99
+ }
100
+ exports.OtherError = OtherError;
101
+ /**
102
+ * The recorder could not confirm data on disk (`recordingTryFlush`).
103
+ *
104
+ * The core has two unrelated error types — `AiMuxError` and
105
+ * `recording::RecordingError` — and so does this binding: this class extends
106
+ * `Error` directly, not {@link AimuxError}. Catch it separately.
107
+ */
108
+ class RecordingError extends Error {
109
+ constructor(message) {
110
+ super(message);
111
+ this.name = new.target.name;
112
+ }
113
+ }
114
+ exports.RecordingError = RecordingError;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- import type { Model } from '../index.js';
2
- import type { GenerateTextOptions, GenerateTextResult, StreamPart, ModelMessage, Tool, ToolChoice, ToolCall, ToolResult, Usage, FinishReason, Warning, Role, MessageContent, ContentPart, ResponseFormat, ReasoningEffort, AiMuxError, GenerateResult, FunctionTool } from './types';
3
- export { Model, StreamTextGenerator, AbortBridge, initLogging, openai, anthropic, deepseek, google, cohere, mistral, xai, bedrock, vertex, anthropicAws, azure, provider, } from '../index.js';
4
- export type { ProviderName } from './types/ProviderName';
5
- export type { GenerateTextOptions, GenerateTextResult, StreamPart, ModelMessage, Tool, ToolChoice, ToolCall, ToolResult, Usage, FinishReason, Warning, Role, MessageContent, ContentPart, ResponseFormat, ReasoningEffort, AiMuxError, GenerateResult, FunctionTool, };
1
+ import type { Model, ProviderConfig, ProviderHandle as RawProviderHandle } from './native.ts';
2
+ import type { GenerateTextOptions, GenerateTextResult, StreamPart, ModelMessage, Tool, ToolChoice, ToolCall, ToolResult, Usage, FinishReason, Warning, Role, MessageContent, ContentPart, ResponseFormat, ReasoningEffort, GenerateResult, FunctionTool, SessionCall, SessionSource, SessionView, ChatCompletion, ChatCompletionChunk, ModelSpec, RuntimeModel, VideoCallOptions, VideoPollOptions, AiMuxError, JsonValue, RawToolCall, ToolCallRepairReply } from './types';
3
+ export { AimuxError, APICallError, RetryError, type RetryErrorReason, JSONParseError, InvalidResponseDataError, NoSuchToolError, InvalidToolInputError, ToolCallRepairError, InvalidArgumentError, InvalidPromptError, TokenExpiredError, UnsupportedFunctionalityError, NoSuchModelError, NoSuchProviderError, TimeoutError, RequestAbortedError, OtherError, RecordingError, type RecordingErrorCode, } from './error.ts';
4
+ export { Model, StreamTextGenerator, AbortBridge, initLogging, recordingFlush, recordingStop, initSessionStore, initSessionInfer, sessionCalls, listSessions, mockReplay, initRecordingRing, router, moa, openai, anthropic, deepseek, google, cohere, mistral, xai, bedrock, vertex, anthropicAws, azure, provider, type ProviderHandle, } from './native.ts';
5
+ export declare const recordingTryFlush: () => void;
6
+ export declare const initRecording: (dir: string) => void;
7
+ export { ProviderName } from './types/ProviderName.ts';
8
+ export type { GenerateTextOptions, GenerateTextResult, StreamPart, ModelMessage, Tool, ToolChoice, ToolCall, ToolResult, Usage, FinishReason, Warning, Role, MessageContent, ContentPart, ResponseFormat, ReasoningEffort, GenerateResult, FunctionTool, SessionCall, SessionSource, SessionView, ChatCompletion, ChatCompletionChunk, ModelSpec, RuntimeModel, VideoCallOptions, VideoPollOptions, RawToolCall, ToolCallRepairReply, };
6
9
  /**
7
10
  * A raw napi `Model` instance returned by `openai()` / `anthropic()` / …
8
11
  *
@@ -11,13 +14,52 @@ export type { GenerateTextOptions, GenerateTextResult, StreamPart, ModelMessage,
11
14
  * class instance type — pass the exact object a provider factory gives you.
12
15
  */
13
16
  export type RawModel = Model;
17
+ /** The argument passed to a {@link RepairToolCall} function. */
18
+ export type ToolCallRepairContext = {
19
+ tool_call: RawToolCall;
20
+ /** The lookup / parse / validation failure that made the call invalid. */
21
+ error: AiMuxError;
22
+ /** JSON Schema of the called tool; the empty-object schema when unknown. */
23
+ input_schema: JsonValue;
24
+ tools: Tool[];
25
+ messages: ModelMessage[];
26
+ instructions: string | null;
27
+ };
28
+ /**
29
+ * Repairs one invalid tool call, mirroring the AI SDK's `repairToolCall`.
30
+ *
31
+ * Return a replacement call, or `null` to leave the call invalid with its
32
+ * original error. Throwing marks the repair as failed: the call stays invalid
33
+ * and carries a {@link ToolCallRepairError} whose cause is the thrown message.
34
+ * A returned call is re-parsed and re-validated; if it still does not match the
35
+ * schema the result is likewise a {@link ToolCallRepairError}.
36
+ *
37
+ * Runs outside any native call, so it may itself call back into aimux (the
38
+ * usual implementation asks a model to rewrite the arguments). It is invoked at
39
+ * most once per tool call, and never for a call made without a tool set.
40
+ */
41
+ export type RepairToolCall = (context: ToolCallRepairContext) => RawToolCall | null | Promise<RawToolCall | null>;
42
+ /**
43
+ * {@link GenerateTextOptions} plus the host-side `repairToolCall` function.
44
+ *
45
+ * `repairToolCall` is a function, so `JSON.stringify` drops it — it never
46
+ * reaches the provider request. It does **not** apply to the OpenAI-format
47
+ * entry points (`generateTextAsOpenai` / `streamTextAsOpenai`): that shape
48
+ * carries no `invalid` marker, so there is nothing to drive repair from.
49
+ */
50
+ export type GenerateTextOptionsWithRepair = GenerateTextOptions & {
51
+ repairToolCall?: RepairToolCall;
52
+ };
14
53
  /**
15
54
  * Generate text (non-streaming). Returns a typed {@link GenerateTextResult}.
16
55
  *
17
56
  * @param model - A raw model instance from `openai()`, `anthropic()`, etc.
18
57
  * @param prompt - A plain string or an array of typed chat messages.
19
58
  * @param options - Optional typed generation options (tools, tool_choice,
20
- * temperature, response_format, …).
59
+ * temperature, response_format, …). Invalid tool calls arrive
60
+ * with `invalid`/`error` set on the tool call; pass
61
+ * {@link RepairToolCall | `repairToolCall`} to fix them up
62
+ * before the result is decoded.
21
63
  * @param signal - Optional `AbortSignal`; aborting it cancels the call.
22
64
  *
23
65
  * Internally calls the raw
@@ -32,7 +74,7 @@ export type RawModel = Model;
32
74
  * console.log(result.text, result.usage)
33
75
  * ```
34
76
  */
35
- export declare function generateText(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptions, signal?: AbortSignal): Promise<GenerateTextResult>;
77
+ export declare function generateText(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptionsWithRepair, signal?: AbortSignal): Promise<GenerateTextResult>;
36
78
  /**
37
79
  * Stream text from a model. Yields typed {@link StreamPart}s.
38
80
  *
@@ -54,4 +96,116 @@ export declare function generateText(model: RawModel, prompt: string | ModelMess
54
96
  * }
55
97
  * ```
56
98
  */
57
- export declare function streamText(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptions, signal?: AbortSignal): AsyncGenerator<StreamPart>;
99
+ export declare function streamText(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptionsWithRepair, signal?: AbortSignal): AsyncGenerator<StreamPart>;
100
+ /**
101
+ * All calls of a session, ordered by step (RFC-0024). Empty if the session
102
+ * is unknown or no store is registered.
103
+ *
104
+ * `initSessionStore()` / `initSessionInfer(enabled)` (raw napi, re-exported
105
+ * above) must be called first to register the store / opt-in inferer.
106
+ */
107
+ export declare function getSessionCalls(sessionId: string): SessionCall[];
108
+ /**
109
+ * All known sessions (RFC-0024).
110
+ */
111
+ export declare function getSessions(): SessionView[];
112
+ /**
113
+ * Generate text and return an OpenAI Chat Completion (non-streaming).
114
+ *
115
+ * Works with **any** provider — the result is always a standard OpenAI
116
+ * `ChatCompletion` object.
117
+ *
118
+ * With {@link RepairToolCall | `repairToolCall`}, invalid calls are repaired
119
+ * on the native result first and the completion is converted from it, so its
120
+ * `tool_calls` carry the repaired arguments (a `ChatCompletion` has no
121
+ * `invalid` marker to repair from).
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * import { openai, generateTextAsOpenai } from 'aimux'
126
+ * const model = await openai(apiKey, 'gpt-4o')
127
+ * const completion = await generateTextAsOpenai(model, 'What is Rust?')
128
+ * console.log(completion.choices[0].message.content)
129
+ * ```
130
+ */
131
+ export declare function generateTextAsOpenai(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptionsWithRepair, signal?: AbortSignal): Promise<ChatCompletion>;
132
+ /**
133
+ * Stream text as OpenAI Chat Completion chunks.
134
+ *
135
+ * Works with **any** provider — yields standard OpenAI `ChatCompletionChunk`
136
+ * objects. Pass `streamOptions` via `providerOptions.openai.stream_options`:
137
+ * `{ include_usage: true, include_reasoning: true }` (both default true).
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * import { openai, streamTextAsOpenai } from 'aimux'
142
+ * const model = await openai(apiKey, 'gpt-4o')
143
+ * for await (const chunk of streamTextAsOpenai(model, 'Write a haiku.')) {
144
+ * const delta = chunk.choices[0]?.delta?.content
145
+ * if (delta) process.stdout.write(delta)
146
+ * }
147
+ * ```
148
+ */
149
+ export declare function streamTextAsOpenai(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptions, signal?: AbortSignal): AsyncGenerator<ChatCompletionChunk>;
150
+ /**
151
+ * A typed wrapper around the raw napi `ProviderHandle` class. Created by
152
+ * {@link createProvider}, supports {@link ProviderHandleTyped.listModels} and
153
+ * {@link ProviderHandleTyped.model}.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * import { createProvider, generateText } from 'aimux'
158
+ * const p = await createProvider('deepseek', apiKey)
159
+ * const models = await p.listModels()
160
+ * const model = await p.model(models[0].id)
161
+ * const result = await generateText(model, 'Hello')
162
+ * ```
163
+ */
164
+ export declare class ProviderHandleTyped {
165
+ private readonly raw;
166
+ constructor(raw: RawProviderHandle);
167
+ /** List models available on this provider (runtime discovery + anya2a spec). */
168
+ listModels(): Promise<RuntimeModel[]>;
169
+ /** Build a language model from a discovered model id. */
170
+ model(modelId: string): Promise<RawModel>;
171
+ }
172
+ /**
173
+ * Create a **provider handle** (RFC-0027) for a registry-backed provider.
174
+ *
175
+ * Unlike `provider()` (which binds to a single modelId), this returns a handle
176
+ * that supports `listModels()` (runtime discovery) and `model()`.
177
+ *
178
+ * @param name - Provider name (e.g. `"deepseek"`, `"groq"`).
179
+ * @param apiKey - API key; omit/null to read the provider's env var.
180
+ * @param config - Optional provider config (baseUrl, headers, …).
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * import { createProvider, generateText } from 'aimux'
185
+ * const p = await createProvider('deepseek', process.env.DEEPSEEK_API_KEY)
186
+ * const models = await p.listModels()
187
+ * const model = await p.model(models[0].id)
188
+ * const result = await generateText(model, 'Hello')
189
+ * ```
190
+ */
191
+ export declare function createProvider(name: string, apiKey?: string, config?: ProviderConfig): Promise<ProviderHandleTyped>;
192
+ /**
193
+ * Fetch the community model catalogue (anya2a). Returns a `Catalogue` object
194
+ * with a `lookup(provider, modelId)` method. Thin fetch — no caching; the host
195
+ * decides how to persist/reuse the result.
196
+ *
197
+ * @param sourceUrl - Optional URL override (default = anya2a endpoint).
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * import { createProvider, getModelSpecs, generateText } from 'aimux'
202
+ * const [p, catalogue] = await Promise.all([
203
+ * createProvider('deepseek', apiKey),
204
+ * getModelSpecs(),
205
+ * ])
206
+ * const models = await p.listModels()
207
+ * const model = await p.model(models[0].id)
208
+ * const spec = catalogue.specs?.['deepseek']?.[models[0].id] // community portrait
209
+ * ```
210
+ */
211
+ export declare function getModelSpecs(sourceUrl?: string): Promise<unknown>;