antarya 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2 -2
- package/dist/index.cjs +543 -0
- package/dist/index.d.cts +397 -0
- package/dist/index.d.ts +397 -0
- package/dist/index.js +502 -0
- package/package.json +37 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/** Base class for every error the SDK throws for an API call. */
|
|
2
|
+
declare class APIError extends Error {
|
|
3
|
+
status?: number;
|
|
4
|
+
type: string;
|
|
5
|
+
requestId?: string;
|
|
6
|
+
retryAfter?: number;
|
|
7
|
+
constructor(message: string, init?: {
|
|
8
|
+
status?: number;
|
|
9
|
+
type?: string;
|
|
10
|
+
requestId?: string;
|
|
11
|
+
retryAfter?: number;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
declare class BadRequestError extends APIError {
|
|
15
|
+
}
|
|
16
|
+
declare class AuthenticationError extends APIError {
|
|
17
|
+
}
|
|
18
|
+
declare class PermissionDeniedError extends APIError {
|
|
19
|
+
}
|
|
20
|
+
declare class NotFoundError extends APIError {
|
|
21
|
+
}
|
|
22
|
+
declare class RequestTooLargeError extends APIError {
|
|
23
|
+
}
|
|
24
|
+
declare class RateLimitError extends APIError {
|
|
25
|
+
}
|
|
26
|
+
declare class InternalServerError extends APIError {
|
|
27
|
+
}
|
|
28
|
+
declare class OverloadedError extends APIError {
|
|
29
|
+
}
|
|
30
|
+
declare class APIConnectionError extends APIError {
|
|
31
|
+
constructor(message?: string, init?: {
|
|
32
|
+
cause?: unknown;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
declare class APITimeoutError extends APIConnectionError {
|
|
36
|
+
constructor(message?: string);
|
|
37
|
+
}
|
|
38
|
+
/** Builds the error class that matches a failed reply. The body may be anything, including HTML. */
|
|
39
|
+
declare function errorFrom(status: number, body: unknown, headers: Headers): APIError;
|
|
40
|
+
|
|
41
|
+
type TextPart = {
|
|
42
|
+
type: "text";
|
|
43
|
+
text: string;
|
|
44
|
+
};
|
|
45
|
+
/** A base64 image in a message; `name` and `text` are filled when it is read. */
|
|
46
|
+
type ImagePart = {
|
|
47
|
+
type: "image";
|
|
48
|
+
source: {
|
|
49
|
+
type: "base64";
|
|
50
|
+
media_type: string;
|
|
51
|
+
data: string;
|
|
52
|
+
};
|
|
53
|
+
name?: string;
|
|
54
|
+
text?: string;
|
|
55
|
+
};
|
|
56
|
+
/** A stored file referenced by id; `name` and `text` are filled from the store. */
|
|
57
|
+
type FilePart = {
|
|
58
|
+
type: "file";
|
|
59
|
+
file_id: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
text?: string | null;
|
|
62
|
+
};
|
|
63
|
+
/** A file sent inside the request as base64; it is read for this request only and not stored. */
|
|
64
|
+
type InlineFilePart = {
|
|
65
|
+
type: "file";
|
|
66
|
+
source: {
|
|
67
|
+
type: "base64";
|
|
68
|
+
filename: string;
|
|
69
|
+
media_type: string;
|
|
70
|
+
data: string;
|
|
71
|
+
};
|
|
72
|
+
name?: string;
|
|
73
|
+
text?: string | null;
|
|
74
|
+
};
|
|
75
|
+
/** A tool call made by the assistant. */
|
|
76
|
+
type ToolCallPart = {
|
|
77
|
+
type: "tool_call";
|
|
78
|
+
id: string;
|
|
79
|
+
name: string;
|
|
80
|
+
input: unknown;
|
|
81
|
+
};
|
|
82
|
+
/** The result of a tool call, sent back by the caller. */
|
|
83
|
+
type ToolResultPart = {
|
|
84
|
+
type: "tool_result";
|
|
85
|
+
tool_call_id: string;
|
|
86
|
+
content: unknown;
|
|
87
|
+
};
|
|
88
|
+
/** The kinds of typed artifact a reply can carry. */
|
|
89
|
+
declare const ARTIFACT_KINDS: readonly ["workbook", "table", "chart", "report"];
|
|
90
|
+
/** A large deliverable returned as a typed object instead of reply text. */
|
|
91
|
+
type ArtifactPart = {
|
|
92
|
+
type: "artifact";
|
|
93
|
+
id: string;
|
|
94
|
+
kind: typeof ARTIFACT_KINDS[number];
|
|
95
|
+
title: string;
|
|
96
|
+
mime_type: string;
|
|
97
|
+
schema_version: "antarya.artifact.v1";
|
|
98
|
+
data: Record<string, unknown>;
|
|
99
|
+
};
|
|
100
|
+
/** Any part a request message can carry. */
|
|
101
|
+
type Part = TextPart | ImagePart | FilePart | InlineFilePart | ToolCallPart | ToolResultPart | ArtifactPart;
|
|
102
|
+
/** The parts a reply can carry. */
|
|
103
|
+
type ReplyPart = TextPart | ToolCallPart | ArtifactPart;
|
|
104
|
+
/** One message in a conversation; input `content` may be a plain string. */
|
|
105
|
+
interface Message {
|
|
106
|
+
role: "user" | "assistant" | "tool";
|
|
107
|
+
content: string | Part[];
|
|
108
|
+
}
|
|
109
|
+
/** A tool the caller offers the model. */
|
|
110
|
+
interface ToolDef {
|
|
111
|
+
name: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
input_schema: Record<string, unknown>;
|
|
114
|
+
}
|
|
115
|
+
/** How the model may use the offered tools. */
|
|
116
|
+
type ToolChoice = {
|
|
117
|
+
type: "auto" | "none" | "any";
|
|
118
|
+
} | {
|
|
119
|
+
type: "tool";
|
|
120
|
+
name: string;
|
|
121
|
+
};
|
|
122
|
+
/** A request for a reply that matches a JSON schema. */
|
|
123
|
+
interface ResponseFormat {
|
|
124
|
+
type: "json_schema";
|
|
125
|
+
schema: Record<string, unknown>;
|
|
126
|
+
}
|
|
127
|
+
/** A chat request. */
|
|
128
|
+
interface ChatRequest {
|
|
129
|
+
model: string;
|
|
130
|
+
messages: Message[];
|
|
131
|
+
system?: string;
|
|
132
|
+
tools?: ToolDef[];
|
|
133
|
+
tool_choice?: ToolChoice;
|
|
134
|
+
response_format?: ResponseFormat;
|
|
135
|
+
max_output_tokens?: number;
|
|
136
|
+
stream?: boolean;
|
|
137
|
+
include_thinking?: boolean;
|
|
138
|
+
metadata?: Record<string, string>;
|
|
139
|
+
session_id?: string;
|
|
140
|
+
}
|
|
141
|
+
/** One step of the model's visible thinking. */
|
|
142
|
+
interface ThinkingNote {
|
|
143
|
+
step: number;
|
|
144
|
+
stage: string;
|
|
145
|
+
summary: string;
|
|
146
|
+
}
|
|
147
|
+
/** Why a reply ended. */
|
|
148
|
+
type StopReason = "end_turn" | "max_output_tokens" | "tool_call";
|
|
149
|
+
/** Token counts for a call. */
|
|
150
|
+
interface Usage {
|
|
151
|
+
input_tokens: number;
|
|
152
|
+
output_tokens: number;
|
|
153
|
+
}
|
|
154
|
+
/** A finished chat reply. */
|
|
155
|
+
interface ChatReply {
|
|
156
|
+
id: string;
|
|
157
|
+
model: string;
|
|
158
|
+
content: ReplyPart[];
|
|
159
|
+
stop_reason: StopReason;
|
|
160
|
+
usage: Usage;
|
|
161
|
+
thinking?: ThinkingNote[];
|
|
162
|
+
}
|
|
163
|
+
/** The public description of a model. */
|
|
164
|
+
interface ModelObject {
|
|
165
|
+
id: string;
|
|
166
|
+
object: "model";
|
|
167
|
+
created: number;
|
|
168
|
+
owned_by: "antarya";
|
|
169
|
+
max_output_tokens: number;
|
|
170
|
+
inputs: string[];
|
|
171
|
+
capabilities: {
|
|
172
|
+
conversations: boolean;
|
|
173
|
+
system: boolean;
|
|
174
|
+
tools: boolean;
|
|
175
|
+
images: boolean;
|
|
176
|
+
files: boolean;
|
|
177
|
+
structured_output: boolean;
|
|
178
|
+
streaming: true;
|
|
179
|
+
thinking: boolean;
|
|
180
|
+
artifacts: boolean;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** A stored file. */
|
|
184
|
+
interface FileObject {
|
|
185
|
+
id: string;
|
|
186
|
+
object: "file";
|
|
187
|
+
filename: string;
|
|
188
|
+
media_type: string;
|
|
189
|
+
size: number;
|
|
190
|
+
created_at: string;
|
|
191
|
+
}
|
|
192
|
+
/** A batch of chat requests. */
|
|
193
|
+
interface BatchObject {
|
|
194
|
+
id: string;
|
|
195
|
+
object: "batch";
|
|
196
|
+
status: "in_progress" | "ended";
|
|
197
|
+
request_counts: {
|
|
198
|
+
total: number;
|
|
199
|
+
done: number;
|
|
200
|
+
};
|
|
201
|
+
created_at: string;
|
|
202
|
+
expires_at: string;
|
|
203
|
+
ended_at: string | null;
|
|
204
|
+
}
|
|
205
|
+
/** A saved conversation. */
|
|
206
|
+
interface SessionObject {
|
|
207
|
+
id: string;
|
|
208
|
+
object: "session";
|
|
209
|
+
created_at: string;
|
|
210
|
+
updated_at: string;
|
|
211
|
+
title?: string | null;
|
|
212
|
+
}
|
|
213
|
+
/** A chat request without the transport flag; `stream` is chosen by the method you call. */
|
|
214
|
+
type ChatParams = Omit<ChatRequest, "stream">;
|
|
215
|
+
/** One request inside a batch. */
|
|
216
|
+
interface BatchRequestItem {
|
|
217
|
+
custom_id: string;
|
|
218
|
+
params: ChatParams;
|
|
219
|
+
}
|
|
220
|
+
/** One line of batch results: the reply fields, or an `error`. */
|
|
221
|
+
type BatchResultLine = {
|
|
222
|
+
custom_id: string;
|
|
223
|
+
error?: {
|
|
224
|
+
type: string;
|
|
225
|
+
message: string;
|
|
226
|
+
};
|
|
227
|
+
} & Partial<ChatReply>;
|
|
228
|
+
/** A list reply. */
|
|
229
|
+
interface List<T> {
|
|
230
|
+
object: "list";
|
|
231
|
+
data: T[];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
declare class Batches {
|
|
235
|
+
private readonly client;
|
|
236
|
+
constructor(client: Antarya);
|
|
237
|
+
create(p: {
|
|
238
|
+
requests: BatchRequestItem[];
|
|
239
|
+
}, opts?: CallOptions): Promise<BatchObject>;
|
|
240
|
+
get(id: string, opts?: CallOptions): Promise<BatchObject>;
|
|
241
|
+
cancel(id: string, opts?: CallOptions): Promise<BatchObject>;
|
|
242
|
+
/** The finished results, one parsed line at a time. */
|
|
243
|
+
results(id: string, opts?: CallOptions): AsyncGenerator<BatchResultLine>;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
type StreamEvent = {
|
|
247
|
+
type: "reply.start";
|
|
248
|
+
id: string;
|
|
249
|
+
model: string;
|
|
250
|
+
} | {
|
|
251
|
+
type: "content.delta";
|
|
252
|
+
index: number;
|
|
253
|
+
part: ReplyPart;
|
|
254
|
+
text?: string;
|
|
255
|
+
} | {
|
|
256
|
+
type: "reply.done";
|
|
257
|
+
stop_reason: StopReason;
|
|
258
|
+
usage: Usage;
|
|
259
|
+
} | {
|
|
260
|
+
type: string;
|
|
261
|
+
[key: string]: unknown;
|
|
262
|
+
};
|
|
263
|
+
/** A streamed chat reply. Iterate it for events, or call finalReply() for the assembled reply. */
|
|
264
|
+
declare class ChatStream implements AsyncIterable<StreamEvent> {
|
|
265
|
+
private readonly res;
|
|
266
|
+
private readonly controller?;
|
|
267
|
+
private onClose?;
|
|
268
|
+
requestId?: string;
|
|
269
|
+
private aborted;
|
|
270
|
+
private reader?;
|
|
271
|
+
private readonly events;
|
|
272
|
+
private id;
|
|
273
|
+
private model;
|
|
274
|
+
private parts;
|
|
275
|
+
private done?;
|
|
276
|
+
/** onClose runs once, when the stream ends, fails, is left early or is stopped. */
|
|
277
|
+
constructor(res: Response, controller?: AbortController | undefined, onClose?: (() => void) | undefined);
|
|
278
|
+
[Symbol.asyncIterator](): AsyncGenerator<StreamEvent>;
|
|
279
|
+
/** Stops the stream. Iteration ends without an error. */
|
|
280
|
+
abort(): void;
|
|
281
|
+
private close;
|
|
282
|
+
/** Reads the rest of the stream and returns the assembled reply. */
|
|
283
|
+
finalReply(): Promise<ChatReply>;
|
|
284
|
+
private run;
|
|
285
|
+
private shape;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
declare class Chat {
|
|
289
|
+
private readonly client;
|
|
290
|
+
constructor(client: Antarya);
|
|
291
|
+
create(p: ChatParams & {
|
|
292
|
+
stream?: false;
|
|
293
|
+
}, opts?: CallOptions): Promise<ChatReply>;
|
|
294
|
+
create(p: ChatParams & {
|
|
295
|
+
stream: true;
|
|
296
|
+
}, opts?: CallOptions): Promise<ChatStream>;
|
|
297
|
+
/** Starts a streamed reply. Call `abort()` on the result to stop it. */
|
|
298
|
+
stream(p: ChatParams & {
|
|
299
|
+
stream?: boolean;
|
|
300
|
+
}, opts?: CallOptions): Promise<ChatStream>;
|
|
301
|
+
countTokens(p: ChatParams, opts?: CallOptions): Promise<{
|
|
302
|
+
input_tokens: number;
|
|
303
|
+
}>;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** A Node ReadStream, found by shape so this file needs no Node imports. */
|
|
307
|
+
type PathStream = AsyncIterable<Uint8Array | string> & {
|
|
308
|
+
path: string | Uint8Array;
|
|
309
|
+
};
|
|
310
|
+
type FileInput = Blob | Uint8Array | ArrayBuffer | PathStream;
|
|
311
|
+
interface CreateFileParams {
|
|
312
|
+
file: FileInput;
|
|
313
|
+
filename?: string;
|
|
314
|
+
media_type?: string;
|
|
315
|
+
}
|
|
316
|
+
declare class Files {
|
|
317
|
+
private readonly client;
|
|
318
|
+
constructor(client: Antarya);
|
|
319
|
+
create(p: CreateFileParams, opts?: CallOptions): Promise<FileObject>;
|
|
320
|
+
list(opts?: CallOptions): Promise<List<FileObject>>;
|
|
321
|
+
get(id: string, opts?: CallOptions): Promise<FileObject>;
|
|
322
|
+
delete(id: string, opts?: CallOptions): Promise<unknown>;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
declare class Models {
|
|
326
|
+
private readonly client;
|
|
327
|
+
constructor(client: Antarya);
|
|
328
|
+
list(opts?: CallOptions): Promise<List<ModelObject>>;
|
|
329
|
+
get(id: string, opts?: CallOptions): Promise<ModelObject>;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
declare class Sessions {
|
|
333
|
+
private readonly client;
|
|
334
|
+
constructor(client: Antarya);
|
|
335
|
+
create(p?: {
|
|
336
|
+
metadata?: Record<string, string>;
|
|
337
|
+
}, opts?: CallOptions): Promise<SessionObject>;
|
|
338
|
+
list(opts?: CallOptions): Promise<List<SessionObject>>;
|
|
339
|
+
get(id: string, opts?: CallOptions): Promise<SessionObject>;
|
|
340
|
+
delete(id: string, opts?: CallOptions): Promise<unknown>;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
interface ClientOptions {
|
|
344
|
+
apiKey?: string;
|
|
345
|
+
baseURL?: string;
|
|
346
|
+
maxRetries?: number;
|
|
347
|
+
timeout?: number;
|
|
348
|
+
fetch?: typeof fetch;
|
|
349
|
+
/** For tests: replaces the wait between retries. */
|
|
350
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
351
|
+
}
|
|
352
|
+
/** Optional last argument of every resource method. */
|
|
353
|
+
interface CallOptions {
|
|
354
|
+
signal?: AbortSignal;
|
|
355
|
+
}
|
|
356
|
+
interface RequestOptions {
|
|
357
|
+
body?: unknown;
|
|
358
|
+
form?: FormData;
|
|
359
|
+
auth?: boolean;
|
|
360
|
+
signal?: AbortSignal;
|
|
361
|
+
stream?: boolean;
|
|
362
|
+
}
|
|
363
|
+
declare class Antarya {
|
|
364
|
+
#private;
|
|
365
|
+
static APIError: typeof APIError;
|
|
366
|
+
static BadRequestError: typeof BadRequestError;
|
|
367
|
+
static AuthenticationError: typeof AuthenticationError;
|
|
368
|
+
static PermissionDeniedError: typeof PermissionDeniedError;
|
|
369
|
+
static NotFoundError: typeof NotFoundError;
|
|
370
|
+
static RequestTooLargeError: typeof RequestTooLargeError;
|
|
371
|
+
static RateLimitError: typeof RateLimitError;
|
|
372
|
+
static InternalServerError: typeof InternalServerError;
|
|
373
|
+
static OverloadedError: typeof OverloadedError;
|
|
374
|
+
static APIConnectionError: typeof APIConnectionError;
|
|
375
|
+
static APITimeoutError: typeof APITimeoutError;
|
|
376
|
+
readonly baseURL: string;
|
|
377
|
+
readonly maxRetries: number;
|
|
378
|
+
readonly timeout: number;
|
|
379
|
+
readonly chat: Chat;
|
|
380
|
+
readonly models: Models;
|
|
381
|
+
readonly files: Files;
|
|
382
|
+
readonly batches: Batches;
|
|
383
|
+
readonly sessions: Sessions;
|
|
384
|
+
private readonly fetchFn;
|
|
385
|
+
private readonly sleep;
|
|
386
|
+
constructor(opts?: ClientOptions);
|
|
387
|
+
/** The key in use. A getter, so it is not listed by JSON.stringify or console.log. */
|
|
388
|
+
get apiKey(): string | undefined;
|
|
389
|
+
/** Keeps the key and the circular resource links out of JSON.stringify. */
|
|
390
|
+
toJSON(): {
|
|
391
|
+
baseURL: string;
|
|
392
|
+
};
|
|
393
|
+
request<T>(method: "GET" | "POST" | "DELETE", path: string, opts?: RequestOptions): Promise<T | Response>;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export { APIConnectionError, APIError, APITimeoutError, ARTIFACT_KINDS, Antarya, AuthenticationError, BadRequestError, ChatStream, InternalServerError, NotFoundError, OverloadedError, PermissionDeniedError, RateLimitError, RequestTooLargeError, Antarya as default, errorFrom };
|
|
397
|
+
export type { ArtifactPart, BatchObject, BatchRequestItem, BatchResultLine, CallOptions, ChatParams, ChatReply, ChatRequest, ClientOptions, CreateFileParams, FileInput, FileObject, FilePart, ImagePart, InlineFilePart, List, Message, ModelObject, Part, ReplyPart, RequestOptions, ResponseFormat, SessionObject, StopReason, StreamEvent, TextPart, ThinkingNote, ToolCallPart, ToolChoice, ToolDef, ToolResultPart, Usage };
|