@pitcher/js-api 1.27.1 → 1.27.3
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/js-api.esm.js +35 -22
- package/js-api.esm.js.map +1 -1
- package/js-api.umd.min.js +9 -9
- package/js-api.umd.min.js.map +1 -1
- package/package.json +1 -1
package/js-api.esm.js
CHANGED
|
@@ -2388,6 +2388,7 @@ function resolvePiaSearchMode(config) {
|
|
|
2388
2388
|
const PIA_SEARCH_ROUTE = "/core/api/protected/pia-prepare/pia-search";
|
|
2389
2389
|
const CAPABILITIES_TIMEOUT_MS = 3e3;
|
|
2390
2390
|
const ON_DEVICE_MAX_TOKENS = 512;
|
|
2391
|
+
const ONLINE_TIMEOUT_MS = 3e4;
|
|
2391
2392
|
const WEB_CAPABILITIES = {
|
|
2392
2393
|
available: true,
|
|
2393
2394
|
offline: false,
|
|
@@ -2473,29 +2474,41 @@ async function piaSearchAnswer(payload) {
|
|
|
2473
2474
|
if (!instanceId) {
|
|
2474
2475
|
throw new Error("piaSearchAnswer: instance_id could not be resolved from the payload or env");
|
|
2475
2476
|
}
|
|
2476
|
-
const
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2477
|
+
const controller = new AbortController();
|
|
2478
|
+
const timer = setTimeout(() => controller.abort(), ONLINE_TIMEOUT_MS);
|
|
2479
|
+
try {
|
|
2480
|
+
const response = await fetch(`${apiOriginFromEnv(env)}${PIA_SEARCH_ROUTE}`, {
|
|
2481
|
+
method: "POST",
|
|
2482
|
+
signal: controller.signal,
|
|
2483
|
+
headers: {
|
|
2484
|
+
"Content-Type": "application/json",
|
|
2485
|
+
Authorization: `Bearer ${env.pitcher.access_token}`
|
|
2486
|
+
},
|
|
2487
|
+
body: JSON.stringify({
|
|
2488
|
+
query: payload.query,
|
|
2489
|
+
instance_id: instanceId,
|
|
2490
|
+
...Array.isArray(payload.file_ids) && payload.file_ids.length > 0 && { file_ids: payload.file_ids }
|
|
2491
|
+
})
|
|
2492
|
+
});
|
|
2493
|
+
if (!response.ok) {
|
|
2494
|
+
throw new Error(`pia_search ${response.status}`);
|
|
2495
|
+
}
|
|
2496
|
+
const data = await response.json();
|
|
2497
|
+
const output = data?.pia_search ?? {};
|
|
2498
|
+
return {
|
|
2499
|
+
answer: typeof output.answer === "string" ? output.answer : "",
|
|
2500
|
+
cited_file_ids: Array.isArray(output.cited_file_ids) ? output.cited_file_ids : [],
|
|
2501
|
+
...output.confidence && { confidence: output.confidence },
|
|
2502
|
+
source: "online"
|
|
2503
|
+
};
|
|
2504
|
+
} catch (error) {
|
|
2505
|
+
if (error?.name === "AbortError") {
|
|
2506
|
+
throw new Error(`pia_search online request timed out after ${ONLINE_TIMEOUT_MS}ms`);
|
|
2507
|
+
}
|
|
2508
|
+
throw error;
|
|
2509
|
+
} finally {
|
|
2510
|
+
clearTimeout(timer);
|
|
2490
2511
|
}
|
|
2491
|
-
const data = await response.json();
|
|
2492
|
-
const output = data?.pia_search ?? {};
|
|
2493
|
-
return {
|
|
2494
|
-
answer: typeof output.answer === "string" ? output.answer : "",
|
|
2495
|
-
cited_file_ids: Array.isArray(output.cited_file_ids) ? output.cited_file_ids : [],
|
|
2496
|
-
...output.confidence && { confidence: output.confidence },
|
|
2497
|
-
source: "online"
|
|
2498
|
-
};
|
|
2499
2512
|
}
|
|
2500
2513
|
|
|
2501
2514
|
function open$2(payload = {}) {
|