@celljs/ta-channels 4.8.0 → 4.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/web-src/faces.tsx DELETED
@@ -1,247 +0,0 @@
1
- import type { Agent } from './channels-util';
2
- // biome-ignore lint/style/useImportType: the JSX below compiles to React.createElement (jsxFactory)
3
- import { React } from './react';
4
-
5
- /**
6
- * The faces of agents: a small coloured shape with two eyes, cheeks and a mouth, one of {@link FACES}
7
- * (channels-util), so that agents are told apart at a glance. ta itself keeps the dinosaur of the logo.
8
- * Drawn on a 40 × 40 grid; the styles (style.ts) make them blink, and look about while they answer.
9
- */
10
- interface Look {
11
- color: string;
12
- /** Eyes and mouth. */
13
- eye: string;
14
- cheek: string;
15
- /** A second colour of the shape: ears, a stem, an antenna. */
16
- accent?: string;
17
- /** The height of the eyes and how far apart they are. */
18
- eyeY: number;
19
- gap: number;
20
- mouth?: string;
21
- /** Brows pressed in, a grin. */
22
- brows?: boolean;
23
- }
24
-
25
- const BLUE = '#4285F4';
26
- const RED = '#EA4335';
27
- const YELLOW = '#FBBC05';
28
- const GREEN = '#34A853';
29
- const MINT = '#5CC27F';
30
- const ORANGE = '#EE7B3B';
31
- const VIOLET = '#8C5CF0';
32
- const CREAM = '#F1DFC0';
33
- const TEAL = '#26B0A9';
34
- const PINK = '#F27BA6';
35
- const LILAC = '#B49CF5';
36
- const SKY = '#45B5E8';
37
- const INDIGO = '#5C6BC0';
38
- const MIST = '#DCE3F0';
39
- const INK = '#202124';
40
- const WHITE = '#FFFFFF';
41
- const CHEEK = 'rgba(255, 160, 185, 0.55)';
42
- /** The edge of a light face. */
43
- const EDGE = 'rgba(0, 0, 0, 0.14)';
44
- const CHEEK_DEEP = 'rgba(120, 10, 30, 0.35)';
45
- const CHEEK_WARM = 'rgba(234, 67, 53, 0.4)';
46
-
47
- /** By face: the order is that of the shapes drawn in {@link shape}. */
48
- const LOOKS: readonly Look[] = [
49
- { color: MINT, eye: '#1D3B27', cheek: CHEEK, eyeY: 21, gap: 8 }, // round
50
- { color: BLUE, eye: WHITE, cheek: CHEEK, eyeY: 23, gap: 8 }, // cat
51
- { color: RED, eye: WHITE, cheek: CHEEK_DEEP, eyeY: 22, gap: 8 }, // pentagon
52
- { color: CREAM, eye: '#4A3420', cheek: 'rgba(240, 120, 120, 0.5)', accent: '#DDBF8E', eyeY: 22, gap: 7.6 }, // bear
53
- { color: GREEN, eye: WHITE, cheek: CHEEK, eyeY: 19, gap: 7.2 }, // capsule
54
- { color: INDIGO, eye: WHITE, cheek: CHEEK, eyeY: 20, gap: 7.4 }, // diamond
55
- { color: YELLOW, eye: INK, cheek: CHEEK_WARM, accent: '#F29900', eyeY: 24, gap: 8.4 }, // bun
56
- { color: VIOLET, eye: '#22134A', cheek: CHEEK, eyeY: 20, gap: 8 }, // hexagon
57
- { color: MIST, eye: '#2B3245', cheek: CHEEK, eyeY: 19, gap: 7.6 }, // ghost
58
- { color: SKY, eye: WHITE, cheek: CHEEK, eyeY: 21, gap: 6.4 }, // star
59
- { color: ORANGE, eye: '#3D1C08', cheek: CHEEK, accent: GREEN, eyeY: 22, gap: 8.6, brows: true }, // pumpkin
60
- { color: WHITE, eye: WHITE, cheek: CHEEK, accent: INK, mouth: INK, eyeY: 22, gap: 10 }, // panda
61
- { color: TEAL, eye: WHITE, cheek: CHEEK, accent: '#1B8A84', eyeY: 22.5, gap: 8.4 }, // screen
62
- { color: PINK, eye: '#4A1428', cheek: 'rgba(160, 20, 70, 0.3)', eyeY: 24, gap: 7.4 }, // drop
63
- { color: LILAC, eye: '#2A1A5E', cheek: CHEEK, eyeY: 25, gap: 8 }, // rabbit
64
- { color: YELLOW, eye: INK, cheek: CHEEK_WARM, eyeY: 25, gap: 7.4 }, // triangle
65
- ];
66
-
67
- /** The corners of a polygon of `count` sides around (cx, cy), the first straight up; `inner` makes it a star. */
68
- function corners(count: number, radius: number, cx: number, cy: number, inner?: number): string {
69
- const points: string[] = [];
70
- const steps = inner ? count * 2 : count;
71
- for (let index = 0; index < steps; index++) {
72
- const r = inner && index % 2 === 1 ? inner : radius;
73
- const angle = -Math.PI / 2 + (index * 2 * Math.PI) / steps;
74
- points.push(`${(cx + r * Math.cos(angle)).toFixed(2)},${(cy + r * Math.sin(angle)).toFixed(2)}`);
75
- }
76
- return points.join(' ');
77
- }
78
-
79
- const PENTAGON = corners(5, 13.5, 20, 21.5);
80
- const HEXAGON = corners(6, 14, 20, 20);
81
- const STAR = corners(5, 15.5, 20, 21.5, 8.6);
82
-
83
- /** A polygon with round corners: filled and stroked in the same colour. */
84
- function Rounded({ points, color, width = 5 }: { points: string; color: string; width?: number }) {
85
- return <polygon points={points} fill={color} stroke={color} strokeWidth={width} strokeLinejoin="round" />;
86
- }
87
-
88
- function shape(face: number, look: Look): React.ReactNode {
89
- const { color, accent = color } = look;
90
- switch (face) {
91
- case 1:
92
- return (
93
- <g>
94
- <Rounded points="7.5,6.5 17,12 8.5,18" color={color} width={4} />
95
- <Rounded points="32.5,6.5 23,12 31.5,18" color={color} width={4} />
96
- <ellipse cx="20" cy="23" rx="14.5" ry="12.5" fill={color} />
97
- </g>
98
- );
99
- case 2:
100
- return <Rounded points={PENTAGON} color={color} />;
101
- case 3:
102
- return (
103
- <g>
104
- <circle cx="9.5" cy="10.5" r="5.5" fill={color} />
105
- <circle cx="30.5" cy="10.5" r="5.5" fill={color} />
106
- <circle cx="9.5" cy="10.5" r="2.6" fill={accent} />
107
- <circle cx="30.5" cy="10.5" r="2.6" fill={accent} />
108
- <ellipse cx="20" cy="22.5" rx="14.5" ry="13" fill={color} />
109
- </g>
110
- );
111
- case 4:
112
- return <rect x="8.5" y="4" width="23" height="32" rx="11.5" fill={color} />;
113
- case 5:
114
- return <Rounded points="20,5.5 34.5,20 20,34.5 5.5,20" color={color} width={5.5} />;
115
- case 6:
116
- return (
117
- <g>
118
- <ellipse cx="20" cy="11" rx="3.2" ry="3.6" fill={accent} />
119
- <path d="M20 12.5c9.2 0 15.5 5.6 15.5 12.4 0 6.4-6.9 10.1-15.5 10.1S4.5 31.3 4.5 24.9C4.5 18.1 10.8 12.5 20 12.5Z" fill={color} />
120
- </g>
121
- );
122
- case 7:
123
- return <Rounded points={HEXAGON} color={color} />;
124
- case 8:
125
- return <path d="M8 19a12 12 0 0 1 24 0v14l-4-3-4 3-4-3-4 3-4-3-4 3Z" fill={color} stroke={EDGE} strokeWidth="0.8" strokeLinejoin="round" />;
126
- case 9:
127
- return <Rounded points={STAR} color={color} width={4.5} />;
128
- case 10:
129
- return (
130
- <g>
131
- <rect x="18.6" y="4.5" width="2.8" height="7" rx="1.4" fill={accent} />
132
- <ellipse cx="12.5" cy="23" rx="8.5" ry="11" fill={color} />
133
- <ellipse cx="27.5" cy="23" rx="8.5" ry="11" fill={color} />
134
- <ellipse cx="20" cy="22.5" rx="9.5" ry="12" fill={color} />
135
- </g>
136
- );
137
- case 11:
138
- return (
139
- <g>
140
- <circle cx="9.5" cy="10" r="5" fill={accent} />
141
- <circle cx="30.5" cy="10" r="5" fill={accent} />
142
- <ellipse cx="20" cy="22.5" rx="14.5" ry="13" fill={color} stroke={EDGE} strokeWidth="0.8" />
143
- <ellipse cx="14.6" cy="22" rx="3.6" ry="4.4" transform="rotate(20 14.6 22)" fill={accent} />
144
- <ellipse cx="25.4" cy="22" rx="3.6" ry="4.4" transform="rotate(-20 25.4 22)" fill={accent} />
145
- </g>
146
- );
147
- case 12:
148
- return (
149
- <g>
150
- <rect x="19.1" y="6" width="1.8" height="7" fill={accent} />
151
- <circle cx="20" cy="5" r="2.2" fill={accent} />
152
- <rect x="5.5" y="12" width="29" height="22.5" rx="6.5" fill={color} />
153
- </g>
154
- );
155
- case 13:
156
- return <path d="M20 4.5c2 0 13 11.6 13 20.2 0 6.4-5.8 10.8-13 10.8S7 31.1 7 24.7C7 16.1 18 4.5 20 4.5Z" fill={color} />;
157
- case 14:
158
- return (
159
- <g>
160
- <ellipse cx="14" cy="10.5" rx="3.6" ry="8" transform="rotate(-8 14 10.5)" fill={color} />
161
- <ellipse cx="26" cy="10.5" rx="3.6" ry="8" transform="rotate(8 26 10.5)" fill={color} />
162
- <ellipse cx="20" cy="25" rx="14" ry="11" fill={color} />
163
- </g>
164
- );
165
- case 15:
166
- return <Rounded points="20,7 35,33 5,33" color={color} width={6} />;
167
- default:
168
- return <circle cx="20" cy="21" r="14.5" fill={color} />;
169
- }
170
- }
171
-
172
- export interface FaceProps {
173
- face: number;
174
- size: number;
175
- /** Answering: the eyes look about. */
176
- working?: boolean;
177
- }
178
-
179
- /** One face; the eyes, cheeks and mouth are the same on every shape. */
180
- export function Face({ face, size, working }: FaceProps) {
181
- const look = LOOKS[face] ?? LOOKS[0];
182
- const half = look.gap / 2;
183
- const eyeW = 4.1;
184
- const eyeH = 4.9;
185
- const top = look.eyeY - eyeH / 2;
186
- const cheekY = look.eyeY + 3.6;
187
- const cheekX = half + 2.2;
188
- const mouthY = look.eyeY + 3.4;
189
- return (
190
- <span className={`tac-face${working ? ' tac-face-working' : ''}`} style={{ width: size, height: size }} data-face={face} aria-hidden="true">
191
- <svg viewBox="0 0 40 40" width={size} height={size} focusable="false" aria-hidden="true">
192
- <g className="tac-face-body">
193
- {shape(face, look)}
194
- <g className="tac-face-look">
195
- <g fill={look.cheek}>
196
- <ellipse cx={20 - cheekX} cy={cheekY} rx="2.2" ry="1.25" />
197
- <ellipse cx={20 + cheekX} cy={cheekY} rx="2.2" ry="1.25" />
198
- </g>
199
- {look.brows && (
200
- <path
201
- d={`M${20 - half - 3.4} ${top - 2.6}l3.6 1.6M${20 + half + 3.4} ${top - 2.6}l-3.6 1.6`}
202
- stroke={look.eye}
203
- strokeWidth="1.4"
204
- strokeLinecap="round"
205
- fill="none"
206
- />
207
- )}
208
- <g className="tac-face-eyes" fill={look.eye}>
209
- <rect x={20 - half - eyeW / 2} y={top} width={eyeW} height={eyeH} rx={eyeW / 2} />
210
- <rect x={20 + half - eyeW / 2} y={top} width={eyeW} height={eyeH} rx={eyeW / 2} />
211
- </g>
212
- <path
213
- d={`M18.1 ${mouthY}q.95 1.25 1.9 0q.95 1.25 1.9 0`}
214
- fill="none"
215
- stroke={look.mouth ?? look.eye}
216
- strokeWidth="1.1"
217
- strokeLinecap="round"
218
- strokeLinejoin="round"
219
- />
220
- </g>
221
- </g>
222
- </svg>
223
- </span>
224
- );
225
- }
226
-
227
- /** A channel: its lead in front, the next member behind; one member alone is drawn whole. */
228
- export function RoomFace({ members, faces, size, working }: { members: Agent[]; faces: Map<string, number>; size: number; working: string[] }) {
229
- const [lead, next] = members;
230
- if (!lead) {
231
- return <span className="tac-room" style={{ width: size, height: size }} />;
232
- }
233
- if (!next) {
234
- return <Face face={faces.get(lead.id) ?? 0} size={size} working={working.includes(lead.id)} />;
235
- }
236
- const small = Math.round(size * 0.72);
237
- return (
238
- <span className="tac-room" style={{ width: size, height: size }} aria-hidden="true">
239
- <span className="tac-room-back">
240
- <Face face={faces.get(next.id) ?? 0} size={small} working={working.includes(next.id)} />
241
- </span>
242
- <span className="tac-room-front">
243
- <Face face={faces.get(lead.id) ?? 0} size={small} working={working.includes(lead.id)} />
244
- </span>
245
- </span>
246
- );
247
- }
package/web-src/host.ts DELETED
@@ -1,12 +0,0 @@
1
- import type { TaExtensionHost, TaPackageService } from '@celljs/ta-protocol';
2
- import { TeamService } from './team';
3
-
4
- /**
5
- * The server side of the package (`pi.host`): ta serve runs it once, so that agents answer each other
6
- * with no page open. Its pi extension reaches the team for ta's tools; pages reach it through the data.
7
- */
8
- export default async function activate(host: TaExtensionHost): Promise<TaPackageService> {
9
- const team = new TeamService(host);
10
- await team.start();
11
- return team;
12
- }
package/web-src/i18n.ts DELETED
@@ -1,221 +0,0 @@
1
- const EN = {
2
- title: 'Agents',
3
- channels: 'Channels',
4
- agents: 'Agents',
5
- newChannel: 'New channel',
6
- newAgent: 'New agent',
7
- name: 'Name',
8
- role: 'Role',
9
- rolePlaceholder: 'What it does and how, as instructions to it',
10
- topic: 'Topic',
11
- members: 'Members',
12
- addMembers: 'Add members',
13
- add: 'Add',
14
- allMembers: 'Every agent is in this channel already; create another one.',
15
- membersHint: 'The first one you pick leads: it answers what names nobody.',
16
- create: 'Create',
17
- cancel: 'Cancel',
18
- back: 'Back',
19
- send: 'Send',
20
- you: 'You',
21
- ta: 'Ta',
22
- lead: 'Lead',
23
- empty: 'No channels yet. Ask Ta for a team, for example: "Make a channel where a designer and an engineer review this page", or create one here.',
24
- noAgents: 'Create an agent first: a channel is made of agents.',
25
- pick: 'Pick a channel.',
26
- quiet: 'Nothing said yet. Mention a member with @, or the lead answers.',
27
- placeholder: 'Message {channel}; @ names a member',
28
- answering: '{name} is answering',
29
- failed: 'did not answer',
30
- mention: 'Mention {name}',
31
- stopped: 'The agents stopped at the limit of a round; it is your turn.',
32
- search: 'Search',
33
- clear: 'Clear',
34
- new: 'New',
35
- idle: 'Idle',
36
- answeringIn: 'Answering in #{channel}',
37
- answeringNow: '{name} is answering…',
38
- noMatch: 'No agent or channel matches.',
39
- noMessages: 'No messages yet',
40
- leadOf: 'Lead: {name}',
41
- noAgentsYet: 'No agents yet. Ask Ta for a team, or create one with +.',
42
- myDouble: 'My double',
43
- memberCount: '{count} members',
44
- channel: 'Channel',
45
- newAgentName: 'new-agent',
46
- notStarted: 'Not started yet',
47
- editAgent: 'Change the name and the avatar',
48
- avatar: 'Avatar',
49
- newAgentHint: 'Pick a name and an avatar above, then tell it what to do first: your first message makes it.',
50
- agentPlaceholder: 'Message {name}',
51
- channelNamePlaceholder: 'For example: Project Falcon',
52
- addAgents: 'Add agents',
53
- searchAgents: 'Search agents, pick 1 to {max}',
54
- showMembers: 'Members',
55
- canAdd: '{count} agents can join',
56
- findAgent: 'Search agents',
57
- addCount: 'Add {count}',
58
- makeLead: 'Make lead',
59
- leadHint: 'Answers what names nobody',
60
- mute: 'Mute: answers nothing here',
61
- unmute: 'Let it answer again',
62
- muted: 'Muted',
63
- replying: 'Answering…',
64
- reset: 'New session: it forgets what it was told',
65
- resetDone: '{name} starts a new session the next time it answers.',
66
- remove: 'Remove from the channel',
67
- onlyMember: 'A channel keeps at least one member',
68
- open: 'Open its session',
69
- deleteChannel: 'Delete channel',
70
- confirmDelete: 'Delete #{channel} and its messages?',
71
- delete: 'Delete',
72
- noChannel: 'Open a channel to see its members.',
73
- more: 'More',
74
- stop: 'Stop',
75
- stoppedAgent: 'Stopped {name}.',
76
- restart: 'Restart',
77
- restartHint: 'A new session: it forgets what it was told',
78
- rename: 'Rename',
79
- editRole: 'Role',
80
- roleHint: 'What it reads first, before anything else: who it is and how it works. It takes effect from its next session; Restart to use it now.',
81
- save: 'Save',
82
- moveTo: 'Move to…',
83
- moveHint: 'Works in another directory, in a new session there',
84
- copyCwd: 'Copy directory',
85
- copied: 'Copied {path}',
86
- exportChat: 'Export conversation (Markdown)',
87
- nothingToExport: '{name} has said nothing yet.',
88
- joinChannel: 'Add to channel',
89
- noChannelToJoin: 'It is in every channel already.',
90
- joined: '{name} joined #{channel}.',
91
- deleteAgent: 'Delete',
92
- confirmDeleteAgent: 'Delete {name}? It leaves its channels, and channels with no one else go too; its session file stays.',
93
- pin: 'Pin',
94
- unpin: 'Unpin',
95
- pinned: 'Pinned',
96
- markUnread: 'Mark as unread',
97
- markRead: 'Mark as read',
98
- editTopic: 'Topic',
99
- topicPlaceholder: 'What the channel is for',
100
- renameChannel: 'Rename #{channel}',
101
- stopAnswering: 'Stop answering',
102
- stoppedChannel: 'Stopped the members answering in #{channel}.',
103
- noMessagesToExport: '#{channel} has no messages yet.',
104
- } as const;
105
-
106
- export type Words = { readonly [K in keyof typeof EN]: string };
107
-
108
- const ZH: Words = {
109
- title: '智能体',
110
- channels: '频道',
111
- agents: '智能体',
112
- newChannel: '新建频道',
113
- newAgent: '新建智能体',
114
- name: '名字',
115
- role: '职责',
116
- rolePlaceholder: '它做什么、怎么做,写成给它的指示',
117
- topic: '主题',
118
- members: '成员',
119
- addMembers: '添加成员',
120
- add: '添加',
121
- allMembers: '所有智能体都已在这个频道里,可以再新建一个。',
122
- membersHint: '先选的成员是负责人:没人被 @ 的消息由它回答。',
123
- create: '创建',
124
- cancel: '取消',
125
- back: '返回',
126
- send: '发送',
127
- you: '你',
128
- ta: 'Ta',
129
- lead: '负责人',
130
- empty: '还没有频道。可以让 Ta 组个团队,比如“建个频道,让设计师和工程师一起评审这个页面”,也可以在这里自己建。',
131
- noAgents: '先建一个智能体:频道由智能体组成。',
132
- pick: '选一个频道。',
133
- quiet: '还没有消息。用 @ 点名成员,不点名就由负责人回答。',
134
- placeholder: '发到 {channel};@ 点名成员',
135
- answering: '{name} 正在回答',
136
- failed: '没有回答',
137
- mention: '@{name}',
138
- stopped: '已到交接上限,等你继续。',
139
- search: '搜索智能体',
140
- clear: '清除',
141
- new: '新建',
142
- idle: '空闲',
143
- answeringIn: '正在 #{channel} 回答',
144
- answeringNow: '{name} 正在回答…',
145
- noMatch: '没有匹配的智能体或频道。',
146
- noMessages: '还没有消息',
147
- leadOf: '负责人:{name}',
148
- noAgentsYet: '还没有智能体。可以让 Ta 组个团队,也可以点 + 新建。',
149
- myDouble: '我的分身',
150
- memberCount: '{count} 位成员',
151
- channel: '频道',
152
- newAgentName: '新智能体',
153
- notStarted: '还没开工',
154
- editAgent: '修改名字和头像',
155
- avatar: '头像',
156
- newAgentHint: '在上面起个名字、挑个头像,再告诉它先做什么:发出第一条消息就建好了。',
157
- agentPlaceholder: '给 {name} 发消息',
158
- channelNamePlaceholder: '例如:官网改版',
159
- addAgents: '添加智能体',
160
- searchAgents: '搜索智能体,选择 1–{max} 个',
161
- showMembers: '频道成员',
162
- canAdd: '还能添加 {count} 个智能体',
163
- findAgent: '搜索智能体',
164
- addCount: '添加 {count} 位',
165
- makeLead: '设为负责人',
166
- leadHint: '回答没有 @ 任何人的消息',
167
- mute: '免打扰:不回答这个频道的消息',
168
- unmute: '取消免打扰',
169
- muted: '免打扰',
170
- replying: '正在回答…',
171
- reset: '重开会话:忘掉之前的对话',
172
- resetDone: '{name} 下次回答时会从新会话开始。',
173
- remove: '移出频道',
174
- onlyMember: '频道至少要留一位成员',
175
- open: '打开它的会话',
176
- deleteChannel: '删除频道',
177
- confirmDelete: '删除 #{channel} 和它的全部消息?',
178
- delete: '删除',
179
- noChannel: '打开一个频道,这里显示它的成员。',
180
- more: '更多',
181
- stop: '停止',
182
- stoppedAgent: '已停止 {name}。',
183
- restart: '重新开始',
184
- restartHint: '开一个新会话:忘掉之前的对话',
185
- rename: '重命名',
186
- editRole: '职责',
187
- roleHint: '它最先读到的指示:它是谁、怎么做事。从下一个会话开始生效;想立刻生效可以“重新开始”。',
188
- save: '保存',
189
- moveTo: '移至…',
190
- moveHint: '换一个目录工作,会在那里开新会话',
191
- copyCwd: '复制工作目录',
192
- copied: '已复制 {path}',
193
- exportChat: '导出对话(Markdown)',
194
- nothingToExport: '{name} 还没有说过话。',
195
- joinChannel: '加入频道',
196
- noChannelToJoin: '它已经在所有频道里了。',
197
- joined: '{name} 已加入 #{channel}。',
198
- deleteAgent: '删除',
199
- confirmDeleteAgent: '删除 {name}?它会退出所在的频道,只剩它一个成员的频道也会一起删除;会话文件会保留。',
200
- pin: '置顶',
201
- unpin: '取消置顶',
202
- pinned: '已置顶',
203
- markUnread: '标为未读',
204
- markRead: '标为已读',
205
- editTopic: '修改主题',
206
- topicPlaceholder: '这个频道是做什么的',
207
- renameChannel: '重命名 #{channel}',
208
- stopAnswering: '停止回答',
209
- stoppedChannel: '已让 #{channel} 里正在回答的成员停下。',
210
- noMessagesToExport: '#{channel} 还没有消息。',
211
- };
212
-
213
- export namespace ChannelWords {
214
- export function of(language: string): Words {
215
- return language === 'zh-CN' ? ZH : EN;
216
- }
217
-
218
- export function format(text: string, values: Record<string, string>): string {
219
- return text.replace(/\{(\w+)\}/g, (whole, key: string) => values[key] ?? whole);
220
- }
221
- }
package/web-src/index.tsx DELETED
@@ -1,82 +0,0 @@
1
- import type { WebExtensionAPI } from '@celljs/ta-web/lib/browser/extension/web-extension-api';
2
- import { ChannelsClient } from './channels';
3
- import { AGENT_PAGE, NewAgentHead, NewAgentPage } from './create';
4
- import { ChannelWords } from './i18n';
5
- import { MembersView } from './members';
6
- // biome-ignore lint/correctness/noUnusedImports: the JSX below compiles to React.createElement (jsxFactory)
7
- import { bind, React } from './react';
8
- import { ChannelHead, ChannelRoom } from './room';
9
- import { AgentsSidebar, SidebarHead } from './sidebar';
10
- import { injectStyle } from './style';
11
- import { CHANNEL_PAGE, type ChannelsContext, ChannelsUiStore, ChannelViews, DOUBLE_PAGE, MEMBERS_VIEW, SessionAvatar } from './views';
12
-
13
- /**
14
- * The page of the team: one side bar with the double, the channels and the agents; a channel as a group
15
- * chat in the main area, its members a tool of the workbench on the right. The team itself runs in ta
16
- * serve (host.ts) and ta's tools are in the pi extension (extension.ts): this only shows it and writes to it.
17
- */
18
- export default function activate(pi: WebExtensionAPI): () => void {
19
- bind(pi.React);
20
- const removeStyle = injectStyle();
21
- const service = new ChannelsClient(pi.storage);
22
- const ui = new ChannelsUiStore();
23
- const context: ChannelsContext = {
24
- pi,
25
- service,
26
- ui,
27
- sessions: new Map(),
28
- showChannel: channelId => {
29
- ui.set({ channelId, adding: false, fresh: ui.state.fresh.filter(id => id !== channelId) });
30
- pi.ui.showView(CHANNEL_PAGE);
31
- },
32
- showMembers: (adding = false) => {
33
- ui.set({ adding });
34
- pi.ui.showView(MEMBERS_VIEW);
35
- },
36
- };
37
- pi.registerView('channels', {
38
- title: () => ChannelWords.of(pi.ui.language).title,
39
- icon: ChannelViews.icon(pi, 'Bot'),
40
- head: () => <SidebarHead context={context} />,
41
- render: () => <AgentsSidebar context={context} />,
42
- location: 'sidebar',
43
- pages: [DOUBLE_PAGE, CHANNEL_PAGE, AGENT_PAGE],
44
- order: 80,
45
- });
46
- pi.registerView('channel', {
47
- title: () => {
48
- const channel = service.state.team.channels.find(candidate => candidate.id === ui.state.channelId);
49
- return channel ? channel.name : ChannelWords.of(pi.ui.language).channel;
50
- },
51
- icon: ChannelViews.icon(pi, 'Hash'),
52
- head: () => <ChannelHead context={context} />,
53
- render: () => <ChannelRoom context={context} />,
54
- });
55
- pi.registerView('agent', {
56
- title: () => ui.state.draft?.name || ChannelWords.of(pi.ui.language).newAgentName,
57
- icon: ChannelViews.icon(pi, 'Bot'),
58
- head: () => <NewAgentHead context={context} />,
59
- render: () => <NewAgentPage context={context} />,
60
- });
61
- pi.registerView('members', {
62
- title: () => ChannelWords.of(pi.ui.language).showMembers,
63
- icon: ChannelViews.icon(pi, 'Users'),
64
- render: () => <MembersView context={context} />,
65
- location: 'panel',
66
- order: 60,
67
- });
68
- // In the session of an agent, the agent answers, not ta.
69
- pi.registerAvatar(props => <SessionAvatar context={context} {...props} />);
70
- // What ta wrote to with its tools is marked in the side bar until the user looks.
71
- const stopFocus = service.onFocus(channelId => {
72
- if (!ui.state.fresh.includes(channelId)) {
73
- ui.set({ fresh: [...ui.state.fresh, channelId] });
74
- }
75
- });
76
- void service.load();
77
- return () => {
78
- stopFocus();
79
- service.dispose();
80
- removeStyle();
81
- };
82
- }