@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,27 @@
|
|
|
1
|
+
import type { SqlConnection, SqlExclusivity, SqlValue } from './sql.js';
|
|
2
|
+
/**
|
|
3
|
+
* The part of a Durable Object's `ctx.storage` the store uses, typed structurally so this package
|
|
4
|
+
* takes no dependency on the Workers types. The real object satisfies it as it is.
|
|
5
|
+
*/
|
|
6
|
+
export type DurableObjectStorage = {
|
|
7
|
+
sql: {
|
|
8
|
+
exec(query: string, ...bindings: SqlValue[]): {
|
|
9
|
+
toArray(): unknown[];
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
transactionSync<T>(body: () => T): T;
|
|
13
|
+
sync(): Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Runs the store's SQL on the object's own SQLite. A transaction's local commit is synchronous, and
|
|
17
|
+
* its result resolves only after `sync()` confirms the write is durable. A `sync()` rejection is the
|
|
18
|
+
* transaction's failure and rolls nothing back: the local commit completed and may have persisted.
|
|
19
|
+
*/
|
|
20
|
+
export declare function durableObjectConnection(storage: DurableObjectStorage): SqlConnection;
|
|
21
|
+
/**
|
|
22
|
+
* The one writer of a storage. Wrappers over the same storage share the entry, so a second
|
|
23
|
+
* acquisition is refused whichever wrapper makes it; the platform runs one instance of an object,
|
|
24
|
+
* but that instance can still hold two stores over one `ctx.storage`. Release clears only the
|
|
25
|
+
* entry this acquisition made, so a stale release never clears a replacement's.
|
|
26
|
+
*/
|
|
27
|
+
export declare function durableObjectExclusivity(storage: object, identity: string): SqlExclusivity;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { JournalEvent, Seq, ThreadSummary } from '../../models/index.js';
|
|
2
|
+
import { JournalStore, type AppendOutcome, type Attempt, type ThreadIndexEntry, type WriterLease } from '../../journal/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* In-memory backing, keeping serialized rows so it exercises the same round trip as SQLite. Its
|
|
5
|
+
* writer lease is exclusive within the process, which is as far as its rows reach.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MemoryJournalStore extends JournalStore {
|
|
8
|
+
private readonly rows;
|
|
9
|
+
/** Each row's thread and seq, so a read need not parse every row. */
|
|
10
|
+
private readonly index;
|
|
11
|
+
private readonly threadIndex;
|
|
12
|
+
private readonly catalog;
|
|
13
|
+
private readonly attempts;
|
|
14
|
+
/** The acquisition the writer record names; `undefined` while nobody holds the lease. */
|
|
15
|
+
private writer;
|
|
16
|
+
get size(): number;
|
|
17
|
+
acquireWriter(): Promise<WriterLease>;
|
|
18
|
+
protected doOpen(): Promise<void>;
|
|
19
|
+
protected doClose(): Promise<void>;
|
|
20
|
+
protected doHead(): Promise<Seq>;
|
|
21
|
+
protected doAppend(attempt: Attempt, digest: string): Promise<AppendOutcome>;
|
|
22
|
+
protected doRead(threadId: string): Promise<JournalEvent[]>;
|
|
23
|
+
protected doRowAt(seq: Seq): Promise<JournalEvent | undefined>;
|
|
24
|
+
protected doThreads(): Promise<ThreadIndexEntry[]>;
|
|
25
|
+
protected doSummaries(): Promise<ThreadSummary[]>;
|
|
26
|
+
protected doPutSummaries(summaries: readonly ThreadSummary[], writer: string): Promise<void>;
|
|
27
|
+
protected doReplaceCatalog(summaries: readonly ThreadSummary[], writer: string): Promise<void>;
|
|
28
|
+
private headSeq;
|
|
29
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { JournalEvent, Seq, ThreadSummary } from '../../models/index.js';
|
|
2
|
+
import { JournalStore, type AppendOutcome, type Attempt, type ThreadIndexEntry, type WriterLease } from '../../journal/index.js';
|
|
3
|
+
export type SqlValue = string | number | null;
|
|
4
|
+
/** A synchronous SQLite connection: what the two stores differ in, except exclusivity. */
|
|
5
|
+
export type SqlConnection = {
|
|
6
|
+
/** Statements without parameters or results; may hold several (the schema). */
|
|
7
|
+
exec(sql: string): void;
|
|
8
|
+
run(sql: string, ...params: SqlValue[]): void;
|
|
9
|
+
all<Row>(sql: string, ...params: SqlValue[]): Row[];
|
|
10
|
+
/** Runs `body` as one write transaction, rolled back when it throws; resolves once the commit is durable. */
|
|
11
|
+
transaction<T>(body: () => T): Promise<T>;
|
|
12
|
+
/** Releases this adapter's resources; never the host's storage. */
|
|
13
|
+
close(): void;
|
|
14
|
+
};
|
|
15
|
+
/** The exclusivity a store's platform grants, taken before anything is read: an OS lock, an in-process registry. */
|
|
16
|
+
export type SqlExclusivity = {
|
|
17
|
+
readonly identity: string;
|
|
18
|
+
release(): void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The journal store over a synchronous SQLite connection: the schema and its version stamp, the
|
|
22
|
+
* writer record, every append, summary and catalog check, and row parsing. A subclass supplies the
|
|
23
|
+
* connection and the exclusivity its platform grants; nothing else differs between stores.
|
|
24
|
+
*/
|
|
25
|
+
export declare abstract class SqlJournalStore extends JournalStore {
|
|
26
|
+
private db;
|
|
27
|
+
/** The acquisition this store holds, recorded in `writer` once the database is open. */
|
|
28
|
+
private acquisition;
|
|
29
|
+
private readonly location;
|
|
30
|
+
/** `location` names the journal in errors, such as `IncompatibleJournalError`. */
|
|
31
|
+
protected constructor(location: string);
|
|
32
|
+
/** Opens the connection `doOpen` uses; the store closes it in `doClose`. */
|
|
33
|
+
protected abstract connect(): SqlConnection;
|
|
34
|
+
/** Takes the platform's exclusivity for `acquireWriter`, or rejects with `JournalBusyError`. */
|
|
35
|
+
protected abstract exclusive(): Promise<SqlExclusivity>;
|
|
36
|
+
acquireWriter(): Promise<WriterLease>;
|
|
37
|
+
/**
|
|
38
|
+
* Inside a transaction: refuses unless `writer` is the acquisition this store holds and the writer
|
|
39
|
+
* record names it. The held acquisition alone fences a released lease whose record could not be
|
|
40
|
+
* cleared; the record alone fences another process that took the journal over.
|
|
41
|
+
*/
|
|
42
|
+
private requireWriter;
|
|
43
|
+
/** Names this store's acquisition in the writer record, which every append checks. */
|
|
44
|
+
private recordWriter;
|
|
45
|
+
protected doOpen(): Promise<void>;
|
|
46
|
+
protected doClose(): Promise<void>;
|
|
47
|
+
private requireDb;
|
|
48
|
+
protected doHead(): Promise<Seq>;
|
|
49
|
+
private headOf;
|
|
50
|
+
protected doAppend(attempt: Attempt, digest: string): Promise<AppendOutcome>;
|
|
51
|
+
protected doRead(threadId: string): Promise<JournalEvent[]>;
|
|
52
|
+
protected doRowAt(seq: Seq): Promise<JournalEvent | undefined>;
|
|
53
|
+
protected doThreads(): Promise<ThreadIndexEntry[]>;
|
|
54
|
+
protected doSummaries(): Promise<ThreadSummary[]>;
|
|
55
|
+
protected doPutSummaries(summaries: readonly ThreadSummary[], writer: string): Promise<void>;
|
|
56
|
+
protected doReplaceCatalog(summaries: readonly ThreadSummary[], writer: string): Promise<void>;
|
|
57
|
+
private writeSummaries;
|
|
58
|
+
private rows;
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SqlJournalStore, type SqlConnection, type SqlExclusivity } from './sql.js';
|
|
2
|
+
/** What `SqliteJournalStore` needs from the host, with no default for either. */
|
|
3
|
+
export type SqliteJournalStoreOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* The directory the writer-lock files live in, an absolute path. Every process that opens this
|
|
6
|
+
* journal must be given the same one, or two writers are not refused; one beside the journal is
|
|
7
|
+
* the natural choice.
|
|
8
|
+
*/
|
|
9
|
+
readonly lockDirectory: string;
|
|
10
|
+
/**
|
|
11
|
+
* How long, in total, an append or a catalog write waits for another connection's write lock, a
|
|
12
|
+
* shell or a backup say, before it fails with `StoreBusyError`. `0` does not wait.
|
|
13
|
+
*/
|
|
14
|
+
readonly busyTimeoutMs: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* SQLite-backed journal at `<directory>/journal.db`: the rows in `events`, the thread index in
|
|
18
|
+
* `threads` and the attempt record in `attempts`, written in one transaction per group; the catalog
|
|
19
|
+
* in `summaries`, written after; the writer record in `writer`; the format stamp in `meta`. The
|
|
20
|
+
* writer lease is an operating system lock, so a process that dies releases it; the record holds the
|
|
21
|
+
* acquisition id every append checks. Construct one and pass it to `core` as `store`.
|
|
22
|
+
*/
|
|
23
|
+
export declare class SqliteJournalStore extends SqlJournalStore {
|
|
24
|
+
private readonly lockDirectory;
|
|
25
|
+
private readonly busyTimeoutMs;
|
|
26
|
+
readonly directory: string;
|
|
27
|
+
constructor(directory: string, options: SqliteJournalStoreOptions);
|
|
28
|
+
get databasePath(): string;
|
|
29
|
+
protected connect(): SqlConnection;
|
|
30
|
+
protected exclusive(): Promise<SqlExclusivity>;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as m}from"../../chunks/AP6Q4EPT.js";import{l as u,m as h}from"../../chunks/37YOGDGY.js";import"../../chunks/KESCTXGO.js";import"../../chunks/TYTQRLTX.js";import"../../chunks/D7E6EWIE.js";import{closeSync as d,mkdirSync as c,openSync as w,realpathSync as f,statSync as p}from"node:fs";import{isAbsolute as M,join as n}from"node:path";import{DatabaseSync as y}from"node:sqlite";var b=class extends m{lockDirectory;busyTimeoutMs;directory;constructor(t,e){super(n(t,"journal.db")),this.directory=t;let{lockDirectory:r,busyTimeoutMs:s}=e;if(!M(r))throw new TypeError(`lockDirectory must be an absolute path: ${r}`);if(!Number.isFinite(s)||s<0)throw new TypeError(`busyTimeoutMs must be a finite number of milliseconds, zero or more: ${s}`);this.lockDirectory=r,this.busyTimeoutMs=s}get databasePath(){return n(this.directory,"journal.db")}connect(){return c(this.directory,{recursive:!0}),new a(this.databasePath,this.busyTimeoutMs)}async exclusive(){c(this.directory,{recursive:!0}),d(w(this.databasePath,"a",384));let t=f(this.databasePath),{dev:e,ino:r}=p(t,{bigint:!0});c(this.lockDirectory,{recursive:!0,mode:448});let s=new y(n(this.lockDirectory,`${e}-${r}.db`));try{s.exec("PRAGMA busy_timeout=0; BEGIN EXCLUSIVE")}catch(i){throw s.close(),l(i)?new u(t):i}return{identity:`sqlite:${e}:${r}`,release:()=>s.close()}}},a=class{db;path;busyTimeoutMs;statements=new Map;writes=Promise.resolve();constructor(t,e){this.path=t,this.busyTimeoutMs=e,this.db=new y(t);try{this.db.exec("PRAGMA journal_mode=WAL")}catch(r){throw this.db.close(),r}}exec(t){this.db.exec(t)}run(t,...e){this.statement(t).run(...e)}all(t,...e){return this.statement(t).all(...e)}transaction(t){let e=()=>this.write(t),r=this.writes.then(e,e);return this.writes=r.catch(()=>{}),r}close(){this.statements.clear(),this.db.close()}statement(t){let e=this.statements.get(t);return e===void 0&&(e=this.db.prepare(t),this.statements.set(t,e)),e}async write(t){await this.beginWrite();try{let e=t();return this.db.exec("COMMIT"),e}catch(e){throw this.rollback(),e}}async beginWrite(){let t=Date.now();for(let e=5;;e=Math.min(e*2,100))try{this.db.exec("BEGIN IMMEDIATE");return}catch(r){if(!l(r))throw r;let s=Date.now()-t;if(s>=this.busyTimeoutMs)throw new h(this.path,s);await new Promise(i=>setTimeout(i,Math.min(e,this.busyTimeoutMs-s)))}}rollback(){if(this.db.isTransaction)try{this.db.exec("ROLLBACK")}catch(t){console.error(t)}}},l=o=>{let t=o?.errcode;return typeof t=="number"&&(t&255)===5};export{b as SqliteJournalStore};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Context } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { LlmService } from '../../services/llm.js';
|
|
4
|
+
declare const RouteCatalogSchema: z.ZodObject<{
|
|
5
|
+
providers: z.ZodArray<z.ZodObject<{
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
default_model: z.ZodString;
|
|
8
|
+
default_thinking_effort: z.ZodNullable<z.ZodEnum<{
|
|
9
|
+
low: "low";
|
|
10
|
+
high: "high";
|
|
11
|
+
none: "none";
|
|
12
|
+
medium: "medium";
|
|
13
|
+
max: "max";
|
|
14
|
+
}>>;
|
|
15
|
+
models: z.ZodArray<z.ZodObject<{
|
|
16
|
+
id: z.ZodString;
|
|
17
|
+
description: z.ZodNullable<z.ZodString>;
|
|
18
|
+
thinking_efforts: z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
19
|
+
low: "low";
|
|
20
|
+
high: "high";
|
|
21
|
+
none: "none";
|
|
22
|
+
medium: "medium";
|
|
23
|
+
max: "max";
|
|
24
|
+
}>>>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
}, z.core.$strip>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
/** The routes a sub-agent call can name, as its caller is told them. */
|
|
29
|
+
export type RouteCatalog = z.output<typeof RouteCatalogSchema>;
|
|
30
|
+
/**
|
|
31
|
+
* Every registered provider, in name order, each with its declared models and its default model
|
|
32
|
+
* first when the list does not name it. Registering a provider is what offers it, so nothing is
|
|
33
|
+
* filtered. Deterministic, so two catalogs compare equal exactly when a caller would be told the
|
|
34
|
+
* same thing.
|
|
35
|
+
*/
|
|
36
|
+
export declare function routeCatalog(llm: LlmService): RouteCatalog;
|
|
37
|
+
/** The whole list, which replaces any list the model can still see (`replaces`). */
|
|
38
|
+
export declare function renderAvailableRoutes(catalog: RouteCatalog, options: {
|
|
39
|
+
replaces: boolean;
|
|
40
|
+
}): string;
|
|
41
|
+
/**
|
|
42
|
+
* Tells the agents `isCaller` selects the routes a sub-agent call can name, at the next model step
|
|
43
|
+
* already due whenever the catalog differs from the latest notice the model can still see: on its
|
|
44
|
+
* first step, when a provider comes or goes, and after a replacement took the notice off the
|
|
45
|
+
* surface. The whole list is told again, never a diff, so the latest visible notice is the catalog.
|
|
46
|
+
*
|
|
47
|
+
* Installed by `subAgents` in the scope it grants in, selecting the agents those grants reach, so it
|
|
48
|
+
* reaches exactly the threads they do. It describes; nothing the tool accepts depends on it. A
|
|
49
|
+
* thread that two mounts both tell gets the notice once, since identical contributions to one step
|
|
50
|
+
* are recorded once (`ModelStep.contribute`).
|
|
51
|
+
*/
|
|
52
|
+
export declare function tellAvailableRoutes(ctx: Context, isCaller: (agentName: string) => boolean): void;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Tool } from '../../loop/index.js';
|
|
3
|
+
import type { EndpointDescription } from './tool.js';
|
|
4
|
+
/** Validates a fork endpoint's call, and is the source of the schema advertised to the model. */
|
|
5
|
+
export declare const ForkParameters: z.ZodObject<{
|
|
6
|
+
task: z.ZodString;
|
|
7
|
+
background: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
export declare const formatForkResult: (output: string, isError: boolean) => string;
|
|
10
|
+
/**
|
|
11
|
+
* What the forked thread is asked to do: the fork framing, naming the tool that forked it so it is
|
|
12
|
+
* told not to call that again, plus the task itself.
|
|
13
|
+
*/
|
|
14
|
+
export declare const forkTaskPrompt: (task: string, toolName: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* A fork endpoint's tool: a child thread that continues this conversation, driven by
|
|
17
|
+
* `ctx.delegations` like any other delegation.
|
|
18
|
+
*
|
|
19
|
+
* The child is cut at the request that produced the call, so it sees exactly what the model saw
|
|
20
|
+
* when it asked — not the call, and not sibling results committed after it. Several calls on one
|
|
21
|
+
* reply run concurrently through the tool-call pool, and every sibling shares that request's cached
|
|
22
|
+
* prefix, the route and the mode included. Its task is queued in the same append that creates it,
|
|
23
|
+
* framed as a fork task, and its answer comes back as a `fork_result`, or with `background` a receipt
|
|
24
|
+
* comes back at once. The call takes no route: a fork runs on its source's route, so its siblings
|
|
25
|
+
* share the prefix.
|
|
26
|
+
*
|
|
27
|
+
* The child's id and its task's are derived from the call, so a call re-dispatched after a crash
|
|
28
|
+
* waits for the task it opened instead of duplicating it, and one whose task already settled
|
|
29
|
+
* returns its recorded output without running twice. Like every start tool, the result names the child's `thread_id`; `message_agent`
|
|
30
|
+
* continues it, with the message as plain input.
|
|
31
|
+
*/
|
|
32
|
+
export declare const forkTool: ({ toolName, description }: EndpointDescription) => Tool;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Plugin } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* One way callers delegate: a tool under `toolName`, granted to `callers` and described to them
|
|
5
|
+
* here, whose calls start children on the target. The endpoint is how callers see the target; the
|
|
6
|
+
* target is what a child runs on, so renaming or rewording the tool never redefines a child.
|
|
7
|
+
*/
|
|
8
|
+
declare const EndpointSchema: z.ZodObject<{
|
|
9
|
+
toolName: z.ZodString;
|
|
10
|
+
callers: z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodLiteral<"global">, z.ZodLiteral<"all">]>;
|
|
11
|
+
description: z.ZodString;
|
|
12
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
13
|
+
kind: z.ZodLiteral<"agent">;
|
|
14
|
+
name: z.ZodString;
|
|
15
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
16
|
+
id: z.ZodString;
|
|
17
|
+
basePrompt: z.ZodString;
|
|
18
|
+
tools: z.ZodArray<z.ZodString>;
|
|
19
|
+
kind: z.ZodLiteral<"role">;
|
|
20
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
21
|
+
kind: z.ZodLiteral<"fork">;
|
|
22
|
+
}, z.core.$strict>], "kind">;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
export type EndpointInput = z.input<typeof EndpointSchema>;
|
|
25
|
+
declare const SubAgentsConfigSchema: z.ZodObject<{
|
|
26
|
+
endpoints: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
27
|
+
toolName: z.ZodString;
|
|
28
|
+
callers: z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodLiteral<"global">, z.ZodLiteral<"all">]>;
|
|
29
|
+
description: z.ZodString;
|
|
30
|
+
target: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
31
|
+
kind: z.ZodLiteral<"agent">;
|
|
32
|
+
name: z.ZodString;
|
|
33
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
34
|
+
id: z.ZodString;
|
|
35
|
+
basePrompt: z.ZodString;
|
|
36
|
+
tools: z.ZodArray<z.ZodString>;
|
|
37
|
+
kind: z.ZodLiteral<"role">;
|
|
38
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
39
|
+
kind: z.ZodLiteral<"fork">;
|
|
40
|
+
}, z.core.$strict>], "kind">;
|
|
41
|
+
}, z.core.$strict>>>;
|
|
42
|
+
}, z.core.$strict>;
|
|
43
|
+
export type SubAgentsConfig = z.input<typeof SubAgentsConfigSchema>;
|
|
44
|
+
/**
|
|
45
|
+
* Lets agents start sub-agents and forks, as tools: one endpoint per tool, whose target is a
|
|
46
|
+
* registered global agent, a role, or a fork of the caller. Mount it once per layer with that
|
|
47
|
+
* layer's endpoints: a second mount in one layer naming the same tool collides rather than
|
|
48
|
+
* merging. Mounts in different layers are independent, such as one on the root and the one the
|
|
49
|
+
* `codex` preset makes per thread for its explorer and its fork.
|
|
50
|
+
*
|
|
51
|
+
* The target kind decides what a call takes and what its child is. An agent target must be
|
|
52
|
+
* registered when this mounts, and must be global wherever this mounts: a child is a sibling of its
|
|
53
|
+
* caller's scope, so an agent registered in the caller's scope is invisible to the child, which
|
|
54
|
+
* could never run on it. A role target creates its child with the role recorded as the child's
|
|
55
|
+
* defining installation of the `role` preset, which `delegations` registers and which defines the
|
|
56
|
+
* child's agent in the child's own layer. Both take a task, a route and `background`. A fork target
|
|
57
|
+
* takes a task and `background` only; see {@link forkTool}.
|
|
58
|
+
*
|
|
59
|
+
* Every tool only starts: its result names the child's `thread_id`, which `message_agent` (the
|
|
60
|
+
* `delegations` plugin) continues. Every call delegates through `ctx.delegations`, so the
|
|
61
|
+
* `delegations` plugin must be mounted first, and this one refuses to mount without it. Every
|
|
62
|
+
* caller is also told the routes a call can name (see `tellAvailableRoutes`), in the same scope as
|
|
63
|
+
* its grants, so this configuration is the one list of who can start a sub-agent. Guidance about
|
|
64
|
+
* coordinating forks belongs to the consumer preset or host.
|
|
65
|
+
*/
|
|
66
|
+
export declare const subAgents: Plugin.Object<SubAgentsConfig | undefined>;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"../../chunks/IJ2WNMD5.js";import"../../chunks/EGZI4XQX.js";import"../../chunks/UD3VJER6.js";import"../../chunks/SGGMBSBA.js";import"../../chunks/3QCW4WDJ.js";import"../../chunks/C5LYCXJG.js";import"../../chunks/J5S4URAW.js";import"../../chunks/G74AGRAJ.js";import"../../chunks/SL2YLB2F.js";import"../../chunks/JPZFKSWT.js";import"../../chunks/RK3VP2Q4.js";import"../../chunks/74HKUGRR.js";import"../../chunks/QMMLQJBS.js";import"../../chunks/YIR5MYGU.js";import"../../chunks/L3N4FIEN.js";import"../../chunks/NAOUTU7A.js";import"../../chunks/UKXMCHHT.js";import"../../chunks/GQGNVSKB.js";import"../../chunks/DXFXAYDN.js";import"../../chunks/DRYAN665.js";import"../../chunks/2OSESBIL.js";import"../../chunks/YLNJXQ3Z.js";import"../../chunks/DDANMY45.js";import"../../chunks/37YOGDGY.js";import"../../chunks/KESCTXGO.js";import"../../chunks/TYTQRLTX.js";import"../../chunks/D7E6EWIE.js";export{a as subAgents};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Tool } from '../../loop/index.js';
|
|
3
|
+
import { type DelegationTarget } from '../delegations/index.js';
|
|
4
|
+
/** Parameters an agent accepts when another agent invokes it as a tool. */
|
|
5
|
+
export declare const SubAgentRequestParameters: z.ZodPreprocess<z.ZodObject<{
|
|
6
|
+
task: z.ZodString;
|
|
7
|
+
background: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
provider: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
9
|
+
model: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
10
|
+
thinking_effort: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
|
|
11
|
+
low: "low";
|
|
12
|
+
high: "high";
|
|
13
|
+
none: "none";
|
|
14
|
+
medium: "medium";
|
|
15
|
+
max: "max";
|
|
16
|
+
}>>>;
|
|
17
|
+
}, z.core.$strip>, unknown>;
|
|
18
|
+
/** How an endpoint describes its target to callers. */
|
|
19
|
+
export type EndpointDescription = {
|
|
20
|
+
readonly toolName: string;
|
|
21
|
+
readonly description: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Delegation, as a tool.
|
|
25
|
+
*
|
|
26
|
+
* One of these is registered per target, a global agent or a role endpoint, so a target is
|
|
27
|
+
* advertised to the model exactly like any other tool and reaching it is an ordinary grant. The
|
|
28
|
+
* child is a normal thread: created with this call as its `origin` and its task in the same
|
|
29
|
+
* write, and driven by `ctx.delegations` until the task settles. The tool only starts: its result
|
|
30
|
+
* names the child's `thread_id`, whether the child answered or failed, and `message_agent` is how a
|
|
31
|
+
* later call continues it.
|
|
32
|
+
*
|
|
33
|
+
* The child is born on the caller's route with the fields the call names folded over it, and keeps
|
|
34
|
+
* that route, so a child started on a cheap model stays on it when continued without naming one.
|
|
35
|
+
*/
|
|
36
|
+
export declare const subAgentTool: ({ toolName, description }: EndpointDescription, target: Exclude<DelegationTarget, {
|
|
37
|
+
kind: "fork";
|
|
38
|
+
}>) => Tool;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Plugin } from '@leuduan/cordis';
|
|
2
|
+
import { type Modes } from '../../kit/modes.js';
|
|
3
|
+
import { type AgentSelector } from '../../kit/scope.js';
|
|
4
|
+
/** What one mode lets through: `allow` lists the tools it lets be called, every other one denied. */
|
|
5
|
+
export type ModeRules = {
|
|
6
|
+
/** The only tools a call may name in this mode; without it, every tool. */
|
|
7
|
+
readonly allow?: readonly string[];
|
|
8
|
+
/** Why a call `allow` leaves out is denied, told to the model. */
|
|
9
|
+
readonly denial?: string;
|
|
10
|
+
/** `'all'` approves every call this mode lets through, satisfying a confirmation. */
|
|
11
|
+
readonly approve?: 'all';
|
|
12
|
+
};
|
|
13
|
+
/** What a mode notice is rendered against: what the model can still see, and what it was told last. */
|
|
14
|
+
export type ModeTold<Mode extends string> = {
|
|
15
|
+
readonly seen: Mode | null;
|
|
16
|
+
readonly last: Mode | null;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* What `toolPolicy` does with a set of durable modes: the rules each mode enforces and what the model
|
|
20
|
+
* is told on entering one. The state itself, and the host's way to set it, stay with the set.
|
|
21
|
+
*/
|
|
22
|
+
export type ModePolicy<Mode extends string = string> = {
|
|
23
|
+
/** Durable modes, from {@link defineModes}, whose rules apply in the mode a thread is in. */
|
|
24
|
+
readonly modes: Modes<Mode>;
|
|
25
|
+
/** What each of the set's modes lets through; a mode without rules is refused at mount. */
|
|
26
|
+
readonly rules: Readonly<Record<Mode, ModeRules>>;
|
|
27
|
+
/**
|
|
28
|
+
* What the model is told on entering `mode`, as a conversation message at the next model step; `null`
|
|
29
|
+
* to tell nothing. Asked only when the latest notice the model can still see says another mode.
|
|
30
|
+
*/
|
|
31
|
+
notice(mode: Mode, told: ModeTold<Mode>): string | null;
|
|
32
|
+
};
|
|
33
|
+
export type ToolPolicyConfig = {
|
|
34
|
+
/** Whose calls these rules govern, and which threads a mode notice tells; every agent without it. */
|
|
35
|
+
readonly agents?: AgentSelector;
|
|
36
|
+
/** Tools held for the user; a predicate for a source whose tools come and go, as MCP's do. */
|
|
37
|
+
readonly confirm?: readonly string[] | ((tool: string) => boolean);
|
|
38
|
+
/** Tools approved without asking, satisfying a confirmation; `'all'` approves every call. */
|
|
39
|
+
readonly approve?: readonly string[] | 'all';
|
|
40
|
+
/** Tools refused outright. */
|
|
41
|
+
readonly deny?: readonly string[];
|
|
42
|
+
} & (ModePolicy | {
|
|
43
|
+
readonly [Key in keyof ModePolicy]?: undefined;
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* What needs asking before a tool runs: the one policy plugin. Each rule votes on
|
|
47
|
+
* `lagent/tool/authorize` on its own, so the engine's table decides between them: a denial wins, an
|
|
48
|
+
* approval satisfies a confirmation and is recorded `confirmed_by: 'policy'`. Grants say who may
|
|
49
|
+
* call a tool at all; this says what a call that may be made needs.
|
|
50
|
+
*
|
|
51
|
+
* Mount it as many times as a host has rules. On the untagged application context it governs every
|
|
52
|
+
* thread, delegated ones included; in a thread's scope, that thread only.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* await root.plugin(toolPolicy, { confirm: ['run_command', 'edit_files'] })
|
|
56
|
+
* await root.plugin(toolPolicy, { approve: 'all' }) // auto-accept
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const toolPolicy: Plugin.Object<ToolPolicyConfig>;
|
|
60
|
+
/** The tools the shipped presets hold for confirmation: everything that writes or executes. */
|
|
61
|
+
export declare const SAFE_WRITES_TOOLS: readonly ["run_command", "start_command", "edit_files"];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b}from"../../chunks/BM3S37EZ.js";import"../../chunks/CDQG7RKA.js";import"../../chunks/DRYAN665.js";import"../../chunks/2OSESBIL.js";import"../../chunks/YLNJXQ3Z.js";import"../../chunks/DDANMY45.js";import"../../chunks/37YOGDGY.js";import"../../chunks/KESCTXGO.js";import"../../chunks/TYTQRLTX.js";import"../../chunks/D7E6EWIE.js";export{b as SAFE_WRITES_TOOLS,a as toolPolicy};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Stats } from 'node:fs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { InvocationContext } from '../../loop/index.js';
|
|
4
|
+
import type { ToolResultPayload } from '../../models/index.js';
|
|
5
|
+
import { type UnifiedDiff } from '../../util/diff.js';
|
|
6
|
+
/** The largest file `edit_files` reads, which bounds the memory one call takes. */
|
|
7
|
+
export declare const MAX_EDIT_FILE_BYTES: number;
|
|
8
|
+
declare const OperationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
9
|
+
op: z.ZodLiteral<"create">;
|
|
10
|
+
path: z.ZodString;
|
|
11
|
+
content: z.ZodString;
|
|
12
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
13
|
+
op: z.ZodLiteral<"update">;
|
|
14
|
+
path: z.ZodString;
|
|
15
|
+
hunks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
16
|
+
old_text: z.ZodString;
|
|
17
|
+
new_text: z.ZodString;
|
|
18
|
+
}, z.core.$strict>>>;
|
|
19
|
+
content: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
21
|
+
op: z.ZodLiteral<"delete">;
|
|
22
|
+
path: z.ZodString;
|
|
23
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
24
|
+
op: z.ZodLiteral<"move">;
|
|
25
|
+
path: z.ZodString;
|
|
26
|
+
to: z.ZodString;
|
|
27
|
+
hunks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
28
|
+
old_text: z.ZodString;
|
|
29
|
+
new_text: z.ZodString;
|
|
30
|
+
}, z.core.$strict>>>;
|
|
31
|
+
}, z.core.$strict>], "op">;
|
|
32
|
+
type Operation = z.infer<typeof OperationSchema>;
|
|
33
|
+
/**
|
|
34
|
+
* The one tool that changes files: creates, updates, deletes and moves, any number in one call.
|
|
35
|
+
*
|
|
36
|
+
* Everything is checked before anything is written: every path is placed inside the write roots
|
|
37
|
+
* and outside every git directory, every file read, every hunk located, and the operations checked
|
|
38
|
+
* against each other. Each file is then written to a temporary sibling and renamed over its target,
|
|
39
|
+
* or hard-linked into place when it must not replace anything, so no reader sees half of it; a
|
|
40
|
+
* filesystem without hard links gets no new file. There is no transaction across files: when one
|
|
41
|
+
* fails to commit, or the call is cancelled, the call stops there, before its next filesystem
|
|
42
|
+
* change, and its result says which files were committed and which were not.
|
|
43
|
+
*
|
|
44
|
+
* Calls are serialized per file across every thread of the process: each holds its files' locks
|
|
45
|
+
* from reading them to the last rename, and re-checks each file just before replacing it, so a
|
|
46
|
+
* change by anything else in between fails that file instead of being overwritten.
|
|
47
|
+
*/
|
|
48
|
+
export declare const editFilesTool: import("../../loop/tool.js").Tool;
|
|
49
|
+
/**
|
|
50
|
+
* The filesystem calls `edit_files` makes, so a test can fail or delay one. Every other caller
|
|
51
|
+
* passes {@link nodeEditFs}.
|
|
52
|
+
*/
|
|
53
|
+
export type EditFs = {
|
|
54
|
+
readFile(path: string): Promise<Buffer>;
|
|
55
|
+
/** Creates `path`, which must not exist. */
|
|
56
|
+
writeFile(path: string, data: Buffer, options: {
|
|
57
|
+
mode?: number;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
rename(from: string, to: string): Promise<void>;
|
|
60
|
+
link(existing: string, created: string): Promise<void>;
|
|
61
|
+
unlink(path: string): Promise<void>;
|
|
62
|
+
stat(path: string): Promise<Stats>;
|
|
63
|
+
lstat(path: string): Promise<Stats>;
|
|
64
|
+
mkdir(path: string): Promise<void>;
|
|
65
|
+
chmod(path: string, mode: number): Promise<void>;
|
|
66
|
+
};
|
|
67
|
+
export declare const nodeEditFs: EditFs;
|
|
68
|
+
/** A path an operation names: as named, as shown, and where it really is. */
|
|
69
|
+
type Target = {
|
|
70
|
+
readonly named: string;
|
|
71
|
+
/** Resolved against the cwd, symbolic links kept. */
|
|
72
|
+
readonly absolute: string;
|
|
73
|
+
/** As results show it. */
|
|
74
|
+
readonly display: string;
|
|
75
|
+
/** With its symbolic links resolved: what is read, written, compared and locked. */
|
|
76
|
+
readonly real: string;
|
|
77
|
+
};
|
|
78
|
+
/** What a file was when it was read, to tell whether it changed before it is replaced. */
|
|
79
|
+
type Snapshot = {
|
|
80
|
+
readonly size: number;
|
|
81
|
+
readonly mtimeMs: number;
|
|
82
|
+
readonly hash: string;
|
|
83
|
+
readonly mode: number;
|
|
84
|
+
};
|
|
85
|
+
type Planned = {
|
|
86
|
+
readonly kind: 'created';
|
|
87
|
+
readonly target: Target;
|
|
88
|
+
readonly bytes: Buffer;
|
|
89
|
+
readonly lines: number;
|
|
90
|
+
} | {
|
|
91
|
+
readonly kind: 'updated';
|
|
92
|
+
readonly target: Target;
|
|
93
|
+
readonly snapshot: Snapshot;
|
|
94
|
+
readonly bytes: Buffer;
|
|
95
|
+
readonly diff: UnifiedDiff;
|
|
96
|
+
/** The hunks that matched loosely, each as the result words it. */
|
|
97
|
+
readonly looseHunks: readonly string[];
|
|
98
|
+
} | {
|
|
99
|
+
readonly kind: 'deleted';
|
|
100
|
+
readonly target: Target;
|
|
101
|
+
readonly snapshot: Snapshot;
|
|
102
|
+
readonly lines: number | null;
|
|
103
|
+
} | {
|
|
104
|
+
readonly kind: 'moved';
|
|
105
|
+
readonly target: Target;
|
|
106
|
+
readonly to: Target;
|
|
107
|
+
readonly snapshot: Snapshot;
|
|
108
|
+
readonly bytes: Buffer;
|
|
109
|
+
readonly diff: UnifiedDiff | null;
|
|
110
|
+
readonly looseHunks: readonly string[];
|
|
111
|
+
};
|
|
112
|
+
/** One file's outcome, as `metadata.files` records it. */
|
|
113
|
+
export type EditedFile = {
|
|
114
|
+
readonly path: string;
|
|
115
|
+
readonly kind: Planned['kind'];
|
|
116
|
+
/** A move's destination. */
|
|
117
|
+
readonly to?: string;
|
|
118
|
+
readonly added: number;
|
|
119
|
+
readonly removed: number;
|
|
120
|
+
/** `destination_only`: a move whose destination was written and whose source could not be removed. */
|
|
121
|
+
readonly status: 'committed' | 'not_committed' | 'destination_only';
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Applies `operations` for a call: the whole of `edit_files` but its parameter parsing. See
|
|
125
|
+
* {@link editFilesTool}.
|
|
126
|
+
*/
|
|
127
|
+
export declare function applyFileOperations(operations: readonly Operation[], context: InvocationContext, fs: EditFs): Promise<ToolResultPayload>;
|
|
128
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The most lines one read returns. */
|
|
2
|
+
export declare const MAX_LINES_PER_READ = 2000;
|
|
3
|
+
/** The most bytes of a file's lines one read returns, line numbers aside. */
|
|
4
|
+
export declare const MAX_PAGE_BYTES: number;
|
|
5
|
+
/** A longer line is cut to this many characters, and the cut is stated. */
|
|
6
|
+
export declare const MAX_LINE_CHARS = 2000;
|
|
7
|
+
/**
|
|
8
|
+
* The largest image `read_file` answers with as an image: low, as the `mcp` plugin's default is,
|
|
9
|
+
* because an image stays in the conversation and every later request sends it again.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MAX_IMAGE_BYTES: number;
|
|
12
|
+
export declare const readFileTool: import("../../loop/tool.js").Tool;
|
|
13
|
+
/** The image type a file's first bytes declare, for the formats a model reads. */
|
|
14
|
+
export declare function imageMediaType(head: Buffer): string | null;
|
|
15
|
+
/** Directories that only ever hold build output, dependencies or version control. */
|
|
16
|
+
export declare const SKIPPED_DIRECTORIES: ReadonlySet<string>;
|
|
17
|
+
export declare const listDirTool: import("../../loop/tool.js").Tool;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML to readable plain text in one linear pass, with no DOM and no dependency.
|
|
3
|
+
*
|
|
4
|
+
* The text is the page's content region when it marks one — `<main>` or `role="main"`, else its
|
|
5
|
+
* only top-level `<article>` — and the whole document otherwise. What a reader would not read is
|
|
6
|
+
* dropped: scripts and styles, navigation, form controls, page banners, footers and sidebars outside
|
|
7
|
+
* the content, and hidden elements. Paragraphs, list items, table rows and preformatted text keep
|
|
8
|
+
* their shape.
|
|
9
|
+
*
|
|
10
|
+
* The parser is forgiving rather than spec-complete: a close tag pops back to its nearest open
|
|
11
|
+
* match, a few elements close an open sibling, and an element left open ends with its parent.
|
|
12
|
+
*/
|
|
13
|
+
export type HtmlLink = {
|
|
14
|
+
text: string;
|
|
15
|
+
href: string;
|
|
16
|
+
};
|
|
17
|
+
export type HtmlText = {
|
|
18
|
+
title: string | null;
|
|
19
|
+
text: string;
|
|
20
|
+
/** The links in `text`, in document order, with `href` as written. */
|
|
21
|
+
links: HtmlLink[];
|
|
22
|
+
};
|
|
23
|
+
export declare function htmlToText(html: string): HtmlText;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Plugin } from '@leuduan/cordis';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { Tool } from '../../loop/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* What the builtin tools are configured with, all of it the host's choice: the spawn environment and
|
|
6
|
+
* the trusted programs the search tools run (`rg`, with `rg: null` for none), what `web_fetch`
|
|
7
|
+
* may reach (`web.privateNetwork`: `refuse` keeps it on the public internet), and the Codex login
|
|
8
|
+
* `web_search` searches through (`web.search`; with `null` there is no `web_search`).
|
|
9
|
+
*/
|
|
10
|
+
declare const BuiltinToolsConfigSchema: z.ZodObject<{
|
|
11
|
+
environment: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
12
|
+
programs: z.ZodObject<{
|
|
13
|
+
git: z.ZodString;
|
|
14
|
+
rg: z.ZodNullable<z.ZodString>;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
web: z.ZodObject<{
|
|
17
|
+
privateNetwork: z.ZodEnum<{
|
|
18
|
+
allow: "allow";
|
|
19
|
+
refuse: "refuse";
|
|
20
|
+
}>;
|
|
21
|
+
search: z.ZodNullable<z.ZodObject<{
|
|
22
|
+
authPath: z.ZodString;
|
|
23
|
+
refreshTimeoutMs: z.ZodNumber;
|
|
24
|
+
model: z.ZodString;
|
|
25
|
+
maxOutputTokens: z.ZodNumber;
|
|
26
|
+
responseLength: z.ZodEnum<{
|
|
27
|
+
medium: "medium";
|
|
28
|
+
short: "short";
|
|
29
|
+
long: "long";
|
|
30
|
+
}>;
|
|
31
|
+
}, z.core.$strict>>;
|
|
32
|
+
}, z.core.$strict>;
|
|
33
|
+
}, z.core.$strict>;
|
|
34
|
+
export type BuiltinToolsConfig = z.input<typeof BuiltinToolsConfigSchema>;
|
|
35
|
+
export type { WebSearchConfig } from './web.js';
|
|
36
|
+
/** The builtin tools that read the workspace without changing it. */
|
|
37
|
+
export declare const READ_ONLY_TOOLS: readonly ["read_file", "list_dir", "rg_search", "rg_files"];
|
|
38
|
+
/** The builtin tools that run `rg`, provided only where the host has it (`programs.rg`). */
|
|
39
|
+
export declare const RG_TOOLS: readonly string[];
|
|
40
|
+
/** Builtin tools that fetch and search the web; `web_search` only where the host configures `web.search`. */
|
|
41
|
+
export declare const WEB_TOOLS: readonly ["web_fetch", "web_search"];
|
|
42
|
+
/**
|
|
43
|
+
* Every tool that ships with the engine. Registration is explicit: no import side effects.
|
|
44
|
+
*
|
|
45
|
+
* `ask_question` is deliberately absent — it needs a host that can reach the user, so it ships as
|
|
46
|
+
* the `lagent:ask` plugin instead of as a builtin that would fail wherever nobody is listening.
|
|
47
|
+
* Shell commands ship as the `commands` plugin, which owns their processes.
|
|
48
|
+
*
|
|
49
|
+
* The search tools, `rg_search` and `rg_files`, run the trusted `rg` and take configuration: the
|
|
50
|
+
* {@link BuiltinToolsConfig}. Without `rg` (`programs.rg: null`) neither is provided; nothing searches
|
|
51
|
+
* by another means. Likewise `web_search` searches only through the Codex login `web.search` names.
|
|
52
|
+
*/
|
|
53
|
+
export declare const builtinToolsFor: (config: z.output<typeof BuiltinToolsConfigSchema>) => readonly Tool[];
|
|
54
|
+
/**
|
|
55
|
+
* Registers every builtin tool for the life of the plugin. The host names the environment and the
|
|
56
|
+
* trusted programs the search tools run with, what `web_fetch` may reach and what `web_search`
|
|
57
|
+
* searches through; there is no default for any of them.
|
|
58
|
+
*/
|
|
59
|
+
export declare const builtinTools: Plugin.Object<BuiltinToolsConfig>;
|