@celljs/ta-share 0.0.0-stage → 4.11.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/web/index.js ADDED
@@ -0,0 +1,1197 @@
1
+ // web-src/i18n.ts
2
+ var EN = {
3
+ shareConversation: "Share conversation…",
4
+ share: "Share…",
5
+ shareTitle: "Share “{title}”",
6
+ sharesTitle: "My shares",
7
+ who: "Who can open it",
8
+ accessLink: "Anyone with the link",
9
+ accessPassword: "With a password",
10
+ accessSelf: "Only me",
11
+ accessPeople: "Ta friends",
12
+ accessPeopleShort: "Ta friends",
13
+ accessPeopleHint: "Opens only in their own Ta, which proves who it is: the link alone opens nothing. While this computer runs Ta.",
14
+ peopleNone: "No Ta friends yet: whoever is in a room with you (Rooms, under Discover) is one.",
15
+ peopleChoose: "Choose at least one.",
16
+ peopleOnly: "Only the Ta friends it was shared with open it, in their own Ta.",
17
+ peopleLine: "for {names}",
18
+ accessLinkShort: "Public",
19
+ accessPasswordShort: "Password",
20
+ accessSelfShort: "Only me",
21
+ accessSelfHint: "Opens only in your own Ta: this computer and the devices paired with it.",
22
+ password: "Password",
23
+ passwordPlaceholder: "At least 4 characters",
24
+ passwordShort: "The password needs at least 4 characters.",
25
+ generate: "Make one",
26
+ lasts: "Works for",
27
+ day1: "1 day",
28
+ day7: "7 days",
29
+ day30: "30 days",
30
+ forever: "Until stopped",
31
+ outputs: "Include the outputs of tools",
32
+ outputsHint: "Each cut to 4 KB. Without them, only what each call did.",
33
+ offline: "Opens while this computer is off",
34
+ offlineHint: "A copy, encrypted here, is kept on the relay for 30 days at most. The relay cannot read it.",
35
+ offlinePassword: "With a password, keeping it only on this computer is safer: a copy on the relay can be guessed at offline.",
36
+ makeLink: "Make the link",
37
+ making: "Making the link…",
38
+ preview: "What goes",
39
+ previewLoading: "Reading the conversation…",
40
+ stats: "{messages} messages · {tools} tool calls",
41
+ redacted: "{n} things that look like secrets are hidden",
42
+ images: "{n} images are left out",
43
+ outputsLeft: "The outputs of tools are left out",
44
+ nothing: "There is nothing to share in this conversation yet.",
45
+ you: "You",
46
+ ta: "Ta",
47
+ copy: "Copy link",
48
+ copied: "Copied",
49
+ copyPassword: "Copy password",
50
+ passwordApart: "The password is not in the link: tell it apart.",
51
+ send: "Send…",
52
+ stop: "Stop sharing",
53
+ stopTitle: "Stop sharing “{title}”?",
54
+ stopHint: "The link stops working at once, and the copy on the relay is deleted.",
55
+ stopped: "Stopped sharing",
56
+ until: "until {date}",
57
+ untilStopped: "until you stop it",
58
+ onlineOnly: "opens while this computer runs Ta",
59
+ offlineToo: "opens while this computer is off too",
60
+ selfOnly: "opens only in your own Ta",
61
+ qr: "QR code of the link",
62
+ linkReady: "Scan with the Ta app or a phone camera, or send the link. A browser shows it; the Ta app can import it.",
63
+ emptyTitle: "Nothing shared yet",
64
+ emptyHint: "Choose Share conversation… in the + of a message box, or ask Ta to make a link of a file.",
65
+ kindConversation: "Conversation",
66
+ kindFile: "File",
67
+ open: "Open",
68
+ opening: "Opening…",
69
+ passwordTitle: "This share needs a password",
70
+ passwordAsk: "The password is not in the link: ask the one who shared it.",
71
+ wrong: "That password is wrong.",
72
+ busy: "Too many wrong passwords. Try again in a few minutes.",
73
+ gone: "This link no longer works: the share was stopped or ran out.",
74
+ offlineHost: "The computer that shared it is not running Ta now. Try again later.",
75
+ self: "Only the one who shared this opens it, in their own Ta.",
76
+ invalid: "This is not a whole link of Ta.",
77
+ failed: "Cannot open it: {message}",
78
+ import: "Import as my conversation",
79
+ importing: "Importing…",
80
+ importInto: "Into {dir}",
81
+ changeDir: "Change",
82
+ imported: "Imported into {dir}",
83
+ sharedAt: "Shared {date}",
84
+ download: "Download {name}",
85
+ outputLabel: "Output",
86
+ errorLabel: "Error",
87
+ toolShare: "Share",
88
+ oldApp: "Update the Ta app to share from here.",
89
+ read: "Read",
90
+ write: "Write",
91
+ edit: "Edit",
92
+ run: "Run",
93
+ search: "Search",
94
+ find: "Find",
95
+ list: "List",
96
+ fetch: "Open",
97
+ webSearch: "Search the web",
98
+ script: "Run a script",
99
+ use: "Use {name}"
100
+ };
101
+ var ZH = {
102
+ shareConversation: "分享对话…",
103
+ share: "分享…",
104
+ shareTitle: "分享“{title}”",
105
+ sharesTitle: "我的分享",
106
+ who: "谁能打开",
107
+ accessLink: "拿到链接的人",
108
+ accessPassword: "凭口令",
109
+ accessSelf: "仅自己",
110
+ accessPeople: "指定的好友",
111
+ accessPeopleShort: "指定的好友",
112
+ accessPeopleHint: "只能在对方自己的 Ta 里打开,由 Ta 证明身份:光有链接打不开。这台电脑运行 Ta 时可以打开。",
113
+ peopleNone: "还没有 Ta 好友:和你在同一个房间里待过的人就是(发现 → 房间)。",
114
+ peopleChoose: "至少选一位。",
115
+ peopleOnly: "这条链接只给指定的 Ta 好友,请在他们自己的 Ta 里打开。",
116
+ peopleLine: "给{names}",
117
+ accessLinkShort: "公开",
118
+ accessPasswordShort: "口令",
119
+ accessSelfShort: "仅自己",
120
+ accessSelfHint: "只能在你自己的 Ta 里打开:这台电脑和配对过的设备。",
121
+ password: "口令",
122
+ passwordPlaceholder: "至少 4 个字符",
123
+ passwordShort: "口令至少要 4 个字符。",
124
+ generate: "随机生成",
125
+ lasts: "有效期",
126
+ day1: "1 天",
127
+ day7: "7 天",
128
+ day30: "30 天",
129
+ forever: "不过期",
130
+ outputs: "附上工具的输出",
131
+ outputsHint: "每条最多 4 KB。不附时只显示每一步做了什么。",
132
+ offline: "电脑关机也能打开",
133
+ offlineHint: "在这里加密后,把副本放在中继上,最长 30 天。中继看不到内容。",
134
+ offlinePassword: "带口令时建议只放在这台电脑上:中继上的副本可以被离线猜口令。",
135
+ makeLink: "生成链接",
136
+ making: "正在生成链接…",
137
+ preview: "将分享的内容",
138
+ previewLoading: "正在读取对话…",
139
+ stats: "{messages} 条消息 · {tools} 次工具调用",
140
+ redacted: "隐去了 {n} 处疑似密钥",
141
+ images: "去掉了 {n} 张图片",
142
+ outputsLeft: "不含工具的输出",
143
+ nothing: "这个对话里还没有可以分享的内容。",
144
+ you: "你",
145
+ ta: "Ta",
146
+ copy: "复制链接",
147
+ copied: "已复制",
148
+ copyPassword: "复制口令",
149
+ passwordApart: "口令不在链接里,请另外告诉对方。",
150
+ send: "发送…",
151
+ stop: "停止分享",
152
+ stopTitle: "停止分享“{title}”?",
153
+ stopHint: "链接立即失效,中继上的副本也会删除。",
154
+ stopped: "已停止分享",
155
+ until: "{date} 前有效",
156
+ untilStopped: "停止分享前一直有效",
157
+ onlineOnly: "这台电脑运行 Ta 时可打开",
158
+ offlineToo: "电脑关机也能打开",
159
+ selfOnly: "只能在你自己的 Ta 里打开",
160
+ qr: "链接的二维码",
161
+ linkReady: "用 Ta 应用或手机相机扫码,或者把链接发给对方。浏览器里能直接看,Ta 应用里还能导入。",
162
+ emptyTitle: "还没有分享",
163
+ emptyHint: "在输入框的 + 里选“分享对话…”,或者让 Ta 帮你把文件生成分享链接。",
164
+ kindConversation: "对话",
165
+ kindFile: "文件",
166
+ open: "打开",
167
+ opening: "正在打开…",
168
+ passwordTitle: "这个分享需要口令",
169
+ passwordAsk: "口令不在链接里,请向分享的人要。",
170
+ wrong: "口令不对。",
171
+ busy: "口令错得太多了,请过几分钟再试。",
172
+ gone: "这个链接已经失效:分享已停止或已过期。",
173
+ offlineHost: "分享的人的电脑现在没有运行 Ta,请稍后再试。",
174
+ self: "这是仅自己可见的分享,只有分享的人能在自己的 Ta 里打开。",
175
+ invalid: "这不是一个完整的 Ta 分享链接。",
176
+ failed: "打不开:{message}",
177
+ import: "导入为我的对话",
178
+ importing: "正在导入…",
179
+ importInto: "导入到 {dir}",
180
+ changeDir: "更换",
181
+ imported: "已导入到 {dir}",
182
+ sharedAt: "分享于 {date}",
183
+ download: "下载 {name}",
184
+ outputLabel: "输出",
185
+ errorLabel: "出错",
186
+ toolShare: "分享",
187
+ oldApp: "请更新 Ta 应用后再从这里分享。",
188
+ read: "读取",
189
+ write: "写入",
190
+ edit: "编辑",
191
+ run: "运行",
192
+ search: "搜索",
193
+ find: "查找",
194
+ list: "列出",
195
+ fetch: "打开网页",
196
+ webSearch: "搜索网页",
197
+ script: "运行脚本",
198
+ use: "使用 {name}"
199
+ };
200
+ var ShareWords;
201
+ ((ShareWords) => {
202
+ function of(language) {
203
+ return language === "zh-CN" ? ZH : EN;
204
+ }
205
+ ShareWords.of = of;
206
+ function format(text, values) {
207
+ return text.replace(/\{(\w+)\}/g, (whole, key) => (key in values) ? String(values[key]) : whole);
208
+ }
209
+ ShareWords.format = format;
210
+ })(ShareWords ||= {});
211
+
212
+ // web-src/react.ts
213
+ var React;
214
+ function bind(react) {
215
+ React = react;
216
+ }
217
+
218
+ // web-src/page.ts
219
+ var pi;
220
+ function bindPage(api) {
221
+ pi = api;
222
+ }
223
+ function t(key, values = {}) {
224
+ return ShareWords.format(ShareWords.of(pi.ui.language)[key], values);
225
+ }
226
+ function icon(name) {
227
+ return pi.ui.icons[name] ?? pi.ui.icons.Share2 ?? pi.ui.icons.Link;
228
+ }
229
+ function message(error) {
230
+ return error instanceof Error ? error.message : String(error);
231
+ }
232
+ function baseName(path) {
233
+ return path.replace(/[\\/]+$/, "").split(/[\\/]/).pop() || path;
234
+ }
235
+ function date(at) {
236
+ return new Date(at).toLocaleDateString(pi.ui.language === "zh-CN" ? "zh-CN" : undefined, { month: "short", day: "numeric", year: "numeric" });
237
+ }
238
+ var Host = {
239
+ preview: (sessionFile, options) => pi.callHost("preview", sessionFile, options),
240
+ shareConversation: (sessionFile, options) => pi.callHost("shareConversation", sessionFile, options),
241
+ shareFile: (title, type, data, options) => pi.callHost("shareFile", title, type, data, options),
242
+ list: () => pi.callHost("list"),
243
+ remove: (id) => pi.callHost("remove", id),
244
+ open: (link, password) => pi.callHost("open", link, password),
245
+ importConversation: (link, password, cwd) => pi.callHost("importConversation", link, password, cwd)
246
+ };
247
+
248
+ class ShareList {
249
+ shares;
250
+ listeners = new Set;
251
+ loading;
252
+ get() {
253
+ return this.shares;
254
+ }
255
+ subscribe(listener) {
256
+ this.listeners.add(listener);
257
+ return () => this.listeners.delete(listener);
258
+ }
259
+ load() {
260
+ this.loading ??= Host.list().then((shares) => this.set(shares)).catch(() => this.set(this.shares ?? [])).finally(() => {
261
+ this.loading = undefined;
262
+ });
263
+ return this.loading;
264
+ }
265
+ added(share) {
266
+ this.set([share, ...(this.shares ?? []).filter((other) => other.id !== share.id)]);
267
+ }
268
+ async remove(id) {
269
+ await Host.remove(id);
270
+ this.set((this.shares ?? []).filter((share) => share.id !== id));
271
+ }
272
+ set(shares) {
273
+ this.shares = shares;
274
+ for (const listener of this.listeners) {
275
+ listener();
276
+ }
277
+ }
278
+ }
279
+ var shares = new ShareList;
280
+ function useShares() {
281
+ const list = React.useSyncExternalStore((listener) => shares.subscribe(listener), () => shares.get());
282
+ React.useEffect(() => {
283
+ shares.load();
284
+ }, []);
285
+ return list;
286
+ }
287
+ function shareLine(share) {
288
+ const access = share.access === "people" ? t("peopleLine", { names: (share.people ?? []).join("、") }) : { link: t("accessLinkShort"), password: t("accessPasswordShort"), self: t("accessSelfShort") }[share.access];
289
+ const until = share.expiresAt ? t("until", { date: date(share.expiresAt) }) : t("untilStopped");
290
+ const where = share.access === "self" ? t("selfOnly") : share.offline ? t("offlineToo") : t("onlineOnly");
291
+ return [access, until, where].join(" · ");
292
+ }
293
+
294
+ // web-src/share-dialog.tsx
295
+ var DAYS = [1, 7, 30, 0];
296
+ function Choice({
297
+ value,
298
+ options,
299
+ onChange,
300
+ label
301
+ }) {
302
+ return /* @__PURE__ */ React.createElement("fieldset", {
303
+ className: "tsh-choice",
304
+ "aria-label": label
305
+ }, options.map((option) => /* @__PURE__ */ React.createElement("button", {
306
+ key: String(option.value),
307
+ type: "button",
308
+ "aria-pressed": option.value === value,
309
+ disabled: option.disabled,
310
+ className: option.value === value ? "tsh-on" : "",
311
+ onClick: () => onChange(option.value)
312
+ }, option.label)));
313
+ }
314
+ function Toggle({
315
+ checked,
316
+ onChange,
317
+ label,
318
+ hint,
319
+ disabled
320
+ }) {
321
+ const Switch = pi.ui.Switch;
322
+ return /* @__PURE__ */ React.createElement("div", {
323
+ className: `tsh-toggle${disabled ? " tsh-disabled" : ""}`
324
+ }, /* @__PURE__ */ React.createElement("div", {
325
+ className: "tsh-toggle-text",
326
+ onClick: () => !disabled && onChange(!checked)
327
+ }, /* @__PURE__ */ React.createElement("span", null, label), hint && /* @__PURE__ */ React.createElement("small", null, hint)), Switch ? /* @__PURE__ */ React.createElement(Switch, {
328
+ checked,
329
+ onChange: (value) => onChange(value),
330
+ label,
331
+ disabled
332
+ }) : /* @__PURE__ */ React.createElement("input", {
333
+ type: "checkbox",
334
+ checked,
335
+ disabled,
336
+ "aria-label": label,
337
+ onChange: (event) => onChange(event.target.checked)
338
+ }));
339
+ }
340
+ function firstText(content) {
341
+ if (typeof content === "string") {
342
+ return content;
343
+ }
344
+ return (Array.isArray(content) ? content : []).flatMap((part) => part?.type === "text" && part.text ? [part.text] : []).join(" ");
345
+ }
346
+ function plain(text) {
347
+ return text.replace(/```[\s\S]*?(```|$)/g, " ").replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/[*_~`#>|]+/g, "").replace(/\s+/g, " ").trim();
348
+ }
349
+ function PreviewBox({ preview, outputs }) {
350
+ if (!preview) {
351
+ return /* @__PURE__ */ React.createElement("div", {
352
+ className: "tsh-preview tsh-preview-wait"
353
+ }, t("previewLoading"));
354
+ }
355
+ const { conversation, stats } = preview;
356
+ const lines = (conversation?.messages ?? []).filter((item) => item.role !== "toolResult").map((item) => ({ role: item.role, text: plain(firstText(item.content)) })).filter((line) => line.text).slice(0, 6);
357
+ const tools = stats?.tools ?? conversation?.messages.reduce((count, item) => count + (item.role === "assistant" ? item.content.filter((part) => part.type === "toolCall").length : 0), 0) ?? 0;
358
+ const notes = [
359
+ stats?.redacted ? t("redacted", { n: stats.redacted }) : "",
360
+ stats?.images ? t("images", { n: stats.images }) : "",
361
+ outputs ? "" : t("outputsLeft")
362
+ ].filter(Boolean);
363
+ return /* @__PURE__ */ React.createElement("div", {
364
+ className: "tsh-preview"
365
+ }, /* @__PURE__ */ React.createElement("div", {
366
+ className: "tsh-preview-head"
367
+ }, /* @__PURE__ */ React.createElement("span", null, t("preview")), stats && /* @__PURE__ */ React.createElement("span", {
368
+ className: "tsh-muted"
369
+ }, t("stats", { messages: stats.messages, tools }))), lines.length > 0 && /* @__PURE__ */ React.createElement("ul", {
370
+ className: "tsh-lines"
371
+ }, lines.map((line, index) => /* @__PURE__ */ React.createElement("li", {
372
+ key: index,
373
+ className: line.role === "user" ? "tsh-line-user" : ""
374
+ }, /* @__PURE__ */ React.createElement("b", null, line.role === "user" ? t("you") : t("ta")), /* @__PURE__ */ React.createElement("span", null, line.text)))), notes.length > 0 && /* @__PURE__ */ React.createElement("p", {
375
+ className: "tsh-notes"
376
+ }, notes.join(" · ")));
377
+ }
378
+ function randomPassword() {
379
+ const letters = "abcdefghjkmnpqrstuvwxyz23456789";
380
+ const bytes = crypto.getRandomValues(new Uint8Array(8));
381
+ return Array.from(bytes, (byte) => letters[byte % letters.length]).join("");
382
+ }
383
+ function Made({ share, password, close }) {
384
+ const [copied, setCopied] = React.useState();
385
+ const [stopping, setStopping] = React.useState(false);
386
+ const copy = (text, what) => void navigator.clipboard?.writeText(text).then(() => setCopied(what));
387
+ const canSend = typeof navigator !== "undefined" && typeof navigator.share === "function";
388
+ const Copy = icon("Copy");
389
+ const Check = icon("Check");
390
+ const Send = icon("Share2");
391
+ const stop = async () => {
392
+ if (await pi.ui.confirm(t("stopTitle", { title: share.title }), t("stopHint"), { confirmLabel: t("stop"), danger: true })) {
393
+ setStopping(true);
394
+ try {
395
+ await shares.remove(share.id);
396
+ pi.ui.notify(t("stopped"));
397
+ close();
398
+ } catch (error) {
399
+ pi.ui.notify(message(error), "error");
400
+ setStopping(false);
401
+ }
402
+ }
403
+ };
404
+ return /* @__PURE__ */ React.createElement("div", {
405
+ className: "tsh-made"
406
+ }, share.access !== "self" && pi.ui.QrCode && /* @__PURE__ */ React.createElement("div", {
407
+ className: "tsh-qr"
408
+ }, /* @__PURE__ */ React.createElement(pi.ui.QrCode, {
409
+ text: share.link,
410
+ label: t("qr")
411
+ })), /* @__PURE__ */ React.createElement("p", {
412
+ className: "tsh-hint"
413
+ }, share.access === "self" ? t("accessSelfHint") : share.access === "people" ? t("accessPeopleHint") : t("linkReady")), /* @__PURE__ */ React.createElement("div", {
414
+ className: "tsh-link",
415
+ title: share.link
416
+ }, share.link), /* @__PURE__ */ React.createElement("p", {
417
+ className: "tsh-muted tsh-center"
418
+ }, shareLine(share)), password && /* @__PURE__ */ React.createElement("div", {
419
+ className: "tsh-password-note"
420
+ }, /* @__PURE__ */ React.createElement("span", null, t("passwordApart"), " ", /* @__PURE__ */ React.createElement("code", null, password)), /* @__PURE__ */ React.createElement("button", {
421
+ type: "button",
422
+ className: "ta-button",
423
+ onClick: () => copy(password, "password")
424
+ }, copied === "password" ? t("copied") : t("copyPassword"))), /* @__PURE__ */ React.createElement("div", {
425
+ className: "tsh-actions"
426
+ }, /* @__PURE__ */ React.createElement("button", {
427
+ type: "button",
428
+ className: "ta-button ta-primary",
429
+ onClick: () => copy(share.link, "link")
430
+ }, copied === "link" ? /* @__PURE__ */ React.createElement(Check, {
431
+ size: 14
432
+ }) : /* @__PURE__ */ React.createElement(Copy, {
433
+ size: 14
434
+ }), " ", copied === "link" ? t("copied") : t("copy")), canSend && share.access !== "self" && /* @__PURE__ */ React.createElement("button", {
435
+ type: "button",
436
+ className: "ta-button",
437
+ onClick: () => void navigator.share({ title: share.title, url: share.link }).catch(() => {
438
+ return;
439
+ })
440
+ }, /* @__PURE__ */ React.createElement(Send, {
441
+ size: 14
442
+ }), " ", t("send"))), /* @__PURE__ */ React.createElement("button", {
443
+ type: "button",
444
+ className: "tsh-stop",
445
+ disabled: stopping,
446
+ onClick: () => void stop()
447
+ }, t("stop")));
448
+ }
449
+ function useFriends() {
450
+ const [friends, setFriends] = React.useState();
451
+ React.useEffect(() => {
452
+ pi.rooms?.listFriends().then(setFriends).catch(() => {
453
+ return;
454
+ });
455
+ }, []);
456
+ return friends;
457
+ }
458
+ function FriendPicker({ friends, chosen, onChange }) {
459
+ if (friends.length === 0) {
460
+ return /* @__PURE__ */ React.createElement("small", {
461
+ className: "tsh-muted"
462
+ }, t("peopleNone"));
463
+ }
464
+ return /* @__PURE__ */ React.createElement("div", {
465
+ className: "tsh-friends"
466
+ }, friends.map((friend) => {
467
+ const on = chosen.includes(friend.id);
468
+ return /* @__PURE__ */ React.createElement("label", {
469
+ key: friend.id,
470
+ className: `tsh-friend${on ? " tsh-on" : ""}`
471
+ }, /* @__PURE__ */ React.createElement("input", {
472
+ type: "checkbox",
473
+ checked: on,
474
+ onChange: (event) => onChange(event.target.checked ? [...chosen, friend.id] : chosen.filter((id) => id !== friend.id))
475
+ }), /* @__PURE__ */ React.createElement("span", null, friend.name));
476
+ }), /* @__PURE__ */ React.createElement("small", {
477
+ className: "tsh-muted"
478
+ }, t("accessPeopleHint")));
479
+ }
480
+ function Options({ target, onMade }) {
481
+ const [access, setAccess] = React.useState("link");
482
+ const [password, setPassword] = React.useState("");
483
+ const [people, setPeople] = React.useState([]);
484
+ const friends = useFriends();
485
+ const [days, setDays] = React.useState(7);
486
+ const [outputs, setOutputs] = React.useState(false);
487
+ const [offline, setOffline] = React.useState(false);
488
+ const [preview, setPreview] = React.useState();
489
+ const [busy, setBusy] = React.useState(false);
490
+ const [error, setError] = React.useState();
491
+ React.useEffect(() => {
492
+ let live = true;
493
+ setPreview(undefined);
494
+ Host.preview(target.sessionFile, { outputs, title: target.title }).then((result) => live && setPreview({ conversation: JSON.parse(result.json), stats: result.stats }), () => live && setPreview({}));
495
+ return () => {
496
+ live = false;
497
+ };
498
+ }, [target.sessionFile, target.title, outputs]);
499
+ const self = access === "self";
500
+ const only = self || access === "people";
501
+ const make = async () => {
502
+ if (access === "password" && password.length < 4) {
503
+ setError(t("passwordShort"));
504
+ return;
505
+ }
506
+ if (access === "people" && people.length === 0) {
507
+ setError(t("peopleChoose"));
508
+ return;
509
+ }
510
+ setBusy(true);
511
+ setError(undefined);
512
+ try {
513
+ const result = await Host.shareConversation(target.sessionFile, {
514
+ access,
515
+ ...access === "password" ? { password } : {},
516
+ ...access === "people" ? { people } : {},
517
+ days: offline && days === 0 ? 30 : days,
518
+ offline: offline && !only,
519
+ outputs,
520
+ title: target.title
521
+ });
522
+ shares.added(result.share);
523
+ onMade(result, access === "password" ? password : undefined);
524
+ } catch (failure) {
525
+ setError(message(failure));
526
+ setBusy(false);
527
+ }
528
+ };
529
+ const empty = preview?.stats?.messages === 0;
530
+ return /* @__PURE__ */ React.createElement("div", {
531
+ className: "tsh-options"
532
+ }, /* @__PURE__ */ React.createElement(PreviewBox, {
533
+ preview,
534
+ outputs
535
+ }), /* @__PURE__ */ React.createElement("div", {
536
+ className: "tsh-field"
537
+ }, /* @__PURE__ */ React.createElement("span", {
538
+ className: "tsh-label"
539
+ }, t("who")), /* @__PURE__ */ React.createElement(Choice, {
540
+ label: t("who"),
541
+ value: access,
542
+ onChange: setAccess,
543
+ options: [
544
+ { value: "link", label: t("accessLink") },
545
+ { value: "password", label: t("accessPassword") },
546
+ ...friends ? [{ value: "people", label: t("accessPeople") }] : [],
547
+ { value: "self", label: t("accessSelf") }
548
+ ]
549
+ }), self && /* @__PURE__ */ React.createElement("small", {
550
+ className: "tsh-muted"
551
+ }, t("accessSelfHint")), access === "people" && friends && /* @__PURE__ */ React.createElement(FriendPicker, {
552
+ friends,
553
+ chosen: people,
554
+ onChange: setPeople
555
+ }), access === "password" && /* @__PURE__ */ React.createElement("div", {
556
+ className: "tsh-password"
557
+ }, /* @__PURE__ */ React.createElement("input", {
558
+ className: "tsh-input",
559
+ type: "text",
560
+ autoComplete: "off",
561
+ spellCheck: false,
562
+ value: password,
563
+ placeholder: t("passwordPlaceholder"),
564
+ "aria-label": t("password"),
565
+ onChange: (event) => setPassword(event.target.value)
566
+ }), /* @__PURE__ */ React.createElement("button", {
567
+ type: "button",
568
+ className: "ta-button",
569
+ onClick: () => setPassword(randomPassword())
570
+ }, t("generate")))), /* @__PURE__ */ React.createElement("div", {
571
+ className: "tsh-field"
572
+ }, /* @__PURE__ */ React.createElement("span", {
573
+ className: "tsh-label"
574
+ }, t("lasts")), /* @__PURE__ */ React.createElement(Choice, {
575
+ label: t("lasts"),
576
+ value: offline && days === 0 ? 30 : days,
577
+ onChange: setDays,
578
+ options: DAYS.map((value) => ({ value, label: value === 0 ? t("forever") : t(`day${value}`), disabled: value === 0 && offline }))
579
+ })), /* @__PURE__ */ React.createElement(Toggle, {
580
+ checked: outputs,
581
+ onChange: setOutputs,
582
+ label: t("outputs"),
583
+ hint: t("outputsHint")
584
+ }), /* @__PURE__ */ React.createElement(Toggle, {
585
+ checked: offline && !only,
586
+ onChange: setOffline,
587
+ disabled: only,
588
+ label: t("offline"),
589
+ hint: access === "password" ? t("offlinePassword") : t("offlineHint")
590
+ }), (error || empty) && /* @__PURE__ */ React.createElement("p", {
591
+ className: "tsh-error"
592
+ }, error ?? t("nothing")), /* @__PURE__ */ React.createElement("div", {
593
+ className: "tsh-actions"
594
+ }, /* @__PURE__ */ React.createElement("button", {
595
+ type: "button",
596
+ className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
597
+ disabled: busy || empty,
598
+ onClick: () => void make()
599
+ }, busy ? t("making") : t("makeLink"))));
600
+ }
601
+ function ShareDialog({ target, close }) {
602
+ const [made, setMade] = React.useState(target.kind === "made" ? { share: target.share } : undefined);
603
+ const title = target.kind === "made" ? target.share.title : target.title;
604
+ return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
605
+ title: t("shareTitle", { title }),
606
+ onClose: close
607
+ }, /* @__PURE__ */ React.createElement("div", {
608
+ className: "tsh-dialog"
609
+ }, made ? /* @__PURE__ */ React.createElement(Made, {
610
+ share: made.share,
611
+ password: made.password,
612
+ close
613
+ }) : target.kind === "conversation" && /* @__PURE__ */ React.createElement(Options, {
614
+ target,
615
+ onMade: (result, password) => setMade({ share: result.share, password })
616
+ })));
617
+ }
618
+ function openShareDialog(target) {
619
+ if (!pi.ui.custom) {
620
+ pi.ui.notify(t("oldApp"), "warning");
621
+ return;
622
+ }
623
+ pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(ShareDialog, {
624
+ target,
625
+ close
626
+ }));
627
+ }
628
+
629
+ // web-src/share-protocol.ts
630
+ var SHARE_TOOL = "share_link";
631
+ var CONVERSATION_KIND = "ta-conversation";
632
+ var FILE_KIND = "file";
633
+ var ShareLink;
634
+ ((ShareLink) => {
635
+ const LINK = /^https?:\/\/[^/\s#?]+\/s#v=1&\S+$/i;
636
+ function is(text) {
637
+ const kind = LINK.test(text.trim()) ? fragment(text).get("c") : "none";
638
+ return kind === null || kind === CONVERSATION_KIND || kind === FILE_KIND;
639
+ }
640
+ ShareLink.is = is;
641
+ function fragment(text) {
642
+ return new URLSearchParams(text.slice(text.indexOf("#") + 1));
643
+ }
644
+ function needsPassword(text) {
645
+ return fragment(text).get("p") === "1";
646
+ }
647
+ ShareLink.needsPassword = needsPassword;
648
+ })(ShareLink ||= {});
649
+
650
+ // web-src/shared-view.tsx
651
+ var SharedToolLine;
652
+ ((SharedToolLine) => {
653
+ const VERBS = {
654
+ read: ["read", ["path", "file_path"]],
655
+ write: ["write", ["path", "file_path"]],
656
+ edit: ["edit", ["path", "file_path"]],
657
+ bash: ["run", ["command"], true],
658
+ grep: ["search", ["pattern"], true],
659
+ find: ["find", ["pattern", "path"]],
660
+ ls: ["list", ["path"]],
661
+ web_fetch: ["fetch", ["url"]],
662
+ web_search: ["webSearch", ["query"]],
663
+ codemode: ["script", []]
664
+ };
665
+ function of(name, args) {
666
+ const known = VERBS[name];
667
+ const pick = (keys) => keys.map((key) => args?.[key]).find((value) => typeof value === "string" && value);
668
+ if (known) {
669
+ return { verb: t(known[0]), target: pick(known[1]), code: known[2] };
670
+ }
671
+ return {
672
+ verb: t("use", { name }),
673
+ target: Object.values(args ?? {}).find((value) => typeof value === "string" && value.length < 200)
674
+ };
675
+ }
676
+ SharedToolLine.of = of;
677
+ })(SharedToolLine ||= {});
678
+ function words(content) {
679
+ return typeof content === "string" ? content : content.flatMap((part) => part.type === "text" ? [part.text] : []).join(`
680
+ `);
681
+ }
682
+ function ToolLine({ part, result }) {
683
+ const { verb, target, code } = SharedToolLine.of(part.name, part.arguments);
684
+ const output = result ? words(result.content).trim() : "";
685
+ const [open, setOpen] = React.useState(false);
686
+ return /* @__PURE__ */ React.createElement("div", {
687
+ className: "tsh-tool-wrap"
688
+ }, /* @__PURE__ */ React.createElement("button", {
689
+ type: "button",
690
+ className: `tsh-tool${result?.isError ? " tsh-failed" : ""}`,
691
+ disabled: !output,
692
+ "aria-expanded": output ? open : undefined,
693
+ onClick: () => setOpen(!open)
694
+ }, /* @__PURE__ */ React.createElement("span", {
695
+ className: "tsh-dot"
696
+ }), /* @__PURE__ */ React.createElement("span", {
697
+ className: "tsh-verb"
698
+ }, verb), target && /* @__PURE__ */ React.createElement("span", {
699
+ className: `tsh-target${code ? " tsh-code" : ""}`
700
+ }, target.split(`
701
+ `)[0])), open && output && /* @__PURE__ */ React.createElement("pre", {
702
+ className: "tsh-output"
703
+ }, output));
704
+ }
705
+ function SharedConversation({ conversation }) {
706
+ const results = React.useMemo(() => {
707
+ const map = new Map;
708
+ for (const item of conversation.messages) {
709
+ if (item.role === "toolResult") {
710
+ map.set(item.toolCallId, item);
711
+ }
712
+ }
713
+ return map;
714
+ }, [conversation]);
715
+ return /* @__PURE__ */ React.createElement("div", {
716
+ className: "tsh-conversation"
717
+ }, conversation.messages.map((item, index) => {
718
+ if (item.role === "user") {
719
+ const text = words(item.content).trim();
720
+ return text ? /* @__PURE__ */ React.createElement("div", {
721
+ key: index,
722
+ className: "tsh-user"
723
+ }, /* @__PURE__ */ React.createElement("div", {
724
+ className: "tsh-bubble"
725
+ }, text)) : null;
726
+ }
727
+ if (item.role !== "assistant") {
728
+ return null;
729
+ }
730
+ return /* @__PURE__ */ React.createElement("div", {
731
+ key: index,
732
+ className: "tsh-ta"
733
+ }, item.content.map((part, at) => part.type === "text" && part.text.trim() ? /* @__PURE__ */ React.createElement("div", {
734
+ key: at,
735
+ className: "tsh-text"
736
+ }, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
737
+ text: part.text
738
+ })) : part.type === "toolCall" ? /* @__PURE__ */ React.createElement(ToolLine, {
739
+ key: at,
740
+ part,
741
+ result: results.get(part.id)
742
+ }) : null), item.errorMessage && /* @__PURE__ */ React.createElement("p", {
743
+ className: "tsh-error"
744
+ }, item.errorMessage));
745
+ }));
746
+ }
747
+ function SharedPage({ html, title }) {
748
+ const policy = "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'";
749
+ const doc = `<meta http-equiv="Content-Security-Policy" content="${policy}">${html}`;
750
+ return /* @__PURE__ */ React.createElement("iframe", {
751
+ className: "tsh-frame",
752
+ title,
753
+ sandbox: "allow-scripts allow-popups",
754
+ referrerPolicy: "no-referrer",
755
+ srcDoc: doc
756
+ });
757
+ }
758
+ function bytesOf(data) {
759
+ const binary = atob(data.replace(/-/g, "+").replace(/_/g, "/"));
760
+ return Uint8Array.from(binary, (char) => char.charCodeAt(0));
761
+ }
762
+ function SharedFile({ content }) {
763
+ const bytes = React.useMemo(() => bytesOf(content.data), [content.data]);
764
+ const type = content.type ?? "application/octet-stream";
765
+ const url = React.useMemo(() => URL.createObjectURL(new Blob([bytes], { type })), [bytes, type]);
766
+ React.useEffect(() => () => URL.revokeObjectURL(url), [url]);
767
+ const text = () => new TextDecoder().decode(bytes);
768
+ if (/^text\/html\b/.test(type)) {
769
+ return /* @__PURE__ */ React.createElement(SharedPage, {
770
+ html: text(),
771
+ title: content.title
772
+ });
773
+ }
774
+ if (/^image\/(png|jpe?g|gif|webp|avif|bmp)$/.test(type)) {
775
+ return /* @__PURE__ */ React.createElement("img", {
776
+ className: "tsh-image",
777
+ src: url,
778
+ alt: content.title
779
+ });
780
+ }
781
+ if (/markdown/.test(type) || /\.(md|markdown)$/i.test(content.title)) {
782
+ return /* @__PURE__ */ React.createElement("div", {
783
+ className: "tsh-text tsh-doc"
784
+ }, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
785
+ text: text()
786
+ }));
787
+ }
788
+ if (/^text\/|json|xml|yaml|javascript|typescript|csv/.test(type)) {
789
+ return /* @__PURE__ */ React.createElement("pre", {
790
+ className: "tsh-plain"
791
+ }, text());
792
+ }
793
+ const Download = icon("Download");
794
+ return /* @__PURE__ */ React.createElement("a", {
795
+ className: "ta-button ta-primary tsh-download",
796
+ href: url,
797
+ download: content.title
798
+ }, /* @__PURE__ */ React.createElement(Download, {
799
+ size: 14
800
+ }), " ", t("download", { name: content.title }));
801
+ }
802
+ var FAILURE = {
803
+ password: "passwordTitle",
804
+ wrong: "wrong",
805
+ busy: "busy",
806
+ gone: "gone",
807
+ offline: "offlineHost",
808
+ self: "self",
809
+ people: "peopleOnly",
810
+ invalid: "invalid",
811
+ timeout: "offlineHost",
812
+ large: "gone"
813
+ };
814
+ function ImportBar({ link, password, title }) {
815
+ const shown = pi.ui.useCwd();
816
+ const [cwd, setCwd] = React.useState(shown);
817
+ const [picking, setPicking] = React.useState(false);
818
+ const [busy, setBusy] = React.useState(false);
819
+ const Download = icon("Download");
820
+ const run = async () => {
821
+ setBusy(true);
822
+ try {
823
+ const result = await Host.importConversation(link, password, cwd);
824
+ if (!result.ok) {
825
+ pi.ui.notify(t(FAILURE[result.reason] ?? "failed", { message: result.message }), "error");
826
+ return;
827
+ }
828
+ pi.ui.notify(t("imported", { dir: baseName(cwd) }));
829
+ await pi.switchSession(pi.server.openSession({ cwd, sessionFile: result.sessionFile }).then((info) => info.sessionId), { title, cwd, sessionFile: result.sessionFile });
830
+ } catch (error) {
831
+ pi.ui.notify(t("failed", { message: message(error) }), "error");
832
+ } finally {
833
+ setBusy(false);
834
+ }
835
+ };
836
+ return /* @__PURE__ */ React.createElement("div", {
837
+ className: "tsh-import"
838
+ }, /* @__PURE__ */ React.createElement("button", {
839
+ type: "button",
840
+ className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
841
+ disabled: busy,
842
+ onClick: () => void run()
843
+ }, /* @__PURE__ */ React.createElement(Download, {
844
+ size: 14
845
+ }), " ", busy ? t("importing") : t("import")), /* @__PURE__ */ React.createElement("span", {
846
+ className: "tsh-muted"
847
+ }, t("importInto", { dir: baseName(cwd) })), pi.ui.FolderPicker && /* @__PURE__ */ React.createElement("button", {
848
+ type: "button",
849
+ className: "tsh-link-button",
850
+ onClick: () => setPicking(true)
851
+ }, t("changeDir")), picking && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
852
+ initial: cwd,
853
+ onPick: (path) => {
854
+ setCwd(path);
855
+ setPicking(false);
856
+ },
857
+ onClose: () => setPicking(false)
858
+ }));
859
+ }
860
+ function SharedView({ link }) {
861
+ const [state, setState] = React.useState({ step: "loading" });
862
+ const [input, setInput] = React.useState("");
863
+ const open = React.useCallback(async (password) => {
864
+ setState({ step: "loading" });
865
+ try {
866
+ const result = await Host.open(link, password);
867
+ if (result.ok) {
868
+ setState({ step: "shown", content: result.content, password });
869
+ } else if (result.reason === "password" || password !== undefined && (result.reason === "wrong" || result.reason === "busy")) {
870
+ setState({ step: "password", error: result.reason === "password" ? undefined : t(FAILURE[result.reason]) });
871
+ } else {
872
+ setState({ step: "failed", text: t(FAILURE[result.reason] ?? "failed", { message: result.message }) });
873
+ }
874
+ } catch (error) {
875
+ setState({ step: "failed", text: t("failed", { message: message(error) }) });
876
+ }
877
+ }, [link]);
878
+ React.useEffect(() => {
879
+ open();
880
+ }, [open]);
881
+ if (state.step === "loading") {
882
+ return /* @__PURE__ */ React.createElement("div", {
883
+ className: "tsh-view tsh-center tsh-muted"
884
+ }, t("opening"));
885
+ }
886
+ if (state.step === "failed") {
887
+ return /* @__PURE__ */ React.createElement("div", {
888
+ className: "tsh-view"
889
+ }, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
890
+ title: state.text,
891
+ tone: "error"
892
+ }));
893
+ }
894
+ if (state.step === "password") {
895
+ return /* @__PURE__ */ React.createElement("div", {
896
+ className: "tsh-view"
897
+ }, /* @__PURE__ */ React.createElement("form", {
898
+ className: "tsh-ask",
899
+ onSubmit: (event) => {
900
+ event.preventDefault();
901
+ if (input) {
902
+ open(input);
903
+ }
904
+ }
905
+ }, /* @__PURE__ */ React.createElement("h3", null, t("passwordTitle")), /* @__PURE__ */ React.createElement("p", {
906
+ className: "tsh-muted"
907
+ }, t("passwordAsk")), /* @__PURE__ */ React.createElement("div", {
908
+ className: "tsh-password"
909
+ }, /* @__PURE__ */ React.createElement("input", {
910
+ className: "tsh-input",
911
+ type: "password",
912
+ autoComplete: "off",
913
+ value: input,
914
+ "aria-label": t("password"),
915
+ placeholder: t("password"),
916
+ onChange: (event) => setInput(event.target.value)
917
+ }), /* @__PURE__ */ React.createElement("button", {
918
+ type: "submit",
919
+ className: "ta-button ta-primary",
920
+ disabled: !input
921
+ }, t("open"))), state.error && /* @__PURE__ */ React.createElement("p", {
922
+ className: "tsh-error"
923
+ }, state.error)));
924
+ }
925
+ const { content } = state;
926
+ if (content.kind === CONVERSATION_KIND) {
927
+ const conversation = JSON.parse(new TextDecoder().decode(bytesOf(content.data)));
928
+ return /* @__PURE__ */ React.createElement("div", {
929
+ className: "tsh-view"
930
+ }, /* @__PURE__ */ React.createElement("header", {
931
+ className: "tsh-head"
932
+ }, /* @__PURE__ */ React.createElement("h2", null, conversation.title || content.title), /* @__PURE__ */ React.createElement("p", {
933
+ className: "tsh-muted"
934
+ }, [conversation.place, t("sharedAt", { date: date(content.createdAt) })].filter(Boolean).join(" · ")), /* @__PURE__ */ React.createElement(ImportBar, {
935
+ link,
936
+ password: state.password,
937
+ title: conversation.title || content.title
938
+ })), /* @__PURE__ */ React.createElement(SharedConversation, {
939
+ conversation
940
+ }));
941
+ }
942
+ return /* @__PURE__ */ React.createElement("div", {
943
+ className: `tsh-view${/^text\/html\b/.test(content.type ?? "") ? " tsh-view-page" : ""}`
944
+ }, /* @__PURE__ */ React.createElement(SharedFile, {
945
+ content
946
+ }));
947
+ }
948
+
949
+ // web-src/shares-page.tsx
950
+ function kindIcon(share) {
951
+ if (share.kind === CONVERSATION_KIND) {
952
+ return "MessageSquareText";
953
+ }
954
+ if (share.kind === "ta-agent") {
955
+ return "Contact";
956
+ }
957
+ return /^text\/html\b/.test(share.type ?? "") ? "Globe" : /^image\//.test(share.type ?? "") ? "Image" : "FileText";
958
+ }
959
+ function ShareRow({ share }) {
960
+ const [copied, setCopied] = React.useState(false);
961
+ const [stopping, setStopping] = React.useState(false);
962
+ const Kind = icon(kindIcon(share));
963
+ const Copy = icon("Copy");
964
+ const Qr = icon("QrCode");
965
+ const Stop = icon("Trash2");
966
+ const stop = async () => {
967
+ if (await pi.ui.confirm(t("stopTitle", { title: share.title }), t("stopHint"), { confirmLabel: t("stop"), danger: true })) {
968
+ setStopping(true);
969
+ await shares.remove(share.id).catch((error) => {
970
+ pi.ui.notify(message(error), "error");
971
+ setStopping(false);
972
+ });
973
+ }
974
+ };
975
+ return /* @__PURE__ */ React.createElement("li", {
976
+ className: `tsh-row${stopping ? " ta-pending" : ""}`
977
+ }, /* @__PURE__ */ React.createElement("span", {
978
+ className: `tsh-tile tsh-tile-${share.access}`,
979
+ "aria-hidden": "true"
980
+ }, /* @__PURE__ */ React.createElement(Kind, {
981
+ size: 18
982
+ })), /* @__PURE__ */ React.createElement("div", {
983
+ className: "tsh-row-text"
984
+ }, /* @__PURE__ */ React.createElement("span", {
985
+ className: "tsh-row-title"
986
+ }, share.title), /* @__PURE__ */ React.createElement("span", {
987
+ className: "tsh-row-line"
988
+ }, shareLine(share))), /* @__PURE__ */ React.createElement("div", {
989
+ className: "tsh-row-actions"
990
+ }, /* @__PURE__ */ React.createElement("button", {
991
+ type: "button",
992
+ className: "tsh-icon",
993
+ title: copied ? t("copied") : t("copy"),
994
+ "aria-label": t("copy"),
995
+ onClick: () => void navigator.clipboard?.writeText(share.link).then(() => setCopied(true))
996
+ }, /* @__PURE__ */ React.createElement(Copy, {
997
+ size: 15
998
+ })), /* @__PURE__ */ React.createElement("button", {
999
+ type: "button",
1000
+ className: "tsh-icon",
1001
+ title: t("qr"),
1002
+ "aria-label": t("qr"),
1003
+ onClick: () => openShareDialog({ kind: "made", share })
1004
+ }, /* @__PURE__ */ React.createElement(Qr, {
1005
+ size: 15
1006
+ })), /* @__PURE__ */ React.createElement("button", {
1007
+ type: "button",
1008
+ className: "tsh-icon tsh-danger",
1009
+ title: t("stop"),
1010
+ "aria-label": t("stop"),
1011
+ disabled: stopping,
1012
+ onClick: () => void stop()
1013
+ }, /* @__PURE__ */ React.createElement(Stop, {
1014
+ size: 15
1015
+ }))));
1016
+ }
1017
+ function SharesPage() {
1018
+ const list = useShares();
1019
+ return /* @__PURE__ */ React.createElement("div", {
1020
+ className: "tsh-page"
1021
+ }, list === undefined ? pi.ui.Skeleton ? /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
1022
+ rows: 3
1023
+ }) : null : list.length === 0 ? /* @__PURE__ */ React.createElement(pi.ui.Empty, {
1024
+ title: t("emptyTitle"),
1025
+ hint: t("emptyHint")
1026
+ }) : /* @__PURE__ */ React.createElement("ul", {
1027
+ className: "tsh-rows"
1028
+ }, list.map((share) => /* @__PURE__ */ React.createElement(ShareRow, {
1029
+ key: share.id,
1030
+ share
1031
+ }))));
1032
+ }
1033
+
1034
+ // web-src/style.ts
1035
+ var STYLE = `
1036
+ .tsh-muted { color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); }
1037
+ .tsh-center { text-align: center; }
1038
+ .tsh-error { margin: 0; color: var(--ta-red); font-size: calc(12.5px * var(--ta-font-scale)); }
1039
+ .tsh-input { flex: 1; min-width: 0; height: 32px; padding: 0 10px; border: 1px solid var(--ta-border-field); border-radius: 8px; background: var(--ta-input); color: var(--ta-text); font: inherit; font-size: calc(13px * var(--ta-font-scale)); outline: none; }
1040
+ .tsh-input:focus { border-color: var(--ta-border-focus); }
1041
+
1042
+ /* The dialog. */
1043
+ .tsh-dialog { display: flex; flex-direction: column; gap: 14px; width: min(440px, calc(100vw - 48px)); }
1044
+ .tsh-options { display: flex; flex-direction: column; gap: 14px; }
1045
+ .tsh-preview { border: 1px solid var(--ta-border-muted); border-radius: 12px; background: var(--ta-raised); padding: 10px 12px; }
1046
+ .tsh-preview-wait { color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); }
1047
+ .tsh-preview-head { display: flex; justify-content: space-between; gap: 8px; font-size: calc(12.5px * var(--ta-font-scale)); font-weight: 500; }
1048
+ .tsh-lines { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; max-height: 132px; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
1049
+ .tsh-lines li { display: flex; gap: 8px; min-width: 0; font-size: calc(12.5px * var(--ta-font-scale)); color: var(--ta-secondary); }
1050
+ .tsh-lines b { flex: none; width: 2.2em; font-weight: 500; color: var(--ta-muted); }
1051
+ .tsh-lines span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1052
+ .tsh-line-user span { color: var(--ta-text); }
1053
+ .tsh-notes { margin: 8px 0 0; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1054
+ .tsh-field { display: flex; flex-direction: column; gap: 6px; }
1055
+ .tsh-label { font-size: calc(12.5px * var(--ta-font-scale)); font-weight: 500; color: var(--ta-secondary); }
1056
+ .tsh-choice { display: flex; margin: 0; border: 0; min-width: 0; padding: 2px; border-radius: 9px; background: var(--ta-segment); gap: 2px; }
1057
+ .tsh-choice button { flex: 1; min-width: 0; height: 28px; border: 0; border-radius: 7px; background: none; color: var(--ta-secondary); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background 120ms, color 120ms; }
1058
+ .tsh-choice button:hover:not(:disabled) { color: var(--ta-text); }
1059
+ .tsh-choice button.tsh-on { background: var(--ta-card); color: var(--ta-text); font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
1060
+ .tsh-choice button:disabled { opacity: .4; cursor: default; }
1061
+ .tsh-password { display: flex; gap: 8px; }
1062
+ .tsh-friends { display: flex; flex-wrap: wrap; gap: 6px; }
1063
+ .tsh-friends small { flex-basis: 100%; }
1064
+ .tsh-friend { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px 0 8px; border: 1px solid var(--ta-border-field); border-radius: 14px; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; }
1065
+ .tsh-friend.tsh-on { border-color: var(--ta-green); background: color-mix(in srgb, var(--ta-green) 10%, transparent); }
1066
+ .tsh-friend input { margin: 0; accent-color: var(--ta-green); }
1067
+ .tsh-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
1068
+ .tsh-toggle-text { cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: calc(13px * var(--ta-font-scale)); }
1069
+ .tsh-toggle-text small { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: 1.4; }
1070
+ .tsh-disabled { opacity: .5; }
1071
+ .tsh-actions { display: flex; justify-content: flex-end; gap: 8px; }
1072
+ .tsh-made { display: flex; flex-direction: column; align-items: stretch; gap: 10px; }
1073
+ .tsh-made .tsh-actions { justify-content: center; }
1074
+ .tsh-qr { align-self: center; width: 188px; padding: 10px; border-radius: 14px; background: #fff; border: 1px solid var(--ta-border-muted); }
1075
+ .tsh-qr svg { display: block; width: 100%; height: auto; }
1076
+ .tsh-hint { margin: 0; text-align: center; color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); line-height: 1.5; }
1077
+ .tsh-link { padding: 8px 10px; border-radius: 8px; background: var(--ta-code); font-family: var(--ta-mono); font-size: calc(11.5px * var(--ta-font-scale)); color: var(--ta-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1078
+ .tsh-password-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--ta-raised); font-size: calc(12.5px * var(--ta-font-scale)); }
1079
+ .tsh-password-note code { font-family: var(--ta-mono); color: var(--ta-text); }
1080
+ .tsh-stop { align-self: center; border: 0; background: none; color: var(--ta-muted); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
1081
+ .tsh-stop:hover { color: var(--ta-red); background: var(--ta-hover); }
1082
+
1083
+ /* My shares. */
1084
+ .tsh-page { max-width: 720px; margin: 0 auto; padding: 12px 16px 32px; }
1085
+ .tsh-rows { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
1086
+ .tsh-row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px; transition: background 120ms, opacity 200ms; }
1087
+ .tsh-row:hover { background: var(--ta-hover); }
1088
+ .tsh-tile { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 11px; color: #fff; background: var(--ta-green); }
1089
+ .tsh-tile-password { background: var(--ta-yellow); }
1090
+ .tsh-tile-self { background: var(--ta-blue); }
1091
+ .tsh-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
1092
+ .tsh-row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1093
+ .tsh-row-line { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1094
+ .tsh-row-actions { flex: none; display: flex; gap: 2px; opacity: .75; }
1095
+ .tsh-row:hover .tsh-row-actions { opacity: 1; }
1096
+ .tsh-icon { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border: 0; border-radius: 8px; background: none; color: var(--ta-secondary); cursor: pointer; }
1097
+ .tsh-icon:hover:not(:disabled) { background: var(--ta-hover-strong); color: var(--ta-text); }
1098
+ .tsh-icon.tsh-danger:hover:not(:disabled) { color: var(--ta-red); }
1099
+
1100
+ /* What a link shares, in the workbench. */
1101
+ .tsh-view { height: 100%; overflow: auto; padding: 18px 20px 32px; box-sizing: border-box; }
1102
+ .tsh-view-page { padding: 0; overflow: hidden; }
1103
+ .tsh-view.tsh-center { padding-top: 22vh; }
1104
+ .tsh-head { margin: 0 auto 18px; max-width: 760px; }
1105
+ .tsh-head h2 { margin: 0 0 4px; font-size: calc(18px * var(--ta-font-scale)); line-height: 1.35; word-break: break-word; }
1106
+ .tsh-head p { margin: 0 0 12px; }
1107
+ .tsh-import { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; }
1108
+ .tsh-link-button { border: 0; background: none; padding: 2px 4px; color: var(--ta-link); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; }
1109
+ .tsh-conversation { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
1110
+ .tsh-user { display: flex; justify-content: flex-end; }
1111
+ .tsh-bubble { max-width: 85%; padding: 8px 13px; border-radius: 14px 14px 4px 14px; background: var(--ta-user); white-space: pre-wrap; word-break: break-word; }
1112
+ .tsh-ta { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
1113
+ .tsh-text { min-width: 0; word-break: break-word; }
1114
+ .tsh-doc { max-width: 760px; margin: 0 auto; }
1115
+ .tsh-tool-wrap { display: flex; flex-direction: column; }
1116
+ .tsh-tool { display: flex; align-items: baseline; gap: 8px; min-width: 0; max-width: 100%; padding: 2px 0; border: 0; background: none; color: var(--ta-muted); font: inherit; font-size: calc(13px * var(--ta-font-scale)); text-align: left; cursor: pointer; }
1117
+ .tsh-tool:disabled { cursor: default; }
1118
+ .tsh-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--ta-green); transform: translateY(-2px); }
1119
+ .tsh-failed .tsh-dot { background: var(--ta-border-field); }
1120
+ .tsh-verb { flex: none; }
1121
+ .tsh-target { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-secondary); }
1122
+ .tsh-code { font-family: var(--ta-mono); font-size: calc(12px * var(--ta-font-scale)); }
1123
+ .tsh-output { margin: 4px 0 4px 14px; max-height: 260px; overflow: auto; padding: 8px 10px; border-radius: 8px; background: var(--ta-code); font-family: var(--ta-mono); font-size: calc(11.5px * var(--ta-font-scale)); white-space: pre-wrap; word-break: break-word; }
1124
+ .tsh-ask { max-width: 360px; margin: 12vh auto 0; display: flex; flex-direction: column; gap: 10px; text-align: center; }
1125
+ .tsh-ask h3 { margin: 0; font-size: calc(16px * var(--ta-font-scale)); }
1126
+ .tsh-ask p { margin: 0; }
1127
+ .tsh-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
1128
+ .tsh-image { display: block; max-width: 100%; margin: 0 auto; border-radius: 10px; }
1129
+ .tsh-plain { margin: 0; padding: 12px 14px; border-radius: 10px; background: var(--ta-code); font-family: var(--ta-mono); font-size: calc(12px * var(--ta-font-scale)); white-space: pre-wrap; word-break: break-word; }
1130
+ .tsh-download { margin: 20vh auto 0; display: flex; width: fit-content; text-decoration: none; }
1131
+ @media (prefers-reduced-motion: reduce) { .tsh-row, .tsh-choice button { transition: none; } }
1132
+ `;
1133
+ function injectStyle() {
1134
+ const element = document.createElement("style");
1135
+ element.dataset.taPackage = "ta-share";
1136
+ element.textContent = STYLE;
1137
+ document.head.appendChild(element);
1138
+ return () => element.remove();
1139
+ }
1140
+
1141
+ // web-src/index.tsx
1142
+ function openLink(pi2, link) {
1143
+ const share = new URLSearchParams(link.slice(link.indexOf("#") + 1)).get("s") ?? link;
1144
+ pi2.ui.openEditor({ id: `ta-share:${share}`, title: () => t("share").replace("…", ""), icon: icon("Share2"), render: () => /* @__PURE__ */ React.createElement(SharedView, {
1145
+ link
1146
+ }) });
1147
+ }
1148
+ function activate(pi2) {
1149
+ bind(pi2.React);
1150
+ bindPage(pi2);
1151
+ const removeStyle = injectStyle();
1152
+ const Share = icon("Share2");
1153
+ pi2.registerComposerAddon({
1154
+ actions: (conversation) => conversation.sessionFile ? [
1155
+ {
1156
+ key: "share",
1157
+ label: t("shareConversation"),
1158
+ icon: /* @__PURE__ */ React.createElement(Share, {
1159
+ size: 16
1160
+ }),
1161
+ run: () => openShareDialog({
1162
+ kind: "conversation",
1163
+ sessionFile: conversation.sessionFile,
1164
+ title: conversation.title || t("kindConversation")
1165
+ })
1166
+ }
1167
+ ] : []
1168
+ });
1169
+ pi2.registerSessionMenu?.((session) => session.sessionFile ? [
1170
+ {
1171
+ key: "share",
1172
+ label: t("share"),
1173
+ icon: Share,
1174
+ run: () => openShareDialog({ kind: "conversation", sessionFile: session.sessionFile, title: session.title })
1175
+ }
1176
+ ] : []);
1177
+ pi2.registerOpener((link) => {
1178
+ if (link.type !== "url" || !ShareLink.is(link.url)) {
1179
+ return false;
1180
+ }
1181
+ openLink(pi2, link.url);
1182
+ return true;
1183
+ }, { specific: true });
1184
+ pi2.registerView("shares", { title: () => t("sharesTitle"), icon: Share, render: SharesPage, discover: true, order: 80 });
1185
+ pi2.registerToolRenderer((name, next) => name === SHARE_TOOL ? next() ?? {
1186
+ renderCall: (args) => ({
1187
+ verb: t("toolShare"),
1188
+ target: typeof args.path === "string" ? args.path : typeof args.title === "string" ? args.title : undefined
1189
+ })
1190
+ } : next());
1191
+ return () => {
1192
+ removeStyle();
1193
+ };
1194
+ }
1195
+ export {
1196
+ activate as default
1197
+ };