@full-self-browsing/lattice 1.3.0 → 1.5.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/dist/agent-run-C6miAzwI.d.ts +45 -0
- package/dist/agent-run-C6miAzwI.d.ts.map +1 -0
- package/dist/agent-run-CgPVFl0Z.js +47 -0
- package/dist/agent-run-CgPVFl0Z.js.map +1 -0
- package/dist/agents.d.ts +5 -0
- package/dist/agents.js +6 -0
- package/dist/artifact-Bg6mJGnm.d.ts +125 -0
- package/dist/artifact-Bg6mJGnm.d.ts.map +1 -0
- package/dist/artifact-DOfpeXLb.js +140 -0
- package/dist/artifact-DOfpeXLb.js.map +1 -0
- package/dist/artifacts.d.ts +2 -0
- package/dist/artifacts.js +2 -0
- package/dist/audit.d.ts +3 -0
- package/dist/audit.js +4 -0
- package/dist/catalog-CAfYwB_-.js +91 -0
- package/dist/catalog-CAfYwB_-.js.map +1 -0
- package/dist/context-pack-Bz3GXmjv.js +99 -0
- package/dist/context-pack-Bz3GXmjv.js.map +1 -0
- package/dist/context.d.ts +2 -0
- package/dist/context.js +2 -0
- package/dist/contract-S3oJGlc9.d.ts +74 -0
- package/dist/contract-S3oJGlc9.d.ts.map +1 -0
- package/dist/core.d.ts +48 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +95 -0
- package/dist/core.js.map +1 -0
- package/dist/errors-eEuEIx6X.js +407 -0
- package/dist/errors-eEuEIx6X.js.map +1 -0
- package/dist/eval.d.ts +2 -0
- package/dist/eval.js +2 -0
- package/dist/fingerprint-DodDbQKN.js +34 -0
- package/dist/fingerprint-DodDbQKN.js.map +1 -0
- package/dist/index-DpnHGHVL.d.ts +53 -0
- package/dist/index-DpnHGHVL.d.ts.map +1 -0
- package/dist/index.d.ts +78 -3234
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +365 -8434
- package/dist/index.js.map +1 -1
- package/dist/infer-DLqp5QIM.d.ts +96 -0
- package/dist/infer-DLqp5QIM.d.ts.map +1 -0
- package/dist/lineage-DBgoPWAZ.js +137 -0
- package/dist/lineage-DBgoPWAZ.js.map +1 -0
- package/dist/local-CXOGPJ1f.js +139 -0
- package/dist/local-CXOGPJ1f.js.map +1 -0
- package/dist/local-Dy--7peL.d.ts +10 -0
- package/dist/local-Dy--7peL.d.ts.map +1 -0
- package/dist/memory-CkQEW6m5.js +62 -0
- package/dist/memory-CkQEW6m5.js.map +1 -0
- package/dist/memory-DRig5EHV.d.ts +10 -0
- package/dist/memory-DRig5EHV.d.ts.map +1 -0
- package/dist/negotiate-ClD88hkc.js +10967 -0
- package/dist/negotiate-ClD88hkc.js.map +1 -0
- package/dist/otel-BgM4e55_.d.ts +421 -0
- package/dist/otel-BgM4e55_.d.ts.map +1 -0
- package/dist/permission-context-CUKMo79F.js +134 -0
- package/dist/permission-context-CUKMo79F.js.map +1 -0
- package/dist/plan-DFm8Llep.js +125 -0
- package/dist/plan-DFm8Llep.js.map +1 -0
- package/dist/preflight-DNHWuJ46.d.ts +64 -0
- package/dist/preflight-DNHWuJ46.d.ts.map +1 -0
- package/dist/provider-C2IfKsvz.d.ts +1178 -0
- package/dist/provider-C2IfKsvz.d.ts.map +1 -0
- package/dist/providers.d.ts +4 -0
- package/dist/providers.js +4 -0
- package/dist/rate-limit-group-nDsBJqSu.d.ts +235 -0
- package/dist/rate-limit-group-nDsBJqSu.d.ts.map +1 -0
- package/dist/receipt-FYouoPHv.js +205 -0
- package/dist/receipt-FYouoPHv.js.map +1 -0
- package/dist/replay-CtIhpLek.js +964 -0
- package/dist/replay-CtIhpLek.js.map +1 -0
- package/dist/result-DLEx2WvU.d.ts +38 -0
- package/dist/result-DLEx2WvU.d.ts.map +1 -0
- package/dist/router-DU4Z3pTd.js +314 -0
- package/dist/router-DU4Z3pTd.js.map +1 -0
- package/dist/router-Yo1-aDOv.d.ts +42 -0
- package/dist/router-Yo1-aDOv.d.ts.map +1 -0
- package/dist/routing.d.ts +6 -0
- package/dist/routing.js +4 -0
- package/dist/{run-crew-DDznbc3G.js → run-crew-B2fQLmgB.js} +16 -23
- package/dist/run-crew-B2fQLmgB.js.map +1 -0
- package/dist/run-crew-Bnve5dyI.d.ts +721 -0
- package/dist/run-crew-Bnve5dyI.d.ts.map +1 -0
- package/dist/{runtime-BTi8lr_O.js → runtime-Dxiet5YS.js} +100 -640
- package/dist/runtime-Dxiet5YS.js.map +1 -0
- package/dist/scaffolds-DKQrCRqh.d.ts +535 -0
- package/dist/scaffolds-DKQrCRqh.d.ts.map +1 -0
- package/dist/scaffolds-ekPIlBeU.js +3139 -0
- package/dist/scaffolds-ekPIlBeU.js.map +1 -0
- package/dist/schema-CNfa_VEy.d.ts +15 -0
- package/dist/schema-CNfa_VEy.d.ts.map +1 -0
- package/dist/storage-DJKmsaEI.d.ts +26 -0
- package/dist/storage-DJKmsaEI.d.ts.map +1 -0
- package/dist/storage.d.ts +10 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +4 -0
- package/dist/tool-call-validation-BFoXkwbf.js +107 -0
- package/dist/tool-call-validation-BFoXkwbf.js.map +1 -0
- package/dist/tools-C4wHgGKQ.js +49 -0
- package/dist/tools-C4wHgGKQ.js.map +1 -0
- package/dist/tools.d.ts +46 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +106 -0
- package/dist/tools.js.map +1 -0
- package/dist/validate-c7EL5uuH.js +224 -0
- package/dist/validate-c7EL5uuH.js.map +1 -0
- package/package.json +105 -6
- package/dist/run-crew-DDznbc3G.js.map +0 -1
- package/dist/runtime-BTi8lr_O.js.map +0 -1
|
@@ -0,0 +1,721 @@
|
|
|
1
|
+
import { Jt as SessionStore, T as Usage, bn as RunEventSink, ct as ToolDefinition, d as ProviderRunRequest, f as ProviderRunResponse, gt as LatticeRunError, l as ProviderRef, mn as OutputContractMap, mt as ToolUseRequest, r as ProviderAdapter, u as ProviderRegistryInput, xn as TracerLike } from "./provider-C2IfKsvz.js";
|
|
2
|
+
import { s as ArtifactRef, x as PolicySpec } from "./artifact-Bg6mJGnm.js";
|
|
3
|
+
import { c as ReceiptEnvelope, n as InferOutputMap, p as ReceiptSigner } from "./infer-DLqp5QIM.js";
|
|
4
|
+
import { n as StorageLike } from "./storage-DJKmsaEI.js";
|
|
5
|
+
import { n as standardSchemaToJsonSchema } from "./schema-CNfa_VEy.js";
|
|
6
|
+
import { n as CapabilityContract, t as BudgetInvariant } from "./contract-S3oJGlc9.js";
|
|
7
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
8
|
+
|
|
9
|
+
//#region src/contract/bands.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Hook lifecycle event vocabulary -- separate from RunEventKind by design.
|
|
12
|
+
*
|
|
13
|
+
* Phase 19 (v1.2) additively extends with BEFORE_AGENT_ITERATION and
|
|
14
|
+
* AFTER_AGENT_ITERATION — emitted by `runAgent` around each iteration's
|
|
15
|
+
* provider call. Existing four events continue to fire inside each
|
|
16
|
+
* iteration (BEFORE/AFTER_PROVIDER per native call; BEFORE/AFTER_TOOL
|
|
17
|
+
* per dispatched tool).
|
|
18
|
+
*/
|
|
19
|
+
type HookLifecycleEvent = "BEFORE_PROVIDER" | "AFTER_PROVIDER" | "BEFORE_TOOL" | "AFTER_TOOL" | "BEFORE_AGENT_ITERATION" | "AFTER_AGENT_ITERATION";
|
|
20
|
+
/**
|
|
21
|
+
* SAFETY-band veto mechanism — Phase 19.
|
|
22
|
+
*
|
|
23
|
+
* Handlers can deny an iteration by calling `controls.deny(reason)`. The
|
|
24
|
+
* pipeline records the latest reason and exposes it via `lastDenialReason()`.
|
|
25
|
+
* The reason resets at the start of each `run()` call.
|
|
26
|
+
*
|
|
27
|
+
* Composition convention: the agent runtime invokes BEFORE_AGENT_ITERATION
|
|
28
|
+
* before provider call, then checks `pipeline.lastDenialReason()`. If set,
|
|
29
|
+
* the iteration aborts with `agent-iteration-denied` failure.
|
|
30
|
+
*/
|
|
31
|
+
interface HookDenyDirective {
|
|
32
|
+
readonly reason: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Controls passed to each handler as an optional second argument.
|
|
36
|
+
*
|
|
37
|
+
* Backward compat: existing single-argument handlers (Phase 15 + Phase 16)
|
|
38
|
+
* ignore this and continue to work unchanged.
|
|
39
|
+
*/
|
|
40
|
+
interface HookControls {
|
|
41
|
+
/** Set a denial reason; the latest call wins per `run()`. */
|
|
42
|
+
readonly deny: (reason: string) => void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Priority bands. Lower number = higher priority (runs first).
|
|
46
|
+
*
|
|
47
|
+
* SAFETY (0) -- safety / breaker hooks; cannot be overridden by lower bands
|
|
48
|
+
* OBSERVABILITY (1) -- logging, metrics, audit; runs after safety, before extension
|
|
49
|
+
* EXTENSION (2) -- user-supplied hooks; runs last
|
|
50
|
+
*
|
|
51
|
+
* Within a band, handlers run in registration order.
|
|
52
|
+
*/
|
|
53
|
+
declare const BAND: {
|
|
54
|
+
readonly SAFETY: 0;
|
|
55
|
+
readonly OBSERVABILITY: 1;
|
|
56
|
+
readonly EXTENSION: 2;
|
|
57
|
+
};
|
|
58
|
+
type Band = typeof BAND[keyof typeof BAND];
|
|
59
|
+
/**
|
|
60
|
+
* Handler input -- frozen snapshot of the caller's context at run() time.
|
|
61
|
+
*
|
|
62
|
+
* structuredClone-then-Object.freeze: handlers receive a deep-cloned,
|
|
63
|
+
* surface-frozen view. Mutations on the handler side do NOT leak back to
|
|
64
|
+
* the calling site.
|
|
65
|
+
*
|
|
66
|
+
* The handler's return value is currently ignored; future revisions may
|
|
67
|
+
* add a typed return that downstream bands consume.
|
|
68
|
+
*/
|
|
69
|
+
interface HookHandler<TContext = unknown> {
|
|
70
|
+
(context: Readonly<TContext>, controls?: HookControls): void | Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
interface RegisterOptions {
|
|
73
|
+
readonly band: Band;
|
|
74
|
+
readonly matcher?: RegExp;
|
|
75
|
+
readonly budgetMs?: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The HookPipeline interface returned by createHookPipeline().
|
|
79
|
+
*
|
|
80
|
+
* IMMUTABILITY: once freeze() is called, register() throws an Error whose
|
|
81
|
+
* .name === "PIPELINE_FROZEN". freeze() is irreversible by design --
|
|
82
|
+
* protects against late-binding hook injection mid-session.
|
|
83
|
+
*/
|
|
84
|
+
interface HookPipeline {
|
|
85
|
+
readonly kind: "hook-pipeline";
|
|
86
|
+
register<TContext = unknown>(event: HookLifecycleEvent, handler: HookHandler<TContext>, options: RegisterOptions): void;
|
|
87
|
+
freeze(): void;
|
|
88
|
+
isFrozen(): boolean;
|
|
89
|
+
run<TContext = unknown>(event: HookLifecycleEvent, context: TContext): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Phase 19: returns the latest denial reason set by any handler during
|
|
92
|
+
* the most recent `run()` call. Resets to `null` at the start of each run.
|
|
93
|
+
* Read by the agent runtime to detect SAFETY-band veto.
|
|
94
|
+
*/
|
|
95
|
+
lastDenialReason(): string | null;
|
|
96
|
+
}
|
|
97
|
+
interface CreateHookPipelineOptions {
|
|
98
|
+
readonly tracer?: TracerLike;
|
|
99
|
+
readonly sessionId?: string;
|
|
100
|
+
readonly defaultBudgetMs?: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Factory: build a fresh hook pipeline.
|
|
104
|
+
*/
|
|
105
|
+
declare function createHookPipeline(options?: CreateHookPipelineOptions): HookPipeline;
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/runtime/config.d.ts
|
|
108
|
+
interface LatticeConfig {
|
|
109
|
+
readonly providers?: ProviderRegistryInput;
|
|
110
|
+
readonly storage?: StorageLike | false;
|
|
111
|
+
readonly sessions?: SessionStore | false;
|
|
112
|
+
readonly defaults?: {
|
|
113
|
+
readonly policy?: PolicySpec;
|
|
114
|
+
};
|
|
115
|
+
readonly tracing?: TracerLike | false;
|
|
116
|
+
readonly events?: RunEventSink | readonly RunEventSink[];
|
|
117
|
+
/**
|
|
118
|
+
* Phase 9 — when configured, every terminal branch of `ai.run` emits a
|
|
119
|
+
* signed `CapabilityReceipt` attached to `RunResult.receipt`. When absent,
|
|
120
|
+
* no receipts are issued and `RunResult.receipt` is undefined.
|
|
121
|
+
*/
|
|
122
|
+
readonly signer?: ReceiptSigner;
|
|
123
|
+
}
|
|
124
|
+
type NormalizedProviderEntry = ProviderRef | ProviderAdapter;
|
|
125
|
+
interface NormalizedLatticeConfig {
|
|
126
|
+
readonly providers: readonly NormalizedProviderEntry[];
|
|
127
|
+
readonly storage?: StorageLike;
|
|
128
|
+
readonly sessions?: SessionStore;
|
|
129
|
+
readonly defaults: {
|
|
130
|
+
readonly policy?: PolicySpec;
|
|
131
|
+
};
|
|
132
|
+
readonly tracing?: TracerLike;
|
|
133
|
+
readonly events: readonly RunEventSink[];
|
|
134
|
+
readonly signer?: ReceiptSigner;
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/agent/format-tools.d.ts
|
|
138
|
+
/**
|
|
139
|
+
* One turn in the running conversation.
|
|
140
|
+
*
|
|
141
|
+
* `role: "tool"` is used for tool-result turns; `toolCallId` and `toolName`
|
|
142
|
+
* are populated so the model can correlate the result with its prior
|
|
143
|
+
* `tool_call` envelope.
|
|
144
|
+
*/
|
|
145
|
+
interface ConversationTurn {
|
|
146
|
+
readonly role: "user" | "assistant" | "tool";
|
|
147
|
+
readonly content: string;
|
|
148
|
+
readonly toolCallId?: string;
|
|
149
|
+
readonly toolName?: string;
|
|
150
|
+
}
|
|
151
|
+
type FormatToolsMode = "native" | "prompt-reencoded" | "auto";
|
|
152
|
+
interface FormatToolsOptions {
|
|
153
|
+
/**
|
|
154
|
+
* Tool-use protocol mode. Defaults to `"auto"`, which currently resolves
|
|
155
|
+
* to `"prompt-reencoded"` for ALL 7 providers (Phase 19 simplification —
|
|
156
|
+
* native tool_use deferred to a follow-on milestone). Reserved for
|
|
157
|
+
* forward compatibility.
|
|
158
|
+
*/
|
|
159
|
+
readonly mode?: FormatToolsMode;
|
|
160
|
+
/**
|
|
161
|
+
* Optional system prompt to prepend. Useful for setting persona /
|
|
162
|
+
* domain-specific instructions on top of the tool-use envelope.
|
|
163
|
+
*/
|
|
164
|
+
readonly system?: string;
|
|
165
|
+
}
|
|
166
|
+
interface FormattedToolsHandle {
|
|
167
|
+
/**
|
|
168
|
+
* Builds the single `task` string passed to `ProviderAdapter.execute()`.
|
|
169
|
+
* Encodes the conversation, available tools, and response-envelope
|
|
170
|
+
* instructions.
|
|
171
|
+
*/
|
|
172
|
+
readonly buildTask: (conversation: readonly ConversationTurn[]) => string;
|
|
173
|
+
/**
|
|
174
|
+
* Phase 39 (v1.3): body-only sibling of `buildTask` — identical turn
|
|
175
|
+
* rendering minus the leading system block, so the byte-stable
|
|
176
|
+
* `describeForSystem()` prefix can be hoisted once per crew for
|
|
177
|
+
* prompt-cache sharing without duplication (39-05).
|
|
178
|
+
*
|
|
179
|
+
* Invariant: `describeForSystem() + "\n" + buildTaskBody(conversation)`
|
|
180
|
+
* reconstructs `buildTask(conversation)` byte-for-byte.
|
|
181
|
+
*/
|
|
182
|
+
readonly buildTaskBody: (conversation: readonly ConversationTurn[]) => string;
|
|
183
|
+
/**
|
|
184
|
+
* Parses the assistant's response text. Returns:
|
|
185
|
+
* - `ToolUseRequest[]` when the response contains one or more tool-call
|
|
186
|
+
* envelopes (parsed in declaration order).
|
|
187
|
+
* - `null` when the response is a final answer (no tool-call envelopes
|
|
188
|
+
* detected).
|
|
189
|
+
*
|
|
190
|
+
* The parser is forgiving: it tolerates extra prose around the JSON
|
|
191
|
+
* envelope (markdown fences, leading explanations) and the model
|
|
192
|
+
* occasionally drifting on whitespace.
|
|
193
|
+
*/
|
|
194
|
+
readonly parseToolUse: (responseText: string) => ReadonlyArray<ToolUseRequest> | null;
|
|
195
|
+
/**
|
|
196
|
+
* Returns the static system block describing available tools. Useful for
|
|
197
|
+
* tracing / logging the exact tool-description text fed to the model.
|
|
198
|
+
*/
|
|
199
|
+
readonly describeForSystem: () => string;
|
|
200
|
+
/**
|
|
201
|
+
* Effective mode this handle resolved to (`"prompt-reencoded"` for all
|
|
202
|
+
* v1.2 providers). Exposed for inspectability.
|
|
203
|
+
*/
|
|
204
|
+
readonly mode: "prompt-reencoded";
|
|
205
|
+
}
|
|
206
|
+
declare const toolSchemaToJsonSchema: typeof standardSchemaToJsonSchema;
|
|
207
|
+
/**
|
|
208
|
+
* Builds the prompt-reencoded tool-use protocol handle for any provider.
|
|
209
|
+
*
|
|
210
|
+
* Phase 19 ships a uniform implementation across all 7 logical providers
|
|
211
|
+
* (openai, openai-compat, anthropic, gemini, xai, openrouter, lm-studio).
|
|
212
|
+
* The `providerName` argument is accepted for forward compatibility but
|
|
213
|
+
* does not branch the implementation in v1.2.
|
|
214
|
+
*/
|
|
215
|
+
declare function formatToolsForProvider(providerName: string, tools: ReadonlyArray<ToolDefinition>, options?: FormatToolsOptions): FormattedToolsHandle;
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/runtime/survivability.d.ts
|
|
218
|
+
/**
|
|
219
|
+
* MV3-survivability adapter contract -- Phase 5 (FSB v0.10.0-attempt-2).
|
|
220
|
+
*
|
|
221
|
+
* This module is a SIBLING of create-ai.ts (the Lattice runtime facade) and
|
|
222
|
+
* a SIBLING of contract/bands.ts (the hook pipeline factory) and
|
|
223
|
+
* contract/checkpoint.ts (the per-step receipt hook). It does NOT modify
|
|
224
|
+
* any of them; the SurvivabilityAdapter contract is composed from those
|
|
225
|
+
* surfaces by the consumer (FSB's lattice-runtime-adapter.js in Plan 05-05).
|
|
226
|
+
*
|
|
227
|
+
* What is the survivability problem?
|
|
228
|
+
* Some host runtimes can evict the execution context mid-flow with no
|
|
229
|
+
* synchronous shutdown signal:
|
|
230
|
+
* - Chrome MV3 service workers: evicted after 30s silence OR 5min idle.
|
|
231
|
+
* - Cloudflare Workers: evicted at end of each request unless waitUntil.
|
|
232
|
+
* - AWS Lambda: process freeze + thaw across invocations.
|
|
233
|
+
* Lattice's existing runtime (create-ai.ts) assumes the process stays
|
|
234
|
+
* live for the duration of a run. The SurvivabilityAdapter contract is
|
|
235
|
+
* the seam where a host runtime tells Lattice "here is how to serialize
|
|
236
|
+
* my state, here is how to deserialize it back, here is how to resume
|
|
237
|
+
* work after I get evicted and recreated."
|
|
238
|
+
*
|
|
239
|
+
* What this module SHIPS:
|
|
240
|
+
* - SurvivabilityAdapter<TState> interface (4 methods)
|
|
241
|
+
* - SerializedSnapshot type (string-encodable opaque envelope)
|
|
242
|
+
* - EvictionHook<TState> type (pre-eviction callback signature)
|
|
243
|
+
* - ResumePolicy literal-union (post-restore reconstruction verdict)
|
|
244
|
+
* - UnsubscribeFn type
|
|
245
|
+
* - createNoopSurvivabilityAdapter() reference implementation
|
|
246
|
+
*
|
|
247
|
+
* What this module DOES NOT ship:
|
|
248
|
+
* - chrome.storage.session integration (FSB-side; Plan 05-05).
|
|
249
|
+
* - offscreen-document message bus (FSB-side; Plan 05-04).
|
|
250
|
+
* - Auto-wiring into create-ai.ts runtime (deferred indefinitely; the
|
|
251
|
+
* contract is consumer-controlled).
|
|
252
|
+
* - Mid-API-request / mid-tool-dispatch recovery dispatcher (CONSERVATIVE
|
|
253
|
+
* recovery wiring is deferred to a follow-on FSB milestone per
|
|
254
|
+
* CONTEXT.md D-22; only the ResumePolicy taxonomy lands here).
|
|
255
|
+
*
|
|
256
|
+
* Composition conventions (NOT enforced; documented for callers):
|
|
257
|
+
* D-09: onEviction hooks SHOULD register in BAND.SAFETY band on the
|
|
258
|
+
* caller's HookPipeline so they run FIRST per Phase 2 priority
|
|
259
|
+
* ordering. This module does NOT auto-register; it ships the
|
|
260
|
+
* contract only.
|
|
261
|
+
* D-10: serialize(state) MAY include the latest checkpoint receipt
|
|
262
|
+
* envelope (Phase 3 createCheckpointHook output) inside the
|
|
263
|
+
* SerializedSnapshot.payload; deserialize() reconstructs session
|
|
264
|
+
* identifiers from the v1.1 receipt body's step-marker fields
|
|
265
|
+
* (stepName, stepIndex, parentStepName, previousStepName,
|
|
266
|
+
* sessionId, timestamp). The payload is opaque to Lattice -- the
|
|
267
|
+
* host runtime defines the shape.
|
|
268
|
+
*
|
|
269
|
+
* ResumePolicy taxonomy (CD-E resolution per attempt-1 02-04-PLAN.md):
|
|
270
|
+
* - SAFE: the snapshot was captured at a safe boundary (BEFORE_ITERATION
|
|
271
|
+
* or BEFORE_NEXT_ITERATION_SCHEDULE step markers) and can be replayed
|
|
272
|
+
* deterministically. The host runtime may re-arm the loop.
|
|
273
|
+
* - RECOVERY_AMBIGUOUS: the snapshot was captured during a tool dispatch
|
|
274
|
+
* where re-execution risk is non-zero (file write, network POST without
|
|
275
|
+
* Idempotency-Key, side-effecting browser action). Host should escalate
|
|
276
|
+
* to the user before deciding.
|
|
277
|
+
* - ON_ERROR_SW_EVICTION_MID_REQUEST: the eviction happened mid-API-call
|
|
278
|
+
* (the provider request was in flight). 6 of 7 FSB providers do NOT
|
|
279
|
+
* document Idempotency-Key headers; replay risks duplicate charges +
|
|
280
|
+
* duplicate responses. Host should treat the run as failed and surface
|
|
281
|
+
* the error to the user.
|
|
282
|
+
* - ON_ERROR_SW_EVICTION_MID_TOOL_DISPATCH: the eviction happened mid-
|
|
283
|
+
* tool-dispatch (a browser action was in progress). Re-execution risk
|
|
284
|
+
* is similar to mid-API-call but lands in a different recovery branch
|
|
285
|
+
* (the host may inspect the page state before deciding).
|
|
286
|
+
*
|
|
287
|
+
* SerializedSnapshot is intentionally opaque + string-encodable. The
|
|
288
|
+
* host runtime defines the payload shape; Lattice's only requirement
|
|
289
|
+
* is that serialize() followed by deserialize() round-trips the state.
|
|
290
|
+
*
|
|
291
|
+
* Ed25519 receipt envelope contract (carries forward from Phase 1-3):
|
|
292
|
+
* Callers MAY embed a v1.1 ReceiptEnvelope inside SerializedSnapshot.payload
|
|
293
|
+
* for signed checkpoint round-trip. verifyReceipt against the embedded
|
|
294
|
+
* envelope MUST return result.ok === true after a serialize -> deserialize
|
|
295
|
+
* cycle (Test 12). This validates that JSON.stringify + JSON.parse over
|
|
296
|
+
* the envelope preserves the JCS-canonical body bytes used by DSSE PAE.
|
|
297
|
+
*
|
|
298
|
+
* Threat model (Phase 5 CONTEXT.md security block):
|
|
299
|
+
* - PII via serialized state: callers MUST ensure SerializedSnapshot.payload
|
|
300
|
+
* contains only stable identifiers + user-controlled state the user has
|
|
301
|
+
* already consented to persist. Mirrors Phase 2 D-04 receipt-body contract
|
|
302
|
+
* (step-marker fields are stable identifiers, not free-form user input).
|
|
303
|
+
* - Snapshot tampering: the noop adapter does NOT sign the snapshot.
|
|
304
|
+
* Callers that need cryptographic integrity SHOULD embed a signed
|
|
305
|
+
* ReceiptEnvelope inside the payload + verify it on deserialize.
|
|
306
|
+
* Phase 5 ships the contract; signature wrapping is a follow-on.
|
|
307
|
+
*
|
|
308
|
+
* Vocabulary separation (carries forward Phase 2 D-12 + Phase 3 D-02):
|
|
309
|
+
* ResumePolicy is the survivability vocabulary -- separate from
|
|
310
|
+
* RunEventKind (tracing) AND separate from HookLifecycleEvent (bands).
|
|
311
|
+
* The three vocabularies meet only when a host runtime composes them.
|
|
312
|
+
*/
|
|
313
|
+
/**
|
|
314
|
+
* String-encodable opaque snapshot. The host runtime defines the payload
|
|
315
|
+
* shape; Lattice's only requirement is that serialize() followed by
|
|
316
|
+
* deserialize() round-trips the original state object.
|
|
317
|
+
*
|
|
318
|
+
* Why string-encodable? MV3's chrome.storage.session and most cross-process
|
|
319
|
+
* storage layers accept structured-clone-safe values. JSON-string payloads
|
|
320
|
+
* are the lowest-common-denominator that survives MV3 SW eviction +
|
|
321
|
+
* Cloudflare Worker freeze + Lambda thaw. Callers MAY use a richer payload
|
|
322
|
+
* shape (Uint8Array, Blob) IF the host runtime supports it; the contract
|
|
323
|
+
* does not constrain payload format beyond "deserialize round-trips it".
|
|
324
|
+
*/
|
|
325
|
+
interface SerializedSnapshot {
|
|
326
|
+
readonly kind: "survivability-snapshot";
|
|
327
|
+
readonly version: "lattice-survivability/v1";
|
|
328
|
+
readonly payload: string;
|
|
329
|
+
readonly capturedAt: string;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Pre-eviction callback. The host runtime CAN attempt to call this hook
|
|
333
|
+
* before the execution context is evicted, but MAY NOT be able to in
|
|
334
|
+
* every case (MV3 eviction has no synchronous signal -- the SW just
|
|
335
|
+
* stops). Callers should treat onEviction as best-effort: useful for
|
|
336
|
+
* gathering final state when the eviction is announced (e.g., user-
|
|
337
|
+
* initiated stop) but not load-bearing for involuntary eviction.
|
|
338
|
+
*
|
|
339
|
+
* The hook receives the current TState by reference. Mutations on the
|
|
340
|
+
* hook side leak to the caller's state -- this is deliberate (the hook
|
|
341
|
+
* is the LAST chance to update state before eviction). Callers who want
|
|
342
|
+
* structuredClone semantics SHOULD wrap state in their own freeze layer.
|
|
343
|
+
*/
|
|
344
|
+
type EvictionHook<TState> = (state: TState) => void | Promise<void>;
|
|
345
|
+
/**
|
|
346
|
+
* Return value of onEviction(); calling unsubscribes the hook.
|
|
347
|
+
*
|
|
348
|
+
* Idempotent -- calling twice has the same effect as calling once.
|
|
349
|
+
*/
|
|
350
|
+
type UnsubscribeFn = () => void;
|
|
351
|
+
/**
|
|
352
|
+
* Resume policy taxonomy. The host runtime calls adapter.resume(snapshot)
|
|
353
|
+
* after eviction + restore; the returned policy tells the host runtime
|
|
354
|
+
* how to react.
|
|
355
|
+
*
|
|
356
|
+
* The 4 literal members carry forward from FSB v0.10.0-attempt-1's
|
|
357
|
+
* 02-04-PLAN.md CONSERVATIVE recovery dispatch (preserved at
|
|
358
|
+
* .planning/milestones/v0.10.0-attempt-1-pre-pivot/02-state-inspectability-
|
|
359
|
+
* carve-out/02-04-PLAN.md). Per CONTEXT.md CD-E this is the locked union.
|
|
360
|
+
*/
|
|
361
|
+
type ResumePolicy = "SAFE" | "RECOVERY_AMBIGUOUS" | "ON_ERROR_SW_EVICTION_MID_REQUEST" | "ON_ERROR_SW_EVICTION_MID_TOOL_DISPATCH";
|
|
362
|
+
/**
|
|
363
|
+
* The SurvivabilityAdapter contract. Host runtimes implement this; Lattice
|
|
364
|
+
* runs against the interface.
|
|
365
|
+
*
|
|
366
|
+
* 4 methods (D-08 locked):
|
|
367
|
+
* - serialize(state): convert in-memory state to SerializedSnapshot
|
|
368
|
+
* - deserialize(snapshot): inverse of serialize
|
|
369
|
+
* - onEviction(hook): register a best-effort pre-eviction callback
|
|
370
|
+
* - resume(snapshot): return ResumePolicy verdict for the post-restore
|
|
371
|
+
* reconstruction. The host runtime acts on the policy.
|
|
372
|
+
*
|
|
373
|
+
* Adapters are POLYMORPHIC over TState -- the host runtime parameterizes
|
|
374
|
+
* the type. Lattice's vitest covers the contract surface with a noop
|
|
375
|
+
* adapter where TState = Record<string, unknown> for ergonomics.
|
|
376
|
+
*/
|
|
377
|
+
interface SurvivabilityAdapter<TState> {
|
|
378
|
+
readonly kind: "survivability-adapter";
|
|
379
|
+
readonly id: string;
|
|
380
|
+
serialize(state: TState): SerializedSnapshot;
|
|
381
|
+
deserialize(snapshot: SerializedSnapshot): TState;
|
|
382
|
+
onEviction(hook: EvictionHook<TState>): UnsubscribeFn;
|
|
383
|
+
resume(snapshot: SerializedSnapshot): Promise<ResumePolicy>;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Factory options for the reference noop adapter.
|
|
387
|
+
*
|
|
388
|
+
* - id: optional. Defaults to "noop-survivability". Useful when callers
|
|
389
|
+
* want to distinguish multiple adapter instances in test fixtures.
|
|
390
|
+
* - policy: optional. Sets the default ResumePolicy returned by resume().
|
|
391
|
+
* Defaults to "SAFE" (matches noop adapter semantics: no recovery
|
|
392
|
+
* ambiguity if nothing was ever persisted).
|
|
393
|
+
*/
|
|
394
|
+
interface NoopSurvivabilityAdapterOptions {
|
|
395
|
+
readonly id?: string;
|
|
396
|
+
readonly policy?: ResumePolicy;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Reference implementation of SurvivabilityAdapter<TState>. Records
|
|
400
|
+
* eviction events but does NOT persist; serialize / deserialize round-
|
|
401
|
+
* trip via JSON.stringify / JSON.parse. Analog to createFakeProvider
|
|
402
|
+
* in the providers/ module -- gives Lattice's vitest a complete shape-
|
|
403
|
+
* conformance target before the real (FSB-side) adapter ships in
|
|
404
|
+
* Plan 05-05.
|
|
405
|
+
*
|
|
406
|
+
* Per CONTEXT.md D-11 the noop adapter ships in Lattice (not FSB)
|
|
407
|
+
* because it covers the contract surface in Lattice's own test suite;
|
|
408
|
+
* FSB's real chrome.storage.session-backed adapter is glue layer.
|
|
409
|
+
*/
|
|
410
|
+
declare function createNoopSurvivabilityAdapter<TState = Record<string, unknown>>(options?: NoopSurvivabilityAdapterOptions): SurvivabilityAdapter<TState>;
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/agent/host.d.ts
|
|
413
|
+
/**
|
|
414
|
+
* Snapshot shape the agent loop serializes between iterations. The full
|
|
415
|
+
* shape is opaque to callers (they only see it through SerializedSnapshot
|
|
416
|
+
* via the configured SurvivabilityAdapter) but it's exported so reference
|
|
417
|
+
* implementations and tests can inspect the round-trip.
|
|
418
|
+
*/
|
|
419
|
+
interface AgentSnapshot {
|
|
420
|
+
readonly version: "agent-snapshot/v1";
|
|
421
|
+
readonly iterationIndex: number;
|
|
422
|
+
readonly conversation: readonly ConversationTurn[];
|
|
423
|
+
readonly cumulativeUsage: Usage;
|
|
424
|
+
readonly providerName: string;
|
|
425
|
+
readonly capturedAt: string;
|
|
426
|
+
/**
|
|
427
|
+
* Phase 39 (v1.3): dispatch ancestry chain of crew `AgentSpec` ids
|
|
428
|
+
* (root-first). Absent = root agent (single-agent runs never set it).
|
|
429
|
+
* Optional so existing serialized `agent-snapshot/v1` snapshots
|
|
430
|
+
* deserialize unchanged — the version literal stays `"agent-snapshot/v1"`
|
|
431
|
+
* (D-05; Pitfall 8). The crew dispatcher threads the chain through
|
|
432
|
+
* dispatch context in 39-05; cycle prevention rejects any dispatch whose
|
|
433
|
+
* target id already appears in the chain.
|
|
434
|
+
*/
|
|
435
|
+
readonly ancestry?: readonly string[];
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Scheduler seam — controls how the agent loop yields between iterations.
|
|
439
|
+
*
|
|
440
|
+
* `scheduleNext(iterationIndex)` is called AFTER an AFTER_AGENT_ITERATION
|
|
441
|
+
* emission and BEFORE the next iteration's BEFORE_AGENT_ITERATION. The
|
|
442
|
+
* scheduler decides when to resume — synchronously (sync loop), on next
|
|
443
|
+
* tick (setTimeout/queueMicrotask), via a queue (Durable Object), or any
|
|
444
|
+
* other strategy.
|
|
445
|
+
*
|
|
446
|
+
* Default (noop): resolves immediately.
|
|
447
|
+
*/
|
|
448
|
+
interface AgentScheduler {
|
|
449
|
+
scheduleNext(iterationIndex: number): Promise<void>;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Transport seam — controls how a provider call is dispatched.
|
|
453
|
+
*
|
|
454
|
+
* `call(provider, request)` wraps the provider's `execute()` invocation.
|
|
455
|
+
* Default (noop): pass-through (`provider.execute!(request)`). Cross-process
|
|
456
|
+
* bridges (FSB's offscreen-document host) override to dispatch via
|
|
457
|
+
* `chrome.runtime.sendMessage`.
|
|
458
|
+
*
|
|
459
|
+
* Per the Phase 19 INV-03 parity invariant, the transport seam does NOT
|
|
460
|
+
* modify the `ProviderAdapter` interface — it operates on top of the
|
|
461
|
+
* existing `execute()` method.
|
|
462
|
+
*/
|
|
463
|
+
interface AgentTransport {
|
|
464
|
+
call(provider: ProviderAdapter, request: ProviderRunRequest): Promise<ProviderRunResponse>;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Storage seam — controls how agent state persists between iterations for
|
|
468
|
+
* resume after host eviction.
|
|
469
|
+
*
|
|
470
|
+
* Phase 20 composes this with the Phase 18 `SurvivabilityAdapter`:
|
|
471
|
+
* - The adapter serializes `AgentSnapshot` to `SerializedSnapshot` on
|
|
472
|
+
* each AFTER_AGENT_ITERATION; storage.save() persists the snapshot.
|
|
473
|
+
* - On run start, the agent loop calls storage.load(). If a non-null
|
|
474
|
+
* snapshot is returned, the adapter deserializes it; the loop resumes
|
|
475
|
+
* at the recorded iteration index.
|
|
476
|
+
* - On success, the loop calls storage.clear() so the next run starts
|
|
477
|
+
* fresh.
|
|
478
|
+
*
|
|
479
|
+
* Default (noop): save() is a no-op, load() returns null, clear() is a
|
|
480
|
+
* no-op. Suitable for Node tests where eviction never occurs.
|
|
481
|
+
*/
|
|
482
|
+
interface AgentStorage {
|
|
483
|
+
save(snapshot: SerializedSnapshot): Promise<void>;
|
|
484
|
+
load(): Promise<SerializedSnapshot | null>;
|
|
485
|
+
clear(): Promise<void>;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* The host adapter — three optional seams, all swappable independently.
|
|
489
|
+
*
|
|
490
|
+
* Callers pass `host` on `AgentIntent`. The agent runtime falls back to
|
|
491
|
+
* `createNoopAgentHost()` when `intent.host` is absent (so Phase 19
|
|
492
|
+
* single-shot Node usage continues to work without explicit configuration).
|
|
493
|
+
*/
|
|
494
|
+
interface AgentHost {
|
|
495
|
+
readonly kind: "agent-host";
|
|
496
|
+
readonly scheduler?: AgentScheduler;
|
|
497
|
+
readonly transport?: AgentTransport;
|
|
498
|
+
readonly storage?: AgentStorage;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Reference implementation suitable for Node tests + the Phase 19 default
|
|
502
|
+
* behavior.
|
|
503
|
+
*
|
|
504
|
+
* - scheduler: resolves immediately (no yield between iterations).
|
|
505
|
+
* - transport: pass-through to provider.execute().
|
|
506
|
+
* - storage: save() / clear() are no-ops; load() always returns null.
|
|
507
|
+
*
|
|
508
|
+
* Equivalent to passing no host at all.
|
|
509
|
+
*/
|
|
510
|
+
declare function createNoopAgentHost(): AgentHost;
|
|
511
|
+
//#endregion
|
|
512
|
+
//#region src/agent/types.d.ts
|
|
513
|
+
type DefaultAgentOutputs = {
|
|
514
|
+
readonly answer: "text";
|
|
515
|
+
};
|
|
516
|
+
/**
|
|
517
|
+
* Per-iteration record stored on `AgentSuccess.iterations` for inspectability.
|
|
518
|
+
*
|
|
519
|
+
* `toolCalls` carries content-addressed args/result hashes (sha256) so
|
|
520
|
+
* downstream receipts can reference them without inlining the bodies.
|
|
521
|
+
*
|
|
522
|
+
* `deniedReason` is populated on iterations whose `BEFORE_AGENT_ITERATION`
|
|
523
|
+
* SAFETY-band handler set `controls.deny(...)`.
|
|
524
|
+
*/
|
|
525
|
+
interface IterationRecord {
|
|
526
|
+
readonly index: number;
|
|
527
|
+
readonly provider: string;
|
|
528
|
+
readonly promptTokens: number;
|
|
529
|
+
readonly completionTokens: number;
|
|
530
|
+
readonly costUsd: number | null;
|
|
531
|
+
readonly durationMs: number;
|
|
532
|
+
readonly toolCalls: ReadonlyArray<{
|
|
533
|
+
readonly id: string;
|
|
534
|
+
readonly name: string;
|
|
535
|
+
readonly argsHash: string;
|
|
536
|
+
readonly resultHash: string;
|
|
537
|
+
}>;
|
|
538
|
+
readonly deniedReason?: string;
|
|
539
|
+
readonly receipt?: ReceiptEnvelope;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Input shape accepted by `ai.runAgent(intent)`.
|
|
543
|
+
*
|
|
544
|
+
* All fields except `task` and `tools` are optional. The runtime supplies
|
|
545
|
+
* sensible defaults (in-process host, fresh pipeline, no signer, no tracer).
|
|
546
|
+
*
|
|
547
|
+
* `TOutputs` parameterizes the final-answer schema map; defaults to a free-form
|
|
548
|
+
* `{ answer: "text" }` shape when the field is omitted. Validation runs once
|
|
549
|
+
* against the final assistant message (no intermediate iteration validation).
|
|
550
|
+
*/
|
|
551
|
+
interface AgentIntent<TOutputs extends OutputContractMap = OutputContractMap> {
|
|
552
|
+
readonly task: string;
|
|
553
|
+
readonly tools: ReadonlyArray<ToolDefinition<StandardSchemaV1>>;
|
|
554
|
+
readonly host?: AgentHost;
|
|
555
|
+
/**
|
|
556
|
+
* Phase 20 (v1.2): when the agent loop resumes from a host.storage snapshot,
|
|
557
|
+
* the configured SurvivabilityAdapter handles the serialize/deserialize
|
|
558
|
+
* round-trip. When absent, runtime defaults to
|
|
559
|
+
* `createNoopSurvivabilityAdapter<AgentSnapshot>()`.
|
|
560
|
+
*/
|
|
561
|
+
readonly survivabilityAdapter?: SurvivabilityAdapter<AgentSnapshot>;
|
|
562
|
+
readonly contract?: CapabilityContract;
|
|
563
|
+
readonly policy?: PolicySpec;
|
|
564
|
+
readonly outputs?: TOutputs;
|
|
565
|
+
readonly pipeline?: HookPipeline;
|
|
566
|
+
readonly signer?: ReceiptSigner;
|
|
567
|
+
readonly tracer?: TracerLike;
|
|
568
|
+
/**
|
|
569
|
+
* When `false`, the runtime will NOT auto-register `createCheckpointHook`
|
|
570
|
+
* even if `signer` is provided. Callers who want full manual control over
|
|
571
|
+
* receipt minting set this to `false` and register their own hook.
|
|
572
|
+
* Defaults to `true` (auto-register when signer present).
|
|
573
|
+
*/
|
|
574
|
+
readonly autoRegisterCheckpoint?: boolean;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Success result returned by `ai.runAgent` when the loop reaches a final
|
|
578
|
+
* answer and (when `outputs` is declared) the final answer validates.
|
|
579
|
+
*
|
|
580
|
+
* `iterations[]` records every iteration that ran — including the one that
|
|
581
|
+
* produced the final answer. `receipt` is the outermost receipt minted at
|
|
582
|
+
* loop close when `signer` is configured (separate from per-iteration
|
|
583
|
+
* receipts on `iterations[i].receipt`).
|
|
584
|
+
*/
|
|
585
|
+
interface AgentSuccess<TOutputs extends OutputContractMap = OutputContractMap> {
|
|
586
|
+
readonly kind: "success";
|
|
587
|
+
readonly output: InferOutputMap<TOutputs>;
|
|
588
|
+
readonly artifacts?: readonly ArtifactRef[];
|
|
589
|
+
readonly usage: Usage;
|
|
590
|
+
readonly iterations: ReadonlyArray<IterationRecord>;
|
|
591
|
+
readonly receipt?: ReceiptEnvelope;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Failure kinds specific to the agent loop. v1.1 `LatticeRunError.kind`
|
|
595
|
+
* values remain valid (provider errors, no-contract-match, validation-failed,
|
|
596
|
+
* tripwire-violated) and are reused verbatim. Phase 19 adds three
|
|
597
|
+
* agent-specific kinds. Phase 39 (v1.3) adds `crew-budget-exceeded` —
|
|
598
|
+
* crew-level shared-pool exhaustion, terminal across the parent/child
|
|
599
|
+
* boundary (D-10).
|
|
600
|
+
*/
|
|
601
|
+
type AgentFailureKind = LatticeRunError["kind"] | "agent-iteration-denied" | "agent-max-iterations" | "agent-wall-time-exceeded" | "crew-budget-exceeded";
|
|
602
|
+
/**
|
|
603
|
+
* Failure result returned by `ai.runAgent`. Discriminates via `kind`.
|
|
604
|
+
*
|
|
605
|
+
* `iterations[]` carries any iterations that completed before the failure
|
|
606
|
+
* (empty if the failure occurred pre-iteration). For `agent-iteration-denied`,
|
|
607
|
+
* the failing iteration is the LAST entry and carries `deniedReason`.
|
|
608
|
+
*/
|
|
609
|
+
interface AgentFailure {
|
|
610
|
+
readonly kind: AgentFailureKind;
|
|
611
|
+
readonly usage: Usage;
|
|
612
|
+
readonly iterations: ReadonlyArray<IterationRecord>;
|
|
613
|
+
readonly reason?: string;
|
|
614
|
+
readonly cause?: unknown;
|
|
615
|
+
readonly receipt?: ReceiptEnvelope;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Discriminated union returned by `ai.runAgent`.
|
|
619
|
+
*/
|
|
620
|
+
type AgentResult<TOutputs extends OutputContractMap = OutputContractMap> = AgentSuccess<TOutputs> | AgentFailure;
|
|
621
|
+
/**
|
|
622
|
+
* Typed error raised when a SAFETY-band handler sets `controls.deny(reason)`
|
|
623
|
+
* during `BEFORE_AGENT_ITERATION`. Carries `terminal: true` semantics to
|
|
624
|
+
* align with v1.1 `TripwireViolationError`: the failure is NOT retried by
|
|
625
|
+
* the fallback chain.
|
|
626
|
+
*
|
|
627
|
+
* Surfaced via `AgentFailure { kind: "agent-iteration-denied", reason, ... }`
|
|
628
|
+
* — callers can also catch the typed error if they prefer.
|
|
629
|
+
*/
|
|
630
|
+
declare class AgentDeniedError extends Error {
|
|
631
|
+
readonly kind: "agent-iteration-denied";
|
|
632
|
+
readonly terminal: true;
|
|
633
|
+
readonly reason: string;
|
|
634
|
+
readonly iterationIndex: number;
|
|
635
|
+
constructor(reason: string, iterationIndex: number);
|
|
636
|
+
}
|
|
637
|
+
//#endregion
|
|
638
|
+
//#region src/agent/crew/agent-spec.d.ts
|
|
639
|
+
/**
|
|
640
|
+
* Crew member specification. A literal sibling of `ToolDefinition`
|
|
641
|
+
* discriminated by `kind: "agent"` (D-03).
|
|
642
|
+
*/
|
|
643
|
+
interface AgentSpec {
|
|
644
|
+
readonly kind: "agent";
|
|
645
|
+
readonly id: string;
|
|
646
|
+
readonly intent: string;
|
|
647
|
+
readonly tools: ReadonlyArray<ToolDefinition<StandardSchemaV1>>;
|
|
648
|
+
readonly childAgents?: ReadonlyArray<AgentSpec>;
|
|
649
|
+
readonly summaryReturnSchema: StandardSchemaV1;
|
|
650
|
+
/** Optional per-agent sub-budget (D-07). */
|
|
651
|
+
readonly contract?: CapabilityContract;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Factory for `AgentSpec` values. Mirrors `defineTool` exactly: spread
|
|
655
|
+
* preserves input identity (no cloning, no mutation) and absent optional
|
|
656
|
+
* members stay absent (`exactOptionalPropertyTypes`-safe).
|
|
657
|
+
*/
|
|
658
|
+
declare function defineAgent(definition: Omit<AgentSpec, "kind">): AgentSpec;
|
|
659
|
+
//#endregion
|
|
660
|
+
//#region src/agent/crew/crew-policy.d.ts
|
|
661
|
+
/** Per-adapter rate-limit override (keyed by `adapter.id` in `limits`). */
|
|
662
|
+
interface CrewRateLimitOverride {
|
|
663
|
+
readonly requestsPerMinute?: number;
|
|
664
|
+
readonly tokensPerMinute?: number;
|
|
665
|
+
}
|
|
666
|
+
/** Crew-level policy contract (D-06, D-11, D-16). */
|
|
667
|
+
interface CrewPolicy {
|
|
668
|
+
/** Crew-level shared budget pool — `BudgetInvariant` reused verbatim. */
|
|
669
|
+
readonly budget?: BudgetInvariant;
|
|
670
|
+
readonly maxTotalIterations?: number;
|
|
671
|
+
readonly maxIterationsPerAgent?: number;
|
|
672
|
+
/** Forward-compat field; the v1.3 runtime rejects values > 1 (D-11). */
|
|
673
|
+
readonly maxConcurrentChildren?: number;
|
|
674
|
+
/** Delegation depth cap; defaults to 1 (parent→child only, D-05). */
|
|
675
|
+
readonly maxDepth?: number;
|
|
676
|
+
/** Per-adapter-id rate-limit overrides (D-16). */
|
|
677
|
+
readonly limits?: Readonly<Record<string, CrewRateLimitOverride>>;
|
|
678
|
+
/** "managed" (default) wraps transports in the rate-limit group; "unmanaged" skips it. */
|
|
679
|
+
readonly coordination?: "managed" | "unmanaged";
|
|
680
|
+
}
|
|
681
|
+
//#endregion
|
|
682
|
+
//#region src/agent/crew/run-crew.d.ts
|
|
683
|
+
interface RunAgentCrewOptions {
|
|
684
|
+
readonly root: AgentSpec;
|
|
685
|
+
readonly hosts: {
|
|
686
|
+
readonly childHost: AgentHost;
|
|
687
|
+
};
|
|
688
|
+
readonly policy?: CrewPolicy;
|
|
689
|
+
/** Crew-level signer threaded into member loops and completion receipts. */
|
|
690
|
+
readonly signer?: ReceiptSigner;
|
|
691
|
+
/** Crew-level tracer threaded into member loops. */
|
|
692
|
+
readonly tracer?: TracerLike;
|
|
693
|
+
/** Crew-level hook pipeline threaded into member loops. */
|
|
694
|
+
readonly pipeline?: HookPipeline;
|
|
695
|
+
}
|
|
696
|
+
interface CrewAgentResult {
|
|
697
|
+
readonly id: string;
|
|
698
|
+
readonly usage: Usage;
|
|
699
|
+
readonly iterations: number;
|
|
700
|
+
readonly receiptCids: readonly string[];
|
|
701
|
+
}
|
|
702
|
+
interface CrewResult {
|
|
703
|
+
/** Parent result, with parent output untouched on success. */
|
|
704
|
+
readonly result: AgentResult;
|
|
705
|
+
/** Per-agent accounting records, including root parent and completed children. */
|
|
706
|
+
readonly perAgent: ReadonlyArray<CrewAgentResult>;
|
|
707
|
+
/** Crew aggregate usage: parent total + sum(child totals), no double-counting. */
|
|
708
|
+
readonly usage: Usage;
|
|
709
|
+
/** Total iterations across every recorded agent. */
|
|
710
|
+
readonly totalIterations: number;
|
|
711
|
+
/** All crew completion receipts, including the crew-root envelope. */
|
|
712
|
+
readonly receipts: ReadonlyArray<ReceiptEnvelope>;
|
|
713
|
+
readonly crewRootCid?: string;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Execute a crew rooted at `options.root`.
|
|
717
|
+
*/
|
|
718
|
+
declare function runAgentCrew(options: RunAgentCrewOptions, config?: LatticeConfig): Promise<CrewResult>;
|
|
719
|
+
//#endregion
|
|
720
|
+
export { FormatToolsMode as A, HookDenyDirective as B, EvictionHook as C, UnsubscribeFn as D, SurvivabilityAdapter as E, LatticeConfig as F, createHookPipeline as G, HookLifecycleEvent as H, NormalizedLatticeConfig as I, BAND as L, FormattedToolsHandle as M, formatToolsForProvider as N, createNoopSurvivabilityAdapter as O, toolSchemaToJsonSchema as P, Band as R, createNoopAgentHost as S, SerializedSnapshot as T, HookPipeline as U, HookHandler as V, RegisterOptions as W, AgentHost as _, CrewPolicy as a, AgentStorage as b, defineAgent as c, AgentFailureKind as d, AgentIntent as f, IterationRecord as g, DefaultAgentOutputs as h, runAgentCrew as i, FormatToolsOptions as j, ConversationTurn as k, AgentDeniedError as l, AgentSuccess as m, CrewResult as n, CrewRateLimitOverride as o, AgentResult as p, RunAgentCrewOptions as r, AgentSpec as s, CrewAgentResult as t, AgentFailure as u, AgentScheduler as v, ResumePolicy as w, AgentTransport as x, AgentSnapshot as y, HookControls as z };
|
|
721
|
+
//# sourceMappingURL=run-crew-Bnve5dyI.d.ts.map
|