@celljs/ta-cloud-handoff 0.0.0-stage → 4.38.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 CHANGED
@@ -1,6 +1,71 @@
1
1
  {
2
2
  "name": "@celljs/ta-cloud-handoff",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.38.0",
4
+ "description": "A pi package for Ta: a conversation of this computer goes on in a cloud workspace while the computer is away, by hand or by itself as it sleeps or runs low, its files and what was said carried over and back, checked the same on both sides",
5
+ "keywords": [
6
+ "pi-package"
7
+ ],
8
+ "homepage": "https://github.com/cellbang/ta",
9
+ "bugs": {
10
+ "url": "https://github.com/cellbang/ta/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/cellbang/cell.git"
15
+ },
16
+ "license": "MIT",
17
+ "files": [
18
+ "web",
19
+ "host",
20
+ "extension",
21
+ "!**/*.map"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc -b && bun build web-src/index.tsx --format esm --target browser --outfile web/index.js && bun build web-src/host.ts --format esm --target node --outfile host/index.mjs && bun build web-src/extension.ts --format esm --target node --outfile extension/index.mjs",
25
+ "clean": "rm -rf lib web host extension *.tsbuildinfo",
26
+ "test": "bun test ./lib",
27
+ "watch": "tsc -b -w --preserveWatchOutput"
28
+ },
29
+ "devDependencies": {
30
+ "@celljs/core": "4.38.0",
31
+ "@celljs/ta-protocol": "4.38.0",
32
+ "@celljs/ta-web": "4.38.0",
33
+ "@types/react": "^19.3.3"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "pi": {
39
+ "title": {
40
+ "en": "Go on in the cloud",
41
+ "zh-CN": "云端接力",
42
+ "zh-TW": "雲端接力",
43
+ "ja-JP": "クラウドで続ける"
44
+ },
45
+ "summary": {
46
+ "en": "When your computer has to go, what runs goes on in your cloud workspace: by itself as the lid closes or the battery runs low (a Mac waits for it before it sleeps), or from the menu of a conversation. Its files, committed or not, and what was said go along; it comes back by itself once the computer is back, the cloud's work merged in.",
47
+ "zh-CN": "电脑要走开时,正在做的事换到你的云端工作区接着做:合盖或快没电时自动交出(Mac 会等交接完再睡),也可以在对话菜单里手动交出。工作目录里的文件(提交没提交的都算)和对话一起过去;电脑回来后自动接回本机,云端做的改动合并回来。",
48
+ "zh-TW": "電腦要走開時,正在做的事換到你的雲端工作區接著做:闔蓋或快沒電時自動交出(Mac 會等交接完再睡),也可以在對話選單裡手動交出。工作目錄裡的檔案(提交沒提交的都算)和對話一起過去;電腦回來後自動接回本機,雲端做的改動合併回來。",
49
+ "ja-JP": "パソコンを離れるとき、進行中の作業をクラウドのワークスペースで続けます。ふたを閉じたり電池が少なくなったりすると自動で移し(Mac は移し終えるまでスリープを待ちます)、会話のメニューから手動でも移せます。作業フォルダーのファイル(コミット前のものも)と会話が一緒に移り、パソコンが戻ると自動で戻して、クラウドでの変更を取り込みます。"
50
+ },
51
+ "icon": "Cloud",
52
+ "web": [
53
+ "./web/index.js"
54
+ ],
55
+ "host": "./host/index.mjs",
56
+ "extensions": [
57
+ "./extension/index.mjs"
58
+ ],
59
+ "permissions": {
60
+ "host": {
61
+ "list": "chat.view",
62
+ "away": "chat.view",
63
+ "*": "hosts.use"
64
+ },
65
+ "tools": {
66
+ "cloud_handoff": "hosts.use",
67
+ "later_on_computer": "chat.send"
68
+ }
69
+ }
70
+ }
71
+ }
package/web/index.js ADDED
@@ -0,0 +1,532 @@
1
+ // web-src/handoff-protocol.ts
2
+ var BOOK_KEY = "book";
3
+ var SETTINGS_KEY = "settings";
4
+ var HandoffSettingsUtil;
5
+ ((HandoffSettingsUtil) => {
6
+ HandoffSettingsUtil.AUTO_MINUTES = 15;
7
+ HandoffSettingsUtil.AUTO_PERCENT = 10;
8
+ HandoffSettingsUtil.PERCENTS = [10, 20, 30];
9
+ function of(stored) {
10
+ const value = stored && typeof stored === "object" ? stored : {};
11
+ return {
12
+ sleep: value.sleep !== false,
13
+ battery: value.battery !== false,
14
+ threshold: typeof value.threshold === "number" && HandoffSettingsUtil.PERCENTS.includes(value.threshold) ? value.threshold : "auto",
15
+ bringBack: value.bringBack !== false
16
+ };
17
+ }
18
+ HandoffSettingsUtil.of = of;
19
+ function low(battery, settings) {
20
+ if (!battery || battery.plugged) {
21
+ return false;
22
+ }
23
+ if (settings.threshold !== "auto") {
24
+ return battery.percent <= settings.threshold;
25
+ }
26
+ return battery.minutesLeft !== undefined ? battery.minutesLeft <= HandoffSettingsUtil.AUTO_MINUTES : battery.percent <= HandoffSettingsUtil.AUTO_PERCENT;
27
+ }
28
+ HandoffSettingsUtil.low = low;
29
+ })(HandoffSettingsUtil ||= {});
30
+ var HANDOFF_TOOL = "cloud_handoff";
31
+ var LATER_TOOL = "later_on_computer";
32
+ var NOTE_ENTRY = "ta-cloud-handoff";
33
+
34
+ // ../ta-protocol/esm/common/language.js
35
+ var TaLanguageUtil;
36
+ (function(TaLanguageUtil2) {
37
+ TaLanguageUtil2.ALL = ["zh-CN", "zh-TW", "en-US", "ja-JP"];
38
+ TaLanguageUtil2.NAMES = { "zh-CN": "简体中文", "zh-TW": "繁體中文", "en-US": "English", "ja-JP": "日本語" };
39
+ function of(tag) {
40
+ const said = (tag !== null && tag !== undefined ? tag : "").toLowerCase().replace(/_/g, "-");
41
+ if (/^zh(\b|-)/.test(said)) {
42
+ return /-hant\b/.test(said) || !/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said) ? "zh-TW" : "zh-CN";
43
+ }
44
+ return /^ja(\b|-)/.test(said) ? "ja-JP" : "en-US";
45
+ }
46
+ TaLanguageUtil2.of = of;
47
+ function server(env = typeof process === "undefined" ? {} : process.env) {
48
+ return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
49
+ }
50
+ TaLanguageUtil2.server = server;
51
+ function pick(language, words) {
52
+ return words[of(language)];
53
+ }
54
+ TaLanguageUtil2.pick = pick;
55
+ function say(words) {
56
+ return words[server()];
57
+ }
58
+ TaLanguageUtil2.say = say;
59
+ function chinese(language) {
60
+ return of(language).startsWith("zh");
61
+ }
62
+ TaLanguageUtil2.chinese = chinese;
63
+ function cjk(language) {
64
+ return of(language) !== "en-US";
65
+ }
66
+ TaLanguageUtil2.cjk = cjk;
67
+ function list(language, items) {
68
+ return items.join(cjk(language) ? "、" : ", ");
69
+ }
70
+ TaLanguageUtil2.list = list;
71
+ })(TaLanguageUtil || (TaLanguageUtil = {}));
72
+
73
+ // web-src/i18n.ts
74
+ var EN = {
75
+ handOff: "Go on in the cloud",
76
+ handOffTo: "Go on in the cloud · {cloud}",
77
+ takeBack: "Bring back to this computer",
78
+ openCloud: "Open it in the cloud",
79
+ open: "Open",
80
+ moving: "Moving to the cloud…",
81
+ returning: "Coming back…",
82
+ tag: "Cloud",
83
+ tagTitle: "Goes on in the cloud workspace {cloud}",
84
+ moved: "It goes on in the cloud workspace {cloud}",
85
+ movedIdle: "It is in the cloud workspace {cloud}: carry on there",
86
+ back: "Back on this computer",
87
+ backConflict: "Back on this computer: files changed on both sides were left as they were here",
88
+ failed: "It did not move: {reason}",
89
+ noteCloud: "Went on in the cloud · {cloud}",
90
+ noteBack: "Back on this computer from {cloud}",
91
+ noteConflict: "{n} file(s) changed on both sides",
92
+ noteLater: "{n} step(s) left for this computer",
93
+ noteModel: "no key of {model} there: another model goes on",
94
+ toolHandOff: "Move to the cloud",
95
+ toolLater: "Leave for the computer",
96
+ noteSleep: "The computer went to sleep: going on in the cloud · {cloud}",
97
+ noteBattery: "Battery low: going on in the cloud · {cloud}",
98
+ settingsTitle: "Cloud handoff",
99
+ settingsNoCloud: "First, in Remote hosts, turn on “Go on here while this computer is away” for a machine you reach by ssh: then what runs here goes on there when this computer has to go.",
100
+ sleepLabel: "When the computer sleeps",
101
+ sleepHint: "Lid closed or put to sleep: conversations that run go on in the cloud. On a Mac, sleep waits up to 20 s for it.",
102
+ batteryLabel: "When the battery runs low",
103
+ batteryHint: "Unplugged and low: conversations that run go on in the cloud.",
104
+ thresholdLabel: "Low means",
105
+ thresholdAuto: "Auto",
106
+ thresholdAutoHint: "Auto: {minutes} min left as the system estimates, else {percent}%.",
107
+ batteryNow: "Now {percent}%{left}, {state}.",
108
+ batteryLeft: ", about {minutes} min left",
109
+ plugged: "plugged in",
110
+ unplugged: "on battery",
111
+ lowNow: "low now",
112
+ noBattery: "This computer has no battery to read.",
113
+ backLabel: "Bring them back",
114
+ backHint: "Once the computer is back (awake, or plugged in) and the turn in the cloud ended, they come back here by themselves."
115
+ };
116
+ var ZH = {
117
+ handOff: "交给云端接着做",
118
+ handOffTo: "交给云端接着做 · {cloud}",
119
+ takeBack: "接回本机",
120
+ openCloud: "在云端打开",
121
+ open: "打开",
122
+ moving: "正在换到云端…",
123
+ returning: "正在接回…",
124
+ tag: "云端",
125
+ tagTitle: "正在云端 {cloud} 接着做",
126
+ moved: "已换到云端 {cloud} 接着做",
127
+ movedIdle: "已放到云端 {cloud},可以在那边接着聊",
128
+ back: "已接回本机",
129
+ backConflict: "已接回本机:两边都改过的文件保留了本机的版本",
130
+ failed: "没能换到云端:{reason}",
131
+ noteCloud: "换到云端接着做 · {cloud}",
132
+ noteBack: "从云端 {cloud} 接回本机",
133
+ noteConflict: "{n} 个文件两边都改过",
134
+ noteLater: "{n} 件事留给本机做",
135
+ noteModel: "云端用不了 {model},换成那边能用的模型",
136
+ toolHandOff: "换到云端",
137
+ toolLater: "留给本机做",
138
+ noteSleep: "电脑睡眠,换到云端接着做 · {cloud}",
139
+ noteBattery: "电量低,换到云端接着做 · {cloud}",
140
+ settingsTitle: "云端接力",
141
+ settingsNoCloud: "先在「远程主机」里选一台能 ssh 的机器,打开「电脑走开时在这里接着做」:之后电脑要走开时,正在做的事会换到那边接着做。",
142
+ sleepLabel: "合盖或睡眠时交给云端",
143
+ sleepHint: "正在做的对话换到云端接着做。Mac 会等它交接完再睡,最多 20 秒。",
144
+ batteryLabel: "电量低时交给云端",
145
+ batteryHint: "没接电源且电量低时,正在做的对话换到云端接着做。",
146
+ thresholdLabel: "电量低是指",
147
+ thresholdAuto: "自动",
148
+ thresholdAutoHint: "自动:系统估计还能用 {minutes} 分钟时;估计不出时按 {percent}%。",
149
+ batteryNow: "现在 {percent}%{left},{state}。",
150
+ batteryLeft: ",约剩 {minutes} 分钟",
151
+ plugged: "已接电源",
152
+ unplugged: "用电池",
153
+ lowNow: "已算电量低",
154
+ noBattery: "这台电脑读不到电池。",
155
+ backLabel: "回来后自动接回",
156
+ backHint: "电脑醒来或接上电源,云端这一轮做完,就自动接回本机。"
157
+ };
158
+ var ZH_TW = {
159
+ handOff: "交給雲端接著做",
160
+ handOffTo: "交給雲端接著做 · {cloud}",
161
+ takeBack: "接回本機",
162
+ openCloud: "在雲端開啟",
163
+ open: "開啟",
164
+ moving: "正在換到雲端…",
165
+ returning: "正在接回…",
166
+ tag: "雲端",
167
+ tagTitle: "正在雲端 {cloud} 接著做",
168
+ moved: "已換到雲端 {cloud} 接著做",
169
+ movedIdle: "已放到雲端 {cloud},可以在那邊接著聊",
170
+ back: "已接回本機",
171
+ backConflict: "已接回本機:兩邊都改過的檔案保留了本機的版本",
172
+ failed: "沒能換到雲端:{reason}",
173
+ noteCloud: "換到雲端接著做 · {cloud}",
174
+ noteBack: "從雲端 {cloud} 接回本機",
175
+ noteConflict: "{n} 個檔案兩邊都改過",
176
+ noteLater: "{n} 件事留給本機做",
177
+ noteModel: "雲端用不了 {model},換成那邊能用的模型",
178
+ toolHandOff: "換到雲端",
179
+ toolLater: "留給本機做",
180
+ noteSleep: "電腦睡眠,換到雲端接著做 · {cloud}",
181
+ noteBattery: "電量低,換到雲端接著做 · {cloud}",
182
+ settingsTitle: "雲端接力",
183
+ settingsNoCloud: "先在「遠端主機」裡選一台能 ssh 的機器,打開「電腦走開時在這裡接著做」:之後電腦要走開時,正在做的事會換到那邊接著做。",
184
+ sleepLabel: "闔蓋或睡眠時交給雲端",
185
+ sleepHint: "正在做的對話換到雲端接著做。Mac 會等它交接完再睡,最多 20 秒。",
186
+ batteryLabel: "電量低時交給雲端",
187
+ batteryHint: "沒接電源且電量低時,正在做的對話換到雲端接著做。",
188
+ thresholdLabel: "電量低是指",
189
+ thresholdAuto: "自動",
190
+ thresholdAutoHint: "自動:系統估計還能用 {minutes} 分鐘時;估計不出時按 {percent}%。",
191
+ batteryNow: "現在 {percent}%{left},{state}。",
192
+ batteryLeft: ",約剩 {minutes} 分鐘",
193
+ plugged: "已接電源",
194
+ unplugged: "用電池",
195
+ lowNow: "已算電量低",
196
+ noBattery: "這台電腦讀不到電池。",
197
+ backLabel: "回來後自動接回",
198
+ backHint: "電腦醒來或接上電源,雲端這一輪做完,就自動接回本機。"
199
+ };
200
+ var JA = {
201
+ handOff: "クラウドで続ける",
202
+ handOffTo: "クラウドで続ける · {cloud}",
203
+ takeBack: "このパソコンに戻す",
204
+ openCloud: "クラウドで開く",
205
+ open: "開く",
206
+ moving: "クラウドへ移しています…",
207
+ returning: "戻しています…",
208
+ tag: "クラウド",
209
+ tagTitle: "クラウド {cloud} で続いています",
210
+ moved: "クラウド {cloud} で続けます",
211
+ movedIdle: "クラウド {cloud} に移しました。そちらで続けられます",
212
+ back: "このパソコンに戻しました",
213
+ backConflict: "このパソコンに戻しました。両方で変わったファイルはこのパソコンのままです",
214
+ failed: "クラウドへ移せませんでした:{reason}",
215
+ noteCloud: "クラウドで続ける · {cloud}",
216
+ noteBack: "クラウド {cloud} からこのパソコンに戻しました",
217
+ noteConflict: "{n} 個のファイルが両方で変更",
218
+ noteLater: "{n} 件をこのパソコンで",
219
+ noteModel: "クラウドでは {model} が使えないので別のモデルで続ける",
220
+ toolHandOff: "クラウドへ移す",
221
+ toolLater: "パソコンに残す",
222
+ noteSleep: "パソコンがスリープ、クラウドで続ける · {cloud}",
223
+ noteBattery: "電池残量が少ない、クラウドで続ける · {cloud}",
224
+ settingsTitle: "クラウドで続ける",
225
+ settingsNoCloud: "先に「リモートホスト」で ssh できるマシンの「パソコンを離れている間ここで続ける」をオンにしてください。パソコンを離れるとき、進行中の作業がそちらで続きます。",
226
+ sleepLabel: "スリープ時にクラウドへ",
227
+ sleepHint: "ふたを閉じたりスリープしたりすると、進行中の会話をクラウドで続けます。Mac は最大 20 秒待ってからスリープします。",
228
+ batteryLabel: "電池残量が少ないときクラウドへ",
229
+ batteryHint: "電源につながず残量が少ないとき、進行中の会話をクラウドで続けます。",
230
+ thresholdLabel: "少ないとは",
231
+ thresholdAuto: "自動",
232
+ thresholdAutoHint: "自動:システムの見積もりで残り {minutes} 分、見積もれないときは {percent}%。",
233
+ batteryNow: "現在 {percent}%{left}、{state}。",
234
+ batteryLeft: "、残り約 {minutes} 分",
235
+ plugged: "電源接続中",
236
+ unplugged: "バッテリー駆動",
237
+ lowNow: "残量少",
238
+ noBattery: "このパソコンの電池は読めません。",
239
+ backLabel: "戻ったら自動で戻す",
240
+ backHint: "パソコンが戻り(スリープ解除か電源接続)、クラウドのターンが終わったら、このパソコンに戻します。"
241
+ };
242
+ var WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
243
+ var HandoffWords;
244
+ ((HandoffWords) => {
245
+ function of(language) {
246
+ return TaLanguageUtil.pick(language, WORDS);
247
+ }
248
+ HandoffWords.of = of;
249
+ function format(text, values) {
250
+ return text.replace(/\{(\w+)\}/g, (all, name) => values[name] === undefined ? all : String(values[name]));
251
+ }
252
+ HandoffWords.format = format;
253
+ })(HandoffWords ||= {});
254
+
255
+ // web-src/react.ts
256
+ var React;
257
+ function bind(react) {
258
+ React = react;
259
+ }
260
+
261
+ // web-src/settings.tsx
262
+ function useSettings(pi) {
263
+ const [value, setValue] = React.useState(() => HandoffSettingsUtil.of(undefined));
264
+ React.useEffect(() => {
265
+ let live = true;
266
+ const read = () => void pi.storage.get(SETTINGS_KEY).then((stored) => live && setValue(HandoffSettingsUtil.of(stored)), () => {
267
+ return;
268
+ });
269
+ read();
270
+ const stop = pi.storage.onChange((keys) => keys.includes(SETTINGS_KEY) && read());
271
+ return () => {
272
+ live = false;
273
+ stop();
274
+ };
275
+ }, [pi]);
276
+ const set = (change) => {
277
+ const next = { ...value, ...change };
278
+ setValue(next);
279
+ pi.storage.set(SETTINGS_KEY, next).catch((error) => pi.ui.notify(error instanceof Error ? error.message : String(error), "error"));
280
+ };
281
+ return [value, set];
282
+ }
283
+ function usePower(pi, settings) {
284
+ const [power, setPower] = React.useState();
285
+ React.useEffect(() => {
286
+ let live = true;
287
+ pi.callHost("power").then((value) => live && setPower(value), () => {
288
+ return;
289
+ });
290
+ return () => {
291
+ live = false;
292
+ };
293
+ }, [pi, settings.threshold]);
294
+ return power;
295
+ }
296
+ function handoffSettings(pi, hasCloud) {
297
+ const words = () => HandoffWords.of(pi.ui.language);
298
+ const say = HandoffWords.format;
299
+ function toggle(key, label) {
300
+ return function Toggle() {
301
+ const [settings, set] = useSettings(pi);
302
+ return /* @__PURE__ */ React.createElement(pi.ui.Switch, {
303
+ checked: settings[key],
304
+ label: label(),
305
+ onChange: (checked) => set({ [key]: checked })
306
+ });
307
+ };
308
+ }
309
+ function Threshold() {
310
+ const [settings, set] = useSettings(pi);
311
+ const power = usePower(pi, settings);
312
+ const w2 = words();
313
+ const values = ["auto", ...HandoffSettingsUtil.PERCENTS];
314
+ const battery = power?.battery;
315
+ const now = !power ? "" : !battery ? w2.noBattery : say(w2.batteryNow, {
316
+ percent: battery.percent,
317
+ left: battery.minutesLeft !== undefined ? say(w2.batteryLeft, { minutes: battery.minutesLeft }) : "",
318
+ state: power.low ? w2.lowNow : battery.plugged ? w2.plugged : w2.unplugged
319
+ });
320
+ return /* @__PURE__ */ React.createElement("div", {
321
+ className: "tch-threshold"
322
+ }, /* @__PURE__ */ React.createElement("fieldset", {
323
+ className: "ta-segmented",
324
+ "aria-label": w2.thresholdLabel,
325
+ disabled: !settings.battery
326
+ }, values.map((value) => /* @__PURE__ */ React.createElement("button", {
327
+ key: String(value),
328
+ type: "button",
329
+ "aria-pressed": value === settings.threshold,
330
+ className: value === settings.threshold ? "ta-on" : "",
331
+ onClick: () => set({ threshold: value })
332
+ }, value === "auto" ? w2.thresholdAuto : `${value}%`))), now && /* @__PURE__ */ React.createElement("div", {
333
+ className: "tch-now"
334
+ }, now));
335
+ }
336
+ const w = () => words();
337
+ return {
338
+ title: () => w().settingsTitle,
339
+ icon: pi.ui.icons.CloudUpload ?? pi.ui.icons.Cloud,
340
+ group: "devices",
341
+ order: 40,
342
+ rows: [
343
+ {
344
+ key: "sleep",
345
+ label: () => w().sleepLabel,
346
+ description: () => hasCloud() ? w().sleepHint : `${w().sleepHint} ${w().settingsNoCloud}`,
347
+ render: toggle("sleep", () => w().sleepLabel)
348
+ },
349
+ { key: "battery", label: () => w().batteryLabel, description: () => w().batteryHint, render: toggle("battery", () => w().batteryLabel) },
350
+ {
351
+ key: "threshold",
352
+ label: () => w().thresholdLabel,
353
+ description: () => say(w().thresholdAutoHint, { minutes: HandoffSettingsUtil.AUTO_MINUTES, percent: HandoffSettingsUtil.AUTO_PERCENT }),
354
+ render: Threshold,
355
+ stacked: true
356
+ },
357
+ { key: "back", label: () => w().backLabel, description: () => w().backHint, render: toggle("bringBack", () => w().backLabel) }
358
+ ]
359
+ };
360
+ }
361
+
362
+ // web-src/style.ts
363
+ var STYLE = `
364
+ /* The line a move leaves in the conversation: a dot, what happened, and what to look at. */
365
+ .tch-note { display: flex; align-items: baseline; gap: 8px; min-width: 0; margin: 2px 0; color: var(--ta-muted); font-size: calc(13px * var(--ta-font-scale)); line-height: 1.6; }
366
+ .tch-note > i { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--ta-blue); transform: translateY(-1px); }
367
+ .tch-note[data-to='back'] > i { background: var(--ta-green); }
368
+ .tch-note[data-warn] > i { background: var(--ta-yellow); }
369
+ .tch-threshold { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
370
+ .tch-threshold > fieldset:disabled { opacity: 0.5; }
371
+ .tch-now { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
372
+ .tch-note-text { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
373
+ `;
374
+ function injectStyle() {
375
+ const element = document.createElement("style");
376
+ element.dataset.taPackage = "ta-cloud-handoff";
377
+ element.textContent = STYLE;
378
+ document.head.appendChild(element);
379
+ return () => element.remove();
380
+ }
381
+
382
+ // web-src/index.tsx
383
+ function local(cwd) {
384
+ return cwd.startsWith("/") || /^[A-Za-z]:[\\/]/.test(cwd);
385
+ }
386
+ function page(url) {
387
+ return /^https?:\/\//.test(url);
388
+ }
389
+ function reason(error) {
390
+ return error instanceof Error ? error.message : String(error);
391
+ }
392
+
393
+ class HandoffState {
394
+ pi;
395
+ handoffs = [];
396
+ workspaces = [];
397
+ listeners = new Set;
398
+ stop;
399
+ constructor(pi) {
400
+ this.pi = pi;
401
+ this.stop = pi.storage.onChange((keys) => {
402
+ if (keys.includes(BOOK_KEY)) {
403
+ this.refresh();
404
+ }
405
+ });
406
+ pi.storage.get(BOOK_KEY);
407
+ this.refresh();
408
+ }
409
+ async refresh() {
410
+ const listed = await this.pi.callHost("list").catch(() => {
411
+ return;
412
+ });
413
+ if (listed) {
414
+ this.handoffs = listed.handoffs;
415
+ this.workspaces = listed.workspaces;
416
+ for (const listener of this.listeners) {
417
+ listener();
418
+ }
419
+ }
420
+ }
421
+ of(sessionFile) {
422
+ return sessionFile ? this.handoffs.find((handoff) => handoff.sessionFile === sessionFile) : undefined;
423
+ }
424
+ subscribe(listener) {
425
+ this.listeners.add(listener);
426
+ return () => this.listeners.delete(listener);
427
+ }
428
+ dispose() {
429
+ this.stop();
430
+ }
431
+ }
432
+ function activate(pi) {
433
+ bind(pi.React);
434
+ const removeStyle = injectStyle();
435
+ const state = new HandoffState(pi);
436
+ const words = () => HandoffWords.of(pi.ui.language);
437
+ const say = (text, values = {}) => HandoffWords.format(text, values);
438
+ const handOff = (sessionFile, cloud) => {
439
+ pi.ui.notify(words().moving, "info", { key: `ta-cloud-handoff:${sessionFile}` });
440
+ pi.callHost("handOff", sessionFile, cloud).then((moved) => pi.ui.notify(say(moved.wasRunning ? words().moved : words().movedIdle, { cloud: moved.cloud }), "info", {
441
+ key: `ta-cloud-handoff:${sessionFile}`,
442
+ ...page(moved.cloudUrl) ? { action: { label: words().openCloud, run: () => void pi.openLink(moved.cloudUrl) } } : {}
443
+ })).catch((error) => pi.ui.notify(say(words().failed, { reason: reason(error) }), "error", { key: `ta-cloud-handoff:${sessionFile}` }));
444
+ };
445
+ const takeBack = (handoff) => {
446
+ pi.ui.notify(words().returning, "info", { key: `ta-cloud-handoff:${handoff.sessionFile}` });
447
+ pi.callHost("takeBack", handoff.id).then((result) => pi.ui.notify(result.files === "conflict" ? words().backConflict : words().back, result.files === "conflict" ? "warning" : "info", {
448
+ key: `ta-cloud-handoff:${handoff.sessionFile}`,
449
+ action: { label: words().open, run: () => void pi.openChat?.(result.sessionFile) }
450
+ })).catch((error) => pi.ui.notify(reason(error), "error", { key: `ta-cloud-handoff:${handoff.sessionFile}` }));
451
+ };
452
+ pi.registerSettings(handoffSettings(pi, () => state.workspaces.length > 0));
453
+ pi.registerSessionMenu?.((session) => {
454
+ const icons = pi.ui.icons;
455
+ const handoff = state.of(session.sessionFile);
456
+ state.refresh();
457
+ if (handoff) {
458
+ if (handoff.state !== "cloud") {
459
+ return [
460
+ {
461
+ key: "cloud-handoff-busy",
462
+ label: handoff.state === "moving" ? words().moving : words().returning,
463
+ icon: icons.Cloud,
464
+ disabled: true,
465
+ run: () => {
466
+ return;
467
+ }
468
+ }
469
+ ];
470
+ }
471
+ return [
472
+ { key: "cloud-handoff-back", label: words().takeBack, icon: icons.Laptop ?? icons.Monitor, run: () => takeBack(handoff) },
473
+ ...page(handoff.cloudUrl) ? [{ key: "cloud-handoff-open", label: words().openCloud, icon: icons.ExternalLink, run: () => void pi.openLink(handoff.cloudUrl) }] : []
474
+ ];
475
+ }
476
+ if (!session.sessionFile || !local(session.cwd) || session.group) {
477
+ return [];
478
+ }
479
+ const file = session.sessionFile;
480
+ return state.workspaces.slice(0, 3).map((workspace) => ({
481
+ key: `cloud-handoff:${workspace.name}`,
482
+ label: state.workspaces.length > 1 ? say(words().handOffTo, { cloud: workspace.name }) : words().handOff,
483
+ icon: icons.CloudUpload ?? icons.Cloud,
484
+ run: () => handOff(file, workspace.name)
485
+ }));
486
+ });
487
+ pi.registerChatTag?.({
488
+ tag: (chat) => {
489
+ const handoff = state.of(chat.sessionFile);
490
+ return handoff ? { text: words().tag, tone: "blue", title: say(words().tagTitle, { cloud: handoff.cloud }) } : undefined;
491
+ },
492
+ subscribe: (listener) => state.subscribe(listener)
493
+ });
494
+ pi.registerMessageRenderer(NOTE_ENTRY, ({ message }) => {
495
+ const note = message.details;
496
+ if (!note || message.display === false) {
497
+ return null;
498
+ }
499
+ const w = words();
500
+ const line = [
501
+ say(note.to === "back" ? w.noteBack : note.why === "sleep" ? w.noteSleep : note.why === "battery" ? w.noteBattery : w.noteCloud, {
502
+ cloud: note.cloud
503
+ }),
504
+ note.conflicts?.length ? say(w.noteConflict, { n: note.conflicts.length }) : "",
505
+ note.later?.length ? say(w.noteLater, { n: note.later.length }) : "",
506
+ note.model ? say(w.noteModel, { model: note.model.from.slice(note.model.from.indexOf("/") + 1) }) : ""
507
+ ].filter(Boolean);
508
+ return /* @__PURE__ */ React.createElement("div", {
509
+ className: "tch-note",
510
+ "data-to": note.to,
511
+ "data-warn": note.conflicts?.length ? "true" : undefined
512
+ }, /* @__PURE__ */ React.createElement("i", null), /* @__PURE__ */ React.createElement("span", {
513
+ className: "tch-note-text"
514
+ }, line.join(" · ")));
515
+ });
516
+ pi.registerToolRenderer?.((name, next) => {
517
+ if (name === HANDOFF_TOOL) {
518
+ return { renderCall: (args) => ({ verb: words().toolHandOff, target: typeof args.cloud === "string" ? args.cloud : "" }) };
519
+ }
520
+ if (name === LATER_TOOL) {
521
+ return { renderCall: (args) => ({ verb: words().toolLater, target: typeof args.what === "string" ? args.what : "" }) };
522
+ }
523
+ return next();
524
+ });
525
+ return () => {
526
+ state.dispose();
527
+ removeStyle();
528
+ };
529
+ }
530
+ export {
531
+ activate as default
532
+ };