@leuduan/lagent 0.1.2 → 44.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -15
- package/dist/chunks/{UC3FVVJ2.js → 2GCIWSOA.js} +2 -2
- package/dist/chunks/2P47AHNK.js +7 -0
- package/dist/chunks/3UMZMPWW.js +1 -0
- package/dist/chunks/5IRF47YB.js +1 -0
- package/dist/chunks/6DRCKZ2C.js +1 -0
- package/dist/chunks/6FRNHMCV.js +1 -0
- package/dist/chunks/7LI64H5X.js +17 -0
- package/dist/chunks/{SL2YLB2F.js → 7VAPNE3L.js} +1 -1
- package/dist/chunks/{BM3S37EZ.js → ASSQZH3F.js} +1 -1
- package/dist/chunks/B4FXK5ER.js +77 -0
- package/dist/chunks/{37YOGDGY.js → BBCW2FZK.js} +1 -1
- package/dist/chunks/BPRCULZH.js +1 -0
- package/dist/chunks/CANPZYTH.js +24 -0
- package/dist/chunks/CQEVREBT.js +1 -0
- package/dist/chunks/CUK7CGC7.js +1 -0
- package/dist/chunks/D4PQP5MA.js +3 -0
- package/dist/chunks/{CDQG7RKA.js → DDZ7YF26.js} +1 -1
- package/dist/chunks/EMRB4KCN.js +6 -0
- package/dist/chunks/EPYQ5M3B.js +3 -0
- package/dist/chunks/G44LG6VL.js +1 -0
- package/dist/chunks/GGSVIIWJ.js +2 -0
- package/dist/chunks/IAAEP6VL.js +30 -0
- package/dist/chunks/{AP6Q4EPT.js → JCTBX33H.js} +1 -1
- package/dist/chunks/JFX2MXBA.js +4 -0
- package/dist/chunks/JFZZXVWD.js +15 -0
- package/dist/chunks/KUZCL2SH.js +1 -0
- package/dist/chunks/MHC6VPB4.js +7 -0
- package/dist/chunks/MMNNZCBO.js +5 -0
- package/dist/chunks/{C5LYCXJG.js → MNJ4SRF7.js} +1 -1
- package/dist/chunks/N6IXG2VL.js +1 -0
- package/dist/chunks/OCBPT7KE.js +1 -0
- package/dist/chunks/OL5A6ITQ.js +1 -0
- package/dist/chunks/Q75FUN7D.js +2 -0
- package/dist/chunks/Q7S5LFGN.js +1 -0
- package/dist/chunks/RCIHV3KG.js +1 -0
- package/dist/chunks/S34ZA2R6.js +1 -0
- package/dist/chunks/SS3B5W34.js +12 -0
- package/dist/chunks/VYMT4TXD.js +1 -0
- package/dist/chunks/W57RW55W.js +1 -0
- package/dist/compositions/base.d.ts +11 -0
- package/dist/{presets → compositions}/codex.d.ts +12 -6
- package/dist/{presets/prompts.d.ts → compositions/codexPrompts.d.ts} +1 -1
- package/dist/context.d.ts +18 -10
- package/dist/index.d.ts +31 -23
- package/dist/index.js +1 -77
- package/dist/journal/catalog.d.ts +1 -1
- package/dist/journal/journal.d.ts +3 -3
- package/dist/journal/projection.d.ts +1 -1
- package/dist/journal/store.d.ts +3 -3
- package/dist/llm/index.d.ts +19 -13
- package/dist/llm/index.js +1 -0
- package/dist/llm/provider.d.ts +11 -0
- package/dist/loop/agent.d.ts +16 -132
- package/dist/loop/authorization.d.ts +41 -0
- package/dist/loop/auxiliary.d.ts +7 -3
- package/dist/loop/chunks.d.ts +3 -3
- package/dist/loop/completion.d.ts +17 -0
- package/dist/loop/errors.d.ts +6 -29
- package/dist/loop/hooks.d.ts +39 -6
- package/dist/loop/index.d.ts +7 -28
- package/dist/loop/runner.d.ts +134 -0
- package/dist/loop/runtime.d.ts +7 -16
- package/dist/loop/strategy.d.ts +12 -3
- package/dist/loop/{prepare.d.ts → surfacePrepare.d.ts} +2 -2
- package/dist/loop/tool.d.ts +11 -6
- package/dist/loop/toolCalls.d.ts +3 -10
- package/dist/plugin.d.ts +31 -34
- package/dist/plugin.js +1 -1
- package/dist/plugins/agentsMd.d.ts +24 -20
- package/dist/plugins/agentsMd.js +1 -1
- package/dist/plugins/ask/index.d.ts +2 -2
- package/dist/plugins/ask/index.js +1 -1
- package/dist/plugins/ask/service.d.ts +2 -2
- package/dist/plugins/commands/index.d.ts +5 -2
- package/dist/plugins/commands/index.js +1 -1
- package/dist/plugins/commands/output.d.ts +1 -1
- package/dist/plugins/commands/record.d.ts +31 -22
- package/dist/plugins/commands/service.d.ts +18 -11
- package/dist/plugins/commands/{background.d.ts → tools.d.ts} +2 -0
- package/dist/plugins/compaction/checkpoint.d.ts +4 -1
- package/dist/plugins/compaction/config.d.ts +3 -3
- package/dist/plugins/compaction/estimate.d.ts +9 -1
- package/dist/plugins/compaction/index.d.ts +87 -2
- package/dist/plugins/compaction/index.js +5 -5
- package/dist/plugins/compaction/{records.d.ts → record.d.ts} +36 -36
- package/dist/plugins/compaction/{log.d.ts → state.d.ts} +8 -1
- package/dist/plugins/dateAndBranch.js +1 -1
- package/dist/plugins/delegations/answers.d.ts +1 -1
- package/dist/plugins/delegations/assignmentKey.d.ts +1 -1
- package/dist/plugins/delegations/cleanup.d.ts +1 -1
- package/dist/plugins/delegations/index.js +1 -1
- package/dist/plugins/delegations/notices.d.ts +8 -8
- package/dist/plugins/delegations/obligations.d.ts +13 -13
- package/dist/plugins/delegations/record.d.ts +11 -10
- package/dist/plugins/delegations/request.d.ts +8 -5
- package/dist/plugins/delegations/role.d.ts +1 -1
- package/dist/plugins/delegations/service.d.ts +9 -8
- package/dist/plugins/delegations/{waitBook.d.ts → waitResolver.d.ts} +9 -9
- package/dist/plugins/diagnostics/digest.d.ts +1 -1
- package/dist/plugins/diagnostics/index.d.ts +1 -1
- package/dist/plugins/diagnostics/index.js +1 -1
- package/dist/plugins/fileTools/config.d.ts +10 -0
- package/dist/plugins/{tools → fileTools}/editFiles.d.ts +16 -27
- package/dist/plugins/fileTools/gitDiscovery.d.ts +9 -0
- package/dist/plugins/fileTools/index.d.ts +18 -0
- package/dist/plugins/fileTools/index.js +1 -0
- package/dist/plugins/fileTools/tools.d.ts +6 -0
- package/dist/plugins/historyRecall/history.d.ts +1 -1
- package/dist/plugins/historyRecall/index.js +1 -1
- package/dist/plugins/historyRecall/render.d.ts +1 -1
- package/dist/plugins/mcp/catalog.d.ts +1 -1
- package/dist/plugins/mcp/index.d.ts +2 -2
- package/dist/plugins/mcp/index.js +1 -1
- package/dist/plugins/mcp/mount.d.ts +2 -2
- package/dist/plugins/mcp/render.d.ts +1 -1
- package/dist/plugins/mcp/{tool.d.ts → tools.d.ts} +1 -1
- package/dist/plugins/{routeContext.d.ts → routeNotice.d.ts} +2 -2
- package/dist/plugins/routeNotice.js +1 -0
- package/dist/{sandbox → plugins/sandbox}/absent.d.ts +11 -10
- package/dist/{sandbox → plugins/sandbox}/index.d.ts +5 -2
- package/dist/plugins/sandbox/index.js +4 -0
- package/dist/{sandbox → plugins/sandbox}/mode.d.ts +5 -5
- package/dist/plugins/sandbox/policy.d.ts +163 -0
- package/dist/{sandbox → plugins/sandbox}/service.d.ts +23 -13
- package/dist/plugins/schedules/index.js +3 -3
- package/dist/plugins/schedules/record.d.ts +18 -18
- package/dist/plugins/schedules/service.d.ts +2 -2
- package/dist/plugins/skills/discovery.d.ts +38 -9
- package/dist/plugins/skills/index.d.ts +1 -1
- package/dist/plugins/skills/index.js +1 -1
- package/dist/plugins/subAgents/index.js +1 -1
- package/dist/plugins/subAgents/{fork.d.ts → tools.d.ts} +36 -1
- package/dist/plugins/threadDirs.d.ts +36 -0
- package/dist/plugins/threadDirs.js +1 -0
- package/dist/plugins/toolPolicy/index.d.ts +2 -2
- package/dist/plugins/toolPolicy/index.js +1 -1
- package/dist/plugins/truncateToolOutput.d.ts +14 -10
- package/dist/plugins/truncateToolOutput.js +6 -1
- package/dist/plugins/usage/index.d.ts +4 -2
- package/dist/plugins/usage/index.js +1 -1
- package/dist/plugins/usage/tracker.d.ts +1 -1
- package/dist/plugins/verify/index.d.ts +7 -55
- package/dist/plugins/verify/index.js +6 -1
- package/dist/plugins/verify/judgement.d.ts +16 -0
- package/dist/plugins/verify/record.d.ts +382 -0
- package/dist/plugins/verify/service.d.ts +7 -4
- package/dist/plugins/verify/state.d.ts +58 -0
- package/dist/plugins/webTools/index.d.ts +34 -0
- package/dist/plugins/webTools/index.js +1 -0
- package/dist/plugins/workflows/assignment.d.ts +6 -2
- package/dist/plugins/workflows/cleanup.d.ts +1 -1
- package/dist/plugins/workflows/definition.d.ts +2 -2
- package/dist/plugins/workflows/{bindings.d.ts → entryPlan.d.ts} +2 -2
- package/dist/plugins/workflows/{providers.d.ts → hostBindings.d.ts} +2 -2
- package/dist/plugins/workflows/index.d.ts +4 -4
- package/dist/plugins/workflows/index.js +10 -5
- package/dist/plugins/workflows/observations.d.ts +3 -3
- package/dist/plugins/workflows/participantModels.d.ts +28 -0
- package/dist/plugins/workflows/participants.d.ts +2 -2
- package/dist/plugins/workflows/policy.d.ts +2 -2
- package/dist/plugins/workflows/record.d.ts +51 -65
- package/dist/plugins/workflows/routing.d.ts +2 -2
- package/dist/plugins/workflows/service.d.ts +24 -24
- package/dist/plugins/workflows/{fold.d.ts → state.d.ts} +2 -2
- package/dist/plugins/workflows/stopCheck.d.ts +13 -0
- package/dist/plugins/workflows/tools.d.ts +13 -0
- package/dist/plugins/workflows/view.d.ts +2 -2
- package/dist/plugins/{workspaceContext.d.ts → workspaceNotice.d.ts} +5 -7
- package/dist/plugins/workspaceNotice.js +1 -0
- package/dist/{plugins/providers → providers}/anthropic.d.ts +6 -3
- package/dist/{plugins/providers → providers}/anthropicMessages.d.ts +2 -1
- package/dist/{plugins/providers → providers}/codex.d.ts +14 -3
- package/dist/{plugins/providers → providers}/deepseek.d.ts +6 -2
- package/dist/{plugins/providers → providers}/failure.d.ts +1 -1
- package/dist/{plugins/providers → providers}/gateway.d.ts +2 -1
- package/dist/providers/index.d.ts +18 -0
- package/dist/providers/index.js +6 -0
- package/dist/{plugins/providers → providers}/openaiChat.d.ts +13 -2
- package/dist/{plugins/providers → providers}/openaiResponses.d.ts +12 -3
- package/dist/{plugins/providers → providers}/opencodeCopilot.d.ts +2 -2
- package/dist/{plugins/providers → providers}/opencodeGo.d.ts +18 -7
- package/dist/{plugins/providers → providers}/shared.d.ts +9 -1
- package/dist/{plugins/providers → providers}/stream.d.ts +4 -2
- package/dist/{models/door.d.ts → records/index.d.ts} +8 -7
- package/dist/records/index.js +1 -0
- package/dist/{models/wire → records}/journal.d.ts +210 -14
- package/dist/{models/wire/primitives.d.ts → records/toolResult.d.ts} +1 -1
- package/dist/services/agents.d.ts +26 -1
- package/dist/services/confinement/files.d.ts +118 -0
- package/dist/services/confinement/service.d.ts +219 -0
- package/dist/services/core.d.ts +2 -8
- package/dist/{kit/extension.d.ts → services/extensionEvents.d.ts} +5 -4
- package/dist/services/journal.d.ts +1 -1
- package/dist/services/llm.d.ts +4 -2
- package/dist/{kit → services}/modes.d.ts +1 -1
- package/dist/services/plugins.d.ts +34 -0
- package/dist/services/{preset.d.ts → presets/definition.d.ts} +4 -4
- package/dist/services/{presets.d.ts → presets/installations.d.ts} +3 -3
- package/dist/services/prompts.d.ts +23 -5
- package/dist/services/{threadActivation.d.ts → threads/activation.d.ts} +3 -3
- package/dist/services/{admission.d.ts → threads/admission.d.ts} +3 -3
- package/dist/services/{birth.d.ts → threads/birth.d.ts} +9 -10
- package/dist/services/threads/index.d.ts +14 -0
- package/dist/services/{runEvents.d.ts → threads/runEvents.d.ts} +2 -2
- package/dist/services/{owner.d.ts → threads/runOwner.d.ts} +5 -4
- package/dist/services/{threads.d.ts → threads/service.d.ts} +9 -8
- package/dist/services/{thread.d.ts → threads/thread.d.ts} +8 -7
- package/dist/services/{threadView.d.ts → threads/view.d.ts} +7 -6
- package/dist/services/tools.d.ts +79 -2
- package/dist/{loop/opening.d.ts → state/birth.d.ts} +22 -2
- package/dist/{loop → state}/chain.d.ts +3 -3
- package/dist/state/confirmations.d.ts +64 -0
- package/dist/{loop → state}/continuation.d.ts +3 -2
- package/dist/{loop → state}/decide.d.ts +10 -2
- package/dist/state/dispatches.d.ts +54 -0
- package/dist/state/errors.d.ts +26 -0
- package/dist/{loop → state}/forks.d.ts +1 -1
- package/dist/{loop → state}/holds.d.ts +1 -1
- package/dist/{loop → state}/inbox.d.ts +2 -2
- package/dist/state/index.d.ts +31 -0
- package/dist/state/inputs.d.ts +58 -0
- package/dist/state/installations.d.ts +28 -0
- package/dist/state/prompt.d.ts +13 -0
- package/dist/state/recovery.d.ts +7 -0
- package/dist/{loop → state}/replace.d.ts +2 -2
- package/dist/{loop → state}/requests.d.ts +3 -3
- package/dist/{loop → state}/route.d.ts +10 -2
- package/dist/state/summary.d.ts +16 -0
- package/dist/{loop → state}/surface.d.ts +3 -3
- package/dist/state/surfaceRead.d.ts +20 -0
- package/dist/{loop/threadState.d.ts → state/thread.d.ts} +12 -11
- package/dist/state/turns.d.ts +87 -0
- package/dist/state/waits.d.ts +38 -0
- package/dist/{loop → state}/wake.d.ts +1 -1
- package/dist/stores/durableObject.js +1 -0
- package/dist/{plugins/store → stores}/memory.d.ts +2 -2
- package/dist/{plugins/store → stores}/sql.d.ts +2 -2
- package/dist/stores/sqlite.js +1 -0
- package/dist/sys/environment.d.ts +0 -5
- package/dist/sys/git.d.ts +0 -13
- package/dist/sys/paths.d.ts +0 -47
- package/dist/sys/spawn.d.ts +16 -6
- package/dist/testing/clock.d.ts +1 -1
- package/dist/testing/fakeLlm.d.ts +4 -2
- package/dist/testing/fedLlm.d.ts +3 -1
- package/dist/testing/helpers.d.ts +31 -13
- package/dist/testing/index.js +1 -1
- package/dist/testing/settlement.d.ts +1 -1
- package/package.json +36 -28
- package/dist/chunks/2O7ZGEIT.js +0 -1
- package/dist/chunks/2OSESBIL.js +0 -1
- package/dist/chunks/3LQHQRIU.js +0 -6
- package/dist/chunks/3QCW4WDJ.js +0 -1
- package/dist/chunks/4XVRUSCQ.js +0 -1
- package/dist/chunks/6ECI2GGV.js +0 -1
- package/dist/chunks/74HKUGRR.js +0 -1
- package/dist/chunks/ADHERZLW.js +0 -2
- package/dist/chunks/D7E6EWIE.js +0 -3
- package/dist/chunks/DRYAN665.js +0 -1
- package/dist/chunks/DXFXAYDN.js +0 -17
- package/dist/chunks/EGZI4XQX.js +0 -24
- package/dist/chunks/ENWFSU27.js +0 -41
- package/dist/chunks/G6RXC3AL.js +0 -1
- package/dist/chunks/G74AGRAJ.js +0 -15
- package/dist/chunks/GQGNVSKB.js +0 -1
- package/dist/chunks/IJ2WNMD5.js +0 -7
- package/dist/chunks/JPZFKSWT.js +0 -1
- package/dist/chunks/KESCTXGO.js +0 -5
- package/dist/chunks/L3N4FIEN.js +0 -1
- package/dist/chunks/NAOUTU7A.js +0 -4
- package/dist/chunks/NDIM7MEW.js +0 -1
- package/dist/chunks/O4PPOM5Z.js +0 -2
- package/dist/chunks/OVZFGILJ.js +0 -1
- package/dist/chunks/P5ZHHOOM.js +0 -6
- package/dist/chunks/QMMLQJBS.js +0 -1
- package/dist/chunks/RK3VP2Q4.js +0 -3
- package/dist/chunks/SGGMBSBA.js +0 -1
- package/dist/chunks/TOOIB6J2.js +0 -1
- package/dist/chunks/TYTQRLTX.js +0 -1
- package/dist/chunks/UCTEU62F.js +0 -1
- package/dist/chunks/UD3VJER6.js +0 -1
- package/dist/chunks/WUUKTSRT.js +0 -7
- package/dist/chunks/X65X4KP5.js +0 -7
- package/dist/chunks/YIR5MYGU.js +0 -1
- package/dist/chunks/YLNJXQ3Z.js +0 -1
- package/dist/kit/claim.d.ts +0 -13
- package/dist/kit/drain.d.ts +0 -10
- package/dist/kit/grants.d.ts +0 -9
- package/dist/kit/scope.d.ts +0 -32
- package/dist/kit/service.d.ts +0 -7
- package/dist/kit/strategy.d.ts +0 -10
- package/dist/kit/tool.d.ts +0 -72
- package/dist/llm/door.d.ts +0 -21
- package/dist/llm/door.js +0 -1
- package/dist/loop/projections.d.ts +0 -307
- package/dist/loop/state.d.ts +0 -70
- package/dist/loop/summary.d.ts +0 -3
- package/dist/models/config/agent.d.ts +0 -18
- package/dist/models/config/prompt.d.ts +0 -18
- package/dist/models/door.js +0 -1
- package/dist/models/index.d.ts +0 -7
- package/dist/plugins/commands/foreground.d.ts +0 -4
- package/dist/plugins/compaction/preset.d.ts +0 -86
- package/dist/plugins/compaction/shared.d.ts +0 -14
- package/dist/plugins/delegations/testing.d.ts +0 -16
- package/dist/plugins/providers/door.d.ts +0 -61
- package/dist/plugins/providers/door.js +0 -1
- package/dist/plugins/providers/index.d.ts +0 -6
- package/dist/plugins/routeContext.js +0 -1
- package/dist/plugins/store/durableObject.js +0 -1
- package/dist/plugins/store/sqlite.js +0 -1
- package/dist/plugins/subAgents/tool.d.ts +0 -38
- package/dist/plugins/tools/index.d.ts +0 -59
- package/dist/plugins/tools/index.js +0 -1
- package/dist/plugins/verify/facts.d.ts +0 -356
- package/dist/plugins/workflows/submit.d.ts +0 -8
- package/dist/plugins/workspaceContext.js +0 -1
- package/dist/presets/agents.d.ts +0 -7
- package/dist/presets/base.d.ts +0 -10
- package/dist/presets/index.d.ts +0 -4
- package/dist/sandbox/index.js +0 -4
- package/dist/sandbox/policy.d.ts +0 -86
- package/dist/services/launches.d.ts +0 -104
- package/dist/services/threadDirs.d.ts +0 -38
- package/dist/testing/sandbox.d.ts +0 -71
- /package/dist/chunks/{UKXMCHHT.js → FJLU4UH3.js} +0 -0
- /package/dist/chunks/{J5S4URAW.js → HK6ZSONF.js} +0 -0
- /package/dist/plugins/ask/{askQuestion.d.ts → tools.d.ts} +0 -0
- /package/dist/plugins/delegations/{waits.d.ts → waitContracts.d.ts} +0 -0
- /package/dist/plugins/{tools → fileTools}/fsRead.d.ts +0 -0
- /package/dist/plugins/{tools → fileTools}/ripgrep.d.ts +0 -0
- /package/dist/plugins/{tools → fileTools}/textEdit.d.ts +0 -0
- /package/dist/{util → plugins/mcp}/version.d.ts +0 -0
- /package/dist/{sandbox → plugins/sandbox}/client.d.ts +0 -0
- /package/dist/{sandbox → plugins/sandbox}/files.d.ts +0 -0
- /package/dist/{sandbox → plugins/sandbox}/protocol.d.ts +0 -0
- /package/dist/{sandbox → plugins/sandbox}/worker.d.ts +0 -0
- /package/dist/{sandbox → plugins/sandbox}/worker.js +0 -0
- /package/dist/plugins/skills/{tool.d.ts → tools.d.ts} +0 -0
- /package/dist/plugins/{tools → webTools}/html.d.ts +0 -0
- /package/dist/plugins/{tools → webTools}/network.d.ts +0 -0
- /package/dist/plugins/{tools → webTools}/web.d.ts +0 -0
- /package/dist/plugins/workflows/{work.d.ts → workStatus.d.ts} +0 -0
- /package/dist/{plugins/providers → providers}/codexAuth.d.ts +0 -0
- /package/dist/services/{contributions.d.ts → catalogContributions.d.ts} +0 -0
- /package/dist/{loop → state}/limits.d.ts +0 -0
- /package/dist/{plugins/store → stores}/durableObject.d.ts +0 -0
- /package/dist/{plugins/store → stores}/durableObjectConnection.d.ts +0 -0
- /package/dist/{plugins/store → stores}/sqlite.d.ts +0 -0
- /package/dist/{models → util}/jsonSchema.d.ts +0 -0
- /package/dist/{kit → util}/retries.d.ts +0 -0
- /package/dist/{kit → util}/timers.d.ts +0 -0
|
@@ -2,17 +2,15 @@ import type { Plugin } from '@leuduan/cordis';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
declare const WorkspaceSchema: z.ZodObject<{
|
|
4
4
|
cwd: z.ZodString;
|
|
5
|
-
read_roots: z.ZodArray<z.ZodString>;
|
|
6
5
|
}, z.core.$strict>;
|
|
7
|
-
/** Where a thread works: its `cwd
|
|
6
|
+
/** Where a thread works: its `cwd`. */
|
|
8
7
|
export type Workspace = z.output<typeof WorkspaceSchema>;
|
|
9
8
|
/**
|
|
10
|
-
* Briefs an agent on where it works: its thread's `cwd
|
|
11
|
-
* the operating system.
|
|
9
|
+
* Briefs an agent on where it works: its thread's `cwd` and the operating system.
|
|
12
10
|
*
|
|
13
11
|
* Only the operating system goes into the prompt, which is recorded once and must not depend on
|
|
14
|
-
* which thread it is (see `PromptRenderInput`). The working directory
|
|
15
|
-
* a conversation message at the next model step that is already due, whenever
|
|
12
|
+
* which thread it is (see `PromptRenderInput`). The working directory is told as
|
|
13
|
+
* a conversation message at the next model step that is already due, whenever it differs from the
|
|
16
14
|
* latest notice the model can still see: on its first step, again if they change, and again after a
|
|
17
15
|
* replacement took that notice off the surface. The cached part of the request ahead of the history
|
|
18
16
|
* is never rewritten, and threads in one workspace are told the same notice.
|
|
@@ -28,7 +26,7 @@ export type Workspace = z.output<typeof WorkspaceSchema>;
|
|
|
28
26
|
* only. The notice is per thread, so it reaches a role child too; the prompt section is for every
|
|
29
27
|
* global agent, so it does not.
|
|
30
28
|
*/
|
|
31
|
-
export declare const
|
|
29
|
+
export declare const workspaceNotice: Plugin.Object<undefined>;
|
|
32
30
|
/**
|
|
33
31
|
* What a thread is told: its whole workspace, every time, with a working directory that differs
|
|
34
32
|
* from `told`, the notice the model can still see, noted as previously.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c}from"../chunks/Q7S5LFGN.js";import"../chunks/EPYQ5M3B.js";import"../chunks/6FRNHMCV.js";import"../chunks/CUK7CGC7.js";import"../chunks/BPRCULZH.js";import"../chunks/DDANMY45.js";import"../chunks/BBCW2FZK.js";import"../chunks/MMNNZCBO.js";import"../chunks/G44LG6VL.js";import"../chunks/D4PQP5MA.js";export{c as renderEnvironmentInfo,b as renderWorkspaceNotice,a as workspaceNotice};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { ContentPart
|
|
2
|
-
import type {
|
|
1
|
+
import type { ContentPart } from '../llm/content.js';
|
|
2
|
+
import type { ConversationMessage, JsonObject, LLMStreamChunk, ModelResponse, ResponseFinish, ThinkingEffort, ToolSpec } from '../llm/primitives.js';
|
|
3
|
+
import type { FailureClassification } from '../llm/failure.js';
|
|
4
|
+
import type { ToolChoice } from '../llm/request.js';
|
|
5
|
+
import type { DeepReadonly } from '../util/json.js';
|
|
3
6
|
/** One Messages content block, as JSON. */
|
|
4
7
|
export type AnthropicBlock = Record<string, unknown>;
|
|
5
8
|
/** One Messages turn. Consecutive messages of one role are one turn. */
|
|
@@ -111,7 +114,7 @@ export declare class AnthropicAPIError extends Error {
|
|
|
111
114
|
}
|
|
112
115
|
/**
|
|
113
116
|
* Whether a failure says the request exceeded the model's context window. The API names no code of
|
|
114
|
-
* its own for it, only `invalid_request_error`, so its wording decides, as `
|
|
117
|
+
* its own for it, only `invalid_request_error`, so its wording decides, as `docs/guides/providers.md` allows
|
|
115
118
|
* where a provider has no code: "prompt is too long", which a gateway may wrap in its own prose.
|
|
116
119
|
*/
|
|
117
120
|
export declare const isAnthropicOverflow: (error: AnthropicAPIError) => boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { LLMClient,
|
|
2
|
+
import type { LLMClient, StreamingLLMResponse } from '../llm/client.js';
|
|
3
|
+
import type { ModelRequest } from '../llm/request.js';
|
|
3
4
|
import { type AnthropicStreamEvent } from './anthropic.js';
|
|
4
5
|
import { type CallHeaders } from './stream.js';
|
|
5
6
|
declare const AnthropicMessagesConfigSchema: z.ZodObject<{
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import type { ModelOption } from '
|
|
3
|
+
import type { ModelOption } from '../llm/client.js';
|
|
4
|
+
import type { LLMProvider } from '../llm/provider.js';
|
|
4
5
|
import { type CodexCredentialManager } from './codexAuth.js';
|
|
5
6
|
import { OpenAIResponsesLLMClient } from './openaiResponses.js';
|
|
6
7
|
export declare const CODEX_PROVIDER_NAME = "codex";
|
|
@@ -14,8 +15,9 @@ export declare const CODEX_DEFAULT_MODEL = "gpt-5.6-luna";
|
|
|
14
15
|
export declare const CODEX_MODELS: readonly ModelOption[];
|
|
15
16
|
/**
|
|
16
17
|
* The usable context window of every model the Codex CLI's model cache lists, in tokens: its
|
|
17
|
-
* `context_window`
|
|
18
|
-
*
|
|
18
|
+
* `context_window` with its `effective_context_window_percent` of 95 applied. `gpt-6.1-sol` lists
|
|
19
|
+
* 500,000, so 475,000; every other model lists 272,000, so 258,400
|
|
20
|
+
* (`~/.codex/models_cache.json`, checked 2026-10-23). The raw figure is itself conservative: the
|
|
19
21
|
* backend accepted 285,889 input tokens on `gpt-5.6-luna`, listed at 272,000 (measured 2026-10-03).
|
|
20
22
|
* A model not listed here has no window.
|
|
21
23
|
*/
|
|
@@ -58,3 +60,12 @@ export declare class CodexLLMClient extends OpenAIResponsesLLMClient {
|
|
|
58
60
|
* goes as it is.
|
|
59
61
|
*/
|
|
60
62
|
export declare const compressingFetch: (baseFetch?: typeof globalThis.fetch) => typeof globalThis.fetch;
|
|
63
|
+
/**
|
|
64
|
+
* The Codex provider: the same Responses API, reached with the ChatGPT login that `codex login`
|
|
65
|
+
* leaves in the file `authPath` names instead of an API key, reread per request and refreshed in
|
|
66
|
+
* place when it nears expiry.
|
|
67
|
+
*/
|
|
68
|
+
export declare const codexProvider: (config: CodexConfig & {
|
|
69
|
+
readonly authPath: string;
|
|
70
|
+
readonly refreshTimeoutMs: number;
|
|
71
|
+
}) => LLMProvider;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type OpenAI from 'openai';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import type { ModelOption
|
|
3
|
+
import type { ModelOption } from '../llm/client.js';
|
|
4
|
+
import type { ModelRequest } from '../llm/request.js';
|
|
5
|
+
import type { LLMProvider } from '../llm/provider.js';
|
|
4
6
|
import { OpenAIResponsesLLMClient } from './openaiResponses.js';
|
|
5
|
-
import { type ProviderErrorFields } from './shared.js';
|
|
7
|
+
import { type ProviderErrorFields, type WithCredential } from './shared.js';
|
|
6
8
|
/** The stateless Responses endpoint DeepSeek documents as OpenAI-compatible. */
|
|
7
9
|
export declare const DEEPSEEK_RESPONSES_BASE_URL = "https://api.deepseek.com";
|
|
8
10
|
export declare const DEEPSEEK_RESPONSES_PROVIDER_NAME = "deepseek-responses";
|
|
@@ -52,4 +54,6 @@ export declare class DeepSeekResponsesLLMClient extends OpenAIResponsesLLMClient
|
|
|
52
54
|
/** The structured code where DeepSeek sends one, else the wording of its message. */
|
|
53
55
|
protected isContextOverflow(fields: ProviderErrorFields): boolean;
|
|
54
56
|
}
|
|
57
|
+
/** DeepSeek's Responses API provider, at DeepSeek's endpoint unless `baseURL` names another. */
|
|
58
|
+
export declare const deepseekProvider: (config: WithCredential<DeepSeekResponsesConfig>) => LLMProvider;
|
|
55
59
|
export {};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* the kind of a socket error code, and the wait a response's headers ask for. Structured evidence
|
|
4
4
|
* only; each protocol's own codes and types are classified beside its adapter.
|
|
5
5
|
*/
|
|
6
|
-
import type { FailureClassification, FailureKind } from '
|
|
6
|
+
import type { FailureClassification, FailureKind } from '../llm/failure.js';
|
|
7
7
|
/**
|
|
8
8
|
* The kind an HTTP status says on its own, the one fallback every protocol shares: `undefined` for a
|
|
9
9
|
* status it does not name. With the SDKs' own retries off, every status they used to retry (408, 409,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { LLMClient,
|
|
1
|
+
import type { LLMClient, StreamingLLMResponse } from '../llm/client.js';
|
|
2
|
+
import type { ModelRequest } from '../llm/request.js';
|
|
2
3
|
/** The protocols a gateway's models answer on: OpenAI Responses, Chat Completions, Anthropic Messages. */
|
|
3
4
|
export type GatewayProtocol = 'responses' | 'chat' | 'messages';
|
|
4
5
|
/** A gateway's check of a call: the protocol it goes on and the call to send. */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@leuduan/lagent/providers`: the shipped providers, their configuration types and the Codex login
|
|
3
|
+
* helpers a host resolves a credential with. Names only: each provider is built in its own module,
|
|
4
|
+
* and what the package keeps private (`codexBackend`) is imported from the module that defines it.
|
|
5
|
+
*/
|
|
6
|
+
export { codexAuthPath, CodexCredentialError } from './codexAuth.js';
|
|
7
|
+
export { CODEX_PROVIDER_NAME, codexProvider } from './codex.js';
|
|
8
|
+
export type { CodexConfig } from './codex.js';
|
|
9
|
+
export { DEEPSEEK_RESPONSES_PROVIDER_NAME, deepseekProvider } from './deepseek.js';
|
|
10
|
+
export type { DeepSeekResponsesConfig } from './deepseek.js';
|
|
11
|
+
export { openaiChatProvider } from './openaiChat.js';
|
|
12
|
+
export type { OpenAIChatConfig } from './openaiChat.js';
|
|
13
|
+
export { openaiResponsesProvider } from './openaiResponses.js';
|
|
14
|
+
export type { OpenAIResponsesConfig } from './openaiResponses.js';
|
|
15
|
+
export { OPENCODE_COPILOT_PROVIDER_NAME, opencodeCopilotProvider } from './opencodeCopilot.js';
|
|
16
|
+
export type { OpenCodeCopilotConfig } from './opencodeCopilot.js';
|
|
17
|
+
export { OPENCODE_GO_PROVIDER_NAME, opencodeGoProvider } from './opencodeGo.js';
|
|
18
|
+
export type { OpenCodeGoConfig } from './opencodeGo.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{b as xe,c as ye,d as Ee,e as C,f as R,g as S,h as I,i as ke,j as y,k as $,l as N,m as we,n as u,o as H,p as q,q as E,r as Oe,s as A,t as ve,u as Y,v as tt,w as Te,x as be,y as Ce}from"../chunks/Q75FUN7D.js";import{a as ge}from"../chunks/PUSUPTAT.js";import"../chunks/34KW6VNQ.js";import{h as _e}from"../chunks/DDANMY45.js";import{A as F,d as j,e as g,l as U,n as fe,p as x,r as O,u as p,v as B}from"../chunks/D4PQP5MA.js";import{createHash as ft}from"node:crypto";import{isAbsolute as _t}from"node:path";import{promisify as Ae}from"node:util";import*as L from"node:zlib";import"openai";import{z as P}from"zod";import"openai";import{z as Re}from"zod";var Z=class extends Error{constructor(e){super(`The model returned output items lagent cannot execute: ${e.join(", ")}`),this.name="UnsupportedResponseOutputError"}},ot=new Set(["file_search_call","web_search_call","code_interpreter_call","mcp_call","mcp_list_tools","mcp_approval_response","image_generation_call","computer_call_output","function_call_output","local_shell_call_output","exec","reasoning_summary","item_reference","custom_tool_call_output"]),nt=new Set(["file_search_call","web_search_call","code_interpreter_call","mcp_call","image_generation_call"]);function Ie(o){if(!nt.has(o.type))return;let e=o,t=e.action,n=e.status;return fe.parse({id:e.id??o.type,type:o.type,name:e.name??e.server_label??null,status:n==="in_progress"||n==="failed"?n:"completed",summary:t?.query??e.code??null})}var st=new Set(["apply_patch_call","computer_call","custom_tool_call","local_shell_call","mcp_approval_request","shell_call"]),ee="openai-responses",te="gpt-5.4",J=["low","medium","high","max"],oe=[{id:"gpt-6-sol",description:"Workhorse for coding and everyday work",thinkingEfforts:J},{id:"gpt-6-astra",description:"Frontier intelligence for the most demanding work",thinkingEfforts:J},{id:"gpt-6-luna",description:"Fast and affordable, for easier tasks",thinkingEfforts:J}],it={"gpt-6-sol":258400,"gpt-6-astra":258400,"gpt-6-luna":258400,[te]:258400},Ne=E.extend({baseURL:Re.string().default(q),defaultModel:Re.string().default(te)}),m=class{providerName;client;callHeaders;replayByModel;thinkingEffort;extraBody;streamIdleTimeoutMs;constructor(e){let t=Ne.parse(e);this.providerName=e.name??ee,this.callHeaders=e.headers,this.replayByModel=e.replayByModel??!1,this.streamIdleTimeoutMs=t.streamIdleTimeoutMs,this.thinkingEffort=t.thinkingEffort??"none",this.extraBody=t.extraBody??{},this.client=A("OpenAI Responses",t,e.client)}buildRequest(e){let t=F(e.systemPrompt),n=e.thinkingEffort??this.thinkingEffort,s={...this.extraBody,model:e.model,...t?{instructions:t}:{},input:pt(e.messages,this.replayTag(e.model)),stream:!0,store:!1,include:["reasoning.encrypted_content"],reasoning:n==="none"?{effort:n}:{effort:n,summary:"auto"}};e.maxOutputTokens!==void 0&&(s.max_output_tokens=e.maxOutputTokens);let r=at(e.responseFormat);return r!==void 0&&(s.text={format:r}),(e.tools.length>0||e.providerTools.length>0)&&(s.tools=[...e.tools.map(lt),...e.providerTools],s.tool_choice=rt(e.toolChoice),s.parallel_tool_calls=e.parallelToolCalls),s}replayTag(e){return this.replayByModel?`${this.providerName}/${e}`:this.providerName}async openStream(e,t,n){return await this.client.responses.create(e,{signal:n,headers:t,...H})}async chat(e){let t=this.buildRequest(e),n=this.callHeaders?.(e,t)??{},{lifetime:s,opened:r}=await S(this.providerName,e.signal,this.streamIdleTimeoutMs,i=>this.openStream(t,n,i),i=>N(this.providerName,i,a=>this.isContextOverflow(a),e.signal));return new Q(s.events(r),this.providerName,this.replayTag(e.model),i=>this.isContextOverflow(i),e.signal,s)}isContextOverflow(e){return e.code===$}},rt=o=>typeof o=="string"?o:{type:"function",name:o.name},at=o=>{switch(o.kind){case"text":return;case"json_object":return{type:"json_object"};case"json_schema":return{type:"json_schema",name:o.name,schema:o.schema,strict:o.strict}}},lt=o=>({type:"function",name:o.name,description:o.description,parameters:o.input_schema,strict:!1}),Se=o=>o.every(e=>e.type==="text")?j(o):o.map(e=>{switch(e.type){case"text":return{type:"input_text",text:e.text};case"image":return{type:"input_image",detail:e.detail,...e.url?{image_url:e.url}:e.data?{image_url:`data:${e.media_type??"image/png"};base64,${e.data}`}:{}};case"file":return{type:"input_file",...e.file_id?{file_id:e.file_id}:{},...e.url?{file_url:e.url}:{},...e.data?{file_data:e.data}:{},...e.filename?{filename:e.filename}:{}}}});function pt(o,e=ee){let t=[];for(let n of o){if(n.role==="tool"){t.push({type:"function_call_output",call_id:n.tool_call_id??"",output:Se(n.content)});continue}if(n.role!=="assistant"){t.push({role:n.role,content:Se(n.content)});continue}if(n.provider_state?.provider===e&&Array.isArray(n.provider_state.data.output)){t.push(...n.provider_state.data.output);continue}let s=O(n);s&&t.push({role:"assistant",content:s});for(let r of n.tool_calls)t.push({type:"function_call",call_id:r.call_id,name:r.name,arguments:U(r)})}return t}function dt(o){let e=o.usage,t=e?.input_tokens_details;return{input_tokens:e?.input_tokens??0,output_tokens:e?.output_tokens??0,cache_read_input_tokens:t?.cached_tokens??0,cache_write_input_tokens:t?.cache_write_tokens??0,reasoning_output_tokens:e?.output_tokens_details?.reasoning_tokens??0}}function ct(o,e=ee){let t=[],n=[],s=[],r=[];for(let i of o.output??[])switch(i.type){case"message":{for(let a of i.content??[])a.type==="output_text"?t.push(a.text):a.type==="refusal"&&t.push(a.refusal);break}case"reasoning":{for(let a of i.content??[])n.push(a.text);for(let a of i.summary??[])n.push(a.text);break}case"function_call":{s.push(R(i.call_id,i.name,i.arguments));break}default:{let a=i.type;(st.has(a)||!ot.has(a))&&r.push(a)}}if(r.length>0)throw new Z([...new Set(r)]);return x.parse({role:"assistant",content:t.join("")||null,reasoning_content:n.join(`
|
|
2
|
+
`)||null,tool_calls:s,provider_calls:(o.output??[]).map(Ie).filter(i=>i!==void 0),usage:dt(o),provider_state:{provider:e,data:{output:o.output??[]}}})}var ut=o=>o.status==="completed"?"completed":o.status==="incomplete"&&o.incomplete_details?.reason==="max_output_tokens"?"length":"other",mt=o=>({response_id:o.id,model:o.model,status:o.status??null,...o.service_tier?{service_tier:o.service_tier}:{},...o.incomplete_details?{incomplete_details:o.incomplete_details}:{}}),Q=class extends I{response;itemsByIndex=new Map;text="";reasoning="";events;replayTag;isContextOverflow;constructor(e,t,n,s,r,i){super(t,r,i),this.events=e,this.replayTag=n,this.isContextOverflow=s}async*read(){try{yield*this.readEvents()}catch(e){throw N(this.providerName,e,this.isContextOverflow,this.signal)}}failure(e,t){let n=new we(e,t);return this.isContextOverflow(e)?new B(this.providerName,{cause:n}):n}async*readEvents(){for await(let e of this.events)switch(e.type){case"response.output_text.delta":this.text+=e.delta,yield{text_delta:e.delta,reasoning_delta:"",provider_call:null};break;case"response.reasoning_summary_text.delta":case"response.reasoning_text.delta":this.reasoning+=e.delta,yield{text_delta:"",reasoning_delta:e.delta,provider_call:null};break;case"response.output_item.done":{this.itemsByIndex.set(e.output_index,e.item);let t=Ie(e.item);t!==void 0&&(yield{text_delta:"",reasoning_delta:"",provider_call:t});break}case"response.completed":case"response.incomplete":this.response=this.withOutput(e.response);return;case"response.failed":throw this.failure(e.response.error??{},"The model request failed");case"error":throw this.failure(e,"The model stream reported an error");default:break}}withOutput(e){if(e.output&&e.output.length>0)return e;let t=[...this.itemsByIndex.entries()].sort(([n],[s])=>n-s).map(([,n])=>n);return{...e,output:t}}settle(){if(this.response!==void 0)return{message:ct(this.response,this.replayTag),finish:ut(this.response),provider_metadata:mt(this.response)}}partial(){return{message:x.parse({role:"assistant",content:this.text||null,reasoning_content:this.reasoning||null}),providerMetadata:{}}}},ht=o=>{let e=Ne.parse(o);return{name:"openai-responses",defaultModel:e.defaultModel||te,defaultThinkingEffort:e.thinkingEffort,models:oe,capacity:t=>({contextWindow:y(it,t),providerTools:!0,toolResultImages:!0}),createClient:()=>new m(o),classify:t=>u(t)}};var se="codex",ie="gpt-5.6-luna",K=["low","medium","high","max"],gt=[{id:"gpt-6.1-sol",description:"Latest workhorse for coding and everyday work",thinkingEfforts:K},...oe,{id:"gpt-5.6-sol",description:"Older workhorse generation",thinkingEfforts:K},{id:"gpt-5.6-terra",description:"Older balanced model for straightforward work",thinkingEfforts:K},{id:ie,description:"Older fast and efficient model",thinkingEfforts:K}],xt={"gpt-6.1-sol":475e3,"gpt-6-astra":258400,"gpt-6-sol":258400,"gpt-6-luna":258400,"gpt-reserve":258400,"gpt-5.6-sol":258400,"gpt-5.6-terra":258400,"gpt-5.6-luna":258400,"codex-auto-review":258400},Me=P.object({authPath:P.string().refine(_t,"the Codex login file must be an absolute path").optional(),refreshTimeoutMs:P.number().int().positive().optional(),streamIdleTimeoutMs:C,baseURL:P.string().default(ve),defaultModel:P.string().default(ie),thinkingEffort:P.enum(g).default("high"),extraBody:ke.optional()}),ne=class extends m{credentials;constructor(e){let t=Me.parse(e),n=e.credentials;if(n===void 0&&t.authPath!==void 0){if(t.refreshTimeoutMs===void 0)throw new Error("Codex needs a `refreshTimeoutMs` with its `authPath`: the host bounds how long a refresh may take");n=Te(t.authPath,{refreshTimeoutMs:t.refreshTimeoutMs})}if(n===void 0)throw new Error("Codex needs an `authPath`: lagent reads no environment, so the host names the login file");super({name:se,headers:(s,r)=>{let i=Et(r);return ge.debug(`codex session_id=${i} model=${String(r.model)} input_items=${Array.isArray(r.input)?r.input.length:0}`),{session_id:i}},streamIdleTimeoutMs:t.streamIdleTimeoutMs,thinkingEffort:t.thinkingEffort,extraBody:t.extraBody,client:e.client??Ce({credentials:n,baseURL:t.baseURL,fetch:yt(e.fetch)})}),this.credentials=n}openStream(e,t,n){return be(this.credentials,n,()=>super.openStream(e,t,n))}},Pe=typeof L.zstdCompress=="function"?{name:"zstd",compress:Ae(L.zstdCompress)}:{name:"gzip",compress:Ae(L.gzip)},yt=(o=globalThis.fetch)=>async(e,t)=>{if(typeof t?.body!="string")return o(e,t);let n=new Headers(t.headers);return n.set("Content-Encoding",Pe.name),n.delete("Content-Length"),o(e,{...t,headers:n,body:await Pe.compress(t.body)})},Et=o=>ft("sha256").update(JSON.stringify([o.model,o.instructions??null,o.tools??null])).digest("hex").slice(0,32),kt=o=>{let e=Me.parse(o);return{name:se,defaultModel:e.defaultModel||ie,defaultThinkingEffort:e.thinkingEffort,models:gt,capacity:t=>({contextWindow:y(xt,t),providerTools:!0,toolResultImages:!0}),createClient:()=>new ne(o),classify:t=>t instanceof Y?{kind:"auth"}:u(t)}};import{z as De}from"zod";var wt="https://api.deepseek.com",Le="deepseek-responses",z="deepseek-flash",We=["low","high","max"],Ot=[{id:z,description:"Fast frontier coding model with image input",thinkingEfforts:We},{id:"deepseek-v4-pro",description:"Most capable DeepSeek model, for the hardest work",thinkingEfforts:We}],vt={[z]:996147,"deepseek-v4-pro":996147},Tt=/maximum context length is \d+ tokens/i,je=E.extend({baseURL:De.string().default(wt),defaultModel:De.string().default(z)}),re=class extends m{constructor(e){let t=je.parse(e);if(t.apiKey===void 0&&e.client===void 0)throw new Error("DeepSeek needs an `apiKey`: lagent reads no environment, so the host resolves the credential");let n={...t,client:e.client,name:Le};super(n)}buildRequest(e){if(e.providerTools.length>0)throw new p(this.providerName,"provider-executed tools");if(e.messages.some(n=>n.content.some(s=>s.type==="file")))throw new p(this.providerName,"file inputs");let t=super.buildRequest(e);return delete t.include,t}isContextOverflow(e){return super.isContextOverflow(e)?!0:typeof e.message=="string"&&Tt.test(e.message)}},bt=o=>{let e=je.parse(o);return{name:"deepseek-responses",defaultModel:e.defaultModel||z,defaultThinkingEffort:e.thinkingEffort,models:Ot,capacity:t=>({contextWindow:y(vt,t),providerTools:!1,toolResultImages:!1}),createClient:()=>new re(o),classify:t=>u(t)}};import"openai";import{z as M}from"zod";var Ue="openai-chat-completions",Be="gpt-5.4",Fe=E.extend({baseURL:M.string().default(q),defaultModel:M.string().default(Be),systemRole:M.enum(["system","developer"]).default("system"),contextWindows:M.record(M.string(),M.number().int().positive()).optional()}),v=class{providerName;client;callHeaders;thinkingEffort;extraBody;systemRole;streamIdleTimeoutMs;constructor(e){let t=Fe.parse(e);this.providerName=e.name??Ue,this.callHeaders=e.headers,this.streamIdleTimeoutMs=t.streamIdleTimeoutMs,this.thinkingEffort=t.thinkingEffort,this.extraBody=t.extraBody??{},this.systemRole=t.systemRole,this.client=A("OpenAI Chat Completions",t,e.client)}buildRequest(e){if(e.providerTools.length>0)throw new p(this.providerName,"provider-executed tools");let t=F(e.systemPrompt),n=e.thinkingEffort??this.thinkingEffort,s={...this.extraBody,model:e.model,messages:[...t?[{role:this.systemRole,content:t}]:[],...e.messages.map(i=>At(i,this.providerName))],stream:!0,stream_options:{include_usage:!0}};n!==void 0&&(s.reasoning_effort=n),e.maxOutputTokens!==void 0&&(s.max_completion_tokens=e.maxOutputTokens);let r=St(e.responseFormat);return r!==void 0&&(s.response_format=r),e.tools.length>0&&(s.tools=e.tools.map(It),s.tool_choice=Rt(e.toolChoice),s.parallel_tool_calls=e.parallelToolCalls),s}async openStream(e,t,n){return await this.client.chat.completions.create(e,{signal:n,headers:t,...H})}async chat(e){let t=this.buildRequest(e),n=this.callHeaders?.(e,t)??{},{lifetime:s,opened:r}=await S(this.providerName,e.signal,this.streamIdleTimeoutMs,i=>this.openStream(t,n,i),i=>N(this.providerName,i,$e,e.signal));return new ae(s.events(r),this.providerName,e.signal,s)}},$e=o=>o.code===$,Ct=o=>{switch(o){case"stop":case"tool_calls":case"function_call":return"completed";case"length":return"length";default:return"other"}},Rt=o=>typeof o=="string"?o:{type:"function",function:{name:o.name}},St=o=>{switch(o.kind){case"text":return;case"json_object":return{type:"json_object"};case"json_schema":return{type:"json_schema",json_schema:{name:o.name,schema:o.schema,strict:o.strict}}}},It=o=>({type:"function",function:{name:o.name,description:o.description,parameters:o.input_schema,strict:!1}}),Nt=(o,e)=>o.every(t=>t.type==="text")?j(o):o.map(t=>{switch(t.type){case"text":return{type:"text",text:t.text};case"image":return{type:"image_url",image_url:{url:t.url||`data:${t.media_type??"image/png"};base64,${t.data??""}`,detail:t.detail}};case"file":{if(!t.file_id&&!t.data)throw new p(e,"files by URL \u2014 upload the file or inline its data");return{type:"file",file:{...t.file_id?{file_id:t.file_id}:{},...t.data?{file_data:t.data}:{},...t.filename?{filename:t.filename}:{}}}}}});function At(o,e=Ue){switch(o.role){case"tool":{let t=o.content.find(n=>n.type!=="text");if(t!==void 0)throw new p(e,`a ${t.type} in a tool result`);return{role:"tool",tool_call_id:o.tool_call_id??"",content:O(o)}}case"assistant":{let t={role:"assistant",content:O(o)||null};return o.tool_calls.length>0&&(t.tool_calls=o.tool_calls.map(n=>({id:n.call_id,type:"function",function:{name:n.name,arguments:U(n)}}))),o.reasoning_content!==null&&(t.reasoning_content=o.reasoning_content),t}default:return{role:o.role,content:Nt(o.content,e)}}}var ae=class extends I{toolCalls=new Map;lastToolCallKey;text="";reasoning="";finishReason=null;usage=null;metadata={};events;constructor(e,t,n,s){super(t,n,s),this.events=e}async*read(){try{yield*this.readEvents()}catch(e){throw N(this.providerName,e,$e,this.signal)}}async*readEvents(){for await(let e of this.events){this.recordMetadata(e);let t=Pt(e);t!==null&&(this.usage=t);let n=e.choices[0];if(n===void 0)continue;n.finish_reason&&(this.finishReason=n.finish_reason);let s=n.delta,r=new Set;for(let d of s.tool_calls??[])this.recordToolCall(d,r);let i=s.content??"",a=s.reasoning_content||s.reasoning||"";this.text+=i,this.reasoning+=a,(i||a)&&(yield{text_delta:i,reasoning_delta:a,provider_call:null})}}recordMetadata(e){if(Object.keys(this.metadata).length>0)return;let t=e;this.metadata={response_id:e.id,model:e.model,...e.system_fingerprint?{system_fingerprint:e.system_fingerprint}:{},...t.service_tier?{service_tier:t.service_tier}:{}}}recordToolCall(e,t){let n=this.toolCallKey(e,t),s=this.toolCalls.get(n)??{order:this.toolCalls.size,id:"",name:"",arguments:""};this.toolCalls.set(n,{order:e.index??s.order,id:e.id??s.id,name:e.function?.name??s.name,arguments:s.arguments+(e.function?.arguments??"")}),this.lastToolCallKey=n}toolCallKey(e,t){if(e.index!==void 0&&e.index!==null)return`index:${e.index}`;if(e.id){let n=t.has(e.id)?`id:${e.id}#${this.toolCalls.size}`:`id:${e.id}`;return t.add(e.id),n}return this.lastToolCallKey??"index:0"}settle(){if(this.finishReason===null)return;let e=[...this.toolCalls.values()].sort((n,s)=>n.order-s.order).map(n=>R(n.id,n.name,n.arguments));return{message:x.parse({role:"assistant",content:this.text||null,reasoning_content:this.reasoning||null,tool_calls:e,usage:this.usage}),finish:Ct(this.finishReason),provider_metadata:{...this.metadata,finish_reason:this.finishReason}}}partial(){return{message:x.parse({role:"assistant",content:this.text||null,reasoning_content:this.reasoning||null,usage:this.usage}),providerMetadata:{...this.metadata,finish_reason:"incomplete"}}}};function Pt(o){let e=o;if(o.usage)return{input_tokens:o.usage.prompt_tokens,output_tokens:o.usage.completion_tokens,cache_read_input_tokens:o.usage.prompt_tokens_details?.cached_tokens??0,cache_write_input_tokens:0,reasoning_output_tokens:o.usage.completion_tokens_details?.reasoning_tokens??0};let t=e.normalizedUsage;if(t===void 0)return null;let n=s=>Number(t[s]??0)||0;return{input_tokens:n("inputTokens"),output_tokens:n("outputTokens"),cache_read_input_tokens:n("cacheReadTokens"),cache_write_input_tokens:n("cacheWriteTokens"),reasoning_output_tokens:0}}var Mt=o=>{let e=Fe.parse(o);return{name:"openai-chat-completions",defaultModel:e.defaultModel||Be,defaultThinkingEffort:e.thinkingEffort,capacity:t=>({contextWindow:y(e.contextWindows??{},t),providerTools:!1,toolResultImages:!1}),createClient:()=>new v(o),classify:t=>u(t)}};import{readFile as Jt}from"node:fs/promises";import{isAbsolute as Zt}from"node:path";import{z as l}from"zod";import{createHash as Dt}from"node:crypto";var Wt=/^[a-zA-Z0-9_-]+$/,qe=o=>Wt.test(o)?o:`lg_${Dt("sha256").update(o).digest("base64url").slice(0,32)}`;function Lt(o,e){let t=o.provider_state;return t?.provider!==e||!Array.isArray(t.data.thinking)?[]:t.data.thinking.filter(n=>n.type==="thinking"?typeof n.signature=="string"&&n.signature!=="":n.type==="redacted_thinking"&&typeof n.data=="string")}function Ke(o,e){let t=[],n=(s,r)=>{if(r.length===0)return;let i=t.at(-1);i?.role===s?i.content.push(...r):t.push({role:s,content:r})};for(let s of o)switch(s.role){case"assistant":n("assistant",Ut(s,e.replayTag));break;case"tool":n("user",[Bt(s,e.provider)]);break;case"user":n("user",le(s.content,e.provider));break;default:n("user",Ft(s.content,e.provider))}for(let s of t)s.role==="user"&&(s.content=jt(s.content));return t}var jt=o=>[...o.filter(e=>e.type==="tool_result"),...o.filter(e=>e.type!=="tool_result")];function Ut(o,e){let t=[...Lt(o,e)],n=O(o);n!==""&&t.push({type:"text",text:n});for(let s of o.tool_calls)t.push({type:"tool_use",id:qe(s.call_id),name:s.name,input:s.arguments??{}});return t}function Bt(o,e){let t=le(o.content,e);if(t.find(s=>s.type==="document")!==void 0)throw new p(e,"a file in a tool result");return{type:"tool_result",tool_use_id:qe(o.tool_call_id??""),...t.length===0?{}:{content:t}}}function Ft(o,e){let t=le(o,e);return t.length===0?[]:[{type:"text",text:"<system-reminder>"},...t,{type:"text",text:"</system-reminder>"}]}function le(o,e){let t=[];for(let n of o)switch(n.type){case"text":n.text!==""&&t.push({type:"text",text:n.text});break;case"image":t.push({type:"image",source:n.url?{type:"url",url:n.url}:{type:"base64",media_type:n.media_type??"image/png",data:n.data??""}});break;case"file":t.push($t(n,e))}return t}function $t(o,e){let t=o.filename?{title:o.filename}:{};if(o.url)return{type:"document",source:{type:"url",url:o.url},...t};if(o.data&&o.media_type==="application/pdf")return{type:"document",source:{type:"base64",media_type:"application/pdf",data:o.data},...t};if(o.data&&o.media_type==="text/plain")return{type:"document",source:{type:"text",media_type:"text/plain",data:Buffer.from(o.data,"base64").toString("utf8")},...t};throw new p(e,o.file_id?"files by provider id":`a file of type '${o.media_type??"unknown"}'`)}var ze=o=>o.map(e=>({name:e.name,...e.description?{description:e.description}:{},input_schema:e.input_schema}));function Ge(o,e){let t=e?{}:{disable_parallel_tool_use:!0};return o==="none"?{type:"none"}:o==="auto"?{type:"auto",...t}:o==="required"?{type:"any",...t}:{type:"tool",name:o.name,...t}}function Ve(o){return o===void 0?{}:o==="none"?{thinking:{type:"disabled"}}:{thinking:{type:"adaptive",display:"summarized"},output_config:{effort:o}}}var h=class extends Error{errorType;status;headers;constructor(e,t,n,s){super(t),this.errorType=e,this.status=n,this.headers=s,this.name="AnthropicAPIError"}},Xe=o=>o.errorType==="invalid_request_error"&&/prompt is too long/i.test(o.message),He={rate_limit_error:"rate_limit",overloaded_error:"overloaded",api_error:"transport",timeout_error:"timeout",authentication_error:"auth",permission_error:"auth",billing_error:"quota"};function V(o,e=Date.now()){if(!(o instanceof h))return{kind:Ee(o)};let t=o.errorType!==void 0&&Object.hasOwn(He,o.errorType)?He[o.errorType]:void 0,{status:n}=o;return n===void 0?{kind:t??"other"}:ye(t??xe(n)??"other",o.headers,e)}var Ht=o=>{switch(o){case"end_turn":case"tool_use":case"stop_sequence":return"completed";case"max_tokens":case"model_context_window_exceeded":return"length";default:return"other"}},G=class{id=null;model=null;blocks=new Map;stopReason=null;stopSequence=null;stopped=!1;usage=null;options;constructor(e){this.options=e}apply(e){switch(e.type){case"message_start":return this.id=e.message.id,this.model=e.message.model,this.addUsage(e.message.usage),null;case"content_block_start":return this.blocks.set(e.index,qt(e.content_block)),null;case"content_block_delta":return this.applyDelta(e.index,e.delta);case"message_delta":return e.delta.stop_reason&&(this.stopReason=e.delta.stop_reason),e.delta.stop_sequence&&(this.stopSequence=e.delta.stop_sequence),this.addUsage(e.usage),null;case"message_stop":return this.stopped=!0,null;case"error":throw new h(e.error.type,e.error.message??"The stream reported an error");default:return null}}get complete(){return this.stopReason!==null&&this.stopped}get stop(){return this.stopReason}applyDelta(e,t){let n=this.blocks.get(e);return n===void 0?null:n.type==="text"&&t.type==="text_delta"&&typeof t.text=="string"?(n.text+=t.text,{text_delta:t.text,reasoning_delta:"",provider_call:null}):n.type==="thinking"&&t.type==="thinking_delta"&&typeof t.thinking=="string"?(n.thinking+=t.thinking,{text_delta:"",reasoning_delta:t.thinking,provider_call:null}):(n.type==="thinking"&&t.type==="signature_delta"&&typeof t.signature=="string"?n.signature+=t.signature:n.type==="tool_use"&&t.type==="input_json_delta"&&typeof t.partial_json=="string"&&(n.json+=t.partial_json),null)}addUsage(e){if(e==null)return;let t=Object.fromEntries(Object.entries(e).filter(([,n])=>n!==null));this.usage={...this.usage,...t}}normalizedUsage(){if(this.usage===null)return null;let e=this.usage.cache_read_input_tokens??0,t=this.usage.cache_creation_input_tokens??0;return{input_tokens:(this.usage.input_tokens??0)+e+t,output_tokens:this.usage.output_tokens??0,cache_read_input_tokens:e,cache_write_input_tokens:t,reasoning_output_tokens:this.usage.output_tokens_details?.thinking_tokens??0}}ordered(){return[...this.blocks.entries()].sort(([e],[t])=>e-t).map(([,e])=>e)}text(){return this.ordered().flatMap(e=>e.type==="text"?[e.text]:[]).join("")}reasoning(){return this.ordered().flatMap(e=>e.type==="thinking"&&e.thinking!==""?[e.thinking]:[]).join(`
|
|
3
|
+
|
|
4
|
+
`)}metadata(){return{...this.id===null?{}:{message_id:this.id},...this.model===null?{}:{model:this.model},stop_reason:this.stopReason??"incomplete",...this.stopSequence===null?{}:{stop_sequence:this.stopSequence}}}settle(){if(!this.complete)return;let e=this.options.toolName??(i=>i),t=[],n=[];for(let i of this.ordered())i.type==="thinking"?t.push({type:"thinking",thinking:i.thinking,signature:i.signature}):i.type==="redacted_thinking"?t.push({type:"redacted_thinking",data:i.data}):i.type==="tool_use"&&n.push(R(i.id,e(i.name),i.json===""?i.input:i.json));let s={id:this.id??"",thinking:t};return{message:x.parse({role:"assistant",content:this.text()||null,reasoning_content:this.reasoning()||null,tool_calls:n,usage:this.normalizedUsage(),provider_state:{provider:this.options.replayTag,data:s}}),finish:Ht(this.stopReason),provider_metadata:this.metadata()}}partial(){return{message:x.parse({role:"assistant",content:this.text()||null,reasoning_content:this.reasoning()||null,usage:this.normalizedUsage()}),providerMetadata:this.metadata()}}};function qt(o){switch(o.type){case"text":return{type:"text",text:typeof o.text=="string"?o.text:""};case"thinking":return{type:"thinking",thinking:typeof o.thinking=="string"?o.thinking:"",signature:typeof o.signature=="string"?o.signature:""};case"redacted_thinking":return{type:"redacted_thinking",data:typeof o.data=="string"?o.data:""};case"tool_use":return{type:"tool_use",id:String(o.id??""),name:String(o.name??""),json:"",input:o.input};default:return{type:"other",raw:o}}}import{z as f}from"zod";var Kt="2023-06-01",zt=f.object({apiKey:f.string().min(1).optional(),baseURL:f.string().min(1),streamIdleTimeoutMs:C,authorization:f.enum(["x-api-key","bearer"]).default("x-api-key"),defaultHeaders:f.record(f.string(),f.string()).optional(),thinkingEffort:f.enum(g).optional(),maxOutputTokens:f.record(f.string(),f.number().int().positive())}),Gt=o=>o.type!=="thinking"&&o.type!=="redacted_thinking";function Vt(o,e){let t=s=>{for(let r=s.length-1;r>=0;r--)if(Gt(s[r])){s[r]={...s[r],cache_control:{type:"ephemeral"}};return}};t(o);let n=e.at(-1);n!==void 0&&t(n.content)}var D=class{providerName;config;fetchImpl;callHeaders;constructor(e){this.providerName=e.name,this.config=zt.parse(e),this.fetchImpl=e.fetch??globalThis.fetch,this.callHeaders=e.headers}replayTag(e){return`${this.providerName}/${e}`}maxOutputTokens(e){if(e.maxOutputTokens!==void 0)return e.maxOutputTokens;let t=this.config.maxOutputTokens;if(Object.hasOwn(t,e.model))return t[e.model];throw new p(this.providerName,`model '${e.model}' with no output cap \u2014 name it in the provider's \`maxOutputTokens\``)}headers(e,t){let{apiKey:n,authorization:s}=this.config;if(n===void 0)throw new Error(`${this.providerName} needs an \`apiKey\`: lagent reads no environment, so the host resolves the credential`);return{...this.config.defaultHeaders,...s==="bearer"?{Authorization:`Bearer ${n}`}:{"x-api-key":n},"anthropic-version":Kt,"content-type":"application/json",accept:"text/event-stream",...this.callHeaders?.(e,t)}}buildRequest(e){if(e.providerTools.length>0)throw new p(this.providerName,"provider-executed tools");if(e.responseFormat.kind!=="text")throw new p(this.providerName,`response format '${e.responseFormat.kind}'`);let t=e.thinkingEffort??this.config.thinkingEffort;if(e.toolChoice!=="auto"&&e.toolChoice!=="none"&&t!==void 0&&t!=="none"&&e.tools.length>0)throw new p(this.providerName,"a forced tool choice while thinking");let s=e.systemPrompt.filter(a=>a.text!=="").map(a=>({type:"text",text:a.text})),r=Ke(e.messages,{provider:this.providerName,replayTag:this.replayTag(e.model)});Vt(s,r);let i={model:e.model,max_tokens:this.maxOutputTokens(e),messages:r,stream:!0,...Ve(t)};return s.length>0&&(i.system=s),e.tools.length>0&&(i.tools=ze(e.tools),i.tool_choice=Ge(e.toolChoice,e.parallelToolCalls)),i}async chat(e){let t=this.buildRequest(e),n=this.headers(e,t),{lifetime:s,opened:r}=await S(this.providerName,e.signal,this.config.streamIdleTimeoutMs,a=>this.open(t,n,a),a=>_e(e.signal,a)?e.signal.reason:this.classified(a)),i=new G({replayTag:this.replayTag(e.model)});return new pe(s.events(Yt(r)),i,this,e.signal,s)}async open(e,t,n){let s=await this.fetchImpl(`${this.config.baseURL.replace(/\/+$/,"")}/messages`,{method:"POST",headers:t,body:JSON.stringify(e),signal:n});if(!s.ok||s.body===null)throw await Xt(s);return s.body}classified(e){return e instanceof h&&Xe(e)?new B(this.providerName,{cause:e}):e}};async function Xt(o){let e=await o.text().catch(()=>""),t;try{t=JSON.parse(e).error}catch{t=void 0}let n=typeof t?.message=="string"&&t.message!==""?t.message:e||o.statusText;return new h(typeof t?.type=="string"?t.type:void 0,`${o.status} ${n}`,o.status,o.headers)}async function*Yt(o){let e=new TextDecoder,t="",n=[];for await(let s of o){t+=e.decode(s,{stream:!0});let r;for(;(r=t.search(/[\r\n]/))>=0&&!(t[r]==="\r"&&r===t.length-1);){let i=t.slice(0,r);t=t.slice(t.startsWith(`\r
|
|
5
|
+
`,r)?r+2:r+1),i===""?(n.length>0&&(yield JSON.parse(n.join(`
|
|
6
|
+
`))),n=[]):i.startsWith("data:")&&n.push(i.slice(5).replace(/^ /,""))}}}var pe=class extends I{events;assembly;client;constructor(e,t,n,s,r){super(n.providerName,s,r),this.events=e,this.assembly=t,this.client=n}async*read(){try{for await(let e of this.events){let t=this.assembly.apply(e);if(t!==null&&(yield t),this.assembly.complete)return}}catch(e){throw this.client.classified(e)}}settle(){return this.assembly.settle()}partial(){return this.assembly.partial()}};var W=class{providerName;prepare;adapters;constructor(e,t,n){this.providerName=e,this.prepare=t,this.adapters=n}async chat(e){let t=this.prepare(e);return this.adapters[t.protocol].chat(t.call)}};var k="opencode-copilot",Qt="https://api.githubcopilot.com",de={"User-Agent":"opencode/2.0.26","X-GitHub-Api-Version":"2026-08-01"},eo=l.strictObject({authPath:l.string().refine(Zt,"authPath must be an absolute path"),streamIdleTimeoutMs:C,defaultModel:l.string().min(1).optional(),thinkingEffort:l.enum(g).optional()}),to=l.object({"github-copilot":l.object({type:l.literal("oauth"),access:l.string().min(1),metadata:l.object({apiEndpoint:l.url().optional()}).optional()})}),oo=l.object({id:l.string().min(1),name:l.string().optional(),model_picker_enabled:l.boolean().optional(),policy:l.object({state:l.string().optional()}).optional(),supported_endpoints:l.array(l.string()).optional(),capabilities:l.object({type:l.string().optional(),limits:l.object({max_context_window_tokens:l.number().int().positive().optional(),max_prompt_tokens:l.number().int().positive(),max_output_tokens:l.number().int().positive()}),supports:l.object({streaming:l.boolean().optional(),tool_calls:l.boolean(),vision:l.boolean().optional(),reasoning_effort:l.array(l.string()).optional(),adaptive_thinking:l.boolean().optional(),min_thinking_budget:l.number().int().positive().optional(),max_thinking_budget:l.number().int().positive().optional()})})});function no(o){let e=o.supported_endpoints;if(e?.includes("/v1/messages"))return"messages";if(e?.includes("/responses"))return"responses";if(e?.includes("/chat/completions"))return"chat";if(e?.length)return;if(o.id.startsWith("claude-"))return"messages";let t=/^gpt-(\d+)/.exec(o.id);return t&&Number(t[1])>=5&&!o.id.startsWith("gpt-5-mini")||o.id.startsWith("grok-")||o.id.startsWith("mai-code-")?"responses":"chat"}function so(o){let e=l.object({data:l.array(l.unknown())}).safeParse(o);if(!e.success)throw new Error("Copilot model discovery returned an invalid catalog");let t=new Map;for(let n of e.data.data){let s=oo.safeParse(n);if(!s.success)continue;let r=s.data;if(r.policy?.state==="disabled"||r.capabilities.supports.streaming===!1||r.capabilities.type!==void 0&&r.capabilities.type!=="chat")continue;let i=no(r);if(i===void 0)continue;let a=r.capabilities.supports,d=a.reasoning_effort?.filter(w=>g.some(X=>X===w)),c=i==="messages"&&!a.adaptive_thinking&&a.max_thinking_budget?["none","high","max"]:d?.length?d:a.adaptive_thinking?void 0:["none"];t.set(r.id,{...r,protocol:i,...c?{thinkingEfforts:c}:{}})}if(t.size===0)throw new Error("Copilot model discovery returned no usable models");return new Map([...t].sort((n,s)=>+!!s[1].model_picker_enabled-+!!n[1].model_picker_enabled))}var io=o=>({"Openai-Intent":"conversation-edits","X-Interaction-Type":o.purpose==="auxiliary"?"conversation-background":"conversation-agent","X-Interaction-Id":o.threadId,"x-initiator":o.purpose==="step"&&o.messages.at(-1)?.role==="user"?"user":"agent",...o.messages.some(e=>e.content.some(t=>t.type==="image"))?{"Copilot-Vision-Request":"true"}:{}}),ce=class extends m{buildRequest(e){let t=super.buildRequest(e);return e.thinkingEffort===void 0&&delete t.reasoning,t}},ue=class extends D{models;constructor(e,t){super(e),this.models=t}buildRequest(e){let t=super.buildRequest(e),n=this.models.get(e.model).capabilities.supports;if(!n.adaptive_thinking&&e.thinkingEffort&&e.thinkingEffort!=="none"){let s=n.max_thinking_budget;if(s===void 0)throw new p(this.providerName,`thinking on '${e.model}'`);let r=e.thinkingEffort==="max"?s-1:Math.floor(s/2),i=Math.min(r,Number(t.max_tokens)-1);if(i<(n.min_thinking_budget??1))throw new p(this.providerName,`thinking budget above the output cap for '${e.model}'`);t.thinking={type:"enabled",budget_tokens:i},delete t.output_config}return t}},me=class extends W{constructor(e,t,n,s){let r=Oe({apiKey:n,baseURL:s,defaultHeaders:de}),i={name:k,headers:io,streamIdleTimeoutMs:e.streamIdleTimeoutMs},a={...i,client:r};super(k,d=>{let c=t.get(d.model);if(!c)throw new p(k,`undiscovered model '${d.model}'`);if(d.providerTools.length)throw new p(k,"provider-executed tools");if(d.tools.length&&!c.capabilities.supports.tool_calls)throw new p(k,`tools on '${d.model}'`);let w=d.thinkingEffort??e.thinkingEffort;if(w!==void 0&&c.thinkingEfforts&&!c.thinkingEfforts.includes(w))throw new p(k,`thinking effort '${w}' on '${d.model}'`);let X=c.thinkingEfforts?.some(et=>et!=="none")??!0,{thinkingEffort:ko,...Qe}=d;return{protocol:c.protocol,call:{...Qe,...w===void 0||!X?{}:{thinkingEffort:w}}}},{responses:new ce({...a,replayByModel:!0}),chat:new v(a),messages:new ue({...i,apiKey:n,authorization:"bearer",baseURL:`${s}/v1`,defaultHeaders:{...de,"anthropic-beta":"interleaved-thinking-2025-05-14"},maxOutputTokens:Object.fromEntries([...t].map(([d,c])=>[d,c.capabilities.limits.max_output_tokens]))},t)})}},ro=async o=>{let e=eo.parse(o),t;try{t=to.parse(JSON.parse(await Jt(e.authPath,"utf8")))["github-copilot"]}catch{throw new Error(`opencode-copilot needs an OAuth login in ${e.authPath}; run opencode auth login`)}let n=(t.metadata?.apiEndpoint??Qt).replace(/\/+$/,""),s=await fetch(`${n}/models`,{headers:{...de,Authorization:`Bearer ${t.access}`},signal:AbortSignal.timeout(5e3)});if(!s.ok)throw new Error(`Copilot model discovery failed: HTTP ${s.status}`);let r=so(await s.json()),i=e.defaultModel??(r.has("gpt-6-luna")?"gpt-6-luna":r.keys().next().value);if(!r.has(i))throw new Error(`Copilot default model '${i}' is unavailable`);return{name:k,defaultModel:i,...e.thinkingEffort===void 0?{}:{defaultThinkingEffort:e.thinkingEffort},models:[...r.values()].map(a=>({id:a.id,...a.name?{description:a.name}:{},...a.thinkingEfforts?{thinkingEfforts:a.thinkingEfforts}:{}})),capacity:a=>{let d=r.get(a),c=d?.capabilities.limits;return{contextWindow:c?Math.min(c.max_prompt_tokens,c.max_context_window_tokens??c.max_prompt_tokens):null,providerTools:!1,toolResultImages:d?.protocol!=="chat"&&d?.capabilities.supports.vision===!0}},createClient:()=>new me(e,r,t.access,n),classify:a=>a instanceof h?V(a):u(a)}};import{z as _}from"zod";var ao="https://opencode.ai/zen/go/v1",b="opencode-go",lo="deepseek-v4.1-flash",po="x-opencode-session",T=["low","medium","high","max"],Ye=["low","medium","high"],co={"grok-4.7":{protocol:"responses",contextWindow:5e5,thinkingEfforts:Ye},"gpt-6-luna":{protocol:"responses",contextWindow:922e3},"gpt-5.6-luna":{protocol:"responses",contextWindow:1e6},"muse-spark-1.3-contributor":{protocol:"responses",contextWindow:1048576,thinkingEfforts:T},"muse-spark-1.2-contributor":{protocol:"responses",contextWindow:1048576,thinkingEfforts:Ye},"claude-haiku-5-5":{protocol:"messages",contextWindow:1e6,maxOutputTokens:128e3},"minimax-m3":{protocol:"messages",contextWindow:1e6,maxOutputTokens:131072},"minimax-m2.7":{protocol:"messages",contextWindow:204800,thinkingEfforts:T,maxOutputTokens:131072},"qwen3.8-max":{protocol:"messages",contextWindow:1e6,maxOutputTokens:131072},"qwen3.8-flash":{protocol:"messages",contextWindow:1e6,maxOutputTokens:131072},"qwen3.7-plus":{protocol:"messages",contextWindow:1e6,maxOutputTokens:65536},"glm-5.3-flash":{protocol:"chat",contextWindow:1e6,developerRole:"system"},"glm-5.3":{protocol:"chat",contextWindow:1e6,thinkingEfforts:T},"glm-5.2":{protocol:"chat",contextWindow:1e6,thinkingEfforts:T},"kimi-k3.1-pro":{protocol:"chat",contextWindow:1048576,developerRole:"system"},"kimi-k3":{protocol:"chat",contextWindow:1048576},"kimi-k2.7-code":{protocol:"chat",contextWindow:262144,thinkingEfforts:T,developerRole:"system"},"longcat-2.5-preview-free":{protocol:"chat",contextWindow:1e6,thinkingEfforts:T},"longcat-2.0":{protocol:"chat"},"step-5-preview":{protocol:"chat"},"step-5-preview-free":{protocol:"chat",contextWindow:1e6,thinkingEfforts:T},"beam-free":{protocol:"chat"},"deepseek-v4.1-flash":{protocol:"chat",contextWindow:1e6},"deepseek-v4-pro":{protocol:"chat",contextWindow:1048576},"deepseek-v4-flash-vision-exp":{protocol:"chat",contextWindow:1e6},"mimo-v2.6-flash":{protocol:"chat",contextWindow:1048576},"mimo-v2.6-pro":{protocol:"chat",contextWindow:1048576},"mimo-v2.5":{protocol:"chat",contextWindow:1e6},"mimo-v2.5-pro":{protocol:"chat"},"minimax-m3.1-flash":{protocol:"chat"},"hy4-preview":{protocol:"chat"},hy3:{protocol:"chat"}},uo=_.strictObject({protocol:_.enum(["responses","chat","messages"]),contextWindow:_.number().int().positive().optional(),thinkingEfforts:_.array(_.enum(g)).min(1).optional(),maxOutputTokens:_.number().int().positive().optional(),developerRole:_.enum(["developer","system"]).optional()}),mo=o=>Object.entries(o??{}).some(([e,t])=>e.toLowerCase()==="user-agent"&&t.trim()!==""),ho=E.extend({baseURL:_.string().default(ao),defaultModel:_.string().default(lo),models:_.record(_.string(),uo).optional()}).refine(o=>mo(o.defaultHeaders),{message:"OpenCode Go needs a `User-Agent` in `defaultHeaders` naming the application, such as `my-agent/1.0`",path:["defaultHeaders"]}),fo=o=>{let e={...co};for(let[t,n]of Object.entries(o.models??{})){let s=Object.hasOwn(e,t)?e[t]:void 0;e[t]={...s,protocol:n.protocol,...n.contextWindow===void 0?{}:{contextWindow:n.contextWindow},...n.thinkingEfforts===void 0?{}:{thinkingEfforts:n.thinkingEfforts},...n.maxOutputTokens===void 0?{}:{maxOutputTokens:n.maxOutputTokens},...n.developerRole===void 0?{}:{developerRole:n.developerRole}}}return e};function Je(o){let e=ho.parse(o),t=fo(e);return Ze(t,e.defaultModel),{config:e,table:t}}function Ze(o,e){let t=Object.hasOwn(o,e)?o[e]:void 0;if(t===void 0)throw new p(b,`model '${e}', whose protocol is unknown \u2014 name it in the provider's \`models\``);if(t.protocol==="messages"&&t.maxOutputTokens===void 0)throw new p(b,`Messages model '${e}' with no output cap \u2014 name its \`maxOutputTokens\` in the provider's \`models\``);return t.protocol}var _o=o=>Object.entries(o).map(([e,t])=>t.thinkingEfforts===void 0?{id:e}:{id:e,thinkingEfforts:t.thinkingEfforts}),go=(o,e)=>(Object.hasOwn(o,e)?o[e].contextWindow:void 0)??null,xo=(o,e)=>e!=="system"||!o.messages.some(t=>t.role==="developer")?o:{...o,messages:o.messages.map(t=>t.role==="developer"?{...t,role:e}:t)},yo=o=>({[po]:o.threadId}),he=class extends W{constructor(e){let{config:t,table:n}=Je(e),s=A("OpenCode Go",t,e.client),r={name:b,headers:yo,streamIdleTimeoutMs:t.streamIdleTimeoutMs,...t.thinkingEffort===void 0?{}:{thinkingEffort:t.thinkingEffort}},i={...r,client:s,...t.extraBody===void 0?{}:{extraBody:t.extraBody}};super(b,a=>{let d=Ze(n,a.model);if(a.providerTools.length>0)throw new p(b,"provider-executed tools");return{protocol:d,call:d==="chat"?xo(a,n[a.model].developerRole):a}},{responses:new m({...i,replayByModel:!0}),chat:new v(i),messages:new D({...r,...t.apiKey===void 0?{}:{apiKey:t.apiKey},baseURL:t.baseURL,...t.defaultHeaders===void 0?{}:{defaultHeaders:t.defaultHeaders},maxOutputTokens:Object.fromEntries(Object.entries(n).flatMap(([a,d])=>d.maxOutputTokens===void 0?[]:[[a,d.maxOutputTokens]])),...e.fetch===void 0?{}:{fetch:e.fetch}})})}},Eo=o=>{let{config:e,table:t}=Je(o);return{name:b,defaultModel:e.defaultModel,defaultThinkingEffort:e.thinkingEffort,models:_o(t),capacity:n=>({contextWindow:go(t,n),providerTools:!1,toolResultImages:!1}),createClient:()=>new he(o),classify:n=>n instanceof h?V(n):u(n)}};export{se as CODEX_PROVIDER_NAME,Y as CodexCredentialError,Le as DEEPSEEK_RESPONSES_PROVIDER_NAME,k as OPENCODE_COPILOT_PROVIDER_NAME,b as OPENCODE_GO_PROVIDER_NAME,tt as codexAuthPath,kt as codexProvider,bt as deepseekProvider,Mt as openaiChatProvider,ht as openaiResponsesProvider,ro as opencodeCopilotProvider,Eo as opencodeGoProvider};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
2
|
import type { ChatCompletionChunk } from 'openai/resources/chat/completions';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import type { ConversationMessage
|
|
5
|
-
import type {
|
|
4
|
+
import type { ConversationMessage } from '../llm/primitives.js';
|
|
5
|
+
import type { LLMClient, StreamingLLMResponse } from '../llm/client.js';
|
|
6
|
+
import type { ModelRequest } from '../llm/request.js';
|
|
7
|
+
import type { LLMProvider } from '../llm/provider.js';
|
|
8
|
+
import type { DeepReadonly } from '../util/json.js';
|
|
9
|
+
import { type WithCredential } from './shared.js';
|
|
6
10
|
import { type CallHeaders } from './stream.js';
|
|
7
11
|
export declare const OPENAI_CHAT_DEFAULT_MODEL = "gpt-5.4";
|
|
8
12
|
export declare const OpenAIChatConfigSchema: z.ZodObject<{
|
|
@@ -59,4 +63,11 @@ export declare class OpenAIChatLLMClient implements LLMClient {
|
|
|
59
63
|
chat(call: ModelRequest): Promise<StreamingLLMResponse>;
|
|
60
64
|
}
|
|
61
65
|
export declare function toChatMessage(message: DeepReadonly<ConversationMessage>, provider?: string): unknown;
|
|
66
|
+
/**
|
|
67
|
+
* The OpenAI Chat Completions provider, and with a `baseURL` any gateway that speaks it. It declares
|
|
68
|
+
* no models and no windows of its own: a gateway serves whatever ids its operator configured, so the
|
|
69
|
+
* windows it declares are the ones `contextWindows` configures. It replays reasoning text but no
|
|
70
|
+
* opaque reasoning state, and provider-executed tools are refused.
|
|
71
|
+
*/
|
|
72
|
+
export declare const openaiChatProvider: (config: WithCredential<OpenAIChatConfig>) => LLMProvider;
|
|
62
73
|
export {};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
2
|
import type { Response, ResponseInputItem, ResponseStreamEvent } from 'openai/resources/responses/responses';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import type { ConversationMessage
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
4
|
+
import type { ConversationMessage } from '../llm/primitives.js';
|
|
5
|
+
import type { LLMClient, ModelOption, StreamingLLMResponse } from '../llm/client.js';
|
|
6
|
+
import type { ModelRequest } from '../llm/request.js';
|
|
7
|
+
import type { LLMProvider } from '../llm/provider.js';
|
|
8
|
+
import type { DeepReadonly } from '../util/json.js';
|
|
9
|
+
import { type ProviderErrorFields, type WithCredential } from './shared.js';
|
|
7
10
|
import { type CallHeaders } from './stream.js';
|
|
8
11
|
export declare class UnsupportedResponseOutputError extends Error {
|
|
9
12
|
constructor(types: readonly string[]);
|
|
@@ -97,4 +100,10 @@ export declare class OpenAIResponsesLLMClient implements LLMClient {
|
|
|
97
100
|
export declare function toResponsesInput(messages: readonly DeepReadonly<ConversationMessage>[], replayTag?: string): ResponseInputItem[];
|
|
98
101
|
/** Normalizes a completed response into a `ConversationMessage`, tagged for the client that got it. */
|
|
99
102
|
export declare function responseToMessage(response: Response, replayTag?: string): ConversationMessage;
|
|
103
|
+
/**
|
|
104
|
+
* The OpenAI Responses provider, at OpenAI's endpoint unless `baseURL` names another. Building one
|
|
105
|
+
* registers nothing, so a host can read its defaults and models first (see `defaultRoute`);
|
|
106
|
+
* `registerProvider(ctx, openaiResponsesProvider(config), { retry })` registers it.
|
|
107
|
+
*/
|
|
108
|
+
export declare const openaiResponsesProvider: (config: WithCredential<OpenAIResponsesConfig>) => LLMProvider;
|
|
100
109
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { LLMProvider } from '
|
|
2
|
+
import type { LLMProvider } from '../llm/provider.js';
|
|
3
3
|
export declare const OPENCODE_COPILOT_PROVIDER_NAME = "opencode-copilot";
|
|
4
4
|
declare const ConfigSchema: z.ZodObject<{
|
|
5
5
|
authPath: z.ZodString;
|
|
@@ -19,5 +19,5 @@ export type OpenCodeCopilotConfig = z.input<typeof ConfigSchema>;
|
|
|
19
19
|
* any startup failure rejects, so no provider is offered without a live catalog. No login or refresh.
|
|
20
20
|
* Protocols and headers follow anomalyco/opencode's github-copilot plugin (checked 2026-10-14).
|
|
21
21
|
*/
|
|
22
|
-
export declare
|
|
22
|
+
export declare const opencodeCopilotProvider: (config: OpenCodeCopilotConfig) => Promise<LLMProvider>;
|
|
23
23
|
export {};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type OpenAI from 'openai';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import type { ModelOption
|
|
3
|
+
import type { ModelOption } from '../llm/client.js';
|
|
4
|
+
import type { LLMProvider } from '../llm/provider.js';
|
|
5
|
+
import type { ThinkingEffort } from '../llm/primitives.js';
|
|
4
6
|
import { GatewayLLMClient, type GatewayProtocol } from './gateway.js';
|
|
7
|
+
import { type WithCredential } from './shared.js';
|
|
5
8
|
export declare const OPENCODE_GO_BASE_URL = "https://opencode.ai/zen/go/v1";
|
|
6
9
|
export declare const OPENCODE_GO_PROVIDER_NAME = "opencode-go";
|
|
7
10
|
export declare const OPENCODE_GO_DEFAULT_MODEL = "deepseek-v4.1-flash";
|
|
@@ -22,12 +25,13 @@ type GoModel = {
|
|
|
22
25
|
type DeveloperRole = 'developer' | 'system';
|
|
23
26
|
type GoModelTable = Readonly<Record<string, GoModel>>;
|
|
24
27
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* https://models.dev/api.json
|
|
29
|
-
* (
|
|
30
|
-
* 2026-10-
|
|
28
|
+
* Go's documented Responses, Chat Completions and Messages models, plus retained legacy ids.
|
|
29
|
+
* Google-native Gemini is not supported. Protocols from https://opencode.ai/v2/docs/console/go,
|
|
30
|
+
* with additions confirmed by https://opencode.ai/inference/go/v1/models (checked 2026-10-24).
|
|
31
|
+
* Windows in tokens come from the `opencode-go` entry of https://models.dev/api.json: its `input`
|
|
32
|
+
* limit where given, else `context`, undiscounted (original entries checked 2026-10-11, additions
|
|
33
|
+
* 2026-10-24). Missing limits stay unknown. A Messages model's output cap is that entry's `output`
|
|
34
|
+
* limit (checked 2026-10-12). `GET /models` lists ids but no protocol; discovery is not done at runtime.
|
|
31
35
|
*/
|
|
32
36
|
export declare const OPENCODE_GO_MODEL_TABLE: GoModelTable;
|
|
33
37
|
export declare const OpenCodeGoConfigSchema: z.ZodObject<{
|
|
@@ -95,4 +99,11 @@ export declare class OpenCodeGoLLMClient extends GatewayLLMClient {
|
|
|
95
99
|
fetch?: typeof globalThis.fetch;
|
|
96
100
|
});
|
|
97
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* The OpenCode Go gateway (`https://opencode.ai/zen/go/v1`): one subscription key in front of many
|
|
104
|
+
* vendors' models, each answering on one protocol: OpenAI Responses, Chat Completions or Anthropic
|
|
105
|
+
* Messages, each served by its own client. The host names itself with a
|
|
106
|
+
* `User-Agent` in `defaultHeaders`; each request carries its thread as Go's session header.
|
|
107
|
+
*/
|
|
108
|
+
export declare const opencodeGoProvider: (config: WithCredential<OpenCodeGoConfig>) => LLMProvider;
|
|
98
109
|
export {};
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import type { FailureClassification } from '
|
|
3
|
+
import type { FailureClassification } from '../llm/failure.js';
|
|
4
|
+
/**
|
|
5
|
+
* A provider's configuration with its credential named: the host resolves it, from wherever it keeps
|
|
6
|
+
* it, and says so even when it has none. A provider without one can still be described, its defaults
|
|
7
|
+
* and models read; building a client for it then fails, naming what is missing.
|
|
8
|
+
*/
|
|
9
|
+
export type WithCredential<Config> = Config & {
|
|
10
|
+
readonly apiKey: string | undefined;
|
|
11
|
+
};
|
|
4
12
|
/** Extra top-level request fields merged into every call (vendor extensions), minus the refused ones. */
|
|
5
13
|
export declare const ExtraBodySchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
6
14
|
/**
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { StreamIdleError } from '
|
|
3
|
-
import type { ConversationMessage, JsonObject, LLMStreamChunk,
|
|
2
|
+
import { StreamIdleError } from '../llm/client.js';
|
|
3
|
+
import type { ConversationMessage, JsonObject, LLMStreamChunk, ModelResponse, ToolCall } from '../llm/primitives.js';
|
|
4
|
+
import type { ModelRequest } from '../llm/request.js';
|
|
5
|
+
import type { StreamingLLMResponse } from '../llm/client.js';
|
|
4
6
|
/**
|
|
5
7
|
* How long one attempt may go without a single event from the provider, waiting for the first
|
|
6
8
|
* included, before it fails as `timeout`; `null` disables the deadline. Required: it is transport
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@leuduan/lagent/
|
|
2
|
+
* `@leuduan/lagent/records`: the serialized contract, what a reader of the journal or a plugin writing
|
|
3
3
|
* rows needs. Journal rows, the types a row mentions, the helpers that read and write them and the
|
|
4
4
|
* JSON types they are written in. The Zod schemas, the tables the types derive from and the
|
|
5
|
-
* hand-written agent and prompt configuration stay
|
|
5
|
+
* hand-written agent and prompt configuration stay in their modules, which the package imports
|
|
6
|
+
* directly.
|
|
6
7
|
*/
|
|
7
|
-
export { isForkSpawn, isSurfaceEvent, parseJournalEvent, queuedInput, stepContribution } from './
|
|
8
|
-
export type { CancelIntent, ConfirmationDescriptor, ExtensionRecord, InboxTarget, InitialInstallation, InputRole, Installation, InstallationLifetime, InterruptionPolicy, JournalEvent, JournalEventData, JournalEventInput, JournalEventType, OriginCause, QueuedInput, ReplacementKind, ReplacementTrigger, RunChain, RunOutcomeKind, RunSettledReason, Seq, StepContribution, StepContributionInput, SurfaceEventType, ThreadEnvironment, ThreadFork, ThreadInput, ThreadOrigin, ThreadSummary, TurnEndReason, TurnRejection, WaitDescriptor, } from './
|
|
9
|
-
export { toolResultMessageContent } from './
|
|
10
|
-
export type { ToolResult, ToolResultPayload, ToolResultPayloadInput } from './
|
|
11
|
-
export { toJsonSchema } from '
|
|
8
|
+
export { isForkSpawn, isSurfaceEvent, parseJournalEvent, queuedInput, stepContribution } from './journal.js';
|
|
9
|
+
export type { CancelIntent, ConfirmationDescriptor, ExtensionRecord, InboxTarget, InitialInstallation, InputRole, Installation, InstallationLifetime, InterruptionPolicy, JournalEvent, JournalEventData, JournalEventInput, JournalEventType, OriginCause, QueuedInput, ReplacementKind, ReplacementTrigger, RunChain, RunOutcomeKind, RunSettledReason, Seq, StepContribution, StepContributionInput, SurfaceEventType, ThreadEnvironment, ThreadFork, ThreadInput, ThreadOrigin, ThreadSummary, TurnEndReason, TurnRejection, WaitDescriptor, } from './journal.js';
|
|
10
|
+
export { toolResultMessageContent } from './toolResult.js';
|
|
11
|
+
export type { ToolResult, ToolResultPayload, ToolResultPayloadInput } from './toolResult.js';
|
|
12
|
+
export { toJsonSchema } from '../util/jsonSchema.js';
|
|
12
13
|
export type { DeepReadonly, JsonValue, ReadonlyJsonValue } from '../util/json.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as p}from"../chunks/FJLU4UH3.js";import{f as e,l as o,m as t,q as r,r as n,s}from"../chunks/MMNNZCBO.js";import"../chunks/G44LG6VL.js";import"../chunks/D4PQP5MA.js";export{n as isForkSpawn,s as isSurfaceEvent,r as parseJournalEvent,o as queuedInput,t as stepContribution,p as toJsonSchema,e as toolResultMessageContent};
|