@anuma/sdk 3.3.0 → 3.3.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.
@@ -9,145 +9,438 @@ import * as _nozbe_watermelondb_Schema from '@nozbe/watermelondb/Schema';
9
9
  import { Class } from '@nozbe/watermelondb/types';
10
10
  import { DatabaseAdapter } from '@nozbe/watermelondb/adapters/type';
11
11
 
12
- /**
13
- * ExtraFields contains additional metadata
14
- */
15
- type LlmapiChatCompletionExtraFields = {
12
+ type AuthToken = string | undefined;
13
+ interface Auth {
16
14
  /**
17
- * Latency is the request latency in milliseconds
15
+ * Which part of the request do we use to send the auth?
16
+ *
17
+ * @default 'header'
18
18
  */
19
- latency?: number;
19
+ in?: 'header' | 'query' | 'cookie';
20
20
  /**
21
- * ModelRequested is the model that was requested
21
+ * Header or query parameter name.
22
+ *
23
+ * @default 'Authorization'
22
24
  */
23
- model_requested?: string;
25
+ name?: string;
26
+ scheme?: 'basic' | 'bearer';
27
+ type: 'apiKey' | 'http';
28
+ }
29
+
30
+ interface SerializerOptions<T> {
24
31
  /**
25
- * Provider is the LLM provider used (e.g., "openai", "anthropic")
32
+ * @default true
26
33
  */
27
- provider?: string;
34
+ explode: boolean;
35
+ style: T;
36
+ }
37
+ type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
38
+ type ObjectStyle = 'form' | 'deepObject';
39
+
40
+ type QuerySerializer = (query: Record<string, unknown>) => string;
41
+ type BodySerializer = (body: unknown) => unknown;
42
+ type QuerySerializerOptionsObject = {
43
+ allowReserved?: boolean;
44
+ array?: Partial<SerializerOptions<ArrayStyle>>;
45
+ object?: Partial<SerializerOptions<ObjectStyle>>;
46
+ };
47
+ type QuerySerializerOptions = QuerySerializerOptionsObject & {
28
48
  /**
29
- * RequestType is always "chat_completion"
49
+ * Per-parameter serialization overrides. When provided, these settings
50
+ * override the global array/object settings for specific parameter names.
30
51
  */
31
- request_type?: string;
52
+ parameters?: Record<string, QuerySerializerOptionsObject>;
32
53
  };
33
- type LlmapiChatCompletionResponse$1 = {
54
+
55
+ type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
56
+ type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
34
57
  /**
35
- * A list of chat completion choices. Can be more than one if `n` is greater
36
- * than 1.
58
+ * Returns the final request URL.
37
59
  */
38
- choices?: Array<OpenaiChatCompletionChoice>;
60
+ buildUrl: BuildUrlFn;
61
+ getConfig: () => Config;
62
+ request: RequestFn;
63
+ setConfig: (config: Config) => Config;
64
+ } & {
65
+ [K in HttpMethod]: MethodFn;
66
+ } & ([SseFn] extends [never] ? {
67
+ sse?: never;
68
+ } : {
69
+ sse: {
70
+ [K in HttpMethod]: SseFn;
71
+ };
72
+ });
73
+ interface Config$1 {
39
74
  /**
40
- * The Unix timestamp (in seconds) of when the chat completion was created.
75
+ * Auth token or a function returning auth token. The resolved value will be
76
+ * added to the request payload as defined by its `security` array.
41
77
  */
42
- created?: number;
78
+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
43
79
  /**
44
- * A unique identifier for the chat completion.
80
+ * A function for serializing request body parameter. By default,
81
+ * {@link JSON.stringify()} will be used.
45
82
  */
46
- id?: string;
83
+ bodySerializer?: BodySerializer | null;
47
84
  /**
48
- * The model used for the chat completion.
85
+ * An object containing any HTTP headers that you want to pre-populate your
86
+ * `Headers` object with.
87
+ *
88
+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
49
89
  */
50
- model?: string;
90
+ headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
51
91
  /**
52
- * The object type, which is always `chat.completion`.
92
+ * The request method.
93
+ *
94
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
53
95
  */
54
- object?: string;
55
- portal?: LlmapiPortalChatCompletionResponse;
56
- service_tier?: OpenaiChatCompletionServiceTier;
96
+ method?: Uppercase<HttpMethod>;
57
97
  /**
58
- * This fingerprint represents the backend configuration that the model runs with.
98
+ * A function for serializing request query parameters. By default, arrays
99
+ * will be exploded in form style, objects will be exploded in deepObject
100
+ * style, and reserved characters are percent-encoded.
59
101
  *
60
- * Can be used in conjunction with the `seed` request parameter to understand when
61
- * backend changes have been made that might impact determinism.
102
+ * This method will have no effect if the native `paramsSerializer()` Axios
103
+ * API function is used.
104
+ *
105
+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
62
106
  */
63
- system_fingerprint?: string;
64
- usage?: OpenaiCompletionUsage;
65
- };
66
- type LlmapiMcpTool = {
107
+ querySerializer?: QuerySerializer | QuerySerializerOptions;
67
108
  /**
68
- * Description is the description of the tool
109
+ * A function validating request data. This is useful if you want to ensure
110
+ * the request conforms to the desired shape, so it can be safely sent to
111
+ * the server.
69
112
  */
70
- description?: string;
113
+ requestValidator?: (data: unknown) => Promise<unknown>;
71
114
  /**
72
- * InputSchema is the JSON schema describing the tool's input
115
+ * A function transforming response data before it's returned. This is useful
116
+ * for post-processing data, e.g., converting ISO strings into Date objects.
73
117
  */
74
- input_schema?: unknown;
118
+ responseTransformer?: (data: unknown) => Promise<unknown>;
75
119
  /**
76
- * Name is the name of the tool
120
+ * A function validating response data. This is useful if you want to ensure
121
+ * the response conforms to the desired shape, so it can be safely passed to
122
+ * the transformers and returned to the user.
77
123
  */
78
- name?: string;
79
- };
80
- type LlmapiMessage = {
124
+ responseValidator?: (data: unknown) => Promise<unknown>;
125
+ }
126
+
127
+ type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & {
81
128
  /**
82
- * Content is the message content
129
+ * Fetch API implementation. You can use this option to provide a custom
130
+ * fetch instance.
131
+ *
132
+ * @default globalThis.fetch
83
133
  */
84
- content?: Array<LlmapiMessageContentPart>;
85
- role?: LlmapiRole;
134
+ fetch?: typeof fetch;
86
135
  /**
87
- * ToolCallID is the ID of the tool call this message is responding to (only for tool role)
136
+ * Implementing clients can call request interceptors inside this hook.
88
137
  */
89
- tool_call_id?: string;
138
+ onRequest?: (url: string, init: RequestInit) => Promise<Request>;
90
139
  /**
91
- * ToolCalls contains tool/function calls made by the assistant (only for assistant role)
140
+ * Callback invoked when a network or parsing error occurs during streaming.
141
+ *
142
+ * This option applies only if the endpoint returns a stream of events.
143
+ *
144
+ * @param error The error that occurred.
92
145
  */
93
- tool_calls?: Array<LlmapiToolCall>;
146
+ onSseError?: (error: unknown) => void;
94
147
  /**
95
- * Type is the message type (for Responses API: "message")
148
+ * Callback invoked when an event is streamed from the server.
149
+ *
150
+ * This option applies only if the endpoint returns a stream of events.
151
+ *
152
+ * @param event Event streamed from the server.
153
+ * @returns Nothing (void).
96
154
  */
97
- type?: string;
98
- };
99
- /**
100
- * File is used when Type=input_file (for Responses API)
101
- */
102
- type LlmapiMessageContentFile = {
155
+ onSseEvent?: (event: StreamEvent<TData>) => void;
156
+ serializedBody?: RequestInit['body'];
103
157
  /**
104
- * FileData is the base64-encoded file content
158
+ * Default retry delay in milliseconds.
159
+ *
160
+ * This option applies only if the endpoint returns a stream of events.
161
+ *
162
+ * @default 3000
105
163
  */
106
- file_data?: string;
164
+ sseDefaultRetryDelay?: number;
107
165
  /**
108
- * FileID is the ID of an uploaded file
166
+ * Maximum number of retry attempts before giving up.
109
167
  */
110
- file_id?: string;
168
+ sseMaxRetryAttempts?: number;
111
169
  /**
112
- * FileURL is the URL to the file
170
+ * Maximum retry delay in milliseconds.
171
+ *
172
+ * Applies only when exponential backoff is used.
173
+ *
174
+ * This option applies only if the endpoint returns a stream of events.
175
+ *
176
+ * @default 30000
113
177
  */
114
- file_url?: string;
178
+ sseMaxRetryDelay?: number;
115
179
  /**
116
- * Filename is the name of the file
180
+ * Optional sleep function for retry backoff.
181
+ *
182
+ * Defaults to using `setTimeout`.
117
183
  */
118
- filename?: string;
184
+ sseSleepFn?: (ms: number) => Promise<void>;
185
+ url: string;
119
186
  };
120
- /**
121
- * ImageURL is used when Type=image_url or Type=input_image
122
- */
123
- type LlmapiMessageContentImage = {
124
- /**
125
- * Detail is the OpenAI detail hint (auto|low|high)
126
- */
127
- detail?: string;
128
- /**
129
- * URL is the image URL or data URI
130
- */
131
- url?: string;
187
+ interface StreamEvent<TData = unknown> {
188
+ data: TData;
189
+ event?: string;
190
+ id?: string;
191
+ retry?: number;
192
+ }
193
+ type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
194
+ stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
132
195
  };
133
- type LlmapiMessageContentPart = {
134
- file?: LlmapiMessageContentFile;
135
- image_url?: LlmapiMessageContentImage;
196
+
197
+ type ErrInterceptor<Err, Res, Options> = (error: Err,
198
+ /** response may be undefined due to a network error where no response object is produced */
199
+ response: Res | undefined, options: Options) => Err | Promise<Err>;
200
+ type ReqInterceptor<Options> = (options: Options) => void | Promise<void>;
201
+ type ResInterceptor<Res, Options> = (response: Res, options: Options) => Res | Promise<Res>;
202
+ declare class Interceptors<Interceptor> {
203
+ fns: Array<Interceptor | null>;
204
+ clear(): void;
205
+ eject(id: number | Interceptor): void;
206
+ exists(id: number | Interceptor): boolean;
207
+ getInterceptorIndex(id: number | Interceptor): number;
208
+ update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
209
+ use(fn: Interceptor): number;
210
+ }
211
+ interface Middleware<Res, Err, Options> {
212
+ error: Interceptors<ErrInterceptor<Err, Res, Options>>;
213
+ request: Interceptors<ReqInterceptor<Options>>;
214
+ response: Interceptors<ResInterceptor<Res, Options>>;
215
+ }
216
+
217
+ interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Config$1 {
136
218
  /**
137
- * Text holds the text content when Type=text or Type=input_text
219
+ * Base URL for all requests made by this client.
138
220
  */
139
- text?: string;
221
+ baseUrl?: T['baseUrl'];
140
222
  /**
141
- * Type is the block type (`text`, `image_url`, or `input_file`)
223
+ * Fetch API implementation. You can use this option to provide a custom
224
+ * fetch instance.
225
+ *
226
+ * @default globalThis.fetch
142
227
  */
143
- type?: string;
144
- };
145
- type LlmapiModel = {
146
- architecture?: LlmapiModelArchitecture;
228
+ fetch?: typeof fetch;
147
229
  /**
148
- * CanonicalSlug is the canonical slug for the model
230
+ * Return the response data parsed in a specified format. By default, `auto`
231
+ * will infer the appropriate method from the `Content-Type` response header.
232
+ * You can override this behavior with any of the {@link Body} methods.
233
+ * Select `stream` if you don't want to parse response data at all.
234
+ *
235
+ * @default 'auto'
149
236
  */
150
- canonical_slug?: string;
237
+ parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
238
+ /**
239
+ * Throw an error instead of returning it in the response?
240
+ *
241
+ * @default false
242
+ */
243
+ throwOnError?: T['throwOnError'];
244
+ }
245
+ interface RequestOptions<TData = unknown, ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
246
+ throwOnError: ThrowOnError;
247
+ }>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
248
+ /**
249
+ * Any body that you want to add to your request.
250
+ *
251
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
252
+ */
253
+ body?: unknown;
254
+ path?: Record<string, unknown>;
255
+ query?: Record<string, unknown>;
256
+ /**
257
+ * Security mechanism(s) to use for the request.
258
+ */
259
+ security?: ReadonlyArray<Auth>;
260
+ url: Url;
261
+ }
262
+ interface ResolvedRequestOptions<ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, ThrowOnError, Url> {
263
+ headers: Headers;
264
+ serializedBody?: string;
265
+ }
266
+ type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<{
267
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
268
+ response: Response;
269
+ }> : Promise<({
270
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
271
+ error: undefined;
272
+ } | {
273
+ data: undefined;
274
+ error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
275
+ }) & {
276
+ /** response may be undefined due to a network error where no response object is produced */
277
+ response?: Response;
278
+ }>;
279
+ interface ClientOptions {
280
+ baseUrl?: string;
281
+ throwOnError?: boolean;
282
+ }
283
+ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
284
+ type SseFn = <TData = unknown, _TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<never, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData>>;
285
+ type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
286
+ type BuildUrlFn = <TData extends {
287
+ body?: unknown;
288
+ path?: Record<string, unknown>;
289
+ query?: Record<string, unknown>;
290
+ url: string;
291
+ }>(options: TData & Options<TData>) => string;
292
+ type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
293
+ interceptors: Middleware<Response, unknown, ResolvedRequestOptions>;
294
+ };
295
+ interface TDataShape {
296
+ body?: unknown;
297
+ headers?: unknown;
298
+ path?: unknown;
299
+ query?: unknown;
300
+ url: string;
301
+ }
302
+ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
303
+ type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = OmitKeys<RequestOptions<TResponse, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
304
+
305
+ /**
306
+ * ExtraFields contains additional metadata
307
+ */
308
+ type LlmapiChatCompletionExtraFields = {
309
+ /**
310
+ * Latency is the request latency in milliseconds
311
+ */
312
+ latency?: number;
313
+ /**
314
+ * ModelRequested is the model that was requested
315
+ */
316
+ model_requested?: string;
317
+ /**
318
+ * Provider is the LLM provider used (e.g., "openai", "anthropic")
319
+ */
320
+ provider?: string;
321
+ /**
322
+ * RequestType is always "chat_completion"
323
+ */
324
+ request_type?: string;
325
+ };
326
+ type LlmapiChatCompletionResponse$1 = {
327
+ /**
328
+ * A list of chat completion choices. Can be more than one if `n` is greater
329
+ * than 1.
330
+ */
331
+ choices?: Array<OpenaiChatCompletionChoice>;
332
+ /**
333
+ * The Unix timestamp (in seconds) of when the chat completion was created.
334
+ */
335
+ created?: number;
336
+ /**
337
+ * A unique identifier for the chat completion.
338
+ */
339
+ id?: string;
340
+ /**
341
+ * The model used for the chat completion.
342
+ */
343
+ model?: string;
344
+ /**
345
+ * The object type, which is always `chat.completion`.
346
+ */
347
+ object?: string;
348
+ portal?: LlmapiPortalChatCompletionResponse;
349
+ service_tier?: OpenaiChatCompletionServiceTier;
350
+ /**
351
+ * This fingerprint represents the backend configuration that the model runs with.
352
+ *
353
+ * Can be used in conjunction with the `seed` request parameter to understand when
354
+ * backend changes have been made that might impact determinism.
355
+ */
356
+ system_fingerprint?: string;
357
+ usage?: OpenaiCompletionUsage;
358
+ };
359
+ type LlmapiMcpTool = {
360
+ /**
361
+ * Description is the description of the tool
362
+ */
363
+ description?: string;
364
+ /**
365
+ * InputSchema is the JSON schema describing the tool's input
366
+ */
367
+ input_schema?: unknown;
368
+ /**
369
+ * Name is the name of the tool
370
+ */
371
+ name?: string;
372
+ };
373
+ type LlmapiMessage = {
374
+ /**
375
+ * Content is the message content
376
+ */
377
+ content?: Array<LlmapiMessageContentPart>;
378
+ role?: LlmapiRole;
379
+ /**
380
+ * ToolCallID is the ID of the tool call this message is responding to (only for tool role)
381
+ */
382
+ tool_call_id?: string;
383
+ /**
384
+ * ToolCalls contains tool/function calls made by the assistant (only for assistant role)
385
+ */
386
+ tool_calls?: Array<LlmapiToolCall>;
387
+ /**
388
+ * Type is the message type (for Responses API: "message")
389
+ */
390
+ type?: string;
391
+ };
392
+ /**
393
+ * File is used when Type=input_file (for Responses API)
394
+ */
395
+ type LlmapiMessageContentFile = {
396
+ /**
397
+ * FileData is the base64-encoded file content
398
+ */
399
+ file_data?: string;
400
+ /**
401
+ * FileID is the ID of an uploaded file
402
+ */
403
+ file_id?: string;
404
+ /**
405
+ * FileURL is the URL to the file
406
+ */
407
+ file_url?: string;
408
+ /**
409
+ * Filename is the name of the file
410
+ */
411
+ filename?: string;
412
+ };
413
+ /**
414
+ * ImageURL is used when Type=image_url or Type=input_image
415
+ */
416
+ type LlmapiMessageContentImage = {
417
+ /**
418
+ * Detail is the OpenAI detail hint (auto|low|high)
419
+ */
420
+ detail?: string;
421
+ /**
422
+ * URL is the image URL or data URI
423
+ */
424
+ url?: string;
425
+ };
426
+ type LlmapiMessageContentPart = {
427
+ file?: LlmapiMessageContentFile;
428
+ image_url?: LlmapiMessageContentImage;
429
+ /**
430
+ * Text holds the text content when Type=text or Type=input_text
431
+ */
432
+ text?: string;
433
+ /**
434
+ * Type is the block type (`text`, `image_url`, or `input_file`)
435
+ */
436
+ type?: string;
437
+ };
438
+ type LlmapiModel = {
439
+ architecture?: LlmapiModelArchitecture;
440
+ /**
441
+ * CanonicalSlug is the canonical slug for the model
442
+ */
443
+ canonical_slug?: string;
151
444
  /**
152
445
  * ContextLength is the maximum context length in tokens
153
446
  */
@@ -1329,295 +1622,6 @@ type ParamOptString = {
1329
1622
  value?: string;
1330
1623
  };
1331
1624
 
1332
- type AuthToken = string | undefined;
1333
- interface Auth {
1334
- /**
1335
- * Which part of the request do we use to send the auth?
1336
- *
1337
- * @default 'header'
1338
- */
1339
- in?: 'header' | 'query' | 'cookie';
1340
- /**
1341
- * Header or query parameter name.
1342
- *
1343
- * @default 'Authorization'
1344
- */
1345
- name?: string;
1346
- scheme?: 'basic' | 'bearer';
1347
- type: 'apiKey' | 'http';
1348
- }
1349
-
1350
- interface SerializerOptions<T> {
1351
- /**
1352
- * @default true
1353
- */
1354
- explode: boolean;
1355
- style: T;
1356
- }
1357
- type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
1358
- type ObjectStyle = 'form' | 'deepObject';
1359
-
1360
- type QuerySerializer = (query: Record<string, unknown>) => string;
1361
- type BodySerializer = (body: any) => any;
1362
- type QuerySerializerOptionsObject = {
1363
- allowReserved?: boolean;
1364
- array?: Partial<SerializerOptions<ArrayStyle>>;
1365
- object?: Partial<SerializerOptions<ObjectStyle>>;
1366
- };
1367
- type QuerySerializerOptions = QuerySerializerOptionsObject & {
1368
- /**
1369
- * Per-parameter serialization overrides. When provided, these settings
1370
- * override the global array/object settings for specific parameter names.
1371
- */
1372
- parameters?: Record<string, QuerySerializerOptionsObject>;
1373
- };
1374
-
1375
- type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
1376
- type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
1377
- /**
1378
- * Returns the final request URL.
1379
- */
1380
- buildUrl: BuildUrlFn;
1381
- getConfig: () => Config;
1382
- request: RequestFn;
1383
- setConfig: (config: Config) => Config;
1384
- } & {
1385
- [K in HttpMethod]: MethodFn;
1386
- } & ([SseFn] extends [never] ? {
1387
- sse?: never;
1388
- } : {
1389
- sse: {
1390
- [K in HttpMethod]: SseFn;
1391
- };
1392
- });
1393
- interface Config$1 {
1394
- /**
1395
- * Auth token or a function returning auth token. The resolved value will be
1396
- * added to the request payload as defined by its `security` array.
1397
- */
1398
- auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
1399
- /**
1400
- * A function for serializing request body parameter. By default,
1401
- * {@link JSON.stringify()} will be used.
1402
- */
1403
- bodySerializer?: BodySerializer | null;
1404
- /**
1405
- * An object containing any HTTP headers that you want to pre-populate your
1406
- * `Headers` object with.
1407
- *
1408
- * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
1409
- */
1410
- headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
1411
- /**
1412
- * The request method.
1413
- *
1414
- * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
1415
- */
1416
- method?: Uppercase<HttpMethod>;
1417
- /**
1418
- * A function for serializing request query parameters. By default, arrays
1419
- * will be exploded in form style, objects will be exploded in deepObject
1420
- * style, and reserved characters are percent-encoded.
1421
- *
1422
- * This method will have no effect if the native `paramsSerializer()` Axios
1423
- * API function is used.
1424
- *
1425
- * {@link https://swagger.io/docs/specification/serialization/#query View examples}
1426
- */
1427
- querySerializer?: QuerySerializer | QuerySerializerOptions;
1428
- /**
1429
- * A function validating request data. This is useful if you want to ensure
1430
- * the request conforms to the desired shape, so it can be safely sent to
1431
- * the server.
1432
- */
1433
- requestValidator?: (data: unknown) => Promise<unknown>;
1434
- /**
1435
- * A function transforming response data before it's returned. This is useful
1436
- * for post-processing data, e.g. converting ISO strings into Date objects.
1437
- */
1438
- responseTransformer?: (data: unknown) => Promise<unknown>;
1439
- /**
1440
- * A function validating response data. This is useful if you want to ensure
1441
- * the response conforms to the desired shape, so it can be safely passed to
1442
- * the transformers and returned to the user.
1443
- */
1444
- responseValidator?: (data: unknown) => Promise<unknown>;
1445
- }
1446
-
1447
- type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & {
1448
- /**
1449
- * Fetch API implementation. You can use this option to provide a custom
1450
- * fetch instance.
1451
- *
1452
- * @default globalThis.fetch
1453
- */
1454
- fetch?: typeof fetch;
1455
- /**
1456
- * Implementing clients can call request interceptors inside this hook.
1457
- */
1458
- onRequest?: (url: string, init: RequestInit) => Promise<Request>;
1459
- /**
1460
- * Callback invoked when a network or parsing error occurs during streaming.
1461
- *
1462
- * This option applies only if the endpoint returns a stream of events.
1463
- *
1464
- * @param error The error that occurred.
1465
- */
1466
- onSseError?: (error: unknown) => void;
1467
- /**
1468
- * Callback invoked when an event is streamed from the server.
1469
- *
1470
- * This option applies only if the endpoint returns a stream of events.
1471
- *
1472
- * @param event Event streamed from the server.
1473
- * @returns Nothing (void).
1474
- */
1475
- onSseEvent?: (event: StreamEvent<TData>) => void;
1476
- serializedBody?: RequestInit['body'];
1477
- /**
1478
- * Default retry delay in milliseconds.
1479
- *
1480
- * This option applies only if the endpoint returns a stream of events.
1481
- *
1482
- * @default 3000
1483
- */
1484
- sseDefaultRetryDelay?: number;
1485
- /**
1486
- * Maximum number of retry attempts before giving up.
1487
- */
1488
- sseMaxRetryAttempts?: number;
1489
- /**
1490
- * Maximum retry delay in milliseconds.
1491
- *
1492
- * Applies only when exponential backoff is used.
1493
- *
1494
- * This option applies only if the endpoint returns a stream of events.
1495
- *
1496
- * @default 30000
1497
- */
1498
- sseMaxRetryDelay?: number;
1499
- /**
1500
- * Optional sleep function for retry backoff.
1501
- *
1502
- * Defaults to using `setTimeout`.
1503
- */
1504
- sseSleepFn?: (ms: number) => Promise<void>;
1505
- url: string;
1506
- };
1507
- interface StreamEvent<TData = unknown> {
1508
- data: TData;
1509
- event?: string;
1510
- id?: string;
1511
- retry?: number;
1512
- }
1513
- type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
1514
- stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
1515
- };
1516
-
1517
- type ErrInterceptor<Err, Res, Options> = (error: Err, response: Res, options: Options) => Err | Promise<Err>;
1518
- type ReqInterceptor<Options> = (options: Options) => void | Promise<void>;
1519
- type ResInterceptor<Res, Options> = (response: Res, options: Options) => Res | Promise<Res>;
1520
- declare class Interceptors<Interceptor> {
1521
- fns: Array<Interceptor | null>;
1522
- clear(): void;
1523
- eject(id: number | Interceptor): void;
1524
- exists(id: number | Interceptor): boolean;
1525
- getInterceptorIndex(id: number | Interceptor): number;
1526
- update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
1527
- use(fn: Interceptor): number;
1528
- }
1529
- interface Middleware<Res, Err, Options> {
1530
- error: Interceptors<ErrInterceptor<Err, Res, Options>>;
1531
- request: Interceptors<ReqInterceptor<Options>>;
1532
- response: Interceptors<ResInterceptor<Res, Options>>;
1533
- }
1534
-
1535
- interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Config$1 {
1536
- /**
1537
- * Base URL for all requests made by this client.
1538
- */
1539
- baseUrl?: T['baseUrl'];
1540
- /**
1541
- * Fetch API implementation. You can use this option to provide a custom
1542
- * fetch instance.
1543
- *
1544
- * @default globalThis.fetch
1545
- */
1546
- fetch?: typeof fetch;
1547
- /**
1548
- * Return the response data parsed in a specified format. By default, `auto`
1549
- * will infer the appropriate method from the `Content-Type` response header.
1550
- * You can override this behavior with any of the {@link Body} methods.
1551
- * Select `stream` if you don't want to parse response data at all.
1552
- *
1553
- * @default 'auto'
1554
- */
1555
- parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
1556
- /**
1557
- * Throw an error instead of returning it in the response?
1558
- *
1559
- * @default false
1560
- */
1561
- throwOnError?: T['throwOnError'];
1562
- }
1563
- interface RequestOptions<TData = unknown, ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
1564
- throwOnError: ThrowOnError;
1565
- }>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
1566
- /**
1567
- * Any body that you want to add to your request.
1568
- *
1569
- * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
1570
- */
1571
- body?: unknown;
1572
- path?: Record<string, unknown>;
1573
- query?: Record<string, unknown>;
1574
- /**
1575
- * Security mechanism(s) to use for the request.
1576
- */
1577
- security?: ReadonlyArray<Auth>;
1578
- url: Url;
1579
- }
1580
- interface ResolvedRequestOptions<ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, ThrowOnError, Url> {
1581
- serializedBody?: string;
1582
- }
1583
- type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<{
1584
- data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
1585
- response: Response;
1586
- }> : Promise<({
1587
- data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
1588
- error: undefined;
1589
- } | {
1590
- data: undefined;
1591
- error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
1592
- }) & {
1593
- response: Response;
1594
- }>;
1595
- interface ClientOptions {
1596
- baseUrl?: string;
1597
- throwOnError?: boolean;
1598
- }
1599
- type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
1600
- type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
1601
- type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
1602
- type BuildUrlFn = <TData extends {
1603
- body?: unknown;
1604
- path?: Record<string, unknown>;
1605
- query?: Record<string, unknown>;
1606
- url: string;
1607
- }>(options: TData & Options<TData>) => string;
1608
- type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
1609
- interceptors: Middleware<Response, unknown, ResolvedRequestOptions>;
1610
- };
1611
- interface TDataShape {
1612
- body?: unknown;
1613
- headers?: unknown;
1614
- path?: unknown;
1615
- query?: unknown;
1616
- url: string;
1617
- }
1618
- type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
1619
- type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = OmitKeys<RequestOptions<TResponse, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
1620
-
1621
1625
  type LlmapiChatCompletionTool = {
1622
1626
  [key: string]: unknown;
1623
1627
  };