@ouispec/agent-worker 0.10.1 → 0.11.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.
Files changed (43) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/orchestrator.d.ts.map +1 -1
  4. package/dist/orchestrator.js +107 -67
  5. package/dist/orchestrator.js.map +1 -1
  6. package/dist/prompt/clock.d.ts +17 -7
  7. package/dist/prompt/clock.d.ts.map +1 -1
  8. package/dist/prompt/clock.js +4 -16
  9. package/dist/prompt/clock.js.map +1 -1
  10. package/dist/prompt/rules/base.d.ts.map +1 -1
  11. package/dist/prompt/rules/base.js +1 -0
  12. package/dist/prompt/rules/base.js.map +1 -1
  13. package/dist/prompt/rules/ui-control.js +1 -1
  14. package/dist/prompt/spoken-input.d.ts +6 -12
  15. package/dist/prompt/spoken-input.d.ts.map +1 -1
  16. package/dist/prompt/spoken-input.js +7 -19
  17. package/dist/prompt/spoken-input.js.map +1 -1
  18. package/dist/runtime/turn-runner.d.ts.map +1 -1
  19. package/dist/runtime/turn-runner.js +2 -1
  20. package/dist/runtime/turn-runner.js.map +1 -1
  21. package/dist/runtime/types.d.ts +12 -1
  22. package/dist/runtime/types.d.ts.map +1 -1
  23. package/dist/step-messages.d.ts +23 -0
  24. package/dist/step-messages.d.ts.map +1 -0
  25. package/dist/step-messages.js +51 -0
  26. package/dist/step-messages.js.map +1 -0
  27. package/dist/stop/partial.d.ts.map +1 -1
  28. package/dist/stop/partial.js +2 -1
  29. package/dist/stop/partial.js.map +1 -1
  30. package/dist/types.d.ts +7 -0
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/ui/page-state-at-end.d.ts +40 -0
  33. package/dist/ui/page-state-at-end.d.ts.map +1 -0
  34. package/dist/ui/{newest-page-state.js → page-state-at-end.js} +30 -31
  35. package/dist/ui/page-state-at-end.js.map +1 -0
  36. package/package.json +2 -2
  37. package/dist/prompt/user-text.d.ts +0 -19
  38. package/dist/prompt/user-text.d.ts.map +0 -1
  39. package/dist/prompt/user-text.js +0 -20
  40. package/dist/prompt/user-text.js.map +0 -1
  41. package/dist/ui/newest-page-state.d.ts +0 -25
  42. package/dist/ui/newest-page-state.d.ts.map +0 -1
  43. package/dist/ui/newest-page-state.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -62,7 +62,7 @@ export type { HttpEmitAdapterConfig } from './emit/http-adapter.js';
62
62
  export { createAgentTurnRunner, categorizeError, payloadRefusal, TURN_DEADLINE_EXCEEDED } from './runtime/turn-runner.js';
63
63
  export type { AgentTurnRunner, TurnOutcome, CategorizedError } from './runtime/turn-runner.js';
64
64
  export { assertAgentRuntimeConfig } from './runtime/config.js';
65
- export type { AgentRuntimeConfig, LambdaAgentConfig, AgentTurnPayload, HistoryRequest } from './runtime/types.js';
65
+ export type { AgentRuntimeConfig, LambdaAgentConfig, AgentTurnPayload, HistoryRequest, TurnHistory } from './runtime/types.js';
66
66
  export { createLambdaAgentHandler } from './lambda/handler.js';
67
67
  export { startContainerAgentWorker } from './container/server.js';
68
68
  export type { ContainerAgentConfig, ContainerAgentWorker } from './container/server.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACxJ,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAChH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,gBAAgB,EAAE,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sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAmC,MAAM,YAAY,CAAC;AAqGtH;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC,eAAe,CAAC,CAu1D1B"}
@@ -28,10 +28,10 @@ import { evaluateToolPolicySafe } from './authz/tool-policy.js';
28
28
  import { createToolInputValidator } from './tools/input-validation.js';
29
29
  import { readClientPage, withoutClientUI } from './ui/snapshot.js';
30
30
  import { KNOWLEDGE_TOOL, knowledgeTool, readClientKnowledge, withClientKnowledge } from './ui/knowledge.js';
31
- import { withNewestPageStateOnly } from './ui/newest-page-state.js';
32
- import { withClock } from './prompt/clock.js';
33
- import { withSpokenInput } from './prompt/spoken-input.js';
34
- import { withUserText } from './prompt/user-text.js';
31
+ import { answerWithoutState, withStatesAtEnd } from './ui/page-state-at-end.js';
32
+ import { stepMessages as forStep, STEP_NOTE_CLOSE, STEP_NOTE_OPEN } from './step-messages.js';
33
+ import { clockText, readClientTimeZone } from './prompt/clock.js';
34
+ import { readClientMessageInput, spokenInputText } from './prompt/spoken-input.js';
35
35
  import { AttachmentGuard } from './attachments/guard.js';
36
36
  import { ATTACHMENT_DATA_NOTE, turnAttachmentParts, withReferenceLines, withTurnAttachments, withoutLeftOut } from './attachments/content.js';
37
37
  import { attachmentTools } from './attachments/tools.js';
@@ -139,8 +139,8 @@ export async function runAgentTurn(config, input) {
139
139
  // Whether the page can be seen (ADR-0245 §2.5): nothing that changes it runs while it cannot.
140
140
  const sight = createPageSight();
141
141
  const uiCounts = { describes: 0, reads: 0, acts: 0, guides: 0 };
142
- // Earlier answers' page states replaced, summed over the turn's steps.
143
- let pageStatesNotRepeated = 0;
142
+ // Answers whose page state was moved to the end of what the model reads, summed over the turn's steps.
143
+ let pageStatesMoved = 0;
144
144
  // The knowledge the client sent for its page goes after the host's prompt.
145
145
  const knowledge = readClientKnowledge(input.context ?? null);
146
146
  // ─── Files (ADR-0252 §2.11, §2.12) ─────────────────────────────────────────
@@ -1093,11 +1093,18 @@ export async function runAgentTurn(config, input) {
1093
1093
  // The system prompt has to travel as a message rather than the top-level
1094
1094
  // `system` field, because only a message carries `providerOptions`.
1095
1095
  //
1096
- // Two breakpoints, both on content that is append-only:
1096
+ // Three breakpoints, each on content that is append-only:
1097
1097
  // 1. system (+ tools) — identical for every round of a segment, and for
1098
1098
  // every turn on the same page.
1099
1099
  // 2. the end of the incoming history — stable across the rounds that follow
1100
1100
  // it, since a round appends rather than rewrites.
1101
+ // 3. the end of the conversation as each step sends it, moved forward every
1102
+ // step, so the next step reads this one's calls and answers from the
1103
+ // cache. With only the first two, everything after the user's message
1104
+ // went uncached at every step: on dev a turn's UI answers (up to tens of
1105
+ // thousands of tokens each) were paid in full again on every later step.
1106
+ // What a step alone is told (its notes) goes after the third, so it never
1107
+ // changes a prefix (step-messages.ts).
1101
1108
  //
1102
1109
  // Caching is a PREFIX match: one byte earlier in the prefix invalidates
1103
1110
  // everything after it. Nothing volatile may move ahead of these points — no
@@ -1186,27 +1193,25 @@ export async function runAgentTurn(config, input) {
1186
1193
  const stoppedBeforeModel = stopOf(abortController.signal);
1187
1194
  if (stoppedBeforeModel)
1188
1195
  return await finishStopped(stoppedBeforeModel, { expired, continued });
1189
- // Convert history to AI SDK CoreMessage format. The page the user is on
1190
- // travels with their message, not in the system prompt: it changes on every
1191
- // page, and in the system prompt it would invalidate the cached prefix. An
1192
- // approved call that ran is the result of the call the model made (see
1196
+ // Convert history to AI SDK CoreMessage format. Everything before the end
1197
+ // of the conversation is sent exactly as it was sent before, so the prompt
1198
+ // cache reads it (step-messages.ts). What is true only now — the page's
1199
+ // index and values, the user's clock, a note on calls whose approval
1200
+ // expired, the host's step context — is not added to the user's message,
1201
+ // where the next turn would send that message without it and write the
1202
+ // conversation from there to the cache again: the index goes after the
1203
+ // system prompt, the rest after the conversation (`stepTail`). An approved
1204
+ // call that ran is the result of the call the model made (see
1193
1205
  // continueApproval).
1194
- // The date and time on the user's clock travel with their message too: a
1195
- // model has no clock, and the changing minute must stay out of the cached
1196
- // system prompt (prompt/clock.ts).
1197
- // A message the person spoke says so straight after their words: it may hold a mis-heard word
1198
- // (prompt/spoken-input.ts). A click on an approval card is not a message, so it says nothing.
1199
1206
  const turnFilesGiven = !!fileArea && (input.attachments?.length ?? 0) > 0;
1200
1207
  const messages = [
1201
- ...withClock(withPageState(withNote(withSpokenInput(convertHistoryToCoreMessages(
1208
+ ...convertHistoryToCoreMessages(
1202
1209
  // An approved call's outcome, and an expired one's, is a later result of the call already in the
1203
1210
  // history: it takes that call's place.
1204
1211
  [...(input.history ?? []), ...expired.outcomes, ...(continued?.outcome ? [continued.outcome] : [])], [input.content, continued?.note].filter(Boolean).join('\n\n'),
1205
1212
  // The turn's own message, when the history already holds it: its files are given below,
1206
1213
  // each with its line, so the history's copy of the message does not name them again.
1207
- turnFilesGiven && input.history?.at(-1)?.role === 'user' ? input.history.length - 1 : null), input.approval ? null : (input.context ?? null)),
1208
- // Said on the user's message whether or not the host's history already holds that message.
1209
- expired.outcomes.length > 0 ? expiredNote(expired) : null), client, config.ui?.maxObservationChars ?? DEFAULT_PAGE_STATE_CHARS, config.ui?.maxIndexChars ?? DEFAULT_INDEX_CHARS), input.context ?? null),
1214
+ turnFilesGiven && input.history?.at(-1)?.role === 'user' ? input.history.length - 1 : null),
1210
1215
  ...(continued?.messages ?? []),
1211
1216
  ];
1212
1217
  // The turn's files go with its message, after everything said about it (ADR-0252 §2.11).
@@ -1248,11 +1253,69 @@ export async function runAgentTurn(config, input) {
1248
1253
  // `instructions` takes `string | SystemModelMessage | SystemModelMessage[]`,
1249
1254
  // and the message form carries `providerOptions`, so the breakpoint travels
1250
1255
  // with it. (`system` is the deprecated alias for the same type.)
1251
- const instructions = {
1256
+ const systemMessage = {
1252
1257
  role: 'system',
1253
1258
  content: systemPrompt,
1254
1259
  ...(cachePoint ? { providerOptions: cachePoint } : {}),
1255
1260
  };
1261
+ // What the page offers, after the system prompt with a breakpoint of its own:
1262
+ // it is the same for every step and every turn on the same page, so it is
1263
+ // read from the cache, and when the page changes only it and what follows are
1264
+ // written again. A change during the turn reaches the model in the answer
1265
+ // that made it (ui-tools.ts `forModel`).
1266
+ const pageIndex = client && client.page.length > 0
1267
+ ? {
1268
+ role: 'system',
1269
+ content: [
1270
+ '<page_index>',
1271
+ `The user's screen offers these surfaces and actions. Run an action with ${UI_ACT_TOOL}; ${UI_DESCRIBE_TOOL} says what one takes.`,
1272
+ indexText(client.page, config.ui?.maxIndexChars ?? DEFAULT_INDEX_CHARS),
1273
+ '</page_index>',
1274
+ ].join('\n'),
1275
+ ...(cachePoint ? { providerOptions: cachePoint } : {}),
1276
+ }
1277
+ : null;
1278
+ const instructions = pageIndex ? [systemMessage, pageIndex] : systemMessage;
1279
+ // ─── What is true now, after the conversation (step-messages.ts) ───────────
1280
+ // The turn's own message: answers after it are this turn's, and only those
1281
+ // are newer than the page the turn began on.
1282
+ const turnMessageAt = messages.map((m) => m.role).lastIndexOf('user');
1283
+ const turnClock = clockText(new Date(), readClientTimeZone(input.context ?? null));
1284
+ const turnSpoken = input.approval ? null : readClientMessageInput(input.context ?? null);
1285
+ const turnPageValues = client && client.page.length > 0
1286
+ ? [
1287
+ observationsText(client.observations, config.ui?.maxObservationChars ?? DEFAULT_PAGE_STATE_CHARS, {
1288
+ schemas: observationSchemas(client.page),
1289
+ }),
1290
+ client.fit?.observations?.length ? `Not shown: ${fitNotes(client.fit.observations).join(' ')}` : null,
1291
+ ]
1292
+ : null;
1293
+ /** The page's state from this turn's newest answer that carried one; until then, as the user's screen sent it. */
1294
+ let newestAnswerState;
1295
+ const stepTail = (notes) => [
1296
+ ...(turnPageValues
1297
+ ? [
1298
+ [
1299
+ '<page_state>',
1300
+ sight.blind()
1301
+ ? `Not current: an answer came without the page's state (${sight.blind()}). These values are from before it, so read the page before you change anything.`
1302
+ : newestAnswerState !== undefined
1303
+ ? 'The page as it is now, from the newest answer that carried its state.'
1304
+ : 'The page as it was when the user sent their message.',
1305
+ `Current values: ${newestAnswerState !== undefined ? JSON.stringify(newestAnswerState) : turnPageValues[0]}`,
1306
+ ...(newestAnswerState === undefined && turnPageValues[1] ? [turnPageValues[1]] : []),
1307
+ '</page_state>',
1308
+ ].join('\n'),
1309
+ ]
1310
+ : []),
1311
+ turnClock,
1312
+ // A message the person spoke may hold a mis-heard word (prompt/spoken-input.ts). A click on an
1313
+ // approval card is not a message, so it says nothing.
1314
+ ...(turnSpoken ? [spokenInputText(turnSpoken)] : []),
1315
+ ...(expired.outcomes.length > 0 ? [expiredNote(expired)] : []),
1316
+ ...(input.stepContext?.trim() ? [input.stepContext.trim()] : []),
1317
+ ...(notes.length > 0 ? [[STEP_NOTE_OPEN, ...notes, STEP_NOTE_CLOSE].join('\n')] : []),
1318
+ ];
1256
1319
  const withCachePoint = (msgs) => !cachePoint ? msgs : [
1257
1320
  ...msgs.slice(0, -1),
1258
1321
  ...msgs.slice(-1).map((m) => ({
@@ -1340,15 +1403,20 @@ export async function runAgentTurn(config, input) {
1340
1403
  }
1341
1404
  : {}),
1342
1405
  };
1343
- // The policy's note goes after the system prompt, for this step only.
1344
- // ai carries an instructions override forward to later steps, so a step
1345
- // without a note sets the plain instructions back.
1346
- // So does the turn's record, once a call has not succeeded.
1406
+ // The policy's note, the forced action and the turn's record (once a call
1407
+ // has not succeeded) are for this step only. They go at the end of what
1408
+ // the model reads, after the moving cache breakpoint, never in the system
1409
+ // prompt: a note there changed the prefix of the whole conversation, so
1410
+ // the step that carried one, and the step after it, wrote the conversation
1411
+ // to the cache again instead of reading it.
1347
1412
  const notes = [note, forced ? `This step: call ${UI_ACT_TOOL} with action "${forced}".` : null, ledger.note(), outputLimitNote].filter((n) => !!n);
1348
- // The page's state on the newest answer only: an earlier page is not the page now.
1349
- const trimmed = messages ? withNewestPageStateOnly(messages) : null;
1350
- if (trimmed)
1351
- pageStatesNotRepeated += trimmed.replaced;
1413
+ // Every answer gives its page state up the same way; the newest of this turn's is read at the end.
1414
+ const trimmed = messages ? withStatesAtEnd(messages, turnMessageAt) : null;
1415
+ if (trimmed) {
1416
+ pageStatesMoved += trimmed.moved;
1417
+ if (trimmed.newest !== undefined)
1418
+ newestAnswerState = trimmed.newest;
1419
+ }
1352
1420
  // The files this step would carry, within the turn's and the conversation's caps (ADR-0252 §2.11).
1353
1421
  const leftOutNow = fileGuard.beforeStep();
1354
1422
  if (leftOutNow.length > 0) {
@@ -1358,13 +1426,11 @@ export async function runAgentTurn(config, input) {
1358
1426
  });
1359
1427
  }
1360
1428
  const leftOut = fileGuard.leftOutParts();
1361
- const stepMessages = leftOut.length > 0 && messages ? withoutLeftOut(trimmed?.messages ?? messages, leftOut) : trimmed?.messages;
1429
+ const stepMessages = leftOut.length > 0 && messages ? withoutLeftOut(trimmed?.messages ?? messages, leftOut) : trimmed?.messages ?? messages;
1362
1430
  return {
1363
1431
  ...constraints,
1364
- ...(stepMessages ? { messages: stepMessages } : {}),
1365
- instructions: notes.length
1366
- ? [instructions, ...notes.map((content) => ({ role: 'system', content }))]
1367
- : instructions,
1432
+ ...(stepMessages ? { messages: forStep(stepMessages, stepTail(notes), cachePoint) } : {}),
1433
+ instructions,
1368
1434
  };
1369
1435
  },
1370
1436
  onStepEnd: async ({ text, toolCalls, usage: stepUsage, finishReason }) => {
@@ -1388,6 +1454,10 @@ export async function runAgentTurn(config, input) {
1388
1454
  totalTextEmitted,
1389
1455
  finishReason,
1390
1456
  outputTokens: stepUsage?.outputTokens ?? 0,
1457
+ // How this step's input was billed: read from the cache, written to it, or neither.
1458
+ inputTokens: stepUsage?.inputTokens ?? 0,
1459
+ cacheReadTokens: stepUsage?.inputTokenDetails?.cacheReadTokens ?? 0,
1460
+ cacheWriteTokens: stepUsage?.inputTokenDetails?.cacheWriteTokens ?? 0,
1391
1461
  });
1392
1462
  },
1393
1463
  });
@@ -1546,7 +1616,7 @@ export async function runAgentTurn(config, input) {
1546
1616
  // What bounds the model: the page's index as it reads it, against the most it is given
1547
1617
  // before the furthest surfaces are listed by id only.
1548
1618
  indexChars: indexText(client.page, Infinity).length,
1549
- pageStatesNotRepeated,
1619
+ pageStatesMoved,
1550
1620
  maxIndexChars: config.ui?.maxIndexChars ?? DEFAULT_INDEX_CHARS,
1551
1621
  },
1552
1622
  }
@@ -1762,37 +1832,6 @@ export async function runAgentTurn(config, input) {
1762
1832
  };
1763
1833
  }
1764
1834
  }
1765
- /** Put a note for the model on the turn's user message, after what the user said. */
1766
- function withNote(messages, note) {
1767
- const last = messages[messages.length - 1];
1768
- if (!note || !last || last.role !== 'user')
1769
- return messages;
1770
- return [...messages.slice(0, -1), withUserText(last, note)];
1771
- }
1772
- /**
1773
- * Put the client's page on the user's message: what it offers, as an index of
1774
- * its actions, and its latest observations. The model reads it as part of what
1775
- * the user said, where it is true for this message only. The index has its own
1776
- * budget, so it never crowds the page's state out (ADR-0245 §2.2).
1777
- */
1778
- function withPageState(messages, client, maxChars, maxIndexChars) {
1779
- if (!client || client.page.length === 0)
1780
- return messages;
1781
- const last = messages[messages.length - 1];
1782
- if (!last || last.role !== 'user')
1783
- return messages;
1784
- const observations = observationsText(client.observations, maxChars, { schemas: observationSchemas(client.page) });
1785
- const notShown = client.fit?.observations?.length ? fitNotes(client.fit.observations) : [];
1786
- const pageState = [
1787
- '<page_state>',
1788
- `The user's screen offers these surfaces and actions. Run an action with ${UI_ACT_TOOL}; ${UI_DESCRIBE_TOOL} says what one takes.`,
1789
- indexText(client.page, maxIndexChars),
1790
- `Current values: ${observations}`,
1791
- ...(notShown.length ? [`Not shown: ${notShown.join(' ')}`] : []),
1792
- '</page_state>',
1793
- ].join('\n');
1794
- return [...messages.slice(0, -1), withUserText(last, pageState)];
1795
- }
1796
1835
  /**
1797
1836
  * Convert our TurnHistoryMessage[] to AI SDK CoreMessage[].
1798
1837
  * The AI SDK handles each provider's message format internally.
@@ -2009,7 +2048,8 @@ function convertResponseToTurnMessages(result, executedToolResults) {
2009
2048
  const tracked = executedToolResults[resultIdx++];
2010
2049
  turnMessages.push({
2011
2050
  role: 'tool',
2012
- content: tracked.result,
2051
+ // Stored as the model is sent it, so the history sends it the same way every turn.
2052
+ content: answerWithoutState(tracked.result),
2013
2053
  toolCallId: tracked.toolCallId,
2014
2054
  name: tracked.toolName,
2015
2055
  });