vit 0.5.1 → 0.6.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/package.json +4 -1
- package/src/cmd/ship.js +18 -23
- package/src/lib/cap.js +73 -0
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Social toolkit for personalized software",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
7
7
|
"vit": "bin/vit.js"
|
|
8
8
|
},
|
|
9
|
+
"exports": {
|
|
10
|
+
"./cap.js": "./src/lib/cap.js"
|
|
11
|
+
},
|
|
9
12
|
"files": [
|
|
10
13
|
"bin/",
|
|
11
14
|
"src/",
|
package/src/cmd/ship.js
CHANGED
|
@@ -17,6 +17,7 @@ import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
|
17
17
|
import { toBeacon } from '../lib/beacon.js';
|
|
18
18
|
import { hashTo3Words } from '../lib/cap-ref.js';
|
|
19
19
|
import { formatError } from '../lib/error-format.js';
|
|
20
|
+
import { publishCap } from '../lib/cap.js';
|
|
20
21
|
|
|
21
22
|
const STOP_WORDS = new Set([
|
|
22
23
|
'a', 'an', 'the', 'and', 'or', 'but', 'in', 'on', 'at', 'to', 'for',
|
|
@@ -345,7 +346,7 @@ async function shipSkill(opts) {
|
|
|
345
346
|
}
|
|
346
347
|
}
|
|
347
348
|
|
|
348
|
-
async function shipCap(opts) {
|
|
349
|
+
export async function shipCap(opts) {
|
|
349
350
|
const gate = requireAgent();
|
|
350
351
|
if (!gate.ok) {
|
|
351
352
|
if (opts.json) {
|
|
@@ -548,28 +549,21 @@ async function shipCap(opts) {
|
|
|
548
549
|
}
|
|
549
550
|
}
|
|
550
551
|
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
|
|
552
|
+
const rkey = TID.nextStr();
|
|
553
|
+
if (verbose) vlog(`[verbose] Record built, rkey: ${rkey}`);
|
|
554
|
+
if (verbose) vlog(`[verbose] putRecord ${CAP_COLLECTION} rkey=${rkey}`);
|
|
555
|
+
const { uri, cid, record, response } = await publishCap(agent, {
|
|
556
|
+
repo: did,
|
|
557
|
+
text,
|
|
554
558
|
title: opts.title,
|
|
555
559
|
description: opts.description,
|
|
556
560
|
ref,
|
|
557
561
|
createdAt: now,
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
if (opts.recap) record.recap = { uri: recapUri, ref: opts.recap };
|
|
562
|
-
const rkey = TID.nextStr();
|
|
563
|
-
if (verbose) vlog(`[verbose] Record built, rkey: ${rkey}`);
|
|
564
|
-
const putArgs = {
|
|
565
|
-
repo: did,
|
|
566
|
-
collection: CAP_COLLECTION,
|
|
562
|
+
beacon,
|
|
563
|
+
kind: opts.kind,
|
|
564
|
+
recap: opts.recap ? { uri: recapUri, ref: opts.recap } : undefined,
|
|
567
565
|
rkey,
|
|
568
|
-
|
|
569
|
-
validate: false,
|
|
570
|
-
};
|
|
571
|
-
if (verbose) vlog(`[verbose] putRecord ${putArgs.collection} rkey=${rkey}`);
|
|
572
|
-
const putRes = await agent.com.atproto.repo.putRecord(putArgs);
|
|
566
|
+
});
|
|
573
567
|
try {
|
|
574
568
|
appendLog('caps.jsonl', {
|
|
575
569
|
ts: now,
|
|
@@ -578,15 +572,15 @@ async function shipCap(opts) {
|
|
|
578
572
|
ref,
|
|
579
573
|
collection: CAP_COLLECTION,
|
|
580
574
|
pds: session.serverMetadata?.issuer,
|
|
581
|
-
uri
|
|
582
|
-
cid
|
|
575
|
+
uri,
|
|
576
|
+
cid,
|
|
583
577
|
});
|
|
584
578
|
} catch (logErr) {
|
|
585
579
|
console.error('warning: failed to write caps.jsonl:', logErr.message);
|
|
586
580
|
}
|
|
587
581
|
if (verbose) vlog(`[verbose] Log written to caps.jsonl`);
|
|
588
582
|
if (opts.json) {
|
|
589
|
-
const out = { ref, uri
|
|
583
|
+
const out = { ref, uri };
|
|
590
584
|
if (opts.kind) out.kind = opts.kind;
|
|
591
585
|
jsonOk(out);
|
|
592
586
|
return;
|
|
@@ -597,16 +591,17 @@ async function shipCap(opts) {
|
|
|
597
591
|
console.log(`anyone can implement this. share the ref to build demand.`);
|
|
598
592
|
} else {
|
|
599
593
|
console.log(`shipped: ${ref}`);
|
|
600
|
-
console.log(`uri: ${
|
|
594
|
+
console.log(`uri: ${uri}`);
|
|
601
595
|
}
|
|
602
596
|
if (verbose) {
|
|
597
|
+
const putArgs = { repo: did, collection: CAP_COLLECTION, rkey, record, validate: false };
|
|
603
598
|
vlog(
|
|
604
599
|
JSON.stringify({
|
|
605
600
|
ts: now,
|
|
606
601
|
pds: session.serverMetadata?.issuer,
|
|
607
602
|
xrpc: 'com.atproto.repo.putRecord',
|
|
608
603
|
request: putArgs,
|
|
609
|
-
response
|
|
604
|
+
response,
|
|
610
605
|
}),
|
|
611
606
|
);
|
|
612
607
|
}
|
package/src/lib/cap.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { TID } from '@atproto/common-web';
|
|
5
|
+
import { CAP_COLLECTION } from './constants.js';
|
|
6
|
+
import { resolveRef } from './cap-ref.js';
|
|
7
|
+
|
|
8
|
+
export async function publishCap(agent, input) {
|
|
9
|
+
if (input.repo == null || input.repo !== agent.did) {
|
|
10
|
+
throw new Error('write target must match authenticated agent');
|
|
11
|
+
}
|
|
12
|
+
if (input.swapCid != null && input.rkey == null) {
|
|
13
|
+
throw new Error('swap CID requires an rkey');
|
|
14
|
+
}
|
|
15
|
+
if (input.reply) {
|
|
16
|
+
const { root, parent } = input.reply;
|
|
17
|
+
if (
|
|
18
|
+
!root
|
|
19
|
+
|| !parent
|
|
20
|
+
|| typeof root.uri !== 'string'
|
|
21
|
+
|| typeof root.cid !== 'string'
|
|
22
|
+
|| typeof parent.uri !== 'string'
|
|
23
|
+
|| typeof parent.cid !== 'string'
|
|
24
|
+
) {
|
|
25
|
+
throw new Error('reply must include valid root and parent references');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (input.embed) {
|
|
29
|
+
const external = input.embed.external;
|
|
30
|
+
if (
|
|
31
|
+
!external
|
|
32
|
+
|| typeof external.uri !== 'string'
|
|
33
|
+
|| typeof external.title !== 'string'
|
|
34
|
+
|| typeof external.description !== 'string'
|
|
35
|
+
) {
|
|
36
|
+
throw new Error('embed must include a valid external value');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const record = {
|
|
41
|
+
$type: CAP_COLLECTION,
|
|
42
|
+
text: input.text || '',
|
|
43
|
+
title: input.title,
|
|
44
|
+
description: input.description,
|
|
45
|
+
ref: input.ref,
|
|
46
|
+
createdAt: input.createdAt,
|
|
47
|
+
};
|
|
48
|
+
if (input.beacon) record.beacon = input.beacon;
|
|
49
|
+
if (input.kind) record.kind = input.kind;
|
|
50
|
+
if (input.recap) record.recap = input.recap;
|
|
51
|
+
if (input.reply) record.reply = input.reply;
|
|
52
|
+
if (input.embed) record.embed = input.embed;
|
|
53
|
+
|
|
54
|
+
const rkey = input.rkey ?? TID.nextStr();
|
|
55
|
+
const putArgs = {
|
|
56
|
+
repo: input.repo,
|
|
57
|
+
collection: CAP_COLLECTION,
|
|
58
|
+
rkey,
|
|
59
|
+
record,
|
|
60
|
+
validate: false,
|
|
61
|
+
};
|
|
62
|
+
if (input.swapCid != null) putArgs.swapRecord = input.swapCid;
|
|
63
|
+
|
|
64
|
+
const putRes = await agent.com.atproto.repo.putRecord(putArgs);
|
|
65
|
+
return {
|
|
66
|
+
uri: putRes.data.uri,
|
|
67
|
+
cid: putRes.data.cid,
|
|
68
|
+
ref: resolveRef(record, putRes.data.cid),
|
|
69
|
+
rkey,
|
|
70
|
+
record,
|
|
71
|
+
response: putRes.data,
|
|
72
|
+
};
|
|
73
|
+
}
|