@leuduan/lagent 0.0.0-stage → 0.1.2

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 (327) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +144 -2
  3. package/dist/chunks/2O7ZGEIT.js +1 -0
  4. package/dist/chunks/2OSESBIL.js +1 -0
  5. package/dist/chunks/34KW6VNQ.js +1 -0
  6. package/dist/chunks/37YOGDGY.js +1 -0
  7. package/dist/chunks/3LQHQRIU.js +6 -0
  8. package/dist/chunks/3QCW4WDJ.js +1 -0
  9. package/dist/chunks/4XVRUSCQ.js +1 -0
  10. package/dist/chunks/6ECI2GGV.js +1 -0
  11. package/dist/chunks/74HKUGRR.js +1 -0
  12. package/dist/chunks/ADHERZLW.js +2 -0
  13. package/dist/chunks/AP6Q4EPT.js +36 -0
  14. package/dist/chunks/BM3S37EZ.js +1 -0
  15. package/dist/chunks/C5LYCXJG.js +1 -0
  16. package/dist/chunks/CDQG7RKA.js +1 -0
  17. package/dist/chunks/D7E6EWIE.js +3 -0
  18. package/dist/chunks/DDANMY45.js +3 -0
  19. package/dist/chunks/DRYAN665.js +1 -0
  20. package/dist/chunks/DXFXAYDN.js +17 -0
  21. package/dist/chunks/EGZI4XQX.js +24 -0
  22. package/dist/chunks/ENWFSU27.js +41 -0
  23. package/dist/chunks/G6RXC3AL.js +1 -0
  24. package/dist/chunks/G74AGRAJ.js +15 -0
  25. package/dist/chunks/GQGNVSKB.js +1 -0
  26. package/dist/chunks/IJ2WNMD5.js +7 -0
  27. package/dist/chunks/J5S4URAW.js +1 -0
  28. package/dist/chunks/JPZFKSWT.js +1 -0
  29. package/dist/chunks/KESCTXGO.js +5 -0
  30. package/dist/chunks/L3N4FIEN.js +1 -0
  31. package/dist/chunks/NAOUTU7A.js +4 -0
  32. package/dist/chunks/NDIM7MEW.js +1 -0
  33. package/dist/chunks/O4PPOM5Z.js +2 -0
  34. package/dist/chunks/OVZFGILJ.js +1 -0
  35. package/dist/chunks/P5ZHHOOM.js +6 -0
  36. package/dist/chunks/PUSUPTAT.js +1 -0
  37. package/dist/chunks/QMMLQJBS.js +1 -0
  38. package/dist/chunks/RK3VP2Q4.js +3 -0
  39. package/dist/chunks/SGGMBSBA.js +1 -0
  40. package/dist/chunks/SL2YLB2F.js +1 -0
  41. package/dist/chunks/TOOIB6J2.js +1 -0
  42. package/dist/chunks/TYTQRLTX.js +1 -0
  43. package/dist/chunks/UC3FVVJ2.js +5 -0
  44. package/dist/chunks/UCTEU62F.js +1 -0
  45. package/dist/chunks/UD3VJER6.js +1 -0
  46. package/dist/chunks/UKXMCHHT.js +1 -0
  47. package/dist/chunks/WUUKTSRT.js +7 -0
  48. package/dist/chunks/X65X4KP5.js +7 -0
  49. package/dist/chunks/YIR5MYGU.js +1 -0
  50. package/dist/chunks/YLNJXQ3Z.js +1 -0
  51. package/dist/context.d.ts +101 -0
  52. package/dist/index.d.ts +47 -0
  53. package/dist/index.js +77 -0
  54. package/dist/journal/catalog.d.ts +112 -0
  55. package/dist/journal/forkChain.d.ts +16 -0
  56. package/dist/journal/index.d.ts +15 -0
  57. package/dist/journal/journal.d.ts +475 -0
  58. package/dist/journal/projection.d.ts +87 -0
  59. package/dist/journal/store.d.ts +181 -0
  60. package/dist/kit/claim.d.ts +13 -0
  61. package/dist/kit/drain.d.ts +10 -0
  62. package/dist/kit/extension.d.ts +180 -0
  63. package/dist/kit/grants.d.ts +9 -0
  64. package/dist/kit/modes.d.ts +65 -0
  65. package/dist/kit/retries.d.ts +25 -0
  66. package/dist/kit/scope.d.ts +32 -0
  67. package/dist/kit/service.d.ts +7 -0
  68. package/dist/kit/strategy.d.ts +10 -0
  69. package/dist/kit/timers.d.ts +43 -0
  70. package/dist/kit/tool.d.ts +72 -0
  71. package/dist/llm/client.d.ts +135 -0
  72. package/dist/llm/content.d.ts +52 -0
  73. package/dist/llm/door.d.ts +21 -0
  74. package/dist/llm/door.js +1 -0
  75. package/dist/llm/failure.d.ts +82 -0
  76. package/dist/llm/index.d.ts +16 -0
  77. package/dist/llm/primitives.d.ts +286 -0
  78. package/dist/llm/prompt.d.ts +21 -0
  79. package/dist/llm/provider.d.ts +63 -0
  80. package/dist/llm/readLedger.d.ts +24 -0
  81. package/dist/llm/request.d.ts +58 -0
  82. package/dist/loop/agent.d.ts +134 -0
  83. package/dist/loop/auxiliary.d.ts +54 -0
  84. package/dist/loop/chain.d.ts +46 -0
  85. package/dist/loop/chunks.d.ts +27 -0
  86. package/dist/loop/continuation.d.ts +166 -0
  87. package/dist/loop/decide.d.ts +64 -0
  88. package/dist/loop/errors.d.ts +162 -0
  89. package/dist/loop/forks.d.ts +61 -0
  90. package/dist/loop/holds.d.ts +104 -0
  91. package/dist/loop/hooks.d.ts +241 -0
  92. package/dist/loop/inbox.d.ts +188 -0
  93. package/dist/loop/index.d.ts +37 -0
  94. package/dist/loop/limits.d.ts +14 -0
  95. package/dist/loop/opening.d.ts +42 -0
  96. package/dist/loop/prepare.d.ts +30 -0
  97. package/dist/loop/projections.d.ts +307 -0
  98. package/dist/loop/replace.d.ts +33 -0
  99. package/dist/loop/requests.d.ts +129 -0
  100. package/dist/loop/route.d.ts +53 -0
  101. package/dist/loop/runtime.d.ts +85 -0
  102. package/dist/loop/state.d.ts +70 -0
  103. package/dist/loop/strategy.d.ts +71 -0
  104. package/dist/loop/summary.d.ts +3 -0
  105. package/dist/loop/surface.d.ts +153 -0
  106. package/dist/loop/threadState.d.ts +72 -0
  107. package/dist/loop/tool.d.ts +101 -0
  108. package/dist/loop/toolCalls.d.ts +42 -0
  109. package/dist/loop/wake.d.ts +32 -0
  110. package/dist/models/config/agent.d.ts +18 -0
  111. package/dist/models/config/prompt.d.ts +18 -0
  112. package/dist/models/door.d.ts +12 -0
  113. package/dist/models/door.js +1 -0
  114. package/dist/models/index.d.ts +7 -0
  115. package/dist/models/jsonSchema.d.ts +7 -0
  116. package/dist/models/wire/journal.d.ts +2772 -0
  117. package/dist/models/wire/primitives.d.ts +65 -0
  118. package/dist/plugin.d.ts +53 -0
  119. package/dist/plugin.js +1 -0
  120. package/dist/plugins/agentsMd.d.ts +76 -0
  121. package/dist/plugins/agentsMd.js +1 -0
  122. package/dist/plugins/ask/askQuestion.d.ts +9 -0
  123. package/dist/plugins/ask/index.d.ts +26 -0
  124. package/dist/plugins/ask/index.js +1 -0
  125. package/dist/plugins/ask/service.d.ts +125 -0
  126. package/dist/plugins/commands/background.d.ts +8 -0
  127. package/dist/plugins/commands/foreground.d.ts +4 -0
  128. package/dist/plugins/commands/index.d.ts +40 -0
  129. package/dist/plugins/commands/index.js +1 -0
  130. package/dist/plugins/commands/output.d.ts +115 -0
  131. package/dist/plugins/commands/record.d.ts +549 -0
  132. package/dist/plugins/commands/service.d.ts +314 -0
  133. package/dist/plugins/commands/shell.d.ts +25 -0
  134. package/dist/plugins/compaction/checkpoint.d.ts +91 -0
  135. package/dist/plugins/compaction/config.d.ts +133 -0
  136. package/dist/plugins/compaction/estimate.d.ts +29 -0
  137. package/dist/plugins/compaction/index.d.ts +2 -0
  138. package/dist/plugins/compaction/index.js +7 -0
  139. package/dist/plugins/compaction/log.d.ts +61 -0
  140. package/dist/plugins/compaction/planner.d.ts +207 -0
  141. package/dist/plugins/compaction/preset.d.ts +86 -0
  142. package/dist/plugins/compaction/prune.d.ts +9 -0
  143. package/dist/plugins/compaction/records.d.ts +227 -0
  144. package/dist/plugins/compaction/segments.d.ts +23 -0
  145. package/dist/plugins/compaction/shared.d.ts +14 -0
  146. package/dist/plugins/compaction/summarize.d.ts +13 -0
  147. package/dist/plugins/dateAndBranch.d.ts +47 -0
  148. package/dist/plugins/dateAndBranch.js +1 -0
  149. package/dist/plugins/delegations/answers.d.ts +39 -0
  150. package/dist/plugins/delegations/assignmentKey.d.ts +22 -0
  151. package/dist/plugins/delegations/cleanup.d.ts +161 -0
  152. package/dist/plugins/delegations/constraint.d.ts +76 -0
  153. package/dist/plugins/delegations/index.d.ts +39 -0
  154. package/dist/plugins/delegations/index.js +1 -0
  155. package/dist/plugins/delegations/notices.d.ts +261 -0
  156. package/dist/plugins/delegations/obligations.d.ts +210 -0
  157. package/dist/plugins/delegations/record.d.ts +632 -0
  158. package/dist/plugins/delegations/request.d.ts +381 -0
  159. package/dist/plugins/delegations/role.d.ts +30 -0
  160. package/dist/plugins/delegations/service.d.ts +562 -0
  161. package/dist/plugins/delegations/standing.d.ts +19 -0
  162. package/dist/plugins/delegations/stopCheck.d.ts +21 -0
  163. package/dist/plugins/delegations/testing.d.ts +16 -0
  164. package/dist/plugins/delegations/tools.d.ts +71 -0
  165. package/dist/plugins/delegations/waitBook.d.ts +116 -0
  166. package/dist/plugins/delegations/waits.d.ts +118 -0
  167. package/dist/plugins/diagnostics/digest.d.ts +14 -0
  168. package/dist/plugins/diagnostics/index.d.ts +68 -0
  169. package/dist/plugins/diagnostics/index.js +1 -0
  170. package/dist/plugins/historyRecall/history.d.ts +9 -0
  171. package/dist/plugins/historyRecall/index.d.ts +31 -0
  172. package/dist/plugins/historyRecall/index.js +1 -0
  173. package/dist/plugins/historyRecall/render.d.ts +34 -0
  174. package/dist/plugins/historyRecall/tools.d.ts +4 -0
  175. package/dist/plugins/mcp/catalog.d.ts +36 -0
  176. package/dist/plugins/mcp/config.d.ts +63 -0
  177. package/dist/plugins/mcp/connection.d.ts +53 -0
  178. package/dist/plugins/mcp/errors.d.ts +32 -0
  179. package/dist/plugins/mcp/index.d.ts +33 -0
  180. package/dist/plugins/mcp/index.js +5 -0
  181. package/dist/plugins/mcp/mount.d.ts +98 -0
  182. package/dist/plugins/mcp/names.d.ts +25 -0
  183. package/dist/plugins/mcp/render.d.ts +29 -0
  184. package/dist/plugins/mcp/slots.d.ts +15 -0
  185. package/dist/plugins/mcp/stdio.d.ts +49 -0
  186. package/dist/plugins/mcp/tool.d.ts +41 -0
  187. package/dist/plugins/providers/anthropic.d.ts +175 -0
  188. package/dist/plugins/providers/anthropicMessages.d.ts +65 -0
  189. package/dist/plugins/providers/codex.d.ts +60 -0
  190. package/dist/plugins/providers/codexAuth.d.ts +116 -0
  191. package/dist/plugins/providers/deepseek.d.ts +55 -0
  192. package/dist/plugins/providers/door.d.ts +61 -0
  193. package/dist/plugins/providers/door.js +1 -0
  194. package/dist/plugins/providers/failure.d.ts +23 -0
  195. package/dist/plugins/providers/gateway.d.ts +23 -0
  196. package/dist/plugins/providers/index.d.ts +6 -0
  197. package/dist/plugins/providers/openaiChat.d.ts +62 -0
  198. package/dist/plugins/providers/openaiResponses.d.ts +100 -0
  199. package/dist/plugins/providers/opencodeCopilot.d.ts +23 -0
  200. package/dist/plugins/providers/opencodeGo.d.ts +98 -0
  201. package/dist/plugins/providers/shared.d.ts +104 -0
  202. package/dist/plugins/providers/stream.d.ts +154 -0
  203. package/dist/plugins/routeContext.d.ts +22 -0
  204. package/dist/plugins/routeContext.js +1 -0
  205. package/dist/plugins/schedules/index.d.ts +21 -0
  206. package/dist/plugins/schedules/index.js +5 -0
  207. package/dist/plugins/schedules/record.d.ts +396 -0
  208. package/dist/plugins/schedules/service.d.ts +120 -0
  209. package/dist/plugins/schedules/time.d.ts +26 -0
  210. package/dist/plugins/schedules/tools.d.ts +6 -0
  211. package/dist/plugins/skills/discovery.d.ts +54 -0
  212. package/dist/plugins/skills/index.d.ts +31 -0
  213. package/dist/plugins/skills/index.js +1 -0
  214. package/dist/plugins/skills/tool.d.ts +11 -0
  215. package/dist/plugins/store/durableObject.d.ts +23 -0
  216. package/dist/plugins/store/durableObject.js +1 -0
  217. package/dist/plugins/store/durableObjectConnection.d.ts +27 -0
  218. package/dist/plugins/store/memory.d.ts +29 -0
  219. package/dist/plugins/store/sql.d.ts +59 -0
  220. package/dist/plugins/store/sqlite.d.ts +31 -0
  221. package/dist/plugins/store/sqlite.js +1 -0
  222. package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
  223. package/dist/plugins/subAgents/fork.d.ts +32 -0
  224. package/dist/plugins/subAgents/index.d.ts +67 -0
  225. package/dist/plugins/subAgents/index.js +1 -0
  226. package/dist/plugins/subAgents/tool.d.ts +38 -0
  227. package/dist/plugins/toolPolicy/index.d.ts +61 -0
  228. package/dist/plugins/toolPolicy/index.js +1 -0
  229. package/dist/plugins/tools/editFiles.d.ts +128 -0
  230. package/dist/plugins/tools/fsRead.d.ts +17 -0
  231. package/dist/plugins/tools/html.d.ts +23 -0
  232. package/dist/plugins/tools/index.d.ts +59 -0
  233. package/dist/plugins/tools/index.js +1 -0
  234. package/dist/plugins/tools/network.d.ts +23 -0
  235. package/dist/plugins/tools/ripgrep.d.ts +20 -0
  236. package/dist/plugins/tools/textEdit.d.ts +67 -0
  237. package/dist/plugins/tools/web.d.ts +32 -0
  238. package/dist/plugins/truncateToolOutput.d.ts +26 -0
  239. package/dist/plugins/truncateToolOutput.js +1 -0
  240. package/dist/plugins/usage/index.d.ts +24 -0
  241. package/dist/plugins/usage/index.js +1 -0
  242. package/dist/plugins/usage/tracker.d.ts +34 -0
  243. package/dist/plugins/verify/facts.d.ts +356 -0
  244. package/dist/plugins/verify/index.d.ts +75 -0
  245. package/dist/plugins/verify/index.js +1 -0
  246. package/dist/plugins/verify/service.d.ts +90 -0
  247. package/dist/plugins/workflows/assignment.d.ts +16 -0
  248. package/dist/plugins/workflows/bindings.d.ts +95 -0
  249. package/dist/plugins/workflows/cleanup.d.ts +38 -0
  250. package/dist/plugins/workflows/definition.d.ts +184 -0
  251. package/dist/plugins/workflows/fold.d.ts +373 -0
  252. package/dist/plugins/workflows/index.d.ts +28 -0
  253. package/dist/plugins/workflows/index.js +6 -0
  254. package/dist/plugins/workflows/observations.d.ts +81 -0
  255. package/dist/plugins/workflows/participants.d.ts +143 -0
  256. package/dist/plugins/workflows/policy.d.ts +112 -0
  257. package/dist/plugins/workflows/providers.d.ts +146 -0
  258. package/dist/plugins/workflows/record.d.ts +2863 -0
  259. package/dist/plugins/workflows/routing.d.ts +116 -0
  260. package/dist/plugins/workflows/schema.d.ts +26 -0
  261. package/dist/plugins/workflows/service.d.ts +477 -0
  262. package/dist/plugins/workflows/submit.d.ts +8 -0
  263. package/dist/plugins/workflows/view.d.ts +103 -0
  264. package/dist/plugins/workflows/work.d.ts +21 -0
  265. package/dist/plugins/workspaceContext.d.ts +38 -0
  266. package/dist/plugins/workspaceContext.js +1 -0
  267. package/dist/presets/agents.d.ts +7 -0
  268. package/dist/presets/base.d.ts +10 -0
  269. package/dist/presets/codex.d.ts +60 -0
  270. package/dist/presets/index.d.ts +4 -0
  271. package/dist/presets/prompts.d.ts +56 -0
  272. package/dist/sandbox/absent.d.ts +32 -0
  273. package/dist/sandbox/client.d.ts +39 -0
  274. package/dist/sandbox/files.d.ts +28 -0
  275. package/dist/sandbox/index.d.ts +49 -0
  276. package/dist/sandbox/index.js +4 -0
  277. package/dist/sandbox/mode.d.ts +57 -0
  278. package/dist/sandbox/policy.d.ts +86 -0
  279. package/dist/sandbox/protocol.d.ts +107 -0
  280. package/dist/sandbox/service.d.ts +143 -0
  281. package/dist/sandbox/worker.d.ts +12 -0
  282. package/dist/sandbox/worker.js +1 -0
  283. package/dist/services/admission.d.ts +174 -0
  284. package/dist/services/agents.d.ts +37 -0
  285. package/dist/services/birth.d.ts +220 -0
  286. package/dist/services/contributions.d.ts +73 -0
  287. package/dist/services/core.d.ts +34 -0
  288. package/dist/services/journal.d.ts +26 -0
  289. package/dist/services/launches.d.ts +104 -0
  290. package/dist/services/llm.d.ts +80 -0
  291. package/dist/services/owner.d.ts +367 -0
  292. package/dist/services/preset.d.ts +154 -0
  293. package/dist/services/presets.d.ts +139 -0
  294. package/dist/services/prompts.d.ts +67 -0
  295. package/dist/services/runEvents.d.ts +79 -0
  296. package/dist/services/thread.d.ts +267 -0
  297. package/dist/services/threadActivation.d.ts +100 -0
  298. package/dist/services/threadDirs.d.ts +38 -0
  299. package/dist/services/threadView.d.ts +92 -0
  300. package/dist/services/threads.d.ts +449 -0
  301. package/dist/services/tools.d.ts +41 -0
  302. package/dist/sys/environment.d.ts +47 -0
  303. package/dist/sys/git.d.ts +60 -0
  304. package/dist/sys/paths.d.ts +56 -0
  305. package/dist/sys/spawn.d.ts +176 -0
  306. package/dist/testing/clock.d.ts +17 -0
  307. package/dist/testing/fakeLlm.d.ts +74 -0
  308. package/dist/testing/fedLlm.d.ts +32 -0
  309. package/dist/testing/helpers.d.ts +344 -0
  310. package/dist/testing/index.d.ts +13 -0
  311. package/dist/testing/index.js +1 -0
  312. package/dist/testing/processes.d.ts +13 -0
  313. package/dist/testing/sandbox.d.ts +71 -0
  314. package/dist/testing/settlement.d.ts +6 -0
  315. package/dist/testing/tmpDirs.d.ts +17 -0
  316. package/dist/util/async.d.ts +8 -0
  317. package/dist/util/diff.d.ts +25 -0
  318. package/dist/util/dispatch.d.ts +8 -0
  319. package/dist/util/errors.d.ts +28 -0
  320. package/dist/util/foldState.d.ts +17 -0
  321. package/dist/util/freeze.d.ts +2 -0
  322. package/dist/util/ids.d.ts +2 -0
  323. package/dist/util/json.d.ts +37 -0
  324. package/dist/util/log.d.ts +6 -0
  325. package/dist/util/text.d.ts +21 -0
  326. package/dist/util/version.d.ts +2 -0
  327. package/package.json +175 -3
@@ -0,0 +1,286 @@
1
+ import { z } from 'zod';
2
+ import type { DeepReadonly } from '../util/json.js';
3
+ export declare const THINKING_EFFORT_VALUES: readonly ["none", "low", "medium", "high", "max"];
4
+ export type ThinkingEffort = (typeof THINKING_EFFORT_VALUES)[number];
5
+ export declare const ThinkingEffortSchema: z.ZodEnum<{
6
+ low: "low";
7
+ high: "high";
8
+ none: "none";
9
+ medium: "medium";
10
+ max: "max";
11
+ }>;
12
+ export type JsonObject = Record<string, unknown>;
13
+ export declare const JsonObjectSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
14
+ export declare const defaultInputSchema: () => JsonObject;
15
+ export declare const ToolSpecSchema: z.ZodPipe<z.ZodObject<{
16
+ name: z.ZodString;
17
+ description: z.ZodDefault<z.ZodString>;
18
+ input_schema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
19
+ }, z.core.$strip>, z.ZodTransform<{
20
+ input_schema: JsonObject;
21
+ name: string;
22
+ description: string;
23
+ }, {
24
+ name: string;
25
+ description: string;
26
+ input_schema: Record<string, unknown>;
27
+ }>>;
28
+ export type ToolSpec = z.infer<typeof ToolSpecSchema>;
29
+ /** A tool call whose arguments parsed to an object: the only kind a tool, a policy or a confirmation sees. */
30
+ export declare const ParsedToolCallSchema: z.ZodObject<{
31
+ call_id: z.ZodString;
32
+ name: z.ZodString;
33
+ arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
34
+ }, z.core.$loose>;
35
+ export type ParsedToolCall = z.infer<typeof ParsedToolCallSchema>;
36
+ /**
37
+ * A tool call whose arguments are not a JSON object: `arguments` is `null`, and `malformed` keeps the
38
+ * text the model sent and why it failed. The loop answers it with an error result and never runs it;
39
+ * the provider is handed back the raw text it sent.
40
+ */
41
+ export declare const MalformedToolCallSchema: z.ZodObject<{
42
+ call_id: z.ZodString;
43
+ name: z.ZodString;
44
+ arguments: z.ZodNull;
45
+ malformed: z.ZodObject<{
46
+ raw: z.ZodString;
47
+ error: z.ZodString;
48
+ }, z.core.$strict>;
49
+ }, z.core.$loose>;
50
+ export type MalformedToolCall = z.infer<typeof MalformedToolCallSchema>;
51
+ /** A tool call as the model emitted it. Extra keys are allowed so provider-specific fields survive checkpoints. */
52
+ export declare const ToolCallSchema: z.ZodUnion<readonly [z.ZodObject<{
53
+ call_id: z.ZodString;
54
+ name: z.ZodString;
55
+ arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
56
+ }, z.core.$loose>, z.ZodObject<{
57
+ call_id: z.ZodString;
58
+ name: z.ZodString;
59
+ arguments: z.ZodNull;
60
+ malformed: z.ZodObject<{
61
+ raw: z.ZodString;
62
+ error: z.ZodString;
63
+ }, z.core.$strict>;
64
+ }, z.core.$loose>]>;
65
+ export type ToolCall = ParsedToolCall | MalformedToolCall;
66
+ /** Whether a call's arguments parsed. */
67
+ export declare const isParsedToolCall: (call: ToolCall) => call is ParsedToolCall;
68
+ /** A call's arguments as text, as the model sent them: the raw text of a malformed call, JSON otherwise. */
69
+ export declare const toolCallArgumentsText: (call: ToolCall) => string;
70
+ export declare const LLMUsageSchema: z.ZodObject<{
71
+ input_tokens: z.ZodDefault<z.ZodNumber>;
72
+ output_tokens: z.ZodDefault<z.ZodNumber>;
73
+ cache_read_input_tokens: z.ZodDefault<z.ZodNumber>;
74
+ cache_write_input_tokens: z.ZodDefault<z.ZodNumber>;
75
+ reasoning_output_tokens: z.ZodDefault<z.ZodNumber>;
76
+ }, z.core.$strip>;
77
+ export type LLMUsage = z.infer<typeof LLMUsageSchema>;
78
+ export declare const usageTotalTokens: (usage: LLMUsage) => number;
79
+ /**
80
+ * A tool call the *provider* ran: a web search or code interpreter.
81
+ *
82
+ * Descriptive only. The engine never dispatches one and is never owed a result for it — it came
83
+ * back already answered, and it replays out of `provider_state`, not from here. This exists so a
84
+ * transcript can show what the model did instead of a gap between two blocks of text.
85
+ */
86
+ export declare const ProviderCallSchema: z.ZodObject<{
87
+ id: z.ZodString;
88
+ type: z.ZodString;
89
+ name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
90
+ status: z.ZodDefault<z.ZodEnum<{
91
+ in_progress: "in_progress";
92
+ completed: "completed";
93
+ failed: "failed";
94
+ }>>;
95
+ summary: z.ZodDefault<z.ZodNullable<z.ZodString>>;
96
+ }, z.core.$loose>;
97
+ export type ProviderCall = z.infer<typeof ProviderCallSchema>;
98
+ export declare const LLMStreamChunkSchema: z.ZodObject<{
99
+ text_delta: z.ZodDefault<z.ZodString>;
100
+ reasoning_delta: z.ZodDefault<z.ZodString>;
101
+ provider_call: z.ZodDefault<z.ZodNullable<z.ZodObject<{
102
+ id: z.ZodString;
103
+ type: z.ZodString;
104
+ name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
105
+ status: z.ZodDefault<z.ZodEnum<{
106
+ in_progress: "in_progress";
107
+ completed: "completed";
108
+ failed: "failed";
109
+ }>>;
110
+ summary: z.ZodDefault<z.ZodNullable<z.ZodString>>;
111
+ }, z.core.$loose>>>;
112
+ }, z.core.$strip>;
113
+ export type LLMStreamChunk = z.infer<typeof LLMStreamChunkSchema>;
114
+ /**
115
+ * What a provider needs back verbatim on the next request — encrypted reasoning, item ids, signed
116
+ * blocks. Tagged with the provider that wrote it, so another one ignores it rather than replaying
117
+ * a shape it does not understand.
118
+ */
119
+ export declare const ProviderStateSchema: z.ZodObject<{
120
+ provider: z.ZodString;
121
+ data: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
122
+ }, z.core.$strip>;
123
+ export type ProviderState = z.infer<typeof ProviderStateSchema>;
124
+ export declare const MESSAGE_ROLES: readonly ["system", "developer", "user", "assistant", "tool"];
125
+ export type MessageRole = (typeof MESSAGE_ROLES)[number];
126
+ export declare const ConversationMessageSchema: z.ZodObject<{
127
+ role: z.ZodEnum<{
128
+ system: "system";
129
+ developer: "developer";
130
+ user: "user";
131
+ assistant: "assistant";
132
+ tool: "tool";
133
+ }>;
134
+ content: z.ZodPreprocess<z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
135
+ type: z.ZodLiteral<"text">;
136
+ text: z.ZodString;
137
+ }, z.core.$strip>, z.ZodObject<{
138
+ type: z.ZodLiteral<"image">;
139
+ url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
140
+ data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
141
+ media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
142
+ detail: z.ZodDefault<z.ZodEnum<{
143
+ auto: "auto";
144
+ low: "low";
145
+ high: "high";
146
+ }>>;
147
+ }, z.core.$strip>, z.ZodObject<{
148
+ type: z.ZodLiteral<"file">;
149
+ file_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
150
+ url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
151
+ data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
152
+ filename: z.ZodDefault<z.ZodNullable<z.ZodString>>;
153
+ media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
154
+ }, z.core.$strip>], "type">>>, unknown>;
155
+ reasoning_content: z.ZodDefault<z.ZodNullable<z.ZodString>>;
156
+ tool_calls: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
157
+ call_id: z.ZodString;
158
+ name: z.ZodString;
159
+ arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
160
+ }, z.core.$loose>, z.ZodObject<{
161
+ call_id: z.ZodString;
162
+ name: z.ZodString;
163
+ arguments: z.ZodNull;
164
+ malformed: z.ZodObject<{
165
+ raw: z.ZodString;
166
+ error: z.ZodString;
167
+ }, z.core.$strict>;
168
+ }, z.core.$loose>]>>>;
169
+ provider_calls: z.ZodDefault<z.ZodArray<z.ZodObject<{
170
+ id: z.ZodString;
171
+ type: z.ZodString;
172
+ name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
173
+ status: z.ZodDefault<z.ZodEnum<{
174
+ in_progress: "in_progress";
175
+ completed: "completed";
176
+ failed: "failed";
177
+ }>>;
178
+ summary: z.ZodDefault<z.ZodNullable<z.ZodString>>;
179
+ }, z.core.$loose>>>;
180
+ tool_call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
181
+ usage: z.ZodDefault<z.ZodNullable<z.ZodObject<{
182
+ input_tokens: z.ZodDefault<z.ZodNumber>;
183
+ output_tokens: z.ZodDefault<z.ZodNumber>;
184
+ cache_read_input_tokens: z.ZodDefault<z.ZodNumber>;
185
+ cache_write_input_tokens: z.ZodDefault<z.ZodNumber>;
186
+ reasoning_output_tokens: z.ZodDefault<z.ZodNumber>;
187
+ }, z.core.$strip>>>;
188
+ provider_state: z.ZodDefault<z.ZodNullable<z.ZodObject<{
189
+ provider: z.ZodString;
190
+ data: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
191
+ }, z.core.$strip>>>;
192
+ }, z.core.$strip>;
193
+ export type ConversationMessage = z.infer<typeof ConversationMessageSchema>;
194
+ export declare const conversationMessage: (fields: z.input<typeof ConversationMessageSchema>) => ConversationMessage;
195
+ /** The text of a message. The one way to read content, so widening it stays a change in one place. */
196
+ export declare const messageText: (message: DeepReadonly<ConversationMessage>) => string;
197
+ /**
198
+ * Why a response stopped, normalized so a consumer can tell a truncated response without reading
199
+ * any provider's own fields: `completed` when the model finished its message (tool calls included),
200
+ * `length` when it hit the output-token cap, `other` for anything else, a cut-off stream, a content
201
+ * filter or a reason the provider did not say. Each provider maps its own; the raw fields stay in
202
+ * `provider_metadata`.
203
+ */
204
+ export declare const RESPONSE_FINISHES: readonly ["completed", "length", "other"];
205
+ export type ResponseFinish = (typeof RESPONSE_FINISHES)[number];
206
+ export declare const ResponseFinishSchema: z.ZodEnum<{
207
+ length: "length";
208
+ completed: "completed";
209
+ other: "other";
210
+ }>;
211
+ export declare const ModelResponseSchema: z.ZodObject<{
212
+ message: z.ZodObject<{
213
+ role: z.ZodEnum<{
214
+ system: "system";
215
+ developer: "developer";
216
+ user: "user";
217
+ assistant: "assistant";
218
+ tool: "tool";
219
+ }>;
220
+ content: z.ZodPreprocess<z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
221
+ type: z.ZodLiteral<"text">;
222
+ text: z.ZodString;
223
+ }, z.core.$strip>, z.ZodObject<{
224
+ type: z.ZodLiteral<"image">;
225
+ url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
226
+ data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
227
+ media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
228
+ detail: z.ZodDefault<z.ZodEnum<{
229
+ auto: "auto";
230
+ low: "low";
231
+ high: "high";
232
+ }>>;
233
+ }, z.core.$strip>, z.ZodObject<{
234
+ type: z.ZodLiteral<"file">;
235
+ file_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
236
+ url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
237
+ data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
238
+ filename: z.ZodDefault<z.ZodNullable<z.ZodString>>;
239
+ media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
240
+ }, z.core.$strip>], "type">>>, unknown>;
241
+ reasoning_content: z.ZodDefault<z.ZodNullable<z.ZodString>>;
242
+ tool_calls: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
243
+ call_id: z.ZodString;
244
+ name: z.ZodString;
245
+ arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
246
+ }, z.core.$loose>, z.ZodObject<{
247
+ call_id: z.ZodString;
248
+ name: z.ZodString;
249
+ arguments: z.ZodNull;
250
+ malformed: z.ZodObject<{
251
+ raw: z.ZodString;
252
+ error: z.ZodString;
253
+ }, z.core.$strict>;
254
+ }, z.core.$loose>]>>>;
255
+ provider_calls: z.ZodDefault<z.ZodArray<z.ZodObject<{
256
+ id: z.ZodString;
257
+ type: z.ZodString;
258
+ name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
259
+ status: z.ZodDefault<z.ZodEnum<{
260
+ in_progress: "in_progress";
261
+ completed: "completed";
262
+ failed: "failed";
263
+ }>>;
264
+ summary: z.ZodDefault<z.ZodNullable<z.ZodString>>;
265
+ }, z.core.$loose>>>;
266
+ tool_call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
267
+ usage: z.ZodDefault<z.ZodNullable<z.ZodObject<{
268
+ input_tokens: z.ZodDefault<z.ZodNumber>;
269
+ output_tokens: z.ZodDefault<z.ZodNumber>;
270
+ cache_read_input_tokens: z.ZodDefault<z.ZodNumber>;
271
+ cache_write_input_tokens: z.ZodDefault<z.ZodNumber>;
272
+ reasoning_output_tokens: z.ZodDefault<z.ZodNumber>;
273
+ }, z.core.$strip>>>;
274
+ provider_state: z.ZodDefault<z.ZodNullable<z.ZodObject<{
275
+ provider: z.ZodString;
276
+ data: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
277
+ }, z.core.$strip>>>;
278
+ }, z.core.$strip>;
279
+ finish: z.ZodEnum<{
280
+ length: "length";
281
+ completed: "completed";
282
+ other: "other";
283
+ }>;
284
+ provider_metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
285
+ }, z.core.$strip>;
286
+ export type ModelResponse = z.infer<typeof ModelResponseSchema>;
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * One block of a system prompt, in the order it is sent.
4
+ *
5
+ * The prompt reaches a provider as blocks rather than one string because where it goes is the
6
+ * provider's business — Responses has `instructions`, Chat Completions wants a leading message,
7
+ * Anthropic a top-level param — and because the boundary between the stable blocks and the
8
+ * volatile ones is where a provider with explicit cache control would cut.
9
+ */
10
+ export declare const PromptBlockSchema: z.ZodObject<{
11
+ kind: z.ZodEnum<{
12
+ base: "base";
13
+ instruction: "instruction";
14
+ context: "context";
15
+ }>;
16
+ tag: z.ZodNullable<z.ZodString>;
17
+ text: z.ZodString;
18
+ }, z.core.$strip>;
19
+ export type PromptBlock = z.infer<typeof PromptBlockSchema>;
20
+ /** Joins blocks for an API that takes one string. */
21
+ export declare const renderPromptBlocks: (blocks: readonly PromptBlock[]) => string;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The provider contract: what a model provider gives the engine, and the route a turn runs on. Here,
3
+ * beside the client contract, so a provider is written against the model layer alone.
4
+ */
5
+ import { z } from 'zod';
6
+ import type { LLMClient, ModelCapacity, ModelOption } from './client.js';
7
+ import type { FailureClassification } from './failure.js';
8
+ import { type ThinkingEffort } from './primitives.js';
9
+ /**
10
+ * The model a turn runs on, with every field resolved: what `run()` named, merged over the thread's
11
+ * last route, then the registry's defaults. A `thinking_effort` of `null` leaves the effort to the
12
+ * provider's own default.
13
+ */
14
+ export declare const ModelRouteSchema: z.ZodObject<{
15
+ provider: z.ZodString;
16
+ model: z.ZodString;
17
+ thinking_effort: z.ZodNullable<z.ZodEnum<{
18
+ low: "low";
19
+ high: "high";
20
+ none: "none";
21
+ medium: "medium";
22
+ max: "max";
23
+ }>>;
24
+ }, z.core.$strip>;
25
+ export type ModelRoute = z.infer<typeof ModelRouteSchema>;
26
+ /** A model provider plugin registers one of these. */
27
+ export interface LLMProvider {
28
+ readonly name: string;
29
+ readonly defaultModel: string;
30
+ /**
31
+ * The effort a route gets when nothing names one, resolved into the route (`routeOn`); absent, the
32
+ * route's effort is `null`. Declare the effort the client is built with: a request that carries none
33
+ * is sent at the client's own default.
34
+ */
35
+ readonly defaultThinkingEffort?: ThinkingEffort;
36
+ /** The models agents are told about. A declaration, not a restriction; absent tells only `defaultModel`. */
37
+ readonly models?: readonly ModelOption[];
38
+ /**
39
+ * What the provider can carry for `model`: its usable context window, `null` where the provider
40
+ * declares none, and whether a request may carry provider-executed tools. Answers for any model
41
+ * the provider can be asked for, told or not; `models` is what agents are told, not this lookup.
42
+ */
43
+ capacity(model: string): ModelCapacity;
44
+ /**
45
+ * The provider's one client, built from its own configuration; the engine asks once and keeps it
46
+ * until the provider is withdrawn. Every request carries its route's effort when that is not `null`;
47
+ * one that carries none is sent at the client's configured effort, else the protocol's own.
48
+ */
49
+ createClient(): LLMClient;
50
+ /**
51
+ * The kind of a failure its client threw that the engine's typed evidence does not already decide
52
+ * (a settlement failure, a `ContextOverflowError`): HTTP statuses, transport errors, a stream's
53
+ * error codes. `retryAfterMs` comes from structured fields only. Unknown is `other`.
54
+ */
55
+ classify(error: unknown): FailureClassification;
56
+ }
57
+ /**
58
+ * The route a turn gets on `provider` when nothing names a model or an effort. Needs no registry,
59
+ * so a host can read a provider's defaults before deciding whether to register it.
60
+ */
61
+ export declare const defaultRoute: (provider: LLMProvider) => ModelRoute;
62
+ /** A route on `provider`, taking its defaults for what is not named. */
63
+ export declare const routeOn: (provider: LLMProvider, model: string | undefined, effort: ThinkingEffort | undefined) => ModelRoute;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The bookkeeping of when a response's read has ended, which `StreamingLLMResponse` states and every
3
+ * implementation of it (an adapter's stream, a call through `ctx.llm`, a test double) keeps: a read
4
+ * ends only when its generator has finished, or the read was closed, and no operation the reader
5
+ * asked for (`next`, `return`, `throw`) is still pending, so a closure queued behind a pending
6
+ * `next` keeps it under way however early the generator itself finished.
7
+ */
8
+ export declare class ReadLedger {
9
+ private pending;
10
+ private finished;
11
+ private over;
12
+ /** Whether the read has ended: finished, with nothing pending. */
13
+ get ended(): boolean;
14
+ /**
15
+ * Runs one operation the reader asked for and counts it out only once the promise the reader
16
+ * holds has settled, never before: a read that is over while its own `return` still reads as
17
+ * pending would let settlement in too early. `closes` marks the generator finished with it, as a
18
+ * `return` or `throw` finishes one that never started.
19
+ */
20
+ operation<T>(run: () => Promise<T>, closes?: boolean): Promise<T>;
21
+ /** The generator finished (ran through, failed or was closed), or an unread attempt was closed. */
22
+ finish(): void;
23
+ private check;
24
+ }
@@ -0,0 +1,58 @@
1
+ import type { DeepReadonly } from '../util/json.js';
2
+ import type { ConversationMessage, JsonObject, ThinkingEffort, ToolSpec } from './primitives.js';
3
+ import type { PromptBlock } from './prompt.js';
4
+ /** How the model may use tools this call. `{ name }` forces one. */
5
+ export type ToolChoice = 'auto' | 'none' | 'required' | {
6
+ name: string;
7
+ };
8
+ /**
9
+ * Why a request is sent: a model step of the thread's conversation, or an auxiliary call a plugin
10
+ * makes beside it, whose reply is never the thread's. Correlation, so middleware that counts,
11
+ * retries or logs per request can tell the two apart; never configuration.
12
+ */
13
+ export type RequestPurpose = 'step' | 'auxiliary';
14
+ /** What the model's text must be. `json_schema` is the named, validated form. */
15
+ export type ResponseFormat = {
16
+ kind: 'text';
17
+ } | {
18
+ kind: 'json_object';
19
+ } | {
20
+ kind: 'json_schema';
21
+ name: string;
22
+ schema: JsonObject;
23
+ strict: boolean;
24
+ };
25
+ /**
26
+ * One model call, as it will be sent.
27
+ *
28
+ * Middleware and providers use this same shape. The engine isolates the middleware draft from
29
+ * canonical history, then snapshots its final value, frozen, for journal recording and the provider.
30
+ * The data in it is shared and readonly all the way down: middleware replaces a field (the messages,
31
+ * the tools, the prompt blocks) rather than changing what is in it, and a provider reads it.
32
+ */
33
+ export interface ModelRequest {
34
+ messages: readonly DeepReadonly<ConversationMessage>[];
35
+ model: string;
36
+ tools: readonly DeepReadonly<ToolSpec>[];
37
+ /**
38
+ * Provider-executed tool definitions, passed through verbatim (`{ type: 'web_search' }`, …).
39
+ * The engine never dispatches one; what it did comes back as
40
+ * `ConversationMessage.provider_calls`.
41
+ */
42
+ providerTools: readonly DeepReadonly<JsonObject>[];
43
+ toolChoice: DeepReadonly<ToolChoice>;
44
+ parallelToolCalls: boolean;
45
+ responseFormat: DeepReadonly<ResponseFormat>;
46
+ /** Overrides the client's own default for this call; absent means the provider decides. */
47
+ thinkingEffort?: ThinkingEffort;
48
+ maxOutputTokens?: number;
49
+ /** The system prompt, carried beside the conversation rather than as its first message. */
50
+ systemPrompt: readonly DeepReadonly<PromptBlock>[];
51
+ readonly signal: AbortSignal;
52
+ /** Correlation, not configuration: a provider may key a prompt cache on these. */
53
+ readonly agentName: string;
54
+ readonly threadId: string;
55
+ readonly llmCallId: string;
56
+ /** Correlation like the ids above, so read-only to middleware and left out of the head digest. */
57
+ readonly purpose: RequestPurpose;
58
+ }
@@ -0,0 +1,134 @@
1
+ import type { Seq, TurnEndReason } from '../models/index.js';
2
+ import type { DeepReadonly, JsonValue } from '../util/json.js';
3
+ import type { SurfacePrepareOutcome } from './hooks.js';
4
+ import type { Lease, LoopRuntime } from './runtime.js';
5
+ /**
6
+ * What one `compact()` is given: a cancellation signal, and options for the strategy, which the
7
+ * engine passes on as they are and never reads.
8
+ */
9
+ export type CompactOptions = {
10
+ readonly signal?: AbortSignal;
11
+ readonly options?: JsonValue;
12
+ };
13
+ /**
14
+ * The run request an execution serves, as its turns see it: the id every `turn/start` records, the
15
+ * attempt cutoff of the execution, and the continuation decision, asked after each turn whether to
16
+ * open another.
17
+ */
18
+ export type ServedRun = {
19
+ readonly id: string;
20
+ readonly attemptCutoff: Seq;
21
+ continueAfter(ending: DeepReadonly<TurnEndReason>, turnStart: Seq): boolean;
22
+ };
23
+ /** Executes journal-driven turns. Admission, readiness and cancellation ownership live outside the loop. */
24
+ export declare class LoopAgent {
25
+ private readonly runtime;
26
+ private readonly threadId;
27
+ private readonly agentName;
28
+ private readonly inbox;
29
+ constructor(options: {
30
+ runtime: LoopRuntime;
31
+ threadId: string;
32
+ agentName: string;
33
+ });
34
+ private stepsTaken;
35
+ /**
36
+ * The caller already owns the lease, has resolved the agent in a ready runtime, has decided the
37
+ * run should advance, and supplies a combined turn signal and the run it serves. Opens a turn,
38
+ * then another for as long as the run's continuation decision says to advance.
39
+ */
40
+ run(options: {
41
+ signal: AbortSignal;
42
+ lease: Lease;
43
+ served: ServedRun;
44
+ }): Promise<void>;
45
+ /**
46
+ * One turn: decide, do it, append what happened, decide again.
47
+ *
48
+ * Every branch of the decision lives in {@link nextAction}; this only carries out what it asked
49
+ * for.
50
+ */
51
+ private turn;
52
+ /**
53
+ * Why a judgment made under `fence` may not stand, or `null` when it does. `activation-changed`:
54
+ * the activation's plugins changed since readiness, and takes precedence. `judgment-invalidated`:
55
+ * the constraint registrations the thread requires, by origin too, are not those it was judged
56
+ * under, one missing or replaced, or a fact a check declared it observed reads differently now.
57
+ * Such a registration's owner, or a plugin of the activation, can be the checker that would
58
+ * object, and core accepts whatever no check objects to; one that came back meanwhile did not
59
+ * judge it; and a verdict resting on a fact that moved while another check awaited is no verdict
60
+ * on the answer as it stands. Read inside the write that records the judgment.
61
+ */
62
+ private fenced;
63
+ /**
64
+ * Records how a judged turn ends, `ending` the checks' verdict or their failure, decided inside
65
+ * the write: one whose fence broke ends the turn `interrupted` instead, the answer still owed its
66
+ * checks, so a later run judges it again, held while a required owner is missing, rather than
67
+ * accepting it unchecked or failing the task because its checker was briefly gone or a fact it
68
+ * read moved. Returns the reason recorded.
69
+ */
70
+ private endJudged;
71
+ /**
72
+ * Records `turn/start` with the thread's route and the run the turn serves, decided in the write's
73
+ * builder, the turn's opening point: a cancel that landed while the loop awaited opens nothing,
74
+ * and a route whose provider is not registered opens nothing either, claims no input, and throws
75
+ * `RouteUnavailableError`, which fails the run before the turn. A provider lost once the row is
76
+ * built, its append still waiting on storage included, fails the opened turn.
77
+ *
78
+ * The route is the turn's for good, since every model step builds its client from it; it cannot
79
+ * change under an execution, which holds the thread while its request is pending.
80
+ */
81
+ private openTurn;
82
+ /** The thread's route as its rows stand. */
83
+ private threadRoute;
84
+ /**
85
+ * Asks the thread's strategy for a plan for a caller between turns (the `request` trigger): no turn
86
+ * opens, no step hook runs and no queued input is claimed; the route is resolved as a turn's would
87
+ * be. The caller owns the lease, as for a run, and composed the signal as a run's is. An
88
+ * interrupted open turn is closed first, as a run closes it; a thread with a tool call unanswered,
89
+ * a confirmation open or an answer unjudged is refused with `ThreadUnsettledError`. Resolves with
90
+ * the outcome, cancellation included.
91
+ */
92
+ compact(options: {
93
+ signal: AbortSignal;
94
+ lease: Lease;
95
+ options: JsonValue | null;
96
+ }): Promise<SurfacePrepareOutcome>;
97
+ /** One request to the thread's strategy, carried out by the engine. */
98
+ private prepare;
99
+ /**
100
+ * Asks the stop checks about the provisional answer. Returns how the turn ends — accepted as
101
+ * `completed`, or `rejected` — or `null` once their continuation messages are recorded.
102
+ *
103
+ * An acceptance ends the turn at once. Steering that arrived while the checks ran is still in the
104
+ * `next-step` inbox, and `run()` opens another turn for it.
105
+ */
106
+ private judge;
107
+ /**
108
+ * Lets the surface be prepared (`pressure`), then records plugin contributions and the claimed
109
+ * input, then asks the model.
110
+ *
111
+ * The dispatch is the first `await` between deciding this step and recording its input, and the
112
+ * lease does not exclude `send()` or `withdraw()`. So once it settles the signal is checked and the
113
+ * inbox read again: only input this step was decided on that is still queued is claimed, so a
114
+ * withdrawn input stays withdrawn, and input that arrived meanwhile waits for the next step. A step
115
+ * left with nothing to claim and no reply owed ends without a model call, and the decider decides
116
+ * again.
117
+ */
118
+ private askModel;
119
+ /** Reports a dispatch a listener ended in failure; one that was cancelled is the turn's to report. */
120
+ private reportFailedDispatch;
121
+ /** Runs a step's tool calls. What they did — answered, waited, ended the turn — lands in the journal. */
122
+ private answerCalls;
123
+ /**
124
+ * One model call. What it produced goes to the journal — `assistant/message`, or
125
+ * `assistant/attempt` when the stream gave nothing usable, which keeps it off the conversation.
126
+ *
127
+ * A request the provider refused as longer than the context window is recorded as an attempt
128
+ * marked `overflow`, and the thread's strategy is asked with `overflow` inside this step, before
129
+ * any `error` row. The rule is one sentence: an overflow fails the turn unless that request
130
+ * committed a replacement, however it ended. When it did, the step ends without an error and the
131
+ * decider asks the model again, from the replaced surface, in a new step.
132
+ */
133
+ private callModel;
134
+ }
@@ -0,0 +1,54 @@
1
+ import type { ContentPartInput, ConversationMessage, LLMUsage, ModelRoute, ResponseFinish, ToolChoice } from '../llm/index.js';
2
+ import type { Seq } from '../models/index.js';
3
+ import type { LoopRuntime, ModelSelection } from './runtime.js';
4
+ /**
5
+ * One auxiliary model call as a strategy asks for it. The engine builds the request: the head a step
6
+ * would send now (the recorded prompt and the tools the agent is granted), then the current surface
7
+ * up to and including the message behind `through`, then `instructions`, each a `user` message sent
8
+ * verbatim. So the request sends only what the journal holds and what its own row records.
9
+ */
10
+ export type AuxiliaryCall = {
11
+ /** The row behind the last surface message sent. The prefix must end on a balanced cut. */
12
+ readonly through: Seq;
13
+ /** The messages after the prefix, at least one, each sent in role `user` exactly as given. */
14
+ readonly instructions: readonly (string | readonly ContentPartInput[])[];
15
+ /** Route fields folded over the dispatch's route (`LlmService.resolveRoute`). */
16
+ readonly route?: ModelSelection;
17
+ /** Fixed on the draft, so request middleware cannot change it. `auto` when absent. */
18
+ readonly toolChoice?: ToolChoice;
19
+ /** Fixed on the draft, so request middleware cannot change it; absent leaves it to the provider. */
20
+ readonly maxOutputTokens?: number;
21
+ };
22
+ /** What an auxiliary call returned, as its `auxiliary/result` row records it, with the message itself. */
23
+ export type AuxiliaryReply = {
24
+ /** The `auxiliary/request` row; what a replacement made from this reply cites. */
25
+ readonly requestSeq: Seq;
26
+ readonly resultSeq: Seq;
27
+ /** The reply, tool calls and provider calls included, for a caller that must refuse them. */
28
+ readonly message: ConversationMessage;
29
+ /** Its text parts. */
30
+ readonly text: string;
31
+ readonly finish: ResponseFinish;
32
+ readonly usage: LLMUsage | null;
33
+ };
34
+ /** Where an auxiliary call is made, and what it may be sent on. */
35
+ export type AuxiliaryContext = {
36
+ readonly threadId: string;
37
+ readonly agentName: string;
38
+ readonly turn: number | null;
39
+ readonly step: number | null;
40
+ /** The dispatch's route. */
41
+ readonly route: ModelRoute;
42
+ readonly signal: AbortSignal;
43
+ };
44
+ /**
45
+ * Makes one auxiliary call: through `lagent/llm/request` middleware and the guidance terminal exactly
46
+ * as a step's request, with `purpose: 'auxiliary'`, its route, tool choice and output cap fixed on
47
+ * the draft, and no chunk published, since the thread's chunk channel carries its reply.
48
+ *
49
+ * Recorded in two rows: `auxiliary/request` in the terminal, before the request is sent, and
50
+ * `auxiliary/result` when the call ends, with its text and finish or its error, cancellation
51
+ * included. A call refused for how it was asked, or that fails before its request row, records
52
+ * nothing; a failure after it is recorded and then thrown as itself.
53
+ */
54
+ export declare function callAuxiliary(runtime: LoopRuntime, context: AuxiliaryContext, call: AuxiliaryCall): Promise<AuxiliaryReply>;