@celljs/ta-channels 4.9.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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/web/index.js +95 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-channels",
3
- "version": "4.9.0",
3
+ "version": "4.9.1",
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,8 +27,8 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.9.0",
31
- "@celljs/ta-web": "4.9.0",
30
+ "@celljs/ta-protocol": "4.9.1",
31
+ "@celljs/ta-web": "4.9.1",
32
32
  "@types/react": "^19.3.0"
33
33
  },
34
34
  "publishConfig": {
package/web/index.js CHANGED
@@ -1214,7 +1214,8 @@ var EN = {
1214
1214
  noTasksHere: "What the double hands out, tasks and teams, is listed here",
1215
1215
  tellDouble: "Talk to the double",
1216
1216
  deleteTask: "Delete the team",
1217
- confirmDeleteTask: "Delete #{channel} and its messages? Its agents stay, among your members."
1217
+ deleteTaskHint: "The messages of #{channel} go with it. Its agents stay, among your members.",
1218
+ selectTasks: "Select"
1218
1219
  };
1219
1220
  var ZH = {
1220
1221
  title: "分身",
@@ -1349,7 +1350,8 @@ var ZH = {
1349
1350
  noTasksHere: "分身交出去的任务和团队会列在这里",
1350
1351
  tellDouble: "和分身说",
1351
1352
  deleteTask: "删除这个团队",
1352
- confirmDeleteTask: "删除 #{channel} 及其消息?团队成员会留在你的成员里。"
1353
+ deleteTaskHint: "#{channel} 的消息会一起删除,团队成员会留在你的成员里。",
1354
+ selectTasks: "多选"
1353
1355
  };
1354
1356
  var ChannelWords;
1355
1357
  ((ChannelWords) => {
@@ -2806,7 +2808,7 @@ class ChannelTaskSource {
2806
2808
  entry(channel, members, faces, working, status, detail, endedAt) {
2807
2809
  return {
2808
2810
  id: channel.id,
2809
- title: channel.topic ? `${channel.name} · ${channel.topic}` : channel.name,
2811
+ title: taskTitle(channel),
2810
2812
  status,
2811
2813
  detail,
2812
2814
  startedAt: channel.createdAt,
@@ -2819,10 +2821,19 @@ class ChannelTaskSource {
2819
2821
  working
2820
2822
  }),
2821
2823
  open: () => openScene(this.context, channel),
2822
- menu: () => taskMenu(this.context, channel, working)
2824
+ menu: () => taskMenu(this.context, channel, working),
2825
+ remove: () => deleteTeam(this.context, channel),
2826
+ removeHint: ChannelWords.format(ChannelViews.words(this.context.pi).deleteTaskHint, { channel: channel.name })
2823
2827
  };
2824
2828
  }
2825
2829
  }
2830
+ function taskTitle(channel) {
2831
+ return channel.topic ? `${channel.name} · ${channel.topic}` : channel.name;
2832
+ }
2833
+ async function deleteTeam(context, channel) {
2834
+ await context.service.deleteChannel(channel.id);
2835
+ context.pi.ui.closeEditor(`channel:${channel.id}`);
2836
+ }
2826
2837
  function openScene(context, channel) {
2827
2838
  context.pi.ui.openEditor({
2828
2839
  id: `channel:${channel.id}`,
@@ -2879,15 +2890,13 @@ function taskMenu(context, channel, working) {
2879
2890
  label: w.deleteTask,
2880
2891
  icon: icon("Trash2"),
2881
2892
  danger: true,
2882
- run: act(async () => {
2883
- if (await pi.ui.confirm(w.deleteTask, ChannelWords.format(w.confirmDeleteTask, { channel: channel.name }), {
2884
- danger: true,
2885
- confirmLabel: w.delete
2886
- })) {
2887
- await service.deleteChannel(channel.id);
2888
- pi.ui.closeEditor(`channel:${channel.id}`);
2893
+ run: act(() => pi.ui.removeTasks([
2894
+ {
2895
+ title: taskTitle(channel),
2896
+ removeHint: ChannelWords.format(w.deleteTaskHint, { channel: channel.name }),
2897
+ remove: () => deleteTeam(context, channel)
2889
2898
  }
2890
- })
2899
+ ]))
2891
2900
  }
2892
2901
  ]
2893
2902
  ];
@@ -2991,14 +3000,14 @@ function ChannelMenu({ context, channel, working }) {
2991
3000
  }
2992
3001
 
2993
3002
  // web-src/sidebar.tsx
2994
- function Row({ pi, avatar, title, badge, preview, live, dot, waiting, time, fresh, hint, selected, onSelect, more, swipe }) {
3003
+ function Row({ pi, avatar, title, badge, preview, live, dot, waiting, time, fresh, hint, selected, onSelect, more, swipe, check }) {
2995
3004
  const row = /* @__PURE__ */ React.createElement("button", {
2996
3005
  type: "button",
2997
3006
  className: `tac-item${selected ? " tac-selected" : ""}`,
2998
3007
  "aria-current": selected || undefined,
2999
3008
  title: hint,
3000
3009
  onClick: onSelect
3001
- }, avatar, /* @__PURE__ */ React.createElement("span", {
3010
+ }, check, avatar, /* @__PURE__ */ React.createElement("span", {
3002
3011
  className: "tac-item-text"
3003
3012
  }, /* @__PURE__ */ React.createElement("span", {
3004
3013
  className: "tac-item-top"
@@ -3191,13 +3200,56 @@ function Section({
3191
3200
  }, children));
3192
3201
  }
3193
3202
  var DOTS = { running: "running", waiting: "waiting", done: "done", failed: "error", stopped: "cancelled" };
3194
- function TaskItem({ context, task }) {
3203
+ function useTaskSelection(pi, tasks) {
3204
+ const [chosen, setChosen] = React.useState();
3205
+ const removable = tasks.filter((task) => task.remove);
3206
+ const selected = chosen ? removable.filter((task) => chosen.has(task.key)) : [];
3207
+ const selecting = !!chosen && removable.length > 0;
3208
+ React.useEffect(() => {
3209
+ if (chosen && removable.length === 0) {
3210
+ setChosen(undefined);
3211
+ }
3212
+ }, [chosen, removable.length]);
3213
+ return {
3214
+ selecting,
3215
+ selected,
3216
+ removable,
3217
+ isChosen: (task) => !!chosen?.has(task.key),
3218
+ start: (task) => setChosen(new Set([task.key])),
3219
+ toggle: (task) => setChosen((before) => {
3220
+ const next = new Set(before);
3221
+ if (!next.delete(task.key)) {
3222
+ next.add(task.key);
3223
+ }
3224
+ return next;
3225
+ }),
3226
+ selectAll: (all) => setChosen(new Set(all ? removable.map((task) => task.key) : [])),
3227
+ done: () => setChosen(undefined),
3228
+ removeSelected: async () => {
3229
+ if (await pi.ui.removeTasks(selected)) {
3230
+ setChosen(undefined);
3231
+ }
3232
+ }
3233
+ };
3234
+ }
3235
+ function TaskItem({ context, task, selection }) {
3195
3236
  const { pi } = context;
3237
+ const w = ChannelViews.words(pi);
3196
3238
  const Own = task.icon;
3197
3239
  const ListTodo = pi.ui.icons.ListTodo ?? ChannelViews.icon(pi, "List");
3198
- const items = () => (task.menu?.() ?? []).map((section) => section.map(({ icon: Icon, ...item }) => ({ ...item, icon: Icon && /* @__PURE__ */ React.createElement(Icon, {
3199
- size: 15
3200
- }) })));
3240
+ const ListChecks = ChannelViews.icon(pi, "ListChecks");
3241
+ const SelectCheck = pi.ui.SelectCheck;
3242
+ const removable = !!task.remove && !!SelectCheck;
3243
+ const selecting = selection.selecting && !!SelectCheck;
3244
+ const items = () => [
3245
+ ...(task.menu?.() ?? []).map((section) => section.map(({ icon: Icon, ...item }) => ({ ...item, icon: Icon && /* @__PURE__ */ React.createElement(Icon, {
3246
+ size: 15
3247
+ }) }))),
3248
+ ...removable ? [[{ key: "select", label: w.selectTasks, icon: /* @__PURE__ */ React.createElement(ListChecks, {
3249
+ size: 15
3250
+ }), run: () => selection.start(task) }]] : []
3251
+ ];
3252
+ const swipe = task.remove && !selecting ? [{ key: "delete", label: w.delete, danger: true, run: () => void pi.ui.removeTasks([task]) }] : undefined;
3201
3253
  return /* @__PURE__ */ React.createElement(Row, {
3202
3254
  pi,
3203
3255
  avatar: Own ? /* @__PURE__ */ React.createElement("span", {
@@ -3215,12 +3267,17 @@ function TaskItem({ context, task }) {
3215
3267
  waiting: task.status === "waiting",
3216
3268
  time: SidebarUtil.time(task.endedAt ?? task.startedAt, pi.ui.language),
3217
3269
  hint: task.title,
3218
- selected: false,
3219
- onSelect: () => task.open(),
3220
- more: task.menu && /* @__PURE__ */ React.createElement(MoreMenu, {
3270
+ selected: selecting && selection.isChosen(task),
3271
+ onSelect: selecting ? () => removable && selection.toggle(task) : () => task.open(),
3272
+ more: !selecting && (task.menu || removable) && /* @__PURE__ */ React.createElement(MoreMenu, {
3221
3273
  pi,
3222
3274
  label: task.title,
3223
3275
  items
3276
+ }),
3277
+ swipe,
3278
+ check: selecting && /* @__PURE__ */ React.createElement(SelectCheck, {
3279
+ checked: selection.isChosen(task),
3280
+ disabled: !removable
3224
3281
  })
3225
3282
  });
3226
3283
  }
@@ -3311,6 +3368,8 @@ function AgentsSidebar({ context }) {
3311
3368
  }
3312
3369
  const shownTasks = tasks.filter((task) => SidebarUtil.matches(query, task.title, task.detail));
3313
3370
  const groups = SidebarUtil.taskGroups(shownTasks);
3371
+ const selection = useTaskSelection(pi, shownTasks);
3372
+ const SelectBar = pi.ui.SelectBar;
3314
3373
  const channels = ChannelsUtil.pinnedFirst(own).filter((channel) => SidebarUtil.matches(query, channel.name, channel.topic, ...membersOf(team, channel).map((agent) => agent.name)));
3315
3374
  const agents = ChannelsUtil.standing(team).filter((agent) => SidebarUtil.matches(query, agent.name, agent.role));
3316
3375
  const directories = SidebarUtil.directories(agents, serverCwd);
@@ -3324,7 +3383,7 @@ function AgentsSidebar({ context }) {
3324
3383
  const sessionId = context.sessions.get(agent.id);
3325
3384
  return opening === agent.id || !pageShown && !!sessionId && sessionId === shownSession;
3326
3385
  };
3327
- const ended = allEnded ? groups.ended : groups.ended.slice(0, ENDED_SHOWN);
3386
+ const ended = allEnded || selection.selecting ? groups.ended : groups.ended.slice(0, ENDED_SHOWN);
3328
3387
  const nothing = query && shownTasks.length === 0 && channels.length === 0 && agents.length === 0;
3329
3388
  const blank = state.loaded && !query && !draft && tasks.length === 0 && own.length === 0 && ChannelsUtil.standing(team).length === 0;
3330
3389
  const running = tasks.filter((task) => task.status === "running").length;
@@ -3416,7 +3475,8 @@ function AgentsSidebar({ context }) {
3416
3475
  }, groups.waiting.map((task) => /* @__PURE__ */ React.createElement(TaskItem, {
3417
3476
  key: task.key,
3418
3477
  context,
3419
- task
3478
+ task,
3479
+ selection
3420
3480
  }))), groups.running.length > 0 && /* @__PURE__ */ React.createElement(Section, {
3421
3481
  id: "running",
3422
3482
  title: w.runningSection,
@@ -3426,7 +3486,8 @@ function AgentsSidebar({ context }) {
3426
3486
  }, groups.running.map((task) => /* @__PURE__ */ React.createElement(TaskItem, {
3427
3487
  key: task.key,
3428
3488
  context,
3429
- task
3489
+ task,
3490
+ selection
3430
3491
  }))), groups.ended.length > 0 && /* @__PURE__ */ React.createElement(Section, {
3431
3492
  id: "ended",
3432
3493
  title: w.endedSection,
@@ -3436,8 +3497,9 @@ function AgentsSidebar({ context }) {
3436
3497
  }, ended.map((task) => /* @__PURE__ */ React.createElement(TaskItem, {
3437
3498
  key: task.key,
3438
3499
  context,
3439
- task
3440
- })), groups.ended.length > ENDED_SHOWN && /* @__PURE__ */ React.createElement("button", {
3500
+ task,
3501
+ selection
3502
+ })), groups.ended.length > ENDED_SHOWN && !selection.selecting && /* @__PURE__ */ React.createElement("button", {
3441
3503
  type: "button",
3442
3504
  className: "tac-show-all",
3443
3505
  onClick: () => setAllEnded(!allEnded)
@@ -3540,7 +3602,13 @@ ${agent.cwd ?? serverCwd}`,
3540
3602
  }),
3541
3603
  swipe: swipeDelete(pi, () => deleteChannel(context, channel))
3542
3604
  });
3543
- }))));
3605
+ }))), selection.selecting && SelectBar && /* @__PURE__ */ React.createElement(SelectBar, {
3606
+ count: selection.selected.length,
3607
+ total: selection.removable.length,
3608
+ onSelectAll: selection.selectAll,
3609
+ onDone: selection.done,
3610
+ actions: [{ key: "delete", label: w.delete, danger: true, run: () => void selection.removeSelected() }]
3611
+ }));
3544
3612
  }
3545
3613
 
3546
3614
  // web-src/style.ts