@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,181 @@
|
|
|
1
|
+
import type { JournalEvent, Seq, ThreadSummary } from '../records/journal.js';
|
|
2
|
+
/**
|
|
3
|
+
* One group's write: a fresh identity, the head it was numbered from, the writer's acquisition, and
|
|
4
|
+
* the rows. Immutable once made, so a write whose answer was lost can be sent again as it was.
|
|
5
|
+
*/
|
|
6
|
+
export type Attempt = {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly baseHead: Seq;
|
|
9
|
+
readonly writer: string;
|
|
10
|
+
readonly rows: readonly JournalEvent[];
|
|
11
|
+
};
|
|
12
|
+
/** What an append did: wrote the rows, or found the same attempt already written and wrote nothing. */
|
|
13
|
+
export type AppendOutcome = 'appended' | 'duplicate';
|
|
14
|
+
/** One thread as the store indexes it, from its rows alone: where it began and how far it reaches. */
|
|
15
|
+
export type ThreadIndexEntry = {
|
|
16
|
+
readonly threadId: string;
|
|
17
|
+
readonly spawnSeq: Seq;
|
|
18
|
+
readonly lastSeq: Seq;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The right to append: exclusive while held, with an acquisition id the store checks inside every
|
|
22
|
+
* append, so rows from a writer that lost the lease are refused rather than detected afterwards.
|
|
23
|
+
*/
|
|
24
|
+
export type WriterLease = {
|
|
25
|
+
/** What the lease is held on, for messages. */
|
|
26
|
+
readonly identity: string;
|
|
27
|
+
readonly acquisitionId: string;
|
|
28
|
+
release(): Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Durable backing for the journal: the rows, one thread at a time, an index of the threads, the
|
|
32
|
+
* catalog of summaries beside them, and the record of who may write. Every method is asynchronous,
|
|
33
|
+
* so a store across a network implements the same contract as SQLite; the conformance suite
|
|
34
|
+
* (`stores/testing/conformance.ts`) is what every store passes.
|
|
35
|
+
*
|
|
36
|
+
* `append` must be durable enough that a crash after it resolves still replays the rows, because
|
|
37
|
+
* nothing else records them. That is also why `read` refuses a row it cannot parse rather than
|
|
38
|
+
* skipping it: the conversation is derived from these rows, so a dropped one rewrites history.
|
|
39
|
+
*
|
|
40
|
+
* The catalog is written after the rows, by the journal, from folds that hold only durable rows; it
|
|
41
|
+
* can trail the rows by one group after a crash, and the thread index — kept in the append's own
|
|
42
|
+
* transaction — is how the journal finds the summaries to refresh when it opens.
|
|
43
|
+
*/
|
|
44
|
+
export declare abstract class JournalStore {
|
|
45
|
+
private opened;
|
|
46
|
+
get isOpen(): boolean;
|
|
47
|
+
/** Initializes resources and loads persisted state; idempotent. */
|
|
48
|
+
open(): Promise<void>;
|
|
49
|
+
/** Releases resources; idempotent. */
|
|
50
|
+
close(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Takes the writer lease, refused with {@link JournalBusyError} while another holds it. May be
|
|
53
|
+
* called before `open()`: a store whose exclusivity comes from the operating system takes it before
|
|
54
|
+
* reading anything.
|
|
55
|
+
*/
|
|
56
|
+
abstract acquireWriter(): Promise<WriterLease>;
|
|
57
|
+
/** The highest `seq` the store holds; 0 when it holds nothing. */
|
|
58
|
+
head(): Promise<Seq>;
|
|
59
|
+
/**
|
|
60
|
+
* Writes an attempt's rows as one unit — all of them survive a crash or none do — and indexes
|
|
61
|
+
* their thread, in one transaction, checked against three things in that transaction:
|
|
62
|
+
*
|
|
63
|
+
* - an attempt with this id already written is `duplicate` when its content — head, writer and
|
|
64
|
+
* rows — is the same, and {@link AttemptMismatchError} when it is not, before anything else is
|
|
65
|
+
* checked, so a resend after the head or the writer moved on is still recognized; an attempt's
|
|
66
|
+
* identity is kept as long as its rows;
|
|
67
|
+
* - the writer record must name `attempt.writer`, else {@link WriterLostError};
|
|
68
|
+
* - the head must still be `attempt.baseHead`, else {@link JournalConflictError}.
|
|
69
|
+
*
|
|
70
|
+
* The rows are one thread's, in ascending seq order above `baseHead` — consecutive as the journal
|
|
71
|
+
* writes them; a gap is allowed so a test can store a journal thinned on purpose — and a thread the
|
|
72
|
+
* index does not hold must begin with its spawn row. A thread has exactly one spawn row; a
|
|
73
|
+
* second is refused without writing any part of the attempt.
|
|
74
|
+
*
|
|
75
|
+
* A store that cannot tell whether a commit landed — a remote one whose answer was lost, say —
|
|
76
|
+
* should say so with a typed ambiguous failure: the journal can then send the same attempt again,
|
|
77
|
+
* and a `duplicate` answer proves the rows are durable, though not that this process still holds
|
|
78
|
+
* the writer lease. Neither shipped store can lose an answer, so the journal has no such resend
|
|
79
|
+
* yet; it is built with the store that needs it.
|
|
80
|
+
*/
|
|
81
|
+
append(attempt: Attempt): Promise<AppendOutcome>;
|
|
82
|
+
/** One thread's own rows, in `seq` order. A fork's source is read whole; the journal bounds the lineage. */
|
|
83
|
+
read(threadId: string): Promise<JournalEvent[]>;
|
|
84
|
+
/** The row at `seq`, whichever thread it belongs to. */
|
|
85
|
+
rowAt(seq: Seq): Promise<JournalEvent | undefined>;
|
|
86
|
+
/** Every thread the store holds, in spawn order: one entry per thread, whatever the journal's length. */
|
|
87
|
+
threads(): Promise<ThreadIndexEntry[]>;
|
|
88
|
+
/** Every summary the catalog holds, in spawn order. */
|
|
89
|
+
summaries(): Promise<ThreadSummary[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Writes summaries, each replacing its thread's unless the stored one already describes more of
|
|
92
|
+
* the thread (a higher `through_seq`): a late write never undoes a newer one. Checked against the
|
|
93
|
+
* writer record as an append is, else {@link WriterLostError}.
|
|
94
|
+
*/
|
|
95
|
+
putSummaries(summaries: readonly ThreadSummary[], writer: string): Promise<void>;
|
|
96
|
+
/** Replaces the whole catalog in one transaction: a rebuild's write, checked against the writer record. */
|
|
97
|
+
replaceCatalog(summaries: readonly ThreadSummary[], writer: string): Promise<void>;
|
|
98
|
+
protected abstract doOpen(): Promise<void>;
|
|
99
|
+
protected abstract doClose(): Promise<void>;
|
|
100
|
+
protected abstract doHead(): Promise<Seq>;
|
|
101
|
+
/** Implements {@link append}'s checks and write in one transaction; `digest` identifies the content. */
|
|
102
|
+
protected abstract doAppend(attempt: Attempt, digest: string): Promise<AppendOutcome>;
|
|
103
|
+
protected abstract doRead(threadId: string): Promise<JournalEvent[]>;
|
|
104
|
+
protected abstract doRowAt(seq: Seq): Promise<JournalEvent | undefined>;
|
|
105
|
+
protected abstract doThreads(): Promise<ThreadIndexEntry[]>;
|
|
106
|
+
protected abstract doSummaries(): Promise<ThreadSummary[]>;
|
|
107
|
+
protected abstract doPutSummaries(summaries: readonly ThreadSummary[], writer: string): Promise<void>;
|
|
108
|
+
protected abstract doReplaceCatalog(summaries: readonly ThreadSummary[], writer: string): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* The event as it stands.
|
|
111
|
+
*
|
|
112
|
+
* Nothing is normalized and nothing is dropped for size: a row that reads back differently from
|
|
113
|
+
* the event in memory makes a live process and a resumed one disagree about their own history,
|
|
114
|
+
* and the fields most able to disagree are the ones this engine does not model — what a provider
|
|
115
|
+
* needs back verbatim and the arguments the model sent a tool, neither of which has a schema to
|
|
116
|
+
* restore what a tidy-up removed. `llm/request` records the prompt as a size and digest precisely
|
|
117
|
+
* so that no row ever has to be trimmed.
|
|
118
|
+
*/
|
|
119
|
+
protected serialize(event: JournalEvent): string;
|
|
120
|
+
protected serializeSummary(summary: ThreadSummary): string;
|
|
121
|
+
private requireOpen;
|
|
122
|
+
}
|
|
123
|
+
/** The content identity of a whole attempt — head, writer and rows: what tells a resent attempt from a different one with the same id. */
|
|
124
|
+
export declare function digestOf(attempt: Pick<Attempt, 'baseHead' | 'writer' | 'rows'>): string;
|
|
125
|
+
export declare class JournalBusyError extends Error {
|
|
126
|
+
readonly location: string;
|
|
127
|
+
constructor(location: string);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A write that waited its whole budget for another connection's write lock on the store, a shell or
|
|
131
|
+
* a backup say, and gave up. Nothing of it was written.
|
|
132
|
+
*/
|
|
133
|
+
export declare class StoreBusyError extends Error {
|
|
134
|
+
readonly location: string;
|
|
135
|
+
readonly waitedMs: number;
|
|
136
|
+
constructor(location: string, waitedMs: number);
|
|
137
|
+
}
|
|
138
|
+
/** An append numbered from a head the store has moved past: another writer, or a lost answer resent as new rows. */
|
|
139
|
+
export declare class JournalConflictError extends Error {
|
|
140
|
+
readonly expected: Seq;
|
|
141
|
+
readonly actual: Seq;
|
|
142
|
+
constructor(expected: Seq, actual: Seq);
|
|
143
|
+
}
|
|
144
|
+
/** An append by a writer the store's record no longer names: its lease was taken by another. */
|
|
145
|
+
export declare class WriterLostError extends Error {
|
|
146
|
+
readonly acquisitionId: string;
|
|
147
|
+
constructor(acquisitionId: string);
|
|
148
|
+
}
|
|
149
|
+
/** An attempt id already written with other rows: two different writes under one identity. */
|
|
150
|
+
export declare class AttemptMismatchError extends Error {
|
|
151
|
+
readonly attemptId: string;
|
|
152
|
+
constructor(attemptId: string);
|
|
153
|
+
}
|
|
154
|
+
/** A journal row that cannot be parsed by this build. */
|
|
155
|
+
export declare class CorruptJournalError extends Error {
|
|
156
|
+
readonly payload: string;
|
|
157
|
+
readonly cause: unknown;
|
|
158
|
+
constructor(payload: string, cause: unknown);
|
|
159
|
+
}
|
|
160
|
+
/** Parses one stored row; `shape` turns the parsed payload into the event's wire form when the store keeps it in parts. */
|
|
161
|
+
export declare function parseStoredEvent(payload: string, shape?: (stored: unknown) => unknown): JournalEvent;
|
|
162
|
+
export declare function parseStoredSummary(payload: string): ThreadSummary;
|
|
163
|
+
/**
|
|
164
|
+
* The journal format this build reads and writes. Bump it whenever the event alphabet or storage
|
|
165
|
+
* layout changes; a populated journal stamped with anything else is refused rather than partially read.
|
|
166
|
+
* A breaking change to persisted rows bumps it too, a plugin's extension row version bump included.
|
|
167
|
+
* Indexes enforcing existing invariants do not change the format.
|
|
168
|
+
*/
|
|
169
|
+
export declare const JOURNAL_VERSION = 44;
|
|
170
|
+
/** A journal written by a build whose format this one cannot read. */
|
|
171
|
+
export declare class IncompatibleJournalError extends Error {
|
|
172
|
+
readonly found: number;
|
|
173
|
+
readonly location: string;
|
|
174
|
+
constructor(found: number, location: string);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Judges a journal's version stamp on open. An empty journal is adopted whatever it says, and
|
|
178
|
+
* anything else holding rows is refused, because half a conversation is worse than none. A journal
|
|
179
|
+
* with no stamp at all reads as `0`.
|
|
180
|
+
*/
|
|
181
|
+
export declare function checkJournalVersion(stamped: number, hasRows: boolean, location: string): void;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { ConversationMessage, JsonObject, LLMStreamChunk, ModelResponse, ThinkingEffort } from './primitives.js';
|
|
2
|
+
import type { ModelRequest } from './request.js';
|
|
3
|
+
/** A model a provider offers to route selection, in the order the provider prefers them. */
|
|
4
|
+
export interface ModelOption {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
/** When to pick it, written for a model choosing a route: cost, speed, strengths. */
|
|
7
|
+
readonly description?: string;
|
|
8
|
+
/** The efforts it accepts, when declared. Absent means unspecified, not unrestricted. */
|
|
9
|
+
readonly thinkingEfforts?: readonly ThinkingEffort[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* What a provider can carry for one model, as `LLMProvider.capacity` declares it and `ctx.llm`
|
|
13
|
+
* answers it for a route. A declaration, like the told model list, never discovered from the
|
|
14
|
+
* provider at run time.
|
|
15
|
+
*/
|
|
16
|
+
export interface ModelCapacity {
|
|
17
|
+
/**
|
|
18
|
+
* The usable context window in tokens, or `null` when the provider declares none for the model.
|
|
19
|
+
* Shipped figures are the conservative ones a provider documents, so a consumer that trusts them
|
|
20
|
+
* errs early, never late.
|
|
21
|
+
*/
|
|
22
|
+
readonly contextWindow: number | null;
|
|
23
|
+
/** Whether a request may carry provider-executed tools (`ModelRequest.providerTools`). */
|
|
24
|
+
readonly providerTools: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether a tool result may carry an image part: the adapter sends one and the provider accepts
|
|
27
|
+
* it. A tool that can answer with an image or in words, as `read_file` can, asks this of the route
|
|
28
|
+
* its result goes to; a thread that later moves to a route without it still sends the image it
|
|
29
|
+
* already has, and that request fails.
|
|
30
|
+
*/
|
|
31
|
+
readonly toolResultImages: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A streamed model response: iterate for deltas, then `completed()` for what came back. A response
|
|
35
|
+
* is read once, by these rules, which an implementation enforces and a consumer may rely on.
|
|
36
|
+
* - It is iterated at most once. The read is claimed when the iterator is acquired, not at its first
|
|
37
|
+
* `next()`, and a second `[Symbol.asyncIterator]()` throws.
|
|
38
|
+
* - `completed()` on a response nobody has read drains it, publishing nothing, and settles.
|
|
39
|
+
* - Once the read has ended, whether it ran through, its reader stopped it early (`return`) or it
|
|
40
|
+
* failed, `completed()` returns or throws that read's outcome: a reader that left gets what
|
|
41
|
+
* arrived as a cut-off reply, a failed read throws its failure again. The outcome is fixed when the
|
|
42
|
+
* read ends: a cancel afterwards changes nothing.
|
|
43
|
+
* - A read ended by the caller's own cancellation (its request's abort, by the reason the signal
|
|
44
|
+
* carries) is a cut-off, never a failure: iteration ends without throwing, and `completed()`
|
|
45
|
+
* returns what arrived with finish `other`. A failure that only coincided with a cancel stays
|
|
46
|
+
* the failure. This is the read only: a request cancelled before a stream exists is refused,
|
|
47
|
+
* as `chat()` rejects with the caller's reason.
|
|
48
|
+
* - While a read is under way, from acquiring the iterator (before its first `next()` too) until it
|
|
49
|
+
* ends, `completed()` throws rather than settle a partial. A read ends only when its last
|
|
50
|
+
* operation, a `next` or a `return` or `throw` asked for and not yet settled, has finished; a
|
|
51
|
+
* `next()` after a `return()` or `throw()` ends without reading.
|
|
52
|
+
*/
|
|
53
|
+
export type StreamingLLMResponse = AsyncIterable<LLMStreamChunk> & {
|
|
54
|
+
completed(): Promise<ModelResponse>;
|
|
55
|
+
};
|
|
56
|
+
/** What a model provider's client implements; a provider is offered with `registerProvider(ctx, provider, { retry })`. */
|
|
57
|
+
export interface LLMClient {
|
|
58
|
+
readonly providerName: string;
|
|
59
|
+
chat(request: ModelRequest): Promise<StreamingLLMResponse>;
|
|
60
|
+
/** Optional owned transport cleanup; sessions never dispose an injected client override. */
|
|
61
|
+
dispose?(): void | Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
/** A provider was asked for something it cannot do. Thrown, never silently dropped. */
|
|
64
|
+
export declare class ProviderUnsupportedError extends Error {
|
|
65
|
+
readonly provider: string;
|
|
66
|
+
readonly feature: string;
|
|
67
|
+
constructor(provider: string, feature: string);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The provider refused or failed a request for exceeding the model's context window.
|
|
71
|
+
*
|
|
72
|
+
* Each provider classifies its own, from a rejected request and from a failure inside the stream,
|
|
73
|
+
* by the structured code where it has one and by its message's wording only where it has none. It
|
|
74
|
+
* carries no token count, by rule: providers state counts only in prose, if at all, and a number
|
|
75
|
+
* read from prose whose format may change is not a measurement. The provider's own error is the
|
|
76
|
+
* `cause`, so its text still reaches the journal. A failure the provider does not classify stays
|
|
77
|
+
* the error it was. A class of its own so the engine can tell this failure from every other one,
|
|
78
|
+
* as the one a shorter request can cure.
|
|
79
|
+
*/
|
|
80
|
+
export declare class ContextOverflowError extends Error {
|
|
81
|
+
readonly provider: string;
|
|
82
|
+
constructor(provider: string, options: {
|
|
83
|
+
cause: unknown;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Why a response could not be settled: `transport`, the stream ended without the provider's own
|
|
88
|
+
* evidence that the response was complete; `empty`, it completed with no text and no tool call;
|
|
89
|
+
* `length`, it had no text and no tool call because the output cap cut it (a reasoning-only reply,
|
|
90
|
+
* which a repeat would repeat); `other`, it had none for another reason the provider gave, such as a
|
|
91
|
+
* content filter; `invalid`, it settled but cannot be acted on, as when two of its calls share an id.
|
|
92
|
+
*/
|
|
93
|
+
export type ResponseSettlementKind = 'transport' | 'empty' | 'length' | 'other' | 'invalid';
|
|
94
|
+
/**
|
|
95
|
+
* A response that cannot be taken as an answer: one the provider never finished, or finished with
|
|
96
|
+
* nothing, which an adapter's `completed()` throws (never iteration); or one the loop cannot act on,
|
|
97
|
+
* `invalid`, which the loop throws itself for any client once `completed()` returned.
|
|
98
|
+
*
|
|
99
|
+
* Each adapter decides from its provider's terminal evidence, never from a reader that stopped
|
|
100
|
+
* early: a stream its reader abandoned, or whose request was aborted, still reports what it got,
|
|
101
|
+
* as a cut-off reply. `partial` is what arrived on a `transport` or `invalid` failure — its text and
|
|
102
|
+
* reasoning, never a tool call or `provider_state` — and `null` on an `empty` one. The message starts with the
|
|
103
|
+
* kind, so the journal's error text says which it was.
|
|
104
|
+
*/
|
|
105
|
+
export declare class ResponseSettlementError extends Error {
|
|
106
|
+
readonly provider: string;
|
|
107
|
+
readonly kind: ResponseSettlementKind;
|
|
108
|
+
readonly partial: ConversationMessage | null;
|
|
109
|
+
readonly providerMetadata: JsonObject;
|
|
110
|
+
constructor(provider: string, kind: ResponseSettlementKind, partial: ConversationMessage | null, providerMetadata: JsonObject, detail: string);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A response stream that went `idleMs` without a single event from the provider: the idle deadline
|
|
114
|
+
* of one attempt, which the engine classifies as `timeout`. It bounds the wait for the first event
|
|
115
|
+
* too, from the moment the request was sent.
|
|
116
|
+
*/
|
|
117
|
+
export declare class StreamIdleError extends Error {
|
|
118
|
+
readonly provider: string;
|
|
119
|
+
readonly idleMs: number;
|
|
120
|
+
constructor(provider: string, idleMs: number);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A stream that failed while it was being read, after it had produced output: what arrived (text and
|
|
124
|
+
* reasoning, never a tool call or `provider_state`), and the failure itself as `cause`, so a reset
|
|
125
|
+
* after visible text still leaves that text on record. A stream that failed before producing
|
|
126
|
+
* anything throws its failure unwrapped.
|
|
127
|
+
*/
|
|
128
|
+
export declare class ResponseInterruptedError extends Error {
|
|
129
|
+
readonly provider: string;
|
|
130
|
+
readonly partial: ConversationMessage;
|
|
131
|
+
readonly providerMetadata: JsonObject;
|
|
132
|
+
constructor(provider: string, partial: ConversationMessage, providerMetadata: JsonObject, options: {
|
|
133
|
+
cause: unknown;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { DeepReadonly } from '../util/json.js';
|
|
3
|
+
export declare const ContentPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
4
|
+
type: z.ZodLiteral<"text">;
|
|
5
|
+
text: z.ZodString;
|
|
6
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
7
|
+
type: z.ZodLiteral<"image">;
|
|
8
|
+
url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
9
|
+
data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
10
|
+
media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
11
|
+
detail: z.ZodDefault<z.ZodEnum<{
|
|
12
|
+
auto: "auto";
|
|
13
|
+
low: "low";
|
|
14
|
+
high: "high";
|
|
15
|
+
}>>;
|
|
16
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
17
|
+
type: z.ZodLiteral<"file">;
|
|
18
|
+
file_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
19
|
+
url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
20
|
+
data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
21
|
+
filename: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
22
|
+
media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
23
|
+
}, z.core.$strip>], "type">;
|
|
24
|
+
export type ContentPart = z.infer<typeof ContentPartSchema>;
|
|
25
|
+
/** A part as a caller writes one, with the fields the schema defaults left out. */
|
|
26
|
+
export type ContentPartInput = z.input<typeof ContentPartSchema>;
|
|
27
|
+
export type ContentPartKind = ContentPart['type'];
|
|
28
|
+
/** Accepts what a caller writes — a string, nothing, or parts — and yields parts. */
|
|
29
|
+
export declare const ContentSchema: z.ZodPreprocess<z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
30
|
+
type: z.ZodLiteral<"text">;
|
|
31
|
+
text: z.ZodString;
|
|
32
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
33
|
+
type: z.ZodLiteral<"image">;
|
|
34
|
+
url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
35
|
+
data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
36
|
+
media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
37
|
+
detail: z.ZodDefault<z.ZodEnum<{
|
|
38
|
+
auto: "auto";
|
|
39
|
+
low: "low";
|
|
40
|
+
high: "high";
|
|
41
|
+
}>>;
|
|
42
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
43
|
+
type: z.ZodLiteral<"file">;
|
|
44
|
+
file_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
45
|
+
url: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
data: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
47
|
+
filename: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
48
|
+
media_type: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
49
|
+
}, z.core.$strip>], "type">>>, unknown>;
|
|
50
|
+
export declare const textPart: (text: string) => ContentPart;
|
|
51
|
+
/** The text of a content list, parts joined. Non-text parts are not text and do not appear. */
|
|
52
|
+
export declare const contentText: (content: readonly DeepReadonly<ContentPart>[]) => string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One vocabulary for how a model call failed, and the one place a failure is given its kind.
|
|
3
|
+
*
|
|
4
|
+
* A kind decides whether `ctx.llm` retries a call and informs a host's rerun policy; it does not prove
|
|
5
|
+
* a rerun is safe. A cancellation is never a failure kind.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import type { StreamingLLMResponse } from './client.js';
|
|
9
|
+
import type { LLMProvider } from './provider.js';
|
|
10
|
+
import type { ModelRequest } from './request.js';
|
|
11
|
+
/**
|
|
12
|
+
* How a model call failed. `transport`, `empty`, `length` and `invalid` come from settlement and the
|
|
13
|
+
* loop; `overflow` from a `ContextOverflowError`; the rest from the provider's `classify`. Unknown is
|
|
14
|
+
* `other`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const FAILURE_KINDS: readonly ["rate_limit", "overloaded", "transport", "timeout", "empty", "length", "invalid", "auth", "quota", "overflow", "other"];
|
|
17
|
+
export type FailureKind = (typeof FAILURE_KINDS)[number];
|
|
18
|
+
export declare const FailureKindSchema: z.ZodEnum<{
|
|
19
|
+
length: "length";
|
|
20
|
+
other: "other";
|
|
21
|
+
transport: "transport";
|
|
22
|
+
empty: "empty";
|
|
23
|
+
invalid: "invalid";
|
|
24
|
+
rate_limit: "rate_limit";
|
|
25
|
+
overloaded: "overloaded";
|
|
26
|
+
timeout: "timeout";
|
|
27
|
+
auth: "auth";
|
|
28
|
+
quota: "quota";
|
|
29
|
+
overflow: "overflow";
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* What a provider's `classify` says of a failure it was handed: its kind, and how long the provider
|
|
33
|
+
* asked the caller to wait, read only from structured fields (a header), never from prose.
|
|
34
|
+
*/
|
|
35
|
+
export type FailureClassification = {
|
|
36
|
+
kind: FailureKind;
|
|
37
|
+
retryAfterMs?: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* A failed model call, as `ctx.llm`'s clients throw it: the provider, the kind, how many times the
|
|
41
|
+
* client was called for it, the wait the provider asked for, and the adapter's own error as `cause`.
|
|
42
|
+
* Its kind is the one authority inside the engine; the typed adapter errors are evidence for it. Its
|
|
43
|
+
* message is the cause's, so the journal's error text stays the provider's prose; the kind is a field.
|
|
44
|
+
*/
|
|
45
|
+
export declare class ModelCallError extends Error {
|
|
46
|
+
readonly provider: string;
|
|
47
|
+
readonly kind: FailureKind;
|
|
48
|
+
readonly attempts: number;
|
|
49
|
+
readonly retryAfterMs: number | null;
|
|
50
|
+
constructor(provider: string, kind: FailureKind, attempts: number, retryAfterMs: number | null, options: {
|
|
51
|
+
cause: unknown;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* One model call through `ctx.llm`, handed back before it opens: its response, and how many times
|
|
56
|
+
* the provider's client has been called for it so far, whatever becomes of it, a refusal or a
|
|
57
|
+
* cancellation included.
|
|
58
|
+
*/
|
|
59
|
+
export interface ModelCallHandle {
|
|
60
|
+
readonly response: Promise<StreamingLLMResponse>;
|
|
61
|
+
readonly attempts: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A client from `ctx.llm`: it retries a failed call by its provider's policy and throws
|
|
65
|
+
* `ModelCallError` for one that still fails.
|
|
66
|
+
*/
|
|
67
|
+
export interface ModelCallClient {
|
|
68
|
+
readonly providerName: string;
|
|
69
|
+
/** Starts one call; the handle is the caller's to keep for its attempt count. */
|
|
70
|
+
call(request: ModelRequest): ModelCallHandle;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The kind of a failure from `provider`'s client, from typed evidence first: a settlement failure
|
|
74
|
+
* keeps its kind, a `ContextOverflowError` is `overflow`, a `StreamIdleError` is `timeout`. Only what neither says reaches the
|
|
75
|
+
* provider's `classify` (a stream interrupted after output is classified by its cause), so a provider
|
|
76
|
+
* written from scratch cannot get overflow or settlement wrong. What `classify` returns is checked
|
|
77
|
+
* before the journal sees it: a kind outside {@link FAILURE_KINDS}, or a `classify` that throws, is
|
|
78
|
+
* `other`, and a wait that is not a finite, nonnegative number is no wait (a fraction rounds up).
|
|
79
|
+
*/
|
|
80
|
+
export declare function classifyFailure(provider: LLMProvider, error: unknown): FailureClassification;
|
|
81
|
+
/** The first `type` in `error`'s `cause` chain, itself included; middleware may wrap what was thrown. */
|
|
82
|
+
export declare function findCause<T extends Error>(error: unknown, type: abstract new (...args: never[]) => T): T | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@leuduan/lagent/llm`: the model and provider contracts as the package offers them, for a provider
|
|
3
|
+
* written outside it and a host that calls a model. Every type the contract mentions, and the values
|
|
4
|
+
* a consumer uses; the schemas and helpers the engine uses itself stay in their modules, which the
|
|
5
|
+
* package imports directly.
|
|
6
|
+
*
|
|
7
|
+
* It depends on `zod` alone, so a provider client built on it works in any harness.
|
|
8
|
+
*/
|
|
9
|
+
export { ContextOverflowError, ProviderUnsupportedError, ResponseInterruptedError, ResponseSettlementError, StreamIdleError, } from './client.js';
|
|
10
|
+
export type { LLMClient, ModelCapacity, ModelOption, ResponseSettlementKind, StreamingLLMResponse } from './client.js';
|
|
11
|
+
export { contentText } from './content.js';
|
|
12
|
+
export { ModelCallError } from './failure.js';
|
|
13
|
+
export type { FailureClassification, FailureKind, ModelCallClient, ModelCallHandle } from './failure.js';
|
|
14
|
+
export type { DeepReadonly, ReadonlyJsonValue } from '../util/json.js';
|
|
15
|
+
export type { ContentPart, ContentPartInput, ContentPartKind } from './content.js';
|
|
16
|
+
export { conversationMessage, LLMStreamChunkSchema, messageText, ThinkingEffortSchema } from './primitives.js';
|
|
17
|
+
export type { ConversationMessage, JsonObject, LLMStreamChunk, LLMUsage, MalformedToolCall, MessageRole, ModelResponse, ParsedToolCall, ProviderCall, ProviderState, ResponseFinish, ThinkingEffort, ToolCall, ToolSpec, } from './primitives.js';
|
|
18
|
+
export { renderPromptBlocks } from './prompt.js';
|
|
19
|
+
export type { PromptBlock } from './prompt.js';
|
|
20
|
+
export { defaultRoute } from './provider.js';
|
|
21
|
+
export type { LLMProvider, ModelRoute } from './provider.js';
|
|
22
|
+
export type { ModelRequest, RequestPurpose, ResponseFormat, ToolChoice } from './request.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as m,e as l}from"../chunks/G44LG6VL.js";import{A as d,d as r,f as e,o,q as t,r as n,u as p,v as s,w as f,x as a,y as x}from"../chunks/D4PQP5MA.js";export{s as ContextOverflowError,o as LLMStreamChunkSchema,l as ModelCallError,p as ProviderUnsupportedError,x as ResponseInterruptedError,f as ResponseSettlementError,a as StreamIdleError,e as ThinkingEffortSchema,r as contentText,t as conversationMessage,m as defaultRoute,n as messageText,d as renderPromptBlocks};
|