@celljs/ta-channels 4.11.0 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +3 -1
- package/README.md +3 -1
- package/extension/index.mjs +55 -2
- package/host/index.mjs +268 -8
- package/package.json +29 -5
- package/web/index.js +191 -36
package/README.en.md
CHANGED
|
@@ -29,7 +29,9 @@ Data is stored on the server in `<agentDir>/extension-data/@celljs/ta-channels.j
|
|
|
29
29
|
| `working` | agents currently answering |
|
|
30
30
|
| `focus` | channels Ta has created tools for or posted messages to; pages use this to mark them in the sidebar |
|
|
31
31
|
|
|
32
|
-
The page learns of changes via `pi.storage.onChange` and rereads them. To change something (create agent, create channel, add channel member, set lead / mute / remove member, delete channel, restart agent session, modify or delete agent, post message as user, open agent session), a page calls `request` on the server side: this package's web extension with `pi.callHost('request', request)`, other extensions with `pi.packages.callPackageHost('@celljs/ta-channels', 'request', [request])
|
|
32
|
+
The page learns of changes via `pi.storage.onChange` and rereads them. To change something (create agent, create channel, add channel member, set lead / mute / remove member, delete channel, restart agent session, modify or delete agent, post message as user, open agent session), a page calls `request` on the server side: this package's web extension with `pi.callHost('request', request)`, other extensions with `pi.packages.callPackageHost('@celljs/ta-channels', 'request', [request])` (the host of another package with `host.callPackageHost`). `request` is a `TeamRequest` (`web-src/channels-model.ts`); the call returns the result, or throws the reason. Each answer is first recorded as a job in `queue` and removed only after the answer is posted to the channel. After ta serve restarts, it continues processing remaining jobs: jobs that already have an answer (the channel has this agent's reply to that message) are not asked again, and messages already forwarded are not forwarded again, so processed messages do not duplicate. On restart, the one message that was being answered and not yet posted is asked again.
|
|
33
|
+
|
|
34
|
+
Another package that needs the agents (ta-rooms, for those to invite to a room) calls `listAgents` of the server side (`callPackageHost('@celljs/ta-channels', 'listAgents')`) rather than reading `team`: it returns `TeamAgentInfo[]` (`web-src/channels-model.ts`), each agent's `id`, `name`, `role`, `mark`, `face` (the one given by its id to an agent made before faces) and `cwd`, `temporary` on those Ta made for a team of its own; it only reads, and holds no session files.
|
|
33
35
|
|
|
34
36
|
## Limitations
|
|
35
37
|
|
package/README.md
CHANGED
|
@@ -29,7 +29,9 @@ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 包 关
|
|
|
29
29
|
| `working` | 正在回答的智能体 |
|
|
30
30
|
| `focus` | Ta 用工具建过或发过消息的频道,页面据此在侧栏标出 |
|
|
31
31
|
|
|
32
|
-
页面通过 `pi.storage.onChange` 得知变化后重新读取。页面要改什么(新建智能体、新建频道、添加频道成员、设负责人 / 免打扰 / 移出成员、删除频道、重开智能体的会话、修改或删除智能体、以用户身份发消息、打开智能体的会话),调用服务端的 `request`:本包的 Web 扩展用 `pi.callHost('request', request)`,其他扩展用 `pi.packages.callPackageHost('@celljs/ta-channels', 'request', [request])
|
|
32
|
+
页面通过 `pi.storage.onChange` 得知变化后重新读取。页面要改什么(新建智能体、新建频道、添加频道成员、设负责人 / 免打扰 / 移出成员、删除频道、重开智能体的会话、修改或删除智能体、以用户身份发消息、打开智能体的会话),调用服务端的 `request`:本包的 Web 扩展用 `pi.callHost('request', request)`,其他扩展用 `pi.packages.callPackageHost('@celljs/ta-channels', 'request', [request])`(别的包的服务端用 `host.callPackageHost`);`request` 的类型是 `TeamRequest`(`web-src/channels-model.ts`),返回结果,出错时抛出原因。每个回答先作为 job 记进 `queue`,回答贴进频道后才移除。ta serve 重启后接着处理剩下的 job:已经有回答(频道里有该智能体对这条消息的回复)的 job 不会再问,已经交出去的消息也不会再交一次,所以已处理的消息不会重复转发。重启时正在回答、还没有贴出的那一条,会再问一次。
|
|
33
|
+
|
|
34
|
+
别的包要知道有哪些智能体(如 ta-rooms 列出可以邀请进房间的),调用服务端的 `listAgents`(`callPackageHost('@celljs/ta-channels', 'listAgents')`),不要读 `team`:它返回 `TeamAgentInfo[]`(`web-src/channels-model.ts`),每个智能体的 `id`、`name`、`role`、`mark`、`face`(早于头像的智能体按 id 分到的那个)、`cwd`,Ta 为自己的团队临时建的带 `temporary`;只读,不含会话文件。
|
|
33
35
|
|
|
34
36
|
## 限制
|
|
35
37
|
|
package/extension/index.mjs
CHANGED
|
@@ -5,19 +5,70 @@ var TaHostUtil;
|
|
|
5
5
|
TaHostUtil2.WAIT_MS = 1000;
|
|
6
6
|
function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
|
|
7
7
|
return new Promise((resolve) => {
|
|
8
|
+
let heard = false;
|
|
9
|
+
let answered = false;
|
|
8
10
|
const timer = setTimeout(() => resolve(undefined), waitMs);
|
|
9
11
|
const request = {
|
|
10
12
|
name,
|
|
13
|
+
heard: () => {
|
|
14
|
+
heard = true;
|
|
15
|
+
},
|
|
11
16
|
resolve: (answer) => {
|
|
17
|
+
answered = true;
|
|
12
18
|
clearTimeout(timer);
|
|
13
19
|
resolve(answer);
|
|
14
20
|
}
|
|
15
21
|
};
|
|
16
22
|
events.emit(TA_HOST_EVENT, request);
|
|
23
|
+
if (!heard && !answered) {
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
resolve(undefined);
|
|
26
|
+
}
|
|
17
27
|
});
|
|
18
28
|
}
|
|
19
29
|
TaHostUtil2.reach = reach;
|
|
20
30
|
})(TaHostUtil || (TaHostUtil = {}));
|
|
31
|
+
var TA_ASK_ENTRY = "ta-ask";
|
|
32
|
+
var TaAskUtil;
|
|
33
|
+
(function(TaAskUtil2) {
|
|
34
|
+
const LENGTH = 120;
|
|
35
|
+
function entry(question) {
|
|
36
|
+
const line = question.replace(/\s+/g, " ").trim();
|
|
37
|
+
return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
|
|
38
|
+
}
|
|
39
|
+
TaAskUtil2.entry = entry;
|
|
40
|
+
function asking(entries) {
|
|
41
|
+
var _a;
|
|
42
|
+
for (let i = entries.length - 1;i >= 0; i--) {
|
|
43
|
+
const entry2 = entries[i];
|
|
44
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
|
|
48
|
+
return read(entry2);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
TaAskUtil2.asking = asking;
|
|
54
|
+
function next(asked, entry2) {
|
|
55
|
+
var _a;
|
|
56
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
|
|
60
|
+
}
|
|
61
|
+
TaAskUtil2.next = next;
|
|
62
|
+
function read(found) {
|
|
63
|
+
var _a;
|
|
64
|
+
const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
|
|
65
|
+
if (typeof question !== "string" || !question.trim()) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
|
|
69
|
+
return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
|
|
70
|
+
}
|
|
71
|
+
})(TaAskUtil || (TaAskUtil = {}));
|
|
21
72
|
|
|
22
73
|
// web-src/channels-model.ts
|
|
23
74
|
var NAME = "@celljs/ta-channels";
|
|
@@ -150,12 +201,12 @@ var ChannelsUtil;
|
|
|
150
201
|
ChannelsUtil.hash = hash;
|
|
151
202
|
function findAgent(team, ref) {
|
|
152
203
|
const key = ref.trim().replace(/^@/, "").toLowerCase();
|
|
153
|
-
return team.agents.find((agent) => agent.id === ref
|
|
204
|
+
return team.agents.find((agent) => agent.id === ref) ?? team.agents.find((agent) => agent.name.toLowerCase() === key);
|
|
154
205
|
}
|
|
155
206
|
ChannelsUtil.findAgent = findAgent;
|
|
156
207
|
function findChannel(team, ref) {
|
|
157
208
|
const key = ref.trim().replace(/^#/, "").toLowerCase();
|
|
158
|
-
return team.channels.find((channel) => channel.id === ref
|
|
209
|
+
return team.channels.find((channel) => channel.id === ref) ?? team.channels.find((channel) => channel.name.toLowerCase() === key);
|
|
159
210
|
}
|
|
160
211
|
ChannelsUtil.findChannel = findChannel;
|
|
161
212
|
function directory(value) {
|
|
@@ -504,6 +555,8 @@ var ChannelsUtil;
|
|
|
504
555
|
lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item.text}`));
|
|
505
556
|
}
|
|
506
557
|
lines.push("", `${authorName(team, message.author, labels)} to you:`);
|
|
558
|
+
const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels).replace(/[\]\n]/g, " ")}`;
|
|
559
|
+
lines.push(`[ta:from ${NAME} #${channel.name}${speaker}]`);
|
|
507
560
|
return `<context>
|
|
508
561
|
${lines.join(`
|
|
509
562
|
`)}
|
package/host/index.mjs
CHANGED
|
@@ -230,19 +230,70 @@ var TaHostUtil;
|
|
|
230
230
|
TaHostUtil2.WAIT_MS = 1000;
|
|
231
231
|
function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
|
|
232
232
|
return new Promise((resolve) => {
|
|
233
|
+
let heard = false;
|
|
234
|
+
let answered = false;
|
|
233
235
|
const timer = setTimeout(() => resolve(undefined), waitMs);
|
|
234
236
|
const request = {
|
|
235
237
|
name,
|
|
238
|
+
heard: () => {
|
|
239
|
+
heard = true;
|
|
240
|
+
},
|
|
236
241
|
resolve: (answer) => {
|
|
242
|
+
answered = true;
|
|
237
243
|
clearTimeout(timer);
|
|
238
244
|
resolve(answer);
|
|
239
245
|
}
|
|
240
246
|
};
|
|
241
247
|
events.emit(TA_HOST_EVENT, request);
|
|
248
|
+
if (!heard && !answered) {
|
|
249
|
+
clearTimeout(timer);
|
|
250
|
+
resolve(undefined);
|
|
251
|
+
}
|
|
242
252
|
});
|
|
243
253
|
}
|
|
244
254
|
TaHostUtil2.reach = reach;
|
|
245
255
|
})(TaHostUtil || (TaHostUtil = {}));
|
|
256
|
+
var TA_ASK_ENTRY = "ta-ask";
|
|
257
|
+
var TaAskUtil;
|
|
258
|
+
(function(TaAskUtil2) {
|
|
259
|
+
const LENGTH = 120;
|
|
260
|
+
function entry(question) {
|
|
261
|
+
const line = question.replace(/\s+/g, " ").trim();
|
|
262
|
+
return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
|
|
263
|
+
}
|
|
264
|
+
TaAskUtil2.entry = entry;
|
|
265
|
+
function asking(entries) {
|
|
266
|
+
var _a;
|
|
267
|
+
for (let i = entries.length - 1;i >= 0; i--) {
|
|
268
|
+
const entry2 = entries[i];
|
|
269
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
|
|
273
|
+
return read(entry2);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
TaAskUtil2.asking = asking;
|
|
279
|
+
function next(asked, entry2) {
|
|
280
|
+
var _a;
|
|
281
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
|
|
285
|
+
}
|
|
286
|
+
TaAskUtil2.next = next;
|
|
287
|
+
function read(found) {
|
|
288
|
+
var _a;
|
|
289
|
+
const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
|
|
290
|
+
if (typeof question !== "string" || !question.trim()) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
|
|
294
|
+
return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
|
|
295
|
+
}
|
|
296
|
+
})(TaAskUtil || (TaAskUtil = {}));
|
|
246
297
|
// ../ta-protocol/esm/common/ta-protocol.js
|
|
247
298
|
var TaServer = Symbol("TaServer");
|
|
248
299
|
var TaClient = Symbol("TaClient");
|
|
@@ -260,6 +311,8 @@ var TaErrorCode = {
|
|
|
260
311
|
CANCELLED: "CELL_TA_CANCELLED",
|
|
261
312
|
NOT_SIGNED_IN: "CELL_TA_NOT_SIGNED_IN",
|
|
262
313
|
ENVIRONMENT_FAILED: "CELL_TA_ENVIRONMENT_FAILED",
|
|
314
|
+
FORBIDDEN: "CELL_TA_FORBIDDEN",
|
|
315
|
+
LIMIT: "CELL_TA_LIMIT",
|
|
263
316
|
CONNECTION_LOST: "CELL_TA_CONNECTION_LOST"
|
|
264
317
|
};
|
|
265
318
|
var TaErrorUtil;
|
|
@@ -296,7 +349,34 @@ ${message}`;
|
|
|
296
349
|
return message.replace(BLOCK, "");
|
|
297
350
|
}
|
|
298
351
|
TaMessageContext2.strip = strip;
|
|
352
|
+
function read(message) {
|
|
353
|
+
var _a;
|
|
354
|
+
const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
|
|
355
|
+
return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
|
|
356
|
+
}
|
|
357
|
+
TaMessageContext2.read = read;
|
|
299
358
|
})(TaMessageContext || (TaMessageContext = {}));
|
|
359
|
+
var TaMessageSource;
|
|
360
|
+
(function(TaMessageSource2) {
|
|
361
|
+
TaMessageSource2.DOUBLE = "ta:double";
|
|
362
|
+
const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
363
|
+
function mark(message, from, detail) {
|
|
364
|
+
if (/^[/!]/.test(message) || of(message)) {
|
|
365
|
+
return message;
|
|
366
|
+
}
|
|
367
|
+
const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
|
|
368
|
+
const context = TaMessageContext.read(message);
|
|
369
|
+
return TaMessageContext.wrap(context === undefined ? line : `${context}
|
|
370
|
+
${line}`, TaMessageContext.strip(message));
|
|
371
|
+
}
|
|
372
|
+
TaMessageSource2.mark = mark;
|
|
373
|
+
function of(message) {
|
|
374
|
+
const context = TaMessageContext.read(message);
|
|
375
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
376
|
+
return match ? { from: match[1], ...match[2] ? { detail: match[2].trim() } : {} } : undefined;
|
|
377
|
+
}
|
|
378
|
+
TaMessageSource2.of = of;
|
|
379
|
+
})(TaMessageSource || (TaMessageSource = {}));
|
|
300
380
|
var TaImageNote;
|
|
301
381
|
(function(TaImageNote2) {
|
|
302
382
|
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 [^\]]+\.\]$/;
|
|
@@ -417,6 +497,86 @@ var TaSkillUse;
|
|
|
417
497
|
}
|
|
418
498
|
TaSkillUse2.command = command;
|
|
419
499
|
})(TaSkillUse || (TaSkillUse = {}));
|
|
500
|
+
// ../ta-protocol/esm/common/team-protocol.js
|
|
501
|
+
var TA_OWNER = "owner";
|
|
502
|
+
var TA_UNDECLARED = "extensions.install";
|
|
503
|
+
var TaPermissionUtil;
|
|
504
|
+
(function(TaPermissionUtil2) {
|
|
505
|
+
function read(pi) {
|
|
506
|
+
const given = pi === null || pi === undefined ? undefined : pi.permissions;
|
|
507
|
+
const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
|
|
508
|
+
const host2 = map(given === null || given === undefined ? undefined : given.host);
|
|
509
|
+
const tools = map(given === null || given === undefined ? undefined : given.tools);
|
|
510
|
+
return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
|
|
511
|
+
}
|
|
512
|
+
TaPermissionUtil2.read = read;
|
|
513
|
+
function host(manifest, method, kind) {
|
|
514
|
+
var _a, _b, _c, _d;
|
|
515
|
+
const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
|
|
516
|
+
const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
|
|
517
|
+
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;
|
|
518
|
+
}
|
|
519
|
+
TaPermissionUtil2.host = host;
|
|
520
|
+
})(TaPermissionUtil || (TaPermissionUtil = {}));
|
|
521
|
+
var action = (id, en, zh, more = {}) => ({
|
|
522
|
+
id,
|
|
523
|
+
area: id.split(".")[0],
|
|
524
|
+
title: { en, "zh-CN": zh },
|
|
525
|
+
...more
|
|
526
|
+
});
|
|
527
|
+
var TA_ACTIONS = [
|
|
528
|
+
action("chat.view", "See conversations", "查看对话"),
|
|
529
|
+
action("chat.send", "Send in conversations", "在对话里发消息"),
|
|
530
|
+
action("chat.create", "Start conversations", "新建对话"),
|
|
531
|
+
action("chat.stop", "Stop a reply", "停止回复"),
|
|
532
|
+
action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话"),
|
|
533
|
+
action("chat.share", "Share by a link", "生成分享链接"),
|
|
534
|
+
action("agent.view", "See agents", "查看智能体"),
|
|
535
|
+
action("agent.use", "Talk with agents", "和智能体对话"),
|
|
536
|
+
action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体"),
|
|
537
|
+
action("channel.view", "See channels", "查看频道"),
|
|
538
|
+
action("channel.post", "Post in channels", "在频道里发言"),
|
|
539
|
+
action("channel.manage", "Create and change channels", "新建、管理频道"),
|
|
540
|
+
action("task.view", "See tasks", "查看任务"),
|
|
541
|
+
action("task.create", "Hand out tasks", "派任务"),
|
|
542
|
+
action("task.manage", "Take over and stop tasks", "接管、停止任务"),
|
|
543
|
+
action("files.read", "Read files", "读文件", { scoped: true }),
|
|
544
|
+
action("files.write", "Change files", "改文件", { scoped: true }),
|
|
545
|
+
action("commands.run", "Let Ta run commands", "让 Ta 运行命令", { scoped: true, risky: true }),
|
|
546
|
+
action("commands.terminal", "Open terminals", "打开终端", { scoped: true, risky: true }),
|
|
547
|
+
action("hosts.use", "Use remote hosts", "使用远程主机", { risky: true }),
|
|
548
|
+
action("models.use", "Use the models", "使用模型"),
|
|
549
|
+
action("models.manage", "Sign in to models", "登录和更换模型账号"),
|
|
550
|
+
action("cron.view", "See scheduled tasks", "查看定时任务"),
|
|
551
|
+
action("cron.manage", "Change scheduled tasks", "管理定时任务"),
|
|
552
|
+
action("extensions.use", "Use extensions", "使用扩展"),
|
|
553
|
+
action("extensions.install", "Install and turn off extensions", "安装、停用扩展"),
|
|
554
|
+
action("settings.view", "See settings", "查看设置"),
|
|
555
|
+
action("settings.manage", "Change settings", "修改设置"),
|
|
556
|
+
action("members.view", "See members", "查看成员"),
|
|
557
|
+
action("members.invite", "Invite people", "邀请别人"),
|
|
558
|
+
action("members.approve", "Answer requests", "处理申请"),
|
|
559
|
+
action("members.roles", "Change roles and members", "管理角色和成员"),
|
|
560
|
+
action("audit.view", "See the record", "查看记录")
|
|
561
|
+
];
|
|
562
|
+
var TaActionUtil;
|
|
563
|
+
(function(TaActionUtil2) {
|
|
564
|
+
const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
|
|
565
|
+
function info(id) {
|
|
566
|
+
return byId.get(id);
|
|
567
|
+
}
|
|
568
|
+
TaActionUtil2.info = info;
|
|
569
|
+
function title(id, language) {
|
|
570
|
+
const found = byId.get(id);
|
|
571
|
+
return found ? language.startsWith("zh") ? found.title["zh-CN"] : found.title.en : id;
|
|
572
|
+
}
|
|
573
|
+
TaActionUtil2.title = title;
|
|
574
|
+
function inside(dir, path) {
|
|
575
|
+
const base = dir.replace(/\/+$/, "");
|
|
576
|
+
return path === base || path.startsWith(`${base}/`) || base === "";
|
|
577
|
+
}
|
|
578
|
+
TaActionUtil2.inside = inside;
|
|
579
|
+
})(TaActionUtil || (TaActionUtil = {}));
|
|
420
580
|
// ../ta-protocol/esm/common/workspace-protocol.js
|
|
421
581
|
var TaWorkspaceServer = Symbol("TaWorkspaceServer");
|
|
422
582
|
var TaTerminalServer = Symbol("TaTerminalServer");
|
|
@@ -651,12 +811,12 @@ var ChannelsUtil;
|
|
|
651
811
|
ChannelsUtil.hash = hash;
|
|
652
812
|
function findAgent(team, ref) {
|
|
653
813
|
const key = ref.trim().replace(/^@/, "").toLowerCase();
|
|
654
|
-
return team.agents.find((agent) => agent.id === ref
|
|
814
|
+
return team.agents.find((agent) => agent.id === ref) ?? team.agents.find((agent) => agent.name.toLowerCase() === key);
|
|
655
815
|
}
|
|
656
816
|
ChannelsUtil.findAgent = findAgent;
|
|
657
817
|
function findChannel(team, ref) {
|
|
658
818
|
const key = ref.trim().replace(/^#/, "").toLowerCase();
|
|
659
|
-
return team.channels.find((channel) => channel.id === ref
|
|
819
|
+
return team.channels.find((channel) => channel.id === ref) ?? team.channels.find((channel) => channel.name.toLowerCase() === key);
|
|
660
820
|
}
|
|
661
821
|
ChannelsUtil.findChannel = findChannel;
|
|
662
822
|
function directory(value) {
|
|
@@ -1005,6 +1165,8 @@ var ChannelsUtil;
|
|
|
1005
1165
|
lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item.text}`));
|
|
1006
1166
|
}
|
|
1007
1167
|
lines.push("", `${authorName(team, message.author, labels)} to you:`);
|
|
1168
|
+
const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels).replace(/[\]\n]/g, " ")}`;
|
|
1169
|
+
lines.push(`[ta:from ${NAME} #${channel.name}${speaker}]`);
|
|
1008
1170
|
return `<context>
|
|
1009
1171
|
${lines.join(`
|
|
1010
1172
|
`)}
|
|
@@ -1275,6 +1437,42 @@ ${brief.trim()}`;
|
|
|
1275
1437
|
HandOff.result = result;
|
|
1276
1438
|
})(HandOff ||= {});
|
|
1277
1439
|
|
|
1440
|
+
// web-src/team-view.ts
|
|
1441
|
+
var TeamViewUtil;
|
|
1442
|
+
((TeamViewUtil) => {
|
|
1443
|
+
function visible(team2, can) {
|
|
1444
|
+
const channels = new Set(team2.channels.filter((channel) => can("channel", channel.id)).map((channel) => channel.id));
|
|
1445
|
+
const agents = new Set(team2.agents.filter((agent) => can("agent", agent.id)).map((agent) => agent.id));
|
|
1446
|
+
for (const channel of team2.channels) {
|
|
1447
|
+
if (channels.has(channel.id)) {
|
|
1448
|
+
for (const member of channel.members) {
|
|
1449
|
+
agents.add(member);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return { agents, channels };
|
|
1454
|
+
}
|
|
1455
|
+
TeamViewUtil.visible = visible;
|
|
1456
|
+
function team(value, visible2) {
|
|
1457
|
+
if (!value) {
|
|
1458
|
+
return value;
|
|
1459
|
+
}
|
|
1460
|
+
return {
|
|
1461
|
+
...value,
|
|
1462
|
+
agents: value.agents.filter((agent) => visible2.agents.has(agent.id)),
|
|
1463
|
+
channels: value.channels.filter((channel) => visible2.channels.has(channel.id))
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
TeamViewUtil.team = team;
|
|
1467
|
+
function byId(value, seen) {
|
|
1468
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1469
|
+
return value;
|
|
1470
|
+
}
|
|
1471
|
+
return Object.fromEntries(Object.entries(value).filter(([id]) => seen.has(id)));
|
|
1472
|
+
}
|
|
1473
|
+
TeamViewUtil.byId = byId;
|
|
1474
|
+
})(TeamViewUtil ||= {});
|
|
1475
|
+
|
|
1278
1476
|
// web-src/team.ts
|
|
1279
1477
|
class TeamService {
|
|
1280
1478
|
host;
|
|
@@ -1300,6 +1498,7 @@ class TeamService {
|
|
|
1300
1498
|
}
|
|
1301
1499
|
async start() {
|
|
1302
1500
|
this.team = await this.get(Keys.TEAM) ?? ChannelsUtil.emptyTeam();
|
|
1501
|
+
this.shareWithMembers();
|
|
1303
1502
|
await this.pinDirectories();
|
|
1304
1503
|
this.queue = await this.get(Keys.QUEUE) ?? { jobs: [], rounds: {} };
|
|
1305
1504
|
await this.set(Keys.WORKING, null);
|
|
@@ -1476,7 +1675,14 @@ class TeamService {
|
|
|
1476
1675
|
async focus(channelId) {
|
|
1477
1676
|
await this.set(Keys.FOCUS, { channelId, at: Date.now() });
|
|
1478
1677
|
}
|
|
1479
|
-
|
|
1678
|
+
poster() {
|
|
1679
|
+
const principal = this.host.team?.current();
|
|
1680
|
+
if (!principal || principal === TA_OWNER) {
|
|
1681
|
+
return {};
|
|
1682
|
+
}
|
|
1683
|
+
return { by: principal, byName: this.host.team?.describe(principal)?.name ?? principal };
|
|
1684
|
+
}
|
|
1685
|
+
async post(channelRef, author, text, poster = {}) {
|
|
1480
1686
|
const channel = ChannelsUtil.findChannel(this.team, channelRef);
|
|
1481
1687
|
if (!channel) {
|
|
1482
1688
|
const known = this.team.channels.map((other) => `#${other.name}`).join(", ") || "none yet";
|
|
@@ -1485,7 +1691,7 @@ class TeamService {
|
|
|
1485
1691
|
if (!text.trim()) {
|
|
1486
1692
|
throw new Error("The message is empty.");
|
|
1487
1693
|
}
|
|
1488
|
-
const message = await this.append(channel.id, { id: ChannelsUtil.newId("message"), author, text: text.trim(), at: Date.now() });
|
|
1694
|
+
const message = await this.append(channel.id, { id: ChannelsUtil.newId("message"), author, text: text.trim(), at: Date.now(), ...poster });
|
|
1489
1695
|
const done = new Promise((resolve) => this.waitingFor(message.id).waiters.push(resolve));
|
|
1490
1696
|
await this.handOn(channel, message, 0, message.id);
|
|
1491
1697
|
await this.settle(message.id);
|
|
@@ -1517,6 +1723,18 @@ class TeamService {
|
|
|
1517
1723
|
await this.focus(channel.id);
|
|
1518
1724
|
return { kind: "channel", id: channel.id, name: channel.name };
|
|
1519
1725
|
}
|
|
1726
|
+
listAgents() {
|
|
1727
|
+
const faces = ChannelsUtil.faces(this.team.agents);
|
|
1728
|
+
return this.team.agents.map((agent) => ({
|
|
1729
|
+
id: agent.id,
|
|
1730
|
+
name: agent.name,
|
|
1731
|
+
role: agent.role,
|
|
1732
|
+
mark: agent.mark,
|
|
1733
|
+
face: faces.get(agent.id) ?? 0,
|
|
1734
|
+
...agent.cwd ? { cwd: agent.cwd } : {},
|
|
1735
|
+
...agent.temporary ? { temporary: true } : {}
|
|
1736
|
+
}));
|
|
1737
|
+
}
|
|
1520
1738
|
async request(request) {
|
|
1521
1739
|
if (this.disposed) {
|
|
1522
1740
|
throw new Error("The team has stopped; the extension may have been turned off.");
|
|
@@ -1541,7 +1759,7 @@ class TeamService {
|
|
|
1541
1759
|
case "deleteAgent":
|
|
1542
1760
|
return this.deleteAgent(request.agent);
|
|
1543
1761
|
case "post":
|
|
1544
|
-
return (await this.post(String(request.channel ?? ""), USER, String(request.text ?? ""))).message;
|
|
1762
|
+
return (await this.post(String(request.channel ?? ""), USER, String(request.text ?? ""), this.poster())).message;
|
|
1545
1763
|
case "setNotice":
|
|
1546
1764
|
return this.setNotice({ channel: request.channel, text: request.text, by: USER });
|
|
1547
1765
|
case "shareAgent":
|
|
@@ -1604,7 +1822,8 @@ class TeamService {
|
|
|
1604
1822
|
const message = messages.find((candidate) => candidate.id === job.messageId);
|
|
1605
1823
|
let reply = messages.find((candidate) => candidate.replyTo === job.messageId && candidate.author === job.agentId);
|
|
1606
1824
|
if (!reply && channel && message) {
|
|
1607
|
-
|
|
1825
|
+
const by = messages.find((candidate) => candidate.id === job.round)?.by;
|
|
1826
|
+
reply = await this.answer(channel, message, job.agentId, by);
|
|
1608
1827
|
}
|
|
1609
1828
|
if (this.disposed) {
|
|
1610
1829
|
return;
|
|
@@ -1659,12 +1878,13 @@ class TeamService {
|
|
|
1659
1878
|
}
|
|
1660
1879
|
return waiting;
|
|
1661
1880
|
}
|
|
1662
|
-
async answer(channel, message, agentId) {
|
|
1881
|
+
async answer(channel, message, agentId, by) {
|
|
1663
1882
|
await this.setWorking(channel.id, agentId, true);
|
|
1664
1883
|
let text;
|
|
1665
1884
|
let failed = false;
|
|
1666
1885
|
try {
|
|
1667
|
-
|
|
1886
|
+
const team = this.host.team;
|
|
1887
|
+
text = await (by && team ? team.actAs(by, () => this.ask(channel, message, agentId)) : this.ask(channel, message, agentId));
|
|
1668
1888
|
} catch (error) {
|
|
1669
1889
|
text = error instanceof Error ? error.message : String(error);
|
|
1670
1890
|
failed = true;
|
|
@@ -1785,8 +2005,48 @@ class TeamService {
|
|
|
1785
2005
|
}
|
|
1786
2006
|
async saveTeam(team) {
|
|
1787
2007
|
this.team = team;
|
|
2008
|
+
this.linkSessions();
|
|
1788
2009
|
await this.set(Keys.TEAM, team);
|
|
1789
2010
|
}
|
|
2011
|
+
shareWithMembers() {
|
|
2012
|
+
const team = this.host.team;
|
|
2013
|
+
if (!team) {
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
const can = (principal, kind, id) => team.can(principal, kind === "agent" ? "agent.view" : "channel.view", { kind, id });
|
|
2017
|
+
team.shareData(NAME, {
|
|
2018
|
+
keys: [Keys.TEAM, Keys.WORKING, Keys.ANSWERED, Keys.FOCUS, Keys.MESSAGES],
|
|
2019
|
+
view: (principal, key, value) => {
|
|
2020
|
+
const visible = TeamViewUtil.visible(this.team, (kind, id) => can(principal, kind, id));
|
|
2021
|
+
if (key === Keys.TEAM) {
|
|
2022
|
+
return TeamViewUtil.team(value, visible);
|
|
2023
|
+
}
|
|
2024
|
+
if (key.startsWith(Keys.MESSAGES)) {
|
|
2025
|
+
return visible.channels.has(key.slice(Keys.MESSAGES.length)) ? value : undefined;
|
|
2026
|
+
}
|
|
2027
|
+
if (key === Keys.FOCUS) {
|
|
2028
|
+
return visible.channels.has(value?.channelId ?? "") ? value : undefined;
|
|
2029
|
+
}
|
|
2030
|
+
return TeamViewUtil.byId(value, key === Keys.WORKING ? visible.channels : visible.agents);
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
this.linkSessions();
|
|
2034
|
+
}
|
|
2035
|
+
linkSessions() {
|
|
2036
|
+
for (const agent of this.team.agents) {
|
|
2037
|
+
if (agent.sessionFile) {
|
|
2038
|
+
this.host.team?.link(agent.sessionFile, { kind: "agent", id: agent.id });
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
listChannels() {
|
|
2043
|
+
return this.team.channels.map((channel) => ({
|
|
2044
|
+
id: channel.id,
|
|
2045
|
+
name: channel.name,
|
|
2046
|
+
...channel.topic ? { topic: channel.topic } : {},
|
|
2047
|
+
members: channel.members
|
|
2048
|
+
}));
|
|
2049
|
+
}
|
|
1790
2050
|
async setWorking(channelId, agentId, on) {
|
|
1791
2051
|
const others = (this.working[channelId] ?? []).filter((id) => id !== agentId);
|
|
1792
2052
|
this.working = { ...this.working, [channelId]: on ? [...others, agentId] : others };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-channels",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "A pi package for Ta: agents with roles of their own and channels where the user, Ta and the agents talk; Ta builds the team for what the user wants",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@celljs/ta-protocol": "4.
|
|
31
|
-
"@celljs/ta-relay": "4.
|
|
32
|
-
"@celljs/ta-web": "4.
|
|
30
|
+
"@celljs/ta-protocol": "4.13.0",
|
|
31
|
+
"@celljs/ta-relay": "4.13.0",
|
|
32
|
+
"@celljs/ta-web": "4.13.0",
|
|
33
33
|
"@types/react": "^19.3.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
@@ -51,6 +51,30 @@
|
|
|
51
51
|
"host": "./host/index.mjs",
|
|
52
52
|
"extensions": [
|
|
53
53
|
"./extension/index.mjs"
|
|
54
|
-
]
|
|
54
|
+
],
|
|
55
|
+
"permissions": {
|
|
56
|
+
"host": {
|
|
57
|
+
"listAgents": "agent.view",
|
|
58
|
+
"listChannels": "channel.view",
|
|
59
|
+
"request:post": "channel.post",
|
|
60
|
+
"request:openAgent": "agent.use",
|
|
61
|
+
"request:setNotice": "channel.manage",
|
|
62
|
+
"request:updateChannel": "channel.manage",
|
|
63
|
+
"request:deleteChannel": "channel.manage",
|
|
64
|
+
"request:changeMember": "channel.manage",
|
|
65
|
+
"request:addMembers": "agent.edit",
|
|
66
|
+
"request:createChannel": "agent.edit",
|
|
67
|
+
"*": "agent.edit"
|
|
68
|
+
},
|
|
69
|
+
"tools": {
|
|
70
|
+
"list_channels": "channel.view",
|
|
71
|
+
"post_to_channel": "channel.post",
|
|
72
|
+
"hand_off": "agent.use",
|
|
73
|
+
"create_agent": "agent.edit",
|
|
74
|
+
"create_channel": "agent.edit",
|
|
75
|
+
"add_to_channel": "agent.edit",
|
|
76
|
+
"update_channel_notice": "channel.manage"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
55
79
|
}
|
|
56
80
|
}
|
package/web/index.js
CHANGED
|
@@ -215,12 +215,12 @@ var ChannelsUtil;
|
|
|
215
215
|
ChannelsUtil.hash = hash;
|
|
216
216
|
function findAgent(team, ref) {
|
|
217
217
|
const key = ref.trim().replace(/^@/, "").toLowerCase();
|
|
218
|
-
return team.agents.find((agent) => agent.id === ref
|
|
218
|
+
return team.agents.find((agent) => agent.id === ref) ?? team.agents.find((agent) => agent.name.toLowerCase() === key);
|
|
219
219
|
}
|
|
220
220
|
ChannelsUtil.findAgent = findAgent;
|
|
221
221
|
function findChannel(team, ref) {
|
|
222
222
|
const key = ref.trim().replace(/^#/, "").toLowerCase();
|
|
223
|
-
return team.channels.find((channel) => channel.id === ref
|
|
223
|
+
return team.channels.find((channel) => channel.id === ref) ?? team.channels.find((channel) => channel.name.toLowerCase() === key);
|
|
224
224
|
}
|
|
225
225
|
ChannelsUtil.findChannel = findChannel;
|
|
226
226
|
function directory(value) {
|
|
@@ -569,6 +569,8 @@ var ChannelsUtil;
|
|
|
569
569
|
lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item.text}`));
|
|
570
570
|
}
|
|
571
571
|
lines.push("", `${authorName(team, message.author, labels)} to you:`);
|
|
572
|
+
const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels).replace(/[\]\n]/g, " ")}`;
|
|
573
|
+
lines.push(`[ta:from ${NAME} #${channel.name}${speaker}]`);
|
|
572
574
|
return `<context>
|
|
573
575
|
${lines.join(`
|
|
574
576
|
`)}
|
|
@@ -1154,6 +1156,7 @@ var EN = {
|
|
|
1154
1156
|
back: "Back",
|
|
1155
1157
|
send: "Send",
|
|
1156
1158
|
you: "You",
|
|
1159
|
+
owner: "Owner",
|
|
1157
1160
|
ta: "Ta",
|
|
1158
1161
|
lead: "Lead",
|
|
1159
1162
|
empty: "No channels yet",
|
|
@@ -1338,6 +1341,7 @@ var ZH = {
|
|
|
1338
1341
|
back: "返回",
|
|
1339
1342
|
send: "发送",
|
|
1340
1343
|
you: "你",
|
|
1344
|
+
owner: "所有者",
|
|
1341
1345
|
ta: "Ta",
|
|
1342
1346
|
lead: "负责人",
|
|
1343
1347
|
empty: "还没有频道",
|
|
@@ -1644,6 +1648,20 @@ function useServerCwd(pi) {
|
|
|
1644
1648
|
}
|
|
1645
1649
|
var SidebarUtil;
|
|
1646
1650
|
((SidebarUtil) => {
|
|
1651
|
+
function homeSections(items) {
|
|
1652
|
+
const sections = new Map;
|
|
1653
|
+
for (const item of items) {
|
|
1654
|
+
if (!item.section) {
|
|
1655
|
+
continue;
|
|
1656
|
+
}
|
|
1657
|
+
const id = `home:${item.extension ?? ""}:${item.section}`;
|
|
1658
|
+
const section = sections.get(id) ?? { id, title: item.section, items: [] };
|
|
1659
|
+
section.items.push(item);
|
|
1660
|
+
sections.set(id, section);
|
|
1661
|
+
}
|
|
1662
|
+
return [...sections.values()];
|
|
1663
|
+
}
|
|
1664
|
+
SidebarUtil.homeSections = homeSections;
|
|
1647
1665
|
function needsLook(task, seen) {
|
|
1648
1666
|
if (task.status === "waiting") {
|
|
1649
1667
|
return true;
|
|
@@ -2975,6 +2993,87 @@ function MemberPicker({ context, team, channel, faces }) {
|
|
|
2975
2993
|
}))));
|
|
2976
2994
|
}
|
|
2977
2995
|
|
|
2996
|
+
// ../ta-protocol/esm/common/team-protocol.js
|
|
2997
|
+
var TA_OWNER = "owner";
|
|
2998
|
+
var TA_UNDECLARED = "extensions.install";
|
|
2999
|
+
var TaPermissionUtil;
|
|
3000
|
+
(function(TaPermissionUtil2) {
|
|
3001
|
+
function read(pi) {
|
|
3002
|
+
const given = pi === null || pi === undefined ? undefined : pi.permissions;
|
|
3003
|
+
const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
|
|
3004
|
+
const host2 = map(given === null || given === undefined ? undefined : given.host);
|
|
3005
|
+
const tools = map(given === null || given === undefined ? undefined : given.tools);
|
|
3006
|
+
return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
|
|
3007
|
+
}
|
|
3008
|
+
TaPermissionUtil2.read = read;
|
|
3009
|
+
function host(manifest, method, kind) {
|
|
3010
|
+
var _a, _b, _c, _d;
|
|
3011
|
+
const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
|
|
3012
|
+
const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
|
|
3013
|
+
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;
|
|
3014
|
+
}
|
|
3015
|
+
TaPermissionUtil2.host = host;
|
|
3016
|
+
})(TaPermissionUtil || (TaPermissionUtil = {}));
|
|
3017
|
+
var action = (id, en, zh, more = {}) => ({
|
|
3018
|
+
id,
|
|
3019
|
+
area: id.split(".")[0],
|
|
3020
|
+
title: { en, "zh-CN": zh },
|
|
3021
|
+
...more
|
|
3022
|
+
});
|
|
3023
|
+
var TA_ACTIONS = [
|
|
3024
|
+
action("chat.view", "See conversations", "查看对话"),
|
|
3025
|
+
action("chat.send", "Send in conversations", "在对话里发消息"),
|
|
3026
|
+
action("chat.create", "Start conversations", "新建对话"),
|
|
3027
|
+
action("chat.stop", "Stop a reply", "停止回复"),
|
|
3028
|
+
action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话"),
|
|
3029
|
+
action("chat.share", "Share by a link", "生成分享链接"),
|
|
3030
|
+
action("agent.view", "See agents", "查看智能体"),
|
|
3031
|
+
action("agent.use", "Talk with agents", "和智能体对话"),
|
|
3032
|
+
action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体"),
|
|
3033
|
+
action("channel.view", "See channels", "查看频道"),
|
|
3034
|
+
action("channel.post", "Post in channels", "在频道里发言"),
|
|
3035
|
+
action("channel.manage", "Create and change channels", "新建、管理频道"),
|
|
3036
|
+
action("task.view", "See tasks", "查看任务"),
|
|
3037
|
+
action("task.create", "Hand out tasks", "派任务"),
|
|
3038
|
+
action("task.manage", "Take over and stop tasks", "接管、停止任务"),
|
|
3039
|
+
action("files.read", "Read files", "读文件", { scoped: true }),
|
|
3040
|
+
action("files.write", "Change files", "改文件", { scoped: true }),
|
|
3041
|
+
action("commands.run", "Let Ta run commands", "让 Ta 运行命令", { scoped: true, risky: true }),
|
|
3042
|
+
action("commands.terminal", "Open terminals", "打开终端", { scoped: true, risky: true }),
|
|
3043
|
+
action("hosts.use", "Use remote hosts", "使用远程主机", { risky: true }),
|
|
3044
|
+
action("models.use", "Use the models", "使用模型"),
|
|
3045
|
+
action("models.manage", "Sign in to models", "登录和更换模型账号"),
|
|
3046
|
+
action("cron.view", "See scheduled tasks", "查看定时任务"),
|
|
3047
|
+
action("cron.manage", "Change scheduled tasks", "管理定时任务"),
|
|
3048
|
+
action("extensions.use", "Use extensions", "使用扩展"),
|
|
3049
|
+
action("extensions.install", "Install and turn off extensions", "安装、停用扩展"),
|
|
3050
|
+
action("settings.view", "See settings", "查看设置"),
|
|
3051
|
+
action("settings.manage", "Change settings", "修改设置"),
|
|
3052
|
+
action("members.view", "See members", "查看成员"),
|
|
3053
|
+
action("members.invite", "Invite people", "邀请别人"),
|
|
3054
|
+
action("members.approve", "Answer requests", "处理申请"),
|
|
3055
|
+
action("members.roles", "Change roles and members", "管理角色和成员"),
|
|
3056
|
+
action("audit.view", "See the record", "查看记录")
|
|
3057
|
+
];
|
|
3058
|
+
var TaActionUtil;
|
|
3059
|
+
(function(TaActionUtil2) {
|
|
3060
|
+
const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
|
|
3061
|
+
function info(id) {
|
|
3062
|
+
return byId.get(id);
|
|
3063
|
+
}
|
|
3064
|
+
TaActionUtil2.info = info;
|
|
3065
|
+
function title(id, language) {
|
|
3066
|
+
const found = byId.get(id);
|
|
3067
|
+
return found ? language.startsWith("zh") ? found.title["zh-CN"] : found.title.en : id;
|
|
3068
|
+
}
|
|
3069
|
+
TaActionUtil2.title = title;
|
|
3070
|
+
function inside(dir, path) {
|
|
3071
|
+
const base = dir.replace(/\/+$/, "");
|
|
3072
|
+
return path === base || path.startsWith(`${base}/`) || base === "";
|
|
3073
|
+
}
|
|
3074
|
+
TaActionUtil2.inside = inside;
|
|
3075
|
+
})(TaActionUtil || (TaActionUtil = {}));
|
|
3076
|
+
|
|
2978
3077
|
// web-src/notice.tsx
|
|
2979
3078
|
var NoticeView;
|
|
2980
3079
|
((NoticeView) => {
|
|
@@ -3103,7 +3202,7 @@ var RoomUtil;
|
|
|
3103
3202
|
return messages.map((message, index) => {
|
|
3104
3203
|
const before = messages[index - 1];
|
|
3105
3204
|
const separator = !before || message.at - before.at > PAUSE_MS;
|
|
3106
|
-
const first = separator || before.author !== message.author || before.author === SYSTEM || !!before.notice || message.at - before.at > RUN_MS;
|
|
3205
|
+
const first = separator || before.author !== message.author || before.by !== message.by || before.author === SYSTEM || !!before.notice || message.at - before.at > RUN_MS;
|
|
3107
3206
|
return { message, first, separator };
|
|
3108
3207
|
});
|
|
3109
3208
|
}
|
|
@@ -3187,8 +3286,22 @@ function ChannelSceneHead({ context, channelId }) {
|
|
|
3187
3286
|
size: 13
|
|
3188
3287
|
}), w.openInMain));
|
|
3189
3288
|
}
|
|
3289
|
+
var mePromise;
|
|
3290
|
+
function useMe(pi) {
|
|
3291
|
+
const [me, setMe] = React.useState(TA_OWNER);
|
|
3292
|
+
React.useEffect(() => {
|
|
3293
|
+
mePromise ??= pi.server.getServerInfo().then((info) => info.member?.id ?? TA_OWNER, () => TA_OWNER);
|
|
3294
|
+
let live = true;
|
|
3295
|
+
mePromise.then((id) => live && setMe(id));
|
|
3296
|
+
return () => {
|
|
3297
|
+
live = false;
|
|
3298
|
+
};
|
|
3299
|
+
}, [pi]);
|
|
3300
|
+
return me;
|
|
3301
|
+
}
|
|
3190
3302
|
function ChannelRoom({ context, channelId: fixed }) {
|
|
3191
3303
|
const { pi, service, ui } = context;
|
|
3304
|
+
const me = useMe(pi);
|
|
3192
3305
|
const state = useChannels(service);
|
|
3193
3306
|
const shown = useUi(ui).channelId;
|
|
3194
3307
|
const channelId = fixed ?? shown;
|
|
@@ -3264,7 +3377,24 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
3264
3377
|
className: "tac-notice tac-notice-line",
|
|
3265
3378
|
disabled: !channel.notice,
|
|
3266
3379
|
onClick: () => setNotice({ open: true, editing: false })
|
|
3267
|
-
}, ChannelWords.format(message.notice === "cleared" ? w.noticeCleared : w.noticeUpdated, { name: name(message.author) })) : message.author === USER ? /* @__PURE__ */ React.createElement("div", {
|
|
3380
|
+
}, ChannelWords.format(message.notice === "cleared" ? w.noticeCleared : w.noticeUpdated, { name: name(message.author) })) : message.author === USER && (message.by ?? TA_OWNER) !== me ? /* @__PURE__ */ React.createElement("div", {
|
|
3381
|
+
className: `tac-msg${first ? " tac-first" : ""}`
|
|
3382
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
3383
|
+
className: "tac-msg-face"
|
|
3384
|
+
}, first && pi.ui.Face && /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
3385
|
+
seed: message.by ?? TA_OWNER,
|
|
3386
|
+
size: 28
|
|
3387
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
3388
|
+
className: "tac-msg-col"
|
|
3389
|
+
}, first && /* @__PURE__ */ React.createElement("div", {
|
|
3390
|
+
className: "tac-msg-name"
|
|
3391
|
+
}, message.byName ?? w.owner), /* @__PURE__ */ React.createElement("div", {
|
|
3392
|
+
className: "tac-msg-bubble",
|
|
3393
|
+
title: time(message.at)
|
|
3394
|
+
}, /* @__PURE__ */ React.createElement(Mentions, {
|
|
3395
|
+
text: message.text,
|
|
3396
|
+
agents: state.team.agents
|
|
3397
|
+
})))) : message.author === USER ? /* @__PURE__ */ React.createElement("div", {
|
|
3268
3398
|
className: "ta-message ta-user tac-mine"
|
|
3269
3399
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
3270
3400
|
className: "ta-bubble"
|
|
@@ -3499,8 +3629,8 @@ function AgentMenu({ context, agent, cwd, working }) {
|
|
|
3499
3629
|
const [dialog, setDialog] = React.useState();
|
|
3500
3630
|
const icon = (name) => ChannelViews.maybeIcon(pi, name, null, 15);
|
|
3501
3631
|
const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
|
|
3502
|
-
const act = (
|
|
3503
|
-
Promise.resolve().then(
|
|
3632
|
+
const act = (action2) => () => {
|
|
3633
|
+
Promise.resolve().then(action2).catch(fail);
|
|
3504
3634
|
};
|
|
3505
3635
|
const openSession = async () => {
|
|
3506
3636
|
if (!agent.sessionFile) {
|
|
@@ -3599,14 +3729,14 @@ function AgentMenu({ context, agent, cwd, working }) {
|
|
|
3599
3729
|
}
|
|
3600
3730
|
}));
|
|
3601
3731
|
}
|
|
3602
|
-
function useSave(
|
|
3732
|
+
function useSave(action2, onClose) {
|
|
3603
3733
|
const [busy, setBusy] = React.useState(false);
|
|
3604
3734
|
const [error, setError] = React.useState();
|
|
3605
3735
|
const submit = (event) => {
|
|
3606
3736
|
event.preventDefault();
|
|
3607
3737
|
setBusy(true);
|
|
3608
3738
|
setError(undefined);
|
|
3609
|
-
|
|
3739
|
+
action2().then(onClose, (failure) => {
|
|
3610
3740
|
setBusy(false);
|
|
3611
3741
|
setError(ChannelViews.message(failure));
|
|
3612
3742
|
});
|
|
@@ -3862,8 +3992,8 @@ function taskMenu(context, channel, working) {
|
|
|
3862
3992
|
const { pi, service } = context;
|
|
3863
3993
|
const w = ChannelViews.words(pi);
|
|
3864
3994
|
const icon = (name) => ChannelViews.icon(pi, name);
|
|
3865
|
-
const act = (
|
|
3866
|
-
Promise.resolve().then(
|
|
3995
|
+
const act = (action2) => () => {
|
|
3996
|
+
Promise.resolve().then(action2).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"));
|
|
3867
3997
|
};
|
|
3868
3998
|
const temporary = membersOf(service.state.team, channel).filter((agent) => agent.temporary);
|
|
3869
3999
|
return [
|
|
@@ -3950,8 +4080,8 @@ function ChannelMenu({ context, channel, working }) {
|
|
|
3950
4080
|
const { fresh } = useUi(ui);
|
|
3951
4081
|
const w = ChannelViews.words(pi);
|
|
3952
4082
|
const icon = (name) => ChannelViews.maybeIcon(pi, name, null, 15);
|
|
3953
|
-
const act = (
|
|
3954
|
-
Promise.resolve().then(
|
|
4083
|
+
const act = (action2) => () => {
|
|
4084
|
+
Promise.resolve().then(action2).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"));
|
|
3955
4085
|
};
|
|
3956
4086
|
const unread = fresh.includes(channel.id);
|
|
3957
4087
|
const pin = act(() => service.updateChannel(channel.id, { pinned: !channel.pinned }));
|
|
@@ -4216,7 +4346,7 @@ function Section({
|
|
|
4216
4346
|
count,
|
|
4217
4347
|
folded,
|
|
4218
4348
|
onFold,
|
|
4219
|
-
action,
|
|
4349
|
+
action: action2,
|
|
4220
4350
|
alert,
|
|
4221
4351
|
children
|
|
4222
4352
|
}) {
|
|
@@ -4240,7 +4370,7 @@ function Section({
|
|
|
4240
4370
|
}), /* @__PURE__ */ React.createElement("span", {
|
|
4241
4371
|
className: "tac-section-chevron",
|
|
4242
4372
|
"aria-hidden": "true"
|
|
4243
|
-
})), !closed &&
|
|
4373
|
+
})), !closed && action2), !closed && /* @__PURE__ */ React.createElement("div", {
|
|
4244
4374
|
className: "tac-section-body"
|
|
4245
4375
|
}, children));
|
|
4246
4376
|
}
|
|
@@ -4324,8 +4454,14 @@ function useUnseen(storage, latest, busy, shown, answered, known) {
|
|
|
4324
4454
|
}
|
|
4325
4455
|
function useSessionLines(context, changed) {
|
|
4326
4456
|
const { pi } = context;
|
|
4457
|
+
const listed = pi.ui.useSavedSessions?.();
|
|
4458
|
+
const follows = !!listed;
|
|
4327
4459
|
const [lines, setLines] = React.useState(context.sessionLines);
|
|
4460
|
+
const again = follows ? "" : changed;
|
|
4328
4461
|
React.useEffect(() => {
|
|
4462
|
+
if (follows && context.sessionLines) {
|
|
4463
|
+
return;
|
|
4464
|
+
}
|
|
4329
4465
|
let live = true;
|
|
4330
4466
|
const read = () => Promise.all([pi.server.listSessions().catch(() => []), pi.server.listSavedSessions().catch(() => [])]).then(([open, saved]) => {
|
|
4331
4467
|
context.sessionLines = [...saved, ...open];
|
|
@@ -4334,14 +4470,19 @@ function useSessionLines(context, changed) {
|
|
|
4334
4470
|
}
|
|
4335
4471
|
});
|
|
4336
4472
|
read();
|
|
4337
|
-
|
|
4338
|
-
|
|
4473
|
+
if (follows) {
|
|
4474
|
+
return () => {
|
|
4475
|
+
live = false;
|
|
4476
|
+
};
|
|
4477
|
+
}
|
|
4478
|
+
const onShow = () => document.visibilityState === "visible" && void read();
|
|
4479
|
+
document.addEventListener("visibilitychange", onShow);
|
|
4339
4480
|
return () => {
|
|
4340
4481
|
live = false;
|
|
4341
|
-
document.removeEventListener("visibilitychange",
|
|
4482
|
+
document.removeEventListener("visibilitychange", onShow);
|
|
4342
4483
|
};
|
|
4343
|
-
}, [context, pi,
|
|
4344
|
-
return lines;
|
|
4484
|
+
}, [context, pi, follows, again]);
|
|
4485
|
+
return React.useMemo(() => lines && listed ? [...lines, ...listed] : lines, [lines, listed]);
|
|
4345
4486
|
}
|
|
4346
4487
|
function useTaskSelection(pi, tasks) {
|
|
4347
4488
|
const [chosen, setChosen] = React.useState();
|
|
@@ -4428,13 +4569,16 @@ var NO_HOME_ITEMS = [];
|
|
|
4428
4569
|
function HomeRow({ pi, item }) {
|
|
4429
4570
|
const [opening, setOpening] = React.useState(false);
|
|
4430
4571
|
const Glyph = item.icon;
|
|
4572
|
+
const Own = item.face;
|
|
4431
4573
|
const open = () => {
|
|
4432
4574
|
setOpening(true);
|
|
4433
4575
|
Promise.resolve().then(() => item.open()).catch((error) => pi.ui.notify(ChannelViews.message(error), "error")).finally(() => setOpening(false));
|
|
4434
4576
|
};
|
|
4435
4577
|
return /* @__PURE__ */ React.createElement(Row, {
|
|
4436
4578
|
pi,
|
|
4437
|
-
avatar: /* @__PURE__ */ React.createElement(
|
|
4579
|
+
avatar: Own && !opening ? /* @__PURE__ */ React.createElement(Own, {
|
|
4580
|
+
size: 40
|
|
4581
|
+
}) : /* @__PURE__ */ React.createElement("span", {
|
|
4438
4582
|
className: "tac-home-icon",
|
|
4439
4583
|
style: { background: `var(--ta-tint-${item.tone})`, color: `var(--ta-tint-ink-${item.tone})` }
|
|
4440
4584
|
}, opening ? /* @__PURE__ */ React.createElement("span", {
|
|
@@ -4465,6 +4609,8 @@ function AgentsSidebar({ context }) {
|
|
|
4465
4609
|
const agentPage = pi.ui.useView(AGENT_PAGE);
|
|
4466
4610
|
const tasks = pi.ui.useTasks();
|
|
4467
4611
|
const homeItems = pi.ui.useHomeItems?.() ?? NO_HOME_ITEMS;
|
|
4612
|
+
const homeShown = homeItems.filter((item) => SidebarUtil.matches(query, item.title, item.detail));
|
|
4613
|
+
const homeSections = SidebarUtil.homeSections(homeShown);
|
|
4468
4614
|
const [folded, fold] = useFolded();
|
|
4469
4615
|
const [byDirectory, setByDirectory] = useStored(pi.storage, BY_DIRECTORY_KEY, false);
|
|
4470
4616
|
const language = pi.ui.language;
|
|
@@ -4535,7 +4681,7 @@ function AgentsSidebar({ context }) {
|
|
|
4535
4681
|
return opening === agent.id || !pageShown && !!sessionId && sessionId === shownSession;
|
|
4536
4682
|
};
|
|
4537
4683
|
const ended = allEnded || selection.selecting ? groups.ended : groups.ended.slice(0, ENDED_SHOWN);
|
|
4538
|
-
const nothing = query && shownTasks.length === 0 && channels.length === 0 && agents.length === 0;
|
|
4684
|
+
const nothing = query && shownTasks.length === 0 && channels.length === 0 && agents.length === 0 && homeShown.length === 0;
|
|
4539
4685
|
const running = tasks.filter((task) => task.status === "running").length;
|
|
4540
4686
|
const waiting = tasks.filter((task) => task.status === "waiting").length;
|
|
4541
4687
|
const fresh = tasks.filter((task) => task.status !== "waiting" && seen.needsLook(task)).length;
|
|
@@ -4586,7 +4732,7 @@ function AgentsSidebar({ context }) {
|
|
|
4586
4732
|
items: () => (double.menu?.() ?? []).map((section) => section.map(({ icon: Icon, ...item }) => ({ ...item, icon: Icon && /* @__PURE__ */ React.createElement(Icon, {
|
|
4587
4733
|
size: 15
|
|
4588
4734
|
}) })))
|
|
4589
|
-
})),
|
|
4735
|
+
})), homeShown.filter((item) => !item.section).map((item) => /* @__PURE__ */ React.createElement(HomeRow, {
|
|
4590
4736
|
key: item.key,
|
|
4591
4737
|
pi,
|
|
4592
4738
|
item
|
|
@@ -4738,7 +4884,19 @@ function AgentsSidebar({ context }) {
|
|
|
4738
4884
|
}),
|
|
4739
4885
|
swipe: swipePinDelete(pi, !!channel.pinned, (pinned) => context.service.updateChannel(channel.id, { pinned }), () => deleteChannel(context, channel))
|
|
4740
4886
|
});
|
|
4741
|
-
}))
|
|
4887
|
+
})), homeSections.map((section) => /* @__PURE__ */ React.createElement(Section, {
|
|
4888
|
+
key: section.id,
|
|
4889
|
+
id: section.id,
|
|
4890
|
+
title: section.title,
|
|
4891
|
+
count: section.items.length,
|
|
4892
|
+
folded,
|
|
4893
|
+
onFold: fold,
|
|
4894
|
+
alert: section.items.some((item) => item.unseen)
|
|
4895
|
+
}, section.items.map((item) => /* @__PURE__ */ React.createElement(HomeRow, {
|
|
4896
|
+
key: item.key,
|
|
4897
|
+
pi,
|
|
4898
|
+
item
|
|
4899
|
+
}))))), selection.selecting && SelectBar && /* @__PURE__ */ React.createElement(SelectBar, {
|
|
4742
4900
|
count: selection.selected.length,
|
|
4743
4901
|
total: selection.removable.length,
|
|
4744
4902
|
onSelectAll: selection.selectAll,
|
|
@@ -4838,9 +4996,7 @@ button.tac-notice-line { border: 0; font: inherit; font-size: calc(12px * var(--
|
|
|
4838
4996
|
button.tac-notice-line:hover:not(:disabled) { color: var(--ta-text); }
|
|
4839
4997
|
button.tac-notice-line:disabled { cursor: default; }
|
|
4840
4998
|
@keyframes tac-notice-in { from { opacity: 0; transform: translateY(-4px); } }
|
|
4841
|
-
|
|
4842
|
-
.tac-notice-bar { padding: 6px 14px 0; }
|
|
4843
|
-
}
|
|
4999
|
+
[data-layout='compact'] .tac-notice-bar { padding: 6px 14px 0; }
|
|
4844
5000
|
|
|
4845
5001
|
/* An agent's card (card.tsx): shared from its menu, opened from its link */
|
|
4846
5002
|
.tac-card { display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
|
|
@@ -4871,11 +5027,12 @@ button.tac-notice-line:disabled { cursor: default; }
|
|
|
4871
5027
|
.tac-live-faces { display: inline-flex; }
|
|
4872
5028
|
.tac-live-faces > * + * { margin-left: -4px; }
|
|
4873
5029
|
.tac-chat-bottom { width: 100%; max-width: calc(var(--ta-col) + 48px); margin: 0 auto; padding: 8px 24px calc(16px + env(safe-area-inset-bottom)); box-sizing: border-box; flex: none; display: flex; flex-direction: column; gap: 8px; }
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
}
|
|
5030
|
+
/* Above the keyboard the home indicator is not there: no room for it, as under the box of a conversation. */
|
|
5031
|
+
:root[data-keyboard] .tac-chat-bottom { padding-bottom: 8px; }
|
|
5032
|
+
:root[data-keyboard-moving] .tac-chat-bottom { transition: padding-bottom 450ms cubic-bezier(0.15, 0.75, 0.2, 1); }
|
|
5033
|
+
[data-layout='compact'] .tac-head-topic, [data-layout='compact'] .tac-head-face:nth-child(n + 4), [data-layout='compact'] .tac-head-more { display: none; }
|
|
5034
|
+
[data-layout='compact'] .tac-chat-col, [data-layout='compact'] .tac-chat-bottom { padding-left: 14px; padding-right: 14px; }
|
|
5035
|
+
[data-layout='compact'] .tac-msg-col { max-width: calc(100% - 38px); }
|
|
4879
5036
|
.tac-new-head { position: relative; display: flex; align-items: center; justify-content: center; flex: 1; min-width: 0; height: 100%; }
|
|
4880
5037
|
.tac-new-title { position: relative; display: flex; justify-content: center; min-width: 0; }
|
|
4881
5038
|
.tac-new-head > .tac-button { position: absolute; right: 0; }
|
|
@@ -4919,11 +5076,9 @@ div.tac-dialog-label { flex-direction: row; justify-content: space-between; marg
|
|
|
4919
5076
|
.tac-dialog-note { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
4920
5077
|
.tac-dialog-actions { display: flex; justify-content: flex-end; margin-top: 4px; }
|
|
4921
5078
|
.tac-dialog-actions .tac-button { height: 36px; padding: 0 18px; font-size: calc(13.5px * var(--ta-font-scale)); }
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
.tac-identity { position: fixed; top: calc(60px + env(safe-area-inset-top) + var(--ta-titlebar, 0px)); left: 12px; right: 12px; width: auto; max-width: none; transform: none; animation: none; }
|
|
4926
|
-
}
|
|
5079
|
+
[data-layout='compact'] .tac-new-head > .tac-button { position: static; margin-left: auto; }
|
|
5080
|
+
[data-layout='compact'] .tac-new-head { justify-content: flex-start; }
|
|
5081
|
+
[data-layout='compact'] .tac-identity { position: fixed; top: calc(60px + env(safe-area-inset-top) + var(--ta-titlebar, 0px)); left: 12px; right: 12px; width: auto; max-width: none; transform: none; animation: none; }
|
|
4927
5082
|
.tac-empty { padding: 8px 18px; }
|
|
4928
5083
|
.tac-item { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; margin: 1px 0; padding: 9px 10px; border: 0; border-radius: 12px; background: none; color: var(--ta-text); font: inherit; text-align: left; cursor: pointer; transition: background 120ms; }
|
|
4929
5084
|
.tac-item:hover { background: var(--ta-hover); }
|