@leuduan/lagent 0.0.0-stage → 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/LICENSE +16 -0
- package/README.md +157 -2
- package/dist/chunks/2GCIWSOA.js +5 -0
- package/dist/chunks/2P47AHNK.js +7 -0
- package/dist/chunks/34KW6VNQ.js +1 -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/7VAPNE3L.js +1 -0
- package/dist/chunks/ASSQZH3F.js +1 -0
- package/dist/chunks/B4FXK5ER.js +77 -0
- package/dist/chunks/BBCW2FZK.js +1 -0
- 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/DDANMY45.js +3 -0
- package/dist/chunks/DDZ7YF26.js +1 -0
- package/dist/chunks/EMRB4KCN.js +6 -0
- package/dist/chunks/EPYQ5M3B.js +3 -0
- package/dist/chunks/FJLU4UH3.js +1 -0
- package/dist/chunks/G44LG6VL.js +1 -0
- package/dist/chunks/GGSVIIWJ.js +2 -0
- package/dist/chunks/HK6ZSONF.js +1 -0
- package/dist/chunks/IAAEP6VL.js +30 -0
- package/dist/chunks/JCTBX33H.js +36 -0
- 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/MNJ4SRF7.js +1 -0
- package/dist/chunks/N6IXG2VL.js +1 -0
- package/dist/chunks/OCBPT7KE.js +1 -0
- package/dist/chunks/OL5A6ITQ.js +1 -0
- package/dist/chunks/PUSUPTAT.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/compositions/codex.d.ts +66 -0
- package/dist/compositions/codexPrompts.d.ts +56 -0
- package/dist/context.d.ts +109 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +1 -0
- package/dist/journal/catalog.d.ts +112 -0
- package/dist/journal/forkChain.d.ts +16 -0
- package/dist/journal/index.d.ts +15 -0
- package/dist/journal/journal.d.ts +475 -0
- package/dist/journal/projection.d.ts +87 -0
- package/dist/journal/store.d.ts +181 -0
- package/dist/llm/client.d.ts +135 -0
- package/dist/llm/content.d.ts +52 -0
- package/dist/llm/failure.d.ts +82 -0
- package/dist/llm/index.d.ts +22 -0
- package/dist/llm/index.js +1 -0
- package/dist/llm/primitives.d.ts +286 -0
- package/dist/llm/prompt.d.ts +21 -0
- package/dist/llm/provider.d.ts +74 -0
- package/dist/llm/readLedger.d.ts +24 -0
- package/dist/llm/request.d.ts +58 -0
- package/dist/loop/agent.d.ts +18 -0
- package/dist/loop/authorization.d.ts +41 -0
- package/dist/loop/auxiliary.d.ts +58 -0
- package/dist/loop/chunks.d.ts +27 -0
- package/dist/loop/completion.d.ts +17 -0
- package/dist/loop/errors.d.ts +139 -0
- package/dist/loop/hooks.d.ts +274 -0
- package/dist/loop/index.d.ts +16 -0
- package/dist/loop/runner.d.ts +134 -0
- package/dist/loop/runtime.d.ts +76 -0
- package/dist/loop/strategy.d.ts +80 -0
- package/dist/loop/surfacePrepare.d.ts +30 -0
- package/dist/loop/tool.d.ts +106 -0
- package/dist/loop/toolCalls.d.ts +35 -0
- package/dist/plugin.d.ts +50 -0
- package/dist/plugin.js +1 -0
- package/dist/plugins/agentsMd.d.ts +80 -0
- package/dist/plugins/agentsMd.js +1 -0
- package/dist/plugins/ask/index.d.ts +26 -0
- package/dist/plugins/ask/index.js +1 -0
- package/dist/plugins/ask/service.d.ts +125 -0
- package/dist/plugins/ask/tools.d.ts +9 -0
- package/dist/plugins/commands/index.d.ts +43 -0
- package/dist/plugins/commands/index.js +1 -0
- package/dist/plugins/commands/output.d.ts +115 -0
- package/dist/plugins/commands/record.d.ts +558 -0
- package/dist/plugins/commands/service.d.ts +321 -0
- package/dist/plugins/commands/shell.d.ts +25 -0
- package/dist/plugins/commands/tools.d.ts +10 -0
- package/dist/plugins/compaction/checkpoint.d.ts +94 -0
- package/dist/plugins/compaction/config.d.ts +133 -0
- package/dist/plugins/compaction/estimate.d.ts +37 -0
- package/dist/plugins/compaction/index.d.ts +87 -0
- package/dist/plugins/compaction/index.js +7 -0
- package/dist/plugins/compaction/planner.d.ts +207 -0
- package/dist/plugins/compaction/prune.d.ts +9 -0
- package/dist/plugins/compaction/record.d.ts +227 -0
- package/dist/plugins/compaction/segments.d.ts +23 -0
- package/dist/plugins/compaction/state.d.ts +68 -0
- package/dist/plugins/compaction/summarize.d.ts +13 -0
- package/dist/plugins/dateAndBranch.d.ts +47 -0
- package/dist/plugins/dateAndBranch.js +1 -0
- package/dist/plugins/delegations/answers.d.ts +39 -0
- package/dist/plugins/delegations/assignmentKey.d.ts +22 -0
- package/dist/plugins/delegations/cleanup.d.ts +161 -0
- package/dist/plugins/delegations/constraint.d.ts +76 -0
- package/dist/plugins/delegations/index.d.ts +39 -0
- package/dist/plugins/delegations/index.js +1 -0
- package/dist/plugins/delegations/notices.d.ts +261 -0
- package/dist/plugins/delegations/obligations.d.ts +210 -0
- package/dist/plugins/delegations/record.d.ts +633 -0
- package/dist/plugins/delegations/request.d.ts +384 -0
- package/dist/plugins/delegations/role.d.ts +30 -0
- package/dist/plugins/delegations/service.d.ts +563 -0
- package/dist/plugins/delegations/standing.d.ts +19 -0
- package/dist/plugins/delegations/stopCheck.d.ts +21 -0
- package/dist/plugins/delegations/tools.d.ts +71 -0
- package/dist/plugins/delegations/waitContracts.d.ts +118 -0
- package/dist/plugins/delegations/waitResolver.d.ts +116 -0
- package/dist/plugins/diagnostics/digest.d.ts +14 -0
- package/dist/plugins/diagnostics/index.d.ts +68 -0
- package/dist/plugins/diagnostics/index.js +1 -0
- package/dist/plugins/fileTools/config.d.ts +10 -0
- package/dist/plugins/fileTools/editFiles.d.ts +117 -0
- package/dist/plugins/fileTools/fsRead.d.ts +17 -0
- 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/ripgrep.d.ts +20 -0
- package/dist/plugins/fileTools/textEdit.d.ts +67 -0
- package/dist/plugins/fileTools/tools.d.ts +6 -0
- package/dist/plugins/historyRecall/history.d.ts +9 -0
- package/dist/plugins/historyRecall/index.d.ts +31 -0
- package/dist/plugins/historyRecall/index.js +1 -0
- package/dist/plugins/historyRecall/render.d.ts +34 -0
- package/dist/plugins/historyRecall/tools.d.ts +4 -0
- package/dist/plugins/mcp/catalog.d.ts +36 -0
- package/dist/plugins/mcp/config.d.ts +63 -0
- package/dist/plugins/mcp/connection.d.ts +53 -0
- package/dist/plugins/mcp/errors.d.ts +32 -0
- package/dist/plugins/mcp/index.d.ts +33 -0
- package/dist/plugins/mcp/index.js +5 -0
- package/dist/plugins/mcp/mount.d.ts +98 -0
- package/dist/plugins/mcp/names.d.ts +25 -0
- package/dist/plugins/mcp/render.d.ts +29 -0
- package/dist/plugins/mcp/slots.d.ts +15 -0
- package/dist/plugins/mcp/stdio.d.ts +49 -0
- package/dist/plugins/mcp/tools.d.ts +41 -0
- package/dist/plugins/mcp/version.d.ts +2 -0
- package/dist/plugins/routeNotice.d.ts +22 -0
- package/dist/plugins/routeNotice.js +1 -0
- package/dist/plugins/sandbox/absent.d.ts +33 -0
- package/dist/plugins/sandbox/client.d.ts +39 -0
- package/dist/plugins/sandbox/files.d.ts +28 -0
- package/dist/plugins/sandbox/index.d.ts +52 -0
- package/dist/plugins/sandbox/index.js +4 -0
- package/dist/plugins/sandbox/mode.d.ts +57 -0
- package/dist/plugins/sandbox/policy.d.ts +163 -0
- package/dist/plugins/sandbox/protocol.d.ts +107 -0
- package/dist/plugins/sandbox/service.d.ts +153 -0
- package/dist/plugins/sandbox/worker.d.ts +12 -0
- package/dist/plugins/sandbox/worker.js +1 -0
- package/dist/plugins/schedules/index.d.ts +21 -0
- package/dist/plugins/schedules/index.js +5 -0
- package/dist/plugins/schedules/record.d.ts +396 -0
- package/dist/plugins/schedules/service.d.ts +120 -0
- package/dist/plugins/schedules/time.d.ts +26 -0
- package/dist/plugins/schedules/tools.d.ts +6 -0
- package/dist/plugins/skills/discovery.d.ts +83 -0
- package/dist/plugins/skills/index.d.ts +31 -0
- package/dist/plugins/skills/index.js +1 -0
- package/dist/plugins/skills/tools.d.ts +11 -0
- package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
- package/dist/plugins/subAgents/index.d.ts +67 -0
- package/dist/plugins/subAgents/index.js +1 -0
- package/dist/plugins/subAgents/tools.d.ts +67 -0
- package/dist/plugins/threadDirs.d.ts +36 -0
- package/dist/plugins/threadDirs.js +1 -0
- package/dist/plugins/toolPolicy/index.d.ts +61 -0
- package/dist/plugins/toolPolicy/index.js +1 -0
- package/dist/plugins/truncateToolOutput.d.ts +30 -0
- package/dist/plugins/truncateToolOutput.js +6 -0
- package/dist/plugins/usage/index.d.ts +26 -0
- package/dist/plugins/usage/index.js +1 -0
- package/dist/plugins/usage/tracker.d.ts +34 -0
- package/dist/plugins/verify/index.d.ts +27 -0
- package/dist/plugins/verify/index.js +6 -0
- 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 +93 -0
- package/dist/plugins/verify/state.d.ts +58 -0
- package/dist/plugins/webTools/html.d.ts +23 -0
- package/dist/plugins/webTools/index.d.ts +34 -0
- package/dist/plugins/webTools/index.js +1 -0
- package/dist/plugins/webTools/network.d.ts +23 -0
- package/dist/plugins/webTools/web.d.ts +32 -0
- package/dist/plugins/workflows/assignment.d.ts +20 -0
- package/dist/plugins/workflows/cleanup.d.ts +38 -0
- package/dist/plugins/workflows/definition.d.ts +184 -0
- package/dist/plugins/workflows/entryPlan.d.ts +95 -0
- package/dist/plugins/workflows/hostBindings.d.ts +146 -0
- package/dist/plugins/workflows/index.d.ts +28 -0
- package/dist/plugins/workflows/index.js +11 -0
- package/dist/plugins/workflows/observations.d.ts +81 -0
- package/dist/plugins/workflows/participantModels.d.ts +28 -0
- package/dist/plugins/workflows/participants.d.ts +143 -0
- package/dist/plugins/workflows/policy.d.ts +112 -0
- package/dist/plugins/workflows/record.d.ts +2849 -0
- package/dist/plugins/workflows/routing.d.ts +116 -0
- package/dist/plugins/workflows/schema.d.ts +26 -0
- package/dist/plugins/workflows/service.d.ts +477 -0
- package/dist/plugins/workflows/state.d.ts +373 -0
- 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 +103 -0
- package/dist/plugins/workflows/workStatus.d.ts +21 -0
- package/dist/plugins/workspaceNotice.d.ts +36 -0
- package/dist/plugins/workspaceNotice.js +1 -0
- package/dist/providers/anthropic.d.ts +178 -0
- package/dist/providers/anthropicMessages.d.ts +66 -0
- package/dist/providers/codex.d.ts +71 -0
- package/dist/providers/codexAuth.d.ts +116 -0
- package/dist/providers/deepseek.d.ts +59 -0
- package/dist/providers/failure.d.ts +23 -0
- package/dist/providers/gateway.d.ts +24 -0
- package/dist/providers/index.d.ts +18 -0
- package/dist/providers/index.js +6 -0
- package/dist/providers/openaiChat.d.ts +73 -0
- package/dist/providers/openaiResponses.d.ts +109 -0
- package/dist/providers/opencodeCopilot.d.ts +23 -0
- package/dist/providers/opencodeGo.d.ts +109 -0
- package/dist/providers/shared.d.ts +112 -0
- package/dist/providers/stream.d.ts +156 -0
- package/dist/records/index.d.ts +13 -0
- package/dist/records/index.js +1 -0
- package/dist/records/journal.d.ts +2968 -0
- package/dist/records/toolResult.d.ts +65 -0
- package/dist/services/agents.d.ts +62 -0
- package/dist/services/catalogContributions.d.ts +73 -0
- package/dist/services/confinement/files.d.ts +118 -0
- package/dist/services/confinement/service.d.ts +219 -0
- package/dist/services/core.d.ts +28 -0
- package/dist/services/extensionEvents.d.ts +181 -0
- package/dist/services/journal.d.ts +26 -0
- package/dist/services/llm.d.ts +82 -0
- package/dist/services/modes.d.ts +65 -0
- package/dist/services/plugins.d.ts +34 -0
- package/dist/services/presets/definition.d.ts +154 -0
- package/dist/services/presets/installations.d.ts +139 -0
- package/dist/services/prompts.d.ts +85 -0
- package/dist/services/threads/activation.d.ts +100 -0
- package/dist/services/threads/admission.d.ts +174 -0
- package/dist/services/threads/birth.d.ts +219 -0
- package/dist/services/threads/index.d.ts +14 -0
- package/dist/services/threads/runEvents.d.ts +79 -0
- package/dist/services/threads/runOwner.d.ts +368 -0
- package/dist/services/threads/service.d.ts +450 -0
- package/dist/services/threads/thread.d.ts +268 -0
- package/dist/services/threads/view.d.ts +93 -0
- package/dist/services/tools.d.ts +118 -0
- package/dist/state/birth.d.ts +62 -0
- package/dist/state/chain.d.ts +46 -0
- package/dist/state/confirmations.d.ts +64 -0
- package/dist/state/continuation.d.ts +167 -0
- package/dist/state/decide.d.ts +72 -0
- package/dist/state/dispatches.d.ts +54 -0
- package/dist/state/errors.d.ts +26 -0
- package/dist/state/forks.d.ts +61 -0
- package/dist/state/holds.d.ts +104 -0
- package/dist/state/inbox.d.ts +188 -0
- 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/limits.d.ts +14 -0
- package/dist/state/prompt.d.ts +13 -0
- package/dist/state/recovery.d.ts +7 -0
- package/dist/state/replace.d.ts +33 -0
- package/dist/state/requests.d.ts +129 -0
- package/dist/state/route.d.ts +61 -0
- package/dist/state/summary.d.ts +16 -0
- package/dist/state/surface.d.ts +153 -0
- package/dist/state/surfaceRead.d.ts +20 -0
- package/dist/state/thread.d.ts +73 -0
- package/dist/state/turns.d.ts +87 -0
- package/dist/state/waits.d.ts +38 -0
- package/dist/state/wake.d.ts +32 -0
- package/dist/stores/durableObject.d.ts +23 -0
- package/dist/stores/durableObject.js +1 -0
- package/dist/stores/durableObjectConnection.d.ts +27 -0
- package/dist/stores/memory.d.ts +29 -0
- package/dist/stores/sql.d.ts +59 -0
- package/dist/stores/sqlite.d.ts +31 -0
- package/dist/stores/sqlite.js +1 -0
- package/dist/sys/environment.d.ts +42 -0
- package/dist/sys/git.d.ts +47 -0
- package/dist/sys/paths.d.ts +9 -0
- package/dist/sys/spawn.d.ts +186 -0
- package/dist/testing/clock.d.ts +17 -0
- package/dist/testing/fakeLlm.d.ts +76 -0
- package/dist/testing/fedLlm.d.ts +34 -0
- package/dist/testing/helpers.d.ts +362 -0
- package/dist/testing/index.d.ts +13 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/processes.d.ts +13 -0
- package/dist/testing/settlement.d.ts +6 -0
- package/dist/testing/tmpDirs.d.ts +17 -0
- package/dist/util/async.d.ts +8 -0
- package/dist/util/diff.d.ts +25 -0
- package/dist/util/dispatch.d.ts +8 -0
- package/dist/util/errors.d.ts +28 -0
- package/dist/util/foldState.d.ts +17 -0
- package/dist/util/freeze.d.ts +2 -0
- package/dist/util/ids.d.ts +2 -0
- package/dist/util/json.d.ts +37 -0
- package/dist/util/jsonSchema.d.ts +7 -0
- package/dist/util/log.d.ts +6 -0
- package/dist/util/retries.d.ts +25 -0
- package/dist/util/text.d.ts +21 -0
- package/dist/util/timers.d.ts +43 -0
- package/package.json +183 -3
|
@@ -0,0 +1,178 @@
|
|
|
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';
|
|
6
|
+
/** One Messages content block, as JSON. */
|
|
7
|
+
export type AnthropicBlock = Record<string, unknown>;
|
|
8
|
+
/** One Messages turn. Consecutive messages of one role are one turn. */
|
|
9
|
+
export type AnthropicMessage = {
|
|
10
|
+
role: 'user' | 'assistant';
|
|
11
|
+
content: AnthropicBlock[];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A call id as Messages accepts it: an id already in its alphabet as it is, any other (another
|
|
15
|
+
* provider's, such as Responses' `call_…|fc_…`) as a digest of itself. Deterministic, so a call and
|
|
16
|
+
* its result agree; never reversed, since only ids Messages wrote come back.
|
|
17
|
+
*/
|
|
18
|
+
export declare const anthropicToolUseId: (id: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* The state an assistant message keeps for replay: its message id, and its thinking blocks with
|
|
21
|
+
* their signatures, which the API verifies and which only the model that wrote them can read.
|
|
22
|
+
*/
|
|
23
|
+
export type AnthropicReplayState = {
|
|
24
|
+
id: string;
|
|
25
|
+
thinking: AnthropicBlock[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A request's conversation as Messages turns.
|
|
29
|
+
*
|
|
30
|
+
* - A `tool` message is a `tool_result` block in the next user turn, and results lead their turn,
|
|
31
|
+
* as the API requires.
|
|
32
|
+
* - A `developer` or `system` message is user text inside `<system-reminder>`: Messages has no role
|
|
33
|
+
* for a notice in the conversation.
|
|
34
|
+
* - An assistant message replays its thinking first, from state `replayTag` wrote; another model's
|
|
35
|
+
* is dropped. A malformed tool call goes back with empty input, since Messages takes an object.
|
|
36
|
+
* - Empty text is dropped (the API refuses it), and a message left with nothing is dropped too.
|
|
37
|
+
*/
|
|
38
|
+
export declare function toAnthropicMessages(messages: readonly DeepReadonly<ConversationMessage>[], options: {
|
|
39
|
+
readonly provider: string;
|
|
40
|
+
readonly replayTag: string;
|
|
41
|
+
}): AnthropicMessage[];
|
|
42
|
+
/**
|
|
43
|
+
* Content parts as Messages blocks: images by URL or base64, files as documents (a PDF by URL or
|
|
44
|
+
* base64, plain text inline). A file the provider holds by id is refused: that is another API's
|
|
45
|
+
* upload, which Messages cannot name.
|
|
46
|
+
*/
|
|
47
|
+
export declare function contentBlocks(content: readonly DeepReadonly<ContentPart>[], provider: string): AnthropicBlock[];
|
|
48
|
+
/** Tool specs as Messages tools; the schema goes as it stands. */
|
|
49
|
+
export declare const toAnthropicTools: (tools: readonly DeepReadonly<ToolSpec>[]) => AnthropicBlock[];
|
|
50
|
+
/** A request's tool choice, with parallel calls off when the request says so. */
|
|
51
|
+
export declare function toAnthropicToolChoice(choice: DeepReadonly<ToolChoice>, parallel: boolean): AnthropicBlock;
|
|
52
|
+
/**
|
|
53
|
+
* The thinking fields for an effort: none sent for none named, so the model's own default stands;
|
|
54
|
+
* `none` disables thinking; any other is adaptive thinking at that effort, with its text summarized,
|
|
55
|
+
* since some models omit thinking text unless asked.
|
|
56
|
+
*/
|
|
57
|
+
export declare function anthropicThinking(effort: ThinkingEffort | undefined): JsonObject;
|
|
58
|
+
/** One raw Messages stream event, as the API streams it. Only the fields read here are typed. */
|
|
59
|
+
export type AnthropicStreamEvent = {
|
|
60
|
+
type: 'message_start';
|
|
61
|
+
message: {
|
|
62
|
+
id: string;
|
|
63
|
+
model: string;
|
|
64
|
+
usage?: RawUsage;
|
|
65
|
+
};
|
|
66
|
+
} | {
|
|
67
|
+
type: 'content_block_start';
|
|
68
|
+
index: number;
|
|
69
|
+
content_block: AnthropicBlock;
|
|
70
|
+
} | {
|
|
71
|
+
type: 'content_block_delta';
|
|
72
|
+
index: number;
|
|
73
|
+
delta: AnthropicBlock;
|
|
74
|
+
} | {
|
|
75
|
+
type: 'content_block_stop';
|
|
76
|
+
index: number;
|
|
77
|
+
} | {
|
|
78
|
+
type: 'message_delta';
|
|
79
|
+
delta: {
|
|
80
|
+
stop_reason?: string | null;
|
|
81
|
+
stop_sequence?: string | null;
|
|
82
|
+
};
|
|
83
|
+
usage?: RawUsage;
|
|
84
|
+
} | {
|
|
85
|
+
type: 'message_stop';
|
|
86
|
+
} | {
|
|
87
|
+
type: 'ping';
|
|
88
|
+
} | {
|
|
89
|
+
type: 'error';
|
|
90
|
+
error: {
|
|
91
|
+
type?: string;
|
|
92
|
+
message?: string;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
type RawUsage = {
|
|
96
|
+
input_tokens?: number | null;
|
|
97
|
+
output_tokens?: number | null;
|
|
98
|
+
cache_read_input_tokens?: number | null;
|
|
99
|
+
cache_creation_input_tokens?: number | null;
|
|
100
|
+
output_tokens_details?: {
|
|
101
|
+
thinking_tokens?: number | null;
|
|
102
|
+
} | null;
|
|
103
|
+
};
|
|
104
|
+
/** A failure the API reported, from a rejected request (with its status) or an `error` stream event. */
|
|
105
|
+
export declare class AnthropicAPIError extends Error {
|
|
106
|
+
readonly errorType: string | undefined;
|
|
107
|
+
readonly status?: number;
|
|
108
|
+
readonly headers?: Headers;
|
|
109
|
+
constructor(
|
|
110
|
+
/** The API's error type, such as `overloaded_error`. */
|
|
111
|
+
errorType: string | undefined, message: string,
|
|
112
|
+
/** The HTTP status of a rejected request; absent for a failure inside the stream. */
|
|
113
|
+
status?: number, headers?: Headers);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Whether a failure says the request exceeded the model's context window. The API names no code of
|
|
117
|
+
* its own for it, only `invalid_request_error`, so its wording decides, as `docs/guides/providers.md` allows
|
|
118
|
+
* where a provider has no code: "prompt is too long", which a gateway may wrap in its own prose.
|
|
119
|
+
*/
|
|
120
|
+
export declare const isAnthropicOverflow: (error: AnthropicAPIError) => boolean;
|
|
121
|
+
/**
|
|
122
|
+
* The kind of a failure from a Messages client, by structured evidence only: the API's error type
|
|
123
|
+
* where it names a kind (a `billing_error` is `quota` whatever status carries it), else the HTTP
|
|
124
|
+
* status as every protocol reads one (`statusKind`, 529 being Anthropic's overloaded). A failure
|
|
125
|
+
* inside the stream has no status, so its type is all there is; else socket codes.
|
|
126
|
+
* `retryAfterMs` comes from the `retry-after-ms` or `retry-after` header.
|
|
127
|
+
*/
|
|
128
|
+
export declare function classifyAnthropicFailure(error: unknown, now?: number): FailureClassification;
|
|
129
|
+
/** `end_turn`, `tool_use` and `stop_sequence` finish a message; the output cap and window are `length`. */
|
|
130
|
+
export declare const anthropicFinish: (stopReason: string) => ResponseFinish;
|
|
131
|
+
export interface MessagesAssemblyOptions {
|
|
132
|
+
/** The tag the message's state is written under, which replays it. */
|
|
133
|
+
readonly replayTag: string;
|
|
134
|
+
/** The name a tool call reaches lagent under, from the name the model used. */
|
|
135
|
+
readonly toolName?: (name: string) => string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* One streamed Messages message, folded event by event. It owns the rule that a message is complete
|
|
139
|
+
* only once its stop reason arrived and `message_stop` followed, and hands back what arrived for a
|
|
140
|
+
* cut-off one: text and reasoning, never a tool call or state.
|
|
141
|
+
*/
|
|
142
|
+
export declare class MessagesAssembly {
|
|
143
|
+
private id;
|
|
144
|
+
private model;
|
|
145
|
+
private readonly blocks;
|
|
146
|
+
private stopReason;
|
|
147
|
+
private stopSequence;
|
|
148
|
+
private stopped;
|
|
149
|
+
private usage;
|
|
150
|
+
private readonly options;
|
|
151
|
+
constructor(options: MessagesAssemblyOptions);
|
|
152
|
+
/** Folds one event and returns the chunk it adds, if any. An `error` event throws. */
|
|
153
|
+
apply(event: AnthropicStreamEvent): LLMStreamChunk | null;
|
|
154
|
+
/** Whether the message is complete: its stop reason arrived, and `message_stop` after it. */
|
|
155
|
+
get complete(): boolean;
|
|
156
|
+
/** The message's stop reason, once one arrived. */
|
|
157
|
+
get stop(): string | null;
|
|
158
|
+
private applyDelta;
|
|
159
|
+
private addUsage;
|
|
160
|
+
/**
|
|
161
|
+
* Usage as lagent counts it: Anthropic's `input_tokens` excludes the cached ones, so input is the
|
|
162
|
+
* sum of uncached, cache-read and cache-written tokens, with the cached ones also kept apart.
|
|
163
|
+
*/
|
|
164
|
+
private normalizedUsage;
|
|
165
|
+
private ordered;
|
|
166
|
+
private text;
|
|
167
|
+
private reasoning;
|
|
168
|
+
/** What the message says about itself: observed, never sent back. */
|
|
169
|
+
metadata(): JsonObject;
|
|
170
|
+
/** The settled message, once complete; `undefined` before. */
|
|
171
|
+
settle(): ModelResponse | undefined;
|
|
172
|
+
/** What arrived so far: text and reasoning, never a tool call nobody finished asking for. */
|
|
173
|
+
partial(): {
|
|
174
|
+
message: ConversationMessage;
|
|
175
|
+
providerMetadata: JsonObject;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { LLMClient, StreamingLLMResponse } from '../llm/client.js';
|
|
3
|
+
import type { ModelRequest } from '../llm/request.js';
|
|
4
|
+
import { type AnthropicStreamEvent } from './anthropic.js';
|
|
5
|
+
import { type CallHeaders } from './stream.js';
|
|
6
|
+
declare const AnthropicMessagesConfigSchema: z.ZodObject<{
|
|
7
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
8
|
+
baseURL: z.ZodString;
|
|
9
|
+
streamIdleTimeoutMs: z.ZodNullable<z.ZodNumber>;
|
|
10
|
+
authorization: z.ZodDefault<z.ZodEnum<{
|
|
11
|
+
"x-api-key": "x-api-key";
|
|
12
|
+
bearer: "bearer";
|
|
13
|
+
}>>;
|
|
14
|
+
defaultHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
15
|
+
thinkingEffort: z.ZodOptional<z.ZodEnum<{
|
|
16
|
+
low: "low";
|
|
17
|
+
high: "high";
|
|
18
|
+
none: "none";
|
|
19
|
+
medium: "medium";
|
|
20
|
+
max: "max";
|
|
21
|
+
}>>;
|
|
22
|
+
maxOutputTokens: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
type AnthropicMessagesConfig = z.input<typeof AnthropicMessagesConfigSchema>;
|
|
25
|
+
type ParsedConfig = z.output<typeof AnthropicMessagesConfigSchema>;
|
|
26
|
+
type RequestPayload = Record<string, unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* The Anthropic Messages adapter for a provider whose models answer on Messages (Go or Copilot),
|
|
29
|
+
* which names itself as `name`. It speaks over `fetch` with no SDK: the request goes as
|
|
30
|
+
* JSON and the server-sent events are read as they arrive, so nothing reads the process environment.
|
|
31
|
+
* `headers` adds headers to each call, over the client's own; it is the client's owner's, and
|
|
32
|
+
* nothing subclasses the client to say it.
|
|
33
|
+
*
|
|
34
|
+
* The prompt goes as `system` blocks, notices as user text, and thinking replays from
|
|
35
|
+
* `provider_state` to the model that wrote it. Provider-executed tools and non-text response
|
|
36
|
+
* formats are refused.
|
|
37
|
+
*/
|
|
38
|
+
export declare class AnthropicMessagesLLMClient implements LLMClient {
|
|
39
|
+
readonly providerName: string;
|
|
40
|
+
protected readonly config: ParsedConfig;
|
|
41
|
+
private readonly fetchImpl;
|
|
42
|
+
private readonly callHeaders;
|
|
43
|
+
constructor(config: AnthropicMessagesConfig & {
|
|
44
|
+
name: string;
|
|
45
|
+
headers?: CallHeaders;
|
|
46
|
+
fetch?: typeof globalThis.fetch;
|
|
47
|
+
});
|
|
48
|
+
/** The tag replayable state is written and read under: one model's signed thinking is no other's. */
|
|
49
|
+
private replayTag;
|
|
50
|
+
/** The output cap of a request: its own, else the one configured for its model. */
|
|
51
|
+
private maxOutputTokens;
|
|
52
|
+
/** The headers of one call: the client's own, then the owner's for this call and its mapped request. */
|
|
53
|
+
private headers;
|
|
54
|
+
buildRequest(call: ModelRequest): RequestPayload;
|
|
55
|
+
chat(call: ModelRequest): Promise<StreamingLLMResponse>;
|
|
56
|
+
private open;
|
|
57
|
+
/** `error` as the overflow it is, when its fields say so, else unchanged. */
|
|
58
|
+
classified(error: unknown): unknown;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The events of a server-sent event stream, each `data` payload parsed as JSON. Lines end in CR, LF
|
|
62
|
+
* or CRLF, as the format allows; a CR at the end of a chunk waits for the next, which may bring its
|
|
63
|
+
* LF. The payload's own `type` names the event, so `event:` lines, ids and comments are not read.
|
|
64
|
+
*/
|
|
65
|
+
export declare function serverSentEvents(body: AsyncIterable<Uint8Array>): AsyncGenerator<AnthropicStreamEvent>;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { ModelOption } from '../llm/client.js';
|
|
4
|
+
import type { LLMProvider } from '../llm/provider.js';
|
|
5
|
+
import { type CodexCredentialManager } from './codexAuth.js';
|
|
6
|
+
import { OpenAIResponsesLLMClient } from './openaiResponses.js';
|
|
7
|
+
export declare const CODEX_PROVIDER_NAME = "codex";
|
|
8
|
+
export declare const CODEX_DEFAULT_MODEL = "gpt-5.6-luna";
|
|
9
|
+
/**
|
|
10
|
+
* The models agents are told about: every model the Codex backend lists for clients, with the
|
|
11
|
+
* efforts lagent can send (the backend also takes `xhigh` and, on some, `ultra`, which
|
|
12
|
+
* `ThinkingEffort` has no value for), from `codex app-server`'s `model/list` (checked 2026-10-11).
|
|
13
|
+
* The models it hides can be named, just not told.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CODEX_MODELS: readonly ModelOption[];
|
|
16
|
+
/**
|
|
17
|
+
* The usable context window of every model the Codex CLI's model cache lists, in tokens: its
|
|
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
|
|
21
|
+
* backend accepted 285,889 input tokens on `gpt-5.6-luna`, listed at 272,000 (measured 2026-10-03).
|
|
22
|
+
* A model not listed here has no window.
|
|
23
|
+
*/
|
|
24
|
+
export declare const CODEX_CONTEXT_WINDOWS: Readonly<Record<string, number>>;
|
|
25
|
+
export declare const CodexConfigSchema: z.ZodObject<{
|
|
26
|
+
authPath: z.ZodOptional<z.ZodString>;
|
|
27
|
+
refreshTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
streamIdleTimeoutMs: z.ZodNullable<z.ZodNumber>;
|
|
29
|
+
baseURL: z.ZodDefault<z.ZodString>;
|
|
30
|
+
defaultModel: z.ZodDefault<z.ZodString>;
|
|
31
|
+
thinkingEffort: z.ZodDefault<z.ZodEnum<{
|
|
32
|
+
low: "low";
|
|
33
|
+
high: "high";
|
|
34
|
+
none: "none";
|
|
35
|
+
medium: "medium";
|
|
36
|
+
max: "max";
|
|
37
|
+
}>>;
|
|
38
|
+
extraBody: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
export type CodexConfig = z.input<typeof CodexConfigSchema>;
|
|
41
|
+
/**
|
|
42
|
+
* The Responses client over the Codex CLI's ChatGPT login. Requests go to the ChatGPT backend through
|
|
43
|
+
* {@link codexOpenAI}, with a token read from the login file per call, so there is no API key and a
|
|
44
|
+
* token rotated by another process (or by this client) takes effect on the next request.
|
|
45
|
+
*/
|
|
46
|
+
export declare class CodexLLMClient extends OpenAIResponsesLLMClient {
|
|
47
|
+
readonly credentials: CodexCredentialManager;
|
|
48
|
+
constructor(config: CodexConfig & {
|
|
49
|
+
client?: OpenAI;
|
|
50
|
+
credentials?: CodexCredentialManager;
|
|
51
|
+
/** The transport under the authorization, for tests. */
|
|
52
|
+
fetch?: typeof globalThis.fetch;
|
|
53
|
+
});
|
|
54
|
+
/** The request goes out over the login, read first (see {@link overLogin}). */
|
|
55
|
+
protected openStream(request: Record<string, unknown>, headers: Record<string, string>, signal: AbortSignal): Promise<AsyncIterable<OpenAI.Responses.ResponseStreamEvent>>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Compresses the JSON body of each request under the authorization: the model calls replay the whole
|
|
59
|
+
* conversation, so their bodies are the large ones. The SDK sends JSON as a string; any other body
|
|
60
|
+
* goes as it is.
|
|
61
|
+
*/
|
|
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;
|
|
@@ -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,59 @@
|
|
|
1
|
+
import type OpenAI from 'openai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { ModelOption } from '../llm/client.js';
|
|
4
|
+
import type { ModelRequest } from '../llm/request.js';
|
|
5
|
+
import type { LLMProvider } from '../llm/provider.js';
|
|
6
|
+
import { OpenAIResponsesLLMClient } from './openaiResponses.js';
|
|
7
|
+
import { type ProviderErrorFields, type WithCredential } from './shared.js';
|
|
8
|
+
/** The stateless Responses endpoint DeepSeek documents as OpenAI-compatible. */
|
|
9
|
+
export declare const DEEPSEEK_RESPONSES_BASE_URL = "https://api.deepseek.com";
|
|
10
|
+
export declare const DEEPSEEK_RESPONSES_PROVIDER_NAME = "deepseek-responses";
|
|
11
|
+
/** DeepSeek's current API name for the DeepSeek-V4.1-Flash model. */
|
|
12
|
+
export declare const DEEPSEEK_RESPONSES_DEFAULT_MODEL = "deepseek-flash";
|
|
13
|
+
/** The models agents are told about, from the Codex CLI's DeepSeek model list (checked 2026-09-26). */
|
|
14
|
+
export declare const DEEPSEEK_RESPONSES_MODELS: readonly ModelOption[];
|
|
15
|
+
/**
|
|
16
|
+
* The usable context window of each DeepSeek model, in tokens, from the Codex CLI's DeepSeek model
|
|
17
|
+
* list: a `context_window` of 1,048,576 with its `effective_context_window_percent` of 95 applied,
|
|
18
|
+
* 996,147, rounded down from 996,147.2 (`~/.codex/ds.models.json`, checked 2026-10-03). The raw
|
|
19
|
+
* figure agreed with DeepSeek's own overflow message for `deepseek-flash`, so the usable one sits
|
|
20
|
+
* below the limit DeepSeek enforces. A model not listed here has no window.
|
|
21
|
+
*/
|
|
22
|
+
export declare const DEEPSEEK_RESPONSES_CONTEXT_WINDOWS: Readonly<Record<string, number>>;
|
|
23
|
+
export declare const DeepSeekResponsesConfigSchema: z.ZodObject<{
|
|
24
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
25
|
+
streamIdleTimeoutMs: z.ZodNullable<z.ZodNumber>;
|
|
26
|
+
defaultHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
27
|
+
extraBody: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
28
|
+
thinkingEffort: z.ZodOptional<z.ZodEnum<{
|
|
29
|
+
low: "low";
|
|
30
|
+
high: "high";
|
|
31
|
+
none: "none";
|
|
32
|
+
medium: "medium";
|
|
33
|
+
max: "max";
|
|
34
|
+
}>>;
|
|
35
|
+
baseURL: z.ZodDefault<z.ZodString>;
|
|
36
|
+
defaultModel: z.ZodDefault<z.ZodString>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
export type DeepSeekResponsesConfig = z.input<typeof DeepSeekResponsesConfigSchema>;
|
|
39
|
+
type DeepSeekResponsesClientConfig = DeepSeekResponsesConfig & {
|
|
40
|
+
client?: OpenAI;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* DeepSeek's OpenAI-compatible Responses API.
|
|
44
|
+
*
|
|
45
|
+
* The normalized Responses mapping is shared with OpenAI, while the provider name keeps one
|
|
46
|
+
* backend's replay state out of another. DeepSeek is stateless too, so completed output is replayed
|
|
47
|
+
* through `provider_state` on the next turn.
|
|
48
|
+
*/
|
|
49
|
+
export declare class DeepSeekResponsesLLMClient extends OpenAIResponsesLLMClient {
|
|
50
|
+
constructor(config: DeepSeekResponsesClientConfig);
|
|
51
|
+
buildRequest(call: ModelRequest): {
|
|
52
|
+
[x: string]: unknown;
|
|
53
|
+
};
|
|
54
|
+
/** The structured code where DeepSeek sends one, else the wording of its message. */
|
|
55
|
+
protected isContextOverflow(fields: ProviderErrorFields): boolean;
|
|
56
|
+
}
|
|
57
|
+
/** DeepSeek's Responses API provider, at DeepSeek's endpoint unless `baseURL` names another. */
|
|
58
|
+
export declare const deepseekProvider: (config: WithCredential<DeepSeekResponsesConfig>) => LLMProvider;
|
|
59
|
+
export {};
|
|
@@ -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/failure.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,24 @@
|
|
|
1
|
+
import type { LLMClient, StreamingLLMResponse } from '../llm/client.js';
|
|
2
|
+
import type { ModelRequest } from '../llm/request.js';
|
|
3
|
+
/** The protocols a gateway's models answer on: OpenAI Responses, Chat Completions, Anthropic Messages. */
|
|
4
|
+
export type GatewayProtocol = 'responses' | 'chat' | 'messages';
|
|
5
|
+
/** A gateway's check of a call: the protocol it goes on and the call to send. */
|
|
6
|
+
export type PrepareCall = (call: ModelRequest) => {
|
|
7
|
+
readonly protocol: GatewayProtocol;
|
|
8
|
+
readonly call: ModelRequest;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* One gateway: a credential and an endpoint in front of models that each answer on one protocol.
|
|
12
|
+
* It owns the rule that a call goes to the adapter for its model's protocol, never tried on
|
|
13
|
+
* another. `prepare` is the gateway's own check of a call: it names the protocol, throws what the
|
|
14
|
+
* gateway refuses, and returns the call to send, normalized for the model where the gateway must.
|
|
15
|
+
* The adapters are the protocol clients the gateway built, which share its name and its per-call
|
|
16
|
+
* headers (see `CallHeaders`).
|
|
17
|
+
*/
|
|
18
|
+
export declare class GatewayLLMClient implements LLMClient {
|
|
19
|
+
readonly providerName: string;
|
|
20
|
+
private readonly prepare;
|
|
21
|
+
private readonly adapters;
|
|
22
|
+
constructor(providerName: string, prepare: PrepareCall, adapters: Readonly<Record<GatewayProtocol, LLMClient>>);
|
|
23
|
+
chat(call: ModelRequest): Promise<StreamingLLMResponse>;
|
|
24
|
+
}
|
|
@@ -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';
|