@leuduan/lagent 0.0.0-stage → 44.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +157 -2
- package/dist/chunks/2GCIWSOA.js +5 -0
- package/dist/chunks/2P47AHNK.js +7 -0
- package/dist/chunks/34KW6VNQ.js +1 -0
- package/dist/chunks/3UMZMPWW.js +1 -0
- package/dist/chunks/5IRF47YB.js +1 -0
- package/dist/chunks/6DRCKZ2C.js +1 -0
- package/dist/chunks/6FRNHMCV.js +1 -0
- package/dist/chunks/7LI64H5X.js +17 -0
- package/dist/chunks/7VAPNE3L.js +1 -0
- package/dist/chunks/ASSQZH3F.js +1 -0
- package/dist/chunks/B4FXK5ER.js +77 -0
- package/dist/chunks/BBCW2FZK.js +1 -0
- package/dist/chunks/BPRCULZH.js +1 -0
- package/dist/chunks/CANPZYTH.js +24 -0
- package/dist/chunks/CQEVREBT.js +1 -0
- package/dist/chunks/CUK7CGC7.js +1 -0
- package/dist/chunks/D4PQP5MA.js +3 -0
- package/dist/chunks/DDANMY45.js +3 -0
- package/dist/chunks/DDZ7YF26.js +1 -0
- package/dist/chunks/EMRB4KCN.js +6 -0
- package/dist/chunks/EPYQ5M3B.js +3 -0
- package/dist/chunks/FJLU4UH3.js +1 -0
- package/dist/chunks/G44LG6VL.js +1 -0
- package/dist/chunks/GGSVIIWJ.js +2 -0
- package/dist/chunks/HK6ZSONF.js +1 -0
- package/dist/chunks/IAAEP6VL.js +30 -0
- package/dist/chunks/JCTBX33H.js +36 -0
- package/dist/chunks/JFX2MXBA.js +4 -0
- package/dist/chunks/JFZZXVWD.js +15 -0
- package/dist/chunks/KUZCL2SH.js +1 -0
- package/dist/chunks/MHC6VPB4.js +7 -0
- package/dist/chunks/MMNNZCBO.js +5 -0
- package/dist/chunks/MNJ4SRF7.js +1 -0
- package/dist/chunks/N6IXG2VL.js +1 -0
- package/dist/chunks/OCBPT7KE.js +1 -0
- package/dist/chunks/OL5A6ITQ.js +1 -0
- package/dist/chunks/PUSUPTAT.js +1 -0
- package/dist/chunks/Q75FUN7D.js +2 -0
- package/dist/chunks/Q7S5LFGN.js +1 -0
- package/dist/chunks/RCIHV3KG.js +1 -0
- package/dist/chunks/S34ZA2R6.js +1 -0
- package/dist/chunks/SS3B5W34.js +12 -0
- package/dist/chunks/VYMT4TXD.js +1 -0
- package/dist/chunks/W57RW55W.js +1 -0
- package/dist/compositions/base.d.ts +11 -0
- package/dist/compositions/codex.d.ts +66 -0
- package/dist/compositions/codexPrompts.d.ts +56 -0
- package/dist/context.d.ts +109 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +1 -0
- package/dist/journal/catalog.d.ts +112 -0
- package/dist/journal/forkChain.d.ts +16 -0
- package/dist/journal/index.d.ts +15 -0
- package/dist/journal/journal.d.ts +475 -0
- package/dist/journal/projection.d.ts +87 -0
- package/dist/journal/store.d.ts +181 -0
- package/dist/llm/client.d.ts +135 -0
- package/dist/llm/content.d.ts +52 -0
- package/dist/llm/failure.d.ts +82 -0
- package/dist/llm/index.d.ts +22 -0
- package/dist/llm/index.js +1 -0
- package/dist/llm/primitives.d.ts +286 -0
- package/dist/llm/prompt.d.ts +21 -0
- package/dist/llm/provider.d.ts +74 -0
- package/dist/llm/readLedger.d.ts +24 -0
- package/dist/llm/request.d.ts +58 -0
- package/dist/loop/agent.d.ts +18 -0
- package/dist/loop/authorization.d.ts +41 -0
- package/dist/loop/auxiliary.d.ts +58 -0
- package/dist/loop/chunks.d.ts +27 -0
- package/dist/loop/completion.d.ts +17 -0
- package/dist/loop/errors.d.ts +139 -0
- package/dist/loop/hooks.d.ts +274 -0
- package/dist/loop/index.d.ts +16 -0
- package/dist/loop/runner.d.ts +134 -0
- package/dist/loop/runtime.d.ts +76 -0
- package/dist/loop/strategy.d.ts +80 -0
- package/dist/loop/surfacePrepare.d.ts +30 -0
- package/dist/loop/tool.d.ts +106 -0
- package/dist/loop/toolCalls.d.ts +35 -0
- package/dist/plugin.d.ts +50 -0
- package/dist/plugin.js +1 -0
- package/dist/plugins/agentsMd.d.ts +80 -0
- package/dist/plugins/agentsMd.js +1 -0
- package/dist/plugins/ask/index.d.ts +26 -0
- package/dist/plugins/ask/index.js +1 -0
- package/dist/plugins/ask/service.d.ts +125 -0
- package/dist/plugins/ask/tools.d.ts +9 -0
- package/dist/plugins/commands/index.d.ts +43 -0
- package/dist/plugins/commands/index.js +1 -0
- package/dist/plugins/commands/output.d.ts +115 -0
- package/dist/plugins/commands/record.d.ts +558 -0
- package/dist/plugins/commands/service.d.ts +321 -0
- package/dist/plugins/commands/shell.d.ts +25 -0
- package/dist/plugins/commands/tools.d.ts +10 -0
- package/dist/plugins/compaction/checkpoint.d.ts +94 -0
- package/dist/plugins/compaction/config.d.ts +133 -0
- package/dist/plugins/compaction/estimate.d.ts +37 -0
- package/dist/plugins/compaction/index.d.ts +87 -0
- package/dist/plugins/compaction/index.js +7 -0
- package/dist/plugins/compaction/planner.d.ts +207 -0
- package/dist/plugins/compaction/prune.d.ts +9 -0
- package/dist/plugins/compaction/record.d.ts +227 -0
- package/dist/plugins/compaction/segments.d.ts +23 -0
- package/dist/plugins/compaction/state.d.ts +68 -0
- package/dist/plugins/compaction/summarize.d.ts +13 -0
- package/dist/plugins/dateAndBranch.d.ts +47 -0
- package/dist/plugins/dateAndBranch.js +1 -0
- package/dist/plugins/delegations/answers.d.ts +39 -0
- package/dist/plugins/delegations/assignmentKey.d.ts +22 -0
- package/dist/plugins/delegations/cleanup.d.ts +161 -0
- package/dist/plugins/delegations/constraint.d.ts +76 -0
- package/dist/plugins/delegations/index.d.ts +39 -0
- package/dist/plugins/delegations/index.js +1 -0
- package/dist/plugins/delegations/notices.d.ts +261 -0
- package/dist/plugins/delegations/obligations.d.ts +210 -0
- package/dist/plugins/delegations/record.d.ts +633 -0
- package/dist/plugins/delegations/request.d.ts +384 -0
- package/dist/plugins/delegations/role.d.ts +30 -0
- package/dist/plugins/delegations/service.d.ts +563 -0
- package/dist/plugins/delegations/standing.d.ts +19 -0
- package/dist/plugins/delegations/stopCheck.d.ts +21 -0
- package/dist/plugins/delegations/tools.d.ts +71 -0
- package/dist/plugins/delegations/waitContracts.d.ts +118 -0
- package/dist/plugins/delegations/waitResolver.d.ts +116 -0
- package/dist/plugins/diagnostics/digest.d.ts +14 -0
- package/dist/plugins/diagnostics/index.d.ts +68 -0
- package/dist/plugins/diagnostics/index.js +1 -0
- package/dist/plugins/fileTools/config.d.ts +10 -0
- package/dist/plugins/fileTools/editFiles.d.ts +117 -0
- package/dist/plugins/fileTools/fsRead.d.ts +17 -0
- package/dist/plugins/fileTools/gitDiscovery.d.ts +9 -0
- package/dist/plugins/fileTools/index.d.ts +18 -0
- package/dist/plugins/fileTools/index.js +1 -0
- package/dist/plugins/fileTools/ripgrep.d.ts +20 -0
- package/dist/plugins/fileTools/textEdit.d.ts +67 -0
- package/dist/plugins/fileTools/tools.d.ts +6 -0
- package/dist/plugins/historyRecall/history.d.ts +9 -0
- package/dist/plugins/historyRecall/index.d.ts +31 -0
- package/dist/plugins/historyRecall/index.js +1 -0
- package/dist/plugins/historyRecall/render.d.ts +34 -0
- package/dist/plugins/historyRecall/tools.d.ts +4 -0
- package/dist/plugins/mcp/catalog.d.ts +36 -0
- package/dist/plugins/mcp/config.d.ts +63 -0
- package/dist/plugins/mcp/connection.d.ts +53 -0
- package/dist/plugins/mcp/errors.d.ts +32 -0
- package/dist/plugins/mcp/index.d.ts +33 -0
- package/dist/plugins/mcp/index.js +5 -0
- package/dist/plugins/mcp/mount.d.ts +98 -0
- package/dist/plugins/mcp/names.d.ts +25 -0
- package/dist/plugins/mcp/render.d.ts +29 -0
- package/dist/plugins/mcp/slots.d.ts +15 -0
- package/dist/plugins/mcp/stdio.d.ts +49 -0
- package/dist/plugins/mcp/tools.d.ts +41 -0
- package/dist/plugins/mcp/version.d.ts +2 -0
- package/dist/plugins/routeNotice.d.ts +22 -0
- package/dist/plugins/routeNotice.js +1 -0
- package/dist/plugins/sandbox/absent.d.ts +33 -0
- package/dist/plugins/sandbox/client.d.ts +39 -0
- package/dist/plugins/sandbox/files.d.ts +28 -0
- package/dist/plugins/sandbox/index.d.ts +52 -0
- package/dist/plugins/sandbox/index.js +4 -0
- package/dist/plugins/sandbox/mode.d.ts +57 -0
- package/dist/plugins/sandbox/policy.d.ts +163 -0
- package/dist/plugins/sandbox/protocol.d.ts +107 -0
- package/dist/plugins/sandbox/service.d.ts +153 -0
- package/dist/plugins/sandbox/worker.d.ts +12 -0
- package/dist/plugins/sandbox/worker.js +1 -0
- package/dist/plugins/schedules/index.d.ts +21 -0
- package/dist/plugins/schedules/index.js +5 -0
- package/dist/plugins/schedules/record.d.ts +396 -0
- package/dist/plugins/schedules/service.d.ts +120 -0
- package/dist/plugins/schedules/time.d.ts +26 -0
- package/dist/plugins/schedules/tools.d.ts +6 -0
- package/dist/plugins/skills/discovery.d.ts +83 -0
- package/dist/plugins/skills/index.d.ts +31 -0
- package/dist/plugins/skills/index.js +1 -0
- package/dist/plugins/skills/tools.d.ts +11 -0
- package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
- package/dist/plugins/subAgents/index.d.ts +67 -0
- package/dist/plugins/subAgents/index.js +1 -0
- package/dist/plugins/subAgents/tools.d.ts +67 -0
- package/dist/plugins/threadDirs.d.ts +36 -0
- package/dist/plugins/threadDirs.js +1 -0
- package/dist/plugins/toolPolicy/index.d.ts +61 -0
- package/dist/plugins/toolPolicy/index.js +1 -0
- package/dist/plugins/truncateToolOutput.d.ts +30 -0
- package/dist/plugins/truncateToolOutput.js +6 -0
- package/dist/plugins/usage/index.d.ts +26 -0
- package/dist/plugins/usage/index.js +1 -0
- package/dist/plugins/usage/tracker.d.ts +34 -0
- package/dist/plugins/verify/index.d.ts +27 -0
- package/dist/plugins/verify/index.js +6 -0
- package/dist/plugins/verify/judgement.d.ts +16 -0
- package/dist/plugins/verify/record.d.ts +382 -0
- package/dist/plugins/verify/service.d.ts +93 -0
- package/dist/plugins/verify/state.d.ts +58 -0
- package/dist/plugins/webTools/html.d.ts +23 -0
- package/dist/plugins/webTools/index.d.ts +34 -0
- package/dist/plugins/webTools/index.js +1 -0
- package/dist/plugins/webTools/network.d.ts +23 -0
- package/dist/plugins/webTools/web.d.ts +32 -0
- package/dist/plugins/workflows/assignment.d.ts +20 -0
- package/dist/plugins/workflows/cleanup.d.ts +38 -0
- package/dist/plugins/workflows/definition.d.ts +184 -0
- package/dist/plugins/workflows/entryPlan.d.ts +95 -0
- package/dist/plugins/workflows/hostBindings.d.ts +146 -0
- package/dist/plugins/workflows/index.d.ts +28 -0
- package/dist/plugins/workflows/index.js +11 -0
- package/dist/plugins/workflows/observations.d.ts +81 -0
- package/dist/plugins/workflows/participantModels.d.ts +28 -0
- package/dist/plugins/workflows/participants.d.ts +143 -0
- package/dist/plugins/workflows/policy.d.ts +112 -0
- package/dist/plugins/workflows/record.d.ts +2849 -0
- package/dist/plugins/workflows/routing.d.ts +116 -0
- package/dist/plugins/workflows/schema.d.ts +26 -0
- package/dist/plugins/workflows/service.d.ts +477 -0
- package/dist/plugins/workflows/state.d.ts +373 -0
- package/dist/plugins/workflows/stopCheck.d.ts +13 -0
- package/dist/plugins/workflows/tools.d.ts +13 -0
- package/dist/plugins/workflows/view.d.ts +103 -0
- package/dist/plugins/workflows/workStatus.d.ts +21 -0
- package/dist/plugins/workspaceNotice.d.ts +36 -0
- package/dist/plugins/workspaceNotice.js +1 -0
- package/dist/providers/anthropic.d.ts +178 -0
- package/dist/providers/anthropicMessages.d.ts +66 -0
- package/dist/providers/codex.d.ts +71 -0
- package/dist/providers/codexAuth.d.ts +116 -0
- package/dist/providers/deepseek.d.ts +59 -0
- package/dist/providers/failure.d.ts +23 -0
- package/dist/providers/gateway.d.ts +24 -0
- package/dist/providers/index.d.ts +18 -0
- package/dist/providers/index.js +6 -0
- package/dist/providers/openaiChat.d.ts +73 -0
- package/dist/providers/openaiResponses.d.ts +109 -0
- package/dist/providers/opencodeCopilot.d.ts +23 -0
- package/dist/providers/opencodeGo.d.ts +109 -0
- package/dist/providers/shared.d.ts +112 -0
- package/dist/providers/stream.d.ts +156 -0
- package/dist/records/index.d.ts +13 -0
- package/dist/records/index.js +1 -0
- package/dist/records/journal.d.ts +2968 -0
- package/dist/records/toolResult.d.ts +65 -0
- package/dist/services/agents.d.ts +62 -0
- package/dist/services/catalogContributions.d.ts +73 -0
- package/dist/services/confinement/files.d.ts +118 -0
- package/dist/services/confinement/service.d.ts +219 -0
- package/dist/services/core.d.ts +28 -0
- package/dist/services/extensionEvents.d.ts +181 -0
- package/dist/services/journal.d.ts +26 -0
- package/dist/services/llm.d.ts +82 -0
- package/dist/services/modes.d.ts +65 -0
- package/dist/services/plugins.d.ts +34 -0
- package/dist/services/presets/definition.d.ts +154 -0
- package/dist/services/presets/installations.d.ts +139 -0
- package/dist/services/prompts.d.ts +85 -0
- package/dist/services/threads/activation.d.ts +100 -0
- package/dist/services/threads/admission.d.ts +174 -0
- package/dist/services/threads/birth.d.ts +219 -0
- package/dist/services/threads/index.d.ts +14 -0
- package/dist/services/threads/runEvents.d.ts +79 -0
- package/dist/services/threads/runOwner.d.ts +368 -0
- package/dist/services/threads/service.d.ts +450 -0
- package/dist/services/threads/thread.d.ts +268 -0
- package/dist/services/threads/view.d.ts +93 -0
- package/dist/services/tools.d.ts +118 -0
- package/dist/state/birth.d.ts +62 -0
- package/dist/state/chain.d.ts +46 -0
- package/dist/state/confirmations.d.ts +64 -0
- package/dist/state/continuation.d.ts +167 -0
- package/dist/state/decide.d.ts +72 -0
- package/dist/state/dispatches.d.ts +54 -0
- package/dist/state/errors.d.ts +26 -0
- package/dist/state/forks.d.ts +61 -0
- package/dist/state/holds.d.ts +104 -0
- package/dist/state/inbox.d.ts +188 -0
- package/dist/state/index.d.ts +31 -0
- package/dist/state/inputs.d.ts +58 -0
- package/dist/state/installations.d.ts +28 -0
- package/dist/state/limits.d.ts +14 -0
- package/dist/state/prompt.d.ts +13 -0
- package/dist/state/recovery.d.ts +7 -0
- package/dist/state/replace.d.ts +33 -0
- package/dist/state/requests.d.ts +129 -0
- package/dist/state/route.d.ts +61 -0
- package/dist/state/summary.d.ts +16 -0
- package/dist/state/surface.d.ts +153 -0
- package/dist/state/surfaceRead.d.ts +20 -0
- package/dist/state/thread.d.ts +73 -0
- package/dist/state/turns.d.ts +87 -0
- package/dist/state/waits.d.ts +38 -0
- package/dist/state/wake.d.ts +32 -0
- package/dist/stores/durableObject.d.ts +23 -0
- package/dist/stores/durableObject.js +1 -0
- package/dist/stores/durableObjectConnection.d.ts +27 -0
- package/dist/stores/memory.d.ts +29 -0
- package/dist/stores/sql.d.ts +59 -0
- package/dist/stores/sqlite.d.ts +31 -0
- package/dist/stores/sqlite.js +1 -0
- package/dist/sys/environment.d.ts +42 -0
- package/dist/sys/git.d.ts +47 -0
- package/dist/sys/paths.d.ts +9 -0
- package/dist/sys/spawn.d.ts +186 -0
- package/dist/testing/clock.d.ts +17 -0
- package/dist/testing/fakeLlm.d.ts +76 -0
- package/dist/testing/fedLlm.d.ts +34 -0
- package/dist/testing/helpers.d.ts +362 -0
- package/dist/testing/index.d.ts +13 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/processes.d.ts +13 -0
- package/dist/testing/settlement.d.ts +6 -0
- package/dist/testing/tmpDirs.d.ts +17 -0
- package/dist/util/async.d.ts +8 -0
- package/dist/util/diff.d.ts +25 -0
- package/dist/util/dispatch.d.ts +8 -0
- package/dist/util/errors.d.ts +28 -0
- package/dist/util/foldState.d.ts +17 -0
- package/dist/util/freeze.d.ts +2 -0
- package/dist/util/ids.d.ts +2 -0
- package/dist/util/json.d.ts +37 -0
- package/dist/util/jsonSchema.d.ts +7 -0
- package/dist/util/log.d.ts +6 -0
- package/dist/util/retries.d.ts +25 -0
- package/dist/util/text.d.ts +21 -0
- package/dist/util/timers.d.ts +43 -0
- package/package.json +183 -3
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import type { Context } from '@leuduan/cordis';
|
|
2
|
+
import type { AppendEntry, Journal } from '../../journal/index.js';
|
|
3
|
+
import type { PromptBlock } from '../../llm/prompt.js';
|
|
4
|
+
import type { CompactOptions, StreamedChunk, SurfacePrepareOutcome } from '../../loop/index.js';
|
|
5
|
+
import type { RouteStatement, RowRef, SendOptions, SendOutcome, WithdrawOptions, WithdrawOutcome } from '../../state/index.js';
|
|
6
|
+
import type { CancelIntent, JournalEvent, ThreadInput, ThreadOrigin, ThreadSummary, TurnEndReason } from '../../records/journal.js';
|
|
7
|
+
import type { DeepReadonly } from '../../util/json.js';
|
|
8
|
+
import type { AdmissionView } from './admission.js';
|
|
9
|
+
import type { ForkOptions } from './birth.js';
|
|
10
|
+
import type { ConfigurationChange, ConfigurationResult, ThreadsService } from './service.js';
|
|
11
|
+
import type { ThreadView } from './view.js';
|
|
12
|
+
/** One answer to a parked confirmation. */
|
|
13
|
+
export type ConfirmationAnswer = {
|
|
14
|
+
request_id: string;
|
|
15
|
+
approved: boolean;
|
|
16
|
+
rejection_message?: string | null;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* How `cancel()` cancels: a person's stop (`user`), which holds the thread until a releasing cause,
|
|
20
|
+
* or a feature's `cleanup`, which holds nothing; `rows`, extension rows built inside the cancel's
|
|
21
|
+
* write for the same group, or a refusal of it by throwing; and `until`, the milestone the call
|
|
22
|
+
* settles at: `released` (the default) once the write has landed and what the cancel captured has
|
|
23
|
+
* released the thread, `recorded` once the write alone has landed.
|
|
24
|
+
*/
|
|
25
|
+
export type CancelOptions = {
|
|
26
|
+
readonly intent: CancelIntent;
|
|
27
|
+
readonly rows?: (threadId: string) => readonly AppendEntry<'ext'>[];
|
|
28
|
+
readonly until?: 'recorded' | 'released';
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* One conversation in the journal. Threads are independent: their own transcript, their own
|
|
32
|
+
* exclusive admission while the owner runs them, their own confirmations. Two may run at once. A
|
|
33
|
+
* thread runs for a recorded request: `send` or `answer` with `wake`, or `resume`.
|
|
34
|
+
*
|
|
35
|
+
* Durable accessors read the journal; execution status and ctx belong to the current activation.
|
|
36
|
+
* The handle never owns plugin lifetime and survives replacement of that activation.
|
|
37
|
+
*/
|
|
38
|
+
export declare class Thread {
|
|
39
|
+
private readonly inbox;
|
|
40
|
+
private readonly service;
|
|
41
|
+
private readonly admission;
|
|
42
|
+
readonly id: string;
|
|
43
|
+
private readonly journal;
|
|
44
|
+
constructor(service: ThreadsService,
|
|
45
|
+
/** The admission owner's reads and cancel, given by the service that owns it. */
|
|
46
|
+
admission: AdmissionView, id: string,
|
|
47
|
+
/** The journal with core's writes, which only the thread owner hands out. */
|
|
48
|
+
journal: Journal);
|
|
49
|
+
/**
|
|
50
|
+
* Reads what this thread's folds say through `reader`, which is synchronous: the thread is loaded
|
|
51
|
+
* and held for the call (a `keep` retention), so nothing drops it meanwhile: how a caller that
|
|
52
|
+
* holds nothing reads a thread's conversation, where one that holds it already reads
|
|
53
|
+
* `ctx.threads.view`. The catalog reads (`summary`, `status`, `lastOutcome`) need neither.
|
|
54
|
+
*/
|
|
55
|
+
read<T>(reader: (view: ThreadView) => T): Promise<T>;
|
|
56
|
+
/** Lazily activates this thread. Its plugins are fixed once ready: mount them from activate listeners or presets. */
|
|
57
|
+
get ctx(): Context;
|
|
58
|
+
/**
|
|
59
|
+
* The current activation's signal, the one its `lagent/thread/activate` listeners receive: it
|
|
60
|
+
* aborts when the activation is released or stopped, not when one turn is cancelled. Activates
|
|
61
|
+
* the thread, as `ctx` does, and like `ctx` throws `ThreadBusyError` while the activation is being
|
|
62
|
+
* released, since a getter cannot wait; a read after the release starts a new activation; and once
|
|
63
|
+
* `ctx.threads` has shut down it throws.
|
|
64
|
+
*/
|
|
65
|
+
get signal(): AbortSignal;
|
|
66
|
+
/**
|
|
67
|
+
* Activates this thread if it is not live, after any release in progress, and resolves once its
|
|
68
|
+
* plugins are ready: the barrier a run waits at, so a plugin that cannot mount, such as a recorded
|
|
69
|
+
* preset installation that no longer restores, rejects here with its error and nothing runs. A
|
|
70
|
+
* host that changes a thread's installations and wants the failure now awaits this.
|
|
71
|
+
*/
|
|
72
|
+
whenReady(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Changes this thread's preset installations as one operation: validates the whole change,
|
|
75
|
+
* releases the live activation, records every installation applied or removed in one write, and
|
|
76
|
+
* restores a thread that was live from the record, rebuilding its recorded prompt when asked
|
|
77
|
+
* (which restores a thread at rest too); a thread at rest otherwise stays at rest, and its next run
|
|
78
|
+
* or `whenReady()` restores it. Removals go first, then
|
|
79
|
+
* applications, which are restored in that order. A given `installationId` makes a retry a no-op,
|
|
80
|
+
* and a removed id is never accepted again; removing an id not installed is no change, and a
|
|
81
|
+
* defining installation is never removed. Refused busy while an operation holds the thread, and
|
|
82
|
+
* refused with `ThreadActivatingError` while its activation is still getting ready, with
|
|
83
|
+
* `ThreadUnsettledError` for an unfinished confirmation (open, or approved and not yet run), and
|
|
84
|
+
* once lagent is closing. The record is the boundary: a cancel before it records nothing, a cancel
|
|
85
|
+
* after it ends only the restoration, and a setup that fails after it rejects with
|
|
86
|
+
* `RestoreFailedError`, the change standing, so a change that removes a broken installation
|
|
87
|
+
* always goes through.
|
|
88
|
+
*/
|
|
89
|
+
configure(change: ConfigurationChange): Promise<ConfigurationResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Takes this thread out of the working set: releases an idle activation and drops the rows and
|
|
92
|
+
* folds, under one admission; the catalog entry stays. Refused busy while an operation holds it.
|
|
93
|
+
*/
|
|
94
|
+
close(): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* This thread's catalog entry: its identity and lineage, how its last turn ended, whether it has
|
|
97
|
+
* work, what it waits on, and what plugins and hosts contributed — everything a listing shows,
|
|
98
|
+
* read without a row of the thread in memory, exact as of the thread's last group.
|
|
99
|
+
*/
|
|
100
|
+
get summary(): ThreadSummary;
|
|
101
|
+
get agentName(): string;
|
|
102
|
+
/** App-owned annotations the engine never reads. */
|
|
103
|
+
get metadata(): ThreadSummary['metadata'];
|
|
104
|
+
/** Where this thread came from: its caller, the caller's row and the cause; `null` for a root thread. */
|
|
105
|
+
get origin(): ThreadOrigin | null;
|
|
106
|
+
/**
|
|
107
|
+
* How many delegation hops separate this thread from its origin root: one for each thread
|
|
108
|
+
* of its caller chain that has a caller, a caller the catalog does not hold included.
|
|
109
|
+
*/
|
|
110
|
+
get depth(): number;
|
|
111
|
+
/**
|
|
112
|
+
* The thread at the top of this one's origin tree, the caller chain's thread with no caller:
|
|
113
|
+
* itself for a thread created without an `origin`. `null` when the chain does not reach one, at a
|
|
114
|
+
* caller the catalog does not hold or a cycle, which only a journal that broke its rules has; a
|
|
115
|
+
* reader that decides by the root then decides nothing, rather than take a thread part-way up for
|
|
116
|
+
* it. From the catalog, loading nothing; fork lineage is {@link lineageRoot}'s.
|
|
117
|
+
*/
|
|
118
|
+
get originRoot(): string | null;
|
|
119
|
+
get environment(): ThreadSummary['environment'];
|
|
120
|
+
/** The thread and row this one was forked at, or `null` unless it is a fork. */
|
|
121
|
+
get forkedFrom(): RowRef | null;
|
|
122
|
+
/**
|
|
123
|
+
* The thread at the start of this one's fork lineage: itself unless it is a fork. Forks of one
|
|
124
|
+
* root share its history, and so the provider cache that holds it.
|
|
125
|
+
*/
|
|
126
|
+
get lineageRoot(): string;
|
|
127
|
+
/** How this thread's own last turn ended, from the catalog; `null` before its first ends, or while one is open. */
|
|
128
|
+
lastOutcome(): DeepReadonly<TurnEndReason> | null;
|
|
129
|
+
/** Forks this thread at a row, or at the turn holding one; see `ctx.threads.fork`. */
|
|
130
|
+
fork(options: ForkOptions): Promise<Thread>;
|
|
131
|
+
/**
|
|
132
|
+
* Re-renders the prompt from the registries as they stand — the thread's own plugins included,
|
|
133
|
+
* which is why it activates the thread and waits for them — and records it; later turns send the
|
|
134
|
+
* new one. The deliberate exception to a prompt being frozen at first run.
|
|
135
|
+
*/
|
|
136
|
+
rebuildPrompt(): Promise<PromptBlock[]>;
|
|
137
|
+
/**
|
|
138
|
+
* This thread's events as they are appended: `ctx.journal.subscribe` filtered to the thread, so a
|
|
139
|
+
* promise the listener returns is reported if it rejects, as any subscriber's is. Returns the
|
|
140
|
+
* unsubscribe function.
|
|
141
|
+
*/
|
|
142
|
+
on(listener: (event: JournalEvent) => void): () => void;
|
|
143
|
+
/** The model's output as it streams on this thread. Returns the unsubscribe function. */
|
|
144
|
+
onChunk(listener: (chunk: StreamedChunk) => void): () => void;
|
|
145
|
+
/**
|
|
146
|
+
* Queues durable input without driving, and resolves once it is durable with what the write did:
|
|
147
|
+
* `queued`, with the row that recorded it; `known`, when this thread was already handed `id`, which
|
|
148
|
+
* queues nothing and names the original row; or `refused`, with the reason `rows` vetoed it for.
|
|
149
|
+
*
|
|
150
|
+
* `rows` runs inside the write once the input's target is decided, and adds a plugin's rows to the
|
|
151
|
+
* same group or vetoes the input by returning `{ refuse }` (see `WriteRows`); a callback that
|
|
152
|
+
* throws fails the send with that error instead. A known id never calls it.
|
|
153
|
+
* `source` attributes the input to a plugin, as on a step contribution, and needs the `id` the
|
|
154
|
+
* plugin derived: the claimed `input/message` keeps both, and input waiting for a turn is claimed
|
|
155
|
+
* as one unsourced input or every consecutive sourced input at the head of the queue.
|
|
156
|
+
*
|
|
157
|
+
* Text is the common case and stays a string; `{ role: 'developer', content }` queues a message
|
|
158
|
+
* that speaks as the harness rather than as the person, and content parts carry what text cannot.
|
|
159
|
+
*
|
|
160
|
+
* Where input waits is the sender's `target` when it names one, and admission's choice otherwise.
|
|
161
|
+
* Admission joins a running turn at its next step; the caller that started the turn owns its
|
|
162
|
+
* result. On an idle thread it waits for a turn of its own, behind input sent before it, and is
|
|
163
|
+
* claimed only by that turn's first step: a turn that opens by answering calls an earlier turn
|
|
164
|
+
* left leaves it for the next turn, which the same run opens once that work completed.
|
|
165
|
+
* `target: 'next-turn'` asks for a turn of its own even while a run holds the thread, as a new
|
|
166
|
+
* assignment does; `target: 'next-step'` joins the next model step of whichever turn takes it,
|
|
167
|
+
* including a turn that resumes parked calls, as a report on work already set going does.
|
|
168
|
+
* Sending never interrupts: an in-flight model call or tool is never cut off. Interruption is
|
|
169
|
+
* `cancel()`, then `send()` with a wake, deliberately two visible steps.
|
|
170
|
+
*
|
|
171
|
+
* A wake may state the route it runs on (`RouteStatement`), checked inside the write: an `expect`
|
|
172
|
+
* that no longer matches the thread's route is refused with `RouteConflictError`, one whose route
|
|
173
|
+
* cannot run with `RouteUnavailableError`; a `select` changes the route, which reauthorizes all the
|
|
174
|
+
* thread's unfinished work on it, only while no request is pending or the route cannot run, and no
|
|
175
|
+
* run serving the pending request holds the thread. A refusal writes nothing.
|
|
176
|
+
*/
|
|
177
|
+
send(input: ThreadInput, options?: SendOptions): Promise<SendOutcome>;
|
|
178
|
+
/**
|
|
179
|
+
* Takes back one queued input that no step has claimed yet, by the id it was sent with, and
|
|
180
|
+
* resolves with what the write did: `withdrawn`, `not-queued` (claimed, discarded or unknown), or
|
|
181
|
+
* `refused` by a `rows` veto, which adds a plugin's rows to the same write either way and is told whether
|
|
182
|
+
* the input was withdrawn. The id stays known, so `send` with it queues nothing again.
|
|
183
|
+
*/
|
|
184
|
+
withdraw(inputId: string, options?: WithdrawOptions): Promise<WithdrawOutcome>;
|
|
185
|
+
/**
|
|
186
|
+
* Records answers to confirmations parked on this thread, all of them or none. Does not drive: the
|
|
187
|
+
* run the answer's cause asks for re-dispatches them, through authorization again. A request that
|
|
188
|
+
* already has a decision — answered before, or approved and then revoked — is refused with
|
|
189
|
+
* `ConfirmationAnsweredError`, carrying the decision on record; a batch naming one request twice
|
|
190
|
+
* is refused outright.
|
|
191
|
+
*/
|
|
192
|
+
answer(decisions: readonly ConfirmationAnswer[], options?: {
|
|
193
|
+
readonly wake?: boolean;
|
|
194
|
+
}): Promise<void>;
|
|
195
|
+
/**
|
|
196
|
+
* Asks the thread to run again, as a person or a host does: a cause that releases the failure,
|
|
197
|
+
* cancellation and startup holds, recorded in one write and resolving once durable. A `route`
|
|
198
|
+
* statement is checked as `send` checks a wake's. Resolves with the run the cause joined or opened.
|
|
199
|
+
*/
|
|
200
|
+
resume(options?: {
|
|
201
|
+
readonly route?: RouteStatement;
|
|
202
|
+
}): Promise<string>;
|
|
203
|
+
/**
|
|
204
|
+
* A cancel's answer to each call the thread suspended, read inside its write: an error result in
|
|
205
|
+
* the declaration's turn and step, citing the call and the declaration.
|
|
206
|
+
*/
|
|
207
|
+
private closeWaitRows;
|
|
208
|
+
/** The thread's pending run request, read inside a write. */
|
|
209
|
+
private pendingRun;
|
|
210
|
+
/**
|
|
211
|
+
* Takes back approvals of calls without a result. Each becomes a rejection, so the call does not run
|
|
212
|
+
* again: its next dispatch ends it with an error. A call that already started, and then waits or
|
|
213
|
+
* was cut off, keeps what it did, and a child thread it started keeps running. Refused while a run
|
|
214
|
+
* holds the thread, since that run may be executing one. A batch with any id that does not qualify
|
|
215
|
+
* records nothing. Writes only to the journal, so it also works on a thread that cannot activate,
|
|
216
|
+
* which is how a host gets such a thread out of an approval it cannot run.
|
|
217
|
+
*/
|
|
218
|
+
revokeApprovals(requestIds: readonly string[], rejectionMessage?: string | null): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Asks the thread's strategy to prepare its surface now, between turns, with the `request`
|
|
221
|
+
* trigger and `options`, which the engine passes on and never reads. This is how a host offers a `/compact` command.
|
|
222
|
+
*
|
|
223
|
+
* Holds the thread's admission, as a run does, but accepts no input: `send()` meanwhile queues for the
|
|
224
|
+
* next turn unless its sender names `next-step`, a run waits for it, and `activity` names the compaction. Requires a
|
|
225
|
+
* settled thread — no tool call without a result, no open confirmation, no answer its stop checks
|
|
226
|
+
* still owe — and rejects with `ThreadUnsettledError` otherwise; an interrupted open turn is closed
|
|
227
|
+
* first, as a run closes it. The route is resolved as a turn's would be. Opens no turn, runs no
|
|
228
|
+
* step hook and claims no queued input. Aborts on `signal`, on `cancel()` and on shutdown, and then
|
|
229
|
+
* resolves `cancelled` rather than rejects, with whatever the dispatch committed; cancelled before
|
|
230
|
+
* it began, it resolves `cancelled` with nothing dispatched. A strategy that failed on its own while
|
|
231
|
+
* the signal aborted resolves `failed`.
|
|
232
|
+
*
|
|
233
|
+
* Resolves with the one outcome record: the replacement rows committed and how the dispatch ended;
|
|
234
|
+
* `skipped` with a reason when no strategy answered.
|
|
235
|
+
*/
|
|
236
|
+
compact(options?: CompactOptions): Promise<SurfacePrepareOutcome>;
|
|
237
|
+
/**
|
|
238
|
+
* Cancels the thread, whatever its state: captures the operation admitted now, if any, and aborts
|
|
239
|
+
* only it, then records one write: the `thread/cancel` row, the clear of everything queued, an
|
|
240
|
+
* error result answering each call the thread suspended on a wait, resolved or not, the rows
|
|
241
|
+
* `options.rows` adds, and the settlement, by the cancel's intent, of a pending run no execution is
|
|
242
|
+
* still to settle. So a cancelled thread never holds a waiting call, and a feature watching the
|
|
243
|
+
* call learns of the cancel from its result. The run the captured execution serves settles in that execution's
|
|
244
|
+
* finalization, unless the finalization built its settlement before this write and left it pending. A `user` cancel (a person's stop) holds the thread until a releasing cause; a
|
|
245
|
+
* `cleanup` one holds nothing. From the call until its write has landed and what it captured has
|
|
246
|
+
* released the thread, the cancel holds the thread, so a run meanwhile is refused busy; a cancel
|
|
247
|
+
* made meanwhile joins it. With `until: 'released'`, the default, resolves then, or rejects with its
|
|
248
|
+
* own write's failure, which records nothing — so a `send` after `cancel()` never races the
|
|
249
|
+
* cancelled operation. With `until: 'recorded'` it settles with that write alone, resolving once
|
|
250
|
+
* it has landed and rejecting with its failure, without waiting for what was captured to wind down:
|
|
251
|
+
* a run's drain and finalization are the engine's, and a failure of theirs goes to `reportError`,
|
|
252
|
+
* so a caller that needs the thread free awaits `released`. Each joined call gets its own write's
|
|
253
|
+
* outcome.
|
|
254
|
+
*/
|
|
255
|
+
cancel(reason: string, options: CancelOptions): Promise<void>;
|
|
256
|
+
}
|
|
257
|
+
/** The answers as journal rows on the thread that asked, appended as one group. */
|
|
258
|
+
export declare const confirmationRows: (threadId: string, decisions: readonly ConfirmationAnswer[]) => {
|
|
259
|
+
type: "confirm/resolved";
|
|
260
|
+
data: {
|
|
261
|
+
request_id: string;
|
|
262
|
+
approved: boolean;
|
|
263
|
+
rejection_message: string | null;
|
|
264
|
+
};
|
|
265
|
+
options: {
|
|
266
|
+
threadId: string;
|
|
267
|
+
};
|
|
268
|
+
}[];
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ConversationMessage, ToolSpec } from '../../llm/primitives.js';
|
|
2
|
+
import type { PromptBlock } from '../../llm/prompt.js';
|
|
3
|
+
import type { ConfirmationState, ForkPoint, InputFate, InstallationRecord, RowRef, RunOutcome, Target, WaitEntry } from '../../state/index.js';
|
|
4
|
+
import type { JournalEvent, QueuedInput, Seq } from '../../records/journal.js';
|
|
5
|
+
import type { DeepReadonly } from '../../util/json.js';
|
|
6
|
+
import type { Journal } from '../../journal/index.js';
|
|
7
|
+
import type { ReadonlyState } from '../../util/foldState.js';
|
|
8
|
+
/**
|
|
9
|
+
* What one thread's folds say, read synchronously (`ctx.threads.view`, `thread.read`): valid while
|
|
10
|
+
* something holds the thread in memory — a journal write or a contributor running for it, a run, a
|
|
11
|
+
* retention. Reading a thread nothing holds may find it unloaded and throws `ThreadNotLoadedError`.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ThreadView {
|
|
14
|
+
private readonly inbox;
|
|
15
|
+
private readonly journal;
|
|
16
|
+
readonly threadId: string;
|
|
17
|
+
private readonly targetOf;
|
|
18
|
+
constructor(journal: Journal, threadId: string, targetOf: (threadId: string) => Target);
|
|
19
|
+
/**
|
|
20
|
+
* The thread's route, why it cannot run here (`blocked`), and whether a route change is accepted
|
|
21
|
+
* now (`selectable`): what a route statement is checked against (`Thread.send`). Never throws.
|
|
22
|
+
*/
|
|
23
|
+
target(): Target;
|
|
24
|
+
/**
|
|
25
|
+
* The conversation as the model sees it, a fork's inherited history included. After a
|
|
26
|
+
* replacement that is the replaced view, stand-ins included; `replayLineage()` is the record.
|
|
27
|
+
*/
|
|
28
|
+
transcript(): readonly ConversationMessage[];
|
|
29
|
+
/**
|
|
30
|
+
* The row behind each {@link transcript} message, index for index — what a fork anchors on. A
|
|
31
|
+
* stand-in's is the `surface/replaced` row that put it there.
|
|
32
|
+
*/
|
|
33
|
+
messageSeqs(): readonly RowRef[];
|
|
34
|
+
/**
|
|
35
|
+
* The `llm/request` that produced the reply at `row`, on the thread that owns it; `null` for a
|
|
36
|
+
* row that is not a reply. Forking there regenerates the reply.
|
|
37
|
+
*/
|
|
38
|
+
requestBehind(row: RowRef): RowRef | null;
|
|
39
|
+
/**
|
|
40
|
+
* The original rows a {@link messageSeqs} row stands for, in transcript order: the row itself
|
|
41
|
+
* when it is an original, and for a `surface/replaced` row, the originals behind every row it
|
|
42
|
+
* cites, followed through replacements of replacements — what a stand-in summarizes, on whichever
|
|
43
|
+
* thread holds `row`.
|
|
44
|
+
*/
|
|
45
|
+
originalsBehind(row: RowRef): RowRef[];
|
|
46
|
+
/**
|
|
47
|
+
* Every turn ending along the thread's lineage, and every replacement recorded between turns,
|
|
48
|
+
* oldest first: where "fork from here" cuts.
|
|
49
|
+
*/
|
|
50
|
+
forkPoints(): ForkPoint[];
|
|
51
|
+
/** The last thing the model said on the thread, if anything; see {@link lastAssistantMessage}. */
|
|
52
|
+
finalMessage(): ReadonlyState<ConversationMessage> | null;
|
|
53
|
+
/**
|
|
54
|
+
* How the run that began after `fromSeq` ended, and what it answered: a run's outcome, which an
|
|
55
|
+
* `aborted` turn ends. A delegation task is not a run and keeps its own settlement rule.
|
|
56
|
+
*/
|
|
57
|
+
outcomeSince(fromSeq: Seq): RunOutcome;
|
|
58
|
+
/** The system prompt the thread sends; empty until its first turn records it. */
|
|
59
|
+
prompt(): readonly PromptBlock[];
|
|
60
|
+
/**
|
|
61
|
+
* The tool specifications `request` sent, as recorded then: thread-local tools and middleware's
|
|
62
|
+
* changes included, whatever is registered now. The request may be the thread's own or one it
|
|
63
|
+
* inherits; it is read on the thread that made it.
|
|
64
|
+
*/
|
|
65
|
+
requestTools(request: JournalEvent<'llm/request'> | JournalEvent<'auxiliary/request'>): readonly ToolSpec[];
|
|
66
|
+
/** Requests waiting on the user, as owned frozen snapshots that survive later answers. */
|
|
67
|
+
pendingConfirmations(): DeepReadonly<ConfirmationState[]>;
|
|
68
|
+
/**
|
|
69
|
+
* The waits the thread declared, in declaration order, answered ones included, as owned frozen
|
|
70
|
+
* snapshots that survive later resolutions; with `owner`, only the waits declared under it. The
|
|
71
|
+
* registration named by an owner resolves its waits; a read never does.
|
|
72
|
+
*/
|
|
73
|
+
waits(options?: {
|
|
74
|
+
readonly owner?: string;
|
|
75
|
+
}): readonly Readonly<WaitEntry>[];
|
|
76
|
+
/** The thread's own rows so far: what `thread.on` would have delivered. */
|
|
77
|
+
replay(): readonly JournalEvent[];
|
|
78
|
+
/**
|
|
79
|
+
* A fork's inherited rows, then its own, each with its original thread id and seq — what a
|
|
80
|
+
* frontend replays to show a fork's whole history. The same as `replay()` for a thread that is
|
|
81
|
+
* not a fork.
|
|
82
|
+
*/
|
|
83
|
+
replayLineage(): readonly JournalEvent[];
|
|
84
|
+
/** Input waiting for a step to claim it, in the order it was sent. */
|
|
85
|
+
queued(): readonly QueuedInput[];
|
|
86
|
+
/**
|
|
87
|
+
* What became of the input `inputId`: never handed to this thread, queued, claimed by a step, or
|
|
88
|
+
* discarded unclaimed; see {@link InputFate}.
|
|
89
|
+
*/
|
|
90
|
+
input(inputId: string): InputFate;
|
|
91
|
+
/** The thread's preset installations in recorded order, as readonly snapshots. */
|
|
92
|
+
installations(): readonly InstallationRecord[];
|
|
93
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Context, Service, type ScopeKey } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type AgentSelector } from './agents.js';
|
|
4
|
+
import { type Tool, type ToolEntry, type InvocationContext, type ToolExecutionMode, type WaitRequest } from '../loop/index.js';
|
|
5
|
+
import { type InterruptionPolicy } from '../records/journal.js';
|
|
6
|
+
import { type ParsedToolCall, type ToolCall } from '../llm/primitives.js';
|
|
7
|
+
import { type ToolResult, type ToolResultPayloadInput } from '../records/toolResult.js';
|
|
8
|
+
import type { JsonValue } from '../util/json.js';
|
|
9
|
+
/**
|
|
10
|
+
* The tools this process can offer, and who may call them. Live: a tool or a grant lasts
|
|
11
|
+
* exactly as long as the plugin that registered it, and an agent's reachable set is resolved when a
|
|
12
|
+
* request is built, never captured earlier. Untagged registrations are global; scoped registrations
|
|
13
|
+
* are visible from that scope and its descendants. The closest definition of a name wins.
|
|
14
|
+
*
|
|
15
|
+
* What an agent may call is exactly what it is granted. A grant holds the selector it was made
|
|
16
|
+
* with and is matched against the agent asking, so a grant to `'global'` or `'all'` keeps up with
|
|
17
|
+
* agents registered after it, and a grant may name a tool or an agent that does not exist yet; it
|
|
18
|
+
* simply resolves to nothing until they do. A scoped agent is reached only by grants naming it or
|
|
19
|
+
* by `'all'` (`selects`).
|
|
20
|
+
*/
|
|
21
|
+
export declare class ToolsService extends Service {
|
|
22
|
+
static inject: string[];
|
|
23
|
+
private readonly layers;
|
|
24
|
+
constructor(ctx: Context);
|
|
25
|
+
/** Registered tool names visible from `scope`, sorted and deduplicated. */
|
|
26
|
+
names(scope: ScopeKey | undefined): string[];
|
|
27
|
+
has(scope: ScopeKey | undefined, name: string): boolean;
|
|
28
|
+
/** The closest registered definition of `name`, then the global fallback. */
|
|
29
|
+
get(scope: ScopeKey | undefined, name: string): ToolEntry | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Adds a tool to one layer; returns the unregister function. Duplicates fail within that layer,
|
|
32
|
+
* and so does a tool that does not say what a re-dispatch after an interruption may do: the
|
|
33
|
+
* declaration has no default, and a missing one would surface as a schema error mid-turn.
|
|
34
|
+
*/
|
|
35
|
+
register(scope: ScopeKey | undefined, name: string, tool: Tool): () => void;
|
|
36
|
+
/** Lets the agents `agents` selects call `toolName` in one layer; returns the revoke function. */
|
|
37
|
+
grant(scope: ScopeKey | undefined, agents: AgentSelector, toolName: string): () => void;
|
|
38
|
+
/**
|
|
39
|
+
* What `agentName` may call right now: its global-to-local grants in registration order, each name
|
|
40
|
+
* once, names nothing answers to skipped. Throws for an agent unknown from `scope`.
|
|
41
|
+
*/
|
|
42
|
+
toolsFor(scope: ScopeKey | undefined, agentName: string): ToolEntry[];
|
|
43
|
+
/** One tool `agentName` may call, or `undefined` when it is unknown or not granted. */
|
|
44
|
+
toolFor(scope: ScopeKey | undefined, agentName: string, toolName: string): ToolEntry | undefined;
|
|
45
|
+
mayCall(scope: ScopeKey | undefined, agentName: string, toolName: string): boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parameters described elsewhere, as JSON schema: advertised as given and handed to `execute`
|
|
49
|
+
* unvalidated, for a tool whose real validator is someone else's, such as an MCP server.
|
|
50
|
+
*/
|
|
51
|
+
export type JsonSchemaParameters = {
|
|
52
|
+
readonly jsonSchema: Record<string, JsonValue>;
|
|
53
|
+
};
|
|
54
|
+
type ParametersOf<P> = P extends z.ZodType ? z.output<P> : Record<string, unknown>;
|
|
55
|
+
/** What `execute` returns: a result with `is_error`, `notes` and `metadata` optional, or a wait (`waitFor`). */
|
|
56
|
+
export type ToolReply = ToolResultPayloadInput | WaitRequest;
|
|
57
|
+
/** One tool, as {@link defineTool} takes it. */
|
|
58
|
+
export type ToolDefinition<P extends z.ZodType | JsonSchemaParameters> = {
|
|
59
|
+
/** The name it is registered under, and advertised to the model by. */
|
|
60
|
+
readonly name: string;
|
|
61
|
+
/** One paragraph advertised to the model. */
|
|
62
|
+
readonly description: string;
|
|
63
|
+
/** A zod schema the arguments are validated against and advertised from, or JSON schema. */
|
|
64
|
+
readonly parameters: P;
|
|
65
|
+
/**
|
|
66
|
+
* What a re-dispatch may do with a call that may have begun when its turn was interrupted; see
|
|
67
|
+
* `Tool.onInterrupted`. Every tool says which; there is no default.
|
|
68
|
+
*/
|
|
69
|
+
readonly onInterrupted: InterruptionPolicy;
|
|
70
|
+
/** Whether a call may overlap its batch's others; see `Tool.executionMode`. No default either. */
|
|
71
|
+
readonly executionMode: ToolExecutionMode;
|
|
72
|
+
/** Runs one call. A throw becomes an `is_error` result: a tool never fails a turn. */
|
|
73
|
+
execute(parameters: ParametersOf<P>, context: InvocationContext, call: ParsedToolCall): Promise<ToolReply>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Defines a tool: the one way to write one. Arguments are validated against `parameters` when it is
|
|
77
|
+
* a zod schema, and a validation failure or a throw from `execute` becomes an `is_error` result, so
|
|
78
|
+
* a tool can never crash a turn; the result is timed. A tool that needs configuration closes over it.
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* const echo = defineTool({
|
|
82
|
+
* name: 'echo',
|
|
83
|
+
* description: 'Repeat the text.',
|
|
84
|
+
* parameters: z.strictObject({ text: z.string() }),
|
|
85
|
+
* onInterrupted: 'rerun',
|
|
86
|
+
* executionMode: 'parallel',
|
|
87
|
+
* execute: async ({ text }) => ({ output: text }),
|
|
88
|
+
* })
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function defineTool<P extends z.ZodType | JsonSchemaParameters>(definition: ToolDefinition<P>): Tool;
|
|
92
|
+
/**
|
|
93
|
+
* Offers `tool` in the calling plugin's scope for the life of its fiber, and grants it to the agents
|
|
94
|
+
* `agents` selects when given; without them it is registered for a grant elsewhere, a preset's say.
|
|
95
|
+
* Returns the disposer.
|
|
96
|
+
*/
|
|
97
|
+
export declare function registerTool(ctx: Context, tool: Tool, options?: {
|
|
98
|
+
readonly agents?: AgentSelector;
|
|
99
|
+
}): () => void | Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* {@link registerTool} for each of `tools`, then a prompt instruction under `tag` for every agent that
|
|
102
|
+
* is granted one of them: the `guidance` of each granted tool, in tool order, and nothing when none
|
|
103
|
+
* is granted or none has any.
|
|
104
|
+
*/
|
|
105
|
+
export declare function registerTools(ctx: Context, tools: readonly Tool[], options: {
|
|
106
|
+
readonly tag: string;
|
|
107
|
+
readonly guidance: ReadonlyMap<string, string>;
|
|
108
|
+
}): void;
|
|
109
|
+
/** A tool's result for `call`, its defaults applied and its duration recorded. */
|
|
110
|
+
export declare function toToolResult(call: ToolCall, reply: ToolResultPayloadInput, startedAt: number): ToolResult;
|
|
111
|
+
export { errorResult } from '../loop/index.js';
|
|
112
|
+
/**
|
|
113
|
+
* Grants `toolName` to the agents `agents` selects, for the life of the calling plugin's fiber, or
|
|
114
|
+
* until the returned disposer runs. The selector is stored as given: registries are live, so
|
|
115
|
+
* a grant to `'global'` or `'all'` is matched against each agent when it asks, agents registered
|
|
116
|
+
* later included.
|
|
117
|
+
*/
|
|
118
|
+
export declare function grantTool(ctx: Context, toolName: string, agents: AgentSelector): () => void | Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ModelRoute } from '../llm/provider.js';
|
|
2
|
+
import type { InitialInstallation, JournalEvent, Seq, ThreadEnvironment, ThreadFork, ThreadOrigin } from '../records/journal.js';
|
|
3
|
+
import type { DeepReadonly } from '../util/json.js';
|
|
4
|
+
import type { RowRef } from './surface.js';
|
|
5
|
+
import type { Reducer } from './thread.js';
|
|
6
|
+
/**
|
|
7
|
+
* What a fresh thread is born with, as its spawn row records it: the one value `create` resolves a
|
|
8
|
+
* birth to, whichever source it came from, and the one a reused thread is compared on. `installations`
|
|
9
|
+
* holds all of them, handed down ones included, each with its lifetime; `requires` is a set, kept
|
|
10
|
+
* sorted and without repeats.
|
|
11
|
+
*/
|
|
12
|
+
export type BirthSpec = DeepReadonly<{
|
|
13
|
+
route: ModelRoute;
|
|
14
|
+
environment: ThreadEnvironment;
|
|
15
|
+
installations: InitialInstallation[];
|
|
16
|
+
requires: string[];
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* A fresh thread as a write-time callback sees it: the agent it is born on, the origin it records
|
|
20
|
+
* (`null` for a root) and its {@link BirthSpec}.
|
|
21
|
+
*/
|
|
22
|
+
export type FreshOpening = {
|
|
23
|
+
agent: string;
|
|
24
|
+
origin: ThreadOrigin | null;
|
|
25
|
+
spec: BirthSpec;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A fork as a write-time callback sees it: its agent (the cut's thread's), the origin it records
|
|
29
|
+
* and the cut it continues from, its own environment and constraint owners as its spawn row records
|
|
30
|
+
* them, and `inherits`, what it goes on with from the cut and does not record: the route and the
|
|
31
|
+
* installations at that row.
|
|
32
|
+
*/
|
|
33
|
+
export type ForkOpening = {
|
|
34
|
+
agent: string;
|
|
35
|
+
origin: ThreadOrigin | null;
|
|
36
|
+
cut: RowRef;
|
|
37
|
+
environment: ThreadEnvironment;
|
|
38
|
+
requires: string[];
|
|
39
|
+
inherits: {
|
|
40
|
+
route: ModelRoute;
|
|
41
|
+
installations: InitialInstallation[];
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type ThreadRecord = {
|
|
45
|
+
thread_id: string;
|
|
46
|
+
agent_name: string;
|
|
47
|
+
metadata: JournalEvent<'thread/spawned'>['data']['metadata'];
|
|
48
|
+
/** The source thread and row this thread was forked at; `null` unless it is a fork. */
|
|
49
|
+
fork: ThreadFork | null;
|
|
50
|
+
origin: ThreadOrigin | null;
|
|
51
|
+
environment: ThreadEnvironment;
|
|
52
|
+
/** The constraint owners the thread's runs are under. */
|
|
53
|
+
requires: readonly string[];
|
|
54
|
+
/** The `thread/spawned` row. */
|
|
55
|
+
seq: Seq;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* A thread's identity, lineage and environment, from its spawn row. A fork's lineage replays its
|
|
59
|
+
* source's spawn row first and its own after it, so the fork's record is its own. The set of all
|
|
60
|
+
* threads is the journal's catalog, not a fold.
|
|
61
|
+
*/
|
|
62
|
+
export declare const threadRecord: Reducer<ThreadRecord | null>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { RunChain, Seq } from '../records/journal.js';
|
|
2
|
+
import type { Reducer } from './thread.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/guides/threads.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,64 @@
|
|
|
1
|
+
import type { JournalEvent, Seq } from '../records/journal.js';
|
|
2
|
+
import type { ReadonlyState } from '../util/foldState.js';
|
|
3
|
+
import type { ParsedToolCall } from '../llm/primitives.js';
|
|
4
|
+
import type { Reducer, ThreadState } from './thread.js';
|
|
5
|
+
import { type WaitEntry } from './waits.js';
|
|
6
|
+
export type ConfirmationState = {
|
|
7
|
+
request_id: string;
|
|
8
|
+
thread_id: string;
|
|
9
|
+
/** The exact model `tool/call` or runtime `execution/requested` row being approved. */
|
|
10
|
+
target: JournalEvent<'confirm/requested'>['data']['target'];
|
|
11
|
+
tool_call: ParsedToolCall;
|
|
12
|
+
reason: string;
|
|
13
|
+
resolution: {
|
|
14
|
+
approved: boolean;
|
|
15
|
+
rejection_message: string | null;
|
|
16
|
+
} | null;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A thread's confirmation requests and their answers, keyed by request id. Thread-scoped: an answer
|
|
20
|
+
* is written on the thread that asked, so a thread's confirmations are a function of its own rows.
|
|
21
|
+
* A fork starts with none: a fork is never cut with a request still open, and an inherited answer
|
|
22
|
+
* belongs to a call the source already finished.
|
|
23
|
+
*/
|
|
24
|
+
export declare const confirmations: Reducer<Map<string, ConfirmationState>>;
|
|
25
|
+
/** One runtime-owned operation and its authorization/result, reconstructed without redispatch. */
|
|
26
|
+
export type RuntimeExecution = {
|
|
27
|
+
seq: Seq;
|
|
28
|
+
request: JournalEvent<'execution/requested'>['data'];
|
|
29
|
+
authorization: {
|
|
30
|
+
seq: Seq;
|
|
31
|
+
data: JournalEvent<'execution/authorization'>['data'];
|
|
32
|
+
} | null;
|
|
33
|
+
result: {
|
|
34
|
+
seq: Seq;
|
|
35
|
+
value: JournalEvent<'execution/result'>['data']['result'];
|
|
36
|
+
} | null;
|
|
37
|
+
};
|
|
38
|
+
export declare const executions: Reducer<Map<Seq, RuntimeExecution>>;
|
|
39
|
+
/** Requests still waiting on the user on one thread. */
|
|
40
|
+
export declare const outstandingConfirmations: (state: ReadonlyMap<string, ReadonlyState<ConfirmationState>>, threadId: string) => ReadonlyState<ConfirmationState>[];
|
|
41
|
+
/**
|
|
42
|
+
* Model dispatches held by a pending confirmation or unresolved wait, by durable sequence.
|
|
43
|
+
* These holds survive turns: dispatching again before the answer or value would only raise a
|
|
44
|
+
* second request, or declare the wait twice.
|
|
45
|
+
*/
|
|
46
|
+
export declare const parkedCallSeqs: (confirmationState: ReadonlyMap<string, ReadonlyState<ConfirmationState>>, waitState: ReadonlyMap<Seq, WaitEntry>, threadId: string) => Set<Seq>;
|
|
47
|
+
/**
|
|
48
|
+
* The confirmation of one durable dispatch, pending or answered. Model and runtime dispatch share
|
|
49
|
+
* this lookup; a provider's call ID, request ID or source citation never grants approval authority.
|
|
50
|
+
*/
|
|
51
|
+
export declare const confirmationFor: (state: ReadonlyMap<string, ReadonlyState<ConfirmationState>>, dispatch: {
|
|
52
|
+
threadId: string;
|
|
53
|
+
target: ConfirmationState["target"];
|
|
54
|
+
}) => ReadonlyState<ConfirmationState> | undefined;
|
|
55
|
+
/** The thread's latest `confirm/resolved` row, or `null`: what tells a parked caller an answer landed under it. */
|
|
56
|
+
export declare const lastAnswer: Reducer<Seq | null>;
|
|
57
|
+
/**
|
|
58
|
+
* Confirmations on `threadId` whose call has no result yet and was not rejected: still waiting on the
|
|
59
|
+
* user, or approved. An approval lasts until the call's result: the call runs at the next turn, and
|
|
60
|
+
* one that waits or is cut off runs again on the same approval, against whatever tool answers to its
|
|
61
|
+
* name by then. Runtime approval belongs to its pending candidate; once that candidate is rejected
|
|
62
|
+
* or superseded it no longer blocks configuration. Unknown command cleanup is accounted separately.
|
|
63
|
+
*/
|
|
64
|
+
export declare function unfinishedConfirmations(state: ReadonlyState<Pick<ThreadState, 'confirmations' | 'executions' | 'answerCheck' | 'dispatchedCalls'>>, threadId: string): ReadonlyState<ConfirmationState>[];
|