@astranova-live/cli 0.1.5 → 0.1.6
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/astra.js +36 -13
- package/package.json +1 -1
package/dist/astra.js
CHANGED
|
@@ -3277,6 +3277,7 @@ function isContextLengthError(error) {
|
|
|
3277
3277
|
|
|
3278
3278
|
// src/agent/loop.ts
|
|
3279
3279
|
var TURN_TIMEOUT_MS = Number(process.env.ASTRA_TIMEOUT) || 18e4;
|
|
3280
|
+
var IDLE_TIMEOUT_MS = 3e4;
|
|
3280
3281
|
var DEBUG3 = !!process.env.ASTRA_DEBUG;
|
|
3281
3282
|
function debugLog3(msg) {
|
|
3282
3283
|
if (DEBUG3) process.stderr.write(`[astra] ${msg}
|
|
@@ -3553,10 +3554,21 @@ async function runSdkTurn(messages, systemPrompt, callbacks) {
|
|
|
3553
3554
|
const model = await getModel();
|
|
3554
3555
|
debugLog3(`Model ready: ${model.modelId ?? "unknown"} \u2014 calling streamText...`);
|
|
3555
3556
|
const abortController = new AbortController();
|
|
3556
|
-
|
|
3557
|
-
|
|
3557
|
+
let idleTimer;
|
|
3558
|
+
let timedOutBy;
|
|
3559
|
+
const overallTimer = setTimeout(() => {
|
|
3560
|
+
debugLog3("SDK turn timeout \u2014 aborting after overall timeout");
|
|
3561
|
+
timedOutBy = "overall";
|
|
3558
3562
|
abortController.abort();
|
|
3559
3563
|
}, TURN_TIMEOUT_MS);
|
|
3564
|
+
const resetIdleTimer = () => {
|
|
3565
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
3566
|
+
idleTimer = setTimeout(() => {
|
|
3567
|
+
debugLog3("SDK turn idle timeout \u2014 no data for 30s, aborting");
|
|
3568
|
+
timedOutBy = "idle";
|
|
3569
|
+
abortController.abort();
|
|
3570
|
+
}, IDLE_TIMEOUT_MS);
|
|
3571
|
+
};
|
|
3560
3572
|
try {
|
|
3561
3573
|
const result = streamText({
|
|
3562
3574
|
model,
|
|
@@ -3567,6 +3579,7 @@ async function runSdkTurn(messages, systemPrompt, callbacks) {
|
|
|
3567
3579
|
temperature: 0.7,
|
|
3568
3580
|
abortSignal: abortController.signal,
|
|
3569
3581
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
3582
|
+
resetIdleTimer();
|
|
3570
3583
|
if (toolCalls && toolCalls.length > 0) {
|
|
3571
3584
|
for (let i = 0; i < toolCalls.length; i++) {
|
|
3572
3585
|
const tc = toolCalls[i];
|
|
@@ -3585,28 +3598,38 @@ async function runSdkTurn(messages, systemPrompt, callbacks) {
|
|
|
3585
3598
|
}
|
|
3586
3599
|
}
|
|
3587
3600
|
});
|
|
3601
|
+
const abortPromise = new Promise((_, reject) => {
|
|
3602
|
+
abortController.signal.addEventListener("abort", () => {
|
|
3603
|
+
const label = timedOutBy === "idle" ? `No response for ${IDLE_TIMEOUT_MS / 1e3}s` : `Response timed out after ${TURN_TIMEOUT_MS / 1e3}s`;
|
|
3604
|
+
reject(new Error(`${label}. Please try again.`));
|
|
3605
|
+
});
|
|
3606
|
+
});
|
|
3588
3607
|
debugLog3("streamText created \u2014 consuming textStream...");
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3608
|
+
resetIdleTimer();
|
|
3609
|
+
await Promise.race([
|
|
3610
|
+
(async () => {
|
|
3611
|
+
for await (const chunk of result.textStream) {
|
|
3612
|
+
resetIdleTimer();
|
|
3613
|
+
callbacks.onTextChunk(chunk);
|
|
3614
|
+
}
|
|
3615
|
+
})(),
|
|
3616
|
+
abortPromise
|
|
3617
|
+
]);
|
|
3592
3618
|
debugLog3("textStream consumed \u2014 awaiting response...");
|
|
3593
|
-
const response = await result.response;
|
|
3594
|
-
const text3 = await result.text;
|
|
3619
|
+
const response = await Promise.race([result.response, abortPromise]);
|
|
3620
|
+
const text3 = await Promise.race([result.text, abortPromise]);
|
|
3595
3621
|
debugLog3(`SDK turn done \u2014 text=${text3.length}chars, messages=${response.messages.length}`);
|
|
3596
3622
|
return {
|
|
3597
3623
|
text: text3 || "(No response from LLM)",
|
|
3598
3624
|
responseMessages: response.messages
|
|
3599
3625
|
};
|
|
3600
3626
|
} catch (error) {
|
|
3601
|
-
clearTimeout(timeout);
|
|
3602
|
-
if (abortController.signal.aborted) {
|
|
3603
|
-
throw new Error(`Response timed out after ${TURN_TIMEOUT_MS / 1e3}s. Please try again.`);
|
|
3604
|
-
}
|
|
3605
3627
|
const message = error instanceof Error ? error.message : String(error);
|
|
3606
|
-
debugLog3(`
|
|
3628
|
+
debugLog3(`SDK turn error: ${message}`);
|
|
3607
3629
|
throw error;
|
|
3608
3630
|
} finally {
|
|
3609
|
-
clearTimeout(
|
|
3631
|
+
clearTimeout(overallTimer);
|
|
3632
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
3610
3633
|
}
|
|
3611
3634
|
}
|
|
3612
3635
|
function convertToCodexInput(messages) {
|