@arbidocs/sdk 0.3.10 → 0.3.11
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/browser.cjs +29 -5
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +29 -5
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +31 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +31 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/browser.cjs
CHANGED
|
@@ -46,10 +46,31 @@ function getErrorMessage(err) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// src/fetch.ts
|
|
49
|
-
var
|
|
49
|
+
var STATUS_FALLBACKS = {
|
|
50
50
|
401: "Token has expired. Please run: arbi login",
|
|
51
|
+
403: "Access denied. You may not have permission for this workspace.",
|
|
52
|
+
404: "Resource not found.",
|
|
51
53
|
503: "The selected LLM is not responding. Please retry or select another model."
|
|
52
54
|
};
|
|
55
|
+
async function extractErrorMessage(res) {
|
|
56
|
+
let bodyDetail;
|
|
57
|
+
try {
|
|
58
|
+
const text = await res.text();
|
|
59
|
+
if (text) {
|
|
60
|
+
try {
|
|
61
|
+
const json = JSON.parse(text);
|
|
62
|
+
bodyDetail = json.detail || json.message || json.error || void 0;
|
|
63
|
+
} catch {
|
|
64
|
+
if (text.length < 200) bodyDetail = text;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
if (bodyDetail) return `Request failed (${res.status}): ${bodyDetail}`;
|
|
70
|
+
const fallback = STATUS_FALLBACKS[res.status];
|
|
71
|
+
if (fallback) return fallback;
|
|
72
|
+
return `Request failed: ${res.status} ${res.statusText}`;
|
|
73
|
+
}
|
|
53
74
|
async function authenticatedFetch(options) {
|
|
54
75
|
const { baseUrl, accessToken, workspaceKeyHeader, path: path2, method, body, headers } = options;
|
|
55
76
|
const res = await fetch(`${baseUrl}${path2}`, {
|
|
@@ -62,10 +83,8 @@ async function authenticatedFetch(options) {
|
|
|
62
83
|
body
|
|
63
84
|
});
|
|
64
85
|
if (!res.ok) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
const text = await res.text().catch(() => "");
|
|
68
|
-
throw new Error(`Request failed: ${res.status} ${text}`);
|
|
86
|
+
const message = await extractErrorMessage(res);
|
|
87
|
+
throw new ArbiApiError(message, { status: res.status, statusText: res.statusText });
|
|
69
88
|
}
|
|
70
89
|
return res;
|
|
71
90
|
}
|
|
@@ -254,6 +273,11 @@ async function streamSSE(response, callbacks = {}) {
|
|
|
254
273
|
usage = data.response.usage;
|
|
255
274
|
callbacks.onUsage?.(data.response.usage);
|
|
256
275
|
}
|
|
276
|
+
if (data.response?.metadata) {
|
|
277
|
+
const meta = data.response.metadata;
|
|
278
|
+
metadata = meta;
|
|
279
|
+
callbacks.onMetadata?.(meta);
|
|
280
|
+
}
|
|
257
281
|
if (data.t != null) callbacks.onElapsedTime?.(data.t);
|
|
258
282
|
callbacks.onComplete?.();
|
|
259
283
|
},
|