@ipab/cli 0.1.0-rc.10 → 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.
- package/README.md +24 -11
- package/dist/authoring.d.ts +7 -0
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +85 -5
- package/dist/authoring.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/bundled-skills.d.ts +1 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +904 -183
- package/dist/cli.js.map +1 -1
- package/dist/config-secret.js +1 -1
- package/dist/config-secret.js.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -2
- package/dist/config.js.map +1 -1
- package/dist/daemon-ui.d.ts +1 -0
- package/dist/daemon-ui.d.ts.map +1 -1
- package/dist/daemon-ui.js +2 -0
- package/dist/daemon-ui.js.map +1 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +7 -3
- package/dist/doctor.js.map +1 -1
- package/dist/get.d.ts.map +1 -1
- package/dist/get.js +1 -1
- package/dist/get.js.map +1 -1
- package/dist/history.d.ts +3 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +16 -1
- package/dist/history.js.map +1 -1
- package/dist/kubo-topology.d.ts +2 -0
- package/dist/kubo-topology.d.ts.map +1 -1
- package/dist/kubo-topology.js +17 -20
- package/dist/kubo-topology.js.map +1 -1
- package/dist/kubo.d.ts +5 -3
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +83 -13
- package/dist/kubo.js.map +1 -1
- package/dist/name-reference.d.ts +8 -0
- package/dist/name-reference.d.ts.map +1 -0
- package/dist/name-reference.js +63 -0
- package/dist/name-reference.js.map +1 -0
- package/dist/pivot-rpc.d.ts +37 -2
- package/dist/pivot-rpc.d.ts.map +1 -1
- package/dist/pivot-rpc.js +188 -8
- package/dist/pivot-rpc.js.map +1 -1
- package/dist/search-index.d.ts.map +1 -1
- package/dist/search-index.js +1 -0
- package/dist/search-index.js.map +1 -1
- package/dist/skill-definition.d.ts +9 -0
- package/dist/skill-definition.d.ts.map +1 -1
- package/dist/skill-definition.js +26 -2
- package/dist/skill-definition.js.map +1 -1
- package/dist/skill-source.d.ts +1 -0
- package/dist/skill-source.d.ts.map +1 -1
- package/dist/skill-source.js +10 -4
- package/dist/skill-source.js.map +1 -1
- package/dist/skills.d.ts +9 -3
- package/dist/skills.d.ts.map +1 -1
- package/dist/skills.js +31 -2
- package/dist/skills.js.map +1 -1
- package/dist/state.d.ts +20 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +87 -3
- package/dist/state.js.map +1 -1
- package/dist/swarm-fs-core.d.ts +217 -0
- package/dist/swarm-fs-core.d.ts.map +1 -0
- package/dist/swarm-fs-core.js +885 -0
- package/dist/swarm-fs-core.js.map +1 -0
- package/dist/swarm-fs-path.d.ts +17 -0
- package/dist/swarm-fs-path.d.ts.map +1 -0
- package/dist/swarm-fs-path.js +46 -0
- package/dist/swarm-fs-path.js.map +1 -0
- package/dist/swarm-fs.d.ts +9 -0
- package/dist/swarm-fs.d.ts.map +1 -0
- package/dist/swarm-fs.js +21 -0
- package/dist/swarm-fs.js.map +1 -0
- package/dist/swarm-observations.d.ts +6 -0
- package/dist/swarm-observations.d.ts.map +1 -1
- package/dist/swarm-observations.js +28 -8
- package/dist/swarm-observations.js.map +1 -1
- package/dist/swarm.d.ts +192 -17
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1360 -442
- package/dist/swarm.js.map +1 -1
- package/dist/unixfs-tree.d.ts +55 -0
- package/dist/unixfs-tree.d.ts.map +1 -1
- package/dist/unixfs-tree.js +361 -2
- package/dist/unixfs-tree.js.map +1 -1
- package/package.json +5 -5
- package/src/authoring.ts +125 -8
- package/src/cli.ts +1215 -281
- package/src/config-secret.ts +1 -1
- package/src/config.ts +20 -2
- package/src/daemon-ui.ts +3 -0
- package/src/doctor.ts +12 -2
- package/src/get.ts +2 -1
- package/src/history.ts +26 -1
- package/src/kubo-topology.ts +25 -22
- package/src/kubo.ts +127 -9
- package/src/name-reference.ts +91 -0
- package/src/pivot-rpc.ts +272 -14
- package/src/search-index.ts +1 -0
- package/src/skill-definition.ts +45 -3
- package/src/skill-source.ts +10 -4
- package/src/skills.ts +43 -2
- package/src/state.ts +117 -2
- package/src/swarm-fs-core.ts +1461 -0
- package/src/swarm-fs-path.ts +68 -0
- package/src/swarm-fs.ts +104 -0
- package/src/swarm-observations.ts +40 -14
- package/src/swarm.ts +1950 -727
- package/src/unixfs-tree.ts +447 -2
package/src/pivot-rpc.ts
CHANGED
|
@@ -26,6 +26,8 @@ import {
|
|
|
26
26
|
} from "@ipab/bundle/pointer/scope";
|
|
27
27
|
import { HostError, message, object } from "./errors.js";
|
|
28
28
|
import {
|
|
29
|
+
p2pClose,
|
|
30
|
+
p2pListen,
|
|
29
31
|
probePeer,
|
|
30
32
|
validateAddress,
|
|
31
33
|
type KuboNode,
|
|
@@ -42,6 +44,159 @@ export const PIVOT_RECEIPT_PROTOCOL = PIVOT_PROTOCOL;
|
|
|
42
44
|
export const MAX_PIVOT_RPC_BYTES = 64 * 1024;
|
|
43
45
|
const MAX_REQUEST_URL_BYTES = 4096;
|
|
44
46
|
|
|
47
|
+
export interface PivotStatus {
|
|
48
|
+
v: 1;
|
|
49
|
+
ready: boolean;
|
|
50
|
+
headCid: string | null;
|
|
51
|
+
indexedHeadCid: string | null;
|
|
52
|
+
syncError: string | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface PivotReplicateRequest {
|
|
56
|
+
v: 1;
|
|
57
|
+
service: string;
|
|
58
|
+
scopeId: string;
|
|
59
|
+
headId: string;
|
|
60
|
+
epoch: number;
|
|
61
|
+
headCid: string;
|
|
62
|
+
member: string;
|
|
63
|
+
timestamp: number;
|
|
64
|
+
nonce: string;
|
|
65
|
+
signature: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function pivotReplicateSigningMessage(
|
|
69
|
+
request: Omit<PivotReplicateRequest, "signature">,
|
|
70
|
+
): string {
|
|
71
|
+
return JSON.stringify([
|
|
72
|
+
"IPAB-PIVOT-REPLICATE/1",
|
|
73
|
+
request.service,
|
|
74
|
+
request.scopeId,
|
|
75
|
+
request.headId,
|
|
76
|
+
request.epoch,
|
|
77
|
+
request.headCid,
|
|
78
|
+
request.member,
|
|
79
|
+
request.timestamp,
|
|
80
|
+
request.nonce,
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function parsePivotReplicateRequest(
|
|
85
|
+
input: unknown,
|
|
86
|
+
): PivotReplicateRequest {
|
|
87
|
+
const data = object(input, "Pivot replicate request");
|
|
88
|
+
let validCid: boolean;
|
|
89
|
+
try {
|
|
90
|
+
validCid =
|
|
91
|
+
typeof data.headCid === "string" &&
|
|
92
|
+
CID.parse(data.headCid).toV1().toString() === data.headCid;
|
|
93
|
+
} catch {
|
|
94
|
+
throw new HostError("Invalid replicate headCid.");
|
|
95
|
+
}
|
|
96
|
+
if (
|
|
97
|
+
Object.keys(data).sort().join() !==
|
|
98
|
+
"epoch,headCid,headId,member,nonce,scopeId,service,signature,timestamp,v" ||
|
|
99
|
+
data.v !== 1 ||
|
|
100
|
+
typeof data.service !== "string" ||
|
|
101
|
+
canonicalService(data.service) !== data.service ||
|
|
102
|
+
typeof data.scopeId !== "string" ||
|
|
103
|
+
!RESOURCE_ID_PATTERN.test(data.scopeId) ||
|
|
104
|
+
typeof data.headId !== "string" ||
|
|
105
|
+
!RESOURCE_ID_PATTERN.test(data.headId) ||
|
|
106
|
+
typeof data.epoch !== "number" ||
|
|
107
|
+
!Number.isSafeInteger(data.epoch) ||
|
|
108
|
+
data.epoch < 1 ||
|
|
109
|
+
typeof data.headCid !== "string" ||
|
|
110
|
+
!validCid ||
|
|
111
|
+
!isCanonicalPublicKey(data.member) ||
|
|
112
|
+
typeof data.timestamp !== "number" ||
|
|
113
|
+
!Number.isSafeInteger(data.timestamp) ||
|
|
114
|
+
data.timestamp < 0 ||
|
|
115
|
+
typeof data.nonce !== "string" ||
|
|
116
|
+
!/^[A-Za-z0-9_-]{22,128}$/.test(data.nonce) ||
|
|
117
|
+
typeof data.signature !== "string" ||
|
|
118
|
+
!/^[A-Za-z0-9_-]{86}$/.test(data.signature)
|
|
119
|
+
)
|
|
120
|
+
throw new HostError("Invalid Pivot replicate request.");
|
|
121
|
+
return {
|
|
122
|
+
v: 1,
|
|
123
|
+
service: data.service,
|
|
124
|
+
scopeId: data.scopeId,
|
|
125
|
+
headId: data.headId,
|
|
126
|
+
epoch: data.epoch,
|
|
127
|
+
headCid: data.headCid,
|
|
128
|
+
member: data.member,
|
|
129
|
+
timestamp: data.timestamp,
|
|
130
|
+
nonce: data.nonce,
|
|
131
|
+
signature: data.signature,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function signPivotReplicateRequest(
|
|
136
|
+
input: Omit<PivotReplicateRequest, "v" | "timestamp" | "nonce" | "signature">,
|
|
137
|
+
privateKey: string,
|
|
138
|
+
): Promise<PivotReplicateRequest> {
|
|
139
|
+
const body: Omit<PivotReplicateRequest, "signature"> = {
|
|
140
|
+
...input,
|
|
141
|
+
v: 1,
|
|
142
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
143
|
+
nonce: toBase64Url(randomBytes(24)),
|
|
144
|
+
};
|
|
145
|
+
return parsePivotReplicateRequest({
|
|
146
|
+
...body,
|
|
147
|
+
signature: await signEd25519(
|
|
148
|
+
await importPrivateKeyPkcs8(privateKey),
|
|
149
|
+
pivotReplicateSigningMessage(body),
|
|
150
|
+
),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export async function verifyPivotReplicateRequest(
|
|
155
|
+
request: PivotReplicateRequest,
|
|
156
|
+
nowSec = Math.floor(Date.now() / 1000),
|
|
157
|
+
): Promise<void> {
|
|
158
|
+
if (Math.abs(request.timestamp - nowSec) > 60)
|
|
159
|
+
throw new HostError(
|
|
160
|
+
"Replicate request timestamp must be within 60 seconds.",
|
|
161
|
+
);
|
|
162
|
+
const { signature, ...body } = request;
|
|
163
|
+
if (
|
|
164
|
+
!(await verifyEd25519(
|
|
165
|
+
await importPublicKeyRaw(request.member),
|
|
166
|
+
signature,
|
|
167
|
+
pivotReplicateSigningMessage(body),
|
|
168
|
+
))
|
|
169
|
+
)
|
|
170
|
+
throw new HostError(
|
|
171
|
+
"Invalid member signature on Pivot replicate request.",
|
|
172
|
+
1,
|
|
173
|
+
"PIVOT_UNAUTHORIZED",
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function parsePivotStatus(input: unknown): PivotStatus {
|
|
178
|
+
const data = object(input, "Pivot status");
|
|
179
|
+
const cid = (value: unknown): value is string | null =>
|
|
180
|
+
value === null ||
|
|
181
|
+
(typeof value === "string" && CID.parse(value).toV1().toString() === value);
|
|
182
|
+
if (
|
|
183
|
+
data.v !== 1 ||
|
|
184
|
+
typeof data.ready !== "boolean" ||
|
|
185
|
+
!cid(data.headCid) ||
|
|
186
|
+
!cid(data.indexedHeadCid) ||
|
|
187
|
+
!(data.syncError === null || typeof data.syncError === "string") ||
|
|
188
|
+
(data.ready && data.headCid === null)
|
|
189
|
+
)
|
|
190
|
+
throw new HostError("Invalid Pivot status.");
|
|
191
|
+
return {
|
|
192
|
+
v: 1,
|
|
193
|
+
ready: data.ready,
|
|
194
|
+
headCid: data.headCid,
|
|
195
|
+
indexedHeadCid: data.indexedHeadCid,
|
|
196
|
+
syncError: data.syncError,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
45
200
|
export interface PivotReceiptRequest {
|
|
46
201
|
v: 1;
|
|
47
202
|
service: string;
|
|
@@ -225,6 +380,7 @@ async function readBoundedBody(request: IncomingMessage): Promise<string> {
|
|
|
225
380
|
export interface PivotServer {
|
|
226
381
|
port: number;
|
|
227
382
|
address: string;
|
|
383
|
+
readonly listening: boolean;
|
|
228
384
|
close: () => Promise<void>;
|
|
229
385
|
}
|
|
230
386
|
|
|
@@ -237,6 +393,11 @@ export type PivotReceiptHandler = (
|
|
|
237
393
|
|
|
238
394
|
export interface PivotServiceHandlers {
|
|
239
395
|
receipt?: PivotReceiptHandler;
|
|
396
|
+
status?: (signal: AbortSignal) => Promise<PivotStatus>;
|
|
397
|
+
replicate?: (
|
|
398
|
+
request: PivotReplicateRequest,
|
|
399
|
+
signal: AbortSignal,
|
|
400
|
+
) => Promise<{ ready: true; headCid: string }>;
|
|
240
401
|
search?: (params: ValidatedSearchParams) => SearchApiResponse | null;
|
|
241
402
|
diagnostic?: (text: string) => void;
|
|
242
403
|
}
|
|
@@ -271,6 +432,53 @@ export async function startPivotHttpServer(
|
|
|
271
432
|
}
|
|
272
433
|
const parsedUrl = new URL(rawUrl, "http://127.0.0.1");
|
|
273
434
|
|
|
435
|
+
if (
|
|
436
|
+
(parsedUrl.pathname === "/v1/status" && handlers.status) ||
|
|
437
|
+
(parsedUrl.pathname === "/v1/replicate" && handlers.replicate)
|
|
438
|
+
) {
|
|
439
|
+
const statusRequest = parsedUrl.pathname === "/v1/status";
|
|
440
|
+
if (request.method !== (statusRequest ? "GET" : "POST")) {
|
|
441
|
+
sendJson(response, 405, { error: "Method not allowed." });
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
try {
|
|
445
|
+
if (statusRequest) {
|
|
446
|
+
sendJson(response, 200, await handlers.status!(controller.signal));
|
|
447
|
+
} else {
|
|
448
|
+
let input: unknown;
|
|
449
|
+
try {
|
|
450
|
+
input = JSON.parse(await readBoundedBody(request)) as unknown;
|
|
451
|
+
} catch (cause) {
|
|
452
|
+
if (cause instanceof ServiceError) throw cause;
|
|
453
|
+
throw new HostError("Invalid replicate JSON.");
|
|
454
|
+
}
|
|
455
|
+
const result = await handlers.replicate!(
|
|
456
|
+
parsePivotReplicateRequest(input),
|
|
457
|
+
controller.signal,
|
|
458
|
+
);
|
|
459
|
+
sendJson(response, 200, result);
|
|
460
|
+
}
|
|
461
|
+
} catch (cause) {
|
|
462
|
+
const status =
|
|
463
|
+
cause instanceof ServiceError
|
|
464
|
+
? cause.status
|
|
465
|
+
: cause instanceof HostError &&
|
|
466
|
+
cause.code === "PIVOT_UNAUTHORIZED"
|
|
467
|
+
? 403
|
|
468
|
+
: cause instanceof HostError
|
|
469
|
+
? 400
|
|
470
|
+
: 500;
|
|
471
|
+
handlers.diagnostic?.(
|
|
472
|
+
`Pivot ${statusRequest ? "status" : "replicate"} failed: ${message(cause)}`,
|
|
473
|
+
);
|
|
474
|
+
if (!response.headersSent)
|
|
475
|
+
sendJson(response, status, {
|
|
476
|
+
error: { message: message(cause).slice(0, 512) },
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
|
|
274
482
|
if (parsedUrl.pathname === "/v1/search") {
|
|
275
483
|
try {
|
|
276
484
|
if (request.method !== "GET") {
|
|
@@ -398,6 +606,9 @@ export async function startPivotHttpServer(
|
|
|
398
606
|
return {
|
|
399
607
|
port: address.port,
|
|
400
608
|
address: `/ip4/127.0.0.1/tcp/${address.port}`,
|
|
609
|
+
get listening() {
|
|
610
|
+
return server.listening;
|
|
611
|
+
},
|
|
401
612
|
close,
|
|
402
613
|
};
|
|
403
614
|
}
|
|
@@ -446,25 +657,26 @@ async function kuboP2pRpc(
|
|
|
446
657
|
);
|
|
447
658
|
}
|
|
448
659
|
|
|
660
|
+
export async function ensurePivotListener(
|
|
661
|
+
node: KuboNode,
|
|
662
|
+
targetAddress: string,
|
|
663
|
+
signal?: AbortSignal,
|
|
664
|
+
fetcher: typeof fetch = fetch,
|
|
665
|
+
): Promise<boolean> {
|
|
666
|
+
return p2pListen(node, PIVOT_PROTOCOL, targetAddress, signal, fetcher);
|
|
667
|
+
}
|
|
668
|
+
|
|
449
669
|
export async function mountPivotServer(
|
|
450
670
|
node: KuboNode,
|
|
451
671
|
handlers: PivotServiceHandlers,
|
|
452
672
|
fetcher: typeof fetch = fetch,
|
|
673
|
+
signal?: AbortSignal,
|
|
453
674
|
): Promise<PivotServer> {
|
|
454
675
|
const httpServer = await startPivotHttpServer(handlers);
|
|
455
676
|
const target = httpServer.address;
|
|
677
|
+
const selfListen = `/p2p/${node.peerId}`;
|
|
456
678
|
try {
|
|
457
|
-
|
|
458
|
-
await kuboP2pRpc(
|
|
459
|
-
node,
|
|
460
|
-
`p2p/close?protocol=${encodeURIComponent(PIVOT_PROTOCOL)}`,
|
|
461
|
-
fetcher,
|
|
462
|
-
).catch(() => {});
|
|
463
|
-
await kuboP2pRpc(
|
|
464
|
-
node,
|
|
465
|
-
`p2p/listen?arg=${encodeURIComponent(PIVOT_PROTOCOL)}&arg=${encodeURIComponent(target)}`,
|
|
466
|
-
fetcher,
|
|
467
|
-
);
|
|
679
|
+
await p2pListen(node, PIVOT_PROTOCOL, target, signal, fetcher);
|
|
468
680
|
} catch (cause) {
|
|
469
681
|
await httpServer.close();
|
|
470
682
|
throw cause;
|
|
@@ -472,11 +684,19 @@ export async function mountPivotServer(
|
|
|
472
684
|
return {
|
|
473
685
|
port: httpServer.port,
|
|
474
686
|
address: target,
|
|
687
|
+
get listening() {
|
|
688
|
+
return httpServer.listening;
|
|
689
|
+
},
|
|
475
690
|
close: async () => {
|
|
476
691
|
try {
|
|
477
|
-
await
|
|
692
|
+
await p2pClose(
|
|
478
693
|
node,
|
|
479
|
-
|
|
694
|
+
{
|
|
695
|
+
protocol: PIVOT_PROTOCOL,
|
|
696
|
+
listenAddress: selfListen,
|
|
697
|
+
targetAddress: target,
|
|
698
|
+
},
|
|
699
|
+
undefined,
|
|
480
700
|
fetcher,
|
|
481
701
|
).catch(() => {});
|
|
482
702
|
} finally {
|
|
@@ -490,8 +710,9 @@ export async function mountPivotReceiptServer(
|
|
|
490
710
|
node: KuboNode,
|
|
491
711
|
handler: PivotReceiptHandler,
|
|
492
712
|
fetcher: typeof fetch = fetch,
|
|
713
|
+
signal?: AbortSignal,
|
|
493
714
|
): Promise<PivotReceiptServer> {
|
|
494
|
-
return mountPivotServer(node, { receipt: handler }, fetcher);
|
|
715
|
+
return mountPivotServer(node, { receipt: handler }, fetcher, signal);
|
|
495
716
|
}
|
|
496
717
|
|
|
497
718
|
export async function withPivotP2pForward<T>(
|
|
@@ -578,6 +799,7 @@ export async function requestPivotReceiptOverP2p(
|
|
|
578
799
|
`Pivot receipt RPC returned non-JSON (HTTP ${response.status}).`,
|
|
579
800
|
);
|
|
580
801
|
}
|
|
802
|
+
|
|
581
803
|
if (!response.ok) {
|
|
582
804
|
const detail =
|
|
583
805
|
parsed &&
|
|
@@ -599,3 +821,39 @@ export async function requestPivotReceiptOverP2p(
|
|
|
599
821
|
},
|
|
600
822
|
);
|
|
601
823
|
}
|
|
824
|
+
|
|
825
|
+
export async function pivotReadinessOverP2p(
|
|
826
|
+
options: Parameters<typeof withPivotP2pForward>[0],
|
|
827
|
+
request?: PivotReplicateRequest,
|
|
828
|
+
): Promise<PivotStatus | { ready: true; headCid: string }> {
|
|
829
|
+
return withPivotP2pForward(options, async ({ host, port }) => {
|
|
830
|
+
const response = await (options.fetcher ?? fetch)(
|
|
831
|
+
`http://${host}:${port}/v1/${request ? "replicate" : "status"}`,
|
|
832
|
+
{
|
|
833
|
+
method: request ? "POST" : "GET",
|
|
834
|
+
headers: {
|
|
835
|
+
accept: "application/json",
|
|
836
|
+
"content-type": "application/json",
|
|
837
|
+
},
|
|
838
|
+
...(request ? { body: JSON.stringify(request) } : {}),
|
|
839
|
+
redirect: "error",
|
|
840
|
+
cache: "no-store",
|
|
841
|
+
signal: AbortSignal.any([
|
|
842
|
+
...(options.signal ? [options.signal] : []),
|
|
843
|
+
AbortSignal.timeout(request ? 150_000 : 15_000),
|
|
844
|
+
]),
|
|
845
|
+
},
|
|
846
|
+
);
|
|
847
|
+
const text = await boundedText(response);
|
|
848
|
+
if (!response.ok)
|
|
849
|
+
throw new HostError(
|
|
850
|
+
`Pivot ${request ? "replicate" : "status"} failed (HTTP ${response.status}): ${text.slice(0, 512)}. Ensure the Pivot runs a version supporting /v1/status and /v1/replicate.`,
|
|
851
|
+
);
|
|
852
|
+
const input: unknown = JSON.parse(text);
|
|
853
|
+
if (!request) return parsePivotStatus(input);
|
|
854
|
+
const result = object(input, "Pivot replicate response");
|
|
855
|
+
if (result.ready !== true || result.headCid !== request.headCid)
|
|
856
|
+
throw new HostError("Pivot did not confirm the requested HEAD.");
|
|
857
|
+
return { ready: true, headCid: request.headCid };
|
|
858
|
+
});
|
|
859
|
+
}
|
package/src/search-index.ts
CHANGED
|
@@ -538,6 +538,7 @@ export async function indexV7UnixfsSwarm(
|
|
|
538
538
|
};
|
|
539
539
|
|
|
540
540
|
await diffDirectory(oldRoot, newRoot, "", 0);
|
|
541
|
+
options.signal?.throwIfAborted();
|
|
541
542
|
const indexedAt = (options.now ?? (() => new Date().toISOString()))();
|
|
542
543
|
state.applySearchIndexDelta(configUrl, {
|
|
543
544
|
headCid: canonicalHead,
|
package/src/skill-definition.ts
CHANGED
|
@@ -25,9 +25,19 @@ export const skillType: BundleType = {
|
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
27
|
export const skillSchema = await encodeSchema(skillType);
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
export interface SkillMetadata {
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
license?: string;
|
|
33
|
+
compatibility?: string;
|
|
34
|
+
metadata?: Record<string, string>;
|
|
35
|
+
allowedTools?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function inspectSkillBundle(
|
|
29
39
|
bundle: Awaited<ReturnType<typeof openBundle>>,
|
|
30
|
-
): Promise<
|
|
40
|
+
): Promise<SkillMetadata> {
|
|
31
41
|
if (
|
|
32
42
|
bundle.schemaKey !== skillSchema.cid.toString() ||
|
|
33
43
|
bundle.manifest.entry !== "SKILL.md" ||
|
|
@@ -49,5 +59,37 @@ export async function skillIdentity(
|
|
|
49
59
|
metadata.name.length > 64
|
|
50
60
|
)
|
|
51
61
|
throw new HostError("Invalid Skill frontmatter name.");
|
|
52
|
-
|
|
62
|
+
if (
|
|
63
|
+
typeof metadata.description !== "string" ||
|
|
64
|
+
metadata.description.length === 0 ||
|
|
65
|
+
metadata.description.length > 1024
|
|
66
|
+
)
|
|
67
|
+
throw new HostError("Invalid Skill frontmatter description.");
|
|
68
|
+
const result: SkillMetadata = {
|
|
69
|
+
name: metadata.name,
|
|
70
|
+
description: metadata.description,
|
|
71
|
+
};
|
|
72
|
+
if (typeof metadata.license === "string") result.license = metadata.license;
|
|
73
|
+
if (typeof metadata.compatibility === "string")
|
|
74
|
+
result.compatibility = metadata.compatibility;
|
|
75
|
+
if (
|
|
76
|
+
metadata.metadata &&
|
|
77
|
+
typeof metadata.metadata === "object" &&
|
|
78
|
+
!Array.isArray(metadata.metadata)
|
|
79
|
+
) {
|
|
80
|
+
const entries = Object.entries(
|
|
81
|
+
metadata.metadata as Record<string, unknown>,
|
|
82
|
+
);
|
|
83
|
+
if (entries.every(([, value]) => typeof value === "string"))
|
|
84
|
+
result.metadata = Object.fromEntries(entries as [string, string][]);
|
|
85
|
+
}
|
|
86
|
+
if (typeof metadata["allowed-tools"] === "string")
|
|
87
|
+
result.allowedTools = metadata["allowed-tools"];
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function skillIdentity(
|
|
92
|
+
bundle: Awaited<ReturnType<typeof openBundle>>,
|
|
93
|
+
): Promise<string> {
|
|
94
|
+
return (await inspectSkillBundle(bundle)).name;
|
|
53
95
|
}
|
package/src/skill-source.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { fileURLToPath } from "node:url";
|
|
|
2
2
|
import { buffer } from "node:stream/consumers";
|
|
3
3
|
import { openBundle } from "@ipab/bundle";
|
|
4
4
|
import { readCar } from "./authoring.js";
|
|
5
|
-
import { skillIdentity } from "./skill-definition.js";
|
|
5
|
+
import { inspectSkillBundle, skillIdentity } from "./skill-definition.js";
|
|
6
6
|
|
|
7
7
|
async function loadSkill() {
|
|
8
8
|
const car = await readCar(
|
|
@@ -12,7 +12,13 @@ async function loadSkill() {
|
|
|
12
12
|
const bundle = await openBundle(car.root, { resolveCid: car.resolveCid });
|
|
13
13
|
if ((await skillIdentity(bundle)) !== "ipab")
|
|
14
14
|
throw new Error("IPAB Skill seed identity must be ipab.");
|
|
15
|
-
|
|
15
|
+
const metadata = await inspectSkillBundle(bundle);
|
|
16
|
+
return {
|
|
17
|
+
cid: car.root.toString(),
|
|
18
|
+
blocks: car.blocks,
|
|
19
|
+
bundle,
|
|
20
|
+
description: metadata.description,
|
|
21
|
+
};
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
export async function seedSkillSource() {
|
|
@@ -21,9 +27,9 @@ export async function seedSkillSource() {
|
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
export async function bundledSkillSource() {
|
|
24
|
-
const { cid, bundle } = await loadSkill();
|
|
30
|
+
const { cid, bundle, description } = await loadSkill();
|
|
25
31
|
const files = new Map<string, Uint8Array>();
|
|
26
32
|
for (const path of bundle.files)
|
|
27
33
|
files.set(path, await buffer(await bundle.readFile(path)));
|
|
28
|
-
return { cid, files };
|
|
34
|
+
return { cid, files, description };
|
|
29
35
|
}
|
package/src/skills.ts
CHANGED
|
@@ -30,17 +30,20 @@ import {
|
|
|
30
30
|
import {
|
|
31
31
|
swarmHeader,
|
|
32
32
|
swarmSkills,
|
|
33
|
+
swarmTypeSkills,
|
|
33
34
|
syncPivotReplicationAndIndex,
|
|
34
35
|
syncSwarmRegistry,
|
|
35
36
|
syncSwarmTemplates,
|
|
37
|
+
syncSwarmTypeSkills,
|
|
36
38
|
type SharedSkill,
|
|
37
39
|
type SwarmContext,
|
|
40
|
+
type TypeSkillAssociation,
|
|
38
41
|
} from "./swarm.js";
|
|
39
42
|
|
|
40
43
|
export const skillsInstaller = "skills@1.9.1";
|
|
41
44
|
export const bundledSkillOrigin = "bundled:ipab";
|
|
42
45
|
type Fingerprint = Record<string, string>;
|
|
43
|
-
interface Installation extends SharedSkill {
|
|
46
|
+
interface Installation extends Omit<SharedSkill, "description"> {
|
|
44
47
|
swarm: string;
|
|
45
48
|
path: string;
|
|
46
49
|
agents: string[];
|
|
@@ -585,6 +588,7 @@ export async function syncDaemonSwarm(
|
|
|
585
588
|
headCid: headerInfo.head?.root ?? null,
|
|
586
589
|
stateCid: headerInfo.stateCid ?? null,
|
|
587
590
|
skills: { status: "skipped", count: 0, error: null },
|
|
591
|
+
typeSkills: { status: "skipped", count: 0, error: null },
|
|
588
592
|
templates: { status: "skipped", count: 0, error: null },
|
|
589
593
|
registry: { status: "skipped", count: 0, error: null },
|
|
590
594
|
};
|
|
@@ -592,6 +596,7 @@ export async function syncDaemonSwarm(
|
|
|
592
596
|
for (const [label, task] of [
|
|
593
597
|
["pivot-index", () => syncPivotReplicationAndIndex(context, swarm, header)],
|
|
594
598
|
["skills", () => syncDaemonSkills(context, swarm, port, false)],
|
|
599
|
+
["typeSkills", () => syncSwarmTypeSkills(context, swarm, header)],
|
|
595
600
|
["templates", () => syncSwarmTemplates(context, swarm, header)],
|
|
596
601
|
["registry", () => syncSwarmRegistry(context, swarm, header)],
|
|
597
602
|
] as const) {
|
|
@@ -672,6 +677,35 @@ export interface SkillsResult {
|
|
|
672
677
|
}[];
|
|
673
678
|
ok: boolean;
|
|
674
679
|
}
|
|
680
|
+
export interface SkillsListResult extends SkillsResult {
|
|
681
|
+
typeSkills: TypeSkillAssociation[];
|
|
682
|
+
}
|
|
683
|
+
export async function listSwarmSkills(
|
|
684
|
+
context: SwarmContext,
|
|
685
|
+
swarm: string,
|
|
686
|
+
options: SkillsOptions,
|
|
687
|
+
port: SkillsPort = officialSkillsPort,
|
|
688
|
+
refresh?: { forceRefresh?: boolean },
|
|
689
|
+
): Promise<SkillsListResult> {
|
|
690
|
+
const result = await manageSkills(context, swarm, options, port);
|
|
691
|
+
const typeSkills = await swarmTypeSkills(context, swarm, {
|
|
692
|
+
mode: "local-first",
|
|
693
|
+
...(refresh?.forceRefresh !== undefined
|
|
694
|
+
? { forceRefresh: refresh.forceRefresh }
|
|
695
|
+
: {}),
|
|
696
|
+
});
|
|
697
|
+
return {
|
|
698
|
+
swarm: result.swarm,
|
|
699
|
+
installer: result.installer,
|
|
700
|
+
agents: result.agents,
|
|
701
|
+
dryRun: result.dryRun,
|
|
702
|
+
items: result.items,
|
|
703
|
+
typeSkills,
|
|
704
|
+
orphaned: result.orphaned,
|
|
705
|
+
results: result.results,
|
|
706
|
+
ok: result.ok,
|
|
707
|
+
};
|
|
708
|
+
}
|
|
675
709
|
export async function inspectBundledSkill(
|
|
676
710
|
source: Awaited<ReturnType<typeof bundledSkillSource>>,
|
|
677
711
|
port: SkillsPort,
|
|
@@ -818,7 +852,14 @@ export async function manageSkills(
|
|
|
818
852
|
await context.store.recoverOwner(owner, []);
|
|
819
853
|
const discovered =
|
|
820
854
|
"bundledSkill" in context
|
|
821
|
-
? [
|
|
855
|
+
? [
|
|
856
|
+
{
|
|
857
|
+
name: "ipab",
|
|
858
|
+
identity: "ipab",
|
|
859
|
+
cid: context.bundledSkill.cid,
|
|
860
|
+
description: context.bundledSkill.description,
|
|
861
|
+
},
|
|
862
|
+
]
|
|
822
863
|
: await swarmSkills(context, swarm, options.names, owner);
|
|
823
864
|
const items: SkillStatus[] = [];
|
|
824
865
|
const snapshots = new Map<string, Fingerprint | null>();
|