@astranova-live/cli 0.1.4 → 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 +52 -17
- package/package.json +1 -1
package/dist/astra.js
CHANGED
|
@@ -779,7 +779,7 @@ async function apiCall(method, path6, body, agentName, retryOpts) {
|
|
|
779
779
|
const response = await fetch(url, {
|
|
780
780
|
method,
|
|
781
781
|
headers,
|
|
782
|
-
body: body ? JSON.stringify(body) : void 0,
|
|
782
|
+
body: method !== "GET" && body ? JSON.stringify(body) : void 0,
|
|
783
783
|
signal: controller.signal
|
|
784
784
|
});
|
|
785
785
|
clearTimeout(timeoutId);
|
|
@@ -2466,14 +2466,26 @@ var apiCallTool = tool2({
|
|
|
2466
2466
|
};
|
|
2467
2467
|
}
|
|
2468
2468
|
debugLog(`api_call raw: method=${method} path=${path6} body=${JSON.stringify(body)} bodyType=${typeof body} rest=${JSON.stringify(rest)}`);
|
|
2469
|
-
|
|
2470
|
-
|
|
2469
|
+
let resolvedBody = resolveBody(body, rest, method);
|
|
2470
|
+
let resolvedPath = path6;
|
|
2471
|
+
if (method === "GET" && resolvedBody) {
|
|
2472
|
+
const params = new URLSearchParams();
|
|
2473
|
+
for (const [k, v] of Object.entries(resolvedBody)) {
|
|
2474
|
+
if (v !== void 0 && v !== null) params.set(k, String(v));
|
|
2475
|
+
}
|
|
2476
|
+
const qs = params.toString();
|
|
2477
|
+
if (qs) {
|
|
2478
|
+
resolvedPath += (path6.includes("?") ? "&" : "?") + qs;
|
|
2479
|
+
}
|
|
2480
|
+
resolvedBody = void 0;
|
|
2481
|
+
}
|
|
2482
|
+
debugLog(`api_call resolved: ${method} ${resolvedPath} body=${JSON.stringify(resolvedBody)}`);
|
|
2471
2483
|
const agentName = getActiveAgent();
|
|
2472
2484
|
const noRetryPaths = ["/api/v1/trades", "/api/v1/board", "/api/v1/agents/register", "/api/v1/agents/me/rewards/claim"];
|
|
2473
2485
|
const isRetryable = method === "GET" || method === "PUT" || !noRetryPaths.some((p) => path6.startsWith(p));
|
|
2474
2486
|
const retryOpts = isRetryable ? {} : false;
|
|
2475
2487
|
const isClaimPath = method === "POST" && path6.startsWith("/api/v1/agents/me/rewards/claim");
|
|
2476
|
-
const result = await apiCall(method,
|
|
2488
|
+
const result = await apiCall(method, resolvedPath, resolvedBody, agentName ?? void 0, retryOpts);
|
|
2477
2489
|
if (!result.ok) {
|
|
2478
2490
|
if (isClaimPath && result.status === 409 && agentName) {
|
|
2479
2491
|
const cached = loadPendingClaim(agentName);
|
|
@@ -3265,6 +3277,7 @@ function isContextLengthError(error) {
|
|
|
3265
3277
|
|
|
3266
3278
|
// src/agent/loop.ts
|
|
3267
3279
|
var TURN_TIMEOUT_MS = Number(process.env.ASTRA_TIMEOUT) || 18e4;
|
|
3280
|
+
var IDLE_TIMEOUT_MS = 3e4;
|
|
3268
3281
|
var DEBUG3 = !!process.env.ASTRA_DEBUG;
|
|
3269
3282
|
function debugLog3(msg) {
|
|
3270
3283
|
if (DEBUG3) process.stderr.write(`[astra] ${msg}
|
|
@@ -3541,10 +3554,21 @@ async function runSdkTurn(messages, systemPrompt, callbacks) {
|
|
|
3541
3554
|
const model = await getModel();
|
|
3542
3555
|
debugLog3(`Model ready: ${model.modelId ?? "unknown"} \u2014 calling streamText...`);
|
|
3543
3556
|
const abortController = new AbortController();
|
|
3544
|
-
|
|
3545
|
-
|
|
3557
|
+
let idleTimer;
|
|
3558
|
+
let timedOutBy;
|
|
3559
|
+
const overallTimer = setTimeout(() => {
|
|
3560
|
+
debugLog3("SDK turn timeout \u2014 aborting after overall timeout");
|
|
3561
|
+
timedOutBy = "overall";
|
|
3546
3562
|
abortController.abort();
|
|
3547
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
|
+
};
|
|
3548
3572
|
try {
|
|
3549
3573
|
const result = streamText({
|
|
3550
3574
|
model,
|
|
@@ -3555,6 +3579,7 @@ async function runSdkTurn(messages, systemPrompt, callbacks) {
|
|
|
3555
3579
|
temperature: 0.7,
|
|
3556
3580
|
abortSignal: abortController.signal,
|
|
3557
3581
|
onStepFinish: ({ toolCalls, toolResults }) => {
|
|
3582
|
+
resetIdleTimer();
|
|
3558
3583
|
if (toolCalls && toolCalls.length > 0) {
|
|
3559
3584
|
for (let i = 0; i < toolCalls.length; i++) {
|
|
3560
3585
|
const tc = toolCalls[i];
|
|
@@ -3573,28 +3598,38 @@ async function runSdkTurn(messages, systemPrompt, callbacks) {
|
|
|
3573
3598
|
}
|
|
3574
3599
|
}
|
|
3575
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
|
+
});
|
|
3576
3607
|
debugLog3("streamText created \u2014 consuming textStream...");
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
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
|
+
]);
|
|
3580
3618
|
debugLog3("textStream consumed \u2014 awaiting response...");
|
|
3581
|
-
const response = await result.response;
|
|
3582
|
-
const text3 = await result.text;
|
|
3619
|
+
const response = await Promise.race([result.response, abortPromise]);
|
|
3620
|
+
const text3 = await Promise.race([result.text, abortPromise]);
|
|
3583
3621
|
debugLog3(`SDK turn done \u2014 text=${text3.length}chars, messages=${response.messages.length}`);
|
|
3584
3622
|
return {
|
|
3585
3623
|
text: text3 || "(No response from LLM)",
|
|
3586
3624
|
responseMessages: response.messages
|
|
3587
3625
|
};
|
|
3588
3626
|
} catch (error) {
|
|
3589
|
-
clearTimeout(timeout);
|
|
3590
|
-
if (abortController.signal.aborted) {
|
|
3591
|
-
throw new Error(`Response timed out after ${TURN_TIMEOUT_MS / 1e3}s. Please try again.`);
|
|
3592
|
-
}
|
|
3593
3627
|
const message = error instanceof Error ? error.message : String(error);
|
|
3594
|
-
debugLog3(`
|
|
3628
|
+
debugLog3(`SDK turn error: ${message}`);
|
|
3595
3629
|
throw error;
|
|
3596
3630
|
} finally {
|
|
3597
|
-
clearTimeout(
|
|
3631
|
+
clearTimeout(overallTimer);
|
|
3632
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
3598
3633
|
}
|
|
3599
3634
|
}
|
|
3600
3635
|
function convertToCodexInput(messages) {
|