@celljs/ta-host 4.9.1 → 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 +12 -3
- 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.js +3 -0
- 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/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 +9 -8
- 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 +12 -3
- 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.js +3 -0
- 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/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 +9 -8
- 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
|
@@ -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,15 +26,24 @@ 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
|
}
|
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() { }
|
|
@@ -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,
|
|
@@ -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
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TaSessionHandlesImpl = exports.TaSessionHandles = void 0;
|
|
10
|
+
const node_fs_1 = require("node:fs");
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
const core_1 = require("@celljs/core");
|
|
13
|
+
const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
|
|
14
|
+
exports.TaSessionHandles = Symbol('TaSessionHandles');
|
|
15
|
+
/** Handles kept: the latest ones, as a client that slept longer has the conversation in its list again. */
|
|
16
|
+
const MAX_HANDLES = 200;
|
|
17
|
+
/** In ta-sessions.json of the agent directory, the latest last; kept across restarts. */
|
|
18
|
+
let TaSessionHandlesImpl = class TaSessionHandlesImpl {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.file = (0, node_path_1.join)(ta_brand_1.TaBrand.agentDir(), 'ta-sessions.json');
|
|
21
|
+
}
|
|
22
|
+
get(sessionId) {
|
|
23
|
+
return this.read().get(sessionId);
|
|
24
|
+
}
|
|
25
|
+
idOf(sessionFile) {
|
|
26
|
+
for (const [id, handle] of this.read()) {
|
|
27
|
+
if (handle.sessionFile === sessionFile) {
|
|
28
|
+
return id;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
set(sessionId, handle) {
|
|
34
|
+
const handles = this.read();
|
|
35
|
+
// One id per file: the file opened under another is reached by that one.
|
|
36
|
+
for (const [id, other] of handles) {
|
|
37
|
+
if (id !== sessionId && other.sessionFile === handle.sessionFile) {
|
|
38
|
+
handles.delete(id);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
handles.delete(sessionId);
|
|
42
|
+
handles.set(sessionId, handle);
|
|
43
|
+
for (const id of handles.keys()) {
|
|
44
|
+
if (handles.size <= MAX_HANDLES) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
handles.delete(id);
|
|
48
|
+
}
|
|
49
|
+
this.write(handles);
|
|
50
|
+
}
|
|
51
|
+
delete(sessionId) {
|
|
52
|
+
const handles = this.read();
|
|
53
|
+
if (handles.delete(sessionId)) {
|
|
54
|
+
this.write(handles);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
read() {
|
|
58
|
+
if (!this.cache) {
|
|
59
|
+
this.cache = new Map();
|
|
60
|
+
try {
|
|
61
|
+
const data = JSON.parse((0, node_fs_1.readFileSync)(this.file, 'utf8'));
|
|
62
|
+
for (const [id, handle] of Object.entries(data && typeof data === 'object' && !Array.isArray(data) ? data : {})) {
|
|
63
|
+
const { sessionFile, cwd } = (handle !== null && handle !== void 0 ? handle : {});
|
|
64
|
+
if (typeof sessionFile === 'string' && typeof cwd === 'string') {
|
|
65
|
+
this.cache.set(id, handle);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (_a) {
|
|
70
|
+
// None yet, or not readable: no handles.
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return this.cache;
|
|
74
|
+
}
|
|
75
|
+
write(handles) {
|
|
76
|
+
try {
|
|
77
|
+
(0, node_fs_1.writeFileSync)(`${this.file}.tmp`, `${JSON.stringify(Object.fromEntries(handles))}\n`, { mode: 0o600 });
|
|
78
|
+
(0, node_fs_1.renameSync)(`${this.file}.tmp`, this.file);
|
|
79
|
+
}
|
|
80
|
+
catch (_a) {
|
|
81
|
+
// Kept in memory: only a restart forgets them.
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
exports.TaSessionHandlesImpl = TaSessionHandlesImpl;
|
|
86
|
+
exports.TaSessionHandlesImpl = TaSessionHandlesImpl = __decorate([
|
|
87
|
+
(0, core_1.Component)(exports.TaSessionHandles)
|
|
88
|
+
], TaSessionHandlesImpl);
|
|
89
|
+
//# sourceMappingURL=session-handles.js.map
|
|
@@ -11,6 +11,12 @@ export declare namespace SessionInfoUtil {
|
|
|
11
11
|
* a skill the user ran is `/skill:name` and what follows, not the skill's file.
|
|
12
12
|
*/
|
|
13
13
|
function firstMessage(messages: readonly MessageLike[]): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The text of the last message of the user or the agent that has some, on one line and cut to a preview's
|
|
16
|
+
* length, as a messaging app shows the last thing said under its name: without its context, the marks of
|
|
17
|
+
* markdown at the start of its lines, and the thinking and tool calls of the agent.
|
|
18
|
+
*/
|
|
19
|
+
function lastMessage(messages: readonly MessageLike[]): string | undefined;
|
|
14
20
|
/** The time of the last message that has one, else `fallback`. */
|
|
15
21
|
function updatedAt(messages: readonly MessageLike[], fallback: number): number;
|
|
16
22
|
/** The text of the content of a message. */
|
|
@@ -6,6 +6,8 @@ const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
|
6
6
|
var SessionInfoUtil;
|
|
7
7
|
(function (SessionInfoUtil) {
|
|
8
8
|
const LENGTH = 120;
|
|
9
|
+
/** Of the text of the last message, what lastMessage reads: its lines are joined, many of them empty or marks only. */
|
|
10
|
+
const PREVIEW_READ = 2000;
|
|
9
11
|
/**
|
|
10
12
|
* The first line of the first message of the user that has text, without its context, cut to a title's length;
|
|
11
13
|
* a skill the user ran is `/skill:name` and what follows, not the skill's file.
|
|
@@ -15,7 +17,7 @@ var SessionInfoUtil;
|
|
|
15
17
|
if (message.role !== 'user') {
|
|
16
18
|
continue;
|
|
17
19
|
}
|
|
18
|
-
const said = ta_protocol_1.TaMessageContext.strip(text(message.content));
|
|
20
|
+
const said = ta_protocol_1.TaImageNote.strip(ta_protocol_1.TaMessageContext.strip(text(message.content)));
|
|
19
21
|
const skill = ta_protocol_1.TaSkillUse.parse(said);
|
|
20
22
|
const line = (skill ? ta_protocol_1.TaSkillUse.command(skill) : said)
|
|
21
23
|
.split('\n')
|
|
@@ -28,6 +30,36 @@ var SessionInfoUtil;
|
|
|
28
30
|
return undefined;
|
|
29
31
|
}
|
|
30
32
|
SessionInfoUtil.firstMessage = firstMessage;
|
|
33
|
+
/**
|
|
34
|
+
* The text of the last message of the user or the agent that has some, on one line and cut to a preview's
|
|
35
|
+
* length, as a messaging app shows the last thing said under its name: without its context, the marks of
|
|
36
|
+
* markdown at the start of its lines, and the thinking and tool calls of the agent.
|
|
37
|
+
*/
|
|
38
|
+
function lastMessage(messages) {
|
|
39
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
40
|
+
const message = messages[i];
|
|
41
|
+
if (message.role !== 'user' && message.role !== 'assistant') {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const said = message.role === 'user' ? ta_protocol_1.TaImageNote.strip(ta_protocol_1.TaMessageContext.strip(text(message.content))) : ta_protocol_1.TaAgentSummary.strip(text(message.content));
|
|
45
|
+
// A list asks for it every few seconds: only the start of a long reply is read, enough for a preview.
|
|
46
|
+
const line = said
|
|
47
|
+
.slice(0, PREVIEW_READ)
|
|
48
|
+
.split('\n')
|
|
49
|
+
.map(part => part
|
|
50
|
+
.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+\.\s+)/, '')
|
|
51
|
+
.replace(/[*_`]{1,3}/g, '')
|
|
52
|
+
.trim())
|
|
53
|
+
.filter(Boolean)
|
|
54
|
+
.join(' ')
|
|
55
|
+
.replace(/\s+/g, ' ');
|
|
56
|
+
if (line) {
|
|
57
|
+
return line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
SessionInfoUtil.lastMessage = lastMessage;
|
|
31
63
|
/** The time of the last message that has one, else `fallback`. */
|
|
32
64
|
function updatedAt(messages, fallback) {
|
|
33
65
|
for (let i = messages.length - 1; i >= 0; i--) {
|
package/lib/node/ta-access.d.ts
CHANGED
|
@@ -21,6 +21,14 @@ export declare namespace TaAccessUtil {
|
|
|
21
21
|
* calls on its WebSocket only, where a call knows its connection (attach, terminals) and gets pushes.
|
|
22
22
|
*/
|
|
23
23
|
function isHttpCall(request: IncomingMessage): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* What starts this ta serve (`ta serve --host --port --exec`, the desktop app, the gateway) and is read
|
|
26
|
+
* once it listens. Left in its environment, every program of its sessions and terminals would take it: a
|
|
27
|
+
* `ta serve` or a Cell app run there would listen on this one's port, a Ta reached from there would take its token.
|
|
28
|
+
*/
|
|
29
|
+
const SERVE_ENV: string[];
|
|
30
|
+
/** Removes {@link SERVE_ENV} from `env`, for what this process starts. */
|
|
31
|
+
function releaseServeEnv(env: NodeJS.ProcessEnv): void;
|
|
24
32
|
/** The token goes in the fragment, which the browser does not send to the server or in `Referer`. */
|
|
25
33
|
function webUrl(httpUrl: string, token: string): string;
|
|
26
34
|
/**
|
|
@@ -40,6 +48,9 @@ export declare namespace TaAccessUtil {
|
|
|
40
48
|
export declare class TaAccess implements RpcWebSocketGuard, Middleware, ServerAware, ApplicationLifecycle<Application> {
|
|
41
49
|
readonly priority = 10000;
|
|
42
50
|
readonly token: string;
|
|
51
|
+
/** Read before the environment lets them go (TaAccessUtil.releaseServeEnv). */
|
|
52
|
+
protected readonly chosenToken: boolean;
|
|
53
|
+
protected readonly openWeb: boolean;
|
|
43
54
|
protected readonly host?: string;
|
|
44
55
|
protected readonly sessions: TaSessionRegistry;
|
|
45
56
|
protected readonly signIn: TaSignIn;
|