@celljs/ta-sync 4.17.0 → 4.19.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/host/index.mjs CHANGED
@@ -2381,6 +2381,87 @@ function writeStream(stream, bytes) {
2381
2381
  });
2382
2382
  }
2383
2383
 
2384
+ // web-src/sync-account.ts
2385
+ class SyncAccount {
2386
+ options;
2387
+ identities = new Set;
2388
+ told = new Map;
2389
+ tried = new Set;
2390
+ timer;
2391
+ stopHearing;
2392
+ running;
2393
+ constructor(options) {
2394
+ this.options = options;
2395
+ }
2396
+ start() {
2397
+ this.stopHearing = this.options.account.onTold((_from, value) => void this.heard(value));
2398
+ this.timer = setInterval(() => void this.round(), this.options.every ?? 30000);
2399
+ this.round();
2400
+ }
2401
+ dispose() {
2402
+ clearInterval(this.timer);
2403
+ this.stopHearing?.();
2404
+ }
2405
+ round() {
2406
+ this.running ??= this.look().catch(() => {
2407
+ return;
2408
+ }).finally(() => {
2409
+ this.running = undefined;
2410
+ });
2411
+ return this.running;
2412
+ }
2413
+ async look() {
2414
+ const { account, sync } = this.options;
2415
+ const computers = await account.computers();
2416
+ if (computers.length === 0 || await this.options.off()) {
2417
+ return;
2418
+ }
2419
+ let status = await sync.status();
2420
+ if (status.state === "off") {
2421
+ const self = await account.self();
2422
+ const first = self && computers.filter((one) => one.online).every((one) => self.id < one.id);
2423
+ if (!first) {
2424
+ return;
2425
+ }
2426
+ status = await sync.enable();
2427
+ }
2428
+ const word = { identity: await this.options.identity() };
2429
+ if (status.state === "on" && (status.owner || status.where !== "relay")) {
2430
+ word.link = (await sync.invite()).link;
2431
+ }
2432
+ const text = JSON.stringify(word);
2433
+ for (const computer of computers) {
2434
+ if (this.told.get(computer.id) !== text) {
2435
+ await account.tell(computer.id, word);
2436
+ this.told.set(computer.id, text);
2437
+ }
2438
+ }
2439
+ if (status.owner) {
2440
+ for (const request of await this.options.requests()) {
2441
+ if (this.identities.has(request.id) && !request.guest) {
2442
+ await sync.answer(request.ask, true);
2443
+ }
2444
+ }
2445
+ }
2446
+ }
2447
+ async heard(word) {
2448
+ if (typeof word?.identity === "string") {
2449
+ this.identities.add(word.identity);
2450
+ }
2451
+ if (typeof word?.link !== "string" || this.tried.has(word.link) || await this.options.off()) {
2452
+ return;
2453
+ }
2454
+ const status = await this.options.sync.status();
2455
+ if (status.state === "off" || status.state === "gone" || status.state === "refused") {
2456
+ this.tried.add(word.link);
2457
+ await this.options.sync.join(word.link).catch(() => {
2458
+ return;
2459
+ });
2460
+ }
2461
+ this.round();
2462
+ }
2463
+ }
2464
+
2384
2465
  // web-src/sync-protocol.ts
2385
2466
  var SYNC_KIND = "ta-sync";
2386
2467
  var SYNC_PACKAGE = "@celljs/ta-sync";
@@ -2452,6 +2533,16 @@ function relayDefaultUrl(env) {
2452
2533
  }
2453
2534
  var RELAY_FRAME_CSP = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' https: data: blob:; style-src 'unsafe-inline' https: data:; img-src https: data: blob:; font-src https: data:; media-src https: data: blob:; connect-src 'none'; form-action 'none'";
2454
2535
  var RELAY_FRAME_HEADER_CSP = `${RELAY_FRAME_CSP}; frame-ancestors 'self'; sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox`;
2536
+ var OPEN_IN_TA = `<p><a id="open" style="display:inline-block;padding:10px 18px;border-radius:20px;background:#111;color:#fff;text-decoration:none;font-weight:600">Open in Ta · 在 Ta 中打开</a></p>
2537
+ <script>document.getElementById('open').href='ta://open?link='+encodeURIComponent(location.href)</script>`;
2538
+ var RELAY_PAIR_PAGE = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Ta</title>
2539
+ <body style="font:16px system-ui;max-width:32em;margin:3em auto;padding:0 1em">
2540
+ <h1>Ta</h1><p>Open this link in the Ta app, or paste it there, to reach your Ta from this device.</p>
2541
+ <p>打开 Ta 应用,粘贴这个链接,就能从这台设备连到你的 Ta。</p>${OPEN_IN_TA}</body>`;
2542
+ var RELAY_SHARE_PAGE = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Ta</title>
2543
+ <body style="font:16px system-ui;max-width:32em;margin:3em auto;padding:0 1em">
2544
+ <h1>Ta</h1><p>Someone shared an extension of Ta. Scan the code in the Ta app, or paste this link in its Quick open, to open it.</p>
2545
+ <p>有人分享了一个 Ta 扩展。在 Ta 应用里扫码,或把这个链接粘贴到“快捷打开”,就能打开它。</p>${OPEN_IN_TA}</body>`;
2455
2546
  var RELAY_SHARE_MAX_BYTES = 8 * 1024 * 1024;
2456
2547
  var RELAY_SHARE_CHUNK_BYTES = 192 * 1024;
2457
2548
  var RELAY_CONTENT_MAX_BYTES = 8 * 1024 * 1024;
@@ -4270,12 +4361,33 @@ function activate(host) {
4270
4361
  });
4271
4362
  const stopData = host.onExtensionData((name, key, cwd) => cwd === undefined && service.dataChanged(name, key));
4272
4363
  service.start();
4364
+ const OFF = "account.off";
4365
+ const off = (value) => host.setExtensionData(SYNC_PACKAGE, OFF, value || null).catch(() => {
4366
+ return;
4367
+ });
4368
+ const account = host.account ? new SyncAccount({
4369
+ account: host.account,
4370
+ sync: service,
4371
+ identity: async () => (await host.rooms.getIdentity()).id,
4372
+ requests: () => host.rooms.listRequests(),
4373
+ off: async () => await host.getExtensionData(SYNC_PACKAGE, OFF) === true
4374
+ }) : undefined;
4375
+ account?.start();
4273
4376
  return {
4274
4377
  status: () => service.status(),
4275
- enable: () => service.enable(),
4378
+ enable: async () => {
4379
+ await off(false);
4380
+ return service.enable();
4381
+ },
4276
4382
  invite: (renew) => service.invite(renew === true),
4277
- join: (link) => service.join(String(link ?? "")),
4278
- leave: () => service.leave(),
4383
+ join: async (link) => {
4384
+ await off(false);
4385
+ return service.join(String(link ?? ""));
4386
+ },
4387
+ leave: async () => {
4388
+ await off(true);
4389
+ return service.leave();
4390
+ },
4279
4391
  answer: (ask, accept) => service.answer(String(ask ?? ""), accept === true),
4280
4392
  removeDevice: (member) => service.removeDevice(String(member ?? "")),
4281
4393
  setResources: (change) => service.setResources(change ?? {}),
@@ -4296,6 +4408,7 @@ function activate(host) {
4296
4408
  migrateRelocate: (from, to) => migrate.relocate(String(from ?? ""), String(to ?? "")),
4297
4409
  dispose: () => {
4298
4410
  stopData();
4411
+ account?.dispose();
4299
4412
  service.dispose();
4300
4413
  migrate.dispose();
4301
4414
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-sync",
3
- "version": "4.17.0",
3
+ "version": "4.19.0",
4
4
  "description": "A pi package for Ta: the user's settings, instructions, skills, extensions and the data extensions declare, the same on each of their computers, through a room of the relay sealed end to end, without an account",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -26,9 +26,9 @@
26
26
  "watch": "tsc -b -w --preserveWatchOutput"
27
27
  },
28
28
  "devDependencies": {
29
- "@celljs/ta-protocol": "4.17.0",
30
- "@celljs/ta-relay": "4.17.0",
31
- "@celljs/ta-web": "4.17.0",
29
+ "@celljs/ta-protocol": "4.19.0",
30
+ "@celljs/ta-relay": "4.19.0",
31
+ "@celljs/ta-web": "4.19.0",
32
32
  "@types/react": "^19.3.0"
33
33
  },
34
34
  "publishConfig": {
package/web/index.js CHANGED
@@ -116,10 +116,10 @@ var en = {
116
116
  extensionsHint: "Packages installed from npm or git, and the extensions you made",
117
117
  data: "Data of extensions",
118
118
  dataHint: "What extensions keep for you everywhere, as the look of Ta and of your double",
119
- identity: "Identity and rooms",
120
- identityHint: "The same you in rooms on every computer, with your rooms and friends; the one in use answers when someone asks your double",
121
- identityAskTitle: "Be the same you in rooms on your computers?",
122
- identityAskBody: "Your identity, rooms and friends go to the computers of this sync, sealed. If another computer shares it already, this one takes on its identity; the rooms this one is in keep the identity they were joined with. Whoever has your identity can pass for you: share it only between your own computers.",
119
+ identity: "Identity and group chats",
120
+ identityHint: "The same you in group chats on every computer, with your group chats and friends; the one in use answers when someone asks your double",
121
+ identityAskTitle: "Be the same you in group chats on your computers?",
122
+ identityAskBody: "Your identity, group chats and friends go to the computers of this sync, sealed. If another computer shares it already, this one takes on its identity; the group chats this one is in keep the identity they were joined with. Whoever has your identity can pass for you: share it only between your own computers.",
123
123
  identityAskConfirm: "Share"
124
124
  };
125
125
  var zh = {
@@ -200,10 +200,10 @@ var zh = {
200
200
  extensionsHint: "从 npm、git 安装的扩展包,以及你自己做的扩展",
201
201
  data: "扩展数据",
202
202
  dataHint: "扩展声明要同步的数据,比如 Ta 的外观设置和分身的样子",
203
- identity: "身份与房间",
204
- identityHint: "每台电脑在房间里都是同一个你,房间和好友也一样;别人 @ 你的分身时,由正在用的那台回答",
205
- identityAskTitle: "让这几台电脑在房间里都是同一个你?",
206
- identityAskBody: "你的身份、房间和好友会加密同步到这些电脑。如果另一台电脑已经共享了身份,这台会换成它的身份;这台原来所在的房间保留原来的身份。拿到身份的人就能冒充你,只在自己的电脑之间打开。",
203
+ identity: "身份与群聊",
204
+ identityHint: "每台电脑在群里都是同一个你,群聊和好友也一样;别人 @ 你的分身时,由正在用的那台回答",
205
+ identityAskTitle: "让这几台电脑在群里都是同一个你?",
206
+ identityAskBody: "你的身份、群聊和好友会加密同步到这些电脑。如果另一台电脑已经共享了身份,这台会换成它的身份;这台原来所在的群聊保留原来的身份。拿到身份的人就能冒充你,只在自己的电脑之间打开。",
207
207
  identityAskConfirm: "共享"
208
208
  };
209
209
  var zhTw = {
@@ -284,10 +284,10 @@ var zhTw = {
284
284
  extensionsHint: "從 npm、git 安裝的擴充功能包,以及你自己做的擴充功能",
285
285
  data: "擴充功能資料",
286
286
  dataHint: "擴充功能宣告要同步的資料,比如 Ta 的外觀設定和分身的樣子",
287
- identity: "身份與房間",
288
- identityHint: "每台電腦在房間裡都是同一個你,房間和好友也一樣;別人 @ 你的分身時,由正在用的那台回答",
289
- identityAskTitle: "讓這幾台電腦在房間裡都是同一個你?",
290
- identityAskBody: "你的身份、房間和好友會加密同步到這些電腦。如果另一台電腦已經共享了身份,這台會換成它的身份;這台原來所在的房間保留原來的身份。拿到身份的人就能冒充你,只在自己的電腦之間開啟。",
287
+ identity: "身份與群聊",
288
+ identityHint: "每台電腦在群裡都是同一個你,群聊和好友也一樣;別人 @ 你的分身時,由正在用的那台回答",
289
+ identityAskTitle: "讓這幾台電腦在群裡都是同一個你?",
290
+ identityAskBody: "你的身份、群聊和好友會加密同步到這些電腦。如果另一台電腦已經共享了身份,這台會換成它的身份;這台原來所在的群聊保留原來的身份。拿到身份的人就能冒充你,只在自己的電腦之間開啟。",
291
291
  identityAskConfirm: "共享"
292
292
  };
293
293
  var ja = {
@@ -368,10 +368,10 @@ var ja = {
368
368
  extensionsHint: "npm、git からインストールされた拡張機能パッケージ、および自分で作成した拡張機能",
369
369
  data: "拡張機能のデータ",
370
370
  dataHint: "拡張機能が同期することを宣言するデータ。Ta の外観設定や分身の外観など",
371
- identity: "身元とルーム",
372
- identityHint: "各コンピューターではルーム内で同じあなたです。ルームと友だちも同じです。誰かがあなたの分身に @-mention したとき、使用中のコンピューターが応答します",
373
- identityAskTitle: "これらのコンピューターをルーム内で同じあなたにしますか?",
374
- identityAskBody: "あなたの身元、ルーム、友だちは暗号化されてこれらのコンピューターに同期されます。別のコンピューターが既に身元を共有している場合、このコンピューターはその身元を引き継ぎます。このコンピューターが属していたルームは元の身元を保持します。身元を持つ人は誰でもあなたになりすますことができます。自分のコンピューター間でのみ開いてください。",
371
+ identity: "身元とグループチャット",
372
+ identityHint: "各コンピューターではグループ内で同じあなたです。グループチャットと友だちも同じです。誰かがあなたの分身に @-mention したとき、使用中のコンピューターが応答します",
373
+ identityAskTitle: "これらのコンピューターをグループ内で同じあなたにしますか?",
374
+ identityAskBody: "あなたの身元、グループチャット、友だちは暗号化されてこれらのコンピューターに同期されます。別のコンピューターが既に身元を共有している場合、このコンピューターはその身元を引き継ぎます。このコンピューターが属していたグループチャットは元の身元を保持します。身元を持つ人は誰でもあなたになりすますことができます。自分のコンピューター間でのみ開いてください。",
375
375
  identityAskConfirm: "共有"
376
376
  };
377
377
  var WORDS = { "zh-CN": zh, "zh-TW": zhTw, "en-US": en, "ja-JP": ja };
@@ -499,10 +499,10 @@ var en2 = {
499
499
  changes: "Snapshots of changes",
500
500
  credentials: "Sign-ins",
501
501
  credentialsHint: "API keys and bot sign-ins",
502
- identity: "Identity and rooms",
503
- identityHint: "Who you are in rooms, the rooms and friends: whoever has them can pass for you",
504
- identitySwitched: "In rooms you are now who you were on {name}: {rooms} rooms came. Rooms this computer was in keep its own identity.",
505
- identityMerged: "{rooms} rooms and {friends} friends were added to yours.",
502
+ identity: "Identity and group chats",
503
+ identityHint: "Who you are in group chats, the group chats and friends: whoever has them can pass for you",
504
+ identitySwitched: "In group chats you are now who you were on {name}: {rooms} group chats came. Group chats this computer was in keep its own identity.",
505
+ identityMerged: "{rooms} group chats and {friends} friends were added to yours.",
506
506
  reload: "Load extensions"
507
507
  };
508
508
  var zh2 = {
@@ -598,10 +598,10 @@ var zh2 = {
598
598
  changes: "改动快照",
599
599
  credentials: "登录凭据",
600
600
  credentialsHint: "API 密钥和机器人的登录",
601
- identity: "身份与房间",
602
- identityHint: "你在房间里的身份、房间和好友,拿到的人就能冒充你",
603
- identitySwitched: "房间里你现在是「{name}」上的身份,带来 {rooms} 个房间;这台电脑原来所在的房间保留原身份。",
604
- identityMerged: "加进来 {rooms} 个房间和 {friends} 位好友。",
601
+ identity: "身份与群聊",
602
+ identityHint: "你在群里的身份、群聊和好友,拿到的人就能冒充你",
603
+ identitySwitched: "群里你现在是「{name}」上的身份,带来 {rooms} 个群聊;这台电脑原来所在的群聊保留原身份。",
604
+ identityMerged: "加进来 {rooms} 个群聊和 {friends} 位好友。",
605
605
  reload: "加载扩展"
606
606
  };
607
607
  var zhTw2 = {
@@ -697,10 +697,10 @@ var zhTw2 = {
697
697
  changes: "改動快照",
698
698
  credentials: "登入憑據",
699
699
  credentialsHint: "API 金鑰和機器人的登入",
700
- identity: "身份與房間",
701
- identityHint: "你在房間裡的身份、房間和好友,拿到的人就能冒充你",
702
- identitySwitched: "房間裡你現在是「{name}」上的身份,帶來 {rooms} 個房間;這台電腦原來所在的房間保留原身份。",
703
- identityMerged: "加進來 {rooms} 個房間和 {friends} 位好友。",
700
+ identity: "身份與群聊",
701
+ identityHint: "你在群裡的身份、群聊和好友,拿到的人就能冒充你",
702
+ identitySwitched: "群裡你現在是「{name}」上的身份,帶來 {rooms} 個群聊;這台電腦原來所在的群聊保留原身份。",
703
+ identityMerged: "加進來 {rooms} 個群聊和 {friends} 位好友。",
704
704
  reload: "載入擴充功能"
705
705
  };
706
706
  var ja2 = {
@@ -796,10 +796,10 @@ var ja2 = {
796
796
  changes: "変更のスナップショット",
797
797
  credentials: "サインイン認証情報",
798
798
  credentialsHint: "API キーとボット サインイン",
799
- identity: "身元とルーム",
800
- identityHint: "ルーム内のあなたの身元、ルーム、友だち。身元を持つ人は誰でもあなたになりすますことができます",
801
- identitySwitched: "ルーム内ではあなたは現在 {name} の身元です。{rooms} 件のルームが来ました。このコンピューターが属していたルームは元の身元を保持します。",
802
- identityMerged: "{rooms} 個のルームと {friends} 人の友だちが追加されました。",
799
+ identity: "身元とグループチャット",
800
+ identityHint: "グループ内のあなたの身元、グループチャット、友だち。身元を持つ人は誰でもあなたになりすますことができます",
801
+ identitySwitched: "グループ内ではあなたは現在 {name} の身元です。{rooms} 件のグループチャットが来ました。このコンピューターが属していたグループチャットは元の身元を保持します。",
802
+ identityMerged: "{rooms} 個のグループチャットと {friends} 人の友だちが追加されました。",
803
803
  reload: "拡張機能を読み込み"
804
804
  };
805
805
  var MOVE_WORDS = { "zh-CN": zh2, "zh-TW": zhTw2, "en-US": en2, "ja-JP": ja2 };
@@ -2082,11 +2082,11 @@ function SyncPanel({ pi, store }) {
2082
2082
  const words = useWords2(pi);
2083
2083
  const status = useStatus(store);
2084
2084
  if (!status) {
2085
- return /* @__PURE__ */ React.createElement("p", {
2086
- className: "tsy-status"
2087
- }, /* @__PURE__ */ React.createElement("span", {
2088
- className: "ta-spinner"
2089
- }), /* @__PURE__ */ React.createElement("span", null, words.connecting));
2085
+ const Loading = pi.ui.Loading ?? pi.ui.Skeleton;
2086
+ return /* @__PURE__ */ React.createElement(Loading, {
2087
+ compact: true,
2088
+ label: words.connecting
2089
+ });
2090
2090
  }
2091
2091
  const openJoin = () => pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(JoinDialog, {
2092
2092
  pi,