@celljs/ta-host 4.10.0 → 4.12.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 +14 -5
- package/esm/node/ta-server-impl.js +39 -18
- 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 +14 -5
- package/lib/node/ta-server-impl.js +37 -16
- 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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TaEventUtil = void 0;
|
|
4
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
4
5
|
/** The lean form of each message and result met, made once: the pages of a conversation measure it by its object. */
|
|
5
6
|
const leaned = new WeakMap();
|
|
6
7
|
var TaEventUtil;
|
|
@@ -68,21 +69,46 @@ var TaEventUtil;
|
|
|
68
69
|
return lean;
|
|
69
70
|
}
|
|
70
71
|
TaEventUtil.leanResult = leanResult;
|
|
71
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* A conversation as clients get it: its messages and the results of its calls lean, and the images of the
|
|
74
|
+
* messages of the user without their bytes but with their size (`TaShownImage`): they come with
|
|
75
|
+
* `getMessageImage` once shown, and a conversation with pictures opens as fast as one without. Events keep
|
|
76
|
+
* them: a message just sent shows on every device at once.
|
|
77
|
+
*/
|
|
72
78
|
function leanConversation(conversation) {
|
|
73
79
|
const tools = {};
|
|
74
80
|
for (const [id, run] of Object.entries(conversation.tools)) {
|
|
75
81
|
tools[id] = run.result === undefined ? run : { ...run, result: leanResult(run.result) };
|
|
76
82
|
}
|
|
77
|
-
return { ...conversation, messages: leanAll(conversation.messages), tools };
|
|
83
|
+
return { ...conversation, messages: leanAll(conversation.messages, leanShown), tools };
|
|
78
84
|
}
|
|
79
85
|
TaEventUtil.leanConversation = leanConversation;
|
|
80
|
-
|
|
86
|
+
/** A message as a page of the conversation gives it: `leanMessage`, and the images of the user's without their bytes. */
|
|
87
|
+
function leanShown(message) {
|
|
88
|
+
const { role, content } = message;
|
|
89
|
+
if (role !== 'user' || !Array.isArray(content)) {
|
|
90
|
+
return leanMessage(message);
|
|
91
|
+
}
|
|
92
|
+
const known = leaned.get(message);
|
|
93
|
+
if (known) {
|
|
94
|
+
return known;
|
|
95
|
+
}
|
|
96
|
+
const heavy = content.some(block => (block === null || block === void 0 ? void 0 : block.type) === 'image' && block.data);
|
|
97
|
+
const lean = heavy ? { ...message, content: content.map(block => ((block === null || block === void 0 ? void 0 : block.type) === 'image' ? shown(block) : block)) } : message;
|
|
98
|
+
leaned.set(message, lean);
|
|
99
|
+
return lean;
|
|
100
|
+
}
|
|
101
|
+
TaEventUtil.leanShown = leanShown;
|
|
102
|
+
function shown(block) {
|
|
103
|
+
var _a;
|
|
104
|
+
return { type: 'image', mimeType: (_a = block.mimeType) !== null && _a !== void 0 ? _a : '', data: '', ...(block.data ? ta_protocol_1.TaImageSize.of(block.data) : undefined) };
|
|
105
|
+
}
|
|
106
|
+
function leanAll(messages, lean = leanMessage) {
|
|
81
107
|
if (!Array.isArray(messages)) {
|
|
82
108
|
return messages;
|
|
83
109
|
}
|
|
84
|
-
const
|
|
85
|
-
return
|
|
110
|
+
const leant = messages.map(lean);
|
|
111
|
+
return leant.every((message, index) => message === messages[index]) ? messages : leant;
|
|
86
112
|
}
|
|
87
113
|
function withLean(event, key, value) {
|
|
88
114
|
return (value === event[key] ? event : { ...event, [key]: value });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
2
|
-
import { type RpcExtensionUIResponse, type TaAttachOptions, type TaAttachResult, type TaClientToolResult, type TaCommandResult, type TaForkFileResult, type TaMessagePage, type TaNavigateResult, type TaOpenSessionOptions, type TaPromptInput, type TaPromptReceipt, type TaSavedSessionInfo, TaServer, type TaServerInfo, type TaSessionInfo, type ThinkingLevel } from '@celljs/ta-protocol';
|
|
3
|
-
import { TaSessionCatalog, TaSessionRegistry } from './host-protocol';
|
|
2
|
+
import { type ImageContent, type RpcExtensionUIResponse, type TaAttachOptions, type TaAttachResult, type TaClientToolResult, type TaCommandResult, type TaForkFileResult, type TaMessagePage, type TaNavigateResult, type TaOpenedSession, type TaOpenSessionOptions, type TaPromptInput, type TaPromptReceipt, type TaSavedSessionInfo, type TaSavedSessionQuery, TaServer, type TaServerInfo, type TaSessionInfo, type TaSlashCommand, type ThinkingLevel } from '@celljs/ta-protocol';
|
|
3
|
+
import { TaSessionCatalog, TaSessionFactory, TaSessionRegistry } from './host-protocol';
|
|
4
4
|
import type { TaSession } from './ta-session';
|
|
5
5
|
import { TaWorkingDirectory } from './working-directory';
|
|
6
6
|
/**
|
|
@@ -13,14 +13,17 @@ export declare class TaServerImpl implements TaServer {
|
|
|
13
13
|
protected readonly environments: ExecEnvironmentFactory;
|
|
14
14
|
protected readonly workingDirectory: TaWorkingDirectory;
|
|
15
15
|
protected readonly catalog: TaSessionCatalog;
|
|
16
|
+
protected readonly factory: TaSessionFactory;
|
|
16
17
|
getServerInfo(): Promise<TaServerInfo>;
|
|
17
18
|
setWorkingDirectory(cwd: string): Promise<TaServerInfo>;
|
|
18
|
-
openSession(options: TaOpenSessionOptions): Promise<
|
|
19
|
+
openSession({ attach, ...options }: TaOpenSessionOptions): Promise<TaOpenedSession>;
|
|
19
20
|
closeSession(sessionId: string): Promise<void>;
|
|
20
21
|
listSessions(): Promise<TaSessionInfo[]>;
|
|
21
|
-
|
|
22
|
+
watchSessions(): Promise<TaSessionInfo[]>;
|
|
23
|
+
listSavedSessions(query?: TaSavedSessionQuery): Promise<TaSavedSessionInfo[]>;
|
|
22
24
|
attach(sessionId: string, afterSeq?: number, options?: TaAttachOptions): Promise<TaAttachResult>;
|
|
23
25
|
getEarlierMessages(sessionId: string, before: number | undefined, timestamp: number | undefined, budget: number): Promise<TaMessagePage>;
|
|
26
|
+
getMessageImage(sessionId: string, timestamp: number, index: number): Promise<ImageContent | undefined>;
|
|
24
27
|
detach(sessionId: string): Promise<void>;
|
|
25
28
|
respondUi(sessionId: string, response: RpcExtensionUIResponse): Promise<boolean>;
|
|
26
29
|
claimClientTool(sessionId: string, id: string): Promise<boolean>;
|
|
@@ -28,6 +31,7 @@ export declare class TaServerImpl implements TaServer {
|
|
|
28
31
|
prompt(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
29
32
|
steer(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
30
33
|
followUp(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
34
|
+
/** Logs how long the run took to end here: with the times the box keeps (stop.times of @celljs/ta-web), where a slow stop went. */
|
|
31
35
|
abort(sessionId: string): Promise<void>;
|
|
32
36
|
clearQueue(sessionId: string): Promise<TaCommandResult<'clear_queue'>>;
|
|
33
37
|
removeQueued(sessionId: string, kind: 'steering' | 'followUp', index: number): Promise<boolean>;
|
|
@@ -60,7 +64,12 @@ export declare class TaServerImpl implements TaServer {
|
|
|
60
64
|
getLastAssistantText(sessionId: string): Promise<TaCommandResult<'get_last_assistant_text'>>;
|
|
61
65
|
setSessionName(sessionId: string, name: string): Promise<void>;
|
|
62
66
|
getMessages(sessionId: string): Promise<TaCommandResult<'get_messages'>>;
|
|
63
|
-
getCommands(sessionId: string): Promise<
|
|
67
|
+
getCommands(sessionId: string): Promise<{
|
|
68
|
+
commands: TaSlashCommand[];
|
|
69
|
+
}>;
|
|
70
|
+
getDirectoryCommands(cwd: string): Promise<{
|
|
71
|
+
commands: TaSlashCommand[];
|
|
72
|
+
}>;
|
|
64
73
|
reload(sessionId: string): Promise<void>;
|
|
65
74
|
protected on<T>(sessionId: string, command: (session: TaSession) => T | Promise<T>): Promise<T>;
|
|
66
75
|
protected guard<T>(command: () => Promise<T>): Promise<T>;
|
|
@@ -21,6 +21,7 @@ const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
|
|
|
21
21
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
22
22
|
const host_protocol_1 = require("./host-protocol");
|
|
23
23
|
const session_info_util_1 = require("./session-info-util");
|
|
24
|
+
const slash_command_util_1 = require("./slash-command-util");
|
|
24
25
|
const ta_errors_1 = require("./ta-errors");
|
|
25
26
|
const working_directory_1 = require("./working-directory");
|
|
26
27
|
/**
|
|
@@ -35,6 +36,7 @@ let TaServerImpl = class TaServerImpl {
|
|
|
35
36
|
cwd: await this.environments.defaultCwd(),
|
|
36
37
|
user: (0, node_os_1.userInfo)().username,
|
|
37
38
|
host: (0, node_os_1.hostname)().replace(/\.local$/, ''),
|
|
39
|
+
home: (0, node_os_1.homedir)(),
|
|
38
40
|
}));
|
|
39
41
|
}
|
|
40
42
|
async setWorkingDirectory(cwd) {
|
|
@@ -49,8 +51,15 @@ let TaServerImpl = class TaServerImpl {
|
|
|
49
51
|
return this.getServerInfo();
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
|
-
async openSession(options) {
|
|
53
|
-
return this.guard(async () =>
|
|
54
|
+
async openSession({ attach, ...options }) {
|
|
55
|
+
return this.guard(async () => {
|
|
56
|
+
const session = await this.sessions.open(options);
|
|
57
|
+
if (!attach) {
|
|
58
|
+
return session.info();
|
|
59
|
+
}
|
|
60
|
+
const attached = session.attach(this.sessions.channel(node_1.RpcContext.requireConnection()), undefined, attach);
|
|
61
|
+
return { ...attached.info, attachment: attached };
|
|
62
|
+
});
|
|
54
63
|
}
|
|
55
64
|
closeSession(sessionId) {
|
|
56
65
|
return this.guard(() => this.sessions.close(sessionId));
|
|
@@ -58,10 +67,13 @@ let TaServerImpl = class TaServerImpl {
|
|
|
58
67
|
async listSessions() {
|
|
59
68
|
return this.sessions.list().map(session => session.info());
|
|
60
69
|
}
|
|
61
|
-
|
|
70
|
+
async watchSessions() {
|
|
71
|
+
return this.sessions.watch(node_1.RpcContext.requireConnection());
|
|
72
|
+
}
|
|
73
|
+
listSavedSessions(query) {
|
|
62
74
|
return this.guard(async () => {
|
|
63
75
|
const open = new Set(this.sessions.list().flatMap(session => { var _a; return (_a = session.pi.sessionFile) !== null && _a !== void 0 ? _a : []; }));
|
|
64
|
-
return this.catalog.list(open);
|
|
76
|
+
return this.catalog.list(open, query !== null && query !== void 0 ? query : undefined);
|
|
65
77
|
});
|
|
66
78
|
}
|
|
67
79
|
attach(sessionId, afterSeq, options) {
|
|
@@ -70,6 +82,9 @@ let TaServerImpl = class TaServerImpl {
|
|
|
70
82
|
getEarlierMessages(sessionId, before, timestamp, budget) {
|
|
71
83
|
return this.on(sessionId, session => session.earlierMessages(before !== null && before !== void 0 ? before : undefined, timestamp !== null && timestamp !== void 0 ? timestamp : undefined, budget));
|
|
72
84
|
}
|
|
85
|
+
getMessageImage(sessionId, timestamp, index) {
|
|
86
|
+
return this.on(sessionId, session => session.messageImage(timestamp, index));
|
|
87
|
+
}
|
|
73
88
|
detach(sessionId) {
|
|
74
89
|
// Not opened again to be left: a session closed meanwhile has no client.
|
|
75
90
|
return this.guard(async () => {
|
|
@@ -86,7 +101,7 @@ let TaServerImpl = class TaServerImpl {
|
|
|
86
101
|
return this.on(sessionId, session => session.claimClientTool(this.sessions.channel(node_1.RpcContext.requireConnection()), id));
|
|
87
102
|
}
|
|
88
103
|
respondClientTool(sessionId, result) {
|
|
89
|
-
return this.on(sessionId, session => session.respondClientTool(result));
|
|
104
|
+
return this.on(sessionId, session => session.respondClientTool(this.sessions.channel(node_1.RpcContext.requireConnection()), result));
|
|
90
105
|
}
|
|
91
106
|
prompt(sessionId, input) {
|
|
92
107
|
return this.on(sessionId, session => session.prompt(input));
|
|
@@ -97,8 +112,11 @@ let TaServerImpl = class TaServerImpl {
|
|
|
97
112
|
followUp(sessionId, input) {
|
|
98
113
|
return this.on(sessionId, session => session.followUp(input));
|
|
99
114
|
}
|
|
100
|
-
|
|
101
|
-
|
|
115
|
+
/** Logs how long the run took to end here: with the times the box keeps (stop.times of @celljs/ta-web), where a slow stop went. */
|
|
116
|
+
async abort(sessionId) {
|
|
117
|
+
const start = Date.now();
|
|
118
|
+
await this.on(sessionId, ({ pi }) => pi.abort());
|
|
119
|
+
console.log(`[${new Date().toISOString()}] ta serve: stopped ${sessionId.slice(0, 8)} in ${Date.now() - start} ms`);
|
|
102
120
|
}
|
|
103
121
|
clearQueue(sessionId) {
|
|
104
122
|
return this.on(sessionId, ({ pi }) => pi.clearQueue());
|
|
@@ -269,17 +287,16 @@ let TaServerImpl = class TaServerImpl {
|
|
|
269
287
|
}
|
|
270
288
|
getCommands(sessionId) {
|
|
271
289
|
return this.on(sessionId, ({ pi }) => ({
|
|
272
|
-
commands:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
...pi.resourceLoader
|
|
278
|
-
.getSkills()
|
|
279
|
-
.skills.map(s => ({ name: `skill:${s.name}`, description: s.description, source: 'skill', sourceInfo: s.sourceInfo })),
|
|
280
|
-
],
|
|
290
|
+
commands: slash_command_util_1.SlashCommandUtil.list({
|
|
291
|
+
commands: pi.extensionRunner.getRegisteredCommands(),
|
|
292
|
+
prompts: pi.promptTemplates,
|
|
293
|
+
skills: pi.resourceLoader.getSkills().skills,
|
|
294
|
+
}),
|
|
281
295
|
}));
|
|
282
296
|
}
|
|
297
|
+
getDirectoryCommands(cwd) {
|
|
298
|
+
return this.guard(async () => ({ commands: await this.factory.commands(cwd) }));
|
|
299
|
+
}
|
|
283
300
|
reload(sessionId) {
|
|
284
301
|
return this.on(sessionId, session => {
|
|
285
302
|
if (session.pi.isStreaming) {
|
|
@@ -312,6 +329,10 @@ __decorate([
|
|
|
312
329
|
(0, core_1.Autowired)(host_protocol_1.TaSessionCatalog),
|
|
313
330
|
__metadata("design:type", Object)
|
|
314
331
|
], TaServerImpl.prototype, "catalog", void 0);
|
|
332
|
+
__decorate([
|
|
333
|
+
(0, core_1.Autowired)(host_protocol_1.TaSessionFactory),
|
|
334
|
+
__metadata("design:type", Object)
|
|
335
|
+
], TaServerImpl.prototype, "factory", void 0);
|
|
315
336
|
exports.TaServerImpl = TaServerImpl = __decorate([
|
|
316
337
|
(0, rpc_1.Rpc)(ta_protocol_1.TaServer)
|
|
317
338
|
], TaServerImpl);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentExtension, AgentTool, type CodingAgentOptions, ModelRuntimeProvider, type PiSdk } from '@celljs/ai-coding-agent';
|
|
2
2
|
import { type ExecEnvironment, ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
3
3
|
import { type ContextFile, type InlineExtension, SessionLock } from '@celljs/ta-harness';
|
|
4
|
-
import type { TaOpenSessionOptions } from '@celljs/ta-protocol';
|
|
4
|
+
import type { TaOpenSessionOptions, TaSlashCommand } from '@celljs/ta-protocol';
|
|
5
5
|
import { ExtensionProviders } from './extension-providers';
|
|
6
6
|
import { type TaHostOptions, TaSessionFactory } from './host-protocol';
|
|
7
7
|
import { PackageHosts } from './package-hosts';
|
|
@@ -22,6 +22,15 @@ export declare namespace SessionFileUtil {
|
|
|
22
22
|
function cwdOverride(sessionFile: string, cwd: string): string | undefined;
|
|
23
23
|
}
|
|
24
24
|
type ModelRuntime = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).ModelRuntime;
|
|
25
|
+
type AgentSessionServices = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).AgentSessionServices;
|
|
26
|
+
interface ServicesOptions {
|
|
27
|
+
cwd: string;
|
|
28
|
+
agentDir: string;
|
|
29
|
+
modelRuntime: ModelRuntime;
|
|
30
|
+
lock: SessionLock;
|
|
31
|
+
appendSystemPrompt?: string;
|
|
32
|
+
commandsOnly?: boolean;
|
|
33
|
+
}
|
|
25
34
|
type SessionManager = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).SessionManager;
|
|
26
35
|
type Model = NonNullable<import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).AgentSession['model']>;
|
|
27
36
|
/** Sets up pi for each session the way its command does, with one model runtime for all of them. */
|
|
@@ -36,6 +45,12 @@ export declare class DefaultTaSessionFactory implements TaSessionFactory {
|
|
|
36
45
|
protected readonly directories: PiDirectories;
|
|
37
46
|
protected readonly extensionProviders: ExtensionProviders;
|
|
38
47
|
create(requested: TaOpenSessionOptions, requestClose: (session: TaSession, idle?: boolean) => void, id?: string): Promise<TaSession>;
|
|
48
|
+
commands(cwd: string): Promise<TaSlashCommand[]>;
|
|
49
|
+
/**
|
|
50
|
+
* pi's services of a session in `cwd` (a directory of pi): its settings, its resources and extensions with
|
|
51
|
+
* those of Ta. `commandsOnly`: for what a session would have, the context files of another machine not read.
|
|
52
|
+
*/
|
|
53
|
+
protected services(sdk: PiSdk, options: ServicesOptions): Promise<AgentSessionServices>;
|
|
39
54
|
protected openSessionManager(sdk: PiSdk, options: TaOpenSessionOptions): SessionManager;
|
|
40
55
|
/**
|
|
41
56
|
* For another machine, its context files (AGENTS.md...) instead of those pi finds above the directory
|
|
@@ -24,6 +24,7 @@ const package_hosts_1 = require("./package-hosts");
|
|
|
24
24
|
const remote_protocol_1 = require("./remote/remote-protocol");
|
|
25
25
|
const session_catalog_1 = require("./session-catalog");
|
|
26
26
|
const session_files_1 = require("./session-files");
|
|
27
|
+
const slash_command_util_1 = require("./slash-command-util");
|
|
27
28
|
const ta_errors_1 = require("./ta-errors");
|
|
28
29
|
const ta_session_1 = require("./ta-session");
|
|
29
30
|
var SessionFileUtil;
|
|
@@ -82,20 +83,7 @@ let DefaultTaSessionFactory = class DefaultTaSessionFactory {
|
|
|
82
83
|
const model = options.model ? this.resolveModel(modelRuntime, options.model) : undefined;
|
|
83
84
|
const runtime = await sdk.createAgentSessionRuntime(async ({ cwd, agentDir: dir, sessionManager: manager, sessionStartEvent }) => {
|
|
84
85
|
var _a;
|
|
85
|
-
const
|
|
86
|
-
const settingsManager = sdk.SettingsManager.create(cwd, dir, { projectTrusted: this.isTrusted(sdk, cwd, dir) });
|
|
87
|
-
const services = await sdk.createAgentSessionServices({
|
|
88
|
-
cwd,
|
|
89
|
-
agentDir: dir,
|
|
90
|
-
settingsManager,
|
|
91
|
-
modelRuntime,
|
|
92
|
-
resourceLoaderOptions: {
|
|
93
|
-
...ta_harness_1.TaPackages.loaderOptions(dir),
|
|
94
|
-
...(await this.contextFiles(environment, dir)),
|
|
95
|
-
extensionFactories: this.extensionFactories(sdk, environment, cwd, lock),
|
|
96
|
-
appendSystemPrompt: options.appendSystemPrompt ? [options.appendSystemPrompt] : undefined,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
86
|
+
const services = await this.services(sdk, { cwd, agentDir: dir, modelRuntime, lock, appendSystemPrompt: options.appendSystemPrompt });
|
|
99
87
|
const created = await sdk.createAgentSessionFromServices({
|
|
100
88
|
services,
|
|
101
89
|
sessionManager: manager,
|
|
@@ -125,6 +113,46 @@ let DefaultTaSessionFactory = class DefaultTaSessionFactory {
|
|
|
125
113
|
throw error;
|
|
126
114
|
}
|
|
127
115
|
}
|
|
116
|
+
async commands(cwd) {
|
|
117
|
+
var _a;
|
|
118
|
+
var _b;
|
|
119
|
+
const sdk = await ai_coding_agent_1.PiSdkUtil.load();
|
|
120
|
+
const agentDir = (_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : sdk.getAgentDir();
|
|
121
|
+
const services = await this.services(sdk, {
|
|
122
|
+
cwd: this.directories.toPi(cwd),
|
|
123
|
+
agentDir,
|
|
124
|
+
modelRuntime: await this.modelRuntimeProvider.provide(),
|
|
125
|
+
lock: new ta_harness_1.SessionLock(),
|
|
126
|
+
commandsOnly: true,
|
|
127
|
+
});
|
|
128
|
+
const loader = services.resourceLoader;
|
|
129
|
+
return slash_command_util_1.SlashCommandUtil.list({
|
|
130
|
+
commands: slash_command_util_1.SlashCommandUtil.invocationNames(loader.getExtensions().extensions.flatMap(extension => [...extension.commands.values()])),
|
|
131
|
+
prompts: loader.getPrompts().prompts,
|
|
132
|
+
skills: loader.getSkills().skills,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* pi's services of a session in `cwd` (a directory of pi): its settings, its resources and extensions with
|
|
137
|
+
* those of Ta. `commandsOnly`: for what a session would have, the context files of another machine not read.
|
|
138
|
+
*/
|
|
139
|
+
async services(sdk, options) {
|
|
140
|
+
const { cwd, agentDir, modelRuntime, lock, appendSystemPrompt, commandsOnly } = options;
|
|
141
|
+
const environment = this.environments.create(this.directories.fromPi(cwd));
|
|
142
|
+
const settingsManager = sdk.SettingsManager.create(cwd, agentDir, { projectTrusted: this.isTrusted(sdk, cwd, agentDir) });
|
|
143
|
+
return sdk.createAgentSessionServices({
|
|
144
|
+
cwd,
|
|
145
|
+
agentDir,
|
|
146
|
+
settingsManager,
|
|
147
|
+
modelRuntime,
|
|
148
|
+
resourceLoaderOptions: {
|
|
149
|
+
...ta_harness_1.TaPackages.loaderOptions(agentDir),
|
|
150
|
+
...(commandsOnly ? {} : await this.contextFiles(environment, agentDir)),
|
|
151
|
+
extensionFactories: this.extensionFactories(sdk, environment, cwd, lock),
|
|
152
|
+
appendSystemPrompt: appendSystemPrompt ? [appendSystemPrompt] : undefined,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
128
156
|
openSessionManager(sdk, options) {
|
|
129
157
|
if (!options.sessionFile) {
|
|
130
158
|
return sdk.SessionManager.create(options.cwd);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
2
|
-
import type { TaOpenSessionOptions } from '@celljs/ta-protocol';
|
|
2
|
+
import type { TaOpenSessionOptions, TaSessionInfo } from '@celljs/ta-protocol';
|
|
3
3
|
import { ClientChannel } from './client-channel';
|
|
4
4
|
import { type TaHostOptions, TaSessionFactory, TaSessionRegistry } from './host-protocol';
|
|
5
5
|
import { TaSessionHandles } from './session-handles';
|
|
6
|
+
import { SessionListFeed } from './session-list-feed';
|
|
6
7
|
import type { TaSession } from './ta-session';
|
|
7
8
|
/**
|
|
8
9
|
* The open sessions. A session's id outlives its memory: closed while idle or by a restart, it opens again
|
|
@@ -20,10 +21,12 @@ export declare class DefaultTaSessionRegistry implements TaSessionRegistry {
|
|
|
20
21
|
protected readonly closing: Map<string, Promise<void>>;
|
|
21
22
|
/** Sessions opening again under their ids: the calls that come meanwhile wait for the same. */
|
|
22
23
|
protected readonly waking: Map<string, Promise<TaSession>>;
|
|
24
|
+
protected readonly feed: SessionListFeed;
|
|
23
25
|
open(options: TaOpenSessionOptions): Promise<TaSession>;
|
|
24
26
|
require(sessionId: string): TaSession;
|
|
25
27
|
resolve(sessionId: string): Promise<TaSession>;
|
|
26
28
|
list(): TaSession[];
|
|
29
|
+
watch(connection: RpcConnection): TaSessionInfo[];
|
|
27
30
|
close(sessionId: string, idle?: boolean): Promise<void>;
|
|
28
31
|
closeAll(): Promise<void>;
|
|
29
32
|
/** The one channel of a connection; it leaves every session when the connection ends. */
|
|
@@ -15,6 +15,7 @@ const core_1 = require("@celljs/core");
|
|
|
15
15
|
const client_channel_1 = require("./client-channel");
|
|
16
16
|
const host_protocol_1 = require("./host-protocol");
|
|
17
17
|
const session_handles_1 = require("./session-handles");
|
|
18
|
+
const session_list_feed_1 = require("./session-list-feed");
|
|
18
19
|
const ta_errors_1 = require("./ta-errors");
|
|
19
20
|
/**
|
|
20
21
|
* The open sessions. A session's id outlives its memory: closed while idle or by a restart, it opens again
|
|
@@ -30,6 +31,7 @@ let DefaultTaSessionRegistry = class DefaultTaSessionRegistry {
|
|
|
30
31
|
this.closing = new Map();
|
|
31
32
|
/** Sessions opening again under their ids: the calls that come meanwhile wait for the same. */
|
|
32
33
|
this.waking = new Map();
|
|
34
|
+
this.feed = new session_list_feed_1.SessionListFeed(() => this.list().map(session => session.info()));
|
|
33
35
|
}
|
|
34
36
|
open(options) {
|
|
35
37
|
// A file that had a session keeps its id, which pages may still have.
|
|
@@ -68,6 +70,9 @@ let DefaultTaSessionRegistry = class DefaultTaSessionRegistry {
|
|
|
68
70
|
list() {
|
|
69
71
|
return [...this.sessions.values()];
|
|
70
72
|
}
|
|
73
|
+
watch(connection) {
|
|
74
|
+
return this.feed.watch(connection);
|
|
75
|
+
}
|
|
71
76
|
async close(sessionId, idle = false) {
|
|
72
77
|
if (!idle) {
|
|
73
78
|
this.handles.delete(sessionId);
|
|
@@ -77,6 +82,7 @@ let DefaultTaSessionRegistry = class DefaultTaSessionRegistry {
|
|
|
77
82
|
return;
|
|
78
83
|
}
|
|
79
84
|
this.sessions.delete(sessionId);
|
|
85
|
+
this.feed.changed();
|
|
80
86
|
const file = session.pi.sessionFile;
|
|
81
87
|
if (idle && file) {
|
|
82
88
|
// The conversation it has now: pi may have moved to another file since it opened.
|
|
@@ -127,6 +133,8 @@ let DefaultTaSessionRegistry = class DefaultTaSessionRegistry {
|
|
|
127
133
|
try {
|
|
128
134
|
const session = await this.factory.create(options, (ended, idle) => void this.close(ended.id, idle), id);
|
|
129
135
|
this.sessions.set(session.id, session);
|
|
136
|
+
session.onInfoChange(() => this.sessions.get(session.id) === session && this.feed.changed());
|
|
137
|
+
this.feed.changed();
|
|
130
138
|
const sessionFile = session.pi.sessionFile;
|
|
131
139
|
if (sessionFile) {
|
|
132
140
|
this.handles.set(session.id, { sessionFile, cwd: session.cwd, clientTools: options.clientTools });
|
package/lib/node/ta-session.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SessionLock } from '@celljs/ta-harness';
|
|
2
|
-
import type { RpcExtensionUIResponse, TaAttachOptions, TaAttachResult, TaClientToolResult, TaConversation, TaEvent, TaMessagePage, TaNavigateResult, TaPromptInput, TaPromptReceipt, TaSessionInfo } from '@celljs/ta-protocol';
|
|
2
|
+
import type { ImageContent, RpcExtensionUIResponse, TaAttachOptions, TaAttachResult, TaClientToolResult, TaConversation, TaEvent, TaMessagePage, TaNavigateResult, TaPromptInput, TaPromptReceipt, TaSessionInfo } from '@celljs/ta-protocol';
|
|
3
3
|
import type { ClientChannel } from './client-channel';
|
|
4
4
|
import type { ClientToolBroker } from './client-tool-broker';
|
|
5
5
|
import { EventLog } from './event-log';
|
|
@@ -44,21 +44,27 @@ export declare class TaSession {
|
|
|
44
44
|
protected unsubscribe?: () => void;
|
|
45
45
|
protected idleTimer?: ReturnType<typeof setTimeout>;
|
|
46
46
|
protected started: boolean;
|
|
47
|
+
protected readonly infoListeners: Set<() => void>;
|
|
47
48
|
constructor(context: TaSessionContext);
|
|
48
49
|
get pi(): AgentSession;
|
|
49
50
|
/** Where the session works, as clients name it: a path, or an `ssh://` location. */
|
|
50
51
|
get cwd(): string;
|
|
51
52
|
start(): Promise<void>;
|
|
52
53
|
info(): TaSessionInfo;
|
|
54
|
+
/** What `info` gives may have changed (TaServer.watchSessions). */
|
|
55
|
+
onInfoChange(listener: () => void): () => void;
|
|
53
56
|
attach(channel: ClientChannel, afterSeq?: number, options?: TaAttachOptions): TaAttachResult;
|
|
54
57
|
earlierMessages(before: number | undefined, timestamp: number | undefined, budget: number): TaMessagePage;
|
|
58
|
+
/** The image of a message of the user that the conversation gives without its bytes (TaShownImage). */
|
|
59
|
+
messageImage(timestamp: number, index: number): ImageContent | undefined;
|
|
55
60
|
/** The conversation of the events sent, as clients get it. */
|
|
56
61
|
protected conversation(): TaConversation;
|
|
57
62
|
detach(channel: ClientChannel): void;
|
|
58
63
|
respondUi(response: RpcExtensionUIResponse): boolean;
|
|
59
64
|
/** Only a client attached runs a call: one that left would hold it for nobody. */
|
|
60
65
|
claimClientTool(channel: ClientChannel, id: string): boolean;
|
|
61
|
-
|
|
66
|
+
/** Only a client attached answers, and only the one that claimed the call when one did. */
|
|
67
|
+
respondClientTool(channel: ClientChannel, result: TaClientToolResult): boolean;
|
|
62
68
|
prompt(input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
63
69
|
steer(input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
64
70
|
followUp(input: TaPromptInput): Promise<TaPromptReceipt>;
|
package/lib/node/ta-session.js
CHANGED
|
@@ -10,6 +10,16 @@ const remote_ui_context_1 = require("./remote-ui-context");
|
|
|
10
10
|
const session_catalog_1 = require("./session-catalog");
|
|
11
11
|
const session_info_util_1 = require("./session-info-util");
|
|
12
12
|
const ta_event_util_1 = require("./ta-event-util");
|
|
13
|
+
/** The events after which what a list shows of a session (its info) may differ. */
|
|
14
|
+
const INFO_EVENTS = new Set([
|
|
15
|
+
'agent_start',
|
|
16
|
+
'agent_settled',
|
|
17
|
+
'message_end',
|
|
18
|
+
'session_info_changed',
|
|
19
|
+
'session_replaced',
|
|
20
|
+
'extension_ui_request',
|
|
21
|
+
'ui_request_resolved',
|
|
22
|
+
]);
|
|
13
23
|
/**
|
|
14
24
|
* One open session of `ta serve`: pi's runtime, its event log, and the clients attached to it. Its id
|
|
15
25
|
* stays the same while the runtime moves between conversations.
|
|
@@ -23,6 +33,7 @@ class TaSession {
|
|
|
23
33
|
this.channels = new Set();
|
|
24
34
|
this.live = new live_run_1.LiveRun();
|
|
25
35
|
this.started = false;
|
|
36
|
+
this.infoListeners = new Set();
|
|
26
37
|
this.runtime = context.runtime;
|
|
27
38
|
this.id = (_a = context.id) !== null && _a !== void 0 ? _a : (0, node_crypto_1.randomUUID)();
|
|
28
39
|
// Opened again: its seqs start past any the session gave before (fewer than one per millisecond), so a
|
|
@@ -58,6 +69,7 @@ class TaSession {
|
|
|
58
69
|
lastMessage: session_info_util_1.SessionInfoUtil.lastMessage(pi.messages),
|
|
59
70
|
model: model ? `${model.provider}/${model.id}` : undefined,
|
|
60
71
|
isStreaming: pi.isStreaming,
|
|
72
|
+
waiting: this.ui.pendingRequests.length > 0,
|
|
61
73
|
messageCount: pi.messages.length,
|
|
62
74
|
attached: this.channels.size,
|
|
63
75
|
createdAt: this.createdAt,
|
|
@@ -65,6 +77,11 @@ class TaSession {
|
|
|
65
77
|
group: this.context.group,
|
|
66
78
|
};
|
|
67
79
|
}
|
|
80
|
+
/** What `info` gives may have changed (TaServer.watchSessions). */
|
|
81
|
+
onInfoChange(listener) {
|
|
82
|
+
this.infoListeners.add(listener);
|
|
83
|
+
return () => this.infoListeners.delete(listener);
|
|
84
|
+
}
|
|
68
85
|
attach(channel, afterSeq, options = {}) {
|
|
69
86
|
this.channels.add(channel);
|
|
70
87
|
this.watchIdle();
|
|
@@ -83,6 +100,13 @@ class TaSession {
|
|
|
83
100
|
earlierMessages(before, timestamp, budget) {
|
|
84
101
|
return message_page_1.MessagePage.before(this.conversation().messages, before, timestamp, budget);
|
|
85
102
|
}
|
|
103
|
+
/** The image of a message of the user that the conversation gives without its bytes (TaShownImage). */
|
|
104
|
+
messageImage(timestamp, index) {
|
|
105
|
+
var _a;
|
|
106
|
+
const message = [...this.pi.messages].reverse().find(candidate => candidate.role === 'user' && candidate.timestamp === timestamp);
|
|
107
|
+
const block = Array.isArray(message === null || message === void 0 ? void 0 : message.content) ? message.content[index] : undefined;
|
|
108
|
+
return (block === null || block === void 0 ? void 0 : block.type) === 'image' && block.data ? { type: 'image', data: block.data, mimeType: (_a = block.mimeType) !== null && _a !== void 0 ? _a : '' } : undefined;
|
|
109
|
+
}
|
|
86
110
|
/** The conversation of the events sent, as clients get it. */
|
|
87
111
|
conversation() {
|
|
88
112
|
return ta_event_util_1.TaEventUtil.leanConversation(this.live.conversation(this.pi.messages, this.pi.isStreaming));
|
|
@@ -100,8 +124,9 @@ class TaSession {
|
|
|
100
124
|
claimClientTool(channel, id) {
|
|
101
125
|
return this.channels.has(channel) && this.context.clientTools.claim(id, channel);
|
|
102
126
|
}
|
|
103
|
-
|
|
104
|
-
|
|
127
|
+
/** Only a client attached answers, and only the one that claimed the call when one did. */
|
|
128
|
+
respondClientTool(channel, result) {
|
|
129
|
+
return this.channels.has(channel) && this.context.clientTools.respond(result, channel);
|
|
105
130
|
}
|
|
106
131
|
prompt(input) {
|
|
107
132
|
return this.accept(input, () => new Promise((resolve, reject) => {
|
|
@@ -180,8 +205,15 @@ class TaSession {
|
|
|
180
205
|
// Its failure is no reason to keep the session: dispose below aborts the run as well.
|
|
181
206
|
await this.within(this.pi.abort().catch(() => undefined));
|
|
182
207
|
}
|
|
183
|
-
|
|
184
|
-
|
|
208
|
+
let disposed = false;
|
|
209
|
+
try {
|
|
210
|
+
disposed = await this.within(this.runtime.dispose());
|
|
211
|
+
}
|
|
212
|
+
finally {
|
|
213
|
+
// Late or failed: either way nothing more of pi goes into the file once it is unlocked.
|
|
214
|
+
if (!disposed) {
|
|
215
|
+
this.pi.dispose();
|
|
216
|
+
}
|
|
185
217
|
}
|
|
186
218
|
}
|
|
187
219
|
finally {
|
|
@@ -257,6 +289,11 @@ class TaSession {
|
|
|
257
289
|
for (const channel of this.channels) {
|
|
258
290
|
channel.send(logged);
|
|
259
291
|
}
|
|
292
|
+
if (INFO_EVENTS.has(event.type)) {
|
|
293
|
+
for (const listener of this.infoListeners) {
|
|
294
|
+
listener();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
260
297
|
}
|
|
261
298
|
isIdle() {
|
|
262
299
|
return this.channels.size === 0 && !this.pi.isStreaming && this.ui.pendingRequests.length === 0;
|
|
@@ -37,6 +37,11 @@ export declare class WebExtensionCatalogImpl implements WebExtensionCatalog {
|
|
|
37
37
|
setTemporaryRetention(days: number): void;
|
|
38
38
|
protected temporary(): TemporaryStore;
|
|
39
39
|
packageOf(cwd: string, id: string): Promise<TaPackageInfo>;
|
|
40
|
+
/**
|
|
41
|
+
* The package an id names: its id of listPackages, or the id of one of its web extensions. Every method of a
|
|
42
|
+
* package takes either, so that a client holding a web extension never looks for its package first.
|
|
43
|
+
*/
|
|
44
|
+
protected findPackage(packages: WebExtensionPackage[], id: string, kind?: string): WebExtensionPackage;
|
|
40
45
|
/** A package another computer shared by a link, put in Ta's own temporary directory (RelayShareUtil). */
|
|
41
46
|
protected fetchShare(link: string): Promise<string>;
|
|
42
47
|
protected fetch(manager: PackageManager, source: string): Promise<string>;
|
|
@@ -46,7 +51,6 @@ export declare class WebExtensionCatalogImpl implements WebExtensionCatalog {
|
|
|
46
51
|
removePackage(cwd: string, id: string): Promise<void>;
|
|
47
52
|
list(cwd: string): Promise<TaWebExtensionInfo[]>;
|
|
48
53
|
read(cwd: string, id: string): Promise<TaWebExtensionSource>;
|
|
49
|
-
remove(cwd: string, id: string): Promise<void>;
|
|
50
54
|
setEnabled(cwd: string, nameOrId: string, enabled: boolean): Promise<void>;
|
|
51
55
|
protected removeRoot(pkg: WebExtensionPackage, manager: PackageManager): Promise<void>;
|
|
52
56
|
protected agentDir(): string;
|
|
@@ -130,11 +130,18 @@ let WebExtensionCatalogImpl = class WebExtensionCatalogImpl {
|
|
|
130
130
|
}
|
|
131
131
|
async packageOf(cwd, id) {
|
|
132
132
|
const { packages } = await this.load(cwd);
|
|
133
|
+
return web_extension_util_1.WebExtensionUtil.describePackage(this.findPackage(packages, id));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The package an id names: its id of listPackages, or the id of one of its web extensions. Every method of a
|
|
137
|
+
* package takes either, so that a client holding a web extension never looks for its package first.
|
|
138
|
+
*/
|
|
139
|
+
findPackage(packages, id, kind = 'package') {
|
|
133
140
|
const pkg = packages.find(candidate => web_extension_util_1.WebExtensionUtil.describePackage(candidate).id === id || web_extension_util_1.WebExtensionUtil.describe(candidate).some(info => info.id === id));
|
|
134
141
|
if (!pkg) {
|
|
135
|
-
throw ta_errors_1.TaErrors.invalidArgument(`No
|
|
142
|
+
throw ta_errors_1.TaErrors.invalidArgument(`No ${kind} has the id ${id}.`, 'listPackages lists the ones there are; the package may have moved or gone.');
|
|
136
143
|
}
|
|
137
|
-
return
|
|
144
|
+
return pkg;
|
|
138
145
|
}
|
|
139
146
|
/** A package another computer shared by a link, put in Ta's own temporary directory (RelayShareUtil). */
|
|
140
147
|
async fetchShare(link) {
|
|
@@ -159,12 +166,7 @@ let WebExtensionCatalogImpl = class WebExtensionCatalogImpl {
|
|
|
159
166
|
}
|
|
160
167
|
async findTemporary(cwd, id) {
|
|
161
168
|
const { packages } = await this.load(cwd);
|
|
162
|
-
|
|
163
|
-
(web_extension_util_1.WebExtensionUtil.describePackage(candidate).id === id || web_extension_util_1.WebExtensionUtil.describe(candidate).some(info => info.id === id)));
|
|
164
|
-
if (!pkg) {
|
|
165
|
-
throw ta_errors_1.TaErrors.invalidArgument(`No temporary package has the id ${id}.`, 'listPackages lists the ones there are; it may have been installed, removed or cleared.');
|
|
166
|
-
}
|
|
167
|
-
return pkg;
|
|
169
|
+
return this.findPackage(packages.filter(candidate => candidate.origin === 'temporary'), id, 'temporary package');
|
|
168
170
|
}
|
|
169
171
|
/** Ta's own directory is deleted, what pi fetched removed, a path of the user's only forgotten. */
|
|
170
172
|
async dropTemporary(record, manager) {
|
|
@@ -179,11 +181,7 @@ let WebExtensionCatalogImpl = class WebExtensionCatalogImpl {
|
|
|
179
181
|
}
|
|
180
182
|
async removePackage(cwd, id) {
|
|
181
183
|
const { packages, manager } = await this.load(cwd);
|
|
182
|
-
|
|
183
|
-
if (!pkg) {
|
|
184
|
-
throw ta_errors_1.TaErrors.invalidArgument(`No package has the id ${id}.`, 'listPackages lists the ones there are; the package may have moved or gone.');
|
|
185
|
-
}
|
|
186
|
-
await this.removeRoot(pkg, manager);
|
|
184
|
+
await this.removeRoot(this.findPackage(packages, id), manager);
|
|
187
185
|
}
|
|
188
186
|
async list(cwd) {
|
|
189
187
|
const { packages } = await this.load(cwd);
|
|
@@ -194,19 +192,17 @@ let WebExtensionCatalogImpl = class WebExtensionCatalogImpl {
|
|
|
194
192
|
const code = web_extension_util_1.WebExtensionUtil.read(pkg, info.entry);
|
|
195
193
|
return { id, hash: web_extension_util_1.WebExtensionUtil.hash(code), code };
|
|
196
194
|
}
|
|
197
|
-
async remove(cwd, id) {
|
|
198
|
-
const { pkg } = await this.find(cwd, id);
|
|
199
|
-
await this.removeRoot(pkg, (await this.load(cwd)).manager);
|
|
200
|
-
}
|
|
201
195
|
async setEnabled(cwd, nameOrId, enabled) {
|
|
202
196
|
if (ta_packages_1.TaPackages.builtins().some(pkg => pkg.name === nameOrId)) {
|
|
203
197
|
ta_packages_1.TaPackages.setEnabled(this.agentDir(), nameOrId, enabled);
|
|
204
198
|
return;
|
|
205
199
|
}
|
|
206
200
|
const loaded = await this.load(cwd);
|
|
207
|
-
const pkg = loaded.packages.find(candidate => candidate.origin !== 'builtin' &&
|
|
201
|
+
const pkg = loaded.packages.find(candidate => candidate.origin !== 'builtin' &&
|
|
202
|
+
candidate.origin !== 'temporary' &&
|
|
203
|
+
(web_extension_util_1.WebExtensionUtil.describePackage(candidate).id === nameOrId || web_extension_util_1.WebExtensionUtil.describe(candidate).some(info => info.id === nameOrId)));
|
|
208
204
|
if (!pkg) {
|
|
209
|
-
throw ta_errors_1.TaErrors.invalidArgument(`${nameOrId} is neither a package that comes with Ta nor the id of a package.`, 'Pass the name of a built-in package, or an id of listPackages.');
|
|
205
|
+
throw ta_errors_1.TaErrors.invalidArgument(`${nameOrId} is neither a package that comes with Ta nor the id of a package.`, 'Pass the name of a built-in package, or an id of listPackages or of one of its web extensions.');
|
|
210
206
|
}
|
|
211
207
|
const resources = package_switch_1.PackageSwitch.resourcesOf(await this.resolve(loaded.manager), pkg.root);
|
|
212
208
|
if (resources.length === 0) {
|