fix: unify code agent turn status authority
This commit is contained in:
@@ -997,7 +997,7 @@ async function agentCommand(context: any) {
|
||||
if (subcommand === "composer") return agentComposer(context);
|
||||
if (subcommand === "result") {
|
||||
const traceId = requiredTraceId(context.rest[1] ?? context.parsed.traceId);
|
||||
const pathName = `/v1/agent/chat/result/${encodeURIComponent(traceId)}`;
|
||||
const pathName = `/v1/agent/turns/${encodeURIComponent(traceId)}`;
|
||||
const response = await requestJson({ ...context, method: "GET", path: pathName });
|
||||
return responsePayload("client.agent.result", response, context, {
|
||||
route: route("GET", pathName),
|
||||
@@ -1009,13 +1009,17 @@ async function agentCommand(context: any) {
|
||||
if (subcommand === "trace") {
|
||||
const traceId = requiredTraceId(context.rest[1] ?? context.parsed.traceId);
|
||||
const pathName = `/v1/agent/chat/trace/${encodeURIComponent(traceId)}`;
|
||||
const turnPath = `/v1/agent/turns/${encodeURIComponent(traceId)}`;
|
||||
const turnResponse = await requestJson({ ...context, method: "GET", path: turnPath });
|
||||
const response = await requestJson({ ...context, method: "GET", path: pathName });
|
||||
const traceBody = traceBodyForCli(response.body, context.parsed);
|
||||
return responsePayload("client.agent.trace", response, context, {
|
||||
route: route("GET", pathName),
|
||||
turnRoute: route("GET", turnPath),
|
||||
traceId,
|
||||
body: traceBody,
|
||||
traceResultSummary: traceResultSummaryForCli(response.body, { traceId, command: "trace", renderedTrace: traceBody }),
|
||||
turnStatus: responseBodyForCli(turnResponse.body, context.parsed),
|
||||
traceResultSummary: traceResultSummaryForCli(turnResponse.body ?? response.body, { traceId, command: "trace", renderedTrace: traceBody }),
|
||||
...traceResponseAliases(traceBody, context.parsed)
|
||||
});
|
||||
}
|
||||
@@ -1526,7 +1530,7 @@ async function sessionFinalResponseCommand(context: any) {
|
||||
};
|
||||
}
|
||||
const traceId = requiredTraceId(resolvedTraceId);
|
||||
const resultPath = `/v1/agent/chat/result/${encodeURIComponent(traceId)}`;
|
||||
const resultPath = `/v1/agent/turns/${encodeURIComponent(traceId)}`;
|
||||
const resultResponse = await requestJson({ ...context, method: "GET", path: resultPath });
|
||||
const validation = finalResponseValidation({
|
||||
conversationId,
|
||||
@@ -2318,14 +2322,14 @@ async function pollAgentResult(context: any, traceId: string, acceptedBody: any)
|
||||
const timeoutMs = numberOption(context.parsed.timeoutMs) ?? DEFAULT_AGENT_TIMEOUT_MS;
|
||||
const pollIntervalMs = numberOption(context.parsed.pollIntervalMs) ?? DEFAULT_POLL_INTERVAL_MS;
|
||||
const startedAt = Date.now();
|
||||
const resultPath = text(acceptedBody?.resultUrl) || `/v1/agent/chat/result/${encodeURIComponent(traceId)}`;
|
||||
const resultPath = text(acceptedBody?.turnUrl) || `/v1/agent/turns/${encodeURIComponent(traceId)}`;
|
||||
let polls = 0;
|
||||
let lastResponse = null;
|
||||
while (Date.now() - startedAt < timeoutMs) {
|
||||
polls += 1;
|
||||
const response = await requestJson({ ...context, method: "GET", path: resultPath, timeoutMs: Math.min(DEFAULT_TIMEOUT_MS, pollIntervalMs + 2000) });
|
||||
lastResponse = response;
|
||||
if (response.status === 200 && response.body?.status && response.body.status !== "running") {
|
||||
if (response.status === 200 && response.body?.terminal === true) {
|
||||
return { final: true, response, polls, timeoutMs, resultPath };
|
||||
}
|
||||
await context.sleep(pollIntervalMs);
|
||||
@@ -2337,7 +2341,7 @@ function agentSendWaitPolicy(traceId: string) {
|
||||
return {
|
||||
defaultWait: false,
|
||||
webEquivalent: true,
|
||||
reason: "Cloud Web submits /v1/agent/chat as a short request and observes progress by polling result/trace; CLI follows the same path by default to avoid UniDesk ssh/tran 60s runtime disconnects.",
|
||||
reason: "Cloud Web submits /v1/agent/chat as a short request and observes progress by polling /v1/agent/turns/:traceId; trace is only used for event details.",
|
||||
waitCommand: `hwlab-cli client agent send --from-trace ${traceId} --message TEXT --wait`,
|
||||
nextCommands: [
|
||||
`hwlab-cli client agent result ${traceId}`,
|
||||
|
||||
Reference in New Issue
Block a user