@adonis-agora/agent 0.82.0 → 0.84.0
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/CHANGELOG.md +23 -0
- package/dist/assets/spa/assets/{index-DMoSumym.js → index-BsGunSCg.js} +2 -2
- package/dist/assets/spa/index.html +1 -1
- package/dist/src/agent-loop.d.ts.map +1 -1
- package/dist/src/agent-loop.js +94 -6
- package/dist/src/agent-loop.js.map +1 -1
- package/dist/src/dead-run.d.ts +1 -0
- package/dist/src/dead-run.d.ts.map +1 -1
- package/dist/src/dead-run.js +7 -1
- package/dist/src/dead-run.js.map +1 -1
- package/dist/src/diagnostics.d.ts +48 -1
- package/dist/src/diagnostics.d.ts.map +1 -1
- package/dist/src/diagnostics.js +6 -0
- package/dist/src/diagnostics.js.map +1 -1
- package/dist/src/durable/agent-run-workflow.d.ts.map +1 -1
- package/dist/src/durable/agent-run-workflow.js +8 -2
- package/dist/src/durable/agent-run-workflow.js.map +1 -1
- package/dist/src/genui-telemetry.d.ts +3 -5
- package/dist/src/genui-telemetry.d.ts.map +1 -1
- package/dist/src/genui-telemetry.js +4 -19
- package/dist/src/genui-telemetry.js.map +1 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/opencode/turns.d.ts.map +1 -1
- package/dist/src/opencode/turns.js +2 -1
- package/dist/src/opencode/turns.js.map +1 -1
- package/dist/src/run-metrics.d.ts +45 -0
- package/dist/src/run-metrics.d.ts.map +1 -0
- package/dist/src/run-metrics.js +46 -0
- package/dist/src/run-metrics.js.map +1 -0
- package/dist/src/runners/inline-agent-runner.d.ts.map +1 -1
- package/dist/src/runners/inline-agent-runner.js +13 -3
- package/dist/src/runners/inline-agent-runner.js.map +1 -1
- package/dist/src/spi/agent-store.d.ts +9 -0
- package/dist/src/spi/agent-store.d.ts.map +1 -1
- package/dist/src/spi/agent-store.js.map +1 -1
- package/dist/src/spi/governance-queries.d.ts +29 -0
- package/dist/src/spi/governance-queries.d.ts.map +1 -1
- package/dist/src/stores/lucid-governance-queries.d.ts +3 -2
- package/dist/src/stores/lucid-governance-queries.d.ts.map +1 -1
- package/dist/src/stores/lucid-governance-queries.js +29 -9
- package/dist/src/stores/lucid-governance-queries.js.map +1 -1
- package/dist/src/stores/lucid-schema.d.ts.map +1 -1
- package/dist/src/stores/lucid-schema.js +8 -0
- package/dist/src/stores/lucid-schema.js.map +1 -1
- package/dist/src/stores/lucid.d.ts.map +1 -1
- package/dist/src/stores/lucid.js +6 -0
- package/dist/src/stores/lucid.js.map +1 -1
- package/dist/src/telescope/agent-governance-providers.d.ts.map +1 -1
- package/dist/src/telescope/agent-governance-providers.js +4 -5
- package/dist/src/telescope/agent-governance-providers.js.map +1 -1
- package/dist/src/telescope/dashboard.d.ts +2 -2
- package/dist/src/telescope/dashboard.d.ts.map +1 -1
- package/dist/src/telescope/dashboard.js +28 -2
- package/dist/src/telescope/dashboard.js.map +1 -1
- package/dist/src/telescope/data-providers.d.ts +18 -3
- package/dist/src/telescope/data-providers.d.ts.map +1 -1
- package/dist/src/telescope/data-providers.js +93 -7
- package/dist/src/telescope/data-providers.js.map +1 -1
- package/dist/src/telescope/extension.d.ts.map +1 -1
- package/dist/src/telescope/extension.js +3 -1
- package/dist/src/telescope/extension.js.map +1 -1
- package/dist/src/telescope/index.d.ts +1 -1
- package/dist/src/telescope/index.d.ts.map +1 -1
- package/dist/src/telescope/index.js +1 -1
- package/dist/src/telescope/index.js.map +1 -1
- package/dist/src/testing/in-memory-governance-queries.d.ts.map +1 -1
- package/dist/src/testing/in-memory-governance-queries.js +23 -7
- package/dist/src/testing/in-memory-governance-queries.js.map +1 -1
- package/dist/src/testing/in-memory-store.d.ts +3 -0
- package/dist/src/testing/in-memory-store.d.ts.map +1 -1
- package/dist/src/testing/in-memory-store.js +6 -0
- package/dist/src/testing/in-memory-store.js.map +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
rel="stylesheet"
|
|
11
11
|
/>
|
|
12
12
|
<title>agent · governance console</title>
|
|
13
|
-
<script type="module" crossorigin src="./assets/index-
|
|
13
|
+
<script type="module" crossorigin src="./assets/index-BsGunSCg.js"></script>
|
|
14
14
|
<link rel="stylesheet" crossorigin href="./assets/index-BxmGk7Ik.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../../src/agent-loop.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,KAAK,kBAAkB,EAAyB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../../src/agent-loop.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,KAAK,kBAAkB,EAAyB,MAAM,8BAA8B,CAAC;AAoB9F,OAAO,EACL,KAAK,WAAW,EAMhB,KAAK,kBAAkB,EACvB,KAAK,UAAU,EAIhB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,YAAY,EAQlB,MAAM,aAAa,CAAC;AACrB,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EAExB,MAAM,yBAAyB,CAAC;AAejC,OAAO,EAOL,KAAK,YAAY,EAGlB,MAAM,aAAa,CAAC;AAKrB,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,0BAA0B,CAAC;AACtF,OAAO,KAAK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H,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAwV/C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,GAAG,EAAE,OAAO,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;CACjB,GAAG,cAAc,EAAE,CAOnB;AAw+CD,+FAA+F;AAC/F,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AA8M1D,qGAAqG;AACrG;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,gBAAgB,CAgBjE;AA6CD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAAkE,CAAC;AAIlG;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAE1E;AAMD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAiBpE;AASD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,CAY5E;AAED,MAAM,WAAW,eAAe,CAAC,OAAO,GAAG,OAAO;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,sGAAsG;IACtG,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,OAAO,GAAG,OAAO,EAClD,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,EACjC,SAAS,EAAE,aAAa,EACxB,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAQnC"}
|
package/dist/src/agent-loop.js
CHANGED
|
@@ -9,7 +9,7 @@ import { prepareActionProposal } from './action-proposal-preparation.js';
|
|
|
9
9
|
import { actionProposalReceipt } from './action-proposal-receipt.js';
|
|
10
10
|
import { danglingToolCallIds, settleDanglingToolCalls } from './dangling-tool-calls.js';
|
|
11
11
|
import { detachedDelivered, detachedStarted, } from './delegation.js';
|
|
12
|
-
import { publishAgentDelegated, publishAgentMessage, publishAgentRetrieved, publishAgentRunFinished, publishAgentRunStarted, publishAgentToolCall, publishAgentToolRetry, spannedAgent, } from './diagnostics.js';
|
|
12
|
+
import { publishAgentDelegated, publishAgentMessage, publishAgentRetrieved, publishAgentRunCancelled, publishAgentRunFailed, publishAgentRunFinished, publishAgentRunStarted, publishAgentToolCall, publishAgentToolRetry, spannedAgent, } from './diagnostics.js';
|
|
13
13
|
import { ASK_TOOL_NAME, askInputSchema, askToolDefinition, DEFAULT_INTAKE_PREAMBLE, isHumanDecision, normalizeElicitationReply, settleElicitation, } from './elicitation.js';
|
|
14
14
|
import { buildMemoryBlock, offerMemories, REMEMBER_TOOL_NAME, rememberInputSchema, rememberToolDefinition, writeMemory, } from './memory.js';
|
|
15
15
|
import { channelChoiceLimits, createNegotiatedUiCollector, withDelivered, } from './negotiated-tool-ui.js';
|
|
@@ -1027,8 +1027,12 @@ async function invokeClaimedTool(turn, claimed, presentationOnly) {
|
|
|
1027
1027
|
// Execution retains every narrowing the offer and preparation had, including an agent-only list.
|
|
1028
1028
|
const allowedTools = intersectAllow(personaOf(turn.input)?.allowedTools, deps.toolAllowList);
|
|
1029
1029
|
const invokeOptions = allowedTools === undefined ? {} : { allowedTools };
|
|
1030
|
+
// Set only when the step's body runs here: a checkpoint read back from the journal has no timing.
|
|
1031
|
+
let ranAt;
|
|
1032
|
+
const timing = () => ranAt === undefined ? { replayed: true } : { durationMs: Date.now() - ranAt };
|
|
1030
1033
|
try {
|
|
1031
1034
|
const raw = await hooks.step(`tool:${call.id}`, async () => {
|
|
1035
|
+
ranAt = Date.now();
|
|
1032
1036
|
// Pushed components stream as they happen and ride this step's RESULT into the journal (see
|
|
1033
1037
|
// `wrapToolStepOutput`), so a replay neither re-streams nor re-persists them.
|
|
1034
1038
|
const ui = createNegotiatedUiCollector(call.id, {
|
|
@@ -1113,7 +1117,7 @@ async function invokeClaimedTool(turn, claimed, presentationOnly) {
|
|
|
1113
1117
|
raw['@@adonis-agent/tool-preflight-denied'] === 1 &&
|
|
1114
1118
|
'reason' in raw &&
|
|
1115
1119
|
typeof raw.reason === 'string') {
|
|
1116
|
-
return { status: 'failed', error: raw.reason, denied: true };
|
|
1120
|
+
return { status: 'failed', error: raw.reason, denied: true, ...timing() };
|
|
1117
1121
|
}
|
|
1118
1122
|
const { output, ui, text } = unwrapToolStepOutput(raw);
|
|
1119
1123
|
if (text)
|
|
@@ -1124,7 +1128,7 @@ async function invokeClaimedTool(turn, claimed, presentationOnly) {
|
|
|
1124
1128
|
if (claimed.terminal === true) {
|
|
1125
1129
|
turn.halt.terminal = true;
|
|
1126
1130
|
}
|
|
1127
|
-
return { status: 'executed', output };
|
|
1131
|
+
return { status: 'executed', output, ...timing() };
|
|
1128
1132
|
}
|
|
1129
1133
|
catch (error) {
|
|
1130
1134
|
if (isReplayIntegrityError(error) || hooks.isControlFlowError?.(error) === true) {
|
|
@@ -1134,9 +1138,24 @@ async function invokeClaimedTool(turn, claimed, presentationOnly) {
|
|
|
1134
1138
|
status: 'failed',
|
|
1135
1139
|
error: error instanceof Error ? error.message : String(error),
|
|
1136
1140
|
...(error instanceof ToolPreflightDeniedError ? { denied: true } : {}),
|
|
1141
|
+
...timing(),
|
|
1137
1142
|
};
|
|
1138
1143
|
}
|
|
1139
1144
|
}
|
|
1145
|
+
/** The timing a settled invocation carries onto its `tool-call` diagnostic. */
|
|
1146
|
+
function toolTiming(outcome) {
|
|
1147
|
+
return {
|
|
1148
|
+
...(outcome.durationMs !== undefined ? { durationMs: outcome.durationMs } : {}),
|
|
1149
|
+
...(outcome.replayed === true ? { replayed: true } : {}),
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* The row's `execution_ms`: measured inside the `tool:<id>` checkpoint, so it is how long the tool ran
|
|
1154
|
+
* rather than how long a replay took to read it back. A replayed checkpoint has none and writes none.
|
|
1155
|
+
*/
|
|
1156
|
+
function executionMs(outcome) {
|
|
1157
|
+
return outcome.durationMs !== undefined ? { executionMs: outcome.durationMs } : {};
|
|
1158
|
+
}
|
|
1140
1159
|
/** Persist one settled invocation and shape the result the model is fed. */
|
|
1141
1160
|
async function recordToolOutcome(turn, claimed, outcome, deciderRef = turn.input.actor.id, meta) {
|
|
1142
1161
|
const { deps, hooks } = turn;
|
|
@@ -1177,11 +1196,19 @@ async function recordToolOutcome(turn, claimed, outcome, deciderRef = turn.input
|
|
|
1177
1196
|
runId: hooks.runId,
|
|
1178
1197
|
status: 'failed',
|
|
1179
1198
|
error: outcome.error,
|
|
1199
|
+
...executionMs(outcome),
|
|
1180
1200
|
...decided,
|
|
1181
1201
|
});
|
|
1182
1202
|
await settle();
|
|
1183
1203
|
});
|
|
1184
|
-
publishAgentToolCall({
|
|
1204
|
+
publishAgentToolCall({
|
|
1205
|
+
runId: hooks.runId,
|
|
1206
|
+
toolCallId: call.id,
|
|
1207
|
+
toolName: call.name,
|
|
1208
|
+
toolType,
|
|
1209
|
+
status: 'failed',
|
|
1210
|
+
...toolTiming(outcome),
|
|
1211
|
+
});
|
|
1185
1212
|
return {
|
|
1186
1213
|
id: call.id,
|
|
1187
1214
|
name: call.name,
|
|
@@ -1197,11 +1224,19 @@ async function recordToolOutcome(turn, claimed, outcome, deciderRef = turn.input
|
|
|
1197
1224
|
status: 'executed',
|
|
1198
1225
|
output: outcome.output,
|
|
1199
1226
|
...(toolType === 'action' ? { executedByRef: deciderRef } : {}),
|
|
1227
|
+
...executionMs(outcome),
|
|
1200
1228
|
...decided,
|
|
1201
1229
|
});
|
|
1202
1230
|
await settle();
|
|
1203
1231
|
});
|
|
1204
|
-
publishAgentToolCall({
|
|
1232
|
+
publishAgentToolCall({
|
|
1233
|
+
runId: hooks.runId,
|
|
1234
|
+
toolCallId: call.id,
|
|
1235
|
+
toolName: call.name,
|
|
1236
|
+
toolType,
|
|
1237
|
+
status: 'executed',
|
|
1238
|
+
...toolTiming(outcome),
|
|
1239
|
+
});
|
|
1205
1240
|
return { id: call.id, name: call.name, output: outcome.output };
|
|
1206
1241
|
}
|
|
1207
1242
|
/**
|
|
@@ -1425,6 +1460,7 @@ async function elicitToolCall(turn, claimed) {
|
|
|
1425
1460
|
}));
|
|
1426
1461
|
publishAgentToolCall({
|
|
1427
1462
|
runId: hooks.runId,
|
|
1463
|
+
toolCallId: call.id,
|
|
1428
1464
|
toolName: call.name,
|
|
1429
1465
|
toolType: 'action',
|
|
1430
1466
|
status: result.skipped ? 'rejected' : 'executed',
|
|
@@ -1647,6 +1683,7 @@ async function runClaimedToolCall(turn, claimed) {
|
|
|
1647
1683
|
});
|
|
1648
1684
|
publishAgentToolCall({
|
|
1649
1685
|
runId: hooks.runId,
|
|
1686
|
+
toolCallId: call.id,
|
|
1650
1687
|
toolName: call.name,
|
|
1651
1688
|
toolType,
|
|
1652
1689
|
status: 'rejected',
|
|
@@ -1696,6 +1733,7 @@ async function expireToolCall(turn, claimed) {
|
|
|
1696
1733
|
});
|
|
1697
1734
|
publishAgentToolCall({
|
|
1698
1735
|
runId: hooks.runId,
|
|
1736
|
+
toolCallId: call.id,
|
|
1699
1737
|
toolName: call.name,
|
|
1700
1738
|
toolType: 'action',
|
|
1701
1739
|
status: 'rejected',
|
|
@@ -2002,6 +2040,48 @@ export function streamErrorFrame(error, runId) {
|
|
|
2002
2040
|
* hooks that make the same loop body either in-process or a replay-safe durable workflow.
|
|
2003
2041
|
*/
|
|
2004
2042
|
export async function runAgentLoop(boundDeps, requested, hooks) {
|
|
2043
|
+
const startedAt = Date.now();
|
|
2044
|
+
try {
|
|
2045
|
+
return await runAgentTurn(boundDeps, requested, hooks);
|
|
2046
|
+
}
|
|
2047
|
+
catch (error) {
|
|
2048
|
+
publishRunEnded(error, requested, hooks, startedAt);
|
|
2049
|
+
throw error;
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
/** Who and what the run is, for its terminal diagnostics. */
|
|
2053
|
+
function runContext(input) {
|
|
2054
|
+
return {
|
|
2055
|
+
...(input.agentName !== undefined ? { agentName: input.agentName } : {}),
|
|
2056
|
+
actorId: input.actor.id,
|
|
2057
|
+
...(input.actor.tenantRef !== undefined && input.actor.tenantRef !== null
|
|
2058
|
+
? { tenantRef: input.actor.tenantRef }
|
|
2059
|
+
: {}),
|
|
2060
|
+
...(input.parentRunId !== undefined ? { parentRunId: input.parentRunId } : {}),
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* `run.failed` / `run.cancelled` for a loop that threw. A durable control-flow signal (suspend on an
|
|
2065
|
+
* approval or a question, continue-as-new) is not an ending — the run goes on — so it publishes
|
|
2066
|
+
* nothing; a run whose abort signal fired was stopped; anything else failed, under the same code the
|
|
2067
|
+
* stream's `error` frame carries.
|
|
2068
|
+
*/
|
|
2069
|
+
function publishRunEnded(error, input, hooks, startedAt) {
|
|
2070
|
+
if (!isReplayIntegrityError(error) && hooks.isControlFlowError?.(error) === true)
|
|
2071
|
+
return;
|
|
2072
|
+
const base = {
|
|
2073
|
+
runId: hooks.runId,
|
|
2074
|
+
threadId: input.threadId,
|
|
2075
|
+
durationMs: Date.now() - startedAt,
|
|
2076
|
+
...runContext(input),
|
|
2077
|
+
};
|
|
2078
|
+
if (hooks.abortSignal?.aborted === true) {
|
|
2079
|
+
publishAgentRunCancelled(base);
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2082
|
+
publishAgentRunFailed({ ...base, code: streamErrorCode(error) });
|
|
2083
|
+
}
|
|
2084
|
+
async function runAgentTurn(boundDeps, requested, hooks) {
|
|
2005
2085
|
// The persona, FIRST and only when the run names one by id: its definition is read from config
|
|
2006
2086
|
// once and frozen in this checkpoint, so a run resumed after the persona was edited or removed
|
|
2007
2087
|
// keeps the prompt and allow-list it started with. A run that names none spends no position here
|
|
@@ -2146,6 +2226,7 @@ export async function runAgentLoop(boundDeps, requested, hooks) {
|
|
|
2146
2226
|
// priced). If NO step had a cost, the run's `cost_usd` stays `null` — never a fabricated `0`.
|
|
2147
2227
|
let totalCost = 0;
|
|
2148
2228
|
let hasCost = false;
|
|
2229
|
+
let lastModelId;
|
|
2149
2230
|
let structured;
|
|
2150
2231
|
publishAgentRunStarted({
|
|
2151
2232
|
runId: hooks.runId,
|
|
@@ -2439,6 +2520,7 @@ export async function runAgentLoop(boundDeps, requested, hooks) {
|
|
|
2439
2520
|
}
|
|
2440
2521
|
// provider-reported model wins over the configured fallback, so cost can't misattribute
|
|
2441
2522
|
const resolvedModelId = turn.modelId ?? deps.modelId ?? 'unknown';
|
|
2523
|
+
lastModelId = resolvedModelId;
|
|
2442
2524
|
// Provider-reported spend wins; else an estimate from the (once-per-run cached) price list; else
|
|
2443
2525
|
// `null` — stamped onto the persisted assistant message's `usage.costUsd` below.
|
|
2444
2526
|
// `resolveModelPrice` e não `priceByModel.get`: o provider responde com o snapshot datado
|
|
@@ -2822,6 +2904,8 @@ export async function runAgentLoop(boundDeps, requested, hooks) {
|
|
|
2822
2904
|
});
|
|
2823
2905
|
});
|
|
2824
2906
|
}
|
|
2907
|
+
// Every text frame of the turn has gone out by now, so its time to first token is known.
|
|
2908
|
+
const firstTextAt = firstText.firstTextAt();
|
|
2825
2909
|
// Settle the run `completed` with its rollup. Normal completion only — the loop never records a
|
|
2826
2910
|
// failure (it doesn't catch its own crash; that's the runner's job). A checkpointed step so a
|
|
2827
2911
|
// resumed durable replay settles the ONE row exactly once, and `recordRunEnd` is first-terminal so
|
|
@@ -2834,9 +2918,10 @@ export async function runAgentLoop(boundDeps, requested, hooks) {
|
|
|
2834
2918
|
inputTokens: totalInput,
|
|
2835
2919
|
outputTokens: totalOutput,
|
|
2836
2920
|
...(hasCost ? { costUsd: totalCost } : {}),
|
|
2921
|
+
...(firstTextAt !== undefined ? { ttftMs: firstTextAt - turnStartedAt } : {}),
|
|
2922
|
+
...(lastModelId !== undefined ? { modelId: lastModelId } : {}),
|
|
2837
2923
|
}));
|
|
2838
2924
|
await writer.end();
|
|
2839
|
-
const firstTextAt = firstText.firstTextAt();
|
|
2840
2925
|
publishAgentRunFinished({
|
|
2841
2926
|
runId: hooks.runId,
|
|
2842
2927
|
threadId: input.threadId,
|
|
@@ -2845,6 +2930,9 @@ export async function runAgentLoop(boundDeps, requested, hooks) {
|
|
|
2845
2930
|
outputTokens: totalOutput,
|
|
2846
2931
|
durationMs: Date.now() - turnStartedAt,
|
|
2847
2932
|
...(firstTextAt !== undefined ? { ttftMs: firstTextAt - turnStartedAt } : {}),
|
|
2933
|
+
...(hasCost ? { costUsd: totalCost } : {}),
|
|
2934
|
+
...(lastModelId !== undefined ? { modelId: lastModelId } : {}),
|
|
2935
|
+
...runContext(input),
|
|
2848
2936
|
});
|
|
2849
2937
|
return { text: lastText, ...(structured !== undefined ? { object: structured } : {}) };
|
|
2850
2938
|
}
|