@celljs/ta-host 4.9.0 → 4.10.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 +1 -1
- package/README.md +1 -1
- package/esm/node/event-log.d.ts +2 -1
- package/esm/node/event-log.js +3 -2
- package/esm/node/exec-environment-factory.d.ts +7 -0
- package/esm/node/exec-environment-factory.js +30 -7
- package/esm/node/host-protocol.d.ts +14 -5
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/remote/remote-hosts.d.ts +1 -3
- package/esm/node/remote/remote-hosts.js +0 -15
- package/esm/node/remote/remote-protocol.d.ts +0 -2
- package/esm/node/remote/remote-server-impl.js +1 -1
- package/esm/node/remote-ui-context.d.ts +1 -1
- package/esm/node/remote-ui-context.js +3 -1
- package/esm/node/session-catalog.d.ts +1 -1
- package/esm/node/session-catalog.js +8 -3
- package/esm/node/session-handles.d.ts +32 -0
- package/esm/node/session-handles.js +86 -0
- package/esm/node/session-info-util.d.ts +6 -0
- package/esm/node/session-info-util.js +34 -2
- package/esm/node/sign-in/sign-in-pages.js +7 -1
- package/esm/node/ta-access.d.ts +11 -0
- package/esm/node/ta-access.js +29 -3
- package/esm/node/ta-errors.js +17 -2
- package/esm/node/ta-event-util.d.ts +12 -2
- package/esm/node/ta-event-util.js +71 -3
- package/esm/node/ta-server-impl.d.ts +0 -2
- package/esm/node/ta-server-impl.js +11 -10
- package/esm/node/ta-session-factory.d.ts +10 -1
- package/esm/node/ta-session-factory.js +22 -2
- package/esm/node/ta-session-registry.d.ts +12 -1
- package/esm/node/ta-session-registry.js +71 -20
- package/esm/node/ta-session.d.ts +9 -5
- package/esm/node/ta-session.js +18 -10
- package/esm/node/workspace-files.d.ts +15 -5
- package/esm/node/workspace-files.js +22 -15
- package/esm/node/workspace-protocol.d.ts +1 -1
- package/esm/node/workspace-util.d.ts +2 -0
- package/esm/node/workspace-util.js +8 -3
- package/lib/node/event-log.d.ts +2 -1
- package/lib/node/event-log.js +3 -2
- package/lib/node/exec-environment-factory.d.ts +7 -0
- package/lib/node/exec-environment-factory.js +30 -7
- package/lib/node/host-protocol.d.ts +14 -5
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/remote/remote-hosts.d.ts +1 -3
- package/lib/node/remote/remote-hosts.js +0 -15
- package/lib/node/remote/remote-protocol.d.ts +0 -2
- package/lib/node/remote/remote-server-impl.js +1 -1
- package/lib/node/remote-ui-context.d.ts +1 -1
- package/lib/node/remote-ui-context.js +3 -1
- package/lib/node/session-catalog.d.ts +1 -1
- package/lib/node/session-catalog.js +8 -3
- package/lib/node/session-handles.d.ts +33 -0
- package/lib/node/session-handles.js +89 -0
- package/lib/node/session-info-util.d.ts +6 -0
- package/lib/node/session-info-util.js +33 -1
- package/lib/node/sign-in/sign-in-pages.js +7 -1
- package/lib/node/ta-access.d.ts +11 -0
- package/lib/node/ta-access.js +29 -3
- package/lib/node/ta-errors.js +17 -2
- package/lib/node/ta-event-util.d.ts +12 -2
- package/lib/node/ta-event-util.js +71 -3
- package/lib/node/ta-server-impl.d.ts +0 -2
- package/lib/node/ta-server-impl.js +11 -10
- package/lib/node/ta-session-factory.d.ts +10 -1
- package/lib/node/ta-session-factory.js +23 -3
- package/lib/node/ta-session-registry.d.ts +12 -1
- package/lib/node/ta-session-registry.js +71 -20
- package/lib/node/ta-session.d.ts +9 -5
- package/lib/node/ta-session.js +18 -10
- package/lib/node/workspace-files.d.ts +15 -5
- package/lib/node/workspace-files.js +22 -15
- package/lib/node/workspace-protocol.d.ts +1 -1
- package/lib/node/workspace-util.d.ts +2 -0
- package/lib/node/workspace-util.js +8 -3
- package/package.json +12 -12
package/esm/node/ta-session.js
CHANGED
|
@@ -13,15 +13,18 @@ import { TaEventUtil } from './ta-event-util.js';
|
|
|
13
13
|
*/
|
|
14
14
|
export class TaSession {
|
|
15
15
|
constructor(context) {
|
|
16
|
+
var _a;
|
|
16
17
|
this.context = context;
|
|
17
|
-
this.id = randomUUID();
|
|
18
18
|
this.createdAt = Date.now();
|
|
19
19
|
this.receipts = new ReceiptBook();
|
|
20
20
|
this.channels = new Set();
|
|
21
21
|
this.live = new LiveRun();
|
|
22
22
|
this.started = false;
|
|
23
23
|
this.runtime = context.runtime;
|
|
24
|
-
this.
|
|
24
|
+
this.id = (_a = context.id) !== null && _a !== void 0 ? _a : randomUUID();
|
|
25
|
+
// Opened again: its seqs start past any the session gave before (fewer than one per millisecond), so a
|
|
26
|
+
// client that attaches with one of those gets the conversation again rather than events of another log.
|
|
27
|
+
this.log = new EventLog(this.id, context.options.eventBufferBytes, context.id ? Date.now() : 0);
|
|
25
28
|
this.ui = new RemoteUiContext(event => this.publish(event));
|
|
26
29
|
context.clientTools.connect(event => this.publish(event));
|
|
27
30
|
}
|
|
@@ -49,6 +52,7 @@ export class TaSession {
|
|
|
49
52
|
sessionFile: pi.sessionFile,
|
|
50
53
|
sessionName: pi.sessionName,
|
|
51
54
|
firstMessage: SessionInfoUtil.firstMessage(pi.messages),
|
|
55
|
+
lastMessage: SessionInfoUtil.lastMessage(pi.messages),
|
|
52
56
|
model: model ? `${model.provider}/${model.id}` : undefined,
|
|
53
57
|
isStreaming: pi.isStreaming,
|
|
54
58
|
messageCount: pi.messages.length,
|
|
@@ -65,9 +69,7 @@ export class TaSession {
|
|
|
65
69
|
return {
|
|
66
70
|
info: this.info(),
|
|
67
71
|
events,
|
|
68
|
-
conversation: afterSeq === undefined || gap
|
|
69
|
-
? MessagePage.recent(this.live.conversation(this.pi.messages, this.pi.isStreaming), options.recentBytes)
|
|
70
|
-
: undefined,
|
|
72
|
+
conversation: afterSeq === undefined || gap ? MessagePage.recent(this.conversation(), options.recentBytes) : undefined,
|
|
71
73
|
pendingUi: this.ui.pendingRequests,
|
|
72
74
|
shownUi: this.ui.shownRequests,
|
|
73
75
|
pendingClientTools: this.context.clientTools.pendingRequests,
|
|
@@ -76,7 +78,11 @@ export class TaSession {
|
|
|
76
78
|
};
|
|
77
79
|
}
|
|
78
80
|
earlierMessages(before, timestamp, budget) {
|
|
79
|
-
return MessagePage.before(this.
|
|
81
|
+
return MessagePage.before(this.conversation().messages, before, timestamp, budget);
|
|
82
|
+
}
|
|
83
|
+
/** The conversation of the events sent, as clients get it. */
|
|
84
|
+
conversation() {
|
|
85
|
+
return TaEventUtil.leanConversation(this.live.conversation(this.pi.messages, this.pi.isStreaming));
|
|
80
86
|
}
|
|
81
87
|
detach(channel) {
|
|
82
88
|
if (this.channels.delete(channel)) {
|
|
@@ -156,12 +162,14 @@ export class TaSession {
|
|
|
156
162
|
* (a tool that ignores the abort, a stream that hangs) or an extension slow to shut down is given
|
|
157
163
|
* `closeTimeoutMs`; then pi is cut off from its agent, so that nothing more goes into the file.
|
|
158
164
|
*/
|
|
159
|
-
async close() {
|
|
165
|
+
async close(announce = true) {
|
|
160
166
|
var _a;
|
|
161
167
|
clearTimeout(this.idleTimer);
|
|
162
168
|
this.ui.cancelAll();
|
|
163
169
|
this.context.clientTools.cancelAll();
|
|
164
|
-
|
|
170
|
+
if (announce) {
|
|
171
|
+
this.publish({ type: 'session_closed' });
|
|
172
|
+
}
|
|
165
173
|
this.channels.clear();
|
|
166
174
|
(_a = this.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
167
175
|
try {
|
|
@@ -197,7 +205,7 @@ export class TaSession {
|
|
|
197
205
|
}
|
|
198
206
|
try {
|
|
199
207
|
const disposition = await run();
|
|
200
|
-
return { clientMessageId: input.clientMessageId, status: disposition === '
|
|
208
|
+
return { clientMessageId: input.clientMessageId, status: disposition === 'started' ? 'accepted' : disposition };
|
|
201
209
|
}
|
|
202
210
|
catch (error) {
|
|
203
211
|
this.receipts.forget(input.clientMessageId);
|
|
@@ -255,7 +263,7 @@ export class TaSession {
|
|
|
255
263
|
clearTimeout(this.idleTimer);
|
|
256
264
|
this.idleTimer = undefined;
|
|
257
265
|
if (this.isIdle()) {
|
|
258
|
-
this.idleTimer = setTimeout(() => this.isIdle() && this.context.requestClose(this), this.context.options.idleTimeoutMs);
|
|
266
|
+
this.idleTimer = setTimeout(() => this.isIdle() && this.context.requestClose(this, true), this.context.options.idleTimeoutMs);
|
|
259
267
|
this.idleTimer.unref();
|
|
260
268
|
}
|
|
261
269
|
}
|
|
@@ -23,20 +23,30 @@ export declare namespace WorkspaceFilesUtil {
|
|
|
23
23
|
/**
|
|
24
24
|
* Answers `GET /api/files/<id>/<path>` with the bytes of a file, without the token of ta serve: `<id>`
|
|
25
25
|
* stands for one directory, and only who has the token learns it (TaWorkspaceServer.fileUrl). Paths stay inside
|
|
26
|
-
* that directory; a directory answers its `index.html`. One range is served, so that videos seek.
|
|
26
|
+
* that directory; a directory answers its `index.html`. One range is served, so that videos seek. A file
|
|
27
|
+
* outside the directory of the conversation (a picture an agent left in `/tmp`) has the directory it is in
|
|
28
|
+
* as its own: who has the token runs programs there anyway, and the pages of the workspace still cannot
|
|
29
|
+
* reach it.
|
|
27
30
|
*/
|
|
28
31
|
export declare class DefaultWorkspaceFiles implements WorkspaceFiles, Middleware {
|
|
29
32
|
/** Before TaAccess, which turns away `/api` requests without the token. */
|
|
30
33
|
readonly priority: number;
|
|
31
34
|
protected readonly environments: ExecEnvironmentFactory;
|
|
32
35
|
protected readonly host?: string;
|
|
33
|
-
|
|
36
|
+
/** By id, the directory paths stay in, and the one whose execution environment reads them. */
|
|
37
|
+
protected readonly directories: Map<string, {
|
|
38
|
+
root: string;
|
|
39
|
+
cwd: string;
|
|
40
|
+
}>;
|
|
34
41
|
protected readonly ids: Map<string, string>;
|
|
35
42
|
url(cwd: string, path: string): string;
|
|
36
43
|
handle(ctx: Context, next: () => Promise<void>): Promise<void>;
|
|
37
|
-
protected send(request: IncomingMessage, response: ServerResponse,
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
protected send(request: IncomingMessage, response: ServerResponse, directory: {
|
|
45
|
+
root: string;
|
|
46
|
+
cwd: string;
|
|
47
|
+
}, path: string): Promise<void>;
|
|
48
|
+
/** The file at `path` of `root`, or the `index.html` of the directory there. */
|
|
49
|
+
protected find(env: ExecEnvironment, root: string, path: string): Promise<{
|
|
40
50
|
absolute: string;
|
|
41
51
|
stat: FileStat;
|
|
42
52
|
} | undefined>;
|
|
@@ -9,6 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { randomBytes } from 'node:crypto';
|
|
11
11
|
import { createReadStream } from 'node:fs';
|
|
12
|
+
import { dirname, resolve } from 'node:path';
|
|
12
13
|
import { Autowired, Component, Value } from '@celljs/core';
|
|
13
14
|
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
14
15
|
import { TA_FILES_PATH } from '@celljs/ta-protocol';
|
|
@@ -117,24 +118,30 @@ export var WorkspaceFilesUtil;
|
|
|
117
118
|
/**
|
|
118
119
|
* Answers `GET /api/files/<id>/<path>` with the bytes of a file, without the token of ta serve: `<id>`
|
|
119
120
|
* stands for one directory, and only who has the token learns it (TaWorkspaceServer.fileUrl). Paths stay inside
|
|
120
|
-
* that directory; a directory answers its `index.html`. One range is served, so that videos seek.
|
|
121
|
+
* that directory; a directory answers its `index.html`. One range is served, so that videos seek. A file
|
|
122
|
+
* outside the directory of the conversation (a picture an agent left in `/tmp`) has the directory it is in
|
|
123
|
+
* as its own: who has the token runs programs there anyway, and the pages of the workspace still cannot
|
|
124
|
+
* reach it.
|
|
121
125
|
*/
|
|
122
126
|
let DefaultWorkspaceFiles = class DefaultWorkspaceFiles {
|
|
123
127
|
constructor() {
|
|
124
128
|
/** Before TaAccess, which turns away `/api` requests without the token. */
|
|
125
129
|
this.priority = ACCESS_MIDDLEWARE_PRIORITY + 1;
|
|
130
|
+
/** By id, the directory paths stay in, and the one whose execution environment reads them. */
|
|
126
131
|
this.directories = new Map();
|
|
127
132
|
this.ids = new Map();
|
|
128
133
|
}
|
|
129
134
|
url(cwd, path) {
|
|
130
|
-
const
|
|
131
|
-
|
|
135
|
+
const absolute = resolve(cwd, path || '.');
|
|
136
|
+
const root = WorkspaceUtil.contains(cwd, absolute) ? cwd : dirname(absolute);
|
|
137
|
+
const key = `${cwd}\0${root}`;
|
|
138
|
+
let id = this.ids.get(key);
|
|
132
139
|
if (!id) {
|
|
133
140
|
id = randomBytes(ID_BYTES).toString('base64url');
|
|
134
|
-
this.ids.set(
|
|
135
|
-
this.directories.set(id, cwd);
|
|
141
|
+
this.ids.set(key, id);
|
|
142
|
+
this.directories.set(id, { root, cwd });
|
|
136
143
|
}
|
|
137
|
-
return WorkspaceFilesUtil.url(id, relative);
|
|
144
|
+
return WorkspaceFilesUtil.url(id, WorkspaceUtil.inside(root, absolute).relative);
|
|
138
145
|
}
|
|
139
146
|
async handle(ctx, next) {
|
|
140
147
|
const request = ctx.request;
|
|
@@ -144,8 +151,8 @@ let DefaultWorkspaceFiles = class DefaultWorkspaceFiles {
|
|
|
144
151
|
return;
|
|
145
152
|
}
|
|
146
153
|
const response = ctx.response;
|
|
147
|
-
const
|
|
148
|
-
if (!
|
|
154
|
+
const directory = this.directories.get(target.id);
|
|
155
|
+
if (!directory || !this.acceptsHost(request)) {
|
|
149
156
|
this.fail(response, 404);
|
|
150
157
|
return;
|
|
151
158
|
}
|
|
@@ -154,11 +161,11 @@ let DefaultWorkspaceFiles = class DefaultWorkspaceFiles {
|
|
|
154
161
|
this.fail(response, 405);
|
|
155
162
|
return;
|
|
156
163
|
}
|
|
157
|
-
await this.send(request, response,
|
|
164
|
+
await this.send(request, response, directory, target.path);
|
|
158
165
|
}
|
|
159
|
-
async send(request, response,
|
|
160
|
-
const env = this.environments.create(cwd);
|
|
161
|
-
const file = await this.find(env, path);
|
|
166
|
+
async send(request, response, directory, path) {
|
|
167
|
+
const env = this.environments.create(directory.cwd);
|
|
168
|
+
const file = await this.find(env, directory.root, path);
|
|
162
169
|
if (!file) {
|
|
163
170
|
this.fail(response, 404);
|
|
164
171
|
return;
|
|
@@ -205,11 +212,11 @@ let DefaultWorkspaceFiles = class DefaultWorkspaceFiles {
|
|
|
205
212
|
response.end(await this.read(env, absolute, stat.size, start, end));
|
|
206
213
|
}
|
|
207
214
|
}
|
|
208
|
-
/** The file at `path`, or the `index.html` of the directory there. */
|
|
209
|
-
async find(env, path) {
|
|
215
|
+
/** The file at `path` of `root`, or the `index.html` of the directory there. */
|
|
216
|
+
async find(env, root, path) {
|
|
210
217
|
let absolute;
|
|
211
218
|
try {
|
|
212
|
-
absolute = WorkspaceUtil.inside(
|
|
219
|
+
absolute = WorkspaceUtil.inside(root, path).absolute;
|
|
213
220
|
}
|
|
214
221
|
catch (_a) {
|
|
215
222
|
return undefined;
|
|
@@ -17,6 +17,6 @@ export interface TaWorkspace {
|
|
|
17
17
|
}
|
|
18
18
|
/** The bytes of workspace files over plain HTTP, for the page to show them as they are (TaWorkspaceServer.fileUrl). */
|
|
19
19
|
export interface WorkspaceFiles {
|
|
20
|
-
/** The URL of `path` of `cwd`;
|
|
20
|
+
/** The URL of `path` of `cwd`; a file outside `cwd` is served from the directory it is in. */
|
|
21
21
|
url(cwd: string, path: string): string;
|
|
22
22
|
}
|
|
@@ -8,6 +8,8 @@ export declare namespace WorkspaceUtil {
|
|
|
8
8
|
absolute: string;
|
|
9
9
|
relative: string;
|
|
10
10
|
};
|
|
11
|
+
/** Whether `absolute` is `cwd` or inside it. */
|
|
12
|
+
function contains(cwd: string, absolute: string): boolean;
|
|
11
13
|
/** Joins a relative path of a directory with a name, with `/`. */
|
|
12
14
|
function join(dir: string, name: string): string;
|
|
13
15
|
/** Directories first, then by name as people sort (`file2` before `file10`). */
|
|
@@ -9,13 +9,18 @@ export var WorkspaceUtil;
|
|
|
9
9
|
/** `path` inside `cwd`, absolute, and relative with `/`; throws when it leaves `cwd`. */
|
|
10
10
|
function inside(cwd, path) {
|
|
11
11
|
const absolute = resolve(cwd, path || '.');
|
|
12
|
-
|
|
13
|
-
if (rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
12
|
+
if (!contains(cwd, absolute)) {
|
|
14
13
|
throw TaErrors.invalidArgument(`The path ${path} is outside of ${cwd}.`, 'Pass a path inside the directory of the workspace.');
|
|
15
14
|
}
|
|
16
|
-
return { absolute, relative:
|
|
15
|
+
return { absolute, relative: relative(cwd, absolute).split(sep).join('/') };
|
|
17
16
|
}
|
|
18
17
|
WorkspaceUtil.inside = inside;
|
|
18
|
+
/** Whether `absolute` is `cwd` or inside it. */
|
|
19
|
+
function contains(cwd, absolute) {
|
|
20
|
+
const rel = relative(cwd, absolute);
|
|
21
|
+
return rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
22
|
+
}
|
|
23
|
+
WorkspaceUtil.contains = contains;
|
|
19
24
|
/** Joins a relative path of a directory with a name, with `/`. */
|
|
20
25
|
function join(dir, name) {
|
|
21
26
|
return dir && dir !== '.' ? posix.join(dir, name) : name;
|
package/lib/node/event-log.d.ts
CHANGED
|
@@ -15,7 +15,8 @@ export declare class EventLog {
|
|
|
15
15
|
protected head: number;
|
|
16
16
|
protected bytes: number;
|
|
17
17
|
protected seq: number;
|
|
18
|
-
|
|
18
|
+
/** `firstSeq`: the seq before the first event; a session opened again under its id starts past those its clients saw. */
|
|
19
|
+
constructor(sessionId: string, maxBytes: number, firstSeq?: number);
|
|
19
20
|
get lastSeq(): number;
|
|
20
21
|
append(event: TaEvent): LoggedEvent;
|
|
21
22
|
/** The events after `afterSeq`; `gap` when some of them are gone. */
|
package/lib/node/event-log.js
CHANGED
|
@@ -6,13 +6,14 @@ exports.EventLog = void 0;
|
|
|
6
6
|
* what happened is in the session file, and a client that fell further behind reads it again.
|
|
7
7
|
*/
|
|
8
8
|
class EventLog {
|
|
9
|
-
|
|
9
|
+
/** `firstSeq`: the seq before the first event; a session opened again under its id starts past those its clients saw. */
|
|
10
|
+
constructor(sessionId, maxBytes, firstSeq = 0) {
|
|
10
11
|
this.sessionId = sessionId;
|
|
11
12
|
this.maxBytes = maxBytes;
|
|
12
13
|
this.entries = [];
|
|
13
14
|
this.head = 0;
|
|
14
15
|
this.bytes = 0;
|
|
15
|
-
this.seq =
|
|
16
|
+
this.seq = firstSeq;
|
|
16
17
|
}
|
|
17
18
|
get lastSeq() {
|
|
18
19
|
return this.seq;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ExecClient, type ExecEnvironment, ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
2
|
+
import { TaLocation } from '@celljs/ta-protocol';
|
|
2
3
|
import { type TaExecOptions } from './host-protocol';
|
|
3
4
|
import { RemoteHosts } from './remote/remote-protocol';
|
|
4
5
|
import { TaWorkingDirectory } from './working-directory';
|
|
@@ -15,8 +16,14 @@ export declare class DefaultExecEnvironmentFactory implements ExecEnvironmentFac
|
|
|
15
16
|
protected client?: ExecClient;
|
|
16
17
|
/** Its `cwd` is the path there: the one to resolve paths against, not the location. */
|
|
17
18
|
create(location: string): ExecEnvironment;
|
|
19
|
+
/**
|
|
20
|
+
* A location as the user wrote it, whole: `~` is the home directory of its machine (where ssh starts
|
|
21
|
+
* there, and where the exec server started), and a relative path is under the default directory.
|
|
22
|
+
*/
|
|
23
|
+
resolve(location: string): Promise<string>;
|
|
18
24
|
/** The working directory the user chose, else that of this process, or of the exec server. */
|
|
19
25
|
defaultCwd(): Promise<string>;
|
|
26
|
+
protected parse(location: string): TaLocation.Remote | undefined;
|
|
20
27
|
protected remote(): ExecClient | undefined;
|
|
21
28
|
}
|
|
22
29
|
//# sourceMappingURL=exec-environment-factory.d.ts.map
|
|
@@ -10,6 +10,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DefaultExecEnvironmentFactory = void 0;
|
|
13
|
+
const node_os_1 = require("node:os");
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
13
15
|
const core_1 = require("@celljs/core");
|
|
14
16
|
const ta_exec_1 = require("@celljs/ta-exec");
|
|
15
17
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
@@ -26,13 +28,7 @@ const working_directory_1 = require("./working-directory");
|
|
|
26
28
|
let DefaultExecEnvironmentFactory = class DefaultExecEnvironmentFactory {
|
|
27
29
|
/** Its `cwd` is the path there: the one to resolve paths against, not the location. */
|
|
28
30
|
create(location) {
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
remote = ta_protocol_1.TaLocation.parse(location);
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
throw ta_errors_1.TaErrors.invalidArgument(error.message, 'Write ssh://<host>/<absolute path>.');
|
|
35
|
-
}
|
|
31
|
+
const remote = this.parse(location);
|
|
36
32
|
if (remote) {
|
|
37
33
|
if (!remote.path) {
|
|
38
34
|
throw ta_errors_1.TaErrors.invalidArgument(`${location} names no directory.`, 'Resolve it first (TaRemoteServer.resolveLocation), or write its path.');
|
|
@@ -42,6 +38,25 @@ let DefaultExecEnvironmentFactory = class DefaultExecEnvironmentFactory {
|
|
|
42
38
|
const client = this.remote();
|
|
43
39
|
return client ? new ta_exec_1.RemoteExecEnvironment(client, location) : new ta_exec_1.LocalExecEnvironment(location);
|
|
44
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* A location as the user wrote it, whole: `~` is the home directory of its machine (where ssh starts
|
|
43
|
+
* there, and where the exec server started), and a relative path is under the default directory.
|
|
44
|
+
*/
|
|
45
|
+
async resolve(location) {
|
|
46
|
+
var _a;
|
|
47
|
+
var _b;
|
|
48
|
+
const remote = this.parse(location);
|
|
49
|
+
const home = ta_protocol_1.TaLocation.homeRelative(location);
|
|
50
|
+
if (remote) {
|
|
51
|
+
return home === undefined ? location : ta_protocol_1.TaLocation.ssh(remote.host, node_path_1.posix.join((await this.remoteHosts.client(remote.host).info()).cwd, home));
|
|
52
|
+
}
|
|
53
|
+
const info = await ((_a = this.remote()) === null || _a === void 0 ? void 0 : _a.info());
|
|
54
|
+
const path = ((_b = info === null || info === void 0 ? void 0 : info.platform) !== null && _b !== void 0 ? _b : process.platform) === 'win32' ? node_path_1.win32 : node_path_1.posix;
|
|
55
|
+
if (home !== undefined) {
|
|
56
|
+
return path.join(info ? info.cwd : (0, node_os_1.homedir)(), home);
|
|
57
|
+
}
|
|
58
|
+
return path.isAbsolute(location) ? location : path.resolve(await this.defaultCwd(), location);
|
|
59
|
+
}
|
|
45
60
|
/** The working directory the user chose, else that of this process, or of the exec server. */
|
|
46
61
|
async defaultCwd() {
|
|
47
62
|
var _a;
|
|
@@ -52,6 +67,14 @@ let DefaultExecEnvironmentFactory = class DefaultExecEnvironmentFactory {
|
|
|
52
67
|
const client = this.remote();
|
|
53
68
|
return client ? (await client.info()).cwd : process.cwd();
|
|
54
69
|
}
|
|
70
|
+
parse(location) {
|
|
71
|
+
try {
|
|
72
|
+
return ta_protocol_1.TaLocation.parse(location);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw ta_errors_1.TaErrors.invalidArgument(error.message, 'Write ssh://<host>/<absolute path>.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
55
78
|
remote() {
|
|
56
79
|
var _a, _b;
|
|
57
80
|
const { url, token = '', epoch } = (_a = this.options) !== null && _a !== void 0 ? _a : {};
|
|
@@ -26,22 +26,31 @@ export interface TaExecOptions {
|
|
|
26
26
|
epoch?: number;
|
|
27
27
|
}
|
|
28
28
|
export interface TaSessionFactory {
|
|
29
|
-
|
|
29
|
+
/** `id`: the id the session had, when it opens again under it. */
|
|
30
|
+
create(options: TaOpenSessionOptions, requestClose: (session: TaSession, idle?: boolean) => void, id?: string): Promise<TaSession>;
|
|
30
31
|
}
|
|
31
32
|
/** The open sessions. */
|
|
32
33
|
export interface TaSessionRegistry {
|
|
33
34
|
open(options: TaOpenSessionOptions): Promise<TaSession>;
|
|
34
|
-
/**
|
|
35
|
+
/** An open session; throws CELL_TA_SESSION_NOT_FOUND. */
|
|
35
36
|
require(sessionId: string): TaSession;
|
|
37
|
+
/**
|
|
38
|
+
* A session by its id, opened again from its file under that id when the service closed it while idle or
|
|
39
|
+
* by a restart (TaSessionHandles); throws CELL_TA_SESSION_NOT_FOUND when it was closed for good or its
|
|
40
|
+
* file is gone.
|
|
41
|
+
*/
|
|
42
|
+
resolve(sessionId: string): Promise<TaSession>;
|
|
36
43
|
list(): TaSession[];
|
|
37
|
-
|
|
44
|
+
/** `idle`: closed to save its memory (idle, or the service stops), it keeps its id and opens again when called; otherwise for good. */
|
|
45
|
+
close(sessionId: string, idle?: boolean): Promise<void>;
|
|
46
|
+
/** As the service stops: each keeps its id, and opens again when called after the restart. */
|
|
38
47
|
closeAll(): Promise<void>;
|
|
39
48
|
channel(connection: RpcConnection): ClientChannel;
|
|
40
49
|
}
|
|
41
50
|
/** The conversations pi keeps in its session files, open or not. */
|
|
42
51
|
export interface TaSessionCatalog {
|
|
43
|
-
/** The latest first. */
|
|
44
|
-
list(): Promise<TaSavedSessionInfo[]>;
|
|
52
|
+
/** The latest first, without the files of `open` (sessions open now, which are listed as such). */
|
|
53
|
+
list(open?: ReadonlySet<string>): Promise<TaSavedSessionInfo[]>;
|
|
45
54
|
}
|
|
46
55
|
/** The packages pi loads in a directory, and their web extensions. */
|
|
47
56
|
export interface WebExtensionCatalog {
|
package/lib/node/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from './remote';
|
|
|
16
16
|
export * from './remote-ui-context';
|
|
17
17
|
export * from './session-catalog';
|
|
18
18
|
export * from './session-files';
|
|
19
|
+
export * from './session-handles';
|
|
19
20
|
export * from './session-info-util';
|
|
20
21
|
export * from './session-storage';
|
|
21
22
|
export * from './settings-server-impl';
|
package/lib/node/index.js
CHANGED
|
@@ -32,6 +32,7 @@ __exportStar(require("./remote"), exports);
|
|
|
32
32
|
__exportStar(require("./remote-ui-context"), exports);
|
|
33
33
|
__exportStar(require("./session-catalog"), exports);
|
|
34
34
|
__exportStar(require("./session-files"), exports);
|
|
35
|
+
__exportStar(require("./session-handles"), exports);
|
|
35
36
|
__exportStar(require("./session-info-util"), exports);
|
|
36
37
|
__exportStar(require("./session-storage"), exports);
|
|
37
38
|
__exportStar(require("./settings-server-impl"), exports);
|
|
@@ -2,7 +2,7 @@ import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
|
|
|
2
2
|
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
3
3
|
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
4
4
|
import { type ExecClient, SshHost, type SshQuestion } from '@celljs/ta-exec';
|
|
5
|
-
import {
|
|
5
|
+
import { type TaRemoteEvent, type TaRemoteHost, type TaRemotePrompt } from '@celljs/ta-protocol';
|
|
6
6
|
import { TaWorkingDirectory } from '../working-directory';
|
|
7
7
|
import { RemoteHosts, type TaRemoteOptions } from './remote-protocol';
|
|
8
8
|
interface Waiting {
|
|
@@ -25,7 +25,6 @@ export declare class DefaultRemoteHosts implements RemoteHosts, ApplicationLifec
|
|
|
25
25
|
list(): TaRemoteHost[];
|
|
26
26
|
add(host: string): void;
|
|
27
27
|
remove(host: string): Promise<void>;
|
|
28
|
-
resolve(location: string): Promise<string>;
|
|
29
28
|
disconnect(host: string): Promise<void>;
|
|
30
29
|
onDisconnect(listener: (host: string) => void): () => void;
|
|
31
30
|
watch(connection: RpcConnection): TaRemotePrompt[];
|
|
@@ -35,7 +34,6 @@ export declare class DefaultRemoteHosts implements RemoteHosts, ApplicationLifec
|
|
|
35
34
|
protected broadcast(event: TaRemoteEvent): void;
|
|
36
35
|
protected check(host: string): string;
|
|
37
36
|
protected connected(host: string): boolean;
|
|
38
|
-
protected parse(location: string): TaLocation.Remote | undefined;
|
|
39
37
|
}
|
|
40
38
|
export {};
|
|
41
39
|
//# sourceMappingURL=remote-hosts.d.ts.map
|
|
@@ -72,13 +72,6 @@ let DefaultRemoteHosts = class DefaultRemoteHosts {
|
|
|
72
72
|
await this.disconnect(host);
|
|
73
73
|
this.workingDirectory.removeRecentHost(host);
|
|
74
74
|
}
|
|
75
|
-
async resolve(location) {
|
|
76
|
-
const remote = this.parse(location);
|
|
77
|
-
if (!remote || remote.path) {
|
|
78
|
-
return location;
|
|
79
|
-
}
|
|
80
|
-
return ta_protocol_1.TaLocation.ssh(remote.host, (await this.client(remote.host).info()).cwd);
|
|
81
|
-
}
|
|
82
75
|
async disconnect(host) {
|
|
83
76
|
const ssh = this.hosts.get(host);
|
|
84
77
|
this.hosts.delete(host);
|
|
@@ -145,14 +138,6 @@ let DefaultRemoteHosts = class DefaultRemoteHosts {
|
|
|
145
138
|
var _b;
|
|
146
139
|
return (_b = (_a = this.hosts.get(host)) === null || _a === void 0 ? void 0 : _a.client.connected) !== null && _b !== void 0 ? _b : false;
|
|
147
140
|
}
|
|
148
|
-
parse(location) {
|
|
149
|
-
try {
|
|
150
|
-
return ta_protocol_1.TaLocation.parse(location);
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
throw ta_errors_1.TaErrors.invalidArgument(error.message, 'Write ssh://<host>/<absolute path>.');
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
141
|
};
|
|
157
142
|
exports.DefaultRemoteHosts = DefaultRemoteHosts;
|
|
158
143
|
__decorate([
|
|
@@ -23,8 +23,6 @@ export interface RemoteHosts {
|
|
|
23
23
|
add(host: string): void;
|
|
24
24
|
/** Disconnects and drops it from the list of those opened before. */
|
|
25
25
|
remove(host: string): Promise<void>;
|
|
26
|
-
/** The location with the home directory as its path when it has none. */
|
|
27
|
-
resolve(location: string): Promise<string>;
|
|
28
26
|
disconnect(host: string): Promise<void>;
|
|
29
27
|
/** Runs once a host is disconnected on purpose. */
|
|
30
28
|
onDisconnect(listener: (host: string) => void): () => void;
|
|
@@ -29,7 +29,7 @@ let TaRemoteServerImpl = class TaRemoteServerImpl {
|
|
|
29
29
|
return ta_errors_1.TaErrors.guard(() => this.hosts.remove(host));
|
|
30
30
|
}
|
|
31
31
|
resolveLocation(location) {
|
|
32
|
-
return ta_errors_1.TaErrors.guard(() => this.
|
|
32
|
+
return ta_errors_1.TaErrors.guard(() => this.environments.resolve(location));
|
|
33
33
|
}
|
|
34
34
|
forwardPort(port, cwd) {
|
|
35
35
|
return ta_errors_1.TaErrors.guard(async () => this.ports.forward(cwd || (await this.environments.defaultCwd()), port));
|
|
@@ -36,12 +36,12 @@ export declare class RemoteUiContext implements ExtensionUIContext {
|
|
|
36
36
|
setWidget(key: string, content: unknown, options?: {
|
|
37
37
|
placement?: 'aboveEditor' | 'belowEditor';
|
|
38
38
|
}): void;
|
|
39
|
+
setWorkingMessage(message?: string): void;
|
|
39
40
|
setTitle(title: string): void;
|
|
40
41
|
setEditorText(text: string): void;
|
|
41
42
|
pasteToEditor(text: string): void;
|
|
42
43
|
getEditorText(): string;
|
|
43
44
|
onTerminalInput(): () => void;
|
|
44
|
-
setWorkingMessage(): void;
|
|
45
45
|
setWorkingVisible(): void;
|
|
46
46
|
setWorkingIndicator(): void;
|
|
47
47
|
setHiddenThinkingLabel(): void;
|
|
@@ -75,6 +75,9 @@ class RemoteUiContext {
|
|
|
75
75
|
this.keep(`widget:${key}`, (content === null || content === void 0 ? void 0 : content.length) ? request : undefined);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
+
setWorkingMessage(message) {
|
|
79
|
+
this.publish({ type: 'working_message', message: message || undefined });
|
|
80
|
+
}
|
|
78
81
|
setTitle(title) {
|
|
79
82
|
this.tell({ method: 'setTitle', title });
|
|
80
83
|
}
|
|
@@ -91,7 +94,6 @@ class RemoteUiContext {
|
|
|
91
94
|
onTerminalInput() {
|
|
92
95
|
return () => undefined;
|
|
93
96
|
}
|
|
94
|
-
setWorkingMessage() { }
|
|
95
97
|
setWorkingVisible() { }
|
|
96
98
|
setWorkingIndicator() { }
|
|
97
99
|
setHiddenThinkingLabel() { }
|
|
@@ -60,7 +60,7 @@ export declare class DefaultTaSessionCatalog implements TaSessionCatalog {
|
|
|
60
60
|
version: string;
|
|
61
61
|
summary?: SessionSummary;
|
|
62
62
|
}>;
|
|
63
|
-
list(): Promise<TaSavedSessionInfo[]>;
|
|
63
|
+
list(open?: ReadonlySet<string>): Promise<TaSavedSessionInfo[]>;
|
|
64
64
|
/** Where pi keeps the sessions it creates (SessionManager.create without a directory). */
|
|
65
65
|
protected sessionsDir(): Promise<string>;
|
|
66
66
|
protected files(root: string): Promise<string[]>;
|
|
@@ -77,6 +77,7 @@ var SessionCatalogUtil;
|
|
|
77
77
|
let header;
|
|
78
78
|
let sessionName;
|
|
79
79
|
let firstMessage;
|
|
80
|
+
const messages = [];
|
|
80
81
|
let messageCount = 0;
|
|
81
82
|
let updatedAt;
|
|
82
83
|
const marks = [];
|
|
@@ -102,6 +103,7 @@ var SessionCatalogUtil;
|
|
|
102
103
|
const message = entry.message;
|
|
103
104
|
messageCount++;
|
|
104
105
|
firstMessage !== null && firstMessage !== void 0 ? firstMessage : (firstMessage = session_info_util_1.SessionInfoUtil.firstMessage([message]));
|
|
106
|
+
messages.push(message);
|
|
105
107
|
if (typeof message.timestamp === 'number') {
|
|
106
108
|
updatedAt = Math.max(updatedAt !== null && updatedAt !== void 0 ? updatedAt : 0, message.timestamp);
|
|
107
109
|
}
|
|
@@ -117,6 +119,7 @@ var SessionCatalogUtil;
|
|
|
117
119
|
piCwd: typeof header.cwd === 'string' ? header.cwd : '',
|
|
118
120
|
sessionName,
|
|
119
121
|
firstMessage,
|
|
122
|
+
lastMessage: session_info_util_1.SessionInfoUtil.lastMessage(messages),
|
|
120
123
|
messageCount,
|
|
121
124
|
createdAt,
|
|
122
125
|
updatedAt: updatedAt !== null && updatedAt !== void 0 ? updatedAt : createdAt,
|
|
@@ -146,11 +149,13 @@ let DefaultTaSessionCatalog = class DefaultTaSessionCatalog {
|
|
|
146
149
|
/** By file: its size and time when read, and what it held. */
|
|
147
150
|
this.cache = new Map();
|
|
148
151
|
}
|
|
149
|
-
async list() {
|
|
152
|
+
async list(open = new Set()) {
|
|
150
153
|
const files = await this.files(await this.sessionsDir());
|
|
154
|
+
// An open session's file grows with every message: it is not read again for a list that leaves it out.
|
|
155
|
+
const closed = files.filter(file => !open.has(file));
|
|
151
156
|
const sessions = [];
|
|
152
|
-
for (let i = 0; i <
|
|
153
|
-
await Promise.all(
|
|
157
|
+
for (let i = 0; i < closed.length; i += BATCH) {
|
|
158
|
+
await Promise.all(closed.slice(i, i + BATCH).map(async (file) => {
|
|
154
159
|
const summary = await this.summary(file);
|
|
155
160
|
if (summary) {
|
|
156
161
|
const { piCwd, ...info } = summary;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { TaClientToolDefinition } from '@celljs/ta-protocol';
|
|
2
|
+
export declare const TaSessionHandles: unique symbol;
|
|
3
|
+
/** What opens a session again under the id clients have: its file, where it works, the tools its clients run. */
|
|
4
|
+
export interface TaSessionHandle {
|
|
5
|
+
sessionFile: string;
|
|
6
|
+
cwd: string;
|
|
7
|
+
clientTools?: TaClientToolDefinition[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The ids of the sessions ta serve gave, with what opens each again. A session closed while idle, or by a
|
|
11
|
+
* restart, keeps its id: the next call with it opens it again (TaSessionRegistry.resolve), so that a page
|
|
12
|
+
* that slept through it carries on rather than failing with CELL_TA_SESSION_NOT_FOUND. Only a session
|
|
13
|
+
* closed for good (closeSession, an extension that ends it) loses its id.
|
|
14
|
+
*/
|
|
15
|
+
export interface TaSessionHandles {
|
|
16
|
+
get(sessionId: string): TaSessionHandle | undefined;
|
|
17
|
+
/** The id kept for a session file. */
|
|
18
|
+
idOf(sessionFile: string): string | undefined;
|
|
19
|
+
set(sessionId: string, handle: TaSessionHandle): void;
|
|
20
|
+
delete(sessionId: string): void;
|
|
21
|
+
}
|
|
22
|
+
/** In ta-sessions.json of the agent directory, the latest last; kept across restarts. */
|
|
23
|
+
export declare class TaSessionHandlesImpl implements TaSessionHandles {
|
|
24
|
+
protected readonly file: string;
|
|
25
|
+
protected cache?: Map<string, TaSessionHandle>;
|
|
26
|
+
get(sessionId: string): TaSessionHandle | undefined;
|
|
27
|
+
idOf(sessionFile: string): string | undefined;
|
|
28
|
+
set(sessionId: string, handle: TaSessionHandle): void;
|
|
29
|
+
delete(sessionId: string): void;
|
|
30
|
+
protected read(): Map<string, TaSessionHandle>;
|
|
31
|
+
protected write(handles: Map<string, TaSessionHandle>): void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=session-handles.d.ts.map
|