@sixb/agent 0.0.0-stage → 0.2.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 (240) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -2
  3. package/dist/abort.d.ts +6 -0
  4. package/dist/abort.d.ts.map +1 -0
  5. package/dist/agent-prompt.d.ts +126 -0
  6. package/dist/agent-prompt.d.ts.map +1 -0
  7. package/dist/agent-runtime/errors.d.ts +13 -0
  8. package/dist/agent-runtime/errors.d.ts.map +1 -0
  9. package/dist/agent-runtime/preflight.d.ts +18 -0
  10. package/dist/agent-runtime/preflight.d.ts.map +1 -0
  11. package/dist/agent-runtime/profile.d.ts +14 -0
  12. package/dist/agent-runtime/profile.d.ts.map +1 -0
  13. package/dist/artifacts/layout-check/layout-check.d.ts +87 -0
  14. package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -0
  15. package/dist/artifacts/materialize.d.ts +115 -0
  16. package/dist/artifacts/materialize.d.ts.map +1 -0
  17. package/dist/artifacts/publish-tool.d.ts +86 -0
  18. package/dist/artifacts/publish-tool.d.ts.map +1 -0
  19. package/dist/ask-parent-tool.d.ts +36 -0
  20. package/dist/ask-parent-tool.d.ts.map +1 -0
  21. package/dist/attachments.d.ts +109 -0
  22. package/dist/attachments.d.ts.map +1 -0
  23. package/dist/child-files.d.ts +91 -0
  24. package/dist/child-files.d.ts.map +1 -0
  25. package/dist/child-questions.d.ts +24 -0
  26. package/dist/child-questions.d.ts.map +1 -0
  27. package/dist/computer-runner.d.ts +74 -0
  28. package/dist/computer-runner.d.ts.map +1 -0
  29. package/dist/context-budget.d.ts +34 -0
  30. package/dist/context-budget.d.ts.map +1 -0
  31. package/dist/context-compaction.d.ts +148 -0
  32. package/dist/context-compaction.d.ts.map +1 -0
  33. package/dist/context-guard.d.ts +69 -0
  34. package/dist/context-guard.d.ts.map +1 -0
  35. package/dist/conversation-memory.d.ts +21 -0
  36. package/dist/conversation-memory.d.ts.map +1 -0
  37. package/dist/conversation-messages.d.ts +33 -0
  38. package/dist/conversation-messages.d.ts.map +1 -0
  39. package/dist/errors.d.ts +46 -0
  40. package/dist/errors.d.ts.map +1 -0
  41. package/dist/execution-plan.d.ts +38 -0
  42. package/dist/execution-plan.d.ts.map +1 -0
  43. package/dist/failure.d.ts +14 -0
  44. package/dist/failure.d.ts.map +1 -0
  45. package/dist/family-mailbox.d.ts +60 -0
  46. package/dist/family-mailbox.d.ts.map +1 -0
  47. package/dist/file-ref.d.ts +6 -0
  48. package/dist/file-ref.d.ts.map +1 -0
  49. package/dist/image-attachments.d.ts +34 -0
  50. package/dist/image-attachments.d.ts.map +1 -0
  51. package/dist/index.d.ts +35 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +14387 -0
  54. package/dist/index.js.map +72 -0
  55. package/dist/inline-images.d.ts +28 -0
  56. package/dist/inline-images.d.ts.map +1 -0
  57. package/dist/message-authors.d.ts +34 -0
  58. package/dist/message-authors.d.ts.map +1 -0
  59. package/dist/message-times.d.ts +9 -0
  60. package/dist/message-times.d.ts.map +1 -0
  61. package/dist/model-adapters.d.ts +59 -0
  62. package/dist/model-adapters.d.ts.map +1 -0
  63. package/dist/model-lines.d.ts +16 -0
  64. package/dist/model-lines.d.ts.map +1 -0
  65. package/dist/prompt-cache.d.ts +28 -0
  66. package/dist/prompt-cache.d.ts.map +1 -0
  67. package/dist/requester.d.ts +15 -0
  68. package/dist/requester.d.ts.map +1 -0
  69. package/dist/run-agent-turn.d.ts +93 -0
  70. package/dist/run-agent-turn.d.ts.map +1 -0
  71. package/dist/run-child.d.ts +77 -0
  72. package/dist/run-child.d.ts.map +1 -0
  73. package/dist/run-conversation-turn.d.ts +42 -0
  74. package/dist/run-conversation-turn.d.ts.map +1 -0
  75. package/dist/run-credential.d.ts +22 -0
  76. package/dist/run-credential.d.ts.map +1 -0
  77. package/dist/run-environment.d.ts +145 -0
  78. package/dist/run-environment.d.ts.map +1 -0
  79. package/dist/run-fate.d.ts +15 -0
  80. package/dist/run-fate.d.ts.map +1 -0
  81. package/dist/run-files-lock.d.ts +16 -0
  82. package/dist/run-files-lock.d.ts.map +1 -0
  83. package/dist/run-sandbox.d.ts +60 -0
  84. package/dist/run-sandbox.d.ts.map +1 -0
  85. package/dist/run-subagent.d.ts +65 -0
  86. package/dist/run-subagent.d.ts.map +1 -0
  87. package/dist/run-workflow-agent-node.d.ts +46 -0
  88. package/dist/run-workflow-agent-node.d.ts.map +1 -0
  89. package/dist/sandbox-api-context.d.ts +34 -0
  90. package/dist/sandbox-api-context.d.ts.map +1 -0
  91. package/dist/sandbox-file-registry.d.ts +9 -0
  92. package/dist/sandbox-file-registry.d.ts.map +1 -0
  93. package/dist/sandbox-files.d.ts +71 -0
  94. package/dist/sandbox-files.d.ts.map +1 -0
  95. package/dist/sandbox-handle.d.ts +15 -0
  96. package/dist/sandbox-handle.d.ts.map +1 -0
  97. package/dist/sandbox-readiness.d.ts +8 -0
  98. package/dist/sandbox-readiness.d.ts.map +1 -0
  99. package/dist/skills/built-in.d.ts +15 -0
  100. package/dist/skills/built-in.d.ts.map +1 -0
  101. package/dist/subagent-context.d.ts +50 -0
  102. package/dist/subagent-context.d.ts.map +1 -0
  103. package/dist/subagent-continuation.d.ts +33 -0
  104. package/dist/subagent-continuation.d.ts.map +1 -0
  105. package/dist/subagent-inbox.d.ts +53 -0
  106. package/dist/subagent-inbox.d.ts.map +1 -0
  107. package/dist/subagent-tools.d.ts +293 -0
  108. package/dist/subagent-tools.d.ts.map +1 -0
  109. package/dist/thread-context.d.ts +17 -0
  110. package/dist/thread-context.d.ts.map +1 -0
  111. package/dist/tools/attachments.d.ts +11 -0
  112. package/dist/tools/attachments.d.ts.map +1 -0
  113. package/dist/tools/bash.d.ts +68 -0
  114. package/dist/tools/bash.d.ts.map +1 -0
  115. package/dist/tools/model-spec.d.ts +9 -0
  116. package/dist/tools/model-spec.d.ts.map +1 -0
  117. package/dist/tools/read.d.ts +43 -0
  118. package/dist/tools/read.d.ts.map +1 -0
  119. package/dist/tools/result-media.d.ts +65 -0
  120. package/dist/tools/result-media.d.ts.map +1 -0
  121. package/dist/tools/result-output.d.ts +18 -0
  122. package/dist/tools/result-output.d.ts.map +1 -0
  123. package/dist/tools/tool-files.d.ts +59 -0
  124. package/dist/tools/tool-files.d.ts.map +1 -0
  125. package/dist/tools/tool-outputs.d.ts +63 -0
  126. package/dist/tools/tool-outputs.d.ts.map +1 -0
  127. package/dist/tools/view-file.d.ts +40 -0
  128. package/dist/tools/view-file.d.ts.map +1 -0
  129. package/dist/tsconfig.json +5 -0
  130. package/dist/turn-runtime.d.ts +19 -0
  131. package/dist/turn-runtime.d.ts.map +1 -0
  132. package/dist/types.d.ts +83 -0
  133. package/dist/types.d.ts.map +1 -0
  134. package/dist/workflow-input-attachments.d.ts +18 -0
  135. package/dist/workflow-input-attachments.d.ts.map +1 -0
  136. package/package.json +59 -4
  137. package/src/abort.ts +40 -0
  138. package/src/agent-prompt.ts +860 -0
  139. package/src/agent-runtime/errors.ts +44 -0
  140. package/src/agent-runtime/preflight.ts +314 -0
  141. package/src/agent-runtime/profile.ts +23 -0
  142. package/src/artifacts/layout-check/check.cjs +478 -0
  143. package/src/artifacts/layout-check/layout-check.ts +460 -0
  144. package/src/artifacts/materialize.ts +380 -0
  145. package/src/artifacts/publish-tool.ts +700 -0
  146. package/src/ask-parent-tool.ts +100 -0
  147. package/src/attachments.ts +1041 -0
  148. package/src/child-files.ts +535 -0
  149. package/src/child-questions.ts +42 -0
  150. package/src/computer-runner.ts +336 -0
  151. package/src/context-budget.ts +177 -0
  152. package/src/context-compaction.ts +1349 -0
  153. package/src/context-guard.ts +826 -0
  154. package/src/conversation-memory.ts +45 -0
  155. package/src/conversation-messages.ts +86 -0
  156. package/src/errors.ts +85 -0
  157. package/src/execution-plan.ts +70 -0
  158. package/src/failure.ts +82 -0
  159. package/src/family-mailbox.ts +189 -0
  160. package/src/file-ref.ts +18 -0
  161. package/src/image-attachments.ts +322 -0
  162. package/src/index.ts +54 -0
  163. package/src/inline-images.ts +69 -0
  164. package/src/message-authors.ts +77 -0
  165. package/src/message-times.ts +24 -0
  166. package/src/model-adapters.ts +273 -0
  167. package/src/model-lines.ts +28 -0
  168. package/src/prompt-cache.ts +40 -0
  169. package/src/requester.ts +21 -0
  170. package/src/run-agent-turn.ts +509 -0
  171. package/src/run-child.ts +344 -0
  172. package/src/run-conversation-turn.ts +272 -0
  173. package/src/run-credential.ts +55 -0
  174. package/src/run-environment.ts +1216 -0
  175. package/src/run-fate.ts +51 -0
  176. package/src/run-files-lock.ts +118 -0
  177. package/src/run-sandbox.ts +63 -0
  178. package/src/run-subagent.ts +433 -0
  179. package/src/run-workflow-agent-node.ts +344 -0
  180. package/src/sandbox-api-context.ts +237 -0
  181. package/src/sandbox-file-registry.ts +26 -0
  182. package/src/sandbox-files.ts +326 -0
  183. package/src/sandbox-handle.ts +19 -0
  184. package/src/sandbox-readiness.ts +22 -0
  185. package/src/skills/built-in.ts +183 -0
  186. package/src/skills/sixb-artifacts/SKILL.md +95 -0
  187. package/src/skills/sixb-artifacts/canvas.md +104 -0
  188. package/src/skills/sixb-artifacts/document.md +63 -0
  189. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/first-job.html +42 -0
  190. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/region.html +29 -0
  191. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/shared.css +35 -0
  192. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/welcome.html +31 -0
  193. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/canvas.json +107 -0
  194. package/src/skills/sixb-artifacts/examples/canvas/retro/canvas.json +158 -0
  195. package/src/skills/sixb-artifacts/examples/document/incident-report/document.md +35 -0
  196. package/src/skills/sixb-artifacts/examples/document/operations-review/document.md +41 -0
  197. package/src/skills/sixb-artifacts/examples/document/operations-review/figures/restorations.svg +1 -0
  198. package/src/skills/sixb-artifacts/examples/page/collections-desk/index.html +169 -0
  199. package/src/skills/sixb-artifacts/examples/page/collections-desk/queries/overdue.json +13 -0
  200. package/src/skills/sixb-artifacts/examples/page/dispatch-board/data/dispatch.json +234 -0
  201. package/src/skills/sixb-artifacts/examples/page/dispatch-board/index.html +245 -0
  202. package/src/skills/sixb-artifacts/examples/page/fleet-planner/data/plan.json +53 -0
  203. package/src/skills/sixb-artifacts/examples/page/fleet-planner/index.html +462 -0
  204. package/src/skills/sixb-artifacts/examples/page/service-explorer/data/service.json +276 -0
  205. package/src/skills/sixb-artifacts/examples/page/service-explorer/index.html +549 -0
  206. package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/queries/overdue.json +13 -0
  207. package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/workbook.json +30 -0
  208. package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Inventory.csv +13 -0
  209. package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Spend.csv +6 -0
  210. package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/workbook.json +47 -0
  211. package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Quarters.csv +5 -0
  212. package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Regions.csv +5 -0
  213. package/src/skills/sixb-artifacts/examples/sheet/service-metrics/workbook.json +78 -0
  214. package/src/skills/sixb-artifacts/examples/slides/launch-plan/index.html +63 -0
  215. package/src/skills/sixb-artifacts/examples/slides/q3-review/index.html +133 -0
  216. package/src/skills/sixb-artifacts/file.md +17 -0
  217. package/src/skills/sixb-artifacts/page.md +215 -0
  218. package/src/skills/sixb-artifacts/queries.md +66 -0
  219. package/src/skills/sixb-artifacts/references.md +68 -0
  220. package/src/skills/sixb-artifacts/sheet.md +223 -0
  221. package/src/skills/sixb-artifacts/slides.md +137 -0
  222. package/src/skills/sixb-memory/SKILL.md +68 -0
  223. package/src/skills/text-assets.d.ts +25 -0
  224. package/src/subagent-context.ts +182 -0
  225. package/src/subagent-continuation.ts +56 -0
  226. package/src/subagent-inbox.ts +101 -0
  227. package/src/subagent-tools.ts +1671 -0
  228. package/src/thread-context.ts +31 -0
  229. package/src/tools/attachments.ts +28 -0
  230. package/src/tools/bash.ts +233 -0
  231. package/src/tools/model-spec.ts +27 -0
  232. package/src/tools/read.ts +262 -0
  233. package/src/tools/result-media.ts +351 -0
  234. package/src/tools/result-output.ts +46 -0
  235. package/src/tools/tool-files.ts +204 -0
  236. package/src/tools/tool-outputs.ts +464 -0
  237. package/src/tools/view-file.ts +155 -0
  238. package/src/turn-runtime.ts +33 -0
  239. package/src/types.ts +91 -0
  240. package/src/workflow-input-attachments.ts +140 -0
@@ -0,0 +1,28 @@
1
+ /** What a request says in place of an attachment's image the budget left out. */
2
+ export declare const INLINE_IMAGE_BUDGET_NOTE = "[Image not inlined: the conversation's inline image budget is used up until it is compacted; the file is available through the sandbox path or content URL.]";
3
+ /**
4
+ * What one request has left of {@link AGENT_INLINE_IMAGE_LIMITS}. A run takes from it in thread
5
+ * order, oldest first: the history's attachments and tool images, then the images its own steps
6
+ * return. The first image that does not fit closes it, so nothing after it is projected at all. A
7
+ * replay walks the same order: an image that fitted keeps its inline data until compaction, and one
8
+ * that did not stays metadata from its own turn on.
9
+ */
10
+ export declare class InlineImageBudget {
11
+ #private;
12
+ /** Whether no further image can go inline in this request. */
13
+ get closed(): boolean;
14
+ /** Count the image in when it fits what is left; one that does not closes the budget. */
15
+ take(data: URL): boolean;
16
+ }
17
+ /**
18
+ * Project images and let the budget decide each, in their order: a few run ahead at once, while
19
+ * every decision waits for the ones before it. Once the budget closes, the rest are never projected:
20
+ * `decide` gets `undefined` for them.
21
+ */
22
+ export declare function projectInOrder<TItem, TProjection>(input: {
23
+ readonly items: readonly TItem[];
24
+ readonly budget: InlineImageBudget;
25
+ readonly project: (item: TItem) => Promise<TProjection>;
26
+ readonly decide: (item: TItem, projection: TProjection | undefined) => void;
27
+ }): Promise<void>;
28
+ //# sourceMappingURL=inline-images.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-images.d.ts","sourceRoot":"","sources":["../src/inline-images.ts"],"names":[],"mappings":"AAEA,iFAAiF;AACjF,eAAO,MAAM,wBAAwB,iKAC2H,CAAA;AAKhK;;;;;;GAMG;AACH,qBAAa,iBAAiB;;IAK5B,8DAA8D;IAC9D,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,yFAAyF;IACzF,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO;CAWzB;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE;IAC9D,QAAQ,CAAC,KAAK,EAAE,SAAS,KAAK,EAAE,CAAA;IAChC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;IAClC,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,WAAW,CAAC,CAAA;IACvD,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,GAAG,SAAS,KAAK,IAAI,CAAA;CAC5E,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBhB"}
@@ -0,0 +1,34 @@
1
+ import { type UserPrincipal } from "@sixb/core";
2
+ import type { AgentMessageRecord, AgentThreadRecord } from "@sixb/core/storage";
3
+ /** What the model reads of who writes in a conversation. Nothing of it is stored or shown. */
4
+ export interface ConversationAuthors {
5
+ /** Who takes part, for the system prompt; absent in a one-person conversation. */
6
+ readonly section?: string;
7
+ /** The `<sixb_author>` closing each retained user message, by message id. */
8
+ readonly byMessageId: ReadonlyMap<string, string>;
9
+ }
10
+ /**
11
+ * A thread with the participants who can read it now: the people the model is told about, with
12
+ * their display names as the turn read them (`AgentTurnContext.readers` and `names`).
13
+ */
14
+ export interface ConversationReaders {
15
+ readonly thread: AgentThreadRecord;
16
+ readonly participants: readonly UserPrincipal[];
17
+ readonly names: Readonly<Record<string, string>>;
18
+ }
19
+ /**
20
+ * Who wrote each retained user message, when the thread has participants or several people wrote
21
+ * in it; nothing in a conversation its owner holds alone, so its messages do not change.
22
+ *
23
+ * Each message's author derives from stored data, so a turn replays the bytes the previous one
24
+ * sent. They change only when someone renames their account. The section naming who takes part
25
+ * goes in the system prompt, the same whoever sends the turn: it changes when someone joins or
26
+ * leaves, or is renamed.
27
+ */
28
+ export declare function conversationAuthors(input: {
29
+ readonly conversation: ConversationReaders;
30
+ readonly messages: readonly AgentMessageRecord[];
31
+ }): ConversationAuthors;
32
+ /** What the authors add to the user messages, for the model input's token estimate. */
33
+ export declare function conversationAuthorsText(authors: ConversationAuthors): string;
34
+ //# sourceMappingURL=message-authors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-authors.d.ts","sourceRoot":"","sources":["../src/message-authors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAO/E,8FAA8F;AAC9F,MAAM,WAAW,mBAAmB;IAClC,kFAAkF;IAClF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,6EAA6E;IAC7E,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClD;AAID;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;IAClC,QAAQ,CAAC,YAAY,EAAE,SAAS,aAAa,EAAE,CAAA;IAC/C,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CACjD;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAA;IAC1C,QAAQ,CAAC,QAAQ,EAAE,SAAS,kBAAkB,EAAE,CAAA;CACjD,GAAG,mBAAmB,CA+BtB;AAED,uFAAuF;AACvF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAE5E"}
@@ -0,0 +1,9 @@
1
+ import type { AgentTurnHistory } from "@sixb/core/internal/agents";
2
+ import { type SentSettings } from "./agent-prompt";
3
+ /**
4
+ * The `<sixb_current_time>` closing each retained user message: when it was sent, in the time zone
5
+ * and locale of the run that answered it (the project's when that run captured none). Stored data
6
+ * only, so every later run replays the same bytes and the history stays a cacheable prefix.
7
+ */
8
+ export declare function userMessageTimes(history: AgentTurnHistory, project: SentSettings): ReadonlyMap<string, string>;
9
+ //# sourceMappingURL=message-times.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-times.d.ts","sourceRoot":"","sources":["../src/message-times.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAErE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,YAAY,GACpB,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAY7B"}
@@ -0,0 +1,59 @@
1
+ import type { AgentMessagePart, JsonValue } from "@sixb/core";
2
+ import { type AgentToolCall, type AgentToolCallFile, type AgentToolCallOptions, type AgentToolCallResult, type AgentToolSpec } from "@sixb/core/internal/agents";
3
+ import type { ModelAssistantPart, ModelStep, ModelTool } from "@sixb/core/models";
4
+ import type { AgentToolModelOutput } from "./tools/result-output";
5
+ export type AgentErrorDetails = {
6
+ readonly threadId: string;
7
+ readonly runId: string;
8
+ } | {
9
+ readonly parentRunId: string;
10
+ readonly runId: string;
11
+ } | {
12
+ readonly workflowId: string;
13
+ readonly agentStepId: string;
14
+ readonly runId: string;
15
+ } | {
16
+ readonly agentStepId: string;
17
+ readonly workflowId: string;
18
+ readonly workflowRunId: string;
19
+ readonly nodeRunId: string;
20
+ };
21
+ /** How a run calls a project tool: through its session, or for a workflow step in the worker. */
22
+ export type AgentToolCaller = (call: AgentToolCall, options: AgentToolCallOptions) => Promise<AgentToolCallResult>;
23
+ interface ProjectModelToolsInput {
24
+ readonly specs: readonly AgentToolSpec[];
25
+ readonly runId: string;
26
+ readonly callTool: AgentToolCaller;
27
+ /** Where the sandbox keeps the run's files, which the paths a tool's files get start with. */
28
+ readonly contextDirectory: string;
29
+ /** The bytes the run's file budget has left, which a call's files may take. */
30
+ readonly fileBytesLeft: () => number;
31
+ /** Copy the files a call stored into the sandbox, before the model reads its output. */
32
+ readonly installFiles: (input: {
33
+ readonly toolName: string;
34
+ readonly files: readonly AgentToolCallFile[];
35
+ readonly signal: AbortSignal;
36
+ }) => Promise<void>;
37
+ readonly toolResultToModelOutput: (input: {
38
+ readonly output: JsonValue;
39
+ readonly signal: AbortSignal;
40
+ readonly toolCallId: string;
41
+ }) => AgentToolModelOutput | Promise<AgentToolModelOutput>;
42
+ readonly errorDetails?: AgentErrorDetails;
43
+ }
44
+ /**
45
+ * The project's tools as the model is offered them. A call runs where the project is, through
46
+ * `callTool`, which checks its input against the tool's schema; the files it stored are copied into
47
+ * the sandbox before the model reads its output.
48
+ */
49
+ export declare function projectModelTools(input: ProjectModelToolsInput): readonly ModelTool[];
50
+ /** The stored file of a call whose output was too large for the context (`outputFileOf`). */
51
+ export type AgentToolOutputFileOf = (toolCallId: string) => AgentToolCallFile | undefined;
52
+ /** Project validated model-loop steps into Sixb's durable trace contract. */
53
+ export declare function agentTraceFromModelSteps(steps: readonly ModelStep[], errorDetails?: AgentErrorDetails, outputFileOf?: AgentToolOutputFileOf): readonly AgentMessagePart[];
54
+ /** Convert an aborted model loop, retaining only coherent content from its in-flight step. */
55
+ export declare function agentTraceFromPartialModelLoop(steps: readonly ModelStep[], partialContent: readonly ModelAssistantPart[], errorDetails?: AgentErrorDetails, outputFileOf?: AgentToolOutputFileOf): readonly AgentMessagePart[];
56
+ /** Expose only failures that the tool author explicitly marked as safe for the model and storage. */
57
+ export declare function agentToolErrorText(error: unknown): string;
58
+ export {};
59
+ //# sourceMappingURL=model-adapters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-adapters.d.ts","sourceRoot":"","sources":["../src/model-adapters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE7D,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAExB,KAAK,aAAa,EACnB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EACT,SAAS,EAEV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAEjE,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrF;IACE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B,CAAA;AAEL,iGAAiG;AACjG,MAAM,MAAM,eAAe,GAAG,CAC5B,IAAI,EAAE,aAAa,EACnB,OAAO,EAA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E,qBAAqB,GACnC,SAAS,gBAAgB,EAAE,CAI7B;AAED,8FAA8F;AAC9F,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,cAAc,EAAE,SAAS,kBAAkB,EAAE,EAC7C,YAAY,CAAC,EAAE,iBAAiB,EAChC,YAAY,CAAC,EAAE,qBAAqB,GACnC,SAAS,gBAAgB,EAAE,CAW7B;AA6GD,qGAAqG;AACrG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEzD"}
@@ -0,0 +1,16 @@
1
+ import type { LanguageModelTier } from "@sixb/core";
2
+ /**
3
+ * One language model on one line, as the prompt lists the models the Agent can ask or delegate
4
+ * to: under its tier, else as a list item, then its name, what the caller adds about it, and its
5
+ * description.
6
+ */
7
+ export declare function renderModelLine(input: {
8
+ readonly tier?: LanguageModelTier;
9
+ /** How the caller names the model, such as the reference a command takes. */
10
+ readonly reference: string;
11
+ readonly name?: string;
12
+ /** Written as given between the name and the description, such as `(default; tools)`. */
13
+ readonly details?: string;
14
+ readonly description?: string;
15
+ }): string;
16
+ //# sourceMappingURL=model-lines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-lines.d.ts","sourceRoot":"","sources":["../src/model-lines.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE;IACrC,QAAQ,CAAC,IAAI,CAAC,EAAE,iBAAiB,CAAA;IACjC,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,yFAAyF;IACzF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B,GAAG,MAAM,CAOT"}
@@ -0,0 +1,28 @@
1
+ import type { ModelCachingIntent } from "@sixb/core/models";
2
+ /**
3
+ * How a conversation's model calls are cached. Its prompt is read again by its next turn, which can
4
+ * come after a human pause, so a turn asks for a long lifetime; a child does too when it can wait on
5
+ * a human decision (see {@link childCacheLifetime}). Both name the conversation, so a provider
6
+ * keeps the turn and its children on the upstream that holds what they cached: a child shares its
7
+ * whole prefix with the runs that continue it, and, in a provider sandbox, its system prompt with
8
+ * siblings given the same tools. On a computer, each child's prompt names its own thread's files.
9
+ */
10
+ export declare function conversationPromptCaching(input: {
11
+ readonly projectId: string;
12
+ /** The conversation's thread: a child's parent thread, never its own. */
13
+ readonly threadId: string;
14
+ readonly lifetime: NonNullable<ModelCachingIntent["lifetime"]>;
15
+ }): ModelCachingIntent;
16
+ /**
17
+ * A child's next read can come after a human decision when its calls can be held for approval, or
18
+ * when it continues a run that paused, as it may pause again: long. Otherwise its next read is its
19
+ * own next step, within the turn: default. A question its parent's turn leaves to the user pauses a
20
+ * child too; that is rare, so a child that can only pause on one keeps the default.
21
+ */
22
+ export declare function childCacheLifetime(input: {
23
+ /** Whether its run's approval mode lets every call run without asking. */
24
+ readonly runsEveryCall: boolean;
25
+ /** Whether it continues a run that paused. */
26
+ readonly continues: boolean;
27
+ }): NonNullable<ModelCachingIntent["lifetime"]>;
28
+ //# sourceMappingURL=prompt-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-cache.d.ts","sourceRoot":"","sources":["../src/prompt-cache.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE3D;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAA;CAC/D,GAAG,kBAAkB,CAErB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,0EAA0E;IAC1E,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAA;IAC/B,8CAA8C;IAC9C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAC5B,GAAG,WAAW,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAE9C"}
@@ -0,0 +1,15 @@
1
+ import type { AuthorizablePrincipal } from "@sixb/core";
2
+ /** Who an Agent run works for, as its prompt names them. */
3
+ export type AgentRequester = {
4
+ readonly type: "user";
5
+ readonly id: string;
6
+ readonly displayName?: string;
7
+ } | {
8
+ readonly type: "serviceAccount";
9
+ };
10
+ /**
11
+ * The requester of an Agent execution: the user, with their display name as the run read it when
12
+ * it started, or a service account. A renamed user is named correctly from the next run.
13
+ */
14
+ export declare function agentRequester(requestedBy: AuthorizablePrincipal | undefined, names: Readonly<Record<string, string>>): AgentRequester | undefined;
15
+ //# sourceMappingURL=requester.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requester.d.ts","sourceRoot":"","sources":["../src/requester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAEvD,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7E;IAAE,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,CAAA;AAEvC;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,qBAAqB,GAAG,SAAS,EAC9C,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACtC,cAAc,GAAG,SAAS,CAM5B"}
@@ -0,0 +1,93 @@
1
+ import type { AgentMessagePart, AgentStepRequestSize } from "@sixb/core";
2
+ import { type AgentContextBudget, type AgentRunSession } from "@sixb/core/internal/agents";
3
+ import { type AgentRunRecord, type AppendAgentMessageInput, type ConversationAgentRunRecord } from "@sixb/core/storage";
4
+ import type { ResolvedAgentExecutionPlan } from "./execution-plan";
5
+ import type { ConversationReaders } from "./message-authors";
6
+ import type { ConversationAgentExecutionEnvironment } from "./run-environment";
7
+ import type { LoadedAgentThreadModelContext } from "./thread-context";
8
+ import { type AgentTurnRuntime } from "./turn-runtime";
9
+ import type { AgentTurnContext } from "./types";
10
+ export interface RunAgentTurnInput {
11
+ /** The worker's stable execution context (storage, tools and stream sink). */
12
+ readonly context: AgentTurnContext;
13
+ readonly plan: ResolvedAgentExecutionPlan;
14
+ /** The run this delivery reserved or reclaimed with its execution token. */
15
+ readonly run: ConversationAgentRunRecord;
16
+ /** The run's session: its finish, and every other write, are fenced by its execution token. */
17
+ readonly session: AgentRunSession;
18
+ /** The worker's shutdown signal. */
19
+ readonly signal: AbortSignal;
20
+ /**
21
+ * The worker's own stop, when `signal` also carries a user cancel. A turn it ends first is
22
+ * recorded with `finishReason: "interrupted"` so the user can resume it.
23
+ */
24
+ readonly stopSignal?: AbortSignal;
25
+ /** Shared with preflight when this turn performed compaction. */
26
+ readonly runtime?: AgentTurnRuntime;
27
+ /** The thread and who can read it now; without it the model is told nothing of its people. */
28
+ readonly conversation?: ConversationReaders;
29
+ /** The history the turn runs on: as it started, or as its compaction left it. */
30
+ readonly threadContext: LoadedAgentThreadModelContext;
31
+ /** What the turn's children ask it, and the work it waits for, when it can delegate. */
32
+ readonly children?: TurnChildren;
33
+ /**
34
+ * The model's limit every call of the turn keeps under (see createAgentContextGuard), and how
35
+ * it compacts the history before it from within. Without them, only the turn's start was
36
+ * weighed.
37
+ */
38
+ readonly contextLimits?: {
39
+ readonly budget: AgentContextBudget;
40
+ /** The bytes per token the turn's history was measured at, else its run's starting one. */
41
+ readonly bytesPerToken?: number;
42
+ /** What the run's latest counted call measured (see prepareAgentModel). */
43
+ readonly measuredBytesPerToken?: () => number | undefined;
44
+ readonly compactInTurn?: ConversationAgentExecutionEnvironment["compactInTurn"];
45
+ };
46
+ /**
47
+ * Handed the answer so far after each step that completed, as the message the turn would
48
+ * append: a turn that fails then records it with its failure, and keeps that work.
49
+ */
50
+ readonly onWork?: (message: AppendAgentMessageInput) => void;
51
+ }
52
+ /**
53
+ * How a turn hears the questions its children ask, leaves them waiting when it ends, and waits for
54
+ * those still at work when it pauses.
55
+ */
56
+ export interface TurnChildren {
57
+ /** Read after the conversation: children of earlier turns still waiting on their question. */
58
+ readonly waiting?: string;
59
+ /** The questions the model has not read yet, read in one more step when it answers. */
60
+ unread(): Promise<string | undefined>;
61
+ /**
62
+ * Before the turn records its end: each child still waiting on its question pauses on it, and
63
+ * the turn waits until it has. Only then can its end cancel the others.
64
+ */
65
+ defer(signal: AbortSignal): Promise<void>;
66
+ /**
67
+ * Before a pausing turn records its end: wait until none of its children is at work. Its end
68
+ * cancels those still at work; one that holds a call pauses by itself.
69
+ */
70
+ settle(signal: AbortSignal): Promise<void>;
71
+ }
72
+ /** Drive one provider-neutral model/tool turn to completion and persist it. */
73
+ export declare function runAgentTurn(input: RunAgentTurnInput): Promise<AgentRunRecord>;
74
+ /**
75
+ * Whether the turn holds a call for its requester, as `runs.finish` checks before it pauses: one
76
+ * waiting, or decided and not reported to the model yet, its children's included.
77
+ */
78
+ /**
79
+ * Mark each step from `fromStep` on as answering a request the turn reduced, for the next turn's
80
+ * estimate not to go by what those calls read.
81
+ */
82
+ export declare function markReducedSteps(parts: readonly AgentMessagePart[], fromStep: number | undefined): readonly AgentMessagePart[];
83
+ /**
84
+ * Record on each step-start what its request carried, by step: the next turn's context meter
85
+ * reads the system prompt and tools the latest one sent.
86
+ */
87
+ export declare function recordStepRequests(parts: readonly AgentMessagePart[], requests: readonly (AgentStepRequestSize | undefined)[]): readonly AgentMessagePart[];
88
+ /**
89
+ * Whether the worker's stop, rather than the user's, ended the turn. Whichever fired first wins:
90
+ * the combined turn signal carries the reason of the first source that aborted it.
91
+ */
92
+ export declare function stoppedByWorker(turnSignal: AbortSignal, stopSignal?: AbortSignal): boolean;
93
+ //# sourceMappingURL=run-agent-turn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-agent-turn.d.ts","sourceRoot":"","sources":["../src/run-agent-turn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACtF,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EAOrB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAEhC,MAAM,oBAAoB,CAAA;AAI3B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAE5D,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,mBAAmB,CAAA;AAE9E,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,KAAK,gBAAgB,EAA0B,MAAM,gBAAgB,CAAA;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,MAAM,WAAW,iBAAiB;IAChC,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;IAClC,QAAQ,CAAC,IAAI,EAAE,0BAA0B,CAAA;IACzC,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,0BAA0B,CAAA;IACxC,+FAA+F;IAC/F,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;IACjC,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;IAC5B;;;OAGG;IACH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gBAAgB,CAC9B,KAAK,EAAE,SAAS,gBAAgB,EAAE,EAClC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,SAAS,gBAAgB,EAAE,CAU7B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,gBAAgB,EAAE,EAClC,QAAQ,EAAE,SAAS,CAAC,oBAAoB,GAAG,SAAS,CAAC,EAAE,GACtD,SAAS,gBAAgB,EAAE,CAS7B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,WAAW,GAAG,OAAO,CAE1F"}
@@ -0,0 +1,77 @@
1
+ import { type AgentRunSession } from "@sixb/core/internal/agents";
2
+ import type { AgentRunRecord, AgentThreadRecord, ExecutionRecord, SubagentRunRecord } from "@sixb/core/storage";
3
+ import type { AgentRunFailure } from "./failure";
4
+ import type { FamilyMailbox } from "./family-mailbox";
5
+ import { type OpenRunSandbox } from "./run-environment";
6
+ import type { AgentExecutionContext, AgentRunSettings } from "./types";
7
+ /** What a runner lends the children it runs. */
8
+ export interface ChildRunnerHost {
9
+ /** What every run of the project shares. */
10
+ readonly settings: AgentRunSettings;
11
+ /** How many children run here at once, across every turn; the rest wait their turn queued. */
12
+ readonly capacity: number;
13
+ /**
14
+ * Claim a queued child, retrying while `stop` holds: nothing redelivers a child, and its parent
15
+ * waits on it. Null when it can't be claimed, such as once its parent ended.
16
+ */
17
+ claim(run: SubagentRunRecord, claim: {
18
+ readonly leaseExpiresAt: string;
19
+ readonly stop: AbortSignal;
20
+ }): Promise<AgentRunSession<SubagentRunRecord> | null>;
21
+ /** The sandbox the child works in, opened when it first needs one. */
22
+ openSandbox(child: {
23
+ readonly session: AgentRunSession<SubagentRunRecord>;
24
+ readonly context: AgentExecutionContext;
25
+ readonly execution: ExecutionRecord;
26
+ readonly thread: AgentThreadRecord;
27
+ }): OpenRunSandbox;
28
+ /** A sandbox teardown that outlives the child: the runner waits for it before it stops. */
29
+ onDetachedTeardown(teardown: Promise<void>): void;
30
+ /** A child that failed: the runner reports it, once its end is recorded. */
31
+ reportFailure?(error: unknown, run: AgentRunRecord, failure: AgentRunFailure): void;
32
+ /** Runs the child's preparation, which calls no model. Runs it once when absent. */
33
+ prepare?<T>(prepare: () => Promise<T>, signal: AbortSignal): Promise<T>;
34
+ }
35
+ /** What a child runs under: its parent turn's. */
36
+ export interface ChildParent {
37
+ /** The runner's own stop: its process stopping, or its hold on the parent lost. */
38
+ readonly signal: AbortSignal;
39
+ /** When the parent's lease runs out, which the child is claimed until. */
40
+ leaseExpiresAt(): string;
41
+ /** Holds the child's lease beside its parent's, from now until the returned release. */
42
+ holdLease(session: AgentRunSession<SubagentRunRecord>): Promise<() => void>;
43
+ /** The turn's mailbox, through which they talk. */
44
+ readonly family: FamilyMailbox;
45
+ }
46
+ /**
47
+ * Runs the children of a runner's turns. A child holds its own run, session, token and sandbox,
48
+ * but no lease of its own: its parent's renewals renew it, and a runner that stops takes its
49
+ * children with it. A child left running once its parent ended is ended when its lease lapses.
50
+ */
51
+ export declare class ChildRunner {
52
+ private readonly host;
53
+ /** Children running here, by run id: a child already running is never started twice. */
54
+ private readonly running;
55
+ /** Children holding one of the runner's slots, and those waiting for one, first come first. */
56
+ private active;
57
+ private readonly waiting;
58
+ constructor(host: ChildRunnerHost);
59
+ /** Run a child, in this process. It records the child's fate itself and never rejects. */
60
+ start(run: SubagentRunRecord, parent: ChildParent): void;
61
+ /**
62
+ * Stop a parent's children still running here, and wait for them to record it. The parent's
63
+ * lease, which renews theirs, must hold until this returns.
64
+ */
65
+ stopChildrenOf(parentRunId: string): Promise<void>;
66
+ /** Wait for every child running here, for a runner that stops. */
67
+ drain(): Promise<void>;
68
+ private run;
69
+ /** Wait for one of the runner's child slots: false once the child stops first. */
70
+ private takeSlot;
71
+ /** A slot a child let go of passes to the child waiting longest. */
72
+ private releaseSlot;
73
+ private runClaimed;
74
+ /** Everything a child needs before its first model call, read through its session. */
75
+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AwGxB,sFAAsF;YACxE,OAAO;CAyDtB"}
@@ -0,0 +1,42 @@
1
+ import { type AgentRunSession } from "@sixb/core/internal/agents";
2
+ import type { AgentRunRecord, AgentThreadRecord, ConversationAgentRunRecord, ExecutionRecord, SubagentRunRecord } from "@sixb/core/storage";
3
+ import type { AgentRunFailure } from "./failure";
4
+ import type { FamilyMailbox } from "./family-mailbox";
5
+ import { type OpenRunSandbox } from "./run-environment";
6
+ import type { AgentExecutionContext, AgentRunSettings } from "./types";
7
+ /** What a runner lends the turns it runs. */
8
+ export interface ConversationTurnRunner {
9
+ /** What every run of the project shares. */
10
+ readonly settings: AgentRunSettings;
11
+ /** The sandbox the turn works in, opened when it first needs one. */
12
+ openSandbox(turn: {
13
+ readonly session: AgentRunSession<ConversationAgentRunRecord>;
14
+ readonly context: AgentExecutionContext;
15
+ readonly execution: ExecutionRecord;
16
+ readonly thread: AgentThreadRecord | null;
17
+ }): OpenRunSandbox;
18
+ /** Run a child the turn spawned or continues, beside the turn, on the turn's mailbox. */
19
+ startChild(run: SubagentRunRecord, family: FamilyMailbox): void;
20
+ /** A sandbox teardown that outlives the turn: the runner waits for it before it stops. */
21
+ onDetachedTeardown(teardown: Promise<void>): void;
22
+ /** A turn that failed: the runner reports it, once its end is recorded. */
23
+ reportFailure?(error: unknown, run: AgentRunRecord, failure: AgentRunFailure): void;
24
+ /**
25
+ * Runs the turn's preparation, which reads and resolves and calls no model: the worker retries a
26
+ * storage blip in place. Runs it once when absent.
27
+ */
28
+ prepare?<T>(prepare: () => Promise<T>): Promise<T>;
29
+ }
30
+ /**
31
+ * Run a claimed conversation turn and record how it ended. Returns once its end is recorded, or
32
+ * at once when its runner lost the run. Throws {@link AgentFinalizationError} when its end could
33
+ * not be recorded, and rethrows its failure when `signal` stopped it, for the runner to release
34
+ * the run rather than call it done.
35
+ */
36
+ export declare function runConversationTurn(input: {
37
+ readonly session: AgentRunSession<ConversationAgentRunRecord>;
38
+ readonly runner: ConversationTurnRunner;
39
+ /** The runner's own stop: its process stopping, or its hold on the run lost. */
40
+ readonly signal: AbortSignal;
41
+ }): Promise<void>;
42
+ //# sourceMappingURL=run-conversation-turn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-conversation-turn.d.ts","sourceRoot":"","sources":["../src/run-conversation-turn.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,eAAe,EAErB,MAAM,4BAA4B,CAAA;AAInC,OAAO,KAAK,EACV,cAAc,EAEd,iBAAiB,EAEjB,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,EAClB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAGrD,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAA;AAI1B,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAMtE,6CAA6C;AAC7C,MAAM,WAAW,sBAAsB;IACrC,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACnC,qEAAqE;IACrE,WAAW,CAAC,IAAI,EAAE;QAChB,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,0BAA0B,CAAC,CAAA;QAC7D,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAA;QACvC,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAA;QACnC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAA;KAC1C,GAAG,cAAc,CAAA;IAClB,yFAAyF;IACzF,UAAU,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAAA;IAC/D,0FAA0F;IAC1F,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IACjD,2EAA2E;IAC3E,aAAa,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI,CAAA;IACnF;;;OAGG;IACH,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CACnD;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,0BAA0B,CAAC,CAAA;IAC7D,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAA;IACvC,gFAAgF;IAChF,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B,GAAG,OAAO,CAAC,IAAI,CAAC,CAwHhB"}
@@ -0,0 +1,22 @@
1
+ import type { SandboxRequestCredential } from "@sixb/core";
2
+ /** The token the run's commands call the API with, valid while this execution owns the run. */
3
+ export declare function runTokenFor(input: {
4
+ readonly projectId: string;
5
+ readonly runId: string;
6
+ readonly executionToken?: string;
7
+ }): string;
8
+ /**
9
+ * The token a runner over HTTP reaches its run's session with. It is the runner's alone: the run's
10
+ * commands get the run token, which the session refuses.
11
+ */
12
+ export declare function runnerTokenFor(input: {
13
+ readonly projectId: string;
14
+ readonly runId: string;
15
+ readonly executionToken?: string;
16
+ }): string;
17
+ /**
18
+ * The run token as a request credential: on a provider that adds credentials outside the guest,
19
+ * every call to the API under `apiBaseUrl` gets it, and the run's commands never hold it.
20
+ */
21
+ export declare function runApiCredential(apiBaseUrl: string, runToken: string): SandboxRequestCredential;
22
+ //# sourceMappingURL=run-credential.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-credential.d.ts","sourceRoot":"","sources":["../src/run-credential.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAG1D,+FAA+F;AAC/F,wBAAgB,WAAW,CAAC,KAAK,EAAE;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CACjC,GAAG,MAAM,CAWT;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CACjC,GAAG,MAAM,CAWT;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,wBAAwB,CAQ/F"}