@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.
- package/LICENSE +21 -0
- package/README.md +449 -0
- package/dist/_generated_documents-DF34ZUJ3.js +4 -0
- package/dist/_generated_documents-DF34ZUJ3.js.map +1 -0
- package/dist/_generated_documents-W4RHWJ4B.cjs +2041 -0
- package/dist/_generated_documents-W4RHWJ4B.cjs.map +1 -0
- package/dist/adapters/angular/index.cjs +163 -0
- package/dist/adapters/angular/index.cjs.map +1 -0
- package/dist/adapters/angular/index.d.cts +254 -0
- package/dist/adapters/angular/index.d.ts +254 -0
- package/dist/adapters/angular/index.js +159 -0
- package/dist/adapters/angular/index.js.map +1 -0
- package/dist/adapters/react/index.cjs +51 -0
- package/dist/adapters/react/index.cjs.map +1 -0
- package/dist/adapters/react/index.d.cts +62 -0
- package/dist/adapters/react/index.d.ts +62 -0
- package/dist/adapters/react/index.js +49 -0
- package/dist/adapters/react/index.js.map +1 -0
- package/dist/billing/index.cjs +26 -0
- package/dist/billing/index.cjs.map +1 -0
- package/dist/billing/index.d.cts +338 -0
- package/dist/billing/index.d.ts +338 -0
- package/dist/billing/index.js +5 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/chunk-4QKWHQT2.cjs +104 -0
- package/dist/chunk-4QKWHQT2.cjs.map +1 -0
- package/dist/chunk-5WRI5ZAA.js +29 -0
- package/dist/chunk-5WRI5ZAA.js.map +1 -0
- package/dist/chunk-7JUBGIQ2.js +1008 -0
- package/dist/chunk-7JUBGIQ2.js.map +1 -0
- package/dist/chunk-7XBJ77RJ.js +103 -0
- package/dist/chunk-7XBJ77RJ.js.map +1 -0
- package/dist/chunk-DHUFVGJR.cjs +20389 -0
- package/dist/chunk-DHUFVGJR.cjs.map +1 -0
- package/dist/chunk-DZUJEN5N.cjs +32 -0
- package/dist/chunk-DZUJEN5N.cjs.map +1 -0
- package/dist/chunk-GDK2HJTF.cjs +1346 -0
- package/dist/chunk-GDK2HJTF.cjs.map +1 -0
- package/dist/chunk-KG3GNTYI.js +1339 -0
- package/dist/chunk-KG3GNTYI.js.map +1 -0
- package/dist/chunk-KV5SP7RP.cjs +114 -0
- package/dist/chunk-KV5SP7RP.cjs.map +1 -0
- package/dist/chunk-NPIKZKLU.cjs +27 -0
- package/dist/chunk-NPIKZKLU.cjs.map +1 -0
- package/dist/chunk-OAAZZUYL.cjs +1517 -0
- package/dist/chunk-OAAZZUYL.cjs.map +1 -0
- package/dist/chunk-P4BYTXZ7.js +98 -0
- package/dist/chunk-P4BYTXZ7.js.map +1 -0
- package/dist/chunk-PDM2KR7T.js +392 -0
- package/dist/chunk-PDM2KR7T.js.map +1 -0
- package/dist/chunk-QOZI2HY5.js +24 -0
- package/dist/chunk-QOZI2HY5.js.map +1 -0
- package/dist/chunk-RFBLNKW6.js +20035 -0
- package/dist/chunk-RFBLNKW6.js.map +1 -0
- package/dist/chunk-UELAE75E.cjs +408 -0
- package/dist/chunk-UELAE75E.cjs.map +1 -0
- package/dist/client-9Rwj21T9.d.cts +77 -0
- package/dist/client-Bskq7sc_.d.ts +77 -0
- package/dist/client-CLhQragb.d.cts +446 -0
- package/dist/client-CLhQragb.d.ts +446 -0
- package/dist/error-CsVoUTY8.d.cts +95 -0
- package/dist/error-CsVoUTY8.d.ts +95 -0
- package/dist/index-BrGSfyXq.d.cts +79 -0
- package/dist/index-zPcVLagO.d.ts +79 -0
- package/dist/index.cjs +1675 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9943 -0
- package/dist/index.d.ts +9943 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/inference/index.cjs +70 -0
- package/dist/inference/index.cjs.map +1 -0
- package/dist/inference/index.d.cts +80 -0
- package/dist/inference/index.d.ts +80 -0
- package/dist/inference/index.js +5 -0
- package/dist/inference/index.js.map +1 -0
- package/dist/pagination/index.cjs +34 -0
- package/dist/pagination/index.cjs.map +1 -0
- package/dist/pagination/index.d.cts +6 -0
- package/dist/pagination/index.d.ts +6 -0
- package/dist/pagination/index.js +5 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/sync-engine-DVKQO-1-.d.cts +423 -0
- package/dist/sync-engine-cLwTqdjv.d.ts +423 -0
- package/dist/types-2RotD0Ab.d.cts +102 -0
- package/dist/types-2RotD0Ab.d.ts +102 -0
- package/package.json +143 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkKV5SP7RP_cjs = require('./chunk-KV5SP7RP.cjs');
|
|
4
|
+
|
|
5
|
+
// src/inference/errors.ts
|
|
6
|
+
var DvinaInferenceError = class extends chunkKV5SP7RP_cjs.DvinaError {
|
|
7
|
+
/** HTTP status code from the server */
|
|
8
|
+
status;
|
|
9
|
+
/** OpenAI-compatible error type (e.g. 'invalid_request_error') */
|
|
10
|
+
type;
|
|
11
|
+
/** Machine-readable error code (e.g. 'model_not_found') */
|
|
12
|
+
code;
|
|
13
|
+
constructor(message, status, type, code, cause) {
|
|
14
|
+
super(message, cause);
|
|
15
|
+
this.name = "DvinaInferenceError";
|
|
16
|
+
this.status = status;
|
|
17
|
+
this.type = type;
|
|
18
|
+
this.code = code;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var DvinaRateLimitError = class extends DvinaInferenceError {
|
|
22
|
+
/** Retry-After header value in seconds, if provided by the server */
|
|
23
|
+
retryAfter;
|
|
24
|
+
constructor(message, retryAfter, cause) {
|
|
25
|
+
super(message, 429, "rate_limit_error", "rate_limit_exceeded", cause);
|
|
26
|
+
this.name = "DvinaRateLimitError";
|
|
27
|
+
this.retryAfter = retryAfter;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var DvinaQuotaError = class extends DvinaInferenceError {
|
|
31
|
+
constructor(message = "Token quota exceeded", cause) {
|
|
32
|
+
super(message, 403, "insufficient_quota", "token_limit_reached", cause);
|
|
33
|
+
this.name = "DvinaQuotaError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var DvinaInferenceAuthError = class extends DvinaInferenceError {
|
|
37
|
+
constructor(message = "Inference authentication failed", status = 401, cause) {
|
|
38
|
+
super(message, status, "authentication_error", "unauthorized", cause);
|
|
39
|
+
this.name = "DvinaInferenceAuthError";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var DvinaStreamError = class extends DvinaInferenceError {
|
|
43
|
+
constructor(message, cause) {
|
|
44
|
+
super(message, 0, "stream_error", "stream_interrupted", cause);
|
|
45
|
+
this.name = "DvinaStreamError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var DvinaContextLengthError = class extends DvinaInferenceError {
|
|
49
|
+
constructor(message = "Context length exceeded", cause) {
|
|
50
|
+
super(message, 400, "invalid_request_error", "context_length_exceeded", cause);
|
|
51
|
+
this.name = "DvinaContextLengthError";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var DvinaTimeoutError = class extends DvinaInferenceError {
|
|
55
|
+
constructor(message = "Request timed out", cause) {
|
|
56
|
+
super(message, 400, "timeout_error", "request_timeout", cause);
|
|
57
|
+
this.name = "DvinaTimeoutError";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var DvinaProviderUnavailableError = class extends DvinaInferenceError {
|
|
61
|
+
constructor(message = "Provider unavailable", cause) {
|
|
62
|
+
super(message, 502, "gateway_error", "provider_unavailable", cause);
|
|
63
|
+
this.name = "DvinaProviderUnavailableError";
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var DvinaProviderError = class extends DvinaInferenceError {
|
|
67
|
+
constructor(message = "Provider error", status = 502, cause) {
|
|
68
|
+
super(message, status, "api_error", "provider_error", cause);
|
|
69
|
+
this.name = "DvinaProviderError";
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var DvinaDeploymentError = class extends DvinaInferenceError {
|
|
73
|
+
constructor(message = "Deployment not found", cause) {
|
|
74
|
+
super(message, 502, "invalid_request_error", "deployment_not_found", cause);
|
|
75
|
+
this.name = "DvinaDeploymentError";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var DvinaUnsupportedModelError = class extends DvinaInferenceError {
|
|
79
|
+
constructor(message = "Unsupported model", cause) {
|
|
80
|
+
super(message, 400, "invalid_request_error", "unsupported_model", cause);
|
|
81
|
+
this.name = "DvinaUnsupportedModelError";
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// src/inference/stream.ts
|
|
86
|
+
async function* parseSSEStream(body) {
|
|
87
|
+
const reader = body.getReader();
|
|
88
|
+
const decoder = new TextDecoder();
|
|
89
|
+
let buffer = "";
|
|
90
|
+
try {
|
|
91
|
+
while (true) {
|
|
92
|
+
const { done, value } = await reader.read();
|
|
93
|
+
if (done) {
|
|
94
|
+
if (buffer.trim()) {
|
|
95
|
+
const chunk = parseDataLine(buffer.trim());
|
|
96
|
+
if (chunk !== void 0) {
|
|
97
|
+
yield chunk;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
buffer += decoder.decode(value, { stream: true });
|
|
103
|
+
const lines = buffer.split(/\r?\n/);
|
|
104
|
+
buffer = lines.pop() ?? "";
|
|
105
|
+
for (const line of lines) {
|
|
106
|
+
if (line === "") continue;
|
|
107
|
+
if (line.startsWith(":")) continue;
|
|
108
|
+
if (line.startsWith("data: ")) {
|
|
109
|
+
const data = line.slice(6);
|
|
110
|
+
if (data === "[DONE]") {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const parsed = JSON.parse(data);
|
|
115
|
+
yield parsed;
|
|
116
|
+
} catch {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (line.startsWith("event: error")) {
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} catch (error) {
|
|
124
|
+
throw new DvinaStreamError(
|
|
125
|
+
`SSE stream interrupted: ${error instanceof Error ? error.message : String(error)}`,
|
|
126
|
+
error instanceof Error ? error : void 0
|
|
127
|
+
);
|
|
128
|
+
} finally {
|
|
129
|
+
reader.releaseLock();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function parseDataLine(line) {
|
|
133
|
+
if (!line.startsWith("data: ")) return void 0;
|
|
134
|
+
const data = line.slice(6);
|
|
135
|
+
if (data === "[DONE]") return void 0;
|
|
136
|
+
try {
|
|
137
|
+
return JSON.parse(data);
|
|
138
|
+
} catch {
|
|
139
|
+
return void 0;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
var ChatCompletionStream = class {
|
|
143
|
+
_chunks = [];
|
|
144
|
+
_source;
|
|
145
|
+
_consumed = false;
|
|
146
|
+
constructor(source) {
|
|
147
|
+
this._source = source;
|
|
148
|
+
}
|
|
149
|
+
async *[Symbol.asyncIterator]() {
|
|
150
|
+
if (this._consumed) {
|
|
151
|
+
for (const chunk of this._chunks) {
|
|
152
|
+
yield chunk;
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
this._consumed = true;
|
|
157
|
+
for await (const chunk of this._source) {
|
|
158
|
+
this._chunks.push(chunk);
|
|
159
|
+
yield chunk;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Concatenate all content deltas into a single string.
|
|
164
|
+
* Must be called after the stream has been fully consumed.
|
|
165
|
+
*/
|
|
166
|
+
getText() {
|
|
167
|
+
const parts = [];
|
|
168
|
+
for (const chunk of this._chunks) {
|
|
169
|
+
const content = chunk.choices[0]?.delta?.content;
|
|
170
|
+
if (content) {
|
|
171
|
+
parts.push(content);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return parts.join("");
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Get the token usage from the final chunk (if the server included it).
|
|
178
|
+
* Must be called after the stream has been fully consumed.
|
|
179
|
+
*/
|
|
180
|
+
getUsage() {
|
|
181
|
+
for (let i = this._chunks.length - 1; i >= 0; i--) {
|
|
182
|
+
if (this._chunks[i].usage) {
|
|
183
|
+
return this._chunks[i].usage;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return void 0;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get the collected chunks array.
|
|
190
|
+
* Must be called after the stream has been fully consumed.
|
|
191
|
+
*/
|
|
192
|
+
getChunks() {
|
|
193
|
+
return this._chunks;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/inference/client.ts
|
|
198
|
+
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
199
|
+
async function throwForStatus(response) {
|
|
200
|
+
let errorBody;
|
|
201
|
+
try {
|
|
202
|
+
errorBody = await response.json();
|
|
203
|
+
} catch {
|
|
204
|
+
}
|
|
205
|
+
const message = errorBody?.error?.message ?? `HTTP ${response.status}: ${response.statusText}`;
|
|
206
|
+
const type = errorBody?.error?.type ?? "api_error";
|
|
207
|
+
const code = errorBody?.error?.code ?? "unknown";
|
|
208
|
+
if (response.status === 401 || response.status === 403) {
|
|
209
|
+
if (code === "token_limit_reached" || type === "insufficient_quota") {
|
|
210
|
+
throw new DvinaQuotaError(message);
|
|
211
|
+
}
|
|
212
|
+
throw new DvinaInferenceAuthError(message, response.status);
|
|
213
|
+
}
|
|
214
|
+
if (response.status === 429) {
|
|
215
|
+
const retryAfterHeader = response.headers.get("retry-after");
|
|
216
|
+
const retryAfter = retryAfterHeader ? parseInt(retryAfterHeader, 10) : void 0;
|
|
217
|
+
throw new DvinaRateLimitError(message, Number.isNaN(retryAfter) ? void 0 : retryAfter);
|
|
218
|
+
}
|
|
219
|
+
switch (code) {
|
|
220
|
+
case "context_length_exceeded":
|
|
221
|
+
throw new DvinaContextLengthError(message);
|
|
222
|
+
case "request_timeout":
|
|
223
|
+
throw new DvinaTimeoutError(message);
|
|
224
|
+
case "provider_unavailable":
|
|
225
|
+
throw new DvinaProviderUnavailableError(message);
|
|
226
|
+
case "provider_error":
|
|
227
|
+
throw new DvinaProviderError(message, response.status);
|
|
228
|
+
case "deployment_not_found":
|
|
229
|
+
throw new DvinaDeploymentError(message);
|
|
230
|
+
case "unsupported_model":
|
|
231
|
+
throw new DvinaUnsupportedModelError(message);
|
|
232
|
+
}
|
|
233
|
+
throw new DvinaInferenceError(message, response.status, type, code);
|
|
234
|
+
}
|
|
235
|
+
function createInferenceClientInternal(baseUrl, getToken, options) {
|
|
236
|
+
return buildInferenceClient(baseUrl, getToken, options?.headers, options?.timeout);
|
|
237
|
+
}
|
|
238
|
+
function createInferenceClient(options) {
|
|
239
|
+
const baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
240
|
+
let getToken;
|
|
241
|
+
if (options.getToken) {
|
|
242
|
+
getToken = options.getToken;
|
|
243
|
+
} else if (options.token) {
|
|
244
|
+
const staticToken = options.token;
|
|
245
|
+
getToken = async () => staticToken;
|
|
246
|
+
} else {
|
|
247
|
+
throw new Error("InferenceClientOptions must provide either `token` or `getToken`.");
|
|
248
|
+
}
|
|
249
|
+
return buildInferenceClient(baseUrl, getToken, options.headers, options.timeout);
|
|
250
|
+
}
|
|
251
|
+
function buildInferenceClient(baseUrl, getToken, customHeaders, timeout) {
|
|
252
|
+
const timeoutMs = timeout ?? DEFAULT_TIMEOUT_MS;
|
|
253
|
+
const headers = customHeaders ?? {};
|
|
254
|
+
async function buildRequestHeaders() {
|
|
255
|
+
const token = await getToken();
|
|
256
|
+
return {
|
|
257
|
+
"Content-Type": "application/json",
|
|
258
|
+
Authorization: `Bearer ${token}`,
|
|
259
|
+
...headers
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
async function request(method, path, body) {
|
|
263
|
+
const controller = new AbortController();
|
|
264
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
265
|
+
try {
|
|
266
|
+
const reqHeaders = await buildRequestHeaders();
|
|
267
|
+
const response = await fetch(`${baseUrl}${path}`, {
|
|
268
|
+
method,
|
|
269
|
+
headers: reqHeaders,
|
|
270
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0,
|
|
271
|
+
signal: controller.signal
|
|
272
|
+
});
|
|
273
|
+
if (!response.ok) {
|
|
274
|
+
await throwForStatus(response);
|
|
275
|
+
}
|
|
276
|
+
return await response.json();
|
|
277
|
+
} catch (error) {
|
|
278
|
+
if (error instanceof DvinaInferenceError) throw error;
|
|
279
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
280
|
+
throw new DvinaInferenceError(
|
|
281
|
+
`Request timed out after ${timeoutMs}ms`,
|
|
282
|
+
0,
|
|
283
|
+
"timeout_error",
|
|
284
|
+
"request_timeout"
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
throw new DvinaInferenceError(
|
|
288
|
+
`Network error: ${error instanceof Error ? error.message : String(error)}`,
|
|
289
|
+
0,
|
|
290
|
+
"network_error",
|
|
291
|
+
"connection_failed",
|
|
292
|
+
error instanceof Error ? error : void 0
|
|
293
|
+
);
|
|
294
|
+
} finally {
|
|
295
|
+
clearTimeout(timer);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function requestStream(path, body) {
|
|
299
|
+
const controller = new AbortController();
|
|
300
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
301
|
+
try {
|
|
302
|
+
const reqHeaders = await buildRequestHeaders();
|
|
303
|
+
const response = await fetch(`${baseUrl}${path}`, {
|
|
304
|
+
method: "POST",
|
|
305
|
+
headers: reqHeaders,
|
|
306
|
+
body: JSON.stringify(body),
|
|
307
|
+
signal: controller.signal
|
|
308
|
+
});
|
|
309
|
+
clearTimeout(timer);
|
|
310
|
+
if (!response.ok) {
|
|
311
|
+
await throwForStatus(response);
|
|
312
|
+
}
|
|
313
|
+
if (!response.body) {
|
|
314
|
+
throw new DvinaStreamError("Response body is null \u2014 streaming not supported in this environment");
|
|
315
|
+
}
|
|
316
|
+
return response.body;
|
|
317
|
+
} catch (error) {
|
|
318
|
+
clearTimeout(timer);
|
|
319
|
+
if (error instanceof DvinaInferenceError) throw error;
|
|
320
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
321
|
+
throw new DvinaInferenceError(
|
|
322
|
+
`Stream connection timed out after ${timeoutMs}ms`,
|
|
323
|
+
0,
|
|
324
|
+
"timeout_error",
|
|
325
|
+
"request_timeout"
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
throw new DvinaInferenceError(
|
|
329
|
+
`Network error: ${error instanceof Error ? error.message : String(error)}`,
|
|
330
|
+
0,
|
|
331
|
+
"network_error",
|
|
332
|
+
"connection_failed",
|
|
333
|
+
error instanceof Error ? error : void 0
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const completions = {
|
|
338
|
+
async create(req) {
|
|
339
|
+
return request("POST", "/chat/completions", {
|
|
340
|
+
...req,
|
|
341
|
+
stream: false
|
|
342
|
+
});
|
|
343
|
+
},
|
|
344
|
+
async stream(req) {
|
|
345
|
+
const body = await requestStream("/chat/completions", {
|
|
346
|
+
...req,
|
|
347
|
+
stream: true
|
|
348
|
+
});
|
|
349
|
+
const source = parseSSEStream(body);
|
|
350
|
+
return new ChatCompletionStream(source);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
const chat = { completions };
|
|
354
|
+
const responses = {
|
|
355
|
+
async create(req) {
|
|
356
|
+
return request("POST", "/responses", {
|
|
357
|
+
...req,
|
|
358
|
+
stream: false
|
|
359
|
+
});
|
|
360
|
+
},
|
|
361
|
+
async stream(req) {
|
|
362
|
+
const body = await requestStream("/responses", {
|
|
363
|
+
...req,
|
|
364
|
+
stream: true
|
|
365
|
+
});
|
|
366
|
+
return {
|
|
367
|
+
[Symbol.asyncIterator]() {
|
|
368
|
+
return parseSSEStream(body);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
const models = {
|
|
374
|
+
async list() {
|
|
375
|
+
return request("GET", "/models");
|
|
376
|
+
},
|
|
377
|
+
async get(modelId) {
|
|
378
|
+
return request("GET", `/models/${encodeURIComponent(modelId)}`);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
async function health() {
|
|
382
|
+
return request("GET", "/health");
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
chat,
|
|
386
|
+
responses,
|
|
387
|
+
models,
|
|
388
|
+
health
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
exports.ChatCompletionStream = ChatCompletionStream;
|
|
393
|
+
exports.DvinaContextLengthError = DvinaContextLengthError;
|
|
394
|
+
exports.DvinaDeploymentError = DvinaDeploymentError;
|
|
395
|
+
exports.DvinaInferenceAuthError = DvinaInferenceAuthError;
|
|
396
|
+
exports.DvinaInferenceError = DvinaInferenceError;
|
|
397
|
+
exports.DvinaProviderError = DvinaProviderError;
|
|
398
|
+
exports.DvinaProviderUnavailableError = DvinaProviderUnavailableError;
|
|
399
|
+
exports.DvinaQuotaError = DvinaQuotaError;
|
|
400
|
+
exports.DvinaRateLimitError = DvinaRateLimitError;
|
|
401
|
+
exports.DvinaStreamError = DvinaStreamError;
|
|
402
|
+
exports.DvinaTimeoutError = DvinaTimeoutError;
|
|
403
|
+
exports.DvinaUnsupportedModelError = DvinaUnsupportedModelError;
|
|
404
|
+
exports.createInferenceClient = createInferenceClient;
|
|
405
|
+
exports.createInferenceClientInternal = createInferenceClientInternal;
|
|
406
|
+
exports.parseSSEStream = parseSSEStream;
|
|
407
|
+
//# sourceMappingURL=chunk-UELAE75E.cjs.map
|
|
408
|
+
//# sourceMappingURL=chunk-UELAE75E.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/inference/errors.ts","../src/inference/stream.ts","../src/inference/client.ts"],"names":["DvinaError"],"mappings":";;;;;AAMO,IAAM,mBAAA,GAAN,cAAkCA,4BAAA,CAAW;AAAA;AAAA,EAEnC,MAAA;AAAA;AAAA,EAEA,IAAA;AAAA;AAAA,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,MAAM,CAAA;AAAA,IACvC;AAAA,GACD;AAEA,EAAA,MAAM,IAAA,GAAa,EAAE,WAAA,EAAY;AAIjC,EAAA,MAAM,SAAA,GAAuB;AAAA,IAC5B,MAAM,OAAO,GAAA,EAAyC;AACrD,MAAA,OAAO,OAAA,CAAiB,QAAQ,YAAA,EAAc;AAAA,QAC7C,GAAG,GAAA;AAAA,QACH,MAAA,EAAQ;AAAA,OACR,CAAA;AAAA,IACF,CAAA;AAAA,IAEA,MAAM,OAAO,GAAA,EAA8E;AAC1F,MAAA,MAAM,IAAA,GAAO,MAAM,aAAA,CAAc,YAAA,EAAc;AAAA,QAC9C,GAAG,GAAA;AAAA,QACH,MAAA,EAAQ;AAAA,OACR,CAAA;AAID,MAAA,OAAO;AAAA,QACN,CAAC,MAAA,CAAO,aAAa,CAAA,GAAI;AACxB,UAAA,OAAO,eAAwB,IAAI,CAAA;AAAA,QACpC;AAAA,OACD;AAAA,IACD;AAAA,GACD;AAIA,EAAA,MAAM,MAAA,GAAiB;AAAA,IACtB,MAAM,IAAA,GAAmC;AACxC,MAAA,OAAO,OAAA,CAA2B,OAAO,SAAS,CAAA;AAAA,IACnD,CAAA;AAAA,IAEA,MAAM,IAAI,OAAA,EAAiC;AAC1C,MAAA,OAAO,QAAe,KAAA,EAAO,CAAA,QAAA,EAAW,kBAAA,CAAmB,OAAO,CAAC,CAAA,CAAE,CAAA;AAAA,IACtE;AAAA,GACD;AAIA,EAAA,eAAe,MAAA,GAAkC;AAChD,IAAA,OAAO,OAAA,CAAwB,OAAO,SAAS,CAAA;AAAA,EAChD;AAEA,EAAA,OAAO;AAAA,IACN,IAAA;AAAA,IACA,SAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACD;AACD","file":"chunk-UELAE75E.cjs","sourcesContent":["import { DvinaError } from '../error.js';\n\n/**\n * Base error class for inference API errors.\n * Contains the OpenAI-compatible error shape returned by the server.\n */\nexport class DvinaInferenceError extends DvinaError {\n\t/** HTTP status code from the server */\n\tpublic readonly status: number;\n\t/** OpenAI-compatible error type (e.g. 'invalid_request_error') */\n\tpublic readonly type: string;\n\t/** Machine-readable error code (e.g. 'model_not_found') */\n\tpublic readonly code: string;\n\n\tconstructor(message: string, status: number, type: string, code: string, cause?: Error) {\n\t\tsuper(message, cause);\n\t\tthis.name = 'DvinaInferenceError';\n\t\tthis.status = status;\n\t\tthis.type = type;\n\t\tthis.code = code;\n\t}\n}\n\n/**\n * Error thrown when the inference API returns 429 (rate limited).\n */\nexport class DvinaRateLimitError extends DvinaInferenceError {\n\t/** Retry-After header value in seconds, if provided by the server */\n\tpublic readonly retryAfter?: number;\n\n\tconstructor(message: string, retryAfter?: number, cause?: Error) {\n\t\tsuper(message, 429, 'rate_limit_error', 'rate_limit_exceeded', cause);\n\t\tthis.name = 'DvinaRateLimitError';\n\t\tthis.retryAfter = retryAfter;\n\t}\n}\n\n/**\n * Error thrown when the workspace token quota is exceeded (403 with code 'token_limit_reached').\n */\nexport class DvinaQuotaError extends DvinaInferenceError {\n\tconstructor(message = 'Token quota exceeded', cause?: Error) {\n\t\tsuper(message, 403, 'insufficient_quota', 'token_limit_reached', cause);\n\t\tthis.name = 'DvinaQuotaError';\n\t}\n}\n\n/**\n * Error thrown when inference API authentication fails (401/403).\n */\nexport class DvinaInferenceAuthError extends DvinaInferenceError {\n\tconstructor(message = 'Inference authentication failed', status = 401, cause?: Error) {\n\t\tsuper(message, status, 'authentication_error', 'unauthorized', cause);\n\t\tthis.name = 'DvinaInferenceAuthError';\n\t}\n}\n\n/**\n * Error thrown during an SSE stream when the connection drops or a mid-stream error occurs.\n */\nexport class DvinaStreamError extends DvinaInferenceError {\n\tconstructor(message: string, cause?: Error) {\n\t\tsuper(message, 0, 'stream_error', 'stream_interrupted', cause);\n\t\tthis.name = 'DvinaStreamError';\n\t}\n}\n\n/**\n * Error thrown when the prompt exceeds the model's context window (400, code 'context_length_exceeded').\n */\nexport class DvinaContextLengthError extends DvinaInferenceError {\n\tconstructor(message = 'Context length exceeded', cause?: Error) {\n\t\tsuper(message, 400, 'invalid_request_error', 'context_length_exceeded', cause);\n\t\tthis.name = 'DvinaContextLengthError';\n\t}\n}\n\n/**\n * Error thrown when the inference request times out (400, code 'request_timeout').\n */\nexport class DvinaTimeoutError extends DvinaInferenceError {\n\tconstructor(message = 'Request timed out', cause?: Error) {\n\t\tsuper(message, 400, 'timeout_error', 'request_timeout', cause);\n\t\tthis.name = 'DvinaTimeoutError';\n\t}\n}\n\n/**\n * Error thrown when the upstream provider is unreachable (502, code 'provider_unavailable').\n */\nexport class DvinaProviderUnavailableError extends DvinaInferenceError {\n\tconstructor(message = 'Provider unavailable', cause?: Error) {\n\t\tsuper(message, 502, 'gateway_error', 'provider_unavailable', cause);\n\t\tthis.name = 'DvinaProviderUnavailableError';\n\t}\n}\n\n/**\n * Error thrown when the upstream provider returns an error (502/400, code 'provider_error').\n */\nexport class DvinaProviderError extends DvinaInferenceError {\n\tconstructor(message = 'Provider error', status = 502, cause?: Error) {\n\t\tsuper(message, status, 'api_error', 'provider_error', cause);\n\t\tthis.name = 'DvinaProviderError';\n\t}\n}\n\n/**\n * Error thrown when a requested deployment is not found (502, code 'deployment_not_found').\n */\nexport class DvinaDeploymentError extends DvinaInferenceError {\n\tconstructor(message = 'Deployment not found', cause?: Error) {\n\t\tsuper(message, 502, 'invalid_request_error', 'deployment_not_found', cause);\n\t\tthis.name = 'DvinaDeploymentError';\n\t}\n}\n\n/**\n * Error thrown when a requested model is not supported (400, code 'unsupported_model').\n */\nexport class DvinaUnsupportedModelError extends DvinaInferenceError {\n\tconstructor(message = 'Unsupported model', cause?: Error) {\n\t\tsuper(message, 400, 'invalid_request_error', 'unsupported_model', cause);\n\t\tthis.name = 'DvinaUnsupportedModelError';\n\t}\n}\n","import { DvinaStreamError } from './errors.js';\nimport type { ChatCompletionChunk } from './types.js';\n\n/**\n * Parse a Server-Sent Events response body into an async iterable of typed chunks.\n *\n * Handles:\n * - Chunked network reads (buffer splitting across `data:` boundaries)\n * - `\\r\\n` and `\\n` line endings\n * - `data: [DONE]` termination signal\n * - Mid-stream errors (yields what it can, then throws)\n *\n * @param body - A ReadableStream<Uint8Array> from a fetch response\n * @returns An async iterable of parsed SSE data objects\n */\nexport async function* parseSSEStream<T = ChatCompletionChunk>(\n\tbody: ReadableStream<Uint8Array>,\n): AsyncGenerator<T, void, undefined> {\n\tconst reader = body.getReader();\n\tconst decoder = new TextDecoder();\n\tlet buffer = '';\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\n\t\t\tif (done) {\n\t\t\t\t// Process any remaining buffer content before exiting\n\t\t\t\tif (buffer.trim()) {\n\t\t\t\t\tconst chunk = parseDataLine<T>(buffer.trim());\n\t\t\t\t\tif (chunk !== undefined) {\n\t\t\t\t\t\tyield chunk;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tbuffer += decoder.decode(value, { stream: true });\n\n\t\t\t// SSE events are separated by double newlines\n\t\t\tconst lines = buffer.split(/\\r?\\n/);\n\n\t\t\t// Keep the last incomplete line in the buffer\n\t\t\tbuffer = lines.pop() ?? '';\n\n\t\t\tfor (const line of lines) {\n\t\t\t\tif (line === '') continue;\n\t\t\t\tif (line.startsWith(':')) continue; // SSE comment\n\n\t\t\t\tif (line.startsWith('data: ')) {\n\t\t\t\t\tconst data = line.slice(6);\n\n\t\t\t\t\tif (data === '[DONE]') {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst parsed = JSON.parse(data) as T;\n\t\t\t\t\t\tyield parsed;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Malformed JSON line — skip rather than crash the whole stream\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle `event: error` style SSE events (used by Responses API)\n\t\t\t\tif (line.startsWith('event: error')) {\n\t\t\t\t\t// The next data line will contain the error payload.\n\t\t\t\t\t// We'll catch it in the next iteration of the data parsing.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tthrow new DvinaStreamError(\n\t\t\t`SSE stream interrupted: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\terror instanceof Error ? error : undefined,\n\t\t);\n\t} finally {\n\t\treader.releaseLock();\n\t}\n}\n\n/**\n * Try to parse a single `data: ...` line value. Returns undefined for non-data or [DONE].\n */\nfunction parseDataLine<T>(line: string): T | undefined {\n\tif (!line.startsWith('data: ')) return undefined;\n\tconst data = line.slice(6);\n\tif (data === '[DONE]') return undefined;\n\ttry {\n\t\treturn JSON.parse(data) as T;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * A chat completion stream that also aggregates the full response for convenience.\n *\n * Implements `AsyncIterable<ChatCompletionChunk>` for chunk-by-chunk processing,\n * and provides helper methods to extract the final assembled text and usage.\n *\n * @example\n * ```typescript\n * const stream = await client.chat.completions.stream({ ... });\n *\n * // Option 1: Iterate chunk by chunk\n * for await (const chunk of stream) {\n * process.stdout.write(chunk.choices[0]?.delta?.content ?? '');\n * }\n *\n * // Option 2: Get aggregated result after iteration\n * const text = stream.getText();\n * const usage = stream.getUsage();\n * ```\n */\nexport class ChatCompletionStream implements AsyncIterable<ChatCompletionChunk> {\n\tprivate readonly _chunks: ChatCompletionChunk[] = [];\n\tprivate readonly _source: AsyncGenerator<ChatCompletionChunk, void, undefined>;\n\tprivate _consumed = false;\n\n\tconstructor(source: AsyncGenerator<ChatCompletionChunk, void, undefined>) {\n\t\tthis._source = source;\n\t}\n\n\tasync *[Symbol.asyncIterator](): AsyncIterator<ChatCompletionChunk> {\n\t\tif (this._consumed) {\n\t\t\t// Allow re-iteration over cached chunks\n\t\t\tfor (const chunk of this._chunks) {\n\t\t\t\tyield chunk;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tthis._consumed = true;\n\t\tfor await (const chunk of this._source) {\n\t\t\tthis._chunks.push(chunk);\n\t\t\tyield chunk;\n\t\t}\n\t}\n\n\t/**\n\t * Concatenate all content deltas into a single string.\n\t * Must be called after the stream has been fully consumed.\n\t */\n\tgetText(): string {\n\t\tconst parts: string[] = [];\n\t\tfor (const chunk of this._chunks) {\n\t\t\tconst content = chunk.choices[0]?.delta?.content;\n\t\t\tif (content) {\n\t\t\t\tparts.push(content);\n\t\t\t}\n\t\t}\n\t\treturn parts.join('');\n\t}\n\n\t/**\n\t * Get the token usage from the final chunk (if the server included it).\n\t * Must be called after the stream has been fully consumed.\n\t */\n\tgetUsage(): { prompt_tokens: number; completion_tokens: number; total_tokens: number } | undefined {\n\t\t// Usage is typically in the last chunk\n\t\tfor (let i = this._chunks.length - 1; i >= 0; i--) {\n\t\t\tif (this._chunks[i].usage) {\n\t\t\t\treturn this._chunks[i].usage;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Get the collected chunks array.\n\t * Must be called after the stream has been fully consumed.\n\t */\n\tgetChunks(): readonly ChatCompletionChunk[] {\n\t\treturn this._chunks;\n\t}\n}\n","import {\n\tDvinaInferenceError,\n\tDvinaInferenceAuthError,\n\tDvinaRateLimitError,\n\tDvinaQuotaError,\n\tDvinaStreamError,\n\tDvinaContextLengthError,\n\tDvinaTimeoutError,\n\tDvinaProviderUnavailableError,\n\tDvinaProviderError,\n\tDvinaDeploymentError,\n\tDvinaUnsupportedModelError,\n} from './errors.js';\nimport { parseSSEStream, ChatCompletionStream } from './stream.js';\nimport type {\n\tInferenceClientOptions,\n\tChatCompletionRequest,\n\tChatCompletionStreamRequest,\n\tChatCompletionResponse,\n\tChatCompletionChunk,\n\tResponsesRequest,\n\tResponsesStreamRequest,\n\tModelListResponse,\n\tModel,\n\tHealthResponse,\n\tInferenceErrorResponse,\n} from './types.js';\n\n// ─── Constants ───────────────────────────────────────────────────────────────\n\nconst DEFAULT_TIMEOUT_MS = 120_000;\n\n// ─── Error handling ──────────────────────────────────────────────────────────\n\n/**\n * Parse the response body into an OpenAI-compatible error and throw the appropriate typed error.\n */\nasync function throwForStatus(response: Response): Promise<never> {\n\tlet errorBody: InferenceErrorResponse | undefined;\n\n\ttry {\n\t\terrorBody = (await response.json()) as InferenceErrorResponse;\n\t} catch {\n\t\t// Body is not JSON — fall through to generic error\n\t}\n\n\tconst message = errorBody?.error?.message ?? `HTTP ${response.status}: ${response.statusText}`;\n\tconst type = errorBody?.error?.type ?? 'api_error';\n\tconst code = errorBody?.error?.code ?? 'unknown';\n\n\t// Auth errors (401, 403)\n\tif (response.status === 401 || response.status === 403) {\n\t\t// Quota exceeded is a special 403\n\t\tif (code === 'token_limit_reached' || type === 'insufficient_quota') {\n\t\t\tthrow new DvinaQuotaError(message);\n\t\t}\n\t\tthrow new DvinaInferenceAuthError(message, response.status);\n\t}\n\n\t// Rate limit (429)\n\tif (response.status === 429) {\n\t\tconst retryAfterHeader = response.headers.get('retry-after');\n\t\tconst retryAfter = retryAfterHeader ? parseInt(retryAfterHeader, 10) : undefined;\n\t\tthrow new DvinaRateLimitError(message, Number.isNaN(retryAfter) ? undefined : retryAfter);\n\t}\n\n\t// Specific error codes → typed subclasses\n\tswitch (code) {\n\t\tcase 'context_length_exceeded':\n\t\t\tthrow new DvinaContextLengthError(message);\n\t\tcase 'request_timeout':\n\t\t\tthrow new DvinaTimeoutError(message);\n\t\tcase 'provider_unavailable':\n\t\t\tthrow new DvinaProviderUnavailableError(message);\n\t\tcase 'provider_error':\n\t\t\tthrow new DvinaProviderError(message, response.status);\n\t\tcase 'deployment_not_found':\n\t\t\tthrow new DvinaDeploymentError(message);\n\t\tcase 'unsupported_model':\n\t\t\tthrow new DvinaUnsupportedModelError(message);\n\t}\n\n\tthrow new DvinaInferenceError(message, response.status, type, code);\n}\n\n// ─── Inference Client Interfaces ─────────────────────────────────────────────\n\n/**\n * Namespaced chat completions API.\n *\n * @example\n * ```typescript\n * // Non-streaming\n * const response = await sdk.inference.chat.completions.create({\n * model: 'claude-sonnet-4-6',\n * messages: [{ role: 'user', content: 'Hello!' }],\n * });\n *\n * // Streaming\n * const stream = await sdk.inference.chat.completions.stream({\n * model: 'claude-sonnet-4-6',\n * messages: [{ role: 'user', content: 'Hello!' }],\n * });\n * for await (const chunk of stream) {\n * process.stdout.write(chunk.choices[0]?.delta?.content ?? '');\n * }\n * ```\n */\nexport interface ChatCompletions {\n\t/** Create a non-streaming chat completion. */\n\tcreate(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;\n\t/** Create a streaming chat completion. Returns an async iterable of chunks. */\n\tstream(request: Omit<ChatCompletionStreamRequest, 'stream'>): Promise<ChatCompletionStream>;\n}\n\nexport interface Chat {\n\tcompletions: ChatCompletions;\n}\n\n/**\n * Namespaced responses API.\n *\n * @example\n * ```typescript\n * // Non-streaming\n * const response = await sdk.inference.responses.create({\n * model: 'gpt-5.2',\n * input: 'Hello!',\n * });\n *\n * // Streaming\n * const stream = await sdk.inference.responses.stream({\n * model: 'gpt-5.2',\n * input: 'Hello!',\n * });\n * for await (const event of stream) {\n * console.log(event);\n * }\n * ```\n */\nexport interface Responses {\n\t/** Create a non-streaming response. */\n\tcreate(request: ResponsesRequest): Promise<unknown>;\n\t/** Create a streaming response. Returns a raw async iterable of SSE events. */\n\tstream(request: Omit<ResponsesStreamRequest, 'stream'>): Promise<AsyncIterable<unknown>>;\n}\n\n/**\n * Namespaced models API.\n */\nexport interface Models {\n\t/** List all available models. */\n\tlist(): Promise<ModelListResponse>;\n\t/** Get a single model by ID. */\n\tget(modelId: string): Promise<Model>;\n}\n\n/**\n * The Dvina Inference client.\n *\n * Provides a typed interface to the `/inference/v1` REST API with full\n * SSE streaming support. Follows the OpenAI client naming conventions\n * (`sdk.inference.chat.completions`, `sdk.inference.responses`, `sdk.inference.models`).\n *\n * @example\n * ```typescript\n * const sdk = new DvinaSdk({ token: 'your-jwt-token' });\n *\n * // Chat completion\n * const response = await sdk.inference.chat.completions.create({\n * model: 'claude-sonnet-4-6',\n * messages: [{ role: 'user', content: 'Hello!' }],\n * });\n *\n * // Streaming\n * const stream = await sdk.inference.chat.completions.stream({\n * model: 'claude-sonnet-4-6',\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * });\n * for await (const chunk of stream) {\n * process.stdout.write(chunk.choices[0]?.delta?.content ?? '');\n * }\n * ```\n */\nexport interface InferenceClient {\n\tchat: Chat;\n\tresponses: Responses;\n\tmodels: Models;\n\t/** Check the health of the inference API. */\n\thealth(): Promise<HealthResponse>;\n}\n\n// ─── Internal factory (used by createDvinaClient) ────────────────────────────\n\n/**\n * Create an inference client using pre-resolved baseUrl and getToken from the SDK.\n * This is the internal factory called by `createDvinaClient` — it does NOT resolve\n * token/options itself, it receives them from the parent SDK client.\n *\n * @internal\n */\nexport function createInferenceClientInternal(\n\tbaseUrl: string,\n\tgetToken: (options?: { forceRefresh?: boolean }) => Promise<string>,\n\toptions?: { headers?: Record<string, string>; timeout?: number },\n): InferenceClient {\n\treturn buildInferenceClient(baseUrl, getToken, options?.headers, options?.timeout);\n}\n\n// ─── Public standalone factory ───────────────────────────────────────────────\n\n/**\n * Create a standalone Dvina Inference client.\n *\n * Use this when you need inference without the full GraphQL SDK.\n * For most cases, prefer `sdk.inference` which shares auth with the SDK.\n *\n * @param options - Client configuration (base URL, auth, headers, timeout)\n * @returns A fully configured inference client\n *\n * @example\n * ```typescript\n * import { createInferenceClient } from '@dvina/sdk/inference';\n *\n * const client = createInferenceClient({\n * baseUrl: 'https://api.dvina.ai/inference/v1',\n * token: 'your-jwt-token',\n * });\n *\n * const response = await client.chat.completions.create({\n * model: 'claude-sonnet-4-6',\n * messages: [{ role: 'user', content: 'Hello!' }],\n * });\n * ```\n */\nexport function createInferenceClient(options: InferenceClientOptions): InferenceClient {\n\tconst baseUrl = options.baseUrl.replace(/\\/+$/, '');\n\n\tlet getToken: (opts?: { forceRefresh?: boolean }) => Promise<string>;\n\tif (options.getToken) {\n\t\tgetToken = options.getToken;\n\t} else if (options.token) {\n\t\tconst staticToken = options.token;\n\t\tgetToken = async () => staticToken;\n\t} else {\n\t\tthrow new Error('InferenceClientOptions must provide either `token` or `getToken`.');\n\t}\n\n\treturn buildInferenceClient(baseUrl, getToken, options.headers, options.timeout);\n}\n\n// ─── Shared builder ──────────────────────────────────────────────────────────\n\nfunction buildInferenceClient(\n\tbaseUrl: string,\n\tgetToken: (options?: { forceRefresh?: boolean }) => Promise<string>,\n\tcustomHeaders?: Record<string, string>,\n\ttimeout?: number,\n): InferenceClient {\n\tconst timeoutMs = timeout ?? DEFAULT_TIMEOUT_MS;\n\tconst headers = customHeaders ?? {};\n\n\t// ── Shared fetch helper ──────────────────────────────────────────────\n\n\tasync function buildRequestHeaders(): Promise<Record<string, string>> {\n\t\tconst token = await getToken();\n\t\treturn {\n\t\t\t'Content-Type': 'application/json',\n\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t...headers,\n\t\t};\n\t}\n\n\tasync function request<T>(method: string, path: string, body?: unknown): Promise<T> {\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), timeoutMs);\n\n\t\ttry {\n\t\t\tconst reqHeaders = await buildRequestHeaders();\n\t\t\tconst response = await fetch(`${baseUrl}${path}`, {\n\t\t\t\tmethod,\n\t\t\t\theaders: reqHeaders,\n\t\t\t\tbody: body !== undefined ? JSON.stringify(body) : undefined,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tawait throwForStatus(response);\n\t\t\t}\n\n\t\t\treturn (await response.json()) as T;\n\t\t} catch (error) {\n\t\t\tif (error instanceof DvinaInferenceError) throw error;\n\t\t\tif (error instanceof Error && error.name === 'AbortError') {\n\t\t\t\tthrow new DvinaInferenceError(\n\t\t\t\t\t`Request timed out after ${timeoutMs}ms`,\n\t\t\t\t\t0,\n\t\t\t\t\t'timeout_error',\n\t\t\t\t\t'request_timeout',\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new DvinaInferenceError(\n\t\t\t\t`Network error: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t0,\n\t\t\t\t'network_error',\n\t\t\t\t'connection_failed',\n\t\t\t\terror instanceof Error ? error : undefined,\n\t\t\t);\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t}\n\n\tasync function requestStream(path: string, body: unknown): Promise<ReadableStream<Uint8Array>> {\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), timeoutMs);\n\n\t\ttry {\n\t\t\tconst reqHeaders = await buildRequestHeaders();\n\t\t\tconst response = await fetch(`${baseUrl}${path}`, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: reqHeaders,\n\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\n\t\t\t// Clear the timeout — the stream itself may take longer than the initial timeout.\n\t\t\t// The timeout only applies to the initial connection, not the full stream duration.\n\t\t\tclearTimeout(timer);\n\n\t\t\tif (!response.ok) {\n\t\t\t\tawait throwForStatus(response);\n\t\t\t}\n\n\t\t\tif (!response.body) {\n\t\t\t\tthrow new DvinaStreamError('Response body is null — streaming not supported in this environment');\n\t\t\t}\n\n\t\t\treturn response.body;\n\t\t} catch (error) {\n\t\t\tclearTimeout(timer);\n\t\t\tif (error instanceof DvinaInferenceError) throw error;\n\t\t\tif (error instanceof Error && error.name === 'AbortError') {\n\t\t\t\tthrow new DvinaInferenceError(\n\t\t\t\t\t`Stream connection timed out after ${timeoutMs}ms`,\n\t\t\t\t\t0,\n\t\t\t\t\t'timeout_error',\n\t\t\t\t\t'request_timeout',\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new DvinaInferenceError(\n\t\t\t\t`Network error: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t0,\n\t\t\t\t'network_error',\n\t\t\t\t'connection_failed',\n\t\t\t\terror instanceof Error ? error : undefined,\n\t\t\t);\n\t\t}\n\t}\n\n\t// ── Chat Completions ─────────────────────────────────────────────────\n\n\tconst completions: ChatCompletions = {\n\t\tasync create(req: ChatCompletionRequest): Promise<ChatCompletionResponse> {\n\t\t\treturn request<ChatCompletionResponse>('POST', '/chat/completions', {\n\t\t\t\t...req,\n\t\t\t\tstream: false,\n\t\t\t});\n\t\t},\n\n\t\tasync stream(req: Omit<ChatCompletionStreamRequest, 'stream'>): Promise<ChatCompletionStream> {\n\t\t\tconst body = await requestStream('/chat/completions', {\n\t\t\t\t...req,\n\t\t\t\tstream: true,\n\t\t\t});\n\n\t\t\tconst source = parseSSEStream<ChatCompletionChunk>(body);\n\t\t\treturn new ChatCompletionStream(source);\n\t\t},\n\t};\n\n\tconst chat: Chat = { completions };\n\n\t// ── Responses ────────────────────────────────────────────────────────\n\n\tconst responses: Responses = {\n\t\tasync create(req: ResponsesRequest): Promise<unknown> {\n\t\t\treturn request<unknown>('POST', '/responses', {\n\t\t\t\t...req,\n\t\t\t\tstream: false,\n\t\t\t});\n\t\t},\n\n\t\tasync stream(req: Omit<ResponsesStreamRequest, 'stream'>): Promise<AsyncIterable<unknown>> {\n\t\t\tconst body = await requestStream('/responses', {\n\t\t\t\t...req,\n\t\t\t\tstream: true,\n\t\t\t});\n\n\t\t\t// Responses API uses a different SSE event format than chat completions.\n\t\t\t// We parse it as generic unknown objects so the consumer can handle the format.\n\t\t\treturn {\n\t\t\t\t[Symbol.asyncIterator]() {\n\t\t\t\t\treturn parseSSEStream<unknown>(body);\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n\n\t// ── Models ───────────────────────────────────────────────────────────\n\n\tconst models: Models = {\n\t\tasync list(): Promise<ModelListResponse> {\n\t\t\treturn request<ModelListResponse>('GET', '/models');\n\t\t},\n\n\t\tasync get(modelId: string): Promise<Model> {\n\t\t\treturn request<Model>('GET', `/models/${encodeURIComponent(modelId)}`);\n\t\t},\n\t};\n\n\t// ── Health ───────────────────────────────────────────────────────────\n\n\tasync function health(): Promise<HealthResponse> {\n\t\treturn request<HealthResponse>('GET', '/health');\n\t}\n\n\treturn {\n\t\tchat,\n\t\tresponses,\n\t\tmodels,\n\t\thealth,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { D as DvinaError } from './error-CsVoUTY8.cjs';
|
|
2
|
+
import { a as DvinaRequest, b as DvinaSubscribe } from './types-2RotD0Ab.cjs';
|
|
3
|
+
import { S as SyncEngine } from './sync-engine-DVKQO-1-.cjs';
|
|
4
|
+
import { I as InferenceClient } from './client-CLhQragb.cjs';
|
|
5
|
+
import { BillingClient } from './billing/index.cjs';
|
|
6
|
+
|
|
7
|
+
interface DvinaSdkBaseOptions {
|
|
8
|
+
/** Base URL without protocol (e.g. 'api.dvina.ai' or 'localhost:4000'). Default: 'api.dvina.ai' */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Override the billing API base URL.
|
|
12
|
+
* Accepts either a bare host (e.g. 'billing.dvina.ai') or a full URL with protocol
|
|
13
|
+
* (e.g. 'http://dvina-billing:3010'). When a protocol is included, it is used as-is.
|
|
14
|
+
* By default, derived from `baseUrl` by replacing the leading `api.` with `billing.`
|
|
15
|
+
* (e.g. 'api.dvina.ai' → 'billing.dvina.ai').
|
|
16
|
+
*/
|
|
17
|
+
billingUrl?: string;
|
|
18
|
+
/** Preferred language for API responses. Static string or reactive callback. */
|
|
19
|
+
language?: string | (() => string);
|
|
20
|
+
/**
|
|
21
|
+
* Global error callback invoked for every terminal SDK error (after all
|
|
22
|
+
* retries and token refreshes have been exhausted).
|
|
23
|
+
*
|
|
24
|
+
* Receives typed error subclasses — use `instanceof` to branch:
|
|
25
|
+
* - `DvinaPlanRestrictionError` — plan/billing limit exceeded (check `restrictionCode`)
|
|
26
|
+
* - `DvinaTokenLimitError` — session token limit reached
|
|
27
|
+
* - `DvinaNotFoundError` — resource not found
|
|
28
|
+
* - `DvinaAuthenticationError` — authentication permanently failed
|
|
29
|
+
* - `DvinaNetworkError` — network/HTTP failure
|
|
30
|
+
* - `DvinaGraphQLError` — other GraphQL errors
|
|
31
|
+
*/
|
|
32
|
+
onError?: (error: DvinaError) => void;
|
|
33
|
+
}
|
|
34
|
+
interface DvinaSdkTokenOptions extends DvinaSdkBaseOptions {
|
|
35
|
+
/** Static auth token. Use for scripts, CLI tools, and tests. */
|
|
36
|
+
token: string;
|
|
37
|
+
getToken?: never;
|
|
38
|
+
}
|
|
39
|
+
interface DvinaSdkCallbackOptions extends DvinaSdkBaseOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Async callback that returns an auth token.
|
|
42
|
+
* When called with `{ forceRefresh: true }`, the callback must bypass any
|
|
43
|
+
* cache and obtain a brand-new token (e.g. via Auth0's silent refresh).
|
|
44
|
+
*/
|
|
45
|
+
getToken: (options?: {
|
|
46
|
+
forceRefresh?: boolean;
|
|
47
|
+
}) => Promise<string>;
|
|
48
|
+
token?: never;
|
|
49
|
+
}
|
|
50
|
+
type DvinaSdkOptions = DvinaSdkTokenOptions | DvinaSdkCallbackOptions;
|
|
51
|
+
interface DvinaClientResult {
|
|
52
|
+
syncEngine: SyncEngine;
|
|
53
|
+
/** Request function that routes through SyncEngine (normalize + Dexie write). Used by model classes for compat. */
|
|
54
|
+
request: DvinaRequest;
|
|
55
|
+
/** Subscribe function that routes through WebSocket transport for GraphQL subscriptions. */
|
|
56
|
+
subscribe: DvinaSubscribe;
|
|
57
|
+
getToken: (options?: {
|
|
58
|
+
forceRefresh?: boolean;
|
|
59
|
+
}) => Promise<string>;
|
|
60
|
+
/** Terminate the WebSocket connection (call on logout / SDK teardown). */
|
|
61
|
+
terminateWs: () => void;
|
|
62
|
+
/** Close and remove the cached IndexedDB database (call on logout / workspace switch / SDK teardown). */
|
|
63
|
+
closeDb: () => Promise<void>;
|
|
64
|
+
/** Inference client for the /inference/v1 REST API (chat completions, responses, models). */
|
|
65
|
+
inference: InferenceClient;
|
|
66
|
+
/** Billing client for the Dvina Billing GraphQL API (plans, subscriptions, seats, sessions). */
|
|
67
|
+
billing: BillingClient;
|
|
68
|
+
/** The resolved base URL (e.g. 'api.dvina.ai'). Used by models to resolve relative asset paths. */
|
|
69
|
+
baseUrl: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create a fully configured Dvina client with SyncEngine, HTTP transport, and WS transport.
|
|
73
|
+
* Called by the DvinaSdk constructor (generated code).
|
|
74
|
+
*/
|
|
75
|
+
declare function createDvinaClient(options: DvinaSdkOptions): DvinaClientResult;
|
|
76
|
+
|
|
77
|
+
export { type DvinaSdkOptions as D, type DvinaSdkBaseOptions as a, type DvinaSdkCallbackOptions as b, type DvinaSdkTokenOptions as c, createDvinaClient as d };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { D as DvinaError } from './error-CsVoUTY8.js';
|
|
2
|
+
import { a as DvinaRequest, b as DvinaSubscribe } from './types-2RotD0Ab.js';
|
|
3
|
+
import { S as SyncEngine } from './sync-engine-cLwTqdjv.js';
|
|
4
|
+
import { I as InferenceClient } from './client-CLhQragb.js';
|
|
5
|
+
import { BillingClient } from './billing/index.js';
|
|
6
|
+
|
|
7
|
+
interface DvinaSdkBaseOptions {
|
|
8
|
+
/** Base URL without protocol (e.g. 'api.dvina.ai' or 'localhost:4000'). Default: 'api.dvina.ai' */
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Override the billing API base URL.
|
|
12
|
+
* Accepts either a bare host (e.g. 'billing.dvina.ai') or a full URL with protocol
|
|
13
|
+
* (e.g. 'http://dvina-billing:3010'). When a protocol is included, it is used as-is.
|
|
14
|
+
* By default, derived from `baseUrl` by replacing the leading `api.` with `billing.`
|
|
15
|
+
* (e.g. 'api.dvina.ai' → 'billing.dvina.ai').
|
|
16
|
+
*/
|
|
17
|
+
billingUrl?: string;
|
|
18
|
+
/** Preferred language for API responses. Static string or reactive callback. */
|
|
19
|
+
language?: string | (() => string);
|
|
20
|
+
/**
|
|
21
|
+
* Global error callback invoked for every terminal SDK error (after all
|
|
22
|
+
* retries and token refreshes have been exhausted).
|
|
23
|
+
*
|
|
24
|
+
* Receives typed error subclasses — use `instanceof` to branch:
|
|
25
|
+
* - `DvinaPlanRestrictionError` — plan/billing limit exceeded (check `restrictionCode`)
|
|
26
|
+
* - `DvinaTokenLimitError` — session token limit reached
|
|
27
|
+
* - `DvinaNotFoundError` — resource not found
|
|
28
|
+
* - `DvinaAuthenticationError` — authentication permanently failed
|
|
29
|
+
* - `DvinaNetworkError` — network/HTTP failure
|
|
30
|
+
* - `DvinaGraphQLError` — other GraphQL errors
|
|
31
|
+
*/
|
|
32
|
+
onError?: (error: DvinaError) => void;
|
|
33
|
+
}
|
|
34
|
+
interface DvinaSdkTokenOptions extends DvinaSdkBaseOptions {
|
|
35
|
+
/** Static auth token. Use for scripts, CLI tools, and tests. */
|
|
36
|
+
token: string;
|
|
37
|
+
getToken?: never;
|
|
38
|
+
}
|
|
39
|
+
interface DvinaSdkCallbackOptions extends DvinaSdkBaseOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Async callback that returns an auth token.
|
|
42
|
+
* When called with `{ forceRefresh: true }`, the callback must bypass any
|
|
43
|
+
* cache and obtain a brand-new token (e.g. via Auth0's silent refresh).
|
|
44
|
+
*/
|
|
45
|
+
getToken: (options?: {
|
|
46
|
+
forceRefresh?: boolean;
|
|
47
|
+
}) => Promise<string>;
|
|
48
|
+
token?: never;
|
|
49
|
+
}
|
|
50
|
+
type DvinaSdkOptions = DvinaSdkTokenOptions | DvinaSdkCallbackOptions;
|
|
51
|
+
interface DvinaClientResult {
|
|
52
|
+
syncEngine: SyncEngine;
|
|
53
|
+
/** Request function that routes through SyncEngine (normalize + Dexie write). Used by model classes for compat. */
|
|
54
|
+
request: DvinaRequest;
|
|
55
|
+
/** Subscribe function that routes through WebSocket transport for GraphQL subscriptions. */
|
|
56
|
+
subscribe: DvinaSubscribe;
|
|
57
|
+
getToken: (options?: {
|
|
58
|
+
forceRefresh?: boolean;
|
|
59
|
+
}) => Promise<string>;
|
|
60
|
+
/** Terminate the WebSocket connection (call on logout / SDK teardown). */
|
|
61
|
+
terminateWs: () => void;
|
|
62
|
+
/** Close and remove the cached IndexedDB database (call on logout / workspace switch / SDK teardown). */
|
|
63
|
+
closeDb: () => Promise<void>;
|
|
64
|
+
/** Inference client for the /inference/v1 REST API (chat completions, responses, models). */
|
|
65
|
+
inference: InferenceClient;
|
|
66
|
+
/** Billing client for the Dvina Billing GraphQL API (plans, subscriptions, seats, sessions). */
|
|
67
|
+
billing: BillingClient;
|
|
68
|
+
/** The resolved base URL (e.g. 'api.dvina.ai'). Used by models to resolve relative asset paths. */
|
|
69
|
+
baseUrl: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create a fully configured Dvina client with SyncEngine, HTTP transport, and WS transport.
|
|
73
|
+
* Called by the DvinaSdk constructor (generated code).
|
|
74
|
+
*/
|
|
75
|
+
declare function createDvinaClient(options: DvinaSdkOptions): DvinaClientResult;
|
|
76
|
+
|
|
77
|
+
export { type DvinaSdkOptions as D, type DvinaSdkBaseOptions as a, type DvinaSdkCallbackOptions as b, type DvinaSdkTokenOptions as c, createDvinaClient as d };
|