@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,70 @@
|
|
|
1
|
+
import type { Journal, PluginJournal } from '../journal/index.js';
|
|
2
|
+
import type { ReadonlyState } from '../util/foldState.js';
|
|
3
|
+
import type { InboxTarget, Seq } from '../models/index.js';
|
|
4
|
+
import { type DecisionView } from './decide.js';
|
|
5
|
+
import type { TurnLimits } from './limits.js';
|
|
6
|
+
import type { ConversationMessage } from '../llm/index.js';
|
|
7
|
+
import type { ConfirmationState } from './projections.js';
|
|
8
|
+
import type { ReplacementRefusal, RowRef } from './surface.js';
|
|
9
|
+
import { type ThreadState } from './threadState.js';
|
|
10
|
+
/**
|
|
11
|
+
* A journal view, usable without constructing an execution runtime or activating plugins.
|
|
12
|
+
* `sentBack` says a stop check sent back the answer of a turn that opened by answering calls, so
|
|
13
|
+
* input waiting for a turn joins it batch by batch (`Inbox.peek`).
|
|
14
|
+
*/
|
|
15
|
+
export declare function decisionView(journal: Journal, threadId: string, target: InboxTarget, step: number, turn: number, sentBack?: boolean): DecisionView;
|
|
16
|
+
export declare function hasThreadWork(journal: Journal, threadId: string, limits: TurnLimits): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Close a process-interrupted turn from journal state, including when no new execution is needed.
|
|
19
|
+
* Decided inside the write, so a turn something else closed meanwhile is not closed twice.
|
|
20
|
+
*/
|
|
21
|
+
export declare function closeInterruptedTurn(journal: Journal, threadId: string, limits: TurnLimits): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* What became of the input id a thread was handed: `unknown` when it never was; `queued` while it
|
|
24
|
+
* waits, for `target`; `claimed` once a step took it; `discarded` when it left the queue unclaimed,
|
|
25
|
+
* withdrawn or cleared by a cancel. Each names the row that queued it, and a claim the
|
|
26
|
+
* `input/message` that took it. A discarded or claimed id stays spent: it is never queued again.
|
|
27
|
+
*/
|
|
28
|
+
export type InputFate = {
|
|
29
|
+
readonly state: 'unknown';
|
|
30
|
+
} | {
|
|
31
|
+
readonly state: 'queued';
|
|
32
|
+
readonly queuedAt: Seq;
|
|
33
|
+
readonly target: InboxTarget;
|
|
34
|
+
} | {
|
|
35
|
+
readonly state: 'claimed';
|
|
36
|
+
readonly queuedAt: Seq;
|
|
37
|
+
readonly claimedAt: Seq;
|
|
38
|
+
} | {
|
|
39
|
+
readonly state: 'discarded';
|
|
40
|
+
readonly queuedAt: Seq;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The fate of input `id` from a thread's state: the one answer to "what became of input X", read
|
|
44
|
+
* inside a write or a contributor from the state the journal folds, or through `ThreadView.input`.
|
|
45
|
+
* A fork's own ids only: its source's are the source's.
|
|
46
|
+
*/
|
|
47
|
+
export declare function inputFate(state: ReadonlyState<Pick<ThreadState, 'inputs' | 'inbox'>>, id: string): InputFate;
|
|
48
|
+
/**
|
|
49
|
+
* Confirmations on one thread whose call has no result yet and was not rejected: still waiting on the
|
|
50
|
+
* user, or approved. An approval lasts until the call's result: the call runs at the next turn, and
|
|
51
|
+
* one that waits or is cut off runs again on the same approval, against whatever tool answers to its
|
|
52
|
+
* name by then.
|
|
53
|
+
*/
|
|
54
|
+
export declare function unfinishedConfirmations(journal: Pick<PluginJournal, 'state'>, threadId: string): ReadonlyState<ConfirmationState>[];
|
|
55
|
+
/**
|
|
56
|
+
* The first replacement `threadId`'s surface refused, or `null`: a thread that has one carries
|
|
57
|
+
* history no execution may continue from, which every entry that executes checks.
|
|
58
|
+
*/
|
|
59
|
+
export declare function refusedReplacement(journal: Pick<Journal, 'state'>, threadId: string): {
|
|
60
|
+
readonly row: RowRef;
|
|
61
|
+
readonly refusal: ReplacementRefusal;
|
|
62
|
+
} | null;
|
|
63
|
+
/**
|
|
64
|
+
* The last thing the model said on a thread, if anything: the message of the last
|
|
65
|
+
* `assistant/message` row on its lineage that the stream did not cut off. Found through the rows
|
|
66
|
+
* behind the surface, not by role, so an assistant-role stand-in is never reported as the model's
|
|
67
|
+
* last word; a reply a replacement took off the surface is still found, through the rows its
|
|
68
|
+
* stand-in replaced.
|
|
69
|
+
*/
|
|
70
|
+
export declare function lastAssistantMessage(journal: Pick<PluginJournal, 'eventAt' | 'state'>, threadId: string): ReadonlyState<ConversationMessage> | null;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ExtensionRecord, 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 { AuxiliaryCall, AuxiliaryReply } from './auxiliary.js';
|
|
5
|
+
import type { ReplacementInput } from './replace.js';
|
|
6
|
+
/** What a strategy is told about one request to prepare the surface. */
|
|
7
|
+
export type SurfacePrepareInput = {
|
|
8
|
+
readonly threadId: string;
|
|
9
|
+
/** The turn and step it runs in; both `null` for a request between turns. */
|
|
10
|
+
readonly turn: number | null;
|
|
11
|
+
readonly step: number | null;
|
|
12
|
+
/** The route the turn recorded, or for a request between turns, the thread's route. */
|
|
13
|
+
readonly route: ModelRoute;
|
|
14
|
+
/**
|
|
15
|
+
* `pressure` on every due model step, `overflow` inside a step whose request the provider refused
|
|
16
|
+
* as longer than the window, `request` when a caller asked through `thread.compact()`.
|
|
17
|
+
*/
|
|
18
|
+
readonly trigger: ReplacementTrigger;
|
|
19
|
+
/**
|
|
20
|
+
* Input queued for this step, which the step records after the replacement unless it was
|
|
21
|
+
* withdrawn meanwhile. Empty on `overflow`, whose input is already recorded, and on `request`.
|
|
22
|
+
*/
|
|
23
|
+
readonly queued: readonly QueuedInput[];
|
|
24
|
+
/** On `request`, the options the caller gave, opaque to the engine; otherwise `null`. */
|
|
25
|
+
readonly options: JsonValue | null;
|
|
26
|
+
/** The turn's signal, or on `request` the caller's. */
|
|
27
|
+
readonly signal: AbortSignal;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* How a request to prepare the surface ends, as a strategy decides it: nothing to do, a failure,
|
|
31
|
+
* or replacements the engine records as one atomic group. A failure may name facts the strategy
|
|
32
|
+
* wants recorded with it, as `ext` rows on the thread, such as an unusable reply it counts.
|
|
33
|
+
*/
|
|
34
|
+
export type FinalPlan = {
|
|
35
|
+
readonly kind: 'skip';
|
|
36
|
+
readonly reason: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'fail';
|
|
39
|
+
readonly reason: string;
|
|
40
|
+
readonly facts?: readonly ExtensionRecord[];
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: 'replace';
|
|
43
|
+
readonly replacements: readonly ReplacementInput[];
|
|
44
|
+
readonly reason?: string;
|
|
45
|
+
};
|
|
46
|
+
/** What came of the one model call a plan asked for. */
|
|
47
|
+
export type AuxiliaryAnswer = {
|
|
48
|
+
readonly reply: AuxiliaryReply;
|
|
49
|
+
} | {
|
|
50
|
+
readonly failure: unknown;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* What a strategy returns for a request: a final plan, or one model call beside the conversation
|
|
54
|
+
* (`ask`) whose answer `finish` turns into the final plan. At most one call per request. (Not
|
|
55
|
+
* `then`: a plan with one would be awaited as a promise.)
|
|
56
|
+
*/
|
|
57
|
+
export type SurfacePlan = FinalPlan | {
|
|
58
|
+
readonly kind: 'ask';
|
|
59
|
+
readonly call: AuxiliaryCall;
|
|
60
|
+
finish(answer: AuxiliaryAnswer): FinalPlan | Promise<FinalPlan>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* A thread's one way to replace part of its surface. It reads what it needs and returns a plan;
|
|
64
|
+
* the engine makes the model call it asks for, records the replacement or the facts, and derives
|
|
65
|
+
* how the request ended from what committed. It holds no binding that outlives the request.
|
|
66
|
+
*/
|
|
67
|
+
export interface SurfaceStrategy {
|
|
68
|
+
/** How a refusal and a report name it, such as `compaction (summarize)`. */
|
|
69
|
+
readonly name: string;
|
|
70
|
+
plan(input: SurfacePrepareInput): SurfacePlan | Promise<SurfacePlan>;
|
|
71
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { Journal } from '../journal/index.js';
|
|
2
|
+
import type { Reducer } from './threadState.js';
|
|
3
|
+
import type { ConversationMessage } from '../llm/index.js';
|
|
4
|
+
import type { JournalEvent, ReplacementKind, Seq, SurfaceEventType } from '../models/index.js';
|
|
5
|
+
import type { ReadonlyState } from '../util/foldState.js';
|
|
6
|
+
/** A journal row, named by the thread that owns it. Inherited rows belong to a fork's source lineage. */
|
|
7
|
+
export type RowRef = {
|
|
8
|
+
readonly threadId: string;
|
|
9
|
+
readonly seq: Seq;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* One message on the surface, with the row behind it.
|
|
13
|
+
*
|
|
14
|
+
* An original message is behind its own `input/message`, `assistant/message` or `tool/result` row;
|
|
15
|
+
* a stand-in is behind the `surface/replaced` row that put it there, whose `source_seqs` name what
|
|
16
|
+
* it replaced (see {@link replacedOriginals}). A `ConversationMessage` alone does not say which, nor
|
|
17
|
+
* whether a host sent it, and the replacement rules need both.
|
|
18
|
+
*/
|
|
19
|
+
export type SurfaceEntry = {
|
|
20
|
+
readonly row: RowRef;
|
|
21
|
+
readonly type: SurfaceEventType;
|
|
22
|
+
/**
|
|
23
|
+
* An `input/message` in role `developer` with no `source`: the host speaking. No replacement
|
|
24
|
+
* may touch one, since no plugin could bring it back in its place.
|
|
25
|
+
*/
|
|
26
|
+
readonly directDeveloperInput: boolean;
|
|
27
|
+
readonly message: ConversationMessage;
|
|
28
|
+
} | {
|
|
29
|
+
readonly row: RowRef;
|
|
30
|
+
readonly type: 'surface/replaced';
|
|
31
|
+
readonly kind: ReplacementKind;
|
|
32
|
+
readonly directDeveloperInput: false;
|
|
33
|
+
readonly message: ConversationMessage;
|
|
34
|
+
};
|
|
35
|
+
/** A surface entry as a plugin reads it from the fold: read-only all the way down, its message included. */
|
|
36
|
+
export type SurfaceEntryView = ReadonlyState<SurfaceEntry>;
|
|
37
|
+
export type SurfaceState = {
|
|
38
|
+
/** What the model sees, in order. */
|
|
39
|
+
readonly entries: SurfaceEntry[];
|
|
40
|
+
/**
|
|
41
|
+
* `surface/replaced` rows this fold skipped, with why. `replaceSurface` writes none that would be
|
|
42
|
+
* skipped, so an entry here is a row written past it: a bug or a hand-edited store. The fold
|
|
43
|
+
* records it rather than throwing, since a throwing core fold would leave every thread unopenable;
|
|
44
|
+
* such a thread is read and forked before the row, and never executed on (`CorruptHistoryError`).
|
|
45
|
+
*/
|
|
46
|
+
readonly refused: {
|
|
47
|
+
readonly row: RowRef;
|
|
48
|
+
readonly refusal: ReplacementRefusal;
|
|
49
|
+
}[];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* What the model sees, in journal order, with the row behind each message.
|
|
53
|
+
*
|
|
54
|
+
* The system prompt is not here: it is recorded once per thread on `thread/prompt` and sent beside
|
|
55
|
+
* the conversation. Content that has to come back byte-identical belongs here, as a thread's
|
|
56
|
+
* opening messages.
|
|
57
|
+
*
|
|
58
|
+
* A reply the stream cut off is not here either. It is journaled for the record, but as far as the
|
|
59
|
+
* conversation is concerned the model has not replied: the thread still owes an answer, recovery
|
|
60
|
+
* sees work left, and a delegating caller sees nothing to take. One rule, read by all three.
|
|
61
|
+
*
|
|
62
|
+
* A `surface/replaced` row is folded by splicing: a `span` puts its stand-in where the run it
|
|
63
|
+
* replaces was, a `rewrite` puts its stand-in in place of the one message it names. Every row it
|
|
64
|
+
* meets is judged by {@link judgeReplacement}, live or replayed, and `replaceSurface` judges a group
|
|
65
|
+
* the same way inside its write, so the engine writes no row that the fold would skip.
|
|
66
|
+
*
|
|
67
|
+
* A fork inherits all of it: the conversation is exactly what a fork continues. Inherited entries
|
|
68
|
+
* are named by their original rows, which belong to the source's lineage.
|
|
69
|
+
*/
|
|
70
|
+
export declare const surface: Reducer<SurfaceState>;
|
|
71
|
+
/**
|
|
72
|
+
* Judges a group of replacements against `entries`, each against the surface the previous one
|
|
73
|
+
* left, without changing `entries`: the first refused, with its position, or `null` when the whole
|
|
74
|
+
* group may land.
|
|
75
|
+
*/
|
|
76
|
+
export declare function judgeGroup(entries: readonly SurfaceEntry[], group: readonly JournalEvent<'surface/replaced'>[]): {
|
|
77
|
+
readonly index: number;
|
|
78
|
+
readonly refusal: ReplacementRefusal;
|
|
79
|
+
} | null;
|
|
80
|
+
/**
|
|
81
|
+
* Whether a row put a message of its own on the surface: an `input/message`, a reply that was not
|
|
82
|
+
* cut off, or a tool result. The one predicate for it: the surface fold, {@link historyMessage} and
|
|
83
|
+
* history's numbering all gate on it. A `surface/replaced` row's stand-in is derived and never counts.
|
|
84
|
+
*/
|
|
85
|
+
export declare const isHistoryRow: (event: JournalEvent) => boolean;
|
|
86
|
+
/**
|
|
87
|
+
* The message a row puts on a conversation, or `null` for a row that puts none there
|
|
88
|
+
* ({@link isHistoryRow}). The one row-to-message logic: the surface fold builds its entries from it
|
|
89
|
+
* and recall renders history from it, so the model reads what the model saw.
|
|
90
|
+
*/
|
|
91
|
+
export declare function historyMessage(event: JournalEvent): ConversationMessage | null;
|
|
92
|
+
/** A replacement as the rules judge it: the row's data and the rows it cites. A journal row is one. */
|
|
93
|
+
export type ReplacementCandidate = Pick<JournalEvent<'surface/replaced'>, 'data' | 'source_seqs'>;
|
|
94
|
+
/** Which rule a refused replacement breaks; see {@link judgeReplacement}. */
|
|
95
|
+
export type ReplacementRule = 'empty' | 'not-current' | 'developer-input' | 'newest-message' | 'unbalanced' | 'rewrite-target';
|
|
96
|
+
export type ReplacementRefusal = {
|
|
97
|
+
readonly accepted: false;
|
|
98
|
+
readonly rule: ReplacementRule;
|
|
99
|
+
readonly message: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* A judgment of one replacement against a surface. An accepted one says where it lands: the cited
|
|
103
|
+
* messages are `entries[start]` up to, not including, `entries[start + count]`.
|
|
104
|
+
*/
|
|
105
|
+
export type ReplacementVerdict = {
|
|
106
|
+
readonly accepted: true;
|
|
107
|
+
readonly start: number;
|
|
108
|
+
readonly count: number;
|
|
109
|
+
} | ReplacementRefusal;
|
|
110
|
+
/**
|
|
111
|
+
* Whether a replacement may land on a surface, as it stands. The one predicate for replacements:
|
|
112
|
+
* the surface fold runs it on every row it folds, `replaceSurface` on every group it writes, and a
|
|
113
|
+
* strategy may run it on a plan before it asks for anything.
|
|
114
|
+
*
|
|
115
|
+
* - **Not empty**: a `span` names at least one row; a `rewrite` names exactly one.
|
|
116
|
+
* - **Contiguous and current**: the cited rows are, in order, a contiguous run of the rows behind the
|
|
117
|
+
* surface. A message already replaced is not current; its stand-in's row is.
|
|
118
|
+
* - **No direct developer input** is inside a span or rewritten: the host's instruction stays where
|
|
119
|
+
* it was, in order with what surrounds it, with no plugin needed to restore it.
|
|
120
|
+
* - **A `span` keeps the newest message**, so what the thread owes is unchanged. It is also
|
|
121
|
+
* **balanced**: no tool call on one side of either edge with its result on the other, and no tool
|
|
122
|
+
* result straight after the stand-in (see {@link isBalancedCut}).
|
|
123
|
+
* - **A `rewrite` targets** a tool result, a `user`-role input, or a rewrite's stand-in: never an
|
|
124
|
+
* assistant message, whose recorded provider state the Responses adapters replay in place of its
|
|
125
|
+
* content; never a `developer` message, which speaks as the harness; never a span's stand-in, whose
|
|
126
|
+
* text the strategy that wrote it owns. It may name the newest message. Its stand-in takes the role
|
|
127
|
+
* and tool call id of what it rewrites, so balance and what is owed hold by identity.
|
|
128
|
+
*
|
|
129
|
+
* The roles a `span` stand-in may take are the row schema's to enforce, and are. Changing what this
|
|
130
|
+
* accepts changes what recorded rows mean on replay, so it bumps the journal format version.
|
|
131
|
+
*/
|
|
132
|
+
export declare function judgeReplacement(entries: readonly SurfaceEntry[], candidate: ReplacementCandidate): ReplacementVerdict;
|
|
133
|
+
/**
|
|
134
|
+
* Whether the surface can be cut just before `entries[at]` (`at` from 0 to `entries.length`)
|
|
135
|
+
* without separating a tool call from its result: no tool result after the cut answers a call before
|
|
136
|
+
* it, and no call before it is still owed one. What a span's edges must be, and what a request built
|
|
137
|
+
* from a prefix of the surface must end on.
|
|
138
|
+
*
|
|
139
|
+
* Results are paired with the latest assistant message that called tools before them, as a
|
|
140
|
+
* provider pairs them and as `unansweredToolCalls` reads them, never by call id across the surface:
|
|
141
|
+
* providers reuse call ids from one turn to the next.
|
|
142
|
+
*/
|
|
143
|
+
export declare function isBalancedCut(entries: readonly SurfaceEntryView[], at: number): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* The original rows behind a row on the surface, in surface order: the row itself when it is an
|
|
146
|
+
* original, or for a `surface/replaced` row, the originals behind every row it cites, followed down
|
|
147
|
+
* through chains of spans and rewrites. Where any message came from, for whatever asks: recall's
|
|
148
|
+
* numbering, a checkpoint's range, the copied input.
|
|
149
|
+
*
|
|
150
|
+
* Every row a replacement the engine wrote cites was on the surface when it was written, so the walk
|
|
151
|
+
* meets only replacements that took effect; one the surface refused is not asked about here.
|
|
152
|
+
*/
|
|
153
|
+
export declare function replacedOriginals(journal: Pick<Journal, 'eventAt'>, row: RowRef): RowRef[];
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { CoreFold } from '../journal/index.js';
|
|
2
|
+
import type { JournalEvent } from '../models/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* One concern of a thread's state: where it starts, and what a row does to it. `apply` may mutate
|
|
5
|
+
* `state` and return it, or return a fresh value; it never reads another concern.
|
|
6
|
+
*/
|
|
7
|
+
export type Reducer<S> = {
|
|
8
|
+
init(): S;
|
|
9
|
+
apply(state: S, event: JournalEvent): S;
|
|
10
|
+
};
|
|
11
|
+
/** Every concern of core's state, by the field it fills in {@link ThreadState}. */
|
|
12
|
+
declare const REDUCERS: {
|
|
13
|
+
readonly surface: Reducer<import("./surface.js").SurfaceState>;
|
|
14
|
+
readonly turnBoundary: Reducer<{
|
|
15
|
+
lastTurn: number;
|
|
16
|
+
step: number;
|
|
17
|
+
lastReason: import("../models/index.js").TurnEndReason | null;
|
|
18
|
+
turnOpen: boolean;
|
|
19
|
+
concludedTurn: number | null;
|
|
20
|
+
}>;
|
|
21
|
+
readonly answerCheck: Reducer<import("./projections.js").AnswerCheck>;
|
|
22
|
+
readonly dispatchedCalls: Reducer<Map<string, number>>;
|
|
23
|
+
readonly dispatchAttempts: Reducer<Map<string, import("./projections.js").DispatchAttempt>>;
|
|
24
|
+
readonly waits: Reducer<Map<number, import("./projections.js").WaitEntry>>;
|
|
25
|
+
readonly confirmations: Reducer<Map<string, import("./projections.js").ConfirmationState>>;
|
|
26
|
+
readonly threadRecord: Reducer<import("./projections.js").ThreadRecord | null>;
|
|
27
|
+
readonly threadRoute: Reducer<{
|
|
28
|
+
provider: string;
|
|
29
|
+
model: string;
|
|
30
|
+
thinking_effort: "low" | "high" | "none" | "medium" | "max" | null;
|
|
31
|
+
} | null>;
|
|
32
|
+
readonly threadPrompt: Reducer<{
|
|
33
|
+
kind: "base" | "instruction" | "context";
|
|
34
|
+
tag: string | null;
|
|
35
|
+
text: string;
|
|
36
|
+
}[] | null>;
|
|
37
|
+
readonly threadTools: Reducer<readonly {
|
|
38
|
+
input_schema: import("../llm/primitives.js").JsonObject;
|
|
39
|
+
name: string;
|
|
40
|
+
description: string;
|
|
41
|
+
}[] | null>;
|
|
42
|
+
readonly forkTask: Reducer<{
|
|
43
|
+
spawnSeq: import("../models/index.js").Seq | null;
|
|
44
|
+
unclaimed: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
readonly inbox: Reducer<import("./projections.js").InboxState>;
|
|
47
|
+
readonly inputs: Reducer<Map<string, import("./projections.js").InputRows>>;
|
|
48
|
+
readonly installations: Reducer<import("./projections.js").InstallationsState>;
|
|
49
|
+
readonly lastAnswer: Reducer<number | null>;
|
|
50
|
+
readonly requests: Reducer<import("./requests.js").RequestsState>;
|
|
51
|
+
readonly chain: Reducer<import("./chain.js").ChainState>;
|
|
52
|
+
};
|
|
53
|
+
type Concern = keyof typeof REDUCERS;
|
|
54
|
+
type StateOf<K extends Concern> = ReturnType<(typeof REDUCERS)[K]['init']>;
|
|
55
|
+
/** A thread's state as core folds it: one field per concern. */
|
|
56
|
+
export type ThreadState = {
|
|
57
|
+
[K in Concern]: StateOf<K>;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Core's one fold: a thread's {@link ThreadState}, every concern reduced from the same rows. Fatal,
|
|
61
|
+
* as all of core's state is, and registered by the journal plugin before the journal opens. Read it
|
|
62
|
+
* with `journal.state(threadState, threadId).inbox`, and so on; a plugin reads it the same way but
|
|
63
|
+
* cannot register or make a fold of this kind.
|
|
64
|
+
*/
|
|
65
|
+
export declare const threadState: CoreFold<ThreadState>;
|
|
66
|
+
/**
|
|
67
|
+
* One field of {@link ThreadState} as a reducer of its own, with the same fork rule, for a replay
|
|
68
|
+
* that folds only what it reads: `journal.stateAt` to a row, or a walk along a lineage. A reducer,
|
|
69
|
+
* not a projection, so it can never be registered as a second fold.
|
|
70
|
+
*/
|
|
71
|
+
export declare function subState<K extends Concern>(key: K): Reducer<StateOf<K>>;
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Context } from '@leuduan/cordis';
|
|
2
|
+
import type { InterruptionPolicy, JsonValue, Seq, ThreadEnvironment, ToolResult } from '../models/index.js';
|
|
3
|
+
import type { ReadonlyJsonValue } from '../util/json.js';
|
|
4
|
+
import type { ModelRoute, ParsedToolCall, ToolSpec } from '../llm/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* How a tool's calls may overlap. `exclusive` forms a barrier: it starts only once the calls before
|
|
7
|
+
* it have settled, and nothing starts beside it.
|
|
8
|
+
*/
|
|
9
|
+
export type ToolExecutionMode = 'parallel' | 'exclusive';
|
|
10
|
+
/**
|
|
11
|
+
* A call that suspends instead of answering now: it waits on a dependency outside this loop, a
|
|
12
|
+
* delegated thread's answer or a person's reply, which the constraint owner named `owner` alone
|
|
13
|
+
* interprets and resolves (`OwnerHandle.resolveWait`). Core records the declaration, the
|
|
14
|
+
* thread is held `wait` without a run slot, and once the owner records a value the call is
|
|
15
|
+
* dispatched again with `InvocationContext.wait`, where the tool returns its ordinary result from
|
|
16
|
+
* it. A cancel answers a waiting call instead. `dependency` is a JSON object the owner versions;
|
|
17
|
+
* `deadlineAt` (epoch milliseconds, or `null`) is the owner's to act on; `reason` says why in words.
|
|
18
|
+
*/
|
|
19
|
+
export type WaitRequest = {
|
|
20
|
+
readonly kind: 'wait';
|
|
21
|
+
readonly owner: string;
|
|
22
|
+
readonly dependency: {
|
|
23
|
+
readonly [key: string]: JsonValue;
|
|
24
|
+
};
|
|
25
|
+
readonly deadlineAt: number | null;
|
|
26
|
+
readonly reason: string;
|
|
27
|
+
};
|
|
28
|
+
export type ToolOutcome = ToolResult | WaitRequest;
|
|
29
|
+
/** Suspends the call on `owner`'s dependency; see {@link WaitRequest}. */
|
|
30
|
+
export declare const waitFor: (request: Omit<WaitRequest, "kind">) => WaitRequest;
|
|
31
|
+
export declare const isWaitRequest: (outcome: object) => outcome is WaitRequest;
|
|
32
|
+
/** A dispatch of a suspended call whose wait resolved: what it waited on, and the value it resolved with. */
|
|
33
|
+
export type ResolvedWait = {
|
|
34
|
+
readonly dependency: {
|
|
35
|
+
readonly [key: string]: ReadonlyJsonValue;
|
|
36
|
+
};
|
|
37
|
+
readonly value: {
|
|
38
|
+
readonly [key: string]: ReadonlyJsonValue;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* What a tool implements. `defineTool` in `kit/tool.ts` builds one, with validation and timing; this
|
|
43
|
+
* is the contract underneath it.
|
|
44
|
+
*/
|
|
45
|
+
export interface Tool {
|
|
46
|
+
readonly name: string;
|
|
47
|
+
/**
|
|
48
|
+
* Whether a call may run beside the others of its response. `parallel` for a tool whose calls do
|
|
49
|
+
* not depend on each other's effects, `exclusive` for one that changes state: an exclusive call
|
|
50
|
+
* runs alone, after every call before it and before any after it. A barrier within one response's
|
|
51
|
+
* batch only: it does not isolate threads that share a workspace, nor a process a call left
|
|
52
|
+
* running. Every tool says which; there is no default.
|
|
53
|
+
*/
|
|
54
|
+
readonly executionMode: ToolExecutionMode;
|
|
55
|
+
/**
|
|
56
|
+
* What a re-dispatch may do with a call of this tool that may have begun when its turn was
|
|
57
|
+
* interrupted. Every tool says which; there is no default. `rerun` for a tool that is read-only or
|
|
58
|
+
* idempotent under the call's identity (`InvocationContext.threadId` and `callSeq`); `report` for
|
|
59
|
+
* anything whose second execution would be a second effect in the world.
|
|
60
|
+
*/
|
|
61
|
+
readonly onInterrupted: InterruptionPolicy;
|
|
62
|
+
buildSpec(): ToolSpec;
|
|
63
|
+
/** Never throws: validation and execution failures become `is_error` results. */
|
|
64
|
+
invoke(call: ParsedToolCall, context: InvocationContext): Promise<ToolOutcome>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* What a tool is handed. `ctx` is the live thread context, with its scoped tool layer,
|
|
68
|
+
* `ctx.threads`, and the services plugins provide, such as `ctx.delegations` and `ctx.ask`.
|
|
69
|
+
*/
|
|
70
|
+
export interface InvocationContext {
|
|
71
|
+
readonly ctx: Context;
|
|
72
|
+
/** Aborts when this turn is cancelled or the root closes. */
|
|
73
|
+
readonly signal: AbortSignal;
|
|
74
|
+
readonly agentName: string;
|
|
75
|
+
readonly threadId: string;
|
|
76
|
+
readonly callId: string;
|
|
77
|
+
/**
|
|
78
|
+
* The `tool/call` row this invocation answers. The durable identity of the dispatch: unique in the
|
|
79
|
+
* journal and kept across a re-dispatch, where a provider's `callId` may be neither.
|
|
80
|
+
*/
|
|
81
|
+
readonly callSeq: Seq;
|
|
82
|
+
/**
|
|
83
|
+
* The `llm/request` row that produced this call: exactly what the model was sent when it asked.
|
|
84
|
+
* Where a tool that forks this thread cuts, so the fork shares that request's cached prefix.
|
|
85
|
+
* `null` only for a reply recorded without its request, which the loop never writes.
|
|
86
|
+
*/
|
|
87
|
+
readonly requestSeq: Seq | null;
|
|
88
|
+
/** Where this thread's work happens. */
|
|
89
|
+
readonly environment: ThreadEnvironment;
|
|
90
|
+
/**
|
|
91
|
+
* The route of the turn running the call, as its `turn/start` recorded it: the one its result is
|
|
92
|
+
* sent on next, and the route a new sub-agent the call starts inherits. `ctx.llm.capacity(route)`
|
|
93
|
+
* says what that result may carry.
|
|
94
|
+
*/
|
|
95
|
+
readonly route: ModelRoute;
|
|
96
|
+
/**
|
|
97
|
+
* `null` on a first dispatch; on a dispatch of a call whose wait resolved, what it waited on and
|
|
98
|
+
* the value it resolved with, from which the tool returns its result without doing the work again.
|
|
99
|
+
*/
|
|
100
|
+
readonly wait: ResolvedWait | null;
|
|
101
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ExtensionRecord, ThreadEnvironment, ToolResult } from '../models/index.js';
|
|
2
|
+
import type { ModelRoute, ToolCall } from '../llm/index.js';
|
|
3
|
+
import type { LoopRuntime } from './runtime.js';
|
|
4
|
+
export type ExecuteToolCallsOptions = {
|
|
5
|
+
runtime: LoopRuntime;
|
|
6
|
+
threadId: string;
|
|
7
|
+
agentName: string;
|
|
8
|
+
environment: ThreadEnvironment;
|
|
9
|
+
/** The turn's route, handed to each call. */
|
|
10
|
+
route: ModelRoute;
|
|
11
|
+
turn: number;
|
|
12
|
+
step: number;
|
|
13
|
+
calls: readonly ToolCall[];
|
|
14
|
+
signal: AbortSignal;
|
|
15
|
+
};
|
|
16
|
+
/** An error result for a call. */
|
|
17
|
+
export declare const errorResult: (call: ToolCall, output: string) => ToolResult;
|
|
18
|
+
/**
|
|
19
|
+
* Runs one step's tool calls.
|
|
20
|
+
*
|
|
21
|
+
* Dispatch overlaps inside a bounded pool, but results are appended in **model order**: the journal
|
|
22
|
+
* is what the next request is built from, so the order calls happen to settle in must not be able
|
|
23
|
+
* to reorder the conversation. A call that suspends leaves a hole: its group goes on, since its calls
|
|
24
|
+
* were declared independent, but no later group starts, and its result comes in a later turn, after
|
|
25
|
+
* its siblings'. Providers pair results by call id, so the conversation stays valid.
|
|
26
|
+
*
|
|
27
|
+
* Every result is appended only while its call is still unanswered, checked inside its write: a
|
|
28
|
+
* cancel answers a suspended call in its own write, perhaps while that call runs again.
|
|
29
|
+
*
|
|
30
|
+
* Returns nothing: what happened is in the journal. A call held for the user left a
|
|
31
|
+
* `confirm/requested`, a call whose tool suspended left a `wait/declared`, a call that ended the turn
|
|
32
|
+
* left it on its result, and a call that was never answered is simply missing a `tool/result`. The
|
|
33
|
+
* decider reads all of them from there, so there is no outcome to hand back and no chance of the two
|
|
34
|
+
* disagreeing.
|
|
35
|
+
*/
|
|
36
|
+
export declare function executeToolCalls(options: ExecuteToolCallsOptions): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Declares the `ext` rows of one plugin event state a `lagent/tool/authorize` listener decides
|
|
39
|
+
* from: one that lands while a call is authorized sends the decision round again, which no other
|
|
40
|
+
* `ext` row does. `defineExtensionEvent({ policyState: true })` is the way in.
|
|
41
|
+
*/
|
|
42
|
+
export declare function declarePolicyState(record: Pick<ExtensionRecord, 'plugin' | 'instance_id' | 'kind'>): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AppendEntry } from '../journal/index.js';
|
|
2
|
+
import type { RunChain } from '../models/index.js';
|
|
3
|
+
import type { PendingRun } from './requests.js';
|
|
4
|
+
import { type RouteAuthority, type RouteStatement } from './route.js';
|
|
5
|
+
/**
|
|
6
|
+
* How a write asks its thread to run: the cause it records beside what it brings. A person's wake
|
|
7
|
+
* names no authority: it releases the failure, cancellation and startup holds, and its turns are a
|
|
8
|
+
* person's. A plugin's names its own: `releases` whether it releases those holds, a person's or a
|
|
9
|
+
* host's authority, and `chain` how a turn it opens counts. Either may state the route it runs on
|
|
10
|
+
* (`RouteStatement`).
|
|
11
|
+
*/
|
|
12
|
+
export type Wake = {
|
|
13
|
+
readonly route?: RouteStatement;
|
|
14
|
+
} & ({
|
|
15
|
+
readonly releases?: undefined;
|
|
16
|
+
readonly chain?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
readonly releases: boolean;
|
|
19
|
+
readonly chain: RunChain;
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* The rows that record `wake` on a thread whose pending request is `pending`, built inside the
|
|
23
|
+
* write that brings it, which read `pending` there: a `run/requested` when none is pending, then
|
|
24
|
+
* the cause, naming the input it brought, if any, and the route it changed the thread to, if it did;
|
|
25
|
+
* and the run the cause joins or opens. A route statement is checked by `routes`, the thread owner,
|
|
26
|
+
* which is the one guard on every route-changing write; a refusal throws, refusing the whole write.
|
|
27
|
+
* A write with no `routes` (a thread's opening group, a plugin's resolution) takes no statement.
|
|
28
|
+
*/
|
|
29
|
+
export declare function causeRows(threadId: string, pending: PendingRun | null, wake: Wake, inputId: string | null, routes?: RouteAuthority): {
|
|
30
|
+
readonly runId: string;
|
|
31
|
+
readonly rows: AppendEntry[];
|
|
32
|
+
};
|
|
@@ -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,18 @@
|
|
|
1
|
+
import type { PromptBlock } from '../../llm/index.js';
|
|
2
|
+
export type TaggedSection = {
|
|
3
|
+
tag: string;
|
|
4
|
+
content: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A prompt as `ctx.prompts` assembles it: the agent's base prompt, then instruction sections, then
|
|
8
|
+
* context sections, so a section's bucket is what decides its position. The rendered result is
|
|
9
|
+
* recorded per thread.
|
|
10
|
+
*/
|
|
11
|
+
export type SystemPrompt = {
|
|
12
|
+
basePrompt: string;
|
|
13
|
+
instructions: TaggedSection[];
|
|
14
|
+
contextSections: TaggedSection[];
|
|
15
|
+
};
|
|
16
|
+
/** The prompt as ordered blocks — the one place its order is decided. */
|
|
17
|
+
export declare function systemPromptBlocks(prompt: SystemPrompt): PromptBlock[];
|
|
18
|
+
export declare const renderSystemPrompt: (prompt: SystemPrompt) => string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@leuduan/lagent/models`: the serialized contract, what a reader of the journal or a plugin writing
|
|
3
|
+
* rows needs. Journal rows, the types a row mentions, the helpers that read and write them and the
|
|
4
|
+
* JSON types they are written in. The Zod schemas, the tables the types derive from and the
|
|
5
|
+
* hand-written agent and prompt configuration stay inside (`index.ts`).
|
|
6
|
+
*/
|
|
7
|
+
export { isForkSpawn, isSurfaceEvent, parseJournalEvent, queuedInput, stepContribution } from './wire/journal.js';
|
|
8
|
+
export type { CancelIntent, ConfirmationDescriptor, ExtensionRecord, InboxTarget, InitialInstallation, InputRole, Installation, InstallationLifetime, InterruptionPolicy, JournalEvent, JournalEventData, JournalEventInput, JournalEventType, OriginCause, QueuedInput, ReplacementKind, ReplacementTrigger, RunChain, RunOutcomeKind, RunSettledReason, Seq, StepContribution, StepContributionInput, SurfaceEventType, ThreadEnvironment, ThreadFork, ThreadInput, ThreadOrigin, ThreadSummary, TurnEndReason, TurnRejection, WaitDescriptor, } from './wire/journal.js';
|
|
9
|
+
export { toolResultMessageContent } from './wire/primitives.js';
|
|
10
|
+
export type { ToolResult, ToolResultPayload, ToolResultPayloadInput } from './wire/primitives.js';
|
|
11
|
+
export { toJsonSchema } from './jsonSchema.js';
|
|
12
|
+
export type { DeepReadonly, JsonValue, ReadonlyJsonValue } from '../util/json.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"../chunks/UKXMCHHT.js";import{f as o,l as t,m as r,q as n,r as s,s as p}from"../chunks/KESCTXGO.js";import"../chunks/TYTQRLTX.js";import"../chunks/D7E6EWIE.js";export{s as isForkSpawn,p as isSurfaceEvent,n as parseJournalEvent,t as queuedInput,r as stepContribution,e as toJsonSchema,o as toolResultMessageContent};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** `wire/` is what gets serialized (snake_case); `config/` is what you write by hand (camelCase). */
|
|
2
|
+
export * from './config/agent.js';
|
|
3
|
+
export * from './config/prompt.js';
|
|
4
|
+
export * from './jsonSchema.js';
|
|
5
|
+
export * from './wire/journal.js';
|
|
6
|
+
export * from './wire/primitives.js';
|
|
7
|
+
export type { DeepReadonly, JsonValue, ReadonlyJsonValue } from '../util/json.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* JSON Schema for a validation schema, as advertised to the model. Uses the input shape, so
|
|
4
|
+
* defaulted fields stay optional, and every advertised schema is derived from the one that
|
|
5
|
+
* actually validates — the two can never drift.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toJsonSchema(schema: z.ZodType): Record<string, unknown>;
|