@ipab/cli 0.1.0-rc.11 → 0.1.0-rc.12

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.
Files changed (95) hide show
  1. package/README.md +15 -10
  2. package/dist/authoring.d.ts +6 -2
  3. package/dist/authoring.d.ts.map +1 -1
  4. package/dist/authoring.js +65 -18
  5. package/dist/authoring.js.map +1 -1
  6. package/dist/builtins/skill.ipab.car +0 -0
  7. package/dist/cli.d.ts +2 -1
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cli.js +854 -179
  10. package/dist/cli.js.map +1 -1
  11. package/dist/config-secret.js +1 -1
  12. package/dist/config-secret.js.map +1 -1
  13. package/dist/daemon-ui.d.ts +1 -0
  14. package/dist/daemon-ui.d.ts.map +1 -1
  15. package/dist/daemon-ui.js +2 -0
  16. package/dist/daemon-ui.js.map +1 -1
  17. package/dist/history.d.ts +3 -1
  18. package/dist/history.d.ts.map +1 -1
  19. package/dist/history.js +16 -1
  20. package/dist/history.js.map +1 -1
  21. package/dist/kubo-topology.d.ts +2 -0
  22. package/dist/kubo-topology.d.ts.map +1 -1
  23. package/dist/kubo-topology.js +17 -20
  24. package/dist/kubo-topology.js.map +1 -1
  25. package/dist/kubo.d.ts +5 -3
  26. package/dist/kubo.d.ts.map +1 -1
  27. package/dist/kubo.js +83 -13
  28. package/dist/kubo.js.map +1 -1
  29. package/dist/name-reference.d.ts +8 -0
  30. package/dist/name-reference.d.ts.map +1 -0
  31. package/dist/name-reference.js +63 -0
  32. package/dist/name-reference.js.map +1 -0
  33. package/dist/pivot-rpc.d.ts +37 -2
  34. package/dist/pivot-rpc.d.ts.map +1 -1
  35. package/dist/pivot-rpc.js +188 -8
  36. package/dist/pivot-rpc.js.map +1 -1
  37. package/dist/search-index.d.ts.map +1 -1
  38. package/dist/search-index.js +1 -0
  39. package/dist/search-index.js.map +1 -1
  40. package/dist/skill-definition.d.ts +9 -0
  41. package/dist/skill-definition.d.ts.map +1 -1
  42. package/dist/skill-definition.js +26 -2
  43. package/dist/skill-definition.js.map +1 -1
  44. package/dist/skill-source.d.ts +1 -0
  45. package/dist/skill-source.d.ts.map +1 -1
  46. package/dist/skill-source.js +10 -4
  47. package/dist/skill-source.js.map +1 -1
  48. package/dist/skills.d.ts +8 -2
  49. package/dist/skills.d.ts.map +1 -1
  50. package/dist/skills.js +31 -2
  51. package/dist/skills.js.map +1 -1
  52. package/dist/swarm-fs-core.d.ts +217 -0
  53. package/dist/swarm-fs-core.d.ts.map +1 -0
  54. package/dist/swarm-fs-core.js +885 -0
  55. package/dist/swarm-fs-core.js.map +1 -0
  56. package/dist/swarm-fs-path.d.ts +17 -0
  57. package/dist/swarm-fs-path.d.ts.map +1 -0
  58. package/dist/swarm-fs-path.js +46 -0
  59. package/dist/swarm-fs-path.js.map +1 -0
  60. package/dist/swarm-fs.d.ts +9 -0
  61. package/dist/swarm-fs.d.ts.map +1 -0
  62. package/dist/swarm-fs.js +21 -0
  63. package/dist/swarm-fs.js.map +1 -0
  64. package/dist/swarm-observations.d.ts +6 -0
  65. package/dist/swarm-observations.d.ts.map +1 -1
  66. package/dist/swarm-observations.js +28 -8
  67. package/dist/swarm-observations.js.map +1 -1
  68. package/dist/swarm.d.ts +124 -17
  69. package/dist/swarm.d.ts.map +1 -1
  70. package/dist/swarm.js +1085 -450
  71. package/dist/swarm.js.map +1 -1
  72. package/dist/unixfs-tree.d.ts +55 -0
  73. package/dist/unixfs-tree.d.ts.map +1 -1
  74. package/dist/unixfs-tree.js +361 -2
  75. package/dist/unixfs-tree.js.map +1 -1
  76. package/package.json +5 -5
  77. package/src/authoring.ts +88 -28
  78. package/src/cli.ts +1142 -267
  79. package/src/config-secret.ts +1 -1
  80. package/src/daemon-ui.ts +3 -0
  81. package/src/history.ts +26 -1
  82. package/src/kubo-topology.ts +25 -22
  83. package/src/kubo.ts +127 -9
  84. package/src/name-reference.ts +91 -0
  85. package/src/pivot-rpc.ts +272 -14
  86. package/src/search-index.ts +1 -0
  87. package/src/skill-definition.ts +45 -3
  88. package/src/skill-source.ts +10 -4
  89. package/src/skills.ts +43 -2
  90. package/src/swarm-fs-core.ts +1461 -0
  91. package/src/swarm-fs-path.ts +68 -0
  92. package/src/swarm-fs.ts +104 -0
  93. package/src/swarm-observations.ts +40 -14
  94. package/src/swarm.ts +1538 -656
  95. package/src/unixfs-tree.ts +447 -2
@@ -1,4 +1,4 @@
1
- import { syntax } from "./errors.js";
1
+ import { syntax } from "./host-error.js";
2
2
  export { verifyStateStorage as secureConfigurationStorage } from "./state-storage.js";
3
3
 
4
4
  export async function readSecretStream(
package/src/daemon-ui.ts CHANGED
@@ -18,6 +18,7 @@ export interface DaemonSyncSummary {
18
18
  headCid: string | null;
19
19
  stateCid: string | null;
20
20
  skills: DaemonSyncSection;
21
+ typeSkills: DaemonSyncSection;
21
22
  templates: DaemonSyncSection;
22
23
  registry: DaemonSyncSection;
23
24
  }
@@ -97,6 +98,7 @@ export function emptySyncState(): DaemonSyncState {
97
98
  headCid: null,
98
99
  stateCid: null,
99
100
  skills: { status: "skipped", count: 0, error: null },
101
+ typeSkills: { status: "skipped", count: 0, error: null },
100
102
  templates: { status: "skipped", count: 0, error: null },
101
103
  registry: { status: "skipped", count: 0, error: null },
102
104
  };
@@ -639,6 +641,7 @@ tr.clickable:hover td{background:var(--surface-2)}
639
641
  syncRow.append(
640
642
  badge("Sync: " + s.sync.status, s.sync.status === "ok" ? "ok" : s.sync.status === "error" ? "err" : "muted"),
641
643
  renderSyncPill("Skills", s.sync.skills),
644
+ renderSyncPill("Type Skills", s.sync.typeSkills),
642
645
  renderSyncPill("Templates", s.sync.templates),
643
646
  renderSyncPill("Registry", s.sync.registry),
644
647
  );
package/src/history.ts CHANGED
@@ -1,4 +1,10 @@
1
- import { IpfsStore, type StoreConfiguration } from "@ipab/ipfs-store";
1
+ import {
2
+ IpfsStore,
3
+ type IpfsReadOptions,
4
+ type StagedBlock,
5
+ type StoreConfiguration,
6
+ } from "@ipab/ipfs-store";
7
+ import { CID } from "multiformats/cid";
2
8
  import type { SQLInputValue } from "node:sqlite";
3
9
  import { HostError, message, syntax } from "./errors.js";
4
10
  import type { Hold, RunRecord, State } from "./state.js";
@@ -208,6 +214,25 @@ export class Ownership {
208
214
  signal ? { signal } : {},
209
215
  );
210
216
  }
217
+ async importBlocks(
218
+ session: string,
219
+ blocks: readonly StagedBlock[],
220
+ root: CID | string,
221
+ options: IpfsReadOptions = {},
222
+ ): Promise<string> {
223
+ const cid = CID.parse(root.toString()).toV1().toString();
224
+ await this.store.importBlocks(session, blocks, cid, this.owner, {
225
+ ...options,
226
+ onRetained: () => {
227
+ const latest = this.state.hold(this.owner)!;
228
+ this.state.saveHold({
229
+ ...latest,
230
+ roots: [...new Set([...latest.roots, cid])],
231
+ });
232
+ },
233
+ });
234
+ return cid;
235
+ }
211
236
  async release(): Promise<void> {
212
237
  const hold = this.state.hold(this.owner);
213
238
  if (!hold) return;
@@ -1,6 +1,24 @@
1
1
  import { object } from "./errors.js";
2
2
  import type { PeeringPeer } from "./kubo-peering.js";
3
3
 
4
+ export function bootstrapAddresses(peers: readonly PeeringPeer[]): string[] {
5
+ return [
6
+ ...new Set(
7
+ peers.flatMap(({ ID, Addrs }) =>
8
+ Addrs.map((address) => `${address}/p2p/${ID}`),
9
+ ),
10
+ ),
11
+ ].sort();
12
+ }
13
+
14
+ export function withoutBootstrap(
15
+ config: Record<string, unknown>,
16
+ ): Record<string, unknown> {
17
+ const rest = { ...config };
18
+ delete rest.Bootstrap;
19
+ return rest;
20
+ }
21
+
4
22
  export function topologyConfig(
5
23
  config: Record<string, unknown>,
6
24
  pivot: boolean,
@@ -8,17 +26,10 @@ export function topologyConfig(
8
26
  loopback: boolean,
9
27
  ): Record<string, unknown> {
10
28
  const swarm = object(config.Swarm, "Kubo Swarm configuration");
11
- const addresses = peers
12
- .flatMap(({ ID, Addrs }) => Addrs.map((address) => `${address}/p2p/${ID}`))
13
- .sort();
14
29
  return {
15
30
  ...config,
16
- Bootstrap: addresses,
17
- Peering: {
18
- Peers: pivot
19
- ? peers.map(({ ID, Addrs }) => ({ ID, Addrs: [...Addrs] }))
20
- : [],
21
- },
31
+ Bootstrap: bootstrapAddresses(peers),
32
+ Peering: { Peers: [] },
22
33
  AutoConf: { Enabled: false },
23
34
  AutoTLS: { Enabled: false },
24
35
  AutoNAT: { ServiceMode: "disabled" },
@@ -33,8 +44,7 @@ export function topologyConfig(
33
44
  },
34
45
  Internal: {
35
46
  ...object(config.Internal ?? {}, "Kubo Internal configuration"),
36
- // Private swarms cannot use public AutoNAT to activate their hop service.
37
- // This is a role declaration, not a verified Internet reachability claim.
47
+ // Private swarms cannot use public AutoNAT; keep static role declaration.
38
48
  Libp2pForceReachability: pivot ? "public" : "private",
39
49
  NonPublicAddrPublishing: true,
40
50
  },
@@ -45,21 +55,14 @@ export function topologyConfig(
45
55
  Discovery: { MDNS: { Enabled: false } },
46
56
  Swarm: {
47
57
  ...swarm,
48
- EnableHolePunching: true,
58
+ EnableHolePunching: false,
49
59
  RelayClient: {
50
- Enabled: true,
51
- // libp2p counts static entries before grouping candidates by PeerID.
52
- // One entry per ID avoids a three-minute wait for duplicate candidates;
53
- // Bootstrap supplies the complete address set to the same peerstore.
54
- StaticRelays: peers
55
- .flatMap(({ ID, Addrs }) =>
56
- Addrs[0] ? [`${Addrs[0]}/p2p/${ID}`] : [],
57
- )
58
- .sort(),
60
+ Enabled: false,
61
+ StaticRelays: [],
59
62
  },
60
63
  RelayService: {
61
64
  ...object(swarm.RelayService ?? {}, "Kubo relay service"),
62
- Enabled: pivot,
65
+ Enabled: false,
63
66
  },
64
67
  },
65
68
  };
package/src/kubo.ts CHANGED
@@ -31,7 +31,11 @@ import {
31
31
  import { HostError, object } from "./errors.js";
32
32
  import { nodeError } from "./authoring.js";
33
33
  import { peerArguments, type PeeringPeer } from "./kubo-peering.js";
34
- import { topologyConfig } from "./kubo-topology.js";
34
+ import {
35
+ bootstrapAddresses,
36
+ topologyConfig,
37
+ withoutBootstrap,
38
+ } from "./kubo-topology.js";
35
39
 
36
40
  import { kuboBinary, withKuboProgram } from "./kubo-install.js";
37
41
  export { kuboBinary };
@@ -405,9 +409,13 @@ async function rpc(
405
409
  : AbortSignal.timeout(timeout),
406
410
  });
407
411
  }
408
- async function ready(node: KuboNode, signal?: AbortSignal): Promise<boolean> {
412
+ async function ready(
413
+ node: KuboNode,
414
+ signal?: AbortSignal,
415
+ fetcher: typeof fetch = fetch,
416
+ ): Promise<boolean> {
409
417
  try {
410
- const response = await rpc(node, "id", signal);
418
+ const response = await rpc(node, "id", signal, 5000, fetcher);
411
419
  if (response.status === 401 || response.status === 403) {
412
420
  await response.body?.cancel();
413
421
  throw new HostError(
@@ -430,6 +438,66 @@ async function ready(node: KuboNode, signal?: AbortSignal): Promise<boolean> {
430
438
  return false;
431
439
  }
432
440
  }
441
+ export async function nodeReady(
442
+ node: KuboNode,
443
+ signal?: AbortSignal,
444
+ fetcher: typeof fetch = fetch,
445
+ ): Promise<boolean> {
446
+ return ready(node, signal, fetcher);
447
+ }
448
+ function normalizeAddresses(value: unknown): string[] | null {
449
+ if (value === null || value === undefined) return [];
450
+ if (!Array.isArray(value)) return null;
451
+ const items = value as unknown[];
452
+ if (!items.every((item) => typeof item === "string")) return null;
453
+ return [...new Set(items)].sort();
454
+ }
455
+ async function reconcileBootstrap(
456
+ node: KuboNode,
457
+ desired: readonly string[],
458
+ signal?: AbortSignal,
459
+ ): Promise<void> {
460
+ const listResponse = await rpc(node, "bootstrap/list", signal, 5_000);
461
+ if (!listResponse.ok) {
462
+ await listResponse.body?.cancel();
463
+ throw new HostError(
464
+ `Owned Kubo bootstrap reconciliation failed (HTTP ${listResponse.status}); retry Swarm activation.`,
465
+ );
466
+ }
467
+ const listed = object(
468
+ JSON.parse(await boundedText(listResponse)) as unknown,
469
+ "owned Kubo bootstrap response",
470
+ );
471
+ const actual = normalizeAddresses(listed.Peers);
472
+ if (actual === null)
473
+ throw new HostError("Invalid owned Kubo bootstrap response.");
474
+ const actualSet = new Set(actual);
475
+ const desiredSet = new Set(desired);
476
+ const toRemove = actual.filter((address) => !desiredSet.has(address));
477
+ const toAdd = desired.filter((address) => !actualSet.has(address));
478
+ if (toRemove.length) {
479
+ const query = toRemove
480
+ .map((address) => `arg=${encodeURIComponent(address)}`)
481
+ .join("&");
482
+ const response = await rpc(node, `bootstrap/rm?${query}`, signal, 5_000);
483
+ await response.body?.cancel();
484
+ if (!response.ok)
485
+ throw new HostError(
486
+ `Owned Kubo bootstrap reconciliation failed (HTTP ${response.status}); retry Swarm activation.`,
487
+ );
488
+ }
489
+ if (toAdd.length) {
490
+ const query = toAdd
491
+ .map((address) => `arg=${encodeURIComponent(address)}`)
492
+ .join("&");
493
+ const response = await rpc(node, `bootstrap/add?${query}`, signal, 5_000);
494
+ await response.body?.cancel();
495
+ if (!response.ok)
496
+ throw new HostError(
497
+ `Owned Kubo bootstrap reconciliation failed (HTTP ${response.status}); retry Swarm activation.`,
498
+ );
499
+ }
500
+ }
433
501
  export async function stopNode(node: KuboNode): Promise<void> {
434
502
  if (!(await ready(node))) return;
435
503
  await (await rpc(node, "shutdown")).body?.cancel();
@@ -526,13 +594,29 @@ export async function startNode(
526
594
  desired,
527
595
  listen === "loopback",
528
596
  );
529
- if (!isDeepStrictEqual(config, nextConfig)) {
597
+ const staticChanged = !isDeepStrictEqual(
598
+ withoutBootstrap(config),
599
+ withoutBootstrap(nextConfig),
600
+ );
601
+ const desiredBootstrap = bootstrapAddresses(desired);
602
+ const currentBootstrap = normalizeAddresses(config.Bootstrap);
603
+ const bootstrapChanged =
604
+ currentBootstrap === null ||
605
+ !isDeepStrictEqual(currentBootstrap, desiredBootstrap);
606
+ if (staticChanged) {
530
607
  await invalidateTopology();
531
608
  if (online) {
532
609
  await stopNode(node);
533
610
  online = false;
534
611
  }
535
612
  await writePrivate(node.repo, "config", nextConfig);
613
+ } else if (bootstrapChanged) {
614
+ await invalidateTopology();
615
+ if (online) {
616
+ await reconcileBootstrap(node, desiredBootstrap, signal);
617
+ } else {
618
+ await writePrivate(node.repo, "config", nextConfig);
619
+ }
536
620
  }
537
621
  const keyPath = join(node.repo, "swarm.key");
538
622
  if (record.epoch === epoch) {
@@ -862,8 +946,9 @@ export interface KuboP2pListener {
862
946
  export async function p2pList(
863
947
  node: KuboNode,
864
948
  signal?: AbortSignal,
949
+ fetcher: typeof fetch = fetch,
865
950
  ): Promise<KuboP2pListener[]> {
866
- const response = await rpc(node, "p2p/ls", signal, 10_000);
951
+ const response = await rpc(node, "p2p/ls", signal, 10_000, fetcher);
867
952
  if (!response.ok) {
868
953
  await response.body?.cancel();
869
954
  throw new HostError(`Owned Kubo p2p/ls failed (HTTP ${response.status}).`);
@@ -899,6 +984,7 @@ export async function p2pClose(
899
984
  targetAddress?: string;
900
985
  },
901
986
  signal?: AbortSignal,
987
+ fetcher: typeof fetch = fetch,
902
988
  ): Promise<void> {
903
989
  const query = new URLSearchParams();
904
990
  if (options.protocol !== undefined) query.set("protocol", options.protocol);
@@ -912,6 +998,7 @@ export async function p2pClose(
912
998
  qs ? `p2p/close?${qs}` : "p2p/close",
913
999
  signal,
914
1000
  10_000,
1001
+ fetcher,
915
1002
  );
916
1003
  if (!response.ok) {
917
1004
  await response.body?.cancel();
@@ -927,23 +1014,30 @@ export async function p2pListen(
927
1014
  protocol: string,
928
1015
  targetAddress: string,
929
1016
  signal?: AbortSignal,
930
- ): Promise<void> {
1017
+ fetcher: typeof fetch = fetch,
1018
+ ): Promise<boolean> {
931
1019
  const selfListen = `/p2p/${node.peerId}`;
932
- const existing = await p2pList(node, signal);
1020
+ const existing = await p2pList(node, signal, fetcher);
933
1021
  const matching = existing.filter(
934
1022
  (entry) =>
935
1023
  entry.protocol === protocol && entry.listenAddress === selfListen,
936
1024
  );
937
1025
  if (matching.length === 1 && matching[0]!.targetAddress === targetAddress)
938
- return;
1026
+ return false;
939
1027
  if (matching.length > 0) {
940
- await p2pClose(node, { protocol, listenAddress: selfListen }, signal);
1028
+ await p2pClose(
1029
+ node,
1030
+ { protocol, listenAddress: selfListen },
1031
+ signal,
1032
+ fetcher,
1033
+ );
941
1034
  }
942
1035
  const response = await rpc(
943
1036
  node,
944
1037
  `p2p/listen?arg=${encodeURIComponent(protocol)}&arg=${encodeURIComponent(targetAddress)}`,
945
1038
  signal,
946
1039
  10_000,
1040
+ fetcher,
947
1041
  );
948
1042
  if (!response.ok) {
949
1043
  const detail = await boundedText(response).catch(() => "");
@@ -952,6 +1046,7 @@ export async function p2pListen(
952
1046
  );
953
1047
  }
954
1048
  await response.body?.cancel();
1049
+ return true;
955
1050
  }
956
1051
 
957
1052
  function parseLoopbackMultiaddr(address: string): {
@@ -1044,6 +1139,29 @@ export async function p2pForward(
1044
1139
  };
1045
1140
  }
1046
1141
 
1142
+ export async function isRecursivelyPinned(
1143
+ node: KuboNode,
1144
+ cid: string,
1145
+ signal?: AbortSignal,
1146
+ fetcher: typeof fetch = fetch,
1147
+ ): Promise<boolean> {
1148
+ const response = await rpc(
1149
+ node,
1150
+ "pin/ls?type=recursive",
1151
+ signal,
1152
+ 15_000,
1153
+ fetcher,
1154
+ );
1155
+ if (!response.ok)
1156
+ throw new HostError(`Owned Kubo pin/ls failed (HTTP ${response.status}).`);
1157
+ const data = object(JSON.parse(await boundedText(response)), "Kubo pins");
1158
+ const keys = object(data.Keys, "Kubo pin keys");
1159
+ return (
1160
+ Object.hasOwn(keys, cid) &&
1161
+ object(keys[cid], "Kubo pin").Type === "recursive"
1162
+ );
1163
+ }
1164
+
1047
1165
  export async function pinAdd(
1048
1166
  node: KuboNode,
1049
1167
  cid: string,
@@ -0,0 +1,91 @@
1
+ import { swarmUrl } from "./config.js";
2
+ import { HostError } from "./host-error.js";
3
+ import { relativePath } from "./space-path.js";
4
+
5
+ export function formalName(name: string): string {
6
+ relativePath(name);
7
+ if (name.length > 256 || name.startsWith("builtin:"))
8
+ throw new HostError("Invalid formal Name.");
9
+ return name;
10
+ }
11
+
12
+ function decodeNameComponent(
13
+ value: string,
14
+ part: "authority" | "path",
15
+ ): string {
16
+ try {
17
+ return decodeURIComponent(value);
18
+ } catch {
19
+ throw new HostError(
20
+ `Malformed percent-encoding in IPAB URI ${part}; use valid UTF-8 escapes or copy the reference from ipab search.`,
21
+ );
22
+ }
23
+ }
24
+
25
+ export function parseNameReference(
26
+ reference: string,
27
+ ): { swarm?: string; name: string } | undefined {
28
+ if (/^name:/i.test(reference))
29
+ throw new HostError("name: is unsupported; use ipab://ALIAS/PATH.");
30
+ if (!/^ipab:/i.test(reference)) return undefined;
31
+ if (/^ipab:\/\/https?:\/\//i.test(reference))
32
+ throw new HostError(
33
+ "Unencoded configuration URL in IPAB URI. Percent-encode the entire configuration URL and each Name path segment separately, or copy the reference from ipab search.",
34
+ );
35
+ const match = /^ipab:\/\/([^/]*)\/(.*)$/is.exec(reference);
36
+ if (!match)
37
+ throw new HostError(
38
+ "Invalid IPAB URI; percent-encode the configuration URL authority and each path segment.",
39
+ );
40
+ const authority = decodeNameComponent(match[1]!, "authority");
41
+ if (authority && !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(authority)) {
42
+ if (!/^https?:\/\//i.test(authority))
43
+ throw new HostError(
44
+ "Invalid IPAB URI authority; use a registered alias or the percent-encoded configuration URL.",
45
+ );
46
+ swarmUrl(authority);
47
+ }
48
+ if (/[?#\s]/.test(match[2]!))
49
+ throw new HostError(
50
+ "Invalid IPAB URI path; percent-encode each Name path segment. Queries and fragments are not supported.",
51
+ );
52
+ const segments = match[2]!.split("/").map((segment) => {
53
+ const decoded = decodeNameComponent(segment, "path");
54
+ if (/[/\\]/.test(decoded))
55
+ throw new HostError(
56
+ "Invalid IPAB URI path separator; use literal / between Name segments, never an encoded slash or backslash.",
57
+ );
58
+ return decoded;
59
+ });
60
+ try {
61
+ return {
62
+ ...(authority ? { swarm: authority } : {}),
63
+ name: match[2] === "" ? "" : formalName(segments.join("/")),
64
+ };
65
+ } catch (error) {
66
+ if (!(error instanceof HostError)) throw error;
67
+ throw new HostError(
68
+ "Invalid IPAB URI path; use a safe relative Name of at most 256 characters without empty, . or .. segments.",
69
+ error.exitCode,
70
+ error.code,
71
+ error.phase,
72
+ );
73
+ }
74
+ }
75
+
76
+ export function formatNameReference(swarm: string, name: string): string {
77
+ const segment = (value: string) =>
78
+ encodeURIComponent(value).replace(
79
+ /[!'()*]/g,
80
+ (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`,
81
+ );
82
+ return `ipab://${segment(swarm)}/${name.split("/").map(segment).join("/")}`;
83
+ }
84
+
85
+ export function templateName(name: string): string {
86
+ if (name.includes(":"))
87
+ throw new HostError(
88
+ "Template NAME must be a safe relative Name, not a URI.",
89
+ );
90
+ return formalName(name);
91
+ }