@arcships/aimux 0.3.0 → 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.
- package/dist/error.d.ts +93 -25
- package/dist/error.js +51 -110
- package/dist/index.d.ts +55 -28
- package/dist/index.js +152 -103
- package/dist/native.d.ts +2 -0
- package/dist/native.js +46 -0
- package/dist/types/AiMuxError.d.ts +28 -10
- package/dist/types/ApiCallError.d.ts +26 -16
- package/dist/types/ApiCallError.js +0 -1
- package/dist/types/CallOptions.d.ts +1 -1
- package/dist/types/ContentPart.d.ts +6 -0
- package/dist/types/EmbeddingCallOptions.d.ts +9 -0
- package/dist/types/GenerateContent.d.ts +12 -1
- package/dist/types/HttpExchange.d.ts +12 -1
- package/dist/types/ImageCallOptions.d.ts +9 -0
- package/dist/types/OutcomeRecord.d.ts +5 -0
- package/dist/types/RawToolCall.d.ts +16 -0
- package/dist/types/RawToolCall.js +2 -0
- package/dist/types/RerankingCallOptions.d.ts +9 -0
- package/dist/types/RetryError.d.ts +9 -0
- package/dist/types/RetryError.js +2 -0
- package/dist/types/RetryErrorReason.d.ts +4 -0
- package/dist/types/RetryErrorReason.js +3 -0
- package/dist/types/SearchCallOptions.d.ts +9 -0
- package/dist/types/SpeechCallOptions.d.ts +9 -0
- package/dist/types/StreamPart.d.ts +12 -0
- package/dist/types/TimeoutConfiguration.d.ts +9 -0
- package/dist/types/ToolCall.d.ts +16 -1
- package/dist/types/ToolCallRepairReply.d.ts +19 -0
- package/dist/types/ToolCallRepairReply.js +2 -0
- package/dist/types/TranscriptionCallOptions.d.ts +9 -0
- package/dist/types/VideoCallOptions.d.ts +16 -1
- package/dist/types/VideoPollOptions.d.ts +13 -0
- package/dist/types/VideoPollOptions.js +3 -0
- package/dist/types/VideoResult.d.ts +1 -1
- package/dist/types.d.ts +5 -0
- package/index.d.ts +83 -7
- package/index.js +59 -54
- package/package.json +12 -12
package/dist/error.d.ts
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
* await generateText(model, '...')
|
|
7
7
|
* } catch (e) {
|
|
8
8
|
* if (e instanceof APICallError) {
|
|
9
|
-
* // Classification is the status field (AI SDK APICallError.statusCode):
|
|
10
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
|
|
11
12
|
* } else if (e instanceof AimuxError) {
|
|
12
|
-
* // any
|
|
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)
|
|
13
16
|
* }
|
|
14
17
|
* }
|
|
15
18
|
* ```
|
|
@@ -17,55 +20,120 @@
|
|
|
17
20
|
* Distinct from the ts-rs wire type `AiMuxError` used inside `StreamPart`.
|
|
18
21
|
*/
|
|
19
22
|
export declare class AimuxError extends Error {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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. */
|
|
25
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;
|
|
26
42
|
/** Provider's machine-readable error code (e.g. `'rate_limit_exceeded'`). */
|
|
27
43
|
readonly providerCode?: string;
|
|
28
|
-
/**
|
|
44
|
+
/** Provider's failure text without Aimux's composed prefix. */
|
|
45
|
+
readonly providerMessage?: string;
|
|
46
|
+
/** Raw error response body, verbatim. */
|
|
29
47
|
readonly responseBody?: string;
|
|
30
|
-
/**
|
|
31
|
-
readonly
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
* e.g. `'{"ApiCall":{"status_code":429,"retry_after_ms":1500,...}}'`.
|
|
35
|
-
* Absent when the error did not originate from a core `AiMuxError`.
|
|
36
|
-
*/
|
|
37
|
-
readonly errorValue?: string;
|
|
38
|
-
constructor(message: string, status?: number, retryMs?: number, retryable?: boolean);
|
|
39
|
-
/** Rebuild from a native throw (or already-wrapped instance). */
|
|
40
|
-
static fromNative(err: unknown): AimuxError;
|
|
48
|
+
/** Sanitized response headers. */
|
|
49
|
+
readonly responseHeaders?: Record<string, string>;
|
|
50
|
+
/** Parsed provider error data (AI SDK `APICallError.data`). */
|
|
51
|
+
readonly data?: unknown;
|
|
41
52
|
}
|
|
42
|
-
|
|
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;
|
|
43
67
|
}
|
|
44
68
|
export declare class JSONParseError extends AimuxError {
|
|
45
69
|
}
|
|
46
70
|
export declare class InvalidResponseDataError extends AimuxError {
|
|
47
71
|
}
|
|
48
|
-
|
|
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;
|
|
49
92
|
}
|
|
50
93
|
export declare class InvalidArgumentError extends AimuxError {
|
|
51
94
|
}
|
|
52
95
|
export declare class InvalidPromptError extends AimuxError {
|
|
53
96
|
}
|
|
54
97
|
export declare class TokenExpiredError extends AimuxError {
|
|
98
|
+
/** Token expiry is produced only from an observed 401 response. */
|
|
99
|
+
readonly status: 401;
|
|
55
100
|
}
|
|
56
101
|
export declare class UnsupportedFunctionalityError extends AimuxError {
|
|
57
102
|
}
|
|
103
|
+
/** Registry lookup failed for a model id (AI SDK `NoSuchModelError`). */
|
|
58
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;
|
|
59
109
|
}
|
|
110
|
+
/** Registry lookup failed for a provider name (AI SDK `NoSuchProviderError`). */
|
|
60
111
|
export declare class NoSuchProviderError extends AimuxError {
|
|
112
|
+
/** The provider name that did not resolve. */
|
|
113
|
+
readonly providerId: string;
|
|
61
114
|
}
|
|
62
115
|
export declare class TimeoutError extends AimuxError {
|
|
63
116
|
}
|
|
64
|
-
/** Request aborted (not DOM `AbortError`). */
|
|
117
|
+
/** Request aborted (not DOM `AbortError`); `message` is the abort payload. */
|
|
65
118
|
export declare class RequestAbortedError extends AimuxError {
|
|
66
|
-
constructor(message?: string, status?: number, retryMs?: number, retryable?: boolean);
|
|
67
119
|
}
|
|
68
120
|
export declare class OtherError extends AimuxError {
|
|
69
121
|
}
|
|
70
|
-
/**
|
|
71
|
-
|
|
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
CHANGED
|
@@ -7,10 +7,13 @@
|
|
|
7
7
|
* await generateText(model, '...')
|
|
8
8
|
* } catch (e) {
|
|
9
9
|
* if (e instanceof APICallError) {
|
|
10
|
-
* // Classification is the status field (AI SDK APICallError.statusCode):
|
|
11
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
|
|
12
13
|
* } else if (e instanceof AimuxError) {
|
|
13
|
-
* // any
|
|
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)
|
|
14
17
|
* }
|
|
15
18
|
* }
|
|
16
19
|
* ```
|
|
@@ -18,98 +21,53 @@
|
|
|
18
21
|
* Distinct from the ts-rs wire type `AiMuxError` used inside `StreamPart`.
|
|
19
22
|
*/
|
|
20
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.OtherError = exports.RequestAbortedError = exports.TimeoutError = exports.NoSuchProviderError = exports.NoSuchModelError = exports.UnsupportedFunctionalityError = exports.TokenExpiredError = exports.InvalidPromptError = exports.InvalidArgumentError = exports.
|
|
22
|
-
exports.withAimuxError = withAimuxError;
|
|
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;
|
|
23
25
|
class AimuxError extends Error {
|
|
24
|
-
constructor(message
|
|
26
|
+
constructor(message) {
|
|
25
27
|
super(message);
|
|
26
28
|
this.name = new.target.name;
|
|
27
|
-
this.code = CODE_BY_NAME.get(this.name) ?? 'Other';
|
|
28
|
-
this.status = status;
|
|
29
|
-
this.retryMs = retryMs;
|
|
30
|
-
this.retryable = retryable;
|
|
31
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
32
|
-
const capture = Error
|
|
33
|
-
.captureStackTrace;
|
|
34
|
-
if (capture)
|
|
35
|
-
capture(this, new.target);
|
|
36
|
-
}
|
|
37
|
-
/** Rebuild from a native throw (or already-wrapped instance). */
|
|
38
|
-
static fromNative(err) {
|
|
39
|
-
if (err instanceof AimuxError) {
|
|
40
|
-
return err;
|
|
41
|
-
}
|
|
42
|
-
let message = String(err);
|
|
43
|
-
let code = 'Other';
|
|
44
|
-
let status = -1;
|
|
45
|
-
let retryMs = -1;
|
|
46
|
-
let retryable = false;
|
|
47
|
-
let providerCode;
|
|
48
|
-
let responseBody;
|
|
49
|
-
let requestId;
|
|
50
|
-
let errorValue;
|
|
51
|
-
if (err instanceof Error) {
|
|
52
|
-
message = err.message;
|
|
53
|
-
const any = err;
|
|
54
|
-
if (typeof any.status === 'number')
|
|
55
|
-
status = any.status;
|
|
56
|
-
if (typeof any.retryMs === 'number')
|
|
57
|
-
retryMs = any.retryMs;
|
|
58
|
-
if (typeof any.retryable === 'boolean')
|
|
59
|
-
retryable = any.retryable;
|
|
60
|
-
if (typeof any.providerCode === 'string')
|
|
61
|
-
providerCode = any.providerCode;
|
|
62
|
-
if (typeof any.responseBody === 'string')
|
|
63
|
-
responseBody = any.responseBody;
|
|
64
|
-
if (typeof any.requestId === 'string')
|
|
65
|
-
requestId = any.requestId;
|
|
66
|
-
if (typeof any.errorValue === 'string')
|
|
67
|
-
errorValue = any.errorValue;
|
|
68
|
-
if (typeof any.code === 'string' && any.code.length > 0) {
|
|
69
|
-
code = any.code;
|
|
70
|
-
}
|
|
71
|
-
else if (typeof any.name === 'string') {
|
|
72
|
-
// Native sets name to e.g. "APICallError"
|
|
73
|
-
code = CODE_BY_NAME.get(any.name) ?? 'Other';
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const wrapped = createByCode(code, message, status, retryMs, retryable);
|
|
77
|
-
if (providerCode !== undefined) {
|
|
78
|
-
;
|
|
79
|
-
wrapped.providerCode = providerCode;
|
|
80
|
-
}
|
|
81
|
-
if (responseBody !== undefined) {
|
|
82
|
-
;
|
|
83
|
-
wrapped.responseBody = responseBody;
|
|
84
|
-
}
|
|
85
|
-
if (requestId !== undefined) {
|
|
86
|
-
;
|
|
87
|
-
wrapped.requestId = requestId;
|
|
88
|
-
}
|
|
89
|
-
if (errorValue !== undefined) {
|
|
90
|
-
;
|
|
91
|
-
wrapped.errorValue = errorValue;
|
|
92
|
-
}
|
|
93
|
-
if (err instanceof Error) {
|
|
94
|
-
;
|
|
95
|
-
wrapped.cause = err;
|
|
96
|
-
}
|
|
97
|
-
return wrapped;
|
|
98
29
|
}
|
|
99
30
|
}
|
|
100
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
|
+
*/
|
|
101
38
|
class APICallError extends AimuxError {
|
|
102
39
|
}
|
|
103
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;
|
|
104
53
|
class JSONParseError extends AimuxError {
|
|
105
54
|
}
|
|
106
55
|
exports.JSONParseError = JSONParseError;
|
|
107
56
|
class InvalidResponseDataError extends AimuxError {
|
|
108
57
|
}
|
|
109
58
|
exports.InvalidResponseDataError = InvalidResponseDataError;
|
|
110
|
-
|
|
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 {
|
|
111
65
|
}
|
|
112
|
-
exports.
|
|
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;
|
|
113
71
|
class InvalidArgumentError extends AimuxError {
|
|
114
72
|
}
|
|
115
73
|
exports.InvalidArgumentError = InvalidArgumentError;
|
|
@@ -122,52 +80,35 @@ exports.TokenExpiredError = TokenExpiredError;
|
|
|
122
80
|
class UnsupportedFunctionalityError extends AimuxError {
|
|
123
81
|
}
|
|
124
82
|
exports.UnsupportedFunctionalityError = UnsupportedFunctionalityError;
|
|
83
|
+
/** Registry lookup failed for a model id (AI SDK `NoSuchModelError`). */
|
|
125
84
|
class NoSuchModelError extends AimuxError {
|
|
126
85
|
}
|
|
127
86
|
exports.NoSuchModelError = NoSuchModelError;
|
|
87
|
+
/** Registry lookup failed for a provider name (AI SDK `NoSuchProviderError`). */
|
|
128
88
|
class NoSuchProviderError extends AimuxError {
|
|
129
89
|
}
|
|
130
90
|
exports.NoSuchProviderError = NoSuchProviderError;
|
|
131
91
|
class TimeoutError extends AimuxError {
|
|
132
92
|
}
|
|
133
93
|
exports.TimeoutError = TimeoutError;
|
|
134
|
-
/** Request aborted (not DOM `AbortError`). */
|
|
94
|
+
/** Request aborted (not DOM `AbortError`); `message` is the abort payload. */
|
|
135
95
|
class RequestAbortedError extends AimuxError {
|
|
136
|
-
constructor(message = 'request aborted', status = -1, retryMs = -1, retryable = false) {
|
|
137
|
-
super(message, status, retryMs, retryable);
|
|
138
|
-
}
|
|
139
96
|
}
|
|
140
97
|
exports.RequestAbortedError = RequestAbortedError;
|
|
141
98
|
class OtherError extends AimuxError {
|
|
142
99
|
}
|
|
143
100
|
exports.OtherError = OtherError;
|
|
144
|
-
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
NoSuchProvider: NoSuchProviderError,
|
|
156
|
-
Timeout: TimeoutError,
|
|
157
|
-
Aborted: RequestAbortedError,
|
|
158
|
-
Other: OtherError,
|
|
159
|
-
};
|
|
160
|
-
const CODE_BY_NAME = new Map(Object.entries(CLASS_BY_CODE).map(([code, cls]) => [cls.name, code]));
|
|
161
|
-
function createByCode(code, message, status, retryMs, retryable) {
|
|
162
|
-
const Cls = CLASS_BY_CODE[code] ?? AimuxError;
|
|
163
|
-
return new Cls(message, status, retryMs, retryable);
|
|
164
|
-
}
|
|
165
|
-
/** Wrap an async native call so throws are typed `AimuxError` subclasses. */
|
|
166
|
-
async function withAimuxError(fn) {
|
|
167
|
-
try {
|
|
168
|
-
return await fn();
|
|
169
|
-
}
|
|
170
|
-
catch (e) {
|
|
171
|
-
throw AimuxError.fromNative(e);
|
|
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;
|
|
172
112
|
}
|
|
173
113
|
}
|
|
114
|
+
exports.RecordingError = RecordingError;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const listSessions: () => string;
|
|
8
|
-
export declare const mockReplay: (recordingsJsonl: string) => native.Model;
|
|
9
|
-
export declare const router: (models: native.Model[], configJson?: string | null | undefined) => native.Model;
|
|
10
|
-
export declare const moa: (references: native.Model[], aggregator: native.Model, configJson?: string | null | undefined) => native.Model;
|
|
11
|
-
export declare const openai: (apiKey: string, modelId: string, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
12
|
-
export declare const anthropic: (apiKey: string, modelId: string, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
13
|
-
export declare const deepseek: (apiKey: string, modelId: string, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
14
|
-
export declare const google: (apiKey: string, modelId: string, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
15
|
-
export declare const cohere: (apiKey: string, modelId: string, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
16
|
-
export declare const mistral: (apiKey: string, modelId: string, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
17
|
-
export declare const xai: (apiKey: string, modelId: string, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
18
|
-
export declare const bedrock: (accessKeyId: string, secretAccessKey: string, region: string, modelId: string, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
19
|
-
export declare const vertex: (accessToken: string, project: string, location: string, modelId: string, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
20
|
-
export declare const anthropicAws: (apiKey: string, region: string, modelId: string, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
21
|
-
export declare const azure: (apiKey: string, resourceName: string, deployment: string, apiVersion?: string | null | undefined, config?: string | native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
22
|
-
export declare const provider: (name: string, apiKey: string | null | undefined, modelId: string, config?: native.ProviderConfig | null | undefined) => Promise<native.Model>;
|
|
23
|
-
export type { ProviderHandle } from '../index.js';
|
|
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;
|
|
24
7
|
export { ProviderName } from './types/ProviderName.ts';
|
|
25
|
-
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, };
|
|
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, };
|
|
26
9
|
/**
|
|
27
10
|
* A raw napi `Model` instance returned by `openai()` / `anthropic()` / …
|
|
28
11
|
*
|
|
@@ -31,13 +14,52 @@ export type { GenerateTextOptions, GenerateTextResult, StreamPart, ModelMessage,
|
|
|
31
14
|
* class instance type — pass the exact object a provider factory gives you.
|
|
32
15
|
*/
|
|
33
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
|
+
};
|
|
34
53
|
/**
|
|
35
54
|
* Generate text (non-streaming). Returns a typed {@link GenerateTextResult}.
|
|
36
55
|
*
|
|
37
56
|
* @param model - A raw model instance from `openai()`, `anthropic()`, etc.
|
|
38
57
|
* @param prompt - A plain string or an array of typed chat messages.
|
|
39
58
|
* @param options - Optional typed generation options (tools, tool_choice,
|
|
40
|
-
* 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.
|
|
41
63
|
* @param signal - Optional `AbortSignal`; aborting it cancels the call.
|
|
42
64
|
*
|
|
43
65
|
* Internally calls the raw
|
|
@@ -52,7 +74,7 @@ export type RawModel = Model;
|
|
|
52
74
|
* console.log(result.text, result.usage)
|
|
53
75
|
* ```
|
|
54
76
|
*/
|
|
55
|
-
export declare function generateText(model: RawModel, prompt: string | ModelMessage[], options?:
|
|
77
|
+
export declare function generateText(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptionsWithRepair, signal?: AbortSignal): Promise<GenerateTextResult>;
|
|
56
78
|
/**
|
|
57
79
|
* Stream text from a model. Yields typed {@link StreamPart}s.
|
|
58
80
|
*
|
|
@@ -74,7 +96,7 @@ export declare function generateText(model: RawModel, prompt: string | ModelMess
|
|
|
74
96
|
* }
|
|
75
97
|
* ```
|
|
76
98
|
*/
|
|
77
|
-
export declare function streamText(model: RawModel, prompt: string | ModelMessage[], options?:
|
|
99
|
+
export declare function streamText(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptionsWithRepair, signal?: AbortSignal): AsyncGenerator<StreamPart>;
|
|
78
100
|
/**
|
|
79
101
|
* All calls of a session, ordered by step (RFC-0024). Empty if the session
|
|
80
102
|
* is unknown or no store is registered.
|
|
@@ -93,6 +115,11 @@ export declare function getSessions(): SessionView[];
|
|
|
93
115
|
* Works with **any** provider — the result is always a standard OpenAI
|
|
94
116
|
* `ChatCompletion` object.
|
|
95
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
|
+
*
|
|
96
123
|
* @example
|
|
97
124
|
* ```ts
|
|
98
125
|
* import { openai, generateTextAsOpenai } from 'aimux'
|
|
@@ -101,7 +128,7 @@ export declare function getSessions(): SessionView[];
|
|
|
101
128
|
* console.log(completion.choices[0].message.content)
|
|
102
129
|
* ```
|
|
103
130
|
*/
|
|
104
|
-
export declare function generateTextAsOpenai(model: RawModel, prompt: string | ModelMessage[], options?:
|
|
131
|
+
export declare function generateTextAsOpenai(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptionsWithRepair, signal?: AbortSignal): Promise<ChatCompletion>;
|
|
105
132
|
/**
|
|
106
133
|
* Stream text as OpenAI Chat Completion chunks.
|
|
107
134
|
*
|