@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,60 @@
1
+ import OpenAI from 'openai';
2
+ import { z } from 'zod';
3
+ import type { ModelOption } from '../../llm/index.js';
4
+ import { type CodexCredentialManager } from './codexAuth.js';
5
+ import { OpenAIResponsesLLMClient } from './openaiResponses.js';
6
+ export declare const CODEX_PROVIDER_NAME = "codex";
7
+ export declare const CODEX_DEFAULT_MODEL = "gpt-5.6-luna";
8
+ /**
9
+ * The models agents are told about: every model the Codex backend lists for clients, with the
10
+ * efforts lagent can send (the backend also takes `xhigh` and, on some, `ultra`, which
11
+ * `ThinkingEffort` has no value for), from `codex app-server`'s `model/list` (checked 2026-10-11).
12
+ * The models it hides can be named, just not told.
13
+ */
14
+ export declare const CODEX_MODELS: readonly ModelOption[];
15
+ /**
16
+ * The usable context window of every model the Codex CLI's model cache lists, in tokens: its
17
+ * `context_window` of 272,000 with its `effective_context_window_percent` of 95 applied, 258,400
18
+ * (`~/.codex/models_cache.json`, checked 2026-10-03). The raw figure is itself conservative: the
19
+ * backend accepted 285,889 input tokens on `gpt-5.6-luna`, listed at 272,000 (measured 2026-10-03).
20
+ * A model not listed here has no window.
21
+ */
22
+ export declare const CODEX_CONTEXT_WINDOWS: Readonly<Record<string, number>>;
23
+ export declare const CodexConfigSchema: z.ZodObject<{
24
+ authPath: z.ZodOptional<z.ZodString>;
25
+ refreshTimeoutMs: z.ZodOptional<z.ZodNumber>;
26
+ streamIdleTimeoutMs: z.ZodNullable<z.ZodNumber>;
27
+ baseURL: z.ZodDefault<z.ZodString>;
28
+ defaultModel: z.ZodDefault<z.ZodString>;
29
+ thinkingEffort: z.ZodDefault<z.ZodEnum<{
30
+ low: "low";
31
+ high: "high";
32
+ none: "none";
33
+ medium: "medium";
34
+ max: "max";
35
+ }>>;
36
+ extraBody: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
37
+ }, z.core.$strip>;
38
+ export type CodexConfig = z.input<typeof CodexConfigSchema>;
39
+ /**
40
+ * The Responses client over the Codex CLI's ChatGPT login. Requests go to the ChatGPT backend through
41
+ * {@link codexOpenAI}, with a token read from the login file per call, so there is no API key and a
42
+ * token rotated by another process (or by this client) takes effect on the next request.
43
+ */
44
+ export declare class CodexLLMClient extends OpenAIResponsesLLMClient {
45
+ readonly credentials: CodexCredentialManager;
46
+ constructor(config: CodexConfig & {
47
+ client?: OpenAI;
48
+ credentials?: CodexCredentialManager;
49
+ /** The transport under the authorization, for tests. */
50
+ fetch?: typeof globalThis.fetch;
51
+ });
52
+ /** The request goes out over the login, read first (see {@link overLogin}). */
53
+ protected openStream(request: Record<string, unknown>, headers: Record<string, string>, signal: AbortSignal): Promise<AsyncIterable<OpenAI.Responses.ResponseStreamEvent>>;
54
+ }
55
+ /**
56
+ * Compresses the JSON body of each request under the authorization: the model calls replay the whole
57
+ * conversation, so their bodies are the large ones. The SDK sends JSON as a string; any other body
58
+ * goes as it is.
59
+ */
60
+ export declare const compressingFetch: (baseFetch?: typeof globalThis.fetch) => typeof globalThis.fetch;
@@ -0,0 +1,116 @@
1
+ import OpenAI from 'openai';
2
+ import { TransportCredentialError } from './shared.js';
3
+ /** The Codex backend every client of a Codex login calls: the model adapter and web search. */
4
+ export declare const CODEX_BASE_URL = "https://chatgpt.com/backend-api/codex";
5
+ export declare const CODEX_REFRESH_TOKEN_URL = "https://auth.openai.com/oauth/token";
6
+ export declare const CODEX_OAUTH_CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
7
+ /** Everything a request needs; never logged, and never interpolated into an error message. */
8
+ export type CodexCredentials = {
9
+ accessToken: string;
10
+ refreshToken: string;
11
+ accountId: string;
12
+ };
13
+ export declare class CodexCredentialError extends TransportCredentialError {
14
+ constructor(message: string);
15
+ }
16
+ export type CodexCredentialManagerOptions = {
17
+ /** The login file, which the host names; see {@link codexAuthPath} for where `codex login` writes it. */
18
+ authPath: string;
19
+ /**
20
+ * How long one refresh request may take, body included, before it fails and the next caller may
21
+ * try. The manager's own deadline, so one stalled refresh cannot hold every later read of the
22
+ * login: no caller's signal sets it, and none can cut a refresh short for the others.
23
+ */
24
+ refreshTimeoutMs: number;
25
+ refreshUrl?: string;
26
+ oauthClientId?: string;
27
+ /** Test seam for the refresh call. */
28
+ fetch?: typeof globalThis.fetch;
29
+ };
30
+ /**
31
+ * Where `codex login` writes its login, for a host to resolve from its own environment and home
32
+ * directory: `$CODEX_HOME/auth.json`, else `<home>/.codex/auth.json`. No library code calls it.
33
+ */
34
+ export declare const codexAuthPath: (environment: Readonly<Record<string, string | undefined>>, home: string) => string;
35
+ /**
36
+ * Reads the ChatGPT login `codex login` leaves on disk, refreshes the access token shortly before
37
+ * it expires, and writes the rotated tokens back to the same file. Nothing is cached: every call
38
+ * re-reads the file, so a token another process rotated is picked up immediately.
39
+ */
40
+ export declare class CodexCredentialManager {
41
+ readonly authPath: string;
42
+ readonly refreshTimeoutMs: number;
43
+ private readonly refreshUrl;
44
+ private readonly oauthClientId;
45
+ private readonly fetchImpl;
46
+ /** Serializes read-refresh-write, the way the Python manager holds an asyncio lock. */
47
+ private queue;
48
+ constructor(options: CodexCredentialManagerOptions);
49
+ /** The current credentials, refreshed first when the access token is about to expire. */
50
+ credentials(): Promise<CodexCredentials>;
51
+ /**
52
+ * Called after a request was rejected as unauthorized: returns the token another process already
53
+ * rotated onto disk, or forces a refresh when the failed one is still the current one.
54
+ */
55
+ recoverUnauthorized(failed: CodexCredentials): Promise<CodexCredentials>;
56
+ private serialize;
57
+ private read;
58
+ private needsRefresh;
59
+ private refresh;
60
+ private requestRefresh;
61
+ /** Writes through a sibling temp file so a crash can never leave a truncated login behind. */
62
+ private write;
63
+ }
64
+ /**
65
+ * The one credential manager for an auth file in this process. A manager serializes only its own
66
+ * read-refresh-write, so two managers of one file could both spend the same refresh token and make
67
+ * one refresh fail; every client of one login shares this manager instead. The first caller's
68
+ * `refreshTimeoutMs` configures it, and a later one that asks for another is refused rather than
69
+ * silently given the first's.
70
+ */
71
+ export declare function codexCredentials(authPath: string, options: {
72
+ readonly refreshTimeoutMs: number;
73
+ }): CodexCredentialManager;
74
+ /**
75
+ * Authorizes every request with the current Codex login, and gives a rejected one a second chance
76
+ * with recovered credentials: credential recovery, not a retry policy, so its two HTTP requests are
77
+ * one attempt. The SDK sends JSON bodies as strings, so the second request can resend it.
78
+ */
79
+ export declare const authorizingFetch: (credentials: Pick<CodexCredentialManager, "credentials" | "recoverUnauthorized">, baseFetch?: typeof globalThis.fetch) => typeof globalThis.fetch;
80
+ /**
81
+ * Runs one request over a Codex login, the one place a Codex request waits for its credentials, for
82
+ * the model adapter and web search alike. The login is read first, outside the SDK: the idle deadline
83
+ * is held (the login's own refresh deadline bounds the wait instead), the SDK's request timeout has
84
+ * not started, and what the read throws, a {@link CodexCredentialError} or a failure to persist a
85
+ * refreshed login, reaches the caller as it is rather than as a failed connection. The credentials
86
+ * read are the ones `request`'s own authorization uses (see {@link authorizingFetch}), whichever SDK
87
+ * client it is given. `signal` bounds only this caller's wait, never the refresh.
88
+ */
89
+ export declare function overLogin<T>(credentials: Pick<CodexCredentialManager, 'credentials'>, signal: AbortSignal | undefined, request: () => Promise<T>): Promise<T>;
90
+ /**
91
+ * The one SDK client over a Codex login, for the provider and anything else that calls the Codex
92
+ * backend: every request authorized from the login, a rejected one retried once with recovered
93
+ * credentials.
94
+ */
95
+ export declare function codexOpenAI(options: {
96
+ readonly credentials: CodexCredentialManager;
97
+ readonly baseURL: string;
98
+ /** The transport under the authorization; the global `fetch` without it. */
99
+ readonly fetch?: typeof globalThis.fetch;
100
+ }): OpenAI;
101
+ /**
102
+ * A Codex login's backend for JSON requests besides the model adapter's, web search's: every request
103
+ * authorized from the login's one manager in this process through {@link codexOpenAI}, and a login
104
+ * problem thrown as its {@link CodexCredentialError}: the login is awaited first ({@link overLogin}), and
105
+ * one raised in the transport is handed back by {@link classifyProviderError}. `post` answers
106
+ * with the status and the parsed body; a non-2xx status throws the SDK's error, and nothing retries.
107
+ */
108
+ export declare function codexBackend(login: {
109
+ readonly authPath: string;
110
+ readonly refreshTimeoutMs: number;
111
+ }): {
112
+ post(path: string, body: Record<string, unknown>, signal: AbortSignal): Promise<{
113
+ status: number;
114
+ data: unknown;
115
+ }>;
116
+ };
@@ -0,0 +1,55 @@
1
+ import type OpenAI from 'openai';
2
+ import { z } from 'zod';
3
+ import type { ModelOption, ModelRequest } from '../../llm/index.js';
4
+ import { OpenAIResponsesLLMClient } from './openaiResponses.js';
5
+ import { type ProviderErrorFields } from './shared.js';
6
+ /** The stateless Responses endpoint DeepSeek documents as OpenAI-compatible. */
7
+ export declare const DEEPSEEK_RESPONSES_BASE_URL = "https://api.deepseek.com";
8
+ export declare const DEEPSEEK_RESPONSES_PROVIDER_NAME = "deepseek-responses";
9
+ /** DeepSeek's current API name for the DeepSeek-V4.1-Flash model. */
10
+ export declare const DEEPSEEK_RESPONSES_DEFAULT_MODEL = "deepseek-flash";
11
+ /** The models agents are told about, from the Codex CLI's DeepSeek model list (checked 2026-09-26). */
12
+ export declare const DEEPSEEK_RESPONSES_MODELS: readonly ModelOption[];
13
+ /**
14
+ * The usable context window of each DeepSeek model, in tokens, from the Codex CLI's DeepSeek model
15
+ * list: a `context_window` of 1,048,576 with its `effective_context_window_percent` of 95 applied,
16
+ * 996,147, rounded down from 996,147.2 (`~/.codex/ds.models.json`, checked 2026-10-03). The raw
17
+ * figure agreed with DeepSeek's own overflow message for `deepseek-flash`, so the usable one sits
18
+ * below the limit DeepSeek enforces. A model not listed here has no window.
19
+ */
20
+ export declare const DEEPSEEK_RESPONSES_CONTEXT_WINDOWS: Readonly<Record<string, number>>;
21
+ export declare const DeepSeekResponsesConfigSchema: z.ZodObject<{
22
+ apiKey: z.ZodOptional<z.ZodString>;
23
+ streamIdleTimeoutMs: z.ZodNullable<z.ZodNumber>;
24
+ defaultHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
25
+ extraBody: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
26
+ thinkingEffort: z.ZodOptional<z.ZodEnum<{
27
+ low: "low";
28
+ high: "high";
29
+ none: "none";
30
+ medium: "medium";
31
+ max: "max";
32
+ }>>;
33
+ baseURL: z.ZodDefault<z.ZodString>;
34
+ defaultModel: z.ZodDefault<z.ZodString>;
35
+ }, z.core.$strip>;
36
+ export type DeepSeekResponsesConfig = z.input<typeof DeepSeekResponsesConfigSchema>;
37
+ type DeepSeekResponsesClientConfig = DeepSeekResponsesConfig & {
38
+ client?: OpenAI;
39
+ };
40
+ /**
41
+ * DeepSeek's OpenAI-compatible Responses API.
42
+ *
43
+ * The normalized Responses mapping is shared with OpenAI, while the provider name keeps one
44
+ * backend's replay state out of another. DeepSeek is stateless too, so completed output is replayed
45
+ * through `provider_state` on the next turn.
46
+ */
47
+ export declare class DeepSeekResponsesLLMClient extends OpenAIResponsesLLMClient {
48
+ constructor(config: DeepSeekResponsesClientConfig);
49
+ buildRequest(call: ModelRequest): {
50
+ [x: string]: unknown;
51
+ };
52
+ /** The structured code where DeepSeek sends one, else the wording of its message. */
53
+ protected isContextOverflow(fields: ProviderErrorFields): boolean;
54
+ }
55
+ export {};
@@ -0,0 +1,61 @@
1
+ /**
2
+ * `@leuduan/lagent/providers`: the shipped providers, their configuration types and the Codex login
3
+ * helpers a host resolves a credential with. The package's own entry point to this folder is
4
+ * `index.ts`, which adds what the package keeps private.
5
+ */
6
+ import type { LLMProvider } from '../../llm/index.js';
7
+ import { type CodexConfig } from './codex.js';
8
+ import { type OpenAIChatConfig } from './openaiChat.js';
9
+ import { type OpenAIResponsesConfig } from './openaiResponses.js';
10
+ import { type DeepSeekResponsesConfig } from './deepseek.js';
11
+ import { type OpenCodeGoConfig } from './opencodeGo.js';
12
+ /**
13
+ * A provider's configuration with its credential named: the host resolves it, from wherever it keeps
14
+ * it, and says so even when it has none. A provider without one can still be described, its defaults
15
+ * and models read; building a client for it then fails, naming what is missing.
16
+ */
17
+ type WithCredential<Config> = Config & {
18
+ readonly apiKey: string | undefined;
19
+ };
20
+ /**
21
+ * The OpenAI Responses provider, at OpenAI's endpoint unless `baseURL` names another. Building one
22
+ * registers nothing, so a host can read its defaults and models first (see `defaultRoute`);
23
+ * `registerProvider(ctx, openaiResponsesProvider(config), { retry })` registers it.
24
+ */
25
+ export declare const openaiResponsesProvider: (config: WithCredential<OpenAIResponsesConfig>) => LLMProvider;
26
+ /** DeepSeek's Responses API provider, at DeepSeek's endpoint unless `baseURL` names another. */
27
+ export declare const deepseekProvider: (config: WithCredential<DeepSeekResponsesConfig>) => LLMProvider;
28
+ /**
29
+ * The Codex provider: the same Responses API, reached with the ChatGPT login that `codex login`
30
+ * leaves in the file `authPath` names instead of an API key, reread per request and refreshed in
31
+ * place when it nears expiry.
32
+ */
33
+ export declare const codexProvider: (config: CodexConfig & {
34
+ readonly authPath: string;
35
+ readonly refreshTimeoutMs: number;
36
+ }) => LLMProvider;
37
+ /**
38
+ * The OpenAI Chat Completions provider, and with a `baseURL` any gateway that speaks it. It declares
39
+ * no models and no windows of its own: a gateway serves whatever ids its operator configured, so the
40
+ * windows it declares are the ones `contextWindows` configures. It replays reasoning text but no
41
+ * opaque reasoning state, and provider-executed tools are refused.
42
+ */
43
+ export declare const openaiChatProvider: (config: WithCredential<OpenAIChatConfig>) => LLMProvider;
44
+ /**
45
+ * The OpenCode Go gateway (`https://opencode.ai/zen/go/v1`): one subscription key in front of many
46
+ * vendors' models, each answering on one protocol: OpenAI Responses, Chat Completions or Anthropic
47
+ * Messages, each served by its own client. The host names itself with a
48
+ * `User-Agent` in `defaultHeaders`; each request carries its thread as Go's session header.
49
+ */
50
+ export declare const opencodeGoProvider: (config: WithCredential<OpenCodeGoConfig>) => LLMProvider;
51
+ export { CODEX_PROVIDER_NAME } from './codex.js';
52
+ export type { CodexConfig } from './codex.js';
53
+ export type { OpenAIChatConfig } from './openaiChat.js';
54
+ export { codexAuthPath, CodexCredentialError } from './codexAuth.js';
55
+ export type { OpenAIResponsesConfig } from './openaiResponses.js';
56
+ export { DEEPSEEK_RESPONSES_PROVIDER_NAME } from './deepseek.js';
57
+ export { OPENCODE_GO_PROVIDER_NAME } from './opencodeGo.js';
58
+ export type { OpenCodeGoConfig } from './opencodeGo.js';
59
+ export type { DeepSeekResponsesConfig } from './deepseek.js';
60
+ export { OPENCODE_COPILOT_PROVIDER_NAME, opencodeCopilotProvider } from './opencodeCopilot.js';
61
+ export type { OpenCodeCopilotConfig } from './opencodeCopilot.js';
@@ -0,0 +1 @@
1
+ import{a,b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l}from"../../chunks/WUUKTSRT.js";import"../../chunks/NDIM7MEW.js";import"../../chunks/34KW6VNQ.js";import"../../chunks/PUSUPTAT.js";import"../../chunks/DDANMY45.js";import"../../chunks/D7E6EWIE.js";export{c as CODEX_PROVIDER_NAME,a as CodexCredentialError,d as DEEPSEEK_RESPONSES_PROVIDER_NAME,f as OPENCODE_COPILOT_PROVIDER_NAME,e as OPENCODE_GO_PROVIDER_NAME,b as codexAuthPath,j as codexProvider,i as deepseekProvider,k as openaiChatProvider,h as openaiResponsesProvider,g as opencodeCopilotProvider,l as opencodeGoProvider};
@@ -0,0 +1,23 @@
1
+ /**
2
+ * What every adapter shares of a failure, whatever its transport or SDK: the kind an HTTP status says,
3
+ * the kind of a socket error code, and the wait a response's headers ask for. Structured evidence
4
+ * only; each protocol's own codes and types are classified beside its adapter.
5
+ */
6
+ import type { FailureClassification, FailureKind } from '../../llm/index.js';
7
+ /**
8
+ * The kind an HTTP status says on its own, the one fallback every protocol shares: `undefined` for a
9
+ * status it does not name. With the SDKs' own retries off, every status they used to retry (408, 409,
10
+ * 429 and every 5xx) has a retried kind, and a 5xx not named here, such as a CDN's 520-524 in front of
11
+ * a backend, is `transport`. A 402 is a spent balance, which waiting does not lift. A protocol's
12
+ * own structured evidence (a quota code, an error type) is read before this, where it has one.
13
+ */
14
+ export declare function statusKind(status: number): FailureKind | undefined;
15
+ /** `kind`, with the wait the headers ask for, except where a wait means nothing: `auth` and `other`. */
16
+ export declare function withRetryAfter(kind: FailureKind, headers: Headers | undefined, now: number): FailureClassification;
17
+ /** The failure kind of a socket error code (Node, undici) somewhere in a failure's causes; else `other`. */
18
+ export declare function socketCodeKind(error: unknown): FailureKind;
19
+ /**
20
+ * The wait a response's headers ask for, in milliseconds: `retry-after-ms`, else `retry-after` as
21
+ * delta-seconds or an HTTP date read against `now`. A malformed or negative value is no wait at all.
22
+ */
23
+ export declare function retryAfterOf(headers: Headers | undefined, now: number): number | undefined;
@@ -0,0 +1,23 @@
1
+ import type { LLMClient, ModelRequest, StreamingLLMResponse } from '../../llm/index.js';
2
+ /** The protocols a gateway's models answer on: OpenAI Responses, Chat Completions, Anthropic Messages. */
3
+ export type GatewayProtocol = 'responses' | 'chat' | 'messages';
4
+ /** A gateway's check of a call: the protocol it goes on and the call to send. */
5
+ export type PrepareCall = (call: ModelRequest) => {
6
+ readonly protocol: GatewayProtocol;
7
+ readonly call: ModelRequest;
8
+ };
9
+ /**
10
+ * One gateway: a credential and an endpoint in front of models that each answer on one protocol.
11
+ * It owns the rule that a call goes to the adapter for its model's protocol, never tried on
12
+ * another. `prepare` is the gateway's own check of a call: it names the protocol, throws what the
13
+ * gateway refuses, and returns the call to send, normalized for the model where the gateway must.
14
+ * The adapters are the protocol clients the gateway built, which share its name and its per-call
15
+ * headers (see `CallHeaders`).
16
+ */
17
+ export declare class GatewayLLMClient implements LLMClient {
18
+ readonly providerName: string;
19
+ private readonly prepare;
20
+ private readonly adapters;
21
+ constructor(providerName: string, prepare: PrepareCall, adapters: Readonly<Record<GatewayProtocol, LLMClient>>);
22
+ chat(call: ModelRequest): Promise<StreamingLLMResponse>;
23
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The package's own entry point to the providers: the public door, and `codexBackend`, which the web
3
+ * search tool uses and the package does not offer.
4
+ */
5
+ export * from './door.js';
6
+ export { codexBackend } from './codexAuth.js';
@@ -0,0 +1,62 @@
1
+ import OpenAI from 'openai';
2
+ import type { ChatCompletionChunk } from 'openai/resources/chat/completions';
3
+ import { z } from 'zod';
4
+ import type { ConversationMessage, LLMClient, ModelRequest, StreamingLLMResponse } from '../../llm/index.js';
5
+ import type { DeepReadonly } from '../../util/json.js';
6
+ import { type CallHeaders } from './stream.js';
7
+ export declare const OPENAI_CHAT_DEFAULT_MODEL = "gpt-5.4";
8
+ export declare const OpenAIChatConfigSchema: z.ZodObject<{
9
+ apiKey: z.ZodOptional<z.ZodString>;
10
+ streamIdleTimeoutMs: z.ZodNullable<z.ZodNumber>;
11
+ defaultHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
12
+ extraBody: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
13
+ thinkingEffort: z.ZodOptional<z.ZodEnum<{
14
+ low: "low";
15
+ high: "high";
16
+ none: "none";
17
+ medium: "medium";
18
+ max: "max";
19
+ }>>;
20
+ baseURL: z.ZodDefault<z.ZodString>;
21
+ defaultModel: z.ZodDefault<z.ZodString>;
22
+ systemRole: z.ZodDefault<z.ZodEnum<{
23
+ system: "system";
24
+ developer: "developer";
25
+ }>>;
26
+ contextWindows: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
27
+ }, z.core.$strip>;
28
+ export type OpenAIChatConfig = z.input<typeof OpenAIChatConfigSchema>;
29
+ type RequestPayload = Record<string, unknown>;
30
+ /**
31
+ * LLM client for the OpenAI Chat Completions API, and for the many gateways that speak it.
32
+ *
33
+ * What it cannot do is the reason it is not the direction: Chat Completions has no field for a
34
+ * model's opaque reasoning state. Reasoning text goes back as the `reasoning_content` vendor
35
+ * extension, which models that read it accept, but this client writes no `provider_state`.
36
+ * Provider-executed tools are refused outright rather than silently dropped.
37
+ */
38
+ export declare class OpenAIChatLLMClient implements LLMClient {
39
+ readonly providerName: string;
40
+ protected readonly client: OpenAI;
41
+ private readonly callHeaders;
42
+ /** Absent sends no effort, leaving it to the model; a named one, `none` included, is sent. */
43
+ private readonly thinkingEffort;
44
+ private readonly extraBody;
45
+ private readonly systemRole;
46
+ private readonly streamIdleTimeoutMs;
47
+ /**
48
+ * `name` is the provider the client speaks for (a gateway's); `headers` adds headers to each call.
49
+ * Both are the client's owner's: nothing subclasses the client to say them.
50
+ */
51
+ constructor(config: OpenAIChatConfig & {
52
+ client?: OpenAI;
53
+ name?: string;
54
+ headers?: CallHeaders;
55
+ });
56
+ buildRequest(call: ModelRequest): RequestPayload;
57
+ /** The one SDK call of this protocol; `headers` are the call's own, over the client's defaults. */
58
+ protected openStream(request: RequestPayload, headers: Record<string, string>, signal: AbortSignal): Promise<AsyncIterable<ChatCompletionChunk>>;
59
+ chat(call: ModelRequest): Promise<StreamingLLMResponse>;
60
+ }
61
+ export declare function toChatMessage(message: DeepReadonly<ConversationMessage>, provider?: string): unknown;
62
+ export {};
@@ -0,0 +1,100 @@
1
+ import OpenAI from 'openai';
2
+ import type { Response, ResponseInputItem, ResponseStreamEvent } from 'openai/resources/responses/responses';
3
+ import { z } from 'zod';
4
+ import type { ConversationMessage, LLMClient, ModelOption, ModelRequest, StreamingLLMResponse } from '../../llm/index.js';
5
+ import type { DeepReadonly } from '../../util/json.js';
6
+ import { type ProviderErrorFields } from './shared.js';
7
+ import { type CallHeaders } from './stream.js';
8
+ export declare class UnsupportedResponseOutputError extends Error {
9
+ constructor(types: readonly string[]);
10
+ }
11
+ export declare const OPENAI_RESPONSES_DEFAULT_MODEL = "gpt-5.4";
12
+ /**
13
+ * The models agents are told about, with the efforts lagent can send. From the list the Codex
14
+ * backend serves, which marks them available in the API (checked 2026-09-26).
15
+ */
16
+ export declare const OPENAI_RESPONSES_MODELS: readonly ModelOption[];
17
+ /**
18
+ * The usable context window of each model this provider declares one for, in tokens.
19
+ *
20
+ * The `gpt-6-*` figures come from the Codex CLI's model cache for the same models on the Codex
21
+ * backend: a `context_window` of 272,000 with its `effective_context_window_percent` of 95 applied,
22
+ * 258,400 (`~/.codex/models_cache.json`, checked 2026-10-03). `gpt-5.4`, the default, is not in
23
+ * that cache; it is given the same 258,400 as the conservative figure for the family. The raw figure
24
+ * is itself conservative: the Codex backend accepted 285,889 input tokens on a model it lists at
25
+ * 272,000 (measured 2026-10-03). A model not listed here has no window.
26
+ */
27
+ export declare const OPENAI_RESPONSES_CONTEXT_WINDOWS: Readonly<Record<string, number>>;
28
+ export declare const OpenAIResponsesConfigSchema: z.ZodObject<{
29
+ apiKey: z.ZodOptional<z.ZodString>;
30
+ streamIdleTimeoutMs: z.ZodNullable<z.ZodNumber>;
31
+ defaultHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
32
+ extraBody: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
33
+ thinkingEffort: z.ZodOptional<z.ZodEnum<{
34
+ low: "low";
35
+ high: "high";
36
+ none: "none";
37
+ medium: "medium";
38
+ max: "max";
39
+ }>>;
40
+ baseURL: z.ZodDefault<z.ZodString>;
41
+ defaultModel: z.ZodDefault<z.ZodString>;
42
+ }, z.core.$strip>;
43
+ export type OpenAIResponsesConfig = z.input<typeof OpenAIResponsesConfigSchema>;
44
+ type RequestPayload = Record<string, unknown>;
45
+ /**
46
+ * LLM client for the OpenAI Responses API. History is application-managed (`store: false`) and
47
+ * provider-owned output items round-trip through `ConversationMessage.provider_state`, so
48
+ * encrypted reasoning survives across turns.
49
+ */
50
+ export declare class OpenAIResponsesLLMClient implements LLMClient {
51
+ readonly providerName: string;
52
+ protected readonly client: OpenAI;
53
+ private readonly callHeaders;
54
+ private readonly replayByModel;
55
+ private readonly thinkingEffort;
56
+ private readonly extraBody;
57
+ private readonly streamIdleTimeoutMs;
58
+ /**
59
+ * `name` is the provider the client speaks for (Codex's, a gateway's); `headers` adds headers to
60
+ * each call; `replayByModel` narrows replayable state to the model that wrote it, for a gateway
61
+ * serving several vendors under one name. All are the client's owner's: nothing subclasses the
62
+ * client to say them.
63
+ */
64
+ constructor(config: OpenAIResponsesConfig & {
65
+ client?: OpenAI;
66
+ name?: string;
67
+ headers?: CallHeaders;
68
+ replayByModel?: boolean;
69
+ });
70
+ buildRequest(call: ModelRequest): RequestPayload;
71
+ /**
72
+ * Whose output a request may splice back verbatim, and the tag its own output is written under:
73
+ * the client's name, so another backend's state is rebuilt from the normalized fields; with
74
+ * `replayByModel`, the name and the model.
75
+ */
76
+ private replayTag;
77
+ /** The one SDK call of this protocol; `headers` are the call's own, over the client's defaults. */
78
+ protected openStream(request: RequestPayload, headers: Record<string, string>, signal: AbortSignal): Promise<AsyncIterable<ResponseStreamEvent>>;
79
+ chat(call: ModelRequest): Promise<StreamingLLMResponse>;
80
+ /**
81
+ * Whether a provider error says the request exceeded the model's context window: the structured
82
+ * code `context_length_exceeded`, on a rejected request and inside the stream alike (where the
83
+ * Codex backend reported it, with type `invalid_request_error`, param `input` and no count;
84
+ * measured 2026-10-03). A variant whose backend has no code for it overrides this.
85
+ */
86
+ protected isContextOverflow(fields: ProviderErrorFields): boolean;
87
+ }
88
+ /**
89
+ * Maps the conversation to Responses input items. An assistant message carrying **this client's**
90
+ * own state is spliced back verbatim; anything else is synthesized from the normalized fields.
91
+ *
92
+ * The tag is the client's replay tag (its name unless it narrows it) rather than this module's,
93
+ * because a credential variant talks to a different backend: Codex's encrypted reasoning is not
94
+ * something `api.openai.com` can read, so whichever client did not write it rebuilds the message from
95
+ * the normalized fields instead.
96
+ */
97
+ export declare function toResponsesInput(messages: readonly DeepReadonly<ConversationMessage>[], replayTag?: string): ResponseInputItem[];
98
+ /** Normalizes a completed response into a `ConversationMessage`, tagged for the client that got it. */
99
+ export declare function responseToMessage(response: Response, replayTag?: string): ConversationMessage;
100
+ export {};
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ import type { LLMProvider } from '../../llm/index.js';
3
+ export declare const OPENCODE_COPILOT_PROVIDER_NAME = "opencode-copilot";
4
+ declare const ConfigSchema: z.ZodObject<{
5
+ authPath: z.ZodString;
6
+ streamIdleTimeoutMs: z.ZodNullable<z.ZodNumber>;
7
+ defaultModel: z.ZodOptional<z.ZodString>;
8
+ thinkingEffort: z.ZodOptional<z.ZodEnum<{
9
+ low: "low";
10
+ high: "high";
11
+ none: "none";
12
+ medium: "medium";
13
+ max: "max";
14
+ }>>;
15
+ }, z.core.$strict>;
16
+ export type OpenCodeCopilotConfig = z.input<typeof ConfigSchema>;
17
+ /**
18
+ * Initialize before registration. Reads the OpenCode login at `authPath`, then discovers models;
19
+ * any startup failure rejects, so no provider is offered without a live catalog. No login or refresh.
20
+ * Protocols and headers follow anomalyco/opencode's github-copilot plugin (checked 2026-10-14).
21
+ */
22
+ export declare function opencodeCopilotProvider(config: OpenCodeCopilotConfig): Promise<LLMProvider>;
23
+ export {};
@@ -0,0 +1,98 @@
1
+ import type OpenAI from 'openai';
2
+ import { z } from 'zod';
3
+ import type { ModelOption, ThinkingEffort } from '../../llm/index.js';
4
+ import { GatewayLLMClient, type GatewayProtocol } from './gateway.js';
5
+ export declare const OPENCODE_GO_BASE_URL = "https://opencode.ai/zen/go/v1";
6
+ export declare const OPENCODE_GO_PROVIDER_NAME = "opencode-go";
7
+ export declare const OPENCODE_GO_DEFAULT_MODEL = "deepseek-v4.1-flash";
8
+ /**
9
+ * A model Go serves: the protocol it answers on, its context window when one is known, the efforts
10
+ * it accepts when it was found to refuse some, for a Messages model, which needs one on every
11
+ * request, its output cap, and for a Chat model that refuses the `developer` role, the role its
12
+ * notices go as instead.
13
+ */
14
+ type GoModel = {
15
+ readonly protocol: GatewayProtocol;
16
+ readonly contextWindow?: number;
17
+ readonly thinkingEfforts?: readonly ThinkingEffort[];
18
+ readonly maxOutputTokens?: number;
19
+ readonly developerRole?: DeveloperRole;
20
+ };
21
+ /** The role a Chat model is sent lagent's notices as: `developer` as they are, or `system`, in place. */
22
+ type DeveloperRole = 'developer' | 'system';
23
+ type GoModelTable = Readonly<Record<string, GoModel>>;
24
+ /**
25
+ * Every model Go serves, with the one protocol it answers on (any other endpoint returns
26
+ * `ModelProtocolUnsupported`) and its context window in tokens. Protocols from Go's model table
27
+ * (https://opencode.ai/v2/docs/console/go); windows from the `opencode-go` entry of
28
+ * https://models.dev/api.json, its `input` limit where it gives one, else `context`, undiscounted
29
+ * (both checked 2026-10-11); a Messages model's output cap is that entry's `output` limit (checked
30
+ * 2026-10-12). `GET /models` lists ids but no protocol, so nothing here is discovered.
31
+ */
32
+ export declare const OPENCODE_GO_MODEL_TABLE: GoModelTable;
33
+ export declare const OpenCodeGoConfigSchema: z.ZodObject<{
34
+ apiKey: z.ZodOptional<z.ZodString>;
35
+ streamIdleTimeoutMs: z.ZodNullable<z.ZodNumber>;
36
+ defaultHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
37
+ extraBody: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
38
+ thinkingEffort: z.ZodOptional<z.ZodEnum<{
39
+ low: "low";
40
+ high: "high";
41
+ none: "none";
42
+ medium: "medium";
43
+ max: "max";
44
+ }>>;
45
+ baseURL: z.ZodDefault<z.ZodString>;
46
+ defaultModel: z.ZodDefault<z.ZodString>;
47
+ models: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
48
+ protocol: z.ZodEnum<{
49
+ messages: "messages";
50
+ responses: "responses";
51
+ chat: "chat";
52
+ }>;
53
+ contextWindow: z.ZodOptional<z.ZodNumber>;
54
+ thinkingEfforts: z.ZodOptional<z.ZodArray<z.ZodEnum<{
55
+ low: "low";
56
+ high: "high";
57
+ none: "none";
58
+ medium: "medium";
59
+ max: "max";
60
+ }>>>;
61
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
62
+ developerRole: z.ZodOptional<z.ZodEnum<{
63
+ system: "system";
64
+ developer: "developer";
65
+ }>>;
66
+ }, z.core.$strict>>>;
67
+ }, z.core.$strip>;
68
+ export type OpenCodeGoConfig = z.input<typeof OpenCodeGoConfigSchema>;
69
+ type ParsedConfig = z.output<typeof OpenCodeGoConfigSchema>;
70
+ /**
71
+ * Go's configuration, parsed, with its default model checked to be one lagent can speak to: a model
72
+ * whose protocol nobody named, or a Messages model with no output cap, fails here rather than on the
73
+ * first turn.
74
+ */
75
+ export declare function parseOpenCodeGoConfig(config: OpenCodeGoConfig): {
76
+ readonly config: ParsedConfig;
77
+ readonly table: GoModelTable;
78
+ };
79
+ /** The models agents are told about: every model shipped and configured. */
80
+ export declare const openCodeGoModels: (table: GoModelTable) => readonly ModelOption[];
81
+ /** The declared window of `model`, `null` where neither the table nor the configuration gives one. */
82
+ export declare const openCodeGoWindow: (table: GoModelTable, model: string) => number | null;
83
+ /**
84
+ * The OpenCode Go gateway: one credential and one endpoint in front of models that each answer on
85
+ * one protocol. Each call goes to the adapter for its model's protocol, Responses, Chat Completions
86
+ * or Anthropic Messages, never tried on another endpoint. Responses and Chat share one SDK client;
87
+ * Messages goes over `fetch`, with the key as `x-api-key`. Every request carries its thread as Go's
88
+ * session header. Go serves several vendors' models under one name, and one vendor's encrypted
89
+ * reasoning or signed thinking is nothing another can read: output replays only to the model that
90
+ * wrote it, and a thread changing model is rebuilt from the normalized fields.
91
+ */
92
+ export declare class OpenCodeGoLLMClient extends GatewayLLMClient {
93
+ constructor(config: OpenCodeGoConfig & {
94
+ client?: OpenAI;
95
+ fetch?: typeof globalThis.fetch;
96
+ });
97
+ }
98
+ export {};