Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions extensions/workflows/narrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,38 @@ test("usage() advances as agents settle, so a post-await read sees them", async
assert.deepEqual(readings, { before: 0, afterOne: 1000, afterTwo: 2000 });
});

test("usage() exposes the host's resolved call capacity", async () => {
const result = await runSandbox(
`
const capacity = usage().limits;
try { capacity.callsRemaining = 999; } catch { /* frozen */ }
return {
concurrency: capacity.concurrency,
maxAgentCalls: capacity.maxAgentCalls,
callsUsed: capacity.callsUsed,
callsRemaining: capacity.callsRemaining,
};
`,
{
usageSnapshot: () => ({
total: 1_000,
limits: {
concurrency: 8,
maxAgentCalls: 128,
callsUsed: 1,
callsRemaining: 127,
},
}),
},
);
assert.deepEqual(result, {
concurrency: 8,
maxAgentCalls: 128,
callsUsed: 1,
callsRemaining: 127,
});
});

test("usage() degrades to a zero reading rather than failing the run", async () => {
const result = await runSandbox(`return usage().total;`, {
usageSnapshot: () => {
Expand Down
11 changes: 11 additions & 0 deletions extensions/workflows/sandbox-child.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ const BOOTSTRAP = String.raw`
const value = raw && typeof raw === "object" ? raw[key] : undefined;
return typeof value === "number" && Number.isFinite(value) ? value : 0;
};
const readLimit = (key) => {
const limits = raw && typeof raw === "object" ? raw.limits : undefined;
const value = limits && typeof limits === "object" ? limits[key] : undefined;
return typeof value === "number" && Number.isFinite(value) ? value : 0;
};
// Every field is coerced, so a missing or malformed snapshot reads as zero
// rather than undefined: a script doing arithmetic on it gets 0, not NaN.
return deepFreeze({
Expand All @@ -217,6 +222,12 @@ const BOOTSTRAP = String.raw`
total: read("total"),
cost: read("cost"),
agents: read("agents"),
limits: {
concurrency: readLimit("concurrency"),
maxAgentCalls: readLimit("maxAgentCalls"),
callsUsed: readLimit("callsUsed"),
callsRemaining: readLimit("callsRemaining"),
},
});
}

Expand Down
Loading