@celljs/ta-moments 4.16.0 → 4.18.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.
@@ -1,4 +1,5 @@
1
1
  // ../ta-protocol/esm/common/ta-extension-host.js
2
+ var TA_WEBHOOK_MAX_BYTES = 256 * 1024;
2
3
  var TA_HOST_EVENT = "ta:host";
3
4
  var TaHostUtil;
4
5
  (function(TaHostUtil2) {
@@ -159,10 +160,53 @@ var MomentsBrief;
159
160
 
160
161
  // ../ta-protocol/esm/common/access-protocol.js
161
162
  var TaAccessServer = Symbol("TaAccessServer");
162
- // ../ta-protocol/esm/common/auth-protocol.js
163
- var TaAuthServer = Symbol("TaAuthServer");
164
- // ../ta-protocol/esm/common/gateway-protocol.js
165
- var TaGatewayServer = Symbol("TaGatewayServer");
163
+ var TA_SIGN_IN_PATH = "/sign-in";
164
+ var TA_DEVICE_SIGN_IN_PATH = `${TA_SIGN_IN_PATH}/device`;
165
+ // ../ta-protocol/esm/common/delegate-protocol.js
166
+ var TaDelegateUtil;
167
+ (function(TaDelegateUtil2) {
168
+ TaDelegateUtil2.LEVELS = ["less", "balanced", "more"];
169
+ TaDelegateUtil2.DEFAULT = "balanced";
170
+ TaDelegateUtil2.WORK_TOOLS = ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls"];
171
+ TaDelegateUtil2.CHANGE_TOOLS = ["edit", "write"];
172
+ const LIMITS = {
173
+ less: { noChanges: false },
174
+ balanced: { noChanges: true, steps: 6 },
175
+ more: { noChanges: true, steps: 2 }
176
+ };
177
+ function parse(value) {
178
+ return TaDelegateUtil2.LEVELS.includes(value) ? value : TaDelegateUtil2.DEFAULT;
179
+ }
180
+ TaDelegateUtil2.parse = parse;
181
+ function mark(level) {
182
+ return `(delegate=${level})`;
183
+ }
184
+ TaDelegateUtil2.mark = mark;
185
+ function levelOf(systemPrompt) {
186
+ const role = TaHostUtil.role(systemPrompt);
187
+ return TaDelegateUtil2.LEVELS.find((level) => role.includes(mark(level)));
188
+ }
189
+ TaDelegateUtil2.levelOf = levelOf;
190
+ function limits(level) {
191
+ return LIMITS[level];
192
+ }
193
+ TaDelegateUtil2.limits = limits;
194
+ function refusal(level, tool, steps) {
195
+ if (!TaDelegateUtil2.WORK_TOOLS.includes(tool)) {
196
+ return;
197
+ }
198
+ const limit = LIMITS[level];
199
+ if (limit.noChanges && TaDelegateUtil2.CHANGE_TOOLS.includes(tool)) {
200
+ return "You do not change files yourself: hand this to a task with start_task, with instructions complete enough to do it. The user set how much you hand out in the settings of the double.";
201
+ }
202
+ if (limit.steps !== undefined && steps >= limit.steps) {
203
+ return "You have looked enough for this: hand the work to a task with start_task now, with what you found in its instructions, and tell the user what you started.";
204
+ }
205
+ return;
206
+ }
207
+ TaDelegateUtil2.refusal = refusal;
208
+ })(TaDelegateUtil || (TaDelegateUtil = {}));
209
+
166
210
  // ../ta-protocol/esm/common/language.js
167
211
  var TaLanguageUtil;
168
212
  (function(TaLanguageUtil2) {
@@ -201,6 +245,377 @@ var TaLanguageUtil;
201
245
  }
202
246
  TaLanguageUtil2.list = list;
203
247
  })(TaLanguageUtil || (TaLanguageUtil = {}));
248
+
249
+ // ../ta-protocol/esm/common/app-protocol.js
250
+ var FONT_SIZES = ["small", "standard", "large", "xlarge"];
251
+ var words = (en, zh, tw, ja) => ({ "en-US": en, "zh-CN": zh, "zh-TW": tw, "ja-JP": ja });
252
+ var SYSTEM = words("as the system", "跟随系统", "跟隨系統", "システムに合わせる");
253
+ var FONT_SHOWN = {
254
+ small: words("small", "小", "小", "小"),
255
+ standard: words("standard", "标准", "標準", "標準"),
256
+ large: words("large", "大", "大", "大"),
257
+ xlarge: words("extra large", "特大", "特大", "特大")
258
+ };
259
+ var TA_WEB_SETTINGS = [
260
+ {
261
+ key: "theme",
262
+ type: "enum",
263
+ values: ["system", "light", "dark"],
264
+ default: "system",
265
+ what: "Light or dark look; system follows the device.",
266
+ title: words("Theme", "外观", "外觀", "外観"),
267
+ shown: { system: SYSTEM, light: words("light", "浅色", "淺色", "ライト"), dark: words("dark", "深色", "深色", "ダーク") }
268
+ },
269
+ {
270
+ key: "language",
271
+ type: "enum",
272
+ values: ["system", ...TaLanguageUtil.ALL],
273
+ default: "system",
274
+ what: "The language of Ta's pages and of what Ta says; system follows the device.",
275
+ title: words("Language", "语言", "語言", "言語"),
276
+ shown: {
277
+ system: SYSTEM,
278
+ ...Object.fromEntries(TaLanguageUtil.ALL.map((language) => [
279
+ language,
280
+ words(TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language])
281
+ ]))
282
+ }
283
+ },
284
+ {
285
+ key: "fontSize",
286
+ type: "enum",
287
+ values: FONT_SIZES,
288
+ default: "standard",
289
+ what: "The size of the text of the whole page.",
290
+ title: words("Text size", "字体大小", "字型大小", "文字サイズ"),
291
+ shown: FONT_SHOWN
292
+ },
293
+ {
294
+ key: "chatFontSize",
295
+ type: "enum",
296
+ values: FONT_SIZES,
297
+ default: "standard",
298
+ what: "The size of the text of conversations, on top of fontSize.",
299
+ title: words("Text size of conversations", "对话字体大小", "對話字型大小", "会話の文字サイズ"),
300
+ shown: FONT_SHOWN
301
+ },
302
+ {
303
+ key: "speak",
304
+ type: "boolean",
305
+ default: false,
306
+ what: "Read every reply aloud.",
307
+ title: words("Read replies aloud", "朗读回复", "朗讀回覆", "返信を読み上げ")
308
+ },
309
+ {
310
+ key: "speakTalk",
311
+ type: "boolean",
312
+ default: false,
313
+ what: "Read the reply aloud when the user spoke to the double by voice.",
314
+ title: words("Read aloud what was asked by voice", "语音提问时朗读回复", "語音提問時朗讀回覆", "音声で聞いたら読み上げ")
315
+ },
316
+ {
317
+ key: "callCaptions",
318
+ type: "boolean",
319
+ default: false,
320
+ what: "Show captions in a call: what the user says and what Ta reads.",
321
+ title: words("Call captions", "通话字幕", "通話字幕", "通話の字幕")
322
+ },
323
+ {
324
+ key: "voice",
325
+ type: "string",
326
+ default: "",
327
+ what: "The voice replies are read with (a voiceURI of the device's voices); empty for the most natural one.",
328
+ title: words("Voice", "朗读声音", "朗讀聲音", "読み上げの声")
329
+ },
330
+ {
331
+ key: "confirmTasks",
332
+ type: "boolean",
333
+ default: false,
334
+ what: "The double asks before it hands out work.",
335
+ title: words("Ask before handing out work", "派任务前先问我", "派任務前先問我", "作業を割り当てる前に確認")
336
+ },
337
+ {
338
+ key: "maxTasks",
339
+ type: "number",
340
+ values: [0, 2, 4, 8],
341
+ default: 0,
342
+ what: "How many of the double's tasks run at once; 0 for as many as it starts.",
343
+ title: words("Tasks at once", "同时运行的任务", "同時執行的任務", "同時に実行するタスク")
344
+ },
345
+ {
346
+ key: "delegate",
347
+ type: "enum",
348
+ values: TaDelegateUtil.LEVELS,
349
+ default: TaDelegateUtil.DEFAULT,
350
+ what: "How much of the work the double hands out to tasks rather than doing it itself.",
351
+ title: words("Hand out work", "派活多少", "派活多少", "作業の割り当て"),
352
+ shown: { less: words("less", "少", "少", "少なめ"), balanced: words("balanced", "适中", "適中", "ふつう"), more: words("more", "多", "多", "多め") }
353
+ },
354
+ {
355
+ key: "assistantModel",
356
+ type: "model",
357
+ default: "",
358
+ what: "The model of the double, <provider>/<model id>; empty for the default model.",
359
+ title: words("Model of the double", "分身的模型", "分身的模型", "分身のモデル")
360
+ },
361
+ {
362
+ key: "taskModel",
363
+ type: "model",
364
+ default: "",
365
+ what: "The model of the tasks the double starts; empty for the default model.",
366
+ title: words("Model of tasks", "任务的模型", "任務的模型", "タスクのモデル")
367
+ },
368
+ { key: "reduceMotion", type: "boolean", default: false, what: "Fewer animations.", title: words("Reduce motion", "减少动画", "減少動畫", "動きを減らす") },
369
+ {
370
+ key: "diagramStyle",
371
+ type: "enum",
372
+ values: ["clean", "sketch", "colour", "motion"],
373
+ default: "clean",
374
+ what: "How diagrams in replies draw: in the colours of the page, as by hand, a colour to a node, or coming in with flowing lines.",
375
+ title: words("Diagram style", "图表风格", "圖表風格", "図のスタイル"),
376
+ shown: {
377
+ clean: words("clean", "简洁", "簡潔", "シンプル"),
378
+ sketch: words("sketch", "草图", "草圖", "スケッチ"),
379
+ colour: words("colour", "彩色", "彩色", "カラー"),
380
+ motion: words("motion", "动效", "動效", "モーション")
381
+ }
382
+ },
383
+ {
384
+ key: "keepAliveMinutes",
385
+ type: "number",
386
+ values: [1, 5, 15, 30],
387
+ default: 5,
388
+ what: "How long an extension started on open keeps running once left, in minutes.",
389
+ title: words("Keep extensions running", "扩展离开后保留", "擴充功能離開後保留", "拡張機能を保持")
390
+ },
391
+ {
392
+ key: "chatFoldDays",
393
+ type: "number",
394
+ values: [3, 7, 30, 0],
395
+ default: 7,
396
+ what: "Conversations not updated for these days fold at the end of the list; 0 for none.",
397
+ title: words("Fold old conversations", "折叠旧对话", "摺疊舊對話", "古い会話を折りたたむ")
398
+ },
399
+ {
400
+ key: "chatArchiveDays",
401
+ type: "number",
402
+ values: [30, 90, 365, 0],
403
+ default: 30,
404
+ what: "Conversations not updated for these days are archived (out of the list, found by search); 0 for none.",
405
+ title: words("Archive old conversations", "归档旧对话", "歸檔舊對話", "古い会話をアーカイブ")
406
+ },
407
+ {
408
+ key: "recentShots",
409
+ type: "boolean",
410
+ default: true,
411
+ what: "The screenshot just taken is offered above the message box, once.",
412
+ title: words("Offer recent screenshots", "提示刚截的图", "提示剛截的圖", "撮ったばかりのスクリーンショットを提案")
413
+ }
414
+ ];
415
+ var TaAppUtil;
416
+ (function(TaAppUtil2) {
417
+ function check(spec, value) {
418
+ var _a, _b;
419
+ switch (spec.type) {
420
+ case "boolean":
421
+ return typeof value === "boolean" ? undefined : "true or false";
422
+ case "string":
423
+ return typeof value === "string" ? undefined : "a string";
424
+ case "model":
425
+ return value === "" || typeof value === "string" && /^[^/\s]+\/\S+$/.test(value) ? undefined : "<provider>/<model id>, or empty";
426
+ default:
427
+ return ((_a = spec.values) === null || _a === undefined ? undefined : _a.includes(value)) ? undefined : `one of ${(_b = spec.values) === null || _b === undefined ? undefined : _b.map((one) => JSON.stringify(one)).join(", ")}`;
428
+ }
429
+ }
430
+ TaAppUtil2.check = check;
431
+ function shown(value, language, spec) {
432
+ var _a;
433
+ const named = (_a = spec === null || spec === undefined ? undefined : spec.shown) === null || _a === undefined ? undefined : _a[String(value)];
434
+ if (named) {
435
+ return TaLanguageUtil.pick(language, named);
436
+ }
437
+ if (typeof value === "boolean") {
438
+ return TaLanguageUtil.pick(language, value ? words("on", "开", "開", "オン") : words("off", "关", "關", "オフ"));
439
+ }
440
+ if (value === "" || value === undefined || value === null) {
441
+ return TaLanguageUtil.pick(language, words("default", "默认", "預設", "デフォルト"));
442
+ }
443
+ return String(value);
444
+ }
445
+ TaAppUtil2.shown = shown;
446
+ })(TaAppUtil || (TaAppUtil = {}));
447
+ // ../ta-protocol/esm/common/auth-protocol.js
448
+ var TaAuthServer = Symbol("TaAuthServer");
449
+ // ../ta-protocol/esm/common/deployment-protocol.js
450
+ var TA_WELL_KNOWN_PATH = "/.well-known/ta";
451
+
452
+ class TaDeploymentError extends Error {
453
+ }
454
+ var TaDeploymentUtil;
455
+ (function(TaDeploymentUtil2) {
456
+ TaDeploymentUtil2.DISTRIBUTION_FILE = "distribution.json";
457
+ function url(value) {
458
+ if (typeof value !== "string" || !value.trim()) {
459
+ return;
460
+ }
461
+ try {
462
+ const parsed = new URL(value.trim());
463
+ if (!/^https?:$/.test(parsed.protocol) || parsed.search || parsed.hash || parsed.username || parsed.password) {
464
+ return;
465
+ }
466
+ return `${parsed.origin}${parsed.pathname}`.replace(/\/+$/, "");
467
+ } catch (_a) {
468
+ return;
469
+ }
470
+ }
471
+ TaDeploymentUtil2.url = url;
472
+ function name(value) {
473
+ return typeof value === "string" && value.trim() ? value.trim().slice(0, 80) : undefined;
474
+ }
475
+ function describe(env, own, version) {
476
+ var _a, _b;
477
+ const gateway = (_a = url(own.gateway)) !== null && _a !== undefined ? _a : url(env.TA_GATEWAY_URL);
478
+ const relay = (_b = url(own.relay)) !== null && _b !== undefined ? _b : url(env.TA_RELAY_URL);
479
+ const called = name(env.TA_DEPLOYMENT_NAME);
480
+ return { v: 1, ...called ? { name: called } : {}, ...gateway ? { gateway } : {}, ...relay ? { relay } : {}, ...version ? { version } : {} };
481
+ }
482
+ TaDeploymentUtil2.describe = describe;
483
+ TaDeploymentUtil2.HEADERS = {
484
+ "content-type": "application/json",
485
+ "access-control-allow-origin": "*",
486
+ "cache-control": "no-store"
487
+ };
488
+ function parse(value) {
489
+ const given = value;
490
+ if (!given || typeof given !== "object" || given.v !== 1) {
491
+ return;
492
+ }
493
+ const deployment = describe({ TA_DEPLOYMENT_NAME: given.name, TA_GATEWAY_URL: given.gateway, TA_RELAY_URL: given.relay }, {});
494
+ const version = name(given.version);
495
+ return version ? { ...deployment, version } : deployment;
496
+ }
497
+ TaDeploymentUtil2.parse = parse;
498
+ async function discover(address, timeoutMs = 6000) {
499
+ const base = url(address);
500
+ if (!base) {
501
+ throw new TaDeploymentError(`${address} is not an address of http or https.`);
502
+ }
503
+ const controller = new AbortController;
504
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
505
+ try {
506
+ const response = await fetch(`${base}${TA_WELL_KNOWN_PATH}`, { signal: controller.signal, redirect: "follow" });
507
+ if (!response.ok) {
508
+ throw new TaDeploymentError(`${base} is not a deployment of Ta (${response.status}).`);
509
+ }
510
+ const deployment = parse(await response.json().catch(() => {
511
+ return;
512
+ }));
513
+ if (!deployment || !deployment.gateway && !deployment.relay) {
514
+ throw new TaDeploymentError(`${base} is not a deployment of Ta.`);
515
+ }
516
+ return deployment;
517
+ } catch (error) {
518
+ if ((error === null || error === undefined ? undefined : error.name) === "AbortError") {
519
+ throw new TaDeploymentError(`${base} did not answer in time.`);
520
+ }
521
+ throw error;
522
+ } finally {
523
+ clearTimeout(timer);
524
+ }
525
+ }
526
+ TaDeploymentUtil2.discover = discover;
527
+ function distribution(value) {
528
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
529
+ throw new TaDeploymentError(`${TaDeploymentUtil2.DISTRIBUTION_FILE} holds a JSON object.`);
530
+ }
531
+ const given = value;
532
+ const result = {};
533
+ if (given.name !== undefined) {
534
+ result.name = name(given.name);
535
+ }
536
+ for (const key of ["relay", "gateway"]) {
537
+ if (given[key] !== undefined) {
538
+ const address = url(given[key]);
539
+ if (!address) {
540
+ throw new TaDeploymentError(`"${key}" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
541
+ }
542
+ result[key] = address;
543
+ }
544
+ }
545
+ if (given.updates !== undefined) {
546
+ const updates = given.updates;
547
+ const base = url(updates === null || updates === undefined ? undefined : updates.base);
548
+ if (!base && (updates === null || updates === undefined ? undefined : updates.base) !== undefined) {
549
+ throw new TaDeploymentError(`"updates.base" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
550
+ }
551
+ const key = typeof (updates === null || updates === undefined ? undefined : updates.key) === "string" && updates.key.includes("PUBLIC KEY") ? updates.key : undefined;
552
+ if ((updates === null || updates === undefined ? undefined : updates.key) !== undefined && !key) {
553
+ throw new TaDeploymentError(`"updates.key" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is a public key in PEM.`);
554
+ }
555
+ result.updates = { ...base ? { base } : {}, ...key ? { key } : {} };
556
+ }
557
+ if (given.reach !== undefined) {
558
+ result.reach = reach(given.reach);
559
+ }
560
+ if (given.inside !== undefined) {
561
+ const inside = url(given.inside);
562
+ if (!inside) {
563
+ throw new TaDeploymentError(`"inside" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
564
+ }
565
+ result.inside = inside;
566
+ }
567
+ return result;
568
+ }
569
+ TaDeploymentUtil2.distribution = distribution;
570
+ function reach(value) {
571
+ const given = typeof value === "string" ? { "*": value } : value;
572
+ const entries = given && typeof given === "object" && !Array.isArray(given) ? Object.entries(given) : [];
573
+ const result = {};
574
+ for (const [language, text] of entries) {
575
+ if (typeof text !== "string" || !text.trim()) {
576
+ throw new TaDeploymentError(`"reach.${language}" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not a sentence.`);
577
+ }
578
+ result[language] = text.trim().slice(0, 200);
579
+ }
580
+ if (Object.keys(result).length === 0) {
581
+ throw new TaDeploymentError(`"reach" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is a sentence, or one by language.`);
582
+ }
583
+ return result;
584
+ }
585
+ function reachIn(reach2, language) {
586
+ var _a, _b, _c, _d, _e;
587
+ if (!reach2) {
588
+ return;
589
+ }
590
+ const base = language.split("-")[0];
591
+ const near = Object.keys(reach2).find((key) => key.split("-")[0] === base);
592
+ return (_e = (_d = (_c = (_b = (_a = reach2[language]) !== null && _a !== undefined ? _a : reach2[base]) !== null && _b !== undefined ? _b : near && reach2[near]) !== null && _c !== undefined ? _c : reach2["*"]) !== null && _d !== undefined ? _d : reach2.en) !== null && _e !== undefined ? _e : Object.values(reach2)[0];
593
+ }
594
+ TaDeploymentUtil2.reachIn = reachIn;
595
+ function apply(distribution2, env) {
596
+ const defaults = { TA_DEPLOYMENT_NAME: distribution2.name, TA_RELAY_URL: distribution2.relay, TA_GATEWAY_URL: distribution2.gateway };
597
+ for (const [key, value] of Object.entries(defaults)) {
598
+ if (value && !env[key]) {
599
+ env[key] = value;
600
+ }
601
+ }
602
+ }
603
+ TaDeploymentUtil2.apply = apply;
604
+ })(TaDeploymentUtil || (TaDeploymentUtil = {}));
605
+ // ../ta-protocol/esm/common/error-protocol.js
606
+ var TaErrorUtil;
607
+ (function(TaErrorUtil2) {
608
+ function code(error) {
609
+ var _a;
610
+ var _b;
611
+ const failure = error;
612
+ const code2 = (_b = failure === null || failure === undefined ? undefined : failure.code) !== null && _b !== undefined ? _b : (_a = failure === null || failure === undefined ? undefined : failure.data) === null || _a === undefined ? undefined : _a.code;
613
+ return typeof code2 === "string" ? code2 : undefined;
614
+ }
615
+ TaErrorUtil2.code = code;
616
+ })(TaErrorUtil || (TaErrorUtil = {}));
617
+ // ../ta-protocol/esm/common/gateway-protocol.js
618
+ var TaGatewayServer = Symbol("TaGatewayServer");
204
619
  // ../ta-protocol/esm/common/location.js
205
620
  var TaLocation;
206
621
  (function(TaLocation2) {
@@ -262,19 +677,19 @@ var TaLocation;
262
677
  TaLocation2.isHost = isHost;
263
678
  const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
264
679
  function readHost(input) {
265
- const words = input.trim().split(/\s+/).filter(Boolean);
266
- if (words[0] === "ssh") {
267
- words.shift();
680
+ const words2 = input.trim().split(/\s+/).filter(Boolean);
681
+ if (words2[0] === "ssh") {
682
+ words2.shift();
268
683
  }
269
684
  let destination;
270
685
  let port;
271
686
  let user;
272
687
  const options = [];
273
- for (let i = 0;i < words.length; i++) {
274
- const word = words[i];
688
+ for (let i = 0;i < words2.length; i++) {
689
+ const word = words2[i];
275
690
  const glued = /^-([pl])(.+)$/.exec(word);
276
691
  if (word === "-p" || word === "-l" || glued) {
277
- const value = glued ? glued[2] : words[++i];
692
+ const value = glued ? glued[2] : words2[++i];
278
693
  if (value === undefined) {
279
694
  return { error: "invalid" };
280
695
  }
@@ -284,7 +699,7 @@ var TaLocation;
284
699
  user = value;
285
700
  }
286
701
  } else if (word === "-o" || word.startsWith("-o")) {
287
- const value = word === "-o" ? words[++i] : word.slice(2);
702
+ const value = word === "-o" ? words2[++i] : word.slice(2);
288
703
  const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
289
704
  if (!option) {
290
705
  options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
@@ -294,7 +709,7 @@ var TaLocation;
294
709
  user = option[2];
295
710
  }
296
711
  } else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
297
- options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
712
+ options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words2[i + 1] !== undefined ? `${word} ${words2[++i]}` : word);
298
713
  } else if (destination === undefined) {
299
714
  destination = word;
300
715
  } else {
@@ -400,44 +815,7 @@ var TaLocation;
400
815
  return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
401
816
  }
402
817
  })(TaLocation || (TaLocation = {}));
403
- // ../ta-protocol/esm/common/package-protocol.js
404
- var TaPackageServer = Symbol("TaPackageServer");
405
- var TaPackageTextUtil;
406
- (function(TaPackageTextUtil2) {
407
- function pick(text, language) {
408
- var _a, _b, _c, _d, _e;
409
- if (text === undefined || typeof text === "string") {
410
- return text;
411
- }
412
- const base = language.split("-")[0];
413
- const kin = Object.keys(text).find((key) => key.split("-")[0] === base);
414
- return (_e = (_d = (_c = (_b = (_a = text[language]) !== null && _a !== undefined ? _a : text[base]) !== null && _b !== undefined ? _b : kin === undefined ? undefined : text[kin]) !== null && _c !== undefined ? _c : text.en) !== null && _d !== undefined ? _d : text["en-US"]) !== null && _e !== undefined ? _e : Object.values(text)[0];
415
- }
416
- TaPackageTextUtil2.pick = pick;
417
- })(TaPackageTextUtil || (TaPackageTextUtil = {}));
418
- // ../ta-protocol/esm/common/ta-protocol.js
419
- var TaServer = Symbol("TaServer");
420
- var TaClient = Symbol("TaClient");
421
- var TaErrorUtil;
422
- (function(TaErrorUtil2) {
423
- function code(error) {
424
- var _a;
425
- var _b;
426
- const failure = error;
427
- const code2 = (_b = failure === null || failure === undefined ? undefined : failure.code) !== null && _b !== undefined ? _b : (_a = failure === null || failure === undefined ? undefined : failure.data) === null || _a === undefined ? undefined : _a.code;
428
- return typeof code2 === "string" ? code2 : undefined;
429
- }
430
- TaErrorUtil2.code = code;
431
- })(TaErrorUtil || (TaErrorUtil = {}));
432
- var TaSlashCommandUtil;
433
- (function(TaSlashCommandUtil2) {
434
- function description(command, language) {
435
- var _a, _b;
436
- const { descriptions } = command;
437
- return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
438
- }
439
- TaSlashCommandUtil2.description = description;
440
- })(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
818
+ // ../ta-protocol/esm/common/message-protocol.js
441
819
  var TaMessageContext;
442
820
  (function(TaMessageContext2) {
443
821
  const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
@@ -462,23 +840,47 @@ ${message}`;
462
840
  var TaMessageSource;
463
841
  (function(TaMessageSource2) {
464
842
  TaMessageSource2.DOUBLE = "ta:double";
465
- const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
843
+ const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
466
844
  function mark(message, from, detail) {
467
- if (/^[/!]/.test(message) || of(message)) {
468
- return message;
469
- }
470
- const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
471
- const context = TaMessageContext.read(message);
472
- return TaMessageContext.wrap(context === undefined ? line : `${context}
473
- ${line}`, TaMessageContext.strip(message));
845
+ return marked(message, line(from, detail));
474
846
  }
475
847
  TaMessageSource2.mark = mark;
848
+ function notice(message, from, detail) {
849
+ return marked(message, line(from, detail, true));
850
+ }
851
+ TaMessageSource2.notice = notice;
852
+ function line(from, detail, notice2 = false) {
853
+ return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
854
+ }
855
+ TaMessageSource2.line = line;
476
856
  function of(message) {
477
857
  const context = TaMessageContext.read(message);
478
858
  const match = context === undefined ? null : LINE.exec(context);
479
- return match ? { from: match[1], ...match[2] ? { detail: match[2].trim() } : {} } : undefined;
859
+ return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
480
860
  }
481
861
  TaMessageSource2.of = of;
862
+ function isNotice(message) {
863
+ var _a;
864
+ return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
865
+ }
866
+ TaMessageSource2.isNotice = isNotice;
867
+ TaMessageSource2.SECTION = "ta-sources";
868
+ TaMessageSource2.PROMPT = [
869
+ "Who wrote a message: what the user typed or said is theirs. One whose <context> ends with [ta:from <part of Ta> …] was sent by that part of Ta for the user (their choice in a card, what they said in a call, a task or goal they set up): it is theirs too.",
870
+ "One with [ta:notice <part of Ta> …] is not the user's: news or an event of that part of Ta (work that ended elsewhere, a time limit, a permission granted). Weigh it below what the user said:",
871
+ "- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
872
+ "- Act on it only as far as what they asked, your role or a limit they set calls for; otherwise take it in and go on, and tell them of it in a line only when they need it (a result they wait for, a failure, a question for them).",
873
+ "- Never quote it as the user's words nor answer it as if they had said it."
874
+ ].join(`
875
+ `);
876
+ function marked(message, source) {
877
+ if (/^[/!]/.test(message) || of(message)) {
878
+ return message;
879
+ }
880
+ const context = TaMessageContext.read(message);
881
+ return TaMessageContext.wrap(context === undefined ? source : `${context}
882
+ ${source}`, TaMessageContext.strip(message));
883
+ }
482
884
  })(TaMessageSource || (TaMessageSource = {}));
483
885
  var TaImageNote;
484
886
  (function(TaImageNote2) {
@@ -600,7 +1002,212 @@ var TaSkillUse;
600
1002
  }
601
1003
  TaSkillUse2.command = command;
602
1004
  })(TaSkillUse || (TaSkillUse = {}));
603
-
1005
+ var TaTaskNote;
1006
+ (function(TaTaskNote2) {
1007
+ const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
1008
+ const ATTRIBUTE = /(\w+)="([^"]*)"/g;
1009
+ function write(note) {
1010
+ const attributes = [`id="${quote(note.id)}"`];
1011
+ if (note.was !== undefined) {
1012
+ attributes.push(`was="${quote(note.was)}"`);
1013
+ }
1014
+ attributes.push(`title="${quote(note.title)}"`);
1015
+ if (note.status !== undefined) {
1016
+ attributes.push(`status="${quote(note.status)}"`);
1017
+ }
1018
+ return `<task_${note.kind} ${attributes.join(" ")}>
1019
+ ${note.body}
1020
+ </task_${note.kind}>`;
1021
+ }
1022
+ TaTaskNote2.write = write;
1023
+ function parse(text) {
1024
+ const match = NOTE.exec(text.trim());
1025
+ if (!match) {
1026
+ return;
1027
+ }
1028
+ const attributes = {};
1029
+ for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
1030
+ attributes[name] = unquote(value);
1031
+ }
1032
+ if (!attributes.id || attributes.title === undefined) {
1033
+ return;
1034
+ }
1035
+ const { id, title, status, was } = attributes;
1036
+ return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
1037
+ }
1038
+ TaTaskNote2.parse = parse;
1039
+ function quote(text) {
1040
+ return text.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/\n/g, " ");
1041
+ }
1042
+ function unquote(text) {
1043
+ return text.replace(/&quot;/g, '"').replace(/&amp;/g, "&");
1044
+ }
1045
+ })(TaTaskNote || (TaTaskNote = {}));
1046
+ var TaSecretRef;
1047
+ (function(TaSecretRef2) {
1048
+ TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
1049
+ const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
1050
+ const KINDS = [
1051
+ [/^PHONE(?:_\d+)?$/, "phone"],
1052
+ [/^EMAIL(?:_\d+)?$/, "email"],
1053
+ [/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
1054
+ [/^BANK_CARD(?:_\d+)?$/, "bankCard"]
1055
+ ];
1056
+ function has(text) {
1057
+ return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
1058
+ }
1059
+ TaSecretRef2.has = has;
1060
+ function kind(name) {
1061
+ var _a;
1062
+ var _b;
1063
+ return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
1064
+ }
1065
+ TaSecretRef2.kind = kind;
1066
+ function split(text) {
1067
+ if (!has(text)) {
1068
+ return [{ text }];
1069
+ }
1070
+ const parts = [];
1071
+ let at = 0;
1072
+ for (const match of text.matchAll(REF)) {
1073
+ if (match.index > at) {
1074
+ parts.push({ text: text.slice(at, match.index) });
1075
+ }
1076
+ parts.push({ secret: match[1], kind: kind(match[1]) });
1077
+ at = match.index + match[0].length;
1078
+ }
1079
+ if (at < text.length) {
1080
+ parts.push({ text: text.slice(at) });
1081
+ }
1082
+ return parts;
1083
+ }
1084
+ TaSecretRef2.split = split;
1085
+ function plain(text, label) {
1086
+ return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
1087
+ }
1088
+ TaSecretRef2.plain = plain;
1089
+ })(TaSecretRef || (TaSecretRef = {}));
1090
+ // ../ta-protocol/esm/common/package-protocol.js
1091
+ var TaPackageServer = Symbol("TaPackageServer");
1092
+ var TaPackageTextUtil;
1093
+ (function(TaPackageTextUtil2) {
1094
+ function pick(text, language) {
1095
+ var _a, _b, _c, _d, _e;
1096
+ if (text === undefined || typeof text === "string") {
1097
+ return text;
1098
+ }
1099
+ const base = language.split("-")[0];
1100
+ const kin = Object.keys(text).find((key) => key.split("-")[0] === base);
1101
+ return (_e = (_d = (_c = (_b = (_a = text[language]) !== null && _a !== undefined ? _a : text[base]) !== null && _b !== undefined ? _b : kin === undefined ? undefined : text[kin]) !== null && _c !== undefined ? _c : text.en) !== null && _d !== undefined ? _d : text["en-US"]) !== null && _e !== undefined ? _e : Object.values(text)[0];
1102
+ }
1103
+ TaPackageTextUtil2.pick = pick;
1104
+ })(TaPackageTextUtil || (TaPackageTextUtil = {}));
1105
+ // ../ta-protocol/esm/common/page-protocol.js
1106
+ var TaPageServer = Symbol("TaPageServer");
1107
+ // ../ta-protocol/esm/common/path-map.js
1108
+ var TaPathMap;
1109
+ (function(TaPathMap2) {
1110
+ function isWindows(path2) {
1111
+ return /^[a-zA-Z]:([\\/]|$)/.test(path2) || /^\\\\[^\\]/.test(path2);
1112
+ }
1113
+ TaPathMap2.isWindows = isWindows;
1114
+ function rest(path2, base) {
1115
+ const windows = isWindows(base);
1116
+ if (windows ? !isWindows(path2) : !base.startsWith("/") || !path2.startsWith("/")) {
1117
+ return;
1118
+ }
1119
+ const within = parts(base, windows);
1120
+ const all = parts(path2, windows);
1121
+ if (!within.length || all.length < within.length) {
1122
+ return;
1123
+ }
1124
+ const same = (a, b) => windows ? a.toLowerCase() === b.toLowerCase() : a === b;
1125
+ return within.every((part, i) => same(part, all[i])) ? all.slice(within.length) : undefined;
1126
+ }
1127
+ TaPathMap2.rest = rest;
1128
+ function under(path2, base) {
1129
+ return rest(path2, base) !== undefined;
1130
+ }
1131
+ TaPathMap2.under = under;
1132
+ function join(base, parts2) {
1133
+ if (!parts2.length) {
1134
+ return base;
1135
+ }
1136
+ const sep = isWindows(base) ? "\\" : "/";
1137
+ return `${base.replace(/[\\/]+$/, "")}${sep}${parts2.join(sep)}`;
1138
+ }
1139
+ TaPathMap2.join = join;
1140
+ function basename(path2) {
1141
+ var _a;
1142
+ return (_a = path2.split(/[\\/]+/).filter(Boolean).pop()) !== null && _a !== undefined ? _a : "";
1143
+ }
1144
+ TaPathMap2.basename = basename;
1145
+ function path(value, pairs) {
1146
+ for (const [from, to] of deepest(pairs)) {
1147
+ const found = rest(value, from);
1148
+ if (found) {
1149
+ return join(to, found);
1150
+ }
1151
+ }
1152
+ return value;
1153
+ }
1154
+ TaPathMap2.path = path;
1155
+ function text(value, pairs) {
1156
+ const order = deepest(pairs);
1157
+ if (!order.length) {
1158
+ return value;
1159
+ }
1160
+ const end = String.raw`\s"'<>|*?:;,`;
1161
+ const pattern = new RegExp(String.raw`(^|[^\w.~-])(?:${order.map(([from]) => `(${source(from)})`).join("|")})((?:[\\/][^\\/${end}]*)*)(?=$|[\\/${end})\]}])`, "g");
1162
+ return value.replace(pattern, (...match) => {
1163
+ var _a;
1164
+ const before = match[1];
1165
+ const found = order.findIndex((_, i) => match[i + 2] !== undefined);
1166
+ const tail = (_a = match[order.length + 2]) !== null && _a !== undefined ? _a : "";
1167
+ return `${before}${join(order[found][1], tail.split(/[\\/]+/).filter(Boolean))}`;
1168
+ });
1169
+ }
1170
+ TaPathMap2.text = text;
1171
+ function json(value, pairs) {
1172
+ const order = deepest(pairs);
1173
+ if (!order.length) {
1174
+ return value;
1175
+ }
1176
+ const one = (each) => {
1177
+ const whole = path(each, order);
1178
+ return whole !== each ? whole : text(each, order);
1179
+ };
1180
+ const walk = (each) => {
1181
+ if (typeof each === "string") {
1182
+ return one(each);
1183
+ }
1184
+ if (Array.isArray(each)) {
1185
+ return each.map(walk);
1186
+ }
1187
+ if (each && typeof each === "object") {
1188
+ return Object.fromEntries(Object.entries(each).map(([key, inner]) => [one(key), walk(inner)]));
1189
+ }
1190
+ return each;
1191
+ };
1192
+ return walk(value);
1193
+ }
1194
+ TaPathMap2.json = json;
1195
+ function parts(path2, windows) {
1196
+ return path2.split(windows ? /[\\/]+/ : /\/+/).filter(Boolean);
1197
+ }
1198
+ function deepest(pairs) {
1199
+ return pairs.filter(([from, to]) => from && to && from !== to && parts(from, isWindows(from)).length > 0).sort(([a], [b]) => parts(b, isWindows(b)).length - parts(a, isWindows(a)).length);
1200
+ }
1201
+ function source(base) {
1202
+ const windows = isWindows(base);
1203
+ const quote = (part) => [...part].map((char) => windows && char.toLowerCase() !== char.toUpperCase() ? `[${char.toLowerCase()}${char.toUpperCase()}]` : char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("");
1204
+ const each = parts(base, windows).map(quote);
1205
+ if (!windows) {
1206
+ return `/${each.join("/+")}`;
1207
+ }
1208
+ return `${base.startsWith("\\\\") ? String.raw`\\\\` : ""}${each.join(String.raw`[\\/]+`)}`;
1209
+ }
1210
+ })(TaPathMap || (TaPathMap = {}));
604
1211
  // ../ta-protocol/esm/common/presence-protocol.js
605
1212
  var TaPresenceServer = Symbol("TaPresenceServer");
606
1213
  var TaMessageAuthor;
@@ -677,8 +1284,281 @@ var TaRoomWatchUtil;
677
1284
  }
678
1285
  TaRoomWatchUtil2.hears = hears;
679
1286
  })(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
1287
+ // ../ta-protocol/esm/common/said-protocol.js
1288
+ var TaSaid;
1289
+ (function(TaSaid2) {
1290
+ const CARD = /^ta-/i;
1291
+ const READ = 4000;
1292
+ const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
1293
+ const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
1294
+ const MARKS_ONLY = /^[-*_=|:+\s]+$/;
1295
+ const MARKS = [
1296
+ ["context", /<\/?context>/],
1297
+ ["source", /\[ta:(?:from|notice|by) /],
1298
+ ["image note", /\[Image: original \d+x\d+|\[Image converted from /],
1299
+ ["skill", /<skill name="|<\/skill>/],
1300
+ ["task note", /<\/?task_(?:update|adopted|renamed)\b/],
1301
+ ["summary", /<\/?(?:conversation_history_summary|summary)>/]
1302
+ ];
1303
+ function text(content, joiner = `
1304
+ `) {
1305
+ if (typeof content === "string") {
1306
+ return content;
1307
+ }
1308
+ return Array.isArray(content) ? content.filter((part) => (part === null || part === undefined ? undefined : part.type) === "text" && typeof part.text === "string").map((part) => part.text).join(joiner) : "";
1309
+ }
1310
+ TaSaid2.text = text;
1311
+ function words2(role, text2, options = {}) {
1312
+ const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
1313
+ return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
1314
+ }
1315
+ TaSaid2.words = words2;
1316
+ function of(message, options) {
1317
+ return message ? words2(message.role, text(message.content), options) : "";
1318
+ }
1319
+ TaSaid2.of = of;
1320
+ function notice(message) {
1321
+ return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
1322
+ }
1323
+ TaSaid2.notice = notice;
1324
+ function marksOnly(role, text2) {
1325
+ return !!text2.trim() && !line(words2(role, text2), { chars: Number.POSITIVE_INFINITY });
1326
+ }
1327
+ TaSaid2.marksOnly = marksOnly;
1328
+ function line(markdown, options) {
1329
+ var _a;
1330
+ const read = markdown.slice(0, READ);
1331
+ const prose = withoutFences(read, () => true, true).trim();
1332
+ const lines = plain(prose || codeOf(read)).split(`
1333
+ `).map((part) => part.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+[.)]\s+)/, "").replace(/\*{1,3}|`+|~~|(?<![\p{L}\p{N}])_{1,3}|_{1,3}(?![\p{L}\p{N}])/gu, "").replace(/\s+/g, " ").trim()).filter((part) => part && !MARKS_ONLY.test(part) && !TAG_LINE.test(part));
1334
+ const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
1335
+ const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
1336
+ `);
1337
+ return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
1338
+ }
1339
+ TaSaid2.line = line;
1340
+ function leaks(shown, options = {}) {
1341
+ const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
1342
+ const lines = shown.split(`
1343
+ `);
1344
+ if (options.cards !== true && lines.some((part) => {
1345
+ var _a;
1346
+ var _b;
1347
+ return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
1348
+ })) {
1349
+ found.push("card");
1350
+ }
1351
+ if (lines.some((part) => TAG_LINE.test(part.trim()))) {
1352
+ found.push("tag");
1353
+ }
1354
+ return found;
1355
+ }
1356
+ TaSaid2.leaks = leaks;
1357
+ const SUMMARY = `<conversation_history_summary>
1358
+ <summary>
1359
+ 1. Primary Request and Intent:
1360
+ The user works on the relay.
1361
+ </summary>
1362
+ </conversation_history_summary>`;
1363
+ TaSaid2.SAMPLES = [
1364
+ {
1365
+ mark: "context and where it came from",
1366
+ role: "user",
1367
+ text: `<context>
1368
+ The channel #ops, its members.
1369
+ [ta:from @celljs/ta-channels #ops]
1370
+ </context>
1371
+ Check the build`,
1372
+ said: "Check the build"
1373
+ },
1374
+ {
1375
+ mark: "a notice, not the user",
1376
+ role: "user",
1377
+ text: `<context>
1378
+ [ta:notice @celljs/ta-call]
1379
+ </context>
1380
+ The work finished. Its last words: tests pass.`,
1381
+ said: "The work finished. Its last words: tests pass."
1382
+ },
1383
+ { mark: "one let in", role: "user", text: `<context>
1384
+ [ta:by p-7 Alice]
1385
+ </context>
1386
+ Hello there`, said: "Hello there" },
1387
+ {
1388
+ mark: "notes of images",
1389
+ role: "user",
1390
+ text: `Look at this
1391
+ [Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
1392
+ [Image converted from image/heic to image/png.]`,
1393
+ said: "Look at this"
1394
+ },
1395
+ {
1396
+ mark: "a skill run",
1397
+ role: "user",
1398
+ text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
1399
+ # Ta package
1400
+ Steps.
1401
+ </skill>
1402
+
1403
+ Make a card`,
1404
+ said: "Make a card"
1405
+ },
1406
+ {
1407
+ mark: "a note of a task",
1408
+ role: "user",
1409
+ text: `<task_update id="t1" title="Fix login" status="done">
1410
+ All tests pass.
1411
+ </task_update>`,
1412
+ said: "Fix login"
1413
+ },
1414
+ { mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
1415
+ Now t2.
1416
+ </task_renamed>` },
1417
+ { mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
1418
+ Switched to voice.`, said: "Switched to voice." },
1419
+ { mark: "a summary alone", role: "assistant", text: SUMMARY },
1420
+ { mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
1421
+ <summary>` },
1422
+ {
1423
+ mark: "a card after the answer",
1424
+ role: "assistant",
1425
+ text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
1426
+ said: "tests pass"
1427
+ },
1428
+ { mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
1429
+ { mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
1430
+ { mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
1431
+ { mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
1432
+ </system-reminder>
1433
+ Ready.`, said: "Ready." }
1434
+ ];
1435
+ function userWords(text2) {
1436
+ const said = TaImageNote.strip(TaMessageContext.strip(text2));
1437
+ const skill = TaSkillUse.parse(said);
1438
+ if (skill) {
1439
+ return TaSkillUse.command(skill);
1440
+ }
1441
+ const note = TaTaskNote.parse(said);
1442
+ if (!note) {
1443
+ return said;
1444
+ }
1445
+ if (note.kind === "renamed") {
1446
+ return "";
1447
+ }
1448
+ return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
1449
+ }
1450
+ function withoutFences(text2, drop, tags = false) {
1451
+ const kept = [];
1452
+ let fence;
1453
+ let left = false;
1454
+ for (const part of text2.split(`
1455
+ `)) {
1456
+ const open = FENCE.exec(part);
1457
+ if (!fence && open) {
1458
+ fence = { mark: open[1], dropped: drop(open[2]) };
1459
+ } else if (fence && closes(part, fence.mark)) {
1460
+ const dropped = fence.dropped;
1461
+ fence = undefined;
1462
+ if (dropped) {
1463
+ continue;
1464
+ }
1465
+ }
1466
+ if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
1467
+ left = true;
1468
+ } else {
1469
+ kept.push(part);
1470
+ }
1471
+ }
1472
+ return left ? kept.join(`
1473
+ `).replace(/\n{3,}/g, `
1474
+
1475
+ `) : kept.join(`
1476
+ `);
1477
+ }
1478
+ function codeOf(text2) {
1479
+ const code = [];
1480
+ let fence;
1481
+ for (const part of text2.split(`
1482
+ `)) {
1483
+ const open = FENCE.exec(part);
1484
+ if (!fence && open) {
1485
+ fence = { mark: open[1], card: CARD.test(open[2]) };
1486
+ } else if (fence && closes(part, fence.mark)) {
1487
+ fence = undefined;
1488
+ } else if (fence && !fence.card) {
1489
+ code.push(part);
1490
+ }
1491
+ }
1492
+ return code.join(`
1493
+ `);
1494
+ }
1495
+ function closes(part, mark) {
1496
+ var _a;
1497
+ const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
1498
+ return !!close && close[0] === mark[0] && close.length >= mark.length;
1499
+ }
1500
+ function plain(text2) {
1501
+ const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
1502
+ const words3 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
1503
+ return words3 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
1504
+ }
1505
+ })(TaSaid || (TaSaid = {}));
1506
+ // ../ta-protocol/esm/common/screen-share-protocol.js
1507
+ var TaScreenShareServer = Symbol("TaScreenShareServer");
1508
+ var TaDesktopUtil;
1509
+ (function(TaDesktopUtil2) {
1510
+ TaDesktopUtil2.DEFAULT_PORT = 5900;
1511
+ function id(target) {
1512
+ var _a;
1513
+ return `${(_a = target.via) !== null && _a !== undefined ? _a : ""}|${host(target)}:${port(target)}`;
1514
+ }
1515
+ TaDesktopUtil2.id = id;
1516
+ function host(target) {
1517
+ var _a;
1518
+ return ((_a = target.host) !== null && _a !== undefined ? _a : "").trim() || "127.0.0.1";
1519
+ }
1520
+ TaDesktopUtil2.host = host;
1521
+ function port(target) {
1522
+ var _a;
1523
+ return (_a = target.port) !== null && _a !== undefined ? _a : TaDesktopUtil2.DEFAULT_PORT;
1524
+ }
1525
+ TaDesktopUtil2.port = port;
1526
+ function parse(id2) {
1527
+ const match = /^([^|]*)\|(.+):(\d+)$/.exec(String(id2 !== null && id2 !== undefined ? id2 : ""));
1528
+ if (!match) {
1529
+ return;
1530
+ }
1531
+ const port2 = Number(match[3]);
1532
+ return port2 > 0 && port2 < 65536 ? { via: match[1], host: match[2], port: port2 } : undefined;
1533
+ }
1534
+ TaDesktopUtil2.parse = parse;
1535
+ function validPort(port2) {
1536
+ return typeof port2 === "number" && Number.isInteger(port2) && port2 >= 1024 && port2 < 65536;
1537
+ }
1538
+ TaDesktopUtil2.validPort = validPort;
1539
+ function loopback(host2) {
1540
+ return /^(127\.\d+\.\d+\.\d+|localhost|::1|\[::1\])$/i.test(host2);
1541
+ }
1542
+ TaDesktopUtil2.loopback = loopback;
1543
+ function validHost(host2) {
1544
+ return typeof host2 === "string" && /^[A-Za-z0-9.:\-[\]]{1,253}$/.test(host2);
1545
+ }
1546
+ TaDesktopUtil2.validHost = validHost;
1547
+ })(TaDesktopUtil || (TaDesktopUtil = {}));
680
1548
  // ../ta-protocol/esm/common/settings-protocol.js
681
1549
  var TaSettingsServer = Symbol("TaSettingsServer");
1550
+ // ../ta-protocol/esm/common/ta-protocol.js
1551
+ var TaServer = Symbol("TaServer");
1552
+ var TaClient = Symbol("TaClient");
1553
+ var TaSlashCommandUtil;
1554
+ (function(TaSlashCommandUtil2) {
1555
+ function description(command, language) {
1556
+ var _a, _b;
1557
+ const { descriptions } = command;
1558
+ return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
1559
+ }
1560
+ TaSlashCommandUtil2.description = description;
1561
+ })(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
682
1562
  // ../ta-protocol/esm/common/team-protocol.js
683
1563
  var TA_UNDECLARED = "extensions.install";
684
1564
  var TaPermissionUtil;
@@ -727,7 +1607,7 @@ var TA_ACTIONS = [
727
1607
  action("commands.terminal", "Open terminals", "打开终端", "開啟終端機", "ターミナルを開く", { scoped: true, risky: true }),
728
1608
  action("hosts.use", "Use remote hosts", "使用远程主机", "使用遠端主機", "リモートホストを使用", { risky: true }),
729
1609
  action("models.use", "Use the models", "使用模型", "使用模型", "モデルを使用"),
730
- action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更"),
1610
+ action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更", { grant: "single" }),
731
1611
  action("cron.view", "See scheduled tasks", "查看定时任务", "檢視定時任務", "スケジュールタスクを確認"),
732
1612
  action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
733
1613
  action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
@@ -740,9 +1620,15 @@ var TA_ACTIONS = [
740
1620
  action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
741
1621
  action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
742
1622
  ];
1623
+ var TA_OWNER_ACTIONS = [
1624
+ action("desktop.view", "See remote desktops", "查看远程桌面", "檢視遠端桌面", "リモートデスクトップを見る", { risky: true }),
1625
+ action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true })
1626
+ ];
1627
+ var OWNER_AREAS = ["desktop"];
743
1628
  var TaActionUtil;
744
1629
  (function(TaActionUtil2) {
745
1630
  const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
1631
+ const titled = new Map([...TA_ACTIONS, ...TA_OWNER_ACTIONS].map((one) => [one.id, one]));
746
1632
  function info(id) {
747
1633
  return byId.get(id);
748
1634
  }
@@ -750,7 +1636,7 @@ var TaActionUtil;
750
1636
  function title(id, language) {
751
1637
  var _a;
752
1638
  var _b, _c;
753
- const title2 = (_a = byId.get(id)) === null || _a === undefined ? undefined : _a.title;
1639
+ const title2 = (_a = titled.get(id)) === null || _a === undefined ? undefined : _a.title;
754
1640
  if (!title2) {
755
1641
  return id;
756
1642
  }
@@ -762,6 +1648,16 @@ var TaActionUtil;
762
1648
  });
763
1649
  }
764
1650
  TaActionUtil2.title = title;
1651
+ function grantable(id) {
1652
+ const info2 = byId.get(id);
1653
+ return !!info2 && !OWNER_AREAS.includes(info2.area);
1654
+ }
1655
+ TaActionUtil2.grantable = grantable;
1656
+ function inRoles(id) {
1657
+ var _a;
1658
+ return grantable(id) && ((_a = byId.get(id)) === null || _a === undefined ? undefined : _a.grant) !== "single";
1659
+ }
1660
+ TaActionUtil2.inRoles = inRoles;
765
1661
  function inside(dir, path) {
766
1662
  const base = dir.replace(/\/+$/, "");
767
1663
  return path === base || path.startsWith(`${base}/`) || base === "";
@@ -770,6 +1666,55 @@ var TaActionUtil;
770
1666
  })(TaActionUtil || (TaActionUtil = {}));
771
1667
  // ../ta-protocol/esm/common/usage-protocol.js
772
1668
  var TaUsageServer = Symbol("TaUsageServer");
1669
+ // ../ta-protocol/esm/common/voice-protocol.js
1670
+ var TaVoiceServer = Symbol("TaVoiceServer");
1671
+ var TaBargeIn;
1672
+ (function(TaBargeIn2) {
1673
+ TaBargeIn2.DEFAULTS = { duck: 0.2, speechMs: 500, level: 0.02, words: 2, waitMs: 1500, echo: 0.3, joinMs: 300, tap: false };
1674
+ TaBargeIn2.SENSITIVITY = [
1675
+ { speechMs: 1000, level: 0.05 },
1676
+ { speechMs: 750, level: 0.035 },
1677
+ { speechMs: TaBargeIn2.DEFAULTS.speechMs, level: TaBargeIn2.DEFAULTS.level },
1678
+ { speechMs: 300, level: 0.012 },
1679
+ { speechMs: 150, level: 0.006 }
1680
+ ];
1681
+ function sensitivity(bargeIn) {
1682
+ let nearest = 0;
1683
+ TaBargeIn2.SENSITIVITY.forEach((step, index) => {
1684
+ if (Math.abs(step.speechMs - bargeIn.speechMs) < Math.abs(TaBargeIn2.SENSITIVITY[nearest].speechMs - bargeIn.speechMs)) {
1685
+ nearest = index;
1686
+ }
1687
+ });
1688
+ return nearest;
1689
+ }
1690
+ TaBargeIn2.sensitivity = sensitivity;
1691
+ function pick(value) {
1692
+ const given = value && typeof value === "object" ? value : {};
1693
+ const out = typeof given.tap === "boolean" ? { tap: given.tap } : {};
1694
+ for (const key of Object.keys(RANGES)) {
1695
+ const number = given[key];
1696
+ if (typeof number === "number" && Number.isFinite(number)) {
1697
+ const [min, max] = RANGES[key];
1698
+ out[key] = Math.min(max, Math.max(min, number));
1699
+ }
1700
+ }
1701
+ return out;
1702
+ }
1703
+ TaBargeIn2.pick = pick;
1704
+ const RANGES = {
1705
+ duck: [0, 1],
1706
+ speechMs: [0, 5000],
1707
+ level: [0, 1],
1708
+ words: [1, 50],
1709
+ waitMs: [100, 1e4],
1710
+ echo: [0, 4],
1711
+ joinMs: [0, 3000]
1712
+ };
1713
+ function resolve(value) {
1714
+ return { ...TaBargeIn2.DEFAULTS, ...pick(value) };
1715
+ }
1716
+ TaBargeIn2.resolve = resolve;
1717
+ })(TaBargeIn || (TaBargeIn = {}));
773
1718
  // ../ta-protocol/esm/common/workspace-protocol.js
774
1719
  var TaWorkspaceServer = Symbol("TaWorkspaceServer");
775
1720
  var TaTerminalServer = Symbol("TaTerminalServer");
@@ -837,8 +1782,8 @@ var Limits;
837
1782
  })(Limits ||= {});
838
1783
 
839
1784
  // web-src/talk-host.ts
840
- import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
841
- import { dirname, join } from "node:path";
1785
+ import { mkdir as mkdir2, readFile as readFile2 } from "node:fs/promises";
1786
+ import { join as join2 } from "node:path";
842
1787
 
843
1788
  // web-src/post-util.ts
844
1789
  var ID = /^[0-9a-f]{8}$/;
@@ -1134,7 +2079,7 @@ var MomentsServerTexts;
1134
2079
  `${input.from} 在动态里分享了扩展「${input.title}」${input.summary ? `:${input.summary}` : ""}。我想拿来用。${where}。`,
1135
2080
  "",
1136
2081
  "1. 先别装,也别运行里面的任何东西:把它解到临时目录(来源是 npm 就用 `npm pack`,是 Git 就浅克隆),列出文件,读 package.json 和扩展代码。",
1137
- "2. 用几句话告诉我:它做什么、会读写哪些文件、会运行哪些命令、会连哪些网络、有没有可疑的地方。",
2082
+ "2. 告诉我:它做什么、会读写哪些文件、会运行哪些命令、会连哪些网络、有没有可疑的地方。",
1138
2083
  `3. 等我说装,再照 ta-package 技能导入到 \`${input.agentDir}/extensions\`;装完按我的电脑调整(路径、语言、配置),只改装到我这里的副本。`
1139
2084
  ].join(`
1140
2085
  `);
@@ -1145,7 +2090,7 @@ var MomentsServerTexts;
1145
2090
  `${input.from} 在動態裡分享了擴充功能「${input.title}」${input.summary ? `:${input.summary}` : ""}。我想拿來用。${where}。`,
1146
2091
  "",
1147
2092
  "1. 先別裝,也別執行裡面的任何東西:把它解到臨時目錄(來源是 npm 就用 `npm pack`,是 Git 就淺複製),列出檔案,讀 package.json 和擴充功能程式碼。",
1148
- "2. 用幾句話告訴我:它做什麼、會讀寫哪些檔案、會執行哪些命令、會連哪些網路、有沒有可疑的地方。",
2093
+ "2. 告訴我:它做什麼、會讀寫哪些檔案、會執行哪些命令、會連哪些網路、有沒有可疑的地方。",
1149
2094
  `3. 等我說裝,再照 ta-package 技能匯入到 \`${input.agentDir}/extensions\`;裝完按我的電腦調整(路徑、語言、配置),只改裝到我這裡的副本。`
1150
2095
  ].join(`
1151
2096
  `);
@@ -1156,7 +2101,7 @@ var MomentsServerTexts;
1156
2101
  `${input.from} posted the extension "${input.title}"${input.summary ? `: ${input.summary}` : ""} in Moments, and I want to use it. ${where}.`,
1157
2102
  "",
1158
2103
  "1. Do not install it or run anything in it yet: unpack it in a temporary directory (`npm pack` for a source of npm, a shallow clone for Git), list its files, and read its package.json and the code of its extensions.",
1159
- "2. Tell me in a few sentences what it does, which files it reads and writes, which commands it runs, what it reaches on the network, and anything that looks wrong.",
2104
+ "2. Tell me what it does, which files it reads and writes, which commands it runs, what it reaches on the network, and anything that looks wrong.",
1160
2105
  `3. Once I say install, import it into \`${input.agentDir}/extensions\` as the ta-package skill says; then fit it to my computer (paths, language, settings), changing only the copy installed here.`
1161
2106
  ].join(`
1162
2107
  `);
@@ -1167,7 +2112,7 @@ var MomentsServerTexts;
1167
2112
  `${input.from} がモーメンツに拡張機能「${input.title}」${input.summary ? `:${input.summary}` : ""} を共有しました。使用したいです。${where}。`,
1168
2113
  "",
1169
2114
  "1. まだインストールしないでください。実行前に、テンポラリディレクトリに解凍します(npm は `npm pack` を使い、Git は浅複製を使う)。ファイルをリストして、package.json と拡張機能コードを読む。",
1170
- "2. 何をするのか、どのファイルを読み書きするのか、どのコマンドを実行するのか、ネットワークに何に接続するのか、または何が疑わしいのかを数文で教えてください。",
2115
+ "2. 何をするのか、どのファイルを読み書きするのか、どのコマンドを実行するのか、ネットワークに何に接続するのか、または何が疑わしいのかを教えてください。",
1171
2116
  `3. インストールしてください と言ったら、ta-package スキルが示すように \`${input.agentDir}/extensions\` にインポートします。次に、コンピュータに合わせて調整します(パス、言語、設定)。ここにインストールされたコピーのみを変更します。`
1172
2117
  ].join(`
1173
2118
  `);
@@ -1177,10 +2122,14 @@ var MomentsServerTexts;
1177
2122
  MomentsServerTexts.take = take;
1178
2123
  })(MomentsServerTexts ||= {});
1179
2124
 
2125
+ // web-src/talk-host-base.ts
2126
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
2127
+ import { dirname, join } from "node:path";
2128
+
1180
2129
  // web-src/talk-util.ts
1181
2130
  var ID2 = /^[0-9a-f]{8}$/;
1182
2131
  var PERSON = /^[A-Za-z0-9_-]{1,64}$/;
1183
- function words(value, max) {
2132
+ function words2(value, max) {
1184
2133
  const text2 = typeof value === "string" ? value.trim().slice(0, max) : "";
1185
2134
  return text2 || undefined;
1186
2135
  }
@@ -1199,7 +2148,7 @@ var TalkUtil;
1199
2148
  return;
1200
2149
  }
1201
2150
  const raw = value;
1202
- const text2 = words(raw.text, raw.double ? Limits.ANSWER_TEXT : Limits.TALK_TEXT);
2151
+ const text2 = words2(raw.text, raw.double ? Limits.ANSWER_TEXT : Limits.TALK_TEXT);
1203
2152
  if (!isId(raw.id) || typeof raw.by !== "string" || !PERSON.test(raw.by) || typeof raw.at !== "number" || !text2) {
1204
2153
  return;
1205
2154
  }
@@ -1207,10 +2156,10 @@ var TalkUtil;
1207
2156
  return {
1208
2157
  id: raw.id,
1209
2158
  by: raw.by,
1210
- name: words(raw.name, 60) ?? "",
2159
+ name: words2(raw.name, 60) ?? "",
1211
2160
  at: raw.at,
1212
2161
  text: text2,
1213
- ...to ? { to, toName: words(raw.toName, 60) ?? "" } : {},
2162
+ ...to ? { to, toName: words2(raw.toName, 60) ?? "" } : {},
1214
2163
  ...raw.ask === true ? { ask: true } : {},
1215
2164
  ...raw.double === true ? { double: true } : {},
1216
2165
  ...isId(raw.re) ? { re: raw.re } : {}
@@ -1253,7 +2202,7 @@ var TalkUtil;
1253
2202
  if (raw.t === "ta-moments:unsay" || raw.t === "ta-moments:heard") {
1254
2203
  return { t: raw.t, post: raw.post, id: raw.id };
1255
2204
  }
1256
- const text2 = words(raw.text, Limits.TALK_TEXT);
2205
+ const text2 = words2(raw.text, Limits.TALK_TEXT);
1257
2206
  if (raw.t !== "ta-moments:say" || !text2) {
1258
2207
  return;
1259
2208
  }
@@ -1302,17 +2251,16 @@ var TalkUtil;
1302
2251
  TalkUtil.without = without;
1303
2252
  })(TalkUtil ||= {});
1304
2253
 
1305
- // web-src/talk-host.ts
2254
+ // web-src/talk-host-base.ts
1306
2255
  var NOTIFY = "@celljs/ta-notify";
1307
2256
  var DAY_MS = 86400000;
1308
2257
  var INCOMING_MS = 5 * 60000;
1309
2258
  var ANSWER_MS = 3 * 60000;
1310
- var ANSWER_MARK = "[ta-moments:answers]";
1311
2259
  function record(value) {
1312
2260
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
1313
2261
  }
1314
2262
 
1315
- class MomentsTalk {
2263
+ class MomentsTalkBase {
1316
2264
  host;
1317
2265
  paths;
1318
2266
  changed;
@@ -1330,6 +2278,134 @@ class MomentsTalk {
1330
2278
  this.changed = changed;
1331
2279
  this.now = now;
1332
2280
  }
2281
+ async push(room, post) {
2282
+ const entries = await this.read(this.file(post));
2283
+ const pals = await this.pals();
2284
+ const author = room.members.find((member) => member.owner)?.id ?? "";
2285
+ for (const member of room.members.filter((each) => !each.owner && !each.guest && each.online)) {
2286
+ await this.send(room.id, member.member, post, TalkUtil.visible(entries, member.id, author, pals));
2287
+ }
2288
+ }
2289
+ async send(room, to, post, entries) {
2290
+ const pages = TalkUtil.pages(entries);
2291
+ for (const [part, page] of pages.entries()) {
2292
+ await this.host.rooms.send(room, { t: "ta-moments:talk", post, part, parts: pages.length, entries: page }, to).catch(() => {
2293
+ return;
2294
+ });
2295
+ if (pages.length > 1 && this.pace) {
2296
+ await new Promise((resolve) => setTimeout(resolve, this.pace));
2297
+ }
2298
+ }
2299
+ }
2300
+ async flush(room) {
2301
+ const owner = room.members.find((member) => member.owner);
2302
+ if (!owner?.online) {
2303
+ return;
2304
+ }
2305
+ for (const item of record(await this.read_(Keys.OUTBOX))[room.id] ?? []) {
2306
+ const message = item.op === "say" ? {
2307
+ t: "ta-moments:say",
2308
+ post: item.post,
2309
+ id: item.id,
2310
+ text: item.text,
2311
+ ...item.to ? { to: item.to } : {},
2312
+ ...item.ask ? { ask: true } : {}
2313
+ } : { t: "ta-moments:unsay", post: item.post, id: item.id };
2314
+ await this.host.rooms.send(room.id, message, owner.member).catch(() => {
2315
+ return;
2316
+ });
2317
+ }
2318
+ }
2319
+ async queue(room, item) {
2320
+ const outbox = record(await this.read_(Keys.OUTBOX));
2321
+ if (Object.values(outbox).flat().length >= Limits.OUTBOX) {
2322
+ const language2 = TaLanguageUtil.server();
2323
+ throw new Error(TaLanguageUtil.pick(language2, {
2324
+ "zh-CN": "还有太多话没送到,等对方上线后再说",
2325
+ "zh-TW": "還有太多話沒送到,等對方上線後再說",
2326
+ "en-US": "Too much is waiting for its authors: try once they are online",
2327
+ "ja-JP": "多くの内容が送信されるのを待っています。対方がオンラインになったら試してください"
2328
+ }));
2329
+ }
2330
+ outbox[room] = [...outbox[room] ?? [], item];
2331
+ await this.write_(Keys.OUTBOX, outbox);
2332
+ }
2333
+ async pals() {
2334
+ const pals = record(await this.read_(Keys.PALS));
2335
+ return (a, b) => !!pals[a]?.includes(b) && !!pals[b]?.includes(a);
2336
+ }
2337
+ async postOf(room, post) {
2338
+ const owner = room.members.find((member) => member.owner);
2339
+ if (!owner || !PostUtil.isId(post) || room.status !== "member") {
2340
+ return;
2341
+ }
2342
+ const value = (await this.host.rooms.getState(room.id, `${StateKeys.POST}${post}`))[`${StateKeys.POST}${post}`];
2343
+ const checked = value?.by === owner.member ? PostUtil.check(value.value) : undefined;
2344
+ return checked && (checked.until === undefined || checked.until > this.now()) ? checked : undefined;
2345
+ }
2346
+ async nameOf(room, post, id) {
2347
+ const member = room.members.find((each) => each.id === id);
2348
+ if (member) {
2349
+ return member.name;
2350
+ }
2351
+ const entries = await this.read(room.owner ? this.file(post) : this.cacheFile(room.id, post));
2352
+ return entries.find((each) => each.by === id)?.name;
2353
+ }
2354
+ async notify(id, text2) {
2355
+ await this.host.callPackageHost(NOTIFY, "notify", [{ from: NAME, id, level: "done", title: MomentsServerTexts.roomTitle(TaLanguageUtil.server()), text: text2, view: VIEW }]).catch(() => {
2356
+ return;
2357
+ });
2358
+ }
2359
+ file(post) {
2360
+ return join(this.paths.post(post), "talk.json");
2361
+ }
2362
+ cacheFile(room, post) {
2363
+ return join(this.paths.cache(room, post), "talk.json");
2364
+ }
2365
+ async read(file) {
2366
+ await this.files.get(file);
2367
+ try {
2368
+ return TalkUtil.entries(JSON.parse(await readFile(file, "utf8")));
2369
+ } catch {
2370
+ return [];
2371
+ }
2372
+ }
2373
+ edit(file, change) {
2374
+ const next = (this.files.get(file) ?? Promise.resolve()).then(async () => {
2375
+ let entries = [];
2376
+ try {
2377
+ entries = TalkUtil.entries(JSON.parse(await readFile(file, "utf8")));
2378
+ } catch {}
2379
+ const changed = change(entries);
2380
+ if (changed === entries) {
2381
+ return;
2382
+ }
2383
+ if (!changed.length) {
2384
+ await rm(file, { force: true });
2385
+ return;
2386
+ }
2387
+ await mkdir(dirname(file), { recursive: true });
2388
+ await writeFile(file, JSON.stringify(changed));
2389
+ });
2390
+ const settled = next.catch(() => {
2391
+ return;
2392
+ });
2393
+ this.files.set(file, settled);
2394
+ settled.then(() => this.files.get(file) === settled && this.files.delete(file));
2395
+ return next;
2396
+ }
2397
+ read_(key) {
2398
+ return this.host.getExtensionData(NAME, key);
2399
+ }
2400
+ write_(key, value) {
2401
+ return this.host.setExtensionData(NAME, key, value);
2402
+ }
2403
+ }
2404
+
2405
+ // web-src/talk-host.ts
2406
+ var ANSWER_MARK = "[ta-moments:answers]";
2407
+
2408
+ class MomentsTalk extends MomentsTalkBase {
1333
2409
  async views(room, post, me) {
1334
2410
  const owner = room.members.find((member) => member.owner);
1335
2411
  const entries = await this.read(room.owner ? this.file(post) : this.cacheFile(room.id, post));
@@ -1364,11 +2440,11 @@ class MomentsTalk {
1364
2440
  return shown;
1365
2441
  }
1366
2442
  async say(room, post, text2, options = {}) {
1367
- const words2 = typeof text2 === "string" ? text2.trim().slice(0, Limits.TALK_TEXT) : "";
2443
+ const words3 = typeof text2 === "string" ? text2.trim().slice(0, Limits.TALK_TEXT) : "";
1368
2444
  const value = await this.postOf(room, post);
1369
- if (!words2 || !value) {
2445
+ if (!words3 || !value) {
1370
2446
  const language2 = TaLanguageUtil.server();
1371
- throw new Error(words2 ? MomentsServerTexts.notFound(language2) : TaLanguageUtil.pick(language2, {
2447
+ throw new Error(words3 ? MomentsServerTexts.notFound(language2) : TaLanguageUtil.pick(language2, {
1372
2448
  "zh-CN": "写点什么再发",
1373
2449
  "zh-TW": "寫點什麼再發",
1374
2450
  "en-US": "Write something first",
@@ -1381,7 +2457,7 @@ class MomentsTalk {
1381
2457
  const toName2 = to ? await this.nameOf(room, post, to) : undefined;
1382
2458
  await this.edit(this.file(post), (entries) => entries.length >= Limits.TALK ? entries : [
1383
2459
  ...entries,
1384
- { id: TalkUtil.newId(), by: me.id, name: me.name, at: this.now(), text: words2, ...to ? { to, toName: toName2 ?? "" } : {} }
2460
+ { id: TalkUtil.newId(), by: me.id, name: me.name, at: this.now(), text: words3, ...to ? { to, toName: toName2 ?? "" } : {} }
1385
2461
  ]);
1386
2462
  await this.push(room, post);
1387
2463
  this.changed();
@@ -1401,7 +2477,7 @@ class MomentsTalk {
1401
2477
  op: "say",
1402
2478
  post,
1403
2479
  id: TalkUtil.newId(),
1404
- text: words2,
2480
+ text: words3,
1405
2481
  ...to ? { to, toName: toName ?? "" } : {},
1406
2482
  ...options.ask ? { ask: true } : {},
1407
2483
  at: this.now()
@@ -1597,7 +2673,7 @@ class MomentsTalk {
1597
2673
  const sessionId = await this.session(key, me.name, question);
1598
2674
  const before = await this.host.getState(sessionId);
1599
2675
  const earlier = (await this.read(this.file(post))).filter((each) => each.id !== question.id && (each.by === question.by || each.to === question.by));
1600
- const notes = await readFile(join(this.paths.post(post), "notes.txt"), "utf8").catch(() => "");
2676
+ const notes = await readFile2(join2(this.paths.post(post), "notes.txt"), "utf8").catch(() => "");
1601
2677
  await this.host.prompt(sessionId, {
1602
2678
  clientMessageId: `ta-moments:ask:${question.id}`,
1603
2679
  message: MomentsTalk.prompt(me.name, value, notes, earlier, question)
@@ -1635,8 +2711,8 @@ class MomentsTalk {
1635
2711
  return open.sessionId;
1636
2712
  }
1637
2713
  }
1638
- const cwd = join(this.host.agentDir, "ta-moments", "answers");
1639
- await mkdir(cwd, { recursive: true });
2714
+ const cwd = join2(this.host.agentDir, "ta-moments", "answers");
2715
+ await mkdir2(cwd, { recursive: true });
1640
2716
  const role = MomentsTalk.role(me);
1641
2717
  const opened = file ? await this.host.openSession({ cwd, sessionFile: file, appendSystemPrompt: role, group: NAME }).catch(() => {
1642
2718
  return;
@@ -1680,128 +2756,6 @@ class MomentsTalk {
1680
2756
  this.asks.set(id, [...times, now]);
1681
2757
  return true;
1682
2758
  }
1683
- async push(room, post) {
1684
- const entries = await this.read(this.file(post));
1685
- const pals = await this.pals();
1686
- const author = room.members.find((member) => member.owner)?.id ?? "";
1687
- for (const member of room.members.filter((each) => !each.owner && !each.guest && each.online)) {
1688
- await this.send(room.id, member.member, post, TalkUtil.visible(entries, member.id, author, pals));
1689
- }
1690
- }
1691
- async send(room, to, post, entries) {
1692
- const pages = TalkUtil.pages(entries);
1693
- for (const [part, page] of pages.entries()) {
1694
- await this.host.rooms.send(room, { t: "ta-moments:talk", post, part, parts: pages.length, entries: page }, to).catch(() => {
1695
- return;
1696
- });
1697
- if (pages.length > 1 && this.pace) {
1698
- await new Promise((resolve) => setTimeout(resolve, this.pace));
1699
- }
1700
- }
1701
- }
1702
- async flush(room) {
1703
- const owner = room.members.find((member) => member.owner);
1704
- if (!owner?.online) {
1705
- return;
1706
- }
1707
- for (const item of record(await this.read_(Keys.OUTBOX))[room.id] ?? []) {
1708
- const message = item.op === "say" ? {
1709
- t: "ta-moments:say",
1710
- post: item.post,
1711
- id: item.id,
1712
- text: item.text,
1713
- ...item.to ? { to: item.to } : {},
1714
- ...item.ask ? { ask: true } : {}
1715
- } : { t: "ta-moments:unsay", post: item.post, id: item.id };
1716
- await this.host.rooms.send(room.id, message, owner.member).catch(() => {
1717
- return;
1718
- });
1719
- }
1720
- }
1721
- async queue(room, item) {
1722
- const outbox = record(await this.read_(Keys.OUTBOX));
1723
- if (Object.values(outbox).flat().length >= Limits.OUTBOX) {
1724
- const language2 = TaLanguageUtil.server();
1725
- throw new Error(TaLanguageUtil.pick(language2, {
1726
- "zh-CN": "还有太多话没送到,等对方上线后再说",
1727
- "zh-TW": "還有太多話沒送到,等對方上線後再說",
1728
- "en-US": "Too much is waiting for its authors: try once they are online",
1729
- "ja-JP": "多くの内容が送信されるのを待っています。対方がオンラインになったら試してください"
1730
- }));
1731
- }
1732
- outbox[room] = [...outbox[room] ?? [], item];
1733
- await this.write_(Keys.OUTBOX, outbox);
1734
- }
1735
- async pals() {
1736
- const pals = record(await this.read_(Keys.PALS));
1737
- return (a, b) => !!pals[a]?.includes(b) && !!pals[b]?.includes(a);
1738
- }
1739
- async postOf(room, post) {
1740
- const owner = room.members.find((member) => member.owner);
1741
- if (!owner || !PostUtil.isId(post) || room.status !== "member") {
1742
- return;
1743
- }
1744
- const value = (await this.host.rooms.getState(room.id, `${StateKeys.POST}${post}`))[`${StateKeys.POST}${post}`];
1745
- const checked = value?.by === owner.member ? PostUtil.check(value.value) : undefined;
1746
- return checked && (checked.until === undefined || checked.until > this.now()) ? checked : undefined;
1747
- }
1748
- async nameOf(room, post, id) {
1749
- const member = room.members.find((each) => each.id === id);
1750
- if (member) {
1751
- return member.name;
1752
- }
1753
- const entries = await this.read(room.owner ? this.file(post) : this.cacheFile(room.id, post));
1754
- return entries.find((each) => each.by === id)?.name;
1755
- }
1756
- async notify(id, text2) {
1757
- await this.host.callPackageHost(NOTIFY, "notify", [{ from: NAME, id, level: "done", title: MomentsServerTexts.roomTitle(TaLanguageUtil.server()), text: text2, view: VIEW }]).catch(() => {
1758
- return;
1759
- });
1760
- }
1761
- file(post) {
1762
- return join(this.paths.post(post), "talk.json");
1763
- }
1764
- cacheFile(room, post) {
1765
- return join(this.paths.cache(room, post), "talk.json");
1766
- }
1767
- async read(file) {
1768
- await this.files.get(file);
1769
- try {
1770
- return TalkUtil.entries(JSON.parse(await readFile(file, "utf8")));
1771
- } catch {
1772
- return [];
1773
- }
1774
- }
1775
- edit(file, change) {
1776
- const next = (this.files.get(file) ?? Promise.resolve()).then(async () => {
1777
- let entries = [];
1778
- try {
1779
- entries = TalkUtil.entries(JSON.parse(await readFile(file, "utf8")));
1780
- } catch {}
1781
- const changed = change(entries);
1782
- if (changed === entries) {
1783
- return;
1784
- }
1785
- if (!changed.length) {
1786
- await rm(file, { force: true });
1787
- return;
1788
- }
1789
- await mkdir(dirname(file), { recursive: true });
1790
- await writeFile(file, JSON.stringify(changed));
1791
- });
1792
- const settled = next.catch(() => {
1793
- return;
1794
- });
1795
- this.files.set(file, settled);
1796
- settled.then(() => this.files.get(file) === settled && this.files.delete(file));
1797
- return next;
1798
- }
1799
- read_(key) {
1800
- return this.host.getExtensionData(NAME, key);
1801
- }
1802
- write_(key, value) {
1803
- return this.host.setExtensionData(NAME, key, value);
1804
- }
1805
2759
  }
1806
2760
  ((MomentsTalk) => {
1807
2761
  function role(me) {
@@ -1872,7 +2826,7 @@ var DraftTool;
1872
2826
  linkTitle: { type: "string", description: "What the link opens, a few words." },
1873
2827
  notes: {
1874
2828
  type: "string",
1875
- description: `How it was made, never posted: the steps, choices and what to watch out for, in a few lines (${Limits.NOTES} characters at most), for the user's Ta to answer friends who ask about the post. No secrets, paths of their computer or anything private.`
2829
+ description: `How it was made, never posted: the steps, choices and what to watch out for, briefly (${Limits.NOTES} characters at most), for the user's Ta to answer friends who ask about the post. No secrets, paths of their computer or anything private.`
1876
2830
  }
1877
2831
  },
1878
2832
  required: ["text"]