@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,72 @@
1
+ import { type Context } from '@leuduan/cordis';
2
+ import { z } from 'zod';
3
+ import type { ParsedToolCall, ToolCall } from '../llm/index.js';
4
+ import type { InvocationContext, Tool, ToolExecutionMode, WaitRequest } from '../loop/index.js';
5
+ import type { InterruptionPolicy, ToolResult, ToolResultPayloadInput } from '../models/index.js';
6
+ import type { JsonValue } from '../util/json.js';
7
+ import type { AgentSelector } from './scope.js';
8
+ /**
9
+ * Parameters described elsewhere, as JSON schema: advertised as given and handed to `execute`
10
+ * unvalidated, for a tool whose real validator is someone else's, such as an MCP server.
11
+ */
12
+ export type JsonSchemaParameters = {
13
+ readonly jsonSchema: Record<string, JsonValue>;
14
+ };
15
+ type ParametersOf<P> = P extends z.ZodType ? z.output<P> : Record<string, unknown>;
16
+ /** What `execute` returns: a result with `is_error`, `notes` and `metadata` optional, or a wait (`waitFor`). */
17
+ export type ToolReply = ToolResultPayloadInput | WaitRequest;
18
+ /** One tool, as {@link defineTool} takes it. */
19
+ export type ToolDefinition<P extends z.ZodType | JsonSchemaParameters> = {
20
+ /** The name it is registered under, and advertised to the model by. */
21
+ readonly name: string;
22
+ /** One paragraph advertised to the model. */
23
+ readonly description: string;
24
+ /** A zod schema the arguments are validated against and advertised from, or JSON schema. */
25
+ readonly parameters: P;
26
+ /**
27
+ * What a re-dispatch may do with a call that may have begun when its turn was interrupted; see
28
+ * `Tool.onInterrupted`. Every tool says which; there is no default.
29
+ */
30
+ readonly onInterrupted: InterruptionPolicy;
31
+ /** Whether a call may overlap its batch's others; see `Tool.executionMode`. No default either. */
32
+ readonly executionMode: ToolExecutionMode;
33
+ /** Runs one call. A throw becomes an `is_error` result: a tool never fails a turn. */
34
+ execute(parameters: ParametersOf<P>, context: InvocationContext, call: ParsedToolCall): Promise<ToolReply>;
35
+ };
36
+ /**
37
+ * Defines a tool: the one way to write one. Arguments are validated against `parameters` when it is
38
+ * a zod schema, and a validation failure or a throw from `execute` becomes an `is_error` result, so
39
+ * a tool can never crash a turn; the result is timed. A tool that needs configuration closes over it.
40
+ *
41
+ * ```ts
42
+ * const echo = defineTool({
43
+ * name: 'echo',
44
+ * description: 'Repeat the text.',
45
+ * parameters: z.strictObject({ text: z.string() }),
46
+ * onInterrupted: 'rerun',
47
+ * executionMode: 'parallel',
48
+ * execute: async ({ text }) => ({ output: text }),
49
+ * })
50
+ * ```
51
+ */
52
+ export declare function defineTool<P extends z.ZodType | JsonSchemaParameters>(definition: ToolDefinition<P>): Tool;
53
+ /**
54
+ * Offers `tool` in the calling plugin's scope for the life of its fiber, and grants it to the agents
55
+ * `agents` selects when given; without them it is registered for a grant elsewhere, a preset's say.
56
+ * Returns the disposer.
57
+ */
58
+ export declare function provideTool(ctx: Context, tool: Tool, options?: {
59
+ readonly agents?: AgentSelector;
60
+ }): () => void | Promise<void>;
61
+ /**
62
+ * {@link provideTool} for each of `tools`, then a prompt instruction under `tag` for every agent that
63
+ * is granted one of them: the `guidance` of each granted tool, in tool order, and nothing when none
64
+ * is granted or none has any.
65
+ */
66
+ export declare function provideTools(ctx: Context, tools: readonly Tool[], options: {
67
+ readonly tag: string;
68
+ readonly guidance: ReadonlyMap<string, string>;
69
+ }): void;
70
+ /** A tool's result for `call`, its defaults applied and its duration recorded. */
71
+ export declare function toToolResult(call: ToolCall, reply: ToolResultPayloadInput, startedAt: number): ToolResult;
72
+ export { errorResult } from '../loop/index.js';
@@ -0,0 +1,135 @@
1
+ import type { ConversationMessage, JsonObject, LLMStreamChunk, ModelResponse, ThinkingEffort } from './primitives.js';
2
+ import type { ModelRequest } from './request.js';
3
+ /** A model a provider offers to route selection, in the order the provider prefers them. */
4
+ export interface ModelOption {
5
+ readonly id: string;
6
+ /** When to pick it, written for a model choosing a route: cost, speed, strengths. */
7
+ readonly description?: string;
8
+ /** The efforts it accepts, when declared. Absent means unspecified, not unrestricted. */
9
+ readonly thinkingEfforts?: readonly ThinkingEffort[];
10
+ }
11
+ /**
12
+ * What a provider can carry for one model, as `LLMProvider.capacity` declares it and `ctx.llm`
13
+ * answers it for a route. A declaration, like the told model list, never discovered from the
14
+ * provider at run time.
15
+ */
16
+ export interface ModelCapacity {
17
+ /**
18
+ * The usable context window in tokens, or `null` when the provider declares none for the model.
19
+ * Shipped figures are the conservative ones a provider documents, so a consumer that trusts them
20
+ * errs early, never late.
21
+ */
22
+ readonly contextWindow: number | null;
23
+ /** Whether a request may carry provider-executed tools (`ModelRequest.providerTools`). */
24
+ readonly providerTools: boolean;
25
+ /**
26
+ * Whether a tool result may carry an image part: the adapter sends one and the provider accepts
27
+ * it. A tool that can answer with an image or in words, as `read_file` can, asks this of the route
28
+ * its result goes to; a thread that later moves to a route without it still sends the image it
29
+ * already has, and that request fails.
30
+ */
31
+ readonly toolResultImages: boolean;
32
+ }
33
+ /**
34
+ * A streamed model response: iterate for deltas, then `completed()` for what came back. A response
35
+ * is read once, by these rules, which an implementation enforces and a consumer may rely on.
36
+ * - It is iterated at most once. The read is claimed when the iterator is acquired, not at its first
37
+ * `next()`, and a second `[Symbol.asyncIterator]()` throws.
38
+ * - `completed()` on a response nobody has read drains it, publishing nothing, and settles.
39
+ * - Once the read has ended, whether it ran through, its reader stopped it early (`return`) or it
40
+ * failed, `completed()` returns or throws that read's outcome: a reader that left gets what
41
+ * arrived as a cut-off reply, a failed read throws its failure again. The outcome is fixed when the
42
+ * read ends: a cancel afterwards changes nothing.
43
+ * - A read ended by the caller's own cancellation (its request's abort, by the reason the signal
44
+ * carries) is a cut-off, never a failure: iteration ends without throwing, and `completed()`
45
+ * returns what arrived with finish `other`. A failure that only coincided with a cancel stays
46
+ * the failure. This is the read only: a request cancelled before a stream exists is refused,
47
+ * as `chat()` rejects with the caller's reason.
48
+ * - While a read is under way, from acquiring the iterator (before its first `next()` too) until it
49
+ * ends, `completed()` throws rather than settle a partial. A read ends only when its last
50
+ * operation, a `next` or a `return` or `throw` asked for and not yet settled, has finished; a
51
+ * `next()` after a `return()` or `throw()` ends without reading.
52
+ */
53
+ export type StreamingLLMResponse = AsyncIterable<LLMStreamChunk> & {
54
+ completed(): Promise<ModelResponse>;
55
+ };
56
+ /** What a model provider's client implements; a provider is offered with `registerProvider(ctx, provider, { retry })`. */
57
+ export interface LLMClient {
58
+ readonly providerName: string;
59
+ chat(request: ModelRequest): Promise<StreamingLLMResponse>;
60
+ /** Optional owned transport cleanup; sessions never dispose an injected client override. */
61
+ dispose?(): void | Promise<void>;
62
+ }
63
+ /** A provider was asked for something it cannot do. Thrown, never silently dropped. */
64
+ export declare class ProviderUnsupportedError extends Error {
65
+ readonly provider: string;
66
+ readonly feature: string;
67
+ constructor(provider: string, feature: string);
68
+ }
69
+ /**
70
+ * The provider refused or failed a request for exceeding the model's context window.
71
+ *
72
+ * Each provider classifies its own, from a rejected request and from a failure inside the stream,
73
+ * by the structured code where it has one and by its message's wording only where it has none. It
74
+ * carries no token count, by rule: providers state counts only in prose, if at all, and a number
75
+ * read from prose whose format may change is not a measurement. The provider's own error is the
76
+ * `cause`, so its text still reaches the journal. A failure the provider does not classify stays
77
+ * the error it was. A class of its own so the engine can tell this failure from every other one,
78
+ * as the one a shorter request can cure.
79
+ */
80
+ export declare class ContextOverflowError extends Error {
81
+ readonly provider: string;
82
+ constructor(provider: string, options: {
83
+ cause: unknown;
84
+ });
85
+ }
86
+ /**
87
+ * Why a response could not be settled: `transport`, the stream ended without the provider's own
88
+ * evidence that the response was complete; `empty`, it completed with no text and no tool call;
89
+ * `length`, it had no text and no tool call because the output cap cut it (a reasoning-only reply,
90
+ * which a repeat would repeat); `other`, it had none for another reason the provider gave, such as a
91
+ * content filter; `invalid`, it settled but cannot be acted on, as when two of its calls share an id.
92
+ */
93
+ export type ResponseSettlementKind = 'transport' | 'empty' | 'length' | 'other' | 'invalid';
94
+ /**
95
+ * A response that cannot be taken as an answer: one the provider never finished, or finished with
96
+ * nothing, which an adapter's `completed()` throws (never iteration); or one the loop cannot act on,
97
+ * `invalid`, which the loop throws itself for any client once `completed()` returned.
98
+ *
99
+ * Each adapter decides from its provider's terminal evidence, never from a reader that stopped
100
+ * early: a stream its reader abandoned, or whose request was aborted, still reports what it got,
101
+ * as a cut-off reply. `partial` is what arrived on a `transport` or `invalid` failure — its text and
102
+ * reasoning, never a tool call or `provider_state` — and `null` on an `empty` one. The message starts with the
103
+ * kind, so the journal's error text says which it was.
104
+ */
105
+ export declare class ResponseSettlementError extends Error {
106
+ readonly provider: string;
107
+ readonly kind: ResponseSettlementKind;
108
+ readonly partial: ConversationMessage | null;
109
+ readonly providerMetadata: JsonObject;
110
+ constructor(provider: string, kind: ResponseSettlementKind, partial: ConversationMessage | null, providerMetadata: JsonObject, detail: string);
111
+ }
112
+ /**
113
+ * A response stream that went `idleMs` without a single event from the provider: the idle deadline
114
+ * of one attempt, which the engine classifies as `timeout`. It bounds the wait for the first event
115
+ * too, from the moment the request was sent.
116
+ */
117
+ export declare class StreamIdleError extends Error {
118
+ readonly provider: string;
119
+ readonly idleMs: number;
120
+ constructor(provider: string, idleMs: number);
121
+ }
122
+ /**
123
+ * A stream that failed while it was being read, after it had produced output: what arrived (text and
124
+ * reasoning, never a tool call or `provider_state`), and the failure itself as `cause`, so a reset
125
+ * after visible text still leaves that text on record. A stream that failed before producing
126
+ * anything throws its failure unwrapped.
127
+ */
128
+ export declare class ResponseInterruptedError extends Error {
129
+ readonly provider: string;
130
+ readonly partial: ConversationMessage;
131
+ readonly providerMetadata: JsonObject;
132
+ constructor(provider: string, partial: ConversationMessage, providerMetadata: JsonObject, options: {
133
+ cause: unknown;
134
+ });
135
+ }
@@ -0,0 +1,52 @@
1
+ import { z } from 'zod';
2
+ import type { DeepReadonly } from '../util/json.js';
3
+ export declare const ContentPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
4
+ type: z.ZodLiteral<"text">;
5
+ text: z.ZodString;
6
+ }, z.core.$strip>, z.ZodObject<{
7
+ type: z.ZodLiteral<"image">;
8
+ url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
9
+ data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
10
+ media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
11
+ detail: z.ZodDefault<z.ZodEnum<{
12
+ auto: "auto";
13
+ low: "low";
14
+ high: "high";
15
+ }>>;
16
+ }, z.core.$strip>, z.ZodObject<{
17
+ type: z.ZodLiteral<"file">;
18
+ file_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
19
+ url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
20
+ data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
21
+ filename: z.ZodDefault<z.ZodNullable<z.ZodString>>;
22
+ media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
23
+ }, z.core.$strip>], "type">;
24
+ export type ContentPart = z.infer<typeof ContentPartSchema>;
25
+ /** A part as a caller writes one, with the fields the schema defaults left out. */
26
+ export type ContentPartInput = z.input<typeof ContentPartSchema>;
27
+ export type ContentPartKind = ContentPart['type'];
28
+ /** Accepts what a caller writes — a string, nothing, or parts — and yields parts. */
29
+ export declare const ContentSchema: z.ZodPreprocess<z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
30
+ type: z.ZodLiteral<"text">;
31
+ text: z.ZodString;
32
+ }, z.core.$strip>, z.ZodObject<{
33
+ type: z.ZodLiteral<"image">;
34
+ url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
35
+ data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
36
+ media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
37
+ detail: z.ZodDefault<z.ZodEnum<{
38
+ auto: "auto";
39
+ low: "low";
40
+ high: "high";
41
+ }>>;
42
+ }, z.core.$strip>, z.ZodObject<{
43
+ type: z.ZodLiteral<"file">;
44
+ file_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
45
+ url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
46
+ data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
47
+ filename: z.ZodDefault<z.ZodNullable<z.ZodString>>;
48
+ media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
49
+ }, z.core.$strip>], "type">>>, unknown>;
50
+ export declare const textPart: (text: string) => ContentPart;
51
+ /** The text of a content list, parts joined. Non-text parts are not text and do not appear. */
52
+ export declare const contentText: (content: readonly DeepReadonly<ContentPart>[]) => string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * `@leuduan/lagent/llm`: the model and provider contracts as the package offers them, for a provider
3
+ * written outside it and a host that calls a model. Every type the contract mentions, and the values
4
+ * a consumer uses; the schemas and helpers the engine uses itself stay inside (`index.ts`).
5
+ *
6
+ * It depends on `zod` alone, so a provider client built on it works in any harness.
7
+ */
8
+ export { ContextOverflowError, ProviderUnsupportedError, ResponseInterruptedError, ResponseSettlementError, StreamIdleError, } from './client.js';
9
+ export type { LLMClient, ModelCapacity, ModelOption, ResponseSettlementKind, StreamingLLMResponse } from './client.js';
10
+ export { contentText } from './content.js';
11
+ export { ModelCallError } from './failure.js';
12
+ export type { FailureClassification, FailureKind, ModelCallClient, ModelCallHandle } from './failure.js';
13
+ export type { DeepReadonly, ReadonlyJsonValue } from '../util/json.js';
14
+ export type { ContentPart, ContentPartInput, ContentPartKind } from './content.js';
15
+ export { conversationMessage, LLMStreamChunkSchema, messageText, ThinkingEffortSchema } from './primitives.js';
16
+ export type { ConversationMessage, JsonObject, LLMStreamChunk, LLMUsage, MalformedToolCall, MessageRole, ModelResponse, ParsedToolCall, ProviderCall, ProviderState, ResponseFinish, ThinkingEffort, ToolCall, ToolSpec, } from './primitives.js';
17
+ export { renderPromptBlocks } from './prompt.js';
18
+ export type { PromptBlock } from './prompt.js';
19
+ export { defaultRoute } from './provider.js';
20
+ export type { LLMProvider, ModelRoute } from './provider.js';
21
+ export type { ModelRequest, RequestPurpose, ResponseFormat, ToolChoice } from './request.js';
@@ -0,0 +1 @@
1
+ import{b as p,f as d}from"../chunks/TYTQRLTX.js";import{A as l,a as r,b as e,c as o,d as t,e as n,i as m,k as s,t as f,v as a,w as x}from"../chunks/D7E6EWIE.js";export{e as ContextOverflowError,f as LLMStreamChunkSchema,p as ModelCallError,r as ProviderUnsupportedError,n as ResponseInterruptedError,o as ResponseSettlementError,t as StreamIdleError,s as ThinkingEffortSchema,m as contentText,a as conversationMessage,d as defaultRoute,x as messageText,l as renderPromptBlocks};
@@ -0,0 +1,82 @@
1
+ /**
2
+ * One vocabulary for how a model call failed, and the one place a failure is given its kind.
3
+ *
4
+ * A kind decides whether `ctx.llm` retries a call and informs a host's rerun policy; it does not prove
5
+ * a rerun is safe. A cancellation is never a failure kind.
6
+ */
7
+ import { z } from 'zod';
8
+ import type { StreamingLLMResponse } from './client.js';
9
+ import type { LLMProvider } from './provider.js';
10
+ import type { ModelRequest } from './request.js';
11
+ /**
12
+ * How a model call failed. `transport`, `empty`, `length` and `invalid` come from settlement and the
13
+ * loop; `overflow` from a `ContextOverflowError`; the rest from the provider's `classify`. Unknown is
14
+ * `other`.
15
+ */
16
+ export declare const FAILURE_KINDS: readonly ["rate_limit", "overloaded", "transport", "timeout", "empty", "length", "invalid", "auth", "quota", "overflow", "other"];
17
+ export type FailureKind = (typeof FAILURE_KINDS)[number];
18
+ export declare const FailureKindSchema: z.ZodEnum<{
19
+ length: "length";
20
+ other: "other";
21
+ transport: "transport";
22
+ empty: "empty";
23
+ invalid: "invalid";
24
+ rate_limit: "rate_limit";
25
+ overloaded: "overloaded";
26
+ timeout: "timeout";
27
+ auth: "auth";
28
+ quota: "quota";
29
+ overflow: "overflow";
30
+ }>;
31
+ /**
32
+ * What a provider's `classify` says of a failure it was handed: its kind, and how long the provider
33
+ * asked the caller to wait, read only from structured fields (a header), never from prose.
34
+ */
35
+ export type FailureClassification = {
36
+ kind: FailureKind;
37
+ retryAfterMs?: number;
38
+ };
39
+ /**
40
+ * A failed model call, as `ctx.llm`'s clients throw it: the provider, the kind, how many times the
41
+ * client was called for it, the wait the provider asked for, and the adapter's own error as `cause`.
42
+ * Its kind is the one authority inside the engine; the typed adapter errors are evidence for it. Its
43
+ * message is the cause's, so the journal's error text stays the provider's prose; the kind is a field.
44
+ */
45
+ export declare class ModelCallError extends Error {
46
+ readonly provider: string;
47
+ readonly kind: FailureKind;
48
+ readonly attempts: number;
49
+ readonly retryAfterMs: number | null;
50
+ constructor(provider: string, kind: FailureKind, attempts: number, retryAfterMs: number | null, options: {
51
+ cause: unknown;
52
+ });
53
+ }
54
+ /**
55
+ * One model call through `ctx.llm`, handed back before it opens: its response, and how many times
56
+ * the provider's client has been called for it so far, whatever becomes of it, a refusal or a
57
+ * cancellation included.
58
+ */
59
+ export interface ModelCallHandle {
60
+ readonly response: Promise<StreamingLLMResponse>;
61
+ readonly attempts: number;
62
+ }
63
+ /**
64
+ * A client from `ctx.llm`: it retries a failed call by its provider's policy and throws
65
+ * `ModelCallError` for one that still fails.
66
+ */
67
+ export interface ModelCallClient {
68
+ readonly providerName: string;
69
+ /** Starts one call; the handle is the caller's to keep for its attempt count. */
70
+ call(request: ModelRequest): ModelCallHandle;
71
+ }
72
+ /**
73
+ * The kind of a failure from `provider`'s client, from typed evidence first: a settlement failure
74
+ * keeps its kind, a `ContextOverflowError` is `overflow`, a `StreamIdleError` is `timeout`. Only what neither says reaches the
75
+ * provider's `classify` (a stream interrupted after output is classified by its cause), so a provider
76
+ * written from scratch cannot get overflow or settlement wrong. What `classify` returns is checked
77
+ * before the journal sees it: a kind outside {@link FAILURE_KINDS}, or a `classify` that throws, is
78
+ * `other`, and a wait that is not a finite, nonnegative number is no wait (a fraction rounds up).
79
+ */
80
+ export declare function classifyFailure(provider: LLMProvider, error: unknown): FailureClassification;
81
+ /** The first `type` in `error`'s `cause` chain, itself included; middleware may wrap what was thrown. */
82
+ export declare function findCause<T extends Error>(error: unknown, type: abstract new (...args: never[]) => T): T | undefined;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The model layer's entry point inside the package: the model-facing alphabet and the provider
3
+ * contract, every name its modules export. Outer layers import from here only. What the package
4
+ * offers others is the narrower `door.ts` (`@leuduan/lagent/llm`).
5
+ *
6
+ * It depends on `zod` alone, so a provider client built on it works in any harness, not only in a
7
+ * lagent session.
8
+ */
9
+ export * from './client.js';
10
+ export * from './content.js';
11
+ export * from './failure.js';
12
+ export * from './primitives.js';
13
+ export * from './prompt.js';
14
+ export * from './provider.js';
15
+ export * from './readLedger.js';
16
+ export * from './request.js';