@celljs/ta-rooms 4.18.0 → 4.20.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/extension/index.mjs +16 -0
- package/host/index.mjs +1608 -6
- package/package.json +4 -4
- package/web/index.js +48 -32
package/host/index.mjs
CHANGED
|
@@ -349,6 +349,22 @@ var TaHostUtil;
|
|
|
349
349
|
}
|
|
350
350
|
TaHostUtil2.role = role;
|
|
351
351
|
})(TaHostUtil || (TaHostUtil = {}));
|
|
352
|
+
var TA_DOUBLE_LOOK = {
|
|
353
|
+
name: "@celljs/ta-web",
|
|
354
|
+
key: "assistant.species",
|
|
355
|
+
given: ["trex", "triceratops", "stegosaurus", "brachiosaurus", "velociraptor", "ankylosaurus", "pteranodon", "parasaurolophus"]
|
|
356
|
+
};
|
|
357
|
+
var TaDoubleLookUtil;
|
|
358
|
+
(function(TaDoubleLookUtil2) {
|
|
359
|
+
function given(id) {
|
|
360
|
+
let hash = 2166136261;
|
|
361
|
+
for (let i = 0;i < id.length; i++) {
|
|
362
|
+
hash = Math.imul(hash ^ id.charCodeAt(i), 16777619);
|
|
363
|
+
}
|
|
364
|
+
return TA_DOUBLE_LOOK.given[(hash >>> 0) % TA_DOUBLE_LOOK.given.length];
|
|
365
|
+
}
|
|
366
|
+
TaDoubleLookUtil2.given = given;
|
|
367
|
+
})(TaDoubleLookUtil || (TaDoubleLookUtil = {}));
|
|
352
368
|
var TA_WITH_OTHERS_MARK = "[ta:speaks-with-others]";
|
|
353
369
|
var TA_ASK_ENTRY = "ta-ask";
|
|
354
370
|
var TaAskUtil;
|
|
@@ -1765,7 +1781,8 @@ class RoomDoubles {
|
|
|
1765
1781
|
turn.cwd = own ? cwd : turn.cwd;
|
|
1766
1782
|
const key = DoubleUtil.sessionKey(room.id, work && { friend: asker.id, cwd: work.cwd }, agent?.id, own);
|
|
1767
1783
|
const role = team ? DoubleUtil.agentRole(me, room.title, team) : DoubleUtil.role(me, room.title);
|
|
1768
|
-
const
|
|
1784
|
+
const name = this.sessionName(room, asker, work, team || undefined, own);
|
|
1785
|
+
const { sessionId, sessionFile } = await this.session(key, cwd, role, name, team ? team.model : undefined);
|
|
1769
1786
|
this.track(sessionFile, turn);
|
|
1770
1787
|
const before = await this.host.getState(sessionId);
|
|
1771
1788
|
const nameOf = (each) => each.agent?.name ?? room.members.find((other) => other.member === each.from)?.name ?? each.name;
|
|
@@ -1858,28 +1875,33 @@ class RoomDoubles {
|
|
|
1858
1875
|
await mkdir(directory, { recursive: true });
|
|
1859
1876
|
return directory;
|
|
1860
1877
|
}
|
|
1861
|
-
session(key, cwd, role, name) {
|
|
1878
|
+
session(key, cwd, role, name, model) {
|
|
1862
1879
|
let opening = this.opening.get(key);
|
|
1863
1880
|
if (!opening) {
|
|
1864
|
-
opening = this.openSession(key, cwd, role, name).finally(() => this.opening.delete(key));
|
|
1881
|
+
opening = this.openSession(key, cwd, role, name, model).finally(() => this.opening.delete(key));
|
|
1865
1882
|
this.opening.set(key, opening);
|
|
1866
1883
|
}
|
|
1867
1884
|
return opening;
|
|
1868
1885
|
}
|
|
1869
|
-
async openSession(key, cwd, role, name) {
|
|
1886
|
+
async openSession(key, cwd, role, name, model) {
|
|
1870
1887
|
const sessions = await this.get(DoubleKeys.SESSIONS) ?? {};
|
|
1871
1888
|
const file = sessions[key];
|
|
1889
|
+
const chosen = model ? { model } : {};
|
|
1872
1890
|
if (file) {
|
|
1873
1891
|
const open = (await this.host.listSessions()).find((session) => session.sessionFile === file);
|
|
1874
1892
|
if (open) {
|
|
1893
|
+
if (model && open.model !== model) {
|
|
1894
|
+
const slash = model.indexOf("/");
|
|
1895
|
+
await this.host.setModel(open.sessionId, model.slice(0, slash), model.slice(slash + 1));
|
|
1896
|
+
}
|
|
1875
1897
|
return { sessionId: open.sessionId, sessionFile: file };
|
|
1876
1898
|
}
|
|
1877
1899
|
try {
|
|
1878
|
-
const opened = await this.host.openSession({ cwd, sessionFile: file, appendSystemPrompt: role, group: NAME });
|
|
1900
|
+
const opened = await this.host.openSession({ cwd, sessionFile: file, appendSystemPrompt: role, group: NAME, ...chosen });
|
|
1879
1901
|
return { sessionId: opened.sessionId, sessionFile: file };
|
|
1880
1902
|
} catch {}
|
|
1881
1903
|
}
|
|
1882
|
-
const { sessionId } = await this.host.openSession({ cwd, appendSystemPrompt: role, group: NAME });
|
|
1904
|
+
const { sessionId } = await this.host.openSession({ cwd, appendSystemPrompt: role, group: NAME, ...chosen });
|
|
1883
1905
|
await this.host.setSessionName(sessionId, name);
|
|
1884
1906
|
const { sessionFile } = await this.host.getState(sessionId);
|
|
1885
1907
|
if (sessionFile) {
|
|
@@ -2051,6 +2073,1585 @@ class FriendNotices {
|
|
|
2051
2073
|
}
|
|
2052
2074
|
}
|
|
2053
2075
|
|
|
2076
|
+
// web-src/picture-host.ts
|
|
2077
|
+
import { readFile } from "node:fs/promises";
|
|
2078
|
+
import { resolve } from "node:path";
|
|
2079
|
+
|
|
2080
|
+
// ../ta-protocol/esm/common/access-protocol.js
|
|
2081
|
+
var TaAccessServer = Symbol("TaAccessServer");
|
|
2082
|
+
var TA_SIGN_IN_PATH = "/sign-in";
|
|
2083
|
+
var TA_DEVICE_SIGN_IN_PATH = `${TA_SIGN_IN_PATH}/device`;
|
|
2084
|
+
// ../ta-protocol/esm/common/account-protocol.js
|
|
2085
|
+
var TaAccountServer = Symbol("TaAccountServer");
|
|
2086
|
+
// ../ta-protocol/esm/common/delegate-protocol.js
|
|
2087
|
+
var TaDelegateUtil;
|
|
2088
|
+
(function(TaDelegateUtil2) {
|
|
2089
|
+
TaDelegateUtil2.LEVELS = ["less", "balanced", "more"];
|
|
2090
|
+
TaDelegateUtil2.DEFAULT = "balanced";
|
|
2091
|
+
TaDelegateUtil2.WORK_TOOLS = ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls"];
|
|
2092
|
+
TaDelegateUtil2.CHANGE_TOOLS = ["edit", "write"];
|
|
2093
|
+
const LIMITS = {
|
|
2094
|
+
less: { noChanges: false },
|
|
2095
|
+
balanced: { noChanges: true, steps: 6 },
|
|
2096
|
+
more: { noChanges: true, steps: 2 }
|
|
2097
|
+
};
|
|
2098
|
+
function parse(value) {
|
|
2099
|
+
return TaDelegateUtil2.LEVELS.includes(value) ? value : TaDelegateUtil2.DEFAULT;
|
|
2100
|
+
}
|
|
2101
|
+
TaDelegateUtil2.parse = parse;
|
|
2102
|
+
function mark(level) {
|
|
2103
|
+
return `(delegate=${level})`;
|
|
2104
|
+
}
|
|
2105
|
+
TaDelegateUtil2.mark = mark;
|
|
2106
|
+
function levelOf(systemPrompt) {
|
|
2107
|
+
const role = TaHostUtil.role(systemPrompt);
|
|
2108
|
+
return TaDelegateUtil2.LEVELS.find((level) => role.includes(mark(level)));
|
|
2109
|
+
}
|
|
2110
|
+
TaDelegateUtil2.levelOf = levelOf;
|
|
2111
|
+
function limits(level) {
|
|
2112
|
+
return LIMITS[level];
|
|
2113
|
+
}
|
|
2114
|
+
TaDelegateUtil2.limits = limits;
|
|
2115
|
+
function refusal(level, tool, steps) {
|
|
2116
|
+
if (!TaDelegateUtil2.WORK_TOOLS.includes(tool)) {
|
|
2117
|
+
return;
|
|
2118
|
+
}
|
|
2119
|
+
const limit = LIMITS[level];
|
|
2120
|
+
if (limit.noChanges && TaDelegateUtil2.CHANGE_TOOLS.includes(tool)) {
|
|
2121
|
+
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.";
|
|
2122
|
+
}
|
|
2123
|
+
if (limit.steps !== undefined && steps >= limit.steps) {
|
|
2124
|
+
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.";
|
|
2125
|
+
}
|
|
2126
|
+
return;
|
|
2127
|
+
}
|
|
2128
|
+
TaDelegateUtil2.refusal = refusal;
|
|
2129
|
+
})(TaDelegateUtil || (TaDelegateUtil = {}));
|
|
2130
|
+
|
|
2131
|
+
// ../ta-protocol/esm/common/app-protocol.js
|
|
2132
|
+
var FONT_SIZES = ["small", "standard", "large", "xlarge"];
|
|
2133
|
+
var words = (en, zh, tw, ja) => ({ "en-US": en, "zh-CN": zh, "zh-TW": tw, "ja-JP": ja });
|
|
2134
|
+
var SYSTEM = words("as the system", "跟随系统", "跟隨系統", "システムに合わせる");
|
|
2135
|
+
var FONT_SHOWN = {
|
|
2136
|
+
small: words("small", "小", "小", "小"),
|
|
2137
|
+
standard: words("standard", "标准", "標準", "標準"),
|
|
2138
|
+
large: words("large", "大", "大", "大"),
|
|
2139
|
+
xlarge: words("extra large", "特大", "特大", "特大")
|
|
2140
|
+
};
|
|
2141
|
+
var TA_WEB_SETTINGS = [
|
|
2142
|
+
{
|
|
2143
|
+
key: "theme",
|
|
2144
|
+
type: "enum",
|
|
2145
|
+
values: ["system", "light", "dark"],
|
|
2146
|
+
default: "system",
|
|
2147
|
+
what: "Light or dark look; system follows the device.",
|
|
2148
|
+
title: words("Theme", "外观", "外觀", "外観"),
|
|
2149
|
+
shown: { system: SYSTEM, light: words("light", "浅色", "淺色", "ライト"), dark: words("dark", "深色", "深色", "ダーク") }
|
|
2150
|
+
},
|
|
2151
|
+
{
|
|
2152
|
+
key: "language",
|
|
2153
|
+
type: "enum",
|
|
2154
|
+
values: ["system", ...TaLanguageUtil.ALL],
|
|
2155
|
+
default: "system",
|
|
2156
|
+
what: "The language of Ta's pages and of what Ta says; system follows the device.",
|
|
2157
|
+
title: words("Language", "语言", "語言", "言語"),
|
|
2158
|
+
shown: {
|
|
2159
|
+
system: SYSTEM,
|
|
2160
|
+
...Object.fromEntries(TaLanguageUtil.ALL.map((language2) => [
|
|
2161
|
+
language2,
|
|
2162
|
+
words(TaLanguageUtil.NAMES[language2], TaLanguageUtil.NAMES[language2], TaLanguageUtil.NAMES[language2], TaLanguageUtil.NAMES[language2])
|
|
2163
|
+
]))
|
|
2164
|
+
}
|
|
2165
|
+
},
|
|
2166
|
+
{
|
|
2167
|
+
key: "fontSize",
|
|
2168
|
+
type: "enum",
|
|
2169
|
+
values: FONT_SIZES,
|
|
2170
|
+
default: "standard",
|
|
2171
|
+
what: "The size of the text of the whole page.",
|
|
2172
|
+
title: words("Text size", "字体大小", "字型大小", "文字サイズ"),
|
|
2173
|
+
shown: FONT_SHOWN
|
|
2174
|
+
},
|
|
2175
|
+
{
|
|
2176
|
+
key: "chatFontSize",
|
|
2177
|
+
type: "enum",
|
|
2178
|
+
values: FONT_SIZES,
|
|
2179
|
+
default: "standard",
|
|
2180
|
+
what: "The size of the text of conversations, on top of fontSize.",
|
|
2181
|
+
title: words("Text size of conversations", "对话字体大小", "對話字型大小", "会話の文字サイズ"),
|
|
2182
|
+
shown: FONT_SHOWN
|
|
2183
|
+
},
|
|
2184
|
+
{
|
|
2185
|
+
key: "speak",
|
|
2186
|
+
type: "boolean",
|
|
2187
|
+
default: false,
|
|
2188
|
+
what: "Read every reply aloud.",
|
|
2189
|
+
title: words("Read replies aloud", "朗读回复", "朗讀回覆", "返信を読み上げ")
|
|
2190
|
+
},
|
|
2191
|
+
{
|
|
2192
|
+
key: "speakTalk",
|
|
2193
|
+
type: "boolean",
|
|
2194
|
+
default: false,
|
|
2195
|
+
what: "Read the reply aloud when the user spoke to the double by voice.",
|
|
2196
|
+
title: words("Read aloud what was asked by voice", "语音提问时朗读回复", "語音提問時朗讀回覆", "音声で聞いたら読み上げ")
|
|
2197
|
+
},
|
|
2198
|
+
{
|
|
2199
|
+
key: "callCaptions",
|
|
2200
|
+
type: "boolean",
|
|
2201
|
+
default: false,
|
|
2202
|
+
what: "Show captions in a call: what the user says and what Ta reads.",
|
|
2203
|
+
title: words("Call captions", "通话字幕", "通話字幕", "通話の字幕")
|
|
2204
|
+
},
|
|
2205
|
+
{
|
|
2206
|
+
key: "voice",
|
|
2207
|
+
type: "string",
|
|
2208
|
+
default: "",
|
|
2209
|
+
what: "The voice replies are read with (a voiceURI of the device's voices); empty for the most natural one.",
|
|
2210
|
+
title: words("Voice", "朗读声音", "朗讀聲音", "読み上げの声")
|
|
2211
|
+
},
|
|
2212
|
+
{
|
|
2213
|
+
key: "confirmTasks",
|
|
2214
|
+
type: "boolean",
|
|
2215
|
+
default: false,
|
|
2216
|
+
what: "The double asks before it hands out work.",
|
|
2217
|
+
title: words("Ask before handing out work", "派任务前先问我", "派任務前先問我", "作業を割り当てる前に確認")
|
|
2218
|
+
},
|
|
2219
|
+
{
|
|
2220
|
+
key: "maxTasks",
|
|
2221
|
+
type: "number",
|
|
2222
|
+
values: [0, 2, 4, 8],
|
|
2223
|
+
default: 0,
|
|
2224
|
+
what: "How many of the double's tasks run at once; 0 for as many as it starts.",
|
|
2225
|
+
title: words("Tasks at once", "同时运行的任务", "同時執行的任務", "同時に実行するタスク")
|
|
2226
|
+
},
|
|
2227
|
+
{
|
|
2228
|
+
key: "delegate",
|
|
2229
|
+
type: "enum",
|
|
2230
|
+
values: TaDelegateUtil.LEVELS,
|
|
2231
|
+
default: TaDelegateUtil.DEFAULT,
|
|
2232
|
+
what: "How much of the work the double hands out to tasks rather than doing it itself.",
|
|
2233
|
+
title: words("Hand out work", "派活多少", "派活多少", "作業の割り当て"),
|
|
2234
|
+
shown: { less: words("less", "少", "少", "少なめ"), balanced: words("balanced", "适中", "適中", "ふつう"), more: words("more", "多", "多", "多め") }
|
|
2235
|
+
},
|
|
2236
|
+
{
|
|
2237
|
+
key: "assistantModel",
|
|
2238
|
+
type: "model",
|
|
2239
|
+
default: "",
|
|
2240
|
+
what: "The model of the double, <provider>/<model id>; empty for the default model.",
|
|
2241
|
+
title: words("Model of the double", "分身的模型", "分身的模型", "分身のモデル")
|
|
2242
|
+
},
|
|
2243
|
+
{
|
|
2244
|
+
key: "taskModel",
|
|
2245
|
+
type: "model",
|
|
2246
|
+
default: "",
|
|
2247
|
+
what: "The model of the tasks the double starts; empty for the default model.",
|
|
2248
|
+
title: words("Model of tasks", "任务的模型", "任務的模型", "タスクのモデル")
|
|
2249
|
+
},
|
|
2250
|
+
{ key: "reduceMotion", type: "boolean", default: false, what: "Fewer animations.", title: words("Reduce motion", "减少动画", "減少動畫", "動きを減らす") },
|
|
2251
|
+
{
|
|
2252
|
+
key: "diagramStyle",
|
|
2253
|
+
type: "enum",
|
|
2254
|
+
values: ["clean", "sketch", "colour", "motion"],
|
|
2255
|
+
default: "clean",
|
|
2256
|
+
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.",
|
|
2257
|
+
title: words("Diagram style", "图表风格", "圖表風格", "図のスタイル"),
|
|
2258
|
+
shown: {
|
|
2259
|
+
clean: words("clean", "简洁", "簡潔", "シンプル"),
|
|
2260
|
+
sketch: words("sketch", "草图", "草圖", "スケッチ"),
|
|
2261
|
+
colour: words("colour", "彩色", "彩色", "カラー"),
|
|
2262
|
+
motion: words("motion", "动效", "動效", "モーション")
|
|
2263
|
+
}
|
|
2264
|
+
},
|
|
2265
|
+
{
|
|
2266
|
+
key: "keepAliveMinutes",
|
|
2267
|
+
type: "number",
|
|
2268
|
+
values: [1, 5, 15, 30],
|
|
2269
|
+
default: 5,
|
|
2270
|
+
what: "How long an extension started on open keeps running once left, in minutes.",
|
|
2271
|
+
title: words("Keep extensions running", "扩展离开后保留", "擴充功能離開後保留", "拡張機能を保持")
|
|
2272
|
+
},
|
|
2273
|
+
{
|
|
2274
|
+
key: "chatFoldDays",
|
|
2275
|
+
type: "number",
|
|
2276
|
+
values: [3, 7, 30, 0],
|
|
2277
|
+
default: 7,
|
|
2278
|
+
what: "Conversations not updated for these days fold at the end of the list; 0 for none.",
|
|
2279
|
+
title: words("Fold old conversations", "折叠旧对话", "摺疊舊對話", "古い会話を折りたたむ")
|
|
2280
|
+
},
|
|
2281
|
+
{
|
|
2282
|
+
key: "chatArchiveDays",
|
|
2283
|
+
type: "number",
|
|
2284
|
+
values: [30, 90, 365, 0],
|
|
2285
|
+
default: 30,
|
|
2286
|
+
what: "Conversations not updated for these days are archived (out of the list, found by search); 0 for none.",
|
|
2287
|
+
title: words("Archive old conversations", "归档旧对话", "歸檔舊對話", "古い会話をアーカイブ")
|
|
2288
|
+
},
|
|
2289
|
+
{
|
|
2290
|
+
key: "recentShots",
|
|
2291
|
+
type: "boolean",
|
|
2292
|
+
default: true,
|
|
2293
|
+
what: "The screenshot just taken is offered above the message box, once.",
|
|
2294
|
+
title: words("Offer recent screenshots", "提示刚截的图", "提示剛截的圖", "撮ったばかりのスクリーンショットを提案")
|
|
2295
|
+
}
|
|
2296
|
+
];
|
|
2297
|
+
var TaAppUtil;
|
|
2298
|
+
(function(TaAppUtil2) {
|
|
2299
|
+
function check(spec, value) {
|
|
2300
|
+
var _a, _b;
|
|
2301
|
+
switch (spec.type) {
|
|
2302
|
+
case "boolean":
|
|
2303
|
+
return typeof value === "boolean" ? undefined : "true or false";
|
|
2304
|
+
case "string":
|
|
2305
|
+
return typeof value === "string" ? undefined : "a string";
|
|
2306
|
+
case "model":
|
|
2307
|
+
return value === "" || typeof value === "string" && /^[^/\s]+\/\S+$/.test(value) ? undefined : "<provider>/<model id>, or empty";
|
|
2308
|
+
default:
|
|
2309
|
+
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(", ")}`;
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
TaAppUtil2.check = check;
|
|
2313
|
+
function shown(value, language2, spec) {
|
|
2314
|
+
var _a;
|
|
2315
|
+
const named = (_a = spec === null || spec === undefined ? undefined : spec.shown) === null || _a === undefined ? undefined : _a[String(value)];
|
|
2316
|
+
if (named) {
|
|
2317
|
+
return TaLanguageUtil.pick(language2, named);
|
|
2318
|
+
}
|
|
2319
|
+
if (typeof value === "boolean") {
|
|
2320
|
+
return TaLanguageUtil.pick(language2, value ? words("on", "开", "開", "オン") : words("off", "关", "關", "オフ"));
|
|
2321
|
+
}
|
|
2322
|
+
if (value === "" || value === undefined || value === null) {
|
|
2323
|
+
return TaLanguageUtil.pick(language2, words("default", "默认", "預設", "デフォルト"));
|
|
2324
|
+
}
|
|
2325
|
+
return String(value);
|
|
2326
|
+
}
|
|
2327
|
+
TaAppUtil2.shown = shown;
|
|
2328
|
+
})(TaAppUtil || (TaAppUtil = {}));
|
|
2329
|
+
// ../ta-protocol/esm/common/auth-protocol.js
|
|
2330
|
+
var TaAuthServer = Symbol("TaAuthServer");
|
|
2331
|
+
// ../ta-protocol/esm/common/deployment-protocol.js
|
|
2332
|
+
var TA_WELL_KNOWN_PATH = "/.well-known/ta";
|
|
2333
|
+
|
|
2334
|
+
class TaDeploymentError extends Error {
|
|
2335
|
+
}
|
|
2336
|
+
var TaDeploymentUtil;
|
|
2337
|
+
(function(TaDeploymentUtil2) {
|
|
2338
|
+
TaDeploymentUtil2.DISTRIBUTION_FILE = "distribution.json";
|
|
2339
|
+
function url(value) {
|
|
2340
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
2341
|
+
return;
|
|
2342
|
+
}
|
|
2343
|
+
try {
|
|
2344
|
+
const parsed = new URL(value.trim());
|
|
2345
|
+
if (!/^https?:$/.test(parsed.protocol) || parsed.search || parsed.hash || parsed.username || parsed.password) {
|
|
2346
|
+
return;
|
|
2347
|
+
}
|
|
2348
|
+
return `${parsed.origin}${parsed.pathname}`.replace(/\/+$/, "");
|
|
2349
|
+
} catch (_a) {
|
|
2350
|
+
return;
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
TaDeploymentUtil2.url = url;
|
|
2354
|
+
function name(value) {
|
|
2355
|
+
return typeof value === "string" && value.trim() ? value.trim().slice(0, 80) : undefined;
|
|
2356
|
+
}
|
|
2357
|
+
function describe(env, own, version) {
|
|
2358
|
+
var _a, _b;
|
|
2359
|
+
const gateway = (_a = url(own.gateway)) !== null && _a !== undefined ? _a : url(env.TA_GATEWAY_URL);
|
|
2360
|
+
const relay = (_b = url(own.relay)) !== null && _b !== undefined ? _b : url(env.TA_RELAY_URL);
|
|
2361
|
+
const called = name(env.TA_DEPLOYMENT_NAME);
|
|
2362
|
+
return { v: 1, ...called ? { name: called } : {}, ...gateway ? { gateway } : {}, ...relay ? { relay } : {}, ...version ? { version } : {} };
|
|
2363
|
+
}
|
|
2364
|
+
TaDeploymentUtil2.describe = describe;
|
|
2365
|
+
TaDeploymentUtil2.HEADERS = {
|
|
2366
|
+
"content-type": "application/json",
|
|
2367
|
+
"access-control-allow-origin": "*",
|
|
2368
|
+
"cache-control": "no-store"
|
|
2369
|
+
};
|
|
2370
|
+
function parse(value) {
|
|
2371
|
+
const given = value;
|
|
2372
|
+
if (!given || typeof given !== "object" || given.v !== 1) {
|
|
2373
|
+
return;
|
|
2374
|
+
}
|
|
2375
|
+
const deployment = describe({ TA_DEPLOYMENT_NAME: given.name, TA_GATEWAY_URL: given.gateway, TA_RELAY_URL: given.relay }, {});
|
|
2376
|
+
const version = name(given.version);
|
|
2377
|
+
return version ? { ...deployment, version } : deployment;
|
|
2378
|
+
}
|
|
2379
|
+
TaDeploymentUtil2.parse = parse;
|
|
2380
|
+
async function discover(address, timeoutMs = 6000) {
|
|
2381
|
+
const base = url(address);
|
|
2382
|
+
if (!base) {
|
|
2383
|
+
throw new TaDeploymentError(`${address} is not an address of http or https.`);
|
|
2384
|
+
}
|
|
2385
|
+
const controller = new AbortController;
|
|
2386
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
2387
|
+
try {
|
|
2388
|
+
const response = await fetch(`${base}${TA_WELL_KNOWN_PATH}`, { signal: controller.signal, redirect: "follow" });
|
|
2389
|
+
if (!response.ok) {
|
|
2390
|
+
throw new TaDeploymentError(`${base} is not a deployment of Ta (${response.status}).`);
|
|
2391
|
+
}
|
|
2392
|
+
const deployment = parse(await response.json().catch(() => {
|
|
2393
|
+
return;
|
|
2394
|
+
}));
|
|
2395
|
+
if (!deployment || !deployment.gateway && !deployment.relay) {
|
|
2396
|
+
throw new TaDeploymentError(`${base} is not a deployment of Ta.`);
|
|
2397
|
+
}
|
|
2398
|
+
return deployment;
|
|
2399
|
+
} catch (error) {
|
|
2400
|
+
if ((error === null || error === undefined ? undefined : error.name) === "AbortError") {
|
|
2401
|
+
throw new TaDeploymentError(`${base} did not answer in time.`);
|
|
2402
|
+
}
|
|
2403
|
+
throw error;
|
|
2404
|
+
} finally {
|
|
2405
|
+
clearTimeout(timer);
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
TaDeploymentUtil2.discover = discover;
|
|
2409
|
+
function distribution(value) {
|
|
2410
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
2411
|
+
throw new TaDeploymentError(`${TaDeploymentUtil2.DISTRIBUTION_FILE} holds a JSON object.`);
|
|
2412
|
+
}
|
|
2413
|
+
const given = value;
|
|
2414
|
+
const result = {};
|
|
2415
|
+
if (given.name !== undefined) {
|
|
2416
|
+
result.name = name(given.name);
|
|
2417
|
+
}
|
|
2418
|
+
for (const key of ["relay", "gateway"]) {
|
|
2419
|
+
if (given[key] !== undefined) {
|
|
2420
|
+
const address = url(given[key]);
|
|
2421
|
+
if (!address) {
|
|
2422
|
+
throw new TaDeploymentError(`"${key}" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
|
|
2423
|
+
}
|
|
2424
|
+
result[key] = address;
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
if (given.updates !== undefined) {
|
|
2428
|
+
const updates = given.updates;
|
|
2429
|
+
const base = url(updates === null || updates === undefined ? undefined : updates.base);
|
|
2430
|
+
if (!base && (updates === null || updates === undefined ? undefined : updates.base) !== undefined) {
|
|
2431
|
+
throw new TaDeploymentError(`"updates.base" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
|
|
2432
|
+
}
|
|
2433
|
+
const key = typeof (updates === null || updates === undefined ? undefined : updates.key) === "string" && updates.key.includes("PUBLIC KEY") ? updates.key : undefined;
|
|
2434
|
+
if ((updates === null || updates === undefined ? undefined : updates.key) !== undefined && !key) {
|
|
2435
|
+
throw new TaDeploymentError(`"updates.key" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is a public key in PEM.`);
|
|
2436
|
+
}
|
|
2437
|
+
result.updates = { ...base ? { base } : {}, ...key ? { key } : {} };
|
|
2438
|
+
}
|
|
2439
|
+
if (given.reach !== undefined) {
|
|
2440
|
+
result.reach = reach(given.reach);
|
|
2441
|
+
}
|
|
2442
|
+
if (given.inside !== undefined) {
|
|
2443
|
+
const inside = url(given.inside);
|
|
2444
|
+
if (!inside) {
|
|
2445
|
+
throw new TaDeploymentError(`"inside" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
|
|
2446
|
+
}
|
|
2447
|
+
result.inside = inside;
|
|
2448
|
+
}
|
|
2449
|
+
return result;
|
|
2450
|
+
}
|
|
2451
|
+
TaDeploymentUtil2.distribution = distribution;
|
|
2452
|
+
function reach(value) {
|
|
2453
|
+
const given = typeof value === "string" ? { "*": value } : value;
|
|
2454
|
+
const entries = given && typeof given === "object" && !Array.isArray(given) ? Object.entries(given) : [];
|
|
2455
|
+
const result = {};
|
|
2456
|
+
for (const [language2, text] of entries) {
|
|
2457
|
+
if (typeof text !== "string" || !text.trim()) {
|
|
2458
|
+
throw new TaDeploymentError(`"reach.${language2}" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not a sentence.`);
|
|
2459
|
+
}
|
|
2460
|
+
result[language2] = text.trim().slice(0, 200);
|
|
2461
|
+
}
|
|
2462
|
+
if (Object.keys(result).length === 0) {
|
|
2463
|
+
throw new TaDeploymentError(`"reach" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is a sentence, or one by language.`);
|
|
2464
|
+
}
|
|
2465
|
+
return result;
|
|
2466
|
+
}
|
|
2467
|
+
function reachIn(reach2, language2) {
|
|
2468
|
+
var _a, _b, _c, _d, _e;
|
|
2469
|
+
if (!reach2) {
|
|
2470
|
+
return;
|
|
2471
|
+
}
|
|
2472
|
+
const base = language2.split("-")[0];
|
|
2473
|
+
const near = Object.keys(reach2).find((key) => key.split("-")[0] === base);
|
|
2474
|
+
return (_e = (_d = (_c = (_b = (_a = reach2[language2]) !== 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];
|
|
2475
|
+
}
|
|
2476
|
+
TaDeploymentUtil2.reachIn = reachIn;
|
|
2477
|
+
function apply(distribution2, env) {
|
|
2478
|
+
const defaults = { TA_DEPLOYMENT_NAME: distribution2.name, TA_RELAY_URL: distribution2.relay, TA_GATEWAY_URL: distribution2.gateway };
|
|
2479
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
2480
|
+
if (value && !env[key]) {
|
|
2481
|
+
env[key] = value;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
TaDeploymentUtil2.apply = apply;
|
|
2486
|
+
})(TaDeploymentUtil || (TaDeploymentUtil = {}));
|
|
2487
|
+
// ../ta-protocol/esm/common/error-protocol.js
|
|
2488
|
+
var TaErrorUtil;
|
|
2489
|
+
(function(TaErrorUtil2) {
|
|
2490
|
+
function code(error) {
|
|
2491
|
+
var _a;
|
|
2492
|
+
var _b;
|
|
2493
|
+
const failure = error;
|
|
2494
|
+
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;
|
|
2495
|
+
return typeof code2 === "string" ? code2 : undefined;
|
|
2496
|
+
}
|
|
2497
|
+
TaErrorUtil2.code = code;
|
|
2498
|
+
})(TaErrorUtil || (TaErrorUtil = {}));
|
|
2499
|
+
// ../ta-protocol/esm/common/gateway-protocol.js
|
|
2500
|
+
var TaGatewayServer = Symbol("TaGatewayServer");
|
|
2501
|
+
// ../ta-protocol/esm/common/location.js
|
|
2502
|
+
var TaLocation;
|
|
2503
|
+
(function(TaLocation2) {
|
|
2504
|
+
TaLocation2.SSH = "ssh://";
|
|
2505
|
+
TaLocation2.CLOUD = "ta://";
|
|
2506
|
+
const CLOUD_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
2507
|
+
const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
|
|
2508
|
+
function isRemote(location) {
|
|
2509
|
+
return location.startsWith(TaLocation2.SSH) || location.startsWith(TaLocation2.CLOUD);
|
|
2510
|
+
}
|
|
2511
|
+
TaLocation2.isRemote = isRemote;
|
|
2512
|
+
function isCloud(host2) {
|
|
2513
|
+
return !!host2 && host2.startsWith(TaLocation2.CLOUD);
|
|
2514
|
+
}
|
|
2515
|
+
TaLocation2.isCloud = isCloud;
|
|
2516
|
+
function isCloudName(name) {
|
|
2517
|
+
return CLOUD_NAME.test(name);
|
|
2518
|
+
}
|
|
2519
|
+
TaLocation2.isCloudName = isCloudName;
|
|
2520
|
+
function cloud(name, path2 = "") {
|
|
2521
|
+
return `${TaLocation2.CLOUD}${name}${path2 ? normalize(path2) : ""}`;
|
|
2522
|
+
}
|
|
2523
|
+
TaLocation2.cloud = cloud;
|
|
2524
|
+
function cloudName(hostOrLocation) {
|
|
2525
|
+
if (!hostOrLocation.startsWith(TaLocation2.CLOUD)) {
|
|
2526
|
+
return;
|
|
2527
|
+
}
|
|
2528
|
+
const rest = hostOrLocation.slice(TaLocation2.CLOUD.length);
|
|
2529
|
+
const slash = rest.indexOf("/");
|
|
2530
|
+
return slash < 0 ? rest : rest.slice(0, slash);
|
|
2531
|
+
}
|
|
2532
|
+
TaLocation2.cloudName = cloudName;
|
|
2533
|
+
function parse(location) {
|
|
2534
|
+
var _a;
|
|
2535
|
+
if (!isRemote(location)) {
|
|
2536
|
+
return;
|
|
2537
|
+
}
|
|
2538
|
+
if (location.startsWith(TaLocation2.CLOUD)) {
|
|
2539
|
+
const name = (_a = cloudName(location)) !== null && _a !== undefined ? _a : "";
|
|
2540
|
+
if (!isCloudName(name)) {
|
|
2541
|
+
throw new Error(`${JSON.stringify(location)} names no cloud workspace: write ta://<name>/<path>.`);
|
|
2542
|
+
}
|
|
2543
|
+
const path3 = location.slice(TaLocation2.CLOUD.length + name.length);
|
|
2544
|
+
return { host: `${TaLocation2.CLOUD}${name}`, path: path3 ? normalize(path3) : "" };
|
|
2545
|
+
}
|
|
2546
|
+
const rest = location.slice(TaLocation2.SSH.length);
|
|
2547
|
+
const slash = rest.indexOf("/");
|
|
2548
|
+
const host2 = slash < 0 ? rest : rest.slice(0, slash);
|
|
2549
|
+
const path2 = slash < 0 ? "" : normalize(rest.slice(slash));
|
|
2550
|
+
if (!isHost(host2)) {
|
|
2551
|
+
throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
|
|
2552
|
+
}
|
|
2553
|
+
return { host: host2, path: path2 };
|
|
2554
|
+
}
|
|
2555
|
+
TaLocation2.parse = parse;
|
|
2556
|
+
function isHost(host2) {
|
|
2557
|
+
return isCloud(host2) ? isCloudName(host2.slice(TaLocation2.CLOUD.length)) : HOST.test(host2);
|
|
2558
|
+
}
|
|
2559
|
+
TaLocation2.isHost = isHost;
|
|
2560
|
+
const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
|
|
2561
|
+
function readHost(input) {
|
|
2562
|
+
const words2 = input.trim().split(/\s+/).filter(Boolean);
|
|
2563
|
+
if (words2[0] === "ssh") {
|
|
2564
|
+
words2.shift();
|
|
2565
|
+
}
|
|
2566
|
+
let destination;
|
|
2567
|
+
let port;
|
|
2568
|
+
let user;
|
|
2569
|
+
const options = [];
|
|
2570
|
+
for (let i = 0;i < words2.length; i++) {
|
|
2571
|
+
const word = words2[i];
|
|
2572
|
+
const glued = /^-([pl])(.+)$/.exec(word);
|
|
2573
|
+
if (word === "-p" || word === "-l" || glued) {
|
|
2574
|
+
const value = glued ? glued[2] : words2[++i];
|
|
2575
|
+
if (value === undefined) {
|
|
2576
|
+
return { error: "invalid" };
|
|
2577
|
+
}
|
|
2578
|
+
if ((glued ? glued[1] : word[1]) === "p") {
|
|
2579
|
+
port = value;
|
|
2580
|
+
} else {
|
|
2581
|
+
user = value;
|
|
2582
|
+
}
|
|
2583
|
+
} else if (word === "-o" || word.startsWith("-o")) {
|
|
2584
|
+
const value = word === "-o" ? words2[++i] : word.slice(2);
|
|
2585
|
+
const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
|
|
2586
|
+
if (!option) {
|
|
2587
|
+
options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
|
|
2588
|
+
} else if (option[1].toLowerCase() === "port") {
|
|
2589
|
+
port = option[2];
|
|
2590
|
+
} else {
|
|
2591
|
+
user = option[2];
|
|
2592
|
+
}
|
|
2593
|
+
} else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
|
|
2594
|
+
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words2[i + 1] !== undefined ? `${word} ${words2[++i]}` : word);
|
|
2595
|
+
} else if (destination === undefined) {
|
|
2596
|
+
destination = word;
|
|
2597
|
+
} else {
|
|
2598
|
+
return { error: "invalid" };
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
if (options.length > 0) {
|
|
2602
|
+
return { error: "options", options };
|
|
2603
|
+
}
|
|
2604
|
+
if (!destination) {
|
|
2605
|
+
return { error: "empty" };
|
|
2606
|
+
}
|
|
2607
|
+
let host2 = destination.replace(/^ssh:\/\//, "").replace(/\/.*$/, "");
|
|
2608
|
+
if (user && !host2.includes("@")) {
|
|
2609
|
+
host2 = `${user}@${host2}`;
|
|
2610
|
+
}
|
|
2611
|
+
if (port) {
|
|
2612
|
+
if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host2)) {
|
|
2613
|
+
return { error: "invalid" };
|
|
2614
|
+
}
|
|
2615
|
+
host2 = port === "22" ? host2 : `${host2}:${port}`;
|
|
2616
|
+
}
|
|
2617
|
+
return isHost(host2) ? { host: host2 } : { error: "invalid" };
|
|
2618
|
+
}
|
|
2619
|
+
TaLocation2.readHost = readHost;
|
|
2620
|
+
function ssh(host2, path2 = "") {
|
|
2621
|
+
return isCloud(host2) ? `${host2}${path2 ? normalize(path2) : ""}` : `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
|
|
2622
|
+
}
|
|
2623
|
+
TaLocation2.ssh = ssh;
|
|
2624
|
+
function hostLabel(host2) {
|
|
2625
|
+
if (isCloud(host2)) {
|
|
2626
|
+
return host2.slice(TaLocation2.CLOUD.length);
|
|
2627
|
+
}
|
|
2628
|
+
const name = host2.replace(/^[^@]*@/, "").replace(/^\[(.*)\](?::\d+)?$/, "$1").replace(/^([^:]*):\d+$/, "$1");
|
|
2629
|
+
return /^[\d.]+$/.test(name) || name.includes(":") ? name : name.split(".")[0] || name;
|
|
2630
|
+
}
|
|
2631
|
+
TaLocation2.hostLabel = hostLabel;
|
|
2632
|
+
function host(location) {
|
|
2633
|
+
var _a;
|
|
2634
|
+
return isRemote(location) ? (_a = parse(location)) === null || _a === undefined ? undefined : _a.host : undefined;
|
|
2635
|
+
}
|
|
2636
|
+
TaLocation2.host = host;
|
|
2637
|
+
function path(location) {
|
|
2638
|
+
var _a;
|
|
2639
|
+
var _b;
|
|
2640
|
+
return (_b = (_a = parse(location)) === null || _a === undefined ? undefined : _a.path) !== null && _b !== undefined ? _b : location;
|
|
2641
|
+
}
|
|
2642
|
+
TaLocation2.path = path;
|
|
2643
|
+
function parent(location) {
|
|
2644
|
+
const remote = parse(location);
|
|
2645
|
+
if (remote) {
|
|
2646
|
+
const above = remote.path ? parentPath(remote.path) : undefined;
|
|
2647
|
+
return above === undefined ? undefined : ssh(remote.host, above);
|
|
2648
|
+
}
|
|
2649
|
+
return parentPath(location);
|
|
2650
|
+
}
|
|
2651
|
+
TaLocation2.parent = parent;
|
|
2652
|
+
function child(location, name) {
|
|
2653
|
+
const remote = parse(location);
|
|
2654
|
+
if (remote) {
|
|
2655
|
+
return ssh(remote.host, childPath(remote.path || "/", name));
|
|
2656
|
+
}
|
|
2657
|
+
return childPath(location, name);
|
|
2658
|
+
}
|
|
2659
|
+
TaLocation2.child = child;
|
|
2660
|
+
function basename(location) {
|
|
2661
|
+
const remote = parse(location);
|
|
2662
|
+
const path2 = (remote ? remote.path : location).replace(/[\\/]+$/, "");
|
|
2663
|
+
const name = path2.slice(Math.max(path2.lastIndexOf("/"), path2.lastIndexOf("\\")) + 1);
|
|
2664
|
+
return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
|
|
2665
|
+
}
|
|
2666
|
+
TaLocation2.basename = basename;
|
|
2667
|
+
function homeRelative(location) {
|
|
2668
|
+
var _a;
|
|
2669
|
+
const remote = parse(location);
|
|
2670
|
+
const path2 = remote ? remote.path ? remote.path.slice(1) : "~" : location;
|
|
2671
|
+
const match = /^~(?:[\\/]+(.*))?$/.exec(path2);
|
|
2672
|
+
return match ? ((_a = match[1]) !== null && _a !== undefined ? _a : "").replace(/[\\/]+$/, "") : undefined;
|
|
2673
|
+
}
|
|
2674
|
+
TaLocation2.homeRelative = homeRelative;
|
|
2675
|
+
function isAbsolute2(location) {
|
|
2676
|
+
if (homeRelative(location) !== undefined) {
|
|
2677
|
+
return false;
|
|
2678
|
+
}
|
|
2679
|
+
return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
|
|
2680
|
+
}
|
|
2681
|
+
TaLocation2.isAbsolute = isAbsolute2;
|
|
2682
|
+
function parentPath(path2) {
|
|
2683
|
+
const trimmed = path2.replace(/[\\/]+$/, "");
|
|
2684
|
+
const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
2685
|
+
if (at < 0) {
|
|
2686
|
+
return;
|
|
2687
|
+
}
|
|
2688
|
+
const head = trimmed.slice(0, at);
|
|
2689
|
+
return head === "" || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
|
|
2690
|
+
}
|
|
2691
|
+
function childPath(path2, name) {
|
|
2692
|
+
const separator = path2.includes("/") || !path2.includes("\\") ? "/" : "\\";
|
|
2693
|
+
return path2.endsWith(separator) ? path2 + name : path2 + separator + name;
|
|
2694
|
+
}
|
|
2695
|
+
function normalize(path2) {
|
|
2696
|
+
const squeezed = `/${path2}`.replace(/\/+/g, "/");
|
|
2697
|
+
return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
|
|
2698
|
+
}
|
|
2699
|
+
})(TaLocation || (TaLocation = {}));
|
|
2700
|
+
// ../ta-protocol/esm/common/message-protocol.js
|
|
2701
|
+
var TaMessageContext;
|
|
2702
|
+
(function(TaMessageContext2) {
|
|
2703
|
+
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
2704
|
+
function wrap(context, message) {
|
|
2705
|
+
return `<context>
|
|
2706
|
+
${context}
|
|
2707
|
+
</context>
|
|
2708
|
+
${message}`;
|
|
2709
|
+
}
|
|
2710
|
+
TaMessageContext2.wrap = wrap;
|
|
2711
|
+
function strip(message) {
|
|
2712
|
+
return message.replace(BLOCK, "");
|
|
2713
|
+
}
|
|
2714
|
+
TaMessageContext2.strip = strip;
|
|
2715
|
+
function read(message) {
|
|
2716
|
+
var _a;
|
|
2717
|
+
const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
|
|
2718
|
+
return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
|
|
2719
|
+
}
|
|
2720
|
+
TaMessageContext2.read = read;
|
|
2721
|
+
})(TaMessageContext || (TaMessageContext = {}));
|
|
2722
|
+
var TaMessageSource;
|
|
2723
|
+
(function(TaMessageSource2) {
|
|
2724
|
+
TaMessageSource2.DOUBLE = "ta:double";
|
|
2725
|
+
const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
2726
|
+
function mark(message, from, detail) {
|
|
2727
|
+
return marked(message, line(from, detail));
|
|
2728
|
+
}
|
|
2729
|
+
TaMessageSource2.mark = mark;
|
|
2730
|
+
function notice(message, from, detail) {
|
|
2731
|
+
return marked(message, line(from, detail, true));
|
|
2732
|
+
}
|
|
2733
|
+
TaMessageSource2.notice = notice;
|
|
2734
|
+
function line(from, detail, notice2 = false) {
|
|
2735
|
+
return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
|
|
2736
|
+
}
|
|
2737
|
+
TaMessageSource2.line = line;
|
|
2738
|
+
function of(message) {
|
|
2739
|
+
const context = TaMessageContext.read(message);
|
|
2740
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
2741
|
+
return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
|
|
2742
|
+
}
|
|
2743
|
+
TaMessageSource2.of = of;
|
|
2744
|
+
function isNotice(message) {
|
|
2745
|
+
var _a;
|
|
2746
|
+
return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
|
|
2747
|
+
}
|
|
2748
|
+
TaMessageSource2.isNotice = isNotice;
|
|
2749
|
+
TaMessageSource2.SECTION = "ta-sources";
|
|
2750
|
+
TaMessageSource2.PROMPT = [
|
|
2751
|
+
"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.",
|
|
2752
|
+
"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:",
|
|
2753
|
+
"- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
|
|
2754
|
+
"- 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).",
|
|
2755
|
+
"- Never quote it as the user's words nor answer it as if they had said it."
|
|
2756
|
+
].join(`
|
|
2757
|
+
`);
|
|
2758
|
+
function marked(message, source) {
|
|
2759
|
+
if (/^[/!]/.test(message) || of(message)) {
|
|
2760
|
+
return message;
|
|
2761
|
+
}
|
|
2762
|
+
const context = TaMessageContext.read(message);
|
|
2763
|
+
return TaMessageContext.wrap(context === undefined ? source : `${context}
|
|
2764
|
+
${source}`, TaMessageContext.strip(message));
|
|
2765
|
+
}
|
|
2766
|
+
})(TaMessageSource || (TaMessageSource = {}));
|
|
2767
|
+
var TaImageNote;
|
|
2768
|
+
(function(TaImageNote2) {
|
|
2769
|
+
const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
|
|
2770
|
+
function strip(text) {
|
|
2771
|
+
const lines = text.split(`
|
|
2772
|
+
`);
|
|
2773
|
+
const kept = lines.filter((line) => !NOTE.test(line.trim()));
|
|
2774
|
+
if (kept.length === lines.length) {
|
|
2775
|
+
return text;
|
|
2776
|
+
}
|
|
2777
|
+
return kept.join(`
|
|
2778
|
+
`).replace(/\n+$/, "").replace(/^\n+/, "");
|
|
2779
|
+
}
|
|
2780
|
+
TaImageNote2.strip = strip;
|
|
2781
|
+
})(TaImageNote || (TaImageNote = {}));
|
|
2782
|
+
var TaImageSize;
|
|
2783
|
+
(function(TaImageSize2) {
|
|
2784
|
+
const JPEG_BYTES = 256 * 1024;
|
|
2785
|
+
function of(base64) {
|
|
2786
|
+
var _a, _b, _c;
|
|
2787
|
+
let bytes;
|
|
2788
|
+
try {
|
|
2789
|
+
const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
|
|
2790
|
+
bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
2791
|
+
} catch (_d) {
|
|
2792
|
+
return;
|
|
2793
|
+
}
|
|
2794
|
+
const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== undefined ? _a : gif(bytes)) !== null && _b !== undefined ? _b : webp(bytes)) !== null && _c !== undefined ? _c : jpeg(bytes);
|
|
2795
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
2796
|
+
}
|
|
2797
|
+
TaImageSize2.of = of;
|
|
2798
|
+
function u16be(bytes, at) {
|
|
2799
|
+
return bytes[at] << 8 | bytes[at + 1];
|
|
2800
|
+
}
|
|
2801
|
+
function u16le(bytes, at) {
|
|
2802
|
+
return bytes[at] | bytes[at + 1] << 8;
|
|
2803
|
+
}
|
|
2804
|
+
function u24le(bytes, at) {
|
|
2805
|
+
return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
|
|
2806
|
+
}
|
|
2807
|
+
function u32be(bytes, at) {
|
|
2808
|
+
return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
|
|
2809
|
+
}
|
|
2810
|
+
function text(bytes, at, length) {
|
|
2811
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
2812
|
+
}
|
|
2813
|
+
function png(bytes) {
|
|
2814
|
+
return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
2815
|
+
}
|
|
2816
|
+
function gif(bytes) {
|
|
2817
|
+
return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
2818
|
+
}
|
|
2819
|
+
function webp(bytes) {
|
|
2820
|
+
if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
|
|
2821
|
+
return;
|
|
2822
|
+
}
|
|
2823
|
+
switch (text(bytes, 12, 4)) {
|
|
2824
|
+
case "VP8 ":
|
|
2825
|
+
return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
|
|
2826
|
+
case "VP8L": {
|
|
2827
|
+
const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
|
|
2828
|
+
return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
|
|
2829
|
+
}
|
|
2830
|
+
case "VP8X":
|
|
2831
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
2832
|
+
default:
|
|
2833
|
+
return;
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
function jpeg(bytes) {
|
|
2837
|
+
if (bytes[0] !== 255 || bytes[1] !== 216) {
|
|
2838
|
+
return;
|
|
2839
|
+
}
|
|
2840
|
+
let at = 2;
|
|
2841
|
+
while (at + 9 < bytes.length) {
|
|
2842
|
+
if (bytes[at] !== 255) {
|
|
2843
|
+
return;
|
|
2844
|
+
}
|
|
2845
|
+
const marker = bytes[at + 1];
|
|
2846
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
2847
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
2848
|
+
}
|
|
2849
|
+
at += 2 + u16be(bytes, at + 2);
|
|
2850
|
+
}
|
|
2851
|
+
return;
|
|
2852
|
+
}
|
|
2853
|
+
})(TaImageSize || (TaImageSize = {}));
|
|
2854
|
+
var TaAgentSummary;
|
|
2855
|
+
(function(TaAgentSummary2) {
|
|
2856
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
2857
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
2858
|
+
function read(text) {
|
|
2859
|
+
if (!START.test(text)) {
|
|
2860
|
+
return;
|
|
2861
|
+
}
|
|
2862
|
+
return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
|
|
2863
|
+
}
|
|
2864
|
+
TaAgentSummary2.read = read;
|
|
2865
|
+
function strip(text) {
|
|
2866
|
+
return text.replace(BLOCK, "");
|
|
2867
|
+
}
|
|
2868
|
+
TaAgentSummary2.strip = strip;
|
|
2869
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
2870
|
+
var TaSkillUse;
|
|
2871
|
+
(function(TaSkillUse2) {
|
|
2872
|
+
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
2873
|
+
function parse(message) {
|
|
2874
|
+
var _a;
|
|
2875
|
+
const match = BLOCK.exec(message);
|
|
2876
|
+
if (!match) {
|
|
2877
|
+
return;
|
|
2878
|
+
}
|
|
2879
|
+
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
|
|
2880
|
+
}
|
|
2881
|
+
TaSkillUse2.parse = parse;
|
|
2882
|
+
function command(use) {
|
|
2883
|
+
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
2884
|
+
}
|
|
2885
|
+
TaSkillUse2.command = command;
|
|
2886
|
+
})(TaSkillUse || (TaSkillUse = {}));
|
|
2887
|
+
var TaTaskNote;
|
|
2888
|
+
(function(TaTaskNote2) {
|
|
2889
|
+
const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
|
|
2890
|
+
const ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
2891
|
+
function write(note) {
|
|
2892
|
+
const attributes = [`id="${quote(note.id)}"`];
|
|
2893
|
+
if (note.was !== undefined) {
|
|
2894
|
+
attributes.push(`was="${quote(note.was)}"`);
|
|
2895
|
+
}
|
|
2896
|
+
attributes.push(`title="${quote(note.title)}"`);
|
|
2897
|
+
if (note.status !== undefined) {
|
|
2898
|
+
attributes.push(`status="${quote(note.status)}"`);
|
|
2899
|
+
}
|
|
2900
|
+
return `<task_${note.kind} ${attributes.join(" ")}>
|
|
2901
|
+
${note.body}
|
|
2902
|
+
</task_${note.kind}>`;
|
|
2903
|
+
}
|
|
2904
|
+
TaTaskNote2.write = write;
|
|
2905
|
+
function parse(text) {
|
|
2906
|
+
const match = NOTE.exec(text.trim());
|
|
2907
|
+
if (!match) {
|
|
2908
|
+
return;
|
|
2909
|
+
}
|
|
2910
|
+
const attributes = {};
|
|
2911
|
+
for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
|
|
2912
|
+
attributes[name] = unquote(value);
|
|
2913
|
+
}
|
|
2914
|
+
if (!attributes.id || attributes.title === undefined) {
|
|
2915
|
+
return;
|
|
2916
|
+
}
|
|
2917
|
+
const { id, title, status, was } = attributes;
|
|
2918
|
+
return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
|
|
2919
|
+
}
|
|
2920
|
+
TaTaskNote2.parse = parse;
|
|
2921
|
+
function quote(text) {
|
|
2922
|
+
return text.replace(/&/g, "&").replace(/"/g, """).replace(/\n/g, " ");
|
|
2923
|
+
}
|
|
2924
|
+
function unquote(text) {
|
|
2925
|
+
return text.replace(/"/g, '"').replace(/&/g, "&");
|
|
2926
|
+
}
|
|
2927
|
+
})(TaTaskNote || (TaTaskNote = {}));
|
|
2928
|
+
var TaSecretRef;
|
|
2929
|
+
(function(TaSecretRef2) {
|
|
2930
|
+
TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
|
|
2931
|
+
const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
|
|
2932
|
+
const KINDS = [
|
|
2933
|
+
[/^PHONE(?:_\d+)?$/, "phone"],
|
|
2934
|
+
[/^EMAIL(?:_\d+)?$/, "email"],
|
|
2935
|
+
[/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
|
|
2936
|
+
[/^BANK_CARD(?:_\d+)?$/, "bankCard"]
|
|
2937
|
+
];
|
|
2938
|
+
function has(text) {
|
|
2939
|
+
return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
|
|
2940
|
+
}
|
|
2941
|
+
TaSecretRef2.has = has;
|
|
2942
|
+
function kind(name) {
|
|
2943
|
+
var _a;
|
|
2944
|
+
var _b;
|
|
2945
|
+
return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
|
|
2946
|
+
}
|
|
2947
|
+
TaSecretRef2.kind = kind;
|
|
2948
|
+
function split(text) {
|
|
2949
|
+
if (!has(text)) {
|
|
2950
|
+
return [{ text }];
|
|
2951
|
+
}
|
|
2952
|
+
const parts = [];
|
|
2953
|
+
let at = 0;
|
|
2954
|
+
for (const match of text.matchAll(REF)) {
|
|
2955
|
+
if (match.index > at) {
|
|
2956
|
+
parts.push({ text: text.slice(at, match.index) });
|
|
2957
|
+
}
|
|
2958
|
+
parts.push({ secret: match[1], kind: kind(match[1]) });
|
|
2959
|
+
at = match.index + match[0].length;
|
|
2960
|
+
}
|
|
2961
|
+
if (at < text.length) {
|
|
2962
|
+
parts.push({ text: text.slice(at) });
|
|
2963
|
+
}
|
|
2964
|
+
return parts;
|
|
2965
|
+
}
|
|
2966
|
+
TaSecretRef2.split = split;
|
|
2967
|
+
function plain(text, label) {
|
|
2968
|
+
return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
|
|
2969
|
+
}
|
|
2970
|
+
TaSecretRef2.plain = plain;
|
|
2971
|
+
})(TaSecretRef || (TaSecretRef = {}));
|
|
2972
|
+
// ../ta-protocol/esm/common/package-protocol.js
|
|
2973
|
+
var TaPackageServer = Symbol("TaPackageServer");
|
|
2974
|
+
var TaPackageTextUtil;
|
|
2975
|
+
(function(TaPackageTextUtil2) {
|
|
2976
|
+
function pick(text, language2) {
|
|
2977
|
+
var _a, _b, _c, _d, _e;
|
|
2978
|
+
if (text === undefined || typeof text === "string") {
|
|
2979
|
+
return text;
|
|
2980
|
+
}
|
|
2981
|
+
const base = language2.split("-")[0];
|
|
2982
|
+
const kin = Object.keys(text).find((key) => key.split("-")[0] === base);
|
|
2983
|
+
return (_e = (_d = (_c = (_b = (_a = text[language2]) !== 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];
|
|
2984
|
+
}
|
|
2985
|
+
TaPackageTextUtil2.pick = pick;
|
|
2986
|
+
})(TaPackageTextUtil || (TaPackageTextUtil = {}));
|
|
2987
|
+
// ../ta-protocol/esm/common/page-protocol.js
|
|
2988
|
+
var TaPageServer = Symbol("TaPageServer");
|
|
2989
|
+
// ../ta-protocol/esm/common/path-map.js
|
|
2990
|
+
var TaPathMap;
|
|
2991
|
+
(function(TaPathMap2) {
|
|
2992
|
+
function isWindows(path2) {
|
|
2993
|
+
return /^[a-zA-Z]:([\\/]|$)/.test(path2) || /^\\\\[^\\]/.test(path2);
|
|
2994
|
+
}
|
|
2995
|
+
TaPathMap2.isWindows = isWindows;
|
|
2996
|
+
function rest(path2, base) {
|
|
2997
|
+
const windows = isWindows(base);
|
|
2998
|
+
if (windows ? !isWindows(path2) : !base.startsWith("/") || !path2.startsWith("/")) {
|
|
2999
|
+
return;
|
|
3000
|
+
}
|
|
3001
|
+
const within = parts(base, windows);
|
|
3002
|
+
const all = parts(path2, windows);
|
|
3003
|
+
if (!within.length || all.length < within.length) {
|
|
3004
|
+
return;
|
|
3005
|
+
}
|
|
3006
|
+
const same = (a, b) => windows ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
3007
|
+
return within.every((part, i) => same(part, all[i])) ? all.slice(within.length) : undefined;
|
|
3008
|
+
}
|
|
3009
|
+
TaPathMap2.rest = rest;
|
|
3010
|
+
function under(path2, base) {
|
|
3011
|
+
return rest(path2, base) !== undefined;
|
|
3012
|
+
}
|
|
3013
|
+
TaPathMap2.under = under;
|
|
3014
|
+
function join2(base, parts2) {
|
|
3015
|
+
if (!parts2.length) {
|
|
3016
|
+
return base;
|
|
3017
|
+
}
|
|
3018
|
+
const sep = isWindows(base) ? "\\" : "/";
|
|
3019
|
+
return `${base.replace(/[\\/]+$/, "")}${sep}${parts2.join(sep)}`;
|
|
3020
|
+
}
|
|
3021
|
+
TaPathMap2.join = join2;
|
|
3022
|
+
function basename(path2) {
|
|
3023
|
+
var _a;
|
|
3024
|
+
return (_a = path2.split(/[\\/]+/).filter(Boolean).pop()) !== null && _a !== undefined ? _a : "";
|
|
3025
|
+
}
|
|
3026
|
+
TaPathMap2.basename = basename;
|
|
3027
|
+
function path(value, pairs) {
|
|
3028
|
+
for (const [from, to] of deepest(pairs)) {
|
|
3029
|
+
const found = rest(value, from);
|
|
3030
|
+
if (found) {
|
|
3031
|
+
return join2(to, found);
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
return value;
|
|
3035
|
+
}
|
|
3036
|
+
TaPathMap2.path = path;
|
|
3037
|
+
function text(value, pairs) {
|
|
3038
|
+
const order = deepest(pairs);
|
|
3039
|
+
if (!order.length) {
|
|
3040
|
+
return value;
|
|
3041
|
+
}
|
|
3042
|
+
const end = String.raw`\s"'<>|*?:;,`;
|
|
3043
|
+
const pattern = new RegExp(String.raw`(^|[^\w.~-])(?:${order.map(([from]) => `(${source(from)})`).join("|")})((?:[\\/][^\\/${end}]*)*)(?=$|[\\/${end})\]}])`, "g");
|
|
3044
|
+
return value.replace(pattern, (...match) => {
|
|
3045
|
+
var _a;
|
|
3046
|
+
const before = match[1];
|
|
3047
|
+
const found = order.findIndex((_, i) => match[i + 2] !== undefined);
|
|
3048
|
+
const tail = (_a = match[order.length + 2]) !== null && _a !== undefined ? _a : "";
|
|
3049
|
+
return `${before}${join2(order[found][1], tail.split(/[\\/]+/).filter(Boolean))}`;
|
|
3050
|
+
});
|
|
3051
|
+
}
|
|
3052
|
+
TaPathMap2.text = text;
|
|
3053
|
+
function json(value, pairs) {
|
|
3054
|
+
const order = deepest(pairs);
|
|
3055
|
+
if (!order.length) {
|
|
3056
|
+
return value;
|
|
3057
|
+
}
|
|
3058
|
+
const one = (each) => {
|
|
3059
|
+
const whole = path(each, order);
|
|
3060
|
+
return whole !== each ? whole : text(each, order);
|
|
3061
|
+
};
|
|
3062
|
+
const walk = (each) => {
|
|
3063
|
+
if (typeof each === "string") {
|
|
3064
|
+
return one(each);
|
|
3065
|
+
}
|
|
3066
|
+
if (Array.isArray(each)) {
|
|
3067
|
+
return each.map(walk);
|
|
3068
|
+
}
|
|
3069
|
+
if (each && typeof each === "object") {
|
|
3070
|
+
return Object.fromEntries(Object.entries(each).map(([key, inner]) => [one(key), walk(inner)]));
|
|
3071
|
+
}
|
|
3072
|
+
return each;
|
|
3073
|
+
};
|
|
3074
|
+
return walk(value);
|
|
3075
|
+
}
|
|
3076
|
+
TaPathMap2.json = json;
|
|
3077
|
+
function parts(path2, windows) {
|
|
3078
|
+
return path2.split(windows ? /[\\/]+/ : /\/+/).filter(Boolean);
|
|
3079
|
+
}
|
|
3080
|
+
function deepest(pairs) {
|
|
3081
|
+
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);
|
|
3082
|
+
}
|
|
3083
|
+
function source(base) {
|
|
3084
|
+
const windows = isWindows(base);
|
|
3085
|
+
const quote = (part) => [...part].map((char) => windows && char.toLowerCase() !== char.toUpperCase() ? `[${char.toLowerCase()}${char.toUpperCase()}]` : char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("");
|
|
3086
|
+
const each = parts(base, windows).map(quote);
|
|
3087
|
+
if (!windows) {
|
|
3088
|
+
return `/${each.join("/+")}`;
|
|
3089
|
+
}
|
|
3090
|
+
return `${base.startsWith("\\\\") ? String.raw`\\\\` : ""}${each.join(String.raw`[\\/]+`)}`;
|
|
3091
|
+
}
|
|
3092
|
+
})(TaPathMap || (TaPathMap = {}));
|
|
3093
|
+
// ../ta-protocol/esm/common/presence-protocol.js
|
|
3094
|
+
var TaPresenceServer = Symbol("TaPresenceServer");
|
|
3095
|
+
var TaMessageAuthor;
|
|
3096
|
+
(function(TaMessageAuthor2) {
|
|
3097
|
+
const LINE = /^\[ta:by ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
3098
|
+
const LINES = /^\[ta:by [^\]\n]*\]$\n?/gm;
|
|
3099
|
+
function strip(message) {
|
|
3100
|
+
const context = TaMessageContext.read(message);
|
|
3101
|
+
if (context === undefined || !LINE.test(context)) {
|
|
3102
|
+
return message;
|
|
3103
|
+
}
|
|
3104
|
+
const kept = context.replace(LINES, "").replace(/\n+$/, "");
|
|
3105
|
+
const body = TaMessageContext.strip(message);
|
|
3106
|
+
return kept.trim() ? TaMessageContext.wrap(kept, body) : body;
|
|
3107
|
+
}
|
|
3108
|
+
TaMessageAuthor2.strip = strip;
|
|
3109
|
+
function mark(message, id, name) {
|
|
3110
|
+
const plain = strip(message);
|
|
3111
|
+
if (/^[/!]/.test(plain)) {
|
|
3112
|
+
return plain;
|
|
3113
|
+
}
|
|
3114
|
+
const line = `[ta:by ${id.replace(/[\s\]]/g, "")} ${name.replace(/[\]\n]/g, " ").trim() || id}]`;
|
|
3115
|
+
const context = TaMessageContext.read(plain);
|
|
3116
|
+
return TaMessageContext.wrap(context === undefined ? line : `${context}
|
|
3117
|
+
${line}`, TaMessageContext.strip(plain));
|
|
3118
|
+
}
|
|
3119
|
+
TaMessageAuthor2.mark = mark;
|
|
3120
|
+
function of(message) {
|
|
3121
|
+
var _a;
|
|
3122
|
+
const context = TaMessageContext.read(message);
|
|
3123
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
3124
|
+
return match ? { id: match[1], name: ((_a = match[2]) !== null && _a !== undefined ? _a : match[1]).trim() } : undefined;
|
|
3125
|
+
}
|
|
3126
|
+
TaMessageAuthor2.of = of;
|
|
3127
|
+
})(TaMessageAuthor || (TaMessageAuthor = {}));
|
|
3128
|
+
// ../ta-protocol/esm/common/relay-protocol.js
|
|
3129
|
+
var TaRelayServer = Symbol("TaRelayServer");
|
|
3130
|
+
// ../ta-protocol/esm/common/remote-protocol.js
|
|
3131
|
+
var TaRemoteServer = Symbol("TaRemoteServer");
|
|
3132
|
+
// ../ta-protocol/esm/common/room-protocol.js
|
|
3133
|
+
var TaRoomServer = Symbol("TaRoomServer");
|
|
3134
|
+
var TA_PICTURE = { key: "picture:", maxChars: 16 * 1024 };
|
|
3135
|
+
var TaRoomWatchUtil;
|
|
3136
|
+
(function(TaRoomWatchUtil2) {
|
|
3137
|
+
function of(messages, state) {
|
|
3138
|
+
const prefixes = Array.isArray(state) ? state.filter((prefix) => typeof prefix === "string" && prefix.length > 0) : [];
|
|
3139
|
+
return { messages: messages !== false, state: [...new Set(prefixes)].sort() };
|
|
3140
|
+
}
|
|
3141
|
+
TaRoomWatchUtil2.of = of;
|
|
3142
|
+
function union(watches) {
|
|
3143
|
+
let messages = false;
|
|
3144
|
+
const state = [];
|
|
3145
|
+
for (const watch of watches) {
|
|
3146
|
+
messages || (messages = watch.messages);
|
|
3147
|
+
state.push(...watch.state);
|
|
3148
|
+
}
|
|
3149
|
+
return of(messages, messages ? [] : state);
|
|
3150
|
+
}
|
|
3151
|
+
TaRoomWatchUtil2.union = union;
|
|
3152
|
+
function same(a, b) {
|
|
3153
|
+
return a === b || !!a && !!b && a.messages === b.messages && a.state.join(`
|
|
3154
|
+
`) === b.state.join(`
|
|
3155
|
+
`);
|
|
3156
|
+
}
|
|
3157
|
+
TaRoomWatchUtil2.same = same;
|
|
3158
|
+
function hears(watch, event) {
|
|
3159
|
+
if (event.type === "message") {
|
|
3160
|
+
return watch.messages;
|
|
3161
|
+
}
|
|
3162
|
+
if (event.type === "state") {
|
|
3163
|
+
return watch.messages || watch.state.some((prefix) => event.key.startsWith(prefix));
|
|
3164
|
+
}
|
|
3165
|
+
return true;
|
|
3166
|
+
}
|
|
3167
|
+
TaRoomWatchUtil2.hears = hears;
|
|
3168
|
+
})(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
|
|
3169
|
+
// ../ta-protocol/esm/common/said-protocol.js
|
|
3170
|
+
var TaSaid;
|
|
3171
|
+
(function(TaSaid2) {
|
|
3172
|
+
const CARD = /^ta-/i;
|
|
3173
|
+
const READ = 4000;
|
|
3174
|
+
const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
|
|
3175
|
+
const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
|
|
3176
|
+
const MARKS_ONLY = /^[-*_=|:+\s]+$/;
|
|
3177
|
+
const MARKS = [
|
|
3178
|
+
["context", /<\/?context>/],
|
|
3179
|
+
["source", /\[ta:(?:from|notice|by) /],
|
|
3180
|
+
["image note", /\[Image: original \d+x\d+|\[Image converted from /],
|
|
3181
|
+
["skill", /<skill name="|<\/skill>/],
|
|
3182
|
+
["task note", /<\/?task_(?:update|adopted|renamed)\b/],
|
|
3183
|
+
["summary", /<\/?(?:conversation_history_summary|summary)>/]
|
|
3184
|
+
];
|
|
3185
|
+
function text(content, joiner = `
|
|
3186
|
+
`) {
|
|
3187
|
+
if (typeof content === "string") {
|
|
3188
|
+
return content;
|
|
3189
|
+
}
|
|
3190
|
+
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) : "";
|
|
3191
|
+
}
|
|
3192
|
+
TaSaid2.text = text;
|
|
3193
|
+
function words2(role, text2, options = {}) {
|
|
3194
|
+
const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
|
|
3195
|
+
return withoutFences(said, (language2) => options.cards === false && CARD.test(language2), true).trim();
|
|
3196
|
+
}
|
|
3197
|
+
TaSaid2.words = words2;
|
|
3198
|
+
function of(message, options) {
|
|
3199
|
+
return message ? words2(message.role, text(message.content), options) : "";
|
|
3200
|
+
}
|
|
3201
|
+
TaSaid2.of = of;
|
|
3202
|
+
function notice(message) {
|
|
3203
|
+
return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
|
|
3204
|
+
}
|
|
3205
|
+
TaSaid2.notice = notice;
|
|
3206
|
+
function marksOnly(role, text2) {
|
|
3207
|
+
return !!text2.trim() && !line(words2(role, text2), { chars: Number.POSITIVE_INFINITY });
|
|
3208
|
+
}
|
|
3209
|
+
TaSaid2.marksOnly = marksOnly;
|
|
3210
|
+
function line(markdown, options) {
|
|
3211
|
+
var _a;
|
|
3212
|
+
const read = markdown.slice(0, READ);
|
|
3213
|
+
const prose = withoutFences(read, () => true, true).trim();
|
|
3214
|
+
const lines = plain(prose || codeOf(read)).split(`
|
|
3215
|
+
`).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));
|
|
3216
|
+
const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
|
|
3217
|
+
const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
|
|
3218
|
+
`);
|
|
3219
|
+
return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
|
|
3220
|
+
}
|
|
3221
|
+
TaSaid2.line = line;
|
|
3222
|
+
function leaks(shown, options = {}) {
|
|
3223
|
+
const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
|
|
3224
|
+
const lines = shown.split(`
|
|
3225
|
+
`);
|
|
3226
|
+
if (options.cards !== true && lines.some((part) => {
|
|
3227
|
+
var _a;
|
|
3228
|
+
var _b;
|
|
3229
|
+
return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
|
|
3230
|
+
})) {
|
|
3231
|
+
found.push("card");
|
|
3232
|
+
}
|
|
3233
|
+
if (lines.some((part) => TAG_LINE.test(part.trim()))) {
|
|
3234
|
+
found.push("tag");
|
|
3235
|
+
}
|
|
3236
|
+
return found;
|
|
3237
|
+
}
|
|
3238
|
+
TaSaid2.leaks = leaks;
|
|
3239
|
+
const SUMMARY = `<conversation_history_summary>
|
|
3240
|
+
<summary>
|
|
3241
|
+
1. Primary Request and Intent:
|
|
3242
|
+
The user works on the relay.
|
|
3243
|
+
</summary>
|
|
3244
|
+
</conversation_history_summary>`;
|
|
3245
|
+
TaSaid2.SAMPLES = [
|
|
3246
|
+
{
|
|
3247
|
+
mark: "context and where it came from",
|
|
3248
|
+
role: "user",
|
|
3249
|
+
text: `<context>
|
|
3250
|
+
The channel #ops, its members.
|
|
3251
|
+
[ta:from @celljs/ta-channels #ops]
|
|
3252
|
+
</context>
|
|
3253
|
+
Check the build`,
|
|
3254
|
+
said: "Check the build"
|
|
3255
|
+
},
|
|
3256
|
+
{
|
|
3257
|
+
mark: "a notice, not the user",
|
|
3258
|
+
role: "user",
|
|
3259
|
+
text: `<context>
|
|
3260
|
+
[ta:notice @celljs/ta-call]
|
|
3261
|
+
</context>
|
|
3262
|
+
The work finished. Its last words: tests pass.`,
|
|
3263
|
+
said: "The work finished. Its last words: tests pass."
|
|
3264
|
+
},
|
|
3265
|
+
{ mark: "one let in", role: "user", text: `<context>
|
|
3266
|
+
[ta:by p-7 Alice]
|
|
3267
|
+
</context>
|
|
3268
|
+
Hello there`, said: "Hello there" },
|
|
3269
|
+
{
|
|
3270
|
+
mark: "notes of images",
|
|
3271
|
+
role: "user",
|
|
3272
|
+
text: `Look at this
|
|
3273
|
+
[Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
|
|
3274
|
+
[Image converted from image/heic to image/png.]`,
|
|
3275
|
+
said: "Look at this"
|
|
3276
|
+
},
|
|
3277
|
+
{
|
|
3278
|
+
mark: "a skill run",
|
|
3279
|
+
role: "user",
|
|
3280
|
+
text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
|
|
3281
|
+
# Ta package
|
|
3282
|
+
Steps.
|
|
3283
|
+
</skill>
|
|
3284
|
+
|
|
3285
|
+
Make a card`,
|
|
3286
|
+
said: "Make a card"
|
|
3287
|
+
},
|
|
3288
|
+
{
|
|
3289
|
+
mark: "a note of a task",
|
|
3290
|
+
role: "user",
|
|
3291
|
+
text: `<task_update id="t1" title="Fix login" status="done">
|
|
3292
|
+
All tests pass.
|
|
3293
|
+
</task_update>`,
|
|
3294
|
+
said: "Fix login"
|
|
3295
|
+
},
|
|
3296
|
+
{ mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
|
|
3297
|
+
Now t2.
|
|
3298
|
+
</task_renamed>` },
|
|
3299
|
+
{ mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
|
|
3300
|
+
Switched to voice.`, said: "Switched to voice." },
|
|
3301
|
+
{ mark: "a summary alone", role: "assistant", text: SUMMARY },
|
|
3302
|
+
{ mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
|
|
3303
|
+
<summary>` },
|
|
3304
|
+
{
|
|
3305
|
+
mark: "a card after the answer",
|
|
3306
|
+
role: "assistant",
|
|
3307
|
+
text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
|
|
3308
|
+
said: "tests pass"
|
|
3309
|
+
},
|
|
3310
|
+
{ mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
|
|
3311
|
+
{ mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
|
|
3312
|
+
{ mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
|
|
3313
|
+
{ mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
|
|
3314
|
+
</system-reminder>
|
|
3315
|
+
Ready.`, said: "Ready." }
|
|
3316
|
+
];
|
|
3317
|
+
function userWords(text2) {
|
|
3318
|
+
const said = TaImageNote.strip(TaMessageContext.strip(text2));
|
|
3319
|
+
const skill = TaSkillUse.parse(said);
|
|
3320
|
+
if (skill) {
|
|
3321
|
+
return TaSkillUse.command(skill);
|
|
3322
|
+
}
|
|
3323
|
+
const note = TaTaskNote.parse(said);
|
|
3324
|
+
if (!note) {
|
|
3325
|
+
return said;
|
|
3326
|
+
}
|
|
3327
|
+
if (note.kind === "renamed") {
|
|
3328
|
+
return "";
|
|
3329
|
+
}
|
|
3330
|
+
return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
|
|
3331
|
+
}
|
|
3332
|
+
function withoutFences(text2, drop, tags = false) {
|
|
3333
|
+
const kept = [];
|
|
3334
|
+
let fence;
|
|
3335
|
+
let left = false;
|
|
3336
|
+
for (const part of text2.split(`
|
|
3337
|
+
`)) {
|
|
3338
|
+
const open = FENCE.exec(part);
|
|
3339
|
+
if (!fence && open) {
|
|
3340
|
+
fence = { mark: open[1], dropped: drop(open[2]) };
|
|
3341
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
3342
|
+
const dropped = fence.dropped;
|
|
3343
|
+
fence = undefined;
|
|
3344
|
+
if (dropped) {
|
|
3345
|
+
continue;
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
|
|
3349
|
+
left = true;
|
|
3350
|
+
} else {
|
|
3351
|
+
kept.push(part);
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
return left ? kept.join(`
|
|
3355
|
+
`).replace(/\n{3,}/g, `
|
|
3356
|
+
|
|
3357
|
+
`) : kept.join(`
|
|
3358
|
+
`);
|
|
3359
|
+
}
|
|
3360
|
+
function codeOf(text2) {
|
|
3361
|
+
const code = [];
|
|
3362
|
+
let fence;
|
|
3363
|
+
for (const part of text2.split(`
|
|
3364
|
+
`)) {
|
|
3365
|
+
const open = FENCE.exec(part);
|
|
3366
|
+
if (!fence && open) {
|
|
3367
|
+
fence = { mark: open[1], card: CARD.test(open[2]) };
|
|
3368
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
3369
|
+
fence = undefined;
|
|
3370
|
+
} else if (fence && !fence.card) {
|
|
3371
|
+
code.push(part);
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
return code.join(`
|
|
3375
|
+
`);
|
|
3376
|
+
}
|
|
3377
|
+
function closes(part, mark) {
|
|
3378
|
+
var _a;
|
|
3379
|
+
const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
|
|
3380
|
+
return !!close && close[0] === mark[0] && close.length >= mark.length;
|
|
3381
|
+
}
|
|
3382
|
+
function plain(text2) {
|
|
3383
|
+
const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
3384
|
+
const words3 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
|
|
3385
|
+
return words3 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
3386
|
+
}
|
|
3387
|
+
})(TaSaid || (TaSaid = {}));
|
|
3388
|
+
// ../ta-protocol/esm/common/screen-share-protocol.js
|
|
3389
|
+
var TaScreenShareServer = Symbol("TaScreenShareServer");
|
|
3390
|
+
var TaDesktopUtil;
|
|
3391
|
+
(function(TaDesktopUtil2) {
|
|
3392
|
+
TaDesktopUtil2.DEFAULT_PORT = 5900;
|
|
3393
|
+
function id(target) {
|
|
3394
|
+
var _a;
|
|
3395
|
+
return `${(_a = target.via) !== null && _a !== undefined ? _a : ""}|${host(target)}:${port(target)}`;
|
|
3396
|
+
}
|
|
3397
|
+
TaDesktopUtil2.id = id;
|
|
3398
|
+
function host(target) {
|
|
3399
|
+
var _a;
|
|
3400
|
+
return ((_a = target.host) !== null && _a !== undefined ? _a : "").trim() || "127.0.0.1";
|
|
3401
|
+
}
|
|
3402
|
+
TaDesktopUtil2.host = host;
|
|
3403
|
+
function port(target) {
|
|
3404
|
+
var _a;
|
|
3405
|
+
return (_a = target.port) !== null && _a !== undefined ? _a : TaDesktopUtil2.DEFAULT_PORT;
|
|
3406
|
+
}
|
|
3407
|
+
TaDesktopUtil2.port = port;
|
|
3408
|
+
function parse(id2) {
|
|
3409
|
+
const match = /^([^|]*)\|(.+):(\d+)$/.exec(String(id2 !== null && id2 !== undefined ? id2 : ""));
|
|
3410
|
+
if (!match) {
|
|
3411
|
+
return;
|
|
3412
|
+
}
|
|
3413
|
+
const port2 = Number(match[3]);
|
|
3414
|
+
return port2 > 0 && port2 < 65536 ? { via: match[1], host: match[2], port: port2 } : undefined;
|
|
3415
|
+
}
|
|
3416
|
+
TaDesktopUtil2.parse = parse;
|
|
3417
|
+
function validPort(port2) {
|
|
3418
|
+
return typeof port2 === "number" && Number.isInteger(port2) && port2 >= 1024 && port2 < 65536;
|
|
3419
|
+
}
|
|
3420
|
+
TaDesktopUtil2.validPort = validPort;
|
|
3421
|
+
function loopback(host2) {
|
|
3422
|
+
return /^(127\.\d+\.\d+\.\d+|localhost|::1|\[::1\])$/i.test(host2);
|
|
3423
|
+
}
|
|
3424
|
+
TaDesktopUtil2.loopback = loopback;
|
|
3425
|
+
function validHost(host2) {
|
|
3426
|
+
return typeof host2 === "string" && /^[A-Za-z0-9.:\-[\]]{1,253}$/.test(host2);
|
|
3427
|
+
}
|
|
3428
|
+
TaDesktopUtil2.validHost = validHost;
|
|
3429
|
+
})(TaDesktopUtil || (TaDesktopUtil = {}));
|
|
3430
|
+
// ../ta-protocol/esm/common/settings-protocol.js
|
|
3431
|
+
var TaSettingsServer = Symbol("TaSettingsServer");
|
|
3432
|
+
// ../ta-protocol/esm/common/ta-protocol.js
|
|
3433
|
+
var TaServer = Symbol("TaServer");
|
|
3434
|
+
var TaClient = Symbol("TaClient");
|
|
3435
|
+
var TaSlashCommandUtil;
|
|
3436
|
+
(function(TaSlashCommandUtil2) {
|
|
3437
|
+
function description(command, language2) {
|
|
3438
|
+
var _a, _b;
|
|
3439
|
+
const { descriptions } = command;
|
|
3440
|
+
return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language2]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language2.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
|
|
3441
|
+
}
|
|
3442
|
+
TaSlashCommandUtil2.description = description;
|
|
3443
|
+
})(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
|
|
3444
|
+
// ../ta-protocol/esm/common/team-protocol.js
|
|
3445
|
+
var TA_UNDECLARED = "extensions.install";
|
|
3446
|
+
var TaPermissionUtil;
|
|
3447
|
+
(function(TaPermissionUtil2) {
|
|
3448
|
+
function read(pi) {
|
|
3449
|
+
const given = pi === null || pi === undefined ? undefined : pi.permissions;
|
|
3450
|
+
const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
|
|
3451
|
+
const host2 = map(given === null || given === undefined ? undefined : given.host);
|
|
3452
|
+
const tools = map(given === null || given === undefined ? undefined : given.tools);
|
|
3453
|
+
return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
|
|
3454
|
+
}
|
|
3455
|
+
TaPermissionUtil2.read = read;
|
|
3456
|
+
function host(manifest, method, kind) {
|
|
3457
|
+
var _a, _b, _c, _d;
|
|
3458
|
+
const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
|
|
3459
|
+
const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
|
|
3460
|
+
return (_d = (_c = (_b = kind ? own(`${method}:${kind}`) : undefined) !== null && _b !== undefined ? _b : own(method)) !== null && _c !== undefined ? _c : own("*")) !== null && _d !== undefined ? _d : TA_UNDECLARED;
|
|
3461
|
+
}
|
|
3462
|
+
TaPermissionUtil2.host = host;
|
|
3463
|
+
})(TaPermissionUtil || (TaPermissionUtil = {}));
|
|
3464
|
+
var action = (id, en, zh, tw, ja, more = {}) => ({
|
|
3465
|
+
id,
|
|
3466
|
+
area: id.split(".")[0],
|
|
3467
|
+
title: { en, "zh-CN": zh, ...tw ? { "zh-TW": tw } : {}, ...ja ? { "ja-JP": ja } : {} },
|
|
3468
|
+
...more
|
|
3469
|
+
});
|
|
3470
|
+
var TA_ACTIONS = [
|
|
3471
|
+
action("chat.view", "See conversations", "查看对话", "檢視對話", "会話を確認"),
|
|
3472
|
+
action("chat.send", "Send in conversations", "在对话里发消息", "在對話裡發訊息", "会話にメッセージを送信"),
|
|
3473
|
+
action("chat.create", "Start conversations", "新建对话", "新建對話", "新しい会話を開始"),
|
|
3474
|
+
action("chat.stop", "Stop a reply", "停止回复", "停止回覆", "返信を停止"),
|
|
3475
|
+
action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话", "改名、歸檔、關閉對話", "会話の名前変更、アーカイブ、クローズ"),
|
|
3476
|
+
action("chat.share", "Share by a link", "生成分享链接", "生成分享連結", "共有リンクで共有"),
|
|
3477
|
+
action("agent.view", "See agents", "查看智能体", "檢視智慧體", "エージェントを確認"),
|
|
3478
|
+
action("agent.use", "Talk with agents", "和智能体对话", "和智慧體對話", "エージェントと対話"),
|
|
3479
|
+
action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体", "新建、修改、刪除智慧體", "エージェントを作成・変更・削除"),
|
|
3480
|
+
action("channel.view", "See channels", "查看频道", "檢視頻道", "チャネルを確認"),
|
|
3481
|
+
action("channel.post", "Post in channels", "在频道里发言", "在頻道里發言", "チャネルに投稿"),
|
|
3482
|
+
action("channel.manage", "Create and change channels", "新建、管理频道", "新建、管理頻道", "チャネルを作成・管理"),
|
|
3483
|
+
action("task.view", "See tasks", "查看任务", "檢視任務", "タスクを確認"),
|
|
3484
|
+
action("task.create", "Hand out tasks", "派任务", "派任務", "タスクを割り当て"),
|
|
3485
|
+
action("task.manage", "Take over and stop tasks", "接管、停止任务", "接管、停止任務", "タスクを引き継ぎ・停止"),
|
|
3486
|
+
action("files.read", "Read files", "读文件", "讀檔案", "ファイルを読取", { scoped: true }),
|
|
3487
|
+
action("files.write", "Change files", "改文件", "改檔案", "ファイルを変更", { scoped: true }),
|
|
3488
|
+
action("commands.run", "Let Ta run commands", "让 Ta 运行命令", "讓 Ta 執行命令", "Ta にコマンド実行を許可", { scoped: true, risky: true }),
|
|
3489
|
+
action("commands.terminal", "Open terminals", "打开终端", "開啟終端機", "ターミナルを開く", { scoped: true, risky: true }),
|
|
3490
|
+
action("hosts.use", "Use remote hosts", "使用远程主机", "使用遠端主機", "リモートホストを使用", { risky: true }),
|
|
3491
|
+
action("models.use", "Use the models", "使用模型", "使用模型", "モデルを使用"),
|
|
3492
|
+
action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更", { grant: "single" }),
|
|
3493
|
+
action("cron.view", "See scheduled tasks", "查看定时任务", "檢視定時任務", "スケジュールタスクを確認"),
|
|
3494
|
+
action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
|
|
3495
|
+
action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
|
|
3496
|
+
action("extensions.install", "Install and turn off extensions", "安装、停用扩展", "安裝、停用擴充功能", "拡張機能をインストール・無効化"),
|
|
3497
|
+
action("settings.view", "See settings", "查看设置", "檢視設定", "設定を確認"),
|
|
3498
|
+
action("settings.manage", "Change settings", "修改设置", "修改設定", "設定を変更"),
|
|
3499
|
+
action("members.view", "See members", "查看成员", "檢視成員", "メンバーを確認"),
|
|
3500
|
+
action("members.invite", "Invite people", "邀请别人", "邀請別人", "メンバーを招待"),
|
|
3501
|
+
action("members.approve", "Answer requests", "处理申请", "處理申請", "リクエストに対応"),
|
|
3502
|
+
action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
|
|
3503
|
+
action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
|
|
3504
|
+
];
|
|
3505
|
+
var TA_OWNER_ACTIONS = [
|
|
3506
|
+
action("desktop.view", "See remote desktops", "查看远程桌面", "檢視遠端桌面", "リモートデスクトップを見る", { risky: true }),
|
|
3507
|
+
action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true })
|
|
3508
|
+
];
|
|
3509
|
+
var OWNER_AREAS = ["desktop"];
|
|
3510
|
+
var TaActionUtil;
|
|
3511
|
+
(function(TaActionUtil2) {
|
|
3512
|
+
const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
|
|
3513
|
+
const titled = new Map([...TA_ACTIONS, ...TA_OWNER_ACTIONS].map((one) => [one.id, one]));
|
|
3514
|
+
function info(id) {
|
|
3515
|
+
return byId.get(id);
|
|
3516
|
+
}
|
|
3517
|
+
TaActionUtil2.info = info;
|
|
3518
|
+
function title(id, language2) {
|
|
3519
|
+
var _a;
|
|
3520
|
+
var _b, _c;
|
|
3521
|
+
const title2 = (_a = titled.get(id)) === null || _a === undefined ? undefined : _a.title;
|
|
3522
|
+
if (!title2) {
|
|
3523
|
+
return id;
|
|
3524
|
+
}
|
|
3525
|
+
return TaLanguageUtil.pick(language2, {
|
|
3526
|
+
"zh-CN": title2["zh-CN"],
|
|
3527
|
+
"zh-TW": (_b = title2["zh-TW"]) !== null && _b !== undefined ? _b : title2["zh-CN"],
|
|
3528
|
+
"en-US": title2.en,
|
|
3529
|
+
"ja-JP": (_c = title2["ja-JP"]) !== null && _c !== undefined ? _c : title2.en
|
|
3530
|
+
});
|
|
3531
|
+
}
|
|
3532
|
+
TaActionUtil2.title = title;
|
|
3533
|
+
function grantable(id) {
|
|
3534
|
+
const info2 = byId.get(id);
|
|
3535
|
+
return !!info2 && !OWNER_AREAS.includes(info2.area);
|
|
3536
|
+
}
|
|
3537
|
+
TaActionUtil2.grantable = grantable;
|
|
3538
|
+
function inRoles(id) {
|
|
3539
|
+
var _a;
|
|
3540
|
+
return grantable(id) && ((_a = byId.get(id)) === null || _a === undefined ? undefined : _a.grant) !== "single";
|
|
3541
|
+
}
|
|
3542
|
+
TaActionUtil2.inRoles = inRoles;
|
|
3543
|
+
function inside(dir, path) {
|
|
3544
|
+
const base = dir.replace(/\/+$/, "");
|
|
3545
|
+
return path === base || path.startsWith(`${base}/`) || base === "";
|
|
3546
|
+
}
|
|
3547
|
+
TaActionUtil2.inside = inside;
|
|
3548
|
+
})(TaActionUtil || (TaActionUtil = {}));
|
|
3549
|
+
// ../ta-protocol/esm/common/usage-protocol.js
|
|
3550
|
+
var TaUsageServer = Symbol("TaUsageServer");
|
|
3551
|
+
// ../ta-protocol/esm/common/voice-protocol.js
|
|
3552
|
+
var TaVoiceServer = Symbol("TaVoiceServer");
|
|
3553
|
+
var TaBargeIn;
|
|
3554
|
+
(function(TaBargeIn2) {
|
|
3555
|
+
TaBargeIn2.DEFAULTS = { duck: 0.2, speechMs: 500, level: 0.02, words: 2, waitMs: 1500, echo: 0.3, joinMs: 300, tap: false };
|
|
3556
|
+
TaBargeIn2.SENSITIVITY = [
|
|
3557
|
+
{ speechMs: 1000, level: 0.05 },
|
|
3558
|
+
{ speechMs: 750, level: 0.035 },
|
|
3559
|
+
{ speechMs: TaBargeIn2.DEFAULTS.speechMs, level: TaBargeIn2.DEFAULTS.level },
|
|
3560
|
+
{ speechMs: 300, level: 0.012 },
|
|
3561
|
+
{ speechMs: 150, level: 0.006 }
|
|
3562
|
+
];
|
|
3563
|
+
function sensitivity(bargeIn) {
|
|
3564
|
+
let nearest = 0;
|
|
3565
|
+
TaBargeIn2.SENSITIVITY.forEach((step, index) => {
|
|
3566
|
+
if (Math.abs(step.speechMs - bargeIn.speechMs) < Math.abs(TaBargeIn2.SENSITIVITY[nearest].speechMs - bargeIn.speechMs)) {
|
|
3567
|
+
nearest = index;
|
|
3568
|
+
}
|
|
3569
|
+
});
|
|
3570
|
+
return nearest;
|
|
3571
|
+
}
|
|
3572
|
+
TaBargeIn2.sensitivity = sensitivity;
|
|
3573
|
+
function pick(value) {
|
|
3574
|
+
const given = value && typeof value === "object" ? value : {};
|
|
3575
|
+
const out = typeof given.tap === "boolean" ? { tap: given.tap } : {};
|
|
3576
|
+
for (const key of Object.keys(RANGES)) {
|
|
3577
|
+
const number = given[key];
|
|
3578
|
+
if (typeof number === "number" && Number.isFinite(number)) {
|
|
3579
|
+
const [min, max] = RANGES[key];
|
|
3580
|
+
out[key] = Math.min(max, Math.max(min, number));
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
return out;
|
|
3584
|
+
}
|
|
3585
|
+
TaBargeIn2.pick = pick;
|
|
3586
|
+
const RANGES = {
|
|
3587
|
+
duck: [0, 1],
|
|
3588
|
+
speechMs: [0, 5000],
|
|
3589
|
+
level: [0, 1],
|
|
3590
|
+
words: [1, 50],
|
|
3591
|
+
waitMs: [100, 1e4],
|
|
3592
|
+
echo: [0, 4],
|
|
3593
|
+
joinMs: [0, 3000]
|
|
3594
|
+
};
|
|
3595
|
+
function resolve(value) {
|
|
3596
|
+
return { ...TaBargeIn2.DEFAULTS, ...pick(value) };
|
|
3597
|
+
}
|
|
3598
|
+
TaBargeIn2.resolve = resolve;
|
|
3599
|
+
})(TaBargeIn || (TaBargeIn = {}));
|
|
3600
|
+
// ../ta-protocol/esm/common/workspace-protocol.js
|
|
3601
|
+
var TaWorkspaceServer = Symbol("TaWorkspaceServer");
|
|
3602
|
+
var TaTerminalServer = Symbol("TaTerminalServer");
|
|
3603
|
+
var TaExcludedFiles;
|
|
3604
|
+
(function(TaExcludedFiles2) {
|
|
3605
|
+
TaExcludedFiles2.NAMES = [".git", ".svn", ".hg", ".DS_Store", "Thumbs.db"];
|
|
3606
|
+
function has(name) {
|
|
3607
|
+
return TaExcludedFiles2.NAMES.includes(name);
|
|
3608
|
+
}
|
|
3609
|
+
TaExcludedFiles2.has = has;
|
|
3610
|
+
function filter(entries) {
|
|
3611
|
+
return entries.filter((entry) => !has(entry.name));
|
|
3612
|
+
}
|
|
3613
|
+
TaExcludedFiles2.filter = filter;
|
|
3614
|
+
})(TaExcludedFiles || (TaExcludedFiles = {}));
|
|
3615
|
+
var TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
|
|
3616
|
+
// web-src/picture-host.ts
|
|
3617
|
+
var MAGIC = [
|
|
3618
|
+
["image/png", (bytes) => bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71],
|
|
3619
|
+
["image/jpeg", (bytes) => bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255],
|
|
3620
|
+
["image/webp", (bytes) => String.fromCharCode(...bytes.subarray(0, 4)) === "RIFF" && String.fromCharCode(...bytes.subarray(8, 12)) === "WEBP"]
|
|
3621
|
+
];
|
|
3622
|
+
var PictureHost;
|
|
3623
|
+
((PictureHost) => {
|
|
3624
|
+
function typeOf(bytes) {
|
|
3625
|
+
const found = MAGIC.find(([, is]) => is(bytes))?.[0];
|
|
3626
|
+
if (found) {
|
|
3627
|
+
return found;
|
|
3628
|
+
}
|
|
3629
|
+
const head = new TextDecoder().decode(bytes.subarray(0, 512)).replace(/^\uFEFF/, "").trimStart();
|
|
3630
|
+
return /^(<\?xml[^>]*>\s*)?(<!--[\s\S]*?-->\s*)*<svg[\s>]/.test(head) ? "image/svg+xml" : undefined;
|
|
3631
|
+
}
|
|
3632
|
+
PictureHost.typeOf = typeOf;
|
|
3633
|
+
async function set(host, file) {
|
|
3634
|
+
if (file === undefined || file === null || file === "") {
|
|
3635
|
+
return { picture: false, identity: await host.rooms.setPicture(null) };
|
|
3636
|
+
}
|
|
3637
|
+
if (typeof file !== "string") {
|
|
3638
|
+
throw new Error("Give the path of the picture: a PNG, JPEG, WebP or SVG file.");
|
|
3639
|
+
}
|
|
3640
|
+
const bytes = new Uint8Array(await readFile(resolve(file)));
|
|
3641
|
+
const type = typeOf(bytes);
|
|
3642
|
+
if (!type) {
|
|
3643
|
+
throw new Error(`${file} is not a PNG, JPEG, WebP or SVG picture.`);
|
|
3644
|
+
}
|
|
3645
|
+
const url = `data:${type};base64,${Buffer.from(bytes).toString("base64")}`;
|
|
3646
|
+
if (url.length > TA_PICTURE.maxChars) {
|
|
3647
|
+
const most = Math.floor((TA_PICTURE.maxChars - 40) * 3 / 4 / 1024);
|
|
3648
|
+
throw new Error(`The picture is ${Math.ceil(bytes.length / 1024)} KB; make it ${most} KB at most (a smaller square, fewer details).`);
|
|
3649
|
+
}
|
|
3650
|
+
return { picture: true, identity: await host.rooms.setPicture(url) };
|
|
3651
|
+
}
|
|
3652
|
+
PictureHost.set = set;
|
|
3653
|
+
})(PictureHost ||= {});
|
|
3654
|
+
|
|
2054
3655
|
// web-src/host.ts
|
|
2055
3656
|
async function activate(host) {
|
|
2056
3657
|
const doubles = new RoomDoubles(host);
|
|
@@ -2063,6 +3664,7 @@ async function activate(host) {
|
|
|
2063
3664
|
return doubles.dispose();
|
|
2064
3665
|
},
|
|
2065
3666
|
doubles: (request) => doubles.request(request),
|
|
3667
|
+
picture: (file) => PictureHost.set(host, file),
|
|
2066
3668
|
service: doubles
|
|
2067
3669
|
};
|
|
2068
3670
|
}
|