@celljs/ta-web 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.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/esm/browser/assistant/assistant-extension.js +13 -5
- package/esm/browser/assistant/assistant-task-source.d.ts +2 -0
- package/esm/browser/assistant/assistant-task-source.js +2 -0
- package/esm/browser/assistant/assistant-task-util.d.ts +6 -0
- package/esm/browser/assistant/assistant-task-util.js +8 -0
- package/esm/browser/assistant/assistant-tasks.js +3 -2
- package/esm/browser/assistant/assistant.d.ts +20 -0
- package/esm/browser/assistant/assistant.js +45 -1
- package/esm/browser/assistant/task-views.d.ts +40 -6
- package/esm/browser/assistant/task-views.js +73 -21
- package/esm/browser/avatar/dino-avatar.d.ts +3 -4
- package/esm/browser/avatar/dino-avatar.js +4 -178
- package/esm/browser/avatar/dino-face.d.ts +19 -0
- package/esm/browser/avatar/dino-face.js +142 -0
- package/esm/browser/avatar/dino-geometry.d.ts +11 -0
- package/esm/browser/avatar/dino-geometry.js +38 -0
- package/esm/browser/avatar/dino-kinds.d.ts +15 -0
- package/esm/browser/avatar/dino-kinds.js +544 -0
- package/esm/browser/avatar/dino-motion.js +1 -1
- package/esm/browser/avatar/dino-shape.d.ts +80 -0
- package/esm/browser/avatar/dino-shape.js +113 -0
- package/esm/browser/avatar/dino-species.d.ts +1 -61
- package/esm/browser/avatar/dino-species.js +2 -653
- package/esm/browser/components/access-view.js +1 -1
- package/esm/browser/components/account-menu.js +1 -1
- package/esm/browser/components/app-shell-hooks.d.ts +47 -0
- package/esm/browser/components/app-shell-hooks.js +165 -0
- package/esm/browser/components/app-view.js +6 -151
- package/esm/browser/components/auth-view.js +1 -1
- package/esm/browser/components/composer.js +17 -10
- package/esm/browser/components/dino.js +1 -1
- package/esm/browser/components/folder-picker.js +4 -1
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/host-view.js +1 -1
- package/esm/browser/components/select-bar.d.ts +9 -0
- package/esm/browser/components/select-bar.js +24 -0
- package/esm/browser/components/settings-choices.d.ts +35 -0
- package/esm/browser/components/settings-choices.js +117 -0
- package/esm/browser/components/settings-parts.d.ts +21 -0
- package/esm/browser/components/settings-parts.js +300 -0
- package/esm/browser/components/settings-view.d.ts +0 -6
- package/esm/browser/components/settings-view.js +4 -406
- package/esm/browser/components/workbench-view.js +1 -1
- package/esm/browser/extension/icons.js +2 -1
- package/esm/browser/extension/web-extension-api.d.ts +38 -1
- package/esm/browser/extension/web-extensions.js +6 -1
- package/esm/browser/extension/web-tasks.d.ts +9 -1
- package/esm/browser/extension/web-tasks.js +24 -0
- package/esm/browser/hooks.d.ts +3 -1
- package/esm/browser/hooks.js +8 -0
- package/esm/browser/i18n/locales.d.ts +6 -1
- package/esm/browser/i18n/messages.d.ts +5 -0
- package/esm/browser/i18n/messages.js +10 -0
- package/esm/browser/style/device.js +16 -0
- package/esm/browser/style/shell.d.ts +1 -1
- package/esm/browser/style/shell.js +1 -0
- package/esm/browser/style/tasks.d.ts +1 -1
- package/esm/browser/style/tasks.js +2 -0
- package/esm/browser/workbench-util.d.ts +61 -0
- package/esm/browser/workbench-util.js +138 -0
- package/esm/browser/workbench.d.ts +1 -37
- package/esm/browser/workbench.js +2 -136
- package/lib/browser/assistant/assistant-extension.js +13 -5
- package/lib/browser/assistant/assistant-task-source.d.ts +2 -0
- package/lib/browser/assistant/assistant-task-source.js +2 -0
- package/lib/browser/assistant/assistant-task-util.d.ts +6 -0
- package/lib/browser/assistant/assistant-task-util.js +8 -0
- package/lib/browser/assistant/assistant-tasks.js +2 -1
- package/lib/browser/assistant/assistant.d.ts +20 -0
- package/lib/browser/assistant/assistant.js +45 -1
- package/lib/browser/assistant/task-views.d.ts +40 -6
- package/lib/browser/assistant/task-views.js +74 -21
- package/lib/browser/avatar/dino-avatar.d.ts +3 -4
- package/lib/browser/avatar/dino-avatar.js +27 -202
- package/lib/browser/avatar/dino-face.d.ts +20 -0
- package/lib/browser/avatar/dino-face.js +148 -0
- package/lib/browser/avatar/dino-geometry.d.ts +12 -0
- package/lib/browser/avatar/dino-geometry.js +47 -0
- package/lib/browser/avatar/dino-kinds.d.ts +16 -0
- package/lib/browser/avatar/dino-kinds.js +547 -0
- package/lib/browser/avatar/dino-motion.js +2 -2
- package/lib/browser/avatar/dino-shape.d.ts +81 -0
- package/lib/browser/avatar/dino-shape.js +126 -0
- package/lib/browser/avatar/dino-species.d.ts +1 -61
- package/lib/browser/avatar/dino-species.js +34 -687
- package/lib/browser/components/access-view.js +2 -2
- package/lib/browser/components/account-menu.js +2 -2
- package/lib/browser/components/app-shell-hooks.d.ts +48 -0
- package/lib/browser/components/app-shell-hooks.js +207 -0
- package/lib/browser/components/app-view.js +16 -161
- package/lib/browser/components/auth-view.js +3 -3
- package/lib/browser/components/composer.js +17 -10
- package/lib/browser/components/dino.js +3 -3
- package/lib/browser/components/folder-picker.js +4 -1
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/host-view.js +5 -5
- package/lib/browser/components/select-bar.d.ts +10 -0
- package/lib/browser/components/select-bar.js +61 -0
- package/lib/browser/components/settings-choices.d.ts +36 -0
- package/lib/browser/components/settings-choices.js +156 -0
- package/lib/browser/components/settings-parts.d.ts +22 -0
- package/lib/browser/components/settings-parts.js +336 -0
- package/lib/browser/components/settings-view.d.ts +0 -6
- package/lib/browser/components/settings-view.js +2 -405
- package/lib/browser/components/workbench-view.js +3 -3
- package/lib/browser/extension/icons.js +1 -0
- package/lib/browser/extension/web-extension-api.d.ts +38 -1
- package/lib/browser/extension/web-extensions.js +5 -0
- package/lib/browser/extension/web-tasks.d.ts +9 -1
- package/lib/browser/extension/web-tasks.js +24 -0
- package/lib/browser/hooks.d.ts +3 -1
- package/lib/browser/hooks.js +9 -0
- package/lib/browser/i18n/locales.d.ts +6 -1
- package/lib/browser/i18n/messages.d.ts +5 -0
- package/lib/browser/i18n/messages.js +10 -0
- package/lib/browser/style/device.js +16 -0
- package/lib/browser/style/shell.d.ts +1 -1
- package/lib/browser/style/shell.js +1 -0
- package/lib/browser/style/tasks.d.ts +1 -1
- package/lib/browser/style/tasks.js +2 -0
- package/lib/browser/workbench-util.d.ts +62 -0
- package/lib/browser/workbench-util.js +144 -0
- package/lib/browser/workbench.d.ts +1 -37
- package/lib/browser/workbench.js +24 -159
- package/package.json +7 -7
|
@@ -1,43 +1,8 @@
|
|
|
1
1
|
import { SessionStore, type SessionStoreOptions, TaConnection } from '@celljs/ta-client';
|
|
2
2
|
import { type TaAccessServer, type TaAuthEvent, type TaAuthServer, type TaGatewayServer, type TaPackageServer, type TaRelayServer, type TaRemoteEvent, type TaRemoteServer, type TaServer, type TaServerInfo, type TaSettingsServer, type TaTerminalServer, type TaWorkspaceServer } from '@celljs/ta-protocol';
|
|
3
|
-
import { type RelayPairing } from '@celljs/ta-relay';
|
|
4
3
|
import { type HostList } from './hosts.js';
|
|
5
4
|
import { type Credential, TaWorkbench, type WorkbenchState } from './workbench-protocol.js';
|
|
6
|
-
type ServiceName
|
|
7
|
-
/** Why a computer added while another is in use was not switched to. */
|
|
8
|
-
export declare class WorkbenchError extends Error {
|
|
9
|
-
readonly reason: 'refused' | 'unreachable';
|
|
10
|
-
constructor(reason: 'refused' | 'unreachable');
|
|
11
|
-
}
|
|
12
|
-
export declare namespace WorkbenchUtil {
|
|
13
|
-
/** A pairing link (`ta pair`) or else a token. */
|
|
14
|
-
function credential(text: string): Credential;
|
|
15
|
-
/**
|
|
16
|
-
* Whether the ta serve in use runs on another machine than this browser: reached through a relay, from
|
|
17
|
-
* the app, or at an address that is not this machine's. A sign-in there cannot come back to it by itself.
|
|
18
|
-
*/
|
|
19
|
-
function elsewhere(hostId: string | undefined, hostname?: string): boolean;
|
|
20
|
-
/** In the Ta app on a phone, where no ta serve serves the page: it reaches one through a relay. */
|
|
21
|
-
function isApp(): boolean;
|
|
22
|
-
function readPairing(text: string | null): RelayPairing | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Whether the server of the page answers at all. A WebSocket that does not open cannot say why: a
|
|
25
|
-
* server that answers refused the token; none means ta serve is not running (the installed app opens
|
|
26
|
-
* from its service worker then).
|
|
27
|
-
*/
|
|
28
|
-
function reachable(base: string, fetcher?: typeof fetch): Promise<boolean>;
|
|
29
|
-
/** The hosts kept in `storage`; the token or pairing an older version kept becomes the first. */
|
|
30
|
-
function readHosts(storage: Storage | undefined, now?: number): HostList;
|
|
31
|
-
/** Which ta serve a credential reaches, to know whose lists were kept. */
|
|
32
|
-
function serverOf(credential: Credential, host: string): string;
|
|
33
|
-
/** Where the lists of `of` are kept: each computer has its own, to show at once when switched to. */
|
|
34
|
-
function listsKey(of: string): string;
|
|
35
|
-
/** The lists kept for `of`, none running: whether one runs is known once connected. */
|
|
36
|
-
function readLists(text: string | null, of: string): Pick<WorkbenchState, 'server' | 'sessions' | 'saved'> | undefined;
|
|
37
|
-
/** `previous` if `next` is the same, so that what shows it is not drawn again. */
|
|
38
|
-
function same<T>(previous: T, next: T): T;
|
|
39
|
-
function retryDelay(attempt: number): number;
|
|
40
|
-
}
|
|
5
|
+
import { type ServiceName } from './workbench-util.js';
|
|
41
6
|
export declare class TaWorkbenchImpl implements TaWorkbench {
|
|
42
7
|
protected list: HostList;
|
|
43
8
|
protected current: WorkbenchState;
|
|
@@ -134,4 +99,3 @@ export declare class TaWorkbenchImpl implements TaWorkbench {
|
|
|
134
99
|
protected update(change: Partial<WorkbenchState>): void;
|
|
135
100
|
protected keepLists(of: string): void;
|
|
136
101
|
}
|
|
137
|
-
export {};
|
package/esm/browser/workbench.js
CHANGED
|
@@ -7,145 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Component } from '@celljs/core';
|
|
8
8
|
import { SessionStore, TaConnection } from '@celljs/ta-client';
|
|
9
9
|
import { TA_WEBSOCKET_PATH, TaErrorCode, } from '@celljs/ta-protocol';
|
|
10
|
-
import {
|
|
10
|
+
import { RelaySocket } from '@celljs/ta-relay';
|
|
11
11
|
import { HostUtil } from './hosts.js';
|
|
12
12
|
import { StateUtil } from './state/state-protocol.js';
|
|
13
13
|
import { TaWorkbench } from './workbench-protocol.js';
|
|
14
|
-
|
|
15
|
-
const TOKEN_KEY = 'ta.token';
|
|
16
|
-
const PAIRING_KEY = 'ta.pairing';
|
|
17
|
-
/** How long a computer added while another is in use has to answer before it counts as unreachable. */
|
|
18
|
-
const PROBE_MS = 15000;
|
|
19
|
-
/** Waits between attempts while ta serve is not running: doubling up to the last. */
|
|
20
|
-
const RETRY_DELAYS_MS = [1000, 2000, 4000, 8000];
|
|
21
|
-
/**
|
|
22
|
-
* How long the connection is down, while the page is seen, before the user is told (`offlineShown`):
|
|
23
|
-
* the first tries to connect again are within it, so a short drop shows nothing.
|
|
24
|
-
*/
|
|
25
|
-
const GRACE_MS = 2500;
|
|
26
|
-
/**
|
|
27
|
-
* The lists of the last time, of the ta serve they were of: the next start shows them at once while it
|
|
28
|
-
* connects, as a phone's app shows its chats before it is online. They are small; the conversations
|
|
29
|
-
* are not kept.
|
|
30
|
-
*/
|
|
31
|
-
const LISTS_KEY = 'ta.lists';
|
|
32
|
-
/** How long the page shows which computer it switches to before it loads again for it. */
|
|
33
|
-
const SWITCH_MS = 160;
|
|
34
|
-
/** A conversation opens with about this much of its latest messages, its earlier ones loaded as much at a time when scrolled to. */
|
|
35
|
-
const PAGE_BYTES = 128 * 1024;
|
|
36
|
-
/** Why a computer added while another is in use was not switched to. */
|
|
37
|
-
export class WorkbenchError extends Error {
|
|
38
|
-
constructor(reason) {
|
|
39
|
-
super(reason === 'refused' ? 'The computer refused this device.' : 'The computer did not answer.');
|
|
40
|
-
this.reason = reason;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export var WorkbenchUtil;
|
|
44
|
-
(function (WorkbenchUtil) {
|
|
45
|
-
/** A pairing link (`ta pair`) or else a token. */
|
|
46
|
-
function credential(text) {
|
|
47
|
-
try {
|
|
48
|
-
return { pairing: RelayPairingUtil.parse(text) };
|
|
49
|
-
}
|
|
50
|
-
catch (_a) {
|
|
51
|
-
return { token: text };
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
WorkbenchUtil.credential = credential;
|
|
55
|
-
/**
|
|
56
|
-
* Whether the ta serve in use runs on another machine than this browser: reached through a relay, from
|
|
57
|
-
* the app, or at an address that is not this machine's. A sign-in there cannot come back to it by itself.
|
|
58
|
-
*/
|
|
59
|
-
function elsewhere(hostId, hostname = typeof location === 'undefined' ? '' : location.hostname) {
|
|
60
|
-
return isApp() || Boolean(hostId === null || hostId === void 0 ? void 0 : hostId.startsWith('relay ')) || !['localhost', '127.0.0.1', '[::1]', '::1'].includes(hostname);
|
|
61
|
-
}
|
|
62
|
-
WorkbenchUtil.elsewhere = elsewhere;
|
|
63
|
-
/** In the Ta app on a phone, where no ta serve serves the page: it reaches one through a relay. */
|
|
64
|
-
function isApp() {
|
|
65
|
-
var _a, _b;
|
|
66
|
-
return Boolean((_b = (_a = globalThis.Capacitor) === null || _a === void 0 ? void 0 : _a.isNativePlatform) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
67
|
-
}
|
|
68
|
-
WorkbenchUtil.isApp = isApp;
|
|
69
|
-
function readPairing(text) {
|
|
70
|
-
try {
|
|
71
|
-
return text ? RelayPairingUtil.parse(RelayPairingUtil.link(JSON.parse(text))) : undefined;
|
|
72
|
-
}
|
|
73
|
-
catch (_a) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
WorkbenchUtil.readPairing = readPairing;
|
|
78
|
-
/**
|
|
79
|
-
* Whether the server of the page answers at all. A WebSocket that does not open cannot say why: a
|
|
80
|
-
* server that answers refused the token; none means ta serve is not running (the installed app opens
|
|
81
|
-
* from its service worker then).
|
|
82
|
-
*/
|
|
83
|
-
async function reachable(base, fetcher = fetch) {
|
|
84
|
-
try {
|
|
85
|
-
await fetcher(base, { method: 'HEAD', cache: 'no-store' });
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
catch (_a) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
WorkbenchUtil.reachable = reachable;
|
|
93
|
-
/** The hosts kept in `storage`; the token or pairing an older version kept becomes the first. */
|
|
94
|
-
function readHosts(storage, now = Date.now()) {
|
|
95
|
-
const text = storage === null || storage === void 0 ? void 0 : storage.getItem(HostUtil.KEY);
|
|
96
|
-
if (text || !storage) {
|
|
97
|
-
return HostUtil.read(text);
|
|
98
|
-
}
|
|
99
|
-
const pairing = readPairing(storage.getItem(PAIRING_KEY));
|
|
100
|
-
const token = storage.getItem(TOKEN_KEY);
|
|
101
|
-
const credential = pairing ? { pairing } : token ? { token } : undefined;
|
|
102
|
-
storage.removeItem(PAIRING_KEY);
|
|
103
|
-
storage.removeItem(TOKEN_KEY);
|
|
104
|
-
return credential ? HostUtil.use({ hosts: [] }, serverOf(credential, pageHost()), credential, now) : { hosts: [] };
|
|
105
|
-
}
|
|
106
|
-
WorkbenchUtil.readHosts = readHosts;
|
|
107
|
-
/** Which ta serve a credential reaches, to know whose lists were kept. */
|
|
108
|
-
function serverOf(credential, host) {
|
|
109
|
-
return 'pairing' in credential ? `relay ${credential.pairing.relay} ${credential.pairing.host}` : `serve ${host}`;
|
|
110
|
-
}
|
|
111
|
-
WorkbenchUtil.serverOf = serverOf;
|
|
112
|
-
/** Where the lists of `of` are kept: each computer has its own, to show at once when switched to. */
|
|
113
|
-
function listsKey(of) {
|
|
114
|
-
return `${LISTS_KEY} ${of}`;
|
|
115
|
-
}
|
|
116
|
-
WorkbenchUtil.listsKey = listsKey;
|
|
117
|
-
/** The lists kept for `of`, none running: whether one runs is known once connected. */
|
|
118
|
-
function readLists(text, of) {
|
|
119
|
-
try {
|
|
120
|
-
const kept = text ? JSON.parse(text) : undefined;
|
|
121
|
-
if ((kept === null || kept === void 0 ? void 0 : kept.of) !== of || !Array.isArray(kept.sessions) || !Array.isArray(kept.saved)) {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
return { server: kept.server, sessions: kept.sessions.map(session => ({ ...session, isStreaming: false })), saved: kept.saved };
|
|
125
|
-
}
|
|
126
|
-
catch (_a) {
|
|
127
|
-
return undefined;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
WorkbenchUtil.readLists = readLists;
|
|
131
|
-
/** `previous` if `next` is the same, so that what shows it is not drawn again. */
|
|
132
|
-
function same(previous, next) {
|
|
133
|
-
return JSON.stringify(previous) === JSON.stringify(next) ? previous : next;
|
|
134
|
-
}
|
|
135
|
-
WorkbenchUtil.same = same;
|
|
136
|
-
function retryDelay(attempt) {
|
|
137
|
-
return RETRY_DELAYS_MS[Math.min(attempt, RETRY_DELAYS_MS.length - 1)];
|
|
138
|
-
}
|
|
139
|
-
WorkbenchUtil.retryDelay = retryDelay;
|
|
140
|
-
})(WorkbenchUtil || (WorkbenchUtil = {}));
|
|
141
|
-
/** None where the page is not in a browser (tests). */
|
|
142
|
-
function storage() {
|
|
143
|
-
return typeof localStorage === 'undefined' ? undefined : localStorage;
|
|
144
|
-
}
|
|
145
|
-
/** The ta serve that serves the page, whose token a sign-in without a pairing is for. */
|
|
146
|
-
function pageHost() {
|
|
147
|
-
return typeof location === 'undefined' ? '' : location.host;
|
|
148
|
-
}
|
|
14
|
+
import { GRACE_MS, PAGE_BYTES, PROBE_MS, pageHost, SWITCH_MS, storage, WorkbenchError, WorkbenchUtil, } from './workbench-util.js';
|
|
149
15
|
let TaWorkbenchImpl = class TaWorkbenchImpl {
|
|
150
16
|
constructor() {
|
|
151
17
|
this.list = WorkbenchUtil.readHosts(storage());
|
|
@@ -90,11 +90,10 @@ let AssistantWebExtension = class AssistantWebExtension {
|
|
|
90
90
|
})
|
|
91
91
|
.catch(fail);
|
|
92
92
|
};
|
|
93
|
+
/** Deletes it without asking: the lists ask (ui.removeTasks), for one or for many. */
|
|
93
94
|
const remove = async (task) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
pi.ui.closeEditor(editorId(task));
|
|
97
|
-
}
|
|
95
|
+
await this.assistant.removeTask(task.id);
|
|
96
|
+
pi.ui.closeEditor(editorId(task));
|
|
98
97
|
};
|
|
99
98
|
/** What can be done with a task, in its … wherever it shows: stop or take over, then remove (a running one is stopped first). */
|
|
100
99
|
const taskMenu = (task) => {
|
|
@@ -106,7 +105,15 @@ let AssistantWebExtension = class AssistantWebExtension {
|
|
|
106
105
|
: []),
|
|
107
106
|
...(task.takenOver ? [] : [{ key: 'takeOver', label: t('ta.task.takeOver'), icon: lucide_react_1.Hand, run: () => takeOver(task) }]),
|
|
108
107
|
],
|
|
109
|
-
[
|
|
108
|
+
[
|
|
109
|
+
{
|
|
110
|
+
key: 'remove',
|
|
111
|
+
label: t('ta.task.remove'),
|
|
112
|
+
icon: lucide_react_1.Trash2,
|
|
113
|
+
danger: true,
|
|
114
|
+
run: () => void pi.ui.removeTasks([{ title: task.title, removeHint: t('ta.task.removeHint'), remove: () => remove(task) }]),
|
|
115
|
+
},
|
|
116
|
+
],
|
|
110
117
|
].filter(section => section.length > 0);
|
|
111
118
|
};
|
|
112
119
|
const showTasks = () => pi.ui.showView(`${assistant_view_1.ASSISTANT_NAME}/${assistant_view_1.ASSISTANT_TASKS_VIEW}`);
|
|
@@ -124,6 +131,7 @@ let AssistantWebExtension = class AssistantWebExtension {
|
|
|
124
131
|
open: openTask,
|
|
125
132
|
openDouble: () => pi.ui.showView(`${assistant_view_1.ASSISTANT_NAME}/assistant`),
|
|
126
133
|
menu: taskMenu,
|
|
134
|
+
remove,
|
|
127
135
|
});
|
|
128
136
|
pi.registerTasks(tasks);
|
|
129
137
|
const registerPage = () => pi.registerView('assistant', {
|
|
@@ -11,6 +11,8 @@ export interface AssistantTaskActions {
|
|
|
11
11
|
/** Shows the double, where a start waits for the user's go. */
|
|
12
12
|
openDouble(): void;
|
|
13
13
|
menu(task: AssistantTask): WebMenuItem[][];
|
|
14
|
+
/** Deletes it without asking (WebTask.remove). */
|
|
15
|
+
remove(task: AssistantTask): Promise<void>;
|
|
14
16
|
}
|
|
15
17
|
/** What of a task's session the list shows: a new task object only when it changes. */
|
|
16
18
|
interface Shown {
|
|
@@ -154,6 +154,8 @@ class AssistantTaskSource {
|
|
|
154
154
|
origin: task.origin,
|
|
155
155
|
open: () => this.actions.open(task),
|
|
156
156
|
menu: () => this.actions.menu(task),
|
|
157
|
+
remove: () => this.actions.remove(task),
|
|
158
|
+
removeHint: this.actions.t('ta.task.removeHint'),
|
|
157
159
|
};
|
|
158
160
|
}
|
|
159
161
|
}
|
|
@@ -43,6 +43,12 @@ export declare namespace AssistantTaskUtil {
|
|
|
43
43
|
function lastWords(messages: readonly SessionMessage[]): string | undefined;
|
|
44
44
|
/** What the double reads when a task ended. */
|
|
45
45
|
function updateNote(task: AssistantTask): string;
|
|
46
|
+
/** The task a note of updateNote is about, if `text` is one. */
|
|
47
|
+
function noteOf(text: string): {
|
|
48
|
+
id: string;
|
|
49
|
+
title: string;
|
|
50
|
+
status: AssistantTask['status'];
|
|
51
|
+
} | undefined;
|
|
46
52
|
/** What the double reads when the user hands it one of their conversations. */
|
|
47
53
|
function adoptedNote(task: AssistantTask, said: string): string;
|
|
48
54
|
}
|
|
@@ -6,6 +6,8 @@ const message_1 = require("../util/message");
|
|
|
6
6
|
exports.MAX_TASKS = 50;
|
|
7
7
|
/** As much of what a task said as the double reads. */
|
|
8
8
|
const RESULT_CHARS = 4000;
|
|
9
|
+
/** The start of a note of updateNote. */
|
|
10
|
+
const NOTE = /^<task_update id="([^"]+)" title="([^"]*)" status="(\w+)">/;
|
|
9
11
|
/**
|
|
10
12
|
* What the pages of the double agree on about its tasks. Every page of the user lists them, follows those
|
|
11
13
|
* that run and keeps the list on the server: no one page owns them, so a change is a newer copy of a task,
|
|
@@ -93,6 +95,12 @@ var AssistantTaskUtil;
|
|
|
93
95
|
return `<task_update id="${task.id}" title="${task.title}" status="${task.status}">\n${((_a = task.result) !== null && _a !== void 0 ? _a : '').slice(0, RESULT_CHARS)}\n</task_update>`;
|
|
94
96
|
}
|
|
95
97
|
AssistantTaskUtil.updateNote = updateNote;
|
|
98
|
+
/** The task a note of updateNote is about, if `text` is one. */
|
|
99
|
+
function noteOf(text) {
|
|
100
|
+
const match = NOTE.exec(text);
|
|
101
|
+
return match ? { id: match[1], title: match[2], status: match[3] } : undefined;
|
|
102
|
+
}
|
|
103
|
+
AssistantTaskUtil.noteOf = noteOf;
|
|
96
104
|
/** What the double reads when the user hands it one of their conversations. */
|
|
97
105
|
function adoptedNote(task, said) {
|
|
98
106
|
return `<task_adopted id="${task.id}" title="${task.title}" status="${task.status}">\nThe user handed you one of their conversations, in ${task.cwd}: follow it as your task ${task.id}. Its last words:\n${said.slice(0, RESULT_CHARS)}\n</task_adopted>`;
|
|
@@ -62,8 +62,9 @@ exports.ASSISTANT_TASKS_VIEW = 'tasks';
|
|
|
62
62
|
/** Every task, the double's and those of extensions, what waits for the user first: a tool of the workbench beside the conversation. */
|
|
63
63
|
function AssistantTasks() {
|
|
64
64
|
const tasks = (0, hooks_1.useTasks)();
|
|
65
|
+
const remove = (0, hooks_1.useRemoveTasks)();
|
|
65
66
|
return (React.createElement("div", { className: "ta-assistant-tasks" },
|
|
66
|
-
React.createElement(task_views_1.TaskBoardList, { tasks: tasks })));
|
|
67
|
+
React.createElement(task_views_1.TaskBoardList, { tasks: tasks, onRemove: remove })));
|
|
67
68
|
}
|
|
68
69
|
/** The … of a task, from the sections its extension gives: the same entries as in the lists. */
|
|
69
70
|
function sectionItems(sections) {
|
|
@@ -5,6 +5,12 @@ import { TaState } from '../state/state-protocol';
|
|
|
5
5
|
import { TaWorkbench } from '../workbench-protocol';
|
|
6
6
|
import { type AssistantAsk, type AssistantState, type AssistantTask, TaAssistant } from './assistant-protocol';
|
|
7
7
|
import { AssistantTaskBook } from './assistant-task-book';
|
|
8
|
+
/** What the double is to hear of a task that ended (finished), and when it ended. */
|
|
9
|
+
interface TaskNote {
|
|
10
|
+
text: string;
|
|
11
|
+
clientMessageId: string;
|
|
12
|
+
at: number;
|
|
13
|
+
}
|
|
8
14
|
export declare class TaAssistantImpl implements TaAssistant {
|
|
9
15
|
protected readonly workbench: TaWorkbench;
|
|
10
16
|
protected readonly persisted: TaState;
|
|
@@ -23,6 +29,14 @@ export declare class TaAssistantImpl implements TaAssistant {
|
|
|
23
29
|
protected readonly following: Map<string, () => void>;
|
|
24
30
|
/** The answers the asks wait for, by ask id. */
|
|
25
31
|
protected readonly answers: Map<string, (start: boolean) => void>;
|
|
32
|
+
/**
|
|
33
|
+
* The notes of tasks that ended, by task id, held while the double works and until the task stayed
|
|
34
|
+
* ended a moment (flushNotes): one per task, the last, so that a task that ends again and again does
|
|
35
|
+
* not pile notes up in the double's queue.
|
|
36
|
+
*/
|
|
37
|
+
protected readonly notes: Map<string, TaskNote>;
|
|
38
|
+
protected noteTimer?: ReturnType<typeof setTimeout>;
|
|
39
|
+
protected noteSettleMs: number;
|
|
26
40
|
protected unwatchSettings?: () => void;
|
|
27
41
|
protected unwatchTasks?: () => void;
|
|
28
42
|
protected unwatchOnline?: () => void;
|
|
@@ -120,6 +134,12 @@ export declare class TaAssistantImpl implements TaAssistant {
|
|
|
120
134
|
* id of the message is the same in each: the time of the task's last answer, by the computer's clock).
|
|
121
135
|
*/
|
|
122
136
|
protected finished(id: string, state: SessionState): void;
|
|
137
|
+
/**
|
|
138
|
+
* Sends the notes of the tasks that stayed ended a moment, once the double is not at work: what it
|
|
139
|
+
* did not hear yet waits here rather than in its queue, where a task that ended again would add one more.
|
|
140
|
+
*/
|
|
141
|
+
protected flushNotes(): void;
|
|
123
142
|
protected update(change: Partial<AssistantState>): void;
|
|
124
143
|
}
|
|
144
|
+
export {};
|
|
125
145
|
//# sourceMappingURL=assistant.d.ts.map
|
|
@@ -21,6 +21,8 @@ const assistant_state_1 = require("./assistant-state");
|
|
|
21
21
|
const assistant_task_book_1 = require("./assistant-task-book");
|
|
22
22
|
const assistant_task_util_1 = require("./assistant-task-util");
|
|
23
23
|
const { FILE, TASKS, PROMPT, ASKING } = assistant_state_1.AssistantStates;
|
|
24
|
+
/** How long a task stays ended before the double hears of it: an agent that goes on by itself ends and runs again within seconds. */
|
|
25
|
+
const NOTE_SETTLE_MS = 5000;
|
|
24
26
|
let TaAssistantImpl = class TaAssistantImpl {
|
|
25
27
|
constructor() {
|
|
26
28
|
this.current = { ready: false, tasks: [], asks: [] };
|
|
@@ -32,6 +34,13 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
32
34
|
this.following = new Map();
|
|
33
35
|
/** The answers the asks wait for, by ask id. */
|
|
34
36
|
this.answers = new Map();
|
|
37
|
+
/**
|
|
38
|
+
* The notes of tasks that ended, by task id, held while the double works and until the task stayed
|
|
39
|
+
* ended a moment (flushNotes): one per task, the last, so that a task that ends again and again does
|
|
40
|
+
* not pile notes up in the double's queue.
|
|
41
|
+
*/
|
|
42
|
+
this.notes = new Map();
|
|
43
|
+
this.noteSettleMs = NOTE_SETTLE_MS;
|
|
35
44
|
this.asked = 0;
|
|
36
45
|
this.listeners = new Set();
|
|
37
46
|
}
|
|
@@ -375,8 +384,14 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
375
384
|
const store = this.workbench.createStore(sessionId, { clientTools });
|
|
376
385
|
await Promise.all([named ? this.server.setSessionName(sessionId, 'Ta') : undefined, this.applyModel(sessionId, info.model), store.attach()]);
|
|
377
386
|
store.onGone(() => void this.recover(store));
|
|
387
|
+
store.subscribe(state => {
|
|
388
|
+
if (!state.working && this.assistant === store) {
|
|
389
|
+
this.flushNotes();
|
|
390
|
+
}
|
|
391
|
+
});
|
|
378
392
|
this.assistant = store;
|
|
379
393
|
this.update({ ready: true, error: undefined });
|
|
394
|
+
this.flushNotes();
|
|
380
395
|
await this.followRunning(sessions);
|
|
381
396
|
}
|
|
382
397
|
/**
|
|
@@ -519,6 +534,8 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
519
534
|
return;
|
|
520
535
|
}
|
|
521
536
|
if (state.working) {
|
|
537
|
+
// Not ended after all: the double hears of it when it ends again.
|
|
538
|
+
this.notes.delete(id);
|
|
522
539
|
if (task.status !== 'running') {
|
|
523
540
|
this.book.change(id, { status: 'running', endedAt: undefined, result: undefined });
|
|
524
541
|
}
|
|
@@ -535,7 +552,34 @@ let TaAssistantImpl = class TaAssistantImpl {
|
|
|
535
552
|
const { status, result, endedAt, key } = assistant_task_util_1.AssistantTaskUtil.outcome(state);
|
|
536
553
|
this.book.change(id, { status, endedAt: endedAt !== null && endedAt !== void 0 ? endedAt : Date.now(), result });
|
|
537
554
|
this.update({ lastFinished: Date.now() });
|
|
538
|
-
|
|
555
|
+
this.notes.set(id, { text: assistant_task_util_1.AssistantTaskUtil.updateNote(this.book.get(id)), clientMessageId: `task-update:${id}:${key}`, at: Date.now() });
|
|
556
|
+
this.flushNotes();
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Sends the notes of the tasks that stayed ended a moment, once the double is not at work: what it
|
|
560
|
+
* did not hear yet waits here rather than in its queue, where a task that ended again would add one more.
|
|
561
|
+
*/
|
|
562
|
+
flushNotes() {
|
|
563
|
+
clearTimeout(this.noteTimer);
|
|
564
|
+
this.noteTimer = undefined;
|
|
565
|
+
const store = this.assistant;
|
|
566
|
+
if (!this.notes.size || !store || store.state.working) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
const now = Date.now();
|
|
570
|
+
let next = Number.POSITIVE_INFINITY;
|
|
571
|
+
for (const [id, note] of this.notes) {
|
|
572
|
+
const wait = note.at + this.noteSettleMs - now;
|
|
573
|
+
if (wait > 0) {
|
|
574
|
+
next = Math.min(next, wait);
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
this.notes.delete(id);
|
|
578
|
+
void this.send(note.text, 'followUp', note.clientMessageId).catch(() => undefined);
|
|
579
|
+
}
|
|
580
|
+
if (next !== Number.POSITIVE_INFINITY) {
|
|
581
|
+
this.noteTimer = setTimeout(() => this.flushNotes(), next);
|
|
582
|
+
}
|
|
539
583
|
}
|
|
540
584
|
update(change) {
|
|
541
585
|
this.current = { ...this.current, ...change };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { WebTask, WebTaskEntry } from '../extension/web-extension-api';
|
|
2
|
+
import type { WebTask, WebTaskEntry, WebTaskRemoval } from '../extension/web-extension-api';
|
|
3
3
|
import { type Translate } from '../i18n/use-t';
|
|
4
4
|
import type { AssistantAsk } from './assistant-protocol';
|
|
5
5
|
/** The dot of a status, in the colors of the steps of a turn. */
|
|
@@ -23,13 +23,47 @@ export declare const TaskCard: React.MemoExoticComponent<({ task }: {
|
|
|
23
23
|
export declare function TaskCards({ tasks }: {
|
|
24
24
|
tasks: WebTaskEntry[];
|
|
25
25
|
}): React.JSX.Element | null;
|
|
26
|
-
/**
|
|
27
|
-
export
|
|
26
|
+
/** What a list of tasks does with its rows: the same functions for every row, so that a row draws again only for its own change. */
|
|
27
|
+
export interface TaskListActions {
|
|
28
|
+
/** Deletes it once the user agrees. */
|
|
29
|
+
remove(task: WebTaskEntry): void;
|
|
30
|
+
/** The list starts selecting, with it chosen. */
|
|
31
|
+
select(key: string): void;
|
|
32
|
+
/** Chooses it, or no longer, while the list selects. */
|
|
33
|
+
toggle(key: string): void;
|
|
34
|
+
}
|
|
35
|
+
export interface TaskRowProps {
|
|
28
36
|
task: WebTaskEntry;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
|
|
37
|
+
actions?: TaskListActions;
|
|
38
|
+
/** The list selects: a tap chooses the row, `checked` once chosen. */
|
|
39
|
+
selecting?: boolean;
|
|
40
|
+
checked?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A task in a list: its face, its title and what it is at, its time. On a phone a swipe to the left shows
|
|
44
|
+
* Delete behind it, as the other lists; its menu starts selecting several, to delete them at once.
|
|
45
|
+
*/
|
|
46
|
+
export declare const TaskRow: React.MemoExoticComponent<({ task, actions, selecting, checked }: TaskRowProps) => React.JSX.Element>;
|
|
47
|
+
/**
|
|
48
|
+
* Which tasks of a list are chosen while it selects (undefined while it does not), and what its rows do: a
|
|
49
|
+
* swipe deletes one, the menu of one starts selecting, and the bar deletes those chosen, asked once. Those
|
|
50
|
+
* gone from the list are no longer chosen; with none left that can be deleted, it stops selecting.
|
|
51
|
+
*/
|
|
52
|
+
export declare function useTaskSelection(tasks: readonly WebTaskEntry[], remove: (tasks: readonly WebTaskRemoval[]) => Promise<boolean>): {
|
|
53
|
+
actions: TaskListActions;
|
|
54
|
+
selecting: boolean;
|
|
55
|
+
isChosen: (task: WebTaskEntry) => boolean;
|
|
56
|
+
selected: WebTaskEntry[];
|
|
57
|
+
removable: WebTaskEntry[];
|
|
58
|
+
selectAll: (all: boolean) => void;
|
|
59
|
+
done: () => void;
|
|
60
|
+
/** Deletes those chosen once the user agrees, and stops selecting. */
|
|
61
|
+
removeSelected: () => Promise<void>;
|
|
62
|
+
};
|
|
63
|
+
/** Every task: what waits for the user, what runs, then what ended, the latest first. `onRemove` deletes some once the user agrees (useRemoveTasks). */
|
|
64
|
+
export declare function TaskBoardList({ tasks, onRemove }: {
|
|
32
65
|
tasks: readonly WebTaskEntry[];
|
|
66
|
+
onRemove(tasks: readonly WebTaskRemoval[]): Promise<boolean>;
|
|
33
67
|
}): React.JSX.Element;
|
|
34
68
|
/** In the head of the double: how many run and how many wait for the user; the tasks open on a click. */
|
|
35
69
|
export declare function TasksChip({ tasks, onOpen }: {
|
|
@@ -38,6 +38,7 @@ exports.Elapsed = Elapsed;
|
|
|
38
38
|
exports.TaskIcon = TaskIcon;
|
|
39
39
|
exports.taskLine = taskLine;
|
|
40
40
|
exports.TaskCards = TaskCards;
|
|
41
|
+
exports.useTaskSelection = useTaskSelection;
|
|
41
42
|
exports.TaskBoardList = TaskBoardList;
|
|
42
43
|
exports.TasksChip = TasksChip;
|
|
43
44
|
exports.AskCard = AskCard;
|
|
@@ -47,6 +48,8 @@ const context_menu_1 = require("../components/context-menu");
|
|
|
47
48
|
const empty_pictures_1 = require("../components/empty-pictures");
|
|
48
49
|
const empty_state_1 = require("../components/empty-state");
|
|
49
50
|
const icon_1 = require("../components/icon");
|
|
51
|
+
const select_bar_1 = require("../components/select-bar");
|
|
52
|
+
const swipe_row_1 = require("../components/swipe-row");
|
|
50
53
|
const web_tasks_1 = require("../extension/web-tasks");
|
|
51
54
|
const use_t_1 = require("../i18n/use-t");
|
|
52
55
|
// The tasks of the double and of extensions, drawn alike: a card in the turn that started it, a row in the lists.
|
|
@@ -109,21 +112,21 @@ function taskLine(task, t) {
|
|
|
109
112
|
const detail = (_a = task.detail) === null || _a === void 0 ? void 0 : _a.trim();
|
|
110
113
|
return detail && detail !== status ? detail : status;
|
|
111
114
|
}
|
|
112
|
-
function menuItems(task) {
|
|
115
|
+
function menuItems(task, more) {
|
|
113
116
|
var _a;
|
|
114
117
|
var _b;
|
|
115
|
-
return
|
|
118
|
+
return [
|
|
119
|
+
...((_b = (_a = task.menu) === null || _a === void 0 ? void 0 : _a.call(task)) !== null && _b !== void 0 ? _b : []).map(section => section.map(item => ({ label: item.label, disabled: item.disabled, danger: item.danger, run: item.run }))),
|
|
120
|
+
more,
|
|
121
|
+
]
|
|
116
122
|
.filter(section => section.length > 0)
|
|
117
|
-
.flatMap((section, index) => [
|
|
118
|
-
...(index > 0 ? ['-'] : []),
|
|
119
|
-
...section.map(item => ({ label: item.label, disabled: item.disabled, danger: item.danger, run: item.run })),
|
|
120
|
-
]);
|
|
123
|
+
.flatMap((section, index) => [...(index > 0 ? ['-'] : []), ...section]);
|
|
121
124
|
}
|
|
122
|
-
/** A held finger or a right click opens its …; so does the button that shows on hover. */
|
|
123
|
-
function useTaskMenu(task) {
|
|
125
|
+
/** A held finger or a right click opens its …; so does the button that shows on hover. `more`: what the list adds, last. */
|
|
126
|
+
function useTaskMenu(task, more = []) {
|
|
124
127
|
const [menu, openMenu] = (0, context_menu_1.useContextMenu)();
|
|
125
128
|
const open = (event) => {
|
|
126
|
-
const items = menuItems(task);
|
|
129
|
+
const items = menuItems(task, more);
|
|
127
130
|
if (items.length > 0) {
|
|
128
131
|
openMenu(event, items);
|
|
129
132
|
}
|
|
@@ -155,12 +158,18 @@ function TaskCards({ tasks }) {
|
|
|
155
158
|
}
|
|
156
159
|
return (React.createElement("div", { className: "ta-task-cards" }, tasks.map(task => (React.createElement(exports.TaskCard, { key: task.key, task: task })))));
|
|
157
160
|
}
|
|
158
|
-
/**
|
|
159
|
-
|
|
161
|
+
/**
|
|
162
|
+
* A task in a list: its face, its title and what it is at, its time. On a phone a swipe to the left shows
|
|
163
|
+
* Delete behind it, as the other lists; its menu starts selecting several, to delete them at once.
|
|
164
|
+
*/
|
|
165
|
+
exports.TaskRow = React.memo(function TaskRow({ task, actions, selecting = false, checked = false }) {
|
|
160
166
|
const t = (0, use_t_1.useT)();
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
167
|
+
const removable = !!task.remove && !!actions;
|
|
168
|
+
const [menu, openMenu] = useTaskMenu(task, removable ? [{ label: t('ta.tasks.select'), run: () => actions === null || actions === void 0 ? void 0 : actions.select(task.key) }] : []);
|
|
169
|
+
const swipe = removable && !selecting ? [{ key: 'remove', label: t('ta.task.remove'), danger: true, run: () => actions === null || actions === void 0 ? void 0 : actions.remove(task) }] : undefined;
|
|
170
|
+
return (React.createElement(swipe_row_1.SwipeRow, { as: "li", className: `ta-task-row ta-task-${task.status}${selecting ? ' ta-selecting' : ''}`, actions: swipe, overlay: menu, onContextMenu: selecting ? undefined : openMenu },
|
|
171
|
+
React.createElement("button", { type: "button", className: "ta-task-row-main", "aria-pressed": selecting ? checked : undefined, disabled: selecting && !removable, onClick: selecting ? () => actions === null || actions === void 0 ? void 0 : actions.toggle(task.key) : () => task.open() },
|
|
172
|
+
selecting && React.createElement(select_bar_1.SelectCheck, { checked: checked, disabled: !removable }),
|
|
164
173
|
React.createElement(TaskIcon, { task: task, size: 28 }),
|
|
165
174
|
React.createElement("span", { className: "ta-task-row-text" },
|
|
166
175
|
React.createElement("span", { className: "ta-task-row-title" }, task.title),
|
|
@@ -168,29 +177,73 @@ exports.TaskRow = React.memo(function TaskRow({ task }) {
|
|
|
168
177
|
React.createElement("span", { className: `ta-status ta-status-${exports.TASK_DOT[task.status]}` }),
|
|
169
178
|
React.createElement("span", null, taskLine(task, t)))),
|
|
170
179
|
React.createElement(Elapsed, { task: task })),
|
|
171
|
-
task.menu && React.createElement(icon_1.IconButton, { icon: lucide_react_1.MoreHorizontal, label: t('ta.more'), className: "ta-task-more", onClick: openMenu })
|
|
172
|
-
menu));
|
|
180
|
+
(task.menu || removable) && !selecting && React.createElement(icon_1.IconButton, { icon: lucide_react_1.MoreHorizontal, label: t('ta.more'), className: "ta-task-more", onClick: openMenu })));
|
|
173
181
|
});
|
|
174
182
|
const ENDED_SHOWN = 8;
|
|
175
|
-
/**
|
|
176
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Which tasks of a list are chosen while it selects (undefined while it does not), and what its rows do: a
|
|
185
|
+
* swipe deletes one, the menu of one starts selecting, and the bar deletes those chosen, asked once. Those
|
|
186
|
+
* gone from the list are no longer chosen; with none left that can be deleted, it stops selecting.
|
|
187
|
+
*/
|
|
188
|
+
function useTaskSelection(tasks, remove) {
|
|
189
|
+
const [chosen, setChosen] = React.useState();
|
|
190
|
+
const removable = React.useMemo(() => tasks.filter(task => task.remove), [tasks]);
|
|
191
|
+
const selected = chosen ? removable.filter(task => chosen.has(task.key)) : [];
|
|
192
|
+
const selecting = !!chosen && removable.length > 0;
|
|
193
|
+
React.useEffect(() => {
|
|
194
|
+
if (chosen && removable.length === 0) {
|
|
195
|
+
setChosen(undefined);
|
|
196
|
+
}
|
|
197
|
+
}, [chosen, removable.length]);
|
|
198
|
+
const actions = React.useMemo(() => ({
|
|
199
|
+
remove: task => void remove([task]),
|
|
200
|
+
select: key => setChosen(new Set([key])),
|
|
201
|
+
toggle: key => setChosen(before => {
|
|
202
|
+
const next = new Set(before);
|
|
203
|
+
if (!next.delete(key)) {
|
|
204
|
+
next.add(key);
|
|
205
|
+
}
|
|
206
|
+
return next;
|
|
207
|
+
}),
|
|
208
|
+
}), [remove]);
|
|
209
|
+
return {
|
|
210
|
+
actions,
|
|
211
|
+
selecting,
|
|
212
|
+
isChosen: (task) => !!(chosen === null || chosen === void 0 ? void 0 : chosen.has(task.key)),
|
|
213
|
+
selected,
|
|
214
|
+
removable,
|
|
215
|
+
selectAll: (all) => setChosen(new Set(all ? removable.map(task => task.key) : [])),
|
|
216
|
+
done: () => setChosen(undefined),
|
|
217
|
+
/** Deletes those chosen once the user agrees, and stops selecting. */
|
|
218
|
+
removeSelected: async () => {
|
|
219
|
+
if (await remove(selected)) {
|
|
220
|
+
setChosen(undefined);
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/** Every task: what waits for the user, what runs, then what ended, the latest first. `onRemove` deletes some once the user agrees (useRemoveTasks). */
|
|
226
|
+
function TaskBoardList({ tasks, onRemove }) {
|
|
177
227
|
const t = (0, use_t_1.useT)();
|
|
178
228
|
const [all, setAll] = React.useState(false);
|
|
179
229
|
const groups = React.useMemo(() => web_tasks_1.WebTaskUtil.groups(tasks), [tasks]);
|
|
230
|
+
const selection = useTaskSelection(tasks, onRemove);
|
|
180
231
|
if (tasks.length === 0) {
|
|
181
232
|
return React.createElement(empty_state_1.EmptyState, { picture: React.createElement(empty_pictures_1.TasksPicture, null), title: t('ta.assistant.noTasks'), hint: t('ta.assistant.noTasksHint') });
|
|
182
233
|
}
|
|
183
|
-
|
|
234
|
+
// Selecting, every row shows: Select all chooses what the user sees.
|
|
235
|
+
const ended = all || selection.selecting ? groups.ended : groups.ended.slice(0, ENDED_SHOWN);
|
|
184
236
|
const group = (title, list, more) => list.length > 0 && (React.createElement("section", { className: "ta-task-group" },
|
|
185
237
|
React.createElement("div", { className: "ta-task-group-title" },
|
|
186
238
|
React.createElement("span", null, t(title)),
|
|
187
239
|
React.createElement("span", { className: "ta-task-group-count" }, list === ended ? groups.ended.length : list.length)),
|
|
188
|
-
React.createElement("ul", { className: "ta-task-rows" }, list.map(task => (React.createElement(exports.TaskRow, { key: task.key, task: task })))),
|
|
240
|
+
React.createElement("ul", { className: "ta-task-rows" }, list.map(task => (React.createElement(exports.TaskRow, { key: task.key, task: task, actions: selection.actions, selecting: selection.selecting, checked: selection.isChosen(task) })))),
|
|
189
241
|
more));
|
|
190
242
|
return (React.createElement(React.Fragment, null,
|
|
191
243
|
group('ta.tasks.waiting', groups.waiting),
|
|
192
244
|
group('ta.tasks.running', groups.running),
|
|
193
|
-
group('ta.tasks.ended', ended, groups.ended.length > ENDED_SHOWN && (React.createElement("button", { type: "button", className: "ta-task-more-rows", onClick: () => setAll(!all) }, t(all ? 'ta.tasks.fewer' : 'ta.tasks.all', { count: groups.ended.length }))))
|
|
245
|
+
group('ta.tasks.ended', ended, groups.ended.length > ENDED_SHOWN && !selection.selecting && (React.createElement("button", { type: "button", className: "ta-task-more-rows", onClick: () => setAll(!all) }, t(all ? 'ta.tasks.fewer' : 'ta.tasks.all', { count: groups.ended.length })))),
|
|
246
|
+
selection.selecting && (React.createElement(select_bar_1.SelectBar, { count: selection.selected.length, total: selection.removable.length, onSelectAll: selection.selectAll, onDone: selection.done, actions: [{ key: 'remove', label: t('ta.task.remove'), danger: true, run: () => void selection.removeSelected() }] }))));
|
|
194
247
|
}
|
|
195
248
|
/** In the head of the double: how many run and how many wait for the user; the tasks open on a click. */
|
|
196
249
|
function TasksChip({ tasks, onOpen }) {
|