@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,139 @@
|
|
|
1
|
+
import { Service, type Context, type ScopeKey } from '@leuduan/cordis';
|
|
2
|
+
import type { InitialInstallation, Installation, InstallationLifetime } from '../../records/journal.js';
|
|
3
|
+
import { type AnyPreset } from './definition.js';
|
|
4
|
+
import type { Thread } from '../threads/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* An installation a caller asks for, at creation (as an {@link InitialInstallationInput}) or later
|
|
7
|
+
* (`Thread.configure`).
|
|
8
|
+
*/
|
|
9
|
+
export type InstallationInput = {
|
|
10
|
+
readonly presetId: string;
|
|
11
|
+
readonly config?: unknown;
|
|
12
|
+
/**
|
|
13
|
+
* Unique within the change or the creation; generated when omitted. Given, it makes a retried
|
|
14
|
+
* application idempotent. A removed id is never accepted again.
|
|
15
|
+
*/
|
|
16
|
+
readonly installationId?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* An installation a thread is created with (`create`'s `installations`), with how long it lasts:
|
|
20
|
+
* `defining` ones are never removed, `configurable` ones are installations like any applied later.
|
|
21
|
+
* A creation preset is only ever `defining`.
|
|
22
|
+
*/
|
|
23
|
+
export type InitialInstallationInput = InstallationInput & {
|
|
24
|
+
readonly lifetime: InstallationLifetime;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* An installation a thread's scope hands down to every thread a call there creates; see
|
|
28
|
+
* {@link handDown}. The id is required: it is what keeps a hand-down from colliding with another in
|
|
29
|
+
* its layer or with the child's own installations.
|
|
30
|
+
*/
|
|
31
|
+
export type HandDown = {
|
|
32
|
+
readonly presetId: string;
|
|
33
|
+
readonly config?: unknown;
|
|
34
|
+
readonly installationId: string;
|
|
35
|
+
};
|
|
36
|
+
/** What a configuration change records, decided against the thread's installations as they stand. */
|
|
37
|
+
export type ConfigurationPlan = {
|
|
38
|
+
readonly rows: readonly ({
|
|
39
|
+
type: 'installation/applied';
|
|
40
|
+
data: Installation;
|
|
41
|
+
options: {
|
|
42
|
+
threadId: string;
|
|
43
|
+
};
|
|
44
|
+
} | {
|
|
45
|
+
type: 'installation/removed';
|
|
46
|
+
data: {
|
|
47
|
+
installation_id: string;
|
|
48
|
+
};
|
|
49
|
+
options: {
|
|
50
|
+
threadId: string;
|
|
51
|
+
};
|
|
52
|
+
})[];
|
|
53
|
+
/** Every installation the change applies, an earlier application of the same id included. */
|
|
54
|
+
readonly applied: readonly string[];
|
|
55
|
+
/** The installations it takes off; an id not installed is none. */
|
|
56
|
+
readonly removed: readonly string[];
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* What a preset installation means: the registry of presets a thread can install, how an
|
|
60
|
+
* installation is validated, an agent-defining one against its thread's agent included, which
|
|
61
|
+
* installations a thread's scope hands down to the children its calls create, and how a thread's
|
|
62
|
+
* recorded installations are mounted when it activates. A core service: the thread owner
|
|
63
|
+
* orchestrates creation, configuration and activation, and hands this service the thread, the scope
|
|
64
|
+
* or the state each question is about. Registrations do not survive a reload.
|
|
65
|
+
*/
|
|
66
|
+
export declare class PresetsService extends Service {
|
|
67
|
+
static inject: string[];
|
|
68
|
+
private readonly registry;
|
|
69
|
+
/** Each thread scope's hand-downs, in declaration order; the global layer stays empty. */
|
|
70
|
+
private readonly handDowns;
|
|
71
|
+
constructor(ctx: Context);
|
|
72
|
+
/** Makes `preset` installable on threads; returns the unregister function. */
|
|
73
|
+
register(preset: AnyPreset): () => void;
|
|
74
|
+
/** Whether a preset is registered under `presetId`. */
|
|
75
|
+
has(presetId: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The installations `entries` record, validated before anything is appended: a registered
|
|
78
|
+
* preset whose placement allows the use, a configuration its schema accepts and parses back to
|
|
79
|
+
* itself, and ids unique among them. At a creation on `agentName`, a preset that defines its
|
|
80
|
+
* thread's agent must define that one. Reads no thread state, so it fails only on a composition
|
|
81
|
+
* bug.
|
|
82
|
+
*/
|
|
83
|
+
installationsFor(entries: readonly InstallationInput[], use: 'creation' | 'change', agentName?: string): Installation[];
|
|
84
|
+
/**
|
|
85
|
+
* The installations a creation on `agentName` records, each with its lifetime: validated as
|
|
86
|
+
* {@link installationsFor} validates a creation's, and a creation preset refused unless it is
|
|
87
|
+
* `defining`, since it can never be applied again once removed.
|
|
88
|
+
*/
|
|
89
|
+
initialInstallations(entries: readonly InitialInstallationInput[], agentName: string): InitialInstallation[];
|
|
90
|
+
/**
|
|
91
|
+
* What a change records on `threadId`, decided against its installations as they stand:
|
|
92
|
+
* removals first, then applications, each id once. Removing an id not installed is no change; a
|
|
93
|
+
* defining installation is never removed. An application whose id is already this very
|
|
94
|
+
* installation, compared after defaults, is no change, which makes a retry idempotent; one whose
|
|
95
|
+
* id names another installation, or a removed one, is refused. The owner calls this before
|
|
96
|
+
* admitting the change and again inside its write.
|
|
97
|
+
*/
|
|
98
|
+
plan(threadId: string, apply: readonly Installation[], remove: readonly string[]): ConfigurationPlan;
|
|
99
|
+
/**
|
|
100
|
+
* Declares in `scope` that every thread a call there creates is born with `handDown` installed,
|
|
101
|
+
* as a defining installation; returns the withdraw function. Use {@link handDown}, which ties it
|
|
102
|
+
* to the declaring plugin. Refused in the global layer, where it would reach the children of every
|
|
103
|
+
* conversation; for a preset that is not registered, since a child restores it from the registry
|
|
104
|
+
* whether or not its parent is live; for a configuration its preset would not record; and for an
|
|
105
|
+
* installation id already handed down in the same layer, so no rule has to choose between two
|
|
106
|
+
* declarations.
|
|
107
|
+
*/
|
|
108
|
+
handDown(scope: ScopeKey | undefined, handDown: HandDown): () => void;
|
|
109
|
+
/**
|
|
110
|
+
* The installations a new thread on `agentName` is born with because the scope of the call
|
|
111
|
+
* creating it hands them down, each defining: from the closest layer out, each in declaration
|
|
112
|
+
* order, a closer declaration winning an id. Validated as the creation's own installations are,
|
|
113
|
+
* and refused when an id is also one of those: two owners for one installation is a composition
|
|
114
|
+
* bug, not something to resolve.
|
|
115
|
+
*/
|
|
116
|
+
handedDown(scope: ScopeKey, threadId: string, agentName: string, own: readonly Installation[]): InitialInstallation[];
|
|
117
|
+
/**
|
|
118
|
+
* Mounts every recorded installation of `thread`, one at a time in recorded order so that
|
|
119
|
+
* registration order is stable across reopening; the owner calls it once the activation's
|
|
120
|
+
* listeners have settled, so installations follow the listeners' own plugins. Any failure fails
|
|
121
|
+
* the activation, which a run turns into a rejection with the input kept.
|
|
122
|
+
*/
|
|
123
|
+
restore(thread: Thread): Promise<void>;
|
|
124
|
+
private requireRegistered;
|
|
125
|
+
/**
|
|
126
|
+
* Whether `installation`'s id is already this very installation. Throws when the id names a
|
|
127
|
+
* different installation, or one that was removed.
|
|
128
|
+
*/
|
|
129
|
+
private alreadyApplied;
|
|
130
|
+
}
|
|
131
|
+
/** Makes `preset` installable on threads for the lifetime of the calling plugin. */
|
|
132
|
+
export declare const registerPreset: (ctx: Context, preset: AnyPreset) => (() => void | Promise<void>);
|
|
133
|
+
/**
|
|
134
|
+
* Hands `handDown` down, for the lifetime of the calling plugin, from the thread scope it is
|
|
135
|
+
* mounted in to every new thread a call there creates: each child is born with it as a defining
|
|
136
|
+
* installation, recorded with its spawn row. See {@link PresetsService.handDown} for what is
|
|
137
|
+
* refused. Looks the service up, so a caller need not inject it.
|
|
138
|
+
*/
|
|
139
|
+
export declare function handDown(ctx: Context, handDown: HandDown): () => void | Promise<void>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Context, Service, type ScopeKey } from '@leuduan/cordis';
|
|
2
|
+
import { type PromptBlock } from '../llm/prompt.js';
|
|
3
|
+
import { type ToolEntry } from '../loop/index.js';
|
|
4
|
+
import type { AgentDefinition } from '../loop/index.js';
|
|
5
|
+
import type { ThreadSummary } from '../records/journal.js';
|
|
6
|
+
import { type AgentSelector } from './agents.js';
|
|
7
|
+
export type PromptSlot = 'base' | 'instruction' | 'context';
|
|
8
|
+
/**
|
|
9
|
+
* What a contribution is rendered against: the agent, where the thread works, and the tools it
|
|
10
|
+
* reaches.
|
|
11
|
+
*
|
|
12
|
+
* Deliberately not the thread's id or metadata. A recorded prompt is the head of every request a
|
|
13
|
+
* provider caches, so it must not depend on which thread it is: threads of one agent in one
|
|
14
|
+
* workspace then render the same prompt. Anything thread-specific belongs in the conversation, as
|
|
15
|
+
* a step contribution (see `workspaceNotice`).
|
|
16
|
+
*/
|
|
17
|
+
export type PromptRenderInput = {
|
|
18
|
+
readonly agent: AgentDefinition;
|
|
19
|
+
readonly thread: {
|
|
20
|
+
readonly environment: ThreadSummary['environment'];
|
|
21
|
+
};
|
|
22
|
+
/** What the agent may call from the rendering scope, as the registries stand at render time. */
|
|
23
|
+
readonly tools: readonly ToolEntry[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* One section a plugin adds to an agent's prompt.
|
|
27
|
+
*
|
|
28
|
+
* `render` is synchronous and pure in its inputs: anything needing IO reads it when the plugin
|
|
29
|
+
* mounts, and returns the cached value here. Returning `null` contributes nothing — or, for a tag
|
|
30
|
+
* that already exists, removes it.
|
|
31
|
+
*/
|
|
32
|
+
export type PromptContribution = {
|
|
33
|
+
readonly tag: string;
|
|
34
|
+
readonly slot: PromptSlot;
|
|
35
|
+
/** Which agents get it; see `AgentSelector`. */
|
|
36
|
+
readonly agents: AgentSelector;
|
|
37
|
+
/** Render order within the slot; ties break on `tag`. Default 0. */
|
|
38
|
+
readonly order?: number;
|
|
39
|
+
render(input: PromptRenderInput): string | null;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Prompt contributions, live like the other registries and layered by Cordis scope like tools:
|
|
43
|
+
* an untagged contribution is global, a contribution registered through a thread's context belongs
|
|
44
|
+
* to that thread's layer. The prompt itself is rendered once, when a thread first runs and every
|
|
45
|
+
* activation plugin is ready, and recorded on it; this service only says what that render
|
|
46
|
+
* would be right now.
|
|
47
|
+
*/
|
|
48
|
+
export declare class PromptsService extends Service {
|
|
49
|
+
static inject: string[];
|
|
50
|
+
private readonly layers;
|
|
51
|
+
constructor(ctx: Context);
|
|
52
|
+
/** Adds a contribution to one layer; returns the function that removes it. */
|
|
53
|
+
contribute(scope: ScopeKey | undefined, contribution: PromptContribution): () => void;
|
|
54
|
+
/**
|
|
55
|
+
* The prompt `agentName` would send on a thread rendered now from `scope`: the agent's base
|
|
56
|
+
* prompt, then the global layer's contributions, then each closer layer outward-in, each in
|
|
57
|
+
* declared order, never mount order. A contribution whose tag is already present replaces that
|
|
58
|
+
* section in place — so the closest layer wins a tag — and `null` removes it.
|
|
59
|
+
*
|
|
60
|
+
* The base prompt is seeded at the layer that defines the agent, so only that layer and closer
|
|
61
|
+
* ones can replace or remove it with a `base` contribution: for a global agent every layer can,
|
|
62
|
+
* while a scoped agent's own base prompt outranks every layer farther out. Instruction and context
|
|
63
|
+
* contributions apply from every layer. Throws for an agent unknown from `scope`.
|
|
64
|
+
*/
|
|
65
|
+
render(scope: ScopeKey | undefined, agentName: string, thread: PromptRenderInput['thread']): PromptBlock[];
|
|
66
|
+
}
|
|
67
|
+
/** Registers a contribution in the calling plugin's layer for the lifetime of its fiber. */
|
|
68
|
+
export declare const contributePrompt: (ctx: Context, contribution: PromptContribution) => (() => void | Promise<void>);
|
|
69
|
+
export type TaggedSection = {
|
|
70
|
+
tag: string;
|
|
71
|
+
content: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* A prompt as `ctx.prompts` assembles it: the agent's base prompt, then instruction sections, then
|
|
75
|
+
* context sections, so a section's bucket is what decides its position. The rendered result is
|
|
76
|
+
* recorded per thread.
|
|
77
|
+
*/
|
|
78
|
+
export type SystemPrompt = {
|
|
79
|
+
basePrompt: string;
|
|
80
|
+
instructions: TaggedSection[];
|
|
81
|
+
contextSections: TaggedSection[];
|
|
82
|
+
};
|
|
83
|
+
/** The prompt as ordered blocks — the one place its order is decided. */
|
|
84
|
+
export declare function systemPromptBlocks(prompt: SystemPrompt): PromptBlock[];
|
|
85
|
+
export declare const renderSystemPrompt: (prompt: SystemPrompt) => string;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type Context, type Scope, type Scoped, type ScopeKey } from '@leuduan/cordis';
|
|
2
|
+
import { type CompactOptions, type Lease, type LoopServices, type SurfacePrepareOutcome } from '../../loop/index.js';
|
|
3
|
+
import type { ServedRun } from '../../loop/index.js';
|
|
4
|
+
import type { Thread } from './thread.js';
|
|
5
|
+
import type { AdmissionView } from './admission.js';
|
|
6
|
+
import type { ThreadsService } from './service.js';
|
|
7
|
+
/**
|
|
8
|
+
* One process-local activation: the thread's Cordis scope, the plugins mounted in it, their
|
|
9
|
+
* readiness, and the loop that runs in it. It owns resources, never admission: which operation
|
|
10
|
+
* holds the thread, and its cancellation, are the admission owner's, which the threads service
|
|
11
|
+
* keeps and which hands each run or compaction its signal and lease.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ThreadActivation {
|
|
14
|
+
readonly scope: Scope;
|
|
15
|
+
readonly target: Scoped;
|
|
16
|
+
private readonly runtime;
|
|
17
|
+
private readonly loop;
|
|
18
|
+
private readiness;
|
|
19
|
+
private readonly controller;
|
|
20
|
+
private failed;
|
|
21
|
+
private prepared;
|
|
22
|
+
/** The plugin tree as it was when the activation became ready, which is what it runs with. */
|
|
23
|
+
private readyTree;
|
|
24
|
+
private staleBecause;
|
|
25
|
+
private draining;
|
|
26
|
+
private closingDone;
|
|
27
|
+
private readonly service;
|
|
28
|
+
private readonly admission;
|
|
29
|
+
readonly thread: Thread;
|
|
30
|
+
private readonly released;
|
|
31
|
+
constructor(service: ThreadsService,
|
|
32
|
+
/** The admission owner's reads, given by the service that owns it. */
|
|
33
|
+
admission: AdmissionView, owner: Context, thread: Thread, loopServices: (scope: ScopeKey) => LoopServices, released: () => void);
|
|
34
|
+
/**
|
|
35
|
+
* From readiness on, the plugin tree is what the activation runs with. A guard on each of its
|
|
36
|
+
* plugins marks the activation stale before that plugin's disposers run, whatever unloads it: a
|
|
37
|
+
* dependency gone, a root mount disposed, a reload. Its own release marks it too, harmlessly.
|
|
38
|
+
*/
|
|
39
|
+
private watchTree;
|
|
40
|
+
private markStale;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the plugins changed since readiness: one unloaded or reloaded, or one added through
|
|
43
|
+
* `thread.ctx`, which is reported once. A stale activation dispatches nothing new, and the owner
|
|
44
|
+
* replaces it once the operation holding the thread settles.
|
|
45
|
+
*/
|
|
46
|
+
isStale(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether a setup in this activation is still running: its listeners and installations have not
|
|
49
|
+
* settled, or a plugin of its tree is in transition, one mounted later through `thread.ctx` or one
|
|
50
|
+
* reloading included. A change that waits for this activation to go, made from one of those
|
|
51
|
+
* setups, would wait on itself, so it is refused meanwhile. Not a readiness check: readiness is
|
|
52
|
+
* settled once.
|
|
53
|
+
*/
|
|
54
|
+
get activating(): boolean;
|
|
55
|
+
private observe;
|
|
56
|
+
/** Aborts on release and on stop; what the activate listeners receive. */
|
|
57
|
+
get signal(): AbortSignal;
|
|
58
|
+
/** Whether readiness failed: the owner releases such an activation once its operation settles. */
|
|
59
|
+
get hasFailed(): boolean;
|
|
60
|
+
/** Set once `release()` has begun: resolves when the scope is disposed. The owner waits for it before activating again. */
|
|
61
|
+
get closed(): Promise<void> | undefined;
|
|
62
|
+
private settle;
|
|
63
|
+
/** One execution of the run `served`, under the admitted operation's signal and lease. */
|
|
64
|
+
run(options: {
|
|
65
|
+
signal: AbortSignal;
|
|
66
|
+
lease: Lease;
|
|
67
|
+
served: ServedRun;
|
|
68
|
+
}): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* One request to prepare the surface, under the admitted operation's signal and lease; see
|
|
71
|
+
* `Thread.compact`. Resolves with the outcome, `cancelled` when the signal aborts first.
|
|
72
|
+
*/
|
|
73
|
+
compact(options: CompactOptions & {
|
|
74
|
+
signal: AbortSignal;
|
|
75
|
+
lease: Lease;
|
|
76
|
+
}): Promise<SurfacePrepareOutcome>;
|
|
77
|
+
/**
|
|
78
|
+
* Waits for readiness, settled once when the activation began, then checks the agent and records
|
|
79
|
+
* the prompt if the thread has none. Only then is the scope complete: the thread's plugins may
|
|
80
|
+
* define its agent, and an unknown one fails here, before a prompt is recorded or a turn opens,
|
|
81
|
+
* so input waits for a retry. A stale activation never gets here: the owner replaces it first.
|
|
82
|
+
*/
|
|
83
|
+
private ready;
|
|
84
|
+
/**
|
|
85
|
+
* Resolves once the activation is ready: its listeners and installations settled, every plugin of
|
|
86
|
+
* its tree active. The same barrier a run uses: a settled but PENDING plugin is not ready, so a
|
|
87
|
+
* caller never reads a half-configured scope.
|
|
88
|
+
*/
|
|
89
|
+
whenReady(): Promise<void>;
|
|
90
|
+
/** The owner releases scopes only after every thread has drained, including failed setup. */
|
|
91
|
+
stop(reason: Error): void;
|
|
92
|
+
/** Resolves once setup has ended, however, and every plugin mounted since is settled. */
|
|
93
|
+
whenIdle(): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Disposes the scope once setup has ended. The owner calls this with no executing operation on
|
|
96
|
+
* the thread, or from the operation that is settling; the scope's own unload guard is what waits
|
|
97
|
+
* for a loop when something else disposes the scope.
|
|
98
|
+
*/
|
|
99
|
+
release(): Promise<void>;
|
|
100
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { Lease } from '../../loop/index.js';
|
|
2
|
+
import type { CancelIntent, InboxTarget } from '../../records/journal.js';
|
|
3
|
+
/**
|
|
4
|
+
* An exclusive operation on one thread; see `Admission.onOperation`. A `cancel` holds the thread from a
|
|
5
|
+
* `cancel()` until its write has landed and what it cancelled has released the thread.
|
|
6
|
+
*/
|
|
7
|
+
export type OperationKind = 'run' | 'compact' | 'rebuild' | 'configure' | 'release' | 'cancel';
|
|
8
|
+
/** How an operation ended: as asked, by throwing, or because it was cancelled or lagent closed. */
|
|
9
|
+
export type OperationEnding = 'completed' | 'failed' | 'cancelled';
|
|
10
|
+
/** What holds a thread: the operation's kind, and the run request a run serves (`null` for any other). */
|
|
11
|
+
export type OperationHolder = {
|
|
12
|
+
readonly kind: OperationKind;
|
|
13
|
+
readonly runId: string | null;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* What `onOperation` listeners are told: an operation was admitted on a thread, or it settled and
|
|
17
|
+
* how. Process-local and never a journal row; `settled` is published once admission is released,
|
|
18
|
+
* so a listener may start the thread's next operation from it.
|
|
19
|
+
*/
|
|
20
|
+
export type OperationEvent = {
|
|
21
|
+
readonly thread_id: string;
|
|
22
|
+
readonly kind: OperationKind;
|
|
23
|
+
readonly phase: 'admitted';
|
|
24
|
+
} | {
|
|
25
|
+
readonly thread_id: string;
|
|
26
|
+
readonly kind: OperationKind;
|
|
27
|
+
readonly phase: 'settled';
|
|
28
|
+
readonly ended: OperationEnding;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* An admitted operation as the code running it sees it: what it is, and the signal and lease it
|
|
32
|
+
* hands to the work. Everything else about it is the owner's.
|
|
33
|
+
*/
|
|
34
|
+
export type AdmittedOperation = {
|
|
35
|
+
readonly threadId: string;
|
|
36
|
+
readonly kind: OperationKind;
|
|
37
|
+
/** The run request a run serves; `null` for any other operation. */
|
|
38
|
+
readonly runId: string | null;
|
|
39
|
+
readonly signal: AbortSignal;
|
|
40
|
+
readonly lease: Lease;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* What a thread's handle and its activation ask the owner: whether it runs, where input waits, the
|
|
44
|
+
* cancel, and the unload guard's wait. Nothing that admits or settles an operation.
|
|
45
|
+
*/
|
|
46
|
+
export type AdmissionView = Pick<Admission, 'isRunning' | 'inputTarget' | 'cancel' | 'whenSettled' | 'isAdmitted'>;
|
|
47
|
+
/**
|
|
48
|
+
* What one `cancel()` gets back: the run of the execution the thread's cancel captured, if it
|
|
49
|
+
* captured a run, and the one settlement of that cancel. `wrote` reports the call's own write,
|
|
50
|
+
* once it is queued, and only then aborts what the call captured, so a cancel an abort listener
|
|
51
|
+
* makes is written after this one. `capturedSettles` says, read inside that write, whether the
|
|
52
|
+
* captured execution's finalization is still to build its run's settlement: until then the
|
|
53
|
+
* finalization settles it by the cancel's intent; after, what it built stands, and a run it left
|
|
54
|
+
* pending is the cancel's to settle.
|
|
55
|
+
*/
|
|
56
|
+
export type CancelHandle = {
|
|
57
|
+
readonly capturedRunId: string | null;
|
|
58
|
+
readonly settled: Promise<void>;
|
|
59
|
+
capturedSettles(): boolean;
|
|
60
|
+
wrote(write: Promise<unknown>): void;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The one owner of which operation holds each thread: admission or refusal, the releasing phase,
|
|
64
|
+
* cancellation, and the publication of admission and settlement in the order
|
|
65
|
+
* docs/guides/threads.md#ordering states. It knows nothing of activations; the threads service runs
|
|
66
|
+
* each operation's work, and disposes activations under it, through `hold`.
|
|
67
|
+
*/
|
|
68
|
+
export declare class Admission {
|
|
69
|
+
/**
|
|
70
|
+
* The one operation admitted on each thread, from before its first `await` until its work and
|
|
71
|
+
* cleanup settled: what `cancel()` aborts and awaits, what refuses a second operation as busy,
|
|
72
|
+
* and what says whether input joins a run's next step.
|
|
73
|
+
*/
|
|
74
|
+
private readonly admitted;
|
|
75
|
+
/** The cancel in progress on each thread, from its first call until it settles. */
|
|
76
|
+
private readonly cancels;
|
|
77
|
+
private readonly listeners;
|
|
78
|
+
private readonly closing;
|
|
79
|
+
private readonly report;
|
|
80
|
+
/**
|
|
81
|
+
* @param closing aborts once lagent is closing: nothing is admitted after, and it is composed
|
|
82
|
+
* into every operation's signal.
|
|
83
|
+
*/
|
|
84
|
+
constructor(closing: AbortSignal, report: (error: unknown) => void);
|
|
85
|
+
/** Refuses as admission would, without admitting: once lagent is closing, or busy while an operation holds the thread. */
|
|
86
|
+
requireFree(threadId: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* Admits `kind` on the thread, or refuses it busy, synchronously, and publishes `admitted` before
|
|
89
|
+
* returning. The operation's signal composes shutdown's, `cancel()`'s and the caller's; its lease
|
|
90
|
+
* says whether it still holds the thread, for a callback that escaped it. A configuration change
|
|
91
|
+
* is admitted releasing: it starts by releasing the live activation, before anything can see it.
|
|
92
|
+
*/
|
|
93
|
+
admit(threadId: string, kind: OperationKind, options?: {
|
|
94
|
+
readonly signal?: AbortSignal | undefined;
|
|
95
|
+
readonly runId?: string | undefined;
|
|
96
|
+
}): AdmittedOperation;
|
|
97
|
+
private operation;
|
|
98
|
+
/**
|
|
99
|
+
* Runs `work` as the admitted operation, then the disposal `cleanup` returns, if any, then its
|
|
100
|
+
* `finalize`, if any, both still under it, then releases admission and publishes `settled` in the
|
|
101
|
+
* same synchronous step, however `work` ended. `finalize` runs in the releasing phase: the
|
|
102
|
+
* operation still holds the thread, so nothing else is admitted and nothing mounts, but it executes
|
|
103
|
+
* nothing more, and input sent meanwhile waits for the next turn. It runs again when a cancel
|
|
104
|
+
* captured the operation while it ran, so it must be safe to repeat. Without either step nothing is
|
|
105
|
+
* awaited between the work's end and the release. The value `work` returns is its own, taken
|
|
106
|
+
* before admission is released. A failing finalization or disposal is reported; the admission is
|
|
107
|
+
* released all the same.
|
|
108
|
+
*/
|
|
109
|
+
hold<T>(admitted: AdmittedOperation, work: () => Promise<T>, steps?: {
|
|
110
|
+
readonly finalize?: () => Promise<void>;
|
|
111
|
+
readonly cleanup?: () => Promise<void> | undefined;
|
|
112
|
+
}): Promise<T>;
|
|
113
|
+
/**
|
|
114
|
+
* Enters or leaves the operation's releasing phase; entering wakes whatever waits for it to stop
|
|
115
|
+
* executing. Set by whoever disposes an activation under the operation, before the disposal starts.
|
|
116
|
+
*/
|
|
117
|
+
setReleasing(admitted: AdmittedOperation, releasing: boolean): void;
|
|
118
|
+
/**
|
|
119
|
+
* Starts the thread's cancel, or joins the one in progress, synchronously. The first call captures
|
|
120
|
+
* the operation admitted now, if any, and marks it with its intent; `wrote` aborts it (a release is
|
|
121
|
+
* waited for, never aborted). The run that operation serves settles by the intent of the first
|
|
122
|
+
* cancel that reached it. With nothing
|
|
123
|
+
* admitted, a `cancel` operation holds the thread at once, closing or not, since a shutdown still
|
|
124
|
+
* cancels. Either way the cancel holds the thread, refusing a run as busy, until every joined
|
|
125
|
+
* call's write has finished, landed or failed (`wrote`), and the captured operation has released;
|
|
126
|
+
* its `settled` then resolves, once for every call.
|
|
127
|
+
*/
|
|
128
|
+
cancel(threadId: string, reason: string, intent: CancelIntent): CancelHandle;
|
|
129
|
+
/** The intent of the first cancel that captured `admitted`, or `null`: what the run it serves settles by. */
|
|
130
|
+
cancelIntent(admitted: AdmittedOperation): CancelIntent | null;
|
|
131
|
+
/**
|
|
132
|
+
* Records, inside the finalization's write, that `admitted` built its run's settlement: a cancel
|
|
133
|
+
* written after it settles a run that build left pending.
|
|
134
|
+
*/
|
|
135
|
+
settlementBuilt(admitted: AdmittedOperation): void;
|
|
136
|
+
/** The thread's cancel holds the thread as a `cancel` operation of its own; published by the caller. */
|
|
137
|
+
private holdForCancel;
|
|
138
|
+
private wroteCancel;
|
|
139
|
+
/** Settles the thread's cancel once every joined write finished and what it captured released. */
|
|
140
|
+
private finishCancel;
|
|
141
|
+
/** What holds the thread now, or `null`. */
|
|
142
|
+
holder(threadId: string): OperationHolder | null;
|
|
143
|
+
/** Whether any operation holds the thread. */
|
|
144
|
+
isAdmitted(threadId: string): boolean;
|
|
145
|
+
/** Whether a run or a compaction holds the thread: what `Thread.status()` calls running. */
|
|
146
|
+
isRunning(threadId: string): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Whether the operation holding the thread is disposing its activation, a release or another in
|
|
149
|
+
* its releasing phase: nothing of the thread may be mounted meanwhile, and it executes nothing.
|
|
150
|
+
*/
|
|
151
|
+
isReleasing(threadId: string): boolean;
|
|
152
|
+
/** Where input sent now waits: a run's next step while a run holds the thread and is not cancelled, else the next turn. */
|
|
153
|
+
inputTarget(threadId: string): InboxTarget;
|
|
154
|
+
/** Resolves once the operation holding the thread now, if any, has settled. */
|
|
155
|
+
settlement(threadId: string): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Resolves once no operation that executes holds the thread: what an activation waits for before
|
|
158
|
+
* it disposes, so a scope never goes under a running loop. An operation disposing the activation
|
|
159
|
+
* is not waited for, since that would be the disposal waiting on itself.
|
|
160
|
+
*/
|
|
161
|
+
whenSettled(threadId: string): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Resolves once no operation holds any thread and no cancel is in progress: what shutdown waits
|
|
164
|
+
* for before releasing scopes. Read again after each wait, since a cancel takes over a thread its
|
|
165
|
+
* captured operation releases, and a shutdown still cancels.
|
|
166
|
+
*/
|
|
167
|
+
drain(): Promise<void>;
|
|
168
|
+
/** Tells `listener` when an operation is admitted on any thread and when it settled; see {@link OperationEvent}. */
|
|
169
|
+
onOperation(listener: (event: OperationEvent) => void): () => void;
|
|
170
|
+
/** The owner's record of `admitted`, which must hold its thread: anything else is a caller bug. */
|
|
171
|
+
private holding;
|
|
172
|
+
/** One frozen copy for every listener, so no listener can change what the next one sees. */
|
|
173
|
+
private publish;
|
|
174
|
+
}
|