@celljs/ta-host 4.9.1 → 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 +5 -5
- package/README.md +5 -5
- package/esm/node/client-tool-broker.d.ts +6 -2
- package/esm/node/client-tool-broker.js +11 -4
- 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 +24 -10
- package/esm/node/index.d.ts +2 -0
- package/esm/node/index.js +2 -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/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/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 +15 -4
- 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 +7 -0
- package/esm/node/session-info-util.js +63 -4
- 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-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 +19 -2
- package/esm/node/ta-event-util.js +97 -3
- package/esm/node/ta-server-impl.d.ts +13 -7
- package/esm/node/ta-server-impl.js +43 -24
- package/esm/node/ta-session-factory.d.ts +26 -2
- package/esm/node/ta-session-factory.js +64 -16
- package/esm/node/ta-session-registry.d.ts +16 -2
- package/esm/node/ta-session-registry.js +79 -20
- package/esm/node/ta-session.d.ts +16 -6
- package/esm/node/ta-session.js +59 -14
- 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 +19 -5
- package/esm/node/workspace-files.js +26 -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/client-tool-broker.d.ts +6 -2
- package/lib/node/client-tool-broker.js +11 -4
- 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 +24 -10
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.js +2 -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/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/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 +15 -4
- 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 +7 -0
- package/lib/node/session-info-util.js +62 -3
- 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-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 +19 -2
- package/lib/node/ta-event-util.js +97 -3
- package/lib/node/ta-server-impl.d.ts +13 -7
- package/lib/node/ta-server-impl.js +41 -22
- package/lib/node/ta-session-factory.d.ts +26 -2
- package/lib/node/ta-session-factory.js +65 -17
- package/lib/node/ta-session-registry.d.ts +16 -2
- package/lib/node/ta-session-registry.js +79 -20
- package/lib/node/ta-session.d.ts +16 -6
- package/lib/node/ta-session.js +59 -14
- 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 +19 -5
- package/lib/node/workspace-files.js +26 -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
|
@@ -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;
|
|
@@ -26,38 +26,52 @@ 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>;
|
|
31
|
+
/** The commands of the `/` menu a session created in `cwd` would have, without creating one (TaServer.getDirectoryCommands). */
|
|
32
|
+
commands(cwd: string): Promise<TaSlashCommand[]>;
|
|
30
33
|
}
|
|
31
34
|
/** The open sessions. */
|
|
32
35
|
export interface TaSessionRegistry {
|
|
33
36
|
open(options: TaOpenSessionOptions): Promise<TaSession>;
|
|
34
|
-
/**
|
|
37
|
+
/** An open session; throws CELL_TA_SESSION_NOT_FOUND. */
|
|
35
38
|
require(sessionId: string): TaSession;
|
|
39
|
+
/**
|
|
40
|
+
* A session by its id, opened again from its file under that id when the service closed it while idle or
|
|
41
|
+
* by a restart (TaSessionHandles); throws CELL_TA_SESSION_NOT_FOUND when it was closed for good or its
|
|
42
|
+
* file is gone.
|
|
43
|
+
*/
|
|
44
|
+
resolve(sessionId: string): Promise<TaSession>;
|
|
36
45
|
list(): TaSession[];
|
|
37
|
-
|
|
46
|
+
/** The infos of the open sessions; the connection is told of each change from now on (TaServer.watchSessions). */
|
|
47
|
+
watch(connection: RpcConnection): TaSessionInfo[];
|
|
48
|
+
/** `idle`: closed to save its memory (idle, or the service stops), it keeps its id and opens again when called; otherwise for good. */
|
|
49
|
+
close(sessionId: string, idle?: boolean): Promise<void>;
|
|
50
|
+
/** As the service stops: each keeps its id, and opens again when called after the restart. */
|
|
38
51
|
closeAll(): Promise<void>;
|
|
39
52
|
channel(connection: RpcConnection): ClientChannel;
|
|
40
53
|
}
|
|
41
54
|
/** The conversations pi keeps in its session files, open or not. */
|
|
42
55
|
export interface TaSessionCatalog {
|
|
43
|
-
/**
|
|
44
|
-
|
|
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[]>;
|
|
45
61
|
}
|
|
46
62
|
/** The packages pi loads in a directory, and their web extensions. */
|
|
47
63
|
export interface WebExtensionCatalog {
|
|
48
64
|
packages(cwd: string): Promise<TaPackageInfo[]>;
|
|
49
65
|
/** As `ta install`, with `-l` for `project`. */
|
|
50
66
|
install(cwd: string, source: string, scope: TaSettingsScope): Promise<void>;
|
|
51
|
-
/** 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}. */
|
|
52
68
|
removePackage(cwd: string, id: string): Promise<void>;
|
|
53
69
|
list(cwd: string): Promise<TaWebExtensionInfo[]>;
|
|
54
70
|
/** Only the file of an extension the list has: an id names no other file. */
|
|
55
71
|
read(cwd: string, id: string): Promise<TaWebExtensionSource>;
|
|
56
|
-
/** Not a built-in package: those turn off with {@link setEnabled}. */
|
|
57
|
-
remove(cwd: string, id: string): Promise<void>;
|
|
58
72
|
/**
|
|
59
73
|
* Turns a package on or off: a built-in one by its name, in ta's settings (TaPackages); another by its
|
|
60
|
-
* 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.
|
|
61
75
|
*/
|
|
62
76
|
setEnabled(cwd: string, nameOrId: string, enabled: boolean): Promise<void>;
|
|
63
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,8 +14,10 @@ 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';
|
|
20
|
+
export * from './session-handles';
|
|
19
21
|
export * from './session-info-util';
|
|
20
22
|
export * from './session-storage';
|
|
21
23
|
export * from './settings-server-impl';
|
package/lib/node/index.js
CHANGED
|
@@ -30,8 +30,10 @@ __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);
|
|
36
|
+
__exportStar(require("./session-handles"), exports);
|
|
35
37
|
__exportStar(require("./session-info-util"), exports);
|
|
36
38
|
__exportStar(require("./session-storage"), exports);
|
|
37
39
|
__exportStar(require("./settings-server-impl"), 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());
|
|
@@ -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() { }
|
|
@@ -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
|