@leuduan/lagent 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +144 -2
- package/dist/chunks/2O7ZGEIT.js +1 -0
- package/dist/chunks/2OSESBIL.js +1 -0
- package/dist/chunks/34KW6VNQ.js +1 -0
- package/dist/chunks/37YOGDGY.js +1 -0
- package/dist/chunks/3LQHQRIU.js +6 -0
- package/dist/chunks/3QCW4WDJ.js +1 -0
- package/dist/chunks/4XVRUSCQ.js +1 -0
- package/dist/chunks/6ECI2GGV.js +1 -0
- package/dist/chunks/74HKUGRR.js +1 -0
- package/dist/chunks/ADHERZLW.js +2 -0
- package/dist/chunks/AP6Q4EPT.js +36 -0
- package/dist/chunks/BM3S37EZ.js +1 -0
- package/dist/chunks/C5LYCXJG.js +1 -0
- package/dist/chunks/CDQG7RKA.js +1 -0
- package/dist/chunks/D7E6EWIE.js +3 -0
- package/dist/chunks/DDANMY45.js +3 -0
- package/dist/chunks/DRYAN665.js +1 -0
- package/dist/chunks/DXFXAYDN.js +17 -0
- package/dist/chunks/EGZI4XQX.js +24 -0
- package/dist/chunks/ENWFSU27.js +41 -0
- package/dist/chunks/G6RXC3AL.js +1 -0
- package/dist/chunks/G74AGRAJ.js +15 -0
- package/dist/chunks/GQGNVSKB.js +1 -0
- package/dist/chunks/IJ2WNMD5.js +7 -0
- package/dist/chunks/J5S4URAW.js +1 -0
- package/dist/chunks/JPZFKSWT.js +1 -0
- package/dist/chunks/KESCTXGO.js +5 -0
- package/dist/chunks/L3N4FIEN.js +1 -0
- package/dist/chunks/NAOUTU7A.js +4 -0
- package/dist/chunks/NDIM7MEW.js +1 -0
- package/dist/chunks/O4PPOM5Z.js +2 -0
- package/dist/chunks/OVZFGILJ.js +1 -0
- package/dist/chunks/P5ZHHOOM.js +6 -0
- package/dist/chunks/PUSUPTAT.js +1 -0
- package/dist/chunks/QMMLQJBS.js +1 -0
- package/dist/chunks/RK3VP2Q4.js +3 -0
- package/dist/chunks/SGGMBSBA.js +1 -0
- package/dist/chunks/SL2YLB2F.js +1 -0
- package/dist/chunks/TOOIB6J2.js +1 -0
- package/dist/chunks/TYTQRLTX.js +1 -0
- package/dist/chunks/UC3FVVJ2.js +5 -0
- package/dist/chunks/UCTEU62F.js +1 -0
- package/dist/chunks/UD3VJER6.js +1 -0
- package/dist/chunks/UKXMCHHT.js +1 -0
- package/dist/chunks/WUUKTSRT.js +7 -0
- package/dist/chunks/X65X4KP5.js +7 -0
- package/dist/chunks/YIR5MYGU.js +1 -0
- package/dist/chunks/YLNJXQ3Z.js +1 -0
- package/dist/context.d.ts +101 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +77 -0
- package/dist/journal/catalog.d.ts +112 -0
- package/dist/journal/forkChain.d.ts +16 -0
- package/dist/journal/index.d.ts +15 -0
- package/dist/journal/journal.d.ts +475 -0
- package/dist/journal/projection.d.ts +87 -0
- package/dist/journal/store.d.ts +181 -0
- package/dist/kit/claim.d.ts +13 -0
- package/dist/kit/drain.d.ts +10 -0
- package/dist/kit/extension.d.ts +180 -0
- package/dist/kit/grants.d.ts +9 -0
- package/dist/kit/modes.d.ts +65 -0
- package/dist/kit/retries.d.ts +25 -0
- package/dist/kit/scope.d.ts +32 -0
- package/dist/kit/service.d.ts +7 -0
- package/dist/kit/strategy.d.ts +10 -0
- package/dist/kit/timers.d.ts +43 -0
- package/dist/kit/tool.d.ts +72 -0
- package/dist/llm/client.d.ts +135 -0
- package/dist/llm/content.d.ts +52 -0
- package/dist/llm/door.d.ts +21 -0
- package/dist/llm/door.js +1 -0
- package/dist/llm/failure.d.ts +82 -0
- package/dist/llm/index.d.ts +16 -0
- package/dist/llm/primitives.d.ts +286 -0
- package/dist/llm/prompt.d.ts +21 -0
- package/dist/llm/provider.d.ts +63 -0
- package/dist/llm/readLedger.d.ts +24 -0
- package/dist/llm/request.d.ts +58 -0
- package/dist/loop/agent.d.ts +134 -0
- package/dist/loop/auxiliary.d.ts +54 -0
- package/dist/loop/chain.d.ts +46 -0
- package/dist/loop/chunks.d.ts +27 -0
- package/dist/loop/continuation.d.ts +166 -0
- package/dist/loop/decide.d.ts +64 -0
- package/dist/loop/errors.d.ts +162 -0
- package/dist/loop/forks.d.ts +61 -0
- package/dist/loop/holds.d.ts +104 -0
- package/dist/loop/hooks.d.ts +241 -0
- package/dist/loop/inbox.d.ts +188 -0
- package/dist/loop/index.d.ts +37 -0
- package/dist/loop/limits.d.ts +14 -0
- package/dist/loop/opening.d.ts +42 -0
- package/dist/loop/prepare.d.ts +30 -0
- package/dist/loop/projections.d.ts +307 -0
- package/dist/loop/replace.d.ts +33 -0
- package/dist/loop/requests.d.ts +129 -0
- package/dist/loop/route.d.ts +53 -0
- package/dist/loop/runtime.d.ts +85 -0
- package/dist/loop/state.d.ts +70 -0
- package/dist/loop/strategy.d.ts +71 -0
- package/dist/loop/summary.d.ts +3 -0
- package/dist/loop/surface.d.ts +153 -0
- package/dist/loop/threadState.d.ts +72 -0
- package/dist/loop/tool.d.ts +101 -0
- package/dist/loop/toolCalls.d.ts +42 -0
- package/dist/loop/wake.d.ts +32 -0
- package/dist/models/config/agent.d.ts +18 -0
- package/dist/models/config/prompt.d.ts +18 -0
- package/dist/models/door.d.ts +12 -0
- package/dist/models/door.js +1 -0
- package/dist/models/index.d.ts +7 -0
- package/dist/models/jsonSchema.d.ts +7 -0
- package/dist/models/wire/journal.d.ts +2772 -0
- package/dist/models/wire/primitives.d.ts +65 -0
- package/dist/plugin.d.ts +53 -0
- package/dist/plugin.js +1 -0
- package/dist/plugins/agentsMd.d.ts +76 -0
- package/dist/plugins/agentsMd.js +1 -0
- package/dist/plugins/ask/askQuestion.d.ts +9 -0
- package/dist/plugins/ask/index.d.ts +26 -0
- package/dist/plugins/ask/index.js +1 -0
- package/dist/plugins/ask/service.d.ts +125 -0
- package/dist/plugins/commands/background.d.ts +8 -0
- package/dist/plugins/commands/foreground.d.ts +4 -0
- package/dist/plugins/commands/index.d.ts +40 -0
- package/dist/plugins/commands/index.js +1 -0
- package/dist/plugins/commands/output.d.ts +115 -0
- package/dist/plugins/commands/record.d.ts +549 -0
- package/dist/plugins/commands/service.d.ts +314 -0
- package/dist/plugins/commands/shell.d.ts +25 -0
- package/dist/plugins/compaction/checkpoint.d.ts +91 -0
- package/dist/plugins/compaction/config.d.ts +133 -0
- package/dist/plugins/compaction/estimate.d.ts +29 -0
- package/dist/plugins/compaction/index.d.ts +2 -0
- package/dist/plugins/compaction/index.js +7 -0
- package/dist/plugins/compaction/log.d.ts +61 -0
- package/dist/plugins/compaction/planner.d.ts +207 -0
- package/dist/plugins/compaction/preset.d.ts +86 -0
- package/dist/plugins/compaction/prune.d.ts +9 -0
- package/dist/plugins/compaction/records.d.ts +227 -0
- package/dist/plugins/compaction/segments.d.ts +23 -0
- package/dist/plugins/compaction/shared.d.ts +14 -0
- package/dist/plugins/compaction/summarize.d.ts +13 -0
- package/dist/plugins/dateAndBranch.d.ts +47 -0
- package/dist/plugins/dateAndBranch.js +1 -0
- package/dist/plugins/delegations/answers.d.ts +39 -0
- package/dist/plugins/delegations/assignmentKey.d.ts +22 -0
- package/dist/plugins/delegations/cleanup.d.ts +161 -0
- package/dist/plugins/delegations/constraint.d.ts +76 -0
- package/dist/plugins/delegations/index.d.ts +39 -0
- package/dist/plugins/delegations/index.js +1 -0
- package/dist/plugins/delegations/notices.d.ts +261 -0
- package/dist/plugins/delegations/obligations.d.ts +210 -0
- package/dist/plugins/delegations/record.d.ts +632 -0
- package/dist/plugins/delegations/request.d.ts +381 -0
- package/dist/plugins/delegations/role.d.ts +30 -0
- package/dist/plugins/delegations/service.d.ts +562 -0
- package/dist/plugins/delegations/standing.d.ts +19 -0
- package/dist/plugins/delegations/stopCheck.d.ts +21 -0
- package/dist/plugins/delegations/testing.d.ts +16 -0
- package/dist/plugins/delegations/tools.d.ts +71 -0
- package/dist/plugins/delegations/waitBook.d.ts +116 -0
- package/dist/plugins/delegations/waits.d.ts +118 -0
- package/dist/plugins/diagnostics/digest.d.ts +14 -0
- package/dist/plugins/diagnostics/index.d.ts +68 -0
- package/dist/plugins/diagnostics/index.js +1 -0
- package/dist/plugins/historyRecall/history.d.ts +9 -0
- package/dist/plugins/historyRecall/index.d.ts +31 -0
- package/dist/plugins/historyRecall/index.js +1 -0
- package/dist/plugins/historyRecall/render.d.ts +34 -0
- package/dist/plugins/historyRecall/tools.d.ts +4 -0
- package/dist/plugins/mcp/catalog.d.ts +36 -0
- package/dist/plugins/mcp/config.d.ts +63 -0
- package/dist/plugins/mcp/connection.d.ts +53 -0
- package/dist/plugins/mcp/errors.d.ts +32 -0
- package/dist/plugins/mcp/index.d.ts +33 -0
- package/dist/plugins/mcp/index.js +5 -0
- package/dist/plugins/mcp/mount.d.ts +98 -0
- package/dist/plugins/mcp/names.d.ts +25 -0
- package/dist/plugins/mcp/render.d.ts +29 -0
- package/dist/plugins/mcp/slots.d.ts +15 -0
- package/dist/plugins/mcp/stdio.d.ts +49 -0
- package/dist/plugins/mcp/tool.d.ts +41 -0
- package/dist/plugins/providers/anthropic.d.ts +175 -0
- package/dist/plugins/providers/anthropicMessages.d.ts +65 -0
- package/dist/plugins/providers/codex.d.ts +60 -0
- package/dist/plugins/providers/codexAuth.d.ts +116 -0
- package/dist/plugins/providers/deepseek.d.ts +55 -0
- package/dist/plugins/providers/door.d.ts +61 -0
- package/dist/plugins/providers/door.js +1 -0
- package/dist/plugins/providers/failure.d.ts +23 -0
- package/dist/plugins/providers/gateway.d.ts +23 -0
- package/dist/plugins/providers/index.d.ts +6 -0
- package/dist/plugins/providers/openaiChat.d.ts +62 -0
- package/dist/plugins/providers/openaiResponses.d.ts +100 -0
- package/dist/plugins/providers/opencodeCopilot.d.ts +23 -0
- package/dist/plugins/providers/opencodeGo.d.ts +98 -0
- package/dist/plugins/providers/shared.d.ts +104 -0
- package/dist/plugins/providers/stream.d.ts +154 -0
- package/dist/plugins/routeContext.d.ts +22 -0
- package/dist/plugins/routeContext.js +1 -0
- package/dist/plugins/schedules/index.d.ts +21 -0
- package/dist/plugins/schedules/index.js +5 -0
- package/dist/plugins/schedules/record.d.ts +396 -0
- package/dist/plugins/schedules/service.d.ts +120 -0
- package/dist/plugins/schedules/time.d.ts +26 -0
- package/dist/plugins/schedules/tools.d.ts +6 -0
- package/dist/plugins/skills/discovery.d.ts +54 -0
- package/dist/plugins/skills/index.d.ts +31 -0
- package/dist/plugins/skills/index.js +1 -0
- package/dist/plugins/skills/tool.d.ts +11 -0
- package/dist/plugins/store/durableObject.d.ts +23 -0
- package/dist/plugins/store/durableObject.js +1 -0
- package/dist/plugins/store/durableObjectConnection.d.ts +27 -0
- package/dist/plugins/store/memory.d.ts +29 -0
- package/dist/plugins/store/sql.d.ts +59 -0
- package/dist/plugins/store/sqlite.d.ts +31 -0
- package/dist/plugins/store/sqlite.js +1 -0
- package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
- package/dist/plugins/subAgents/fork.d.ts +32 -0
- package/dist/plugins/subAgents/index.d.ts +67 -0
- package/dist/plugins/subAgents/index.js +1 -0
- package/dist/plugins/subAgents/tool.d.ts +38 -0
- package/dist/plugins/toolPolicy/index.d.ts +61 -0
- package/dist/plugins/toolPolicy/index.js +1 -0
- package/dist/plugins/tools/editFiles.d.ts +128 -0
- package/dist/plugins/tools/fsRead.d.ts +17 -0
- package/dist/plugins/tools/html.d.ts +23 -0
- package/dist/plugins/tools/index.d.ts +59 -0
- package/dist/plugins/tools/index.js +1 -0
- package/dist/plugins/tools/network.d.ts +23 -0
- package/dist/plugins/tools/ripgrep.d.ts +20 -0
- package/dist/plugins/tools/textEdit.d.ts +67 -0
- package/dist/plugins/tools/web.d.ts +32 -0
- package/dist/plugins/truncateToolOutput.d.ts +26 -0
- package/dist/plugins/truncateToolOutput.js +1 -0
- package/dist/plugins/usage/index.d.ts +24 -0
- package/dist/plugins/usage/index.js +1 -0
- package/dist/plugins/usage/tracker.d.ts +34 -0
- package/dist/plugins/verify/facts.d.ts +356 -0
- package/dist/plugins/verify/index.d.ts +75 -0
- package/dist/plugins/verify/index.js +1 -0
- package/dist/plugins/verify/service.d.ts +90 -0
- package/dist/plugins/workflows/assignment.d.ts +16 -0
- package/dist/plugins/workflows/bindings.d.ts +95 -0
- package/dist/plugins/workflows/cleanup.d.ts +38 -0
- package/dist/plugins/workflows/definition.d.ts +184 -0
- package/dist/plugins/workflows/fold.d.ts +373 -0
- package/dist/plugins/workflows/index.d.ts +28 -0
- package/dist/plugins/workflows/index.js +6 -0
- package/dist/plugins/workflows/observations.d.ts +81 -0
- package/dist/plugins/workflows/participants.d.ts +143 -0
- package/dist/plugins/workflows/policy.d.ts +112 -0
- package/dist/plugins/workflows/providers.d.ts +146 -0
- package/dist/plugins/workflows/record.d.ts +2863 -0
- package/dist/plugins/workflows/routing.d.ts +116 -0
- package/dist/plugins/workflows/schema.d.ts +26 -0
- package/dist/plugins/workflows/service.d.ts +477 -0
- package/dist/plugins/workflows/submit.d.ts +8 -0
- package/dist/plugins/workflows/view.d.ts +103 -0
- package/dist/plugins/workflows/work.d.ts +21 -0
- package/dist/plugins/workspaceContext.d.ts +38 -0
- package/dist/plugins/workspaceContext.js +1 -0
- package/dist/presets/agents.d.ts +7 -0
- package/dist/presets/base.d.ts +10 -0
- package/dist/presets/codex.d.ts +60 -0
- package/dist/presets/index.d.ts +4 -0
- package/dist/presets/prompts.d.ts +56 -0
- package/dist/sandbox/absent.d.ts +32 -0
- package/dist/sandbox/client.d.ts +39 -0
- package/dist/sandbox/files.d.ts +28 -0
- package/dist/sandbox/index.d.ts +49 -0
- package/dist/sandbox/index.js +4 -0
- package/dist/sandbox/mode.d.ts +57 -0
- package/dist/sandbox/policy.d.ts +86 -0
- package/dist/sandbox/protocol.d.ts +107 -0
- package/dist/sandbox/service.d.ts +143 -0
- package/dist/sandbox/worker.d.ts +12 -0
- package/dist/sandbox/worker.js +1 -0
- package/dist/services/admission.d.ts +174 -0
- package/dist/services/agents.d.ts +37 -0
- package/dist/services/birth.d.ts +220 -0
- package/dist/services/contributions.d.ts +73 -0
- package/dist/services/core.d.ts +34 -0
- package/dist/services/journal.d.ts +26 -0
- package/dist/services/launches.d.ts +104 -0
- package/dist/services/llm.d.ts +80 -0
- package/dist/services/owner.d.ts +367 -0
- package/dist/services/preset.d.ts +154 -0
- package/dist/services/presets.d.ts +139 -0
- package/dist/services/prompts.d.ts +67 -0
- package/dist/services/runEvents.d.ts +79 -0
- package/dist/services/thread.d.ts +267 -0
- package/dist/services/threadActivation.d.ts +100 -0
- package/dist/services/threadDirs.d.ts +38 -0
- package/dist/services/threadView.d.ts +92 -0
- package/dist/services/threads.d.ts +449 -0
- package/dist/services/tools.d.ts +41 -0
- package/dist/sys/environment.d.ts +47 -0
- package/dist/sys/git.d.ts +60 -0
- package/dist/sys/paths.d.ts +56 -0
- package/dist/sys/spawn.d.ts +176 -0
- package/dist/testing/clock.d.ts +17 -0
- package/dist/testing/fakeLlm.d.ts +74 -0
- package/dist/testing/fedLlm.d.ts +32 -0
- package/dist/testing/helpers.d.ts +344 -0
- package/dist/testing/index.d.ts +13 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/processes.d.ts +13 -0
- package/dist/testing/sandbox.d.ts +71 -0
- package/dist/testing/settlement.d.ts +6 -0
- package/dist/testing/tmpDirs.d.ts +17 -0
- package/dist/util/async.d.ts +8 -0
- package/dist/util/diff.d.ts +25 -0
- package/dist/util/dispatch.d.ts +8 -0
- package/dist/util/errors.d.ts +28 -0
- package/dist/util/foldState.d.ts +17 -0
- package/dist/util/freeze.d.ts +2 -0
- package/dist/util/ids.d.ts +2 -0
- package/dist/util/json.d.ts +37 -0
- package/dist/util/log.d.ts +6 -0
- package/dist/util/text.d.ts +21 -0
- package/dist/util/version.d.ts +2 -0
- package/package.json +175 -3
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { type ModelRoute } from '../llm/index.js';
|
|
2
|
+
import type { Journal } from '../journal/index.js';
|
|
3
|
+
import { type BirthConflict, type BirthSpec, type ForkOpening, type FreshOpening, type RowRef, type WriteRows } from '../loop/index.js';
|
|
4
|
+
import type { InitialInstallation, Installation, JournalEventInput, Seq, ThreadEnvironment, ThreadInput, ThreadOrigin, ThreadSummary } from '../models/index.js';
|
|
5
|
+
import type { Wake } from '../loop/index.js';
|
|
6
|
+
import { type DeepReadonly, type ReadonlyJsonValue } from '../util/json.js';
|
|
7
|
+
import type { InitialInstallationInput, PresetsService } from './presets.js';
|
|
8
|
+
/**
|
|
9
|
+
* What must match when a creation or fork finds its id taken: `identity` is the thread's agent,
|
|
10
|
+
* origin and whether it is a fork, and for a fork its cut; `configuration` also compares the
|
|
11
|
+
* birth the request resolves to with the one recorded.
|
|
12
|
+
*/
|
|
13
|
+
export type Reuse = 'identity' | 'configuration';
|
|
14
|
+
/**
|
|
15
|
+
* What a new thread's opening write carries beside its spawn row, the same for `create` and `fork`:
|
|
16
|
+
* one group, so the thread never exists without them. All of it is creation-only: a thread found
|
|
17
|
+
* again under its id gets none, whichever {@link Reuse} the request names.
|
|
18
|
+
*/
|
|
19
|
+
export type Opening = {
|
|
20
|
+
/** The caller chooses the id once per creation and reuses it on retries. */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Never inherited by a fork: application markers belong to the thread they were written on. */
|
|
23
|
+
metadata?: Readonly<Record<string, ReadonlyJsonValue>>;
|
|
24
|
+
/**
|
|
25
|
+
* The thread's first input, queued for a turn of its own. A fork created with one owes only it,
|
|
26
|
+
* not a reply to the conversation it inherited, until a step claims it.
|
|
27
|
+
*/
|
|
28
|
+
input?: ThreadInput;
|
|
29
|
+
/** The first input's id, for idempotent re-dispatch; a fresh one when omitted. */
|
|
30
|
+
inputId?: string;
|
|
31
|
+
/** Plugin rows for the same group, or a veto that rejects the creation with its refusal; see {@link WriteRows}. */
|
|
32
|
+
rows?: WriteRows;
|
|
33
|
+
/**
|
|
34
|
+
* A cause in the same group asking the new thread to run, naming its first input, as `send`'s
|
|
35
|
+
* `wake`: how a delegation authorizes a new child's task in the write that opens it. It states no
|
|
36
|
+
* route: the thread is born on its own.
|
|
37
|
+
*/
|
|
38
|
+
wake?: Wake;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* What a fresh thread is born with, as a request states it. Each field `defaults` or `caller`
|
|
42
|
+
* leaves out is filled from that source; `exact` states a whole {@link BirthSpec} instead.
|
|
43
|
+
*/
|
|
44
|
+
export type BirthInput<I> = {
|
|
45
|
+
/**
|
|
46
|
+
* The route the thread is born on, complete: required, since which model a conversation runs on
|
|
47
|
+
* is the caller's choice. A later change travels with a cause's route statement.
|
|
48
|
+
*/
|
|
49
|
+
route: ModelRoute;
|
|
50
|
+
/**
|
|
51
|
+
* Where the thread's work happens, field by field. An omitted field is the default: the root's
|
|
52
|
+
* `cwd` and no read roots, or with `caller` the caller's. The cwd and every read root must be absolute.
|
|
53
|
+
*/
|
|
54
|
+
environment?: Partial<DeepReadonly<ThreadEnvironment>>;
|
|
55
|
+
/**
|
|
56
|
+
* Preset installations the thread is born with, recorded in its spawn row, so the thread never
|
|
57
|
+
* exists without them and a fork cut anywhere inherits them, each with its lifetime: a `defining`
|
|
58
|
+
* one is never removed, a `configurable` one changes through `Thread.configure` as one applied
|
|
59
|
+
* later does. Validated as a configuration change validates, a preset that defines its thread's
|
|
60
|
+
* agent must define this one, and a creation preset must be `defining`. With `caller`, the
|
|
61
|
+
* installations the caller's live scope hands down follow these, as defining ones.
|
|
62
|
+
*/
|
|
63
|
+
installations?: readonly I[];
|
|
64
|
+
/**
|
|
65
|
+
* The constraint owners, by plugin name, that every run of the thread is under: a run waits while
|
|
66
|
+
* one is not registered and repaired, and so does a run of every thread created under it by
|
|
67
|
+
* origin, which records only its own. A set: sorted and deduplicated when recorded.
|
|
68
|
+
*/
|
|
69
|
+
requires?: readonly string[];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Where a fresh thread's configuration comes from, and its origin: where the thread came from, in
|
|
73
|
+
* the shape a summary records it, immutable once recorded; creation refuses one whose cited row is
|
|
74
|
+
* not the caller's (`origins.validate`).
|
|
75
|
+
*
|
|
76
|
+
* - `defaults`: fields left out come from core's configuration.
|
|
77
|
+
* - `caller`: fields left out come from the caller, plus what its live scope hands down; the caller
|
|
78
|
+
* must have a live activation, whatever the origin's cause.
|
|
79
|
+
* - `exact`: reads nothing from the caller or core: the spec is the birth.
|
|
80
|
+
*/
|
|
81
|
+
export type BirthChoice<I> = {
|
|
82
|
+
origin?: ThreadOrigin;
|
|
83
|
+
birth: {
|
|
84
|
+
from: 'defaults';
|
|
85
|
+
} & BirthInput<I>;
|
|
86
|
+
} | {
|
|
87
|
+
origin: ThreadOrigin;
|
|
88
|
+
birth: {
|
|
89
|
+
from: 'caller';
|
|
90
|
+
} & BirthInput<I>;
|
|
91
|
+
} | {
|
|
92
|
+
origin?: ThreadOrigin;
|
|
93
|
+
birth: {
|
|
94
|
+
from: 'exact';
|
|
95
|
+
spec: BirthSpec;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* How `create` starts a thread: its {@link Opening}, a {@link BirthChoice} and a {@link Reuse},
|
|
100
|
+
* both required, with no default. `caller` goes with `identity` only: comparing a birth that came
|
|
101
|
+
* from the caller's live hand-downs would not be a comparison of birth facts. Under `configuration`
|
|
102
|
+
* installations must be named, since generated ids cannot compare.
|
|
103
|
+
*/
|
|
104
|
+
export type CreateThreadOptions = Opening & (({
|
|
105
|
+
reuse: 'identity';
|
|
106
|
+
} & BirthChoice<InitialInstallationInput>) | ({
|
|
107
|
+
reuse: 'configuration';
|
|
108
|
+
} & Exclude<BirthChoice<InitialInstallationInput & {
|
|
109
|
+
installationId: string;
|
|
110
|
+
}>, {
|
|
111
|
+
birth: {
|
|
112
|
+
from: 'caller';
|
|
113
|
+
};
|
|
114
|
+
}>));
|
|
115
|
+
/**
|
|
116
|
+
* Where a fork is cut. `at` names the row itself: a `thread/spawned`, `turn/start`, `llm/request`
|
|
117
|
+
* or `turn/end` row of the source's lineage, as a bare seq or as the `{ threadId, seq }` pair the
|
|
118
|
+
* thread helpers return. `atTurn` names any row of the lineage and cuts at the end of the turn
|
|
119
|
+
* holding it, or with `before`, just ahead of the turn, at its `turn/start`: edit and resend, with
|
|
120
|
+
* `input` in the turn's place, which `before` therefore requires. A turn that has not ended cannot
|
|
121
|
+
* be cut at its end.
|
|
122
|
+
*/
|
|
123
|
+
export type ForkCut = {
|
|
124
|
+
at: Seq | RowRef;
|
|
125
|
+
atTurn?: never;
|
|
126
|
+
before?: never;
|
|
127
|
+
} | {
|
|
128
|
+
atTurn: Seq | RowRef;
|
|
129
|
+
before?: boolean;
|
|
130
|
+
at?: never;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* How to fork a thread; see {@link ThreadsService.fork}. A fork inherits its route and installations
|
|
134
|
+
* at the cut; `reuse` is required: `identity` is the cut, agent and origin, `configuration` also
|
|
135
|
+
* the fork's own environment and `requires`.
|
|
136
|
+
*/
|
|
137
|
+
export type ForkOptions = Opening & ForkCut & {
|
|
138
|
+
reuse: Reuse;
|
|
139
|
+
/** Set by a delegating tool; a fork someone asks for directly has none and is a root. */
|
|
140
|
+
origin?: ThreadOrigin;
|
|
141
|
+
/**
|
|
142
|
+
* The environment of the thread `fork` is called on, field by field, where omitted — also when the
|
|
143
|
+
* cut is redirected to an ancestor, whose working directory may differ.
|
|
144
|
+
*/
|
|
145
|
+
environment?: Partial<DeepReadonly<ThreadEnvironment>>;
|
|
146
|
+
/** The constraint owners the fork's runs are under, as {@link BirthInput.requires}. None when omitted. */
|
|
147
|
+
requires?: readonly string[];
|
|
148
|
+
};
|
|
149
|
+
/** What resolving a birth reads from outside its options. */
|
|
150
|
+
export type BirthContext = {
|
|
151
|
+
readonly journal: Journal;
|
|
152
|
+
readonly presets: PresetsService;
|
|
153
|
+
/** The `environment.cwd` a thread created without one gets. */
|
|
154
|
+
readonly defaultCwd: string;
|
|
155
|
+
/**
|
|
156
|
+
* The installations the live scope of caller `callerId` hands down to a child on `agent`, refused
|
|
157
|
+
* when the caller has no live activation: its plugins could not say what the child is born with.
|
|
158
|
+
*/
|
|
159
|
+
readonly handedDown: (agent: string, own: readonly Installation[], callerId: string) => InitialInstallation[];
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* A resolved opening: what a creation or fork records, built once and used for validation,
|
|
163
|
+
* comparison, a write-time callback's payload and the spawn row.
|
|
164
|
+
*/
|
|
165
|
+
export type ResolvedOpening = {
|
|
166
|
+
readonly kind: 'fresh';
|
|
167
|
+
readonly opening: FreshOpening;
|
|
168
|
+
} | {
|
|
169
|
+
readonly kind: 'fork';
|
|
170
|
+
readonly opening: ForkOpening;
|
|
171
|
+
};
|
|
172
|
+
/** Read roots as a spawn row records them: each normalized, once, in the order given. A relative one is refused. */
|
|
173
|
+
export declare function readRoots(roots: readonly string[]): string[];
|
|
174
|
+
/** Constraint owners as a spawn row records them: a set, sorted and without repeats. */
|
|
175
|
+
export declare const canonicalRequires: (requires: readonly string[] | undefined) => string[];
|
|
176
|
+
/**
|
|
177
|
+
* Resolves a fresh creation's birth, validated before anything is appended. `origin` is the
|
|
178
|
+
* validated one (`null` for a root). Under `configuration` reuse every installation must name its
|
|
179
|
+
* id: a generated one could never compare.
|
|
180
|
+
*/
|
|
181
|
+
export declare function resolveFresh(context: BirthContext, args: {
|
|
182
|
+
agent: string;
|
|
183
|
+
origin: ThreadOrigin | null;
|
|
184
|
+
birth: CreateThreadOptions['birth'];
|
|
185
|
+
reuse: Reuse;
|
|
186
|
+
}): FreshOpening;
|
|
187
|
+
/**
|
|
188
|
+
* Resolves a fork's own configuration: its environment, field by field from `options`, else from the
|
|
189
|
+
* thread `fork` was called on (`named`, even when the cut redirects to an ancestor), and its
|
|
190
|
+
* constraint owners. The route and installations are the cut's, never stated.
|
|
191
|
+
*/
|
|
192
|
+
export declare function resolveForkOwn(named: ThreadSummary, options: Pick<ForkOptions, 'environment' | 'requires'>): {
|
|
193
|
+
environment: ThreadEnvironment;
|
|
194
|
+
requires: string[];
|
|
195
|
+
};
|
|
196
|
+
/** What a fork goes on with from its cut and does not record: the route and installations as the lineage folds to there. */
|
|
197
|
+
export declare function inheritsAt(journal: Journal, cut: RowRef): ForkOpening['inherits'];
|
|
198
|
+
/** The spawn row a resolved opening records. */
|
|
199
|
+
export declare function spawnRow(resolved: ResolvedOpening, metadata: NonNullable<Opening['metadata']>): JournalEventInput['thread/spawned'];
|
|
200
|
+
/** What a request must match of an existing thread by identity: its agent, origin and kind, and for a fork its cut. */
|
|
201
|
+
export type Identity = {
|
|
202
|
+
readonly kind: 'fresh' | 'fork';
|
|
203
|
+
readonly agent: string;
|
|
204
|
+
readonly origin: ThreadOrigin | null;
|
|
205
|
+
readonly cut?: RowRef;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* What differs between an existing thread and the identity a request asks for: its agent, its
|
|
209
|
+
* origin, whether it is a fork, and for a fork its cut. The origin is compared as the request states it.
|
|
210
|
+
*/
|
|
211
|
+
export declare function identityConflicts(summary: ThreadSummary, requested: Identity): BirthConflict[];
|
|
212
|
+
/**
|
|
213
|
+
* What differs between a fresh birth's recorded spawn row and the birth requested: route,
|
|
214
|
+
* environment, installations and `requires`, the last as a set. Installation order is significant.
|
|
215
|
+
*/
|
|
216
|
+
export declare function specConflicts(spawn: JournalEventInput['thread/spawned'], requested: BirthSpec): BirthConflict[];
|
|
217
|
+
/** What differs between a fork's recorded own configuration and the one requested. */
|
|
218
|
+
export declare function forkConflicts(summary: ThreadSummary, requested: Pick<ForkOpening, 'environment' | 'requires'>): BirthConflict[];
|
|
219
|
+
/** Throws {@link BirthConflictError} when `conflicts` is not empty. */
|
|
220
|
+
export declare function requireNoConflicts(threadId: string, conflicts: readonly BirthConflict[]): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Context } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { PluginJournal, ThreadSummaryCore } from '../journal/index.js';
|
|
4
|
+
import type { DeepReadonly, JsonValue } from '../util/json.js';
|
|
5
|
+
/** What one thread's contribution says, as {@link ContributionDefinition.read} reports it. */
|
|
6
|
+
export type ContributionReading<T> =
|
|
7
|
+
/** The thread's value: computed from its folds when it is loaded, else the catalog's cached copy. */
|
|
8
|
+
{
|
|
9
|
+
readonly status: 'available';
|
|
10
|
+
readonly value: DeepReadonly<T>;
|
|
11
|
+
}
|
|
12
|
+
/** The contribution is not about this thread: its `applies` says no. */
|
|
13
|
+
| {
|
|
14
|
+
readonly status: 'not-applicable';
|
|
15
|
+
}
|
|
16
|
+
/** It applies, but there is no valid value to read: nothing nor no one computed it, or it fails its schema or version. Never read as an empty value. */
|
|
17
|
+
| {
|
|
18
|
+
readonly status: 'unavailable';
|
|
19
|
+
readonly reason: string;
|
|
20
|
+
};
|
|
21
|
+
export type ContributionDefinitionInput<T extends JsonValue> = {
|
|
22
|
+
/** Where the value sits in a thread's catalog entry; one definition per key. */
|
|
23
|
+
key: string;
|
|
24
|
+
/** The shape of what is cached; a changed shape is recomputed, never migrated. */
|
|
25
|
+
schema: z.ZodType<T>;
|
|
26
|
+
/** An integer that changes when the value's meaning does, though its shape does not: entries with another one are recomputed. */
|
|
27
|
+
version: number;
|
|
28
|
+
/** Whether the thread has a value. Decided from the catalog entry alone, so a reader needs nothing loaded. */
|
|
29
|
+
applies(summary: ThreadSummaryCore): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The value from the thread's folds, synchronously. Total for a thread that applies: a failure
|
|
32
|
+
* throws, and the entry is then missing and reads `unavailable`, never an empty value. It
|
|
33
|
+
* must return JSON, and may return what a fold holds read-only: the result is validated and copied.
|
|
34
|
+
*/
|
|
35
|
+
compute(journal: PluginJournal, threadId: string): NoInfer<DeepReadonly<T>>;
|
|
36
|
+
};
|
|
37
|
+
/** A summary contribution: define it once at module level, register it from a service, read it where it is needed. */
|
|
38
|
+
export type ContributionDefinition<T extends JsonValue> = {
|
|
39
|
+
readonly key: string;
|
|
40
|
+
/**
|
|
41
|
+
* Computes the value into every thread's catalog entry with each write group, for the lifetime of
|
|
42
|
+
* `ctx`, and queues the refresh of the entries that are missing, fail the schema or carry another
|
|
43
|
+
* version. `refreshed` settles when it has run, with the threads whose repair failed: they keep
|
|
44
|
+
* an entry without the key and read `unavailable`. A service waits for it before it serves from
|
|
45
|
+
* the catalog.
|
|
46
|
+
*/
|
|
47
|
+
register(ctx: Context): {
|
|
48
|
+
readonly refreshed: Promise<string[]>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* What `threadId` says. A loaded thread computes from its folds, so it reads the same with the
|
|
52
|
+
* contributing service unmounted; any other validates the cached entry. Never loads a thread and
|
|
53
|
+
* never queues a repair.
|
|
54
|
+
*/
|
|
55
|
+
read(journal: PluginJournal, threadId: string): ContributionReading<T>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Defines a typed, versioned contribution to every thread's catalog entry: what is read of a thread
|
|
59
|
+
* that is not loaded, as after a restart, or by a listing that loads nothing.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* const openTasks = defineContribution({
|
|
63
|
+
* key: 'app:open-tasks',
|
|
64
|
+
* version: 1,
|
|
65
|
+
* schema: z.number(),
|
|
66
|
+
* applies: (summary) => summary.origin !== null,
|
|
67
|
+
* compute: (journal, threadId) => journal.state(tasks, threadId).size,
|
|
68
|
+
* })
|
|
69
|
+
* openTasks.register(ctx) // in a service
|
|
70
|
+
* openTasks.read(ctx.journal, threadId) // { status: 'available', value: 2 }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function defineContribution<T extends JsonValue>(input: ContributionDefinitionInput<T>): ContributionDefinition<T>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Plugin } from '@leuduan/cordis';
|
|
2
|
+
import type { JournalStore } from '../journal/index.js';
|
|
3
|
+
import { type TurnLimits } from '../loop/index.js';
|
|
4
|
+
export type CoreConfig = {
|
|
5
|
+
/** The journal's backing, constructed by the application. */
|
|
6
|
+
store: JournalStore;
|
|
7
|
+
/** Default `environment.cwd` for new threads; absolute. */
|
|
8
|
+
cwd: string;
|
|
9
|
+
/**
|
|
10
|
+
* Absolute application data directory holding each thread's own directory, or `null` for none:
|
|
11
|
+
* plugins that need directories then refuse to mount. Required: where to keep files is the
|
|
12
|
+
* application's choice.
|
|
13
|
+
*/
|
|
14
|
+
dataDir: string | null;
|
|
15
|
+
limits?: Partial<TurnLimits>;
|
|
16
|
+
/**
|
|
17
|
+
* What becomes of a thread the owner loaded to run once its run lets go: `retire` takes it out of
|
|
18
|
+
* memory, `keep` leaves it loaded. Required: what to cache is the application's choice.
|
|
19
|
+
*/
|
|
20
|
+
retention: 'retire' | 'keep';
|
|
21
|
+
/**
|
|
22
|
+
* How many reactive turns in a row a thread may run (turns its own work woke, such as notices)
|
|
23
|
+
* before a producer of more unattended work refuses: `ctx.threads.chain(threadId).atLimit`. A
|
|
24
|
+
* person's or an assignment's authority resets the count. Required: how much unattended work to
|
|
25
|
+
* allow is the application's choice.
|
|
26
|
+
*/
|
|
27
|
+
chainLimit: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Mounts the core services on one root: `ctx.journal`, `ctx.llm`, `ctx.agents`, `ctx.tools`,
|
|
31
|
+
* `ctx.prompts`, `ctx.threadDirs`, `ctx.launches`, `ctx.presets` and `ctx.threads`. Providers, tools, agents and
|
|
32
|
+
* capability plugins mount beside it.
|
|
33
|
+
*/
|
|
34
|
+
export declare const core: Plugin.Object<CoreConfig>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Context, Plugin } from '@leuduan/cordis';
|
|
2
|
+
import { Journal, type JournalStore } from '../journal/index.js';
|
|
3
|
+
import { type TurnLimits } from '../loop/index.js';
|
|
4
|
+
export type JournalConfig = {
|
|
5
|
+
/** Durable backing. A store that is already open stays caller-owned. */
|
|
6
|
+
store: JournalStore;
|
|
7
|
+
/** What a thread's summary asks of the folds: whether a run would find work depends on them. */
|
|
8
|
+
limits: TurnLimits;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Opens the one journal this process runs against and provides it as `ctx.journal`.
|
|
12
|
+
*
|
|
13
|
+
* The journal takes the store's writer lease before reading: another process may hold this journal.
|
|
14
|
+
*
|
|
15
|
+
* Core's one fold, `threadState`, is registered before the journal opens and never removed: it
|
|
16
|
+
* holds every row before the first write, which `replaceSurface` judges against its surface.
|
|
17
|
+
* The loop's summary is what the journal writes to the catalog with every group; `journal/` knows
|
|
18
|
+
* only its shape. A journal that can no longer be written is announced as `lagent/journal/revoked`;
|
|
19
|
+
* it has already refused every later write, and the host must exit.
|
|
20
|
+
*/
|
|
21
|
+
export declare const journalPlugin: Plugin.Object<JournalConfig>;
|
|
22
|
+
/**
|
|
23
|
+
* The journal with core's writes, for the engine's own services: the same journal `ctx.journal`
|
|
24
|
+
* holds, which types it for plugins as one that appends `ext` rows only.
|
|
25
|
+
*/
|
|
26
|
+
export declare const engineJournal: (ctx: Context) => Journal;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Service, type Context } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type SpawnedCommand, type SpawnEnvironment } from '../sys/spawn.js';
|
|
4
|
+
/**
|
|
5
|
+
* How a model-driven process becomes a local launch: the one place `run_command`, and later other
|
|
6
|
+
* model-driven processes such as MCP stdio servers, start a process, so a host's confinement sees
|
|
7
|
+
* every one. Not `sys/spawn`: lagent's own spawns (`rg`, git, the shell probe, stop-check hooks) call
|
|
8
|
+
* `spawnCommand` directly and are never intercepted.
|
|
9
|
+
*/
|
|
10
|
+
/** Which launch a process got, recorded with it: never secrets, ids or ports. */
|
|
11
|
+
export declare const LaunchProvenanceSchema: z.ZodObject<{
|
|
12
|
+
launcher: z.ZodString;
|
|
13
|
+
version: z.ZodString;
|
|
14
|
+
policy: z.ZodString;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
export type LaunchProvenance = z.output<typeof LaunchProvenanceSchema>;
|
|
17
|
+
/** The `policy` of a launch a handler chose to run unconfined: what a host or a listing marks as such. */
|
|
18
|
+
export declare const UNCONFINED_LAUNCH = "unconfined";
|
|
19
|
+
/**
|
|
20
|
+
* What to launch: the geometry to confine (`root`, `scratch`) and the thread the launch is for, the
|
|
21
|
+
* subject a handler's per-thread policy is decided on.
|
|
22
|
+
*/
|
|
23
|
+
export type LaunchRequest = {
|
|
24
|
+
/** The thread the launch serves: the policy subject, never a place to confine. */
|
|
25
|
+
readonly threadId: string;
|
|
26
|
+
/** What runs. */
|
|
27
|
+
readonly program: {
|
|
28
|
+
readonly shell: string;
|
|
29
|
+
};
|
|
30
|
+
/** Absolute: where it starts. */
|
|
31
|
+
readonly workdir: string;
|
|
32
|
+
/** The writable root the protected names are rebuilt for: the thread's working directory for commands. */
|
|
33
|
+
readonly root: string;
|
|
34
|
+
/** Keys the process's temporary directory: `thread:<id>` for commands. Equal keys share one directory. */
|
|
35
|
+
readonly scratch: string;
|
|
36
|
+
/** The process's environment: the caller's. */
|
|
37
|
+
readonly environment: SpawnEnvironment;
|
|
38
|
+
/** Aborting it stops the launch: preparation at once, and the process within its stop bound. */
|
|
39
|
+
readonly signal: AbortSignal;
|
|
40
|
+
};
|
|
41
|
+
export type LaunchOptions = {
|
|
42
|
+
readonly timeoutMs?: number;
|
|
43
|
+
readonly killGraceMs: number;
|
|
44
|
+
/** Awaited before the process is released, as `spawnCommand`'s, with the launch it got. */
|
|
45
|
+
readonly beforeRelease?: (pgid: number, launch: LaunchProvenance | null) => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
/** A local process to spawn in place of `/bin/sh -c <command>`. */
|
|
48
|
+
export type PreparedLaunch = {
|
|
49
|
+
readonly argv: readonly [string, ...string[]];
|
|
50
|
+
readonly cwd: string;
|
|
51
|
+
readonly env: SpawnEnvironment;
|
|
52
|
+
readonly provenance: LaunchProvenance;
|
|
53
|
+
/** After the process ended: bounded report lines, or `null`. Never rejects the process's outcome. */
|
|
54
|
+
violations(): Promise<string | null>;
|
|
55
|
+
};
|
|
56
|
+
/** What confines launches, such as the OS sandbox of `@leuduan/lagent/sandbox`. */
|
|
57
|
+
export type LaunchHandler = {
|
|
58
|
+
/** Rejects, with a message for the model, to refuse the launch. */
|
|
59
|
+
prepare(request: LaunchRequest): Promise<PreparedLaunch>;
|
|
60
|
+
};
|
|
61
|
+
export type LaunchHandle = {
|
|
62
|
+
/**
|
|
63
|
+
* Stops admitting through the handler, aborts every launch it prepared, and waits for each one's
|
|
64
|
+
* preparation, process and report within `timeoutMs`. Resolves `true` only when every group was
|
|
65
|
+
* confirmed stopped: no `stopFailed` result, ever, and nothing still running at the bound.
|
|
66
|
+
* Idempotent: every caller shares the first call's result.
|
|
67
|
+
*/
|
|
68
|
+
release(timeoutMs: number): Promise<boolean>;
|
|
69
|
+
};
|
|
70
|
+
/** A launched process: its group, what it was launched as, and the handler's report once it ends. */
|
|
71
|
+
export type Launched = {
|
|
72
|
+
readonly spawned: SpawnedCommand;
|
|
73
|
+
readonly launch: LaunchProvenance | null;
|
|
74
|
+
/** Settles after `spawned.result`, within {@link DIAGNOSTICS_MS}; `null` for nothing to report. Never rejects. */
|
|
75
|
+
readonly diagnostics: Promise<string | null>;
|
|
76
|
+
};
|
|
77
|
+
/** How long after a process ended its report may take. */
|
|
78
|
+
export declare const DIAGNOSTICS_MS = 1000;
|
|
79
|
+
/**
|
|
80
|
+
* The launch seam. With no handler, a launch is `/bin/sh -c <command>`. The first {@link handle}
|
|
81
|
+
* declares for the root's lifetime that launches go through a handler, which decides what each one
|
|
82
|
+
* gets (confinement, or refusal): from then on a launch with no live handler, because it was
|
|
83
|
+
* released, failed or never mounted again, is refused, and nothing falls back to a plain spawn. A
|
|
84
|
+
* host mounts the handler before anything launches.
|
|
85
|
+
*
|
|
86
|
+
* A handler is told nothing about consumers. It is released as a whole: core aborts what it
|
|
87
|
+
* prepared and reports whether every group stopped, so the handler may then free what confined them.
|
|
88
|
+
*/
|
|
89
|
+
export declare class LaunchesService extends Service {
|
|
90
|
+
private readonly root;
|
|
91
|
+
constructor(ctx: Context);
|
|
92
|
+
/**
|
|
93
|
+
* Registers the one handler. Throws while another is live. Afterwards, until the root ends, a
|
|
94
|
+
* launch with no live handler is refused.
|
|
95
|
+
*/
|
|
96
|
+
handle(handler: LaunchHandler): LaunchHandle;
|
|
97
|
+
/** One launch: through the handler when one was registered, else `/bin/sh -c`. */
|
|
98
|
+
launch(request: LaunchRequest, options: LaunchOptions): Promise<Launched>;
|
|
99
|
+
private spawnPlain;
|
|
100
|
+
private spawnThrough;
|
|
101
|
+
private release;
|
|
102
|
+
/** Whether every operation settled within `timeoutMs` and no stop ever failed. */
|
|
103
|
+
private settle;
|
|
104
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Context, Service } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type LLMProvider, type ModelCallClient, type ModelCapacity, type ModelRoute } from '../llm/index.js';
|
|
4
|
+
import { type ModelSelection } from '../loop/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* How `ctx.llm` retries a provider's failed call, required at registration. `maxAttempts` counts the
|
|
7
|
+
* first request, so `1` retries nothing. The wait before a retry is exponential from `baseDelayMs`
|
|
8
|
+
* with full jitter, capped at `maxDelayMs`; a wait the provider asked for (`retryAfterMs`) at or below
|
|
9
|
+
* `maxDelayMs` is the wait, and one above it stops retrying.
|
|
10
|
+
*/
|
|
11
|
+
export declare const RetryPolicySchema: z.ZodObject<{
|
|
12
|
+
maxAttempts: z.ZodNumber;
|
|
13
|
+
baseDelayMs: z.ZodNumber;
|
|
14
|
+
maxDelayMs: z.ZodNumber;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
export type RetryPolicy = z.input<typeof RetryPolicySchema>;
|
|
17
|
+
/** The service's own registration, reachable only through {@link registerProvider}. */
|
|
18
|
+
declare const register: unique symbol;
|
|
19
|
+
/**
|
|
20
|
+
* Offers `provider` to route selection and to the agents told about routes, for the life of the
|
|
21
|
+
* calling fiber, with `retry` the policy its calls are retried by. Register only what should be
|
|
22
|
+
* offered. Returns the disposer, as `registerAgent` does.
|
|
23
|
+
*/
|
|
24
|
+
export declare const registerProvider: (ctx: Context, provider: LLMProvider, options: {
|
|
25
|
+
retry: RetryPolicy;
|
|
26
|
+
}) => (() => void | Promise<void>);
|
|
27
|
+
/**
|
|
28
|
+
* Provider registry, route resolution and client construction.
|
|
29
|
+
*
|
|
30
|
+
* One client per provider, built when first asked for and kept until the provider is withdrawn: a
|
|
31
|
+
* client is asked for on every model call, and rebuilding a transport each time would be waste. The
|
|
32
|
+
* model and the effort travel on each request, so neither is part of the key. A route's effort is
|
|
33
|
+
* the route's to resolve (`resolveRoute`, `routeOn`); the client only supplies the provider's own
|
|
34
|
+
* default when a request carries none.
|
|
35
|
+
*/
|
|
36
|
+
export declare class LlmService extends Service {
|
|
37
|
+
private readonly providers;
|
|
38
|
+
private readonly policies;
|
|
39
|
+
/** By provider name. */
|
|
40
|
+
private readonly clients;
|
|
41
|
+
constructor(ctx: Context);
|
|
42
|
+
get providerNames(): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Offers `provider` until the returned disposer runs (see {@link registerProvider}, the one way in).
|
|
45
|
+
* The disposer withdraws it and its client at once, so a provider registered again under the name
|
|
46
|
+
* never reaches the old one, and resolves once it is disposed, rejecting with what its cleanup threw.
|
|
47
|
+
*/
|
|
48
|
+
[register](provider: LLMProvider, retry: z.output<typeof RetryPolicySchema>): () => Promise<void>;
|
|
49
|
+
/** The provider registered under `name`; throws `RouteUnavailableError` when none is. */
|
|
50
|
+
provider(name: string): LLMProvider;
|
|
51
|
+
/** Why `route` cannot run now: its provider is not registered; `null` when it can. */
|
|
52
|
+
unavailable(route: Pick<ModelRoute, 'provider'>): string | null;
|
|
53
|
+
/**
|
|
54
|
+
* `selection` folded over `base`, the route it changes: a named model or effort replaces that
|
|
55
|
+
* field, and a named different provider takes that provider's defaults for whatever it leaves
|
|
56
|
+
* unnamed, since a model or an effort means nothing on another provider. Throws
|
|
57
|
+
* `RouteUnavailableError` when the resulting provider is not registered. Registry lookup only; no
|
|
58
|
+
* client is built. Resolved once, as the route is written, so a recorded route is always complete.
|
|
59
|
+
*/
|
|
60
|
+
resolveRoute(selection: ModelSelection, base: ModelRoute): ModelRoute;
|
|
61
|
+
/**
|
|
62
|
+
* What the route's provider declares for its model: the usable context window, `null` when it
|
|
63
|
+
* declares none, whether its requests may carry provider-executed tools, and whether its tool
|
|
64
|
+
* results may carry images. Registry lookup only; throws when the provider is not registered.
|
|
65
|
+
*/
|
|
66
|
+
capacity(route: Pick<ModelRoute, 'provider' | 'model'>): ModelCapacity;
|
|
67
|
+
/**
|
|
68
|
+
* The client a resolved route's provider sends through, the same for every model and effort: the
|
|
69
|
+
* provider's own, wrapped so a failed call is retried by its policy and otherwise throws a
|
|
70
|
+
* `ModelCallError` with its kind and attempt count (see {@link RetryingClient}). The route's effort
|
|
71
|
+
* is not applied here: a request carries it, or leaves the provider's own default. Throws when its
|
|
72
|
+
* provider is not registered.
|
|
73
|
+
*/
|
|
74
|
+
clientFor(route: ModelRoute): ModelCallClient;
|
|
75
|
+
/** Removes the clients of the providers `owned` names, synchronously. */
|
|
76
|
+
private detachClients;
|
|
77
|
+
/** Disposes each provider client, once: the one that owns its transport owns its cleanup. */
|
|
78
|
+
private disposeClients;
|
|
79
|
+
}
|
|
80
|
+
export {};
|