@tablation/crew 0.133.2 → 0.134.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/dist/cli.js +101 -13
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -10483,6 +10483,69 @@ async function post(target, path, body) {
|
|
|
10483
10483
|
if (!res.ok) throw new AgentLogHttpError(`${path}: ${res.status} ${res.statusText}`, res.status);
|
|
10484
10484
|
return await res.json();
|
|
10485
10485
|
}
|
|
10486
|
+
var RUNNING_OUTCOME = "running";
|
|
10487
|
+
async function startAgentRunRow(target, s) {
|
|
10488
|
+
try {
|
|
10489
|
+
const entry = await post(target, "/agents/log", {
|
|
10490
|
+
agentId: target.agentId,
|
|
10491
|
+
ticketReference: s.ticketReference,
|
|
10492
|
+
outcome: RUNNING_OUTCOME,
|
|
10493
|
+
startedAt: s.startedAt,
|
|
10494
|
+
source: "client",
|
|
10495
|
+
client: "crew",
|
|
10496
|
+
model: s.model,
|
|
10497
|
+
promptVersion: s.promptVersion,
|
|
10498
|
+
promptSha: s.promptSha,
|
|
10499
|
+
runId: s.runId,
|
|
10500
|
+
harness: s.harness,
|
|
10501
|
+
provider: s.provider
|
|
10502
|
+
});
|
|
10503
|
+
return entry.id;
|
|
10504
|
+
} catch {
|
|
10505
|
+
return void 0;
|
|
10506
|
+
}
|
|
10507
|
+
}
|
|
10508
|
+
function finishedRowBody(run4, workItem) {
|
|
10509
|
+
const values = {
|
|
10510
|
+
ticket_reference: run4.ticketReference,
|
|
10511
|
+
outcome: run4.outcome,
|
|
10512
|
+
finished_at: run4.finishedAt,
|
|
10513
|
+
model: run4.model,
|
|
10514
|
+
input_tokens: run4.tokensIn,
|
|
10515
|
+
output_tokens: run4.tokensOut,
|
|
10516
|
+
cache_read_tokens: run4.cacheReadTokens,
|
|
10517
|
+
cache_write_tokens: run4.cacheWriteTokens,
|
|
10518
|
+
cost_usd: run4.costUsd,
|
|
10519
|
+
num_turns: run4.numTurns,
|
|
10520
|
+
prefix_tokens: run4.prefixTokens,
|
|
10521
|
+
prompt_version: run4.promptVersion,
|
|
10522
|
+
prompt_sha: run4.promptSha,
|
|
10523
|
+
harness: run4.harness,
|
|
10524
|
+
provider: run4.provider,
|
|
10525
|
+
work_item_table: workItem.workItemTable,
|
|
10526
|
+
work_item_record_id: workItem.workItemRecordId
|
|
10527
|
+
};
|
|
10528
|
+
return Object.fromEntries(Object.entries(values).filter(([, v]) => v !== void 0));
|
|
10529
|
+
}
|
|
10530
|
+
async function updateStartedRow(target, rowId, body) {
|
|
10531
|
+
try {
|
|
10532
|
+
const model = await request(
|
|
10533
|
+
target,
|
|
10534
|
+
"GET",
|
|
10535
|
+
`/data-models/agent_log?workspaceId=${encodeURIComponent(target.workspaceId)}`
|
|
10536
|
+
);
|
|
10537
|
+
const have = await columnsOf(target, model.id);
|
|
10538
|
+
const values = Object.fromEntries(Object.entries(body).filter(([column]) => have.has(column)));
|
|
10539
|
+
await request(target, "PATCH", `/data-models/${model.id}/records/${rowId}`, values);
|
|
10540
|
+
return true;
|
|
10541
|
+
} catch (e) {
|
|
10542
|
+
if (!(e instanceof AgentLogHttpError)) throw new AgentLogUnreachableError(e.message);
|
|
10543
|
+
if (e.status === 404) return false;
|
|
10544
|
+
if (e.status >= 500) throw new AgentLogUnreachableError(e.message);
|
|
10545
|
+
e.row = true;
|
|
10546
|
+
throw e;
|
|
10547
|
+
}
|
|
10548
|
+
}
|
|
10486
10549
|
async function reportAgentRun(target, run4) {
|
|
10487
10550
|
let ticketRecordId;
|
|
10488
10551
|
if (target.tickets && run4.ticketReference) {
|
|
@@ -10513,20 +10576,23 @@ async function reportAgentRun(target, run4) {
|
|
|
10513
10576
|
const { runId, ...legacyBody } = { ...body, runId: run4.runId };
|
|
10514
10577
|
const workItem = target.tickets && ticketRecordId ? { workItemTable: target.tickets.issuesModelId, workItemRecordId: ticketRecordId } : {};
|
|
10515
10578
|
let entry;
|
|
10516
|
-
|
|
10517
|
-
|
|
10518
|
-
} catch (e) {
|
|
10519
|
-
if (!(e instanceof AgentLogHttpError)) throw new AgentLogUnreachableError(e.message);
|
|
10520
|
-
if (e.status >= 500) throw new AgentLogUnreachableError(e.message);
|
|
10521
|
-
if (e.status !== 400 || !run4.harness && !run4.provider && !ticketRecordId && !runId) {
|
|
10522
|
-
e.row = true;
|
|
10523
|
-
throw e;
|
|
10524
|
-
}
|
|
10579
|
+
if (run4.rowId && await updateStartedRow(target, run4.rowId, finishedRowBody(run4, workItem))) entry = { id: run4.rowId };
|
|
10580
|
+
if (!entry) {
|
|
10525
10581
|
try {
|
|
10526
|
-
entry = await post(target, "/agents/log",
|
|
10527
|
-
} catch (
|
|
10528
|
-
if (
|
|
10529
|
-
throw
|
|
10582
|
+
entry = await post(target, "/agents/log", { ...body, ...runId ? { runId } : {}, ...workItem, harness: run4.harness, provider: run4.provider });
|
|
10583
|
+
} catch (e) {
|
|
10584
|
+
if (!(e instanceof AgentLogHttpError)) throw new AgentLogUnreachableError(e.message);
|
|
10585
|
+
if (e.status >= 500) throw new AgentLogUnreachableError(e.message);
|
|
10586
|
+
if (e.status !== 400 || !run4.harness && !run4.provider && !ticketRecordId && !runId) {
|
|
10587
|
+
e.row = true;
|
|
10588
|
+
throw e;
|
|
10589
|
+
}
|
|
10590
|
+
try {
|
|
10591
|
+
entry = await post(target, "/agents/log", legacyBody);
|
|
10592
|
+
} catch (e2) {
|
|
10593
|
+
if (e2 instanceof AgentLogHttpError && e2.status < 500) e2.row = true;
|
|
10594
|
+
throw e2;
|
|
10595
|
+
}
|
|
10530
10596
|
}
|
|
10531
10597
|
}
|
|
10532
10598
|
for (const cycle of run4.cycles) {
|
|
@@ -12986,6 +13052,7 @@ async function finishRun(id, obs, emit, startedAt, end, agentLogKey, hintMoved)
|
|
|
12986
13052
|
model: id.model,
|
|
12987
13053
|
// CREW-2980: under `auth: workspace` the endpoint's rows are the accounting; the run row
|
|
12988
13054
|
// keeps turns only, and `reportAgentRun` sums those rows into the ticket counters.
|
|
13055
|
+
...id.agentLogRowId ? { rowId: id.agentLogRowId } : {},
|
|
12989
13056
|
...id.workspaceRunId ? { runId: id.workspaceRunId } : {
|
|
12990
13057
|
tokensIn: result?.inputTokens,
|
|
12991
13058
|
tokensOut: result?.outputTokens,
|
|
@@ -13134,6 +13201,26 @@ function spawnAgent(plan, emit, hintMoved) {
|
|
|
13134
13201
|
} catch {
|
|
13135
13202
|
}
|
|
13136
13203
|
}
|
|
13204
|
+
const startedRow = plan.workspaceRunId && plan.agentLog ? startAgentRunRow(plan.agentLog, {
|
|
13205
|
+
runId: plan.workspaceRunId,
|
|
13206
|
+
ticketReference: plan.ticket ?? void 0,
|
|
13207
|
+
startedAt,
|
|
13208
|
+
model: plan.model,
|
|
13209
|
+
harness: id.harness,
|
|
13210
|
+
provider: id.provider,
|
|
13211
|
+
promptVersion: plan.promptVersion,
|
|
13212
|
+
promptSha: plan.promptSha
|
|
13213
|
+
}).then((rowId) => {
|
|
13214
|
+
if (!rowId) return;
|
|
13215
|
+
id.agentLogRowId = rowId;
|
|
13216
|
+
const sc = readRunSidecar(plan.streamPath);
|
|
13217
|
+
if (sc) {
|
|
13218
|
+
try {
|
|
13219
|
+
writeFileSync20(pidPathFor(plan.streamPath), JSON.stringify({ ...sc, agentLogRowId: rowId }));
|
|
13220
|
+
} catch {
|
|
13221
|
+
}
|
|
13222
|
+
}
|
|
13223
|
+
}) : Promise.resolve();
|
|
13137
13224
|
const obs = new RunObserver(id, adapter, eventsSink, emit.cycle);
|
|
13138
13225
|
const meta = { pid: child.pid ?? null, ...deadline ? { deadline } : {} };
|
|
13139
13226
|
obs.onClaim = () => writeRunMeta(id, startedAt, obs.liveTicket, meta);
|
|
@@ -13165,6 +13252,7 @@ function spawnAgent(plan, emit, hintMoved) {
|
|
|
13165
13252
|
if (limitTimer && !killed && !obs.sawResult && msUntilDeadline(deadline) <= 0) {
|
|
13166
13253
|
killed = { limitMinutes: plan.maxRunMinutes ?? 0, elapsedMs: Date.now() - Date.parse(spawnedAt) };
|
|
13167
13254
|
}
|
|
13255
|
+
await startedRow;
|
|
13168
13256
|
const { ms: ms3, handoffPending } = await finishRun(
|
|
13169
13257
|
id,
|
|
13170
13258
|
obs,
|
package/package.json
CHANGED