@decartai/sdk 0.1.19 → 0.1.20
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/package.js +1 -1
- package/dist/process/request.js +2 -2
- package/dist/queue/request.js +4 -4
- package/dist/shared/request.js +15 -1
- package/package.json +1 -1
package/dist/package.js
CHANGED
package/dist/process/request.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSDKError } from "../utils/errors.js";
|
|
2
|
-
import { buildAuthHeaders, buildFormData } from "../shared/request.js";
|
|
2
|
+
import { buildAuthHeaders, buildFormData, readErrorBody } from "../shared/request.js";
|
|
3
3
|
//#region src/process/request.ts
|
|
4
4
|
async function sendRequest({ baseUrl, apiKey, model, inputs, signal, integration }) {
|
|
5
5
|
const formData = buildFormData(inputs);
|
|
@@ -15,7 +15,7 @@ async function sendRequest({ baseUrl, apiKey, model, inputs, signal, integration
|
|
|
15
15
|
signal
|
|
16
16
|
});
|
|
17
17
|
if (!response.ok) {
|
|
18
|
-
const errorText = await response
|
|
18
|
+
const errorText = await readErrorBody(response);
|
|
19
19
|
throw createSDKError("PROCESSING_ERROR", `Processing failed: ${response.status} - ${errorText}`);
|
|
20
20
|
}
|
|
21
21
|
return response.blob();
|
package/dist/queue/request.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createQueueResultError, createQueueStatusError, createQueueSubmitError } from "../utils/errors.js";
|
|
2
|
-
import { buildAuthHeaders, buildFormData } from "../shared/request.js";
|
|
2
|
+
import { buildAuthHeaders, buildFormData, readErrorBody } from "../shared/request.js";
|
|
3
3
|
//#region src/queue/request.ts
|
|
4
4
|
/**
|
|
5
5
|
* Submit a job to the queue.
|
|
@@ -20,7 +20,7 @@ async function submitJob({ baseUrl, apiKey, model, inputs, signal, integration }
|
|
|
20
20
|
signal
|
|
21
21
|
});
|
|
22
22
|
if (!response.ok) {
|
|
23
|
-
const errorText = await response
|
|
23
|
+
const errorText = await readErrorBody(response);
|
|
24
24
|
throw createQueueSubmitError(`Failed to submit job: ${response.status} - ${errorText}`, response.status);
|
|
25
25
|
}
|
|
26
26
|
return response.json();
|
|
@@ -41,7 +41,7 @@ async function getJobStatus({ baseUrl, apiKey, jobId, signal, integration }) {
|
|
|
41
41
|
signal
|
|
42
42
|
});
|
|
43
43
|
if (!response.ok) {
|
|
44
|
-
const errorText = await response
|
|
44
|
+
const errorText = await readErrorBody(response);
|
|
45
45
|
throw createQueueStatusError(`Failed to get job status: ${response.status} - ${errorText}`, response.status);
|
|
46
46
|
}
|
|
47
47
|
return response.json();
|
|
@@ -62,7 +62,7 @@ async function getJobContent({ baseUrl, apiKey, jobId, signal, integration }) {
|
|
|
62
62
|
signal
|
|
63
63
|
});
|
|
64
64
|
if (!response.ok) {
|
|
65
|
-
const errorText = await response
|
|
65
|
+
const errorText = await readErrorBody(response);
|
|
66
66
|
throw createQueueResultError(`Failed to get job content: ${response.status} - ${errorText}`, response.status);
|
|
67
67
|
}
|
|
68
68
|
return response.blob();
|
package/dist/shared/request.js
CHANGED
|
@@ -26,6 +26,20 @@ async function fileInputToBlob(input) {
|
|
|
26
26
|
throw createInvalidInputError("Invalid file input type");
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
+
* Read an error response body for an SDK error message. The API returns JSON
|
|
30
|
+
* like {"detail": "Prompt is too long: ..."} — surface the human-readable
|
|
31
|
+
* detail instead of the raw JSON when present.
|
|
32
|
+
*/
|
|
33
|
+
async function readErrorBody(response) {
|
|
34
|
+
const text = await response.text().catch(() => "");
|
|
35
|
+
if (!text) return "Unknown error";
|
|
36
|
+
try {
|
|
37
|
+
const detail = JSON.parse(text).detail;
|
|
38
|
+
if (typeof detail === "string" && detail) return detail;
|
|
39
|
+
} catch {}
|
|
40
|
+
return text;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
29
43
|
* Build common headers for API requests.
|
|
30
44
|
*/
|
|
31
45
|
function buildAuthHeaders(options = {}) {
|
|
@@ -47,4 +61,4 @@ function buildFormData(inputs) {
|
|
|
47
61
|
return formData;
|
|
48
62
|
}
|
|
49
63
|
//#endregion
|
|
50
|
-
export { buildAuthHeaders, buildFormData, fileInputToBlob };
|
|
64
|
+
export { buildAuthHeaders, buildFormData, fileInputToBlob, readErrorBody };
|