@soiljs/spi 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +150 -2
- package/dist/chunk-6VZ7CJCJ.js +117 -0
- package/dist/chunk-6VZ7CJCJ.js.map +1 -0
- package/dist/index.d.ts +140 -0
- package/dist/index.js +345 -0
- package/dist/index.js.map +1 -0
- package/dist/storage-COwm2B68.d.ts +676 -0
- package/dist/testing/index.d.ts +30 -0
- package/dist/testing/index.js +1091 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +38 -3
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
interface ScopeRef {
|
|
2
|
+
tenantId?: string;
|
|
3
|
+
projectId?: string;
|
|
4
|
+
}
|
|
5
|
+
interface ArtifactRef {
|
|
6
|
+
uri: string;
|
|
7
|
+
sha256: string;
|
|
8
|
+
byteSize: number;
|
|
9
|
+
contentType: string;
|
|
10
|
+
}
|
|
11
|
+
type UsageCompleteness = "complete" | "partial" | "unknown";
|
|
12
|
+
interface UsageMetrics {
|
|
13
|
+
inputTokens: number | null;
|
|
14
|
+
outputTokens: number | null;
|
|
15
|
+
cacheReadTokens: number | null;
|
|
16
|
+
cacheWriteTokens: number | null;
|
|
17
|
+
completeness: UsageCompleteness;
|
|
18
|
+
costMicros?: number | null;
|
|
19
|
+
}
|
|
20
|
+
interface UsageTotals {
|
|
21
|
+
inputTokens: number;
|
|
22
|
+
outputTokens: number;
|
|
23
|
+
cacheReadTokens: number;
|
|
24
|
+
cacheWriteTokens: number;
|
|
25
|
+
completeCount: number;
|
|
26
|
+
incompleteCount: number;
|
|
27
|
+
hasIncompleteUsage: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Unknown and partial observations never contribute invented token counts. */
|
|
30
|
+
declare function aggregateUsageTotals(usages: Iterable<UsageMetrics>): UsageTotals;
|
|
31
|
+
interface LeaseToken {
|
|
32
|
+
holderId: string;
|
|
33
|
+
epoch: number;
|
|
34
|
+
expiresAt: string;
|
|
35
|
+
}
|
|
36
|
+
interface ErrorRecord {
|
|
37
|
+
code: string;
|
|
38
|
+
message: string;
|
|
39
|
+
reason?: string;
|
|
40
|
+
details?: Record<string, JsonValue>;
|
|
41
|
+
requestStage?: "admission_rejected" | "dispatched" | "unknown";
|
|
42
|
+
}
|
|
43
|
+
type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
44
|
+
[key: string]: JsonValue;
|
|
45
|
+
};
|
|
46
|
+
type StopReason = "end_turn" | "tool_terminated" | "max_tokens" | "content_filter" | "max_iterations" | "max_model_calls" | "max_tool_calls" | "cancelled" | "error" | "unknown";
|
|
47
|
+
|
|
48
|
+
declare const TURN_STATUSES: readonly ["queued", "running", "waiting_approval", "waiting_child", "waiting_resolution", "completed", "failed", "cancelled"];
|
|
49
|
+
type TurnStatus = (typeof TURN_STATUSES)[number];
|
|
50
|
+
declare const TERMINAL_TURN_STATUSES: readonly ["completed", "failed", "cancelled"];
|
|
51
|
+
type TerminalTurnStatus = (typeof TERMINAL_TURN_STATUSES)[number];
|
|
52
|
+
declare const STEP_KINDS: readonly ["model_call", "tool_exec", "compaction", "sub_turn", "steering_input"];
|
|
53
|
+
type StepKind = (typeof STEP_KINDS)[number];
|
|
54
|
+
declare const STEP_STATUSES: readonly ["pending", "awaiting_approval", "running", "waiting_child", "unknown", "completed", "failed", "rejected", "skipped", "cancelled"];
|
|
55
|
+
type StepStatus = (typeof STEP_STATUSES)[number];
|
|
56
|
+
declare const TERMINAL_STEP_STATUSES: readonly ["completed", "failed", "rejected", "skipped", "cancelled"];
|
|
57
|
+
type TerminalStepStatus = (typeof TERMINAL_STEP_STATUSES)[number];
|
|
58
|
+
declare const ATTEMPT_KINDS: readonly ["execute", "reconcile"];
|
|
59
|
+
type AttemptKind = (typeof ATTEMPT_KINDS)[number];
|
|
60
|
+
declare const ATTEMPT_STATUSES: readonly ["running", "succeeded", "failed", "cancelled", "unknown"];
|
|
61
|
+
type AttemptStatus = (typeof ATTEMPT_STATUSES)[number];
|
|
62
|
+
declare const STEERING_STATUSES: readonly ["pending", "consumed"];
|
|
63
|
+
type SteeringStatus = (typeof STEERING_STATUSES)[number];
|
|
64
|
+
declare const APPROVAL_STATUSES: readonly ["pending", "approved", "rejected"];
|
|
65
|
+
type ApprovalStatus = (typeof APPROVAL_STATUSES)[number];
|
|
66
|
+
declare const TOOL_EFFECTS: readonly ["none", "external"];
|
|
67
|
+
type ToolEffect = (typeof TOOL_EFFECTS)[number];
|
|
68
|
+
declare const COMMAND_KINDS: readonly ["approve", "resolve_unknown", "cancel", "steer", "resume"];
|
|
69
|
+
type CommandKind = (typeof COMMAND_KINDS)[number];
|
|
70
|
+
declare const isTurnStatus: (value: unknown) => value is TurnStatus;
|
|
71
|
+
declare const isTerminalTurnStatus: (value: unknown) => value is TerminalTurnStatus;
|
|
72
|
+
declare const isStepKind: (value: unknown) => value is StepKind;
|
|
73
|
+
declare const isStepStatus: (value: unknown) => value is StepStatus;
|
|
74
|
+
declare const isTerminalStepStatus: (value: unknown) => value is TerminalStepStatus;
|
|
75
|
+
declare const isAttemptKind: (value: unknown) => value is AttemptKind;
|
|
76
|
+
declare const isAttemptStatus: (value: unknown) => value is AttemptStatus;
|
|
77
|
+
declare const isSteeringStatus: (value: unknown) => value is SteeringStatus;
|
|
78
|
+
declare const isApprovalStatus: (value: unknown) => value is ApprovalStatus;
|
|
79
|
+
declare const isToolEffect: (value: unknown) => value is ToolEffect;
|
|
80
|
+
declare const isCommandKind: (value: unknown) => value is CommandKind;
|
|
81
|
+
|
|
82
|
+
/** Only explicitly selected, bounded host diagnostics are persisted. Never pass vendor bodies. */
|
|
83
|
+
declare class HostControlError extends Error {
|
|
84
|
+
readonly record: ErrorRecord;
|
|
85
|
+
get code(): string;
|
|
86
|
+
get requestStage(): NonNullable<ErrorRecord["requestStage"]>;
|
|
87
|
+
get details(): ErrorRecord["details"];
|
|
88
|
+
constructor(record: ErrorRecord);
|
|
89
|
+
}
|
|
90
|
+
declare function toErrorRecord(error: unknown, code?: string): ErrorRecord;
|
|
91
|
+
declare const SOIL_ERROR_CODES: readonly ["SESSION_BUSY", "LEASE_LOST", "CONCURRENCY_CONFLICT", "IDEMPOTENCY_CONFLICT", "COMMAND_REJECTED", "TOOL_VALIDATION_FAILED", "AGENT_NOT_REGISTERED"];
|
|
92
|
+
type SoilErrorCode = (typeof SOIL_ERROR_CODES)[number];
|
|
93
|
+
declare const COMMAND_REJECTION_REASONS: readonly ["unauthorized", "scope_mismatch", "not_found", "invalid_state", "turn_already_terminal"];
|
|
94
|
+
type CommandRejectionReason = (typeof COMMAND_REJECTION_REASONS)[number];
|
|
95
|
+
declare class SoilError extends Error {
|
|
96
|
+
readonly code: SoilErrorCode;
|
|
97
|
+
readonly retryable: boolean;
|
|
98
|
+
constructor(message: string, code: SoilErrorCode, retryable?: boolean, options?: ErrorOptions);
|
|
99
|
+
}
|
|
100
|
+
declare class SessionBusyError extends SoilError {
|
|
101
|
+
readonly activeTurnId: string;
|
|
102
|
+
constructor(activeTurnId: string, options?: ErrorOptions);
|
|
103
|
+
}
|
|
104
|
+
declare class LeaseLostError extends SoilError {
|
|
105
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
106
|
+
}
|
|
107
|
+
declare class ConcurrencyConflictError extends SoilError {
|
|
108
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
109
|
+
}
|
|
110
|
+
declare class IdempotencyConflictError extends SoilError {
|
|
111
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
112
|
+
}
|
|
113
|
+
declare class CommandRejectedError extends SoilError {
|
|
114
|
+
readonly rejectionReason: CommandRejectionReason;
|
|
115
|
+
constructor(rejectionReason: CommandRejectionReason, options?: ErrorOptions);
|
|
116
|
+
}
|
|
117
|
+
interface SchemaIssue {
|
|
118
|
+
readonly message: string;
|
|
119
|
+
readonly path?: readonly (PropertyKey | {
|
|
120
|
+
readonly key: PropertyKey;
|
|
121
|
+
})[];
|
|
122
|
+
}
|
|
123
|
+
declare class ToolValidationError extends SoilError {
|
|
124
|
+
readonly issues: readonly SchemaIssue[];
|
|
125
|
+
constructor(issues: readonly SchemaIssue[], options?: ErrorOptions);
|
|
126
|
+
}
|
|
127
|
+
declare class AgentNotRegisteredError extends SoilError {
|
|
128
|
+
readonly agentId: string;
|
|
129
|
+
readonly agentVersion?: string | undefined;
|
|
130
|
+
constructor(agentId: string, agentVersion?: string | undefined, options?: ErrorOptions);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface CommandActor {
|
|
134
|
+
readonly id: string;
|
|
135
|
+
readonly role?: string;
|
|
136
|
+
readonly source: "local_api" | "cloud_console" | "system";
|
|
137
|
+
}
|
|
138
|
+
type CommandPayload = {
|
|
139
|
+
kind: "approve";
|
|
140
|
+
turnId: string;
|
|
141
|
+
approvalId: string;
|
|
142
|
+
decision: "approved" | "rejected";
|
|
143
|
+
reason?: string;
|
|
144
|
+
} | {
|
|
145
|
+
kind: "resolve_unknown";
|
|
146
|
+
turnId: string;
|
|
147
|
+
stepId: string;
|
|
148
|
+
resolution: {
|
|
149
|
+
kind: "confirmed_completed";
|
|
150
|
+
output: unknown;
|
|
151
|
+
modelOutput?: JsonValue;
|
|
152
|
+
} | {
|
|
153
|
+
kind: "confirmed_not_executed";
|
|
154
|
+
retry: boolean;
|
|
155
|
+
} | {
|
|
156
|
+
kind: "marked_failed";
|
|
157
|
+
reason: string;
|
|
158
|
+
};
|
|
159
|
+
} | {
|
|
160
|
+
kind: "cancel";
|
|
161
|
+
turnId: string;
|
|
162
|
+
reason?: string;
|
|
163
|
+
drainQueued?: "keep" | "cancel";
|
|
164
|
+
} | {
|
|
165
|
+
kind: "steer";
|
|
166
|
+
turnId: string;
|
|
167
|
+
input: string;
|
|
168
|
+
urgency?: "next_iteration" | "interrupt";
|
|
169
|
+
fallbackToNewTurn?: boolean;
|
|
170
|
+
supersedeApprovals?: boolean;
|
|
171
|
+
} | {
|
|
172
|
+
kind: "resume";
|
|
173
|
+
turnId: string;
|
|
174
|
+
};
|
|
175
|
+
interface CommandEnvelope {
|
|
176
|
+
readonly commandId: string;
|
|
177
|
+
readonly issuedAt: string;
|
|
178
|
+
readonly scope?: ScopeRef;
|
|
179
|
+
readonly actor: CommandActor;
|
|
180
|
+
readonly payload: CommandPayload;
|
|
181
|
+
}
|
|
182
|
+
interface CommandReceipt {
|
|
183
|
+
readonly commandId: string;
|
|
184
|
+
readonly status: "applied" | "duplicate" | "rejected";
|
|
185
|
+
readonly processedAt: string;
|
|
186
|
+
readonly resultTurnId?: string;
|
|
187
|
+
readonly rejectionReason?: CommandRejectionReason;
|
|
188
|
+
}
|
|
189
|
+
/** Runtime invokes this before applyCommand; a model response never authorizes a command. */
|
|
190
|
+
type CommandAuthorizer = (envelope: CommandEnvelope, targetTurn: Turn) => Promise<{
|
|
191
|
+
allowed: boolean;
|
|
192
|
+
reason?: string;
|
|
193
|
+
}>;
|
|
194
|
+
|
|
195
|
+
/** All returned entities are detached snapshots; mutating one must never mutate storage. */
|
|
196
|
+
interface Session {
|
|
197
|
+
readonly sessionId: string;
|
|
198
|
+
readonly agentId: string;
|
|
199
|
+
readonly agentVersion: string;
|
|
200
|
+
readonly scope?: ScopeRef;
|
|
201
|
+
readonly context: Readonly<Record<string, unknown>>;
|
|
202
|
+
readonly activeTurnId?: string;
|
|
203
|
+
readonly compactionCursorStepId?: string;
|
|
204
|
+
readonly createdAt: string;
|
|
205
|
+
readonly updatedAt: string;
|
|
206
|
+
readonly version: number;
|
|
207
|
+
}
|
|
208
|
+
interface Turn {
|
|
209
|
+
readonly toolExecution?: "parallel" | "sequential";
|
|
210
|
+
readonly stopReason?: StopReason;
|
|
211
|
+
readonly providerFinishReason?: string;
|
|
212
|
+
readonly partial?: boolean;
|
|
213
|
+
/** T4 completion intent; recovery must finish before dispatching more work. */
|
|
214
|
+
readonly completionIntent?: {
|
|
215
|
+
readonly stepId: string;
|
|
216
|
+
readonly output: unknown;
|
|
217
|
+
};
|
|
218
|
+
readonly turnId: string;
|
|
219
|
+
readonly sessionId: string;
|
|
220
|
+
readonly agentId: string;
|
|
221
|
+
readonly agentVersion: string;
|
|
222
|
+
readonly scope?: ScopeRef;
|
|
223
|
+
readonly input: string;
|
|
224
|
+
readonly context: Readonly<Record<string, unknown>>;
|
|
225
|
+
readonly status: TurnStatus;
|
|
226
|
+
readonly iteration: number;
|
|
227
|
+
readonly queueSeq?: number;
|
|
228
|
+
readonly idempotencyKey?: string;
|
|
229
|
+
readonly rootTurnId: string;
|
|
230
|
+
readonly parentTurnId?: string;
|
|
231
|
+
readonly parentStepId?: string;
|
|
232
|
+
readonly depth: number;
|
|
233
|
+
readonly limits?: Readonly<Record<string, number>>;
|
|
234
|
+
readonly propagation?: {
|
|
235
|
+
readonly cancelWithParent: boolean;
|
|
236
|
+
};
|
|
237
|
+
readonly lease?: LeaseToken;
|
|
238
|
+
/** Wakeable waiting Turns have no lease until acquireLease claims them. */
|
|
239
|
+
readonly wakeRequested: boolean;
|
|
240
|
+
readonly compactionCursorStepId?: string;
|
|
241
|
+
readonly output?: unknown;
|
|
242
|
+
readonly artifacts?: readonly ArtifactRef[];
|
|
243
|
+
readonly error?: ErrorRecord;
|
|
244
|
+
readonly createdAt: string;
|
|
245
|
+
readonly updatedAt: string;
|
|
246
|
+
readonly completedAt?: string;
|
|
247
|
+
readonly version: number;
|
|
248
|
+
}
|
|
249
|
+
interface Step {
|
|
250
|
+
readonly prepared?: boolean;
|
|
251
|
+
readonly validatedInput?: unknown;
|
|
252
|
+
readonly terminatesTurn?: boolean;
|
|
253
|
+
readonly modelOutput?: JsonValue;
|
|
254
|
+
readonly stepId: string;
|
|
255
|
+
readonly turnId: string;
|
|
256
|
+
readonly iteration: number;
|
|
257
|
+
/** Stable ledger order, independent of parallel completion order. */
|
|
258
|
+
readonly stepSeq: number;
|
|
259
|
+
readonly kind: StepKind;
|
|
260
|
+
readonly status: StepStatus;
|
|
261
|
+
readonly operationKey: string;
|
|
262
|
+
readonly toolCallId?: string;
|
|
263
|
+
readonly toolName?: string;
|
|
264
|
+
readonly toolVersion?: string;
|
|
265
|
+
readonly effect?: ToolEffect;
|
|
266
|
+
readonly input?: unknown;
|
|
267
|
+
readonly output?: unknown;
|
|
268
|
+
readonly artifacts?: readonly ArtifactRef[];
|
|
269
|
+
readonly usage?: UsageMetrics;
|
|
270
|
+
readonly protocolId?: string;
|
|
271
|
+
readonly modelId?: string;
|
|
272
|
+
/** Opaque protocol-owned JSON, or an immutable artifact written before commit. */
|
|
273
|
+
readonly continuation?: unknown;
|
|
274
|
+
readonly continuationArtifact?: ArtifactRef;
|
|
275
|
+
readonly error?: ErrorRecord;
|
|
276
|
+
readonly childTurnId?: string;
|
|
277
|
+
readonly approvalId?: string;
|
|
278
|
+
readonly createdAt: string;
|
|
279
|
+
readonly completedAt?: string;
|
|
280
|
+
readonly version: number;
|
|
281
|
+
}
|
|
282
|
+
interface Attempt {
|
|
283
|
+
readonly modelOutput?: JsonValue;
|
|
284
|
+
readonly modelCalls?: number;
|
|
285
|
+
readonly turnId: string;
|
|
286
|
+
readonly stepId: string;
|
|
287
|
+
readonly attemptNo: number;
|
|
288
|
+
readonly kind: AttemptKind;
|
|
289
|
+
readonly status: AttemptStatus;
|
|
290
|
+
readonly holderId: string;
|
|
291
|
+
readonly leaseEpoch: number;
|
|
292
|
+
readonly startedAt: string;
|
|
293
|
+
readonly completedAt?: string;
|
|
294
|
+
readonly usage?: UsageMetrics;
|
|
295
|
+
readonly output?: unknown;
|
|
296
|
+
readonly artifacts?: readonly ArtifactRef[];
|
|
297
|
+
readonly error?: ErrorRecord;
|
|
298
|
+
readonly evidence?: unknown;
|
|
299
|
+
}
|
|
300
|
+
interface SteeringEntry {
|
|
301
|
+
readonly steeringId: string;
|
|
302
|
+
readonly turnId: string;
|
|
303
|
+
readonly input: string;
|
|
304
|
+
readonly status: SteeringStatus;
|
|
305
|
+
readonly urgency: "next_iteration" | "interrupt";
|
|
306
|
+
readonly supersedeApprovals: boolean;
|
|
307
|
+
readonly createdAt: string;
|
|
308
|
+
readonly consumedAt?: string;
|
|
309
|
+
readonly consumedByStepId?: string;
|
|
310
|
+
}
|
|
311
|
+
interface ApprovalRecord {
|
|
312
|
+
readonly approvalId: string;
|
|
313
|
+
readonly sessionId: string;
|
|
314
|
+
readonly rootTurnId: string;
|
|
315
|
+
readonly parentTurnId?: string;
|
|
316
|
+
readonly turnId: string;
|
|
317
|
+
readonly stepId: string;
|
|
318
|
+
readonly status: ApprovalStatus;
|
|
319
|
+
readonly createdAt: string;
|
|
320
|
+
readonly resolvedAt?: string;
|
|
321
|
+
readonly actor?: CommandActor;
|
|
322
|
+
readonly reason?: string;
|
|
323
|
+
}
|
|
324
|
+
interface TurnSnapshot {
|
|
325
|
+
readonly turn: Turn;
|
|
326
|
+
readonly steps: readonly Step[];
|
|
327
|
+
readonly attempts: readonly Attempt[];
|
|
328
|
+
readonly steering: readonly SteeringEntry[];
|
|
329
|
+
readonly approvals: readonly ApprovalRecord[];
|
|
330
|
+
}
|
|
331
|
+
type SessionSnapshot = Session;
|
|
332
|
+
type StepSnapshot = Step;
|
|
333
|
+
type AttemptSnapshot = Attempt;
|
|
334
|
+
type SteeringEntrySnapshot = SteeringEntry;
|
|
335
|
+
type ApprovalRecordSnapshot = ApprovalRecord;
|
|
336
|
+
|
|
337
|
+
declare const DURABLE_EVENT_TYPES: readonly ["session.created", "turn.queued", "turn.started", "turn.paused", "turn.completed", "turn.failed", "turn.cancelled", "steering.queued", "steering.applied", "step.dispatched", "step.approval_requested", "step.approval_resolved", "step.completed", "step.failed", "step.unknown", "step.resolved", "compaction.committed", "sub_turn.linked", "command.applied"];
|
|
338
|
+
type DurableEventType = (typeof DURABLE_EVENT_TYPES)[number];
|
|
339
|
+
declare const REALTIME_EVENT_TYPES: readonly ["text.delta", "reasoning.delta", "tool.call.delta", "tool.progress"];
|
|
340
|
+
type RealtimeEventType = (typeof REALTIME_EVENT_TYPES)[number];
|
|
341
|
+
declare function isDurableEventType(value: unknown): value is DurableEventType;
|
|
342
|
+
declare function isRealtimeEventType(value: unknown): value is RealtimeEventType;
|
|
343
|
+
interface EventCorrelation {
|
|
344
|
+
readonly scope?: ScopeRef;
|
|
345
|
+
readonly sessionId: string;
|
|
346
|
+
readonly rootTurnId: string;
|
|
347
|
+
readonly parentTurnId?: string;
|
|
348
|
+
readonly turnId: string;
|
|
349
|
+
readonly stepId?: string;
|
|
350
|
+
readonly attemptNo?: number;
|
|
351
|
+
readonly traceId: string;
|
|
352
|
+
readonly spanId: string;
|
|
353
|
+
readonly parentSpanId?: string;
|
|
354
|
+
}
|
|
355
|
+
/** Transactional facts only. Credentials must be stripped before persistence. */
|
|
356
|
+
interface DurableRuntimeEvent extends EventCorrelation {
|
|
357
|
+
readonly type: DurableEventType;
|
|
358
|
+
readonly seq: number;
|
|
359
|
+
readonly eventId: string;
|
|
360
|
+
readonly occurredAt: string;
|
|
361
|
+
readonly data?: Readonly<Record<string, unknown>>;
|
|
362
|
+
}
|
|
363
|
+
/** Memory only: no durable sequence or event identity, delivery may be dropped. */
|
|
364
|
+
interface RealtimeEvent extends EventCorrelation {
|
|
365
|
+
readonly type: RealtimeEventType;
|
|
366
|
+
readonly occurredAt: string;
|
|
367
|
+
readonly delta?: string;
|
|
368
|
+
readonly message?: string;
|
|
369
|
+
readonly data?: Readonly<Record<string, unknown>>;
|
|
370
|
+
}
|
|
371
|
+
interface SpanRecord extends EventCorrelation {
|
|
372
|
+
readonly name: string;
|
|
373
|
+
readonly startedAt: string;
|
|
374
|
+
readonly endedAt: string;
|
|
375
|
+
readonly status: "ok" | "error" | "cancelled" | "unknown";
|
|
376
|
+
readonly usage?: UsageMetrics;
|
|
377
|
+
readonly error?: ErrorRecord;
|
|
378
|
+
readonly attributes?: Readonly<Record<string, unknown>>;
|
|
379
|
+
}
|
|
380
|
+
interface ObservabilityHook {
|
|
381
|
+
onDurableEvent(event: DurableRuntimeEvent): void | Promise<void>;
|
|
382
|
+
onRealtimeEvent?(event: RealtimeEvent): void | Promise<void>;
|
|
383
|
+
onSpanEnd?(span: SpanRecord): void | Promise<void>;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
interface StorageAdapter {
|
|
387
|
+
readonly kind: string;
|
|
388
|
+
readonly ledger: LedgerStore;
|
|
389
|
+
readonly artifacts: ArtifactStore;
|
|
390
|
+
readonly outbox: OutboxStore;
|
|
391
|
+
open(): Promise<void>;
|
|
392
|
+
close(): Promise<void>;
|
|
393
|
+
}
|
|
394
|
+
interface CreateSessionInput {
|
|
395
|
+
sessionId: string;
|
|
396
|
+
agentId: string;
|
|
397
|
+
agentVersion: string;
|
|
398
|
+
scope?: ScopeRef;
|
|
399
|
+
context?: Record<string, unknown>;
|
|
400
|
+
}
|
|
401
|
+
interface LeaseRequest {
|
|
402
|
+
holderId: string;
|
|
403
|
+
ttlMs: number;
|
|
404
|
+
}
|
|
405
|
+
interface TurnWrite {
|
|
406
|
+
turnId: string;
|
|
407
|
+
lease: LeaseToken;
|
|
408
|
+
}
|
|
409
|
+
interface AdmitTurnInput {
|
|
410
|
+
toolExecution?: "parallel" | "sequential";
|
|
411
|
+
sessionId: string;
|
|
412
|
+
turnId: string;
|
|
413
|
+
input: string;
|
|
414
|
+
mode: "reject" | "follow_up";
|
|
415
|
+
idempotencyKey?: string;
|
|
416
|
+
context?: Record<string, unknown>;
|
|
417
|
+
limits?: Record<string, number>;
|
|
418
|
+
lease: LeaseRequest;
|
|
419
|
+
}
|
|
420
|
+
interface AdmitTurnResult {
|
|
421
|
+
turn: Turn;
|
|
422
|
+
/** Absent for queued Turns. Idempotent reads never acquire or extend a lease. */
|
|
423
|
+
lease?: LeaseToken;
|
|
424
|
+
duplicate: boolean;
|
|
425
|
+
}
|
|
426
|
+
interface EnqueueSteeringInput {
|
|
427
|
+
turnId: string;
|
|
428
|
+
steeringId: string;
|
|
429
|
+
input: string;
|
|
430
|
+
urgency?: "next_iteration" | "interrupt";
|
|
431
|
+
supersedeApprovals?: boolean;
|
|
432
|
+
fallbackToNewTurn: boolean;
|
|
433
|
+
/** Required admission identity if the target has reached a terminal state. */
|
|
434
|
+
fallback: {
|
|
435
|
+
turnId: string;
|
|
436
|
+
lease: LeaseRequest;
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
type EnqueueSteeringResult = {
|
|
440
|
+
accepted: true;
|
|
441
|
+
mode: "steered" | "promoted_to_turn";
|
|
442
|
+
turnId: string;
|
|
443
|
+
} | {
|
|
444
|
+
accepted: false;
|
|
445
|
+
reason: "turn_already_terminal";
|
|
446
|
+
};
|
|
447
|
+
interface NewStep {
|
|
448
|
+
terminatesTurn?: boolean;
|
|
449
|
+
stepId: string;
|
|
450
|
+
kind: StepKind;
|
|
451
|
+
operationKey: string;
|
|
452
|
+
input?: unknown;
|
|
453
|
+
toolCallId?: string;
|
|
454
|
+
toolName?: string;
|
|
455
|
+
toolVersion?: string;
|
|
456
|
+
effect?: ToolEffect;
|
|
457
|
+
status?: "pending" | "awaiting_approval";
|
|
458
|
+
approvalId?: string;
|
|
459
|
+
}
|
|
460
|
+
/** Records a completed model/compaction attempt, or finalizes its previously started attempt. */
|
|
461
|
+
interface CompletedStepInput {
|
|
462
|
+
stepId: string;
|
|
463
|
+
operationKey: string;
|
|
464
|
+
attemptNo: number;
|
|
465
|
+
input?: unknown;
|
|
466
|
+
output: unknown;
|
|
467
|
+
usage?: UsageMetrics;
|
|
468
|
+
artifacts?: readonly ArtifactRef[];
|
|
469
|
+
protocolId?: string;
|
|
470
|
+
modelId?: string;
|
|
471
|
+
continuation?: unknown;
|
|
472
|
+
continuationArtifact?: ArtifactRef;
|
|
473
|
+
}
|
|
474
|
+
interface ModelDispatchInput extends TurnWrite {
|
|
475
|
+
iteration: number;
|
|
476
|
+
model: CompletedStepInput;
|
|
477
|
+
steps: readonly NewStep[];
|
|
478
|
+
}
|
|
479
|
+
interface CompleteStepInput extends TurnWrite {
|
|
480
|
+
modelOutput?: JsonValue;
|
|
481
|
+
stepId: string;
|
|
482
|
+
attemptNo: number;
|
|
483
|
+
expectedStepVersion: number;
|
|
484
|
+
/**
|
|
485
|
+
* pending archives the running Attempt and leaves the nonterminal Step retryable.
|
|
486
|
+
* Permitted after reconcile proves not_executed, or for a failed/cancelled/unknown
|
|
487
|
+
* Attempt on model_call, compaction, or tool_exec with effect === "none".
|
|
488
|
+
* An external-effect Step always requires reconcile proof of not_executed.
|
|
489
|
+
* Retry diagnostics/results belong to the immutable Attempt, not the pending Step.
|
|
490
|
+
*/
|
|
491
|
+
status: Extract<StepStatus, "completed" | "failed" | "unknown" | "cancelled" | "pending">;
|
|
492
|
+
attemptStatus: Exclude<AttemptStatus, "running">;
|
|
493
|
+
output?: unknown;
|
|
494
|
+
artifacts?: readonly ArtifactRef[];
|
|
495
|
+
usage?: UsageMetrics;
|
|
496
|
+
error?: ErrorRecord;
|
|
497
|
+
evidence?: unknown;
|
|
498
|
+
}
|
|
499
|
+
interface FinishTurnInput extends TurnWrite {
|
|
500
|
+
stopReason?: StopReason;
|
|
501
|
+
providerFinishReason?: string;
|
|
502
|
+
partial?: boolean;
|
|
503
|
+
parentModelOutput?: JsonValue;
|
|
504
|
+
status: TerminalTurnStatus;
|
|
505
|
+
output?: unknown;
|
|
506
|
+
artifacts?: readonly ArtifactRef[];
|
|
507
|
+
error?: ErrorRecord;
|
|
508
|
+
drainQueued?: "keep" | "cancel";
|
|
509
|
+
/** The successor receives a fresh lease; omitted means reuse the current holder/TTL. */
|
|
510
|
+
nextLease?: LeaseRequest;
|
|
511
|
+
}
|
|
512
|
+
interface FinishTurnResult {
|
|
513
|
+
turn: Turn;
|
|
514
|
+
nextTurn?: Turn;
|
|
515
|
+
nextLease?: LeaseToken;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Every mutation is a short atomic transaction including its Outbox events.
|
|
519
|
+
* All TurnWrite operations fence holderId AND epoch AND expiry before mutation,
|
|
520
|
+
* including when the Turn/Step CAS would otherwise fail. No async user work runs
|
|
521
|
+
* inside a transaction. Committed Step/Attempt history is immutable.
|
|
522
|
+
*/
|
|
523
|
+
interface LedgerStore {
|
|
524
|
+
/** Persist validation/approval once, fenced and ordered before tool dispatch. */
|
|
525
|
+
prepareToolStep(input: TurnWrite & {
|
|
526
|
+
stepId: string;
|
|
527
|
+
expectedStepVersion: number;
|
|
528
|
+
validatedInput?: unknown;
|
|
529
|
+
approvalId?: string;
|
|
530
|
+
error?: ErrorRecord;
|
|
531
|
+
}): Promise<Step>;
|
|
532
|
+
/** Skip only unstarted work. Never replace running/unknown effects. */
|
|
533
|
+
skipSteps(input: TurnWrite & {
|
|
534
|
+
stepIds: readonly string[];
|
|
535
|
+
reason: string;
|
|
536
|
+
}): Promise<void>;
|
|
537
|
+
/** Reserve a model request before dispatch, including requests inside compaction. */
|
|
538
|
+
reserveModelCall(input: TurnWrite & {
|
|
539
|
+
stepId: string;
|
|
540
|
+
attemptNo: number;
|
|
541
|
+
}): Promise<boolean>;
|
|
542
|
+
createSession(input: CreateSessionInput): Promise<Session>;
|
|
543
|
+
getSession(sessionId: string, scope?: ScopeRef): Promise<Session | null>;
|
|
544
|
+
/**
|
|
545
|
+
* Detached Turns in deterministic creation/ledger order, independent of Outbox retention.
|
|
546
|
+
* Filters by session and, when supplied, scope; limit takes the earliest matching Turns.
|
|
547
|
+
*/
|
|
548
|
+
listSessionTurns(sessionId: string, options?: {
|
|
549
|
+
scope?: ScopeRef;
|
|
550
|
+
limit?: number;
|
|
551
|
+
}): Promise<readonly Turn[]>;
|
|
552
|
+
/** T1: scope-local payload fingerprint dedup, single active Turn and monotonic FIFO queueSeq. */
|
|
553
|
+
admitTurn(input: AdmitTurnInput): Promise<AdmitTurnResult>;
|
|
554
|
+
/** T2: terminal fallback admission and steering insertion must never be split transactions. */
|
|
555
|
+
enqueueSteering(input: EnqueueSteeringInput): Promise<EnqueueSteeringResult>;
|
|
556
|
+
consumeSteeringAndRecord(input: TurnWrite & {
|
|
557
|
+
iteration: number;
|
|
558
|
+
stepId: string;
|
|
559
|
+
operationKey: string;
|
|
560
|
+
}): Promise<Step | null>;
|
|
561
|
+
commitCompactionStep(input: TurnWrite & {
|
|
562
|
+
iteration: number;
|
|
563
|
+
step: CompletedStepInput;
|
|
564
|
+
compactedUpToStepId: string;
|
|
565
|
+
}): Promise<Step>;
|
|
566
|
+
/** T3: commit model/usage and all proposed siblings; sequential preparation/approval is deferred. */
|
|
567
|
+
commitModelAndDispatchSteps(input: ModelDispatchInput): Promise<TurnSnapshot>;
|
|
568
|
+
startStepAttempt(input: TurnWrite & {
|
|
569
|
+
stepId: string;
|
|
570
|
+
kind: AttemptKind;
|
|
571
|
+
/** Allows persisting a model/compaction Step before performing the outbound call. */
|
|
572
|
+
newStep?: NewStep & {
|
|
573
|
+
iteration: number;
|
|
574
|
+
};
|
|
575
|
+
expectedStepVersion?: number;
|
|
576
|
+
}): Promise<{
|
|
577
|
+
step: Step;
|
|
578
|
+
attempt: Attempt;
|
|
579
|
+
}>;
|
|
580
|
+
/** T4: one Step CAS; never replace sibling results or an already terminal Attempt. */
|
|
581
|
+
completeStep(input: CompleteStepInput): Promise<Step>;
|
|
582
|
+
/** T5a: unique parent tuple; a duplicate is a read-only replay even after parent dehydration. */
|
|
583
|
+
dispatchSubTurn(input: TurnWrite & {
|
|
584
|
+
parentStepId: string;
|
|
585
|
+
child: {
|
|
586
|
+
toolExecution?: "parallel" | "sequential";
|
|
587
|
+
turnId: string;
|
|
588
|
+
/** Child Session must be distinct, preserving each Session's single-active invariant. */
|
|
589
|
+
sessionId: string;
|
|
590
|
+
input: string;
|
|
591
|
+
limits?: Record<string, number>;
|
|
592
|
+
propagation?: {
|
|
593
|
+
cancelWithParent: boolean;
|
|
594
|
+
};
|
|
595
|
+
};
|
|
596
|
+
childLease: LeaseRequest;
|
|
597
|
+
}): Promise<AdmitTurnResult>;
|
|
598
|
+
/** T5b: terminal child + immutable parent Step result + parent wakeRequested, all atomic. */
|
|
599
|
+
completeChildAndWakeParent(input: FinishTurnInput): Promise<{
|
|
600
|
+
child: Turn;
|
|
601
|
+
parent: Turn;
|
|
602
|
+
parentStep: Step;
|
|
603
|
+
}>;
|
|
604
|
+
/**
|
|
605
|
+
* T6: called only after Runtime authorization. Store must independently check
|
|
606
|
+
* scope/state and persist the receipt with the mutation. Mismatched payload
|
|
607
|
+
* fingerprints throw IdempotencyConflictError, including rejected commands.
|
|
608
|
+
* Re-evaluate blockers: resolution > approval > child; wakeable does not mean leased.
|
|
609
|
+
*/
|
|
610
|
+
applyCommand(envelope: CommandEnvelope): Promise<CommandReceipt>;
|
|
611
|
+
/** T7: completed drains FIFO; failed/cancelled preserve (or explicitly cancel) the queue. */
|
|
612
|
+
finishTurnAndDequeue(input: FinishTurnInput): Promise<FinishTurnResult>;
|
|
613
|
+
/** Preempt only expired/released leases; each acquisition increments the persisted epoch. */
|
|
614
|
+
acquireLease(input: {
|
|
615
|
+
turnId: string;
|
|
616
|
+
} & LeaseRequest): Promise<LeaseToken>;
|
|
617
|
+
renewLease(input: TurnWrite & {
|
|
618
|
+
ttlMs: number;
|
|
619
|
+
}): Promise<LeaseToken>;
|
|
620
|
+
releaseLease(input: TurnWrite): Promise<void>;
|
|
621
|
+
listRecoverableTurns(options: {
|
|
622
|
+
scope?: ScopeRef;
|
|
623
|
+
limit: number;
|
|
624
|
+
}): Promise<readonly Turn[]>;
|
|
625
|
+
/** Full history unless afterStepId is supplied; cursor is exclusive and ledger ordered. */
|
|
626
|
+
getTurnSnapshot(turnId: string, options?: {
|
|
627
|
+
scope?: ScopeRef;
|
|
628
|
+
afterStepId?: string;
|
|
629
|
+
}): Promise<TurnSnapshot | null>;
|
|
630
|
+
}
|
|
631
|
+
interface ArtifactStore {
|
|
632
|
+
put(input: {
|
|
633
|
+
data: Uint8Array;
|
|
634
|
+
contentType: string;
|
|
635
|
+
scope?: ScopeRef;
|
|
636
|
+
}): Promise<ArtifactRef>;
|
|
637
|
+
get(ref: ArtifactRef): Promise<Uint8Array | null>;
|
|
638
|
+
/** Optional maintenance capability; ledger references must always protect live blobs. */
|
|
639
|
+
pruneUnreferenced?(options: {
|
|
640
|
+
olderThan: string;
|
|
641
|
+
isReferenced: (sha256: string) => Promise<boolean>;
|
|
642
|
+
limit?: number;
|
|
643
|
+
}): Promise<{
|
|
644
|
+
deletedCount: number;
|
|
645
|
+
freedBytes: number;
|
|
646
|
+
}>;
|
|
647
|
+
}
|
|
648
|
+
interface OutboxBatch {
|
|
649
|
+
events: DurableRuntimeEvent[];
|
|
650
|
+
gap?: {
|
|
651
|
+
fromSeq: number;
|
|
652
|
+
toSeq: number;
|
|
653
|
+
reason: "retention_ttl" | "max_pending_exceeded";
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
interface OutboxStore {
|
|
657
|
+
read(options: {
|
|
658
|
+
consumerId: string;
|
|
659
|
+
afterSeq?: number;
|
|
660
|
+
limit: number;
|
|
661
|
+
}): Promise<OutboxBatch>;
|
|
662
|
+
/** Monotonic per consumer: a stale ack cannot move the cursor backwards. */
|
|
663
|
+
ack(options: {
|
|
664
|
+
consumerId: string;
|
|
665
|
+
upToSeq: number;
|
|
666
|
+
}): Promise<void>;
|
|
667
|
+
prune(policy: {
|
|
668
|
+
maxRetentionMs?: number;
|
|
669
|
+
maxPendingEvents?: number;
|
|
670
|
+
}): Promise<{
|
|
671
|
+
prunedCount: number;
|
|
672
|
+
oldestAvailableSeq: number;
|
|
673
|
+
}>;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export { type ObservabilityHook as $, type ArtifactRef as A, type CompleteStepInput as B, COMMAND_KINDS as C, type CompletedStepInput as D, ConcurrencyConflictError as E, type CreateSessionInput as F, DURABLE_EVENT_TYPES as G, type DurableEventType as H, type DurableRuntimeEvent as I, type JsonValue as J, type EnqueueSteeringInput as K, type EnqueueSteeringResult as L, type ErrorRecord as M, type EventCorrelation as N, type FinishTurnInput as O, type FinishTurnResult as P, HostControlError as Q, IdempotencyConflictError as R, type SchemaIssue as S, type ToolEffect as T, type UsageMetrics as U, LeaseLostError as V, type LeaseRequest as W, type LeaseToken as X, type LedgerStore as Y, type ModelDispatchInput as Z, type NewStep as _, type ScopeRef as a, type OutboxBatch as a0, type OutboxStore as a1, REALTIME_EVENT_TYPES as a2, type RealtimeEvent as a3, type RealtimeEventType as a4, SOIL_ERROR_CODES as a5, STEERING_STATUSES as a6, STEP_KINDS as a7, STEP_STATUSES as a8, type Session as a9, isApprovalStatus as aA, isAttemptKind as aB, isAttemptStatus as aC, isCommandKind as aD, isDurableEventType as aE, isRealtimeEventType as aF, isSteeringStatus as aG, isStepKind as aH, isStepStatus as aI, isTerminalStepStatus as aJ, isTerminalTurnStatus as aK, isToolEffect as aL, isTurnStatus as aM, toErrorRecord as aN, SessionBusyError as aa, type SessionSnapshot as ab, SoilError as ac, type SoilErrorCode as ad, type SpanRecord as ae, type SteeringEntry as af, type SteeringEntrySnapshot as ag, type SteeringStatus as ah, type StepKind as ai, type StepSnapshot as aj, type StepStatus as ak, type StopReason as al, type StorageAdapter as am, TERMINAL_STEP_STATUSES as an, TERMINAL_TURN_STATUSES as ao, TOOL_EFFECTS as ap, TURN_STATUSES as aq, type TerminalTurnStatus as ar, ToolValidationError as as, type Turn as at, type TurnSnapshot as au, type TurnStatus as av, type TurnWrite as aw, type UsageCompleteness as ax, type UsageTotals as ay, aggregateUsageTotals as az, type ArtifactStore as b, type Step as c, type TerminalStepStatus as d, APPROVAL_STATUSES as e, ATTEMPT_KINDS as f, ATTEMPT_STATUSES as g, type AdmitTurnInput as h, type AdmitTurnResult as i, AgentNotRegisteredError as j, type ApprovalRecord as k, type ApprovalRecordSnapshot as l, type ApprovalStatus as m, type Attempt as n, type AttemptKind as o, type AttemptSnapshot as p, type AttemptStatus as q, COMMAND_REJECTION_REASONS as r, type CommandActor as s, type CommandAuthorizer as t, type CommandEnvelope as u, type CommandKind as v, type CommandPayload as w, type CommandReceipt as x, CommandRejectedError as y, type CommandRejectionReason as z };
|