@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,109 @@
1
+ import type { AgentFileDataProjection, FileRef } from "@sixb/core";
2
+ import { type AgentRunFileStore } from "@sixb/core/internal/agents";
3
+ import type { LanguageModel, ModelMessage } from "@sixb/core/models";
4
+ import type { AgentMessageRecord } from "@sixb/core/storage";
5
+ /**
6
+ * Where a parent finds what its children wrote to `out/`, a directory per spawn key, in the context
7
+ * directory: `wait_agent` copies them there, and later turns materialize them there again.
8
+ */
9
+ export declare const CHILD_FILES_DIRECTORY = "children";
10
+ /**
11
+ * How many files, and bytes, a sandbox receives of a run's attachments: also what a parent Agent
12
+ * and its child hand each other.
13
+ */
14
+ export declare const SANDBOX_ATTACHMENT_LIMITS: {
15
+ readonly maxFiles: 50;
16
+ readonly fileMaxBytes: number;
17
+ readonly totalMaxBytes: number;
18
+ };
19
+ export interface PreparedAgentAttachmentContext {
20
+ readonly entries: readonly PreparedAgentAttachment[];
21
+ readonly promptTextByPartKey: ReadonlyMap<string, string>;
22
+ readonly modelFileDataByPartKey: ReadonlyMap<string, AgentFileDataProjection>;
23
+ readonly sandboxFiles: readonly PreparedSandboxAttachmentFile[];
24
+ readonly manifestJson: string;
25
+ /** The images each stored step's tools returned, as the model read them after that step. */
26
+ readonly toolFilesByStep?: ReadonlyMap<string, ModelMessage>;
27
+ /**
28
+ * The user attachments the request may inline as images, projected only once the request's
29
+ * inline image budget decides them ({@link settleAttachmentImages}). Until then each reads as
30
+ * the budget had no room for it.
31
+ */
32
+ readonly pendingImages?: ReadonlyMap<string, PendingAttachmentImage>;
33
+ }
34
+ /** What projecting an attachment as an image gave: its inline data, or why there is none. */
35
+ export type AttachmentImageProjection = {
36
+ readonly kind: "inline";
37
+ readonly data: AgentFileDataProjection;
38
+ readonly notes: readonly string[];
39
+ } | {
40
+ readonly kind: "not-inlined";
41
+ readonly notes: readonly string[];
42
+ };
43
+ /** An image's fate in the request: projected, or left out because the budget was used up. */
44
+ export type AttachmentImageOutcome = AttachmentImageProjection | {
45
+ readonly kind: "budget";
46
+ };
47
+ /** A user attachment the request may inline as an image, decoded and encoded only on demand. */
48
+ export interface PendingAttachmentImage {
49
+ project(signal: AbortSignal): Promise<AttachmentImageProjection>;
50
+ /** The attachment as the request reads it once its image's fate is known. */
51
+ settle(outcome: AttachmentImageOutcome): {
52
+ readonly entry: PreparedAgentAttachment;
53
+ readonly promptText: string;
54
+ readonly modelFileData?: AgentFileDataProjection;
55
+ };
56
+ }
57
+ export interface PreparedAgentAttachment {
58
+ readonly key: string;
59
+ readonly messageId: string;
60
+ readonly partIndex: number;
61
+ readonly fileRef: FileRef;
62
+ readonly fileName: string;
63
+ readonly mediaType: string;
64
+ readonly sizeBytes: number;
65
+ readonly contentPath: string;
66
+ readonly contentUrl: string;
67
+ readonly sandboxPath?: string;
68
+ readonly inlineDisposition: "image" | "text" | "metadata-only" | "omitted";
69
+ readonly notes: readonly string[];
70
+ }
71
+ export interface PreparedSandboxAttachmentFile {
72
+ readonly key: string;
73
+ readonly path: string;
74
+ readonly bytes: Uint8Array;
75
+ readonly fileRef: FileRef;
76
+ }
77
+ export interface PreparedAgentToolFileProjection {
78
+ readonly promptText: string;
79
+ readonly modelFileData?: AgentFileDataProjection;
80
+ }
81
+ export declare function prepareAgentAttachments(input: {
82
+ readonly projectId: string;
83
+ readonly threadId: string;
84
+ readonly messages: readonly AgentMessageRecord[];
85
+ readonly blobStorage: AgentRunFileStore;
86
+ readonly apiBaseUrl: string;
87
+ /** Where the run's files go: attachments are materialized in it. */
88
+ readonly contextDirectory: string;
89
+ readonly inlineImages: boolean;
90
+ readonly signal?: AbortSignal;
91
+ }): Promise<PreparedAgentAttachmentContext>;
92
+ /** Build the bounded, ephemeral projection of a tool-created file for the next model step. */
93
+ export declare function prepareAgentToolFileProjection(input: {
94
+ readonly fileRef: FileRef;
95
+ readonly blobStorage: AgentRunFileStore;
96
+ readonly inlineImages: boolean;
97
+ readonly signal?: AbortSignal;
98
+ readonly sandboxPath?: string;
99
+ readonly imageOmissionNote?: string;
100
+ }): Promise<PreparedAgentToolFileProjection>;
101
+ export declare function modelSupportsInlineImages(model: LanguageModel): boolean;
102
+ /**
103
+ * The context once the request's inline image budget decided its pending images: each reads inline,
104
+ * or as metadata with the note that says why, in the prompt and in the manifest.
105
+ */
106
+ export declare function settleAttachmentImages(context: PreparedAgentAttachmentContext, outcomes: ReadonlyMap<string, AttachmentImageOutcome>): PreparedAgentAttachmentContext;
107
+ export declare function formatBytes(bytes: number): string;
108
+ export { attachmentKey, attachmentKeyMessageId, findMessageAttachment, toolResultAttachmentKey, } from "@sixb/core/internal/agents";
109
+ //# sourceMappingURL=attachments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachments.d.ts","sourceRoot":"","sources":["../src/attachments.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAY,OAAO,EAAE,MAAM,YAAY,CAAA;AAC5E,OAAO,EACL,KAAK,iBAAiB,EAGvB,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAoB5D;;;GAGG;AACH,eAAO,MAAM,qBAAqB,aAAa,CAAA;AAG/C;;;GAGG;AACH,eAAO,MAAM,yBAAyB;;;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CAAA;IAChD,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,oEAAoE;IACpE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAC9B,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA6D1C;AAED,8FAA8F;AAC9F,wBAAsB,8BAA8B,CAAC,KAAK,EAAE;IAC1D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;IACvC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CACpC,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAsF3C;AAyfD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAMvE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,8BAA8B,EACvC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,sBAAsB,CAAC,GACpD,8BAA8B,CA4BhC;AA8LD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,4BAA4B,CAAA"}
@@ -0,0 +1,91 @@
1
+ import type { AgentRunFileStore } from "@sixb/core/internal/agents";
2
+ import type { SubagentRunFile } from "@sixb/core/storage";
3
+ import { type PreparedAgentAttachmentContext } from "./attachments";
4
+ import type { AgentRunFiles } from "./types";
5
+ /** A file a child returned, copied into its parent's sandbox for the turn. */
6
+ export interface InstalledChildFile extends SubagentRunFile {
7
+ /** As the agent names it: relative to the working directory, or absolute. */
8
+ readonly sandboxPath: string;
9
+ }
10
+ /** A file a parent hands its child, checked but not read yet. */
11
+ export interface HandedSource {
12
+ /** Where the child finds it: the path the parent named, relative to the working directory. */
13
+ readonly path: string;
14
+ /** Where it really is, every symbolic link followed. */
15
+ readonly absolutePath: string;
16
+ readonly sizeBytes?: number;
17
+ }
18
+ /**
19
+ * Check the files and directories a parent hands its child, without reading them. Refused when a
20
+ * path is missing or a link, leaves the working directory or really is the run's own context, or
21
+ * when the files pass the attachment limits.
22
+ */
23
+ export declare function listHandedSources(input: {
24
+ readonly files: AgentRunFiles;
25
+ readonly paths: readonly string[];
26
+ readonly signal: AbortSignal;
27
+ }): Promise<readonly HandedSource[]>;
28
+ /**
29
+ * Read and store the files a parent hands its child once it will be admitted, one at a time,
30
+ * against the parent's run budget: `release` them when it is not.
31
+ */
32
+ export declare function storeHandedFiles(input: {
33
+ readonly files: AgentRunFiles;
34
+ readonly sources: readonly HandedSource[];
35
+ readonly signal: AbortSignal;
36
+ }): Promise<{
37
+ readonly files: readonly SubagentRunFile[];
38
+ release(): void;
39
+ }>;
40
+ /** The references the files would be stored under, read one at a time and stored nowhere. */
41
+ export declare function handedFileRefs(input: {
42
+ readonly files: AgentRunFiles;
43
+ readonly sources: readonly HandedSource[];
44
+ readonly signal: AbortSignal;
45
+ }): Promise<readonly SubagentRunFile[]>;
46
+ /**
47
+ * The child's side: the files its parent handed over, at the same paths in its sandbox, listed in
48
+ * `$SIXB_ATTACHMENTS` and readable with `view_file`.
49
+ */
50
+ export declare function prepareHandedFiles(input: {
51
+ readonly projectId: string;
52
+ readonly parentRunId: string;
53
+ readonly files: readonly SubagentRunFile[];
54
+ /**
55
+ * The files are in the sandbox already, as a resumed workspace kept them: listed, not copied,
56
+ * so what the child changed in them stays. Those in the context directory are copied again:
57
+ * every run starts without it.
58
+ */
59
+ readonly inSandbox?: boolean;
60
+ /** The child's context directory, relative to its working directory or absolute. */
61
+ readonly contextDirectory: string;
62
+ readonly blobStorage: AgentRunFileStore;
63
+ readonly signal?: AbortSignal;
64
+ }): Promise<PreparedAgentAttachmentContext>;
65
+ /**
66
+ * Store what a child that finished wrote under `out/`, by path relative to it, against a budget of
67
+ * their own: what the child published does not count. A file its parent handed over there and the
68
+ * child left unchanged does not come back. Past the attachment limits, none comes back and `error`
69
+ * says why, so the child's answer still does.
70
+ */
71
+ export declare function storeChildOutputs(input: {
72
+ readonly files: AgentRunFiles;
73
+ readonly handed: readonly SubagentRunFile[];
74
+ readonly signal: AbortSignal;
75
+ }): Promise<{
76
+ readonly files: readonly SubagentRunFile[];
77
+ readonly error?: string;
78
+ }>;
79
+ /**
80
+ * The parent's side: copy what a child wrote under `out/` into the parent's sandbox for the turn,
81
+ * under `children/<key>/` in its context directory. Each file's reference names it by that path,
82
+ * as its `logicalPath`, and by a name no other file of the child shares, so a later turn tells
83
+ * them apart in `$SIXB_ATTACHMENTS`.
84
+ */
85
+ export declare function installChildOutputs(input: {
86
+ readonly files: AgentRunFiles;
87
+ readonly key: string;
88
+ readonly outputs: readonly SubagentRunFile[];
89
+ readonly signal: AbortSignal;
90
+ }): Promise<readonly InstalledChildFile[]>;
91
+ //# sourceMappingURL=child-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-files.d.ts","sourceRoot":"","sources":["../src/child-files.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAEnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGzD,OAAO,EAGL,KAAK,8BAA8B,EAEpC,MAAM,eAAe,CAAA;AAatB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAsB5C,8EAA8E;AAC9E,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,6EAA6E;IAC7E,QAAQ,CAAC,WAAW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Q,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,CAAA;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IAC5B,oFAAoF;IACpF,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;IACvC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAC9B,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA6C1C;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE;IAC7C,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAA;IAC3C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B,GAAG,OAAO,CAAC;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAuDnF;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAA;IAC5C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B,GAAG,OAAO,CAAC,SAAS,kBAAkB,EAAE,CAAC,CA2BzC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A question a child asked: the id of its mail and what it asks. A child paused on it keeps both in
3
+ * its thread, the text as its `ask_parent` call's input and the id in that call's output.
4
+ */
5
+ export interface QuestionRef {
6
+ readonly id: string;
7
+ readonly text: string;
8
+ }
9
+ /** A question a child of the turn asked. */
10
+ export interface ChildQuestion extends QuestionRef {
11
+ /** The child that asked it, waiting for the answer. */
12
+ readonly runId: string;
13
+ }
14
+ /**
15
+ * What the Agent reads for its children's questions it has not seen yet, or, `earlier`, for the
16
+ * children of earlier turns paused on theirs. The children's text is escaped: it must not close the
17
+ * block or pass for one of Sixb's own.
18
+ */
19
+ export declare function renderChildQuestions(questions: readonly (QuestionRef & {
20
+ readonly key: string;
21
+ })[], options?: {
22
+ readonly earlier?: boolean;
23
+ }): string;
24
+ //# sourceMappingURL=child-questions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-questions.d.ts","sourceRoot":"","sources":["../src/child-questions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED,4CAA4C;AAC5C,MAAM,WAAW,aAAc,SAAQ,WAAW;IAChD,uDAAuD;IACvD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,CAAC,WAAW,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,EAC9D,OAAO,GAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAC3C,MAAM,CAcR"}
@@ -0,0 +1,74 @@
1
+ import type { Sandbox, SandboxRequestCredential } from "@sixb/core";
2
+ import type { ConversationAgentRunRecord } from "@sixb/core/storage";
3
+ /** Opens the sandbox a computer's run works in. */
4
+ export type OpenComputerSandbox = (input: {
5
+ /** The user's folder, for a turn; absent for a child, which works in a folder of its own. */
6
+ readonly workingDirectory?: string;
7
+ /** Where the run's own files go, outside the folder: its commands may write there too. */
8
+ readonly runFiles: string;
9
+ /** The run's token, which the sandbox adds outside its commands. */
10
+ readonly credential: SandboxRequestCredential;
11
+ readonly signal: AbortSignal;
12
+ }) => Promise<Sandbox>;
13
+ export interface ComputerRunnerOptions {
14
+ /** The project's API origin. */
15
+ readonly apiUrl: string;
16
+ /** The user's own credential, as an `Authorization` header value, read for each claim. */
17
+ authorization(): Promise<string>;
18
+ /**
19
+ * This computer, as each claim names it with the folder: a thread runs on one of its owner's
20
+ * computers, in one folder there, and only `sixb` open there claims its turns.
21
+ */
22
+ computer(): Promise<{
23
+ readonly id: string;
24
+ readonly name: string;
25
+ }>;
26
+ /** The folder the user's turns work in: its real path. */
27
+ readonly folder: string;
28
+ /**
29
+ * Where each run's own files go: a directory per thread, so every turn's prompt names the same
30
+ * paths, emptied when a run starts and removed when it ends. Shared by every runner on the
31
+ * computer, which hold a thread's directory one run at a time.
32
+ */
33
+ readonly runFilesRoot: string;
34
+ readonly openSandbox: OpenComputerSandbox;
35
+ /** How many children of one turn run at once. Defaults to 4. */
36
+ readonly childCapacity?: number;
37
+ /** A run that failed, once its end is recorded. */
38
+ readonly onFailure?: (error: unknown) => void;
39
+ readonly fetch?: (request: Request) => Promise<Response>;
40
+ }
41
+ export declare class ComputerRunner {
42
+ private readonly options;
43
+ private readonly teardowns;
44
+ /** Each running turn's renewal, by run id, to renew at once. */
45
+ private readonly renewals;
46
+ constructor(options: ComputerRunnerOptions);
47
+ /**
48
+ * Claim a queued turn and run it to its end. False when it was not this computer's to run: it
49
+ * ended already, or another runner holds it. `signal` stops the runner: the turn ends
50
+ * interrupted, its end recorded.
51
+ */
52
+ runTurn(runId: string, signal: AbortSignal, onClaimed?: (run: ConversationAgentRunRecord) => void): Promise<boolean>;
53
+ /**
54
+ * Renew a running turn's lease now rather than at its next renewal: its answer carries a cancel
55
+ * just asked for, so a stop from this computer takes effect at once.
56
+ */
57
+ renewNow(runId: string): void;
58
+ /** Wait for sandbox teardowns that outlived their runs. */
59
+ drain(): Promise<void>;
60
+ /**
61
+ * Renew the turn's lease, and its children's, until stopped. A renewal answers a cancel; one
62
+ * that finds the turn no longer this computer's stops it.
63
+ */
64
+ private renew;
65
+ private childRunner;
66
+ /**
67
+ * A run's sandbox: the user's folder for a turn, which the prompt describes, or a blank folder
68
+ * of its own for a child. Its own files go in its thread's directory, outside the folder: the
69
+ * prompt names them, so each run of the thread names the same paths.
70
+ */
71
+ private sandbox;
72
+ private track;
73
+ }
74
+ //# sourceMappingURL=computer-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computer-runner.d.ts","sourceRoot":"","sources":["../src/computer-runner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AASnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAA;AAapE,mDAAmD;AACnD,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE;IACxC,6FAA6F;IAC7F,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAClC,0FAA0F;IAC1F,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,oEAAoE;IACpE,QAAQ,CAAC,UAAU,EAAE,wBAAwB,CAAA;IAC7C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAEtB,MAAM,WAAW,qBAAqB;IACpC,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,0FAA0F;IAC1F,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;IAChC;;;OAGG;IACH,QAAQ,IAAI,OAAO,CAAC;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACnE,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAA;IACzC,gEAAgE;IAChE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B,mDAAmD;IACnD,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAC7C,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CACzD;AAOD,qBAAa,cAAc;IAKb,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2B;IACrD,gEAAgE;IAChE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;gBAE5B,OAAO,EAAE,qBAAqB;IAE3D;;;;OAIG;IACG,OAAO,CACX,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,WAAW,EACnB,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,0BAA0B,KAAK,IAAI,GACpD,OAAO,CAAC,OAAO,CAAC;IA+EnB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B,2DAA2D;IACrD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;OAGG;IACH,OAAO,CAAC,KAAK;IAsBb,OAAO,CAAC,WAAW;IAkCnB;;;;OAIG;IACH,OAAO,CAAC,OAAO;IA8Df,OAAO,CAAC,KAAK;CAId"}
@@ -0,0 +1,34 @@
1
+ import { type AgentContextBudget, type AgentModelSelection } from "@sixb/core/internal/agents";
2
+ import { type LanguageModel, type LanguageModelRequest } from "@sixb/core/models";
3
+ /**
4
+ * Derive the model's input and output budgets from its definition, and cap each call's output to
5
+ * them. The model comes pinned: whoever hands it over resolved it once for the run.
6
+ */
7
+ export declare function prepareAgentModel(selection: AgentModelSelection): {
8
+ readonly model: LanguageModel;
9
+ readonly budget: AgentContextBudget;
10
+ /**
11
+ * The bytes per token the run's latest counted call measured, bounded around the run's rate (the
12
+ * project's measurements and its own calls'), as calibration and the output ceiling read it.
13
+ * Undefined until a call is counted.
14
+ */
15
+ readonly measuredBytesPerToken: () => number | undefined;
16
+ };
17
+ /**
18
+ * What a call may write for what its input weighs: the room it leaves of the window, up to
19
+ * `capTokens`. The one measure the output ceiling and the guard size a call's answer by.
20
+ */
21
+ export declare function agentOutputRoomTokens(inputTokens: number, budget: AgentContextBudget, capTokens: number): number;
22
+ /**
23
+ * The least room a request past its model's limit is still sent with: what a compaction summary
24
+ * may write (see contextSummaryOutputTokens), the answer the framework already sizes as enough to
25
+ * carry a conversation on. With less, the turn ends with the context error rather than send a
26
+ * call whose answer would be cut off almost at once.
27
+ */
28
+ export declare function agentMinimumAnswerTokens(budget: AgentContextBudget): number;
29
+ /**
30
+ * A call's request as the conversation estimator weighs it (see measureAgentModelRequest), at
31
+ * `bytesPerToken`.
32
+ */
33
+ export declare function estimateAgentRequestTokens(request: Pick<LanguageModelRequest, "messages" | "tools" | "responseFormat">, bytesPerToken: number): number;
34
+ //# sourceMappingURL=context-budget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-budget.d.ts","sourceRoot":"","sources":["../src/context-budget.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,kBAAkB,EAEvB,KAAK,mBAAmB,EAUzB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAE1B,MAAM,mBAAmB,CAAA;AAE1B;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,mBAAmB,GAAG;IACjE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;IACnC;;;;OAIG;IACH,QAAQ,CAAC,qBAAqB,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;CACzD,CAyEA;AAuBD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,kBAAkB,EAC1B,SAAS,EAAE,MAAM,GAChB,MAAM,CAER;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAE3E;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,GAAG,OAAO,GAAG,gBAAgB,CAAC,EAC5E,aAAa,EAAE,MAAM,GACpB,MAAM,CAER"}
@@ -0,0 +1,148 @@
1
+ import { type AgentContextBudget, type AgentContextEstimateTool, type AgentRunSession, type AgentSystemPromptSize, type AgentThreadModelContextMessage, type AgentToolSpec, type AgentTurnHistory } from "@sixb/core/internal/agents";
2
+ import type { OntologyDocsIndexEntry } from "@sixb/core/internal/ontology";
3
+ import type { ModelCachingIntent, ModelMessage, ModelTool } from "@sixb/core/models";
4
+ import type { AgentContextCheckpointReason, ConversationAgentRunRecord, SubagentRunRecord } from "@sixb/core/storage";
5
+ import type { ConversationMemory } from "./conversation-memory";
6
+ import type { ResolvedAgentExecutionPlan } from "./execution-plan";
7
+ import { type ConversationReaders } from "./message-authors";
8
+ import { type LoadedAgentThreadModelContext } from "./thread-context";
9
+ import type { AgentTurnRuntime } from "./turn-runtime";
10
+ import type { AgentExecutionContext } from "./types";
11
+ /** What a turn's model calls start with: the prefix a summary of the conversation continues. */
12
+ export interface ConversationRequest {
13
+ readonly systemPrompt: string;
14
+ /** The same prompt with each section's bytes, when the environment rendered it. */
15
+ readonly systemPromptSize?: AgentSystemPromptSize;
16
+ readonly tools: readonly Pick<ModelTool, "name" | "description" | "inputSchema">[];
17
+ readonly messages: readonly ModelMessage[];
18
+ }
19
+ /**
20
+ * The request a turn's calls send for a history, built as the run's environment and its turn
21
+ * build it, with the memory its prompt shows.
22
+ */
23
+ export type BuildConversationRequest = (input: {
24
+ readonly threadContext: LoadedAgentThreadModelContext;
25
+ readonly memory: ConversationMemory | undefined;
26
+ }) => Promise<ConversationRequest>;
27
+ export interface PreparedAgentConversationContext {
28
+ readonly threadContext: LoadedAgentThreadModelContext;
29
+ /** The memory the run's prompt shows, as of the active checkpoint. */
30
+ readonly memory?: ConversationMemory;
31
+ /** The bytes per token the turn's history was measured at, when the preflight measured it. */
32
+ readonly bytesPerToken?: number;
33
+ }
34
+ /** Memory as of a checkpoint's creation, or of the thread's start when there is none. */
35
+ export type LoadConversationMemory = (checkpoint: {
36
+ readonly createdAt: Date;
37
+ } | null) => Promise<ConversationMemory | undefined>;
38
+ /** What a request carries besides its history, as an estimate counts it. */
39
+ export interface AgentContextEstimateShape {
40
+ readonly systemPrompt: string;
41
+ readonly tools: readonly AgentContextEstimateTool[];
42
+ /** Messages every request sends ahead of the history: a child's task, once summarized. */
43
+ readonly head?: readonly AgentThreadModelContextMessage[];
44
+ }
45
+ /**
46
+ * What a thread's compaction reads and writes through, before a run or during it: a
47
+ * conversation's, or a child's, whose thread is its history.
48
+ */
49
+ export interface AgentThreadCompactionInput {
50
+ readonly context: Pick<AgentExecutionContext, "id">;
51
+ /** The run's session: its history, the checkpoint it writes, and the records it publishes. */
52
+ readonly session: AgentRunSession;
53
+ readonly plan: ResolvedAgentExecutionPlan;
54
+ readonly budget: AgentContextBudget;
55
+ readonly run: ConversationAgentRunRecord | SubagentRunRecord;
56
+ readonly runtime: AgentTurnRuntime;
57
+ readonly loadMemory?: LoadConversationMemory;
58
+ /** The request the run would send for a history: what its summary continues. */
59
+ readonly conversationRequest: BuildConversationRequest;
60
+ /** What the run's requests carry besides a history, with the memory its prompt shows. */
61
+ readonly estimateShape: (threadContext: LoadedAgentThreadModelContext, memory: ConversationMemory | undefined) => AgentContextEstimateShape;
62
+ /** How the run's calls are cached: the summary is read as their continuation. */
63
+ readonly caching: ModelCachingIntent;
64
+ }
65
+ /** What a conversation's compaction reads and writes through, before its turn or during it. */
66
+ interface ConversationCompactionInput extends Omit<AgentThreadCompactionInput, "context" | "run" | "estimateShape" | "caching"> {
67
+ readonly context: AgentExecutionContext;
68
+ readonly run: ConversationAgentRunRecord;
69
+ /** The ontology files listed in the conversation's prompt. */
70
+ readonly ontologyIndex?: readonly OntologyDocsIndexEntry[];
71
+ /** Where the run's files go, as the prompt names them. */
72
+ readonly contextDirectory: string;
73
+ /** Who can read the run's thread: in a shared one, who wrote what counts toward the estimate. */
74
+ readonly conversation?: ConversationReaders;
75
+ readonly frameworkTools?: readonly ModelTool[];
76
+ }
77
+ /** Load, estimate, and—when required—compact one admitted conversational run before setup. */
78
+ export declare function prepareAgentConversationContext(input: ConversationCompactionInput & {
79
+ /** The conversation's history as the turn started. */
80
+ readonly history: AgentTurnHistory;
81
+ }): Promise<PreparedAgentConversationContext>;
82
+ /** What compacting a thread from within the run in flight is given. */
83
+ interface InRunCompaction {
84
+ /** The history the run works on: as it started, or as its compaction left it. */
85
+ readonly threadContext: LoadedAgentThreadModelContext;
86
+ /** The memory the run's prompt shows. */
87
+ readonly memory: ConversationMemory | undefined;
88
+ readonly reason: AgentContextCheckpointReason;
89
+ /** Whether the thread came back idle, its cache expired: see summarize. */
90
+ readonly coldCache: boolean;
91
+ }
92
+ /**
93
+ * Compact the conversation before the turn in flight, from within it: everything before the
94
+ * turn's own message is summarized, and the turn, its message and the steps it has taken, stays
95
+ * as it is. Undefined when there is nothing before the turn to summarize, when the run already
96
+ * compacted the thread (a run writes one checkpoint), or when the compaction failed: the turn
97
+ * then goes on with what it has.
98
+ */
99
+ export declare function compactAgentConversationInTurn(input: ConversationCompactionInput & InRunCompaction): Promise<PreparedAgentConversationContext | undefined>;
100
+ /**
101
+ * Compact a thread before the run in flight, from within it: everything before the message the
102
+ * run started from is summarized, and that message and the steps it took stay as they are. A
103
+ * conversation's turn, or a child continuing its thread. Undefined as for
104
+ * {@link compactAgentConversationInTurn}.
105
+ *
106
+ * Its estimates before and after weigh the same request, the history with the run's message,
107
+ * without the steps it keeps: what the summary replaced, not what the run is about to send.
108
+ */
109
+ export declare function compactAgentThreadInRun(input: AgentThreadCompactionInput & InRunCompaction): Promise<PreparedAgentConversationContext | undefined>;
110
+ /**
111
+ * Whether a run starts on a thread worth compacting though it fits: its last model call is older
112
+ * than the cache its calls ask for, so the next one rewrites the whole prompt anyway, the prompt
113
+ * is large enough for a summary to make that rewrite much smaller, and compacting brings it under
114
+ * that size, rather than summarize at every idle turn. A thread whose last call the session cannot
115
+ * date (none since its checkpoint) is not compacted for it.
116
+ */
117
+ export declare function shouldCompactIdleContext(input: {
118
+ readonly history: AgentTurnHistory;
119
+ readonly caching: ModelCachingIntent;
120
+ readonly estimatedInputTokens: number;
121
+ /** What the next request weighs once compacted: see compactedRequestTokens. */
122
+ readonly compactedTokens: number;
123
+ }): boolean;
124
+ /** What a thread weighs once compacted from within its run (see compactAgentThreadInRun). */
125
+ export declare function inRunCompactedTokens(input: {
126
+ readonly plan: ResolvedAgentExecutionPlan;
127
+ readonly budget: AgentContextBudget;
128
+ readonly threadContext: LoadedAgentThreadModelContext;
129
+ readonly estimateShape: AgentContextEstimateShape;
130
+ readonly bytesPerToken: number;
131
+ }): number;
132
+ /**
133
+ * The conversation's next request as the model will count it, and the bytes per token it was
134
+ * counted at (see estimateAgentThreadRequest): the run's history, at the rate its run started
135
+ * from, with the system prompt and tools its requests send.
136
+ */
137
+ export declare function estimateAgentConversation(input: AgentContextEstimateShape & {
138
+ readonly plan: ResolvedAgentExecutionPlan;
139
+ readonly budget: AgentContextBudget;
140
+ readonly threadContext: LoadedAgentThreadModelContext;
141
+ }): {
142
+ readonly tokens: number;
143
+ readonly bytesPerToken: number;
144
+ };
145
+ /** Tools as an estimate counts them: their schemas serialized as they are sent. */
146
+ export declare function contextEstimateTools(specs: readonly Pick<AgentToolSpec, "name" | "description" | "inputSchema">[]): readonly AgentContextEstimateTool[];
147
+ export {};
148
+ //# sourceMappingURL=context-compaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-compaction.d.ts","sourceRoot":"","sources":["../src/context-compaction.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,kBAAkB,EAEvB,KAAK,wBAAwB,EAE7B,KAAK,eA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
+ import { type ModelMessage, type ModelToolSpecification } from "@sixb/core/models";
3
+ import type { AgentContextCheckpointReason } from "@sixb/core/storage";
4
+ /** What a turn's requests start with in place of the turn's history, once it compacted. */
5
+ export type CompactConversationBeforeTurn = (input: {
6
+ readonly reason: AgentContextCheckpointReason;
7
+ }) => Promise<readonly ModelMessage[] | undefined>;
8
+ export interface AgentContextGuardInput {
9
+ /** Its `inputBudgetTokens` is the limit the turn's requests keep under. */
10
+ readonly budget: AgentContextBudget;
11
+ /** The tools every request sends. */
12
+ readonly tools: readonly ModelToolSpecification[];
13
+ /** The bytes per token the turn measured its history at, else the one its run started from. */
14
+ readonly bytesPerToken?: number;
15
+ /**
16
+ * What the run's latest counted call measured, around the run's rate (see prepareAgentModel):
17
+ * once there is one, the calls after it go by it, as the output ceiling does.
18
+ */
19
+ readonly measuredBytesPerToken?: () => number | undefined;
20
+ /** Tools whose results are never cleared. */
21
+ readonly excludeTools?: readonly string[];
22
+ /**
23
+ * Compacts what comes before the turn, once: the messages the turn's requests start with from
24
+ * then on, in place of those they started with. Undefined when it could not.
25
+ */
26
+ readonly compact?: CompactConversationBeforeTurn;
27
+ }
28
+ export interface AgentContextGuard {
29
+ /** Before each call: the request, reduced when it would cross the model's limit. */
30
+ readonly prepareStep: (input: PrepareModelStepInput) => Promise<PrepareModelStepResult | undefined>;
31
+ /** After a call the provider rejected as too long for the window: the request reduced to fit. */
32
+ readonly recoverStep: (input: RecoverModelStepInput) => Promise<PrepareModelStepResult | undefined>;
33
+ /**
34
+ * The first step whose request had tool results cleared or cut, which every later one keeps:
35
+ * those steps' usage weighs less than replaying the stored steps sends.
36
+ */
37
+ readonly reducedFromStep: () => number | undefined;
38
+ }
39
+ /**
40
+ * Keep every request of a model loop under the model's limit (the window less the output reserve),
41
+ * checked before each call from what the last call really read and what was added since. Right
42
+ * before a request would cross it:
43
+ *
44
+ * 1. clear the oldest tool results the model has read in one batch, down to
45
+ * {@link AGENT_CONTEXT_COMPACTED_SHARE} of the limit, when it frees at least a tenth of the
46
+ * limit ({@link CLEARED_AT_LEAST_SHARE}), enough to be worth the cache it breaks: the three most
47
+ * recent stay when clearing the older ones gets there, only the newest when it does not (see
48
+ * {@link KEPT_TOOL_RESULTS}), and the steps after it read the cleared request through;
49
+ * 2. else compact what came before the turn, once, and clear again what is still needed;
50
+ * 3. past the limit even so, clear as many of the results the model has read as it takes, the
51
+ * newest still kept, and cut those it has not read to fit.
52
+ *
53
+ * A result the model asks for again after it was cleared or cut is one the turn needs: it is
54
+ * neither cleared nor cut again, so a turn whose working set does not fit ends on the provider's
55
+ * refusal instead of reading and reducing the same results in turn.
56
+ *
57
+ * A call the provider rejects as too long for the window is measured at the window at least, and
58
+ * reduced the same way, compacting first when it can, for the loop to ask it again once.
59
+ *
60
+ * The first call has no call before it to go by: its whole request is estimated, at the rate the
61
+ * thread measured.
62
+ */
63
+ export declare function createAgentContextGuard(input: AgentContextGuardInput): AgentContextGuard;
64
+ /**
65
+ * A cleared tool result's note: the same bytes whenever it replaces that tool's result. A result
66
+ * saved to a file points at the file, which holds the whole of it, rather than at the call.
67
+ */
68
+ export declare function clearedToolResultText(toolName: string, savedPath?: string): string;
69
+ //# sourceMappingURL=context-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-guard.d.ts","sourceRoot":"","sources":["../src/context-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EAGvB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC3B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAIL,KAAK,YAAY,EAIjB,KAAK,sBAAsB,EAC5B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAA;AAiCtE,2FAA2F;AAC3F,MAAM,MAAM,6BAA6B,GAAG,CAAC,KAAK,EAAE;IAClD,QAAQ,CAAC,MAAM,EAAE,4BAA4B,CAAA;CAC9C,KAAK,OAAO,CAAC,SAAS,YAAY,EAAE,GAAG,SAAS,CAAC,CAAA;AAElD,MAAM,WAAW,sBAAsB;IACrC,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;IACnC,qCAAqC;IACrC,QAAQ,CAAC,KAAK,EAAE,SAAS,sBAAsB,EAAE,CAAA;IACjD,+FAA+F;IAC/F,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B;;;OAGG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;IACzD,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACzC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,6BAA6B,CAAA;CACjD;AAED,MAAM,WAAW,iBAAiB;IAChC,oFAAoF;IACpF,QAAQ,CAAC,WAAW,EAAE,CACpB,KAAK,EAAE,qBAAqB,KACzB,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC,CAAA;IAChD,iGAAiG;IACjG,QAAQ,CAAC,WAAW,EAAE,CACpB,KAAK,EAAE,qBAAqB,KACzB,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC,CAAA;IAChD;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;CACnD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,sBAAsB,GAAG,iBAAiB,CAOxF;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAIlF"}
@@ -0,0 +1,21 @@
1
+ import type { AgentMemoryRepoView } from "@sixb/core";
2
+ import type { AgentRunSession } from "@sixb/core/internal/agents";
3
+ import type { AgentMemoryPromptContext } from "./agent-prompt";
4
+ /** The Agent's memory for one conversational run. */
5
+ export interface ConversationMemory {
6
+ /** Installed under `$SIXB_MEMORY_DIR` at their latest revision, for the Agent to read and save. */
7
+ readonly repos: readonly AgentMemoryRepoView[];
8
+ /** Each repo's `MEMORY.md` as of the time the prompt is frozen at. */
9
+ readonly prompt: AgentMemoryPromptContext;
10
+ }
11
+ /**
12
+ * The repos the run's requester can read, through its session. The prompt shows each `MEMORY.md` as
13
+ * it was at `asOf`, the start of the thread or its latest compaction, so a save leaves the prompt
14
+ * and its cache as they are until the context is next compacted; the installed files are the
15
+ * latest.
16
+ */
17
+ export declare function loadConversationMemory(input: {
18
+ readonly session: Pick<AgentRunSession, "memory">;
19
+ readonly asOf: Date;
20
+ }): Promise<ConversationMemory | undefined>;
21
+ //# sourceMappingURL=conversation-memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation-memory.d.ts","sourceRoot":"","sources":["../src/conversation-memory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AAE9D,qDAAqD;AACrD,MAAM,WAAW,kBAAkB;IACjC,mGAAmG;IACnG,QAAQ,CAAC,KAAK,EAAE,SAAS,mBAAmB,EAAE,CAAA;IAC9C,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAA;CAC1C;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE;IAClD,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAA;IACjD,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CACpB,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAkB1C"}