@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,46 @@
|
|
|
1
|
+
import type { RunChain, Seq } from '../models/index.js';
|
|
2
|
+
import type { Reducer } from './threadState.js';
|
|
3
|
+
/** An inputless cause not yet consumed: the run whose next turn it classifies, `null` once carried. */
|
|
4
|
+
type InputlessCause = {
|
|
5
|
+
readonly seq: Seq;
|
|
6
|
+
readonly runId: string | null;
|
|
7
|
+
readonly chain: RunChain;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A thread's chain of unattended work, folded from its causes, claims and turns: core's
|
|
11
|
+
* {@link ChainState} concern of `threadState`, which a fork starts over.
|
|
12
|
+
*
|
|
13
|
+
* The rules, a turn's class and the count of reactive turns in a row, are in
|
|
14
|
+
* `docs/lifecycle.md#the-chain`. What only this fold fixes: a later weaker claim never lowers a
|
|
15
|
+
* class, a request extended while it runs is not a claim, and the count is provisional while a
|
|
16
|
+
* `reactive` turn is open and final at its `turn/end`, by the class it ended with.
|
|
17
|
+
*/
|
|
18
|
+
export type ChainState = {
|
|
19
|
+
/** The chain a cause with an input named, by input id, until a step claims that input or it is discarded. */
|
|
20
|
+
readonly byInput: Map<string, RunChain>;
|
|
21
|
+
/**
|
|
22
|
+
* Inputless causes not consumed yet, in order. Each is consumed once, by the first turn on its
|
|
23
|
+
* run that opens after it; a settlement carries the ones it names as residual to the successor,
|
|
24
|
+
* and the rest retire.
|
|
25
|
+
*/
|
|
26
|
+
inputless: readonly InputlessCause[];
|
|
27
|
+
/** The turn open, if any, and the strongest class it received. */
|
|
28
|
+
open: {
|
|
29
|
+
readonly turn: number;
|
|
30
|
+
readonly class: RunChain | null;
|
|
31
|
+
} | null;
|
|
32
|
+
/** Reactive turns in a row since the last `person` or `fresh` authority, committed ones only. */
|
|
33
|
+
count: number;
|
|
34
|
+
};
|
|
35
|
+
export declare const chain: Reducer<ChainState>;
|
|
36
|
+
/** Where a thread's chain stands, as `ctx.threads.chain` reads it. */
|
|
37
|
+
export type ChainStanding = {
|
|
38
|
+
/** Whether the turn open now has received a person's authority; `false` between turns. */
|
|
39
|
+
readonly personTurn: boolean;
|
|
40
|
+
/** Reactive turns in a row, the open one counted if it is reactive. */
|
|
41
|
+
readonly turns: number;
|
|
42
|
+
/** Whether `turns` has reached the limit: a producer of more unattended work is refused. */
|
|
43
|
+
readonly atLimit: boolean;
|
|
44
|
+
};
|
|
45
|
+
export declare function chainStanding(state: ChainState, limit: number): ChainStanding;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LLMStreamChunk } from '../llm/index.js';
|
|
2
|
+
/** One delta off a model stream, with enough context for a frontend to place it. */
|
|
3
|
+
export type StreamedChunk = {
|
|
4
|
+
readonly thread_id: string;
|
|
5
|
+
readonly llm_call_id: string;
|
|
6
|
+
readonly turn: number;
|
|
7
|
+
readonly step: number;
|
|
8
|
+
readonly chunk: LLMStreamChunk;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The model's output as it arrives, published to whoever is watching and then forgotten.
|
|
12
|
+
*
|
|
13
|
+
* Deliberately not part of the journal. Nothing folds a chunk — the assistant message carries the same
|
|
14
|
+
* text once the stream ends — so keeping them in the journal only made history depend on a persistence
|
|
15
|
+
* setting: with chunks dropped on write, a live session and a reopened one read back different
|
|
16
|
+
* events. The journal is what happened; this is what it looked like happening.
|
|
17
|
+
*
|
|
18
|
+
* A frontend that wants to replay streaming can subscribe here and keep its own record.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ChunkChannel {
|
|
21
|
+
private readonly listeners;
|
|
22
|
+
private readonly report;
|
|
23
|
+
constructor(report: (error: unknown) => void);
|
|
24
|
+
/** One frozen copy of the chunk for every listener, so no listener can change what the next one sees. */
|
|
25
|
+
emit(chunk: StreamedChunk): void;
|
|
26
|
+
subscribe(listener: (chunk: StreamedChunk) => void): () => void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { CancelIntent, InterruptionCause, JsonValue, RunOutcomeKind, RunSettledReason, Seq, TurnEndReason } from '../models/index.js';
|
|
2
|
+
import { type DeepReadonly } from '../util/json.js';
|
|
3
|
+
import type { DerivedHold, Hold } from './holds.js';
|
|
4
|
+
import type { PendingRun } from './requests.js';
|
|
5
|
+
import type { ThreadState } from './threadState.js';
|
|
6
|
+
/**
|
|
7
|
+
* What a registered constraint says of a thread's pending request: `allow`; `hold` with why (`reason`,
|
|
8
|
+
* in words) and, optionally, a machine-readable `code` and `data`, until the feature calls `changed`;
|
|
9
|
+
* or `obsolete`, the request's authority gone for good: it settles `superseded` once nothing of it is
|
|
10
|
+
* left to drain.
|
|
11
|
+
*/
|
|
12
|
+
export type ConstraintAnswer = {
|
|
13
|
+
readonly kind: 'allow';
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'hold';
|
|
16
|
+
readonly reason: string;
|
|
17
|
+
readonly code?: string;
|
|
18
|
+
readonly data?: JsonValue;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: 'obsolete';
|
|
21
|
+
readonly reason: string;
|
|
22
|
+
};
|
|
23
|
+
/** An answer as the decision reads it: core stamps the registration's `owner` onto a hold. */
|
|
24
|
+
export type OwnedAnswer = Exclude<ConstraintAnswer, {
|
|
25
|
+
readonly kind: 'hold';
|
|
26
|
+
}> | (Extract<ConstraintAnswer, {
|
|
27
|
+
readonly kind: 'hold';
|
|
28
|
+
}> & {
|
|
29
|
+
readonly owner: string;
|
|
30
|
+
});
|
|
31
|
+
/** What the work on a thread looks like to the decision: the folds' answers, read as it decides. */
|
|
32
|
+
export type WorkSnapshot = {
|
|
33
|
+
/** Whether a run would find something to do (`hasThreadWork`). */
|
|
34
|
+
readonly hasWork: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether input waits for the next step: steering that arrived during the turn just ended, or a
|
|
37
|
+
* report its sender queued for the next step, which a turn that ran out answering calls left.
|
|
38
|
+
*/
|
|
39
|
+
readonly nextStepQueued: boolean;
|
|
40
|
+
/** Whether any input waits, for a step or a turn. */
|
|
41
|
+
readonly anyQueued: boolean;
|
|
42
|
+
/** Whether the conversation holds calls with no answer. */
|
|
43
|
+
readonly unanswered: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** How a turn ended, as a continuation decision reads it: its kind, and for an interruption its cause. */
|
|
46
|
+
export type Ending = {
|
|
47
|
+
readonly kind: Exclude<TurnEndReason['kind'], 'interrupted'>;
|
|
48
|
+
} | {
|
|
49
|
+
readonly kind: 'interrupted';
|
|
50
|
+
readonly cause: InterruptionCause;
|
|
51
|
+
};
|
|
52
|
+
/** Everything one continuation decision reads. No clock, I/O or callback. */
|
|
53
|
+
export type ContinuationInput = {
|
|
54
|
+
readonly pending: PendingRun;
|
|
55
|
+
/** How the execution's last turn ended; `null` at the execution's entry, or for an idle thread. */
|
|
56
|
+
readonly ending: Ending | null;
|
|
57
|
+
/**
|
|
58
|
+
* The repairs the request may still spend on interrupted turns, read from its durable count
|
|
59
|
+
* (`repairsLeft`), so a crash, a hold or a new execution neither grants nor loses one.
|
|
60
|
+
*/
|
|
61
|
+
readonly repairsLeft: number;
|
|
62
|
+
readonly work: WorkSnapshot;
|
|
63
|
+
/**
|
|
64
|
+
* Whether a confirmation on the thread or under it was answered since its last turn began: what
|
|
65
|
+
* the next turn carries to the call that parked on it.
|
|
66
|
+
*/
|
|
67
|
+
readonly answeredUnder: boolean;
|
|
68
|
+
/** The derived holds on the request, as `deriveHolds` orders them. */
|
|
69
|
+
readonly holds: readonly DerivedHold[];
|
|
70
|
+
/** What the constraints the thread is under say, combined; `allow` with none. */
|
|
71
|
+
readonly constraint: OwnedAnswer;
|
|
72
|
+
/** The intent of the cancel that captured this execution, if one did. */
|
|
73
|
+
readonly cancel: CancelIntent | null;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* What a thread does next with its pending request: run another turn (`advance`); end the
|
|
77
|
+
* execution with the request still pending (`hold`, `shutdown` when an abort that no cancel
|
|
78
|
+
* captured ended it); settle the request with an outcome; or rerun the interrupted turn (`repair`),
|
|
79
|
+
* when plugins, or what its judgment was fenced on, changed under it.
|
|
80
|
+
*/
|
|
81
|
+
export type Continuation = {
|
|
82
|
+
readonly kind: 'advance';
|
|
83
|
+
} | {
|
|
84
|
+
readonly kind: 'hold';
|
|
85
|
+
readonly hold: Hold;
|
|
86
|
+
} | {
|
|
87
|
+
readonly kind: 'settle';
|
|
88
|
+
readonly outcome: RunOutcomeKind;
|
|
89
|
+
readonly reason: RunSettledReason;
|
|
90
|
+
} | {
|
|
91
|
+
readonly kind: 'repair';
|
|
92
|
+
};
|
|
93
|
+
/** How a cancel settles the run it reaches: a person's `cancelled`, a feature's cleanup `superseded`. */
|
|
94
|
+
export declare const cancelOutcome: (intent: CancelIntent) => RunOutcomeKind;
|
|
95
|
+
/** The repairs left to a request whose rows fold to `requests`: one, less one per interrupted turn since a releasing cause, after the first. */
|
|
96
|
+
export declare const repairsLeft: (requests: {
|
|
97
|
+
readonly interruptions: number;
|
|
98
|
+
}) => number;
|
|
99
|
+
/** A constraint's hold as the hold on the request: its answer, the owner that gave it stamped. */
|
|
100
|
+
export declare function constraintHold(answer: Extract<OwnedAnswer, {
|
|
101
|
+
readonly kind: 'hold';
|
|
102
|
+
}>): Hold;
|
|
103
|
+
/**
|
|
104
|
+
* The one continuation decision, at an idle thread and at every turn boundary of an execution. It
|
|
105
|
+
* replaces the loop's own branch after a turn, and every host's rule for running a thread again;
|
|
106
|
+
* the turn and step decider underneath (`nextAction`) is unchanged. In order:
|
|
107
|
+
*
|
|
108
|
+
* 1. A cancel that captured the execution settles it by its intent; a constraint that calls the
|
|
109
|
+
* request obsolete settles it `superseded`.
|
|
110
|
+
* 2. How the last turn ended: an abort no cancel captured is a shutdown, leaving the request
|
|
111
|
+
* pending; an interrupted turn holds for any current hold (a repair would run the turn again
|
|
112
|
+
* under it), and otherwise is repaired while the execution has a repair left. Once none is, a
|
|
113
|
+
* turn whose activation changed fails the request, and one whose judgment was invalidated (a
|
|
114
|
+
* transient race with the facts it judged) leaves it held until the next releasing cause, the
|
|
115
|
+
* answer still owed its checks; a turn recovery closed goes on as at an entry. An error fails the
|
|
116
|
+
* request, as a failure before any turn does (`setup`); out of steps or a rejected answer goes
|
|
117
|
+
* on only for input waiting for the next step (`nextStep`), and fails otherwise; a blocked
|
|
118
|
+
* turn holds on an approval still waiting unless an answer under the thread landed since it
|
|
119
|
+
* began, and otherwise decides as below; a completed turn goes on while input waits, and settles
|
|
120
|
+
* `completed` otherwise.
|
|
121
|
+
* 3. Going on, or at the entry: the derived holds (past an approval hold when an answer landed
|
|
122
|
+
* since the last turn began; a wait holds whatever landed), then the constraint's own hold, then
|
|
123
|
+
* whether a run would find work at all. One that would not still holds on an approval waiting,
|
|
124
|
+
* and otherwise settles as its last turn ended, or `completed` with nothing done. A blocked turn
|
|
125
|
+
* whose calls nothing holds and none can be dispatched breaks the rules the holds keep: the
|
|
126
|
+
* decision throws.
|
|
127
|
+
*/
|
|
128
|
+
export declare function continuation(input: ContinuationInput): Continuation;
|
|
129
|
+
/**
|
|
130
|
+
* The run a cancel's own write settles, by its intent: the request pending when the write lands,
|
|
131
|
+
* unless it is the run of the execution the cancel captured, whose finalization settles it. That is
|
|
132
|
+
* the pending run of an idle thread, or a successor the captured execution's finalization already
|
|
133
|
+
* opened from residual causes.
|
|
134
|
+
*/
|
|
135
|
+
export declare function cancelWriteSettles(pending: PendingRun | null, capturedRunId: string | null): string | null;
|
|
136
|
+
/** A turn a run served: how it ended, its `turn/start`, and the attempt cutoff of the execution that opened it. */
|
|
137
|
+
export type ServedTurn = {
|
|
138
|
+
readonly ending: DeepReadonly<TurnEndReason>;
|
|
139
|
+
readonly start: Seq;
|
|
140
|
+
readonly attemptCutoff: Seq;
|
|
141
|
+
};
|
|
142
|
+
/** The thread's last turn when it served `runId` and has ended. */
|
|
143
|
+
export declare function lastTurn(state: ThreadState, runId: string): ServedTurn | null;
|
|
144
|
+
/**
|
|
145
|
+
* The thread's last turn when it served `runId` and ended, as a resumed run re-enters from it: a
|
|
146
|
+
* crash between a failed turn and its settlement fails the run, carrying the causes that release
|
|
147
|
+
* the failure to a successor, rather than retry it under the failed run. A turn that a shutdown
|
|
148
|
+
* aborted, or that recovery abandoned, is no ending to decide from: the run goes on. Nor is a turn that did not fail when a releasing cause came after it: a person who asked
|
|
149
|
+
* since would have opened a request of their own, had the run settled first. That includes an
|
|
150
|
+
* interrupted turn, its activation changed or its judgment invalidated: until a releasing cause
|
|
151
|
+
* lands, it is the ending the run is repaired from, held on or failed by, as its spent repairs say.
|
|
152
|
+
*/
|
|
153
|
+
export declare function resumedTurn(state: ThreadState, runId: string): ServedTurn | null;
|
|
154
|
+
/** Where a continuation decision reads the last turn from: how it ended (`null` before any) and where it began. */
|
|
155
|
+
export type DecisionTurn = {
|
|
156
|
+
readonly ending: Ending | null;
|
|
157
|
+
readonly start: Seq | null;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* The turn the decision at an execution's entry, or one made before admitting a run, reads: the
|
|
161
|
+
* ending of a turn that served the pending run when a crash or a hold left it there (`resumed`),
|
|
162
|
+
* and otherwise where the thread's last turn began, so an answer since counts.
|
|
163
|
+
*/
|
|
164
|
+
export declare function entryTurn(state: ThreadState): DecisionTurn & {
|
|
165
|
+
readonly resumed: ServedTurn | null;
|
|
166
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { QueuedInput, Seq, TurnEndReason } from '../models/index.js';
|
|
2
|
+
import type { ToolCall } from '../llm/index.js';
|
|
3
|
+
import type { TurnLimits } from './limits.js';
|
|
4
|
+
/**
|
|
5
|
+
* What one thread looks like at a decision point. Not the public `ThreadView` read.
|
|
6
|
+
*
|
|
7
|
+
* Every field is a fold of the journal but one input: which queue the boundary reads and whether a
|
|
8
|
+
* stop check sent back the answer of a turn that opened by answering calls (`decisionView`'s
|
|
9
|
+
* `target` and `sentBack`), which the loop remembers for the turn. A crash closes the turn, and a new
|
|
10
|
+
* turn starts both afresh, so a journal that stops anywhere still decides the same way.
|
|
11
|
+
*/
|
|
12
|
+
export type DecisionView = {
|
|
13
|
+
/** Input waiting at this boundary. */
|
|
14
|
+
readonly queued: readonly QueuedInput[];
|
|
15
|
+
/** Calls the conversation has no answer for. */
|
|
16
|
+
readonly unanswered: readonly ToolCall[];
|
|
17
|
+
/** Of those, the ones that cannot be dispatched now: waiting on a confirmation, or on a wait not resolved. */
|
|
18
|
+
readonly parked: readonly ToolCall[];
|
|
19
|
+
/** Whether the conversation ends on something the model has not replied to. */
|
|
20
|
+
readonly owed: boolean;
|
|
21
|
+
/** Whether a tool result asked for this turn to stop. */
|
|
22
|
+
readonly concluded: boolean;
|
|
23
|
+
/** The answer the conversation ends on, while no stop check has accepted or rejected it. */
|
|
24
|
+
readonly provisional: Seq | null;
|
|
25
|
+
/** Steps already taken in this turn. */
|
|
26
|
+
readonly step: number;
|
|
27
|
+
};
|
|
28
|
+
export type Action =
|
|
29
|
+
/** Run these, then decide again. */
|
|
30
|
+
{
|
|
31
|
+
kind: 'answer-calls';
|
|
32
|
+
calls: readonly ToolCall[];
|
|
33
|
+
}
|
|
34
|
+
/** Record this input, ask the model, then decide again. */
|
|
35
|
+
| {
|
|
36
|
+
kind: 'ask-model';
|
|
37
|
+
claim: readonly QueuedInput[];
|
|
38
|
+
}
|
|
39
|
+
/** Ask the stop checks to judge the provisional answer. */
|
|
40
|
+
| {
|
|
41
|
+
kind: 'check';
|
|
42
|
+
}
|
|
43
|
+
/** Stop, for this reason. */
|
|
44
|
+
| {
|
|
45
|
+
kind: 'end';
|
|
46
|
+
reason: TurnEndReason;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* What a thread does next.
|
|
50
|
+
*
|
|
51
|
+
* A pure function of the view, so the whole of the loop's control flow is a truth table rather than
|
|
52
|
+
* something you need a model, a store and a clock to exercise. The loop is then: decide, do it,
|
|
53
|
+
* append what happened, decide again — which is why resuming needs no separate path. A journal that
|
|
54
|
+
* stops mid-turn produces a view like any other, and the same decision picks it up.
|
|
55
|
+
*
|
|
56
|
+
* Deliberately absent: what to do when a model call *fails*. A transient failure before any output
|
|
57
|
+
* is retried beneath the loop, by `ctx.llm`'s client under the provider's policy; one that still
|
|
58
|
+
* fails ends the turn, reported with its kind, and whether to run it again is the host's. Request
|
|
59
|
+
* middleware cannot retry: it may call `next()` once. A decider that could see a failure and ask
|
|
60
|
+
* again would spin on a provider outage, since the conversation it reads is unchanged by one.
|
|
61
|
+
*/
|
|
62
|
+
export declare function nextAction(view: DecisionView, limits: TurnLimits): Action;
|
|
63
|
+
/** Whether there is anything to do at all — the same decision, asked as a question. */
|
|
64
|
+
export declare const hasWork: (view: DecisionView, limits: TurnLimits) => boolean;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { ReadonlyJsonValue } from '../util/json.js';
|
|
2
|
+
import type { Refusal } from './inbox.js';
|
|
3
|
+
import type { ReplacementRule, RowRef } from './surface.js';
|
|
4
|
+
/** What holds a thread while an operation on it is refused busy. */
|
|
5
|
+
export type ThreadHolding = 'run' | 'compact' | 'rebuild' | 'configure' | 'release' | 'cancel';
|
|
6
|
+
/** A human's answer to an approval request. */
|
|
7
|
+
export type ApprovalDecision = {
|
|
8
|
+
readonly approved: boolean;
|
|
9
|
+
readonly rejection_message: string | null;
|
|
10
|
+
};
|
|
11
|
+
/** No agent is registered under this name. */
|
|
12
|
+
export declare class UnknownAgentError extends ReferenceError {
|
|
13
|
+
readonly agentName: string;
|
|
14
|
+
constructor(agentName: string);
|
|
15
|
+
}
|
|
16
|
+
/** No thread has this id. */
|
|
17
|
+
export declare class UnknownThreadError extends ReferenceError {
|
|
18
|
+
readonly threadId: string;
|
|
19
|
+
constructor(threadId: string);
|
|
20
|
+
}
|
|
21
|
+
/** A turn is already running on this thread; one driver at a time. */
|
|
22
|
+
export declare class ThreadBusyError extends Error {
|
|
23
|
+
readonly threadId: string;
|
|
24
|
+
readonly holding?: ThreadHolding;
|
|
25
|
+
/** @param holding - what holds the thread, when known: `run`, `compact`, `rebuild`, `configure`, `release` or `cancel`. */
|
|
26
|
+
constructor(threadId: string, holding?: ThreadHolding);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A configuration change was recorded, but the thread's plugins could not be restored from it: the
|
|
30
|
+
* thread is configured as asked and cannot run until a later change lets it restore. `cause` is
|
|
31
|
+
* the setup's error.
|
|
32
|
+
*/
|
|
33
|
+
export declare class RestoreFailedError extends Error {
|
|
34
|
+
readonly threadId: string;
|
|
35
|
+
constructor(threadId: string, cause: unknown);
|
|
36
|
+
}
|
|
37
|
+
/** Creating this thread would nest deeper than `maxThreadDepth` allows. */
|
|
38
|
+
export declare class DepthExceededError extends Error {
|
|
39
|
+
readonly threadId: string;
|
|
40
|
+
readonly limit: number;
|
|
41
|
+
constructor(threadId: string, limit: number);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Thrown inside a step whose activation went stale before its dispatch, or by a judgment once the
|
|
45
|
+
* activation went stale under it: the turn ends `interrupted` (`activation-changed`).
|
|
46
|
+
*/
|
|
47
|
+
export declare class StaleActivation extends Error {
|
|
48
|
+
constructor();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Thrown by a judgment whose fence broke while the activation stayed valid (`LoopAgent.fenced`): a
|
|
52
|
+
* required registration is gone or was replaced, or a fact a stop check declared it observed
|
|
53
|
+
* changed. The turn ends `interrupted` (`judgment-invalidated`), the answer still owed its checks.
|
|
54
|
+
*/
|
|
55
|
+
export declare class JudgmentInvalidated extends Error {
|
|
56
|
+
constructor();
|
|
57
|
+
}
|
|
58
|
+
/** A turn that failed after appending its own `turn/end`; the journal already says what happened. */
|
|
59
|
+
export declare class RecordedTurnFailure extends Error {
|
|
60
|
+
readonly cause: unknown;
|
|
61
|
+
constructor(cause: unknown);
|
|
62
|
+
}
|
|
63
|
+
/** A fork was asked for at a row it cannot be cut at; nothing was appended. */
|
|
64
|
+
export declare class ForkCutError extends Error {
|
|
65
|
+
readonly threadId: string;
|
|
66
|
+
readonly seq: number;
|
|
67
|
+
constructor(threadId: string, seq: number, reason: string);
|
|
68
|
+
}
|
|
69
|
+
/** What a thread's recorded birth says about one field of a request that differs from it. */
|
|
70
|
+
export type BirthConflict = {
|
|
71
|
+
readonly field: 'agent' | 'origin' | 'kind' | 'cut' | 'route' | 'environment' | 'installations' | 'requires';
|
|
72
|
+
/** What the thread recorded: for `kind`, `fresh` or `fork`. */
|
|
73
|
+
readonly recorded: ReadonlyJsonValue;
|
|
74
|
+
readonly requested: ReadonlyJsonValue;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* A creation or fork asked for an id a thread already holds, and the request is not that thread:
|
|
78
|
+
* under `identity` reuse its agent, origin, kind or cut differ, under `configuration` its birth
|
|
79
|
+
* does too. Never adopted, nothing was written; `conflicts` name every field that differs.
|
|
80
|
+
*/
|
|
81
|
+
export declare class BirthConflictError extends Error {
|
|
82
|
+
readonly threadId: string;
|
|
83
|
+
readonly conflicts: readonly BirthConflict[];
|
|
84
|
+
constructor(threadId: string, conflicts: readonly BirthConflict[]);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A `create` or `fork` whose write-time `rows` callback vetoed it: nothing was recorded. The
|
|
88
|
+
* callback's own {@link Refusal} is `refusal`; an error the callback threw is not this, it propagates
|
|
89
|
+
* as it was thrown.
|
|
90
|
+
*/
|
|
91
|
+
export declare class WriteRefusedError extends Error {
|
|
92
|
+
readonly refusal: Refusal;
|
|
93
|
+
readonly operation: 'create' | 'fork';
|
|
94
|
+
constructor(refusal: Refusal, operation: 'create' | 'fork');
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A change of a thread's installations was asked while its activation is still getting ready: the
|
|
98
|
+
* change would wait on the setup it came from. Nothing was recorded; `whenReady()` or `close()` the
|
|
99
|
+
* thread first.
|
|
100
|
+
*/
|
|
101
|
+
export declare class ThreadActivatingError extends Error {
|
|
102
|
+
readonly threadId: string;
|
|
103
|
+
constructor(threadId: string);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* An answer to a confirmation that already has one, which it carries. Core compares nothing: a retry
|
|
107
|
+
* that repeats the recorded answer is refused like any other, and the caller decides whether the
|
|
108
|
+
* recorded decision is the one it meant. A revoked approval is a recorded rejection.
|
|
109
|
+
*/
|
|
110
|
+
export declare class ConfirmationAnsweredError extends Error {
|
|
111
|
+
readonly threadId: string;
|
|
112
|
+
readonly requestId: string;
|
|
113
|
+
readonly decision: ApprovalDecision;
|
|
114
|
+
constructor(threadId: string, requestId: string, decision: ApprovalDecision);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The thread is not settled enough for what was asked: a request to prepare its surface or a change
|
|
118
|
+
* of its installations met a tool call without a result, a confirmation unfinished (open, or
|
|
119
|
+
* approved and not yet executed; the reason names its request ids) or an answer its stop checks have
|
|
120
|
+
* not judged. Nothing was recorded: no replacement or auxiliary call, no installation change.
|
|
121
|
+
*/
|
|
122
|
+
export declare class ThreadUnsettledError extends Error {
|
|
123
|
+
readonly threadId: string;
|
|
124
|
+
constructor(threadId: string, reason: string);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A replacement `replaceSurface` refused: it breaks a rule of the surface it would land on (see
|
|
128
|
+
* `judgeReplacement`). Nothing of its group was recorded. Distinct from any other failure, so a
|
|
129
|
+
* strategy can tell a plan the surface refused from a journal that could not write.
|
|
130
|
+
*/
|
|
131
|
+
export declare class ReplacementRefusedError extends Error {
|
|
132
|
+
readonly index: number;
|
|
133
|
+
readonly rule: ReplacementRule;
|
|
134
|
+
constructor(message: string,
|
|
135
|
+
/** The refused replacement's position in the group it was offered with. */
|
|
136
|
+
index: number,
|
|
137
|
+
/** The surface rule it breaks. */
|
|
138
|
+
rule: ReplacementRule);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A thread whose surface refused a replacement row, one written past `replaceSurface`: a bug or a
|
|
142
|
+
* hand-edited store. Its history can be read, and forked before that row, but nothing executes on
|
|
143
|
+
* it: not a run, not a compaction, not the close of an interrupted turn. What only records, a
|
|
144
|
+
* configuration change or a prompt rebuild, is not execution and is not refused.
|
|
145
|
+
*/
|
|
146
|
+
export declare class CorruptHistoryError extends Error {
|
|
147
|
+
readonly threadId: string;
|
|
148
|
+
readonly row: RowRef;
|
|
149
|
+
readonly reason: string;
|
|
150
|
+
constructor(threadId: string,
|
|
151
|
+
/** The first refused row; it may belong to the lineage a fork inherited. */
|
|
152
|
+
row: RowRef, reason: string);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* An auxiliary call the engine refused to send, because of how it was asked for: a prefix that does
|
|
156
|
+
* not end on a row of the current surface or that separates a tool call from its result, no
|
|
157
|
+
* instructions, or no route. Nothing was recorded or sent; it is the caller's error, never the
|
|
158
|
+
* model's.
|
|
159
|
+
*/
|
|
160
|
+
export declare class AuxiliaryRefusedError extends Error {
|
|
161
|
+
constructor(message: string);
|
|
162
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Journal } from '../journal/index.js';
|
|
2
|
+
import type { Seq, TurnEndReason } from '../models/index.js';
|
|
3
|
+
import type { RowRef } from './surface.js';
|
|
4
|
+
/**
|
|
5
|
+
* Where forks may be cut, and the lookups that find such a row from a turn or a reply. Journal
|
|
6
|
+
* reads only: forking never activates, leases or waits on the thread it forks.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Where "fork from here" cuts, along a thread's lineage: a turn's ending, or a replacement recorded
|
|
10
|
+
* between turns, such as a `compact()`, which a `turn/end` alone would miss. A replacement point
|
|
11
|
+
* carries the turn it followed, `null` when no turn had ended before it.
|
|
12
|
+
*/
|
|
13
|
+
export type ForkPoint = (RowRef & {
|
|
14
|
+
readonly kind: 'turn/end';
|
|
15
|
+
readonly turn: number;
|
|
16
|
+
readonly reason: TurnEndReason;
|
|
17
|
+
}) | (RowRef & {
|
|
18
|
+
readonly kind: 'surface/replaced';
|
|
19
|
+
readonly afterTurn: number | null;
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Resolves `at` on `sourceId` to the row a fork is cut at, and the thread that owns it.
|
|
23
|
+
*
|
|
24
|
+
* The row must be of a cut kind and belong to the source's lineage; a row the source inherited is
|
|
25
|
+
* redirected to the thread that owns it, so the fork becomes that thread's. A pair must name the
|
|
26
|
+
* owner. The cut must also be settled (see {@link unsettled}).
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveCut(journal: Journal, sourceId: string, at: Seq | RowRef): RowRef;
|
|
29
|
+
/**
|
|
30
|
+
* The cut for forking at the turn that contains `anchor`: that turn's `turn/end`, or with `before`
|
|
31
|
+
* its `turn/start` — after what the turn started with was recorded, such as the prompt of a first
|
|
32
|
+
* turn, a mode switch and the turn's route, and before any of its input.
|
|
33
|
+
*
|
|
34
|
+
* An anchor inside a turn that has not ended is rejected rather than clipped back to the turn
|
|
35
|
+
* before; `before` has no such problem, since it cuts ahead of the turn's input.
|
|
36
|
+
*/
|
|
37
|
+
export declare function turnCut(journal: Journal, threadId: string, anchor: Seq | RowRef, before: boolean): RowRef;
|
|
38
|
+
/**
|
|
39
|
+
* Every `turn/end` along a thread's lineage that a fork can be cut at, and every replacement recorded
|
|
40
|
+
* between turns, oldest first, with the thread that owns each. A turn that ended with a call
|
|
41
|
+
* unanswered, or with an answer still owed its stop checks, is left out. A replacement recorded
|
|
42
|
+
* inside a turn is not listed: its turn's ending follows it. One pass: the two folds are replayed
|
|
43
|
+
* along the lineage as they go.
|
|
44
|
+
*/
|
|
45
|
+
export declare function forkPoints(journal: Journal, threadId: string): ForkPoint[];
|
|
46
|
+
/**
|
|
47
|
+
* The `llm/request` that produced the reply recorded at `row`: the request with the same
|
|
48
|
+
* `llm_call_id`, searched on the thread that owns the reply. `null` for a row that is not a reply.
|
|
49
|
+
*/
|
|
50
|
+
export declare function requestBehind(journal: Journal, row: RowRef): RowRef | null;
|
|
51
|
+
/**
|
|
52
|
+
* The request behind the conversation's latest reply — the one whose tool calls a step is
|
|
53
|
+
* answering, and so the row a tool that forks this thread cuts at. `null` before any reply. A
|
|
54
|
+
* stand-in in the assistant role is not a reply: no request is behind it.
|
|
55
|
+
*/
|
|
56
|
+
export declare function latestReplyRequest(journal: Journal, threadId: string): RowRef | null;
|
|
57
|
+
/**
|
|
58
|
+
* The row of the conversation's latest reply: the `assistant/message` whose tool calls a step is
|
|
59
|
+
* answering, on a fork's source when the fork inherited it. `null` before any reply.
|
|
60
|
+
*/
|
|
61
|
+
export declare function latestReply(journal: Journal, threadId: string): RowRef | null;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { Seq } from '../models/index.js';
|
|
2
|
+
import type { ReadonlyState } from '../util/foldState.js';
|
|
3
|
+
import { type ReadonlyJsonValue } from '../util/json.js';
|
|
4
|
+
import type { RequestsState } from './requests.js';
|
|
5
|
+
/**
|
|
6
|
+
* Why a pending request does not run now. Every one is derived from recorded facts and live
|
|
7
|
+
* registrations, never stored:
|
|
8
|
+
*
|
|
9
|
+
* - `approval`: the thread's last turn ended blocked and a confirmation waits on it or under it;
|
|
10
|
+
* the answer releases it.
|
|
11
|
+
* - `failure`: the latest settlement failed and no releasing cause is pending.
|
|
12
|
+
* - `cancellation`: a person cancelled the thread, and no releasing cause came after.
|
|
13
|
+
* - `startup`: the startup policy declined the request at boot; a releasing cause releases it.
|
|
14
|
+
* - `missing`: a constraint owner the thread or a thread above it by origin requires is not
|
|
15
|
+
* registered, or its repair has not finished; or the callers above it cannot be read.
|
|
16
|
+
* - `wait`: a call of the thread waits on a dependency whose owner has not resolved it; only its
|
|
17
|
+
* resolution, or a cancel that answers the call, ends it. `deadline` is the owner's to act on.
|
|
18
|
+
* - `constraint`: a registered owner's constraint says not now, with the `code` and `data` it
|
|
19
|
+
* answered with; core stamps the `owner`.
|
|
20
|
+
* - `rejudge`: the judgment of the answer's stop checks was invalidated until the repair budget ran
|
|
21
|
+
* out; the answer stays owed its checks, and a releasing cause releases it.
|
|
22
|
+
* - `shutdown`: lagent is closing; the request stays pending for the next start.
|
|
23
|
+
*/
|
|
24
|
+
export type Hold = {
|
|
25
|
+
readonly reason: 'missing';
|
|
26
|
+
} | {
|
|
27
|
+
readonly reason: 'wait';
|
|
28
|
+
readonly callSeq: Seq;
|
|
29
|
+
readonly owner: string;
|
|
30
|
+
readonly ownerRegistered: boolean;
|
|
31
|
+
readonly deadline: number | null;
|
|
32
|
+
readonly text: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly reason: 'constraint';
|
|
35
|
+
readonly owner: string;
|
|
36
|
+
readonly code?: string;
|
|
37
|
+
readonly data?: ReadonlyJsonValue;
|
|
38
|
+
readonly text: string;
|
|
39
|
+
} | {
|
|
40
|
+
readonly reason: 'rejudge';
|
|
41
|
+
readonly text: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly reason: 'approval' | 'failure' | 'cancellation' | 'startup' | 'shutdown';
|
|
44
|
+
};
|
|
45
|
+
/** The reasons a hold can be read for while lagent runs: every one but `shutdown`. */
|
|
46
|
+
export type HoldReason = Exclude<Hold['reason'], 'shutdown'>;
|
|
47
|
+
/** The holds the folds and the catalog derive: those that neither a constraint nor a closing lagent made. */
|
|
48
|
+
export type DerivedHold = Exclude<Hold, {
|
|
49
|
+
readonly reason: 'constraint' | 'shutdown';
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Which look a hold was read from: `catalog`, the screening the catalog shows without loading the
|
|
53
|
+
* thread, or `loaded`, decided from the thread's folds.
|
|
54
|
+
*/
|
|
55
|
+
export type HoldBasis = 'catalog' | 'loaded';
|
|
56
|
+
/** Whether two holds say the same thing. */
|
|
57
|
+
export declare const sameHold: (a: Hold, b: Hold) => boolean;
|
|
58
|
+
/** What a hold says in words, for a reader that prints one: its text, or `null` when its reason says it all. */
|
|
59
|
+
export declare const holdText: (hold: Hold) => string | null;
|
|
60
|
+
/**
|
|
61
|
+
* What holds are derived from, read from the thread's folds or from its catalog entry, which record
|
|
62
|
+
* the same facts, and from the owner's registrations.
|
|
63
|
+
*/
|
|
64
|
+
export type HoldFacts = {
|
|
65
|
+
/** Whether the thread's last turn ended blocked and a confirmation waits on it or on a thread created under it. */
|
|
66
|
+
readonly approval: boolean;
|
|
67
|
+
/** Whether the latest settlement failed and no releasing cause is pending (`failureHeld`). */
|
|
68
|
+
readonly failed: boolean;
|
|
69
|
+
/** Whether a person's cancel holds the thread (`cancelHeld`). */
|
|
70
|
+
readonly cancelled: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the startup policy declined this request and no releasing cause landed since boot: the
|
|
73
|
+
* owner's to say, since a releasing cause recorded before the restart is one the policy judged.
|
|
74
|
+
*/
|
|
75
|
+
readonly startupDeclined: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The constraint owners the thread or a thread above it by origin requires that are not registered,
|
|
78
|
+
* or not repaired yet, with why; or that the callers above it cannot be read.
|
|
79
|
+
*/
|
|
80
|
+
readonly missing: readonly string[];
|
|
81
|
+
/**
|
|
82
|
+
* The thread's first wait that has not resolved, if any: its call, why it waits, its owner and
|
|
83
|
+
* deadline, and whether that owner is registered now.
|
|
84
|
+
*/
|
|
85
|
+
readonly unresolvedWait: {
|
|
86
|
+
readonly callSeq: Seq;
|
|
87
|
+
readonly reason: string;
|
|
88
|
+
readonly owner: string;
|
|
89
|
+
readonly deadlineAt: number | null;
|
|
90
|
+
readonly registered: boolean;
|
|
91
|
+
} | null;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* The holds on a thread's pending request, in the order a decision reads them: the one rule both
|
|
95
|
+
* the folds' decision and the owner's catalog reading apply. A request that holds a releasing cause
|
|
96
|
+
* is past the failure, cancellation and startup holds; the approval hold yields only to the answer
|
|
97
|
+
* itself, and the wait hold to the resolution. A constraint's own `hold` is not derived here: the
|
|
98
|
+
* decision reads its verdict.
|
|
99
|
+
*/
|
|
100
|
+
export declare function deriveHolds(facts: HoldFacts): DerivedHold[];
|
|
101
|
+
/** Whether a failure holds the thread: its latest settlement failed and no releasing cause is pending. */
|
|
102
|
+
export declare function failureHeld(requests: ReadonlyState<RequestsState>): boolean;
|
|
103
|
+
/** Whether a person's cancel holds the thread: its latest `user` cancel has no releasing cause after it. */
|
|
104
|
+
export declare function cancelHeld(requests: ReadonlyState<RequestsState>): boolean;
|