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