@pstdio/sdk 0.22.1 → 0.24.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/README.md CHANGED
@@ -32,6 +32,32 @@ Page targets change location. Panel targets preserve it. Compound targets contai
32
32
 
33
33
  Use `qualifyRef(owner, ref)` in provider contract modules. Keep definitions local and pass qualified refs between extensions. For webviews, declare capabilities and call the typed `GuestHost`; `placement.close` closes the calling placement through the normal tab controller.
34
34
 
35
+ ## Dashboard URLs
36
+
37
+ Use `serializePageUrl({ projectId, page, resource })` to return a dashboard link from a command. The page descriptor contains its `id`, qualified `ref`, and declared `path`; `resource` is optional. The workbench uses the same route and resource codec.
38
+
39
+ Use `parsePageUrl({ url, projectId, pages })` to resolve a saved link against the expected project and allowed page descriptors. It accepts root-relative URLs and returns a page ID and optional resource, or `undefined` for an unsupported destination. It never fetches the URL. The caller still checks its supported resource kind and owner. A URL grants no access.
40
+
41
+ Page and panel navigation targets remain the API for opening views and tabs.
42
+
43
+ ## Webview change subscriptions
44
+
45
+ Use the typed client's `events.subscribe(event, listener)` to refetch after a command changes data:
46
+
47
+ ```ts
48
+ const client = createWebviewClient<typeof commands>(host);
49
+ const stop = client.events.subscribe(
50
+ { kind: "event", id: "notes.changed" },
51
+ () => void reloadNotes(),
52
+ );
53
+ // Dispose when the view unmounts.
54
+ stop();
55
+ ```
56
+
57
+ Local event refs use the client's extension owner: `{ kind: "event", id: "notes.changed" }` resolves to `<extensionId>.event.notes.changed`. Qualified event refs can name another extension in the same project. String IDs are already resolved and stay unchanged. Host-owned and command-lifecycle refs follow the runtime's rules through the shared `resolveEventReferenceId` helper. Commands emit events after committing their changes through `ctx.events.emit`.
58
+
59
+ The host delivers only events matching the view's project. Projectless events reach global views only. Listeners also run when host sync connects or reconnects, so a mounted view can reconcile missed changes. Load current data when mounting, then subscribe; events are invalidations, not stored records or an exactly-once stream. Duplicate refetches must be safe. The subscription does not reload the webview document or grant new permissions.
60
+
35
61
  ## Package delivery
36
62
 
37
63
  Development and installed consumers both load built SDK entries. Repository development builds this package before starting the source CLI. Builds stage release files under `.publish` through the shared release script. Package verification installs those same staged artifacts into a temporary directory outside the monorepo and checks every entry point.
package/dist/api/index.js CHANGED
@@ -13909,6 +13909,7 @@ var listExtensionConnectionsResponseSchema = exports_external.object({
13909
13909
 
13910
13910
  // ../pstdio-api-contracts/src/extensions/execute.ts
13911
13911
  var extensionResourceRefSchema = exports_external.object({
13912
+ shorthand: exports_external.string().optional(),
13912
13913
  type: exports_external.string(),
13913
13914
  id: exports_external.string(),
13914
13915
  projectId: exports_external.string().optional(),
@@ -15458,9 +15459,11 @@ var resolveSessionIdResponseSchema = exports_external.object({
15458
15459
  });
15459
15460
  // ../pstdio-api-contracts/src/settings.ts
15460
15461
  var settingsSchema = exports_external.object({
15462
+ notifications_enabled: exports_external.boolean(),
15461
15463
  max_concurrent_sessions: exports_external.number().int().min(1).nullable()
15462
15464
  });
15463
15465
  var updateSettingsInputSchema = exports_external.object({
15466
+ notifications_enabled: exports_external.boolean().optional(),
15464
15467
  max_concurrent_sessions: exports_external.number().int().min(1).nullable().optional()
15465
15468
  }).strict().refine((value) => Object.keys(value).length > 0, { message: "Expected at least one setting" });
15466
15469
  // ../pstdio-api-contracts/src/skills.ts
package/dist/api.d.ts CHANGED
@@ -93,6 +93,7 @@ declare const commandExecuteRequestSchema: z.ZodObject<{
93
93
  workspaceId: z.ZodOptional<z.ZodString>;
94
94
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
95
95
  resource: z.ZodOptional<z.ZodObject<{
96
+ shorthand: z.ZodOptional<z.ZodString>;
96
97
  type: z.ZodString;
97
98
  id: z.ZodString;
98
99
  projectId: z.ZodOptional<z.ZodString>;
@@ -120,6 +121,7 @@ declare const commandExecuteRequestSchema: z.ZodObject<{
120
121
  mode: z.ZodOptional<z.ZodString>;
121
122
  projectId: z.ZodOptional<z.ZodString>;
122
123
  resource: z.ZodOptional<z.ZodObject<{
124
+ shorthand: z.ZodOptional<z.ZodString>;
123
125
  type: z.ZodString;
124
126
  id: z.ZodString;
125
127
  projectId: z.ZodOptional<z.ZodString>;
@@ -247,6 +249,7 @@ declare const createAutomationRunInputSchema: z.ZodObject<{
247
249
  workspaceId: z.ZodOptional<z.ZodString>;
248
250
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
249
251
  resource: z.ZodOptional<z.ZodObject<{
252
+ shorthand: z.ZodOptional<z.ZodString>;
250
253
  type: z.ZodString;
251
254
  id: z.ZodString;
252
255
  projectId: z.ZodOptional<z.ZodString>;
@@ -290,6 +293,7 @@ declare const createSessionInputSchema: z.ZodObject<{
290
293
  agent: z.ZodOptional<z.ZodString>;
291
294
  workspace_id: z.ZodOptional<z.ZodString>;
292
295
  anchors: z.ZodOptional<z.ZodArray<z.ZodObject<{
296
+ shorthand: z.ZodOptional<z.ZodString>;
293
297
  type: z.ZodString;
294
298
  id: z.ZodString;
295
299
  projectId: z.ZodOptional<z.ZodString>;
@@ -448,6 +452,7 @@ declare const extensionKeybindingRecordSchema: z.ZodObject<{
448
452
  id: z.ZodString;
449
453
  }, z.core.$strip>]>;
450
454
  resource: z.ZodOptional<z.ZodObject<{
455
+ shorthand: z.ZodOptional<z.ZodString>;
451
456
  type: z.ZodString;
452
457
  id: z.ZodString;
453
458
  projectId: z.ZodOptional<z.ZodString>;
@@ -491,6 +496,7 @@ declare const extensionKeybindingRecordSchema: z.ZodObject<{
491
496
  id: z.ZodString;
492
497
  }, z.core.$strip>]>;
493
498
  resource: z.ZodOptional<z.ZodObject<{
499
+ shorthand: z.ZodOptional<z.ZodString>;
494
500
  type: z.ZodString;
495
501
  id: z.ZodString;
496
502
  projectId: z.ZodOptional<z.ZodString>;
@@ -597,6 +603,7 @@ declare const extensionRecordSchema: z.ZodObject<{
597
603
  }, z.core.$strip>;
598
604
 
599
605
  declare const extensionResourceRefSchema: z.ZodObject<{
606
+ shorthand: z.ZodOptional<z.ZodString>;
600
607
  type: z.ZodString;
601
608
  id: z.ZodString;
602
609
  projectId: z.ZodOptional<z.ZodString>;
@@ -1318,6 +1325,7 @@ declare const resolveSessionIdResponseSchema: z.ZodObject<{
1318
1325
  export declare interface ResourceRef {
1319
1326
  type: string;
1320
1327
  id: string;
1328
+ shorthand?: string;
1321
1329
  projectId?: string;
1322
1330
  label?: string;
1323
1331
  icon?: string;
@@ -1423,6 +1431,7 @@ declare const sessionConversationResponseSchema: z.ZodObject<{
1423
1431
  cwd: z.ZodNullable<z.ZodString>;
1424
1432
  params_json: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>>;
1425
1433
  anchors_json: z.ZodArray<z.ZodObject<{
1434
+ shorthand: z.ZodOptional<z.ZodString>;
1426
1435
  type: z.ZodString;
1427
1436
  id: z.ZodString;
1428
1437
  projectId: z.ZodOptional<z.ZodString>;
@@ -1440,6 +1449,7 @@ declare const sessionConversationResponseSchema: z.ZodObject<{
1440
1449
  export declare type Settings = z.infer<typeof settingsSchema>;
1441
1450
 
1442
1451
  declare const settingsSchema: z.ZodObject<{
1452
+ notifications_enabled: z.ZodBoolean;
1443
1453
  max_concurrent_sessions: z.ZodNullable<z.ZodNumber>;
1444
1454
  }, z.core.$strip>;
1445
1455
 
@@ -1513,6 +1523,7 @@ export declare interface UpdateNotificationInput {
1513
1523
  export declare type UpdateSettingsInput = z.infer<typeof updateSettingsInputSchema>;
1514
1524
 
1515
1525
  declare const updateSettingsInputSchema: z.ZodObject<{
1526
+ notifications_enabled: z.ZodOptional<z.ZodBoolean>;
1516
1527
  max_concurrent_sessions: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
1517
1528
  }, z.core.$strict>;
1518
1529
 
@@ -1855,6 +1866,7 @@ declare const workbenchExtensionMetadataSchema: z.ZodObject<{
1855
1866
  id: z.ZodString;
1856
1867
  }, z.core.$strip>]>;
1857
1868
  resource: z.ZodOptional<z.ZodObject<{
1869
+ shorthand: z.ZodOptional<z.ZodString>;
1858
1870
  type: z.ZodString;
1859
1871
  id: z.ZodString;
1860
1872
  projectId: z.ZodOptional<z.ZodString>;
@@ -1898,6 +1910,7 @@ declare const workbenchExtensionMetadataSchema: z.ZodObject<{
1898
1910
  id: z.ZodString;
1899
1911
  }, z.core.$strip>]>;
1900
1912
  resource: z.ZodOptional<z.ZodObject<{
1913
+ shorthand: z.ZodOptional<z.ZodString>;
1901
1914
  type: z.ZodString;
1902
1915
  id: z.ZodString;
1903
1916
  projectId: z.ZodOptional<z.ZodString>;
@@ -2369,6 +2382,7 @@ declare const workbenchExtensionMetadataSchema: z.ZodObject<{
2369
2382
  id: z.ZodString;
2370
2383
  }, z.core.$strip>]>;
2371
2384
  resource: z.ZodOptional<z.ZodObject<{
2385
+ shorthand: z.ZodOptional<z.ZodString>;
2372
2386
  type: z.ZodString;
2373
2387
  id: z.ZodString;
2374
2388
  projectId: z.ZodOptional<z.ZodString>;
@@ -2412,6 +2426,7 @@ declare const workbenchExtensionMetadataSchema: z.ZodObject<{
2412
2426
  id: z.ZodString;
2413
2427
  }, z.core.$strip>]>;
2414
2428
  resource: z.ZodOptional<z.ZodObject<{
2429
+ shorthand: z.ZodOptional<z.ZodString>;
2415
2430
  type: z.ZodString;
2416
2431
  id: z.ZodString;
2417
2432
  projectId: z.ZodOptional<z.ZodString>;
@@ -2550,6 +2565,7 @@ declare const workbenchExtensionMetadataSchema: z.ZodObject<{
2550
2565
  id: z.ZodString;
2551
2566
  }, z.core.$strip>]>;
2552
2567
  resource: z.ZodOptional<z.ZodObject<{
2568
+ shorthand: z.ZodOptional<z.ZodString>;
2553
2569
  type: z.ZodString;
2554
2570
  id: z.ZodString;
2555
2571
  projectId: z.ZodOptional<z.ZodString>;
@@ -2593,6 +2609,7 @@ declare const workbenchExtensionMetadataSchema: z.ZodObject<{
2593
2609
  id: z.ZodString;
2594
2610
  }, z.core.$strip>]>;
2595
2611
  resource: z.ZodOptional<z.ZodObject<{
2612
+ shorthand: z.ZodOptional<z.ZodString>;
2596
2613
  type: z.ZodString;
2597
2614
  id: z.ZodString;
2598
2615
  projectId: z.ZodOptional<z.ZodString>;
@@ -2783,6 +2800,7 @@ declare const workbenchExtensionMetadataSchema: z.ZodObject<{
2783
2800
  id: z.ZodString;
2784
2801
  }, z.core.$strip>]>;
2785
2802
  resource: z.ZodOptional<z.ZodObject<{
2803
+ shorthand: z.ZodOptional<z.ZodString>;
2786
2804
  type: z.ZodString;
2787
2805
  id: z.ZodString;
2788
2806
  projectId: z.ZodOptional<z.ZodString>;
@@ -2826,6 +2844,7 @@ declare const workbenchExtensionMetadataSchema: z.ZodObject<{
2826
2844
  id: z.ZodString;
2827
2845
  }, z.core.$strip>]>;
2828
2846
  resource: z.ZodOptional<z.ZodObject<{
2847
+ shorthand: z.ZodOptional<z.ZodString>;
2829
2848
  type: z.ZodString;
2830
2849
  id: z.ZodString;
2831
2850
  projectId: z.ZodOptional<z.ZodString>;
@@ -499,21 +499,26 @@ var createSyncClient = (clientOptions) => ({
499
499
  if (event === "init")
500
500
  setConnected();
501
501
  };
502
+ const readConnection = async (signal) => {
503
+ const response = await resolveFetch(clientOptions)(resolveClientUrl(resolveBaseUrl(clientOptions), buildSyncStreamPath(lastSeq)), {
504
+ headers: Object.fromEntries(createRequestHeaders(clientOptions).entries()),
505
+ signal,
506
+ credentials: "same-origin"
507
+ });
508
+ if (!response.ok || !response.body)
509
+ throw new Error("SSE connection failed");
510
+ if (closed)
511
+ return;
512
+ if (lastSeq > 0)
513
+ setConnected();
514
+ await readSseStream(response.body, ({ event, data }) => handleEvent(event, data), { signal });
515
+ };
502
516
  const connect = async () => {
503
517
  if (closed)
504
518
  return;
505
519
  abortController = new AbortController;
506
520
  try {
507
- const response = await resolveFetch(clientOptions)(resolveClientUrl(resolveBaseUrl(clientOptions), buildSyncStreamPath(lastSeq)), {
508
- headers: Object.fromEntries(createRequestHeaders(clientOptions).entries()),
509
- signal: abortController.signal,
510
- credentials: "same-origin"
511
- });
512
- if (!response.ok || !response.body)
513
- throw new Error("SSE connection failed");
514
- await readSseStream(response.body, ({ event, data }) => handleEvent(event, data), {
515
- signal: abortController.signal
516
- });
521
+ await readConnection(abortController.signal);
517
522
  } catch (err) {
518
523
  if (closed || err.name === "AbortError")
519
524
  return;
package/dist/client.d.ts CHANGED
@@ -157,6 +157,7 @@ declare const commandExecuteRequestSchema: z.ZodObject<{
157
157
  workspaceId: z.ZodOptional<z.ZodString>;
158
158
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
159
159
  resource: z.ZodOptional<z.ZodObject<{
160
+ shorthand: z.ZodOptional<z.ZodString>;
160
161
  type: z.ZodString;
161
162
  id: z.ZodString;
162
163
  projectId: z.ZodOptional<z.ZodString>;
@@ -184,6 +185,7 @@ declare const commandExecuteRequestSchema: z.ZodObject<{
184
185
  mode: z.ZodOptional<z.ZodString>;
185
186
  projectId: z.ZodOptional<z.ZodString>;
186
187
  resource: z.ZodOptional<z.ZodObject<{
188
+ shorthand: z.ZodOptional<z.ZodString>;
187
189
  type: z.ZodString;
188
190
  id: z.ZodString;
189
191
  projectId: z.ZodOptional<z.ZodString>;
@@ -311,6 +313,7 @@ declare const createAutomationRunInputSchema: z.ZodObject<{
311
313
  workspaceId: z.ZodOptional<z.ZodString>;
312
314
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
313
315
  resource: z.ZodOptional<z.ZodObject<{
316
+ shorthand: z.ZodOptional<z.ZodString>;
314
317
  type: z.ZodString;
315
318
  id: z.ZodString;
316
319
  projectId: z.ZodOptional<z.ZodString>;
@@ -360,6 +363,7 @@ declare const createSessionInputSchema: z.ZodObject<{
360
363
  agent: z.ZodOptional<z.ZodString>;
361
364
  workspace_id: z.ZodOptional<z.ZodString>;
362
365
  anchors: z.ZodOptional<z.ZodArray<z.ZodObject<{
366
+ shorthand: z.ZodOptional<z.ZodString>;
363
367
  type: z.ZodString;
364
368
  id: z.ZodString;
365
369
  projectId: z.ZodOptional<z.ZodString>;
@@ -519,6 +523,7 @@ declare const followUpResponseSchema: z.ZodObject<{
519
523
  cwd: z.ZodNullable<z.ZodString>;
520
524
  params_json: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>>;
521
525
  anchors_json: z.ZodArray<z.ZodObject<{
526
+ shorthand: z.ZodOptional<z.ZodString>;
522
527
  type: z.ZodString;
523
528
  id: z.ZodString;
524
529
  projectId: z.ZodOptional<z.ZodString>;
@@ -1193,6 +1198,7 @@ declare const resolveSessionIdResponseSchema: z.ZodObject<{
1193
1198
  declare interface ResourceRef {
1194
1199
  type: string;
1195
1200
  id: string;
1201
+ shorthand?: string;
1196
1202
  projectId?: string;
1197
1203
  label?: string;
1198
1204
  icon?: string;
@@ -1271,6 +1277,7 @@ declare const sessionConversationResponseSchema: z.ZodObject<{
1271
1277
  cwd: z.ZodNullable<z.ZodString>;
1272
1278
  params_json: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>>;
1273
1279
  anchors_json: z.ZodArray<z.ZodObject<{
1280
+ shorthand: z.ZodOptional<z.ZodString>;
1274
1281
  type: z.ZodString;
1275
1282
  id: z.ZodString;
1276
1283
  projectId: z.ZodOptional<z.ZodString>;
@@ -1309,6 +1316,7 @@ declare const sessionSchema: z.ZodObject<{
1309
1316
  cwd: z.ZodNullable<z.ZodString>;
1310
1317
  params_json: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>>;
1311
1318
  anchors_json: z.ZodArray<z.ZodObject<{
1319
+ shorthand: z.ZodOptional<z.ZodString>;
1312
1320
  type: z.ZodString;
1313
1321
  id: z.ZodString;
1314
1322
  projectId: z.ZodOptional<z.ZodString>;
@@ -1341,6 +1349,7 @@ export declare type SettingsClient = {
1341
1349
  };
1342
1350
 
1343
1351
  declare const settingsSchema: z.ZodObject<{
1352
+ notifications_enabled: z.ZodBoolean;
1344
1353
  max_concurrent_sessions: z.ZodNullable<z.ZodNumber>;
1345
1354
  }, z.core.$strip>;
1346
1355
 
@@ -1432,6 +1441,7 @@ export declare type SseEvent = {
1432
1441
  };
1433
1442
 
1434
1443
  export declare type StartSyncInput = SyncWriterProvider & {
1444
+ /** Called after the initial snapshot, or when a cursor-based connection resumes. */
1435
1445
  onConnected?: () => void;
1436
1446
  onDisconnected?: () => void;
1437
1447
  onConnectionLost?: () => void;
@@ -1475,6 +1485,7 @@ declare interface UpdateNotificationInput {
1475
1485
  declare type UpdateSettingsInput = z.infer<typeof updateSettingsInputSchema>;
1476
1486
 
1477
1487
  declare const updateSettingsInputSchema: z.ZodObject<{
1488
+ notifications_enabled: z.ZodOptional<z.ZodBoolean>;
1478
1489
  max_concurrent_sessions: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
1479
1490
  }, z.core.$strict>;
1480
1491
 
@@ -1640,6 +1651,7 @@ declare const workspaceListItemSchema: z.ZodObject<{
1640
1651
  workspace_shorthand: z.ZodString;
1641
1652
  startup_log_file_id: z.ZodNullable<z.ZodString>;
1642
1653
  anchors_json: z.ZodArray<z.ZodObject<{
1654
+ shorthand: z.ZodOptional<z.ZodString>;
1643
1655
  type: z.ZodString;
1644
1656
  id: z.ZodString;
1645
1657
  projectId: z.ZodOptional<z.ZodString>;
@@ -1692,6 +1704,7 @@ declare const workspaceSchema: z.ZodObject<{
1692
1704
  workspace_shorthand: z.ZodString;
1693
1705
  startup_log_file_id: z.ZodNullable<z.ZodString>;
1694
1706
  anchors_json: z.ZodArray<z.ZodObject<{
1707
+ shorthand: z.ZodOptional<z.ZodString>;
1695
1708
  type: z.ZodString;
1696
1709
  id: z.ZodString;
1697
1710
  projectId: z.ZodOptional<z.ZodString>;
@@ -0,0 +1,115 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __returnValue = (v) => v;
3
+ function __exportSetter(name, newValue) {
4
+ this[name] = __returnValue.bind(null, newValue);
5
+ }
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true,
11
+ configurable: true,
12
+ set: __exportSetter.bind(all, name)
13
+ });
14
+ };
15
+
16
+ // src/data/draft-layout.ts
17
+ var assertSafePathSegment = (value) => {
18
+ if (!value || value === "." || value === ".." || /[/\\\0]/.test(value))
19
+ throw new Error(`Unsafe path segment: ${value}`);
20
+ };
21
+ var requireRepoFiles = (repoFiles) => {
22
+ if (!repoFiles)
23
+ throw new Error("This command must be run inside a project repository.");
24
+ return repoFiles;
25
+ };
26
+ var createDraftLayout = (root, document) => {
27
+ const directory = (name) => {
28
+ assertSafePathSegment(name);
29
+ return `${root}/${name}`;
30
+ };
31
+ return {
32
+ directory,
33
+ markdown: (name, suffix = "") => `${directory(name)}/${document}${suffix}.md`,
34
+ files: (name, suffix = "") => `${directory(name)}/files${suffix}`
35
+ };
36
+ };
37
+ // src/data/frontmatter.ts
38
+ var escapeYamlScalar = (value) => value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n");
39
+ var quoteYamlScalar = (value) => `"${escapeYamlScalar(value)}"`;
40
+ var findClosingFrontmatterDelimiter = (content) => {
41
+ const match = /\n---[ \t]*(?:\r?\n|$)/.exec(content.slice(3));
42
+ if (!match)
43
+ return null;
44
+ const start = 3 + match.index + 1;
45
+ const end = 3 + match.index + match[0].length;
46
+ return { end, start };
47
+ };
48
+ var stripFrontmatter = (content) => {
49
+ if (!content.startsWith("---"))
50
+ return content;
51
+ const delimiter = findClosingFrontmatterDelimiter(content);
52
+ if (!delimiter)
53
+ return content;
54
+ return content.slice(delimiter.end);
55
+ };
56
+ var applyFrontmatter = (frontmatter, content) => {
57
+ const body = stripFrontmatter(content).replace(/^\n+/, "");
58
+ if (!body)
59
+ return frontmatter;
60
+ return `${frontmatter}
61
+
62
+ ${body}`;
63
+ };
64
+ var unescapeYamlScalar = (value) => {
65
+ let result = "";
66
+ for (let index = 0;index < value.length; index++) {
67
+ const current = value[index];
68
+ const next = value[index + 1];
69
+ if (current !== "\\" || next === undefined) {
70
+ result += current;
71
+ continue;
72
+ }
73
+ if (next === "n")
74
+ result += `
75
+ `;
76
+ else if (next === '"')
77
+ result += '"';
78
+ else if (next === "\\")
79
+ result += "\\";
80
+ else
81
+ result += `${current}${next}`;
82
+ index++;
83
+ }
84
+ return result;
85
+ };
86
+ var unquoteYamlScalar = (value) => {
87
+ const quoted = value.match(/^(["'])(.*)\1$/);
88
+ return quoted ? unescapeYamlScalar(quoted[2] ?? "") : value;
89
+ };
90
+ // src/data/resolve.ts
91
+ var sameName = (a, b) => a.trim().toLowerCase() === b.trim().toLowerCase();
92
+ var resolveByIdOrName = (items, value, nameOf, label) => {
93
+ const byId = items.find((item) => item.id === value);
94
+ if (byId)
95
+ return byId.id;
96
+ const byName = items.filter((item) => sameName(nameOf(item), value));
97
+ if (byName.length > 1)
98
+ throw new Error(`Ambiguous ${label} "${value}"`);
99
+ const [match] = byName;
100
+ if (match)
101
+ return match.id;
102
+ throw new Error(`Unknown ${label} "${value}"`);
103
+ };
104
+ export {
105
+ unquoteYamlScalar,
106
+ stripFrontmatter,
107
+ sameName,
108
+ resolveByIdOrName,
109
+ requireRepoFiles,
110
+ quoteYamlScalar,
111
+ findClosingFrontmatterDelimiter,
112
+ createDraftLayout,
113
+ assertSafePathSegment,
114
+ applyFrontmatter
115
+ };
package/dist/data.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ export declare const applyFrontmatter: (frontmatter: string, content: string) => string;
2
+
3
+ declare interface ArtifactFile {
4
+ path: string;
5
+ size?: number;
6
+ updatedAt?: string;
7
+ }
8
+
9
+ declare interface ArtifactMount {
10
+ exists(path: string): Promise<boolean>;
11
+ readText(path: string): Promise<string>;
12
+ writeText(path: string, value: string): Promise<void>;
13
+ readBytes(path: string): Promise<Uint8Array>;
14
+ writeBytes(path: string, value: Uint8Array): Promise<void>;
15
+ list(pattern?: string): Promise<ArtifactFile[]>;
16
+ listDirs(path?: string): Promise<string[]>;
17
+ delete(path: string): Promise<void>;
18
+ }
19
+
20
+ export declare const assertSafePathSegment: (value: string) => void;
21
+
22
+ export declare const createDraftLayout: (root: string, document: string) => {
23
+ directory: (name: string) => string;
24
+ markdown: (name: string, suffix?: string) => string;
25
+ files: (name: string, suffix?: string) => string;
26
+ };
27
+
28
+ export declare const findClosingFrontmatterDelimiter: (content: string) => {
29
+ end: number;
30
+ start: number;
31
+ } | null;
32
+
33
+ export declare const quoteYamlScalar: (value: string) => string;
34
+
35
+ export declare const requireRepoFiles: (repoFiles: ArtifactMount | undefined) => ArtifactMount;
36
+
37
+ export declare const resolveByIdOrName: <TItem extends {
38
+ id: string;
39
+ }>(items: TItem[], value: string, nameOf: (item: TItem) => string, label: string) => string;
40
+
41
+ export declare const sameName: (a: string, b: string) => boolean;
42
+
43
+ export declare const stripFrontmatter: (content: string) => string;
44
+
45
+ export declare const unquoteYamlScalar: (value: string) => string;
46
+
47
+ export { }