@notionhq/custom-blocks-dev-shell 0.1.116 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Workers local shell</title>
7
- <script type="module" crossorigin src="/assets/index-DSaseWP_.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-CWJ-vFk0.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-Do-x8yIt.css">
9
9
  </head>
10
10
  <body>
@@ -865,6 +865,15 @@ function variant(key, options, message$1) {
865
865
  }
866
866
  });
867
867
  }
868
+ // @__NO_SIDE_EFFECTS__
869
+ function omit(schema, keys) {
870
+ const entries$1 = { ...schema.entries };
871
+ for (const key of keys) delete entries$1[key];
872
+ return _standardSchema({
873
+ ...schema,
874
+ entries: entries$1
875
+ });
876
+ }
868
877
  function parse(schema, input, config$1) {
869
878
  const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config$1));
870
879
  if (dataset.issues) throw new ValiError(dataset.issues);
@@ -907,6 +916,10 @@ var notionDataSourceIdSchema = pipe(
907
916
  var notionPageIdSchema = pipe(string(), brand("NotionPageId"));
908
917
  var notionAgentIdSchema = pipe(string(), brand("NotionAgentId"));
909
918
  var notionSpaceIdSchema = pipe(string(), brand("NotionSpaceId"));
919
+ var notionAppInstallationIdSchema = pipe(
920
+ string(),
921
+ brand("NotionAppInstallationId")
922
+ );
910
923
 
911
924
  // ../protocol/src/context/parent.ts
912
925
  var pageParentSchema = object({
@@ -929,6 +942,10 @@ var agentParentSchema = object({
929
942
  type: literal("agent_id"),
930
943
  agent_id: notionAgentIdSchema
931
944
  });
945
+ var appInstallationParentSchema = object({
946
+ type: literal("app_installation_id"),
947
+ app_installation_id: notionAppInstallationIdSchema
948
+ });
932
949
  var unavailableParentSchema = object({ type: literal("unavailable") });
933
950
  var notionParentSchema = variant("type", [
934
951
  pageParentSchema,
@@ -936,15 +953,57 @@ var notionParentSchema = variant("type", [
936
953
  workspaceParentSchema,
937
954
  blockParentSchema,
938
955
  agentParentSchema,
956
+ appInstallationParentSchema,
939
957
  unavailableParentSchema
940
958
  ]);
941
959
 
942
- // ../protocol/src/pages/pageAppearance.ts
943
- var notionEmojiIconSchema = object({
960
+ // ../protocol/src/files.ts
961
+ var bridgeExternalFileSchema = object({
962
+ type: literal("external"),
963
+ external: object({ url: string() })
964
+ });
965
+ var bridgeNotionHostedFileSchema = object({
966
+ type: literal("file"),
967
+ file: object({
968
+ url: string(),
969
+ expiry_time: optional(string())
970
+ })
971
+ });
972
+ var bridgeFilePropertyItemSchema = union([
973
+ object({ ...bridgeExternalFileSchema.entries, name: string() }),
974
+ object({ ...bridgeNotionHostedFileSchema.entries, name: string() })
975
+ ]);
976
+
977
+ // ../protocol/src/icons.ts
978
+ var bridgeIconNameSchema = string();
979
+ var knownBridgeIconColorSchema = picklist([
980
+ "gray",
981
+ "lightgray",
982
+ "brown",
983
+ "yellow",
984
+ "orange",
985
+ "green",
986
+ "blue",
987
+ "purple",
988
+ "pink",
989
+ "red"
990
+ ]);
991
+ var bridgeIconColorSchema = union([
992
+ knownBridgeIconColorSchema,
993
+ string()
994
+ ]);
995
+ var bridgeIconSchema = looseObject({
996
+ type: literal("icon"),
997
+ icon: looseObject({
998
+ name: bridgeIconNameSchema,
999
+ color: optional(bridgeIconColorSchema)
1000
+ })
1001
+ });
1002
+ var bridgeEmojiSchema = object({
944
1003
  type: literal("emoji"),
945
1004
  emoji: string()
946
1005
  });
947
- var notionCustomEmojiIconSchema = object({
1006
+ var bridgeCustomEmojiSchema = object({
948
1007
  type: literal("custom_emoji"),
949
1008
  custom_emoji: object({
950
1009
  id: string(),
@@ -952,26 +1011,18 @@ var notionCustomEmojiIconSchema = object({
952
1011
  url: optional(string())
953
1012
  })
954
1013
  });
955
- var notionExternalFileSchema = object({
956
- type: literal("external"),
957
- external: object({ url: string() })
958
- });
959
- var notionHostedFileSchema = object({
960
- type: literal("file"),
961
- file: object({
962
- url: string(),
963
- expiry_time: optional(string())
964
- })
965
- });
966
- var notionPageIconSchema = variant("type", [
967
- notionEmojiIconSchema,
968
- notionCustomEmojiIconSchema,
969
- notionExternalFileSchema,
970
- notionHostedFileSchema
1014
+
1015
+ // ../protocol/src/pages/pageAppearance.ts
1016
+ var bridgePageIconSchema = variant("type", [
1017
+ bridgeIconSchema,
1018
+ bridgeEmojiSchema,
1019
+ bridgeCustomEmojiSchema,
1020
+ bridgeExternalFileSchema,
1021
+ bridgeNotionHostedFileSchema
971
1022
  ]);
972
- var notionPageCoverSchema = variant("type", [
973
- notionExternalFileSchema,
974
- notionHostedFileSchema
1023
+ var bridgePageCoverSchema = variant("type", [
1024
+ bridgeExternalFileSchema,
1025
+ bridgeNotionHostedFileSchema
975
1026
  ]);
976
1027
 
977
1028
  // ../protocol/src/utils/nullableStringSchema.ts
@@ -1061,23 +1112,6 @@ var notionDateInputSchema = union([
1061
1112
  })
1062
1113
  ]);
1063
1114
 
1064
- // ../protocol/src/pages/properties/fileInput.ts
1065
- var notionFileInputSchema = union([
1066
- object({
1067
- type: literal("external"),
1068
- name: string(),
1069
- external: object({ url: string() })
1070
- }),
1071
- object({
1072
- type: literal("file"),
1073
- name: string(),
1074
- file: object({
1075
- url: string(),
1076
- expiry_time: optional(string())
1077
- })
1078
- })
1079
- ]);
1080
-
1081
1115
  // ../protocol/src/utils/recordPointer.ts
1082
1116
  var notionRecordPointerSchema = object({
1083
1117
  id: string(),
@@ -1210,7 +1244,7 @@ var bridgePagePropertyValueSchema = variant("type", [
1210
1244
  object({
1211
1245
  ...pagePropertyBaseSchema,
1212
1246
  type: literal("files"),
1213
- files: array(notionFileInputSchema)
1247
+ files: array(bridgeFilePropertyItemSchema)
1214
1248
  }),
1215
1249
  object({
1216
1250
  ...pagePropertyBaseSchema,
@@ -1237,11 +1271,6 @@ var bridgePagePropertyValueSchema = variant("type", [
1237
1271
  type: literal("last_edited_by"),
1238
1272
  last_edited_by: metadataActorSchema
1239
1273
  }),
1240
- object({
1241
- ...pagePropertyBaseSchema,
1242
- type: literal("last_visited_time"),
1243
- last_visited_time: nullableStringSchema
1244
- }),
1245
1274
  object({
1246
1275
  ...pagePropertyBaseSchema,
1247
1276
  type: literal("unique_id"),
@@ -1292,8 +1321,8 @@ var bridgePageForProtocol3To5Schema = object({
1292
1321
  properties: bridgePagePropertyWriteMapSchema,
1293
1322
  created_time: optional(string()),
1294
1323
  last_edited_time: optional(string()),
1295
- icon: optional(notionPageIconSchema),
1296
- cover: optional(notionPageCoverSchema),
1324
+ icon: optional(bridgePageIconSchema),
1325
+ cover: optional(bridgePageCoverSchema),
1297
1326
  url: optional(string()),
1298
1327
  public_url: optional(string()),
1299
1328
  /** Whether the page or an ancestor is archived. */
@@ -1375,6 +1404,13 @@ var themeChangedMessageSchema = object({
1375
1404
  theme: notionThemeSchema
1376
1405
  });
1377
1406
 
1407
+ // ../protocol/src/dataSources/bridgeArchiveStatus.ts
1408
+ var bridgeArchiveStatusSchema = picklist([
1409
+ "active",
1410
+ "archived",
1411
+ "all"
1412
+ ]);
1413
+
1378
1414
  // ../protocol/src/dataSources/collectionPointer.ts
1379
1415
  var collectionPointerValidator = object({
1380
1416
  id: notionDataSourceIdSchema,
@@ -1446,7 +1482,6 @@ var NOTION_PROPERTY_TYPES = [
1446
1482
  "rollup",
1447
1483
  "button",
1448
1484
  "verification",
1449
- "last_visited_time",
1450
1485
  "location",
1451
1486
  "created_time",
1452
1487
  "last_edited_time",
@@ -1494,7 +1529,6 @@ var notionPropertySchemaSchema = variant("type", [
1494
1529
  // Internal-only types passed through under their bridge-native names.
1495
1530
  object({ ...baseProp.entries, type: literal("button") }),
1496
1531
  object({ ...baseProp.entries, type: literal("verification") }),
1497
- object({ ...baseProp.entries, type: literal("last_visited_time") }),
1498
1532
  object({ ...baseProp.entries, type: literal("location") }),
1499
1533
  // Synthetic built-ins. The host always emits one of each per data source.
1500
1534
  object({ ...baseProp.entries, type: literal("created_time") }),
@@ -1574,18 +1608,6 @@ var customBlockContainsFilterOperatorSchema = union([
1574
1608
  emptyOperatorSchema
1575
1609
  ]);
1576
1610
 
1577
- // ../protocol/src/dataSources/filters/createdByFilterOperator.ts
1578
- var customBlockCreatorFilterValueSchema = strictObject({
1579
- object: literal("user"),
1580
- id: pipe(string(), minLength(1), maxLength(2e3))
1581
- });
1582
- var customBlockCreatedByFilterOperatorSchema = union([
1583
- strictObject({ contains: customBlockCreatorFilterValueSchema }),
1584
- strictObject({ does_not_contain: customBlockCreatorFilterValueSchema }),
1585
- strictObject({ is_empty: literal(true) }),
1586
- strictObject({ is_not_empty: literal(true) })
1587
- ]);
1588
-
1589
1611
  // ../protocol/src/dataSources/filters/dateFilterOperator.ts
1590
1612
  var dateTargetSchema = picklist(["start_date", "end_date"]);
1591
1613
  var customBlockRelativeDateValueSchema = picklist([
@@ -1681,7 +1703,7 @@ var customBlockOptionFilterOperatorSchema = union([
1681
1703
  // ../protocol/src/dataSources/filters/peopleFilterOperator.ts
1682
1704
  var customBlockPersonFilterValueSchema = strictObject({
1683
1705
  object: picklist(["user", "group"]),
1684
- id: pipe(string(), minLength(1))
1706
+ id: pipe(string(), minLength(1), maxLength(2e3))
1685
1707
  });
1686
1708
  var customBlockPeopleFilterOperatorSchema = union([
1687
1709
  strictObject({ contains: customBlockPersonFilterValueSchema }),
@@ -1744,15 +1766,34 @@ var customBlockTextFilterOperatorSchema = union([
1744
1766
  emptyOperatorSchema
1745
1767
  ]);
1746
1768
 
1769
+ // ../protocol/src/dataSources/filters/timestampFilterOperator.ts
1770
+ var customBlockTimestampFilterOperatorSchema = union(
1771
+ customBlockDateFilterOperatorSchema.options.map(
1772
+ (option) => omit(option, ["target"])
1773
+ )
1774
+ );
1775
+
1747
1776
  // ../protocol/src/dataSources/filters/bridgeDataSourceFilterCondition.ts
1748
1777
  var bridgeDataSourceFilterConditionSchema = union([
1778
+ strictObject({
1779
+ propertyId: string(),
1780
+ last_edited_by: customBlockPeopleFilterOperatorSchema
1781
+ }),
1782
+ strictObject({
1783
+ propertyId: string(),
1784
+ created_time: customBlockTimestampFilterOperatorSchema
1785
+ }),
1786
+ strictObject({
1787
+ propertyId: string(),
1788
+ last_edited_time: customBlockTimestampFilterOperatorSchema
1789
+ }),
1749
1790
  strictObject({
1750
1791
  propertyId: string(),
1751
1792
  relation: customBlockRelationFilterOperatorSchema
1752
1793
  }),
1753
1794
  strictObject({
1754
1795
  propertyId: string(),
1755
- created_by: customBlockCreatedByFilterOperatorSchema
1796
+ created_by: customBlockPeopleFilterOperatorSchema
1756
1797
  }),
1757
1798
  strictObject({
1758
1799
  propertyId: string(),
@@ -1837,11 +1878,10 @@ var bridgePageSchema = object({
1837
1878
  properties: bridgePagePropertyReadMapSchema,
1838
1879
  created_by: optional(metadataActorSchema, null),
1839
1880
  last_edited_by: optional(metadataActorSchema, null),
1840
- last_visited_time: optional(nullable(string()), null),
1841
1881
  created_time: optional(nullable(string()), null),
1842
1882
  last_edited_time: optional(nullable(string()), null),
1843
- icon: optional(nullable(notionPageIconSchema), null),
1844
- cover: optional(nullable(notionPageCoverSchema), null),
1883
+ icon: optional(nullable(bridgePageIconSchema), null),
1884
+ cover: optional(nullable(bridgePageCoverSchema), null),
1845
1885
  url: optional(nullable(string()), null),
1846
1886
  public_url: optional(nullable(string()), null),
1847
1887
  /** Whether the page or an ancestor is archived. */
@@ -1862,7 +1902,8 @@ var queryDataSourceMessageSchema = object({
1862
1902
  /** A sandbox-resolved property filter. */
1863
1903
  filter: optional(bridgeDataSourceFilterSchema),
1864
1904
  /** Sandbox-resolved property sorts, in priority order. */
1865
- sorts: optional(array(bridgeDataSourceSortSchema))
1905
+ sorts: optional(array(bridgeDataSourceSortSchema)),
1906
+ archive_status: optional(bridgeArchiveStatusSchema)
1866
1907
  });
1867
1908
  var customBlockQueryDataSourceErrorCodeSchema = string();
1868
1909
  var customBlockQueryDataSourceErrorInfoSchema = object({
@@ -1946,14 +1987,14 @@ var notionDataSourceSchema = object({
1946
1987
  inaccessible: optional(literal(true))
1947
1988
  });
1948
1989
 
1949
- // ../protocol/src/manifest/capabilities.ts
1950
- var customBlockCapabilityDeclarationSchema = object({
1951
- capability: string(),
1952
- resource: string()
1990
+ // ../protocol/src/manifest/grants.ts
1991
+ var customBlockGrantSchema = object({
1992
+ action: string(),
1993
+ resource: union([string(), pipe(array(string()), minLength(1))])
1953
1994
  });
1954
1995
 
1955
1996
  // ../protocol/src/manifest/manifest.ts
1956
- var manifestIconSchema = variant("type", [
1997
+ var bridgeManifestIconSchema = variant("type", [
1957
1998
  object({
1958
1999
  type: literal("emoji"),
1959
2000
  emoji: string()
@@ -1963,16 +2004,24 @@ var manifestIconSchema = variant("type", [
1963
2004
  url: string()
1964
2005
  })
1965
2006
  ]);
1966
- var manifestPropertySchema = object({
2007
+ var bridgeManifestPropertySchema = object({
1967
2008
  name: string(),
1968
2009
  description: optional(string()),
1969
2010
  type: notionPropertyTypeSchema
1970
2011
  });
1971
- var manifestDataSourceSchema = object({
2012
+ var manifestPageSchema = object({
2013
+ name: string(),
2014
+ description: optional(string()),
2015
+ icon: optional(bridgeManifestIconSchema)
2016
+ });
2017
+ var bridgeManifestDataSourceSchema = object({
1972
2018
  name: string(),
1973
2019
  description: optional(string()),
1974
- icon: optional(manifestIconSchema),
1975
- properties: optional(record(string(), manifestPropertySchema), {})
2020
+ icon: optional(bridgeManifestIconSchema),
2021
+ properties: optional(
2022
+ record(string(), bridgeManifestPropertySchema),
2023
+ {}
2024
+ )
1976
2025
  });
1977
2026
  var manifestSchema = object({
1978
2027
  version: literal(1),
@@ -1980,13 +2029,17 @@ var manifestSchema = object({
1980
2029
  description: optional(string()),
1981
2030
  slashCommand: optional(string()),
1982
2031
  icon: optional(object({ type: literal("emoji"), emoji: string() })),
1983
- dataSources: optional(record(string(), manifestDataSourceSchema), {}),
2032
+ dataSources: optional(
2033
+ record(string(), bridgeManifestDataSourceSchema),
2034
+ {}
2035
+ ),
2036
+ pages: optional(record(string(), manifestPageSchema)),
1984
2037
  /**
1985
- * Capabilities the block needs. Omitted means the block predates capability
1986
- * approval, so hosts do not ask the viewer. An empty array declares no
1987
- * capabilities.
2038
+ * Grants the block needs. Omitted means the block predates viewer
2039
+ * approval, so hosts do not ask the viewer. An empty array declares
2040
+ * nothing.
1988
2041
  */
1989
- capabilities: optional(array(customBlockCapabilityDeclarationSchema))
2042
+ grants: optional(array(customBlockGrantSchema))
1990
2043
  });
1991
2044
 
1992
2045
  // ../protocol/src/utils/errors.ts
@@ -2174,9 +2227,7 @@ var createPageParentSchema = variant("type", [
2174
2227
  pageParentSchema,
2175
2228
  dataSourceParentSchema
2176
2229
  ]);
2177
- var createPageMessageBaseSchema = {
2178
- type: literal("createPage"),
2179
- requestId: string(),
2230
+ var createPageBaseEntries = {
2180
2231
  /**
2181
2232
  * Property values, keyed by raw property IDs from Notion.
2182
2233
  *
@@ -2184,18 +2235,36 @@ var createPageMessageBaseSchema = {
2184
2235
  * To create a page with manifest-defined property keys, call `pages.create`. The SDK resolves
2185
2236
  * those keys before it sends this message.
2186
2237
  */
2187
- properties: bridgePagePropertyWriteMapSchema
2238
+ properties: bridgePagePropertyWriteMapSchema,
2239
+ icon: optional(bridgePageIconSchema),
2240
+ cover: optional(bridgePageCoverSchema)
2241
+ };
2242
+ var createPageUnderPageArgsSchema = object({
2243
+ ...createPageBaseEntries,
2244
+ parent: pageParentSchema,
2245
+ position: optional(notionCreatePagePositionSchema)
2246
+ });
2247
+ var createPageUnderDataSourceArgsSchema = object({
2248
+ ...createPageBaseEntries,
2249
+ parent: dataSourceParentSchema,
2250
+ position: optional(never())
2251
+ });
2252
+ var createPageArgsSchema = union([
2253
+ createPageUnderPageArgsSchema,
2254
+ createPageUnderDataSourceArgsSchema
2255
+ ]);
2256
+ var createPageMessageEntries = {
2257
+ type: literal("createPage"),
2258
+ requestId: string()
2188
2259
  };
2189
2260
  var createPageMessageSchema = variant("type", [
2190
2261
  object({
2191
- ...createPageMessageBaseSchema,
2192
- parent: pageParentSchema,
2193
- position: optional(notionCreatePagePositionSchema)
2262
+ ...createPageMessageEntries,
2263
+ ...createPageUnderPageArgsSchema.entries
2194
2264
  }),
2195
2265
  object({
2196
- ...createPageMessageBaseSchema,
2197
- parent: dataSourceParentSchema,
2198
- position: optional(never())
2266
+ ...createPageMessageEntries,
2267
+ ...createPageUnderDataSourceArgsSchema.entries
2199
2268
  })
2200
2269
  ]);
2201
2270
 
@@ -2318,8 +2387,8 @@ var updatePageMessageSchema = object({
2318
2387
  * by `useDataSource()`. The SDK resolves those keys before it sends this message.
2319
2388
  */
2320
2389
  properties: optional(bridgePagePropertyWriteMapSchema),
2321
- icon: optional(notionPageIconSchema),
2322
- cover: optional(notionPageCoverSchema),
2390
+ icon: optional(bridgePageIconSchema),
2391
+ cover: optional(bridgePageCoverSchema),
2323
2392
  archived: optional(boolean())
2324
2393
  });
2325
2394
 
@@ -2397,6 +2466,8 @@ var listUsersResultMessageSchema = variant("status", [
2397
2466
  // ../protocol/src/messages/invalidSandboxMessage.ts
2398
2467
  var invalidSandboxMessageSchema = object({
2399
2468
  type: literal("invalidSandboxMessage"),
2469
+ /** Identifies the rejected request or response, when readable. */
2470
+ requestId: optional(string()),
2400
2471
  /**
2401
2472
  * A human-readable string intended for sandbox-side logging. It has no structured contract.
2402
2473
  */
@@ -2436,6 +2507,8 @@ var hostToSandboxMessageWithProtocol3To5CompatibilitySchema = variant("type", [
2436
2507
  // ../protocol/src/messages/invalidHostMessage.ts
2437
2508
  var invalidHostMessageSchema = object({
2438
2509
  type: literal("invalidHostMessage"),
2510
+ /** Identifies the rejected request or response, when readable. */
2511
+ requestId: optional(string()),
2439
2512
  /**
2440
2513
  * A human-readable string intended for sandbox-side logging. It has no structured contract.
2441
2514
  */
@@ -2459,6 +2532,9 @@ var sandboxToHostMessageSchema = variant("type", [
2459
2532
  invalidHostMessageSchema
2460
2533
  ]);
2461
2534
 
2535
+ // ../protocol/src/utils/readRequestId.ts
2536
+ var requestIdentitySchema = object({ requestId: string() });
2537
+
2462
2538
  // cli/diagnostics/formatUnknownError.ts
2463
2539
  function formatUnknownError(error) {
2464
2540
  return error instanceof Error ? error.message : String(error);
@@ -6504,15 +6580,11 @@ function convertPublicApiPropertyValue(publicType, value) {
6504
6580
  const uniqueId = payload;
6505
6581
  return uniqueId.prefix ? `${uniqueId.prefix}-${uniqueId.number}` : String(uniqueId.number);
6506
6582
  }
6507
- // The production host still serializes formula, rollup, and
6508
- // last_visited_time as plain text. Match it so fixtures predict what a
6509
- // block receives from the real host.
6583
+ // Match the production host’s text serialization for formula and rollup.
6510
6584
  case "formula":
6511
6585
  return formulaToText(payload);
6512
6586
  case "rollup":
6513
6587
  return rollupToText(payload);
6514
- case "last_visited_time":
6515
- return payload;
6516
6588
  case "created_time":
6517
6589
  case "last_edited_time":
6518
6590
  return timestampToLocal(payload);
@@ -6636,8 +6708,7 @@ var VALUE_SCHEMAS = {
6636
6708
  rollup: stringValue,
6637
6709
  verification: stringValue,
6638
6710
  place: stringValue,
6639
- location: stringValue,
6640
- last_visited_time: stringValue
6711
+ location: stringValue
6641
6712
  };
6642
6713
  function matchesPropertyType(value, type) {
6643
6714
  return is(VALUE_SCHEMAS[type] ?? anyLocalValue, value);
@@ -7385,6 +7456,16 @@ function createDevShellDataService(options) {
7385
7456
  import { existsSync as existsSync4, mkdirSync as mkdirSync3, writeFileSync } from "node:fs";
7386
7457
  import { resolve as resolve3 } from "node:path";
7387
7458
 
7459
+ // shared/blocks/formatBlockValidationIssues.ts
7460
+ function formatBlockValidationIssues(blockKey, issues, pathPrefix) {
7461
+ const details = issues.map((issue) => {
7462
+ const path = [pathPrefix, getDotPath(issue)].filter(Boolean).join(".");
7463
+ return `${path}: ${issue.message}`;
7464
+ });
7465
+ return `Block "${blockKey}" has an invalid declaration:
7466
+ ${details.join("\n")}`;
7467
+ }
7468
+
7388
7469
  // cli/workers/blockCapabilities.ts
7389
7470
  var workerBlockCapabilitySchema = object({
7390
7471
  _tag: literal("custom_block"),
@@ -7400,7 +7481,16 @@ var workerBlockCapabilitySchema = object({
7400
7481
  })
7401
7482
  });
7402
7483
  function blockCapabilities(manifest) {
7403
- return manifest.capabilities.filter((capability) => capability._tag === "custom_block").map((capability) => parse(workerBlockCapabilitySchema, capability));
7484
+ return manifest.capabilities.filter((capability) => capability._tag === "custom_block").map((capability) => {
7485
+ const parsed = safeParse(workerBlockCapabilitySchema, capability);
7486
+ if (!parsed.success) {
7487
+ const error = new ValiError(parsed.issues);
7488
+ error.message = `${formatBlockValidationIssues(capability.key, parsed.issues, "")}
7489
+ Fix the custom block declaration, then restart the dev shell to rebuild the manifest.`;
7490
+ throw error;
7491
+ }
7492
+ return parsed.output;
7493
+ });
7404
7494
  }
7405
7495
 
7406
7496
  // cli/dataSources/materializeWorkerSchemaDataSources.ts
@@ -7804,6 +7894,61 @@ var SharedServer = class {
7804
7894
  }
7805
7895
  };
7806
7896
 
7897
+ // cli/server/waitForPreviewUrls.ts
7898
+ import { request } from "node:http";
7899
+ import { setTimeout as delay } from "node:timers/promises";
7900
+ async function waitForPreviewUrls(urls, signal, timeoutMs = 1e4) {
7901
+ const deadline = new AbortController();
7902
+ const timer = setTimeout(() => deadline.abort(), timeoutMs);
7903
+ const bounded = AbortSignal.any([signal, deadline.signal]);
7904
+ const pending = new Set(urls);
7905
+ try {
7906
+ while (pending.size > 0) {
7907
+ bounded.throwIfAborted();
7908
+ await Promise.all(
7909
+ [...pending].map(async (url) => {
7910
+ if (await respondsSuccessfully(new URL(url), bounded)) {
7911
+ pending.delete(url);
7912
+ }
7913
+ })
7914
+ );
7915
+ if (pending.size > 0) {
7916
+ await delay(100, void 0, { signal: bounded });
7917
+ }
7918
+ }
7919
+ bounded.throwIfAborted();
7920
+ } catch (error) {
7921
+ if (deadline.signal.aborted && !signal.aborted) {
7922
+ throw new Error(
7923
+ `Preview readiness timed out after ${timeoutMs}ms. No successful HTTP response from: ${[...pending].join(", ")}.`
7924
+ );
7925
+ }
7926
+ throw error;
7927
+ } finally {
7928
+ clearTimeout(timer);
7929
+ }
7930
+ }
7931
+ function respondsSuccessfully(url, signal) {
7932
+ return new Promise((resolve10) => {
7933
+ const probe = request(
7934
+ {
7935
+ hostname: "127.0.0.1",
7936
+ port: url.port,
7937
+ path: `${url.pathname}${url.search}`,
7938
+ headers: { Host: url.host },
7939
+ signal
7940
+ },
7941
+ (response) => {
7942
+ const status = response.statusCode ?? 0;
7943
+ response.destroy();
7944
+ resolve10(status >= 200 && status < 300);
7945
+ }
7946
+ );
7947
+ probe.on("error", () => resolve10(false));
7948
+ probe.end();
7949
+ });
7950
+ }
7951
+
7807
7952
  // cli/server/writeBlockViteConfig.ts
7808
7953
  import { existsSync as existsSync5, mkdirSync as mkdirSync4, writeFileSync as writeFileSync2 } from "node:fs";
7809
7954
  import { relative, resolve as resolve4 } from "node:path";
@@ -7952,6 +8097,7 @@ function buildBlockRegistry(blocks, port = DEFAULT_DEV_SHELL_PORT) {
7952
8097
  }
7953
8098
  used.add(hostname);
7954
8099
  return {
8100
+ status: "ready",
7955
8101
  key: capability.key,
7956
8102
  manifest: capability.config.manifest,
7957
8103
  name: capability.key,
@@ -8286,6 +8432,8 @@ async function launchDevShell(options) {
8286
8432
  if (installSignalHandlers) {
8287
8433
  installProcessSignalHandlers(run);
8288
8434
  }
8435
+ const readiness = new AbortController();
8436
+ run.addResource(() => readiness.abort());
8289
8437
  try {
8290
8438
  const writeReady = configureStartupOutput(options.argv.includes("--json"));
8291
8439
  const args = parseWorkerLaunchArgs(options.argv);
@@ -8351,16 +8499,28 @@ async function launchDevShell(options) {
8351
8499
  if (run.closing) {
8352
8500
  return;
8353
8501
  }
8354
- writeReady?.({
8355
- event: "ready",
8356
- shellUrl: `http://localhost:${args.shellPort}`,
8357
- workerDir,
8358
- devShellVersion: options.devShellVersion,
8359
- customBlocks: describeStartupCustomBlocks(
8360
- plan,
8361
- dataService.getSnapshot().dataSources
8362
- )
8363
- });
8502
+ if (writeReady) {
8503
+ await waitForPreviewUrls(
8504
+ [
8505
+ `http://localhost:${args.shellPort}`,
8506
+ ...plan.registry.map((block) => block.url)
8507
+ ],
8508
+ readiness.signal
8509
+ );
8510
+ if (run.closing) {
8511
+ return;
8512
+ }
8513
+ writeReady({
8514
+ event: "ready",
8515
+ shellUrl: `http://localhost:${args.shellPort}`,
8516
+ workerDir,
8517
+ devShellVersion: options.devShellVersion,
8518
+ customBlocks: describeStartupCustomBlocks(
8519
+ plan,
8520
+ dataService.getSnapshot().dataSources
8521
+ )
8522
+ });
8523
+ }
8364
8524
  printSummary(args, plan.registry);
8365
8525
  } catch (error) {
8366
8526
  if (run.closing) {