@leuduan/lagent 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +144 -2
- package/dist/chunks/2O7ZGEIT.js +1 -0
- package/dist/chunks/2OSESBIL.js +1 -0
- package/dist/chunks/34KW6VNQ.js +1 -0
- package/dist/chunks/37YOGDGY.js +1 -0
- package/dist/chunks/3LQHQRIU.js +6 -0
- package/dist/chunks/3QCW4WDJ.js +1 -0
- package/dist/chunks/4XVRUSCQ.js +1 -0
- package/dist/chunks/6ECI2GGV.js +1 -0
- package/dist/chunks/74HKUGRR.js +1 -0
- package/dist/chunks/ADHERZLW.js +2 -0
- package/dist/chunks/AP6Q4EPT.js +36 -0
- package/dist/chunks/BM3S37EZ.js +1 -0
- package/dist/chunks/C5LYCXJG.js +1 -0
- package/dist/chunks/CDQG7RKA.js +1 -0
- package/dist/chunks/D7E6EWIE.js +3 -0
- package/dist/chunks/DDANMY45.js +3 -0
- package/dist/chunks/DRYAN665.js +1 -0
- package/dist/chunks/DXFXAYDN.js +17 -0
- package/dist/chunks/EGZI4XQX.js +24 -0
- package/dist/chunks/ENWFSU27.js +41 -0
- package/dist/chunks/G6RXC3AL.js +1 -0
- package/dist/chunks/G74AGRAJ.js +15 -0
- package/dist/chunks/GQGNVSKB.js +1 -0
- package/dist/chunks/IJ2WNMD5.js +7 -0
- package/dist/chunks/J5S4URAW.js +1 -0
- package/dist/chunks/JPZFKSWT.js +1 -0
- package/dist/chunks/KESCTXGO.js +5 -0
- package/dist/chunks/L3N4FIEN.js +1 -0
- package/dist/chunks/NAOUTU7A.js +4 -0
- package/dist/chunks/NDIM7MEW.js +1 -0
- package/dist/chunks/O4PPOM5Z.js +2 -0
- package/dist/chunks/OVZFGILJ.js +1 -0
- package/dist/chunks/P5ZHHOOM.js +6 -0
- package/dist/chunks/PUSUPTAT.js +1 -0
- package/dist/chunks/QMMLQJBS.js +1 -0
- package/dist/chunks/RK3VP2Q4.js +3 -0
- package/dist/chunks/SGGMBSBA.js +1 -0
- package/dist/chunks/SL2YLB2F.js +1 -0
- package/dist/chunks/TOOIB6J2.js +1 -0
- package/dist/chunks/TYTQRLTX.js +1 -0
- package/dist/chunks/UC3FVVJ2.js +5 -0
- package/dist/chunks/UCTEU62F.js +1 -0
- package/dist/chunks/UD3VJER6.js +1 -0
- package/dist/chunks/UKXMCHHT.js +1 -0
- package/dist/chunks/WUUKTSRT.js +7 -0
- package/dist/chunks/X65X4KP5.js +7 -0
- package/dist/chunks/YIR5MYGU.js +1 -0
- package/dist/chunks/YLNJXQ3Z.js +1 -0
- package/dist/context.d.ts +101 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +77 -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/kit/claim.d.ts +13 -0
- package/dist/kit/drain.d.ts +10 -0
- package/dist/kit/extension.d.ts +180 -0
- package/dist/kit/grants.d.ts +9 -0
- package/dist/kit/modes.d.ts +65 -0
- package/dist/kit/retries.d.ts +25 -0
- package/dist/kit/scope.d.ts +32 -0
- package/dist/kit/service.d.ts +7 -0
- package/dist/kit/strategy.d.ts +10 -0
- package/dist/kit/timers.d.ts +43 -0
- package/dist/kit/tool.d.ts +72 -0
- package/dist/llm/client.d.ts +135 -0
- package/dist/llm/content.d.ts +52 -0
- package/dist/llm/door.d.ts +21 -0
- package/dist/llm/door.js +1 -0
- package/dist/llm/failure.d.ts +82 -0
- package/dist/llm/index.d.ts +16 -0
- package/dist/llm/primitives.d.ts +286 -0
- package/dist/llm/prompt.d.ts +21 -0
- package/dist/llm/provider.d.ts +63 -0
- package/dist/llm/readLedger.d.ts +24 -0
- package/dist/llm/request.d.ts +58 -0
- package/dist/loop/agent.d.ts +134 -0
- package/dist/loop/auxiliary.d.ts +54 -0
- package/dist/loop/chain.d.ts +46 -0
- package/dist/loop/chunks.d.ts +27 -0
- package/dist/loop/continuation.d.ts +166 -0
- package/dist/loop/decide.d.ts +64 -0
- package/dist/loop/errors.d.ts +162 -0
- package/dist/loop/forks.d.ts +61 -0
- package/dist/loop/holds.d.ts +104 -0
- package/dist/loop/hooks.d.ts +241 -0
- package/dist/loop/inbox.d.ts +188 -0
- package/dist/loop/index.d.ts +37 -0
- package/dist/loop/limits.d.ts +14 -0
- package/dist/loop/opening.d.ts +42 -0
- package/dist/loop/prepare.d.ts +30 -0
- package/dist/loop/projections.d.ts +307 -0
- package/dist/loop/replace.d.ts +33 -0
- package/dist/loop/requests.d.ts +129 -0
- package/dist/loop/route.d.ts +53 -0
- package/dist/loop/runtime.d.ts +85 -0
- package/dist/loop/state.d.ts +70 -0
- package/dist/loop/strategy.d.ts +71 -0
- package/dist/loop/summary.d.ts +3 -0
- package/dist/loop/surface.d.ts +153 -0
- package/dist/loop/threadState.d.ts +72 -0
- package/dist/loop/tool.d.ts +101 -0
- package/dist/loop/toolCalls.d.ts +42 -0
- package/dist/loop/wake.d.ts +32 -0
- package/dist/models/config/agent.d.ts +18 -0
- package/dist/models/config/prompt.d.ts +18 -0
- package/dist/models/door.d.ts +12 -0
- package/dist/models/door.js +1 -0
- package/dist/models/index.d.ts +7 -0
- package/dist/models/jsonSchema.d.ts +7 -0
- package/dist/models/wire/journal.d.ts +2772 -0
- package/dist/models/wire/primitives.d.ts +65 -0
- package/dist/plugin.d.ts +53 -0
- package/dist/plugin.js +1 -0
- package/dist/plugins/agentsMd.d.ts +76 -0
- package/dist/plugins/agentsMd.js +1 -0
- package/dist/plugins/ask/askQuestion.d.ts +9 -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/commands/background.d.ts +8 -0
- package/dist/plugins/commands/foreground.d.ts +4 -0
- package/dist/plugins/commands/index.d.ts +40 -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 +549 -0
- package/dist/plugins/commands/service.d.ts +314 -0
- package/dist/plugins/commands/shell.d.ts +25 -0
- package/dist/plugins/compaction/checkpoint.d.ts +91 -0
- package/dist/plugins/compaction/config.d.ts +133 -0
- package/dist/plugins/compaction/estimate.d.ts +29 -0
- package/dist/plugins/compaction/index.d.ts +2 -0
- package/dist/plugins/compaction/index.js +7 -0
- package/dist/plugins/compaction/log.d.ts +61 -0
- package/dist/plugins/compaction/planner.d.ts +207 -0
- package/dist/plugins/compaction/preset.d.ts +86 -0
- package/dist/plugins/compaction/prune.d.ts +9 -0
- package/dist/plugins/compaction/records.d.ts +227 -0
- package/dist/plugins/compaction/segments.d.ts +23 -0
- package/dist/plugins/compaction/shared.d.ts +14 -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 +632 -0
- package/dist/plugins/delegations/request.d.ts +381 -0
- package/dist/plugins/delegations/role.d.ts +30 -0
- package/dist/plugins/delegations/service.d.ts +562 -0
- package/dist/plugins/delegations/standing.d.ts +19 -0
- package/dist/plugins/delegations/stopCheck.d.ts +21 -0
- package/dist/plugins/delegations/testing.d.ts +16 -0
- package/dist/plugins/delegations/tools.d.ts +71 -0
- package/dist/plugins/delegations/waitBook.d.ts +116 -0
- package/dist/plugins/delegations/waits.d.ts +118 -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/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/tool.d.ts +41 -0
- package/dist/plugins/providers/anthropic.d.ts +175 -0
- package/dist/plugins/providers/anthropicMessages.d.ts +65 -0
- package/dist/plugins/providers/codex.d.ts +60 -0
- package/dist/plugins/providers/codexAuth.d.ts +116 -0
- package/dist/plugins/providers/deepseek.d.ts +55 -0
- package/dist/plugins/providers/door.d.ts +61 -0
- package/dist/plugins/providers/door.js +1 -0
- package/dist/plugins/providers/failure.d.ts +23 -0
- package/dist/plugins/providers/gateway.d.ts +23 -0
- package/dist/plugins/providers/index.d.ts +6 -0
- package/dist/plugins/providers/openaiChat.d.ts +62 -0
- package/dist/plugins/providers/openaiResponses.d.ts +100 -0
- package/dist/plugins/providers/opencodeCopilot.d.ts +23 -0
- package/dist/plugins/providers/opencodeGo.d.ts +98 -0
- package/dist/plugins/providers/shared.d.ts +104 -0
- package/dist/plugins/providers/stream.d.ts +154 -0
- package/dist/plugins/routeContext.d.ts +22 -0
- package/dist/plugins/routeContext.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 +54 -0
- package/dist/plugins/skills/index.d.ts +31 -0
- package/dist/plugins/skills/index.js +1 -0
- package/dist/plugins/skills/tool.d.ts +11 -0
- package/dist/plugins/store/durableObject.d.ts +23 -0
- package/dist/plugins/store/durableObject.js +1 -0
- package/dist/plugins/store/durableObjectConnection.d.ts +27 -0
- package/dist/plugins/store/memory.d.ts +29 -0
- package/dist/plugins/store/sql.d.ts +59 -0
- package/dist/plugins/store/sqlite.d.ts +31 -0
- package/dist/plugins/store/sqlite.js +1 -0
- package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
- package/dist/plugins/subAgents/fork.d.ts +32 -0
- package/dist/plugins/subAgents/index.d.ts +67 -0
- package/dist/plugins/subAgents/index.js +1 -0
- package/dist/plugins/subAgents/tool.d.ts +38 -0
- package/dist/plugins/toolPolicy/index.d.ts +61 -0
- package/dist/plugins/toolPolicy/index.js +1 -0
- package/dist/plugins/tools/editFiles.d.ts +128 -0
- package/dist/plugins/tools/fsRead.d.ts +17 -0
- package/dist/plugins/tools/html.d.ts +23 -0
- package/dist/plugins/tools/index.d.ts +59 -0
- package/dist/plugins/tools/index.js +1 -0
- package/dist/plugins/tools/network.d.ts +23 -0
- package/dist/plugins/tools/ripgrep.d.ts +20 -0
- package/dist/plugins/tools/textEdit.d.ts +67 -0
- package/dist/plugins/tools/web.d.ts +32 -0
- package/dist/plugins/truncateToolOutput.d.ts +26 -0
- package/dist/plugins/truncateToolOutput.js +1 -0
- package/dist/plugins/usage/index.d.ts +24 -0
- package/dist/plugins/usage/index.js +1 -0
- package/dist/plugins/usage/tracker.d.ts +34 -0
- package/dist/plugins/verify/facts.d.ts +356 -0
- package/dist/plugins/verify/index.d.ts +75 -0
- package/dist/plugins/verify/index.js +1 -0
- package/dist/plugins/verify/service.d.ts +90 -0
- package/dist/plugins/workflows/assignment.d.ts +16 -0
- package/dist/plugins/workflows/bindings.d.ts +95 -0
- package/dist/plugins/workflows/cleanup.d.ts +38 -0
- package/dist/plugins/workflows/definition.d.ts +184 -0
- package/dist/plugins/workflows/fold.d.ts +373 -0
- package/dist/plugins/workflows/index.d.ts +28 -0
- package/dist/plugins/workflows/index.js +6 -0
- package/dist/plugins/workflows/observations.d.ts +81 -0
- package/dist/plugins/workflows/participants.d.ts +143 -0
- package/dist/plugins/workflows/policy.d.ts +112 -0
- package/dist/plugins/workflows/providers.d.ts +146 -0
- package/dist/plugins/workflows/record.d.ts +2863 -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/submit.d.ts +8 -0
- package/dist/plugins/workflows/view.d.ts +103 -0
- package/dist/plugins/workflows/work.d.ts +21 -0
- package/dist/plugins/workspaceContext.d.ts +38 -0
- package/dist/plugins/workspaceContext.js +1 -0
- package/dist/presets/agents.d.ts +7 -0
- package/dist/presets/base.d.ts +10 -0
- package/dist/presets/codex.d.ts +60 -0
- package/dist/presets/index.d.ts +4 -0
- package/dist/presets/prompts.d.ts +56 -0
- package/dist/sandbox/absent.d.ts +32 -0
- package/dist/sandbox/client.d.ts +39 -0
- package/dist/sandbox/files.d.ts +28 -0
- package/dist/sandbox/index.d.ts +49 -0
- package/dist/sandbox/index.js +4 -0
- package/dist/sandbox/mode.d.ts +57 -0
- package/dist/sandbox/policy.d.ts +86 -0
- package/dist/sandbox/protocol.d.ts +107 -0
- package/dist/sandbox/service.d.ts +143 -0
- package/dist/sandbox/worker.d.ts +12 -0
- package/dist/sandbox/worker.js +1 -0
- package/dist/services/admission.d.ts +174 -0
- package/dist/services/agents.d.ts +37 -0
- package/dist/services/birth.d.ts +220 -0
- package/dist/services/contributions.d.ts +73 -0
- package/dist/services/core.d.ts +34 -0
- package/dist/services/journal.d.ts +26 -0
- package/dist/services/launches.d.ts +104 -0
- package/dist/services/llm.d.ts +80 -0
- package/dist/services/owner.d.ts +367 -0
- package/dist/services/preset.d.ts +154 -0
- package/dist/services/presets.d.ts +139 -0
- package/dist/services/prompts.d.ts +67 -0
- package/dist/services/runEvents.d.ts +79 -0
- package/dist/services/thread.d.ts +267 -0
- package/dist/services/threadActivation.d.ts +100 -0
- package/dist/services/threadDirs.d.ts +38 -0
- package/dist/services/threadView.d.ts +92 -0
- package/dist/services/threads.d.ts +449 -0
- package/dist/services/tools.d.ts +41 -0
- package/dist/sys/environment.d.ts +47 -0
- package/dist/sys/git.d.ts +60 -0
- package/dist/sys/paths.d.ts +56 -0
- package/dist/sys/spawn.d.ts +176 -0
- package/dist/testing/clock.d.ts +17 -0
- package/dist/testing/fakeLlm.d.ts +74 -0
- package/dist/testing/fedLlm.d.ts +32 -0
- package/dist/testing/helpers.d.ts +344 -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/sandbox.d.ts +71 -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/log.d.ts +6 -0
- package/dist/util/text.d.ts +21 -0
- package/dist/util/version.d.ts +2 -0
- package/package.json +175 -3
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import type { AgentDefinition, ExtensionRecord, JournalEvent, JournalEventInput, QueuedInput, Seq, StepContribution, StepContributionInput, TurnRejection } from '../models/index.js';
|
|
2
|
+
import type { ModelCallClient, ModelRequest, ModelRoute, ParsedToolCall, RequestPurpose, ResponseFinish, StreamingLLMResponse, ThinkingEffort } from '../llm/index.js';
|
|
3
|
+
import type { LoopRuntime } from './runtime.js';
|
|
4
|
+
import type { RowRef } from './surface.js';
|
|
5
|
+
import type { InvocationContext, Tool, ToolOutcome } from './tool.js';
|
|
6
|
+
/**
|
|
7
|
+
* Every point at which the loop hands control to a plugin.
|
|
8
|
+
*
|
|
9
|
+
* Dispatches are named here so there is one place to read what a plugin can intercept — and the
|
|
10
|
+
* only place in the loop that reaches for `runtime.ctx`. They are thin on purpose: the cordis event
|
|
11
|
+
* *is* the seam, and wrapping it in an interface the engine implements would put a third hop between
|
|
12
|
+
* the loop and the listener without making either easier to read.
|
|
13
|
+
*/
|
|
14
|
+
/** A tool call about to run; `lagent/tool/execute` listeners may wrap, replace or short-circuit it. */
|
|
15
|
+
export interface ToolInvocation {
|
|
16
|
+
readonly tool: Tool;
|
|
17
|
+
readonly call: ParsedToolCall;
|
|
18
|
+
readonly context: InvocationContext;
|
|
19
|
+
readonly toolName: string;
|
|
20
|
+
readonly threadId: string;
|
|
21
|
+
}
|
|
22
|
+
/** A tool call, before it is dispatched or held for confirmation. */
|
|
23
|
+
export interface ToolAuthorizationRequest {
|
|
24
|
+
readonly toolCall: ParsedToolCall;
|
|
25
|
+
readonly agent: AgentDefinition;
|
|
26
|
+
readonly threadId: string;
|
|
27
|
+
}
|
|
28
|
+
/** A denial that tells the model why, so it can change course rather than retry the call. */
|
|
29
|
+
export interface ToolDenial {
|
|
30
|
+
readonly decision: 'deny';
|
|
31
|
+
readonly reason: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* One policy's say on a call. `deny` refuses it, `confirm` requires confirmation before it runs,
|
|
35
|
+
* and `approve` satisfies such a requirement — a policy vouching for the call, as the user would.
|
|
36
|
+
* A {@link ToolDenial} refuses it with a reason. No answer has no opinion.
|
|
37
|
+
*/
|
|
38
|
+
export type ToolPolicyDecision = 'deny' | 'confirm' | 'approve' | ToolDenial;
|
|
39
|
+
/**
|
|
40
|
+
* What authorization concluded: the reasons every denying policy gave, and who satisfied a
|
|
41
|
+
* confirmation requirement when one was met.
|
|
42
|
+
*/
|
|
43
|
+
export type ToolAuthorization = {
|
|
44
|
+
decision: 'deny';
|
|
45
|
+
confirmedBy: null;
|
|
46
|
+
reasons: string[];
|
|
47
|
+
} | {
|
|
48
|
+
decision: 'confirm';
|
|
49
|
+
confirmedBy: null;
|
|
50
|
+
} | {
|
|
51
|
+
decision: 'allow';
|
|
52
|
+
confirmedBy: 'policy' | 'user' | null;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Every policy contributes, and the outcome is independent of registration order: denial wins over
|
|
56
|
+
* everything; a confirmation requirement holds the call unless the user approved it or a policy
|
|
57
|
+
* approves it. Approval can therefore satisfy a confirmation, never override a denial.
|
|
58
|
+
*/
|
|
59
|
+
export declare function authorizeToolCall(runtime: LoopRuntime, request: ToolAuthorizationRequest, options: {
|
|
60
|
+
userApproved: boolean;
|
|
61
|
+
}): Promise<ToolAuthorization>;
|
|
62
|
+
/** A model step about to record its input. `lagent/llm/step` listeners may contribute to it. */
|
|
63
|
+
export interface ModelStep {
|
|
64
|
+
readonly threadId: string;
|
|
65
|
+
readonly turn: number;
|
|
66
|
+
readonly step: number;
|
|
67
|
+
/** The route the turn recorded on `turn/start`, which every request it sends through lagent uses. */
|
|
68
|
+
readonly route: ModelRoute;
|
|
69
|
+
/** The inbox input this step will record after the contributions. */
|
|
70
|
+
readonly claimed: readonly QueuedInput[];
|
|
71
|
+
/**
|
|
72
|
+
* Adds a message ahead of the claimed input. Valid only while the listener runs. Lower `rank`s
|
|
73
|
+
* are recorded first and equal ones keep listener order; it is any finite number, and omitted it
|
|
74
|
+
* is 0, so an environment fact needs none and a notice that must sit before or after it says so
|
|
75
|
+
* (`1`, `-1`, `0.5`). A rank is presentation order only. A contribution identical to one the step
|
|
76
|
+
* already carries, source and message alike, is recorded once, so a plugin mounted in two layers
|
|
77
|
+
* that reach one thread tells it once; the same contribution at two different ranks throws.
|
|
78
|
+
*/
|
|
79
|
+
contribute(message: StepContributionInput, rank?: number): void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* What plugins add to a model step, validated, by ascending rank and then listener order, each
|
|
83
|
+
* identical one once.
|
|
84
|
+
*
|
|
85
|
+
* Synchronous on purpose: the loop records the result with no await in between, so a contribution
|
|
86
|
+
* always matches the plugin state it was read from. A throwing listener, or an invalid
|
|
87
|
+
* contribution, fails the step before any of its input is recorded.
|
|
88
|
+
*/
|
|
89
|
+
export declare function collectStepContributions(runtime: LoopRuntime, step: Omit<ModelStep, 'contribute'>): StepContribution[];
|
|
90
|
+
/**
|
|
91
|
+
* How one request to prepare the surface settled: the replacement rows it committed, and how it
|
|
92
|
+
* ended. `completed` when the strategy's plan replaced something, with its reason; `skipped` when
|
|
93
|
+
* it planned nothing, or no strategy prepares the thread; `failed` when it planned a failure or
|
|
94
|
+
* threw, the error's text as the reason; `cancelled` when the request's signal aborted.
|
|
95
|
+
*/
|
|
96
|
+
export type SurfacePrepareOutcome = {
|
|
97
|
+
readonly committed: RowRef[];
|
|
98
|
+
readonly ended: 'completed' | 'skipped' | 'failed' | 'cancelled';
|
|
99
|
+
readonly reason?: string;
|
|
100
|
+
};
|
|
101
|
+
/** A provisional answer, awaiting the stop checks' judgement. */
|
|
102
|
+
export interface TurnStop {
|
|
103
|
+
readonly threadId: string;
|
|
104
|
+
readonly turn: number;
|
|
105
|
+
/**
|
|
106
|
+
* A frozen copy, so a listener cannot alter what it judges. `seq` is its row: the reply's
|
|
107
|
+
* `assistant/message`, or the concluding `tool/result`. `text` is the reply's text parts, or the
|
|
108
|
+
* concluding result's output. A reply also says why the model stopped: `length` is a reply cut at
|
|
109
|
+
* the output cap, which a check may send back to be continued.
|
|
110
|
+
*/
|
|
111
|
+
readonly answer: {
|
|
112
|
+
readonly seq: Seq;
|
|
113
|
+
readonly kind: 'reply';
|
|
114
|
+
readonly text: string;
|
|
115
|
+
readonly finish: ResponseFinish;
|
|
116
|
+
} | {
|
|
117
|
+
readonly seq: Seq;
|
|
118
|
+
readonly kind: 'concluded';
|
|
119
|
+
readonly text: string;
|
|
120
|
+
};
|
|
121
|
+
/** Steps this turn may still take; a continuation with none left ends the turn `max-steps`. */
|
|
122
|
+
readonly stepsLeft: number;
|
|
123
|
+
/** The turn's signal; a slow check should honour it. */
|
|
124
|
+
readonly signal: AbortSignal;
|
|
125
|
+
/**
|
|
126
|
+
* Declares a fact the check's verdict, an abstention included, rests on. `read` returns a token
|
|
127
|
+
* for it that differs whenever the fact does: synchronous, read-only and cheap, since core calls
|
|
128
|
+
* it again inside the write that records the judgment, and an answer whose declared facts read
|
|
129
|
+
* differently then is not judged, whatever the other checks said: the turn ends interrupted and a
|
|
130
|
+
* later run judges it again. Call it in the same synchronous step that reads the fact, before the
|
|
131
|
+
* check awaits anything, and before its promise settles at the latest; a call after the judgment
|
|
132
|
+
* ended throws. A read that throws counts as a change. Only declared facts are covered: what a
|
|
133
|
+
* check reads from the filesystem or the network stays its own to judge.
|
|
134
|
+
*/
|
|
135
|
+
observe(read: () => string): void;
|
|
136
|
+
}
|
|
137
|
+
/** A fact a stop check declared, with the token it read when it declared it. */
|
|
138
|
+
export type StopObservation = {
|
|
139
|
+
readonly read: () => string;
|
|
140
|
+
readonly value: string | null;
|
|
141
|
+
};
|
|
142
|
+
/** One check's say on an answer. No answer accepts it. */
|
|
143
|
+
export type StopVerdict = {
|
|
144
|
+
decision: 'continue';
|
|
145
|
+
message: StepContributionInput;
|
|
146
|
+
} | {
|
|
147
|
+
decision: 'reject';
|
|
148
|
+
reason: string;
|
|
149
|
+
source: ExtensionRecord;
|
|
150
|
+
};
|
|
151
|
+
/** What the checks concluded together. */
|
|
152
|
+
export type StopJudgement = {
|
|
153
|
+
kind: 'accept';
|
|
154
|
+
} | {
|
|
155
|
+
kind: 'continue';
|
|
156
|
+
messages: StepContribution[];
|
|
157
|
+
} | {
|
|
158
|
+
kind: 'reject';
|
|
159
|
+
rejections: TurnRejection[];
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Asks every stop check about an answer. The outcome is independent of registration order: any
|
|
163
|
+
* rejection ends the turn, otherwise any continuation sends the model back, otherwise the answer
|
|
164
|
+
* is accepted. A throwing check, or an invalid verdict, fails the check without deciding anything.
|
|
165
|
+
* The facts the checks declare they observed collect in `observations`, which the caller validates
|
|
166
|
+
* when it records the outcome.
|
|
167
|
+
*/
|
|
168
|
+
export declare function judgeAnswer(runtime: LoopRuntime, stop: Omit<TurnStop, 'observe'>, observations: StopObservation[]): Promise<StopJudgement>;
|
|
169
|
+
/** Runs a tool through its listeners. One that does not call `next()` has answered the call itself. */
|
|
170
|
+
export declare const executeTool: (runtime: LoopRuntime, invocation: ToolInvocation, run: () => Promise<ToolOutcome>) => Promise<ToolOutcome>;
|
|
171
|
+
/**
|
|
172
|
+
* A model request as `lagent/llm/request` middleware sees it. The turn's route is fixed, so `model`
|
|
173
|
+
* and `thinkingEffort` are read-only: assigning or deleting either throws, as it does for the
|
|
174
|
+
* correlation ids, `purpose` and `signal`. On an auxiliary request
|
|
175
|
+
* (`purpose: 'auxiliary'`) the caller's `toolChoice` and `maxOutputTokens` are fixed the same way,
|
|
176
|
+
* which the type cannot say.
|
|
177
|
+
*/
|
|
178
|
+
export type ModelRequestDraft = Omit<ModelRequest, 'model' | 'thinkingEffort'> & {
|
|
179
|
+
readonly model: string;
|
|
180
|
+
readonly thinkingEffort?: ThinkingEffort;
|
|
181
|
+
};
|
|
182
|
+
/** Fields of a draft a caller may fix beside the route; see {@link modelSend}. */
|
|
183
|
+
export type FixedRequestField = 'toolChoice' | 'maxOutputTokens';
|
|
184
|
+
/** The rows that record a model request before it is sent. */
|
|
185
|
+
type RequestRowType = 'llm/request' | 'auxiliary/request';
|
|
186
|
+
/** What a caller says of its request row: where it was made and why; the terminal adds what was sent, and the tools. */
|
|
187
|
+
type RequestRowFields<K extends RequestRowType> = Omit<JournalEventInput[K], 'llm_call_id' | 'model' | 'message_count'>;
|
|
188
|
+
/** One model call's send, from {@link modelSend}: what the terminal recorded and how far the client got. */
|
|
189
|
+
export interface ModelSend<K extends RequestRowType> {
|
|
190
|
+
/** Sends `request`, once. The stream is the client's; see {@link modelSend}. */
|
|
191
|
+
call(request: ModelRequest): Promise<StreamingLLMResponse>;
|
|
192
|
+
/** The request row the terminal recorded; none while it has not, or when middleware answered without calling `next()`. */
|
|
193
|
+
readonly row: JournalEvent<K> | undefined;
|
|
194
|
+
/** The attempts the client made, kept before its call is awaited so a refusal or cancellation still has them; 0 until one starts. */
|
|
195
|
+
readonly attempts: number;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The fields every model request of a thread's agent carries the same way, a step's and an
|
|
199
|
+
* auxiliary call's alike: the route's model and effort, the tools the agent is granted now, the
|
|
200
|
+
* thread's recorded prompt, and the correlation. A caller adds what differs: its `messages`, its
|
|
201
|
+
* `toolChoice`, an output cap.
|
|
202
|
+
*/
|
|
203
|
+
export declare function baseRequest(runtime: LoopRuntime, call: {
|
|
204
|
+
readonly threadId: string;
|
|
205
|
+
readonly agentName: string;
|
|
206
|
+
readonly route: ModelRoute;
|
|
207
|
+
readonly signal: AbortSignal;
|
|
208
|
+
readonly llmCallId: string;
|
|
209
|
+
readonly purpose: RequestPurpose;
|
|
210
|
+
}): Omit<ModelRequest, 'messages' | 'toolChoice' | 'maxOutputTokens'>;
|
|
211
|
+
/**
|
|
212
|
+
* The send of one model request, which a step's call and an auxiliary call share; they differ in the
|
|
213
|
+
* row they record (`type`, with the `fields` they say of it) and in how they read the stream.
|
|
214
|
+
*
|
|
215
|
+
* Middleware gets a draft of its own whose fields it may replace, never the data in them, and never
|
|
216
|
+
* the route: the model and effort the step was told are the ones sent, and never what the caller
|
|
217
|
+
* fixed beside it. The builder's data is frozen where it is made (surface messages, registry specs,
|
|
218
|
+
* prompt rows, auxiliary instructions); the fields the builder made for this call are frozen here, so
|
|
219
|
+
* the draft shares all of it without a copy. The terminal takes the {@link snapshot} that the journal
|
|
220
|
+
* recorder, the observers and the provider all receive.
|
|
221
|
+
*
|
|
222
|
+
* The terminal records the request row, with a `thread/tools` row before it when the tools differ
|
|
223
|
+
* from the thread's latest, shows it to `lagent/llm/sent` listeners and starts the call,
|
|
224
|
+
* and it checks for cancellation twice: before it records anything, so a cancel during middleware
|
|
225
|
+
* leaves no row, and after the row is recorded and observed, so a cancel there leaves the row and
|
|
226
|
+
* sends nothing.
|
|
227
|
+
*/
|
|
228
|
+
export declare function modelSend<K extends RequestRowType>(runtime: LoopRuntime, client: ModelCallClient, type: K, fields: RequestRowFields<K>, fixed?: readonly FixedRequestField[]): ModelSend<K>;
|
|
229
|
+
/** A model request as it was sent: the prepared request, with no signal. */
|
|
230
|
+
export type SentModelRequest = Omit<ModelRequest, 'signal'>;
|
|
231
|
+
/** What `lagent/llm/sent` listeners see: the request as sent, and the row that recorded it. */
|
|
232
|
+
export interface SentRequest {
|
|
233
|
+
readonly request: SentModelRequest;
|
|
234
|
+
readonly row: JournalEvent<'llm/request'> | JournalEvent<'auxiliary/request'>;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Hands a problem that does not fail the turn to `internal/error` listeners, or the console. Kept
|
|
238
|
+
* here rather than inlined so `hooks.ts` stays the loop's only use of cordis (architecture test).
|
|
239
|
+
*/
|
|
240
|
+
export declare function reportError(runtime: LoopRuntime, error: unknown): void;
|
|
241
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { ExtensionRecord, InboxTarget, QueuedInput, Seq, ThreadInput } from '../models/index.js';
|
|
2
|
+
import type { AppendEntry, Journal } from '../journal/index.js';
|
|
3
|
+
import type { DeepReadonly, ReadonlyJsonValue } from '../util/json.js';
|
|
4
|
+
import type { RouteAuthority } from './route.js';
|
|
5
|
+
import type { FreshOpening, ForkOpening } from './opening.js';
|
|
6
|
+
import { type Wake } from './wake.js';
|
|
7
|
+
/**
|
|
8
|
+
* Why a write-time callback refused its write, as data a host or plugin can act on without parsing
|
|
9
|
+
* `message`: the text a person is shown, an optional `code` for the cause when a reader branches on
|
|
10
|
+
* one, and optional `data` for its facts.
|
|
11
|
+
*/
|
|
12
|
+
export type Refusal = {
|
|
13
|
+
readonly message: string;
|
|
14
|
+
readonly code?: string;
|
|
15
|
+
readonly data?: ReadonlyJsonValue;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* What a write-time callback returns: the plugin rows to add to the write's group, or `{ refuse }`,
|
|
19
|
+
* its explicit veto, which writes nothing and gives the {@link Refusal} to whoever asked. Anything
|
|
20
|
+
* the callback throws is a failure, not a veto: it propagates as it was thrown.
|
|
21
|
+
*/
|
|
22
|
+
export type RowsResult = readonly AppendEntry<'ext'>[] | {
|
|
23
|
+
readonly refuse: Refusal;
|
|
24
|
+
};
|
|
25
|
+
/** Whether a callback vetoed its write. */
|
|
26
|
+
export declare const isVeto: (result: RowsResult) => result is {
|
|
27
|
+
readonly refuse: Refusal;
|
|
28
|
+
};
|
|
29
|
+
/** What every write that queues input tells its callback: the thread, where the input waits, and the run its cause joins. */
|
|
30
|
+
type WriteBase = {
|
|
31
|
+
readonly threadId: string;
|
|
32
|
+
/** Where the input waits, which `send` decides inside the write; a creation always queues for `next-turn`. */
|
|
33
|
+
readonly target: InboxTarget;
|
|
34
|
+
/** The run request the write's cause joins or opens; `null` when it brings none. */
|
|
35
|
+
readonly runId: string | null;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* What a write-time callback is told, by the write it runs in. A creation or a fork carries the
|
|
39
|
+
* resolved opening it records, a frozen copy, so a callback reads what core records and cannot
|
|
40
|
+
* change it; `inputId` is the first input's id, `null` when the write queues none. A `send`
|
|
41
|
+
* carries the id it queues.
|
|
42
|
+
*/
|
|
43
|
+
export type RowsWrite = (WriteBase & {
|
|
44
|
+
readonly kind: 'create';
|
|
45
|
+
readonly inputId: string | null;
|
|
46
|
+
readonly opening: DeepReadonly<FreshOpening>;
|
|
47
|
+
}) | (WriteBase & {
|
|
48
|
+
readonly kind: 'fork';
|
|
49
|
+
readonly inputId: string | null;
|
|
50
|
+
readonly opening: DeepReadonly<ForkOpening>;
|
|
51
|
+
}) | (WriteBase & {
|
|
52
|
+
readonly kind: 'send';
|
|
53
|
+
readonly inputId: string;
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* A write-time callback on a write that queues input — `create`, `fork` or `send`: run inside the
|
|
57
|
+
* write's transaction, once the write's own rows are built and before anything is stored, it returns
|
|
58
|
+
* plugin rows for the same group, or vetoes the write by returning `{ refuse }` (see
|
|
59
|
+
* {@link RowsResult}). Synchronous, as every `transact` callback is.
|
|
60
|
+
*/
|
|
61
|
+
export type WriteRows = (write: RowsWrite) => RowsResult;
|
|
62
|
+
/**
|
|
63
|
+
* What `send` returns for input it accepted: the input's id and `queuedAt`, the seq of the row that
|
|
64
|
+
* queued it. The id is the one the caller passed or the one `send` made.
|
|
65
|
+
*/
|
|
66
|
+
export type InputReceipt = {
|
|
67
|
+
readonly inputId: string;
|
|
68
|
+
readonly queuedAt: Seq;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* What a `send` did: queued the input, with the run request its wake joined or opened in the same
|
|
72
|
+
* write (`runId`, `null` when it had no wake; see `waitForRun`); found its id already known and
|
|
73
|
+
* wrote nothing, its receipt naming the row that queued it the first time; or wrote nothing because
|
|
74
|
+
* its `rows` callback vetoed, for `refusal`.
|
|
75
|
+
*/
|
|
76
|
+
export type SendOutcome = ({
|
|
77
|
+
readonly status: 'queued';
|
|
78
|
+
readonly runId: string | null;
|
|
79
|
+
} & InputReceipt) | ({
|
|
80
|
+
readonly status: 'known';
|
|
81
|
+
} & InputReceipt) | {
|
|
82
|
+
readonly status: 'refused';
|
|
83
|
+
readonly refusal: Refusal;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* How `send` queues: under `id`, attributed to `source`, with `rows` added to its write, and with
|
|
87
|
+
* `wake`, a cause in the same write that asks the thread to run (`{}` for a person's). A sourced
|
|
88
|
+
* input needs its `id`.
|
|
89
|
+
*/
|
|
90
|
+
export type SendOptions = {
|
|
91
|
+
readonly id?: string;
|
|
92
|
+
readonly source?: ExtensionRecord;
|
|
93
|
+
readonly rows?: WriteRows;
|
|
94
|
+
readonly wake?: Wake;
|
|
95
|
+
/**
|
|
96
|
+
* Where the input waits; omitted, admission places it (a running turn's next step, else a turn of
|
|
97
|
+
* its own). `next-turn` waits for a turn of its own even while a run holds the thread. `next-step`
|
|
98
|
+
* joins the next model step whichever turn takes it: a running turn's, a resumed turn's once its
|
|
99
|
+
* parked calls are answered, or a new turn's first step together with what waits for that turn.
|
|
100
|
+
*/
|
|
101
|
+
readonly target?: InboxTarget;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* A write-time callback on a `withdraw`: run inside its transaction, told whether the input was
|
|
105
|
+
* still queued and is withdrawn by this write, it returns plugin rows for the same group, written
|
|
106
|
+
* either way, or vetoes the withdrawal by returning `{ refuse }` (see {@link RowsResult}).
|
|
107
|
+
*/
|
|
108
|
+
export type WithdrawRows = (write: {
|
|
109
|
+
readonly threadId: string;
|
|
110
|
+
readonly withdrawn: boolean;
|
|
111
|
+
}) => RowsResult;
|
|
112
|
+
export type WithdrawOptions = {
|
|
113
|
+
readonly rows?: WithdrawRows;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* What a `withdraw` did: took the input out of the queue (`withdrawn`); found it not queued, being
|
|
117
|
+
* claimed, discarded or unknown (`not-queued`), writing only what `rows` returned; or wrote nothing
|
|
118
|
+
* because `rows` vetoed, with its `refusal`.
|
|
119
|
+
*/
|
|
120
|
+
export type WithdrawOutcome = {
|
|
121
|
+
readonly status: 'withdrawn' | 'not-queued';
|
|
122
|
+
} | {
|
|
123
|
+
readonly status: 'refused';
|
|
124
|
+
readonly refusal: Refusal;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Input waiting for a boundary, held in the journal rather than in memory.
|
|
128
|
+
*
|
|
129
|
+
* Every mutation is an `inbox/spliced` event, so a message queued while the agent was busy survives
|
|
130
|
+
* a crash exactly like the conversation does. `next-turn` is claimed only by a turn's first step,
|
|
131
|
+
* when that step asks the model: a turn that opens by answering calls an earlier turn left leaves it
|
|
132
|
+
* for the next turn. `next-step` joins the next model step of whichever turn takes it: the turn in
|
|
133
|
+
* flight, which is what makes steering possible, a resumed turn once its calls are answered, or the
|
|
134
|
+
* first step of the next turn.
|
|
135
|
+
*/
|
|
136
|
+
export declare class Inbox {
|
|
137
|
+
private readonly journal;
|
|
138
|
+
private readonly threadId;
|
|
139
|
+
constructor(journal: Journal, threadId: string);
|
|
140
|
+
private get queues();
|
|
141
|
+
private get state();
|
|
142
|
+
get nextTurn(): readonly QueuedInput[];
|
|
143
|
+
get nextStep(): readonly QueuedInput[];
|
|
144
|
+
/** The row that queued input `id`, or `undefined` when this thread was never handed that id. */
|
|
145
|
+
private queuedAt;
|
|
146
|
+
/** Everything waiting for a step to claim it, in the order it was sent. */
|
|
147
|
+
get pending(): QueuedInput[];
|
|
148
|
+
/**
|
|
149
|
+
* Idempotent durable input. The target is the sender's when it names one; otherwise execution
|
|
150
|
+
* admission chooses it (`target`), asked inside the write, as is whether the id was queued
|
|
151
|
+
* before: two sends of one id queue it once, and a known id calls no `rows`. Input attributed to
|
|
152
|
+
* a plugin (`source`) needs the id the plugin derived, since a redelivery must find it. `routes`
|
|
153
|
+
* checks a wake's route statement.
|
|
154
|
+
*/
|
|
155
|
+
send(input: ThreadInput, target: () => InboxTarget, options?: SendOptions, routes?: RouteAuthority): Promise<SendOutcome>;
|
|
156
|
+
/**
|
|
157
|
+
* Discards one queued input by id, wherever it waits, deciding inside the write whether it is still
|
|
158
|
+
* queued; `rows` adds a plugin's rows to the same write either way (see {@link WithdrawRows}).
|
|
159
|
+
*/
|
|
160
|
+
withdraw(id: string, options?: WithdrawOptions): Promise<WithdrawOutcome>;
|
|
161
|
+
/**
|
|
162
|
+
* The rows that discard everything pending, `next-step` first so a drained turn cannot pick it
|
|
163
|
+
* up: none when nothing waits. Built inside the write that carries them, a cancel's.
|
|
164
|
+
*/
|
|
165
|
+
clearRows(): AppendEntry<'inbox/spliced'>[];
|
|
166
|
+
/**
|
|
167
|
+
* The batch one step will consume: everything queued for the next step, plus, when this boundary
|
|
168
|
+
* opens a turn, the head of what waits for one: a single unsourced input, or every consecutive
|
|
169
|
+
* sourced input at the head. The batch is ordered by seq; order holds within a batch, not across
|
|
170
|
+
* the whole queue, so `next-step` input sent after something still waiting for a turn can enter
|
|
171
|
+
* before it. A person's message is never skipped to collect plugin input waiting for a turn behind
|
|
172
|
+
* it, so sourced input left at `next-turn` (notice, notice, person, notice) opens three turns:
|
|
173
|
+
* `[N, N]`, `[U]`, `[N]`; with the notices at `next-step`, it opens one: `[N, N, U, N]`. With
|
|
174
|
+
* `sentBack`, a later step takes the next such batch too: a turn that opened by answering calls
|
|
175
|
+
* claimed nothing that waited for a turn, and once a stop check sent its answer back, what waits
|
|
176
|
+
* could be what the check holds the answer for.
|
|
177
|
+
*
|
|
178
|
+
* Reading only. The input leaves the queue when its `input/message` is appended, so recording it
|
|
179
|
+
* and claiming it are the same event and a crash between them is not a thing that can happen.
|
|
180
|
+
*/
|
|
181
|
+
peek(target: InboxTarget, sentBack?: boolean): QueuedInput[];
|
|
182
|
+
/**
|
|
183
|
+
* Array-splice semantics, normalized against the inbox as it stands: the row that records it, or
|
|
184
|
+
* nothing to record. Built inside a write, so the indices are the ones the row lands on.
|
|
185
|
+
*/
|
|
186
|
+
private spliceEntry;
|
|
187
|
+
}
|
|
188
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the rest of the package may use from the loop.
|
|
3
|
+
*
|
|
4
|
+
* Journal operations (projections, inbox, recovery) need no execution runtime. A live thread
|
|
5
|
+
* activation drives execution through LoopAgent; plugins extend it through tools and hooks.
|
|
6
|
+
*/
|
|
7
|
+
export * from './projections.js';
|
|
8
|
+
export * from './surface.js';
|
|
9
|
+
export * from './threadState.js';
|
|
10
|
+
export * from './chunks.js';
|
|
11
|
+
export * from './errors.js';
|
|
12
|
+
export * from './limits.js';
|
|
13
|
+
export * from './runtime.js';
|
|
14
|
+
export { Inbox } from './inbox.js';
|
|
15
|
+
export { isVeto } from './inbox.js';
|
|
16
|
+
export type { BirthSpec, ForkOpening, FreshOpening } from './opening.js';
|
|
17
|
+
export type { Refusal, RowsResult, RowsWrite, InputReceipt, SendOptions, SendOutcome, WithdrawOptions, WithdrawOutcome, WithdrawRows, WriteRows, } from './inbox.js';
|
|
18
|
+
export { closeInterruptedTurn, hasThreadWork, inputFate, lastAssistantMessage, refusedReplacement, unfinishedConfirmations, } from './state.js';
|
|
19
|
+
export type { InputFate } from './state.js';
|
|
20
|
+
export * from './summary.js';
|
|
21
|
+
export * from './requests.js';
|
|
22
|
+
export { chainStanding } from './chain.js';
|
|
23
|
+
export type { ChainStanding } from './chain.js';
|
|
24
|
+
export * from './wake.js';
|
|
25
|
+
export * from './route.js';
|
|
26
|
+
export * from './holds.js';
|
|
27
|
+
export * from './continuation.js';
|
|
28
|
+
export * from './forks.js';
|
|
29
|
+
export * from './hooks.js';
|
|
30
|
+
export type { AuxiliaryCall, AuxiliaryReply } from './auxiliary.js';
|
|
31
|
+
export { replaceSurface } from './replace.js';
|
|
32
|
+
export type { ReplacementContext, ReplacementInput } from './replace.js';
|
|
33
|
+
export * from './strategy.js';
|
|
34
|
+
export * from './tool.js';
|
|
35
|
+
export { declarePolicyState, errorResult } from './toolCalls.js';
|
|
36
|
+
export { LoopAgent } from './agent.js';
|
|
37
|
+
export type { CompactOptions, ServedRun } from './agent.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What bounds a runaway turn. Each is a number the loop can hand back to the model as a tool result
|
|
3
|
+
* or a turn ending it can react to; together with the depth cap they bound total spend.
|
|
4
|
+
*/
|
|
5
|
+
export type TurnLimits = {
|
|
6
|
+
/** Positive finite integer: steps in one thread's turn before it stops with `max-steps`. */
|
|
7
|
+
maxStepsPerTurn: number;
|
|
8
|
+
/** Non-negative finite integer: nesting below a root. Zero forbids delegation; each hop is one level. */
|
|
9
|
+
maxThreadDepth: number;
|
|
10
|
+
/** Positive finite integer: tool calls dispatched at once within one step; the rest wait for a slot. */
|
|
11
|
+
maxParallelToolCalls: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const DEFAULT_TURN_LIMITS: TurnLimits;
|
|
14
|
+
export declare const resolveLimits: (overrides?: Partial<TurnLimits>) => TurnLimits;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ModelRoute } from '../llm/index.js';
|
|
2
|
+
import type { InitialInstallation, ThreadEnvironment, ThreadOrigin } from '../models/index.js';
|
|
3
|
+
import type { DeepReadonly } from '../util/json.js';
|
|
4
|
+
import type { RowRef } from './surface.js';
|
|
5
|
+
/**
|
|
6
|
+
* What a fresh thread is born with, as its spawn row records it: the one value `create` resolves a
|
|
7
|
+
* birth to, whichever source it came from, and the one a reused thread is compared on. `installations`
|
|
8
|
+
* holds all of them, handed down ones included, each with its lifetime; `requires` is a set, kept
|
|
9
|
+
* sorted and without repeats.
|
|
10
|
+
*/
|
|
11
|
+
export type BirthSpec = DeepReadonly<{
|
|
12
|
+
route: ModelRoute;
|
|
13
|
+
environment: ThreadEnvironment;
|
|
14
|
+
installations: InitialInstallation[];
|
|
15
|
+
requires: string[];
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* A fresh thread as a write-time callback sees it: the agent it is born on, the origin it records
|
|
19
|
+
* (`null` for a root) and its {@link BirthSpec}.
|
|
20
|
+
*/
|
|
21
|
+
export type FreshOpening = {
|
|
22
|
+
agent: string;
|
|
23
|
+
origin: ThreadOrigin | null;
|
|
24
|
+
spec: BirthSpec;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A fork as a write-time callback sees it: its agent (the cut's thread's), the origin it records
|
|
28
|
+
* and the cut it continues from, its own environment and constraint owners as its spawn row records
|
|
29
|
+
* them, and `inherits`, what it goes on with from the cut and does not record: the route and the
|
|
30
|
+
* installations at that row.
|
|
31
|
+
*/
|
|
32
|
+
export type ForkOpening = {
|
|
33
|
+
agent: string;
|
|
34
|
+
origin: ThreadOrigin | null;
|
|
35
|
+
cut: RowRef;
|
|
36
|
+
environment: ThreadEnvironment;
|
|
37
|
+
requires: string[];
|
|
38
|
+
inherits: {
|
|
39
|
+
route: ModelRoute;
|
|
40
|
+
installations: InitialInstallation[];
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { QueuedInput, ReplacementTrigger } from '../models/index.js';
|
|
2
|
+
import type { JsonValue } from '../util/json.js';
|
|
3
|
+
import { type ModelRoute } from '../llm/index.js';
|
|
4
|
+
import type { SurfacePrepareOutcome } from './hooks.js';
|
|
5
|
+
import type { Lease, LoopRuntime } from './runtime.js';
|
|
6
|
+
/** One request to prepare the surface, as the loop or `thread.compact()` starts it. */
|
|
7
|
+
export type SurfacePrepareDispatch = {
|
|
8
|
+
readonly threadId: string;
|
|
9
|
+
readonly agentName: string;
|
|
10
|
+
readonly turn: number | null;
|
|
11
|
+
readonly step: number | null;
|
|
12
|
+
readonly route: ModelRoute;
|
|
13
|
+
readonly trigger: ReplacementTrigger;
|
|
14
|
+
readonly queued: readonly QueuedInput[];
|
|
15
|
+
readonly options: JsonValue | null;
|
|
16
|
+
readonly signal: AbortSignal;
|
|
17
|
+
/** The lease the caller holds; checked before the engine records anything for the plan. */
|
|
18
|
+
readonly lease: Lease;
|
|
19
|
+
};
|
|
20
|
+
/** How a request settled, and the error that ended it when the strategy threw. */
|
|
21
|
+
export type SurfacePrepareSettled = {
|
|
22
|
+
readonly outcome: SurfacePrepareOutcome;
|
|
23
|
+
readonly error: unknown;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Asks the thread's strategy for a plan and carries it out: the one model call it asks for, then the
|
|
27
|
+
* replacement or the facts its final plan names, all recorded by the engine. Never throws for the
|
|
28
|
+
* strategy: what a failure means is the trigger's policy, which the caller applies.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runSurfacePrepare(runtime: LoopRuntime, dispatch: SurfacePrepareDispatch): Promise<SurfacePrepareSettled>;
|