@ipab/cli 0.1.0-rc.6 → 0.1.0-rc.7
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 +72 -33
- package/dist/app-authoring.d.ts +5 -0
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +4 -1
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-templates.d.ts +0 -1
- package/dist/app-templates.d.ts.map +1 -1
- package/dist/app-templates.js +6 -45
- package/dist/app-templates.js.map +1 -1
- package/dist/builtins/skill.ipab.car +0 -0
- package/dist/builtins/template.bundle-viewer.car +0 -0
- package/dist/builtins/template.check.car +0 -0
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +1 -39
- package/dist/builtins.js.map +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +395 -86
- package/dist/cli.js.map +1 -1
- package/dist/context.d.ts +16 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +20 -0
- package/dist/context.js.map +1 -1
- package/dist/ipc.d.ts +2 -1
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +44 -3
- package/dist/ipc.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +6 -3
- package/dist/runtime.js.map +1 -1
- package/dist/skill-definition.d.ts +6 -0
- package/dist/skill-definition.d.ts.map +1 -0
- package/dist/skill-definition.js +38 -0
- package/dist/skill-definition.js.map +1 -0
- package/dist/skill-source.d.ts +5 -0
- package/dist/skill-source.d.ts.map +1 -0
- package/dist/skill-source.js +12 -0
- package/dist/skill-source.js.map +1 -0
- package/dist/skills.d.ts +84 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +736 -0
- package/dist/skills.js.map +1 -0
- package/dist/space.d.ts +15 -2
- package/dist/space.d.ts.map +1 -1
- package/dist/space.js +153 -3
- package/dist/space.js.map +1 -1
- package/dist/state.js +1 -1
- package/dist/swarm-files.d.ts +1 -1
- package/dist/swarm-files.d.ts.map +1 -1
- package/dist/swarm-files.js +2 -2
- package/dist/swarm-files.js.map +1 -1
- package/dist/swarm-meta.d.ts +17 -0
- package/dist/swarm-meta.d.ts.map +1 -0
- package/dist/swarm-meta.js +96 -0
- package/dist/swarm-meta.js.map +1 -0
- package/dist/swarm.d.ts +53 -0
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +465 -73
- package/dist/swarm.js.map +1 -1
- package/dist/template-paths.d.ts +7 -0
- package/dist/template-paths.d.ts.map +1 -0
- package/dist/template-paths.js +23 -0
- package/dist/template-paths.js.map +1 -0
- package/dist/template-presentation.d.ts +20 -0
- package/dist/template-presentation.d.ts.map +1 -0
- package/dist/template-presentation.js +133 -0
- package/dist/template-presentation.js.map +1 -0
- package/dist/template-source.d.ts +2 -1
- package/dist/template-source.d.ts.map +1 -1
- package/dist/template-source.js +7 -1
- package/dist/template-source.js.map +1 -1
- package/dist/templates.d.ts +11 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +53 -0
- package/dist/templates.js.map +1 -0
- package/package.json +7 -6
- package/src/app-authoring.ts +18 -2
- package/src/app-templates.ts +8 -72
- package/src/builtins.ts +2 -48
- package/src/cli.ts +474 -71
- package/src/context.ts +45 -0
- package/src/ipc.ts +63 -2
- package/src/runtime.ts +6 -2
- package/src/skill-definition.ts +53 -0
- package/src/skill-source.ts +15 -0
- package/src/skills.ts +1005 -0
- package/src/space.ts +214 -5
- package/src/state.ts +1 -1
- package/src/swarm-files.ts +2 -1
- package/src/swarm-meta.ts +109 -0
- package/src/swarm.ts +721 -128
- package/src/template-paths.ts +43 -0
- package/src/template-presentation.ts +151 -0
- package/src/template-source.ts +9 -2
- package/src/templates.ts +77 -0
package/src/space.ts
CHANGED
|
@@ -5,8 +5,10 @@ import { CID } from "multiformats/cid";
|
|
|
5
5
|
import { sha256 } from "multiformats/hashes/sha2";
|
|
6
6
|
import type { IpfsStore } from "@ipab/ipfs-store";
|
|
7
7
|
import { openBundle, type ContentBundle } from "@ipab/bundle";
|
|
8
|
-
import { HostError, message } from "./errors.js";
|
|
9
|
-
import
|
|
8
|
+
import { HostError, message, object } from "./errors.js";
|
|
9
|
+
import { Ownership } from "./history.js";
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
11
|
+
import { ReadableStream as NodeReadableStream } from "node:stream/web";
|
|
10
12
|
import { appDescription, appSchemaCid } from "./app-definition.js";
|
|
11
13
|
import { readSupportedSchemas } from "./supported-schemas.js";
|
|
12
14
|
export { appSchema, appSchemaCid } from "./app-definition.js";
|
|
@@ -42,7 +44,7 @@ export function relativePath(path: string): string {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export async function bytes(
|
|
45
|
-
stream: ReadableStream<Uint8Array>,
|
|
47
|
+
stream: ReadableStream<Uint8Array> | NodeReadableStream<Uint8Array>,
|
|
46
48
|
limit: number,
|
|
47
49
|
): Promise<Uint8Array> {
|
|
48
50
|
const reader = stream.getReader();
|
|
@@ -157,6 +159,75 @@ export async function loadApp(
|
|
|
157
159
|
};
|
|
158
160
|
}
|
|
159
161
|
|
|
162
|
+
/** Checkpoints are owned by the execution, not pins; only the final result is handed to history. */
|
|
163
|
+
export async function deriveBundle(
|
|
164
|
+
inputCid: string,
|
|
165
|
+
replacements: unknown,
|
|
166
|
+
store: IpfsStore,
|
|
167
|
+
owner: Ownership,
|
|
168
|
+
signal?: AbortSignal,
|
|
169
|
+
): Promise<string> {
|
|
170
|
+
signal?.throwIfAborted();
|
|
171
|
+
const changes = Object.entries(object(replacements, "Bundle replacements"));
|
|
172
|
+
if (changes.length > MAX_PATHS)
|
|
173
|
+
throw new HostError("Bundle replacement path limit exceeded.");
|
|
174
|
+
let total = 0;
|
|
175
|
+
for (const [path, value] of changes) {
|
|
176
|
+
relativePath(path);
|
|
177
|
+
if (!(value instanceof Uint8Array))
|
|
178
|
+
throw new HostError("Bundle replacements must contain byte arrays.");
|
|
179
|
+
total += value.byteLength;
|
|
180
|
+
if (total > OUTPUT_BYTES)
|
|
181
|
+
throw new HostError("Bundle replacement byte limit exceeded.");
|
|
182
|
+
}
|
|
183
|
+
const input = CID.parse(inputCid).toV1().toString();
|
|
184
|
+
const original = await validatedBundle(input, store, owner, signal);
|
|
185
|
+
const id = randomUUID();
|
|
186
|
+
const session = `ipab-derive:${owner.state.identity}:${id}`;
|
|
187
|
+
const temporary = await Ownership.create(
|
|
188
|
+
owner.state,
|
|
189
|
+
store,
|
|
190
|
+
`derive:${id}`,
|
|
191
|
+
session,
|
|
192
|
+
);
|
|
193
|
+
try {
|
|
194
|
+
const output = new OutputSpace(store, temporary, session, signal);
|
|
195
|
+
const replaced = new Set(changes.map(([path]) => path));
|
|
196
|
+
for (const path of original.files) {
|
|
197
|
+
signal?.throwIfAborted();
|
|
198
|
+
if (replaced.has(path)) continue;
|
|
199
|
+
const file = await store.read(
|
|
200
|
+
`${input}/${path}`,
|
|
201
|
+
signal ? { signal } : {},
|
|
202
|
+
);
|
|
203
|
+
await output.link(path, file.cid.toString(), signal);
|
|
204
|
+
}
|
|
205
|
+
for (const [path, value] of changes) {
|
|
206
|
+
const content = value as Uint8Array;
|
|
207
|
+
const chunks = async function* () {
|
|
208
|
+
for (let offset = 0; offset < content.length; offset += CHUNK_BYTES) {
|
|
209
|
+
signal?.throwIfAborted();
|
|
210
|
+
yield await Promise.resolve(
|
|
211
|
+
content.subarray(offset, offset + CHUNK_BYTES),
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
await output.write(path, chunks(), signal);
|
|
216
|
+
}
|
|
217
|
+
const result = await output.finalize();
|
|
218
|
+
const derived = await validatedBundle(result, store, temporary, signal);
|
|
219
|
+
if (derived.schemaKey !== original.schemaKey)
|
|
220
|
+
throw new HostError(
|
|
221
|
+
"Derived Bundle must preserve the input's exact type CID.",
|
|
222
|
+
);
|
|
223
|
+
await owner.retain([result], signal);
|
|
224
|
+
signal?.throwIfAborted();
|
|
225
|
+
return result;
|
|
226
|
+
} finally {
|
|
227
|
+
await temporary.release();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
160
231
|
interface Entry {
|
|
161
232
|
cid: CID;
|
|
162
233
|
size: bigint;
|
|
@@ -175,6 +246,11 @@ export class OutputSpace {
|
|
|
175
246
|
private readonly pending = new Set<string>();
|
|
176
247
|
private totalBytes = 0;
|
|
177
248
|
private fault: Error | undefined;
|
|
249
|
+
private bundleMode = false;
|
|
250
|
+
private bundleSchema: string | undefined;
|
|
251
|
+
private submittedBundle: string | undefined;
|
|
252
|
+
private selectingBundle = false;
|
|
253
|
+
private sessionStarted = false;
|
|
178
254
|
constructor(
|
|
179
255
|
readonly store: IpfsStore,
|
|
180
256
|
readonly owner: Ownership,
|
|
@@ -184,6 +260,10 @@ export class OutputSpace {
|
|
|
184
260
|
this.session = session;
|
|
185
261
|
}
|
|
186
262
|
private claim(path: string): void {
|
|
263
|
+
if (this.bundleMode)
|
|
264
|
+
throw new HostError(
|
|
265
|
+
"Explicit Bundle results cannot be mixed with output Space writes.",
|
|
266
|
+
);
|
|
187
267
|
relativePath(path);
|
|
188
268
|
if (this.claimed.size >= MAX_PATHS)
|
|
189
269
|
throw new HostError("Output path limit exceeded.");
|
|
@@ -199,7 +279,125 @@ export class OutputSpace {
|
|
|
199
279
|
this.pending.add(path);
|
|
200
280
|
}
|
|
201
281
|
fail(error: unknown): void {
|
|
202
|
-
this.fault ??=
|
|
282
|
+
this.fault ??=
|
|
283
|
+
error instanceof HostError ? error : new HostError(message(error));
|
|
284
|
+
}
|
|
285
|
+
private selectBundleMode(): void {
|
|
286
|
+
if (this.fault) throw this.fault;
|
|
287
|
+
if (this.claimed.size)
|
|
288
|
+
throw new HostError(
|
|
289
|
+
"Explicit Bundle results cannot be mixed with output Space writes.",
|
|
290
|
+
);
|
|
291
|
+
if (this.selectingBundle)
|
|
292
|
+
throw new HostError(
|
|
293
|
+
"Concurrent Bundle result selection is not supported.",
|
|
294
|
+
);
|
|
295
|
+
this.bundleMode = true;
|
|
296
|
+
}
|
|
297
|
+
async beginOpenSession(
|
|
298
|
+
inputCid: string,
|
|
299
|
+
signal?: AbortSignal,
|
|
300
|
+
supportedTypes?: ReadonlySet<string>,
|
|
301
|
+
expectedTypes?: unknown,
|
|
302
|
+
): Promise<void> {
|
|
303
|
+
try {
|
|
304
|
+
this.selectBundleMode();
|
|
305
|
+
if (this.sessionStarted || this.submittedBundle)
|
|
306
|
+
throw new HostError(
|
|
307
|
+
"Open session has already started or submitted a result.",
|
|
308
|
+
);
|
|
309
|
+
this.sessionStarted = true;
|
|
310
|
+
this.selectingBundle = true;
|
|
311
|
+
if (expectedTypes !== undefined) {
|
|
312
|
+
if (
|
|
313
|
+
!Array.isArray(expectedTypes) ||
|
|
314
|
+
expectedTypes.length > MAX_PATHS ||
|
|
315
|
+
!expectedTypes.every(
|
|
316
|
+
(cid: unknown) =>
|
|
317
|
+
typeof cid === "string" &&
|
|
318
|
+
CID.parse(cid).toV1().toString() === cid,
|
|
319
|
+
)
|
|
320
|
+
)
|
|
321
|
+
throw new HostError(
|
|
322
|
+
"Open supportedTypes must be exact canonical CID strings.",
|
|
323
|
+
);
|
|
324
|
+
const expected = new Set<string>(expectedTypes as string[]);
|
|
325
|
+
if (expected.size !== expectedTypes.length)
|
|
326
|
+
throw new HostError(
|
|
327
|
+
"Open supportedTypes must not contain duplicate CIDs.",
|
|
328
|
+
);
|
|
329
|
+
if (
|
|
330
|
+
!supportedTypes ||
|
|
331
|
+
expected.size !== supportedTypes.size ||
|
|
332
|
+
[...expected].some((cid) => !supportedTypes.has(cid))
|
|
333
|
+
)
|
|
334
|
+
throw new HostError(
|
|
335
|
+
"Open supportedTypes must exactly match the App supportedSchemas declaration.",
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
const bundle = await validatedBundle(
|
|
339
|
+
inputCid,
|
|
340
|
+
this.store,
|
|
341
|
+
this.owner,
|
|
342
|
+
signal,
|
|
343
|
+
);
|
|
344
|
+
signal?.throwIfAborted();
|
|
345
|
+
if (supportedTypes && !supportedTypes.has(bundle.schemaKey))
|
|
346
|
+
throw new HostError(
|
|
347
|
+
"App does not declare support for the Open input's exact type CID.",
|
|
348
|
+
);
|
|
349
|
+
this.bundleSchema = bundle.schemaKey;
|
|
350
|
+
} catch (error) {
|
|
351
|
+
this.fail(error);
|
|
352
|
+
throw error;
|
|
353
|
+
} finally {
|
|
354
|
+
this.selectingBundle = false;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
cancelOpenSession(): void {
|
|
358
|
+
this.bundleMode = true;
|
|
359
|
+
this.fail(
|
|
360
|
+
new HostError(
|
|
361
|
+
"Open session cancelled without a committed Bundle result.",
|
|
362
|
+
130,
|
|
363
|
+
"CANCELLED",
|
|
364
|
+
"execution",
|
|
365
|
+
),
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
discardBundleResult(): void {
|
|
369
|
+
this.submittedBundle = undefined;
|
|
370
|
+
}
|
|
371
|
+
async submitBundleResult(root: string, signal?: AbortSignal): Promise<void> {
|
|
372
|
+
try {
|
|
373
|
+
this.selectBundleMode();
|
|
374
|
+
} catch (error) {
|
|
375
|
+
this.fail(error);
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
this.selectingBundle = true;
|
|
379
|
+
try {
|
|
380
|
+
const cid = CID.parse(root).toV1().toString();
|
|
381
|
+
if (this.submittedBundle && this.submittedBundle !== cid) {
|
|
382
|
+
const error = new HostError(
|
|
383
|
+
"A different Bundle result has already been submitted.",
|
|
384
|
+
);
|
|
385
|
+
this.fail(error);
|
|
386
|
+
throw error;
|
|
387
|
+
}
|
|
388
|
+
signal?.throwIfAborted();
|
|
389
|
+
if (this.submittedBundle === cid) return;
|
|
390
|
+
const bundle = await validatedBundle(cid, this.store, this.owner, signal);
|
|
391
|
+
signal?.throwIfAborted();
|
|
392
|
+
if (this.bundleSchema && bundle.schemaKey !== this.bundleSchema)
|
|
393
|
+
throw new HostError(
|
|
394
|
+
"Bundle result must preserve the Open session's exact type CID.",
|
|
395
|
+
);
|
|
396
|
+
this.submittedBundle = cid;
|
|
397
|
+
} finally {
|
|
398
|
+
// Validation/storage failures leave the explicit session open for retry, never a Space result.
|
|
399
|
+
this.selectingBundle = false;
|
|
400
|
+
}
|
|
203
401
|
}
|
|
204
402
|
async write(
|
|
205
403
|
path: string,
|
|
@@ -235,7 +433,7 @@ export class OutputSpace {
|
|
|
235
433
|
block instanceof Uint8Array
|
|
236
434
|
? block
|
|
237
435
|
: await bytes(
|
|
238
|
-
|
|
436
|
+
NodeReadableStream.from(block),
|
|
239
437
|
this.store.limits.blockBytes,
|
|
240
438
|
);
|
|
241
439
|
await this.store.stageBlock(
|
|
@@ -312,7 +510,18 @@ export class OutputSpace {
|
|
|
312
510
|
}
|
|
313
511
|
}
|
|
314
512
|
async finalize(): Promise<string> {
|
|
513
|
+
this.signal?.throwIfAborted();
|
|
315
514
|
if (this.fault) throw this.fault;
|
|
515
|
+
if (this.bundleMode) {
|
|
516
|
+
if (this.selectingBundle || !this.submittedBundle)
|
|
517
|
+
throw new HostError(
|
|
518
|
+
"Open session ended without submitting a Bundle result.",
|
|
519
|
+
130,
|
|
520
|
+
"CANCELLED",
|
|
521
|
+
"commit",
|
|
522
|
+
);
|
|
523
|
+
return this.submittedBundle;
|
|
524
|
+
}
|
|
316
525
|
if (this.pending.size)
|
|
317
526
|
throw new HostError(
|
|
318
527
|
"Output has unfinished stream writes.",
|
package/src/state.ts
CHANGED
package/src/swarm-files.ts
CHANGED
|
@@ -30,6 +30,7 @@ export async function readPrivate<T>(
|
|
|
30
30
|
directory: string,
|
|
31
31
|
name: string,
|
|
32
32
|
additionalPaths: readonly ProtectedPath[] = [],
|
|
33
|
+
maximumBytes = 2 * 1024 * 1024,
|
|
33
34
|
): Promise<T | undefined> {
|
|
34
35
|
const path = join(directory, name);
|
|
35
36
|
if (additionalPaths.length) {
|
|
@@ -48,7 +49,7 @@ export async function readPrivate<T>(
|
|
|
48
49
|
throw cause;
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
if ((await lstat(path)).size >
|
|
52
|
+
if ((await lstat(path)).size > maximumBytes)
|
|
52
53
|
throw new HostError("Protected state is oversized.");
|
|
53
54
|
return JSON.parse(await readFile(path, "utf8")) as T;
|
|
54
55
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { encodeSchema, type BundleType } from "@ipab/bundle";
|
|
2
|
+
import { HostError, object } from "./errors.js";
|
|
3
|
+
import { relativePath } from "./space.js";
|
|
4
|
+
|
|
5
|
+
export const legacySwarmMetaType: BundleType = {
|
|
6
|
+
contentType: "application/json",
|
|
7
|
+
schema: {
|
|
8
|
+
type: "object",
|
|
9
|
+
required: ["templatePath", "registryPath"],
|
|
10
|
+
properties: {
|
|
11
|
+
templatePath: { type: "string", minLength: 1, maxLength: 196 },
|
|
12
|
+
registryPath: { type: "string", minLength: 1, maxLength: 196 },
|
|
13
|
+
},
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export const swarmMetaType: BundleType = {
|
|
18
|
+
contentType: "application/json",
|
|
19
|
+
schema: {
|
|
20
|
+
type: "object",
|
|
21
|
+
additionalProperties: false,
|
|
22
|
+
required: ["templatePath", "registryPath", "skillPath"],
|
|
23
|
+
properties: {
|
|
24
|
+
templatePath: { type: "string", minLength: 1, maxLength: 196 },
|
|
25
|
+
registryPath: { type: "string", minLength: 1, maxLength: 196 },
|
|
26
|
+
skillPath: { type: "string", minLength: 1, maxLength: 196 },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
export const swarmMetaSchema = await encodeSchema(swarmMetaType);
|
|
31
|
+
export const legacySwarmMetaSchema = await encodeSchema(legacySwarmMetaType);
|
|
32
|
+
export interface SwarmMeta {
|
|
33
|
+
templatePath: string;
|
|
34
|
+
registryPath: string;
|
|
35
|
+
skillPath?: string;
|
|
36
|
+
}
|
|
37
|
+
export const legacySwarmStateType: BundleType = {
|
|
38
|
+
contentType: "application/json",
|
|
39
|
+
schema: {
|
|
40
|
+
type: "object",
|
|
41
|
+
required: ["v", "templatePath", "registryPath", "names"],
|
|
42
|
+
properties: {
|
|
43
|
+
v: { const: 5 },
|
|
44
|
+
templatePath: { type: "string", minLength: 1, maxLength: 196 },
|
|
45
|
+
registryPath: { type: "string", minLength: 1, maxLength: 196 },
|
|
46
|
+
names: {
|
|
47
|
+
type: "object",
|
|
48
|
+
additionalProperties: { type: "string" },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
additionalProperties: false,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
export const swarmStateType: BundleType = {
|
|
55
|
+
contentType: "application/json",
|
|
56
|
+
schema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
required: ["v", "templatePath", "registryPath", "skillPath", "names"],
|
|
59
|
+
properties: {
|
|
60
|
+
v: { const: 5 },
|
|
61
|
+
templatePath: { type: "string", minLength: 1, maxLength: 196 },
|
|
62
|
+
registryPath: { type: "string", minLength: 1, maxLength: 196 },
|
|
63
|
+
skillPath: { type: "string", minLength: 1, maxLength: 196 },
|
|
64
|
+
names: { type: "object", additionalProperties: { type: "string" } },
|
|
65
|
+
},
|
|
66
|
+
additionalProperties: false,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
export const swarmStateSchema = await encodeSchema(swarmStateType);
|
|
70
|
+
export const legacySwarmStateSchema = await encodeSchema(legacySwarmStateType);
|
|
71
|
+
export function isSwarmStateSchema(cid: string): boolean {
|
|
72
|
+
return (
|
|
73
|
+
cid === swarmStateSchema.cid.toString() ||
|
|
74
|
+
cid === legacySwarmStateSchema.cid.toString()
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
export function parseSwarmMeta(value: unknown): SwarmMeta {
|
|
78
|
+
const data = object(value, "Swarm Meta");
|
|
79
|
+
if (
|
|
80
|
+
![
|
|
81
|
+
"registryPath,templatePath",
|
|
82
|
+
"registryPath,skillPath,templatePath",
|
|
83
|
+
].includes(Object.keys(data).sort().join()) ||
|
|
84
|
+
typeof data.templatePath !== "string" ||
|
|
85
|
+
typeof data.registryPath !== "string" ||
|
|
86
|
+
("skillPath" in data && typeof data.skillPath !== "string")
|
|
87
|
+
)
|
|
88
|
+
throw new HostError(
|
|
89
|
+
"Swarm Meta requires templatePath, registryPath and (for the new exact type) skillPath.",
|
|
90
|
+
);
|
|
91
|
+
for (const path of [
|
|
92
|
+
data.templatePath,
|
|
93
|
+
data.registryPath,
|
|
94
|
+
...(typeof data.skillPath === "string" ? [data.skillPath] : []),
|
|
95
|
+
]) {
|
|
96
|
+
relativePath(path);
|
|
97
|
+
if (path.length > 196 || path.includes(":"))
|
|
98
|
+
throw new HostError(
|
|
99
|
+
"Swarm Meta paths must be current-Swarm ordinary Name prefixes of at most 196 characters, not URIs.",
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
templatePath: data.templatePath,
|
|
104
|
+
registryPath: data.registryPath,
|
|
105
|
+
...(typeof data.skillPath === "string"
|
|
106
|
+
? { skillPath: data.skillPath }
|
|
107
|
+
: {}),
|
|
108
|
+
};
|
|
109
|
+
}
|