@get-bb/plugin-sdk 0.6.150 → 0.6.164

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,1001 @@
1
+ // Portable type declarations for `@get-bb/plugin-sdk`. Unpublished BB
2
+ // workspace contracts are flattened; public subpaths may reuse the
3
+ // package root without requiring any other @bb/* package.
4
+ //
5
+ // Confused by the API, or need a symbol that isn't here? Clone the BB repo
6
+ // and read the real source: https://github.com/get-bb/bb
7
+
8
+ import { z } from 'zod';
9
+
10
+ interface JsonObject {
11
+ [key: string]: JsonValue;
12
+ }
13
+ type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;
14
+
15
+ declare const hostSchema: z.ZodObject<{
16
+ createdAt: z.ZodNumber;
17
+ id: z.ZodString;
18
+ lastRejectedProtocolVersion: z.ZodNullable<z.ZodNumber>;
19
+ lastSeenAt: z.ZodNullable<z.ZodNumber>;
20
+ lifecycle: z.ZodObject<{
21
+ message: z.ZodNullable<z.ZodString>;
22
+ pendingLog: z.ZodString;
23
+ phase: z.ZodEnum<{
24
+ active: "active";
25
+ creating: "creating";
26
+ destroyed: "destroyed";
27
+ removing: "removing";
28
+ resuming: "resuming";
29
+ suspended: "suspended";
30
+ suspending: "suspending";
31
+ }>;
32
+ suspendedAt: z.ZodNullable<z.ZodNumber>;
33
+ teardown: z.ZodNullable<z.ZodObject<{
34
+ attempt: z.ZodNumber;
35
+ blockedByEnvironmentId: z.ZodNullable<z.ZodString>;
36
+ needsRecovery: z.ZodBoolean;
37
+ status: z.ZodEnum<{
38
+ failed: "failed";
39
+ removed: "removed";
40
+ running: "running";
41
+ }>;
42
+ }, z.core.$strip>>;
43
+ }, z.core.$strip>;
44
+ machineProviderId: z.ZodNullable<z.ZodString>;
45
+ maxPermissionMode: z.ZodEnum<{
46
+ "accept-edits": "accept-edits";
47
+ auto: "auto";
48
+ full: "full";
49
+ }>;
50
+ name: z.ZodString;
51
+ status: z.ZodEnum<{
52
+ connected: "connected";
53
+ disconnected: "disconnected";
54
+ }>;
55
+ type: z.ZodEnum<{
56
+ ephemeral: "ephemeral";
57
+ persistent: "persistent";
58
+ }>;
59
+ updatedAt: z.ZodNumber;
60
+ }, z.core.$strip>;
61
+ type Host = z.infer<typeof hostSchema>;
62
+
63
+ declare const providerErrorInfoSchema: z.ZodObject<{
64
+ category: z.ZodEnum<{
65
+ "active-turn-not-steerable": "active-turn-not-steerable";
66
+ "bad-request": "bad-request";
67
+ "budget-exceeded": "budget-exceeded";
68
+ "connection-failed": "connection-failed";
69
+ "context-window-exceeded": "context-window-exceeded";
70
+ "max-output-tokens": "max-output-tokens";
71
+ "max-turns": "max-turns";
72
+ "rate-limit": "rate-limit";
73
+ "stream-disconnected": "stream-disconnected";
74
+ "structured-output-retries": "structured-output-retries";
75
+ "thread-rollback-failed": "thread-rollback-failed";
76
+ "too-many-failed-attempts": "too-many-failed-attempts";
77
+ billing: "billing";
78
+ internal: "internal";
79
+ overloaded: "overloaded";
80
+ policy: "policy";
81
+ sandbox: "sandbox";
82
+ unauthorized: "unauthorized";
83
+ unknown: "unknown";
84
+ }>;
85
+ httpStatusCode: z.ZodNullable<z.ZodNumber>;
86
+ providerCode: z.ZodNullable<z.ZodString>;
87
+ }, z.core.$strip>;
88
+ type ProviderErrorInfo = z.infer<typeof providerErrorInfoSchema>;
89
+ declare const providerRateLimitStateSchema: z.ZodObject<{
90
+ kind: z.ZodEnum<{
91
+ "spend-control": "spend-control";
92
+ "subscription-window": "subscription-window";
93
+ credits: "credits";
94
+ unknown: "unknown";
95
+ }>;
96
+ overageReason: z.ZodNullable<z.ZodString>;
97
+ overageStatus: z.ZodNullable<z.ZodEnum<{
98
+ allowed: "allowed";
99
+ rejected: "rejected";
100
+ unavailable: "unavailable";
101
+ warning: "warning";
102
+ }>>;
103
+ providerId: z.ZodString;
104
+ reachedReason: z.ZodNullable<z.ZodString>;
105
+ status: z.ZodEnum<{
106
+ allowed: "allowed";
107
+ blocked: "blocked";
108
+ unknown: "unknown";
109
+ warning: "warning";
110
+ }>;
111
+ windows: z.ZodArray<z.ZodObject<{
112
+ label: z.ZodNullable<z.ZodString>;
113
+ providerKey: z.ZodNullable<z.ZodString>;
114
+ resetsAtMs: z.ZodNullable<z.ZodNumber>;
115
+ status: z.ZodEnum<{
116
+ allowed: "allowed";
117
+ blocked: "blocked";
118
+ unknown: "unknown";
119
+ warning: "warning";
120
+ }>;
121
+ }, z.core.$strip>>;
122
+ }, z.core.$strip>;
123
+ type ProviderRateLimitState = z.infer<typeof providerRateLimitStateSchema>;
124
+
125
+ declare const providerPendingInteractionSchema: z.ZodUnion<readonly [z.ZodObject<{
126
+ createdAt: z.ZodNumber;
127
+ expiresAt: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
128
+ id: z.ZodString;
129
+ origin: z.ZodOptional<z.ZodObject<{
130
+ kind: z.ZodLiteral<"provider">;
131
+ providerId: z.ZodString;
132
+ providerRequestId: z.ZodString;
133
+ providerThreadId: z.ZodString;
134
+ }, z.core.$strip>>;
135
+ payload: z.ZodObject<{
136
+ availableDecisions: z.ZodArray<z.ZodEnum<{
137
+ allow_for_session: "allow_for_session";
138
+ allow_once: "allow_once";
139
+ deny: "deny";
140
+ }>>;
141
+ kind: z.ZodLiteral<"approval">;
142
+ reason: z.ZodNullable<z.ZodString>;
143
+ subject: z.ZodDiscriminatedUnion<[z.ZodObject<{
144
+ actions: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
145
+ command: z.ZodString;
146
+ name: z.ZodString;
147
+ path: z.ZodString;
148
+ type: z.ZodLiteral<"read">;
149
+ }, z.core.$strip>, z.ZodObject<{
150
+ command: z.ZodString;
151
+ path: z.ZodNullable<z.ZodString>;
152
+ type: z.ZodLiteral<"listFiles">;
153
+ }, z.core.$strip>, z.ZodObject<{
154
+ command: z.ZodString;
155
+ path: z.ZodNullable<z.ZodString>;
156
+ query: z.ZodNullable<z.ZodString>;
157
+ type: z.ZodLiteral<"search">;
158
+ }, z.core.$strip>, z.ZodObject<{
159
+ command: z.ZodString;
160
+ type: z.ZodLiteral<"unknown">;
161
+ }, z.core.$strip>], "type">>;
162
+ command: z.ZodString;
163
+ cwd: z.ZodNullable<z.ZodString>;
164
+ itemId: z.ZodString;
165
+ kind: z.ZodLiteral<"command">;
166
+ sessionGrant: z.ZodNullable<z.ZodObject<{
167
+ fileSystem: z.ZodNullable<z.ZodObject<{
168
+ read: z.ZodArray<z.ZodString>;
169
+ write: z.ZodArray<z.ZodString>;
170
+ }, z.core.$strip>>;
171
+ network: z.ZodNullable<z.ZodObject<{
172
+ enabled: z.ZodNullable<z.ZodBoolean>;
173
+ }, z.core.$strip>>;
174
+ }, z.core.$strict>>;
175
+ }, z.core.$strip>, z.ZodObject<{
176
+ itemId: z.ZodString;
177
+ kind: z.ZodLiteral<"file_change">;
178
+ sessionGrant: z.ZodNullable<z.ZodObject<{
179
+ fileSystem: z.ZodNullable<z.ZodObject<{
180
+ read: z.ZodArray<z.ZodString>;
181
+ write: z.ZodArray<z.ZodString>;
182
+ }, z.core.$strip>>;
183
+ network: z.ZodNullable<z.ZodObject<{
184
+ enabled: z.ZodNullable<z.ZodBoolean>;
185
+ }, z.core.$strip>>;
186
+ }, z.core.$strict>>;
187
+ writeScope: z.ZodNullable<z.ZodString>;
188
+ }, z.core.$strip>, z.ZodObject<{
189
+ itemId: z.ZodString;
190
+ kind: z.ZodLiteral<"permission_grant">;
191
+ permissions: z.ZodObject<{
192
+ fileSystem: z.ZodNullable<z.ZodObject<{
193
+ read: z.ZodArray<z.ZodString>;
194
+ write: z.ZodArray<z.ZodString>;
195
+ }, z.core.$strip>>;
196
+ network: z.ZodNullable<z.ZodObject<{
197
+ enabled: z.ZodNullable<z.ZodBoolean>;
198
+ }, z.core.$strip>>;
199
+ }, z.core.$strict>;
200
+ toolName: z.ZodNullable<z.ZodString>;
201
+ }, z.core.$strip>, z.ZodObject<{
202
+ itemId: z.ZodString;
203
+ kind: z.ZodLiteral<"plan">;
204
+ plan: z.ZodString;
205
+ planFilePath: z.ZodNullable<z.ZodString>;
206
+ }, z.core.$strip>, z.ZodObject<{
207
+ itemId: z.ZodString;
208
+ kind: z.ZodLiteral<"tool_use">;
209
+ presentation: z.ZodObject<{
210
+ badge: z.ZodOptional<z.ZodObject<{
211
+ glyph: z.ZodString;
212
+ hint: z.ZodString;
213
+ label: z.ZodString;
214
+ tone: z.ZodEnum<{
215
+ destructive: "destructive";
216
+ neutral: "neutral";
217
+ }>;
218
+ }, z.core.$strip>>;
219
+ detail: z.ZodOptional<z.ZodString>;
220
+ icon: z.ZodObject<{
221
+ glyph: z.ZodString;
222
+ }, z.core.$strip>;
223
+ label: z.ZodObject<{
224
+ completed: z.ZodString;
225
+ pending: z.ZodString;
226
+ }, z.core.$strip>;
227
+ suppress: z.ZodOptional<z.ZodBoolean>;
228
+ tint: z.ZodOptional<z.ZodObject<{
229
+ dark: z.ZodString;
230
+ light: z.ZodString;
231
+ }, z.core.$strip>>;
232
+ title: z.ZodOptional<z.ZodString>;
233
+ }, z.core.$strip>;
234
+ tool: z.ZodString;
235
+ }, z.core.$strip>], "kind">;
236
+ }, z.core.$strip>;
237
+ providerId: z.ZodString;
238
+ providerRequestId: z.ZodString;
239
+ providerThreadId: z.ZodString;
240
+ resolution: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
241
+ decision: z.ZodLiteral<"allow_once">;
242
+ grantedPermissions: z.ZodNullable<z.ZodObject<{
243
+ fileSystem: z.ZodNullable<z.ZodObject<{
244
+ read: z.ZodArray<z.ZodString>;
245
+ write: z.ZodArray<z.ZodString>;
246
+ }, z.core.$strip>>;
247
+ network: z.ZodNullable<z.ZodObject<{
248
+ enabled: z.ZodNullable<z.ZodBoolean>;
249
+ }, z.core.$strip>>;
250
+ }, z.core.$strict>>;
251
+ }, z.core.$strip>, z.ZodObject<{
252
+ decision: z.ZodLiteral<"allow_for_session">;
253
+ grantedPermissions: z.ZodNullable<z.ZodObject<{
254
+ fileSystem: z.ZodNullable<z.ZodObject<{
255
+ read: z.ZodArray<z.ZodString>;
256
+ write: z.ZodArray<z.ZodString>;
257
+ }, z.core.$strip>>;
258
+ network: z.ZodNullable<z.ZodObject<{
259
+ enabled: z.ZodNullable<z.ZodBoolean>;
260
+ }, z.core.$strip>>;
261
+ }, z.core.$strict>>;
262
+ }, z.core.$strip>, z.ZodObject<{
263
+ decision: z.ZodLiteral<"deny">;
264
+ }, z.core.$strip>], "decision">>;
265
+ resolvedAt: z.ZodNullable<z.ZodNumber>;
266
+ status: z.ZodEnum<{
267
+ interrupted: "interrupted";
268
+ pending: "pending";
269
+ resolved: "resolved";
270
+ resolving: "resolving";
271
+ }>;
272
+ statusReason: z.ZodNullable<z.ZodString>;
273
+ threadId: z.ZodString;
274
+ turnId: z.ZodString;
275
+ }, z.core.$strip>, z.ZodObject<{
276
+ createdAt: z.ZodNumber;
277
+ expiresAt: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
278
+ id: z.ZodString;
279
+ origin: z.ZodOptional<z.ZodObject<{
280
+ kind: z.ZodLiteral<"provider">;
281
+ providerId: z.ZodString;
282
+ providerRequestId: z.ZodString;
283
+ providerThreadId: z.ZodString;
284
+ }, z.core.$strip>>;
285
+ payload: z.ZodObject<{
286
+ kind: z.ZodLiteral<"user_question">;
287
+ questions: z.ZodArray<z.ZodObject<{
288
+ allowFreeText: z.ZodBoolean;
289
+ id: z.ZodString;
290
+ multiSelect: z.ZodBoolean;
291
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
292
+ description: z.ZodOptional<z.ZodString>;
293
+ label: z.ZodString;
294
+ value: z.ZodString;
295
+ }, z.core.$strip>>>;
296
+ prompt: z.ZodString;
297
+ required: z.ZodDefault<z.ZodBoolean>;
298
+ shortLabel: z.ZodOptional<z.ZodString>;
299
+ }, z.core.$strip>>;
300
+ }, z.core.$strip>;
301
+ providerId: z.ZodString;
302
+ providerRequestId: z.ZodString;
303
+ providerThreadId: z.ZodString;
304
+ resolution: z.ZodNullable<z.ZodObject<{
305
+ answers: z.ZodRecord<z.ZodString, z.ZodObject<{
306
+ freeText: z.ZodOptional<z.ZodString>;
307
+ selected: z.ZodArray<z.ZodString>;
308
+ }, z.core.$strip>>;
309
+ kind: z.ZodLiteral<"user_answer">;
310
+ }, z.core.$strip>>;
311
+ resolvedAt: z.ZodNullable<z.ZodNumber>;
312
+ status: z.ZodEnum<{
313
+ interrupted: "interrupted";
314
+ pending: "pending";
315
+ resolved: "resolved";
316
+ resolving: "resolving";
317
+ }>;
318
+ statusReason: z.ZodNullable<z.ZodString>;
319
+ threadId: z.ZodString;
320
+ turnId: z.ZodString;
321
+ }, z.core.$strip>, z.ZodObject<{
322
+ createdAt: z.ZodNumber;
323
+ expiresAt: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
324
+ id: z.ZodString;
325
+ origin: z.ZodOptional<z.ZodObject<{
326
+ kind: z.ZodLiteral<"provider">;
327
+ providerId: z.ZodString;
328
+ providerRequestId: z.ZodString;
329
+ providerThreadId: z.ZodString;
330
+ }, z.core.$strip>>;
331
+ payload: z.ZodObject<{
332
+ data: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
333
+ kind: z.ZodString & z.ZodType<`${string}/${string}`, string, z.core.$ZodTypeInternals<`${string}/${string}`, string>>;
334
+ title: z.ZodString;
335
+ }, z.core.$strip>;
336
+ providerId: z.ZodString;
337
+ providerRequestId: z.ZodString;
338
+ providerThreadId: z.ZodString;
339
+ resolution: z.ZodNullable<z.ZodObject<{
340
+ kind: z.ZodLiteral<"request_answer">;
341
+ value: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
342
+ }, z.core.$strip>>;
343
+ resolvedAt: z.ZodNullable<z.ZodNumber>;
344
+ status: z.ZodEnum<{
345
+ interrupted: "interrupted";
346
+ pending: "pending";
347
+ resolved: "resolved";
348
+ resolving: "resolving";
349
+ }>;
350
+ statusReason: z.ZodNullable<z.ZodString>;
351
+ threadId: z.ZodString;
352
+ turnId: z.ZodString;
353
+ }, z.core.$strip>]>;
354
+ type ProviderPendingInteraction = z.infer<typeof providerPendingInteractionSchema>;
355
+ declare const pluginPendingInteractionSchema: z.ZodObject<{
356
+ createdAt: z.ZodNumber;
357
+ expiresAt: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
358
+ id: z.ZodString;
359
+ origin: z.ZodObject<{
360
+ kind: z.ZodLiteral<"plugin">;
361
+ pluginId: z.ZodString;
362
+ rendererId: z.ZodString;
363
+ }, z.core.$strip>;
364
+ payload: z.ZodObject<{
365
+ data: z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>;
366
+ kind: z.ZodLiteral<"plugin">;
367
+ presentation: z.ZodOptional<z.ZodObject<{
368
+ badge: z.ZodOptional<z.ZodObject<{
369
+ glyph: z.ZodString;
370
+ hint: z.ZodString;
371
+ label: z.ZodString;
372
+ tone: z.ZodEnum<{
373
+ destructive: "destructive";
374
+ neutral: "neutral";
375
+ }>;
376
+ }, z.core.$strip>>;
377
+ detail: z.ZodOptional<z.ZodString>;
378
+ icon: z.ZodObject<{
379
+ glyph: z.ZodString;
380
+ }, z.core.$strip>;
381
+ label: z.ZodObject<{
382
+ completed: z.ZodString;
383
+ pending: z.ZodString;
384
+ }, z.core.$strip>;
385
+ suppress: z.ZodOptional<z.ZodBoolean>;
386
+ tint: z.ZodOptional<z.ZodObject<{
387
+ dark: z.ZodString;
388
+ light: z.ZodString;
389
+ }, z.core.$strip>>;
390
+ title: z.ZodOptional<z.ZodString>;
391
+ }, z.core.$strip>>;
392
+ title: z.ZodString;
393
+ }, z.core.$strip>;
394
+ resolution: z.ZodNullable<z.ZodObject<{
395
+ description: z.ZodOptional<z.ZodObject<{
396
+ detail: z.ZodOptional<z.ZodString>;
397
+ payload: z.ZodOptional<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>;
398
+ title: z.ZodOptional<z.ZodString>;
399
+ }, z.core.$strip>>;
400
+ kind: z.ZodLiteral<"plugin_submitted">;
401
+ }, z.core.$strip>>;
402
+ resolvedAt: z.ZodNullable<z.ZodNumber>;
403
+ status: z.ZodEnum<{
404
+ interrupted: "interrupted";
405
+ pending: "pending";
406
+ resolved: "resolved";
407
+ resolving: "resolving";
408
+ }>;
409
+ statusReason: z.ZodNullable<z.ZodString>;
410
+ threadId: z.ZodString;
411
+ turnId: z.ZodNullable<z.ZodString>;
412
+ }, z.core.$strip>;
413
+ type PluginPendingInteraction = z.infer<typeof pluginPendingInteractionSchema>;
414
+ type PendingInteraction = ProviderPendingInteraction | PluginPendingInteraction;
415
+
416
+ declare const threadQueuedMessageSchema: z.ZodObject<{
417
+ content: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
418
+ mentions: z.ZodDefault<z.ZodArray<z.ZodObject<{
419
+ end: z.ZodNumber;
420
+ resource: z.ZodPreprocess<z.ZodDiscriminatedUnion<[z.ZodObject<{
421
+ kind: z.ZodLiteral<"thread">;
422
+ label: z.ZodString;
423
+ projectId: z.ZodOptional<z.ZodString>;
424
+ threadId: z.ZodString;
425
+ }, z.core.$strip>, z.ZodObject<{
426
+ kind: z.ZodLiteral<"project">;
427
+ label: z.ZodString;
428
+ projectId: z.ZodString;
429
+ }, z.core.$strip>, z.ZodObject<{
430
+ kind: z.ZodLiteral<"section">;
431
+ label: z.ZodString;
432
+ sectionId: z.ZodString;
433
+ }, z.core.$strip>, z.ZodObject<{
434
+ entryKind: z.ZodEnum<{
435
+ directory: "directory";
436
+ file: "file";
437
+ }>;
438
+ kind: z.ZodLiteral<"path">;
439
+ label: z.ZodString;
440
+ path: z.ZodString;
441
+ source: z.ZodEnum<{
442
+ "thread-storage": "thread-storage";
443
+ workspace: "workspace";
444
+ }>;
445
+ }, z.core.$strip>, z.ZodObject<{
446
+ argumentHint: z.ZodNullable<z.ZodString>;
447
+ kind: z.ZodLiteral<"command">;
448
+ label: z.ZodString;
449
+ name: z.ZodString;
450
+ origin: z.ZodEnum<{
451
+ builtin: "builtin";
452
+ project: "project";
453
+ user: "user";
454
+ }>;
455
+ source: z.ZodEnum<{
456
+ command: "command";
457
+ skill: "skill";
458
+ }>;
459
+ trigger: z.ZodEnum<{
460
+ "/": "/";
461
+ $: "$";
462
+ }>;
463
+ }, z.core.$strip>, z.ZodObject<{
464
+ icon: z.ZodOptional<z.ZodNullable<z.ZodString>>;
465
+ itemId: z.ZodString;
466
+ kind: z.ZodLiteral<"plugin">;
467
+ label: z.ZodString;
468
+ pluginId: z.ZodString;
469
+ }, z.core.$strip>, z.ZodObject<{
470
+ kind: z.ZodLiteral<"attachment">;
471
+ label: z.ZodString;
472
+ path: z.ZodString;
473
+ }, z.core.$strip>], "kind">, unknown>;
474
+ start: z.ZodNumber;
475
+ }, z.core.$strip>>>;
476
+ text: z.ZodString;
477
+ type: z.ZodLiteral<"text">;
478
+ visibility: z.ZodOptional<z.ZodEnum<{
479
+ "agent-only": "agent-only";
480
+ }>>;
481
+ }, z.core.$strip>, z.ZodObject<{
482
+ type: z.ZodLiteral<"image">;
483
+ url: z.ZodString;
484
+ visibility: z.ZodOptional<z.ZodEnum<{
485
+ "agent-only": "agent-only";
486
+ }>>;
487
+ }, z.core.$strip>, z.ZodObject<{
488
+ hostId: z.ZodOptional<z.ZodString>;
489
+ path: z.ZodString;
490
+ sourceProjectId: z.ZodOptional<z.ZodString>;
491
+ type: z.ZodLiteral<"localImage">;
492
+ visibility: z.ZodOptional<z.ZodEnum<{
493
+ "agent-only": "agent-only";
494
+ }>>;
495
+ }, z.core.$strip>, z.ZodObject<{
496
+ hostId: z.ZodOptional<z.ZodString>;
497
+ mimeType: z.ZodOptional<z.ZodString>;
498
+ name: z.ZodOptional<z.ZodString>;
499
+ path: z.ZodString;
500
+ sizeBytes: z.ZodOptional<z.ZodNumber>;
501
+ sourceProjectId: z.ZodOptional<z.ZodString>;
502
+ type: z.ZodLiteral<"localFile">;
503
+ visibility: z.ZodOptional<z.ZodEnum<{
504
+ "agent-only": "agent-only";
505
+ }>>;
506
+ }, z.core.$strip>], "type">>;
507
+ createdAt: z.ZodNumber;
508
+ editable: z.ZodBoolean;
509
+ failureReason: z.ZodNullable<z.ZodString>;
510
+ groupWithNext: z.ZodBoolean;
511
+ id: z.ZodString;
512
+ initiator: z.ZodEnum<{
513
+ agent: "agent";
514
+ system: "system";
515
+ user: "user";
516
+ }>;
517
+ model: z.ZodString;
518
+ origin: z.ZodNullable<z.ZodEnum<{
519
+ app: "app";
520
+ cli: "cli";
521
+ plugin: "plugin";
522
+ sdk: "sdk";
523
+ }>>;
524
+ originPluginId: z.ZodNullable<z.ZodString>;
525
+ payload: z.ZodDiscriminatedUnion<[z.ZodObject<{
526
+ kind: z.ZodLiteral<"inline">;
527
+ }, z.core.$strip>, z.ZodObject<{
528
+ attempt: z.ZodNumber;
529
+ kind: z.ZodLiteral<"retry">;
530
+ reason: z.ZodString;
531
+ retryOfTurnRequestId: z.ZodString;
532
+ }, z.core.$strip>], "kind">;
533
+ permissionMode: z.ZodEnum<{
534
+ "accept-edits": "accept-edits";
535
+ auto: "auto";
536
+ full: "full";
537
+ }>;
538
+ reasoningLevel: z.ZodString;
539
+ sendAt: z.ZodNullable<z.ZodNumber>;
540
+ senderThreadId: z.ZodNullable<z.ZodString>;
541
+ serviceTier: z.ZodString;
542
+ state: z.ZodEnum<{
543
+ claimed: "claimed";
544
+ failed_exhausted: "failed_exhausted";
545
+ failed_retrying: "failed_retrying";
546
+ queued: "queued";
547
+ scheduled: "scheduled";
548
+ waiting: "waiting";
549
+ }>;
550
+ systemNotice: z.ZodNullable<z.ZodObject<{
551
+ kind: z.ZodEnum<{
552
+ "child-completed": "child-completed";
553
+ "child-failed": "child-failed";
554
+ "child-interrupted": "child-interrupted";
555
+ "child-needs-attention": "child-needs-attention";
556
+ "child-outcome-batch": "child-outcome-batch";
557
+ "environment-directory-updated": "environment-directory-updated";
558
+ "ownership-assigned": "ownership-assigned";
559
+ "ownership-batch": "ownership-batch";
560
+ "ownership-removed": "ownership-removed";
561
+ "tool-result-delivered": "tool-result-delivered";
562
+ unlabeled: "unlabeled";
563
+ }>;
564
+ subject: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
565
+ kind: z.ZodLiteral<"thread">;
566
+ outcomes: z.ZodOptional<z.ZodArray<z.ZodObject<{
567
+ interruption: z.ZodOptional<z.ZodObject<{
568
+ cause: z.ZodOptional<z.ZodLiteral<"host-connection-lost">>;
569
+ reason: z.ZodEnum<{
570
+ "host-daemon-restarted": "host-daemon-restarted";
571
+ "host-removed": "host-removed";
572
+ "manual-stop": "manual-stop";
573
+ "provider-turn-idle": "provider-turn-idle";
574
+ }>;
575
+ }, z.core.$strip>>;
576
+ status: z.ZodEnum<{
577
+ completed: "completed";
578
+ failed: "failed";
579
+ interrupted: "interrupted";
580
+ }>;
581
+ threadId: z.ZodString;
582
+ }, z.core.$strip>>>;
583
+ threadId: z.ZodString;
584
+ threadName: z.ZodString;
585
+ }, z.core.$strip>, z.ZodObject<{
586
+ count: z.ZodNumber;
587
+ kind: z.ZodLiteral<"thread-batch">;
588
+ outcomes: z.ZodOptional<z.ZodArray<z.ZodObject<{
589
+ interruption: z.ZodOptional<z.ZodObject<{
590
+ cause: z.ZodOptional<z.ZodLiteral<"host-connection-lost">>;
591
+ reason: z.ZodEnum<{
592
+ "host-daemon-restarted": "host-daemon-restarted";
593
+ "host-removed": "host-removed";
594
+ "manual-stop": "manual-stop";
595
+ "provider-turn-idle": "provider-turn-idle";
596
+ }>;
597
+ }, z.core.$strip>>;
598
+ status: z.ZodEnum<{
599
+ completed: "completed";
600
+ failed: "failed";
601
+ interrupted: "interrupted";
602
+ }>;
603
+ threadId: z.ZodString;
604
+ }, z.core.$strip>>>;
605
+ }, z.core.$strip>, z.ZodObject<{
606
+ kind: z.ZodLiteral<"tool-call">;
607
+ suppress: z.ZodBoolean;
608
+ toolName: z.ZodString;
609
+ }, z.core.$strip>, z.ZodObject<{
610
+ kind: z.ZodLiteral<"directory">;
611
+ path: z.ZodString;
612
+ }, z.core.$strip>], "kind">>;
613
+ }, z.core.$strip>>;
614
+ threadId: z.ZodString;
615
+ updatedAt: z.ZodNumber;
616
+ waitingOn: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
617
+ kind: z.ZodLiteral<"time">;
618
+ }, z.core.$strip>, z.ZodObject<{
619
+ kind: z.ZodLiteral<"thread-busy">;
620
+ }, z.core.$strip>, z.ZodObject<{
621
+ kind: z.ZodLiteral<"stopping">;
622
+ }, z.core.$strip>, z.ZodObject<{
623
+ kind: z.ZodLiteral<"turn-starting">;
624
+ }, z.core.$strip>, z.ZodObject<{
625
+ kind: z.ZodLiteral<"provisioning">;
626
+ }, z.core.$strip>, z.ZodObject<{
627
+ hostName: z.ZodString;
628
+ kind: z.ZodLiteral<"host-offline">;
629
+ }, z.core.$strip>, z.ZodObject<{
630
+ kind: z.ZodLiteral<"interaction">;
631
+ }, z.core.$strip>, z.ZodObject<{
632
+ kind: z.ZodLiteral<"app-update">;
633
+ }, z.core.$strip>, z.ZodObject<{
634
+ kind: z.ZodLiteral<"plugin">;
635
+ pluginId: z.ZodString;
636
+ reason: z.ZodString;
637
+ }, z.core.$strip>, z.ZodObject<{
638
+ kind: z.ZodLiteral<"superseded">;
639
+ }, z.core.$strip>], "kind">>;
640
+ }, z.core.$strip>;
641
+ type ThreadQueuedMessage = z.infer<typeof threadQueuedMessageSchema>;
642
+
643
+ interface EnvironmentRemoval {
644
+ environmentId: string;
645
+ removedAt: number;
646
+ hostId: string | null;
647
+ path: string | null;
648
+ providerOwnedPath: boolean;
649
+ }
650
+
651
+ declare const terminalSessionSchema: z.ZodObject<{
652
+ closeReason: z.ZodNullable<z.ZodEnum<{
653
+ "daemon-disconnect": "daemon-disconnect";
654
+ "environment-destroyed": "environment-destroyed";
655
+ "open-timeout": "open-timeout";
656
+ "process-exit": "process-exit";
657
+ "thread-archived": "thread-archived";
658
+ "thread-deleted": "thread-deleted";
659
+ user: "user";
660
+ }>>;
661
+ cols: z.ZodNumber;
662
+ createdAt: z.ZodNumber;
663
+ environmentId: z.ZodNullable<z.ZodString>;
664
+ exitCode: z.ZodNullable<z.ZodNumber>;
665
+ hostId: z.ZodString;
666
+ id: z.ZodString;
667
+ initialCwd: z.ZodString;
668
+ lastUserInputAt: z.ZodNullable<z.ZodNumber>;
669
+ rows: z.ZodNumber;
670
+ status: z.ZodEnum<{
671
+ disconnected: "disconnected";
672
+ exited: "exited";
673
+ running: "running";
674
+ starting: "starting";
675
+ }>;
676
+ threadId: z.ZodNullable<z.ZodString>;
677
+ title: z.ZodString;
678
+ updatedAt: z.ZodNumber;
679
+ }, z.core.$strip>;
680
+ type TerminalSession = z.infer<typeof terminalSessionSchema>;
681
+
682
+ declare const threadResponseSchema: z.ZodObject<{
683
+ activeBackgroundAgentCount: z.ZodNumber;
684
+ archivedAt: z.ZodNullable<z.ZodNumber>;
685
+ canEditMessages: z.ZodBoolean;
686
+ canRestoreEnvironment: z.ZodBoolean;
687
+ canSpawnChild: z.ZodBoolean;
688
+ createdAt: z.ZodNumber;
689
+ deletedAt: z.ZodNullable<z.ZodNumber>;
690
+ environmentId: z.ZodNullable<z.ZodString>;
691
+ id: z.ZodString;
692
+ lastReadAt: z.ZodNullable<z.ZodNumber>;
693
+ latestAttentionAt: z.ZodNumber;
694
+ lifecycleOwnerThreadId: z.ZodNullable<z.ZodString>;
695
+ originKind: z.ZodNullable<z.ZodEnum<{
696
+ fork: "fork";
697
+ }>>;
698
+ originPluginId: z.ZodNullable<z.ZodString>;
699
+ parentNotifications: z.ZodEnum<{
700
+ auto: "auto";
701
+ off: "off";
702
+ stuck: "stuck";
703
+ }>;
704
+ parentThreadId: z.ZodNullable<z.ZodString>;
705
+ pinnedAt: z.ZodNullable<z.ZodNumber>;
706
+ projectId: z.ZodString;
707
+ providerId: z.ZodString;
708
+ queuedMessageCount: z.ZodNumber;
709
+ runtime: z.ZodObject<{
710
+ displayStatus: z.ZodEnum<{
711
+ "waiting-for-host": "waiting-for-host";
712
+ active: "active";
713
+ error: "error";
714
+ idle: "idle";
715
+ pending: "pending";
716
+ provisioning: "provisioning";
717
+ starting: "starting";
718
+ stopping: "stopping";
719
+ }>;
720
+ }, z.core.$strip>;
721
+ sectionId: z.ZodNullable<z.ZodString>;
722
+ sourceThreadId: z.ZodNullable<z.ZodString>;
723
+ status: z.ZodEnum<{
724
+ active: "active";
725
+ error: "error";
726
+ idle: "idle";
727
+ pending: "pending";
728
+ starting: "starting";
729
+ stopping: "stopping";
730
+ }>;
731
+ title: z.ZodNullable<z.ZodString>;
732
+ titleFallback: z.ZodNullable<z.ZodString>;
733
+ updatedAt: z.ZodNumber;
734
+ visibility: z.ZodEnum<{
735
+ hidden: "hidden";
736
+ visible: "visible";
737
+ }>;
738
+ }, z.core.$strip>;
739
+ type ThreadResponse = z.infer<typeof threadResponseSchema>;
740
+
741
+ /**
742
+ * One terminal outcome of the work on a thread, in a single union so a plugin
743
+ * that keeps a record per run handles every way that work can end in one
744
+ * exhaustive `switch`. Experimental: see docs/api_to_audit.md.
745
+ *
746
+ * - `completed`: the thread went idle; `lastAssistantText` as on `thread.idle`.
747
+ * - `failed`: the thread landed in `error`; `error` as on `thread.failed`.
748
+ * - `cancelled`: a queued message was removed before it dispatched; `entry`
749
+ * is that message, so `entry.originPluginId` says whose it was.
750
+ * - `archived` / `deleted`: the thread itself is gone.
751
+ */
752
+ type PluginThreadSettledEvent = {
753
+ outcome: "completed";
754
+ thread: ThreadResponse;
755
+ lastAssistantText: string | null;
756
+ } | {
757
+ outcome: "failed";
758
+ thread: ThreadResponse;
759
+ error: string | null;
760
+ } | {
761
+ outcome: "cancelled";
762
+ thread: ThreadResponse;
763
+ entry: ThreadQueuedMessage;
764
+ } | {
765
+ outcome: "archived";
766
+ thread: ThreadResponse;
767
+ } | {
768
+ outcome: "deleted";
769
+ thread: ThreadResponse;
770
+ };
771
+ /**
772
+ * Why a turn failed, assembled by core from the failed turn's own records so a
773
+ * listener never has to replay the event log to find out.
774
+ *
775
+ * Ids and failure facts only. There is no thread DTO and no copy of the
776
+ * message that failed: a retry re-submits the turn BY REFERENCE
777
+ * (`bb.sdk.threads.retry`), so the id is the whole of what a policy needs, and
778
+ * anything else about the thread is one `bb.sdk.threads.get` away and fresher
779
+ * for being read when it is used.
780
+ */
781
+ interface PluginTurnFailedEvent {
782
+ /** The thread the failed turn ran on. */
783
+ threadId: string;
784
+ /**
785
+ * The failed turn's `client/turn/requested` id — what
786
+ * `bb.sdk.threads.retry` takes as `turnRequestId`. On a retry's failure this
787
+ * is the RETRY's id; core walks back to the request the chain started from
788
+ * when it queues the next attempt.
789
+ */
790
+ requestId: string;
791
+ /** The provider turn, when the failure happened inside one. */
792
+ turnId: string | null;
793
+ /**
794
+ * The failure's structured classification: the provider's own report when
795
+ * the failure happened inside a turn, or the typed rejection code (a rate
796
+ * limit, an auth failure) when the provider refused the request at the
797
+ * door. Null when neither carried one, so a retry policy must handle null
798
+ * rather than assume.
799
+ */
800
+ errorInfo: ProviderErrorInfo | null;
801
+ /**
802
+ * Whether the provider accepted the turn's input before failing. True is a
803
+ * mid-stream failure — the input is already part of the provider's
804
+ * conversation, so core's retry continues it instead of re-sending the
805
+ * blocks. False is a request the provider never took, which a retry
806
+ * re-sends verbatim.
807
+ */
808
+ inputAccepted: boolean;
809
+ /**
810
+ * The most recent rate-limit snapshot this thread's provider reported, or
811
+ * null when the provider reports no windows.
812
+ */
813
+ rateLimits: ProviderRateLimitState | null;
814
+ /**
815
+ * Which attempt just failed: 1 is the original dispatch, 2 the first retry.
816
+ * A policy caps its own retries by comparing against this.
817
+ */
818
+ attemptNumber: number;
819
+ /**
820
+ * The plugin that sent the failed turn's message through
821
+ * `bb.sdk.threads.send` or `bb.sdk.threads.spawn`, or null when a user, an
822
+ * agent, or core sent it. A retry is sent by core, so a retry's failure
823
+ * reports null. A retry policy uses this to ask the sender whether it
824
+ * wants the turn re-run.
825
+ */
826
+ originPluginId: string | null;
827
+ }
828
+ /**
829
+ * Lifecycle events a plugin can observe with `bb.events.on` (design §4.5).
830
+ *
831
+ * **Events are announcements core makes.** Something already happened; a
832
+ * handler is told about it and whatever it returns is IGNORED. Handlers run
833
+ * fire-and-forget after the change is applied and can never block or veto it.
834
+ * The surface that *can* is `bb.experimental_hooks`, where core asks a
835
+ * question and acts on the answer — the same split git draws between its
836
+ * post-commit and pre-commit hooks.
837
+ *
838
+ * `thread` is the same public DTO GET /threads/:id serves and `entry` is the
839
+ * queued row GET /threads/:id/queued-messages serves.
840
+ */
841
+ interface PluginThreadEventPayloads {
842
+ "experimental_environment.removed": {
843
+ removal: EnvironmentRemoval;
844
+ };
845
+ /** Debounced per thread (at most once per second), with the latest sequence and current thread DTO. Reading history does not emit this event. */
846
+ "experimental_thread.events": {
847
+ thread: ThreadResponse;
848
+ sequence: number;
849
+ };
850
+ /**
851
+ * Fired after a thread moves to a new parent or loses its parent: a
852
+ * `threads.update` that changes `parentThreadId`, or core releasing a
853
+ * thread's unarchived children when it is archived. `thread` carries the
854
+ * new `parentThreadId`. Every thread below it moved with it and gets no
855
+ * event of its own. Experimental: see docs/api_to_audit.md.
856
+ */
857
+ "experimental_thread.parentChanged": {
858
+ thread: ThreadResponse;
859
+ previousParentThreadId: string | null;
860
+ };
861
+ /**
862
+ * Fired after a thread's read state changes and the thread is now read
863
+ * (`lastReadAt >= latestAttentionAt`): a client opened it or marked it
864
+ * read, or the user sent it a turn. Marking a thread unread does not fire
865
+ * it. Experimental: see docs/api_to_audit.md.
866
+ */
867
+ "experimental_thread.read": {
868
+ thread: ThreadResponse;
869
+ };
870
+ /** Real accepted terminal input; excludes output, keepalives and input contents. */
871
+ "experimental_terminal.input": {
872
+ terminal: TerminalSession;
873
+ };
874
+ /**
875
+ * Fired once after a machine is removed, whether a user removed it or its
876
+ * machine provider finished tearing it down. `host` is the record as it was
877
+ * when it was removed; `bb.sdk.hosts.get` answers 404 for it from now on, so
878
+ * this is the moment to drop anything the plugin keeps per host.
879
+ */
880
+ "experimental_host.deleted": {
881
+ host: Host;
882
+ };
883
+ /** Fired after a thread row is created. */
884
+ "thread.created": {
885
+ thread: ThreadResponse;
886
+ };
887
+ /** Fired when a thread transitions into `active`. */
888
+ "thread.active": {
889
+ thread: ThreadResponse;
890
+ };
891
+ /** Fired when a thread transitions into `idle`. `lastAssistantText` is
892
+ * assembled the same way GET /threads/:id/output is. */
893
+ "thread.idle": {
894
+ thread: ThreadResponse;
895
+ lastAssistantText: string | null;
896
+ };
897
+ /** Fired when a thread transitions into `error`. `error` is the latest
898
+ * system/error event message, when one exists. */
899
+ "thread.failed": {
900
+ thread: ThreadResponse;
901
+ error: string | null;
902
+ };
903
+ /** Fired after a thread is archived (including cascade archives). */
904
+ "thread.archived": {
905
+ thread: ThreadResponse;
906
+ };
907
+ /**
908
+ * Fired after a thread comes back from the archive. Nothing is provisioned
909
+ * here: a provider that tore its environment down on archive is asked to
910
+ * provide one again when the thread next needs to run, with that
911
+ * environment in the ask's context. This is the moment to start warming
912
+ * one up ahead of that ask.
913
+ */
914
+ "thread.unarchived": {
915
+ thread: ThreadResponse;
916
+ };
917
+ /** Fired after a thread is soft-deleted. */
918
+ "thread.deleted": {
919
+ thread: ThreadResponse;
920
+ };
921
+ /** Fired after a pending interaction row is committed. */
922
+ "interaction.pending": {
923
+ thread: ThreadResponse;
924
+ interaction: PendingInteraction;
925
+ };
926
+ /**
927
+ * Fired after a dispatch attempt is queued as a row — by a `message.dispatch`
928
+ * hook's `wait` decision, by a `sendAt` in the future, or by a core wait (the
929
+ * thread is busy, its turn is still starting, provisioning, stopping, or
930
+ * awaiting an interaction).
931
+ *
932
+ * Every listener sees every queued row, not just the ones it is holding: an
933
+ * observer that only wants its own filters on
934
+ * `entry.waitingOn?.kind === "plugin" && entry.waitingOn.pluginId === bb.pluginId`.
935
+ *
936
+ * A re-queue fires this again with the new wait, because a row that moved
937
+ * from one wait to another is news to whoever was waiting on the old one.
938
+ */
939
+ "message.queued": {
940
+ entry: ThreadQueuedMessage;
941
+ };
942
+ /**
943
+ * Fired after a queued row's waits all cleared and it dispatched. The turn
944
+ * it carried runs after this, so a handler must not assume it has started.
945
+ */
946
+ "message.dispatched": {
947
+ entry: ThreadQueuedMessage;
948
+ };
949
+ /**
950
+ * Fired after a turn failed and the thread has already landed in `error`.
951
+ *
952
+ * An announcement, not a question: the failure stands exactly as core
953
+ * applied it, and a listener that wants another attempt asks for one with
954
+ * `bb.sdk.threads.retry({ threadId, turnRequestId, sendAt })`. That retry is
955
+ * an ordinary dispatch attempt, so it still passes the `message.dispatch`
956
+ * hook — a retry coming back after a rate-limit window respects a limiter
957
+ * that is at capacity instead of jumping the queue.
958
+ */
959
+ "turn.failed": PluginTurnFailedEvent;
960
+ /**
961
+ * Fired after a queued row is removed before it ever dispatched — the user
962
+ * deleted it from the queued card or `bb thread queue`. This is the only
963
+ * signal for that removal: a plugin holding external resources for a
964
+ * waiting message (a sandbox mid-provision, a reserved slot) releases them
965
+ * here. Rows that dispatch fire `message.dispatched` instead, and rows that
966
+ * vanish because their thread was archived or deleted fire the thread
967
+ * event, not this one.
968
+ */
969
+ "message.cancelled": {
970
+ entry: ThreadQueuedMessage;
971
+ };
972
+ /**
973
+ * Fired with every `thread.idle`, `thread.failed`, `thread.archived` and
974
+ * `thread.deleted`, and with every `message.cancelled` whose thread still
975
+ * exists, as one {@link PluginThreadSettledEvent}. Experimental: see
976
+ * docs/api_to_audit.md.
977
+ */
978
+ "experimental_thread.settled": PluginThreadSettledEvent;
979
+ }
980
+ type PluginThreadEventName = keyof PluginThreadEventPayloads;
981
+
982
+ interface ThreadEventThread {
983
+ threadId: string;
984
+ createdAt: number | null;
985
+ }
986
+ interface ThreadEventSubject {
987
+ threadId: string;
988
+ createdAt(): number | null;
989
+ }
990
+ interface ThreadEventGate {
991
+ track<T>(call: () => Promise<T>): Promise<T>;
992
+ deliver(subject: ThreadEventSubject | null, deliver: () => void): void;
993
+ }
994
+ declare function threadOfEvent<E extends PluginThreadEventName>(event: E, payload: PluginThreadEventPayloads[E]): ThreadEventThread | null;
995
+ declare function createThreadEventGate(options?: {
996
+ now?: () => number;
997
+ schedule?: (run: () => void) => void;
998
+ }): ThreadEventGate;
999
+
1000
+ export { createThreadEventGate, threadOfEvent };
1001
+ export type { ThreadEventGate, ThreadEventSubject, ThreadEventThread };