@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,286 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { DeepReadonly } from '../util/json.js';
|
|
3
|
+
export declare const THINKING_EFFORT_VALUES: readonly ["none", "low", "medium", "high", "max"];
|
|
4
|
+
export type ThinkingEffort = (typeof THINKING_EFFORT_VALUES)[number];
|
|
5
|
+
export declare const ThinkingEffortSchema: z.ZodEnum<{
|
|
6
|
+
low: "low";
|
|
7
|
+
high: "high";
|
|
8
|
+
none: "none";
|
|
9
|
+
medium: "medium";
|
|
10
|
+
max: "max";
|
|
11
|
+
}>;
|
|
12
|
+
export type JsonObject = Record<string, unknown>;
|
|
13
|
+
export declare const JsonObjectSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
14
|
+
export declare const defaultInputSchema: () => JsonObject;
|
|
15
|
+
export declare const ToolSpecSchema: z.ZodPipe<z.ZodObject<{
|
|
16
|
+
name: z.ZodString;
|
|
17
|
+
description: z.ZodDefault<z.ZodString>;
|
|
18
|
+
input_schema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
19
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
20
|
+
input_schema: JsonObject;
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
}, {
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
input_schema: Record<string, unknown>;
|
|
27
|
+
}>>;
|
|
28
|
+
export type ToolSpec = z.infer<typeof ToolSpecSchema>;
|
|
29
|
+
/** A tool call whose arguments parsed to an object: the only kind a tool, a policy or a confirmation sees. */
|
|
30
|
+
export declare const ParsedToolCallSchema: z.ZodObject<{
|
|
31
|
+
call_id: z.ZodString;
|
|
32
|
+
name: z.ZodString;
|
|
33
|
+
arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
34
|
+
}, z.core.$loose>;
|
|
35
|
+
export type ParsedToolCall = z.infer<typeof ParsedToolCallSchema>;
|
|
36
|
+
/**
|
|
37
|
+
* A tool call whose arguments are not a JSON object: `arguments` is `null`, and `malformed` keeps the
|
|
38
|
+
* text the model sent and why it failed. The loop answers it with an error result and never runs it;
|
|
39
|
+
* the provider is handed back the raw text it sent.
|
|
40
|
+
*/
|
|
41
|
+
export declare const MalformedToolCallSchema: z.ZodObject<{
|
|
42
|
+
call_id: z.ZodString;
|
|
43
|
+
name: z.ZodString;
|
|
44
|
+
arguments: z.ZodNull;
|
|
45
|
+
malformed: z.ZodObject<{
|
|
46
|
+
raw: z.ZodString;
|
|
47
|
+
error: z.ZodString;
|
|
48
|
+
}, z.core.$strict>;
|
|
49
|
+
}, z.core.$loose>;
|
|
50
|
+
export type MalformedToolCall = z.infer<typeof MalformedToolCallSchema>;
|
|
51
|
+
/** A tool call as the model emitted it. Extra keys are allowed so provider-specific fields survive checkpoints. */
|
|
52
|
+
export declare const ToolCallSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
53
|
+
call_id: z.ZodString;
|
|
54
|
+
name: z.ZodString;
|
|
55
|
+
arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
56
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
57
|
+
call_id: z.ZodString;
|
|
58
|
+
name: z.ZodString;
|
|
59
|
+
arguments: z.ZodNull;
|
|
60
|
+
malformed: z.ZodObject<{
|
|
61
|
+
raw: z.ZodString;
|
|
62
|
+
error: z.ZodString;
|
|
63
|
+
}, z.core.$strict>;
|
|
64
|
+
}, z.core.$loose>]>;
|
|
65
|
+
export type ToolCall = ParsedToolCall | MalformedToolCall;
|
|
66
|
+
/** Whether a call's arguments parsed. */
|
|
67
|
+
export declare const isParsedToolCall: (call: ToolCall) => call is ParsedToolCall;
|
|
68
|
+
/** A call's arguments as text, as the model sent them: the raw text of a malformed call, JSON otherwise. */
|
|
69
|
+
export declare const toolCallArgumentsText: (call: ToolCall) => string;
|
|
70
|
+
export declare const LLMUsageSchema: z.ZodObject<{
|
|
71
|
+
input_tokens: z.ZodDefault<z.ZodNumber>;
|
|
72
|
+
output_tokens: z.ZodDefault<z.ZodNumber>;
|
|
73
|
+
cache_read_input_tokens: z.ZodDefault<z.ZodNumber>;
|
|
74
|
+
cache_write_input_tokens: z.ZodDefault<z.ZodNumber>;
|
|
75
|
+
reasoning_output_tokens: z.ZodDefault<z.ZodNumber>;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
export type LLMUsage = z.infer<typeof LLMUsageSchema>;
|
|
78
|
+
export declare const usageTotalTokens: (usage: LLMUsage) => number;
|
|
79
|
+
/**
|
|
80
|
+
* A tool call the *provider* ran: a web search or code interpreter.
|
|
81
|
+
*
|
|
82
|
+
* Descriptive only. The engine never dispatches one and is never owed a result for it — it came
|
|
83
|
+
* back already answered, and it replays out of `provider_state`, not from here. This exists so a
|
|
84
|
+
* transcript can show what the model did instead of a gap between two blocks of text.
|
|
85
|
+
*/
|
|
86
|
+
export declare const ProviderCallSchema: z.ZodObject<{
|
|
87
|
+
id: z.ZodString;
|
|
88
|
+
type: z.ZodString;
|
|
89
|
+
name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
90
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
91
|
+
in_progress: "in_progress";
|
|
92
|
+
completed: "completed";
|
|
93
|
+
failed: "failed";
|
|
94
|
+
}>>;
|
|
95
|
+
summary: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
96
|
+
}, z.core.$loose>;
|
|
97
|
+
export type ProviderCall = z.infer<typeof ProviderCallSchema>;
|
|
98
|
+
export declare const LLMStreamChunkSchema: z.ZodObject<{
|
|
99
|
+
text_delta: z.ZodDefault<z.ZodString>;
|
|
100
|
+
reasoning_delta: z.ZodDefault<z.ZodString>;
|
|
101
|
+
provider_call: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
102
|
+
id: z.ZodString;
|
|
103
|
+
type: z.ZodString;
|
|
104
|
+
name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
105
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
106
|
+
in_progress: "in_progress";
|
|
107
|
+
completed: "completed";
|
|
108
|
+
failed: "failed";
|
|
109
|
+
}>>;
|
|
110
|
+
summary: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
111
|
+
}, z.core.$loose>>>;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
export type LLMStreamChunk = z.infer<typeof LLMStreamChunkSchema>;
|
|
114
|
+
/**
|
|
115
|
+
* What a provider needs back verbatim on the next request — encrypted reasoning, item ids, signed
|
|
116
|
+
* blocks. Tagged with the provider that wrote it, so another one ignores it rather than replaying
|
|
117
|
+
* a shape it does not understand.
|
|
118
|
+
*/
|
|
119
|
+
export declare const ProviderStateSchema: z.ZodObject<{
|
|
120
|
+
provider: z.ZodString;
|
|
121
|
+
data: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
122
|
+
}, z.core.$strip>;
|
|
123
|
+
export type ProviderState = z.infer<typeof ProviderStateSchema>;
|
|
124
|
+
export declare const MESSAGE_ROLES: readonly ["system", "developer", "user", "assistant", "tool"];
|
|
125
|
+
export type MessageRole = (typeof MESSAGE_ROLES)[number];
|
|
126
|
+
export declare const ConversationMessageSchema: z.ZodObject<{
|
|
127
|
+
role: z.ZodEnum<{
|
|
128
|
+
system: "system";
|
|
129
|
+
developer: "developer";
|
|
130
|
+
user: "user";
|
|
131
|
+
assistant: "assistant";
|
|
132
|
+
tool: "tool";
|
|
133
|
+
}>;
|
|
134
|
+
content: z.ZodPreprocess<z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
135
|
+
type: z.ZodLiteral<"text">;
|
|
136
|
+
text: z.ZodString;
|
|
137
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
138
|
+
type: z.ZodLiteral<"image">;
|
|
139
|
+
url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
140
|
+
data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
141
|
+
media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
142
|
+
detail: z.ZodDefault<z.ZodEnum<{
|
|
143
|
+
auto: "auto";
|
|
144
|
+
low: "low";
|
|
145
|
+
high: "high";
|
|
146
|
+
}>>;
|
|
147
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
148
|
+
type: z.ZodLiteral<"file">;
|
|
149
|
+
file_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
150
|
+
url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
151
|
+
data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
152
|
+
filename: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
153
|
+
media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
154
|
+
}, z.core.$strip>], "type">>>, unknown>;
|
|
155
|
+
reasoning_content: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
156
|
+
tool_calls: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
157
|
+
call_id: z.ZodString;
|
|
158
|
+
name: z.ZodString;
|
|
159
|
+
arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
160
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
161
|
+
call_id: z.ZodString;
|
|
162
|
+
name: z.ZodString;
|
|
163
|
+
arguments: z.ZodNull;
|
|
164
|
+
malformed: z.ZodObject<{
|
|
165
|
+
raw: z.ZodString;
|
|
166
|
+
error: z.ZodString;
|
|
167
|
+
}, z.core.$strict>;
|
|
168
|
+
}, z.core.$loose>]>>>;
|
|
169
|
+
provider_calls: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
170
|
+
id: z.ZodString;
|
|
171
|
+
type: z.ZodString;
|
|
172
|
+
name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
173
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
174
|
+
in_progress: "in_progress";
|
|
175
|
+
completed: "completed";
|
|
176
|
+
failed: "failed";
|
|
177
|
+
}>>;
|
|
178
|
+
summary: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
179
|
+
}, z.core.$loose>>>;
|
|
180
|
+
tool_call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
181
|
+
usage: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
182
|
+
input_tokens: z.ZodDefault<z.ZodNumber>;
|
|
183
|
+
output_tokens: z.ZodDefault<z.ZodNumber>;
|
|
184
|
+
cache_read_input_tokens: z.ZodDefault<z.ZodNumber>;
|
|
185
|
+
cache_write_input_tokens: z.ZodDefault<z.ZodNumber>;
|
|
186
|
+
reasoning_output_tokens: z.ZodDefault<z.ZodNumber>;
|
|
187
|
+
}, z.core.$strip>>>;
|
|
188
|
+
provider_state: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
189
|
+
provider: z.ZodString;
|
|
190
|
+
data: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
191
|
+
}, z.core.$strip>>>;
|
|
192
|
+
}, z.core.$strip>;
|
|
193
|
+
export type ConversationMessage = z.infer<typeof ConversationMessageSchema>;
|
|
194
|
+
export declare const conversationMessage: (fields: z.input<typeof ConversationMessageSchema>) => ConversationMessage;
|
|
195
|
+
/** The text of a message. The one way to read content, so widening it stays a change in one place. */
|
|
196
|
+
export declare const messageText: (message: DeepReadonly<ConversationMessage>) => string;
|
|
197
|
+
/**
|
|
198
|
+
* Why a response stopped, normalized so a consumer can tell a truncated response without reading
|
|
199
|
+
* any provider's own fields: `completed` when the model finished its message (tool calls included),
|
|
200
|
+
* `length` when it hit the output-token cap, `other` for anything else, a cut-off stream, a content
|
|
201
|
+
* filter or a reason the provider did not say. Each provider maps its own; the raw fields stay in
|
|
202
|
+
* `provider_metadata`.
|
|
203
|
+
*/
|
|
204
|
+
export declare const RESPONSE_FINISHES: readonly ["completed", "length", "other"];
|
|
205
|
+
export type ResponseFinish = (typeof RESPONSE_FINISHES)[number];
|
|
206
|
+
export declare const ResponseFinishSchema: z.ZodEnum<{
|
|
207
|
+
length: "length";
|
|
208
|
+
completed: "completed";
|
|
209
|
+
other: "other";
|
|
210
|
+
}>;
|
|
211
|
+
export declare const ModelResponseSchema: z.ZodObject<{
|
|
212
|
+
message: z.ZodObject<{
|
|
213
|
+
role: z.ZodEnum<{
|
|
214
|
+
system: "system";
|
|
215
|
+
developer: "developer";
|
|
216
|
+
user: "user";
|
|
217
|
+
assistant: "assistant";
|
|
218
|
+
tool: "tool";
|
|
219
|
+
}>;
|
|
220
|
+
content: z.ZodPreprocess<z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
221
|
+
type: z.ZodLiteral<"text">;
|
|
222
|
+
text: z.ZodString;
|
|
223
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
224
|
+
type: z.ZodLiteral<"image">;
|
|
225
|
+
url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
226
|
+
data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
227
|
+
media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
228
|
+
detail: z.ZodDefault<z.ZodEnum<{
|
|
229
|
+
auto: "auto";
|
|
230
|
+
low: "low";
|
|
231
|
+
high: "high";
|
|
232
|
+
}>>;
|
|
233
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
234
|
+
type: z.ZodLiteral<"file">;
|
|
235
|
+
file_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
236
|
+
url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
237
|
+
data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
238
|
+
filename: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
239
|
+
media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
240
|
+
}, z.core.$strip>], "type">>>, unknown>;
|
|
241
|
+
reasoning_content: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
242
|
+
tool_calls: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
243
|
+
call_id: z.ZodString;
|
|
244
|
+
name: z.ZodString;
|
|
245
|
+
arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
246
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
247
|
+
call_id: z.ZodString;
|
|
248
|
+
name: z.ZodString;
|
|
249
|
+
arguments: z.ZodNull;
|
|
250
|
+
malformed: z.ZodObject<{
|
|
251
|
+
raw: z.ZodString;
|
|
252
|
+
error: z.ZodString;
|
|
253
|
+
}, z.core.$strict>;
|
|
254
|
+
}, z.core.$loose>]>>>;
|
|
255
|
+
provider_calls: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
256
|
+
id: z.ZodString;
|
|
257
|
+
type: z.ZodString;
|
|
258
|
+
name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
259
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
260
|
+
in_progress: "in_progress";
|
|
261
|
+
completed: "completed";
|
|
262
|
+
failed: "failed";
|
|
263
|
+
}>>;
|
|
264
|
+
summary: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
265
|
+
}, z.core.$loose>>>;
|
|
266
|
+
tool_call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
267
|
+
usage: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
268
|
+
input_tokens: z.ZodDefault<z.ZodNumber>;
|
|
269
|
+
output_tokens: z.ZodDefault<z.ZodNumber>;
|
|
270
|
+
cache_read_input_tokens: z.ZodDefault<z.ZodNumber>;
|
|
271
|
+
cache_write_input_tokens: z.ZodDefault<z.ZodNumber>;
|
|
272
|
+
reasoning_output_tokens: z.ZodDefault<z.ZodNumber>;
|
|
273
|
+
}, z.core.$strip>>>;
|
|
274
|
+
provider_state: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
275
|
+
provider: z.ZodString;
|
|
276
|
+
data: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
277
|
+
}, z.core.$strip>>>;
|
|
278
|
+
}, z.core.$strip>;
|
|
279
|
+
finish: z.ZodEnum<{
|
|
280
|
+
length: "length";
|
|
281
|
+
completed: "completed";
|
|
282
|
+
other: "other";
|
|
283
|
+
}>;
|
|
284
|
+
provider_metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
285
|
+
}, z.core.$strip>;
|
|
286
|
+
export type ModelResponse = z.infer<typeof ModelResponseSchema>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* One block of a system prompt, in the order it is sent.
|
|
4
|
+
*
|
|
5
|
+
* The prompt reaches a provider as blocks rather than one string because where it goes is the
|
|
6
|
+
* provider's business — Responses has `instructions`, Chat Completions wants a leading message,
|
|
7
|
+
* Anthropic a top-level param — and because the boundary between the stable blocks and the
|
|
8
|
+
* volatile ones is where a provider with explicit cache control would cut.
|
|
9
|
+
*/
|
|
10
|
+
export declare const PromptBlockSchema: z.ZodObject<{
|
|
11
|
+
kind: z.ZodEnum<{
|
|
12
|
+
base: "base";
|
|
13
|
+
instruction: "instruction";
|
|
14
|
+
context: "context";
|
|
15
|
+
}>;
|
|
16
|
+
tag: z.ZodNullable<z.ZodString>;
|
|
17
|
+
text: z.ZodString;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type PromptBlock = z.infer<typeof PromptBlockSchema>;
|
|
20
|
+
/** Joins blocks for an API that takes one string. */
|
|
21
|
+
export declare const renderPromptBlocks: (blocks: readonly PromptBlock[]) => string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The provider contract: what a model provider gives the engine, and the route a turn runs on. Here,
|
|
3
|
+
* beside the client contract, so a provider is written against the model layer alone.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { LLMClient, ModelCapacity, ModelOption } from './client.js';
|
|
7
|
+
import type { FailureClassification } from './failure.js';
|
|
8
|
+
import { type ThinkingEffort } from './primitives.js';
|
|
9
|
+
/**
|
|
10
|
+
* The model a turn runs on, with every field resolved: what `run()` named, merged over the thread's
|
|
11
|
+
* last route, then the registry's defaults. A `thinking_effort` of `null` leaves the effort to the
|
|
12
|
+
* provider's own default.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ModelRouteSchema: z.ZodObject<{
|
|
15
|
+
provider: z.ZodString;
|
|
16
|
+
model: z.ZodString;
|
|
17
|
+
thinking_effort: z.ZodNullable<z.ZodEnum<{
|
|
18
|
+
low: "low";
|
|
19
|
+
high: "high";
|
|
20
|
+
none: "none";
|
|
21
|
+
medium: "medium";
|
|
22
|
+
max: "max";
|
|
23
|
+
}>>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export type ModelRoute = z.infer<typeof ModelRouteSchema>;
|
|
26
|
+
/**
|
|
27
|
+
* Route fields to fold over a route (`LlmService.resolveRoute`): absent fields keep the route's own;
|
|
28
|
+
* naming a different provider resets what is left unnamed to that provider's defaults. A `null`
|
|
29
|
+
* effort names the provider's own default, as a route records it, so a complete route resolves to
|
|
30
|
+
* itself.
|
|
31
|
+
*/
|
|
32
|
+
export type ModelSelection = {
|
|
33
|
+
readonly provider?: string;
|
|
34
|
+
readonly model?: string;
|
|
35
|
+
readonly thinkingEffort?: ThinkingEffort | null;
|
|
36
|
+
};
|
|
37
|
+
/** A model provider plugin registers one of these. */
|
|
38
|
+
export interface LLMProvider {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly defaultModel: string;
|
|
41
|
+
/**
|
|
42
|
+
* The effort a route gets when nothing names one, resolved into the route (`routeOn`); absent, the
|
|
43
|
+
* route's effort is `null`. Declare the effort the client is built with: a request that carries none
|
|
44
|
+
* is sent at the client's own default.
|
|
45
|
+
*/
|
|
46
|
+
readonly defaultThinkingEffort?: ThinkingEffort;
|
|
47
|
+
/** The models agents are told about. A declaration, not a restriction; absent tells only `defaultModel`. */
|
|
48
|
+
readonly models?: readonly ModelOption[];
|
|
49
|
+
/**
|
|
50
|
+
* What the provider can carry for `model`: its usable context window, `null` where the provider
|
|
51
|
+
* declares none, and whether a request may carry provider-executed tools. Answers for any model
|
|
52
|
+
* the provider can be asked for, told or not; `models` is what agents are told, not this lookup.
|
|
53
|
+
*/
|
|
54
|
+
capacity(model: string): ModelCapacity;
|
|
55
|
+
/**
|
|
56
|
+
* The provider's one client, built from its own configuration; the engine asks once and keeps it
|
|
57
|
+
* until the provider is withdrawn. Every request carries its route's effort when that is not `null`;
|
|
58
|
+
* one that carries none is sent at the client's configured effort, else the protocol's own.
|
|
59
|
+
*/
|
|
60
|
+
createClient(): LLMClient;
|
|
61
|
+
/**
|
|
62
|
+
* The kind of a failure its client threw that the engine's typed evidence does not already decide
|
|
63
|
+
* (a settlement failure, a `ContextOverflowError`): HTTP statuses, transport errors, a stream's
|
|
64
|
+
* error codes. `retryAfterMs` comes from structured fields only. Unknown is `other`.
|
|
65
|
+
*/
|
|
66
|
+
classify(error: unknown): FailureClassification;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The route a turn gets on `provider` when nothing names a model or an effort. Needs no registry,
|
|
70
|
+
* so a host can read a provider's defaults before deciding whether to register it.
|
|
71
|
+
*/
|
|
72
|
+
export declare const defaultRoute: (provider: LLMProvider) => ModelRoute;
|
|
73
|
+
/** A route on `provider`, taking its defaults for what is not named. */
|
|
74
|
+
export declare const routeOn: (provider: LLMProvider, model: string | undefined, effort: ThinkingEffort | undefined) => ModelRoute;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bookkeeping of when a response's read has ended, which `StreamingLLMResponse` states and every
|
|
3
|
+
* implementation of it (an adapter's stream, a call through `ctx.llm`, a test double) keeps: a read
|
|
4
|
+
* ends only when its generator has finished, or the read was closed, and no operation the reader
|
|
5
|
+
* asked for (`next`, `return`, `throw`) is still pending, so a closure queued behind a pending
|
|
6
|
+
* `next` keeps it under way however early the generator itself finished.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ReadLedger {
|
|
9
|
+
private pending;
|
|
10
|
+
private finished;
|
|
11
|
+
private over;
|
|
12
|
+
/** Whether the read has ended: finished, with nothing pending. */
|
|
13
|
+
get ended(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Runs one operation the reader asked for and counts it out only once the promise the reader
|
|
16
|
+
* holds has settled, never before: a read that is over while its own `return` still reads as
|
|
17
|
+
* pending would let settlement in too early. `closes` marks the generator finished with it, as a
|
|
18
|
+
* `return` or `throw` finishes one that never started.
|
|
19
|
+
*/
|
|
20
|
+
operation<T>(run: () => Promise<T>, closes?: boolean): Promise<T>;
|
|
21
|
+
/** The generator finished (ran through, failed or was closed), or an unread attempt was closed. */
|
|
22
|
+
finish(): void;
|
|
23
|
+
private check;
|
|
24
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { DeepReadonly } from '../util/json.js';
|
|
2
|
+
import type { ConversationMessage, JsonObject, ThinkingEffort, ToolSpec } from './primitives.js';
|
|
3
|
+
import type { PromptBlock } from './prompt.js';
|
|
4
|
+
/** How the model may use tools this call. `{ name }` forces one. */
|
|
5
|
+
export type ToolChoice = 'auto' | 'none' | 'required' | {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Why a request is sent: a model step of the thread's conversation, or an auxiliary call a plugin
|
|
10
|
+
* makes beside it, whose reply is never the thread's. Correlation, so middleware that counts,
|
|
11
|
+
* retries or logs per request can tell the two apart; never configuration.
|
|
12
|
+
*/
|
|
13
|
+
export type RequestPurpose = 'step' | 'auxiliary';
|
|
14
|
+
/** What the model's text must be. `json_schema` is the named, validated form. */
|
|
15
|
+
export type ResponseFormat = {
|
|
16
|
+
kind: 'text';
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'json_object';
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'json_schema';
|
|
21
|
+
name: string;
|
|
22
|
+
schema: JsonObject;
|
|
23
|
+
strict: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* One model call, as it will be sent.
|
|
27
|
+
*
|
|
28
|
+
* Middleware and providers use this same shape. The engine isolates the middleware draft from
|
|
29
|
+
* canonical history, then snapshots its final value, frozen, for journal recording and the provider.
|
|
30
|
+
* The data in it is shared and readonly all the way down: middleware replaces a field (the messages,
|
|
31
|
+
* the tools, the prompt blocks) rather than changing what is in it, and a provider reads it.
|
|
32
|
+
*/
|
|
33
|
+
export interface ModelRequest {
|
|
34
|
+
messages: readonly DeepReadonly<ConversationMessage>[];
|
|
35
|
+
model: string;
|
|
36
|
+
tools: readonly DeepReadonly<ToolSpec>[];
|
|
37
|
+
/**
|
|
38
|
+
* Provider-executed tool definitions, passed through verbatim (`{ type: 'web_search' }`, …).
|
|
39
|
+
* The engine never dispatches one; what it did comes back as
|
|
40
|
+
* `ConversationMessage.provider_calls`.
|
|
41
|
+
*/
|
|
42
|
+
providerTools: readonly DeepReadonly<JsonObject>[];
|
|
43
|
+
toolChoice: DeepReadonly<ToolChoice>;
|
|
44
|
+
parallelToolCalls: boolean;
|
|
45
|
+
responseFormat: DeepReadonly<ResponseFormat>;
|
|
46
|
+
/** Overrides the client's own default for this call; absent means the provider decides. */
|
|
47
|
+
thinkingEffort?: ThinkingEffort;
|
|
48
|
+
maxOutputTokens?: number;
|
|
49
|
+
/** The system prompt, carried beside the conversation rather than as its first message. */
|
|
50
|
+
systemPrompt: readonly DeepReadonly<PromptBlock>[];
|
|
51
|
+
readonly signal: AbortSignal;
|
|
52
|
+
/** Correlation, not configuration: a provider may key a prompt cache on these. */
|
|
53
|
+
readonly agentName: string;
|
|
54
|
+
readonly threadId: string;
|
|
55
|
+
readonly llmCallId: string;
|
|
56
|
+
/** Correlation like the ids above, so read-only to middleware and left out of the head digest. */
|
|
57
|
+
readonly purpose: RequestPurpose;
|
|
58
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* One agent: its name and the base of its prompt. Registered programmatically with
|
|
4
|
+
* `ctx.agents.register` (usually through `registerAgent`); the name is how threads
|
|
5
|
+
* and other agents refer to it.
|
|
6
|
+
*
|
|
7
|
+
* Strict: an agent says who it is, and nothing else. What it may call is granted to it by name
|
|
8
|
+
* (`grantTool`) by the plugins that compose the application; instruction and context sections come
|
|
9
|
+
* from plugins through `ctx.prompts`; how callers see it, a description and guidance, belongs to the
|
|
10
|
+
* `subAgents` endpoint that offers it. A plugin that needs per-agent configuration keys it by agent
|
|
11
|
+
* name in its own config, so a misspelled key is rejected here instead of silently ignored there.
|
|
12
|
+
*/
|
|
13
|
+
export declare const AgentDefinitionSchema: z.ZodObject<{
|
|
14
|
+
name: z.ZodString;
|
|
15
|
+
basePrompt: z.ZodDefault<z.ZodString>;
|
|
16
|
+
}, z.core.$strict>;
|
|
17
|
+
export type AgentDefinition = z.infer<typeof AgentDefinitionSchema>;
|
|
18
|
+
export type AgentDefinitionInput = z.input<typeof AgentDefinitionSchema>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AppendEntry, Journal } from '../journal/index.js';
|
|
2
|
+
import type { ExtensionRecord, Seq } from '../records/journal.js';
|
|
3
|
+
import type { LoopRuntime } from './runtime.js';
|
|
4
|
+
import type { ToolAuthorization, ToolAuthorizationRequest } from './hooks.js';
|
|
5
|
+
/**
|
|
6
|
+
* One owner for authorization ordering: flush policy writes, read approval, collect all policies,
|
|
7
|
+
* then commit only against the policy state they saw. Authorization and any approval request are
|
|
8
|
+
* one write guarded against cancellation. Both model and runtime dispatch use it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function authorizeOperation(options: {
|
|
11
|
+
runtime: LoopRuntime;
|
|
12
|
+
request: ToolAuthorizationRequest;
|
|
13
|
+
signal: AbortSignal;
|
|
14
|
+
approval(): {
|
|
15
|
+
approved: boolean;
|
|
16
|
+
rejection_message: string | null;
|
|
17
|
+
} | undefined;
|
|
18
|
+
validate?(): void;
|
|
19
|
+
record(authorization: ToolAuthorization): readonly [AppendEntry<'tool/authorization' | 'execution/authorization'>, ...AppendEntry<'confirm/requested'>[]];
|
|
20
|
+
}): Promise<{
|
|
21
|
+
kind: 'decided';
|
|
22
|
+
authorization: ToolAuthorization;
|
|
23
|
+
attemptSeq: Seq;
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'rejected';
|
|
26
|
+
reason: string | null;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'unstarted';
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Declares the `ext` rows of one plugin event state a `lagent/tool/authorize` listener decides
|
|
32
|
+
* from: one that lands while a call is authorized sends the decision round again, which no other
|
|
33
|
+
* `ext` row does. `defineExtensionEvent({ policyState: true })` is the way in.
|
|
34
|
+
*/
|
|
35
|
+
export declare function declarePolicyState(record: Pick<ExtensionRecord, 'plugin' | 'instance_id' | 'kind'>): void;
|
|
36
|
+
/**
|
|
37
|
+
* Whether policy state — declared `ext` rows or answers (`confirm/resolved`) — landed after `from`
|
|
38
|
+
* on `threadId` or a thread that called it: what a running thread's policies read. A thread of that
|
|
39
|
+
* chain that is not loaded counts as changed if anything landed on it.
|
|
40
|
+
*/
|
|
41
|
+
export declare function policyChangedSince(journal: Journal, threadId: string, from: Seq): boolean;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ContentPartInput } from '../llm/content.js';
|
|
2
|
+
import type { ConversationMessage, LLMUsage, ResponseFinish } from '../llm/primitives.js';
|
|
3
|
+
import type { ToolChoice } from '../llm/request.js';
|
|
4
|
+
import type { ModelRoute } from '../llm/provider.js';
|
|
5
|
+
import type { Seq } from '../records/journal.js';
|
|
6
|
+
import type { LoopRuntime } from './runtime.js';
|
|
7
|
+
import type { ModelSelection } from '../llm/provider.js';
|
|
8
|
+
/**
|
|
9
|
+
* One auxiliary model call as a strategy asks for it. The engine builds the request: the head a step
|
|
10
|
+
* would send now (the recorded prompt and the tools the agent is granted), then the current surface
|
|
11
|
+
* up to and including the message behind `through`, then `instructions`, each a `user` message sent
|
|
12
|
+
* verbatim. So the request sends only what the journal holds and what its own row records.
|
|
13
|
+
*/
|
|
14
|
+
export type AuxiliaryCall = {
|
|
15
|
+
/** The row behind the last surface message sent. The prefix must end on a balanced cut. */
|
|
16
|
+
readonly through: Seq;
|
|
17
|
+
/** The messages after the prefix, at least one, each sent in role `user` exactly as given. */
|
|
18
|
+
readonly instructions: readonly (string | readonly ContentPartInput[])[];
|
|
19
|
+
/** Route fields folded over the dispatch's route (`LlmService.resolveRoute`). */
|
|
20
|
+
readonly route?: ModelSelection;
|
|
21
|
+
/** Fixed on the draft, so request middleware cannot change it. `auto` when absent. */
|
|
22
|
+
readonly toolChoice?: ToolChoice;
|
|
23
|
+
/** Fixed on the draft, so request middleware cannot change it; absent leaves it to the provider. */
|
|
24
|
+
readonly maxOutputTokens?: number;
|
|
25
|
+
};
|
|
26
|
+
/** What an auxiliary call returned, as its `auxiliary/result` row records it, with the message itself. */
|
|
27
|
+
export type AuxiliaryReply = {
|
|
28
|
+
/** The `auxiliary/request` row; what a replacement made from this reply cites. */
|
|
29
|
+
readonly requestSeq: Seq;
|
|
30
|
+
readonly resultSeq: Seq;
|
|
31
|
+
/** The reply, tool calls and provider calls included, for a caller that must refuse them. */
|
|
32
|
+
readonly message: ConversationMessage;
|
|
33
|
+
/** Its text parts. */
|
|
34
|
+
readonly text: string;
|
|
35
|
+
readonly finish: ResponseFinish;
|
|
36
|
+
readonly usage: LLMUsage | null;
|
|
37
|
+
};
|
|
38
|
+
/** Where an auxiliary call is made, and what it may be sent on. */
|
|
39
|
+
export type AuxiliaryContext = {
|
|
40
|
+
readonly threadId: string;
|
|
41
|
+
readonly agentName: string;
|
|
42
|
+
readonly turn: number | null;
|
|
43
|
+
readonly step: number | null;
|
|
44
|
+
/** The dispatch's route. */
|
|
45
|
+
readonly route: ModelRoute;
|
|
46
|
+
readonly signal: AbortSignal;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Makes one auxiliary call: through `lagent/llm/request` middleware and the guidance terminal exactly
|
|
50
|
+
* as a step's request, with `purpose: 'auxiliary'`, its route, tool choice and output cap fixed on
|
|
51
|
+
* the draft, and no chunk published, since the thread's chunk channel carries its reply.
|
|
52
|
+
*
|
|
53
|
+
* Recorded in two rows: `auxiliary/request` in the terminal, before the request is sent, and
|
|
54
|
+
* `auxiliary/result` when the call ends, with its text and finish or its error, cancellation
|
|
55
|
+
* included. A call refused for how it was asked, or that fails before its request row, records
|
|
56
|
+
* nothing; a failure after it is recorded and then thrown as itself.
|
|
57
|
+
*/
|
|
58
|
+
export declare function callAuxiliary(runtime: LoopRuntime, context: AuxiliaryContext, call: AuxiliaryCall): Promise<AuxiliaryReply>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LLMStreamChunk } from '../llm/primitives.js';
|
|
2
|
+
/** One delta off a model stream, with enough context for a frontend to place it. */
|
|
3
|
+
export type StreamedChunk = {
|
|
4
|
+
readonly threadId: string;
|
|
5
|
+
readonly llmCallId: string;
|
|
6
|
+
readonly turn: number;
|
|
7
|
+
readonly step: number;
|
|
8
|
+
readonly chunk: LLMStreamChunk;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The model's output as it arrives, published to whoever is watching and then forgotten.
|
|
12
|
+
*
|
|
13
|
+
* Deliberately not part of the journal. Nothing folds a chunk — the assistant message carries the same
|
|
14
|
+
* text once the stream ends — so keeping them in the journal only made history depend on a persistence
|
|
15
|
+
* setting: with chunks dropped on write, a live session and a reopened one read back different
|
|
16
|
+
* events. The journal is what happened; this is what it looked like happening.
|
|
17
|
+
*
|
|
18
|
+
* A frontend that wants to replay streaming can subscribe here and keep its own record.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ChunkChannel {
|
|
21
|
+
private readonly listeners;
|
|
22
|
+
private readonly report;
|
|
23
|
+
constructor(report: (error: unknown) => void);
|
|
24
|
+
/** One frozen copy of the chunk for every listener, so no listener can change what the next one sees. */
|
|
25
|
+
emit(chunk: StreamedChunk): void;
|
|
26
|
+
subscribe(listener: (chunk: StreamedChunk) => void): () => void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ModelRoute } from '../llm/provider.js';
|
|
2
|
+
import type { Seq, ThreadEnvironment } from '../records/journal.js';
|
|
3
|
+
import type { CompletionRequest } from './hooks.js';
|
|
4
|
+
import type { LoopRuntime } from './runtime.js';
|
|
5
|
+
/** Dispatches a pure completion plan once, under its candidate's durable identity and current policy. */
|
|
6
|
+
export declare function prepareCompletion(options: {
|
|
7
|
+
runtime: LoopRuntime;
|
|
8
|
+
threadId: string;
|
|
9
|
+
agentName: string;
|
|
10
|
+
environment: ThreadEnvironment;
|
|
11
|
+
route: ModelRoute;
|
|
12
|
+
turn: number;
|
|
13
|
+
candidateSeq: Seq;
|
|
14
|
+
request: CompletionRequest;
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
validate(): void;
|
|
17
|
+
}): Promise<'settled' | 'blocked'>;
|