@arnilo/prism 0.2.4 → 0.2.5
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/CHANGELOG.md +5 -0
- package/dist/agent-session/create-agent.d.ts +6 -0
- package/dist/agent-session/create-agent.js +13 -0
- package/dist/agent-session/event-subscriber.d.ts +17 -0
- package/dist/agent-session/event-subscriber.js +68 -0
- package/dist/agent-session/helpers.d.ts +44 -0
- package/dist/agent-session/helpers.js +194 -0
- package/dist/agent-session/session.d.ts +101 -0
- package/dist/agent-session/session.js +1568 -0
- package/dist/agent-session.d.ts +6 -105
- package/dist/agent-session.js +6 -1833
- package/dist/contracts-core/agent.d.ts +257 -0
- package/dist/contracts-core/agent.js +5 -0
- package/dist/contracts-core/compaction.d.ts +72 -0
- package/dist/contracts-core/compaction.js +2 -0
- package/dist/contracts-core/content.d.ts +116 -0
- package/dist/contracts-core/content.js +2 -0
- package/dist/contracts-core/extensions.d.ts +163 -0
- package/dist/contracts-core/extensions.js +2 -0
- package/dist/contracts-core/loop.d.ts +98 -0
- package/dist/contracts-core/loop.js +2 -0
- package/dist/contracts-core/persistence.d.ts +366 -0
- package/dist/contracts-core/persistence.js +9 -0
- package/dist/contracts-core/provider.d.ts +97 -0
- package/dist/contracts-core/provider.js +2 -0
- package/dist/contracts-core/resources.d.ts +44 -0
- package/dist/contracts-core/resources.js +7 -0
- package/dist/contracts-core/run-limits.d.ts +81 -0
- package/dist/contracts-core/run-limits.js +2 -0
- package/dist/contracts-core/session.d.ts +187 -0
- package/dist/contracts-core/session.js +131 -0
- package/dist/contracts-core.d.ts +13 -1425
- package/dist/contracts-core.js +10 -138
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/docs/0.1.0-readiness.md +10 -10
- package/docs/index.md +2 -2
- package/docs/migration.md +4 -0
- package/docs/release-and-install.md +26 -3
- package/package.json +2 -2
package/dist/contracts-core.d.ts
CHANGED
|
@@ -1,1426 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { ToolDefinition, ToolRegistry } from "./contracts-protocol.js";
|
|
5
|
-
import type { AudioContent, DocumentContent, FileContent } from "./content.js";
|
|
6
|
-
import type { ContributionRegistries } from "./contributions.js";
|
|
7
|
-
import type { AgentInput } from "./input.js";
|
|
8
|
-
import type { ManifestContributionDeclaration } from "./manifests.js";
|
|
9
|
-
import type { Middleware, MiddlewareHookName, MiddlewareRegistry } from "./middleware.js";
|
|
10
|
-
import type { SecretRedactor } from "./redaction.js";
|
|
11
|
-
import type { PermissionPolicy, TrustPolicy } from "./security.js";
|
|
12
|
-
import type { ToolValidator } from "./tools.js";
|
|
13
|
-
export type JsonPrimitive = string | number | boolean | null;
|
|
14
|
-
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
15
|
-
export interface JsonObject {
|
|
16
|
-
readonly [key: string]: JsonValue;
|
|
17
|
-
}
|
|
18
|
-
export interface ErrorInfo {
|
|
19
|
-
readonly name?: string;
|
|
20
|
-
readonly message: string;
|
|
21
|
-
readonly code?: string | number;
|
|
22
|
-
/** Provider backpressure hint (e.g. from a `Retry-After` header); retry policies
|
|
23
|
-
* honor it capped at their own `maxDelayMs`. */
|
|
24
|
-
readonly retryAfterMs?: number;
|
|
25
|
-
readonly cause?: unknown;
|
|
26
|
-
}
|
|
1
|
+
/** Contracts-core barrel (0.2.5 plan 025 Task 1 god-module split): re-exports the
|
|
2
|
+
* public contracts surface from cohesive family modules so the import surface
|
|
3
|
+
* of `./contracts-core.js` is unchanged (0.1.4 barrel precedent). */
|
|
27
4
|
export type { AudioContent, DocumentContent, FileContent } from "./content.js";
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
readonly resourceUri?: string;
|
|
39
|
-
readonly name?: string;
|
|
40
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
41
|
-
}
|
|
42
|
-
export interface ThinkingContent {
|
|
43
|
-
readonly type: "thinking";
|
|
44
|
-
readonly text: string;
|
|
45
|
-
readonly signature?: string;
|
|
46
|
-
}
|
|
47
|
-
export interface ToolCallDeltaContent {
|
|
48
|
-
readonly type: "tool_call_delta";
|
|
49
|
-
readonly index: number;
|
|
50
|
-
readonly id?: string;
|
|
51
|
-
readonly name?: string;
|
|
52
|
-
readonly argumentsText?: string;
|
|
53
|
-
/** Who executes the call. `"provider-hosted"` = the provider runs it server-side;
|
|
54
|
-
* the host must NOT dispatch it or send a `tool_result`. Defaults to `"host"`. */
|
|
55
|
-
readonly authority?: ToolCallAuthority;
|
|
56
|
-
}
|
|
57
|
-
export type ToolCallAuthority = "host" | "provider-hosted";
|
|
58
|
-
export interface ToolCallContent {
|
|
59
|
-
readonly type: "tool_call";
|
|
60
|
-
readonly id: string;
|
|
61
|
-
readonly name: string;
|
|
62
|
-
readonly arguments: JsonObject;
|
|
63
|
-
/** Set when streamed arguments failed JSON parse; dispatch blocks without execute(). */
|
|
64
|
-
readonly argumentsError?: ErrorInfo;
|
|
65
|
-
/** Who executes the call. `"provider-hosted"` = the provider already ran it
|
|
66
|
-
* server-side; the host must NOT dispatch it or append a `tool_result`. The
|
|
67
|
-
* assistant response text already incorporates the call's effect. */
|
|
68
|
-
readonly authority?: ToolCallAuthority;
|
|
69
|
-
}
|
|
70
|
-
export interface ToolResultContent {
|
|
71
|
-
readonly type: "tool_result";
|
|
72
|
-
readonly toolCallId: string;
|
|
73
|
-
readonly name: string;
|
|
74
|
-
readonly result?: unknown;
|
|
75
|
-
readonly error?: ErrorInfo;
|
|
76
|
-
}
|
|
77
|
-
export interface Message {
|
|
78
|
-
readonly id?: string;
|
|
79
|
-
readonly role: "system" | "user" | "assistant" | "tool";
|
|
80
|
-
readonly content: readonly ContentBlock[];
|
|
81
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
82
|
-
}
|
|
83
|
-
export interface ModelConfig {
|
|
84
|
-
readonly provider: string;
|
|
85
|
-
readonly model: string;
|
|
86
|
-
readonly displayName?: string;
|
|
87
|
-
readonly capabilities?: ModelCapabilities;
|
|
88
|
-
readonly limits?: ModelLimits;
|
|
89
|
-
readonly cost?: ModelCost;
|
|
90
|
-
readonly cache?: ModelCacheCapabilities;
|
|
91
|
-
readonly compat?: JsonObject;
|
|
92
|
-
readonly parameters?: Readonly<Record<string, unknown>>;
|
|
93
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
94
|
-
}
|
|
95
|
-
export interface ModelCapabilities {
|
|
96
|
-
/** Known values include `text`, `image`, `audio`, `file`, and `document`. */
|
|
97
|
-
readonly input?: readonly string[];
|
|
98
|
-
readonly output?: readonly string[];
|
|
99
|
-
readonly reasoning?: boolean;
|
|
100
|
-
readonly tools?: boolean;
|
|
101
|
-
readonly streaming?: boolean;
|
|
102
|
-
/** Native JSON-schema structured output support for this model. */
|
|
103
|
-
readonly structuredOutput?: boolean | "json_schema";
|
|
104
|
-
}
|
|
105
|
-
export interface ModelLimits {
|
|
106
|
-
readonly contextWindow?: number;
|
|
107
|
-
readonly maxOutputTokens?: number;
|
|
108
|
-
}
|
|
109
|
-
export interface ModelCost {
|
|
110
|
-
readonly input?: number;
|
|
111
|
-
readonly output?: number;
|
|
112
|
-
readonly cacheRead?: number;
|
|
113
|
-
readonly cacheWrite?: number;
|
|
114
|
-
readonly currency?: string;
|
|
115
|
-
readonly unit?: string;
|
|
116
|
-
}
|
|
117
|
-
export interface Usage {
|
|
118
|
-
readonly inputTokens?: number;
|
|
119
|
-
readonly outputTokens?: number;
|
|
120
|
-
readonly totalTokens?: number;
|
|
121
|
-
readonly cacheReadTokens?: number;
|
|
122
|
-
readonly cacheWriteTokens?: number;
|
|
123
|
-
readonly cost?: number;
|
|
124
|
-
readonly currency?: string;
|
|
125
|
-
}
|
|
126
|
-
export interface RunLimits {
|
|
127
|
-
readonly maxTurns?: number;
|
|
128
|
-
readonly maxProviderAttempts?: number;
|
|
129
|
-
readonly maxToolRounds?: number;
|
|
130
|
-
readonly maxToolCalls?: number;
|
|
131
|
-
readonly maxWallTimeMs?: number;
|
|
132
|
-
readonly maxRequestBytes?: number;
|
|
133
|
-
readonly maxResponseBytes?: number;
|
|
134
|
-
readonly maxInputTokens?: number;
|
|
135
|
-
readonly maxOutputTokens?: number;
|
|
136
|
-
readonly maxTotalTokens?: number;
|
|
137
|
-
readonly maxCost?: {
|
|
138
|
-
readonly amount: number;
|
|
139
|
-
readonly currency: string;
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
export type RunLimitName = keyof Required<RunLimits>;
|
|
143
|
-
export interface RunLimitCounters {
|
|
144
|
-
readonly turns: number;
|
|
145
|
-
readonly providerAttempts: number;
|
|
146
|
-
readonly toolRounds: number;
|
|
147
|
-
readonly toolCalls: number;
|
|
148
|
-
readonly wallTimeMs: number;
|
|
149
|
-
readonly requestBytes: number;
|
|
150
|
-
readonly responseBytes: number;
|
|
151
|
-
readonly inputTokens: number;
|
|
152
|
-
readonly outputTokens: number;
|
|
153
|
-
readonly totalTokens: number;
|
|
154
|
-
readonly cost: number;
|
|
155
|
-
}
|
|
156
|
-
export interface RunLimitBreach {
|
|
157
|
-
readonly limit: RunLimitName;
|
|
158
|
-
readonly maximum: number;
|
|
159
|
-
readonly observed: number;
|
|
160
|
-
readonly currency?: string;
|
|
161
|
-
}
|
|
162
|
-
export type GuardrailStage = "input" | "output" | "tool_input" | "tool_output";
|
|
163
|
-
export type GuardrailAction = "allow" | "block" | "tripwire" | "interrupt";
|
|
164
|
-
export type GuardrailValue<S extends GuardrailStage> = S extends "input" ? readonly Message[] : S extends "output" ? ProviderTurnResult : S extends "tool_input" ? ToolCallContent : ToolResult;
|
|
165
|
-
export interface GuardrailContext<S extends GuardrailStage> {
|
|
166
|
-
readonly stage: S;
|
|
167
|
-
readonly value: GuardrailValue<S>;
|
|
168
|
-
readonly sessionId: string;
|
|
169
|
-
readonly runId: string;
|
|
170
|
-
readonly toolCallId?: string;
|
|
171
|
-
readonly toolName?: string;
|
|
172
|
-
readonly metadata: Readonly<Record<string, unknown>>;
|
|
173
|
-
readonly signal: AbortSignal;
|
|
174
|
-
}
|
|
175
|
-
export interface GuardrailDecision {
|
|
176
|
-
readonly action: GuardrailAction;
|
|
177
|
-
readonly reason?: string;
|
|
178
|
-
/** Public data only; Prism JSON-normalizes, bounds, and redacts it before emission. */
|
|
179
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
180
|
-
}
|
|
181
|
-
export interface Guardrail<S extends GuardrailStage = GuardrailStage> {
|
|
182
|
-
readonly name: string;
|
|
183
|
-
readonly stage: S;
|
|
184
|
-
/** Host-authored stable identity for durable definitions; unused by ordinary runs. */
|
|
185
|
-
readonly revision?: string;
|
|
186
|
-
evaluate(context: GuardrailContext<S>): GuardrailDecision | Promise<GuardrailDecision>;
|
|
187
|
-
}
|
|
188
|
-
export interface GuardrailRecord {
|
|
189
|
-
readonly guardrail: string;
|
|
190
|
-
readonly stage: GuardrailStage;
|
|
191
|
-
readonly action: GuardrailAction;
|
|
192
|
-
readonly reason?: string;
|
|
193
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
194
|
-
}
|
|
195
|
-
export interface Guardrails {
|
|
196
|
-
readonly input?: readonly Guardrail<"input">[];
|
|
197
|
-
readonly output?: readonly Guardrail<"output">[];
|
|
198
|
-
readonly toolInput?: readonly Guardrail<"tool_input">[];
|
|
199
|
-
readonly toolOutput?: readonly Guardrail<"tool_output">[];
|
|
200
|
-
/** Defaults to sequential; at most 16 stage evaluations run at once. */
|
|
201
|
-
readonly maxConcurrency?: number;
|
|
202
|
-
}
|
|
203
|
-
export type CacheRetention = "none" | "short" | "long";
|
|
204
|
-
export type PromptCacheKind = "implicit" | "openai_key" | "cache_control" | "provider_specific" | "none";
|
|
205
|
-
export interface ModelCacheCapabilities {
|
|
206
|
-
readonly kind?: PromptCacheKind;
|
|
207
|
-
readonly maxKeyLength?: number;
|
|
208
|
-
readonly maxBreakpoints?: number;
|
|
209
|
-
readonly minCacheableTokens?: number;
|
|
210
|
-
readonly longRetention?: boolean;
|
|
211
|
-
}
|
|
212
|
-
export type PromptCacheMode = "auto" | "on" | "off";
|
|
213
|
-
export type PromptCacheBreakpointLocation = "system_prompt" | "tools" | "stable_context" | "last_stable_message" | "last_user_message" | "message_id";
|
|
214
|
-
export type PromptCacheBreakpointTtl = "short" | "long";
|
|
215
|
-
export interface PromptCacheBreakpoint {
|
|
216
|
-
readonly location: PromptCacheBreakpointLocation;
|
|
217
|
-
readonly messageId?: string;
|
|
218
|
-
readonly ttl?: PromptCacheBreakpointTtl;
|
|
219
|
-
}
|
|
220
|
-
export interface PromptCacheHints {
|
|
221
|
-
readonly mode?: PromptCacheMode;
|
|
222
|
-
readonly key?: string;
|
|
223
|
-
readonly retention?: CacheRetention;
|
|
224
|
-
readonly breakpoints?: readonly PromptCacheBreakpoint[];
|
|
225
|
-
}
|
|
226
|
-
export interface StructuredOutputOptions {
|
|
227
|
-
readonly name: string;
|
|
228
|
-
readonly schema: JsonObject;
|
|
229
|
-
readonly strict?: boolean;
|
|
230
|
-
}
|
|
231
|
-
export interface ProviderRequestOptions {
|
|
232
|
-
readonly sessionId?: string;
|
|
233
|
-
readonly cacheRetention?: CacheRetention;
|
|
234
|
-
readonly cacheKey?: string;
|
|
235
|
-
readonly cache?: PromptCacheHints;
|
|
236
|
-
readonly headers?: Readonly<Record<string, string>>;
|
|
237
|
-
readonly compat?: JsonObject;
|
|
238
|
-
readonly extra?: JsonObject;
|
|
239
|
-
/** Provider-neutral JSON-schema structured output request. Requires model `capabilities.structuredOutput`. */
|
|
240
|
-
readonly structuredOutput?: StructuredOutputOptions;
|
|
241
|
-
/** Opaque provider continuation cursor (e.g. OpenAI `previous_response_id`). When set,
|
|
242
|
-
* the provider resumes from this cursor instead of re-sending full history. */
|
|
243
|
-
readonly continuation?: {
|
|
244
|
-
readonly cursor: string;
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
export interface ProviderRequest {
|
|
248
|
-
readonly model: ModelConfig;
|
|
249
|
-
readonly messages: readonly Message[];
|
|
250
|
-
readonly tools?: readonly ToolDefinition[];
|
|
251
|
-
readonly context?: readonly ContextBlock[];
|
|
252
|
-
readonly options?: ProviderRequestOptions;
|
|
253
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
254
|
-
readonly signal?: AbortSignal;
|
|
255
|
-
}
|
|
256
|
-
export interface AIProvider {
|
|
257
|
-
readonly id: string;
|
|
258
|
-
generate(request: ProviderRequest): AsyncIterable<ProviderEvent>;
|
|
259
|
-
}
|
|
260
|
-
export type ProviderResolver = (model: ModelConfig) => AIProvider | undefined;
|
|
261
|
-
/** Realtime audio/session event. Realtime is a bidirectional session, not a request/response
|
|
262
|
-
* stream, so it is a separate neutral seam from `AIProvider.generate()`. Credentials are
|
|
263
|
-
* bound to the session handshake only and never appear in events. */
|
|
264
|
-
export interface RealtimeSession {
|
|
265
|
-
readonly id: string;
|
|
266
|
-
readonly provider: string;
|
|
267
|
-
/** Send an audio chunk (PCM/Opus; provider-specific format set at creation). */
|
|
268
|
-
sendAudio(chunk: Uint8Array, options?: {
|
|
269
|
-
readonly signal?: AbortSignal;
|
|
270
|
-
}): Promise<void>;
|
|
271
|
-
/** Inbound events (audio out, transcripts, hosted tool calls, interruption, close, error). */
|
|
272
|
-
events(): AsyncIterable<RealtimeEvent>;
|
|
273
|
-
/** Request the provider stop the current response mid-stream. */
|
|
274
|
-
interrupt(options?: {
|
|
275
|
-
readonly signal?: AbortSignal;
|
|
276
|
-
}): Promise<void>;
|
|
277
|
-
/** Close the session and release the transport. Idempotent. */
|
|
278
|
-
close(reason?: string, options?: {
|
|
279
|
-
readonly signal?: AbortSignal;
|
|
280
|
-
}): Promise<void>;
|
|
281
|
-
}
|
|
282
|
-
/** Factory a provider exposes for realtime sessions; not part of `AIProvider`. */
|
|
283
|
-
export type RealtimeSessionFactory = (options: RealtimeSessionOptions) => RealtimeSession;
|
|
284
|
-
export interface RealtimeSessionOptions {
|
|
285
|
-
readonly model: ModelConfig;
|
|
286
|
-
readonly signal?: AbortSignal;
|
|
287
|
-
/** Provider-specific caps override; providers enforce finite defaults. */
|
|
288
|
-
readonly caps?: RealtimeCaps;
|
|
289
|
-
}
|
|
290
|
-
export interface RealtimeCaps {
|
|
291
|
-
readonly maxAudioEventsPerSecond?: number;
|
|
292
|
-
readonly maxBytesPerSecond?: number;
|
|
293
|
-
readonly maxWallMs?: number;
|
|
294
|
-
}
|
|
295
|
-
export interface AgentDefinition {
|
|
296
|
-
readonly name: string;
|
|
297
|
-
readonly description?: string;
|
|
298
|
-
/** Direct model config, or a model id resolved from `registries.models`. */
|
|
299
|
-
readonly model?: ModelConfig | string;
|
|
300
|
-
/** Tool names to activate from the active tool registry / `registries.tools`. */
|
|
301
|
-
readonly tools?: readonly string[];
|
|
302
|
-
/** Skill names resolved through `resolveActiveSkills()`; `toolNames` enforcement applies. */
|
|
303
|
-
readonly skills?: readonly string[];
|
|
304
|
-
/** Context provider names from `registries.contextProviders`. */
|
|
305
|
-
readonly context?: readonly string[];
|
|
306
|
-
readonly systemPrompt?: SystemPromptConfig;
|
|
307
|
-
readonly instructions?: string;
|
|
308
|
-
readonly loop?: AgentLoopStrategy | AgentLoopOptions;
|
|
309
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
310
|
-
/** Optional escape hatch. When present, overrides declarative resolution. */
|
|
311
|
-
create?(config?: AgentConfig): Promise<Agent> | Agent;
|
|
312
|
-
}
|
|
313
|
-
/** Input to {@link resolveAgentDefinition}. All fields are optional; the host
|
|
314
|
-
* controls scope by which registries it passes. */
|
|
315
|
-
export interface AgentDefinitionResolutionContext {
|
|
316
|
-
readonly registries?: ContributionRegistries;
|
|
317
|
-
readonly providerSource?: ProviderResolver;
|
|
318
|
-
readonly tools?: ToolRegistry | readonly ToolDefinition[];
|
|
319
|
-
readonly skillsRegistry?: SkillRegistry;
|
|
320
|
-
/** Migration-only: omitted `tools`/`skills` activate every in-scope tool/skill. Defaults to fail-closed. */
|
|
321
|
-
readonly activateAllCapabilities?: true;
|
|
322
|
-
readonly overrides?: Partial<AgentConfig>;
|
|
323
|
-
}
|
|
324
|
-
export interface AgentConfig {
|
|
325
|
-
readonly id?: string;
|
|
326
|
-
readonly name?: string;
|
|
327
|
-
readonly instructions?: string;
|
|
328
|
-
readonly model: ModelConfig;
|
|
329
|
-
readonly provider?: AIProvider;
|
|
330
|
-
readonly providerSource?: ProviderResolver;
|
|
331
|
-
readonly tools?: ToolRegistry | readonly ToolDefinition[];
|
|
332
|
-
readonly context?: readonly ContextProvider[];
|
|
333
|
-
readonly skills?: SkillRegistry | readonly Skill[];
|
|
334
|
-
/** Migration opt-in: activate every registry skill by default when run options do not narrow activation. */
|
|
335
|
-
readonly activateAllSkills?: true;
|
|
336
|
-
/** Progressive: catalog (name+description) unless loaded; eager: full instructions every turn. Default progressive. */
|
|
337
|
-
readonly skillsDisclosure?: import("./skill-disclosure.js").SkillsDisclosure;
|
|
338
|
-
/** Opt-in projection-only fold for aged large tool results in provider view; store untouched. */
|
|
339
|
-
readonly toolResultFold?: import("./tool-result-fold.js").ToolResultFoldOptions;
|
|
340
|
-
readonly inputBuilder?: InputBuilder;
|
|
341
|
-
readonly promptBuilder?: PromptBuilder;
|
|
342
|
-
readonly middleware?: MiddlewareRegistry;
|
|
343
|
-
readonly resourceLoader?: ResourceLoader;
|
|
344
|
-
readonly store?: SessionStore;
|
|
345
|
-
readonly permission?: PermissionPolicy;
|
|
346
|
-
/** Optional trust check for tool and resource targets. */
|
|
347
|
-
readonly trust?: TrustPolicy;
|
|
348
|
-
readonly providerOptions?: ProviderRequestOptions;
|
|
349
|
-
readonly providerRequestPolicies?: ProviderRequestPolicy | readonly ProviderRequestPolicy[];
|
|
350
|
-
readonly systemPrompt?: SystemPromptConfig;
|
|
351
|
-
readonly redactor?: SecretRedactor;
|
|
352
|
-
readonly runLedger?: RunLedger;
|
|
353
|
-
/** Optional durable recovery store. */
|
|
354
|
-
readonly effectStore?: ToolEffectStore;
|
|
355
|
-
readonly ownership?: OwnershipScope;
|
|
356
|
-
/** Host-verified identity default for sessions created from this agent. */
|
|
357
|
-
readonly identity?: import("./identity.js").AgentIdentity;
|
|
358
|
-
readonly idempotencyKey?: string;
|
|
359
|
-
readonly compaction?: false | CompactionOptions;
|
|
360
|
-
readonly retry?: false | RetryOptions;
|
|
361
|
-
/** Agent-wide ceilings; per-run limits may only narrow these values. */
|
|
362
|
-
readonly limits?: RunLimits;
|
|
363
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
364
|
-
readonly validator?: ToolValidator;
|
|
365
|
-
readonly instructionInjectors?: readonly InstructionInjector[];
|
|
366
|
-
readonly inputLayout?: InputAssemblyLayout;
|
|
367
|
-
readonly loop?: AgentLoopStrategy | AgentLoopOptions;
|
|
368
|
-
readonly guardrails?: Guardrails;
|
|
369
|
-
/** Opt-in durable interruption/checkpointing default for this agent. */
|
|
370
|
-
readonly runState?: AgentRunStateOptions;
|
|
371
|
-
/** Internal marker set by createSecureAgent(); makes security defaults immutable per run. */
|
|
372
|
-
readonly secure?: true;
|
|
373
|
-
}
|
|
374
|
-
/** Opt-in fail-closed composition over the normal explicit AgentConfig API. */
|
|
375
|
-
export interface SecureAgentOptions extends Omit<AgentConfig, "tools" | "validator" | "redactor" | "permission" | "trust" | "ownership" | "identity" | "limits" | "runState" | "secure"> {
|
|
376
|
-
readonly id: string;
|
|
377
|
-
readonly tools: readonly ToolDefinition[];
|
|
378
|
-
readonly toolArgumentValidator: import("./tools.js").ToolArgumentValidator;
|
|
379
|
-
readonly redactor: SecretRedactor;
|
|
380
|
-
readonly permission: PermissionPolicy;
|
|
381
|
-
readonly trust: TrustPolicy;
|
|
382
|
-
readonly ownership: OwnershipScope;
|
|
383
|
-
/** Optional host-verified identity; when set must match `ownership`. */
|
|
384
|
-
readonly identity?: import("./identity.js").AgentIdentity;
|
|
385
|
-
readonly limits: RunLimits;
|
|
386
|
-
readonly definitionRevision: string;
|
|
387
|
-
readonly runState: Omit<AgentRunStateOptions, "definitionRevision" | "interruptBeforeTool">;
|
|
388
|
-
}
|
|
389
|
-
export interface Agent {
|
|
390
|
-
readonly config: AgentConfig;
|
|
391
|
-
createSession(config?: AgentSessionConfig): AgentSession;
|
|
392
|
-
}
|
|
393
|
-
export interface AgentSessionConfig {
|
|
394
|
-
readonly id?: string;
|
|
395
|
-
readonly agent?: Agent;
|
|
396
|
-
readonly store?: SessionStore;
|
|
397
|
-
readonly leafId?: string;
|
|
398
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
399
|
-
}
|
|
400
|
-
export interface AgentSessionForkOptions {
|
|
401
|
-
readonly leafId?: string;
|
|
402
|
-
}
|
|
403
|
-
export interface AgentSessionCloneOptions {
|
|
404
|
-
readonly id?: string;
|
|
405
|
-
readonly leafId?: string;
|
|
406
|
-
}
|
|
407
|
-
export type SubscriberOverflowPolicy = "close" | "drop_oldest" | "drop_newest";
|
|
408
|
-
export interface SubscribeOptions {
|
|
409
|
-
/** Maximum queued events for a subscriber that is not actively awaiting `next()`. Defaults to 1024. */
|
|
410
|
-
readonly maxQueuedEvents?: number;
|
|
411
|
-
/** What to do when `maxQueuedEvents` is reached. Defaults to `close`. */
|
|
412
|
-
readonly overflow?: SubscriberOverflowPolicy;
|
|
413
|
-
}
|
|
414
|
-
export interface CommandDefinition {
|
|
415
|
-
readonly name: string;
|
|
416
|
-
readonly description?: string;
|
|
417
|
-
readonly parameters?: JsonObject;
|
|
418
|
-
execute(args: JsonObject, context: CommandExecutionContext): Promise<CommandResult> | CommandResult;
|
|
419
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
420
|
-
}
|
|
421
|
-
export interface CommandExecutionContext {
|
|
422
|
-
readonly sessionId?: string;
|
|
423
|
-
readonly runId?: string;
|
|
424
|
-
readonly signal?: AbortSignal;
|
|
425
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
426
|
-
}
|
|
427
|
-
export interface CommandResult {
|
|
428
|
-
readonly name: string;
|
|
429
|
-
readonly content?: readonly ContentBlock[];
|
|
430
|
-
readonly value?: unknown;
|
|
431
|
-
readonly error?: ErrorInfo;
|
|
432
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
433
|
-
}
|
|
434
|
-
export interface ContextBlock {
|
|
435
|
-
readonly id?: string;
|
|
436
|
-
readonly title?: string;
|
|
437
|
-
readonly content: string | readonly ContentBlock[];
|
|
438
|
-
readonly priority?: number;
|
|
439
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
440
|
-
}
|
|
441
|
-
export interface ContextProvider {
|
|
442
|
-
readonly name: string;
|
|
443
|
-
resolve(context: ContextResolutionContext): Promise<readonly ContextBlock[]> | readonly ContextBlock[];
|
|
444
|
-
}
|
|
445
|
-
export interface ContextResolutionContext {
|
|
446
|
-
readonly sessionId?: string;
|
|
447
|
-
readonly runId?: string;
|
|
448
|
-
readonly messages: readonly Message[];
|
|
449
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
450
|
-
readonly signal?: AbortSignal;
|
|
451
|
-
}
|
|
452
|
-
/** When an {@link InstructionInjector} contributes to the assembled provider input. */
|
|
453
|
-
export type InstructionTiming = "first_turn" | "every_turn" | "on_input";
|
|
454
|
-
/** Runtime turn scope handed to an {@link InstructionInjector}. Mirrors {@link LoopContext}
|
|
455
|
-
* scope using already-redacted input/history so predicates cannot recover secrets. */
|
|
456
|
-
export interface InstructionContext {
|
|
457
|
-
readonly sessionId: string;
|
|
458
|
-
readonly runId: string;
|
|
459
|
-
readonly turn: number;
|
|
460
|
-
readonly input: readonly Message[];
|
|
461
|
-
readonly history: readonly Message[];
|
|
462
|
-
readonly metadata: Readonly<Record<string, unknown>>;
|
|
463
|
-
readonly signal: AbortSignal;
|
|
464
|
-
}
|
|
465
|
-
/** Output of an {@link InstructionInjector}. Only `instructions` and `contextBlocks` are
|
|
466
|
-
* honored; other fields grant nothing (no tools, skills, or permissions). */
|
|
467
|
-
export interface InstructionContribution {
|
|
468
|
-
readonly instructions?: string;
|
|
469
|
-
readonly contextBlocks?: readonly ContextBlock[];
|
|
470
|
-
readonly when: InstructionTiming;
|
|
471
|
-
/** Used only when `when === "on_input"`; absent predicate means apply every turn. */
|
|
472
|
-
readonly predicate?: (ctx: InstructionContext) => boolean;
|
|
473
|
-
}
|
|
474
|
-
/** Additive instruction/context contribution that a package registers through
|
|
475
|
-
* {@link ExtensionAPI.registerInstructionInjector} and the host selects on
|
|
476
|
-
* {@link AgentConfig.instructionInjectors} / {@link RunOptions.instructionInjectors}.
|
|
477
|
-
* Inert until selected; cannot grant privileges beyond text/context blocks. */
|
|
478
|
-
export interface InstructionInjector {
|
|
479
|
-
readonly name: string;
|
|
480
|
-
readonly description?: string;
|
|
481
|
-
apply(ctx: InstructionContext): InstructionContribution;
|
|
482
|
-
}
|
|
483
|
-
export interface InputBuilder {
|
|
484
|
-
readonly name: string;
|
|
485
|
-
build(input: string | Message | readonly Message[], context?: InputBuildContext): Promise<readonly Message[]> | readonly Message[];
|
|
486
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
487
|
-
}
|
|
488
|
-
export interface InputBuildContext {
|
|
489
|
-
readonly inputLayout?: InputAssemblyLayout;
|
|
490
|
-
readonly sessionId?: string;
|
|
491
|
-
readonly runId?: string;
|
|
492
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
493
|
-
readonly signal?: AbortSignal;
|
|
494
|
-
readonly permission?: PermissionPolicy;
|
|
495
|
-
readonly trust?: TrustPolicy;
|
|
496
|
-
}
|
|
497
|
-
export interface PromptBuilder {
|
|
498
|
-
readonly name: string;
|
|
499
|
-
build(request: PromptBuildRequest): Promise<readonly Message[]> | readonly Message[];
|
|
500
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
501
|
-
}
|
|
502
|
-
export interface PromptBuildRequest {
|
|
503
|
-
readonly messages: readonly Message[];
|
|
504
|
-
readonly context?: readonly ContextBlock[];
|
|
505
|
-
readonly skills?: readonly Skill[];
|
|
506
|
-
readonly skillsDisclosure?: import("./skill-disclosure.js").SkillsDisclosure;
|
|
507
|
-
readonly loadedSkills?: import("./skill-disclosure.js").LoadedSkillSet;
|
|
508
|
-
/** Skills demoted to catalog-only by context budget this turn. */
|
|
509
|
-
readonly demotedSkillBodies?: readonly string[];
|
|
510
|
-
readonly tools?: readonly ToolDefinition[];
|
|
511
|
-
/** Model being prompted; lets builders adapt composition to declared capabilities
|
|
512
|
-
* (e.g. the default builder omits the `Available tools:` text for tool-capable models). */
|
|
513
|
-
readonly model?: ModelConfig;
|
|
514
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
515
|
-
readonly signal?: AbortSignal;
|
|
516
|
-
}
|
|
517
|
-
export interface Skill {
|
|
518
|
-
readonly name: string;
|
|
519
|
-
readonly description?: string;
|
|
520
|
-
readonly instructions?: string;
|
|
521
|
-
readonly context?: readonly ContextProvider[];
|
|
522
|
-
readonly toolNames?: readonly string[];
|
|
523
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
524
|
-
}
|
|
525
|
-
export interface SkillRegistry {
|
|
526
|
-
register(skill: Skill): void;
|
|
527
|
-
get(name: string): Skill | undefined;
|
|
528
|
-
resolve(name: string): Skill;
|
|
529
|
-
list(): readonly Skill[];
|
|
530
|
-
}
|
|
531
|
-
/** Directory-name spelling for discovered contribution kinds. Maps to a
|
|
532
|
-
* {@link ManifestContributionDeclaration} kind for non-skill kinds:
|
|
533
|
-
* `context` → `contextProvider`, `instructions` → `systemPromptContribution`. */
|
|
534
|
-
export type ContributionFileKind = "skill" | "tool" | "context" | "instructions";
|
|
535
|
-
/** Inert envelope emitted by the host/CLI discovery scanner. Carries the
|
|
536
|
-
* realized {@link Skill} for skill kinds and a manifest-referenced
|
|
537
|
-
* {@link ManifestContributionDeclaration} for other kinds; the host owns
|
|
538
|
-
* any executable behavior. Contains no code, no credential. */
|
|
539
|
-
export interface DiscoveredContribution {
|
|
540
|
-
readonly kind: ContributionFileKind;
|
|
541
|
-
readonly name: string;
|
|
542
|
-
readonly origin: "global" | "workspace";
|
|
543
|
-
readonly path: string;
|
|
544
|
-
/** Present when `kind === "skill"`. */
|
|
545
|
-
readonly skill?: Skill;
|
|
546
|
-
/** Present for non-skill kinds. */
|
|
547
|
-
readonly declaration?: ManifestContributionDeclaration;
|
|
548
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
549
|
-
}
|
|
550
|
-
export type ExtensionLifecycleEventName = "resource_discovery" | "session_start" | "session_shutdown" | "before_agent_start" | "turn" | "context" | "provider_request" | "tool_call" | "tool_result" | "compaction" | "retry";
|
|
551
|
-
export interface ExtensionEvent {
|
|
552
|
-
readonly type: ExtensionLifecycleEventName | "extension_error" | string;
|
|
553
|
-
readonly payload?: unknown;
|
|
554
|
-
readonly extension?: string;
|
|
555
|
-
readonly error?: ErrorInfo;
|
|
556
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
557
|
-
}
|
|
558
|
-
export interface Extension {
|
|
559
|
-
readonly name: string;
|
|
560
|
-
setup(api: ExtensionAPI): void | Promise<void>;
|
|
561
|
-
/** Host-attested signature/digest for `ExtensionLoadPolicy.verifySignature`. */
|
|
562
|
-
readonly signature?: string;
|
|
563
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
564
|
-
}
|
|
565
|
-
export interface ProviderPackage {
|
|
566
|
-
readonly name: string;
|
|
567
|
-
readonly version?: string;
|
|
568
|
-
readonly description?: string;
|
|
569
|
-
readonly docs?: ProviderPackageDocs;
|
|
570
|
-
setup(api: ProviderPackageAPI): void | Promise<void>;
|
|
571
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
572
|
-
}
|
|
573
|
-
export interface ProviderPackageDocs {
|
|
574
|
-
readonly description?: string;
|
|
575
|
-
readonly links?: readonly string[];
|
|
576
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
577
|
-
}
|
|
578
|
-
export interface ProviderPackageAPI extends ExtensionAPI {
|
|
579
|
-
}
|
|
580
|
-
export type AuthMethod = ApiKeyAuthMethod | OAuthAuthMethod | CustomAuthMethod;
|
|
581
|
-
export interface ApiKeyAuthMethod {
|
|
582
|
-
readonly kind: "api_key";
|
|
583
|
-
readonly provider: string;
|
|
584
|
-
readonly name?: string;
|
|
585
|
-
readonly credentialName?: string;
|
|
586
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
587
|
-
}
|
|
588
|
-
export interface OAuthAuthMethod {
|
|
589
|
-
readonly kind: "oauth";
|
|
590
|
-
readonly provider: string;
|
|
591
|
-
readonly name?: string;
|
|
592
|
-
readonly oauth?: OAuthProvider;
|
|
593
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
594
|
-
}
|
|
595
|
-
export interface OAuthLoginCallbacks {
|
|
596
|
-
onAuth?(url: string): void | Promise<void>;
|
|
597
|
-
onDeviceCode?(code: {
|
|
598
|
-
readonly userCode: string;
|
|
599
|
-
readonly verificationUri: string;
|
|
600
|
-
readonly expiresAt?: string;
|
|
601
|
-
}): void | Promise<void>;
|
|
602
|
-
onPrompt?(message: string): string | undefined | Promise<string | undefined>;
|
|
603
|
-
onSelect?(prompt: {
|
|
604
|
-
readonly message: string;
|
|
605
|
-
readonly choices: readonly string[];
|
|
606
|
-
}): string | undefined | Promise<string | undefined>;
|
|
607
|
-
/** Aborts OAuth login flows and device-code polling when signaled. */
|
|
608
|
-
readonly signal?: AbortSignal;
|
|
609
|
-
}
|
|
610
|
-
export interface OAuthCredentials {
|
|
611
|
-
readonly access?: string;
|
|
612
|
-
readonly refresh?: string;
|
|
613
|
-
readonly expires?: string | number;
|
|
614
|
-
readonly accountId?: string;
|
|
615
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
616
|
-
}
|
|
617
|
-
export interface OAuthProvider {
|
|
618
|
-
readonly id: string;
|
|
619
|
-
login(callbacks?: OAuthLoginCallbacks): Promise<OAuthCredentials> | OAuthCredentials;
|
|
620
|
-
refresh?(credentials: OAuthCredentials): Promise<OAuthCredentials> | OAuthCredentials;
|
|
621
|
-
/** Best-effort upstream revocation; the store delete is what fails closed locally. */
|
|
622
|
-
revoke?(credentials: OAuthCredentials): Promise<void> | void;
|
|
623
|
-
getCredential?(credentials: OAuthCredentials): Promise<Credential | undefined> | Credential | undefined;
|
|
624
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
625
|
-
}
|
|
626
|
-
export interface CustomAuthMethod {
|
|
627
|
-
readonly kind: "custom" | string;
|
|
628
|
-
readonly provider: string;
|
|
629
|
-
readonly name?: string;
|
|
630
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
631
|
-
}
|
|
632
|
-
export interface ProviderRequestPolicy {
|
|
633
|
-
readonly name: string;
|
|
634
|
-
apply(context: ProviderRequestPolicyContext): Promise<ProviderRequest | ProviderRequestPolicyResult> | ProviderRequest | ProviderRequestPolicyResult;
|
|
635
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
636
|
-
}
|
|
637
|
-
export interface ProviderRequestPolicyContext {
|
|
638
|
-
readonly request: ProviderRequest;
|
|
639
|
-
readonly sessionId?: string;
|
|
640
|
-
readonly runId?: string;
|
|
641
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
642
|
-
readonly signal?: AbortSignal;
|
|
643
|
-
}
|
|
644
|
-
export interface ProviderRequestPolicyResult {
|
|
645
|
-
readonly request: ProviderRequest;
|
|
646
|
-
readonly secrets?: readonly (string | undefined)[];
|
|
647
|
-
}
|
|
648
|
-
export type SystemPromptMode = "append" | "prepend" | "replace" | "disable";
|
|
649
|
-
export type SystemPromptSource = "package" | "app" | "user" | "run" | string;
|
|
650
|
-
export interface SystemPromptContribution {
|
|
651
|
-
readonly id: string;
|
|
652
|
-
readonly source?: SystemPromptSource;
|
|
653
|
-
readonly mode?: SystemPromptMode;
|
|
654
|
-
readonly text: string;
|
|
655
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
656
|
-
}
|
|
657
|
-
export type SystemPromptConfig = false | SystemPromptContribution | readonly SystemPromptContribution[];
|
|
658
|
-
export interface ExtensionAPI {
|
|
659
|
-
readonly registries: ContributionRegistries;
|
|
660
|
-
readonly middleware: MiddlewareRegistry;
|
|
661
|
-
on(type: ExtensionLifecycleEventName | string, handler: (event: ExtensionEvent) => void | Promise<void>): () => void;
|
|
662
|
-
emit(event: ExtensionEvent): Promise<void>;
|
|
663
|
-
use<T>(hook: MiddlewareHookName | string, middleware: Middleware<T>): () => void;
|
|
664
|
-
registerProvider(provider: AIProvider): void;
|
|
665
|
-
registerModel(model: ModelConfig): void;
|
|
666
|
-
registerTool(tool: ToolDefinition): void;
|
|
667
|
-
registerContextProvider(provider: ContextProvider): void;
|
|
668
|
-
registerSkill(skill: Skill): void;
|
|
669
|
-
registerCommand(command: CommandDefinition): void;
|
|
670
|
-
registerAgent(agent: AgentDefinition): void;
|
|
671
|
-
registerInputBuilder(builder: InputBuilder): void;
|
|
672
|
-
registerPromptBuilder(builder: PromptBuilder): void;
|
|
673
|
-
registerCompactionStrategy(strategy: CompactionStrategy): void;
|
|
674
|
-
registerRetryPolicy(policy: RetryPolicy): void;
|
|
675
|
-
registerStoreFactory(factory: StoreFactory): void;
|
|
676
|
-
registerResourceLoader(key: string, loader: ResourceLoader): void;
|
|
677
|
-
registerSettingsProvider(key: string, provider: SettingsProvider): void;
|
|
678
|
-
registerCredentialResolver(key: string, resolver: CredentialResolver): void;
|
|
679
|
-
registerProviderPackage(providerPackage: ProviderPackage): void;
|
|
680
|
-
registerAuthMethod(method: AuthMethod): void;
|
|
681
|
-
registerProviderRequestPolicy(policy: ProviderRequestPolicy): void;
|
|
682
|
-
registerSystemPromptContribution(contribution: SystemPromptContribution): void;
|
|
683
|
-
registerInstructionInjector(injector: InstructionInjector): void;
|
|
684
|
-
}
|
|
685
|
-
export type SessionEntryKind = "message" | "event" | "summary" | "metadata" | "model_change" | "label" | "custom" | "compaction";
|
|
686
|
-
export declare const SESSION_ENTRY_KINDS: readonly SessionEntryKind[];
|
|
687
|
-
export declare const SESSION_ENTRY_SCHEMA_VERSION = 1;
|
|
688
|
-
export declare function isSessionEntryKind(value: unknown): value is SessionEntryKind;
|
|
689
|
-
export interface SessionEntry {
|
|
690
|
-
readonly id: string;
|
|
691
|
-
readonly parentId?: string;
|
|
692
|
-
readonly sessionId: string;
|
|
693
|
-
readonly timestamp: string;
|
|
694
|
-
readonly kind: SessionEntryKind;
|
|
695
|
-
readonly schemaVersion?: 1;
|
|
696
|
-
readonly runId?: string;
|
|
697
|
-
readonly message?: Message;
|
|
698
|
-
readonly event?: AgentEvent;
|
|
699
|
-
readonly model?: ModelConfig;
|
|
700
|
-
readonly previousModel?: ModelConfig;
|
|
701
|
-
readonly label?: string;
|
|
702
|
-
readonly summary?: string;
|
|
703
|
-
readonly data?: unknown;
|
|
704
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
705
|
-
}
|
|
706
|
-
export interface SessionStore {
|
|
707
|
-
append(entry: SessionEntry, options?: SessionAppendOptions): Promise<void>;
|
|
708
|
-
list(sessionId: string): Promise<readonly SessionEntry[]>;
|
|
709
|
-
get?(id: string): Promise<SessionEntry | undefined>;
|
|
710
|
-
/** DB-friendly branch read: return one branch's ancestor chain as a page so adapters
|
|
711
|
-
* avoid `list(sessionId)` (full-session scan) + in-memory rebuild. Optional — the
|
|
712
|
-
* built-in memory/JSONL stores omit it and the runtime falls back to `list()`. */
|
|
713
|
-
readBranchPath?(query: SessionBranchRead): Promise<PersistencePage<SessionEntry>>;
|
|
714
|
-
/**
|
|
715
|
-
* Optional bounded session search. Prefer implementing this **or** returning a companion
|
|
716
|
-
* `SessionIndex` from the adapter factory — hosts must not need both. Call
|
|
717
|
-
* `resolveSessionSearchQuery` before scan/query. Memory defaults to capped linear
|
|
718
|
-
* search (`sessionSearchMode: "unsupported"` throws). JSONL throws unsupported.
|
|
719
|
-
*/
|
|
720
|
-
searchSessions?(query: SessionSearchQuery): Promise<PersistencePage<SessionSearchHit>>;
|
|
721
|
-
}
|
|
722
|
-
/** Host-written `SessionRecord.metadata` / session metadata key for workspace filtering. */
|
|
723
|
-
export declare const SESSION_SEARCH_WORKSPACE_METADATA_KEY: "workspaceRoot";
|
|
724
|
-
export declare const DEFAULT_SESSION_SEARCH_LIMIT = 20;
|
|
725
|
-
export declare const HARD_MAX_SESSION_SEARCH_LIMIT = 100;
|
|
726
|
-
export declare const DEFAULT_MAX_SESSION_SEARCH_QUERY_BYTES: number;
|
|
727
|
-
export declare const HARD_MAX_SESSION_SEARCH_QUERY_BYTES: number;
|
|
728
|
-
export declare const DEFAULT_MAX_SESSION_SEARCH_SNIPPET_BYTES = 512;
|
|
729
|
-
export declare const HARD_MAX_SESSION_SEARCH_SNIPPET_BYTES: number;
|
|
730
|
-
export declare const DEFAULT_MAX_SESSION_SEARCH_CURSOR_BYTES: number;
|
|
731
|
-
export declare const HARD_MAX_SESSION_SEARCH_CURSOR_BYTES: number;
|
|
732
|
-
export declare const DEFAULT_MAX_SESSION_SEARCH_LINEAR_SESSIONS = 1000;
|
|
733
|
-
export declare const HARD_MAX_SESSION_SEARCH_LINEAR_SESSIONS = 5000;
|
|
734
|
-
export declare const DEFAULT_MAX_SESSION_SEARCH_LINEAR_ENTRIES = 10000;
|
|
735
|
-
export declare const HARD_MAX_SESSION_SEARCH_LINEAR_ENTRIES = 50000;
|
|
736
|
-
export declare const DEFAULT_MAX_SESSION_SEARCH_LINEAR_BYTES: number;
|
|
737
|
-
export declare const HARD_MAX_SESSION_SEARCH_LINEAR_BYTES: number;
|
|
738
|
-
export declare const DEFAULT_MAX_SESSION_SEARCH_FTS_CANDIDATES = 1000;
|
|
739
|
-
export declare const HARD_MAX_SESSION_SEARCH_FTS_CANDIDATES = 5000;
|
|
740
|
-
/** Bounded session search filters. Workspace matches host-written `metadata.workspaceRoot`. */
|
|
741
|
-
export interface SessionSearchQuery extends PersistenceQuery, OwnershipScope {
|
|
742
|
-
readonly workspaceRoot?: string;
|
|
743
|
-
/** Optional full-text / message+summary query (adapter-defined matching). */
|
|
744
|
-
readonly query?: string;
|
|
745
|
-
readonly provider?: string;
|
|
746
|
-
readonly model?: string;
|
|
747
|
-
readonly label?: string;
|
|
748
|
-
readonly summary?: string;
|
|
749
|
-
readonly fromUpdatedAt?: string;
|
|
750
|
-
readonly toUpdatedAt?: string;
|
|
751
|
-
readonly signal?: AbortSignal;
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Safe search hit for resume/checkout. Never includes credentials or raw full transcripts.
|
|
755
|
-
* `leafId` is the branch tip for `session.checkout` when known.
|
|
756
|
-
*/
|
|
757
|
-
export interface SessionSearchHit {
|
|
758
|
-
readonly sessionId: string;
|
|
759
|
-
readonly leafId?: string;
|
|
760
|
-
readonly updatedAt?: string;
|
|
761
|
-
readonly label?: string;
|
|
762
|
-
readonly summary?: string;
|
|
763
|
-
readonly snippet?: string;
|
|
764
|
-
/** Safe display fields only (e.g. workspaceRoot); never credentials. */
|
|
765
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
766
|
-
}
|
|
767
|
-
/** Narrow search seam; adapters may implement this instead of `SessionStore.searchSessions`. */
|
|
768
|
-
export interface SessionIndex {
|
|
769
|
-
search(query: SessionSearchQuery): Promise<PersistencePage<SessionSearchHit>>;
|
|
770
|
-
}
|
|
771
|
-
/** Validated search query with finite `limit` / `order` filled in. */
|
|
772
|
-
export interface ResolvedSessionSearchQuery extends SessionSearchQuery {
|
|
773
|
-
readonly limit: number;
|
|
774
|
-
readonly order: "asc" | "desc";
|
|
775
|
-
}
|
|
776
|
-
/**
|
|
777
|
-
* O(1) validation before any scan/query. Applies default page limit; rejects NaN,
|
|
778
|
-
* non-positive limits, oversize query/cursor/filter strings, and invalid order.
|
|
779
|
-
*/
|
|
780
|
-
export declare function resolveSessionSearchQuery(query: SessionSearchQuery): ResolvedSessionSearchQuery;
|
|
781
|
-
export declare const SESSION_SEARCH_UNSUPPORTED_CODE: "session_search_unsupported";
|
|
782
|
-
/** Thrown when a store opts out of `searchSessions` (memory `unsupported`, JSONL). */
|
|
783
|
-
export declare class SessionSearchUnsupportedError extends Error {
|
|
784
|
-
readonly code: "session_search_unsupported";
|
|
785
|
-
constructor(message?: string);
|
|
786
|
-
}
|
|
787
|
-
export declare function isSessionSearchUnsupported(error: unknown): error is SessionSearchUnsupportedError;
|
|
788
|
-
/** Query for a single branch's ancestor chain (DB-friendly: one recursive/ancestor query
|
|
789
|
-
* instead of a full-session scan). Honored by `SessionStore.readBranchPath` and the pure
|
|
790
|
-
* branch helpers' reader overload. `leafId` is optional (omit for the latest leaf). */
|
|
791
|
-
export interface SessionBranchRead {
|
|
792
|
-
readonly sessionId: string;
|
|
793
|
-
readonly leafId?: string;
|
|
794
|
-
readonly cursor?: string;
|
|
795
|
-
readonly limit?: number;
|
|
796
|
-
}
|
|
797
|
-
/** Database-neutral callable returning one branch's ancestor chain as a page. Implementations
|
|
798
|
-
* issue a single recursive CTE / ancestor walk; the pure helpers follow `nextCursor` to
|
|
799
|
-
* completion. Returns redacted `SessionEntry` values only (stores already persist redacted
|
|
800
|
-
* entries; the runtime redacts before append). */
|
|
801
|
-
export type BranchReader = (query: SessionBranchRead) => Promise<PersistencePage<SessionEntry>>;
|
|
802
|
-
/**
|
|
803
|
-
* Options for `SessionStore.append`. Stores that honor them reject dangling
|
|
804
|
-
* `expectedParentId` values and deduplicate exact retries by `idempotencyKey` +
|
|
805
|
-
* parent. Production stores may add stricter branch-tip CAS and report
|
|
806
|
-
* `currentLeafId` in `SessionAppendConflictError`. `idempotencyKey` is an opaque
|
|
807
|
-
* host string; stores redact it like metadata when persisted. Carries no
|
|
808
|
-
* credentials, credential resolvers, provider instances, or unredacted secrets.
|
|
809
|
-
*/
|
|
810
|
-
export interface SessionAppendOptions {
|
|
811
|
-
/** Parent entry the new entry should attach to. Must exist when provided. */
|
|
812
|
-
readonly expectedParentId?: string;
|
|
813
|
-
/** Opaque host idempotency key; exact retries for one parent deduplicate. */
|
|
814
|
-
readonly idempotencyKey?: string;
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Durable pointer to a branch tip. One session may own many handles (one per
|
|
818
|
-
* leaf). `BranchRecord.leafEntryId` is the persistence-side equivalent.
|
|
819
|
-
*/
|
|
820
|
-
export interface SessionBranchHandle {
|
|
821
|
-
readonly sessionId: string;
|
|
822
|
-
readonly leafId: string;
|
|
823
|
-
}
|
|
824
|
-
/** Stable error code carried by `SessionAppendConflictError`. */
|
|
825
|
-
export declare const SESSION_APPEND_CONFLICT_CODE: "session_append_conflict";
|
|
826
|
-
/** CAS conflict code for `appendSession` metadata writes. Stable and message-independent. */
|
|
827
|
-
export declare const SESSION_METADATA_CONFLICT_CODE: "metadata_conflict";
|
|
828
|
-
/** Conflict details carried by `SessionMetadataConflictError`. Versions only; never metadata content. */
|
|
829
|
-
export interface SessionMetadataConflict {
|
|
830
|
-
readonly code: typeof SESSION_METADATA_CONFLICT_CODE;
|
|
831
|
-
readonly id: string;
|
|
832
|
-
readonly expectedVersion: number;
|
|
833
|
-
readonly currentVersion: number;
|
|
834
|
-
}
|
|
835
|
-
/**
|
|
836
|
-
* Thrown when `appendSession` is called with an `expectedVersion` CAS guard and the
|
|
837
|
-
* stored session's version no longer matches (concurrent create/branch/archive, or a
|
|
838
|
-
* delete raced the write). Recognize via the stable `code` or `isSessionMetadataConflict`.
|
|
839
|
-
*/
|
|
840
|
-
export declare class SessionMetadataConflictError extends Error {
|
|
841
|
-
readonly conflict: SessionMetadataConflict;
|
|
842
|
-
readonly code: "metadata_conflict";
|
|
843
|
-
constructor(conflict: SessionMetadataConflict);
|
|
844
|
-
}
|
|
845
|
-
/** Type guard keyed off the stable `code` (works across bundles; not message text). */
|
|
846
|
-
export declare function isSessionMetadataConflict(error: unknown): error is SessionMetadataConflictError;
|
|
847
|
-
/** Conflict details carried by `SessionAppendConflictError`. Carries no secrets. */
|
|
848
|
-
export interface SessionAppendConflict {
|
|
849
|
-
readonly code: typeof SESSION_APPEND_CONFLICT_CODE;
|
|
850
|
-
readonly expectedParentId?: string;
|
|
851
|
-
readonly currentLeafId?: string;
|
|
852
|
-
readonly idempotencyDuplicate?: boolean;
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
* Thrown when `SessionStore.append` rejects an entry under `SessionAppendOptions`
|
|
856
|
-
* (dangling/stale `expectedParentId`, stricter adapter CAS failure, or duplicate
|
|
857
|
-
* idempotency key for the same parent). Recognize via the stable `code` and
|
|
858
|
-
* `isSessionAppendConflict`, not message text.
|
|
859
|
-
*/
|
|
860
|
-
export declare class SessionAppendConflictError extends Error {
|
|
861
|
-
readonly conflict: SessionAppendConflict;
|
|
862
|
-
readonly code: "session_append_conflict";
|
|
863
|
-
constructor(conflict: SessionAppendConflict);
|
|
864
|
-
}
|
|
865
|
-
/** Type guard keyed off the stable `code` (works across bundles; not message text). */
|
|
866
|
-
export declare function isSessionAppendConflict(error: unknown): error is SessionAppendConflictError;
|
|
867
|
-
export interface StoreFactory {
|
|
868
|
-
readonly name: string;
|
|
869
|
-
create(config?: JsonObject): Promise<SessionStore> | SessionStore;
|
|
870
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
871
|
-
}
|
|
872
|
-
/** Ownership scope identifiers. Hosts may use these for multi-tenant isolation. */
|
|
873
|
-
export interface OwnershipScope {
|
|
874
|
-
readonly tenantId?: string;
|
|
875
|
-
readonly accountId?: string;
|
|
876
|
-
readonly userId?: string;
|
|
877
|
-
}
|
|
878
|
-
/** Cursor-paginated result page. */
|
|
879
|
-
export interface PersistencePage<T> {
|
|
880
|
-
readonly items: readonly T[];
|
|
881
|
-
readonly nextCursor?: string;
|
|
882
|
-
readonly total?: number;
|
|
883
|
-
}
|
|
884
|
-
/** Common query controls for cursor-based pagination. */
|
|
885
|
-
export interface PersistenceQuery {
|
|
886
|
-
readonly cursor?: string;
|
|
887
|
-
readonly limit?: number;
|
|
888
|
-
readonly order?: "asc" | "desc";
|
|
889
|
-
}
|
|
890
|
-
/** Generic versioned checkpoint key. Namespaces prevent consumer collisions. */
|
|
891
|
-
export interface CheckpointKey extends OwnershipScope {
|
|
892
|
-
readonly namespace: string;
|
|
893
|
-
readonly key: string;
|
|
894
|
-
readonly signal?: AbortSignal;
|
|
895
|
-
}
|
|
896
|
-
/** Input for an optimistic checkpoint write. Versions must strictly increase. */
|
|
897
|
-
export interface CheckpointSaveInput extends CheckpointKey {
|
|
898
|
-
readonly version: number;
|
|
899
|
-
/** Exact current version required before update; use 0 for create-only. */
|
|
900
|
-
readonly expectedVersion?: number;
|
|
901
|
-
/** Monotonic lease fence. Lower or absent worker fences cannot replace a fenced record. */
|
|
902
|
-
readonly fencingToken?: number;
|
|
903
|
-
readonly value: unknown;
|
|
904
|
-
readonly category?: string;
|
|
905
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
906
|
-
}
|
|
907
|
-
/** Durable generic checkpoint record. */
|
|
908
|
-
export interface CheckpointRecord extends OwnershipScope {
|
|
909
|
-
readonly namespace: string;
|
|
910
|
-
readonly key: string;
|
|
911
|
-
readonly version: number;
|
|
912
|
-
readonly fencingToken?: number;
|
|
913
|
-
readonly value: unknown;
|
|
914
|
-
readonly category?: string;
|
|
915
|
-
readonly createdAt: string;
|
|
916
|
-
readonly updatedAt: string;
|
|
917
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
918
|
-
}
|
|
919
|
-
/** Bounded checkpoint query. */
|
|
920
|
-
export interface CheckpointQuery extends PersistenceQuery, OwnershipScope {
|
|
921
|
-
readonly namespace?: string;
|
|
922
|
-
readonly keyPrefix?: string;
|
|
923
|
-
readonly category?: string | readonly string[];
|
|
924
|
-
readonly signal?: AbortSignal;
|
|
925
|
-
}
|
|
926
|
-
/** Generic versioned checkpoint capability for persistence adapters. */
|
|
927
|
-
export interface CheckpointStore {
|
|
928
|
-
saveCheckpoint(input: CheckpointSaveInput): Promise<CheckpointRecord>;
|
|
929
|
-
loadCheckpoint(input: CheckpointKey): Promise<CheckpointRecord | null>;
|
|
930
|
-
listCheckpoints(query?: CheckpointQuery): Promise<PersistencePage<CheckpointRecord>>;
|
|
931
|
-
deleteCheckpoint(input: CheckpointKey): Promise<boolean>;
|
|
932
|
-
}
|
|
933
|
-
/** Generic lease key. Ownership fields are part of the trust boundary. */
|
|
934
|
-
export interface LeaseKey extends OwnershipScope {
|
|
935
|
-
readonly namespace: string;
|
|
936
|
-
readonly key: string;
|
|
937
|
-
readonly signal?: AbortSignal;
|
|
938
|
-
}
|
|
939
|
-
export interface LeaseAcquireInput extends LeaseKey {
|
|
940
|
-
readonly ownerId: string;
|
|
941
|
-
readonly ttlMs: number;
|
|
942
|
-
}
|
|
943
|
-
export interface LeaseClaimInput extends LeaseKey {
|
|
944
|
-
readonly ownerId: string;
|
|
945
|
-
readonly token: string;
|
|
946
|
-
readonly ttlMs?: number;
|
|
947
|
-
}
|
|
948
|
-
export interface LeaseRecord extends OwnershipScope {
|
|
949
|
-
readonly namespace: string;
|
|
950
|
-
readonly key: string;
|
|
951
|
-
readonly ownerId: string;
|
|
952
|
-
readonly token: string;
|
|
953
|
-
readonly fencingToken: number;
|
|
954
|
-
readonly acquiredAt: string;
|
|
955
|
-
readonly expiresAt: string;
|
|
956
|
-
readonly updatedAt: string;
|
|
957
|
-
}
|
|
958
|
-
/** Atomic distributed lease capability. Expired rows retain fencing counters. */
|
|
959
|
-
export interface LeaseStore {
|
|
960
|
-
tryAcquireLease(input: LeaseAcquireInput): Promise<LeaseRecord | null>;
|
|
961
|
-
renewLease(input: LeaseClaimInput & {
|
|
962
|
-
readonly ttlMs: number;
|
|
963
|
-
}): Promise<LeaseRecord | null>;
|
|
964
|
-
releaseLease(input: LeaseClaimInput): Promise<boolean>;
|
|
965
|
-
getLease(input: LeaseKey): Promise<LeaseRecord | null>;
|
|
966
|
-
}
|
|
967
|
-
/** Stored session record. Does not include provider objects or credentials. */
|
|
968
|
-
export interface SessionRecord extends OwnershipScope {
|
|
969
|
-
readonly id: string;
|
|
970
|
-
readonly parentSessionId?: string;
|
|
971
|
-
readonly agentDefinitionId?: string;
|
|
972
|
-
readonly agentDefinitionVersion?: string;
|
|
973
|
-
readonly createdAt: string;
|
|
974
|
-
readonly updatedAt: string;
|
|
975
|
-
readonly expiresAt?: string;
|
|
976
|
-
readonly retentionPolicyId?: string;
|
|
977
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
978
|
-
/** Write version for optimistic metadata CAS; undefined on legacy/never-written rows. */
|
|
979
|
-
readonly version?: number;
|
|
980
|
-
}
|
|
981
|
-
/** Stored branch handle / leaf pointer. The leaf is the current entry id for the branch. */
|
|
982
|
-
export interface BranchRecord {
|
|
983
|
-
readonly id: string;
|
|
984
|
-
readonly sessionId: string;
|
|
985
|
-
readonly name?: string;
|
|
986
|
-
readonly rootEntryId?: string;
|
|
987
|
-
readonly parentBranchId?: string;
|
|
988
|
-
/** Durable leaf entry id for this branch (the persistence-side branch tip). */
|
|
989
|
-
readonly leafEntryId?: string;
|
|
990
|
-
readonly createdAt: string;
|
|
991
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
992
|
-
}
|
|
993
|
-
export interface RunFeedbackRecord extends OwnershipScope {
|
|
994
|
-
readonly id: string;
|
|
995
|
-
readonly runId: string;
|
|
996
|
-
readonly sessionId: string;
|
|
997
|
-
readonly traceId?: string;
|
|
998
|
-
readonly rating?: number;
|
|
999
|
-
readonly comment?: string;
|
|
1000
|
-
readonly tags: readonly string[];
|
|
1001
|
-
readonly scorerIds: readonly string[];
|
|
1002
|
-
readonly evaluationIds: readonly string[];
|
|
1003
|
-
readonly createdAt: string;
|
|
1004
|
-
readonly createdBy?: string;
|
|
1005
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1006
|
-
}
|
|
1007
|
-
export interface AppendRunFeedbackInput extends OwnershipScope {
|
|
1008
|
-
readonly id: string;
|
|
1009
|
-
readonly runId: string;
|
|
1010
|
-
readonly sessionId?: string;
|
|
1011
|
-
readonly traceId?: string;
|
|
1012
|
-
readonly rating?: number;
|
|
1013
|
-
readonly comment?: string;
|
|
1014
|
-
readonly tags?: readonly string[];
|
|
1015
|
-
readonly scorerIds?: readonly string[];
|
|
1016
|
-
readonly evaluationIds?: readonly string[];
|
|
1017
|
-
readonly createdAt?: string;
|
|
1018
|
-
readonly createdBy?: string;
|
|
1019
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1020
|
-
readonly signal?: AbortSignal;
|
|
1021
|
-
}
|
|
1022
|
-
/** Cursor-paginated, ownership-scoped feedback query. */
|
|
1023
|
-
export interface RunFeedbackQuery extends PersistenceQuery, OwnershipScope {
|
|
1024
|
-
readonly runId?: string;
|
|
1025
|
-
readonly sessionId?: string;
|
|
1026
|
-
readonly traceId?: string;
|
|
1027
|
-
readonly rating?: number;
|
|
1028
|
-
readonly scorerId?: string;
|
|
1029
|
-
readonly evaluationId?: string;
|
|
1030
|
-
readonly tag?: string;
|
|
1031
|
-
readonly fromCreatedAt?: string;
|
|
1032
|
-
readonly toCreatedAt?: string;
|
|
1033
|
-
readonly signal?: AbortSignal;
|
|
1034
|
-
}
|
|
1035
|
-
export interface DeleteRunFeedbackInput extends OwnershipScope {
|
|
1036
|
-
readonly id: string;
|
|
1037
|
-
readonly signal?: AbortSignal;
|
|
1038
|
-
}
|
|
1039
|
-
/** Feedback storage seam. Records are append-only; correction uses a new record and deletion is explicit. */
|
|
1040
|
-
export interface RunFeedbackStore {
|
|
1041
|
-
append(input: AppendRunFeedbackInput): Promise<RunFeedbackRecord>;
|
|
1042
|
-
query(query: RunFeedbackQuery): Promise<PersistencePage<RunFeedbackRecord>>;
|
|
1043
|
-
delete(input: DeleteRunFeedbackInput): Promise<boolean>;
|
|
1044
|
-
}
|
|
1045
|
-
/** Stored agent definition version. Does not include provider credentials/resolvers/provider instances. */
|
|
1046
|
-
export interface AgentDefinitionRecord extends OwnershipScope {
|
|
1047
|
-
readonly id: string;
|
|
1048
|
-
readonly name: string;
|
|
1049
|
-
readonly version: string;
|
|
1050
|
-
readonly source?: string;
|
|
1051
|
-
readonly agentDefinition: AgentDefinition;
|
|
1052
|
-
readonly createdAt: string;
|
|
1053
|
-
readonly createdBy?: string;
|
|
1054
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1055
|
-
}
|
|
1056
|
-
/** Stored retention policy. */
|
|
1057
|
-
export interface RetentionPolicy extends OwnershipScope {
|
|
1058
|
-
readonly id: string;
|
|
1059
|
-
readonly name?: string;
|
|
1060
|
-
readonly maxAgeDays?: number;
|
|
1061
|
-
readonly maxEntriesPerSession?: number;
|
|
1062
|
-
readonly maxTotalBytes?: number;
|
|
1063
|
-
readonly archiveStore?: string;
|
|
1064
|
-
readonly appliedKinds?: readonly SessionEntryKind[];
|
|
1065
|
-
readonly createdAt: string;
|
|
1066
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1067
|
-
}
|
|
1068
|
-
/** Stored migration record. */
|
|
1069
|
-
export interface MigrationRecord {
|
|
1070
|
-
readonly id: string;
|
|
1071
|
-
readonly name: string;
|
|
1072
|
-
readonly version: string;
|
|
1073
|
-
readonly appliedAt: string;
|
|
1074
|
-
readonly appliedBy?: string;
|
|
1075
|
-
readonly checksum?: string;
|
|
1076
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1077
|
-
}
|
|
1078
|
-
/** Query for sessions. */
|
|
1079
|
-
export interface SessionQuery extends PersistenceQuery, OwnershipScope {
|
|
1080
|
-
readonly id?: string;
|
|
1081
|
-
readonly parentSessionId?: string;
|
|
1082
|
-
readonly agentDefinitionId?: string;
|
|
1083
|
-
readonly agentDefinitionVersion?: string;
|
|
1084
|
-
readonly retentionPolicyId?: string;
|
|
1085
|
-
/** Match sessions whose `metadata` object contains this top-level key (e.g. conversation marker). */
|
|
1086
|
-
readonly metadataKey?: string;
|
|
1087
|
-
readonly fromCreatedAt?: string;
|
|
1088
|
-
readonly toCreatedAt?: string;
|
|
1089
|
-
readonly fromUpdatedAt?: string;
|
|
1090
|
-
readonly toUpdatedAt?: string;
|
|
1091
|
-
readonly hasExpired?: boolean;
|
|
1092
|
-
}
|
|
1093
|
-
/** Validate a top-level `SessionRecord.metadata` key used by `SessionQuery.metadataKey` filters. */
|
|
1094
|
-
export declare function assertSessionMetadataKey(key: string): string;
|
|
1095
|
-
/** Query for session entries. */
|
|
1096
|
-
export interface SessionEntryQuery extends PersistenceQuery, OwnershipScope {
|
|
1097
|
-
readonly sessionId?: string;
|
|
1098
|
-
readonly runId?: string;
|
|
1099
|
-
readonly parentId?: string;
|
|
1100
|
-
/** Filter to entries on the branch ending at this leaf id. */
|
|
1101
|
-
readonly leafId?: string;
|
|
1102
|
-
readonly kind?: SessionEntryKind | readonly SessionEntryKind[];
|
|
1103
|
-
readonly fromTimestamp?: string;
|
|
1104
|
-
readonly toTimestamp?: string;
|
|
1105
|
-
}
|
|
1106
|
-
/** Query for branch handles/leaves. */
|
|
1107
|
-
export interface BranchQuery extends PersistenceQuery {
|
|
1108
|
-
readonly sessionId?: string;
|
|
1109
|
-
readonly name?: string;
|
|
1110
|
-
readonly parentBranchId?: string;
|
|
1111
|
-
readonly hasLeaf?: boolean;
|
|
1112
|
-
}
|
|
1113
|
-
/** Query for runs. */
|
|
1114
|
-
export interface RunQuery extends PersistenceQuery, OwnershipScope {
|
|
1115
|
-
readonly sessionId?: string;
|
|
1116
|
-
readonly branchId?: string;
|
|
1117
|
-
readonly agentDefinitionId?: string;
|
|
1118
|
-
readonly agentDefinitionVersion?: string;
|
|
1119
|
-
readonly status?: RunStatus | readonly RunStatus[];
|
|
1120
|
-
readonly fromStartedAt?: string;
|
|
1121
|
-
readonly toStartedAt?: string;
|
|
1122
|
-
readonly fromFinishedAt?: string;
|
|
1123
|
-
readonly toFinishedAt?: string;
|
|
1124
|
-
readonly isFinished?: boolean;
|
|
1125
|
-
}
|
|
1126
|
-
/** Query for agent event ledger rows. */
|
|
1127
|
-
export interface AgentEventQuery extends PersistenceQuery, OwnershipScope {
|
|
1128
|
-
readonly sessionId?: string;
|
|
1129
|
-
readonly runId?: string;
|
|
1130
|
-
readonly entryId?: string;
|
|
1131
|
-
readonly type?: AgentEventType | readonly AgentEventType[];
|
|
1132
|
-
readonly fromTimestamp?: string;
|
|
1133
|
-
readonly toTimestamp?: string;
|
|
1134
|
-
readonly redacted?: boolean;
|
|
1135
|
-
}
|
|
1136
|
-
/** Query for tool-call rows. */
|
|
1137
|
-
export interface ToolCallQuery extends PersistenceQuery, OwnershipScope {
|
|
1138
|
-
readonly sessionId?: string;
|
|
1139
|
-
readonly runId?: string;
|
|
1140
|
-
readonly entryId?: string;
|
|
1141
|
-
readonly name?: string;
|
|
1142
|
-
readonly status?: ToolCallStatus | readonly ToolCallStatus[];
|
|
1143
|
-
readonly fromStartedAt?: string;
|
|
1144
|
-
readonly toStartedAt?: string;
|
|
1145
|
-
readonly fromFinishedAt?: string;
|
|
1146
|
-
readonly toFinishedAt?: string;
|
|
1147
|
-
readonly redacted?: boolean;
|
|
1148
|
-
}
|
|
1149
|
-
/** Query for usage rows. */
|
|
1150
|
-
export interface UsageQuery extends PersistenceQuery, OwnershipScope {
|
|
1151
|
-
readonly sessionId?: string;
|
|
1152
|
-
readonly runId?: string;
|
|
1153
|
-
readonly entryId?: string;
|
|
1154
|
-
readonly scope?: UsageScope;
|
|
1155
|
-
readonly turn?: number;
|
|
1156
|
-
readonly attempt?: number;
|
|
1157
|
-
readonly fromRecordedAt?: string;
|
|
1158
|
-
readonly toRecordedAt?: string;
|
|
1159
|
-
}
|
|
1160
|
-
/** Query for agent definition versions. */
|
|
1161
|
-
export interface AgentDefinitionQuery extends PersistenceQuery, OwnershipScope {
|
|
1162
|
-
readonly name?: string;
|
|
1163
|
-
readonly version?: string;
|
|
1164
|
-
readonly source?: string;
|
|
1165
|
-
readonly fromCreatedAt?: string;
|
|
1166
|
-
readonly toCreatedAt?: string;
|
|
1167
|
-
}
|
|
1168
|
-
/** Query for retention policies. */
|
|
1169
|
-
export interface RetentionPolicyQuery extends PersistenceQuery, OwnershipScope {
|
|
1170
|
-
readonly name?: string;
|
|
1171
|
-
readonly archiveStore?: string;
|
|
1172
|
-
}
|
|
1173
|
-
/** Query for migration records. */
|
|
1174
|
-
export interface MigrationQuery extends PersistenceQuery {
|
|
1175
|
-
readonly name?: string;
|
|
1176
|
-
readonly version?: string;
|
|
1177
|
-
readonly fromAppliedAt?: string;
|
|
1178
|
-
readonly toAppliedAt?: string;
|
|
1179
|
-
}
|
|
1180
|
-
/**
|
|
1181
|
-
* Production database-neutral persistence store contract.
|
|
1182
|
-
* Hosts implement this interface to provide durable, paginated storage
|
|
1183
|
-
* for sessions, entries, runs, events, tool calls, usage, agent definitions,
|
|
1184
|
-
* and migrations, with optional generic checkpoint and atomic lease capabilities. No SQL client, ORM, host file storage, or network dependency is
|
|
1185
|
-
* required by the contract.
|
|
1186
|
-
*/
|
|
1187
|
-
export interface ProductionPersistenceStore {
|
|
1188
|
-
readonly name?: string;
|
|
1189
|
-
/** Optional generic write capability for resumable consumers such as workflows. */
|
|
1190
|
-
readonly checkpoints?: CheckpointStore;
|
|
1191
|
-
/** Optional atomic distributed lease capability for coordinators and workers. */
|
|
1192
|
-
readonly leases?: LeaseStore;
|
|
1193
|
-
/** Optional immutable run/trace feedback storage capability. */
|
|
1194
|
-
readonly feedback?: RunFeedbackStore;
|
|
1195
|
-
/** Optional durable, cross-replica-capable event source. */
|
|
1196
|
-
readonly events?: AgentEventSource;
|
|
1197
|
-
querySessions(query: SessionQuery): Promise<PersistencePage<SessionRecord>>;
|
|
1198
|
-
queryBranches(query: BranchQuery): Promise<PersistencePage<BranchRecord>>;
|
|
1199
|
-
queryEntries(query: SessionEntryQuery): Promise<PersistencePage<SessionEntry>>;
|
|
1200
|
-
queryRuns(query: RunQuery): Promise<PersistencePage<RunRecord>>;
|
|
1201
|
-
queryEvents(query: AgentEventQuery): Promise<PersistencePage<AgentEventRecord>>;
|
|
1202
|
-
queryToolCalls(query: ToolCallQuery): Promise<PersistencePage<ToolCallRecord>>;
|
|
1203
|
-
queryUsage(query: UsageQuery): Promise<PersistencePage<UsageRecord>>;
|
|
1204
|
-
queryAgentDefinitions(query: AgentDefinitionQuery): Promise<PersistencePage<AgentDefinitionRecord>>;
|
|
1205
|
-
queryRetentionPolicies(query: RetentionPolicyQuery): Promise<PersistencePage<RetentionPolicy>>;
|
|
1206
|
-
queryMigrations(query: MigrationQuery): Promise<PersistencePage<MigrationRecord>>;
|
|
1207
|
-
/** Optional session-record write capability (conversation threads, host-managed sessions).
|
|
1208
|
-
* Upserts by id; ownership columns are set on create, `metadata`/`updatedAt` on update.
|
|
1209
|
-
* Additive CAS: pass `expectedVersion` to require the stored version to match before the
|
|
1210
|
-
* write (0 = create-only, a positive number = exact current version); omit it for legacy
|
|
1211
|
-
* last-write-wins. Returns the new `version` when the underlying store supports it. */
|
|
1212
|
-
appendSession?(record: SessionRecord & {
|
|
1213
|
-
readonly expectedVersion?: number;
|
|
1214
|
-
}): Promise<{
|
|
1215
|
-
readonly version: number;
|
|
1216
|
-
} | undefined>;
|
|
1217
|
-
/** DB-friendly branch read (mirrors `SessionStore.readBranchPath`): one ancestor-chain
|
|
1218
|
-
* query instead of `queryEntries({ sessionId })` + in-memory walk. Optional. */
|
|
1219
|
-
readBranchPath?(query: SessionBranchRead): Promise<PersistencePage<SessionEntry>>;
|
|
1220
|
-
/**
|
|
1221
|
-
* Optional Phase 8 retention / legal-hold / export / tenant-quota lifecycle.
|
|
1222
|
-
* Prefer attaching `createMemoryPersistenceLifecycle()` or adapter-native methods.
|
|
1223
|
-
*/
|
|
1224
|
-
readonly lifecycle?: import("./persistence-lifecycle.js").PersistenceLifecycleStore;
|
|
1225
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1226
|
-
}
|
|
1227
|
-
export interface CompactionStrategy {
|
|
1228
|
-
readonly name: string;
|
|
1229
|
-
compact(context: CompactionContext): Promise<CompactionResult> | CompactionResult;
|
|
1230
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1231
|
-
}
|
|
1232
|
-
export interface CompactionContext {
|
|
1233
|
-
readonly sessionId: string;
|
|
1234
|
-
readonly entries: readonly SessionEntry[];
|
|
1235
|
-
readonly keepRecentEntries?: number;
|
|
1236
|
-
readonly trigger?: "manual" | "auto" | string;
|
|
1237
|
-
readonly secrets?: readonly (string | undefined)[];
|
|
1238
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1239
|
-
readonly signal?: AbortSignal;
|
|
1240
|
-
}
|
|
1241
|
-
export interface CompactionResult {
|
|
1242
|
-
readonly summary: string;
|
|
1243
|
-
readonly entries?: readonly SessionEntry[];
|
|
1244
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1245
|
-
}
|
|
1246
|
-
export interface CompactionOptions {
|
|
1247
|
-
readonly strategy?: CompactionStrategy;
|
|
1248
|
-
readonly thresholdEntries?: number;
|
|
1249
|
-
readonly keepRecentEntries?: number;
|
|
1250
|
-
readonly maxSummaryChars?: number;
|
|
1251
|
-
readonly secrets?: readonly (string | undefined)[];
|
|
1252
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1253
|
-
readonly signal?: AbortSignal;
|
|
1254
|
-
}
|
|
1255
|
-
export interface CompactionMiddlewarePayload {
|
|
1256
|
-
readonly context: CompactionContext;
|
|
1257
|
-
readonly result: CompactionResult;
|
|
1258
|
-
}
|
|
1259
|
-
export interface CompactionEntryData {
|
|
1260
|
-
readonly throughEntryId?: string;
|
|
1261
|
-
readonly keepEntryIds?: readonly string[];
|
|
1262
|
-
readonly strategy?: string;
|
|
1263
|
-
readonly trigger?: "manual" | "auto" | string;
|
|
1264
|
-
}
|
|
1265
|
-
export interface RetryPolicy {
|
|
1266
|
-
readonly name: string;
|
|
1267
|
-
decide(context: RetryContext): Promise<RetryDecision> | RetryDecision;
|
|
1268
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1269
|
-
}
|
|
1270
|
-
export interface RetryContext {
|
|
1271
|
-
readonly sessionId: string;
|
|
1272
|
-
readonly runId: string;
|
|
1273
|
-
readonly attempt: number;
|
|
1274
|
-
readonly error: ErrorInfo;
|
|
1275
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1276
|
-
readonly signal?: AbortSignal;
|
|
1277
|
-
}
|
|
1278
|
-
export interface RetryDecision {
|
|
1279
|
-
readonly retry: boolean;
|
|
1280
|
-
readonly delayMs?: number;
|
|
1281
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1282
|
-
}
|
|
1283
|
-
export interface RetryOptions {
|
|
1284
|
-
readonly policy?: RetryPolicy;
|
|
1285
|
-
readonly maxAttempts?: number;
|
|
1286
|
-
readonly baseDelayMs?: number;
|
|
1287
|
-
readonly maxDelayMs?: number;
|
|
1288
|
-
readonly secrets?: readonly (string | undefined)[];
|
|
1289
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1290
|
-
}
|
|
1291
|
-
export interface RetryMiddlewarePayload {
|
|
1292
|
-
readonly context: RetryContext;
|
|
1293
|
-
readonly decision: RetryDecision;
|
|
1294
|
-
}
|
|
1295
|
-
export interface Resource {
|
|
1296
|
-
readonly uri: string;
|
|
1297
|
-
readonly mediaType?: string;
|
|
1298
|
-
readonly text?: string;
|
|
1299
|
-
readonly data?: Uint8Array;
|
|
1300
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1301
|
-
}
|
|
1302
|
-
export interface ResourceLoader {
|
|
1303
|
-
load(uri: string, context?: ResourceLoadContext): Promise<Resource>;
|
|
1304
|
-
list?(context?: ResourceLoadContext): Promise<readonly Resource[]>;
|
|
1305
|
-
}
|
|
1306
|
-
export interface ResourceLoadContext {
|
|
1307
|
-
readonly signal?: AbortSignal;
|
|
1308
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1309
|
-
readonly permission?: PermissionPolicy;
|
|
1310
|
-
readonly trust?: TrustPolicy;
|
|
1311
|
-
}
|
|
1312
|
-
export interface SettingsProvider {
|
|
1313
|
-
get<T = unknown>(key: string): Promise<T | undefined> | T | undefined;
|
|
1314
|
-
}
|
|
1315
|
-
export interface CredentialRequest {
|
|
1316
|
-
readonly name: string;
|
|
1317
|
-
readonly provider?: string;
|
|
1318
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1319
|
-
}
|
|
1320
|
-
export interface Credential {
|
|
1321
|
-
readonly type: "bearer" | "api_key" | "basic" | "custom";
|
|
1322
|
-
readonly value: string;
|
|
1323
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1324
|
-
}
|
|
1325
|
-
export interface CredentialResolver {
|
|
1326
|
-
resolve(request: CredentialRequest): Promise<Credential | undefined> | Credential | undefined;
|
|
1327
|
-
}
|
|
1328
|
-
export interface CredentialResolverSource {
|
|
1329
|
-
readonly name: string;
|
|
1330
|
-
readonly resolver: CredentialResolver;
|
|
1331
|
-
}
|
|
1332
|
-
export interface OAuthCredentialStore {
|
|
1333
|
-
set(provider: string, credentials: OAuthCredentials): void | Promise<void>;
|
|
1334
|
-
}
|
|
1335
|
-
export interface LoopContext {
|
|
1336
|
-
readonly sessionId: string;
|
|
1337
|
-
readonly runId: string;
|
|
1338
|
-
readonly metadata: Readonly<Record<string, unknown>>;
|
|
1339
|
-
readonly signal: AbortSignal;
|
|
1340
|
-
readonly history: Message[];
|
|
1341
|
-
readonly input: AgentInput;
|
|
1342
|
-
readonly inputMessages: readonly Message[];
|
|
1343
|
-
readonly maxToolRounds: number;
|
|
1344
|
-
/** Maximum independent tool calls dispatched concurrently per provider turn. Default `1`. */
|
|
1345
|
-
readonly toolConcurrency: number;
|
|
1346
|
-
assemble(nextInput: AgentInput, toolResults?: readonly ToolResult[], turn?: number): Promise<ProviderRequest>;
|
|
1347
|
-
/**
|
|
1348
|
-
* Charges a complete tool round before any call in it can start. On durable interrupt
|
|
1349
|
-
* runs this is also the round-level approval gate: it collects every gated call of the
|
|
1350
|
-
* round into one suspension. Loops must await it; dispatch without it falls back to
|
|
1351
|
-
* per-call single-decision suspensions.
|
|
1352
|
-
*/
|
|
1353
|
-
chargeToolRound?(calls: readonly ToolCallContent[]): void | Promise<void>;
|
|
1354
|
-
generate(request: ProviderRequest): Promise<ProviderTurnResult>;
|
|
1355
|
-
dispatchToolCall(call: ToolCallContent): Promise<ToolResult>;
|
|
1356
|
-
isToolCallExclusive?(call: ToolCallContent): boolean;
|
|
1357
|
-
appendMessage(message: Message): Promise<void>;
|
|
1358
|
-
emit(event: AgentEvent): void;
|
|
1359
|
-
/** True when mid-run steers are queued for the next provider turn. */
|
|
1360
|
-
hasPendingSteers?(): boolean;
|
|
1361
|
-
/** Drain pending steers into history/session. Returns true when any were applied. */
|
|
1362
|
-
applyPendingSteers?(): Promise<boolean>;
|
|
1363
|
-
/** Snapshot captured at the last suspension when the strategy declared snapshot/restore. Present only on resume. */
|
|
1364
|
-
readonly restoredLoopState?: JsonValue;
|
|
1365
|
-
}
|
|
1366
|
-
export interface AgentLoopStrategy {
|
|
1367
|
-
readonly name: string;
|
|
1368
|
-
/** Host-authored loop revision. Joins the durable-run fingerprint when snapshot hooks are present. */
|
|
1369
|
-
readonly revision?: string;
|
|
1370
|
-
run(ctx: LoopContext): Promise<Usage | undefined>;
|
|
1371
|
-
/**
|
|
1372
|
-
* Capture loop-local resumable state at suspension. Must return a JSON-compatible value;
|
|
1373
|
-
* core bounds and redacts it inside the durable run-state envelope. Declare together with
|
|
1374
|
-
* `restore`; a custom strategy without both hooks is rejected before any provider call on
|
|
1375
|
-
* durable runs (`AgentLoopStateError` / `ERR_PRISM_LOOP_NOT_DURABLE`).
|
|
1376
|
-
*/
|
|
1377
|
-
snapshot?(): JsonValue;
|
|
1378
|
-
/** Rehydrate from a previously captured snapshot; must throw on drift. Called before `run` on resume. */
|
|
1379
|
-
restore?(snapshot: JsonValue): void;
|
|
1380
|
-
}
|
|
1381
|
-
export type AgentLoopOptions = {
|
|
1382
|
-
readonly strategy: "single-shot";
|
|
1383
|
-
/** Independent tool calls per turn run concurrently up to this limit. Default `1` (sequential). */
|
|
1384
|
-
readonly toolConcurrency?: number;
|
|
1385
|
-
} | {
|
|
1386
|
-
readonly strategy: "generate-validate-revise";
|
|
1387
|
-
readonly validator: ArtifactValidator<unknown>;
|
|
1388
|
-
readonly parser?: ArtifactParser<unknown>;
|
|
1389
|
-
readonly repairer?: ArtifactRepairer<unknown>;
|
|
1390
|
-
readonly maxRevisions?: number;
|
|
1391
|
-
/** Dispatch provider tool calls in artifact turns. Default `"disabled"`; `"bounded"` uses RunOptions.maxToolRounds sequentially. */
|
|
1392
|
-
readonly toolCalls?: "disabled" | "bounded";
|
|
1393
|
-
/** Native provider JSON-schema output. Ignored when `structuredOutputMode` is `artifact-loop`. */
|
|
1394
|
-
readonly structuredOutput?: StructuredOutputOptions;
|
|
1395
|
-
/** `native` maps schema to capable providers; `artifact-loop` keeps repair turns only. */
|
|
1396
|
-
readonly structuredOutputMode?: "native" | "artifact-loop";
|
|
1397
|
-
/**
|
|
1398
|
-
* When to attach native `structuredOutput` under `toolCalls: "bounded"`.
|
|
1399
|
-
* `every-turn` (default): schema on every provider request (legacy).
|
|
1400
|
-
* `final-turn-only`: tool-eligible turns omit schema; artifact/revision turns send schema and withdraw tools.
|
|
1401
|
-
*/
|
|
1402
|
-
readonly structuredOutputTiming?: "every-turn" | "final-turn-only";
|
|
1403
|
-
};
|
|
1404
|
-
export interface ArtifactValidation {
|
|
1405
|
-
readonly ok: boolean;
|
|
1406
|
-
readonly errors?: readonly {
|
|
1407
|
-
readonly path?: string;
|
|
1408
|
-
readonly message: string;
|
|
1409
|
-
}[];
|
|
1410
|
-
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1411
|
-
}
|
|
1412
|
-
export interface ArtifactContext {
|
|
1413
|
-
readonly sessionId: string;
|
|
1414
|
-
readonly runId: string;
|
|
1415
|
-
readonly turn: number;
|
|
1416
|
-
readonly signal: AbortSignal;
|
|
1417
|
-
readonly metadata: Readonly<Record<string, unknown>>;
|
|
1418
|
-
}
|
|
1419
|
-
export interface ArtifactParseResult<T> {
|
|
1420
|
-
readonly ok: boolean;
|
|
1421
|
-
readonly value?: T;
|
|
1422
|
-
readonly error?: string;
|
|
1423
|
-
}
|
|
1424
|
-
export type ArtifactParser<T> = (text: string, ctx: ArtifactContext) => ArtifactParseResult<T> | Promise<ArtifactParseResult<T>>;
|
|
1425
|
-
export type ArtifactValidator<T> = (value: T, ctx: ArtifactContext) => ArtifactValidation | Promise<ArtifactValidation>;
|
|
1426
|
-
export type ArtifactRepairer<T> = (value: T | undefined, failure: ArtifactValidation, ctx: ArtifactContext) => AgentInput | Promise<AgentInput>;
|
|
5
|
+
export * from "./contracts-core/content.js";
|
|
6
|
+
export * from "./contracts-core/run-limits.js";
|
|
7
|
+
export * from "./contracts-core/provider.js";
|
|
8
|
+
export * from "./contracts-core/agent.js";
|
|
9
|
+
export * from "./contracts-core/extensions.js";
|
|
10
|
+
export * from "./contracts-core/session.js";
|
|
11
|
+
export * from "./contracts-core/persistence.js";
|
|
12
|
+
export * from "./contracts-core/compaction.js";
|
|
13
|
+
export * from "./contracts-core/resources.js";
|
|
14
|
+
export * from "./contracts-core/loop.js";
|