@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,80 @@
|
|
|
1
|
+
import type { Context } from '@leuduan/cordis';
|
|
2
|
+
import type { ExtensionRecord, QueuedInput, ReplacementTrigger } from '../records/journal.js';
|
|
3
|
+
import type { JsonValue } from '../util/json.js';
|
|
4
|
+
import type { ModelRoute } from '../llm/provider.js';
|
|
5
|
+
import type { AuxiliaryCall, AuxiliaryReply } from './auxiliary.js';
|
|
6
|
+
import type { ReplacementInput } from '../state/index.js';
|
|
7
|
+
/** What a strategy is told about one request to prepare the surface. */
|
|
8
|
+
export type SurfacePrepareInput = {
|
|
9
|
+
readonly threadId: string;
|
|
10
|
+
/** The turn and step it runs in; both `null` for a request between turns. */
|
|
11
|
+
readonly turn: number | null;
|
|
12
|
+
readonly step: number | null;
|
|
13
|
+
/** The route the turn recorded, or for a request between turns, the thread's route. */
|
|
14
|
+
readonly route: ModelRoute;
|
|
15
|
+
/**
|
|
16
|
+
* `pressure` on every due model step, `overflow` inside a step whose request the provider refused
|
|
17
|
+
* as longer than the window, `request` when a caller asked through `thread.compact()`.
|
|
18
|
+
*/
|
|
19
|
+
readonly trigger: ReplacementTrigger;
|
|
20
|
+
/**
|
|
21
|
+
* Input queued for this step, which the step records after the replacement unless it was
|
|
22
|
+
* withdrawn meanwhile. Empty on `overflow`, whose input is already recorded, and on `request`.
|
|
23
|
+
*/
|
|
24
|
+
readonly queued: readonly QueuedInput[];
|
|
25
|
+
/** On `request`, the options the caller gave, opaque to the engine; otherwise `null`. */
|
|
26
|
+
readonly options: JsonValue | null;
|
|
27
|
+
/** The turn's signal, or on `request` the caller's. */
|
|
28
|
+
readonly signal: AbortSignal;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* How a request to prepare the surface ends, as a strategy decides it: nothing to do, a failure,
|
|
32
|
+
* or replacements the engine records as one atomic group. A failure may name facts the strategy
|
|
33
|
+
* wants recorded with it, as `ext` rows on the thread, such as an unusable reply it counts.
|
|
34
|
+
*/
|
|
35
|
+
export type FinalPlan = {
|
|
36
|
+
readonly kind: 'skip';
|
|
37
|
+
readonly reason: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: 'fail';
|
|
40
|
+
readonly reason: string;
|
|
41
|
+
readonly facts?: readonly ExtensionRecord[];
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: 'replace';
|
|
44
|
+
readonly replacements: readonly ReplacementInput[];
|
|
45
|
+
readonly reason?: string;
|
|
46
|
+
};
|
|
47
|
+
/** What came of the one model call a plan asked for. */
|
|
48
|
+
export type AuxiliaryAnswer = {
|
|
49
|
+
readonly reply: AuxiliaryReply;
|
|
50
|
+
} | {
|
|
51
|
+
readonly failure: unknown;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* What a strategy returns for a request: a final plan, or one model call beside the conversation
|
|
55
|
+
* (`ask`) whose answer `finish` turns into the final plan. At most one call per request. (Not
|
|
56
|
+
* `then`: a plan with one would be awaited as a promise.)
|
|
57
|
+
*/
|
|
58
|
+
export type SurfacePlan = FinalPlan | {
|
|
59
|
+
readonly kind: 'ask';
|
|
60
|
+
readonly call: AuxiliaryCall;
|
|
61
|
+
finish(answer: AuxiliaryAnswer): FinalPlan | Promise<FinalPlan>;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* A thread's one way to replace part of its surface. It reads what it needs and returns a plan;
|
|
65
|
+
* the engine makes the model call it asks for, records the replacement or the facts, and derives
|
|
66
|
+
* how the request ended from what committed. It holds no binding that outlives the request.
|
|
67
|
+
*/
|
|
68
|
+
export interface SurfaceStrategy {
|
|
69
|
+
/** How a refusal and a report name it, such as `compaction (summarize)`. */
|
|
70
|
+
readonly name: string;
|
|
71
|
+
plan(input: SurfacePrepareInput): SurfacePlan | Promise<SurfacePlan>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Makes `strategy` the one that prepares `threadId`'s surface, for as long as the calling plugin's
|
|
75
|
+
* fiber lives. A thread runs one strategy: a second, from another mount or installation, throws, so
|
|
76
|
+
* the plugin that came later fails, and with it the activation, rather than running beside the first.
|
|
77
|
+
*/
|
|
78
|
+
export declare function registerSurfaceStrategy(ctx: Context, threadId: string, strategy: SurfaceStrategy): void;
|
|
79
|
+
/** The strategy that prepares `threadId`'s surface, if any. */
|
|
80
|
+
export declare function strategyOf(ctx: Context, threadId: string): SurfaceStrategy | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { QueuedInput, ReplacementTrigger } from '../records/journal.js';
|
|
2
|
+
import type { JsonValue } from '../util/json.js';
|
|
3
|
+
import { type ModelRoute } from '../llm/provider.js';
|
|
4
|
+
import type { SurfacePrepareOutcome } from './hooks.js';
|
|
5
|
+
import type { Lease, LoopRuntime } from './runtime.js';
|
|
6
|
+
/** One request to prepare the surface, as the loop or `thread.compact()` starts it. */
|
|
7
|
+
export type SurfacePrepareDispatch = {
|
|
8
|
+
readonly threadId: string;
|
|
9
|
+
readonly agentName: string;
|
|
10
|
+
readonly turn: number | null;
|
|
11
|
+
readonly step: number | null;
|
|
12
|
+
readonly route: ModelRoute;
|
|
13
|
+
readonly trigger: ReplacementTrigger;
|
|
14
|
+
readonly queued: readonly QueuedInput[];
|
|
15
|
+
readonly options: JsonValue | null;
|
|
16
|
+
readonly signal: AbortSignal;
|
|
17
|
+
/** The lease the caller holds; checked before the engine records anything for the plan. */
|
|
18
|
+
readonly lease: Lease;
|
|
19
|
+
};
|
|
20
|
+
/** How a request settled, and the error that ended it when the strategy threw. */
|
|
21
|
+
export type SurfacePrepareSettled = {
|
|
22
|
+
readonly outcome: SurfacePrepareOutcome;
|
|
23
|
+
readonly error: unknown;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Asks the thread's strategy for a plan and carries it out: the one model call it asks for, then the
|
|
27
|
+
* replacement or the facts its final plan names, all recorded by the engine. Never throws for the
|
|
28
|
+
* strategy: what a failure means is the trigger's policy, which the caller applies.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runSurfacePrepare(runtime: LoopRuntime, dispatch: SurfacePrepareDispatch): Promise<SurfacePrepareSettled>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Context } from '@leuduan/cordis';
|
|
2
|
+
import type { InterruptionPolicy, Seq, ThreadEnvironment } from '../records/journal.js';
|
|
3
|
+
import type { JsonValue } from '../util/json.js';
|
|
4
|
+
import type { ToolResult } from '../records/toolResult.js';
|
|
5
|
+
import type { ReadonlyJsonValue } from '../util/json.js';
|
|
6
|
+
import type { ModelRoute } from '../llm/provider.js';
|
|
7
|
+
import type { ParsedToolCall, ToolCall, ToolSpec } from '../llm/primitives.js';
|
|
8
|
+
/** An error result answering the dispatched call. */
|
|
9
|
+
export declare const errorResult: (call: ToolCall, output: string) => ToolResult;
|
|
10
|
+
/**
|
|
11
|
+
* How a tool's calls may overlap. `exclusive` forms a barrier: it starts only once the calls before
|
|
12
|
+
* it have settled, and nothing starts beside it.
|
|
13
|
+
*/
|
|
14
|
+
export type ToolExecutionMode = 'parallel' | 'exclusive';
|
|
15
|
+
/**
|
|
16
|
+
* A call that suspends instead of answering now: it waits on a dependency outside this loop, a
|
|
17
|
+
* delegated thread's answer or a person's reply, which the constraint owner named `owner` alone
|
|
18
|
+
* interprets and resolves (`OwnerHandle.resolveWait`). Core records the declaration, the
|
|
19
|
+
* thread is held `wait` without a run slot, and once the owner records a value the call is
|
|
20
|
+
* dispatched again with `InvocationContext.wait`, where the tool returns its ordinary result from
|
|
21
|
+
* it. A cancel answers a waiting call instead. `dependency` is a JSON object the owner versions;
|
|
22
|
+
* `deadlineAt` (epoch milliseconds, or `null`) is the owner's to act on; `reason` says why in words.
|
|
23
|
+
*/
|
|
24
|
+
export type WaitRequest = {
|
|
25
|
+
readonly kind: 'wait';
|
|
26
|
+
readonly owner: string;
|
|
27
|
+
readonly dependency: {
|
|
28
|
+
readonly [key: string]: JsonValue;
|
|
29
|
+
};
|
|
30
|
+
readonly deadlineAt: number | null;
|
|
31
|
+
readonly reason: string;
|
|
32
|
+
};
|
|
33
|
+
export type ToolOutcome = ToolResult | WaitRequest;
|
|
34
|
+
/** Suspends the call on `owner`'s dependency; see {@link WaitRequest}. */
|
|
35
|
+
export declare const waitFor: (request: Omit<WaitRequest, "kind">) => WaitRequest;
|
|
36
|
+
export declare const isWaitRequest: (outcome: object) => outcome is WaitRequest;
|
|
37
|
+
/** A dispatch of a suspended call whose wait resolved: what it waited on, and the value it resolved with. */
|
|
38
|
+
export type ResolvedWait = {
|
|
39
|
+
readonly dependency: {
|
|
40
|
+
readonly [key: string]: ReadonlyJsonValue;
|
|
41
|
+
};
|
|
42
|
+
readonly value: {
|
|
43
|
+
readonly [key: string]: ReadonlyJsonValue;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* What a tool implements. `defineTool` in `services/tools.ts` builds one, with validation and timing; this
|
|
48
|
+
* is the contract underneath it.
|
|
49
|
+
*/
|
|
50
|
+
export interface Tool {
|
|
51
|
+
readonly name: string;
|
|
52
|
+
/**
|
|
53
|
+
* Whether a call may run beside the others of its response. `parallel` for a tool whose calls do
|
|
54
|
+
* not depend on each other's effects, `exclusive` for one that changes state: an exclusive call
|
|
55
|
+
* runs alone, after every call before it and before any after it. A barrier within one response's
|
|
56
|
+
* batch only: it does not isolate threads that share a workspace, nor a process a call left
|
|
57
|
+
* running. Every tool says which; there is no default.
|
|
58
|
+
*/
|
|
59
|
+
readonly executionMode: ToolExecutionMode;
|
|
60
|
+
/**
|
|
61
|
+
* What a re-dispatch may do with a call of this tool that may have begun when its turn was
|
|
62
|
+
* interrupted. Every tool says which; there is no default. `rerun` for a tool that is read-only or
|
|
63
|
+
* idempotent under the call's identity (`InvocationContext.threadId` and `callSeq`); `report` for
|
|
64
|
+
* anything whose second execution would be a second effect in the world.
|
|
65
|
+
*/
|
|
66
|
+
readonly onInterrupted: InterruptionPolicy;
|
|
67
|
+
buildSpec(): ToolSpec;
|
|
68
|
+
/** Never throws: validation and execution failures become `is_error` results. */
|
|
69
|
+
invoke(call: ParsedToolCall, context: InvocationContext): Promise<ToolOutcome>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* What a tool is handed. `ctx` is the live thread context, with its scoped tool layer,
|
|
73
|
+
* `ctx.threads`, and the services plugins provide, such as `ctx.delegations` and `ctx.ask`.
|
|
74
|
+
*/
|
|
75
|
+
export interface InvocationContext {
|
|
76
|
+
readonly ctx: Context;
|
|
77
|
+
/** Aborts when this turn is cancelled or the root closes. */
|
|
78
|
+
readonly signal: AbortSignal;
|
|
79
|
+
readonly agentName: string;
|
|
80
|
+
readonly threadId: string;
|
|
81
|
+
readonly callId: string;
|
|
82
|
+
/**
|
|
83
|
+
* The `tool/call` or runtime `execution/requested` row this invocation serves. The durable
|
|
84
|
+
* identity of the dispatch: unique in the journal, where a provider's `callId` may not be.
|
|
85
|
+
*/
|
|
86
|
+
readonly callSeq: Seq;
|
|
87
|
+
/**
|
|
88
|
+
* The `llm/request` row that produced this call: exactly what the model was sent when it asked.
|
|
89
|
+
* Where a tool that forks this thread cuts, so the fork shares that request's cached prefix.
|
|
90
|
+
* `null` for runtime completion preparation, which has no model request.
|
|
91
|
+
*/
|
|
92
|
+
readonly requestSeq: Seq | null;
|
|
93
|
+
/** Where this thread's work happens. */
|
|
94
|
+
readonly environment: ThreadEnvironment;
|
|
95
|
+
/**
|
|
96
|
+
* The route of the turn running the call, as its `turn/start` recorded it: the one its result is
|
|
97
|
+
* sent on next, and the route a new sub-agent the call starts inherits. `ctx.llm.capacity(route)`
|
|
98
|
+
* says what that result may carry.
|
|
99
|
+
*/
|
|
100
|
+
readonly route: ModelRoute;
|
|
101
|
+
/**
|
|
102
|
+
* `null` on a first dispatch; on a dispatch of a call whose wait resolved, what it waited on and
|
|
103
|
+
* the value it resolved with, from which the tool returns its result without doing the work again.
|
|
104
|
+
*/
|
|
105
|
+
readonly wait: ResolvedWait | null;
|
|
106
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ThreadEnvironment } from '../records/journal.js';
|
|
2
|
+
import type { ToolCall } from '../llm/primitives.js';
|
|
3
|
+
import type { ModelRoute } from '../llm/provider.js';
|
|
4
|
+
import type { LoopRuntime } from './runtime.js';
|
|
5
|
+
export type ExecuteToolCallsOptions = {
|
|
6
|
+
runtime: LoopRuntime;
|
|
7
|
+
threadId: string;
|
|
8
|
+
agentName: string;
|
|
9
|
+
environment: ThreadEnvironment;
|
|
10
|
+
/** The turn's route, handed to each call. */
|
|
11
|
+
route: ModelRoute;
|
|
12
|
+
turn: number;
|
|
13
|
+
step: number;
|
|
14
|
+
calls: readonly ToolCall[];
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Runs one step's tool calls.
|
|
19
|
+
*
|
|
20
|
+
* Dispatch overlaps inside a bounded pool, but results are appended in **model order**: the journal
|
|
21
|
+
* is what the next request is built from, so the order calls happen to settle in must not be able
|
|
22
|
+
* to reorder the conversation. A call that suspends leaves a hole: its group goes on, since its calls
|
|
23
|
+
* were declared independent, but no later group starts, and its result comes in a later turn, after
|
|
24
|
+
* its siblings'. Providers pair results by call id, so the conversation stays valid.
|
|
25
|
+
*
|
|
26
|
+
* Every result is appended only while its call is still unanswered, checked inside its write: a
|
|
27
|
+
* cancel answers a suspended call in its own write, perhaps while that call runs again.
|
|
28
|
+
*
|
|
29
|
+
* Returns nothing: what happened is in the journal. A call held for the user left a
|
|
30
|
+
* `confirm/requested`, a call whose tool suspended left a `wait/declared`, a call that ended the turn
|
|
31
|
+
* left it on its result, and a call that was never answered is simply missing a `tool/result`. The
|
|
32
|
+
* decider reads all of them from there, so there is no outcome to hand back and no chance of the two
|
|
33
|
+
* disagreeing.
|
|
34
|
+
*/
|
|
35
|
+
export declare function executeToolCalls(options: ExecuteToolCallsOptions): Promise<void>;
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin-authoring door: what a plugin imports beside `@leuduan/cordis`.
|
|
3
|
+
*
|
|
4
|
+
* Registering a tool, an agent or a prompt contribution; granting a tool; defining, mounting and
|
|
5
|
+
* validating the configuration of a preset (`definePreset`, `mountPreset`, `parsePresetConfig`), and
|
|
6
|
+
* handing one down to the children a thread's calls create (`handDown`);
|
|
7
|
+
* defining a durable `ext` event, writing it beside a send or a creation (`WriteRows`), and reading what a thread was
|
|
8
|
+
* told; defining a set of durable modes (`defineModes`); adding a typed value to every thread's catalog entry (`defineContribution`); claiming a thread for one plugin, refusing a mount in a thread's scope (`requireUnscoped`)
|
|
9
|
+
* and refusing a missing root service (`requireService`); reading paths and git as the shipped tools
|
|
10
|
+
* do (`sys/`). A tool touches files and starts processes through `InvocationContext.operation`, so the
|
|
11
|
+
* confinement policy judges them; the raw process launches (`spawnCommand`, `runToCompletion`) are on
|
|
12
|
+
* the root door, for the host's own processes;
|
|
13
|
+
* the contracts a tool and a step hook implement; and the `ctx.*` service types every plugin reads.
|
|
14
|
+
* A value lives on one door: the application API is the root entry point, the model contracts are
|
|
15
|
+
* `@leuduan/lagent/llm`, the serialized shapes (`JournalEvent`, `Seq`, `ToolResult`, `stepContribution`,
|
|
16
|
+
* `toJsonSchema`) are `@leuduan/lagent/records`.
|
|
17
|
+
*/
|
|
18
|
+
export * from './context.js';
|
|
19
|
+
export { defineTool, errorResult, grantTool, registerTool } from './services/tools.js';
|
|
20
|
+
export type { JsonSchemaParameters, ToolDefinition, ToolReply } from './services/tools.js';
|
|
21
|
+
export { claimThread, drainBeforeUnload, requireService, requireUnscoped } from './services/plugins.js';
|
|
22
|
+
export { defineModes } from './services/modes.js';
|
|
23
|
+
export type { Modes, ModesDefinition } from './services/modes.js';
|
|
24
|
+
export { AgentSelectorSchema, isScopedAgentName, registerAgent, selects } from './services/agents.js';
|
|
25
|
+
export type { AgentSelector } from './services/agents.js';
|
|
26
|
+
export { definePreset, mountPreset, parsePresetConfig } from './services/presets/definition.js';
|
|
27
|
+
export type { Preset, PresetInstallation, PresetMountOptions, PresetPlace, PresetPlacement, PresetSelection, } from './services/presets/definition.js';
|
|
28
|
+
export { handDown } from './services/presets/installations.js';
|
|
29
|
+
export type { HandDown } from './services/presets/installations.js';
|
|
30
|
+
export type { AgentDefinition, AgentDefinitionInput } from './loop/index.js';
|
|
31
|
+
export { contributePrompt } from './services/prompts.js';
|
|
32
|
+
export { defineContribution } from './services/catalogContributions.js';
|
|
33
|
+
export type { ContributionDefinition, ContributionReading } from './services/catalogContributions.js';
|
|
34
|
+
export type { PromptContribution, PromptRenderInput, PromptSlot } from './services/prompts.js';
|
|
35
|
+
export { ExtensionVersionError, defineExtensionEvent, latestNotice, latestVisible, tellOnStep, } from './services/extensionEvents.js';
|
|
36
|
+
export type { NoticeEvent, StepNotice, ToldNotice, ToldNotices } from './services/extensionEvents.js';
|
|
37
|
+
export { ProjectionFailedError, projection } from './journal/index.js';
|
|
38
|
+
export type { AppendOptions, Committed, PluginJournal, PluginProjection, Transaction } from './journal/index.js';
|
|
39
|
+
export type { CallerChain, OriginBreak, OriginOpening, Origins, RequiredOwner, RequiredOwners, } from './journal/index.js';
|
|
40
|
+
export type { BirthSpec, ForkOpening, FreshOpening, Refusal, RowsResult, RowsWrite, WriteRows } from './state/index.js';
|
|
41
|
+
export { isWaitRequest, waitFor } from './loop/index.js';
|
|
42
|
+
export { lastAssistantMessage } from './state/index.js';
|
|
43
|
+
export { registerSurfaceStrategy } from './loop/index.js';
|
|
44
|
+
export type { AuxiliaryCall, AuxiliaryReply, CompletionRequest, InvocationContext, ModelRequestDraft, ModelStep, SentModelRequest, SentRequest, StopVerdict, AuxiliaryAnswer, FinalPlan, SurfacePlan, SurfacePrepareInput, SurfaceStrategy, Tool, ToolAuthorizationRequest, ToolDenial, ToolEntry, ToolExecutionMode, ToolInvocation, ToolOutcome, ToolPolicyDecision, TurnStop, WaitRequest, ResolvedWait, } from './loop/index.js';
|
|
45
|
+
export type { ReplacementInput } from './state/index.js';
|
|
46
|
+
export { stableStringify } from './util/json.js';
|
|
47
|
+
export { systemClock, timerQueue } from './util/timers.js';
|
|
48
|
+
export type { Clock, TimerQueue } from './util/timers.js';
|
|
49
|
+
export type { AppendEntry } from './journal/index.js';
|
|
50
|
+
export type { SpawnEnvironment } from './sys/spawn.js';
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as N}from"./chunks/DDZ7YF26.js";import{b as t}from"./chunks/KUZCL2SH.js";import{c as P}from"./chunks/CQEVREBT.js";import{b as w,d as F}from"./chunks/HK6ZSONF.js";import{a as M}from"./chunks/7VAPNE3L.js";import{b}from"./chunks/EPYQ5M3B.js";import"./chunks/5IRF47YB.js";import{a as u,b as S,e as E}from"./chunks/OL5A6ITQ.js";import{b as A,c as T,e as h}from"./chunks/JFX2MXBA.js";import{a as l,b as c,c as d,d as g}from"./chunks/S34ZA2R6.js";import{a as q,b as y,c as C,d as j,e as v}from"./chunks/6FRNHMCV.js";import{b as m,c as p,d as a,e as x}from"./chunks/CUK7CGC7.js";import{U as i,V as n,W as s,Y as f}from"./chunks/BPRCULZH.js";import"./chunks/FJLU4UH3.js";import"./chunks/DDANMY45.js";import{c as e,h as r,j as o}from"./chunks/BBCW2FZK.js";import"./chunks/MMNNZCBO.js";import"./chunks/G44LG6VL.js";import"./chunks/D4PQP5MA.js";export{p as AgentSelectorSchema,q as ExtensionVersionError,o as ProjectionFailedError,l as claimThread,b as contributePrompt,M as defineContribution,y as defineExtensionEvent,N as defineModes,u as definePreset,A as defineTool,c as drainBeforeUnload,i as errorResult,h as grantTool,P as handDown,x as isScopedAgentName,s as isWaitRequest,t as lastAssistantMessage,C as latestNotice,j as latestVisible,S as mountPreset,E as parsePresetConfig,r as projection,m as registerAgent,f as registerSurfaceStrategy,T as registerTool,d as requireService,g as requireUnscoped,a as selects,e as stableStringify,w as systemClock,v as tellOnStep,F as timerQueue,n as waitFor};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type Context } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Where a thread's instructions are found and how much of them it is told: the agents-md preset's
|
|
5
|
+
* whole configuration, and the plugin form's besides its selector. All depend on the host, so none
|
|
6
|
+
* has a default here.
|
|
7
|
+
*/
|
|
8
|
+
export declare const AgentsMdDiscoverySchema: z.ZodObject<{
|
|
9
|
+
fileNames: z.ZodArray<z.ZodString>;
|
|
10
|
+
maxBytes: z.ZodNumber;
|
|
11
|
+
}, z.core.$strict>;
|
|
12
|
+
export type AgentsMdDiscovery = z.output<typeof AgentsMdDiscoverySchema>;
|
|
13
|
+
/** The preset's id, which `codexPreset` hands down. */
|
|
14
|
+
export declare const AGENTS_MD_PRESET = "agents-md";
|
|
15
|
+
/** The installation id the preset hands itself down under, so a child holds one and passes it on. */
|
|
16
|
+
export declare const AGENTS_MD_INSTALLATION = "agents-md";
|
|
17
|
+
/** Where instructions are found, and who tells them, as a refusal of a second briefing names it. */
|
|
18
|
+
export type Briefing = AgentsMdDiscovery & {
|
|
19
|
+
readonly holder: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Tells the thread whose scope the calling plugin is mounted in its instructions, for as long as
|
|
23
|
+
* that plugin lives; the plugin injects `journal` and `confinement`. The one implementation behind
|
|
24
|
+
* both forms, and what `codexPreset` mounts on its own thread. Only that thread's steps reach a
|
|
25
|
+
* listener in its scope, so the briefing needs no selector; `threadId` is the thread it is
|
|
26
|
+
* mounted for.
|
|
27
|
+
*
|
|
28
|
+
* It claims the thread's scope first, so a second briefing on the thread is refused, naming
|
|
29
|
+
* `holder`'s, and tells the thread at the first model step at which no notice found with the same
|
|
30
|
+
* discovery settings is the latest recorded: the files, or that none was found, as one recorded
|
|
31
|
+
* notice with those settings. Every later step under the same settings works from that record, so
|
|
32
|
+
* the files are never read again for them, a reopen or a retried call repeats nothing, and a fork
|
|
33
|
+
* inherits what its source was told; a briefing with other settings, such as an installation that
|
|
34
|
+
* replaced the first, finds and tells the files anew.
|
|
35
|
+
*
|
|
36
|
+
* The files are read through the thread's confinement operation, as its own file tools would read
|
|
37
|
+
* them, and read ahead: the returned promise settles once they were, so a setup that awaits it
|
|
38
|
+
* leaves the thread ready with its instructions prepared, and the step, which cannot wait, only tells
|
|
39
|
+
* what was prepared. What a step finds unprepared, because the confinement changed since the read
|
|
40
|
+
* (`ConfinementService.epoch`), is dropped and prepared again for a later step, never read by the
|
|
41
|
+
* step itself and never told from before the change. An operation the handler refuses (a sandbox
|
|
42
|
+
* that cannot say what the conversation may read) tells nothing, records nothing, and says so in the log.
|
|
43
|
+
*/
|
|
44
|
+
export declare function tellAgentsMd(ctx: Context, briefing: Briefing, threadId: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Tells a thread the instructions file in its `cwd`, once, as a conversation message: on the first
|
|
47
|
+
* model step at which nothing of the kind is recorded for the thread, it reads the first of
|
|
48
|
+
* `fileNames` in the `cwd` that exists and is not empty, at most `maxBytes` of it, and records what
|
|
49
|
+
* it told, "none found" included, with those settings. Only the `cwd` is looked in: no directory
|
|
50
|
+
* above it, whatever marks a repository there. A thread is never told twice under the same
|
|
51
|
+
* settings: every later step, a reopened journal and a retried call work from that record, and
|
|
52
|
+
* edits made while the thread lives are not told; the agent can read the file with its tools,
|
|
53
|
+
* since a file told is inside what it may read. A conversation already under way is told at its
|
|
54
|
+
* next step, and so is one whose briefing now has other settings than its latest notice recorded.
|
|
55
|
+
*
|
|
56
|
+
* The notice states how the file applies: it governs the `cwd`'s tree, direct instructions beat
|
|
57
|
+
* it, and files below the `cwd` are the agent's to look for when it works there.
|
|
58
|
+
*
|
|
59
|
+
* The notice is recorded text, so once a replacement takes it off the surface it is told again as
|
|
60
|
+
* recorded: a copy of the notice row's content, under the same source, never a fresh read of the
|
|
61
|
+
* file, so a compaction is not the moment an edit gets told.
|
|
62
|
+
*
|
|
63
|
+
* Not a prompt section: `rebuildPrompt()` would pick up an edited file and change the thread's
|
|
64
|
+
* instructions with nothing in history saying when. A file that cannot be read is logged and
|
|
65
|
+
* skipped rather than failing the step, since an optional file must not block a thread.
|
|
66
|
+
*
|
|
67
|
+
* A thread has one briefing: a second, from another mount or installation, is refused when the
|
|
68
|
+
* thread activates, naming the first.
|
|
69
|
+
*
|
|
70
|
+
* Two placements. Installed on a thread, it tells that thread and hands itself down with the same
|
|
71
|
+
* settings under {@link AGENTS_MD_INSTALLATION}, so a child is born with it, and its children in
|
|
72
|
+
* turn; register it at startup, where a reopened child restores it whether or not its parent is
|
|
73
|
+
* live. Mounted on the root for an agent selector,
|
|
74
|
+
* `mountPreset(root, agentsMdPreset, discovery, { agents })`, it tells each activation whose agent
|
|
75
|
+
* the selector picks, and hands nothing down. Its configuration is only the discovery settings.
|
|
76
|
+
*/
|
|
77
|
+
export declare const agentsMdPreset: import("../services/presets/definition.js").Preset<z.ZodObject<{
|
|
78
|
+
fileNames: z.ZodArray<z.ZodString>;
|
|
79
|
+
maxBytes: z.ZodNumber;
|
|
80
|
+
}, z.core.$strict>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e}from"../chunks/EMRB4KCN.js";import"../chunks/PUSUPTAT.js";import"../chunks/CQEVREBT.js";import"../chunks/5IRF47YB.js";import"../chunks/OL5A6ITQ.js";import"../chunks/S34ZA2R6.js";import"../chunks/6FRNHMCV.js";import"../chunks/CUK7CGC7.js";import"../chunks/BPRCULZH.js";import"../chunks/DDANMY45.js";import"../chunks/BBCW2FZK.js";import"../chunks/MMNNZCBO.js";import"../chunks/G44LG6VL.js";import"../chunks/D4PQP5MA.js";export{c as AGENTS_MD_INSTALLATION,b as AGENTS_MD_PRESET,a as AgentsMdDiscoverySchema,e as agentsMdPreset,d as tellAgentsMd};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Plugin } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type AskServiceConfig } from './service.js';
|
|
4
|
+
/**
|
|
5
|
+
* The questions agents ask the user, through the `ctx.ask` service it mounts: each is a durable wait
|
|
6
|
+
* the host lists with `open(threadId)` and answers with `answer({ threadId, callSeq }, text)`, which
|
|
7
|
+
* survives a reload and a restart. Its configuration is required: `deadlineMs`, how long a question
|
|
8
|
+
* waits before the agent is told to go on without it (`null` for no deadline), and the `clock` it is
|
|
9
|
+
* kept on.
|
|
10
|
+
*
|
|
11
|
+
* Root-only, mounted once by the application, before the presets that mount {@link askQuestion}.
|
|
12
|
+
* The worked example is in the plugin guide (`docs/guides/plugins.md`, Run constraints).
|
|
13
|
+
*/
|
|
14
|
+
export declare const ask: Plugin.Constructor<AskServiceConfig>;
|
|
15
|
+
declare const AskQuestionConfigSchema: z.ZodObject<{
|
|
16
|
+
name: z.ZodDefault<z.ZodString>;
|
|
17
|
+
agents: z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodLiteral<"global">, z.ZodLiteral<"all">]>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type AskQuestionConfig = z.input<typeof AskQuestionConfigSchema>;
|
|
20
|
+
/**
|
|
21
|
+
* Lets agents ask the user questions: the `ask_question` tool, for the agents `agents` selects.
|
|
22
|
+
* Mounted where a preset grants it; refuses to mount without the {@link ask} service.
|
|
23
|
+
*/
|
|
24
|
+
export declare const askQuestion: Plugin.Object<AskQuestionConfig>;
|
|
25
|
+
export { ASK_OWNER, QuestionAnsweredError, QuestionClosedError } from './service.js';
|
|
26
|
+
export type { AskService, AskServiceConfig, OpenQuestion } from './service.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e}from"../../chunks/RCIHV3KG.js";import"../../chunks/MNJ4SRF7.js";import"../../chunks/HK6ZSONF.js";import"../../chunks/JFX2MXBA.js";import"../../chunks/S34ZA2R6.js";import"../../chunks/CUK7CGC7.js";import"../../chunks/BPRCULZH.js";import"../../chunks/FJLU4UH3.js";import"../../chunks/DDANMY45.js";import"../../chunks/BBCW2FZK.js";import"../../chunks/MMNNZCBO.js";import"../../chunks/G44LG6VL.js";import"../../chunks/D4PQP5MA.js";export{a as ASK_OWNER,b as QuestionAnsweredError,c as QuestionClosedError,d as ask,e as askQuestion};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Service, type Context } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type InvocationContext, type ResolvedWait, type WaitRequest } from '../../loop/index.js';
|
|
4
|
+
import type { Seq } from '../../records/journal.js';
|
|
5
|
+
declare module '@leuduan/cordis' {
|
|
6
|
+
interface Context {
|
|
7
|
+
/** The questions agents ask the user, and their answers (optional plugin). */
|
|
8
|
+
ask: AskService;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** The owner a question's wait names. */
|
|
12
|
+
export declare const ASK_OWNER = "lagent:ask";
|
|
13
|
+
export declare const AskServiceConfigSchema: z.ZodObject<{
|
|
14
|
+
deadlineMs: z.ZodNullable<z.ZodNumber>;
|
|
15
|
+
clock: z.ZodCustom<import("../../util/timers.js").Clock, import("../../util/timers.js").Clock>;
|
|
16
|
+
}, z.core.$strict>;
|
|
17
|
+
export type AskServiceConfig = z.input<typeof AskServiceConfigSchema>;
|
|
18
|
+
declare const AskOptionSchema: z.ZodObject<{
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
label: z.ZodString;
|
|
21
|
+
description: z.ZodString;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
/** One predefined answer. The user may always reply freely instead. */
|
|
24
|
+
export type AskOption = z.output<typeof AskOptionSchema>;
|
|
25
|
+
/** How a question resolved, versioned by ask: the person's answer, or its deadline passing. */
|
|
26
|
+
declare const QuestionValueSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
27
|
+
v: z.ZodLiteral<1>;
|
|
28
|
+
answer: z.ZodString;
|
|
29
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
30
|
+
v: z.ZodLiteral<1>;
|
|
31
|
+
timeout: z.ZodLiteral<true>;
|
|
32
|
+
}, z.core.$strict>]>;
|
|
33
|
+
export type QuestionValue = z.output<typeof QuestionValueSchema>;
|
|
34
|
+
/** A question waiting for its answer, from the asking thread's rows. */
|
|
35
|
+
export type OpenQuestion = {
|
|
36
|
+
readonly threadId: string;
|
|
37
|
+
/** The asking call's `tool/call` row: the question's identity. */
|
|
38
|
+
readonly callSeq: Seq;
|
|
39
|
+
readonly question: string;
|
|
40
|
+
readonly options: readonly AskOption[] | null;
|
|
41
|
+
readonly agent: string;
|
|
42
|
+
readonly deadlineAt: number | null;
|
|
43
|
+
};
|
|
44
|
+
/** An answer to a question that already has one, recorded first: a person's answer, or its timeout. */
|
|
45
|
+
export declare class QuestionAnsweredError extends Error {
|
|
46
|
+
readonly threadId: string;
|
|
47
|
+
readonly callSeq: Seq;
|
|
48
|
+
readonly recorded: QuestionValue;
|
|
49
|
+
constructor(threadId: string, callSeq: Seq, recorded: QuestionValue);
|
|
50
|
+
}
|
|
51
|
+
/** An answer to a question that is not open: its call was answered without one, or it was never asked. */
|
|
52
|
+
export declare class QuestionClosedError extends Error {
|
|
53
|
+
readonly threadId: string;
|
|
54
|
+
readonly callSeq: Seq;
|
|
55
|
+
constructor(threadId: string, callSeq: Seq);
|
|
56
|
+
}
|
|
57
|
+
/** What a resolved question's call is answered with: what it asked, and how it resolved. */
|
|
58
|
+
export declare function questionAnswer(wait: ResolvedWait): {
|
|
59
|
+
readonly question: string;
|
|
60
|
+
readonly value: QuestionValue;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The questions agents ask the user. A question is a durable wait under {@link ASK_OWNER}: the
|
|
64
|
+
* asking call suspends, its run gives up its slot and the thread is held `wait` until the answer, the
|
|
65
|
+
* deadline or a cancel, across restarts too. Core owns the suspension and the redispatch; this owns
|
|
66
|
+
* the question's content, its deadline and answer-once.
|
|
67
|
+
*
|
|
68
|
+
* Deadlines are kept on one timer queue: armed as a question is declared, and at startup from the
|
|
69
|
+
* catalog, where one that passed while the process was down times out in the repair. A recorded
|
|
70
|
+
* deadline is honoured whatever `deadlineMs` says now. At the chain limit a question is asked with
|
|
71
|
+
* no deadline, since a timeout opens a reactive turn.
|
|
72
|
+
*/
|
|
73
|
+
export declare class AskService extends Service<AskServiceConfig> {
|
|
74
|
+
static inject: string[];
|
|
75
|
+
readonly config: z.output<typeof AskServiceConfigSchema>;
|
|
76
|
+
private readonly deadlines;
|
|
77
|
+
private handle;
|
|
78
|
+
/** Timeouts being written, which shutdown lets land. */
|
|
79
|
+
private readonly timingOut;
|
|
80
|
+
/** Timeouts whose write failed, by question: each is tried again, later. */
|
|
81
|
+
private readonly retries;
|
|
82
|
+
private closing;
|
|
83
|
+
constructor(ctx: Context, config: AskServiceConfig);
|
|
84
|
+
/** The wait a call asks `question` with, under the configured deadline. */
|
|
85
|
+
ask(context: InvocationContext, question: {
|
|
86
|
+
readonly question: string;
|
|
87
|
+
readonly options: AskOption[] | null;
|
|
88
|
+
}): WaitRequest;
|
|
89
|
+
/**
|
|
90
|
+
* The thread's open questions, in the order they were asked, from its rows. Synchronous, by a
|
|
91
|
+
* caller that holds the thread, as `ctx.threads.view` is; the catalog's `waits` under
|
|
92
|
+
* {@link ASK_OWNER} say which threads have one.
|
|
93
|
+
*/
|
|
94
|
+
open(threadId: string): OpenQuestion[];
|
|
95
|
+
/**
|
|
96
|
+
* Answers the question of call `callSeq` on `threadId`, as a person: resolves once the answer is
|
|
97
|
+
* durable, and the asking call runs again with it. Refuses with {@link QuestionAnsweredError} when
|
|
98
|
+
* an answer or the deadline came first, and with {@link QuestionClosedError} when the question is
|
|
99
|
+
* not open.
|
|
100
|
+
*/
|
|
101
|
+
answer(question: {
|
|
102
|
+
readonly threadId: string;
|
|
103
|
+
readonly callSeq: Seq;
|
|
104
|
+
}, text: string): Promise<void>;
|
|
105
|
+
private registration;
|
|
106
|
+
/** A question declared arms its deadline; one resolved, or whose call was answered, disarms it. */
|
|
107
|
+
private onRow;
|
|
108
|
+
private disarm;
|
|
109
|
+
private arm;
|
|
110
|
+
/**
|
|
111
|
+
* Closes a question at its deadline, unless an answer or a cancel came first. A write that fails is
|
|
112
|
+
* reported and tried again later, so the deadline is not lost with it.
|
|
113
|
+
*/
|
|
114
|
+
private timeout;
|
|
115
|
+
/**
|
|
116
|
+
* The startup repair, from the catalog: every open question's deadline armed, and one that passed
|
|
117
|
+
* while the process was down timed out now. Resolves once those writes have landed, so the startup
|
|
118
|
+
* policy judges their causes. A timeout whose write failed is reported and tried again later, as at
|
|
119
|
+
* runtime, rather than failing the repair: a failed repair stays failed, and the retry recovers.
|
|
120
|
+
*/
|
|
121
|
+
private repair;
|
|
122
|
+
/** Stops closing questions at their deadlines, which the next startup does, and lets those under way land. */
|
|
123
|
+
private shutdown;
|
|
124
|
+
}
|
|
125
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Tool } from '../../loop/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Asks the user a question through the ask service (`ctx.ask`): the call suspends on a durable wait,
|
|
4
|
+
* its run gives up its slot, and the call runs again once the question resolves. It is then
|
|
5
|
+
* answered with the person's answer, or, past the host's deadline, told to go on without it, which
|
|
6
|
+
* is no error and conveys no approval. A cancel answers the call itself, so it never runs again.
|
|
7
|
+
* Offered as `name`, `ask_question` unless the plugin renames it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const askQuestionTool: (name: string) => Tool;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Plugin } from '@leuduan/cordis';
|
|
2
|
+
import { type CommandsConfigInput } from './service.js';
|
|
3
|
+
export { commandRecords, commandRow, readCommandNotice } from './record.js';
|
|
4
|
+
export type { CommandEnded, CommandNotice, CommandRecord, CommandStarted } from './record.js';
|
|
5
|
+
export { commandWork } from './service.js';
|
|
6
|
+
export type { CommandInfo, CommandsConfigInput, CommandsService, CommandWork } from './service.js';
|
|
7
|
+
/** The tools `commands` registers, by name: the foreground one, then the four for background commands. */
|
|
8
|
+
export declare const COMMAND_TOOLS: readonly ["run_command", "start_command", "read_command_output", "list_commands", "stop_command"];
|
|
9
|
+
/**
|
|
10
|
+
* Shell commands: `run_command`, and background commands through `start_command`,
|
|
11
|
+
* `read_command_output`, `list_commands` and `stop_command`. Every command runs in a process group
|
|
12
|
+
* of its own (`sys/spawn`), so a timeout, a cancellation or a stop reaches everything it started,
|
|
13
|
+
* and nothing it started outlives lagent.
|
|
14
|
+
*
|
|
15
|
+
* All five tools are always registered; which agent may call which is a grant. An application that
|
|
16
|
+
* wants no background execution grants none of the four. A tool that starts a process must be held
|
|
17
|
+
* for confirmation wherever it is granted: `SAFE_WRITES_TOOLS` lists `run_command` and
|
|
18
|
+
* `start_command`.
|
|
19
|
+
*
|
|
20
|
+
* A background command started with `notify: "exit"` on a conversation with no caller wakes it with
|
|
21
|
+
* a notice when it exits on its own (`commandNotice`, which a host reads with `readCommandNotice`).
|
|
22
|
+
*
|
|
23
|
+
* Whether a thread's command work, or its subtree's, has ended has one answer, `commandWork`, from
|
|
24
|
+
* the threads' rows and what this process runs: a cleanup or a quiescence check reads it rather
|
|
25
|
+
* than the records. It holds whether or not this plugin is mounted: without it nothing drains, and
|
|
26
|
+
* a thread neither loaded nor carrying the plugin's catalog entry is unresolved.
|
|
27
|
+
*
|
|
28
|
+
* Every agent that may call `run_command` or `start_command` is told, in its prompt, what `/bin/sh`
|
|
29
|
+
* is on this system, read once at mount.
|
|
30
|
+
*
|
|
31
|
+
* Every command runs with exactly the `environment` the host configures, which nothing defaults:
|
|
32
|
+
* lagent passes on none of its own. Commands launch through `ctx.confinement`, with the thread they serve,
|
|
33
|
+
* so a host that registers a confinement handler, such as an OS sandbox, confines every `run_command` and
|
|
34
|
+
* `start_command` without this plugin knowing it. What the handler lets the model do is the
|
|
35
|
+
* handler's to tell, as a notice.
|
|
36
|
+
*
|
|
37
|
+
* Each command's log is kept in its thread's directory, so the plugin injects `threadDirs`: on a root
|
|
38
|
+
* without `threadDirs` mounted it stays pending, mounting nothing, until one is.
|
|
39
|
+
*
|
|
40
|
+
* Root-only: the background commands live on the `ctx.commands` service this mounts.
|
|
41
|
+
*/
|
|
42
|
+
export declare const commands: Plugin.Object<CommandsConfigInput>;
|
|
43
|
+
export type { BackgroundCommand, CommandLookup, CommandsConfig, RecordedCommand, RecordedStatus } from './service.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e,f}from"../../chunks/JFZZXVWD.js";import"../../chunks/N6IXG2VL.js";import"../../chunks/6DRCKZ2C.js";import"../../chunks/7LI64H5X.js";import"../../chunks/3UMZMPWW.js";import"../../chunks/7VAPNE3L.js";import"../../chunks/EPYQ5M3B.js";import"../../chunks/5IRF47YB.js";import"../../chunks/JFX2MXBA.js";import"../../chunks/S34ZA2R6.js";import"../../chunks/6FRNHMCV.js";import"../../chunks/CUK7CGC7.js";import"../../chunks/BPRCULZH.js";import"../../chunks/FJLU4UH3.js";import"../../chunks/DDANMY45.js";import"../../chunks/BBCW2FZK.js";import"../../chunks/MMNNZCBO.js";import"../../chunks/G44LG6VL.js";import"../../chunks/D4PQP5MA.js";export{e as COMMAND_TOOLS,b as commandRecords,a as commandRow,d as commandWork,f as commands,c as readCommandNotice};
|