@dvina/sdk 4.1.58 → 4.1.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_generated_documents-XONZIXZ4.js +1 -0
- package/dist/adapters/angular/index.d.ts +1 -1
- package/dist/adapters/angular/index.js +1 -159
- package/dist/adapters/react/index.js +1 -49
- package/dist/billing/index.js +1 -5
- package/dist/chunk-5E7LX4YQ.js +1 -0
- package/dist/chunk-EK7ODJWE.js +1 -0
- package/dist/chunk-EOIDWBEZ.js +1 -0
- package/dist/chunk-G34ETQUN.js +1 -0
- package/dist/chunk-H3TI6B7T.js +1 -0
- package/dist/chunk-IIQ3WGOJ.js +1 -0
- package/dist/chunk-JQL7QV2D.js +5 -0
- package/dist/chunk-SJ6Q5IDB.js +31 -0
- package/dist/{client-K9LxSCVw.d.ts → client-D309vpHA.d.ts} +206 -1
- package/dist/index.d.ts +110 -3
- package/dist/index.js +1 -10
- package/dist/inference/index.js +1 -5
- package/dist/package.json +12 -48
- package/dist/pagination/index.js +1 -5
- package/package.json +13 -49
- package/dist/_generated_documents-2RBYHBRH.js +0 -4
- package/dist/_generated_documents-2RBYHBRH.js.map +0 -1
- package/dist/_generated_documents-3OGB3BZM.cjs +0 -2545
- package/dist/_generated_documents-3OGB3BZM.cjs.map +0 -1
- package/dist/adapters/angular/index.cjs +0 -163
- package/dist/adapters/angular/index.cjs.map +0 -1
- package/dist/adapters/angular/index.d.cts +0 -254
- package/dist/adapters/angular/index.js.map +0 -1
- package/dist/adapters/react/index.cjs +0 -51
- package/dist/adapters/react/index.cjs.map +0 -1
- package/dist/adapters/react/index.d.cts +0 -62
- package/dist/adapters/react/index.js.map +0 -1
- package/dist/billing/index.cjs +0 -26
- package/dist/billing/index.cjs.map +0 -1
- package/dist/billing/index.d.cts +0 -328
- package/dist/billing/index.js.map +0 -1
- package/dist/chunk-2J5WONKO.cjs +0 -1608
- package/dist/chunk-2J5WONKO.cjs.map +0 -1
- package/dist/chunk-342BFYZZ.cjs +0 -98
- package/dist/chunk-342BFYZZ.cjs.map +0 -1
- package/dist/chunk-5WRI5ZAA.js +0 -29
- package/dist/chunk-5WRI5ZAA.js.map +0 -1
- package/dist/chunk-7XBJ77RJ.js +0 -103
- package/dist/chunk-7XBJ77RJ.js.map +0 -1
- package/dist/chunk-AE5KAIKK.js +0 -24
- package/dist/chunk-AE5KAIKK.js.map +0 -1
- package/dist/chunk-AQ45E6MZ.cjs +0 -23951
- package/dist/chunk-AQ45E6MZ.cjs.map +0 -1
- package/dist/chunk-DLCUHX6I.js +0 -1064
- package/dist/chunk-DLCUHX6I.js.map +0 -1
- package/dist/chunk-DZUJEN5N.cjs +0 -32
- package/dist/chunk-DZUJEN5N.cjs.map +0 -1
- package/dist/chunk-FOKGSMXS.cjs +0 -27
- package/dist/chunk-FOKGSMXS.cjs.map +0 -1
- package/dist/chunk-IWQGSVFY.js +0 -23541
- package/dist/chunk-IWQGSVFY.js.map +0 -1
- package/dist/chunk-KEM6SUTS.js +0 -92
- package/dist/chunk-KEM6SUTS.js.map +0 -1
- package/dist/chunk-KV5SP7RP.cjs +0 -114
- package/dist/chunk-KV5SP7RP.cjs.map +0 -1
- package/dist/chunk-PDM2KR7T.js +0 -392
- package/dist/chunk-PDM2KR7T.js.map +0 -1
- package/dist/chunk-UELAE75E.cjs +0 -408
- package/dist/chunk-UELAE75E.cjs.map +0 -1
- package/dist/chunk-USR4MXFW.cjs +0 -1699
- package/dist/chunk-USR4MXFW.cjs.map +0 -1
- package/dist/chunk-WX7EFPHT.js +0 -1600
- package/dist/chunk-WX7EFPHT.js.map +0 -1
- package/dist/client-Bb2gD6Iz.d.cts +0 -488
- package/dist/client-X8guW4nw.d.cts +0 -7954
- package/dist/error-CsVoUTY8.d.cts +0 -95
- package/dist/index-D_Z25Pa1.d.cts +0 -79
- package/dist/index.cjs +0 -1979
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -3716
- package/dist/index.js.map +0 -1
- package/dist/inference/index.cjs +0 -70
- package/dist/inference/index.cjs.map +0 -1
- package/dist/inference/index.d.cts +0 -80
- package/dist/inference/index.js.map +0 -1
- package/dist/pagination/index.cjs +0 -34
- package/dist/pagination/index.cjs.map +0 -1
- package/dist/pagination/index.d.cts +0 -6
- package/dist/pagination/index.js.map +0 -1
- package/dist/sync-engine-gpxyhQBl.d.cts +0 -478
- package/dist/types-Chg8ASmf.d.cts +0 -116
package/dist/chunk-KEM6SUTS.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// src/runtime/request.ts
|
|
2
|
-
var Request = class {
|
|
3
|
-
_request;
|
|
4
|
-
_syncEngine;
|
|
5
|
-
_subscribe;
|
|
6
|
-
_baseUrl;
|
|
7
|
-
constructor(request, syncEngine, subscribe, baseUrl) {
|
|
8
|
-
this._request = request;
|
|
9
|
-
this._syncEngine = syncEngine;
|
|
10
|
-
this._subscribe = subscribe;
|
|
11
|
-
this._baseUrl = baseUrl;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
// src/pagination/connection.ts
|
|
16
|
-
var DEFAULT_PAGE_SIZE = 50;
|
|
17
|
-
function defaultConnection(variables) {
|
|
18
|
-
return {
|
|
19
|
-
...variables,
|
|
20
|
-
first: variables.first ?? (variables.after ? DEFAULT_PAGE_SIZE : void 0),
|
|
21
|
-
last: variables.last ?? (variables.before ? DEFAULT_PAGE_SIZE : void 0)
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
var PageInfo = class {
|
|
25
|
-
hasNextPage;
|
|
26
|
-
hasPreviousPage;
|
|
27
|
-
startCursor;
|
|
28
|
-
endCursor;
|
|
29
|
-
constructor(data) {
|
|
30
|
-
this.hasNextPage = data.hasNextPage;
|
|
31
|
-
this.hasPreviousPage = data.hasPreviousPage;
|
|
32
|
-
this.startCursor = data.startCursor;
|
|
33
|
-
this.endCursor = data.endCursor;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var AbstractConnection = class extends Request {
|
|
37
|
-
pageInfo;
|
|
38
|
-
nodes;
|
|
39
|
-
totalCount;
|
|
40
|
-
constructor(request) {
|
|
41
|
-
super(request);
|
|
42
|
-
this.pageInfo = new PageInfo({
|
|
43
|
-
hasNextPage: false,
|
|
44
|
-
hasPreviousPage: false
|
|
45
|
-
});
|
|
46
|
-
this.nodes = [];
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var Connection = class extends AbstractConnection {
|
|
50
|
-
_fetch;
|
|
51
|
-
constructor(request, fetch, nodes, pageInfo, totalCount) {
|
|
52
|
-
super(request);
|
|
53
|
-
this._fetch = fetch;
|
|
54
|
-
this.nodes = nodes;
|
|
55
|
-
this.pageInfo = pageInfo;
|
|
56
|
-
this.totalCount = totalCount;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Fetch the next page and append nodes.
|
|
60
|
-
* Mutates this connection instance in place (nodes are appended, pageInfo updated).
|
|
61
|
-
*/
|
|
62
|
-
async fetchNext(options) {
|
|
63
|
-
if (this.pageInfo.hasNextPage) {
|
|
64
|
-
const response = await this._fetch({ after: this.pageInfo.endCursor }, options);
|
|
65
|
-
if (response) {
|
|
66
|
-
this.nodes = [...this.nodes, ...response.nodes];
|
|
67
|
-
this.pageInfo.endCursor = response.pageInfo.endCursor ?? this.pageInfo.endCursor;
|
|
68
|
-
this.pageInfo.hasNextPage = response.pageInfo.hasNextPage;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Fetch the previous page and prepend nodes.
|
|
75
|
-
* Mutates this connection instance in place (nodes are prepended, pageInfo updated).
|
|
76
|
-
*/
|
|
77
|
-
async fetchPrevious(options) {
|
|
78
|
-
if (this.pageInfo.hasPreviousPage) {
|
|
79
|
-
const response = await this._fetch({ before: this.pageInfo.startCursor }, options);
|
|
80
|
-
if (response) {
|
|
81
|
-
this.nodes = [...response.nodes, ...this.nodes];
|
|
82
|
-
this.pageInfo.startCursor = response.pageInfo.startCursor ?? this.pageInfo.startCursor;
|
|
83
|
-
this.pageInfo.hasPreviousPage = response.pageInfo.hasPreviousPage;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export { AbstractConnection, Connection, PageInfo, Request, defaultConnection };
|
|
91
|
-
//# sourceMappingURL=chunk-KEM6SUTS.js.map
|
|
92
|
-
//# sourceMappingURL=chunk-KEM6SUTS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime/request.ts","../src/pagination/connection.ts"],"names":[],"mappings":";AAWO,IAAM,UAAN,MAAc;AAAA,EACV,QAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EAEH,WAAA,CAAY,OAAA,EAAuB,UAAA,EAAyB,SAAA,EAA4B,OAAA,EAAkB;AAChH,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAChB,IAAA,IAAA,CAAK,WAAA,GAAc,UAAA;AACnB,IAAA,IAAA,CAAK,UAAA,GAAa,SAAA;AAClB,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAAA,EACjB;AACD;;;ACnBA,IAAM,iBAAA,GAAoB,EAAA;AAMnB,SAAS,kBAAiD,SAAA,EAAiB;AACjF,EAAA,OAAO;AAAA,IACN,GAAG,SAAA;AAAA,IACH,KAAA,EAAO,SAAA,CAAU,KAAA,KAAU,SAAA,CAAU,QAAQ,iBAAA,GAAoB,MAAA,CAAA;AAAA,IACjE,IAAA,EAAM,SAAA,CAAU,IAAA,KAAS,SAAA,CAAU,SAAS,iBAAA,GAAoB,MAAA;AAAA,GACjE;AACD;AAKO,IAAM,WAAN,MAAe;AAAA,EACd,WAAA;AAAA,EACA,eAAA;AAAA,EACA,WAAA;AAAA,EACA,SAAA;AAAA,EAEP,YAAY,IAAA,EAAoB;AAC/B,IAAA,IAAA,C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AA;AAC9C,QAAA,IAAA,CAAK,SAAS,SAAA,GAAY,QAAA,CAAS,QAAA,CAAS,SAAA,IAAa,KAAK,QAAA,CAAS,SAAA;AACvE,QAAA,IAAA,CAAK,QAAA,CAAS,WAAA,GAAc,QAAA,CAAS,QAAA,CAAS,WAAA;AAAA,MAC/C;AAAA,IACD;AACA,IAAA,OAAO,IAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,cAAc,OAAA,EAAuC;AACjE,IAAA,IAAI,IAAA,CAAK,SAAS,eAAA,EAAiB;AAClC,MAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,MAAA,CAAO,EAAE,QAAQ,IAAA,CAAK,QAAA,CAAS,WAAA,EAAY,EAAG,OAAO,CAAA;AACjF,MAAA,IAAI,QAAA,EAAU;AACb,QAAA,IAAA,CAAK,QAAQ,CAAC,GAAG,SAAS,KAAA,EAAO,GAAG,KAAK,KAAK,CAAA;AAC9C,QAAA,IAAA,CAAK,SAAS,WAAA,GAAc,QAAA,CAAS,QAAA,CAAS,WAAA,IAAe,KAAK,QAAA,CAAS,WAAA;AAC3E,QAAA,IAAA,CAAK,QAAA,CAAS,eAAA,GAAkB,QAAA,CAAS,QAAA,CAAS,eAAA;AAAA,MACnD;AAAA,IACD;AACA,IAAA,OAAO,IAAA;AAAA,EACR;AACD","file":"chunk-KEM6SUTS.js","sourcesContent":["import type { DvinaRequest, DvinaSubscribe } from '../types.js';\nimport type { SyncEngine } from '../store/sync-engine.js';\n\n/**\n * Base class that holds the transport functions.\n * Every generated model, connection, query, and the root SDK class extend this.\n *\n * Operation classes use `_syncEngine` for queries/mutations/watch.\n * Subscription classes use `_subscribe` for WebSocket streaming.\n * Model classes use `_request` for compatibility (lazy fetch).\n */\nexport class Request {\n\tprotected _request: DvinaRequest;\n\tprotected _syncEngine?: SyncEngine;\n\tprotected _subscribe?: DvinaSubscribe;\n\tprotected _baseUrl?: string;\n\n\tpublic constructor(request: DvinaRequest, syncEngine?: SyncEngine, subscribe?: DvinaSubscribe, baseUrl?: string) {\n\t\tthis._request = request;\n\t\tthis._syncEngine = syncEngine;\n\t\tthis._subscribe = subscribe;\n\t\tthis._baseUrl = baseUrl;\n\t}\n}\n","import { Request } from '../runtime/request.js';\nimport type { DvinaRequest, ConnectionVariables, FetchOptions, PageInfoData } from '../types.js';\n\n/** Default page size when cursor-paginating without an explicit first/last */\nconst DEFAULT_PAGE_SIZE = 50;\n\n/**\n * Default connection variables when paginating.\n * Ensures `first` or `last` is set when a cursor is provided.\n */\nexport function defaultConnection<V extends ConnectionVariables>(variables: V): V {\n\treturn {\n\t\t...variables,\n\t\tfirst: variables.first ?? (variables.after ? DEFAULT_PAGE_SIZE : undefined),\n\t\tlast: variables.last ?? (variables.before ? DEFAULT_PAGE_SIZE : undefined),\n\t};\n}\n\n/**\n * PageInfo model following the Relay spec.\n */\nexport class PageInfo {\n\tpublic hasNextPage: boolean;\n\tpublic hasPreviousPage: boolean;\n\tpublic startCursor?: string | null;\n\tpublic endCursor?: string | null;\n\n\tconstructor(data: PageInfoData) {\n\t\tthis.hasNextPage = data.hasNextPage;\n\t\tthis.hasPreviousPage = data.hasPreviousPage;\n\t\tthis.startCursor = data.startCursor;\n\t\tthis.endCursor = data.endCursor;\n\t}\n}\n\n/**\n * Abstract base class for connection types.\n * Holds nodes and page info, used for type checking.\n */\nexport abstract class AbstractConnection<Node> extends Request {\n\tpublic pageInfo: PageInfo;\n\tpublic nodes: Node[];\n\tpublic totalCount?: number;\n\n\tpublic constructor(request: DvinaRequest) {\n\t\tsuper(request);\n\t\tthis.pageInfo = new PageInfo({\n\t\t\thasNextPage: false,\n\t\t\thasPreviousPage: false,\n\t\t});\n\t\tthis.nodes = [];\n\t}\n}\n\n/**\n * Concrete connection class with pagination helpers.\n * Generated connection subclasses extend this.\n *\n * The `_fetch` closure is created by the query class and allows re-fetching\n * with different pagination variables.\n */\nexport class Connection<Node> extends AbstractConnection<Node> {\n\tprivate _fetch: (variables?: ConnectionVariables, options?: FetchOptions) => Promise<Connection<Node> | undefined>;\n\n\tpublic constructor(\n\t\trequest: DvinaRequest,\n\t\tfetch: (variables?: ConnectionVariables, options?: FetchOptions) => Promise<Connection<Node> | undefined>,\n\t\tnodes: Node[],\n\t\tpageInfo: PageInfo,\n\t\ttotalCount?: number,\n\t) {\n\t\tsuper(request);\n\t\tthis._fetch = fetch;\n\t\tthis.nodes = nodes;\n\t\tthis.pageInfo = pageInfo;\n\t\tthis.totalCount = totalCount;\n\t}\n\n\t/**\n\t * Fetch the next page and append nodes.\n\t * Mutates this connection instance in place (nodes are appended, pageInfo updated).\n\t */\n\tpublic async fetchNext(options?: FetchOptions): Promise<this> {\n\t\tif (this.pageInfo.hasNextPage) {\n\t\t\tconst response = await this._fetch({ after: this.pageInfo.endCursor }, options);\n\t\t\tif (response) {\n\t\t\t\tthis.nodes = [...this.nodes, ...response.nodes];\n\t\t\t\tthis.pageInfo.endCursor = response.pageInfo.endCursor ?? this.pageInfo.endCursor;\n\t\t\t\tthis.pageInfo.hasNextPage = response.pageInfo.hasNextPage;\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Fetch the previous page and prepend nodes.\n\t * Mutates this connection instance in place (nodes are prepended, pageInfo updated).\n\t */\n\tpublic async fetchPrevious(options?: FetchOptions): Promise<this> {\n\t\tif (this.pageInfo.hasPreviousPage) {\n\t\t\tconst response = await this._fetch({ before: this.pageInfo.startCursor }, options);\n\t\t\tif (response) {\n\t\t\t\tthis.nodes = [...response.nodes, ...this.nodes];\n\t\t\t\tthis.pageInfo.startCursor = response.pageInfo.startCursor ?? this.pageInfo.startCursor;\n\t\t\t\tthis.pageInfo.hasPreviousPage = response.pageInfo.hasPreviousPage;\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n}\n"]}
|
package/dist/chunk-KV5SP7RP.cjs
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/error.ts
|
|
4
|
-
var DvinaError = class extends Error {
|
|
5
|
-
/** The original error, if any */
|
|
6
|
-
cause;
|
|
7
|
-
constructor(message, cause) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.name = "DvinaError";
|
|
10
|
-
this.cause = cause;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
var DvinaGraphQLError = class extends DvinaError {
|
|
14
|
-
/** The raw GraphQL errors array */
|
|
15
|
-
errors;
|
|
16
|
-
/** The query that caused the error (for debugging) */
|
|
17
|
-
query;
|
|
18
|
-
/** The variables that were passed */
|
|
19
|
-
variables;
|
|
20
|
-
constructor(errors, query, variables) {
|
|
21
|
-
const message = errors.map((e) => e.message).join("; ") || "Unknown GraphQL error";
|
|
22
|
-
super(message);
|
|
23
|
-
this.name = "DvinaGraphQLError";
|
|
24
|
-
this.errors = errors;
|
|
25
|
-
this.query = query;
|
|
26
|
-
this.variables = variables;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var DvinaNetworkError = class extends DvinaError {
|
|
30
|
-
/** HTTP status code, if available */
|
|
31
|
-
status;
|
|
32
|
-
constructor(message, status, cause) {
|
|
33
|
-
super(message, cause);
|
|
34
|
-
this.name = "DvinaNetworkError";
|
|
35
|
-
this.status = status;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var DvinaAuthenticationError = class extends DvinaError {
|
|
39
|
-
/** The token that was used when the auth error occurred (for stale-token detection). */
|
|
40
|
-
failedToken;
|
|
41
|
-
constructor(message = "Authentication failed", failedTokenOrCause, cause) {
|
|
42
|
-
super(message, typeof failedTokenOrCause === "string" ? cause : failedTokenOrCause);
|
|
43
|
-
this.name = "DvinaAuthenticationError";
|
|
44
|
-
this.failedToken = typeof failedTokenOrCause === "string" ? failedTokenOrCause : void 0;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
var GRAPHQL_ERROR_CODES = {
|
|
48
|
-
SESSION_TOKEN_LIMIT_REACHED: "SESSION_TOKEN_LIMIT_REACHED",
|
|
49
|
-
STORAGE_LIMIT_REACHED: "STORAGE_LIMIT_REACHED",
|
|
50
|
-
DEEP_ANALYSIS_LIMIT_EXCEEDED: "DEEP_ANALYSIS_LIMIT_EXCEEDED",
|
|
51
|
-
PLAN_DETAIL_RESTRICTION: "PLAN_DETAIL_RESTRICTION",
|
|
52
|
-
RESOURCE_NOT_FOUND: "RESOURCE_NOT_FOUND"
|
|
53
|
-
};
|
|
54
|
-
var PLAN_RESTRICTION_CODES = /* @__PURE__ */ new Set([
|
|
55
|
-
GRAPHQL_ERROR_CODES.PLAN_DETAIL_RESTRICTION,
|
|
56
|
-
GRAPHQL_ERROR_CODES.STORAGE_LIMIT_REACHED,
|
|
57
|
-
GRAPHQL_ERROR_CODES.DEEP_ANALYSIS_LIMIT_EXCEEDED
|
|
58
|
-
]);
|
|
59
|
-
var DvinaPlanRestrictionError = class extends DvinaGraphQLError {
|
|
60
|
-
/** The specific restriction code (e.g. 'PLAN_DETAIL_RESTRICTION') */
|
|
61
|
-
restrictionCode;
|
|
62
|
-
constructor(errors, restrictionCode, query, variables) {
|
|
63
|
-
super(errors, query, variables);
|
|
64
|
-
this.name = "DvinaPlanRestrictionError";
|
|
65
|
-
this.restrictionCode = restrictionCode;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
var DvinaTokenLimitError = class extends DvinaGraphQLError {
|
|
69
|
-
constructor(errors, query, variables) {
|
|
70
|
-
super(errors, query, variables);
|
|
71
|
-
this.name = "DvinaTokenLimitError";
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var DvinaNotFoundError = class extends DvinaGraphQLError {
|
|
75
|
-
constructor(errors, query, variables) {
|
|
76
|
-
super(errors, query, variables);
|
|
77
|
-
this.name = "DvinaNotFoundError";
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
function extractErrorCode(errors) {
|
|
81
|
-
for (const err of errors) {
|
|
82
|
-
const raw = err.extensions?.["code"];
|
|
83
|
-
if (raw !== void 0 && raw !== null) {
|
|
84
|
-
return String(raw).toUpperCase();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return void 0;
|
|
88
|
-
}
|
|
89
|
-
function createGraphQLError(errors, query, variables) {
|
|
90
|
-
const code = extractErrorCode(errors);
|
|
91
|
-
if (code === GRAPHQL_ERROR_CODES.SESSION_TOKEN_LIMIT_REACHED) {
|
|
92
|
-
return new DvinaTokenLimitError(errors, query, variables);
|
|
93
|
-
}
|
|
94
|
-
if (code === GRAPHQL_ERROR_CODES.RESOURCE_NOT_FOUND) {
|
|
95
|
-
return new DvinaNotFoundError(errors, query, variables);
|
|
96
|
-
}
|
|
97
|
-
if (code && PLAN_RESTRICTION_CODES.has(code)) {
|
|
98
|
-
return new DvinaPlanRestrictionError(errors, code, query, variables);
|
|
99
|
-
}
|
|
100
|
-
return new DvinaGraphQLError(errors, query, variables);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
exports.DvinaAuthenticationError = DvinaAuthenticationError;
|
|
104
|
-
exports.DvinaError = DvinaError;
|
|
105
|
-
exports.DvinaGraphQLError = DvinaGraphQLError;
|
|
106
|
-
exports.DvinaNetworkError = DvinaNetworkError;
|
|
107
|
-
exports.DvinaNotFoundError = DvinaNotFoundError;
|
|
108
|
-
exports.DvinaPlanRestrictionError = DvinaPlanRestrictionError;
|
|
109
|
-
exports.DvinaTokenLimitError = DvinaTokenLimitError;
|
|
110
|
-
exports.GRAPHQL_ERROR_CODES = GRAPHQL_ERROR_CODES;
|
|
111
|
-
exports.createGraphQLError = createGraphQLError;
|
|
112
|
-
exports.extractErrorCode = extractErrorCode;
|
|
113
|
-
//# sourceMappingURL=chunk-KV5SP7RP.cjs.map
|
|
114
|
-
//# sourceMappingURL=chunk-KV5SP7RP.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error.ts"],"names":[],"mappings":";;;AAGO,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA;AAAA,E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A,GAAO,oBAAA;AAAA,EACb;AACD;AAQO,SAAS,iBAAiB,MAAA,EAA0D;AAC1F,EAAA,KAAA,MAAW,OAAO,MAAA,EAAQ;AACzB,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,UAAA,GAAa,MAAM,CAAA;AACnC,IAAA,IAAI,GAAA,KAAQ,MAAA,IAAa,GAAA,KAAQ,IAAA,EAAM;AACtC,MAAA,OAAO,MAAA,CAAO,GAAG,CAAA,CAAE,WAAA,EAAY;AAAA,IAChC;AAAA,EACD;AACA,EAAA,OAAO,MAAA;AACR;AAMO,SAAS,kBAAA,CACf,MAAA,EACA,KAAA,EACA,SAAA,EACoB;AACpB,EAAA,MAAM,IAAA,GAAO,iBAAiB,MAAM,CAAA;AAEpC,EAAA,IAAI,IAAA,KAAS,oBAAoB,2BAAA,EAA6B;AAC7D,IAAA,OAAO,IAAI,oBAAA,CAAqB,MAAA,EAAQ,KAAA,EAAO,SAAS,CAAA;AAAA,EACzD;AAEA,EAAA,IAAI,IAAA,KAAS,oBAAoB,kBAAA,EAAoB;AACpD,IAAA,OAAO,IAAI,kBAAA,CAAmB,MAAA,EAAQ,KAAA,EAAO,SAAS,CAAA;AAAA,EACvD;AAEA,EAAA,IAAI,IAAA,IAAQ,sBAAA,CAAuB,GAAA,CAAI,IAAI,CAAA,EAAG;AAC7C,IAAA,OAAO,IAAI,yBAAA,CAA0B,MAAA,EAAQ,IAAA,EAAM,OAAO,SAAS,CAAA;AAAA,EACpE;AAEA,EAAA,OAAO,IAAI,iBAAA,CAAkB,MAAA,EAAQ,KAAA,EAAO,SAAS,CAAA;AACtD","file":"chunk-KV5SP7RP.cjs","sourcesContent":["/**\n * Base error class for all Dvina SDK errors.\n */\nexport class DvinaError extends Error {\n\t/** The original error, if any */\n\tpublic readonly cause?: Error;\n\n\tconstructor(message: string, cause?: Error) {\n\t\tsuper(message);\n\t\tthis.name = 'DvinaError';\n\t\tthis.cause = cause;\n\t}\n}\n\n/**\n * Error thrown when the GraphQL response contains errors.\n */\nexport class DvinaGraphQLError extends DvinaError {\n\t/** The raw GraphQL errors array */\n\tpublic readonly errors: readonly GraphQLErrorEntry[];\n\t/** The query that caused the error (for debugging) */\n\tpublic readonly query?: string;\n\t/** The variables that were passed */\n\tpublic readonly variables?: Record<string, unknown>;\n\n\tconstructor(errors: readonly GraphQLErrorEntry[], query?: string, variables?: Record<string, unknown>) {\n\t\tconst message = errors.map((e) => e.message).join('; ') || 'Unknown GraphQL error';\n\t\tsuper(message);\n\t\tthis.name = 'DvinaGraphQLError';\n\t\tthis.errors = errors;\n\t\tthis.query = query;\n\t\tthis.variables = variables;\n\t}\n}\n\n/**\n * Error thrown on network failures (connection refused, timeout, etc.)\n */\nexport class DvinaNetworkError extends DvinaError {\n\t/** HTTP status code, if available */\n\tpublic readonly status?: number;\n\n\tconstructor(message: string, status?: number, cause?: Error) {\n\t\tsuper(message, cause);\n\t\tthis.name = 'DvinaNetworkError';\n\t\tthis.status = status;\n\t}\n}\n\n/**\n * Error thrown when authentication fails (401/403).\n */\nexport class DvinaAuthenticationError extends DvinaError {\n\t/** The token that was used when the auth error occurred (for stale-token detection). */\n\tpublic readonly failedToken?: string;\n\n\tconstructor(message = 'Authentication failed', failedTokenOrCause?: string | Error, cause?: Error) {\n\t\tsuper(message, typeof failedTokenOrCause === 'string' ? cause : failedTokenOrCause);\n\t\tthis.name = 'DvinaAuthenticationError';\n\t\tthis.failedToken = typeof failedTokenOrCause === 'string' ? failedTokenOrCause : undefined;\n\t}\n}\n\n// ─── GraphQL Business Error Codes ────────────────────────────────────────────\n\n/**\n * Known GraphQL error codes returned by the Dvina API in `extensions.code`.\n * Used for programmatic matching in SDK error detection.\n */\nexport const GRAPHQL_ERROR_CODES = {\n\tSESSION_TOKEN_LIMIT_REACHED: 'SESSION_TOKEN_LIMIT_REACHED',\n\tSTORAGE_LIMIT_REACHED: 'STORAGE_LIMIT_REACHED',\n\tDEEP_ANALYSIS_LIMIT_EXCEEDED: 'DEEP_ANALYSIS_LIMIT_EXCEEDED',\n\tPLAN_DETAIL_RESTRICTION: 'PLAN_DETAIL_RESTRICTION',\n\tRESOURCE_NOT_FOUND: 'RESOURCE_NOT_FOUND',\n} as const;\n\n/** Codes that indicate a plan/billing restriction. */\nconst PLAN_RESTRICTION_CODES = new Set<string>([\n\tGRAPHQL_ERROR_CODES.PLAN_DETAIL_RESTRICTION,\n\tGRAPHQL_ERROR_CODES.STORAGE_LIMIT_REACHED,\n\tGRAPHQL_ERROR_CODES.DEEP_ANALYSIS_LIMIT_EXCEEDED,\n]);\n\n// ─── GraphQL Business Error Subclasses ───────────────────────────────────────\n\n/**\n * Base class for plan/billing restriction errors.\n * Thrown when the workspace exceeds a plan limit (storage, capabilities, deep analysis).\n *\n * Consumers can `catch (e) { if (e instanceof DvinaPlanRestrictionError) showUpgradeDialog(); }`\n */\nexport class DvinaPlanRestrictionError extends DvinaGraphQLError {\n\t/** The specific restriction code (e.g. 'PLAN_DETAIL_RESTRICTION') */\n\tpublic readonly restrictionCode: string;\n\n\tconstructor(\n\t\terrors: readonly GraphQLErrorEntry[],\n\t\trestrictionCode: string,\n\t\tquery?: string,\n\t\tvariables?: Record<string, unknown>,\n\t) {\n\t\tsuper(errors, query, variables);\n\t\tthis.name = 'DvinaPlanRestrictionError';\n\t\tthis.restrictionCode = restrictionCode;\n\t}\n}\n\n/**\n * Error thrown when the chat session token limit is reached (SESSION_TOKEN_LIMIT_REACHED).\n * Distinct from inference quota — this is a per-session GraphQL limit.\n */\nexport class DvinaTokenLimitError extends DvinaGraphQLError {\n\tconstructor(errors: readonly GraphQLErrorEntry[], query?: string, variables?: Record<string, unknown>) {\n\t\tsuper(errors, query, variables);\n\t\tthis.name = 'DvinaTokenLimitError';\n\t}\n}\n\n/**\n * Error thrown when a requested resource is not found (RESOURCE_NOT_FOUND).\n */\nexport class DvinaNotFoundError extends DvinaGraphQLError {\n\tconstructor(errors: readonly GraphQLErrorEntry[], query?: string, variables?: Record<string, unknown>) {\n\t\tsuper(errors, query, variables);\n\t\tthis.name = 'DvinaNotFoundError';\n\t}\n}\n\n// ─── Error Detection Helpers ─────────────────────────────────────────────────\n\n/**\n * Extract the first extension code from a list of GraphQL errors (normalized to uppercase).\n * Returns `undefined` if no code is present.\n */\nexport function extractErrorCode(errors: readonly GraphQLErrorEntry[]): string | undefined {\n\tfor (const err of errors) {\n\t\tconst raw = err.extensions?.['code'];\n\t\tif (raw !== undefined && raw !== null) {\n\t\t\treturn String(raw).toUpperCase();\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Create the appropriate `DvinaGraphQLError` subclass for the given errors,\n * or return a generic `DvinaGraphQLError` if no specific match is found.\n */\nexport function createGraphQLError(\n\terrors: readonly GraphQLErrorEntry[],\n\tquery?: string,\n\tvariables?: Record<string, unknown>,\n): DvinaGraphQLError {\n\tconst code = extractErrorCode(errors);\n\n\tif (code === GRAPHQL_ERROR_CODES.SESSION_TOKEN_LIMIT_REACHED) {\n\t\treturn new DvinaTokenLimitError(errors, query, variables);\n\t}\n\n\tif (code === GRAPHQL_ERROR_CODES.RESOURCE_NOT_FOUND) {\n\t\treturn new DvinaNotFoundError(errors, query, variables);\n\t}\n\n\tif (code && PLAN_RESTRICTION_CODES.has(code)) {\n\t\treturn new DvinaPlanRestrictionError(errors, code, query, variables);\n\t}\n\n\treturn new DvinaGraphQLError(errors, query, variables);\n}\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/**\n * Shape of a single GraphQL error in the response.\n */\nexport interface GraphQLErrorEntry {\n\tmessage: string;\n\tlocations?: readonly { line: number; column: number }[];\n\tpath?: readonly (string | number)[];\n\textensions?: Record<string, unknown>;\n}\n"]}
|
package/dist/chunk-PDM2KR7T.js
DELETED
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
import { DvinaError } from './chunk-7XBJ77RJ.js';
|
|
2
|
-
|
|
3
|
-
// src/inference/errors.ts
|
|
4
|
-
var DvinaInferenceError = class extends DvinaError {
|
|
5
|
-
/** HTTP status code from the server */
|
|
6
|
-
status;
|
|
7
|
-
/** OpenAI-compatible error type (e.g. 'invalid_request_error') */
|
|
8
|
-
type;
|
|
9
|
-
/** Machine-readable error code (e.g. 'model_not_found') */
|
|
10
|
-
code;
|
|
11
|
-
constructor(message, status, type, code, cause) {
|
|
12
|
-
super(message, cause);
|
|
13
|
-
this.name = "DvinaInferenceError";
|
|
14
|
-
this.status = status;
|
|
15
|
-
this.type = type;
|
|
16
|
-
this.code = code;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
var DvinaRateLimitError = class extends DvinaInferenceError {
|
|
20
|
-
/** Retry-After header value in seconds, if provided by the server */
|
|
21
|
-
retryAfter;
|
|
22
|
-
constructor(message, retryAfter, cause) {
|
|
23
|
-
super(message, 429, "rate_limit_error", "rate_limit_exceeded", cause);
|
|
24
|
-
this.name = "DvinaRateLimitError";
|
|
25
|
-
this.retryAfter = retryAfter;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var DvinaQuotaError = class extends DvinaInferenceError {
|
|
29
|
-
constructor(message = "Token quota exceeded", cause) {
|
|
30
|
-
super(message, 403, "insufficient_quota", "token_limit_reached", cause);
|
|
31
|
-
this.name = "DvinaQuotaError";
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var DvinaInferenceAuthError = class extends DvinaInferenceError {
|
|
35
|
-
constructor(message = "Inference authentication failed", status = 401, cause) {
|
|
36
|
-
super(message, status, "authentication_error", "unauthorized", cause);
|
|
37
|
-
this.name = "DvinaInferenceAuthError";
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var DvinaStreamError = class extends DvinaInferenceError {
|
|
41
|
-
constructor(message, cause) {
|
|
42
|
-
super(message, 0, "stream_error", "stream_interrupted", cause);
|
|
43
|
-
this.name = "DvinaStreamError";
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var DvinaContextLengthError = class extends DvinaInferenceError {
|
|
47
|
-
constructor(message = "Context length exceeded", cause) {
|
|
48
|
-
super(message, 400, "invalid_request_error", "context_length_exceeded", cause);
|
|
49
|
-
this.name = "DvinaContextLengthError";
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var DvinaTimeoutError = class extends DvinaInferenceError {
|
|
53
|
-
constructor(message = "Request timed out", cause) {
|
|
54
|
-
super(message, 400, "timeout_error", "request_timeout", cause);
|
|
55
|
-
this.name = "DvinaTimeoutError";
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
var DvinaProviderUnavailableError = class extends DvinaInferenceError {
|
|
59
|
-
constructor(message = "Provider unavailable", cause) {
|
|
60
|
-
super(message, 502, "gateway_error", "provider_unavailable", cause);
|
|
61
|
-
this.name = "DvinaProviderUnavailableError";
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var DvinaProviderError = class extends DvinaInferenceError {
|
|
65
|
-
constructor(message = "Provider error", status = 502, cause) {
|
|
66
|
-
super(message, status, "api_error", "provider_error", cause);
|
|
67
|
-
this.name = "DvinaProviderError";
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var DvinaDeploymentError = class extends DvinaInferenceError {
|
|
71
|
-
constructor(message = "Deployment not found", cause) {
|
|
72
|
-
super(message, 502, "invalid_request_error", "deployment_not_found", cause);
|
|
73
|
-
this.name = "DvinaDeploymentError";
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var DvinaUnsupportedModelError = class extends DvinaInferenceError {
|
|
77
|
-
constructor(message = "Unsupported model", cause) {
|
|
78
|
-
super(message, 400, "invalid_request_error", "unsupported_model", cause);
|
|
79
|
-
this.name = "DvinaUnsupportedModelError";
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// src/inference/stream.ts
|
|
84
|
-
async function* parseSSEStream(body) {
|
|
85
|
-
const reader = body.getReader();
|
|
86
|
-
const decoder = new TextDecoder();
|
|
87
|
-
let buffer = "";
|
|
88
|
-
try {
|
|
89
|
-
while (true) {
|
|
90
|
-
const { done, value } = await reader.read();
|
|
91
|
-
if (done) {
|
|
92
|
-
if (buffer.trim()) {
|
|
93
|
-
const chunk = parseDataLine(buffer.trim());
|
|
94
|
-
if (chunk !== void 0) {
|
|
95
|
-
yield chunk;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
buffer += decoder.decode(value, { stream: true });
|
|
101
|
-
const lines = buffer.split(/\r?\n/);
|
|
102
|
-
buffer = lines.pop() ?? "";
|
|
103
|
-
for (const line of lines) {
|
|
104
|
-
if (line === "") continue;
|
|
105
|
-
if (line.startsWith(":")) continue;
|
|
106
|
-
if (line.startsWith("data: ")) {
|
|
107
|
-
const data = line.slice(6);
|
|
108
|
-
if (data === "[DONE]") {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
const parsed = JSON.parse(data);
|
|
113
|
-
yield parsed;
|
|
114
|
-
} catch {
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (line.startsWith("event: error")) {
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
} catch (error) {
|
|
122
|
-
throw new DvinaStreamError(
|
|
123
|
-
`SSE stream interrupted: ${error instanceof Error ? error.message : String(error)}`,
|
|
124
|
-
error instanceof Error ? error : void 0
|
|
125
|
-
);
|
|
126
|
-
} finally {
|
|
127
|
-
reader.releaseLock();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function parseDataLine(line) {
|
|
131
|
-
if (!line.startsWith("data: ")) return void 0;
|
|
132
|
-
const data = line.slice(6);
|
|
133
|
-
if (data === "[DONE]") return void 0;
|
|
134
|
-
try {
|
|
135
|
-
return JSON.parse(data);
|
|
136
|
-
} catch {
|
|
137
|
-
return void 0;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
var ChatCompletionStream = class {
|
|
141
|
-
_chunks = [];
|
|
142
|
-
_source;
|
|
143
|
-
_consumed = false;
|
|
144
|
-
constructor(source) {
|
|
145
|
-
this._source = source;
|
|
146
|
-
}
|
|
147
|
-
async *[Symbol.asyncIterator]() {
|
|
148
|
-
if (this._consumed) {
|
|
149
|
-
for (const chunk of this._chunks) {
|
|
150
|
-
yield chunk;
|
|
151
|
-
}
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
this._consumed = true;
|
|
155
|
-
for await (const chunk of this._source) {
|
|
156
|
-
this._chunks.push(chunk);
|
|
157
|
-
yield chunk;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Concatenate all content deltas into a single string.
|
|
162
|
-
* Must be called after the stream has been fully consumed.
|
|
163
|
-
*/
|
|
164
|
-
getText() {
|
|
165
|
-
const parts = [];
|
|
166
|
-
for (const chunk of this._chunks) {
|
|
167
|
-
const content = chunk.choices[0]?.delta?.content;
|
|
168
|
-
if (content) {
|
|
169
|
-
parts.push(content);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return parts.join("");
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Get the token usage from the final chunk (if the server included it).
|
|
176
|
-
* Must be called after the stream has been fully consumed.
|
|
177
|
-
*/
|
|
178
|
-
getUsage() {
|
|
179
|
-
for (let i = this._chunks.length - 1; i >= 0; i--) {
|
|
180
|
-
if (this._chunks[i].usage) {
|
|
181
|
-
return this._chunks[i].usage;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return void 0;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Get the collected chunks array.
|
|
188
|
-
* Must be called after the stream has been fully consumed.
|
|
189
|
-
*/
|
|
190
|
-
getChunks() {
|
|
191
|
-
return this._chunks;
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// src/inference/client.ts
|
|
196
|
-
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
197
|
-
async function throwForStatus(response) {
|
|
198
|
-
let errorBody;
|
|
199
|
-
try {
|
|
200
|
-
errorBody = await response.json();
|
|
201
|
-
} catch {
|
|
202
|
-
}
|
|
203
|
-
const message = errorBody?.error?.message ?? `HTTP ${response.status}: ${response.statusText}`;
|
|
204
|
-
const type = errorBody?.error?.type ?? "api_error";
|
|
205
|
-
const code = errorBody?.error?.code ?? "unknown";
|
|
206
|
-
if (response.status === 401 || response.status === 403) {
|
|
207
|
-
if (code === "token_limit_reached" || type === "insufficient_quota") {
|
|
208
|
-
throw new DvinaQuotaError(message);
|
|
209
|
-
}
|
|
210
|
-
throw new DvinaInferenceAuthError(message, response.status);
|
|
211
|
-
}
|
|
212
|
-
if (response.status === 429) {
|
|
213
|
-
const retryAfterHeader = response.headers.get("retry-after");
|
|
214
|
-
const retryAfter = retryAfterHeader ? parseInt(retryAfterHeader, 10) : void 0;
|
|
215
|
-
throw new DvinaRateLimitError(message, Number.isNaN(retryAfter) ? void 0 : retryAfter);
|
|
216
|
-
}
|
|
217
|
-
switch (code) {
|
|
218
|
-
case "context_length_exceeded":
|
|
219
|
-
throw new DvinaContextLengthError(message);
|
|
220
|
-
case "request_timeout":
|
|
221
|
-
throw new DvinaTimeoutError(message);
|
|
222
|
-
case "provider_unavailable":
|
|
223
|
-
throw new DvinaProviderUnavailableError(message);
|
|
224
|
-
case "provider_error":
|
|
225
|
-
throw new DvinaProviderError(message, response.status);
|
|
226
|
-
case "deployment_not_found":
|
|
227
|
-
throw new DvinaDeploymentError(message);
|
|
228
|
-
case "unsupported_model":
|
|
229
|
-
throw new DvinaUnsupportedModelError(message);
|
|
230
|
-
}
|
|
231
|
-
throw new DvinaInferenceError(message, response.status, type, code);
|
|
232
|
-
}
|
|
233
|
-
function createInferenceClientInternal(baseUrl, getToken, options) {
|
|
234
|
-
return buildInferenceClient(baseUrl, getToken, options?.headers, options?.timeout);
|
|
235
|
-
}
|
|
236
|
-
function createInferenceClient(options) {
|
|
237
|
-
const baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
238
|
-
let getToken;
|
|
239
|
-
if (options.getToken) {
|
|
240
|
-
getToken = options.getToken;
|
|
241
|
-
} else if (options.token) {
|
|
242
|
-
const staticToken = options.token;
|
|
243
|
-
getToken = async () => staticToken;
|
|
244
|
-
} else {
|
|
245
|
-
throw new Error("InferenceClientOptions must provide either `token` or `getToken`.");
|
|
246
|
-
}
|
|
247
|
-
return buildInferenceClient(baseUrl, getToken, options.headers, options.timeout);
|
|
248
|
-
}
|
|
249
|
-
function buildInferenceClient(baseUrl, getToken, customHeaders, timeout) {
|
|
250
|
-
const timeoutMs = timeout ?? DEFAULT_TIMEOUT_MS;
|
|
251
|
-
const headers = customHeaders ?? {};
|
|
252
|
-
async function buildRequestHeaders() {
|
|
253
|
-
const token = await getToken();
|
|
254
|
-
return {
|
|
255
|
-
"Content-Type": "application/json",
|
|
256
|
-
Authorization: `Bearer ${token}`,
|
|
257
|
-
...headers
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
async function request(method, path, body) {
|
|
261
|
-
const controller = new AbortController();
|
|
262
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
263
|
-
try {
|
|
264
|
-
const reqHeaders = await buildRequestHeaders();
|
|
265
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
266
|
-
method,
|
|
267
|
-
headers: reqHeaders,
|
|
268
|
-
body: body !== void 0 ? JSON.stringify(body) : void 0,
|
|
269
|
-
signal: controller.signal
|
|
270
|
-
});
|
|
271
|
-
if (!response.ok) {
|
|
272
|
-
await throwForStatus(response);
|
|
273
|
-
}
|
|
274
|
-
return await response.json();
|
|
275
|
-
} catch (error) {
|
|
276
|
-
if (error instanceof DvinaInferenceError) throw error;
|
|
277
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
278
|
-
throw new DvinaInferenceError(
|
|
279
|
-
`Request timed out after ${timeoutMs}ms`,
|
|
280
|
-
0,
|
|
281
|
-
"timeout_error",
|
|
282
|
-
"request_timeout"
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
throw new DvinaInferenceError(
|
|
286
|
-
`Network error: ${error instanceof Error ? error.message : String(error)}`,
|
|
287
|
-
0,
|
|
288
|
-
"network_error",
|
|
289
|
-
"connection_failed",
|
|
290
|
-
error instanceof Error ? error : void 0
|
|
291
|
-
);
|
|
292
|
-
} finally {
|
|
293
|
-
clearTimeout(timer);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
async function requestStream(path, body) {
|
|
297
|
-
const controller = new AbortController();
|
|
298
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
299
|
-
try {
|
|
300
|
-
const reqHeaders = await buildRequestHeaders();
|
|
301
|
-
const response = await fetch(`${baseUrl}${path}`, {
|
|
302
|
-
method: "POST",
|
|
303
|
-
headers: reqHeaders,
|
|
304
|
-
body: JSON.stringify(body),
|
|
305
|
-
signal: controller.signal
|
|
306
|
-
});
|
|
307
|
-
clearTimeout(timer);
|
|
308
|
-
if (!response.ok) {
|
|
309
|
-
await throwForStatus(response);
|
|
310
|
-
}
|
|
311
|
-
if (!response.body) {
|
|
312
|
-
throw new DvinaStreamError("Response body is null \u2014 streaming not supported in this environment");
|
|
313
|
-
}
|
|
314
|
-
return response.body;
|
|
315
|
-
} catch (error) {
|
|
316
|
-
clearTimeout(timer);
|
|
317
|
-
if (error instanceof DvinaInferenceError) throw error;
|
|
318
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
319
|
-
throw new DvinaInferenceError(
|
|
320
|
-
`Stream connection timed out after ${timeoutMs}ms`,
|
|
321
|
-
0,
|
|
322
|
-
"timeout_error",
|
|
323
|
-
"request_timeout"
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
throw new DvinaInferenceError(
|
|
327
|
-
`Network error: ${error instanceof Error ? error.message : String(error)}`,
|
|
328
|
-
0,
|
|
329
|
-
"network_error",
|
|
330
|
-
"connection_failed",
|
|
331
|
-
error instanceof Error ? error : void 0
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
const completions = {
|
|
336
|
-
async create(req) {
|
|
337
|
-
return request("POST", "/chat/completions", {
|
|
338
|
-
...req,
|
|
339
|
-
stream: false
|
|
340
|
-
});
|
|
341
|
-
},
|
|
342
|
-
async stream(req) {
|
|
343
|
-
const body = await requestStream("/chat/completions", {
|
|
344
|
-
...req,
|
|
345
|
-
stream: true
|
|
346
|
-
});
|
|
347
|
-
const source = parseSSEStream(body);
|
|
348
|
-
return new ChatCompletionStream(source);
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
const chat = { completions };
|
|
352
|
-
const responses = {
|
|
353
|
-
async create(req) {
|
|
354
|
-
return request("POST", "/responses", {
|
|
355
|
-
...req,
|
|
356
|
-
stream: false
|
|
357
|
-
});
|
|
358
|
-
},
|
|
359
|
-
async stream(req) {
|
|
360
|
-
const body = await requestStream("/responses", {
|
|
361
|
-
...req,
|
|
362
|
-
stream: true
|
|
363
|
-
});
|
|
364
|
-
return {
|
|
365
|
-
[Symbol.asyncIterator]() {
|
|
366
|
-
return parseSSEStream(body);
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
const models = {
|
|
372
|
-
async list() {
|
|
373
|
-
return request("GET", "/models");
|
|
374
|
-
},
|
|
375
|
-
async get(modelId) {
|
|
376
|
-
return request("GET", `/models/${encodeURIComponent(modelId)}`);
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
async function health() {
|
|
380
|
-
return request("GET", "/health");
|
|
381
|
-
}
|
|
382
|
-
return {
|
|
383
|
-
chat,
|
|
384
|
-
responses,
|
|
385
|
-
models,
|
|
386
|
-
health
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
export { ChatCompletionStream, DvinaContextLengthError, DvinaDeploymentError, DvinaInferenceAuthError, DvinaInferenceError, DvinaProviderError, DvinaProviderUnavailableError, DvinaQuotaError, DvinaRateLimitError, DvinaStreamError, DvinaTimeoutError, DvinaUnsupportedModelError, createInferenceClient, createInferenceClientInternal, parseSSEStream };
|
|
391
|
-
//# sourceMappingURL=chunk-PDM2KR7T.js.map
|
|
392
|
-
//# sourceMappingURL=chunk-PDM2KR7T.js.map
|