@coda-console/friends 0.5.0 → 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.
@@ -0,0 +1,43 @@
1
+ // 由 Accord 公钥派生展示昵称(算法见 coda#3040):浏览器与 Node 通用,只用纯 JS 与 Uint8Array,不碰 Buffer 或 node:*。
2
+
3
+ const AUTHOR = /^ed25519:([0-9a-f]{64})$/;
4
+ const GROUPS = 36;
5
+
6
+ /** 密钥的短码:`ed25519:` 之后的前 8 位(没有就空串)。 */
7
+ export function shortAuthor(author) {
8
+ const match = AUTHOR.exec(author ?? '');
9
+ return match ? match[1].slice(0, 8) : '';
10
+ }
11
+
12
+ /**
13
+ * 32 字节公钥的昵称:256 位从第 0 字节最高位起每 7 位一组,至多 36 组。0–77 是字母(v % 26),78–87 是数字,
14
+ * 88–127 是结束符:已有不足 2 位时跳过,够 2 位就结束。读完仍不足 2 位给空串。
15
+ */
16
+ export function nicknameOf(key) {
17
+ let name = '';
18
+ for (let group = 0; group < GROUPS; group++) {
19
+ let v = 0;
20
+ for (let bit = group * 7; bit < group * 7 + 7; bit++) v = (v << 1) | ((key[bit >> 3] >> (7 - (bit & 7))) & 1);
21
+ if (v < 78) name += String.fromCharCode(97 + (v % 26));
22
+ else if (v < 88) name += String(v - 78);
23
+ else if (name.length >= 2) return name;
24
+ }
25
+ return name.length >= 2 ? name : '';
26
+ }
27
+
28
+ /** 32 字节公钥按大端无符号整数转成十进制,左侧补零到 78 位。 */
29
+ export const tailOf = key => BigInt(`0x${[...key].map(byte => byte.toString(16).padStart(2, '0')).join('')}`).toString().padStart(78, '0');
30
+
31
+ /**
32
+ * 好友与本机身份的展示名:合法公钥且解得出昵称给 `昵称 #尾号`(尾号是 tail 的末 4 位);合法公钥解不出昵称给公钥短码;
33
+ * 没有合法公钥(如待互认的好友)给 fallbackNode。
34
+ */
35
+ export function identityTitle(author, fallbackNode = '') {
36
+ const hex = AUTHOR.exec(author ?? '')?.[1];
37
+ if (hex) {
38
+ const key = Uint8Array.from({ length: 32 }, (_, i) => parseInt(hex.slice(i * 2, i * 2 + 2), 16));
39
+ const name = nicknameOf(key);
40
+ return name ? `${name} #${tailOf(key).slice(-4)}` : shortAuthor(author);
41
+ }
42
+ return fallbackNode;
43
+ }
package/lib/outbox.mjs CHANGED
@@ -4,8 +4,8 @@
4
4
  import { createHash } from 'node:crypto';
5
5
  import { readJson, writeJson } from './json-file.mjs';
6
6
 
7
- /** 网关不替业务发布、撤回的类型:好友关系、名片等 Accord 自己的记录。 */
8
- export const RESERVED_KINDS = new Set(['binding', 'profile', 'friends', 'coda/profile', 'coda/friends']);
7
+ /** 网关不替业务发布、撤回的类型:好友关系、名片等 Accord 自己的记录;friends/card 是已下线的旧名片,封住旧写路径。 */
8
+ export const RESERVED_KINDS = new Set(['binding', 'profile', 'friends', 'coda/profile', 'coda/friends', 'friends/card']);
9
9
  export const MAX_ID_CHARS = 200, MAX_ID_BYTES = 256, MAX_BODY_BYTES = 65536, MAX_AUDIENCE = 500;
10
10
  const KIND = /^[a-z][a-z0-9-]{0,63}(?:\/[a-z][a-z0-9-]{0,63})?$/;
11
11
  const AUDIENCE = /^(?:public|ed25519:[0-9a-f]{64})$/;
@@ -62,8 +62,7 @@ export const canonicalHash = value => createHash('sha256').update(JSON.stringify
62
62
  // 不同作者对同一个 (kind, id) 排下的待撤互不相干,也不挡着对方撤自己的记录。
63
63
  // 每次写入发布或撤回的意图都领一个递增的整数 `seq`(落在条目里,不看系统时钟):冲洗按它的先后执行,并据它判断旧撤回是否已被更晚的发布取代。
64
64
  // 待发 { seq, kind, id, desired: 'publish', state: queued|paused|no_identity|needs_cert, body, audience, hash, lastError?, + 上次同步的元数据 }
65
- // 已同步 { seq, kind, id, desired: 'publish', state: 'synced', hash, audience, lastAuthor, lastSyncedHash, lastSyncedAt, lastCreatedAt? }(没有 body;
66
- // lastCreatedAt 是 body.createdAt,同一 id 重试时沿用它,不必再查 Accord)
65
+ // 已同步 { seq, kind, id, desired: 'publish', state: 'synced', hash, audience, lastAuthor, lastSyncedHash, lastSyncedAt }(没有 body)
67
66
  // 待撤 { seq, kind, id, desired: 'retract', state: queued|no_identity|needs_cert, targetAuthor, lastError?, + 上次同步的元数据 }
68
67
  // targetAuthor 是排队时的作者:换了作者就不再替新作者撤,等原作者回来
69
68
  // 被拒 { …, state: 'error', lastError }:Accord 明确拒绝,不再自动重试;下一次发布或撤回同一条会替换它
@@ -97,12 +96,10 @@ export function withState(entry, state, error) {
97
96
  return { ...rest, state, ...(error ? { lastError: error } : {}) };
98
97
  }
99
98
 
100
- /** 发布成功:释放 body,只留 `{ seq, kind, id, desired, state: 'synced', hash, audience, lastAuthor, lastSyncedHash, lastSyncedAt }`,body 有合法的 createdAt 再留 `lastCreatedAt`。 */
101
- export const markSynced = (entry, author, now) => {
102
- const createdAt = entry.body?.createdAt;
103
- return { seq: entry.seq, kind: entry.kind, id: entry.id, desired: 'publish', state: 'synced', hash: entry.hash, audience: entry.audience, lastAuthor: author, lastSyncedHash: entry.hash,
104
- lastSyncedAt: now, ...(Number.isSafeInteger(createdAt) && createdAt >= 0 ? { lastCreatedAt: createdAt } : {}) };
105
- };
99
+ /** 发布成功:释放 body,只留 `{ seq, kind, id, desired, state: 'synced', hash, audience, lastAuthor, lastSyncedHash, lastSyncedAt }`。 */
100
+ export const markSynced = (entry, author, now) =>
101
+ ({ seq: entry.seq, kind: entry.kind, id: entry.id, desired: 'publish', state: 'synced', hash: entry.hash, audience: entry.audience, lastAuthor: author, lastSyncedHash: entry.hash,
102
+ lastSyncedAt: now });
106
103
 
107
104
  /** Accord 明确拒绝:不再留 body 和 audience,只留元数据与原因。 */
108
105
  export const markRejected = (entry, message) =>
@@ -118,16 +115,21 @@ export function holdState(entry, certState, pausedKinds) {
118
115
 
119
116
  /**
120
117
  * 读出整张表 `{ 键: 条目 }`(磁盘上是 `{ seq, entries }`,旧版是直接平铺的条目);键按条目内容重新规范(兼容旧键名),
121
- * 缺失、损坏、条目不成样子的都丢掉。序号计数器取顶层 `seq` 与现存条目最大序号中较大的。
118
+ * 缺失、损坏、条目不成样子的都丢掉;保留类型(含旧版残留的 friends/card)的条目也丢掉,丢了的个数记在表上不可枚举的 `dropped`,
119
+ * 由冲洗落盘清理。序号计数器取顶层 `seq` 与现存条目最大序号中较大的。
122
120
  */
123
121
  export async function readOutbox(dir) {
124
122
  const parsed = await readJson(dir, 'outbox.json'), entries = withSeq({}, 0);
125
123
  if (!isPlain(parsed)) return entries;
124
+ let dropped = 0;
126
125
  const stored = isPlain(parsed.entries) ? parsed.entries : parsed;
127
126
  for (const entry of Object.values(stored)) {
128
127
  if (isPlain(entry) && typeof entry.kind === 'string' && typeof entry.id === 'string' && ['publish', 'retract'].includes(entry.desired) && typeof entry.state === 'string'
129
- && (entry.desired === 'publish' || typeof entry.targetAuthor === 'string')) entries[keyOf(entry)] = entry;
128
+ && (entry.desired === 'publish' || typeof entry.targetAuthor === 'string')) {
129
+ if (RESERVED_KINDS.has(entry.kind)) dropped++; else entries[keyOf(entry)] = entry;
130
+ }
130
131
  }
132
+ Object.defineProperty(entries, 'dropped', { value: dropped });
131
133
  return withSeq(entries, Math.max(Number.isSafeInteger(parsed.seq) ? parsed.seq : 0, ...Object.values(entries).map(entry => entry.seq ?? 0)));
132
134
  }
133
135
 
@@ -1,7 +1,7 @@
1
- // 好友页按「视图里的每台电脑」读数据的纯逻辑:成员列表、按身份合并名片、按电脑分节。不碰 Coda 的 Node API;页面和单测都加载它。
1
+ // 好友页按「视图里的每台电脑」读数据的纯逻辑:成员列表、按身份归组、按电脑分节。不碰 Coda 的 Node API;页面和单测都加载它。
2
2
  // 页面不自己选机器:App 的全局视图里有哪几台,页面就读哪几台。
3
3
 
4
- import { certStateOf, mergeFriendRows, mergeProfileAndCard, readCardRecord, readProfileRecord } from './friends.mjs';
4
+ import { certStateOf, mergeFriendRows } from './friends.mjs';
5
5
 
6
6
  /** 视图里的成员(去重、保持 coda.machines 的顺序);`unreachable` 是读不到的原因,可达的为 null。 */
7
7
  export function listMembers(coda) {
@@ -11,16 +11,9 @@ export function listMembers(coda) {
11
11
  .map(m => ({ id: m.id, name: m.name || m.id, unreachable: m.unreachable ? (m.unreachable === true ? '暂时连不上' : String(m.unreachable)) : null }));
12
12
  }
13
13
 
14
- // 一个身份的几台电脑里,某种名片记录(profile 或 friends/card)版本最高的那条,记下是哪台读到的;版本相同取视图里靠前的。
15
- const newest = (members, records, read, author) => members
16
- .flatMap(m => m[records].map(read).filter(card => card && card.author === author).map(card => ({ ...card, from: m.id })))
17
- .reduce((best, one) => (best && best.version >= one.version ? best : one), null);
18
-
19
14
  /**
20
15
  * 按 `author` 把读到了的成员分组(没有身份的电脑归在 author 为 null 一组;Accord 没读到的成员不参与),组的顺序是成员第一次出现的顺序。
21
- * 每组一张名片:几台读到的不一样(同步有先后)时,profile 与 friends/card 各取版本最高的一条,再按 mergeProfileAndCard 合成;
22
- * `from` 是提供头像那条记录的电脑(头像没写就是提供名字的那条)。不逐字段比对。
23
- * `signer` 是改名片时发往的那一台:组里第一台能签名(证书可用)的,没有就是组里第一台。
16
+ * `signer` 是代表这个身份证书状态的那一台:组里第一台能签名(证书可用)的,没有就是组里第一台。
24
17
  */
25
18
  export function identities(members) {
26
19
  const groups = new Map();
@@ -28,12 +21,7 @@ export function identities(members) {
28
21
  if (!groups.has(member.author)) groups.set(member.author, []);
29
22
  groups.get(member.author).push(member);
30
23
  }
31
- return [...groups].map(([author, group]) => {
32
- const profile = newest(group, 'profiles', readProfileRecord, author), card = newest(group, 'cards', readCardRecord, author);
33
- const merged = mergeProfileAndCard(profile, card);
34
- const source = [profile, card].find(one => one?.avatarPresent) ?? profile ?? card;
35
- return { author, members: group, card: merged && { ...merged, from: source.from }, signer: group.find(m => certStateOf(m.entry) === 'active') ?? group[0] };
36
- });
24
+ return [...groups].map(([author, group]) => ({ author, members: group, signer: group.find(m => certStateOf(m.entry) === 'active') ?? group[0] }));
37
25
  }
38
26
 
39
27
  /**
@@ -45,6 +33,6 @@ export function friendSections(members) {
45
33
  member,
46
34
  title: members.length > 1 ? member.name : null,
47
35
  unreachable: member.unreachable || member.accordProblem || null,
48
- rows: member.unreachable || member.accordProblem ? [] : mergeFriendRows({ friends: member.friends, profiles: member.profiles, cards: member.cards, notes: member.notes }),
36
+ rows: member.unreachable || member.accordProblem ? [] : mergeFriendRows(member.friends),
49
37
  }));
50
38
  }
package/main.mjs CHANGED
@@ -1,38 +1,13 @@
1
- // 好友插件的模块(Coda 的 docs/plugins.md「插件宿主」)。好友页自己的 Accord 读写在页面里发起(页面用自己的 coda.query /
2
- // coda.call / coda.watch);模块管两件事:
3
- // - 好友的本地备注:存在插件自己的持久目录 notes.json 里,不外发,页面通过视图消息读写,
4
- // 也能用 `coda self notes.list|notes.set|notes.delete` 读写;
5
- // - 业务无关的社交网关 friends/social@1(lib/gateway.mjs):别的插件经它读好友、发布与撤回记录,全部透传 coda/accord@1;
6
- // 发布策略用 `coda self policy.get|policy.setKind` 读写。
1
+ // 好友插件的模块(Coda 的 docs/plugins.md「插件宿主」)。好友页自己的 Accord 读写在页面里发起(页面用自己的 coda.watch /
2
+ // coda.call);模块只管业务无关的社交网关 friends/social@1(lib/gateway.mjs):别的插件经它读好友、发布与撤回记录,
3
+ // 全部透传 coda/accord@1;发布策略用 `coda self policy.get|policy.setKind` 读写。
7
4
  import { createGateway } from './lib/gateway.mjs';
8
- import { deleteNote, readNotes, setNote } from './lib/notes.mjs';
9
5
 
10
- let dir = null, gateway = null;
6
+ let gateway = null;
11
7
  const handles = [];
12
8
 
13
9
  export async function activate(coda) {
14
- dir = coda.plugin.state;
15
- const actions = {
16
- 'notes.list': () => readNotes(dir),
17
- 'notes.set': ({ node, note } = {}) => setNote(dir, node, note),
18
- 'notes.delete': ({ node } = {}) => deleteNote(dir, node),
19
- };
20
- const run = (name, input) => {
21
- if (!dir) throw new Error('这台机器没有插件状态目录,备注存不下');
22
- return actions[name](input);
23
- };
24
- for (const name of Object.keys(actions)) handles.push(coda.self.handle(name, input => run(name, input ?? {})));
25
- coda.views.register('friends', {
26
- open(view) {
27
- view.onMessage(async message => {
28
- const name = message?.type;
29
- if (!Object.hasOwn(actions, name) || typeof message.rid !== 'string') return;
30
- try { view.postMessage({ type: 'reply', rid: message.rid, ok: true, value: await run(name, message) }); }
31
- catch (e) { view.postMessage({ type: 'reply', rid: message.rid, ok: false, error: String(e?.message ?? e) }); }
32
- });
33
- },
34
- });
35
- gateway = createGateway(coda, dir);
10
+ gateway = createGateway(coda, coda.plugin.state);
36
11
  for (const [name, fn] of Object.entries(gateway.policy)) handles.push(coda.self.handle(name, input => fn(input ?? {})));
37
12
  await gateway.start();
38
13
  }
@@ -41,5 +16,4 @@ export function deactivate() {
41
16
  gateway?.stop();
42
17
  gateway = null;
43
18
  for (const handle of handles.splice(0)) handle?.dispose?.();
44
- dir = null;
45
19
  }
package/package.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@coda-console/friends",
3
3
  "id": "friends",
4
4
  "displayName": "好友",
5
- "description": "管理 Accord 身份、个人名片与熟人好友通道",
5
+ "description": "管理 Accord 身份与熟人好友通道,并提供业务无关的好友网关",
6
6
  "icon": { "symbol": "person.2.fill", "color": "blue" },
7
- "version": "0.5.0",
7
+ "version": "0.6.0",
8
8
  "categories": [
9
9
  "Skills 与工具"
10
10
  ],
@@ -40,7 +40,7 @@
40
40
  {
41
41
  "name": "friends/social@1",
42
42
  "title": "好友社交网关",
43
- "description": "业务无关的好友网关:读好友与好友分享的记录,向好友发布、撤回记录,设置可代签的社交名片 friends/card,发私信 friends/dm、好友动态 friends/feed,并以 dm、feed 两条帧流实时跟随;签名与记录全部透传 coda/accord@1,没有身份或证书过期时在本机排队,恢复后自动补发。",
43
+ "description": "业务无关的好友网关:读好友与好友分享的记录,向好友发布、撤回记录;签名与记录全部透传 coda/accord@1,没有身份或证书过期时在本机排队,恢复后自动补发。",
44
44
  "spec": {
45
45
  "type": "object",
46
46
  "properties": { "version": { "const": 1 } },
@@ -73,10 +73,9 @@
73
73
  "properties": {
74
74
  "selfAuthor": { "type": ["string", "null"] },
75
75
  "certState": { "enum": ["no_identity", "needs_cert", "active"] },
76
- "friends": { "type": "array", "items": { "type": "object" } },
77
- "truncated": { "type": "boolean" }
76
+ "friends": { "type": "array", "items": { "type": "object" } }
78
77
  },
79
- "required": ["selfAuthor", "certState", "friends", "truncated"],
78
+ "required": ["selfAuthor", "certState", "friends"],
80
79
  "additionalProperties": false
81
80
  }
82
81
  },
@@ -136,145 +135,6 @@
136
135
  "additionalProperties": false
137
136
  }
138
137
  },
139
- "set-card": {
140
- "idempotent": true,
141
- "input": {
142
- "type": "object",
143
- "properties": {
144
- "name": { "type": "string", "minLength": 1, "maxLength": 40 },
145
- "emoji": { "type": "string", "maxLength": 8 },
146
- "color": { "enum": ["blue", "orange", "green", "purple", "pink", "teal", "gray"] },
147
- "avatar": {
148
- "anyOf": [
149
- {
150
- "type": "object",
151
- "description": "内容寻址的图片指针(BlobPointer):path 只收 content/<sha256>,sha256 须与 path 里的一致",
152
- "properties": {
153
- "owner": { "type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" },
154
- "path": { "type": "string", "pattern": "^content/[0-9a-f]{64}$" },
155
- "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
156
- "mime": { "type": "string", "minLength": 1, "maxLength": 128 },
157
- "size": { "type": "integer", "minimum": 0, "maximum": 5242880 },
158
- "name": { "type": "string", "minLength": 1, "maxLength": 200 }
159
- },
160
- "required": ["owner", "path", "sha256"],
161
- "additionalProperties": false
162
- },
163
- { "type": "null" }
164
- ]
165
- }
166
- },
167
- "required": ["name"],
168
- "additionalProperties": false
169
- },
170
- "result": {
171
- "type": "object",
172
- "properties": {
173
- "state": { "enum": ["synced", "queued", "paused", "no_identity", "needs_cert", "error"] },
174
- "skipped": { "type": "boolean" },
175
- "author": { "type": ["string", "null"] },
176
- "version": { "type": "integer", "minimum": 0 },
177
- "error": { "type": "string" }
178
- },
179
- "required": ["state"],
180
- "additionalProperties": false
181
- }
182
- },
183
- "send-dm": {
184
- "idempotent": true,
185
- "input": {
186
- "type": "object",
187
- "properties": {
188
- "to": { "type": "string", "pattern": "^ed25519:[0-9a-f]{64}$" },
189
- "id": { "type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[^\\u0000-\\u001f\\u007f-\\u009f]*[^\\s\\u0000-\\u001f\\u007f-\\u009f][^\\u0000-\\u001f\\u007f-\\u009f]*$", "description": "至多 200 个字符且 UTF-8 至多 256 字节,不含控制字符,去首尾空白后不能为空;省略由网关生成 UUID" },
190
- "text": { "type": "string", "maxLength": 8000, "description": "至多 8000 个字符(码点,按原样计,含首尾空白),发布时去首尾空白" },
191
- "attachments": {
192
- "type": "array",
193
- "minItems": 1,
194
- "maxItems": 4,
195
- "items": {
196
- "type": "object",
197
- "description": "内容寻址的图片指针(BlobPointer):path 只收 content/<sha256>,sha256 须与 path 里的一致",
198
- "properties": {
199
- "owner": { "type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" },
200
- "path": { "type": "string", "pattern": "^content/[0-9a-f]{64}$" },
201
- "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
202
- "mime": { "type": "string", "minLength": 1, "maxLength": 128 },
203
- "size": { "type": "integer", "minimum": 0, "maximum": 5242880 },
204
- "name": { "type": "string", "minLength": 1, "maxLength": 200 }
205
- },
206
- "required": ["owner", "path", "sha256"],
207
- "additionalProperties": false
208
- }
209
- },
210
- "replyTo": { "type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[^\\u0000-\\u001f\\u007f-\\u009f]*[^\\s\\u0000-\\u001f\\u007f-\\u009f][^\\u0000-\\u001f\\u007f-\\u009f]*$", "description": "所回复私信的 id:与 id 同样至多 200 个字符且 UTF-8 至多 256 字节,不含控制字符" }
211
- },
212
- "required": ["to"],
213
- "additionalProperties": false
214
- },
215
- "result": {
216
- "type": "object",
217
- "properties": {
218
- "state": { "enum": ["synced", "queued", "paused", "no_identity", "needs_cert", "error"] },
219
- "id": { "type": "string" },
220
- "skipped": { "type": "boolean" },
221
- "author": { "type": ["string", "null"] },
222
- "version": { "type": "integer", "minimum": 0 },
223
- "error": { "type": "string" }
224
- },
225
- "required": ["state"],
226
- "additionalProperties": false
227
- }
228
- },
229
- "post-feed": {
230
- "idempotent": true,
231
- "input": {
232
- "type": "object",
233
- "properties": {
234
- "id": { "type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[^\\u0000-\\u001f\\u007f-\\u009f]*[^\\s\\u0000-\\u001f\\u007f-\\u009f][^\\u0000-\\u001f\\u007f-\\u009f]*$", "description": "至多 200 个字符且 UTF-8 至多 256 字节,不含控制字符,去首尾空白后不能为空;省略由网关生成 UUID" },
235
- "text": { "type": "string", "maxLength": 8000, "description": "至多 8000 个字符(码点,按原样计,含首尾空白),发布时去首尾空白" },
236
- "media": {
237
- "type": "array",
238
- "minItems": 1,
239
- "maxItems": 4,
240
- "items": {
241
- "type": "object",
242
- "description": "内容寻址的图片指针(BlobPointer):path 只收 content/<sha256>,sha256 须与 path 里的一致",
243
- "properties": {
244
- "owner": { "type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" },
245
- "path": { "type": "string", "pattern": "^content/[0-9a-f]{64}$" },
246
- "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
247
- "mime": { "type": "string", "minLength": 1, "maxLength": 128 },
248
- "size": { "type": "integer", "minimum": 0, "maximum": 5242880 },
249
- "name": { "type": "string", "minLength": 1, "maxLength": 200 }
250
- },
251
- "required": ["owner", "path", "sha256"],
252
- "additionalProperties": false
253
- }
254
- },
255
- "audience": {
256
- "type": "array",
257
- "items": { "type": "string", "pattern": "^(?:public|ed25519:[0-9a-f]{64})$" },
258
- "minItems": 1,
259
- "maxItems": 500
260
- }
261
- },
262
- "additionalProperties": false
263
- },
264
- "result": {
265
- "type": "object",
266
- "properties": {
267
- "state": { "enum": ["synced", "queued", "paused", "no_identity", "needs_cert", "error"] },
268
- "id": { "type": "string" },
269
- "skipped": { "type": "boolean" },
270
- "author": { "type": ["string", "null"] },
271
- "version": { "type": "integer", "minimum": 0 },
272
- "error": { "type": "string" }
273
- },
274
- "required": ["state"],
275
- "additionalProperties": false
276
- }
277
- },
278
138
  "retract": {
279
139
  "idempotent": true,
280
140
  "input": {
@@ -335,37 +195,9 @@
335
195
  }
336
196
  }
337
197
  },
338
- "streams": {
339
- "dm": {
340
- "shape": "read",
341
- "frames": true,
342
- "description": "私信的实时帧流:首帧 { type: 'snapshot', cursor, items }(按 createdAt 升序),之后每次变化一帧 { type: 'upsert', cursor, item } 或 { type: 'retract', cursor, author, id, peer };peer 只看与这位好友的私信,after 给上次的 cursor 只补增量,续不上回到快照",
343
- "input": {
344
- "type": "object",
345
- "properties": {
346
- "peer": { "type": "string", "pattern": "^ed25519:[0-9a-f]{64}$" },
347
- "after": { "type": "string", "minLength": 1, "maxLength": 128 }
348
- },
349
- "additionalProperties": false
350
- }
351
- },
352
- "feed": {
353
- "shape": "read",
354
- "frames": true,
355
- "description": "好友动态的实时帧流:首帧 { type: 'snapshot', cursor, items }(按 createdAt 降序),之后每次变化一帧 { type: 'upsert', cursor, item } 或 { type: 'retract', cursor, author, id };author 只看这一位的,after 给上次的 cursor 只补增量,续不上回到快照",
356
- "input": {
357
- "type": "object",
358
- "properties": {
359
- "author": { "type": "string", "pattern": "^ed25519:[0-9a-f]{64}$" },
360
- "after": { "type": "string", "minLength": 1, "maxLength": 128 }
361
- },
362
- "additionalProperties": false
363
- }
364
- }
365
- },
366
198
  "permissions": {
367
- "read": { "title": "查看好友列表、读取好友分享的记录与实时私信、动态", "read": true, "operations": ["friends", "records"], "streams": ["dm", "feed"] },
368
- "publish": { "title": "通过好友网关发布、撤回记录、设置社交名片、发私信与动态、查看待发队列", "operations": ["publish", "set-card", "send-dm", "post-feed", "retract", "outbox"] }
199
+ "read": { "title": "查看好友列表、读取好友分享的记录", "read": true, "operations": ["friends", "records"] },
200
+ "publish": { "title": "通过好友网关发布、撤回记录、查看待发队列", "operations": ["publish", "retract", "outbox"] }
369
201
  }
370
202
  }
371
203
  ],