fix: expose AgentRun prompt assembly trace details
This commit is contained in:
@@ -1021,7 +1021,15 @@ function mapAgentRunEvent(event, mapping = {}) {
|
||||
};
|
||||
if (event.type === "backend_status") {
|
||||
const phase = String(payload.phase ?? "status");
|
||||
return { ...base, type: "backend", status: "running", label: `agentrun:backend:${phase}`, message: textPayload(payload, phase), waitingFor: waitingForForPhase(phase) };
|
||||
return {
|
||||
...base,
|
||||
type: "backend",
|
||||
status: "running",
|
||||
label: `agentrun:backend:${phase}`,
|
||||
message: textPayload(payload, phase),
|
||||
waitingFor: waitingForForPhase(phase),
|
||||
details: agentRunBackendStatusDetails(phase, payload)
|
||||
};
|
||||
}
|
||||
if (event.type === "assistant_message") {
|
||||
const terminal = payload.replyAuthority === true || payload.final === true;
|
||||
@@ -1072,6 +1080,56 @@ function mapAgentRunEvent(event, mapping = {}) {
|
||||
return { ...base, type: "backend", status: "running", label: `agentrun:event:${String(event.type ?? "unknown")}`, message: textPayload(payload, "AgentRun event") };
|
||||
}
|
||||
|
||||
function agentRunBackendStatusDetails(phase, payload = {}) {
|
||||
if (phase === "initial-prompt-assembly") {
|
||||
return compactObject({
|
||||
initialPromptInjected: payload.initialPromptInjected === true,
|
||||
reason: firstNonEmpty(payload.reason),
|
||||
initialPrompt: agentRunResourceSummary(payload.initialPrompt),
|
||||
valuesPrinted: false
|
||||
});
|
||||
}
|
||||
if (phase === "resource-bundle-materialized") {
|
||||
return compactObject({
|
||||
kind: firstNonEmpty(payload.kind),
|
||||
commitId: firstNonEmpty(payload.commitId),
|
||||
toolAliases: agentRunResourceSummary(payload.toolAliases),
|
||||
promptRefs: agentRunResourceSummary(payload.promptRefs),
|
||||
skillRefs: agentRunResourceSummary(payload.skillRefs),
|
||||
initialPrompt: agentRunResourceSummary(payload.initialPrompt),
|
||||
valuesPrinted: false
|
||||
});
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function agentRunResourceSummary(value) {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
||||
return compactObject({
|
||||
available: typeof value.available === "boolean" ? value.available : undefined,
|
||||
count: Number.isInteger(value.count) ? value.count : undefined,
|
||||
bytes: Number.isInteger(value.bytes) ? value.bytes : undefined,
|
||||
sha256: firstNonEmpty(value.sha256),
|
||||
promptRefCount: Number.isInteger(value.promptRefCount) ? value.promptRefCount : undefined,
|
||||
skillRefCount: Number.isInteger(value.skillRefCount) ? value.skillRefCount : undefined,
|
||||
names: Array.isArray(value.names) ? value.names.map((item) => firstNonEmpty(item)).filter(Boolean).slice(0, 20) : undefined,
|
||||
requiredMissing: Array.isArray(value.requiredMissing) ? value.requiredMissing.map((item) => firstNonEmpty(item)).filter(Boolean).slice(0, 20) : undefined,
|
||||
valuesPrinted: false
|
||||
});
|
||||
}
|
||||
|
||||
function compactObject(value) {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
||||
const result = {};
|
||||
for (const [key, item] of Object.entries(value)) {
|
||||
if (item === undefined || item === null) continue;
|
||||
if (Array.isArray(item) && item.length === 0) continue;
|
||||
if (typeof item === "object" && !Array.isArray(item) && Object.keys(item).length === 0) continue;
|
||||
result[key] = item;
|
||||
}
|
||||
return Object.keys(result).length > 0 ? result : undefined;
|
||||
}
|
||||
|
||||
function agentRunCommandExecutionEvent(base, payload = {}) {
|
||||
const item = payload.item && typeof payload.item === "object" ? payload.item : null;
|
||||
const payloadToolType = firstNonEmpty(payload.toolName, payload.type, payload.name);
|
||||
|
||||
Reference in New Issue
Block a user