@celljs/ta-host 4.10.0 → 4.11.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 +4 -4
- package/README.md +4 -4
- package/esm/node/client-tool-broker.d.ts +6 -2
- package/esm/node/client-tool-broker.js +11 -4
- package/esm/node/host-protocol.d.ts +12 -7
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/package-hosts.d.ts +6 -0
- package/esm/node/package-hosts.js +36 -1
- package/esm/node/package-server-impl.d.ts +0 -1
- package/esm/node/package-server-impl.js +0 -3
- package/esm/node/relay-bridge.d.ts +12 -2
- package/esm/node/relay-bridge.js +93 -3
- package/esm/node/rooms-bridge.d.ts +60 -0
- package/esm/node/rooms-bridge.js +155 -0
- package/esm/node/session-catalog.d.ts +7 -3
- package/esm/node/session-catalog.js +12 -4
- package/esm/node/session-info-util.d.ts +2 -1
- package/esm/node/session-info-util.js +34 -7
- package/esm/node/session-list-feed.d.ts +28 -0
- package/esm/node/session-list-feed.js +62 -0
- package/esm/node/sign-in/sign-in-flow.d.ts +2 -0
- package/esm/node/sign-in/sign-in-flow.js +9 -0
- package/esm/node/sign-in/sign-in-provider.js +3 -2
- package/esm/node/slash-command-util.d.ts +43 -0
- package/esm/node/slash-command-util.js +105 -0
- package/esm/node/ta-event-util.d.ts +9 -2
- package/esm/node/ta-event-util.js +31 -5
- package/esm/node/ta-server-impl.d.ts +13 -5
- package/esm/node/ta-server-impl.js +34 -16
- package/esm/node/ta-session-factory.d.ts +16 -1
- package/esm/node/ta-session-factory.js +42 -14
- package/esm/node/ta-session-registry.d.ts +4 -1
- package/esm/node/ta-session-registry.js +8 -0
- package/esm/node/ta-session.d.ts +8 -2
- package/esm/node/ta-session.js +41 -4
- package/esm/node/web-extension-catalog.d.ts +5 -1
- package/esm/node/web-extension-catalog.js +15 -19
- package/esm/node/web-extension-util.js +7 -3
- package/esm/node/workspace-files.d.ts +16 -12
- package/esm/node/workspace-files.js +14 -10
- package/esm/node/workspace-protocol.d.ts +1 -1
- package/lib/node/client-tool-broker.d.ts +6 -2
- package/lib/node/client-tool-broker.js +11 -4
- package/lib/node/host-protocol.d.ts +12 -7
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/package-hosts.d.ts +6 -0
- package/lib/node/package-hosts.js +35 -0
- package/lib/node/package-server-impl.d.ts +0 -1
- package/lib/node/package-server-impl.js +0 -3
- package/lib/node/relay-bridge.d.ts +12 -2
- package/lib/node/relay-bridge.js +91 -1
- package/lib/node/rooms-bridge.d.ts +61 -0
- package/lib/node/rooms-bridge.js +158 -0
- package/lib/node/session-catalog.d.ts +7 -3
- package/lib/node/session-catalog.js +12 -4
- package/lib/node/session-info-util.d.ts +2 -1
- package/lib/node/session-info-util.js +34 -7
- package/lib/node/session-list-feed.d.ts +29 -0
- package/lib/node/session-list-feed.js +66 -0
- package/lib/node/sign-in/sign-in-flow.d.ts +2 -0
- package/lib/node/sign-in/sign-in-flow.js +10 -1
- package/lib/node/sign-in/sign-in-provider.js +3 -2
- package/lib/node/slash-command-util.d.ts +44 -0
- package/lib/node/slash-command-util.js +108 -0
- package/lib/node/ta-event-util.d.ts +9 -2
- package/lib/node/ta-event-util.js +31 -5
- package/lib/node/ta-server-impl.d.ts +13 -5
- package/lib/node/ta-server-impl.js +32 -14
- package/lib/node/ta-session-factory.d.ts +16 -1
- package/lib/node/ta-session-factory.js +42 -14
- package/lib/node/ta-session-registry.d.ts +4 -1
- package/lib/node/ta-session-registry.js +8 -0
- package/lib/node/ta-session.d.ts +8 -2
- package/lib/node/ta-session.js +41 -4
- package/lib/node/web-extension-catalog.d.ts +5 -1
- package/lib/node/web-extension-catalog.js +15 -19
- package/lib/node/web-extension-util.js +7 -3
- package/lib/node/workspace-files.d.ts +16 -12
- package/lib/node/workspace-files.js +13 -9
- package/lib/node/workspace-protocol.d.ts +1 -1
- package/package.json +10 -10
|
@@ -10,21 +10,25 @@ const PI_RESOURCES = ['extensions', 'skills', 'prompts', 'themes'];
|
|
|
10
10
|
export var WebExtensionUtil;
|
|
11
11
|
(function (WebExtensionUtil) {
|
|
12
12
|
function describe(pkg) {
|
|
13
|
+
var _a;
|
|
13
14
|
const manifest = readManifest(pkg.root);
|
|
14
|
-
|
|
15
|
+
const lists = Array.isArray((_a = manifest === null || manifest === void 0 ? void 0 : manifest.pi) === null || _a === void 0 ? void 0 : _a.lists) ? manifest.pi.lists.filter((kind) => typeof kind === 'string' && kind !== '') : [];
|
|
16
|
+
return entries(pkg.root, manifest).map(entry => { var _a, _b, _c; var _d, _e; return ({
|
|
15
17
|
id: id(pkg, entry),
|
|
16
|
-
name: (
|
|
18
|
+
name: (_d = manifest === null || manifest === void 0 ? void 0 : manifest.name) !== null && _d !== void 0 ? _d : basename(pkg.root),
|
|
17
19
|
description: manifest === null || manifest === void 0 ? void 0 : manifest.description,
|
|
18
20
|
version: manifest === null || manifest === void 0 ? void 0 : manifest.version,
|
|
19
21
|
scope: pkg.scope,
|
|
20
22
|
origin: pkg.origin,
|
|
21
|
-
enabled: (
|
|
23
|
+
enabled: (_e = pkg.enabled) !== null && _e !== void 0 ? _e : true,
|
|
22
24
|
source: pkg.source,
|
|
23
25
|
entry,
|
|
24
26
|
hash: hash(readFileSync(join(pkg.root, entry), 'utf8')),
|
|
25
27
|
title: text((_a = manifest === null || manifest === void 0 ? void 0 : manifest.pi) === null || _a === void 0 ? void 0 : _a.title),
|
|
26
28
|
icon: icon(manifest),
|
|
27
29
|
activation: pkg.temporary || ((_b = manifest === null || manifest === void 0 ? void 0 : manifest.pi) === null || _b === void 0 ? void 0 : _b.webActivation) === 'open' ? 'open' : 'startup',
|
|
30
|
+
...(typeof ((_c = manifest === null || manifest === void 0 ? void 0 : manifest.pi) === null || _c === void 0 ? void 0 : _c.category) === 'string' && manifest.pi.category ? { category: manifest.pi.category } : {}),
|
|
31
|
+
...(lists.length > 0 ? { lists } : {}),
|
|
28
32
|
...(pkg.temporary ? { temporary: pkg.temporary } : {}),
|
|
29
33
|
}); });
|
|
30
34
|
}
|
|
@@ -2,6 +2,12 @@ import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
|
2
2
|
import { type ExecEnvironment, ExecEnvironmentFactory, type FileStat } from '@celljs/ta-exec';
|
|
3
3
|
import { type Context, Middleware } from '@celljs/web/lib/node';
|
|
4
4
|
import { WorkspaceFiles } from './workspace-protocol.js';
|
|
5
|
+
interface ServedDirectory {
|
|
6
|
+
root: string;
|
|
7
|
+
cwd: string;
|
|
8
|
+
/** The name of the one file of `root` served: a file outside the directory of the conversation. */
|
|
9
|
+
only?: string;
|
|
10
|
+
}
|
|
5
11
|
export declare namespace WorkspaceFilesUtil {
|
|
6
12
|
function contentType(path: string): string;
|
|
7
13
|
/** `/api/files/<id>/<path>`; undefined for other URLs or a path that does not decode. */
|
|
@@ -24,27 +30,24 @@ export declare namespace WorkspaceFilesUtil {
|
|
|
24
30
|
* Answers `GET /api/files/<id>/<path>` with the bytes of a file, without the token of ta serve: `<id>`
|
|
25
31
|
* stands for one directory, and only who has the token learns it (TaWorkspaceServer.fileUrl). Paths stay inside
|
|
26
32
|
* 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
|
|
28
|
-
*
|
|
29
|
-
* reach it.
|
|
33
|
+
* outside the directory of the conversation (a picture an agent left in `/tmp`) has an id of its own that
|
|
34
|
+
* stands for that file alone: the URL needs no token, so it must not open the directory the file is in
|
|
35
|
+
* (the home directory for `~/a.png`, with its keys) nor the pages of the workspace reach it.
|
|
30
36
|
*/
|
|
31
37
|
export declare class DefaultWorkspaceFiles implements WorkspaceFiles, Middleware {
|
|
32
38
|
/** Before TaAccess, which turns away `/api` requests without the token. */
|
|
33
39
|
readonly priority: number;
|
|
34
40
|
protected readonly environments: ExecEnvironmentFactory;
|
|
35
41
|
protected readonly host?: string;
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
/**
|
|
43
|
+
* By id, the directory paths stay in, the one whose execution environment reads them, and for a file
|
|
44
|
+
* outside the conversation's directory, the one path of `root` served.
|
|
45
|
+
*/
|
|
46
|
+
protected readonly directories: Map<string, ServedDirectory>;
|
|
41
47
|
protected readonly ids: Map<string, string>;
|
|
42
48
|
url(cwd: string, path: string): string;
|
|
43
49
|
handle(ctx: Context, next: () => Promise<void>): Promise<void>;
|
|
44
|
-
protected send(request: IncomingMessage, response: ServerResponse, directory:
|
|
45
|
-
root: string;
|
|
46
|
-
cwd: string;
|
|
47
|
-
}, path: string): Promise<void>;
|
|
50
|
+
protected send(request: IncomingMessage, response: ServerResponse, directory: ServedDirectory, path: string): Promise<void>;
|
|
48
51
|
/** The file at `path` of `root`, or the `index.html` of the directory there. */
|
|
49
52
|
protected find(env: ExecEnvironment, root: string, path: string): Promise<{
|
|
50
53
|
absolute: string;
|
|
@@ -55,3 +58,4 @@ export declare class DefaultWorkspaceFiles implements WorkspaceFiles, Middleware
|
|
|
55
58
|
protected acceptsHost(request: IncomingMessage): boolean;
|
|
56
59
|
protected fail(response: ServerResponse, status: number): void;
|
|
57
60
|
}
|
|
61
|
+
export {};
|
|
@@ -9,7 +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
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
13
13
|
import { Autowired, Component, Value } from '@celljs/core';
|
|
14
14
|
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
15
15
|
import { TA_FILES_PATH } from '@celljs/ta-protocol';
|
|
@@ -119,29 +119,33 @@ export var WorkspaceFilesUtil;
|
|
|
119
119
|
* Answers `GET /api/files/<id>/<path>` with the bytes of a file, without the token of ta serve: `<id>`
|
|
120
120
|
* stands for one directory, and only who has the token learns it (TaWorkspaceServer.fileUrl). Paths stay inside
|
|
121
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
|
|
123
|
-
*
|
|
124
|
-
* reach it.
|
|
122
|
+
* outside the directory of the conversation (a picture an agent left in `/tmp`) has an id of its own that
|
|
123
|
+
* stands for that file alone: the URL needs no token, so it must not open the directory the file is in
|
|
124
|
+
* (the home directory for `~/a.png`, with its keys) nor the pages of the workspace reach it.
|
|
125
125
|
*/
|
|
126
126
|
let DefaultWorkspaceFiles = class DefaultWorkspaceFiles {
|
|
127
127
|
constructor() {
|
|
128
128
|
/** Before TaAccess, which turns away `/api` requests without the token. */
|
|
129
129
|
this.priority = ACCESS_MIDDLEWARE_PRIORITY + 1;
|
|
130
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* By id, the directory paths stay in, the one whose execution environment reads them, and for a file
|
|
132
|
+
* outside the conversation's directory, the one path of `root` served.
|
|
133
|
+
*/
|
|
131
134
|
this.directories = new Map();
|
|
132
135
|
this.ids = new Map();
|
|
133
136
|
}
|
|
134
137
|
url(cwd, path) {
|
|
135
138
|
const absolute = resolve(cwd, path || '.');
|
|
136
|
-
const
|
|
137
|
-
const
|
|
139
|
+
const inside = WorkspaceUtil.contains(cwd, absolute);
|
|
140
|
+
const served = inside ? { root: cwd, cwd } : { root: dirname(absolute), cwd, only: basename(absolute) };
|
|
141
|
+
const key = `${cwd}\0${inside ? '' : absolute}`;
|
|
138
142
|
let id = this.ids.get(key);
|
|
139
143
|
if (!id) {
|
|
140
144
|
id = randomBytes(ID_BYTES).toString('base64url');
|
|
141
145
|
this.ids.set(key, id);
|
|
142
|
-
this.directories.set(id,
|
|
146
|
+
this.directories.set(id, served);
|
|
143
147
|
}
|
|
144
|
-
return WorkspaceFilesUtil.url(id, WorkspaceUtil.inside(root, absolute).relative);
|
|
148
|
+
return WorkspaceFilesUtil.url(id, WorkspaceUtil.inside(served.root, absolute).relative);
|
|
145
149
|
}
|
|
146
150
|
async handle(ctx, next) {
|
|
147
151
|
const request = ctx.request;
|
|
@@ -165,7 +169,7 @@ let DefaultWorkspaceFiles = class DefaultWorkspaceFiles {
|
|
|
165
169
|
}
|
|
166
170
|
async send(request, response, directory, path) {
|
|
167
171
|
const env = this.environments.create(directory.cwd);
|
|
168
|
-
const file = await this.find(env, directory.root, path);
|
|
172
|
+
const file = directory.only === undefined || path === directory.only ? await this.find(env, directory.root, path) : undefined;
|
|
169
173
|
if (!file) {
|
|
170
174
|
this.fail(response, 404);
|
|
171
175
|
return;
|
|
@@ -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`; a file outside `cwd`
|
|
20
|
+
/** The URL of `path` of `cwd`; a file outside `cwd` has a URL that serves it alone. */
|
|
21
21
|
url(cwd: string, path: string): string;
|
|
22
22
|
}
|
|
@@ -29,8 +29,12 @@ export declare class ClientToolBroker {
|
|
|
29
29
|
claim(id: string, runner: object): boolean;
|
|
30
30
|
/** `runner` left the session: the calls it took and did not answer go to the others again. */
|
|
31
31
|
release(runner: object): void;
|
|
32
|
-
/**
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* False when nobody waits for this call, or another client took it: only the runner that claimed a call
|
|
34
|
+
* answers it, so that a page that did not run it cannot put an answer of its own in its place. A call nobody
|
|
35
|
+
* claimed (a client from before claims, or a result sent again after a reconnect) takes the first answer.
|
|
36
|
+
*/
|
|
37
|
+
respond(result: TaClientToolResult, runner?: object): boolean;
|
|
34
38
|
cancelAll(): void;
|
|
35
39
|
protected call(toolName: string, id: string, input: unknown, signal?: AbortSignal): Promise<{
|
|
36
40
|
content: {
|
|
@@ -63,11 +63,18 @@ class ClientToolBroker {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
/**
|
|
67
|
-
|
|
66
|
+
/**
|
|
67
|
+
* False when nobody waits for this call, or another client took it: only the runner that claimed a call
|
|
68
|
+
* answers it, so that a page that did not run it cannot put an answer of its own in its place. A call nobody
|
|
69
|
+
* claimed (a client from before claims, or a result sent again after a reconnect) takes the first answer.
|
|
70
|
+
*/
|
|
71
|
+
respond(result, runner) {
|
|
68
72
|
const call = this.pending.get(result.id);
|
|
69
|
-
call
|
|
70
|
-
|
|
73
|
+
if (!call || (call.runner && call.runner !== runner)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
call.settle(result);
|
|
77
|
+
return true;
|
|
71
78
|
}
|
|
72
79
|
cancelAll() {
|
|
73
80
|
for (const call of [...this.pending.values()]) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
2
|
-
import type { TaOpenSessionOptions, TaPackageInfo, TaSavedSessionInfo, TaSettingsScope, TaTemporaryFrom, TaWebExtensionInfo, TaWebExtensionSource } from '@celljs/ta-protocol';
|
|
2
|
+
import type { TaOpenSessionOptions, TaPackageInfo, TaSavedSessionInfo, TaSavedSessionQuery, TaSessionInfo, TaSettingsScope, TaSlashCommand, TaTemporaryFrom, TaWebExtensionInfo, TaWebExtensionSource } from '@celljs/ta-protocol';
|
|
3
3
|
import type { ClientChannel } from './client-channel';
|
|
4
4
|
import type { TaSession } from './ta-session';
|
|
5
5
|
export declare const TaSessionFactory: unique symbol;
|
|
@@ -28,6 +28,8 @@ export interface TaExecOptions {
|
|
|
28
28
|
export interface TaSessionFactory {
|
|
29
29
|
/** `id`: the id the session had, when it opens again under it. */
|
|
30
30
|
create(options: TaOpenSessionOptions, requestClose: (session: TaSession, idle?: boolean) => void, id?: string): Promise<TaSession>;
|
|
31
|
+
/** The commands of the `/` menu a session created in `cwd` would have, without creating one (TaServer.getDirectoryCommands). */
|
|
32
|
+
commands(cwd: string): Promise<TaSlashCommand[]>;
|
|
31
33
|
}
|
|
32
34
|
/** The open sessions. */
|
|
33
35
|
export interface TaSessionRegistry {
|
|
@@ -41,6 +43,8 @@ export interface TaSessionRegistry {
|
|
|
41
43
|
*/
|
|
42
44
|
resolve(sessionId: string): Promise<TaSession>;
|
|
43
45
|
list(): TaSession[];
|
|
46
|
+
/** The infos of the open sessions; the connection is told of each change from now on (TaServer.watchSessions). */
|
|
47
|
+
watch(connection: RpcConnection): TaSessionInfo[];
|
|
44
48
|
/** `idle`: closed to save its memory (idle, or the service stops), it keeps its id and opens again when called; otherwise for good. */
|
|
45
49
|
close(sessionId: string, idle?: boolean): Promise<void>;
|
|
46
50
|
/** As the service stops: each keeps its id, and opens again when called after the restart. */
|
|
@@ -49,24 +53,25 @@ export interface TaSessionRegistry {
|
|
|
49
53
|
}
|
|
50
54
|
/** The conversations pi keeps in its session files, open or not. */
|
|
51
55
|
export interface TaSessionCatalog {
|
|
52
|
-
/**
|
|
53
|
-
|
|
56
|
+
/**
|
|
57
|
+
* The latest first, without the files of `open` (sessions open now, which are listed as such), and only
|
|
58
|
+
* those in the window of `query`.
|
|
59
|
+
*/
|
|
60
|
+
list(open?: ReadonlySet<string>, query?: TaSavedSessionQuery): Promise<TaSavedSessionInfo[]>;
|
|
54
61
|
}
|
|
55
62
|
/** The packages pi loads in a directory, and their web extensions. */
|
|
56
63
|
export interface WebExtensionCatalog {
|
|
57
64
|
packages(cwd: string): Promise<TaPackageInfo[]>;
|
|
58
65
|
/** As `ta install`, with `-l` for `project`. */
|
|
59
66
|
install(cwd: string, source: string, scope: TaSettingsScope): Promise<void>;
|
|
60
|
-
/** A package of {@link packages}, not a built-in one. */
|
|
67
|
+
/** A package of {@link packages} by its id or the id of one of its web extensions, not a built-in one: those turn off with {@link setEnabled}. */
|
|
61
68
|
removePackage(cwd: string, id: string): Promise<void>;
|
|
62
69
|
list(cwd: string): Promise<TaWebExtensionInfo[]>;
|
|
63
70
|
/** Only the file of an extension the list has: an id names no other file. */
|
|
64
71
|
read(cwd: string, id: string): Promise<TaWebExtensionSource>;
|
|
65
|
-
/** Not a built-in package: those turn off with {@link setEnabled}. */
|
|
66
|
-
remove(cwd: string, id: string): Promise<void>;
|
|
67
72
|
/**
|
|
68
73
|
* Turns a package on or off: a built-in one by its name, in ta's settings (TaPackages); another by its
|
|
69
|
-
* id, in pi's settings as `pi config` does (PackageSwitch), or in ta's when pi loads nothing of it.
|
|
74
|
+
* id (or that of one of its web extensions), in pi's settings as `pi config` does (PackageSwitch), or in ta's when pi loads nothing of it.
|
|
70
75
|
*/
|
|
71
76
|
setEnabled(cwd: string, nameOrId: string, enabled: boolean): Promise<void>;
|
|
72
77
|
/** A package of {@link packages} by its id, or the id of one of its web extensions. */
|
package/lib/node/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './receipt-book';
|
|
|
14
14
|
export * from './relay-bridge';
|
|
15
15
|
export * from './remote';
|
|
16
16
|
export * from './remote-ui-context';
|
|
17
|
+
export * from './rooms-bridge';
|
|
17
18
|
export * from './session-catalog';
|
|
18
19
|
export * from './session-files';
|
|
19
20
|
export * from './session-handles';
|
package/lib/node/index.js
CHANGED
|
@@ -30,6 +30,7 @@ __exportStar(require("./receipt-book"), exports);
|
|
|
30
30
|
__exportStar(require("./relay-bridge"), exports);
|
|
31
31
|
__exportStar(require("./remote"), exports);
|
|
32
32
|
__exportStar(require("./remote-ui-context"), exports);
|
|
33
|
+
__exportStar(require("./rooms-bridge"), exports);
|
|
33
34
|
__exportStar(require("./session-catalog"), exports);
|
|
34
35
|
__exportStar(require("./session-files"), exports);
|
|
35
36
|
__exportStar(require("./session-handles"), exports);
|
|
@@ -2,7 +2,9 @@ import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
|
|
|
2
2
|
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
3
3
|
import { type TaExtensionHost, type TaHostAnswer, TaPackageServer, type TaPackageService, TaServer } from '@celljs/ta-protocol';
|
|
4
4
|
import { ExtensionDataStore } from './extension-data';
|
|
5
|
+
import { type RelayBridge } from './relay-bridge';
|
|
5
6
|
import { PiDirectories } from './remote/remote-protocol';
|
|
7
|
+
import { type RoomsBridge } from './rooms-bridge';
|
|
6
8
|
export declare const PackageHosts: unique symbol;
|
|
7
9
|
/**
|
|
8
10
|
* The server side of built-in packages under `ta serve`: the module a package names in `pi.host` of its
|
|
@@ -33,6 +35,8 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
|
|
|
33
35
|
protected readonly data: ExtensionDataStore;
|
|
34
36
|
protected readonly server: TaServer;
|
|
35
37
|
protected readonly packages: TaPackageServer;
|
|
38
|
+
protected readonly relay: RelayBridge;
|
|
39
|
+
protected readonly roomsBridge: RoomsBridge;
|
|
36
40
|
protected readonly running: Map<string, Running>;
|
|
37
41
|
protected extensionHost?: TaExtensionHost;
|
|
38
42
|
onStart(): Promise<void>;
|
|
@@ -43,6 +47,8 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
|
|
|
43
47
|
protected start(name: string, file: string): Running;
|
|
44
48
|
protected stop(name: string): Promise<void>;
|
|
45
49
|
protected host(): TaExtensionHost;
|
|
50
|
+
protected sessionMessages(file: string): Promise<unknown[]>;
|
|
51
|
+
protected createSession(cwd: string, messages: readonly unknown[], name?: string): Promise<string>;
|
|
46
52
|
protected agentDir(): string;
|
|
47
53
|
}
|
|
48
54
|
export {};
|
|
@@ -20,7 +20,9 @@ const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
|
|
|
20
20
|
const ta_packages_1 = require("@celljs/ta-harness/lib/node/ta-packages");
|
|
21
21
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
22
22
|
const extension_data_1 = require("./extension-data");
|
|
23
|
+
const relay_bridge_1 = require("./relay-bridge");
|
|
23
24
|
const remote_protocol_1 = require("./remote/remote-protocol");
|
|
25
|
+
const rooms_bridge_1 = require("./rooms-bridge");
|
|
24
26
|
const ta_errors_1 = require("./ta-errors");
|
|
25
27
|
exports.PackageHosts = Symbol('PackageHosts');
|
|
26
28
|
var PackageHostUtil;
|
|
@@ -152,6 +154,10 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
152
154
|
return cwd === undefined ? undefined : this.directories.fromPi(cwd);
|
|
153
155
|
},
|
|
154
156
|
listPackages: cwd => packages.listPackages(cwd),
|
|
157
|
+
shares: this.relay.shares,
|
|
158
|
+
rooms: this.roomsBridge.rooms,
|
|
159
|
+
sessionMessages: file => this.sessionMessages(file),
|
|
160
|
+
createSession: (cwd, messages, name) => this.createSession(cwd, messages, name),
|
|
155
161
|
getServerInfo: () => server.getServerInfo(),
|
|
156
162
|
listSessions: () => server.listSessions(),
|
|
157
163
|
openSession: options => server.openSession(options),
|
|
@@ -169,6 +175,27 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
169
175
|
}
|
|
170
176
|
return this.extensionHost;
|
|
171
177
|
}
|
|
178
|
+
async sessionMessages(file) {
|
|
179
|
+
const manager = (await ai_coding_agent_1.PiSdkUtil.load()).SessionManager.open(file);
|
|
180
|
+
return manager.getBranch().flatMap(entry => (entry.type === 'message' ? [entry.message] : []));
|
|
181
|
+
}
|
|
182
|
+
async createSession(cwd, messages, name) {
|
|
183
|
+
if (!messages.some(message => message.role === 'assistant')) {
|
|
184
|
+
throw ta_errors_1.TaErrors.invalidArgument('A conversation needs an answer of the agent to be kept.', 'Pass the messages of a conversation that has one.');
|
|
185
|
+
}
|
|
186
|
+
const manager = (await ai_coding_agent_1.PiSdkUtil.load()).SessionManager.create(this.directories.toPi(cwd));
|
|
187
|
+
for (const message of messages) {
|
|
188
|
+
manager.appendMessage(message);
|
|
189
|
+
}
|
|
190
|
+
if (name === null || name === void 0 ? void 0 : name.trim()) {
|
|
191
|
+
manager.appendSessionInfo(name.trim());
|
|
192
|
+
}
|
|
193
|
+
const file = manager.getSessionFile();
|
|
194
|
+
if (!file) {
|
|
195
|
+
throw ta_errors_1.TaErrors.commandFailed(new Error('pi kept no file of the conversation.'));
|
|
196
|
+
}
|
|
197
|
+
return file;
|
|
198
|
+
}
|
|
172
199
|
agentDir() {
|
|
173
200
|
var _a;
|
|
174
201
|
var _b;
|
|
@@ -196,6 +223,14 @@ __decorate([
|
|
|
196
223
|
(0, core_1.Autowired)({ id: ta_protocol_1.TaPackageServer, detached: true }),
|
|
197
224
|
__metadata("design:type", Object)
|
|
198
225
|
], PackageHostsImpl.prototype, "packages", void 0);
|
|
226
|
+
__decorate([
|
|
227
|
+
(0, core_1.Autowired)({ id: relay_bridge_1.RELAY_BRIDGE, detached: true }),
|
|
228
|
+
__metadata("design:type", Function)
|
|
229
|
+
], PackageHostsImpl.prototype, "relay", void 0);
|
|
230
|
+
__decorate([
|
|
231
|
+
(0, core_1.Autowired)({ id: rooms_bridge_1.ROOMS_BRIDGE, detached: true }),
|
|
232
|
+
__metadata("design:type", Function)
|
|
233
|
+
], PackageHostsImpl.prototype, "roomsBridge", void 0);
|
|
199
234
|
exports.PackageHostsImpl = PackageHostsImpl = __decorate([
|
|
200
235
|
(0, core_1.Component)([exports.PackageHosts, core_1.ApplicationLifecycle])
|
|
201
236
|
], PackageHostsImpl);
|
|
@@ -13,7 +13,6 @@ export declare class TaPackageServerImpl implements TaPackageServer {
|
|
|
13
13
|
protected readonly packageHosts: PackageHosts;
|
|
14
14
|
listWebExtensions(cwd?: string): Promise<TaWebExtensionInfo[]>;
|
|
15
15
|
readWebExtension(id: string, cwd?: string): Promise<TaWebExtensionSource>;
|
|
16
|
-
removeWebExtension(id: string, cwd?: string): Promise<void>;
|
|
17
16
|
setPackageEnabled(nameOrId: string, enabled: boolean, cwd?: string): Promise<void>;
|
|
18
17
|
listPackages(cwd?: string): Promise<TaPackageInfo[]>;
|
|
19
18
|
installPackage(source: string, scope: TaSettingsScope, cwd?: string): Promise<void>;
|
|
@@ -28,9 +28,6 @@ let TaPackageServerImpl = class TaPackageServerImpl {
|
|
|
28
28
|
readWebExtension(id, cwd) {
|
|
29
29
|
return ta_errors_1.TaErrors.guard(async () => this.webExtensions.read(await this.cwd(cwd), id));
|
|
30
30
|
}
|
|
31
|
-
removeWebExtension(id, cwd) {
|
|
32
|
-
return ta_errors_1.TaErrors.guard(async () => this.webExtensions.remove(await this.cwd(cwd), id));
|
|
33
|
-
}
|
|
34
31
|
setPackageEnabled(nameOrId, enabled, cwd) {
|
|
35
32
|
return ta_errors_1.TaErrors.guard(async () => {
|
|
36
33
|
await this.webExtensions.setEnabled(await this.cwd(cwd), nameOrId, enabled);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Server } from 'node:http';
|
|
2
2
|
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
3
3
|
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
4
|
-
import { type TaPackageShare, type TaRelayDevice, type TaRelayInfo, TaRelayServer } from '@celljs/ta-protocol';
|
|
5
|
-
import { RelayHost, RelayStore } from '@celljs/ta-relay/lib/node';
|
|
4
|
+
import { type TaPackageShare, type TaRelayDevice, type TaRelayInfo, TaRelayServer, type TaSharedContent, type TaShareInfo, type TaShareInput, type TaShares } from '@celljs/ta-protocol';
|
|
5
|
+
import { type RelayContentShare, RelayHost, RelayHubs, type RelayPublicIdentity, RelayStore } from '@celljs/ta-relay/lib/node';
|
|
6
6
|
import { ServerAware } from '@celljs/web/lib/node';
|
|
7
7
|
import { WebExtensionCatalog } from './host-protocol';
|
|
8
8
|
import { type TaAccess } from './ta-access';
|
|
@@ -16,7 +16,11 @@ export declare const RELAY_BRIDGE: unique symbol;
|
|
|
16
16
|
export declare class RelayBridge implements ServerAware, ApplicationLifecycle<Application> {
|
|
17
17
|
protected readonly access: TaAccess;
|
|
18
18
|
readonly store: RelayStore;
|
|
19
|
+
/** The identity, friends and rooms of this Ta (RoomsBridge runs them): shares with Ta friends need them too. */
|
|
20
|
+
readonly hubs: RelayHubs;
|
|
19
21
|
protected host?: RelayHost;
|
|
22
|
+
/** Content shared by links (TaExtensionHost.shares): kept in the agent directory, handed on by this server, a copy sealed on the relay if asked. */
|
|
23
|
+
readonly shares: TaShares;
|
|
20
24
|
get online(): boolean;
|
|
21
25
|
/** relay.json changed here: no need to wait for the watch. */
|
|
22
26
|
refresh(): void;
|
|
@@ -24,6 +28,12 @@ export declare class RelayBridge implements ServerAware, ApplicationLifecycle<Ap
|
|
|
24
28
|
onStop(): Promise<void>;
|
|
25
29
|
/** A package as it goes by a link: a gzipped tar of its directory, without node_modules and .git. */
|
|
26
30
|
static pack(root: string): Promise<Uint8Array>;
|
|
31
|
+
protected share(input: TaShareInput): Promise<TaShareInfo>;
|
|
32
|
+
protected unshare(id: string): Promise<boolean>;
|
|
33
|
+
protected open(text: string, password?: string): Promise<TaSharedContent>;
|
|
34
|
+
/** The Ta friends of these ids, as this Ta keeps them. */
|
|
35
|
+
protected friendsOf(ids: readonly string[] | undefined): RelayPublicIdentity[];
|
|
36
|
+
protected info(content: RelayContentShare): TaShareInfo;
|
|
27
37
|
protected start(server: Server): void;
|
|
28
38
|
}
|
|
29
39
|
/** `ta pair` for clients: the devices of relay.json, which RelayBridge serves. Their keys never leave, but in the link of a new one. */
|
package/lib/node/relay-bridge.js
CHANGED
|
@@ -36,6 +36,19 @@ const WATCH_INTERVAL_MS = 2000;
|
|
|
36
36
|
let RelayBridge = RelayBridge_1 = class RelayBridge {
|
|
37
37
|
constructor() {
|
|
38
38
|
this.store = new node_1.RelayStore(ta_brand_1.TaBrand.agentDir());
|
|
39
|
+
/** The identity, friends and rooms of this Ta (RoomsBridge runs them): shares with Ta friends need them too. */
|
|
40
|
+
this.hubs = new node_1.RelayHubs({
|
|
41
|
+
store: new node_1.RelayHubFiles(ta_brand_1.TaBrand.agentDir()),
|
|
42
|
+
name: node_1.RelayHubFiles.userName,
|
|
43
|
+
relay: () => { var _a; return (_a = this.store.read().url) !== null && _a !== void 0 ? _a : node_1.RELAY_DEFAULT_URL; },
|
|
44
|
+
});
|
|
45
|
+
/** Content shared by links (TaExtensionHost.shares): kept in the agent directory, handed on by this server, a copy sealed on the relay if asked. */
|
|
46
|
+
this.shares = {
|
|
47
|
+
create: input => this.share(input),
|
|
48
|
+
list: async () => this.store.contents().map(content => this.info(content)),
|
|
49
|
+
remove: async (id) => this.unshare(id),
|
|
50
|
+
open: (link, password) => this.open(link, password),
|
|
51
|
+
};
|
|
39
52
|
}
|
|
40
53
|
get online() {
|
|
41
54
|
var _a;
|
|
@@ -65,10 +78,87 @@ let RelayBridge = RelayBridge_1 = class RelayBridge {
|
|
|
65
78
|
static async pack(root) {
|
|
66
79
|
return package_archive_1.PackageArchive.pack((0, node_path_1.basename)(root), package_archive_1.PackageArchive.collect(root));
|
|
67
80
|
}
|
|
81
|
+
async share(input) {
|
|
82
|
+
if (input.data.length > node_1.RELAY_CONTENT_MAX_BYTES) {
|
|
83
|
+
throw new node_1.RelayContentError('large', `It is ${(input.data.length / 1024 / 1024).toFixed(1)} MB, more than the ${node_1.RELAY_CONTENT_MAX_BYTES / 1024 / 1024} MB a link takes.`);
|
|
84
|
+
}
|
|
85
|
+
const createdAt = Date.now();
|
|
86
|
+
const people = input.access === 'people' ? this.friendsOf(input.people) : undefined;
|
|
87
|
+
if (people && people.length === 0) {
|
|
88
|
+
throw new node_1.RelayContentError('people', 'Choose the Ta friends to share it with: none of them is a friend of this Ta.');
|
|
89
|
+
}
|
|
90
|
+
const { content, link } = await this.store.addContent({ ...input, createdAt, people, ...(people ? { identity: await this.hubs.identity() } : {}) }, createdAt);
|
|
91
|
+
if (content.offline) {
|
|
92
|
+
const key = node_1.RelayBytes.fromBase64(content.key);
|
|
93
|
+
try {
|
|
94
|
+
await node_1.RelayBlobClient.put({
|
|
95
|
+
relay: link.relay,
|
|
96
|
+
share: content.id,
|
|
97
|
+
token: content.offline.token,
|
|
98
|
+
authHash: await node_1.RelayContentUtil.sha256(await node_1.RelayContentUtil.authToken(key)),
|
|
99
|
+
expiresAt: content.offline.expiresAt,
|
|
100
|
+
bytes: await node_1.RelayContentUtil.seal(key, { kind: content.kind, title: content.title, type: content.type, createdAt, data: input.data }),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.store.removeContent(content.id);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
this.refresh();
|
|
109
|
+
return this.info(content);
|
|
110
|
+
}
|
|
111
|
+
async unshare(id) {
|
|
112
|
+
const { url } = this.store.read();
|
|
113
|
+
const content = this.store.removeContent(id);
|
|
114
|
+
this.refresh();
|
|
115
|
+
if (content === null || content === void 0 ? void 0 : content.offline) {
|
|
116
|
+
await node_1.RelayBlobClient.remove(url !== null && url !== void 0 ? url : node_1.RELAY_DEFAULT_URL, content.id, content.offline.token).catch(() => undefined);
|
|
117
|
+
}
|
|
118
|
+
return !!content;
|
|
119
|
+
}
|
|
120
|
+
async open(text, password) {
|
|
121
|
+
var _a;
|
|
122
|
+
const link = node_1.RelayContentUtil.parse(text);
|
|
123
|
+
const own = ((_a = this.store.read().host) === null || _a === void 0 ? void 0 : _a.id) === link.host ? this.store.content(link.share) : undefined;
|
|
124
|
+
const data = own && this.store.contentData(own);
|
|
125
|
+
if (own && data) {
|
|
126
|
+
return { kind: own.kind, title: own.title, type: own.type, createdAt: own.createdAt, data };
|
|
127
|
+
}
|
|
128
|
+
if (link.access === 'people') {
|
|
129
|
+
// Its key is made with the key of the one who shared it, one of this Ta's friends: else it is not for this Ta.
|
|
130
|
+
const owner = this.hubs.friends().find(friend => friend.id === link.owner);
|
|
131
|
+
if (!owner) {
|
|
132
|
+
throw new node_1.RelayContentError('people', 'Only the Ta friends it was shared with open it, in their own Ta.');
|
|
133
|
+
}
|
|
134
|
+
return node_1.RelayContentUtil.fetch(link, { people: { identity: await this.hubs.identity(), ownerBox: owner.box } });
|
|
135
|
+
}
|
|
136
|
+
return node_1.RelayContentUtil.fetch(link, { password });
|
|
137
|
+
}
|
|
138
|
+
/** The Ta friends of these ids, as this Ta keeps them. */
|
|
139
|
+
friendsOf(ids) {
|
|
140
|
+
const wanted = new Set(Array.isArray(ids) ? ids : []);
|
|
141
|
+
return this.hubs.friends().filter(friend => wanted.has(friend.id));
|
|
142
|
+
}
|
|
143
|
+
info(content) {
|
|
144
|
+
return {
|
|
145
|
+
id: content.id,
|
|
146
|
+
kind: content.kind,
|
|
147
|
+
title: content.title,
|
|
148
|
+
...(content.type ? { type: content.type } : {}),
|
|
149
|
+
access: content.access,
|
|
150
|
+
size: content.size,
|
|
151
|
+
createdAt: content.createdAt,
|
|
152
|
+
...(content.expiresAt ? { expiresAt: content.expiresAt } : {}),
|
|
153
|
+
offline: !!content.offline,
|
|
154
|
+
link: node_1.RelayContentUtil.link(this.store.contentLink(content)),
|
|
155
|
+
...(content.people ? { people: content.people.map(person => person.name) } : {}),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
68
158
|
start(server) {
|
|
69
159
|
const { port } = server.address();
|
|
70
160
|
const localUrl = `ws://127.0.0.1:${port}${ta_protocol_1.TA_WEBSOCKET_PATH}?token=${encodeURIComponent(this.access.token)}`;
|
|
71
|
-
const host = new node_1.RelayHost({ store: this.store, localUrl, sharePackage: share => RelayBridge_1.pack(share.root) });
|
|
161
|
+
const host = new node_1.RelayHost({ store: this.store, localUrl, sharePackage: share => RelayBridge_1.pack(share.root), shareContent: true });
|
|
72
162
|
this.host = host;
|
|
73
163
|
host.start();
|
|
74
164
|
(0, node_fs_1.watchFile)(this.store.file, { interval: WATCH_INTERVAL_MS }, () => host.refresh());
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
2
|
+
import { type RpcConnection } from '@celljs/rpc/lib/node';
|
|
3
|
+
import { type TaFriend, type TaIdentity, type TaRoomEvent, type TaRoomInfo, type TaRoomRequest, TaRoomServer, type TaRooms, type TaRoomValue, type TaRoomWatch } from '@celljs/ta-protocol';
|
|
4
|
+
import type { RelayHubs } from '@celljs/ta-relay/lib/node';
|
|
5
|
+
import { type RelayBridge } from './relay-bridge';
|
|
6
|
+
/** The id of {@link RoomsBridge}. */
|
|
7
|
+
export declare const ROOMS_BRIDGE: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* The rooms of this Ta (docs/design/ta-link.md 3): RelayHubs, connected to its rooms while ta serve runs, so that
|
|
10
|
+
* the owner hears who asks to join without a page open; the clients that watch hear what happens in them, and
|
|
11
|
+
* the server side of packages has them as TaExtensionHost.rooms.
|
|
12
|
+
*/
|
|
13
|
+
export declare class RoomsBridge implements ApplicationLifecycle<Application> {
|
|
14
|
+
protected readonly relay: RelayBridge;
|
|
15
|
+
/** The connections that watch, and what they hear: messages and the state too, or the state of some keys. */
|
|
16
|
+
protected readonly watchers: Map<RpcConnection, TaRoomWatch>;
|
|
17
|
+
get hubs(): RelayHubs;
|
|
18
|
+
readonly rooms: TaRooms;
|
|
19
|
+
onStart(): void;
|
|
20
|
+
onStop(): void;
|
|
21
|
+
/** `watch` undefined: no more. */
|
|
22
|
+
watch(connection: RpcConnection, watch: TaRoomWatch | undefined): void;
|
|
23
|
+
protected broadcast(event: TaRoomEvent): void;
|
|
24
|
+
protected static identity({ id, name }: TaIdentity): TaIdentity;
|
|
25
|
+
}
|
|
26
|
+
/** The rooms for clients (TaRoomServer): those of RoomsBridge, what goes wrong said as the errors of Ta. */
|
|
27
|
+
export declare class TaRoomServerImpl implements TaRoomServer {
|
|
28
|
+
protected readonly bridge: RoomsBridge;
|
|
29
|
+
protected get rooms(): TaRooms;
|
|
30
|
+
getIdentity(): Promise<TaIdentity>;
|
|
31
|
+
setName(name: string): Promise<TaIdentity>;
|
|
32
|
+
listRooms(): Promise<TaRoomInfo[]>;
|
|
33
|
+
createRoom(input: {
|
|
34
|
+
kind: string;
|
|
35
|
+
title: string;
|
|
36
|
+
view?: string;
|
|
37
|
+
}): Promise<TaRoomInfo>;
|
|
38
|
+
invite(room: string, options?: {
|
|
39
|
+
days?: number;
|
|
40
|
+
renew?: boolean;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
link: string;
|
|
43
|
+
expiresAt: number;
|
|
44
|
+
}>;
|
|
45
|
+
join(link: string): Promise<TaRoomInfo>;
|
|
46
|
+
listRequests(): Promise<TaRoomRequest[]>;
|
|
47
|
+
answer(room: string, ask: string, accept: boolean): Promise<void>;
|
|
48
|
+
removeMember(room: string, member: string): Promise<void>;
|
|
49
|
+
leave(room: string): Promise<void>;
|
|
50
|
+
send(room: string, data: unknown, to?: string): Promise<void>;
|
|
51
|
+
getState(room: string, prefix?: string): Promise<Record<string, TaRoomValue>>;
|
|
52
|
+
setState(room: string, key: string, value: unknown, version?: number): Promise<{
|
|
53
|
+
ok: boolean;
|
|
54
|
+
version: number;
|
|
55
|
+
}>;
|
|
56
|
+
listFriends(): Promise<TaFriend[]>;
|
|
57
|
+
removeFriend(id: string): Promise<boolean>;
|
|
58
|
+
watch(messages?: boolean, state?: string[]): Promise<void>;
|
|
59
|
+
unwatch(): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=rooms-bridge.d.ts.map
|