@dvina/sdk 3.3.124

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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +449 -0
  3. package/dist/_generated_documents-DF34ZUJ3.js +4 -0
  4. package/dist/_generated_documents-DF34ZUJ3.js.map +1 -0
  5. package/dist/_generated_documents-W4RHWJ4B.cjs +2041 -0
  6. package/dist/_generated_documents-W4RHWJ4B.cjs.map +1 -0
  7. package/dist/adapters/angular/index.cjs +163 -0
  8. package/dist/adapters/angular/index.cjs.map +1 -0
  9. package/dist/adapters/angular/index.d.cts +254 -0
  10. package/dist/adapters/angular/index.d.ts +254 -0
  11. package/dist/adapters/angular/index.js +159 -0
  12. package/dist/adapters/angular/index.js.map +1 -0
  13. package/dist/adapters/react/index.cjs +51 -0
  14. package/dist/adapters/react/index.cjs.map +1 -0
  15. package/dist/adapters/react/index.d.cts +62 -0
  16. package/dist/adapters/react/index.d.ts +62 -0
  17. package/dist/adapters/react/index.js +49 -0
  18. package/dist/adapters/react/index.js.map +1 -0
  19. package/dist/billing/index.cjs +26 -0
  20. package/dist/billing/index.cjs.map +1 -0
  21. package/dist/billing/index.d.cts +338 -0
  22. package/dist/billing/index.d.ts +338 -0
  23. package/dist/billing/index.js +5 -0
  24. package/dist/billing/index.js.map +1 -0
  25. package/dist/chunk-4QKWHQT2.cjs +104 -0
  26. package/dist/chunk-4QKWHQT2.cjs.map +1 -0
  27. package/dist/chunk-5WRI5ZAA.js +29 -0
  28. package/dist/chunk-5WRI5ZAA.js.map +1 -0
  29. package/dist/chunk-7JUBGIQ2.js +1008 -0
  30. package/dist/chunk-7JUBGIQ2.js.map +1 -0
  31. package/dist/chunk-7XBJ77RJ.js +103 -0
  32. package/dist/chunk-7XBJ77RJ.js.map +1 -0
  33. package/dist/chunk-DHUFVGJR.cjs +20389 -0
  34. package/dist/chunk-DHUFVGJR.cjs.map +1 -0
  35. package/dist/chunk-DZUJEN5N.cjs +32 -0
  36. package/dist/chunk-DZUJEN5N.cjs.map +1 -0
  37. package/dist/chunk-GDK2HJTF.cjs +1346 -0
  38. package/dist/chunk-GDK2HJTF.cjs.map +1 -0
  39. package/dist/chunk-KG3GNTYI.js +1339 -0
  40. package/dist/chunk-KG3GNTYI.js.map +1 -0
  41. package/dist/chunk-KV5SP7RP.cjs +114 -0
  42. package/dist/chunk-KV5SP7RP.cjs.map +1 -0
  43. package/dist/chunk-NPIKZKLU.cjs +27 -0
  44. package/dist/chunk-NPIKZKLU.cjs.map +1 -0
  45. package/dist/chunk-OAAZZUYL.cjs +1517 -0
  46. package/dist/chunk-OAAZZUYL.cjs.map +1 -0
  47. package/dist/chunk-P4BYTXZ7.js +98 -0
  48. package/dist/chunk-P4BYTXZ7.js.map +1 -0
  49. package/dist/chunk-PDM2KR7T.js +392 -0
  50. package/dist/chunk-PDM2KR7T.js.map +1 -0
  51. package/dist/chunk-QOZI2HY5.js +24 -0
  52. package/dist/chunk-QOZI2HY5.js.map +1 -0
  53. package/dist/chunk-RFBLNKW6.js +20035 -0
  54. package/dist/chunk-RFBLNKW6.js.map +1 -0
  55. package/dist/chunk-UELAE75E.cjs +408 -0
  56. package/dist/chunk-UELAE75E.cjs.map +1 -0
  57. package/dist/client-9Rwj21T9.d.cts +77 -0
  58. package/dist/client-Bskq7sc_.d.ts +77 -0
  59. package/dist/client-CLhQragb.d.cts +446 -0
  60. package/dist/client-CLhQragb.d.ts +446 -0
  61. package/dist/error-CsVoUTY8.d.cts +95 -0
  62. package/dist/error-CsVoUTY8.d.ts +95 -0
  63. package/dist/index-BrGSfyXq.d.cts +79 -0
  64. package/dist/index-zPcVLagO.d.ts +79 -0
  65. package/dist/index.cjs +1675 -0
  66. package/dist/index.cjs.map +1 -0
  67. package/dist/index.d.cts +9943 -0
  68. package/dist/index.d.ts +9943 -0
  69. package/dist/index.js +10 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/inference/index.cjs +70 -0
  72. package/dist/inference/index.cjs.map +1 -0
  73. package/dist/inference/index.d.cts +80 -0
  74. package/dist/inference/index.d.ts +80 -0
  75. package/dist/inference/index.js +5 -0
  76. package/dist/inference/index.js.map +1 -0
  77. package/dist/pagination/index.cjs +34 -0
  78. package/dist/pagination/index.cjs.map +1 -0
  79. package/dist/pagination/index.d.cts +6 -0
  80. package/dist/pagination/index.d.ts +6 -0
  81. package/dist/pagination/index.js +5 -0
  82. package/dist/pagination/index.js.map +1 -0
  83. package/dist/sync-engine-DVKQO-1-.d.cts +423 -0
  84. package/dist/sync-engine-cLwTqdjv.d.ts +423 -0
  85. package/dist/types-2RotD0Ab.d.cts +102 -0
  86. package/dist/types-2RotD0Ab.d.ts +102 -0
  87. package/package.json +143 -0
@@ -0,0 +1,446 @@
1
+ /**
2
+ * A single part of a multi-modal message content array.
3
+ */
4
+ interface ContentPart {
5
+ type: 'text' | 'image_url';
6
+ text?: string;
7
+ image_url?: {
8
+ url: string;
9
+ };
10
+ }
11
+ /**
12
+ * A tool call requested by the assistant.
13
+ */
14
+ interface ToolCall {
15
+ id: string;
16
+ type: 'function';
17
+ function: {
18
+ name: string;
19
+ arguments: string;
20
+ };
21
+ }
22
+ /**
23
+ * A tool definition that can be passed to the model.
24
+ */
25
+ interface Tool {
26
+ type: 'function';
27
+ function: {
28
+ name: string;
29
+ description?: string;
30
+ parameters?: Record<string, unknown>;
31
+ };
32
+ }
33
+ /**
34
+ * Tool choice configuration.
35
+ * - `'auto'`: model decides whether to call a tool
36
+ * - `'none'`: model never calls a tool
37
+ * - `'required'`: model must call a tool
38
+ * - `{ type: 'function'; function: { name } }`: model must call the specified tool
39
+ */
40
+ type ToolChoice = 'auto' | 'none' | 'required' | {
41
+ type: 'function';
42
+ function: {
43
+ name: string;
44
+ };
45
+ };
46
+ /**
47
+ * A single message in a chat conversation.
48
+ */
49
+ interface ChatMessage {
50
+ role: 'system' | 'user' | 'assistant' | 'tool';
51
+ content: string | ContentPart[];
52
+ name?: string;
53
+ tool_calls?: ToolCall[];
54
+ tool_call_id?: string;
55
+ }
56
+ /**
57
+ * Request body for POST /chat/completions (non-streaming).
58
+ */
59
+ interface ChatCompletionRequest {
60
+ model: string;
61
+ messages: ChatMessage[];
62
+ temperature?: number;
63
+ max_completion_tokens?: number;
64
+ stream?: false;
65
+ tools?: Tool[];
66
+ tool_choice?: ToolChoice;
67
+ }
68
+ /**
69
+ * Request body for POST /chat/completions (streaming).
70
+ */
71
+ interface ChatCompletionStreamRequest {
72
+ model: string;
73
+ messages: ChatMessage[];
74
+ temperature?: number;
75
+ max_completion_tokens?: number;
76
+ stream: true;
77
+ tools?: Tool[];
78
+ tool_choice?: ToolChoice;
79
+ }
80
+ /**
81
+ * Request body for POST /responses (non-streaming).
82
+ */
83
+ interface ResponsesRequest {
84
+ model: string;
85
+ input: string | unknown[];
86
+ stream?: false;
87
+ instructions?: string;
88
+ temperature?: number;
89
+ max_output_tokens?: number;
90
+ tools?: unknown[];
91
+ tool_choice?: unknown;
92
+ reasoning?: {
93
+ effort?: string;
94
+ summary?: string;
95
+ };
96
+ text?: {
97
+ format?: unknown;
98
+ };
99
+ include?: string[];
100
+ [key: string]: unknown;
101
+ }
102
+ /**
103
+ * Request body for POST /responses (streaming).
104
+ */
105
+ interface ResponsesStreamRequest {
106
+ model: string;
107
+ input: string | unknown[];
108
+ stream: true;
109
+ instructions?: string;
110
+ temperature?: number;
111
+ max_output_tokens?: number;
112
+ tools?: unknown[];
113
+ tool_choice?: unknown;
114
+ reasoning?: {
115
+ effort?: string;
116
+ summary?: string;
117
+ };
118
+ text?: {
119
+ format?: unknown;
120
+ };
121
+ include?: string[];
122
+ [key: string]: unknown;
123
+ }
124
+ /**
125
+ * Token usage statistics returned by the API.
126
+ */
127
+ interface Usage {
128
+ prompt_tokens: number;
129
+ completion_tokens: number;
130
+ total_tokens: number;
131
+ }
132
+ /**
133
+ * A single choice in a non-streaming chat completion response.
134
+ */
135
+ interface ChatCompletionChoice {
136
+ index: number;
137
+ message: {
138
+ role: string;
139
+ content: string | null;
140
+ tool_calls?: ToolCall[];
141
+ };
142
+ finish_reason: string;
143
+ }
144
+ /**
145
+ * Non-streaming chat completion response (OpenAI-compatible).
146
+ */
147
+ interface ChatCompletionResponse {
148
+ id: string;
149
+ object: 'chat.completion';
150
+ created: number;
151
+ model: string;
152
+ choices: ChatCompletionChoice[];
153
+ usage: Usage;
154
+ }
155
+ /**
156
+ * A delta object within a streaming chunk.
157
+ */
158
+ interface StreamDelta {
159
+ role?: string;
160
+ content?: string;
161
+ tool_calls?: unknown[];
162
+ }
163
+ /**
164
+ * A single choice in a streaming chat completion chunk.
165
+ */
166
+ interface StreamChunkChoice {
167
+ index: number;
168
+ delta: StreamDelta;
169
+ finish_reason: string | null;
170
+ }
171
+ /**
172
+ * A single SSE chunk during streaming chat completion.
173
+ */
174
+ interface ChatCompletionChunk {
175
+ id: string;
176
+ object: 'chat.completion.chunk';
177
+ created: number;
178
+ model: string;
179
+ choices: StreamChunkChoice[];
180
+ usage?: Usage;
181
+ }
182
+ /**
183
+ * A model object returned by the models endpoint.
184
+ */
185
+ interface Model {
186
+ id: string;
187
+ object: 'model';
188
+ created: number;
189
+ owned_by: string;
190
+ }
191
+ /**
192
+ * Response from GET /models.
193
+ */
194
+ interface ModelListResponse {
195
+ object: 'list';
196
+ data: Model[];
197
+ }
198
+ /**
199
+ * OpenAI-compatible error response body from the inference API.
200
+ */
201
+ interface InferenceErrorResponse {
202
+ error: {
203
+ message: string;
204
+ type: string;
205
+ code: string;
206
+ };
207
+ }
208
+ /**
209
+ * Response from GET /health.
210
+ */
211
+ interface HealthResponse {
212
+ status: 'ok';
213
+ models: number;
214
+ openaiHost: string;
215
+ anthropicHost: string;
216
+ apiVersion: string;
217
+ timestamp: number;
218
+ }
219
+ /**
220
+ * Options for creating an inference client.
221
+ */
222
+ interface InferenceClientOptions {
223
+ /** Base URL for the inference API (e.g. 'https://api.dvina.ai/inference/v1'). */
224
+ baseUrl: string;
225
+ /**
226
+ * Static auth token. Use for scripts, CLI tools, and tests.
227
+ * Mutually exclusive with `getToken`.
228
+ */
229
+ token?: string;
230
+ /**
231
+ * Async callback that returns an auth token.
232
+ * When called with `{ forceRefresh: true }`, the callback must bypass any
233
+ * cache and obtain a brand-new token.
234
+ * Mutually exclusive with `token`.
235
+ */
236
+ getToken?: (options?: {
237
+ forceRefresh?: boolean;
238
+ }) => Promise<string>;
239
+ /** Custom headers to include in every request. */
240
+ headers?: Record<string, string>;
241
+ /**
242
+ * Request timeout in milliseconds. Default: 120000 (2 minutes).
243
+ */
244
+ timeout?: number;
245
+ }
246
+
247
+ /**
248
+ * Parse a Server-Sent Events response body into an async iterable of typed chunks.
249
+ *
250
+ * Handles:
251
+ * - Chunked network reads (buffer splitting across `data:` boundaries)
252
+ * - `\r\n` and `\n` line endings
253
+ * - `data: [DONE]` termination signal
254
+ * - Mid-stream errors (yields what it can, then throws)
255
+ *
256
+ * @param body - A ReadableStream<Uint8Array> from a fetch response
257
+ * @returns An async iterable of parsed SSE data objects
258
+ */
259
+ declare function parseSSEStream<T = ChatCompletionChunk>(body: ReadableStream<Uint8Array>): AsyncGenerator<T, void, undefined>;
260
+ /**
261
+ * A chat completion stream that also aggregates the full response for convenience.
262
+ *
263
+ * Implements `AsyncIterable<ChatCompletionChunk>` for chunk-by-chunk processing,
264
+ * and provides helper methods to extract the final assembled text and usage.
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * const stream = await client.chat.completions.stream({ ... });
269
+ *
270
+ * // Option 1: Iterate chunk by chunk
271
+ * for await (const chunk of stream) {
272
+ * process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
273
+ * }
274
+ *
275
+ * // Option 2: Get aggregated result after iteration
276
+ * const text = stream.getText();
277
+ * const usage = stream.getUsage();
278
+ * ```
279
+ */
280
+ declare class ChatCompletionStream implements AsyncIterable<ChatCompletionChunk> {
281
+ private readonly _chunks;
282
+ private readonly _source;
283
+ private _consumed;
284
+ constructor(source: AsyncGenerator<ChatCompletionChunk, void, undefined>);
285
+ [Symbol.asyncIterator](): AsyncIterator<ChatCompletionChunk>;
286
+ /**
287
+ * Concatenate all content deltas into a single string.
288
+ * Must be called after the stream has been fully consumed.
289
+ */
290
+ getText(): string;
291
+ /**
292
+ * Get the token usage from the final chunk (if the server included it).
293
+ * Must be called after the stream has been fully consumed.
294
+ */
295
+ getUsage(): {
296
+ prompt_tokens: number;
297
+ completion_tokens: number;
298
+ total_tokens: number;
299
+ } | undefined;
300
+ /**
301
+ * Get the collected chunks array.
302
+ * Must be called after the stream has been fully consumed.
303
+ */
304
+ getChunks(): readonly ChatCompletionChunk[];
305
+ }
306
+
307
+ /**
308
+ * Namespaced chat completions API.
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * // Non-streaming
313
+ * const response = await sdk.inference.chat.completions.create({
314
+ * model: 'claude-sonnet-4-6',
315
+ * messages: [{ role: 'user', content: 'Hello!' }],
316
+ * });
317
+ *
318
+ * // Streaming
319
+ * const stream = await sdk.inference.chat.completions.stream({
320
+ * model: 'claude-sonnet-4-6',
321
+ * messages: [{ role: 'user', content: 'Hello!' }],
322
+ * });
323
+ * for await (const chunk of stream) {
324
+ * process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
325
+ * }
326
+ * ```
327
+ */
328
+ interface ChatCompletions {
329
+ /** Create a non-streaming chat completion. */
330
+ create(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
331
+ /** Create a streaming chat completion. Returns an async iterable of chunks. */
332
+ stream(request: Omit<ChatCompletionStreamRequest, 'stream'>): Promise<ChatCompletionStream>;
333
+ }
334
+ interface Chat {
335
+ completions: ChatCompletions;
336
+ }
337
+ /**
338
+ * Namespaced responses API.
339
+ *
340
+ * @example
341
+ * ```typescript
342
+ * // Non-streaming
343
+ * const response = await sdk.inference.responses.create({
344
+ * model: 'gpt-5.2',
345
+ * input: 'Hello!',
346
+ * });
347
+ *
348
+ * // Streaming
349
+ * const stream = await sdk.inference.responses.stream({
350
+ * model: 'gpt-5.2',
351
+ * input: 'Hello!',
352
+ * });
353
+ * for await (const event of stream) {
354
+ * console.log(event);
355
+ * }
356
+ * ```
357
+ */
358
+ interface Responses {
359
+ /** Create a non-streaming response. */
360
+ create(request: ResponsesRequest): Promise<unknown>;
361
+ /** Create a streaming response. Returns a raw async iterable of SSE events. */
362
+ stream(request: Omit<ResponsesStreamRequest, 'stream'>): Promise<AsyncIterable<unknown>>;
363
+ }
364
+ /**
365
+ * Namespaced models API.
366
+ */
367
+ interface Models {
368
+ /** List all available models. */
369
+ list(): Promise<ModelListResponse>;
370
+ /** Get a single model by ID. */
371
+ get(modelId: string): Promise<Model>;
372
+ }
373
+ /**
374
+ * The Dvina Inference client.
375
+ *
376
+ * Provides a typed interface to the `/inference/v1` REST API with full
377
+ * SSE streaming support. Follows the OpenAI client naming conventions
378
+ * (`sdk.inference.chat.completions`, `sdk.inference.responses`, `sdk.inference.models`).
379
+ *
380
+ * @example
381
+ * ```typescript
382
+ * const sdk = new DvinaSdk({ token: 'your-jwt-token' });
383
+ *
384
+ * // Chat completion
385
+ * const response = await sdk.inference.chat.completions.create({
386
+ * model: 'claude-sonnet-4-6',
387
+ * messages: [{ role: 'user', content: 'Hello!' }],
388
+ * });
389
+ *
390
+ * // Streaming
391
+ * const stream = await sdk.inference.chat.completions.stream({
392
+ * model: 'claude-sonnet-4-6',
393
+ * messages: [{ role: 'user', content: 'Tell me a story' }],
394
+ * });
395
+ * for await (const chunk of stream) {
396
+ * process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
397
+ * }
398
+ * ```
399
+ */
400
+ interface InferenceClient {
401
+ chat: Chat;
402
+ responses: Responses;
403
+ models: Models;
404
+ /** Check the health of the inference API. */
405
+ health(): Promise<HealthResponse>;
406
+ }
407
+ /**
408
+ * Create an inference client using pre-resolved baseUrl and getToken from the SDK.
409
+ * This is the internal factory called by `createDvinaClient` — it does NOT resolve
410
+ * token/options itself, it receives them from the parent SDK client.
411
+ *
412
+ * @internal
413
+ */
414
+ declare function createInferenceClientInternal(baseUrl: string, getToken: (options?: {
415
+ forceRefresh?: boolean;
416
+ }) => Promise<string>, options?: {
417
+ headers?: Record<string, string>;
418
+ timeout?: number;
419
+ }): InferenceClient;
420
+ /**
421
+ * Create a standalone Dvina Inference client.
422
+ *
423
+ * Use this when you need inference without the full GraphQL SDK.
424
+ * For most cases, prefer `sdk.inference` which shares auth with the SDK.
425
+ *
426
+ * @param options - Client configuration (base URL, auth, headers, timeout)
427
+ * @returns A fully configured inference client
428
+ *
429
+ * @example
430
+ * ```typescript
431
+ * import { createInferenceClient } from '@dvina/sdk/inference';
432
+ *
433
+ * const client = createInferenceClient({
434
+ * baseUrl: 'https://api.dvina.ai/inference/v1',
435
+ * token: 'your-jwt-token',
436
+ * });
437
+ *
438
+ * const response = await client.chat.completions.create({
439
+ * model: 'claude-sonnet-4-6',
440
+ * messages: [{ role: 'user', content: 'Hello!' }],
441
+ * });
442
+ * ```
443
+ */
444
+ declare function createInferenceClient(options: InferenceClientOptions): InferenceClient;
445
+
446
+ export { type Chat as C, type HealthResponse as H, type InferenceClient as I, type Model as M, type Responses as R, type StreamChunkChoice as S, type Tool as T, type Usage as U, type ChatCompletionChoice as a, type ChatCompletionChunk as b, type ChatCompletionRequest as c, type ChatCompletionResponse as d, ChatCompletionStream as e, type ChatCompletionStreamRequest as f, type ChatCompletions as g, type ChatMessage as h, type ContentPart as i, type InferenceClientOptions as j, type InferenceErrorResponse as k, type ModelListResponse as l, type Models as m, type ResponsesRequest as n, type ResponsesStreamRequest as o, type StreamDelta as p, type ToolCall as q, type ToolChoice as r, createInferenceClient as s, createInferenceClientInternal as t, parseSSEStream as u };