@celljs/ta-share 4.24.0 → 4.25.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/README.en.md +1 -1
- package/README.md +1 -1
- package/extension/index.mjs +343 -0
- package/host/index.mjs +1502 -7
- package/package.json +6 -5
- package/web/index.js +1018 -23
package/README.en.md
CHANGED
|
@@ -26,4 +26,4 @@ It works for 1, 7 or 30 days, or until stopped; "opens while this computer is of
|
|
|
26
26
|
|
|
27
27
|
- **Server side** (`pi.host`, `web-src/host.ts`): `ShareService`. The snapshot of a conversation (`ConversationSnapshot`: the user's messages, the replies and the calls of tools of the branch shown; no thinking, images or cards of extensions; the outputs of tools if asked, 4 KB each; the words as a person reads them, `TaSaid`, without the context, skill files and summaries that are for the model) and `Redactor`; links made, listed, stopped and opened by `TaExtensionHost.shares`; imports by `TaExtensionHost.createSession` (ssh:// directories too).
|
|
28
28
|
- **pi extension** (`web-src/extension.ts`): the tool `share_link`.
|
|
29
|
-
- **Web extension** (`web-src/index.tsx`): the + of the message box, the menu of a conversation (`registerSessionMenu`), the dialog (`ui.custom`), My shares, and a tab of the workbench for links (`registerOpener(…, { specific: true })`).
|
|
29
|
+
- **Web extension** (`web-src/index.tsx`): the + of the message box, the menu of a conversation (`registerSessionMenu`), the menu of a file in the explorer (`registerFileMenu`), the dialog (`ui.custom`), My shares, and a tab of the workbench for links (`registerOpener(…, { specific: true })`).
|
package/README.md
CHANGED
|
@@ -26,4 +26,4 @@ Ta 自带的 pi 包(默认开启,可在 设置 → 扩展 关闭):把对
|
|
|
26
26
|
|
|
27
27
|
- **服务端**(`pi.host`,`web-src/host.ts`):`ShareService`。对话快照(`ConversationSnapshot`:当前分支的用户消息、回复文字、工具调用;不含思考、图片、扩展卡片,工具输出可选、每条最多 4 KB;文字是人读到的样子(`TaSaid`),不带给模型看的 context、技能文件和压缩摘要)与脱敏(`Redactor`),经 `TaExtensionHost.shares` 生成、列出、停止、打开链接;导入经 `TaExtensionHost.createSession`(ssh:// 目录同样适用)。
|
|
28
28
|
- **pi 扩展**(`web-src/extension.ts`):工具 `share_link`。
|
|
29
|
-
- **Web 扩展**(`web-src/index.tsx`):输入框 + 菜单、会话菜单(`registerSessionMenu`)、分享弹窗(`ui.custom`)、"我的分享"页、打开链接的工作台标签(`registerOpener(…, { specific: true })`)。
|
|
29
|
+
- **Web 扩展**(`web-src/index.tsx`):输入框 + 菜单、会话菜单(`registerSessionMenu`)、资源管理器里文件的菜单(`registerFileMenu`)、分享弹窗(`ui.custom`)、"我的分享"页、打开链接的工作台标签(`registerOpener(…, { specific: true })`)。
|
package/extension/index.mjs
CHANGED
|
@@ -148,6 +148,26 @@ var TaLanguageUtil;
|
|
|
148
148
|
})(TaLanguageUtil || (TaLanguageUtil = {}));
|
|
149
149
|
|
|
150
150
|
// web-src/server-texts.ts
|
|
151
|
+
var REASONS = {
|
|
152
|
+
"zh-CN": { phishing: "钓鱼或诈骗", malware: "病毒或恶意软件", sexual: "色情内容", illegal: "违法内容", harassment: "骚扰或侵权", other: "其他" },
|
|
153
|
+
"zh-TW": { phishing: "釣魚或詐騙", malware: "病毒或惡意軟體", sexual: "色情內容", illegal: "違法內容", harassment: "騷擾或侵權", other: "其他" },
|
|
154
|
+
"en-US": {
|
|
155
|
+
phishing: "Phishing or scam",
|
|
156
|
+
malware: "Virus or malware",
|
|
157
|
+
sexual: "Sexual content",
|
|
158
|
+
illegal: "Illegal content",
|
|
159
|
+
harassment: "Harassment or infringement",
|
|
160
|
+
other: "Other"
|
|
161
|
+
},
|
|
162
|
+
"ja-JP": {
|
|
163
|
+
phishing: "フィッシング・詐欺",
|
|
164
|
+
malware: "ウイルス・マルウェア",
|
|
165
|
+
sexual: "性的なコンテンツ",
|
|
166
|
+
illegal: "違法なコンテンツ",
|
|
167
|
+
harassment: "嫌がらせ・権利侵害",
|
|
168
|
+
other: "その他"
|
|
169
|
+
}
|
|
170
|
+
};
|
|
151
171
|
var ShareServerTexts;
|
|
152
172
|
((ShareServerTexts) => {
|
|
153
173
|
function language(env = process.env) {
|
|
@@ -203,6 +223,74 @@ var ShareServerTexts;
|
|
|
203
223
|
});
|
|
204
224
|
}
|
|
205
225
|
ShareServerTexts.confirm = confirm;
|
|
226
|
+
function publicConfirm(port, minutes) {
|
|
227
|
+
const hours = minutes % 60 === 0 ? minutes / 60 : undefined;
|
|
228
|
+
return TaLanguageUtil.say({
|
|
229
|
+
"zh-CN": [
|
|
230
|
+
`公开本机服务 localhost:${port}?`,
|
|
231
|
+
`拿到链接的任何人都能访问这个服务,${hours ? `${hours} 小时` : `${minutes} 分钟`}后自动停止,关掉 Ta 也会停止。链接经 Cloudflare 转发,域名是随机的 trycloudflare.com。只公开你愿意给别人看的服务;公司网络通常禁止这样做。`
|
|
232
|
+
],
|
|
233
|
+
"zh-TW": [
|
|
234
|
+
`公開本機服務 localhost:${port}?`,
|
|
235
|
+
`拿到連結的任何人都能存取這個服務,${hours ? `${hours} 小時` : `${minutes} 分鐘`}後自動停止,關掉 Ta 也會停止。連結經 Cloudflare 轉發,網域是隨機的 trycloudflare.com。只公開你願意給別人看的服務;公司網路通常禁止這樣做。`
|
|
236
|
+
],
|
|
237
|
+
"en-US": [
|
|
238
|
+
`Make localhost:${port} public?`,
|
|
239
|
+
`Anyone with the link can reach this service, for ${hours ? `${hours} hour${hours === 1 ? "" : "s"}` : `${minutes} minutes`} or until Ta stops. It goes through Cloudflare, on a random domain of trycloudflare.com. Make public only what you would show anyone; company networks usually forbid it.`
|
|
240
|
+
],
|
|
241
|
+
"ja-JP": [
|
|
242
|
+
`localhost:${port} を公開しますか?`,
|
|
243
|
+
`リンクを持つ誰でもこのサービスにアクセスできます。${hours ? `${hours} 時間` : `${minutes} 分`}後、または Ta を閉じると停止します。Cloudflare 経由で、ランダムな trycloudflare.com のドメインになります。誰に見られてもよいものだけを公開してください。会社のネットワークでは通常禁止されています。`
|
|
244
|
+
]
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
ShareServerTexts.publicConfirm = publicConfirm;
|
|
248
|
+
function reportsTitle() {
|
|
249
|
+
return TaLanguageUtil.say({ "zh-CN": "分享被举报", "zh-TW": "分享被檢舉", "en-US": "A share was reported", "ja-JP": "共有が報告されました" });
|
|
250
|
+
}
|
|
251
|
+
ShareServerTexts.reportsTitle = reportsTitle;
|
|
252
|
+
function reported(reason, count, note) {
|
|
253
|
+
const lang = language();
|
|
254
|
+
const why = TaLanguageUtil.pick(lang, REASONS)[reason] ?? reason;
|
|
255
|
+
const times = TaLanguageUtil.pick(lang, {
|
|
256
|
+
"zh-CN": count > 1 ? `(${count} 次)` : "",
|
|
257
|
+
"zh-TW": count > 1 ? `(${count} 次)` : "",
|
|
258
|
+
"en-US": count > 1 ? ` (${count} times)` : "",
|
|
259
|
+
"ja-JP": count > 1 ? `(${count} 回)` : ""
|
|
260
|
+
});
|
|
261
|
+
return `${why}${times}${note ? `:${note.slice(0, 120)}` : ""}`;
|
|
262
|
+
}
|
|
263
|
+
ShareServerTexts.reported = reported;
|
|
264
|
+
function logged(entry) {
|
|
265
|
+
const [kind] = entry.target.split(":");
|
|
266
|
+
const what = TaLanguageUtil.say({
|
|
267
|
+
"zh-CN": kind === "account" ? "一个账号" : kind === "host" ? "一台电脑" : "一条链接",
|
|
268
|
+
"zh-TW": kind === "account" ? "一個帳號" : kind === "host" ? "一台電腦" : "一條連結",
|
|
269
|
+
"en-US": kind === "account" ? "an account" : kind === "host" ? "a computer" : "a link",
|
|
270
|
+
"ja-JP": kind === "account" ? "アカウント" : kind === "host" ? "コンピュータ" : "リンク"
|
|
271
|
+
});
|
|
272
|
+
if (entry.action === "appeal") {
|
|
273
|
+
return TaLanguageUtil.say({
|
|
274
|
+
"zh-CN": `收到申诉:${entry.reason ?? ""}`,
|
|
275
|
+
"zh-TW": `收到申訴:${entry.reason ?? ""}`,
|
|
276
|
+
"en-US": `An appeal: ${entry.reason ?? ""}`,
|
|
277
|
+
"ja-JP": `異議申し立て:${entry.reason ?? ""}`
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
const done = TaLanguageUtil.say({
|
|
281
|
+
"zh-CN": entry.action === "limit" ? "限制了公开分享:" : "封禁了",
|
|
282
|
+
"zh-TW": entry.action === "limit" ? "限制了公開分享:" : "封鎖了",
|
|
283
|
+
"en-US": entry.action === "limit" ? "limited the public links of" : "blocked",
|
|
284
|
+
"ja-JP": entry.action === "limit" ? "公開共有を制限しました:" : "ブロックしました:"
|
|
285
|
+
});
|
|
286
|
+
return TaLanguageUtil.say({
|
|
287
|
+
"zh-CN": `自动规则${done}${what},误判可在举报处理里撤销。`,
|
|
288
|
+
"zh-TW": `自動規則${done}${what},誤判可在檢舉處理裡撤銷。`,
|
|
289
|
+
"en-US": `The rules ${done} ${what}; undo it in Reports if it was wrong.`,
|
|
290
|
+
"ja-JP": `自動ルールが${what}を${done}誤りなら「報告の対応」で取り消せます。`
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
ShareServerTexts.logged = logged;
|
|
206
294
|
function password() {
|
|
207
295
|
return TaLanguageUtil.say({
|
|
208
296
|
"zh-CN": "设置查看口令",
|
|
@@ -226,8 +314,10 @@ var ShareServerTexts;
|
|
|
226
314
|
// web-src/share-protocol.ts
|
|
227
315
|
var NAME = "@celljs/ta-share";
|
|
228
316
|
var SHARE_TOOL = "share_link";
|
|
317
|
+
var PUBLIC_TOOL = "public_link";
|
|
229
318
|
var CONVERSATION_KIND = "ta-conversation";
|
|
230
319
|
var FILE_KIND = "file";
|
|
320
|
+
var MAX_FILE_BYTES = 8 * 1024 * 1024;
|
|
231
321
|
var ShareLink;
|
|
232
322
|
((ShareLink) => {
|
|
233
323
|
const LINK = /^https?:\/\/[^/\s#?]+\/s#v=1&\S+$/i;
|
|
@@ -245,6 +335,216 @@ var ShareLink;
|
|
|
245
335
|
ShareLink.needsPassword = needsPassword;
|
|
246
336
|
})(ShareLink ||= {});
|
|
247
337
|
|
|
338
|
+
// web-src/share-tunnels.ts
|
|
339
|
+
import { spawn } from "node:child_process";
|
|
340
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
341
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
342
|
+
import { delimiter, join } from "node:path";
|
|
343
|
+
var CLOUDFLARED_VERSION = "2026.11.1";
|
|
344
|
+
var CLOUDFLARED_FILES = {
|
|
345
|
+
"darwin-arm64": { file: "cloudflared-darwin-arm64.tgz", sha256: "1cd7041838e5b0943378763ca86ddc0af896d1727875f36b29f5cc35eb2c4df7", tgz: true },
|
|
346
|
+
"darwin-x64": { file: "cloudflared-darwin-amd64.tgz", sha256: "52686df40889be19803c368470bd46d5228737462f10a40380bedb6af8ed49a2", tgz: true },
|
|
347
|
+
"linux-x64": { file: "cloudflared-linux-amd64", sha256: "97bb3b02d23a5980fc9c15a1a270e692da1923f103f920d5b16d4931d5ab55e7" },
|
|
348
|
+
"linux-arm64": { file: "cloudflared-linux-arm64", sha256: "b155cec3e48e489cfb8e5c602769fb8c771083018d8881d68b4d18a791567c5a" },
|
|
349
|
+
"win32-x64": { file: "cloudflared-windows-amd64.exe", sha256: "341deda3db5ec498a0482254d6c38c0b7cf01a30c37bb5dd95d2216d08955e35" }
|
|
350
|
+
};
|
|
351
|
+
var TUNNEL_MINUTES = 60;
|
|
352
|
+
var TUNNEL_MAX_MINUTES = 8 * 60;
|
|
353
|
+
var TUNNEL_MAX = 3;
|
|
354
|
+
var URL_PATTERN = /https:\/\/[a-z0-9-]+\.trycloudflare\.com/;
|
|
355
|
+
var START_MS = 45000;
|
|
356
|
+
|
|
357
|
+
class ShareTunnels {
|
|
358
|
+
options;
|
|
359
|
+
tunnels = new Map;
|
|
360
|
+
fetching;
|
|
361
|
+
constructor(options) {
|
|
362
|
+
this.options = options;
|
|
363
|
+
}
|
|
364
|
+
get env() {
|
|
365
|
+
return this.options.env ?? process.env;
|
|
366
|
+
}
|
|
367
|
+
now() {
|
|
368
|
+
return (this.options.now ?? Date.now)();
|
|
369
|
+
}
|
|
370
|
+
get allowed() {
|
|
371
|
+
return !/^(off|0|false|no)$/i.test(String(this.env.TA_PUBLIC_TUNNELS ?? "").trim());
|
|
372
|
+
}
|
|
373
|
+
async state() {
|
|
374
|
+
return { allowed: this.allowed, enabled: this.allowed && await this.options.enabled(), tunnels: this.list() };
|
|
375
|
+
}
|
|
376
|
+
async setEnabled(enabled) {
|
|
377
|
+
if (enabled && !this.allowed) {
|
|
378
|
+
throw new Error(ShareTunnels.FORBIDDEN);
|
|
379
|
+
}
|
|
380
|
+
await this.options.setEnabled(!!enabled);
|
|
381
|
+
if (!enabled) {
|
|
382
|
+
this.stopAll();
|
|
383
|
+
}
|
|
384
|
+
return this.state();
|
|
385
|
+
}
|
|
386
|
+
list() {
|
|
387
|
+
return [...this.tunnels.values()].map(({ child: _child, timer: _timer, ...info }) => info);
|
|
388
|
+
}
|
|
389
|
+
async open(port, minutes = TUNNEL_MINUTES, title) {
|
|
390
|
+
if (!this.allowed) {
|
|
391
|
+
throw new Error(ShareTunnels.FORBIDDEN);
|
|
392
|
+
}
|
|
393
|
+
if (!await this.options.enabled()) {
|
|
394
|
+
throw new Error("Public links of services of this computer are off: the user turns them on in Discover → My shares.");
|
|
395
|
+
}
|
|
396
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
397
|
+
throw new Error("Give the port of a service of this computer, 1 to 65535.");
|
|
398
|
+
}
|
|
399
|
+
if (port === this.servePort()) {
|
|
400
|
+
throw new Error("That is the port of Ta itself, which is never made public: reach it from a phone through Ta instead.");
|
|
401
|
+
}
|
|
402
|
+
const same = [...this.tunnels.values()].find((tunnel2) => tunnel2.port === port);
|
|
403
|
+
if (same) {
|
|
404
|
+
return this.list().find((tunnel2) => tunnel2.id === same.id);
|
|
405
|
+
}
|
|
406
|
+
if (this.tunnels.size >= TUNNEL_MAX) {
|
|
407
|
+
throw new Error(`At most ${TUNNEL_MAX} public links are open at once: stop one in Discover → My shares.`);
|
|
408
|
+
}
|
|
409
|
+
const kept = Math.min(Math.max(Math.round(Number(minutes) || TUNNEL_MINUTES), 1), TUNNEL_MAX_MINUTES);
|
|
410
|
+
const { command, args } = this.options.command ? await this.options.command(port) : { command: await this.cloudflared(), args: ShareTunnels.args(port) };
|
|
411
|
+
const child = spawn(command, args, { stdio: ["ignore", "pipe", "pipe"], env: { ...this.env, TUNNEL_METRICS: "" }, windowsHide: true });
|
|
412
|
+
const url = await new Promise((resolve, reject) => {
|
|
413
|
+
let seen = "";
|
|
414
|
+
const timer2 = setTimeout(() => done(new Error("Cloudflare gave no link in time: the network may not reach it.")), START_MS);
|
|
415
|
+
const done = (error, found) => {
|
|
416
|
+
clearTimeout(timer2);
|
|
417
|
+
child.stdout?.off("data", read);
|
|
418
|
+
child.stderr?.off("data", read);
|
|
419
|
+
child.off("exit", exited);
|
|
420
|
+
child.off("error", failed);
|
|
421
|
+
if (found) {
|
|
422
|
+
resolve(found);
|
|
423
|
+
} else {
|
|
424
|
+
child.kill();
|
|
425
|
+
reject(error);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
const read = (data) => {
|
|
429
|
+
seen = (seen + String(data)).slice(-8000);
|
|
430
|
+
const found = URL_PATTERN.exec(seen)?.[0];
|
|
431
|
+
if (found) {
|
|
432
|
+
done(undefined, found);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
const exited = (code) => done(new Error(`cloudflared stopped (${code ?? "killed"}): ${seen.trim().split(`
|
|
436
|
+
`).slice(-3).join(" ")}`));
|
|
437
|
+
const failed = (error) => done(error);
|
|
438
|
+
child.stdout?.on("data", read);
|
|
439
|
+
child.stderr?.on("data", read);
|
|
440
|
+
child.once("exit", exited);
|
|
441
|
+
child.once("error", failed);
|
|
442
|
+
});
|
|
443
|
+
const now = this.now();
|
|
444
|
+
const id = randomBytes(9).toString("base64url");
|
|
445
|
+
const timer = setTimeout(() => this.stop(id), kept * 60000);
|
|
446
|
+
timer.unref?.();
|
|
447
|
+
const tunnel = {
|
|
448
|
+
id,
|
|
449
|
+
port,
|
|
450
|
+
url,
|
|
451
|
+
title: String(title ?? "").trim().slice(0, 80) || `localhost:${port}`,
|
|
452
|
+
createdAt: now,
|
|
453
|
+
expiresAt: now + kept * 60000,
|
|
454
|
+
child,
|
|
455
|
+
timer
|
|
456
|
+
};
|
|
457
|
+
child.stdout?.resume();
|
|
458
|
+
child.stderr?.resume();
|
|
459
|
+
child.once("exit", () => this.forget(id));
|
|
460
|
+
this.tunnels.set(id, tunnel);
|
|
461
|
+
return this.list().find((each) => each.id === id);
|
|
462
|
+
}
|
|
463
|
+
stop(id) {
|
|
464
|
+
const tunnel = this.tunnels.get(String(id));
|
|
465
|
+
if (!tunnel) {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
this.forget(tunnel.id);
|
|
469
|
+
tunnel.child.kill();
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
stopAll() {
|
|
473
|
+
for (const id of [...this.tunnels.keys()]) {
|
|
474
|
+
this.stop(id);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
forget(id) {
|
|
478
|
+
const tunnel = this.tunnels.get(id);
|
|
479
|
+
if (tunnel) {
|
|
480
|
+
clearTimeout(tunnel.timer);
|
|
481
|
+
this.tunnels.delete(id);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
servePort() {
|
|
485
|
+
try {
|
|
486
|
+
const port = JSON.parse(readFileSync(join(this.options.agentDir, "serve-state.json"), "utf8")).port;
|
|
487
|
+
return typeof port === "number" ? port : undefined;
|
|
488
|
+
} catch {
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
static args(port) {
|
|
493
|
+
return ["tunnel", "--no-autoupdate", "--url", `http://localhost:${port}`];
|
|
494
|
+
}
|
|
495
|
+
static FORBIDDEN = "Public links of services of this computer are turned off for this computer (TA_PUBLIC_TUNNELS=off).";
|
|
496
|
+
cloudflared() {
|
|
497
|
+
const name = process.platform === "win32" ? "cloudflared.exe" : "cloudflared";
|
|
498
|
+
for (const dir of String(this.env.PATH ?? "").split(delimiter)) {
|
|
499
|
+
if (dir && existsSync(join(dir, name))) {
|
|
500
|
+
return Promise.resolve(join(dir, name));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
const kept = join(this.options.agentDir, "bin", `${name.replace(/\.exe$/, "")}-${CLOUDFLARED_VERSION}${name.endsWith(".exe") ? ".exe" : ""}`);
|
|
504
|
+
if (existsSync(kept)) {
|
|
505
|
+
return Promise.resolve(kept);
|
|
506
|
+
}
|
|
507
|
+
this.fetching ??= ShareTunnels.download(kept).finally(() => {
|
|
508
|
+
this.fetching = undefined;
|
|
509
|
+
});
|
|
510
|
+
return this.fetching;
|
|
511
|
+
}
|
|
512
|
+
static async download(to, platform = `${process.platform}-${process.arch}`) {
|
|
513
|
+
const release = CLOUDFLARED_FILES[platform];
|
|
514
|
+
if (!release) {
|
|
515
|
+
throw new Error(`There is no cloudflared for ${platform}: install it and put it on the PATH.`);
|
|
516
|
+
}
|
|
517
|
+
const response = await fetch(`https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARED_VERSION}/${release.file}`);
|
|
518
|
+
if (!response.ok) {
|
|
519
|
+
throw new Error(`cloudflared could not be fetched (${response.status}).`);
|
|
520
|
+
}
|
|
521
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
522
|
+
if (createHash("sha256").update(bytes).digest("hex") !== release.sha256) {
|
|
523
|
+
throw new Error("cloudflared fetched is not the release Ta knows (its SHA-256 differs): nothing was kept.");
|
|
524
|
+
}
|
|
525
|
+
const dir = join(to, "..");
|
|
526
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
527
|
+
const temp = `${to}.${randomBytes(4).toString("hex")}`;
|
|
528
|
+
if (release.tgz) {
|
|
529
|
+
const work = `${temp}.d`;
|
|
530
|
+
mkdirSync(work, { recursive: true });
|
|
531
|
+
writeFileSync(join(work, "release.tgz"), bytes);
|
|
532
|
+
await new Promise((resolve, reject) => {
|
|
533
|
+
const tar = spawn("tar", ["-xzf", "release.tgz", "cloudflared"], { cwd: work, stdio: "ignore" });
|
|
534
|
+
tar.once("error", reject);
|
|
535
|
+
tar.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`tar could not unpack cloudflared (${code}).`)));
|
|
536
|
+
});
|
|
537
|
+
renameSync(join(work, "cloudflared"), temp);
|
|
538
|
+
rmSync(work, { recursive: true, force: true });
|
|
539
|
+
} else {
|
|
540
|
+
writeFileSync(temp, bytes);
|
|
541
|
+
}
|
|
542
|
+
chmodSync(temp, 493);
|
|
543
|
+
renameSync(temp, to);
|
|
544
|
+
return to;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
248
548
|
// web-src/extension.ts
|
|
249
549
|
var TYPES = {
|
|
250
550
|
html: "text/html",
|
|
@@ -341,6 +641,49 @@ function activate(pi) {
|
|
|
341
641
|
return { content: [{ type: "text", text: `Shared: ${link}${how}` }], details: { link } };
|
|
342
642
|
}
|
|
343
643
|
});
|
|
644
|
+
pi.registerTool({
|
|
645
|
+
name: PUBLIC_TOOL,
|
|
646
|
+
label: "Public link of a local service",
|
|
647
|
+
description: "Make a temporary public link (https://….trycloudflare.com) of a web page or API running on a port of localhost here, for someone elsewhere to open. Only when the user asks to let others reach a local service. Off unless the user turned it on in Discover → My shares, and never where the computer forbids it (a company network); the user confirms each one. It stops after its minutes or when Ta stops. Answer with the link.",
|
|
648
|
+
promptSnippet: "Make a public link of a service on localhost, when the user asks",
|
|
649
|
+
parameters: {
|
|
650
|
+
type: "object",
|
|
651
|
+
properties: {
|
|
652
|
+
port: { type: "number", description: "The port of the service on localhost." },
|
|
653
|
+
minutes: { type: "number", description: `How long it stays open: ${TUNNEL_MINUTES} by default, ${TUNNEL_MAX_MINUTES} at most.` },
|
|
654
|
+
title: { type: "string", description: "What the service is, in a few words, as My shares lists it." }
|
|
655
|
+
},
|
|
656
|
+
required: ["port"]
|
|
657
|
+
},
|
|
658
|
+
execute: async (_id, params, _signal, _update, ctx) => {
|
|
659
|
+
const found = await reach();
|
|
660
|
+
if (!found) {
|
|
661
|
+
throw new Error("Public links need the Ta service.");
|
|
662
|
+
}
|
|
663
|
+
if (!ctx.hasUI) {
|
|
664
|
+
throw new Error("A public link needs the user to confirm it in Ta; there is no one to ask here.");
|
|
665
|
+
}
|
|
666
|
+
const port = Number(params.port);
|
|
667
|
+
const minutes = Math.min(Math.max(Math.round(Number(params.minutes) || TUNNEL_MINUTES), 1), TUNNEL_MAX_MINUTES);
|
|
668
|
+
const state = await found.service.tunnelState();
|
|
669
|
+
if (!state.allowed || !state.enabled) {
|
|
670
|
+
await found.service.tunnels.open(port, minutes);
|
|
671
|
+
}
|
|
672
|
+
if (!await ctx.ui.confirm(...ShareServerTexts.publicConfirm(port, minutes)).catch(() => false)) {
|
|
673
|
+
throw new Error("The user did not want to make it public.");
|
|
674
|
+
}
|
|
675
|
+
const tunnel = await found.service.tunnels.open(port, minutes, typeof params.title === "string" ? params.title : undefined);
|
|
676
|
+
return {
|
|
677
|
+
content: [
|
|
678
|
+
{
|
|
679
|
+
type: "text",
|
|
680
|
+
text: `Public: ${tunnel.url} (localhost:${tunnel.port}, until ${new Date(tunnel.expiresAt).toISOString()}). Stop it in Discover → My shares.`
|
|
681
|
+
}
|
|
682
|
+
],
|
|
683
|
+
details: { link: tunnel.url }
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
});
|
|
344
687
|
}
|
|
345
688
|
export {
|
|
346
689
|
typeOf,
|