@get-bb/plugin-sdk 0.6.68 → 0.6.75

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.
@@ -1260,6 +1260,9 @@ function useQuerySelection(subscribe, getSnapshot, select) {
1260
1260
  return value;
1261
1261
  }
1262
1262
 
1263
+ // ../domain/src/shared-types.ts
1264
+ import { z as z2 } from "zod";
1265
+
1263
1266
  // ../domain/src/json-value.ts
1264
1267
  import { z } from "zod";
1265
1268
  var jsonValueSchema = z.lazy(
@@ -1277,23 +1280,1149 @@ var jsonObjectSchema = z.record(
1277
1280
  jsonValueSchema
1278
1281
  );
1279
1282
 
1283
+ // ../domain/src/shared-types.ts
1284
+ var reasoningLevelSchema = z2.string().min(1);
1285
+ var serviceTierSchema = z2.string().min(1);
1286
+ var instructionModeValues = ["append", "replace"];
1287
+ var instructionModeSchema = z2.enum(instructionModeValues);
1288
+ var permissionModeValues = ["accept-edits", "auto", "full"];
1289
+ var permissionModeSchema = z2.enum(permissionModeValues);
1290
+ var permissionModeInputSchema = z2.union([permissionModeSchema, z2.literal("workspace-write")]).transform(
1291
+ (permissionMode) => permissionMode === "workspace-write" ? "accept-edits" : permissionMode
1292
+ );
1293
+ var legacyRecordedPermissionModeValues = [
1294
+ "workspace-write",
1295
+ "readonly"
1296
+ ];
1297
+ var recordedPermissionModeSchema = z2.enum([
1298
+ ...permissionModeValues,
1299
+ ...legacyRecordedPermissionModeValues
1300
+ ]);
1301
+ var permissionEscalationValues = ["ask", "deny"];
1302
+ var permissionEscalationSchema = z2.enum(permissionEscalationValues);
1303
+ var promptInputVisibilityValues = ["agent-only"];
1304
+ var promptInputVisibilitySchema = z2.enum(promptInputVisibilityValues);
1305
+ var promptInputVisibilityFields = {
1306
+ visibility: promptInputVisibilitySchema.optional()
1307
+ };
1308
+ var promptMentionPathSourceValues = ["workspace", "thread-storage"];
1309
+ var promptMentionPathSourceSchema = z2.enum(promptMentionPathSourceValues);
1310
+ var promptMentionPathEntryKindValues = ["file", "directory"];
1311
+ var promptMentionPathEntryKindSchema = z2.enum(
1312
+ promptMentionPathEntryKindValues
1313
+ );
1314
+ var promptMentionCommandTriggerValues = ["/", "$"];
1315
+ var promptMentionCommandTriggerSchema = z2.enum(
1316
+ promptMentionCommandTriggerValues
1317
+ );
1318
+ var promptMentionCommandSourceValues = ["skill", "command"];
1319
+ var promptMentionCommandSourceSchema = z2.enum(
1320
+ promptMentionCommandSourceValues
1321
+ );
1322
+ var promptMentionCommandOriginValues = [
1323
+ "builtin",
1324
+ "project",
1325
+ "user"
1326
+ ];
1327
+ var promptMentionCommandOriginSchema = z2.enum(
1328
+ promptMentionCommandOriginValues
1329
+ );
1330
+ var canonicalPromptMentionResourceSchema = z2.discriminatedUnion("kind", [
1331
+ z2.object({
1332
+ kind: z2.literal("thread"),
1333
+ threadId: z2.string(),
1334
+ projectId: z2.string().optional(),
1335
+ label: z2.string()
1336
+ }),
1337
+ z2.object({
1338
+ kind: z2.literal("project"),
1339
+ projectId: z2.string(),
1340
+ label: z2.string()
1341
+ }),
1342
+ z2.object({
1343
+ kind: z2.literal("section"),
1344
+ sectionId: z2.string(),
1345
+ label: z2.string()
1346
+ }),
1347
+ z2.object({
1348
+ kind: z2.literal("path"),
1349
+ source: promptMentionPathSourceSchema,
1350
+ entryKind: promptMentionPathEntryKindSchema,
1351
+ path: z2.string(),
1352
+ label: z2.string()
1353
+ }),
1354
+ z2.object({
1355
+ kind: z2.literal("command"),
1356
+ trigger: promptMentionCommandTriggerSchema,
1357
+ name: z2.string(),
1358
+ source: promptMentionCommandSourceSchema,
1359
+ origin: promptMentionCommandOriginSchema,
1360
+ label: z2.string(),
1361
+ argumentHint: z2.string().nullable()
1362
+ }),
1363
+ z2.object({
1364
+ kind: z2.literal("plugin"),
1365
+ pluginId: z2.string(),
1366
+ icon: z2.string().nullable().optional(),
1367
+ itemId: z2.string(),
1368
+ label: z2.string()
1369
+ }),
1370
+ z2.object({
1371
+ kind: z2.literal("attachment"),
1372
+ path: z2.string(),
1373
+ label: z2.string()
1374
+ })
1375
+ ]);
1376
+ function normalizeLegacyPromptMentionResource(value) {
1377
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
1378
+ return value;
1379
+ }
1380
+ const record = value;
1381
+ if (record.kind !== "folder" || typeof record.folderId !== "string") {
1382
+ return value;
1383
+ }
1384
+ const { folderId, ...rest } = record;
1385
+ return { ...rest, kind: "section", sectionId: folderId };
1386
+ }
1387
+ var promptMentionResourceSchema = z2.preprocess(
1388
+ normalizeLegacyPromptMentionResource,
1389
+ canonicalPromptMentionResourceSchema
1390
+ );
1391
+ var promptTextMentionSchema = z2.object({
1392
+ start: z2.number().int().nonnegative(),
1393
+ end: z2.number().int().nonnegative(),
1394
+ resource: promptMentionResourceSchema
1395
+ });
1396
+ var promptInputSchema = z2.discriminatedUnion("type", [
1397
+ z2.object({
1398
+ type: z2.literal("text"),
1399
+ text: z2.string(),
1400
+ mentions: z2.array(promptTextMentionSchema).default([]),
1401
+ ...promptInputVisibilityFields
1402
+ }),
1403
+ z2.object({
1404
+ type: z2.literal("image"),
1405
+ url: z2.string().url(),
1406
+ ...promptInputVisibilityFields
1407
+ }),
1408
+ z2.object({
1409
+ type: z2.literal("localImage"),
1410
+ path: z2.string(),
1411
+ sourceProjectId: z2.string().min(1).optional(),
1412
+ hostId: z2.string().min(1).optional(),
1413
+ ...promptInputVisibilityFields
1414
+ }),
1415
+ z2.object({
1416
+ type: z2.literal("localFile"),
1417
+ path: z2.string(),
1418
+ sourceProjectId: z2.string().min(1).optional(),
1419
+ hostId: z2.string().min(1).optional(),
1420
+ name: z2.string().optional(),
1421
+ sizeBytes: z2.number().int().nonnegative().optional(),
1422
+ mimeType: z2.string().optional(),
1423
+ ...promptInputVisibilityFields
1424
+ })
1425
+ ]);
1426
+ var threadExecutionSourceSchema = z2.enum([
1427
+ "client/thread/start",
1428
+ "client/turn/requested",
1429
+ "client/turn/start"
1430
+ ]);
1431
+ var callerExecutionInputSourceValues = [
1432
+ "explicit",
1433
+ "client-preference"
1434
+ ];
1435
+ var callerExecutionInputSourceSchema = z2.enum(
1436
+ callerExecutionInputSourceValues
1437
+ );
1438
+ var threadExecutionOptionsSchema = z2.object({
1439
+ model: z2.string().optional(),
1440
+ serviceTier: serviceTierSchema.optional(),
1441
+ reasoningLevel: reasoningLevelSchema.optional(),
1442
+ permissionMode: permissionModeSchema.optional(),
1443
+ source: threadExecutionSourceSchema.optional(),
1444
+ seq: z2.number().int().optional()
1445
+ });
1446
+ var resolvedThreadExecutionOptionsSchema = threadExecutionOptionsSchema.extend({
1447
+ model: z2.string().min(1),
1448
+ serviceTier: serviceTierSchema,
1449
+ reasoningLevel: reasoningLevelSchema,
1450
+ permissionMode: permissionModeSchema,
1451
+ source: threadExecutionSourceSchema
1452
+ });
1453
+ var recordedThreadExecutionOptionsSchema = resolvedThreadExecutionOptionsSchema.extend({
1454
+ permissionMode: recordedPermissionModeSchema
1455
+ });
1456
+ var runtimePermissionScopeValues = ["workspace", "full"];
1457
+ var runtimePermissionScopeSchema = z2.enum(runtimePermissionScopeValues);
1458
+ var runtimePermissionPolicySchema = z2.discriminatedUnion(
1459
+ "permissionMode",
1460
+ [
1461
+ z2.object({
1462
+ permissionMode: z2.literal("accept-edits"),
1463
+ permissionScope: z2.literal("workspace"),
1464
+ approvalReviewer: z2.literal("user"),
1465
+ permissionEscalation: permissionEscalationSchema
1466
+ }),
1467
+ z2.object({
1468
+ permissionMode: z2.literal("auto"),
1469
+ permissionScope: z2.literal("workspace"),
1470
+ approvalReviewer: z2.literal("automatic"),
1471
+ permissionEscalation: permissionEscalationSchema
1472
+ }),
1473
+ z2.object({
1474
+ permissionMode: z2.literal("full"),
1475
+ permissionScope: z2.literal("full"),
1476
+ approvalReviewer: z2.null(),
1477
+ permissionEscalation: z2.null()
1478
+ })
1479
+ ]
1480
+ );
1481
+ var promptModeSchema = z2.literal("plan");
1482
+ var sessionOptionValueSchema = z2.union([z2.string(), z2.boolean()]);
1483
+ var sessionOptionSelectionsSchema = z2.record(
1484
+ z2.string().min(1),
1485
+ sessionOptionValueSchema
1486
+ );
1487
+ var runtimeThreadExecutionBaseOptionsSchema = z2.object({
1488
+ model: z2.string().min(1),
1489
+ serviceTier: serviceTierSchema,
1490
+ reasoningLevel: reasoningLevelSchema,
1491
+ promptMode: promptModeSchema.optional(),
1492
+ sessionOptions: sessionOptionSelectionsSchema.optional(),
1493
+ providerOptions: jsonObjectSchema
1494
+ });
1495
+ var runtimeThreadExecutionOptionsSchema = runtimeThreadExecutionBaseOptionsSchema.and(runtimePermissionPolicySchema);
1496
+ var projectExecutionDefaultsSchema = z2.object({
1497
+ providerId: z2.string().min(1),
1498
+ model: z2.string().min(1),
1499
+ serviceTier: serviceTierSchema,
1500
+ reasoningLevel: reasoningLevelSchema,
1501
+ permissionMode: permissionModeSchema
1502
+ });
1503
+
1504
+ // ../domain/src/git-checkout.ts
1505
+ import { z as z3 } from "zod";
1506
+ var gitBranchForbiddenCharacterPattern = /[\u0000-\u001f\u007f\\:~^?*\[]/u;
1507
+ var gitBranchWhitespacePattern = /[ \t]/u;
1508
+ var gitReservedBranchNames = /* @__PURE__ */ new Set([
1509
+ "AUTO_MERGE",
1510
+ "BISECT_HEAD",
1511
+ "CHERRY_PICK_HEAD",
1512
+ "FETCH_HEAD",
1513
+ "HEAD",
1514
+ "MERGE_HEAD",
1515
+ "ORIG_HEAD",
1516
+ "REVERT_HEAD"
1517
+ ]);
1518
+ function isValidGitBranchName(name) {
1519
+ const components = name.split("/");
1520
+ return name.length > 0 && name.trim().length > 0 && !name.startsWith("-") && !name.startsWith("/") && name !== "@" && !gitReservedBranchNames.has(name) && !gitBranchForbiddenCharacterPattern.test(name) && !gitBranchWhitespacePattern.test(name) && !name.includes("..") && !name.includes("@{") && !name.includes("//") && !name.endsWith("/") && !name.endsWith(".") && components.every(
1521
+ (component) => component.length > 0 && !component.startsWith(".") && !component.endsWith(".lock")
1522
+ );
1523
+ }
1524
+ var gitBranchNameSchema = z3.string().refine(isValidGitBranchName, { message: "Invalid git branch name" });
1525
+ var gitBranchSelectionSchema = z3.discriminatedUnion("kind", [
1526
+ z3.object({ kind: z3.literal("named"), name: gitBranchNameSchema }),
1527
+ z3.object({ kind: z3.literal("default") })
1528
+ ]);
1529
+ var gitCheckoutRefSchema = z3.discriminatedUnion("kind", [
1530
+ z3.object({
1531
+ kind: z3.literal("branch"),
1532
+ branchName: z3.string().min(1),
1533
+ headSha: z3.string().min(1).nullable()
1534
+ }),
1535
+ z3.object({
1536
+ kind: z3.literal("detached"),
1537
+ headSha: z3.string().min(1).nullable()
1538
+ }),
1539
+ z3.object({
1540
+ kind: z3.literal("unborn"),
1541
+ branchName: z3.string().min(1).nullable()
1542
+ }),
1543
+ z3.object({
1544
+ kind: z3.literal("unknown"),
1545
+ reason: z3.string().min(1)
1546
+ })
1547
+ ]);
1548
+ var workspaceGitOperationSchema = z3.discriminatedUnion("kind", [
1549
+ z3.object({ kind: z3.literal("none") }),
1550
+ z3.object({
1551
+ kind: z3.literal("merge"),
1552
+ hasConflicts: z3.boolean()
1553
+ }),
1554
+ z3.object({
1555
+ kind: z3.literal("rebase"),
1556
+ hasConflicts: z3.boolean()
1557
+ }),
1558
+ z3.object({
1559
+ kind: z3.literal("cherry-pick"),
1560
+ hasConflicts: z3.boolean()
1561
+ }),
1562
+ z3.object({
1563
+ kind: z3.literal("revert"),
1564
+ hasConflicts: z3.boolean()
1565
+ }),
1566
+ z3.object({
1567
+ kind: z3.literal("unknown"),
1568
+ reason: z3.string().min(1),
1569
+ hasConflicts: z3.boolean()
1570
+ })
1571
+ ]);
1572
+ var gitBranchRefClassificationSchema = z3.object({
1573
+ name: z3.string().min(1),
1574
+ kind: z3.enum(["local", "remote", "missing"])
1575
+ });
1576
+ var defaultBranchRelationSchema = z3.enum([
1577
+ "equal",
1578
+ "local-behind",
1579
+ "local-ahead",
1580
+ "diverged",
1581
+ "unknown"
1582
+ ]);
1583
+ var gitSourceInspectionSchema = z3.object({
1584
+ checkout: gitCheckoutRefSchema,
1585
+ defaultBranch: z3.string().min(1).nullable(),
1586
+ isWorktree: z3.boolean(),
1587
+ defaultBranchRelation: defaultBranchRelationSchema.nullable(),
1588
+ hasUncommittedChanges: z3.boolean(),
1589
+ operation: workspaceGitOperationSchema,
1590
+ originDefaultBranch: z3.string().min(1).nullable()
1591
+ });
1592
+ var gitBranchOptionsSchema = z3.object({
1593
+ branches: z3.array(z3.string()),
1594
+ branchesTruncated: z3.boolean(),
1595
+ remoteBranches: z3.array(z3.string()),
1596
+ remoteBranchesTruncated: z3.boolean(),
1597
+ selectedBranch: gitBranchRefClassificationSchema.nullable()
1598
+ });
1599
+ var projectSourceCheckoutSchema = gitSourceInspectionSchema.extend(
1600
+ gitBranchOptionsSchema.shape
1601
+ );
1602
+
1603
+ // ../domain/src/change-kinds.ts
1604
+ import { z as z18 } from "zod";
1605
+
1606
+ // ../domain/src/thread-event-types.ts
1607
+ import { z as z4 } from "zod";
1608
+ var systemEventTypeValues = [
1609
+ "client/thread/start",
1610
+ "client/turn/requested",
1611
+ "client/turn/rejected",
1612
+ "client/turn/start",
1613
+ "system/error",
1614
+ "system/manager/user_message",
1615
+ "system/thread/interrupted",
1616
+ "system/operation",
1617
+ "system/interaction/lifecycle",
1618
+ "system/permissionGrant/lifecycle",
1619
+ "system/userQuestion/lifecycle",
1620
+ "system/thread-provisioning",
1621
+ "system/provider-turn-watchdog"
1622
+ ];
1623
+ var providerEventTypeValues = [
1624
+ "thread/started",
1625
+ "thread/identity",
1626
+ "turn/started",
1627
+ "turn/completed",
1628
+ "turn/input/accepted",
1629
+ "thread/name/updated",
1630
+ "thread/compacted",
1631
+ "thread/context/cleared",
1632
+ "thread/goal/updated",
1633
+ "thread/goal/cleared",
1634
+ "item/started",
1635
+ "item/completed",
1636
+ "item/agentMessage/delta",
1637
+ "item/commandExecution/outputDelta",
1638
+ "item/fileChange/outputDelta",
1639
+ "item/reasoning/summaryTextDelta",
1640
+ "item/reasoning/textDelta",
1641
+ "item/plan/delta",
1642
+ "item/mcpToolCall/progress",
1643
+ "item/toolCall/progress",
1644
+ "item/backgroundTask/progress",
1645
+ "item/backgroundTask/completed",
1646
+ "item/delegation/progress",
1647
+ "item/delegation/completed",
1648
+ "thread/tokenUsage/updated",
1649
+ "thread/contextWindowUsage/updated",
1650
+ "turn/plan/updated",
1651
+ "turn/mainRun/updated",
1652
+ "turn/diff/updated",
1653
+ "provider/error",
1654
+ "provider/rateLimits/updated",
1655
+ "provider.env-resolved",
1656
+ "thread/extensionState/updated",
1657
+ "provider/warning",
1658
+ "provider/modelFallback",
1659
+ "provider/unhandled"
1660
+ ];
1661
+ var threadEventTypeValues = [
1662
+ ...providerEventTypeValues,
1663
+ ...systemEventTypeValues
1664
+ ];
1665
+ var threadEventTypeSet = new Set(threadEventTypeValues);
1666
+ var threadEventTypeSchema = z4.string().refine(
1667
+ (value) => threadEventTypeSet.has(value),
1668
+ "Invalid thread event type"
1669
+ );
1670
+
1671
+ // ../domain/src/thread.ts
1672
+ import { z as z17 } from "zod";
1673
+
1674
+ // ../domain/src/thread-create-origin.ts
1675
+ import { z as z5 } from "zod";
1676
+ var threadCreateOriginValues = ["app", "cli", "sdk", "plugin"];
1677
+ var threadCreateOriginSchema = z5.enum(threadCreateOriginValues);
1678
+
1679
+ // ../domain/src/environment.ts
1680
+ import { z as z6 } from "zod";
1681
+ var environmentMachineSelectionSchema = z6.discriminatedUnion("type", [
1682
+ z6.object({ type: z6.literal("existing"), hostId: z6.string().min(1) }),
1683
+ z6.object({
1684
+ type: z6.literal("new"),
1685
+ machineProviderId: z6.string().min(1),
1686
+ inputs: jsonValueSchema.nullable()
1687
+ })
1688
+ ]);
1689
+ var environmentProviderSelectionSchema = z6.object({
1690
+ machine: environmentMachineSelectionSchema,
1691
+ inputs: jsonValueSchema.nullable()
1692
+ });
1693
+ var environmentStatusValues = [
1694
+ "creating",
1695
+ "provisioning",
1696
+ "ready",
1697
+ "error",
1698
+ "destroyed"
1699
+ ];
1700
+ var environmentStatusSchema = z6.enum(environmentStatusValues);
1701
+ var environmentHostLifecycleValues = [
1702
+ "active",
1703
+ "removing",
1704
+ "cleanup-failed",
1705
+ "removed"
1706
+ ];
1707
+ var environmentHostLifecycleSchema = z6.enum(
1708
+ environmentHostLifecycleValues
1709
+ );
1710
+ var WORKSPACE_PROVISION_TYPES = [
1711
+ "unmanaged",
1712
+ "managed-worktree",
1713
+ "personal"
1714
+ ];
1715
+ var workspaceProvisionTypeSchema = z6.enum(WORKSPACE_PROVISION_TYPES);
1716
+ var environmentWorkspaceDisplayKindValues = [
1717
+ "managed-worktree",
1718
+ "unmanaged-worktree",
1719
+ "other"
1720
+ ];
1721
+ var environmentWorkspaceDisplayKindSchema = z6.enum(
1722
+ environmentWorkspaceDisplayKindValues
1723
+ );
1724
+ var discoveredWorkspacePropertiesSchema = z6.object({
1725
+ path: z6.string().min(1),
1726
+ isGitRepo: z6.boolean(),
1727
+ isWorktree: z6.boolean(),
1728
+ branchName: z6.string().nullable(),
1729
+ defaultBranch: z6.string().nullable()
1730
+ });
1731
+ var environmentLifecycleSchema = z6.object({
1732
+ phase: z6.enum(["active", "retiring", "teardown", "destroyed"]),
1733
+ retireAt: z6.number().nullable(),
1734
+ teardown: z6.object({
1735
+ status: z6.enum(["running", "failed", "removed"]),
1736
+ attempt: z6.number().int().nonnegative(),
1737
+ message: z6.string().optional()
1738
+ }).nullable()
1739
+ });
1740
+ var environmentSchema = z6.object({
1741
+ id: z6.string(),
1742
+ name: z6.string().nullable(),
1743
+ projectId: z6.string(),
1744
+ hostId: z6.string(),
1745
+ path: z6.string().nullable(),
1746
+ isGitRepo: z6.boolean(),
1747
+ isWorktree: z6.boolean(),
1748
+ branchName: z6.string().nullable(),
1749
+ baseBranch: z6.string().nullable(),
1750
+ defaultBranch: z6.string().nullable(),
1751
+ mergeBaseBranch: z6.string().nullable(),
1752
+ status: environmentStatusSchema,
1753
+ environmentProviderId: z6.string().nullable(),
1754
+ lifecycle: environmentLifecycleSchema,
1755
+ hostLifecycle: environmentHostLifecycleSchema,
1756
+ environmentProviderSelection: environmentProviderSelectionSchema.nullable(),
1757
+ environmentProviderInstanceKey: z6.string().nullable(),
1758
+ managed: z6.boolean(),
1759
+ workspaceProvisionType: workspaceProvisionTypeSchema.nullable(),
1760
+ createdAt: z6.number(),
1761
+ updatedAt: z6.number()
1762
+ });
1763
+
1764
+ // ../domain/src/queued-message.ts
1765
+ import { z as z10 } from "zod";
1766
+
1767
+ // ../domain/src/plugin-id.ts
1768
+ import { z as z7 } from "zod";
1769
+ var pluginIdSchema = z7.string().regex(/^[a-z0-9][a-z0-9-]*$/u);
1770
+
1771
+ // ../domain/src/protocol-ids.ts
1772
+ import { z as z8 } from "zod";
1773
+ var clientTurnRequestIdSchema = z8.string().regex(/^creq_[23456789abcdefghijkmnpqrstuvwxyz]{10}$/u);
1774
+
1775
+ // ../domain/src/system-message.ts
1776
+ import { z as z9 } from "zod";
1777
+ var systemMessageKindValues = [
1778
+ "ownership-assigned",
1779
+ "ownership-removed",
1780
+ "child-needs-attention",
1781
+ "child-completed",
1782
+ "child-failed",
1783
+ "child-interrupted",
1784
+ "child-outcome-batch",
1785
+ "tool-result-delivered",
1786
+ "environment-directory-updated",
1787
+ "unlabeled"
1788
+ ];
1789
+ var systemMessageKindSchema = z9.enum(systemMessageKindValues);
1790
+ var systemThreadInterruptedReasonSchema = z9.enum([
1791
+ "manual-stop",
1792
+ "host-daemon-restarted",
1793
+ "host-removed",
1794
+ "provider-turn-idle"
1795
+ ]);
1796
+ var childThreadOutcomeSchema = z9.object({
1797
+ threadId: z9.string(),
1798
+ status: z9.enum(["completed", "failed", "interrupted"]),
1799
+ interruption: z9.object({
1800
+ reason: systemThreadInterruptedReasonSchema,
1801
+ cause: z9.literal("host-connection-lost").optional()
1802
+ }).optional()
1803
+ });
1804
+ var systemMessageSubjectSchema = z9.discriminatedUnion("kind", [
1805
+ z9.object({
1806
+ kind: z9.literal("thread"),
1807
+ threadId: z9.string(),
1808
+ threadName: z9.string(),
1809
+ outcomes: z9.array(childThreadOutcomeSchema).optional()
1810
+ }),
1811
+ z9.object({
1812
+ kind: z9.literal("thread-batch"),
1813
+ count: z9.number(),
1814
+ outcomes: z9.array(childThreadOutcomeSchema).optional()
1815
+ }),
1816
+ z9.object({
1817
+ kind: z9.literal("tool-call"),
1818
+ toolName: z9.string(),
1819
+ suppress: z9.boolean()
1820
+ }),
1821
+ z9.object({
1822
+ kind: z9.literal("directory"),
1823
+ path: z9.string()
1824
+ })
1825
+ ]);
1826
+
1827
+ // ../domain/src/queued-message.ts
1828
+ var queuedMessageWaitingOnKindValues = [
1829
+ "time",
1830
+ "thread-busy",
1831
+ "stopping",
1832
+ "turn-starting",
1833
+ "provisioning",
1834
+ "host-offline",
1835
+ "interaction",
1836
+ "plugin"
1837
+ ];
1838
+ var queuedMessageWaitingOnKindSchema = z10.enum(
1839
+ queuedMessageWaitingOnKindValues
1840
+ );
1841
+ var queuedMessageWaitHostNameSchema = z10.string().min(1).max(200);
1842
+ var QUEUED_MESSAGE_WAIT_REASON_MAX_LENGTH = 200;
1843
+ var queuedMessageWaitReasonSchema = z10.string().min(1).max(QUEUED_MESSAGE_WAIT_REASON_MAX_LENGTH);
1844
+ var queuedMessageWaitingOnSchema = z10.discriminatedUnion("kind", [
1845
+ z10.object({ kind: z10.literal("time") }),
1846
+ z10.object({ kind: z10.literal("thread-busy") }),
1847
+ z10.object({ kind: z10.literal("stopping") }),
1848
+ z10.object({ kind: z10.literal("turn-starting") }),
1849
+ z10.object({ kind: z10.literal("provisioning") }),
1850
+ z10.object({
1851
+ kind: z10.literal("host-offline"),
1852
+ hostName: queuedMessageWaitHostNameSchema
1853
+ }),
1854
+ z10.object({ kind: z10.literal("interaction") }),
1855
+ z10.object({
1856
+ kind: z10.literal("plugin"),
1857
+ pluginId: pluginIdSchema,
1858
+ reason: queuedMessageWaitReasonSchema
1859
+ })
1860
+ ]);
1861
+ var QUEUED_MESSAGE_FAILURE_REASON_MAX_LENGTH = 200;
1862
+ var queuedMessageFailureReasonSchema = z10.string().min(1).max(QUEUED_MESSAGE_FAILURE_REASON_MAX_LENGTH);
1863
+ var QUEUED_MESSAGE_PLUGIN_WAIT_HOLDER_PREFIX = "plugin:";
1864
+ var queuedMessageWaitHolderSchema = z10.templateLiteral([
1865
+ QUEUED_MESSAGE_PLUGIN_WAIT_HOLDER_PREFIX,
1866
+ pluginIdSchema
1867
+ ]);
1868
+ var queuedMessagePayloadKindValues = ["inline", "retry"];
1869
+ var queuedMessagePayloadKindSchema = z10.enum(
1870
+ queuedMessagePayloadKindValues
1871
+ );
1872
+ var queuedMessagePayloadSchema = z10.discriminatedUnion("kind", [
1873
+ z10.object({ kind: z10.literal("inline") }),
1874
+ z10.object({
1875
+ kind: z10.literal("retry"),
1876
+ /**
1877
+ * The ORIGINAL request, not the attempt that just failed. Retrying a retry
1878
+ * re-submits the same original blocks, so this id is carried forward
1879
+ * unchanged across attempts and `attempt` is what distinguishes them.
1880
+ */
1881
+ retryOfTurnRequestId: clientTurnRequestIdSchema,
1882
+ /** Which attempt this row will dispatch: 2 is the first retry. */
1883
+ attempt: z10.number().int().min(2),
1884
+ /**
1885
+ * Why this turn is being retried, in the retrier's words ("Rate limited"),
1886
+ * as the row's card and `bb thread queue list` render it.
1887
+ *
1888
+ * It lives on the payload rather than on `waitingOn` because a retry can
1889
+ * wait on the clock, on a limiter, or on nothing at all, and the reason
1890
+ * outlives all three: it is a fact about the retry, not about what is
1891
+ * currently holding it. Filled at the boundary, so every row has one.
1892
+ */
1893
+ reason: queuedMessageWaitReasonSchema
1894
+ })
1895
+ ]);
1896
+ var queuedMessageSystemNoticeSchema = z10.object({
1897
+ kind: systemMessageKindSchema,
1898
+ subject: systemMessageSubjectSchema.nullable()
1899
+ });
1900
+
1901
+ // ../domain/src/queued-message-lifecycle.ts
1902
+ import { z as z11 } from "zod";
1903
+ var queuedMessageStateValues = [
1904
+ "queued",
1905
+ "scheduled",
1906
+ "waiting",
1907
+ "failed_retrying",
1908
+ "failed_exhausted",
1909
+ "claimed"
1910
+ ];
1911
+ var queuedMessageStateSchema = z11.enum(queuedMessageStateValues);
1912
+
1913
+ // ../domain/src/thread-status.ts
1914
+ import { z as z12 } from "zod";
1915
+ var threadStatusValues = [
1916
+ "pending",
1917
+ "idle",
1918
+ "starting",
1919
+ "active",
1920
+ "stopping",
1921
+ "error"
1922
+ ];
1923
+ var threadStatusSchema = z12.enum(threadStatusValues);
1924
+
1925
+ // ../domain/src/thread-origin-kind.ts
1926
+ import { z as z13 } from "zod";
1927
+ var threadOriginKindValues = ["fork"];
1928
+ var threadOriginKindSchema = z13.enum(threadOriginKindValues);
1929
+
1930
+ // ../domain/src/thread-parent-notifications.ts
1931
+ import { z as z14 } from "zod";
1932
+ var threadParentNotificationsValues = [
1933
+ "auto",
1934
+ "stuck",
1935
+ "off"
1936
+ ];
1937
+ var threadParentNotificationsSchema = z14.enum(
1938
+ threadParentNotificationsValues
1939
+ );
1940
+
1941
+ // ../domain/src/thread-visibility.ts
1942
+ import { z as z15 } from "zod";
1943
+ var threadVisibilityValues = ["visible", "hidden"];
1944
+ var threadVisibilitySchema = z15.enum(threadVisibilityValues);
1945
+
1946
+ // ../domain/src/thread-runtime-state.ts
1947
+ import { z as z16 } from "zod";
1948
+ var threadRuntimeDisplayStatusValues = [
1949
+ ...threadStatusValues,
1950
+ "provisioning",
1951
+ "waiting-for-host"
1952
+ ];
1953
+ var threadRuntimeDisplayStatusSchema = z16.enum(
1954
+ threadRuntimeDisplayStatusValues
1955
+ );
1956
+ var threadRuntimeStateSchema = z16.object({
1957
+ displayStatus: threadRuntimeDisplayStatusSchema
1958
+ });
1959
+ var threadActivityStateSchema = z16.object({
1960
+ activeWorkflowCount: z16.number().int().nonnegative(),
1961
+ activeBackgroundAgentCount: z16.number().int().nonnegative(),
1962
+ activeBackgroundCommandCount: z16.number().int().nonnegative(),
1963
+ activePlanModeCount: z16.number().int().nonnegative(),
1964
+ activeGoalCount: z16.number().int().nonnegative()
1965
+ });
1966
+
1967
+ // ../domain/src/thread.ts
1968
+ var workspaceStateValues = [
1969
+ "clean",
1970
+ "untracked",
1971
+ "dirty_uncommitted",
1972
+ "committed_unmerged",
1973
+ "dirty_and_committed_unmerged"
1974
+ ];
1975
+ var workspaceStateSchema = z17.enum(workspaceStateValues);
1976
+ var workspaceFileStatusKindSchema = z17.enum([
1977
+ "M",
1978
+ "A",
1979
+ "D",
1980
+ "R",
1981
+ "C",
1982
+ "U",
1983
+ "??",
1984
+ "?"
1985
+ ]);
1986
+ var workspaceFileStatusSchema = z17.object({
1987
+ path: z17.string(),
1988
+ status: workspaceFileStatusKindSchema,
1989
+ insertions: z17.number().nullable(),
1990
+ deletions: z17.number().nullable()
1991
+ });
1992
+ var workspaceCommitSummarySchema = z17.object({
1993
+ sha: z17.string(),
1994
+ shortSha: z17.string(),
1995
+ subject: z17.string(),
1996
+ authorName: z17.string(),
1997
+ authoredAt: z17.number()
1998
+ });
1999
+ var workspaceChangeStatsSchema = z17.object({
2000
+ insertions: z17.number(),
2001
+ deletions: z17.number(),
2002
+ lineStatsComplete: z17.boolean(),
2003
+ fileCount: z17.number().int().nonnegative(),
2004
+ files: z17.array(workspaceFileStatusSchema)
2005
+ });
2006
+ var workspaceWorkingTreeSchema = workspaceChangeStatsSchema.extend({
2007
+ hasUncommittedChanges: z17.boolean(),
2008
+ state: workspaceStateSchema
2009
+ });
2010
+ var workspaceBranchSchema = z17.object({
2011
+ currentBranch: z17.string().nullable(),
2012
+ defaultBranch: z17.string()
2013
+ });
2014
+ var workspaceMergeBaseSchema = workspaceChangeStatsSchema.extend({
2015
+ mergeBaseBranch: z17.string(),
2016
+ baseRef: z17.string().nullable(),
2017
+ aheadCount: z17.number(),
2018
+ behindCount: z17.number(),
2019
+ squashMergeCheckComplete: z17.boolean(),
2020
+ hasCommittedUnmergedChanges: z17.boolean(),
2021
+ commits: z17.array(workspaceCommitSummarySchema)
2022
+ });
2023
+ var workspaceStatusSchema = z17.object({
2024
+ workingTree: workspaceWorkingTreeSchema,
2025
+ checkout: gitCheckoutRefSchema,
2026
+ branch: workspaceBranchSchema,
2027
+ mergeBase: workspaceMergeBaseSchema.nullable()
2028
+ });
2029
+ var threadQueuedMessageSchema = z17.object({
2030
+ id: z17.string(),
2031
+ origin: threadCreateOriginSchema.nullable(),
2032
+ originPluginId: z17.string().nullable(),
2033
+ initiator: z17.enum(["user", "agent", "system"]),
2034
+ senderThreadId: z17.string().nullable(),
2035
+ /**
2036
+ * The thread this row is waiting on. Redundant on the thread-scoped list
2037
+ * route that first served this DTO, and load-bearing everywhere else it is
2038
+ * now served: a `queue.*` plugin event and a cross-thread wait-holder query
2039
+ * both hand out rows with no surrounding thread to read it from.
2040
+ */
2041
+ threadId: z17.string(),
2042
+ content: z17.array(promptInputSchema).min(1),
2043
+ model: z17.string().min(1),
2044
+ reasoningLevel: reasoningLevelSchema,
2045
+ permissionMode: permissionModeSchema,
2046
+ serviceTier: serviceTierSchema,
2047
+ groupWithNext: z17.boolean(),
2048
+ /**
2049
+ * Epoch ms this row is scheduled to attempt dispatch, or null when it is
2050
+ * eligible as soon as its other waits clear.
2051
+ */
2052
+ sendAt: z17.number().int().nonnegative().nullable(),
2053
+ state: queuedMessageStateSchema,
2054
+ /**
2055
+ * Why this row is queued, or null for a `queued` row that is simply next in
2056
+ * line behind the running turn.
2057
+ */
2058
+ waitingOn: queuedMessageWaitingOnSchema.nullable(),
2059
+ /**
2060
+ * Why this row's last DRAIN attempt failed outright, or null when it has not
2061
+ * failed one — which is every row that has never been re-attempted, and
2062
+ * every row whose latest attempt merely queued again. An inline attempt
2063
+ * reports its failure to the sender that is still listening and never lands
2064
+ * here.
2065
+ *
2066
+ * Independent of `waitingOn`, not folded into it: the row is still waiting on
2067
+ * whatever it was waiting on, and writing a wait rewrites it wholesale, so a
2068
+ * failure stored there would not survive the next attempt.
2069
+ */
2070
+ failureReason: queuedMessageFailureReasonSchema.nullable(),
2071
+ payload: queuedMessagePayloadSchema,
2072
+ /**
2073
+ * Whether the sender may still rewrite this row's input. Not derivable from
2074
+ * `payload` alone: a `retry` row is never editable, and an `inline` row
2075
+ * stops being editable once the drain has claimed it — and the claim is
2076
+ * deliberately not part of this response, since it is drain bookkeeping and
2077
+ * not something a client should reason about. The server folds both into
2078
+ * this one answer.
2079
+ */
2080
+ editable: z17.boolean(),
2081
+ createdAt: z17.number(),
2082
+ updatedAt: z17.number()
2083
+ });
2084
+ var threadSchema = z17.object({
2085
+ id: z17.string(),
2086
+ projectId: z17.string(),
2087
+ environmentId: z17.string().nullable(),
2088
+ providerId: z17.string(),
2089
+ title: z17.string().nullable(),
2090
+ titleFallback: z17.string().nullable(),
2091
+ sectionId: z17.string().nullable(),
2092
+ status: threadStatusSchema,
2093
+ parentThreadId: z17.string().nullable(),
2094
+ lifecycleOwnerThreadId: z17.string().nullable(),
2095
+ sourceThreadId: z17.string().nullable(),
2096
+ originKind: threadOriginKindSchema.nullable(),
2097
+ originPluginId: z17.string().nullable(),
2098
+ visibility: threadVisibilitySchema,
2099
+ parentNotifications: threadParentNotificationsSchema,
2100
+ archivedAt: z17.number().nullable(),
2101
+ pinnedAt: z17.number().nullable(),
2102
+ deletedAt: z17.number().nullable(),
2103
+ lastReadAt: z17.number().nullable(),
2104
+ latestAttentionAt: z17.number(),
2105
+ createdAt: z17.number(),
2106
+ updatedAt: z17.number()
2107
+ });
2108
+ var threadWithRuntimeSchema = threadSchema.extend({
2109
+ runtime: threadRuntimeStateSchema
2110
+ });
2111
+ var threadQueuedWorkValues = ["none", "waiting", "failed"];
2112
+ var threadQueuedWorkSchema = z17.enum(threadQueuedWorkValues);
2113
+ var threadListEntrySchema = threadWithRuntimeSchema.extend({
2114
+ activity: threadActivityStateSchema,
2115
+ queuedWork: threadQueuedWorkSchema,
2116
+ pinSortKey: z17.string().nullable(),
2117
+ hasPendingInteraction: z17.boolean(),
2118
+ environmentHostId: z17.string().nullable(),
2119
+ environmentName: z17.string().nullable(),
2120
+ environmentBranchName: z17.string().nullable(),
2121
+ environmentPath: z17.string().nullable(),
2122
+ environmentProviderId: z17.string().nullable(),
2123
+ environmentIsWorktree: z17.boolean().nullable(),
2124
+ environmentWorkspaceDisplayKind: environmentWorkspaceDisplayKindSchema
2125
+ });
2126
+
2127
+ // ../domain/src/change-kinds.ts
2128
+ var THREAD_CHANGE_KINDS = [
2129
+ "thread-created",
2130
+ "thread-deleted",
2131
+ "events-appended",
2132
+ "history-rewritten",
2133
+ "history-compacted",
2134
+ "interactions-changed",
2135
+ "status-changed",
2136
+ "title-changed",
2137
+ "queue-changed",
2138
+ "archived-changed",
2139
+ "pin-state-changed",
2140
+ "parent-changed",
2141
+ "environment-changed",
2142
+ "read-state-changed",
2143
+ "tabs-changed",
2144
+ "terminals-changed"
2145
+ ];
2146
+ var PROJECT_CHANGE_KINDS = [
2147
+ "project-created",
2148
+ "project-updated",
2149
+ "project-deleted",
2150
+ "project-sources-changed",
2151
+ "threads-changed",
2152
+ "project-order-changed"
2153
+ ];
2154
+ var ENVIRONMENT_CHANGE_KINDS = [
2155
+ "environment-created",
2156
+ "environment-deleted",
2157
+ "metadata-changed",
2158
+ "status-changed",
2159
+ "work-status-changed",
2160
+ "git-refs-changed",
2161
+ "thread-storage-changed",
2162
+ "diff-viewed-changed"
2163
+ ];
2164
+ var HOST_CHANGE_KINDS = [
2165
+ "host-connected",
2166
+ "host-disconnected",
2167
+ "provider-model-catalog-changed"
2168
+ ];
2169
+ var SYSTEM_CHANGE_KINDS = [
2170
+ "config-changed",
2171
+ "plugins-changed",
2172
+ "plugin-install-jobs-changed",
2173
+ "plugin-update-jobs-changed",
2174
+ "provider-registrations-changed",
2175
+ "environment-availability-changed",
2176
+ "server-move-changed",
2177
+ "app-update-changed"
2178
+ ];
2179
+ var threadChangeKindSchema = z18.enum(THREAD_CHANGE_KINDS);
2180
+ var projectChangeKindSchema = z18.enum(PROJECT_CHANGE_KINDS);
2181
+ var environmentChangeKindSchema = z18.enum(ENVIRONMENT_CHANGE_KINDS);
2182
+ var hostChangeKindSchema = z18.enum(HOST_CHANGE_KINDS);
2183
+ var systemChangeKindSchema = z18.enum(SYSTEM_CHANGE_KINDS);
2184
+ var threadTimelineSubscriptionTargetSchema = z18.object({
2185
+ kind: z18.literal("thread-timeline"),
2186
+ threadId: z18.string().min(1),
2187
+ segmentLimit: z18.number().int().positive().nullable(),
2188
+ deferContent: z18.boolean()
2189
+ }).strict();
2190
+ function canonicalPluginReadInput(value) {
2191
+ if (value === null || typeof value !== "object") return JSON.stringify(value);
2192
+ if (Array.isArray(value))
2193
+ return `[${value.map(canonicalPluginReadInput).join(",")}]`;
2194
+ return `{${Object.keys(value).sort().map(
2195
+ (key) => `${JSON.stringify(key)}:${canonicalPluginReadInput(value[key])}`
2196
+ ).join(",")}}`;
2197
+ }
2198
+ var pluginReadSubscriptionTargetSchema = z18.object({
2199
+ kind: z18.literal("plugin-read"),
2200
+ pluginId: z18.string().min(1),
2201
+ method: z18.string().min(1),
2202
+ read: z18.union([
2203
+ z18.object({ input: jsonValueSchema }).strict(),
2204
+ z18.object({ key: z18.string() }).strict()
2205
+ ]).refine(
2206
+ (read) => new TextEncoder().encode(canonicalPluginReadInput(read)).byteLength <= 16384,
2207
+ "Plugin read input exceeds 16 KiB"
2208
+ )
2209
+ }).strict();
2210
+ var realtimeSubscriptionTargetSchema = z18.discriminatedUnion("kind", [
2211
+ pluginReadSubscriptionTargetSchema,
2212
+ z18.object({ kind: z18.literal("plugin"), pluginId: z18.string().min(1) }).strict(),
2213
+ z18.object({
2214
+ kind: z18.literal("thread-detail"),
2215
+ threadId: z18.string().min(1)
2216
+ }).strict(),
2217
+ threadTimelineSubscriptionTargetSchema,
2218
+ z18.object({
2219
+ kind: z18.literal("thread-list")
2220
+ }).strict(),
2221
+ z18.object({
2222
+ kind: z18.literal("project-detail"),
2223
+ projectId: z18.string().min(1)
2224
+ }).strict(),
2225
+ z18.object({
2226
+ kind: z18.literal("project-list")
2227
+ }).strict(),
2228
+ z18.object({
2229
+ kind: z18.literal("environment-detail"),
2230
+ environmentId: z18.string().min(1)
2231
+ }).strict(),
2232
+ z18.object({
2233
+ kind: z18.literal("environment-list")
2234
+ }).strict(),
2235
+ z18.object({
2236
+ kind: z18.literal("host-detail"),
2237
+ hostId: z18.string().min(1)
2238
+ }).strict(),
2239
+ z18.object({
2240
+ kind: z18.literal("host-list")
2241
+ }).strict(),
2242
+ z18.object({
2243
+ kind: z18.literal("system")
2244
+ }).strict()
2245
+ ]);
2246
+ function isValidSubscriptionTarget(value) {
2247
+ return realtimeSubscriptionTargetSchema.safeParse(value).success;
2248
+ }
2249
+ var validSubscriptionTargetsSchema = z18.preprocess(
2250
+ (value) => Array.isArray(value) ? value.filter(isValidSubscriptionTarget) : value,
2251
+ z18.array(realtimeSubscriptionTargetSchema)
2252
+ );
2253
+ var validSubscriptionTargetSchema = z18.preprocess(
2254
+ (value) => value === void 0 || isValidSubscriptionTarget(value) ? value : null,
2255
+ realtimeSubscriptionTargetSchema.nullable().optional()
2256
+ );
2257
+ var subscriptionFields = {
2258
+ target: validSubscriptionTargetSchema,
2259
+ targets: validSubscriptionTargetsSchema.optional()
2260
+ };
2261
+ var hasSubscriptionTargets = (value) => value.target !== void 0 !== (value.targets !== void 0);
2262
+ var subscribeMessageSchema = z18.object({ type: z18.literal("subscribe"), ...subscriptionFields }).refine(hasSubscriptionTargets);
2263
+ var unsubscribeMessageSchema = z18.object({ type: z18.literal("unsubscribe"), ...subscriptionFields }).refine(hasSubscriptionTargets);
2264
+ var pingMessageSchema = z18.object({
2265
+ type: z18.literal("ping")
2266
+ });
2267
+ var visibilityMessageSchema = z18.object({
2268
+ type: z18.literal("visibility"),
2269
+ visible: z18.boolean()
2270
+ });
2271
+ var clientMessageSchema = z18.discriminatedUnion("type", [
2272
+ subscribeMessageSchema,
2273
+ unsubscribeMessageSchema,
2274
+ pingMessageSchema,
2275
+ visibilityMessageSchema
2276
+ ]);
2277
+ var pongMessageSchema = z18.object({
2278
+ type: z18.literal("pong")
2279
+ }).strict();
2280
+ var pongMessageLenientSchema = z18.object({
2281
+ type: z18.literal("pong")
2282
+ });
2283
+ var threadStatusChangeMetadataSchema = z18.object({
2284
+ status: threadStatusSchema,
2285
+ runtime: threadRuntimeStateSchema,
2286
+ activity: threadActivityStateSchema,
2287
+ latestAttentionAt: z18.number(),
2288
+ updatedAt: z18.number()
2289
+ }).strict();
2290
+ var threadChangeMetadataSchema = z18.object({
2291
+ backgroundActivityChanged: z18.boolean().optional(),
2292
+ eventTypes: z18.array(threadEventTypeSchema).readonly().optional(),
2293
+ timelineSequence: z18.number().int().nonnegative().optional(),
2294
+ hasPendingInteraction: z18.boolean().optional(),
2295
+ projectId: z18.string().optional(),
2296
+ statusChange: threadStatusChangeMetadataSchema.optional()
2297
+ }).strict();
2298
+ var threadChangedMessageSchema = z18.object({
2299
+ type: z18.literal("changed"),
2300
+ entity: z18.literal("thread"),
2301
+ id: z18.string().optional(),
2302
+ metadata: threadChangeMetadataSchema.optional(),
2303
+ changes: z18.array(threadChangeKindSchema).readonly()
2304
+ }).strict();
2305
+ var projectChangedMessageSchema = z18.object({
2306
+ type: z18.literal("changed"),
2307
+ entity: z18.literal("project"),
2308
+ id: z18.string().optional(),
2309
+ changes: z18.array(projectChangeKindSchema).readonly()
2310
+ }).strict();
2311
+ var environmentChangedMessageSchema = z18.object({
2312
+ type: z18.literal("changed"),
2313
+ entity: z18.literal("environment"),
2314
+ id: z18.string().optional(),
2315
+ changes: z18.array(environmentChangeKindSchema).readonly()
2316
+ }).strict();
2317
+ var hostChangedMessageSchema = z18.object({
2318
+ type: z18.literal("changed"),
2319
+ entity: z18.literal("host"),
2320
+ id: z18.string().optional(),
2321
+ changes: z18.array(hostChangeKindSchema).readonly()
2322
+ }).strict();
2323
+ var systemChangedMessageSchema = z18.object({
2324
+ type: z18.literal("changed"),
2325
+ entity: z18.literal("system"),
2326
+ changes: z18.array(systemChangeKindSchema).readonly()
2327
+ }).strict();
2328
+ var tagsChangedMessageSchema = z18.object({
2329
+ type: z18.literal("changed"),
2330
+ entity: z18.literal("tags"),
2331
+ tags: z18.array(z18.string().min(1)).min(1)
2332
+ }).strict();
2333
+ var pluginChangedMessageSchema = z18.object({
2334
+ type: z18.literal("changed"),
2335
+ entity: z18.literal("plugin"),
2336
+ pluginId: z18.string().min(1),
2337
+ tags: z18.array(z18.string().min(1)).min(1).nullable()
2338
+ }).strict();
2339
+ var changedMessageSchema = z18.discriminatedUnion("entity", [
2340
+ threadChangedMessageSchema,
2341
+ projectChangedMessageSchema,
2342
+ environmentChangedMessageSchema,
2343
+ hostChangedMessageSchema,
2344
+ systemChangedMessageSchema,
2345
+ tagsChangedMessageSchema,
2346
+ pluginChangedMessageSchema
2347
+ ]);
2348
+ function lenientKinds(kinds) {
2349
+ const known = new Set(kinds);
2350
+ return z18.array(z18.string()).transform(
2351
+ (values) => values.filter((value) => known.has(value))
2352
+ );
2353
+ }
2354
+ var knownThreadEventTypes = new Set(
2355
+ threadEventTypeValues
2356
+ );
2357
+ var threadChangeMetadataLenientSchema = z18.object({
2358
+ timelineSequence: z18.number().int().nonnegative().optional(),
2359
+ backgroundActivityChanged: z18.boolean().optional(),
2360
+ eventTypes: z18.array(z18.string()).transform(
2361
+ (values) => values.filter(
2362
+ (value) => knownThreadEventTypes.has(value)
2363
+ )
2364
+ ).optional(),
2365
+ hasPendingInteraction: z18.boolean().optional(),
2366
+ projectId: z18.string().optional(),
2367
+ statusChange: threadStatusChangeMetadataSchema.optional().catch(void 0)
2368
+ });
2369
+ var threadChangedMessageLenientSchema = z18.object({
2370
+ type: z18.literal("changed"),
2371
+ entity: z18.literal("thread"),
2372
+ id: z18.string().optional(),
2373
+ metadata: threadChangeMetadataLenientSchema.optional(),
2374
+ changes: lenientKinds(THREAD_CHANGE_KINDS)
2375
+ });
2376
+ var projectChangedMessageLenientSchema = z18.object({
2377
+ type: z18.literal("changed"),
2378
+ entity: z18.literal("project"),
2379
+ id: z18.string().optional(),
2380
+ changes: lenientKinds(PROJECT_CHANGE_KINDS)
2381
+ });
2382
+ var environmentChangedMessageLenientSchema = z18.object({
2383
+ type: z18.literal("changed"),
2384
+ entity: z18.literal("environment"),
2385
+ id: z18.string().optional(),
2386
+ changes: lenientKinds(ENVIRONMENT_CHANGE_KINDS)
2387
+ });
2388
+ var hostChangedMessageLenientSchema = z18.object({
2389
+ type: z18.literal("changed"),
2390
+ entity: z18.literal("host"),
2391
+ id: z18.string().optional(),
2392
+ changes: lenientKinds(HOST_CHANGE_KINDS)
2393
+ });
2394
+ var systemChangedMessageLenientSchema = z18.object({
2395
+ type: z18.literal("changed"),
2396
+ entity: z18.literal("system"),
2397
+ changes: lenientKinds(SYSTEM_CHANGE_KINDS)
2398
+ });
2399
+ var changedMessageLenientSchema = z18.discriminatedUnion("entity", [
2400
+ threadChangedMessageLenientSchema,
2401
+ projectChangedMessageLenientSchema,
2402
+ environmentChangedMessageLenientSchema,
2403
+ hostChangedMessageLenientSchema,
2404
+ systemChangedMessageLenientSchema,
2405
+ tagsChangedMessageSchema.strip(),
2406
+ pluginChangedMessageSchema.strip()
2407
+ ]);
2408
+
1280
2409
  // src/internal/rpc-tags.ts
1281
- import { z as z2 } from "zod";
1282
- var rpcInvalidationTags = z2.array(z2.string().min(1)).min(1);
2410
+ import { z as z19 } from "zod";
2411
+ var rpcInvalidationTags = z19.array(z19.string().min(1)).min(1);
1283
2412
  function rpcResponseTags(declarations, input, output) {
1284
- const tags = z2.array(z2.string().min(1)).parse(declarations.tags?.(input, output) ?? []);
2413
+ const tags = z19.array(z19.string().min(1)).parse(declarations.tags?.(input, output) ?? []);
1285
2414
  const keyTags = {};
1286
2415
  if (declarations.keyTags && typeof output === "object" && output !== null && !Array.isArray(output)) {
1287
2416
  for (const [key, value] of Object.entries(output)) {
1288
- keyTags[key] = z2.array(z2.string().min(1)).parse(declarations.keyTags(key, value));
2417
+ keyTags[key] = z19.array(z19.string().min(1)).parse(declarations.keyTags(key, value));
1289
2418
  }
1290
2419
  }
1291
- const invalidated = z2.array(z2.string().min(1)).parse(declarations.invalidates?.(input, output) ?? []);
2420
+ const invalidated = z19.array(z19.string().min(1)).parse(declarations.invalidates?.(input, output) ?? []);
1292
2421
  return { tags, keyTags, invalidated };
1293
2422
  }
1294
2423
 
1295
2424
  // src/internal/rpc-query-host.ts
1296
- import { z as z3 } from "zod";
2425
+ import { z as z20 } from "zod";
1297
2426
  var rpcQueryKey = (pluginId, method, input) => [
1298
2427
  "plugin-rpc",
1299
2428
  pluginId,
@@ -1366,6 +2495,15 @@ async function callRpc(host, pluginId, contract, method, input) {
1366
2495
  ...rpcResponseTags(methodContract, parsedInput.value, result.data)
1367
2496
  };
1368
2497
  }
2498
+ function resolvePluginId(host, pluginId) {
2499
+ const resolved = pluginId ?? host.pluginId;
2500
+ if (resolved === null) {
2501
+ throw new Error(
2502
+ "plugin RPC hooks outside a plugin slot component need an explicit pluginId"
2503
+ );
2504
+ }
2505
+ return resolved;
2506
+ }
1369
2507
  var tagsOf = (data) => [
1370
2508
  ...data.tags,
1371
2509
  ...Object.values(data.keyTags).flat()
@@ -1380,10 +2518,17 @@ function createRpcQueryHooks(useHost) {
1380
2518
  }
1381
2519
  const experimental_useRpcQuery = (options) => {
1382
2520
  const host = useHost();
1383
- const pluginId = options.pluginId ?? host.pluginId;
2521
+ const pluginId = resolvePluginId(host, options.pluginId);
1384
2522
  const input = jsonValueSchema.parse(options.input ?? null);
1385
2523
  const queryKey = rpcQueryKey(pluginId, options.method, input);
1386
2524
  useSubscription(host, pluginId, options.enabled ?? true);
2525
+ const watchIdentity = canonicalPluginReadInput(input);
2526
+ useEffect2(() => {
2527
+ if (options.enabled === false) return;
2528
+ return host.watch?.(pluginId, options.method, {
2529
+ input: jsonValueSchema.parse(JSON.parse(watchIdentity))
2530
+ });
2531
+ }, [host, pluginId, options.method, watchIdentity, options.enabled]);
1387
2532
  const query = useTaggedQuery(
1388
2533
  {
1389
2534
  queryKey,
@@ -1395,13 +2540,7 @@ function createRpcQueryHooks(useHost) {
1395
2540
  queryFn: () => runTaggedRead(
1396
2541
  host.queryClient,
1397
2542
  queryKey,
1398
- async () => callRpc(
1399
- host,
1400
- pluginId,
1401
- options.contract,
1402
- options.method,
1403
- input
1404
- )
2543
+ async () => callRpc(host, pluginId, options.contract, options.method, input)
1405
2544
  )
1406
2545
  },
1407
2546
  host.queryClient
@@ -1421,11 +2560,11 @@ function createRpcQueryHooks(useHost) {
1421
2560
  };
1422
2561
  function experimental_useRpcKeyedQuery(options) {
1423
2562
  const host = useHost();
1424
- const pluginId = options.pluginId ?? host.pluginId;
2563
+ const pluginId = resolvePluginId(host, options.pluginId);
1425
2564
  const enabled = options.enabled ?? true;
1426
2565
  const identity = JSON.stringify([...new Set(options.keys)].sort());
1427
2566
  const keys = useMemo2(
1428
- () => z3.array(z3.string()).parse(JSON.parse(identity)),
2567
+ () => z20.array(z20.string()).parse(JSON.parse(identity)),
1429
2568
  [identity]
1430
2569
  );
1431
2570
  let cache = owners.get(host.queryClient);
@@ -1451,7 +2590,7 @@ function createRpcQueryHooks(useHost) {
1451
2590
  );
1452
2591
  return {
1453
2592
  ...response,
1454
- result: z3.record(z3.string(), jsonValueSchema).parse(response.result)
2593
+ result: z20.record(z20.string(), jsonValueSchema).parse(response.result)
1455
2594
  };
1456
2595
  }
1457
2596
  });
@@ -1488,6 +2627,15 @@ function createRpcQueryHooks(useHost) {
1488
2627
  [keys, enabled, selectRows]
1489
2628
  );
1490
2629
  const query = useQuerySelection(subscribe, getSnapshot, select);
2630
+ useEffect2(() => {
2631
+ if (!enabled) return;
2632
+ const releases = keys.map(
2633
+ (key) => host.watch?.(pluginId, options.method, { key })
2634
+ );
2635
+ return () => {
2636
+ releases.forEach((release) => release?.());
2637
+ };
2638
+ }, [host, pluginId, options.method, keys, enabled]);
1491
2639
  const refetch = useCallback2(async () => {
1492
2640
  await current.observer.refetch();
1493
2641
  }, [current]);
@@ -1498,7 +2646,7 @@ function createRpcQueryHooks(useHost) {
1498
2646
  }
1499
2647
  function experimental_useRpcMutation(options) {
1500
2648
  const host = useHost();
1501
- const pluginId = options.pluginId ?? host.pluginId;
2649
+ const pluginId = resolvePluginId(host, options.pluginId);
1502
2650
  const mutation = useTaggedMutation({
1503
2651
  client: host.queryClient,
1504
2652
  invalidate: (tags) => invalidateTags(host.queryClient, pluginTagScope(pluginId), tags),
@@ -1547,18 +2695,12 @@ function createRpcQueryHooks(useHost) {
1547
2695
  }
1548
2696
  function experimental_useRpcRefresh() {
1549
2697
  const host = useHost();
1550
- const isRefreshing = useIsFetching(
1551
- { queryKey: ["plugin-rpc", host.pluginId] },
1552
- host.queryClient
1553
- ) > 0;
2698
+ const pluginId = resolvePluginId(host, void 0);
2699
+ const isRefreshing = useIsFetching({ queryKey: ["plugin-rpc", pluginId] }, host.queryClient) > 0;
1554
2700
  return {
1555
2701
  isRefreshing,
1556
2702
  refresh: () => {
1557
- void invalidateTags(
1558
- host.queryClient,
1559
- pluginTagScope(host.pluginId),
1560
- null
1561
- );
2703
+ void invalidateTags(host.queryClient, pluginTagScope(pluginId), null);
1562
2704
  }
1563
2705
  };
1564
2706
  }