@celljs/ta-channels 4.8.0 → 4.9.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 -2
- package/README.md +3 -2
- package/extension/index.mjs +109 -8
- package/host/index.mjs +281 -5
- package/package.json +13 -4
- package/web/index.js +992 -205
- package/web-src/agent-menu.tsx +0 -236
- package/web-src/channel-menu.tsx +0 -98
- package/web-src/channels-model.ts +0 -156
- package/web-src/channels-util.spec.ts +0 -312
- package/web-src/channels-util.ts +0 -556
- package/web-src/channels.ts +0 -235
- package/web-src/create.tsx +0 -273
- package/web-src/extension.ts +0 -91
- package/web-src/faces.tsx +0 -247
- package/web-src/host.ts +0 -12
- package/web-src/i18n.ts +0 -221
- package/web-src/index.tsx +0 -82
- package/web-src/members.tsx +0 -258
- package/web-src/more-menu.tsx +0 -113
- package/web-src/react.ts +0 -11
- package/web-src/room.tsx +0 -212
- package/web-src/sidebar.tsx +0 -295
- package/web-src/style.ts +0 -249
- package/web-src/team-tools.ts +0 -103
- package/web-src/team.spec.ts +0 -370
- package/web-src/team.ts +0 -560
- package/web-src/views.spec.ts +0 -89
- package/web-src/views.tsx +0 -239
package/web-src/views.tsx
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import type { WebAvatarProps, WebExtensionAPI, WebIcon } from '@celljs/ta-web/lib/browser/extension/web-extension-api';
|
|
2
|
-
import type { ChannelsClient, ChannelsState } from './channels';
|
|
3
|
-
import { type Agent, type Channel, ChannelsUtil, NAME, type Team } from './channels-util';
|
|
4
|
-
import { Face } from './faces';
|
|
5
|
-
import { ChannelWords, type Words } from './i18n';
|
|
6
|
-
import { React } from './react';
|
|
7
|
-
|
|
8
|
-
/** The page of the double, which the side bar lists first. */
|
|
9
|
-
export const DOUBLE_PAGE = 'assistant/assistant';
|
|
10
|
-
/** The page of a channel. */
|
|
11
|
-
export const CHANNEL_PAGE = `${NAME}/channel`;
|
|
12
|
-
/** The members of the channel shown, a tool of the workbench on the right. */
|
|
13
|
-
export const MEMBERS_VIEW = `${NAME}/members`;
|
|
14
|
-
const CHANNEL_KEY = 'ta-channels.channel';
|
|
15
|
-
|
|
16
|
-
/** What the side bar and the page of a channel share while the page is open. */
|
|
17
|
-
export interface ChannelsUi {
|
|
18
|
-
query: string;
|
|
19
|
-
/** The agent being made on its page (create.tsx); without `cwd`, it works in the directory of ta serve when it is made. */
|
|
20
|
-
draft?: { name: string; face: number; cwd?: string };
|
|
21
|
-
/** The card to change its name and face is open. */
|
|
22
|
-
editing: boolean;
|
|
23
|
-
/** The dialog to make a channel is open. */
|
|
24
|
-
creating: boolean;
|
|
25
|
-
/** The channel its page shows. */
|
|
26
|
-
channelId?: string;
|
|
27
|
-
/** Channels ta wrote to with its tools since the user last looked. */
|
|
28
|
-
fresh: string[];
|
|
29
|
-
/** The members view lists the agents to add, not the members. */
|
|
30
|
-
adding: boolean;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export class ChannelsUiStore {
|
|
34
|
-
protected current: ChannelsUi = {
|
|
35
|
-
query: '',
|
|
36
|
-
fresh: [],
|
|
37
|
-
adding: false,
|
|
38
|
-
editing: false,
|
|
39
|
-
creating: false,
|
|
40
|
-
channelId: (typeof sessionStorage === 'undefined' ? undefined : sessionStorage.getItem(CHANNEL_KEY)) ?? undefined,
|
|
41
|
-
};
|
|
42
|
-
protected readonly listeners = new Set<() => void>();
|
|
43
|
-
|
|
44
|
-
get state(): ChannelsUi {
|
|
45
|
-
return this.current;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
subscribe(listener: () => void): () => void {
|
|
49
|
-
this.listeners.add(listener);
|
|
50
|
-
return () => this.listeners.delete(listener);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
set(change: Partial<ChannelsUi>): void {
|
|
54
|
-
this.current = { ...this.current, ...change };
|
|
55
|
-
if (change.channelId && typeof sessionStorage !== 'undefined') {
|
|
56
|
-
sessionStorage.setItem(CHANNEL_KEY, change.channelId);
|
|
57
|
-
}
|
|
58
|
-
for (const listener of this.listeners) {
|
|
59
|
-
listener();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** What the views share: the API of the page, the channels and what the views show. */
|
|
65
|
-
export interface ChannelsContext {
|
|
66
|
-
pi: WebExtensionAPI;
|
|
67
|
-
service: ChannelsClient;
|
|
68
|
-
ui: ChannelsUiStore;
|
|
69
|
-
/** The sessions of the agents the page showed, by agent id. */
|
|
70
|
-
sessions: Map<string, string>;
|
|
71
|
-
/** Shows a channel as the page of the main area. */
|
|
72
|
-
showChannel(channelId: string): void;
|
|
73
|
-
/** Shows the members of the channel shown on the right; `adding`, the agents to add. */
|
|
74
|
-
showMembers(adding?: boolean): void;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export namespace ChannelViews {
|
|
78
|
-
export function words(pi: WebExtensionAPI): Words {
|
|
79
|
-
return ChannelWords.of(pi.ui.language);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function icon(pi: WebExtensionAPI, name: string): WebIcon {
|
|
83
|
-
return pi.ui.icons[name] ?? (() => null);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** An icon the page may not have yet (icons only grow): else `fallback`. */
|
|
87
|
-
export function maybeIcon(pi: WebExtensionAPI, name: string, fallback: React.ReactNode, size: number): React.ReactNode {
|
|
88
|
-
const Icon = pi.ui.icons[name];
|
|
89
|
-
return Icon ? <Icon size={size} /> : fallback;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function message(error: unknown): string {
|
|
93
|
-
return error instanceof Error ? error.message : String(error);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** The agent asked for last: sessions open in any order, the last asked for is shown. */
|
|
97
|
-
let latest: string | undefined;
|
|
98
|
-
|
|
99
|
-
/** Shows the session of an agent as the conversation, opened on the server if it is not. */
|
|
100
|
-
export async function openAgent(context: ChannelsContext, agentId: string): Promise<void> {
|
|
101
|
-
latest = agentId;
|
|
102
|
-
const sessionId = await context.service.openAgent(agentId);
|
|
103
|
-
context.sessions.set(agentId, sessionId);
|
|
104
|
-
if (latest === agentId) {
|
|
105
|
-
await context.pi.switchSession(sessionId);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function useChannels(service: ChannelsClient): ChannelsState {
|
|
111
|
-
const state = React.useSyncExternalStore(
|
|
112
|
-
listener => service.subscribe(listener),
|
|
113
|
-
() => service.state,
|
|
114
|
-
);
|
|
115
|
-
React.useEffect(() => {
|
|
116
|
-
void service.load(true);
|
|
117
|
-
}, [service]);
|
|
118
|
-
return state;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function useUi(ui: ChannelsUiStore): ChannelsUi {
|
|
122
|
-
return React.useSyncExternalStore(
|
|
123
|
-
listener => ui.subscribe(listener),
|
|
124
|
-
() => ui.state,
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** An agent's face; ta and the user are drawn elsewhere. */
|
|
129
|
-
export function AgentAvatar({ agent, faces, size, working }: { agent?: Agent; faces: Map<string, number>; size: number; working?: boolean }) {
|
|
130
|
-
return <Face face={agent ? (faces.get(agent.id) ?? 0) : 0} size={size} working={working} />;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** The agent of a session, at the head of its turns when the session is shown; ta for a session of no agent. */
|
|
134
|
-
export function SessionAvatar({ context, session, mood, size }: WebAvatarProps & { context: ChannelsContext }) {
|
|
135
|
-
const { team } = React.useSyncExternalStore(
|
|
136
|
-
listener => context.service.subscribe(listener),
|
|
137
|
-
() => context.service.state,
|
|
138
|
-
);
|
|
139
|
-
const faces = useFaces(team);
|
|
140
|
-
const agent = team.agents.find(
|
|
141
|
-
candidate => (!!session.sessionFile && candidate.sessionFile === session.sessionFile) || context.sessions.get(candidate.id) === session.sessionId,
|
|
142
|
-
);
|
|
143
|
-
if (!agent) {
|
|
144
|
-
const Avatar = context.pi.ui.Avatar;
|
|
145
|
-
return <Avatar mood={mood} size={size} />;
|
|
146
|
-
}
|
|
147
|
-
return <AgentAvatar agent={agent} faces={faces} size={size} working={mood === 'thinking' || mood === 'working'} />;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export function useFaces(team: Team): Map<string, number> {
|
|
151
|
-
return React.useMemo(() => ChannelsUtil.faces(team.agents), [team.agents]);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/** The members of a channel that are agents still, the lead first. */
|
|
155
|
-
export function membersOf(team: Team, channel: Channel): Agent[] {
|
|
156
|
-
return channel.members.map(id => team.agents.find(agent => agent.id === id)).filter((agent): agent is Agent => !!agent);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** The working directory of ta serve: where agents without one of their own work. */
|
|
160
|
-
export function useServerCwd(pi: WebExtensionAPI): string | undefined {
|
|
161
|
-
const [cwd, setCwd] = React.useState<string>();
|
|
162
|
-
React.useEffect(() => {
|
|
163
|
-
let live = true;
|
|
164
|
-
pi.server.getServerInfo().then(
|
|
165
|
-
info => live && setCwd(info.cwd),
|
|
166
|
-
() => undefined,
|
|
167
|
-
);
|
|
168
|
-
return () => {
|
|
169
|
-
live = false;
|
|
170
|
-
};
|
|
171
|
-
}, [pi]);
|
|
172
|
-
return cwd;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export namespace SidebarUtil {
|
|
176
|
-
/** Today the time, this year the day, else the date. */
|
|
177
|
-
export function time(at: number | undefined, language: string, now = new Date()): string {
|
|
178
|
-
if (!at) {
|
|
179
|
-
return '';
|
|
180
|
-
}
|
|
181
|
-
const date = new Date(at);
|
|
182
|
-
if (date.toDateString() === now.toDateString()) {
|
|
183
|
-
return date.toLocaleTimeString(language, { hour: '2-digit', minute: '2-digit', hour12: false });
|
|
184
|
-
}
|
|
185
|
-
if (date.getFullYear() === now.getFullYear()) {
|
|
186
|
-
return date.toLocaleDateString(language, { month: 'numeric', day: 'numeric' });
|
|
187
|
-
}
|
|
188
|
-
return date.toLocaleDateString(language, { year: '2-digit', month: 'numeric', day: 'numeric' });
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/** The host of an `ssh://` directory; undefined for one of the machine of ta serve. */
|
|
192
|
-
export function host(cwd: string): string | undefined {
|
|
193
|
-
return /^ssh:\/\/([^/]+)/.exec(cwd)?.[1];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function folder(cwd: string): string {
|
|
197
|
-
const parts = cwd.split(/[\\/]+/).filter(Boolean);
|
|
198
|
-
return parts[parts.length - 1] ?? cwd;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function matches(query: string, ...texts: (string | undefined)[]): boolean {
|
|
202
|
-
const key = query.trim().toLowerCase();
|
|
203
|
-
return !key || texts.some(text => text?.toLowerCase().includes(key));
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** The agents by directory, in the order each directory first comes. */
|
|
207
|
-
export function byDirectory(agents: Agent[], serverCwd: string): { cwd: string; agents: Agent[] }[] {
|
|
208
|
-
const groups = new Map<string, Agent[]>();
|
|
209
|
-
for (const agent of agents) {
|
|
210
|
-
const cwd = agent.cwd ?? serverCwd;
|
|
211
|
-
groups.set(cwd, [...(groups.get(cwd) ?? []), agent]);
|
|
212
|
-
}
|
|
213
|
-
return [...groups].map(([cwd, list]) => ({ cwd, agents: list }));
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export function useSubmit(action: () => Promise<unknown>, onDone: () => void): { busy: boolean; error?: string; submit(event?: React.SyntheticEvent): void } {
|
|
218
|
-
const [busy, setBusy] = React.useState(false);
|
|
219
|
-
const [error, setError] = React.useState<string>();
|
|
220
|
-
return {
|
|
221
|
-
busy,
|
|
222
|
-
error,
|
|
223
|
-
submit: event => {
|
|
224
|
-
event?.preventDefault();
|
|
225
|
-
setBusy(true);
|
|
226
|
-
setError(undefined);
|
|
227
|
-
action().then(
|
|
228
|
-
() => {
|
|
229
|
-
setBusy(false);
|
|
230
|
-
onDone();
|
|
231
|
-
},
|
|
232
|
-
failure => {
|
|
233
|
-
setBusy(false);
|
|
234
|
-
setError(ChannelViews.message(failure));
|
|
235
|
-
},
|
|
236
|
-
);
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
}
|