@yanlinglabs/winter-agent-sdk 0.0.1

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.
@@ -0,0 +1,598 @@
1
+ import type { InitPluginInfo } from "./config.js";
2
+ export type ProtocolVersion = `${number}.${number}`;
3
+ export declare const PROTOCOL_VERSION: "1.0";
4
+ export interface WireMcpServerStatus {
5
+ name: string;
6
+ status: string;
7
+ }
8
+ export interface InitFrame {
9
+ type: "init";
10
+ protocolVersion: ProtocolVersion;
11
+ sessionId: string;
12
+ cwd: string;
13
+ model: string;
14
+ permissionMode: string;
15
+ tools: string[];
16
+ mcp_servers?: WireMcpServerStatus[];
17
+ [k: string]: unknown;
18
+ }
19
+ export interface UserFrame {
20
+ type: "user";
21
+ text: string;
22
+ [k: string]: unknown;
23
+ }
24
+ export interface DataFrame {
25
+ type: "data";
26
+ message: SdkMessage;
27
+ [k: string]: unknown;
28
+ }
29
+ export interface ControlRequestFrame {
30
+ type: "control_request";
31
+ requestId: string;
32
+ subtype: string;
33
+ payload: unknown;
34
+ }
35
+ export interface ControlResponseFrame {
36
+ type: "control_response";
37
+ requestId: string;
38
+ ok: boolean;
39
+ payload?: unknown;
40
+ error?: {
41
+ code: string;
42
+ message: string;
43
+ };
44
+ }
45
+ export interface UnknownFrame {
46
+ type: string;
47
+ [k: string]: unknown;
48
+ }
49
+ export type WinterFrame = InitFrame | UserFrame | DataFrame | ControlRequestFrame | ControlResponseFrame | UnknownFrame;
50
+ export interface SDKHookStartedMessage {
51
+ type: "system";
52
+ subtype: "hook_started";
53
+ hook_id: string;
54
+ hook_name: string;
55
+ hook_event: string;
56
+ session_id: string;
57
+ uuid: string;
58
+ }
59
+ export interface SDKHookProgressMessage {
60
+ type: "system";
61
+ subtype: "hook_progress";
62
+ hook_id: string;
63
+ hook_name: string;
64
+ hook_event: string;
65
+ stdout: string;
66
+ stderr: string;
67
+ output: string;
68
+ session_id: string;
69
+ uuid: string;
70
+ }
71
+ export interface SDKHookResponseMessage {
72
+ type: "system";
73
+ subtype: "hook_response";
74
+ hook_id: string;
75
+ hook_name: string;
76
+ hook_event: string;
77
+ output: string;
78
+ stdout: string;
79
+ stderr: string;
80
+ exit_code?: number;
81
+ outcome: "success" | "error" | "cancelled";
82
+ session_id: string;
83
+ uuid: string;
84
+ }
85
+ export interface SDKPermissionDeniedMessage {
86
+ type: "system";
87
+ subtype: "permission_denied";
88
+ tool_name: string;
89
+ tool_use_id: string;
90
+ agent_id?: string;
91
+ decision_reason_type?: string;
92
+ decision_reason?: string;
93
+ message: string;
94
+ uuid: string;
95
+ session_id: string;
96
+ }
97
+ export interface SDKPermissionDenial {
98
+ tool_name: string;
99
+ tool_use_id: string;
100
+ tool_input: Record<string, unknown>;
101
+ }
102
+ export interface SDKTaskStartedMessage {
103
+ type: "system";
104
+ subtype: "task_started";
105
+ task_id: string;
106
+ tool_use_id?: string;
107
+ description: string;
108
+ subagent_type?: string;
109
+ is_backgrounded?: boolean;
110
+ spawn_depth?: number;
111
+ task_type?: string;
112
+ workflow_name?: string;
113
+ prompt?: string;
114
+ skip_transcript?: boolean;
115
+ ambient?: boolean;
116
+ uuid: string;
117
+ session_id: string;
118
+ }
119
+ export interface SDKTaskNotificationMessage {
120
+ type: "system";
121
+ subtype: "task_notification";
122
+ task_id: string;
123
+ tool_use_id?: string;
124
+ status: "completed" | "failed" | "stopped";
125
+ output_file: string;
126
+ summary: string;
127
+ usage?: {
128
+ total_tokens: number;
129
+ tool_uses: number;
130
+ duration_ms: number;
131
+ };
132
+ skip_transcript?: boolean;
133
+ ambient?: boolean;
134
+ uuid: string;
135
+ session_id: string;
136
+ }
137
+ export interface SDKTaskUpdatedMessage {
138
+ type: "system";
139
+ subtype: "task_updated";
140
+ task_id: string;
141
+ patch: {
142
+ status?: "pending" | "running" | "completed" | "failed" | "killed" | "paused";
143
+ description?: string;
144
+ end_time?: number;
145
+ total_paused_ms?: number;
146
+ error?: string;
147
+ is_backgrounded?: boolean;
148
+ };
149
+ uuid: string;
150
+ session_id: string;
151
+ }
152
+ export interface SDKTaskProgressMessage {
153
+ type: "system";
154
+ subtype: "task_progress";
155
+ task_id: string;
156
+ tool_use_id?: string;
157
+ description: string;
158
+ subagent_type?: string;
159
+ usage: {
160
+ total_tokens: number;
161
+ tool_uses: number;
162
+ duration_ms: number;
163
+ };
164
+ last_tool_name?: string;
165
+ summary?: string;
166
+ uuid: string;
167
+ session_id: string;
168
+ }
169
+ export interface SDKBackgroundTasksChangedMessage {
170
+ type: "system";
171
+ subtype: "background_tasks_changed";
172
+ tasks: Array<{
173
+ task_id: string;
174
+ task_type: string;
175
+ description: string;
176
+ ambient?: boolean;
177
+ }>;
178
+ uuid: string;
179
+ session_id: string;
180
+ }
181
+ export interface SDKLocalCommandOutputMessage {
182
+ type: "system";
183
+ subtype: "local_command_output";
184
+ content: string;
185
+ uuid: string;
186
+ session_id: string;
187
+ }
188
+ export type BackgroundTaskMessage = SDKTaskStartedMessage | SDKTaskNotificationMessage | SDKTaskUpdatedMessage | SDKTaskProgressMessage | SDKBackgroundTasksChangedMessage | SDKLocalCommandOutputMessage;
189
+ export type SDKStatus = "compacting" | "requesting" | null;
190
+ export interface SDKStatusMessage {
191
+ type: "system";
192
+ subtype: "status";
193
+ status: SDKStatus;
194
+ permissionMode?: string;
195
+ compact_result?: "success" | "failed";
196
+ compact_error?: string;
197
+ uuid: string;
198
+ session_id: string;
199
+ }
200
+ export interface SDKCompactBoundaryMessage {
201
+ type: "system";
202
+ subtype: "compact_boundary";
203
+ compact_metadata: {
204
+ trigger: "manual" | "auto";
205
+ pre_tokens: number;
206
+ post_tokens?: number;
207
+ duration_ms?: number;
208
+ preserved_segment?: {
209
+ head_uuid: string;
210
+ anchor_uuid: string;
211
+ tail_uuid: string;
212
+ };
213
+ preserved_messages?: {
214
+ anchor_uuid: string;
215
+ uuids: string[];
216
+ };
217
+ };
218
+ uuid: string;
219
+ session_id: string;
220
+ }
221
+ export type WireContentBlock = {
222
+ type: "text";
223
+ text: string;
224
+ [k: string]: unknown;
225
+ }
226
+ /** `signature` is a plain string that MAY be `""`: capture (F) shows the pinned runtime normalising a signatureless thinking block to exactly that and REPLAYING it. Optional would let a producer omit it and break the signature chain silently. */
227
+ | {
228
+ type: "thinking";
229
+ thinking: string;
230
+ signature: string;
231
+ [k: string]: unknown;
232
+ }
233
+ /** `data` is OPAQUE provider state. It rides in-dialect (the dialect defines it) and NOWHERE else -- never a log, never an error message, never the advisor transcript (Global Constraints). */
234
+ | {
235
+ type: "redacted_thinking";
236
+ data: string;
237
+ [k: string]: unknown;
238
+ } | {
239
+ type: "tool_use";
240
+ id: string;
241
+ name: string;
242
+ input: unknown;
243
+ [k: string]: unknown;
244
+ } | {
245
+ type: "tool_result";
246
+ tool_use_id: string;
247
+ content: string | WireContentBlock[];
248
+ [k: string]: unknown;
249
+ } | {
250
+ type: "image";
251
+ source: {
252
+ type: "base64";
253
+ media_type: string;
254
+ data: string;
255
+ };
256
+ [k: string]: unknown;
257
+ };
258
+ export type WireStreamEventDelta = {
259
+ type: "text_delta";
260
+ text: string;
261
+ [k: string]: unknown;
262
+ }
263
+ /** `estimated_tokens` is the one delta payload field the pin names at all -- second-hand, in `SDKThinkingTokensMessage`'s own JSDoc (`sdk.d.ts:5015`) -- so it is optional here beside the text Winter's emitter sets. */
264
+ | {
265
+ type: "thinking_delta";
266
+ thinking: string;
267
+ estimated_tokens?: number;
268
+ [k: string]: unknown;
269
+ } | {
270
+ type: "signature_delta";
271
+ signature: string;
272
+ [k: string]: unknown;
273
+ } | {
274
+ type: "input_json_delta";
275
+ partial_json: string;
276
+ [k: string]: unknown;
277
+ };
278
+ export type WireStreamEvent = {
279
+ type: "message_start";
280
+ message?: {
281
+ id?: string;
282
+ model?: string;
283
+ role?: "assistant";
284
+ content?: WireContentBlock[];
285
+ [k: string]: unknown;
286
+ };
287
+ [k: string]: unknown;
288
+ } | {
289
+ type: "content_block_start";
290
+ index: number;
291
+ content_block: WireContentBlock;
292
+ [k: string]: unknown;
293
+ } | {
294
+ type: "content_block_delta";
295
+ index: number;
296
+ delta: WireStreamEventDelta;
297
+ [k: string]: unknown;
298
+ } | {
299
+ type: "content_block_stop";
300
+ index: number;
301
+ [k: string]: unknown;
302
+ } | {
303
+ type: "message_delta";
304
+ delta: {
305
+ stop_reason?: string | null;
306
+ stop_sequence?: string | null;
307
+ [k: string]: unknown;
308
+ };
309
+ usage?: {
310
+ output_tokens?: number;
311
+ [k: string]: unknown;
312
+ };
313
+ [k: string]: unknown;
314
+ } | {
315
+ type: "message_stop";
316
+ [k: string]: unknown;
317
+ };
318
+ /**
319
+ * Phase 6 Task 3 (derived-shapes-p6.md item (a), `sdk.d.ts:4544-4558`): the live-token-streaming frame.
320
+ *
321
+ * SIX FIELDS PLUS THE DISCRIMINANT, and two of them are easy to miss: `ttft_ms?` (`4553`) and
322
+ * `user_message_uuid?` (`4557`). `parent_tool_use_id` is `string | null` and NOT optional -- a
323
+ * main-thread frame emits the key explicitly with `null`, matching `SDKAssistantMessage`'s own
324
+ * convention.
325
+ *
326
+ * GATED on `includePartialMessages` (`1712-1716`), and ADDITIVE: the pin's own JSDoc (`4542`) says
327
+ * the complete `assistant` message still follows as its own message, which is what lets a host ignore
328
+ * `stream_event` entirely and still see every completed block. R6-G: auxiliary provider calls
329
+ * (compaction summariser, classifier, advisor, countTokens) emit NONE of these -- capture (F) observed
330
+ * the pinned runtime suppressing exactly that call's stream events -- and `ttft_ms` rides the FIRST
331
+ * `stream_event` of each forwarded generation.
332
+ */
333
+ export interface SDKPartialAssistantMessage {
334
+ type: "stream_event";
335
+ event: WireStreamEvent;
336
+ parent_tool_use_id: string | null;
337
+ uuid: string;
338
+ session_id: string;
339
+ ttft_ms?: number;
340
+ user_message_uuid?: string;
341
+ }
342
+ /**
343
+ * The pinned provider-error taxonomy, `sdk.d.ts:3159` -- the closed 11-member union carried on
344
+ * `api_retry.error`, `SDKAssistantMessage.error?` and `StopFailureHookInput.error`.
345
+ *
346
+ * These eleven buckets are all a Winter adapter has to map into for parity; anything finer is a
347
+ * Winter extension to disclose (provider-runtime's `ProviderError.providerCode` is exactly that).
348
+ * DECLARED HERE as well as in provider-runtime's `types.ts` on purpose: this package is
349
+ * dependency-free and fence-resident and cannot import the Bun-only one, and the frame that carries
350
+ * the union must declare what it carries.
351
+ */
352
+ export type SDKAssistantMessageError = "authentication_failed" | "oauth_org_not_allowed" | "account_on_hold" | "billing_error" | "rate_limit" | "overloaded" | "invalid_request" | "model_not_found" | "server_error" | "unknown" | "max_output_tokens";
353
+ /**
354
+ * `sdk.d.ts:3085-3095` (JSDoc `3083`). Nine keys, ALL REQUIRED -- none optional.
355
+ *
356
+ * `error_status: number | null`: the null case is a connection error (e.g. a timeout) that had no
357
+ * HTTP response, which is why provider-runtime's `ProviderError.status` is ABSENT rather than `null`
358
+ * for that case and this frame's producer maps absence to `null` at the boundary.
359
+ *
360
+ * R6-6/R6-C: one frame per retry attempt, announced BEFORE the delay is taken; `max_retries` is 10
361
+ * (capture (G) pinned it on every frame of all three runs).
362
+ */
363
+ export interface SDKAPIRetryMessage {
364
+ type: "system";
365
+ subtype: "api_retry";
366
+ attempt: number;
367
+ max_retries: number;
368
+ retry_delay_ms: number;
369
+ error_status: number | null;
370
+ error: SDKAssistantMessageError;
371
+ uuid: string;
372
+ session_id: string;
373
+ }
374
+ /**
375
+ * `sdk.d.ts:4651-4669`. Every field except `status` is optional, and the vocabulary is
376
+ * consumer-SUBSCRIPTION-shaped throughout -- which is the whole point of R6-B.
377
+ */
378
+ export interface SDKRateLimitInfo {
379
+ status: "allowed" | "allowed_warning" | "rejected";
380
+ rateLimitType?: "five_hour" | "seven_day" | "seven_day_opus" | "seven_day_sonnet" | "seven_day_overage_included" | "overage";
381
+ resetsAt?: number;
382
+ utilization?: number;
383
+ [k: string]: unknown;
384
+ }
385
+ /**
386
+ * `sdk.d.ts:4638-4646`. A TOP-LEVEL `type`, not a `system` subtype -- unlike `api_retry`/`status`/
387
+ * `thinking_tokens`/the refusal pair. `auth_status` and `tool_progress` share this convention.
388
+ *
389
+ * **R6-B: an HTTP 429 is NOT this frame.** Capture (G) proved the pinned runtime emits ZERO
390
+ * `rate_limit_event` frames for a 429 carrying a full `anthropic-ratelimit-*` header set with a
391
+ * `rejected` unified status; the pinned 429 path is `api_retry` with `error_status: 429` and
392
+ * `error: "rate_limit"`. Winter emits this ONLY for subscription-shaped quota states (the codex-oauth
393
+ * quota manager's limited/`resumeAt`), and header-derived limits never become frames at all.
394
+ */
395
+ export interface SDKRateLimitEvent {
396
+ type: "rate_limit_event";
397
+ rate_limit_info: SDKRateLimitInfo;
398
+ uuid: string;
399
+ session_id: string;
400
+ }
401
+ /**
402
+ * `sdk.d.ts:3161-3168`. Top-level `type`, four payload fields, and NO JSDoc at all on the pin.
403
+ *
404
+ * R6-F: this is a LOGIN-FLOW PROGRESS channel (codex-oauth login/refresh), never the
405
+ * credential-failure frame -- a bad key is a provider error that lands on the result shape.
406
+ * `isAuthenticating: boolean` + `output: string[]` is a running transcript of an interactive auth
407
+ * attempt, which is what that shape reads as.
408
+ */
409
+ export interface SDKAuthStatusMessage {
410
+ type: "auth_status";
411
+ isAuthenticating: boolean;
412
+ output: string[];
413
+ error?: string;
414
+ uuid: string;
415
+ session_id: string;
416
+ }
417
+ /**
418
+ * `sdk.d.ts:5017-5024` (JSDoc `5015`). NOT gated on `includePartialMessages`: a host that never opts
419
+ * into `stream_event` still gets thinking progress. `estimated_tokens` is the running total for the
420
+ * CURRENT thinking block and `estimated_tokens_delta` this frame's increment; both are approximate
421
+ * progress for a spinner, explicitly not the billed `output_tokens`.
422
+ */
423
+ export interface SDKThinkingTokensMessage {
424
+ type: "system";
425
+ subtype: "thinking_tokens";
426
+ estimated_tokens: number;
427
+ estimated_tokens_delta: number;
428
+ uuid: string;
429
+ session_id: string;
430
+ }
431
+ /**
432
+ * `sdk.d.ts:4476-4508` (JSDoc `4474`). `trigger` is the literal `'refusal'` and NOTHING ELSE, and
433
+ * the JSDoc scopes emission to "the primary model ends the stream with `stop_reason` 'refusal' and
434
+ * the turn is retried once on a fallback model".
435
+ *
436
+ * **A MODEL-REFUSAL FALLBACK IS NOT AN OVERLOAD FALLBACK** (R6-C). Capture (G) confirmed the overload
437
+ * swap is FRAME-INVISIBLE on the pin; Winter emits its own `system/model_switch` for that and this
438
+ * pinned pair only on `stopReason: "refusal"`.
439
+ *
440
+ * `direction`'s `'revert'`/`'sticky'` are doc-marked as retained for consumer compat and no longer
441
+ * emitted. `api_refusal_explanation` is doc-marked unstable human prose, display-only, NEVER to be
442
+ * parsed -- a rule Winter carries verbatim.
443
+ */
444
+ export interface SDKModelRefusalFallbackMessage {
445
+ type: "system";
446
+ subtype: "model_refusal_fallback";
447
+ trigger: "refusal";
448
+ direction: "retry" | "revert" | "sticky";
449
+ scope?: "session" | "local";
450
+ original_model: string;
451
+ fallback_model: string;
452
+ request_id: string | null;
453
+ api_refusal_category?: string | null;
454
+ api_refusal_explanation?: string | null;
455
+ retracted_message_uuids?: string[];
456
+ refused_user_message_uuid?: string | null;
457
+ content: string;
458
+ uuid: string;
459
+ session_id: string;
460
+ }
461
+ /** `sdk.d.ts:4513-4523` (JSDoc `4511`): the refusal produced NO retry. Nine fields -- no `direction`/`scope`/`fallback_model`, because there is no fallback to name. */
462
+ export interface SDKModelRefusalNoFallbackMessage {
463
+ type: "system";
464
+ subtype: "model_refusal_no_fallback";
465
+ trigger: "refusal";
466
+ original_model: string;
467
+ request_id: string | null;
468
+ api_refusal_category?: string | null;
469
+ api_refusal_explanation?: string | null;
470
+ retracted_message_uuids?: string[];
471
+ refused_user_message_uuid?: string | null;
472
+ content: string;
473
+ uuid: string;
474
+ session_id: string;
475
+ }
476
+ /**
477
+ * R6-8: a foreign model's reasoning SUMMARY, surfaced live WITHOUT entering the transcript.
478
+ *
479
+ * Capture (F) settled why this frame has to exist: the pinned runtime never emits or replays a
480
+ * thinking block without a `signature` key -- when the stream carries none it materialises `""` -- so
481
+ * a foreign summary written into `assistant.message.content` as a `thinking` block would go on the
482
+ * wire carrying an empty or fabricated signature. That is precisely the impersonation R6-8 forbids,
483
+ * and the pin offers no mechanism to omit the field instead. The summary therefore lives in the
484
+ * provider-state sidecar and rides this frame; Anthropic-family thinking/redacted blocks ride
485
+ * in-dialect with their REAL signatures, exactly as before.
486
+ */
487
+ export interface SDKReasoningSummaryMessage {
488
+ type: "system";
489
+ subtype: "reasoning_summary";
490
+ text: string;
491
+ provider: string;
492
+ model: string;
493
+ uuid: string;
494
+ session_id: string;
495
+ }
496
+ /**
497
+ * R6-C: the model this session is generating with CHANGED, and the pin has no frame that says so.
498
+ *
499
+ * `reason` distinguishes the three producers: `"fallback"` (the primary was abandoned per
500
+ * `fallbackModel`), `"set_model"` (a host asked, applied at the quiescent boundary), and
501
+ * `"interrupt"` (a pending switch applied immediately because the turn was interrupted). The swap is
502
+ * additionally recorded in the dialect record's `providerHistory`, so a transcript reader can
503
+ * reconstruct which model produced which entry after the fact.
504
+ */
505
+ export interface SDKModelSwitchMessage {
506
+ type: "system";
507
+ subtype: "model_switch";
508
+ reason: "fallback" | "set_model" | "interrupt";
509
+ from_model: string;
510
+ to_model: string;
511
+ provider: string;
512
+ uuid: string;
513
+ session_id: string;
514
+ }
515
+ /**
516
+ * R6-7: a resume found the provider-state chain incomplete, so some message was degraded.
517
+ *
518
+ * THE SIMPLEST OF THE TWO CHANNELS THE PLAN OFFERED, and the choice is recorded here rather than left
519
+ * implicit: the alternative was a warning list threaded onto the history renderer's input, but the
520
+ * renderer is Lane C's and the ledger pins `ContinuationChain` as the bare `Map` `buildContinuationChain`
521
+ * returns -- a warning list would have had to ride a second, parallel return value through a frozen
522
+ * signature. A frame reaches the host directly, needs no seam, and is where a user-visible degradation
523
+ * belongs.
524
+ *
525
+ * `detail` is Winter-authored prose about COUNTS and IDENTITY only. It never names or contains opaque
526
+ * provider state (Global Constraints).
527
+ */
528
+ export interface SDKContinuityWarningMessage {
529
+ type: "system";
530
+ subtype: "continuity_warning";
531
+ /**
532
+ * Five values (P6 fix wave). `provider_state_missing` / `provider_state_deleted` /
533
+ * `sidecar_unreadable` are emitted on a RESUME (`store/continuation-attach.ts`);
534
+ * `cross_domain_replay_dropped` at a MODEL SWITCH whose loss class is `warned-lossy` (Ruling E-2,
535
+ * `applyPendingModelSwitch`); `child_provider_refused` when an R6-17 child named a model on
536
+ * ANOTHER provider for which no credential is configured (Ruling E-1 / R-E3) -- the child then
537
+ * runs on a deferred-refusal provider whose first generation is R6-F's result with no request,
538
+ * never the parent's provider with a foreign model id on the parent's wire.
539
+ */
540
+ warning: "provider_state_missing" | "provider_state_deleted" | "cross_domain_replay_dropped" | "sidecar_unreadable" | "child_provider_refused";
541
+ detail: string;
542
+ anchor_uuid?: string;
543
+ uuid: string;
544
+ session_id: string;
545
+ }
546
+ export type SdkMessage = {
547
+ type: "system";
548
+ subtype: "init";
549
+ session_id: string;
550
+ cwd: string;
551
+ model: string;
552
+ permissionMode: string;
553
+ tools: string[];
554
+ slash_commands: string[];
555
+ terminal_slash_commands?: string[];
556
+ output_style: string;
557
+ skills: string[];
558
+ plugins: InitPluginInfo[];
559
+ mcp_servers?: WireMcpServerStatus[];
560
+ [k: string]: unknown;
561
+ } | SDKHookStartedMessage | SDKHookProgressMessage | SDKHookResponseMessage | SDKPermissionDeniedMessage | SDKStatusMessage | SDKCompactBoundaryMessage | BackgroundTaskMessage | SDKPartialAssistantMessage | SDKAPIRetryMessage | SDKRateLimitEvent | SDKAuthStatusMessage | SDKThinkingTokensMessage | SDKModelRefusalFallbackMessage | SDKModelRefusalNoFallbackMessage | SDKReasoningSummaryMessage | SDKModelSwitchMessage | SDKContinuityWarningMessage | {
562
+ type: "assistant";
563
+ message: {
564
+ content: Array<{
565
+ type: "text";
566
+ text: string;
567
+ } | {
568
+ type: string;
569
+ [k: string]: unknown;
570
+ }>;
571
+ };
572
+ parent_tool_use_id?: string | null;
573
+ [k: string]: unknown;
574
+ } | {
575
+ type: "user";
576
+ message: {
577
+ role: "user";
578
+ content: Array<{
579
+ type: string;
580
+ [k: string]: unknown;
581
+ }>;
582
+ };
583
+ parent_tool_use_id?: string | null;
584
+ [k: string]: unknown;
585
+ } | {
586
+ type: "result";
587
+ subtype: "success" | "error_max_turns" | "error_during_execution" | "error_max_budget_usd" | "error_max_structured_output_retries" | string;
588
+ is_error?: boolean;
589
+ result?: string;
590
+ structured_output?: unknown;
591
+ terminal_reason?: "structured_output_retry_exhausted" | "api_error" | string;
592
+ api_error_status?: number | null;
593
+ permission_denials: SDKPermissionDenial[];
594
+ [k: string]: unknown;
595
+ } | {
596
+ type: string;
597
+ [k: string]: unknown;
598
+ };
@@ -0,0 +1,81 @@
1
+ import type { SdkMessage as RuntimeSdkMessage } from "./protocol/frames.js";
2
+ import type { AccountInfo, ModelInfo, ModelFamilyListing, RewindFilesResult } from "./protocol/config.js";
3
+ import { type Options } from "./options.js";
4
+ import type { PermissionMode, PermissionResult } from "./permissions/types.js";
5
+ export type SdkMessage = Extract<RuntimeSdkMessage, {
6
+ type: "system";
7
+ } | {
8
+ type: "assistant";
9
+ } | {
10
+ type: "result";
11
+ }>;
12
+ export type ControlRequestHandlerResult = {
13
+ ok: true;
14
+ payload?: unknown;
15
+ } | {
16
+ ok: false;
17
+ error: {
18
+ code: string;
19
+ message: string;
20
+ };
21
+ };
22
+ export type ControlRequestHandler = (payload: unknown) => Promise<ControlRequestHandlerResult>;
23
+ export interface QueryInternal {
24
+ registerControlRequestHandler(subtype: string, handler: ControlRequestHandler): void;
25
+ respondPermission(requestId: string, result: PermissionResult): void;
26
+ }
27
+ export interface Query extends AsyncGenerator<SdkMessage> {
28
+ interrupt(): Promise<void>;
29
+ setModel(model?: string): Promise<void>;
30
+ /**
31
+ * Phase 6 Task 10 (derived-shapes-p6 item (d), `sdk.d.ts:2566`): the models this session may select.
32
+ *
33
+ * A BARE ARRAY — no envelope, no default marker, no "current model" field; the current model is read
34
+ * from `system/init.model` instead, and no pinned `Query` method returns it. Served from the
35
+ * worker's own registry (capture (J): the pinned runtime issues no `/v1/models` request for this),
36
+ * so the answer is a table lookup rather than a network round trip.
37
+ */
38
+ supportedModels(): Promise<ModelInfo[]>;
39
+ /**
40
+ * WS-13c §7 (P6.6 Lane C) — WINTER-ONLY, no pinned counterpart: the active slot set this session is
41
+ * currently offering, plus every model family behind "more options". A model switcher shows
42
+ * `active.slots` first and renders `families[].models` any way it likes (§7's own last sentence).
43
+ *
44
+ * Rides its own `list_model_families` control subtype, same shape as `supportedModels`/`accountInfo`
45
+ * above. A malformed or absent runtime payload degrades to `{ active: undefined, families: [] }`
46
+ * rather than a throw — this method answers with data, so a rejected promise could not tell "no
47
+ * families configured" from a transport fault.
48
+ */
49
+ listModelFamilies(): Promise<ModelFamilyListing>;
50
+ /**
51
+ * `AccountInfo` for this session (`sdk.d.ts:2632`). Every field is optional and an empty object is a
52
+ * valid answer — capture (J) observed exactly three keys present under API-key auth.
53
+ *
54
+ * DISCLOSED DIVERGENCE IN THE TRANSPORT, not in the shape: the pin carries `AccountInfo` on the
55
+ * `initialize`/`reinitialize` response, a surface Winter's protocol does not have, so this rides its
56
+ * own Winter-only `account_info` control subtype. The public method and its return shape are the
57
+ * pin's.
58
+ */
59
+ accountInfo(): Promise<AccountInfo>;
60
+ /**
61
+ * Phase 5 Task 3 (R5-11, derived-shapes-p5 item (e)): restore every tracked file to its state at
62
+ * `userMessageId`. Requires `enableFileCheckpointing`; without it the result is
63
+ * `{canRewind: false, error}`, never a throw.
64
+ *
65
+ * The parameter is `userMessageId` on the pin -- its own `@param` line describes the VALUE as a
66
+ * uuid, so the name and the value disagree; WS-11 §9 and the phase plan both wrote
67
+ * `userMessageUuid` and are corrected here to the shape authority.
68
+ *
69
+ * `dryRun` previews without touching the filesystem -- and, per item (e), without populating
70
+ * `skippedLinks`, so a preview's counts do not reflect link-safety refusals.
71
+ */
72
+ rewindFiles(userMessageId: string, options?: {
73
+ dryRun?: boolean;
74
+ }): Promise<RewindFilesResult>;
75
+ setPermissionMode(mode: PermissionMode): Promise<void>;
76
+ __internal?: QueryInternal;
77
+ }
78
+ export declare function query(args: {
79
+ prompt: string | AsyncIterable<string>;
80
+ options: Options;
81
+ }): Query;