@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TaImageSize } from '@celljs/ta-protocol';
|
|
1
2
|
/** The lean form of each message and result met, made once: the pages of a conversation measure it by its object. */
|
|
2
3
|
const leaned = new WeakMap();
|
|
3
4
|
export var TaEventUtil;
|
|
@@ -65,21 +66,46 @@ export var TaEventUtil;
|
|
|
65
66
|
return lean;
|
|
66
67
|
}
|
|
67
68
|
TaEventUtil.leanResult = leanResult;
|
|
68
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* A conversation as clients get it: its messages and the results of its calls lean, and the images of the
|
|
71
|
+
* messages of the user without their bytes but with their size (`TaShownImage`): they come with
|
|
72
|
+
* `getMessageImage` once shown, and a conversation with pictures opens as fast as one without. Events keep
|
|
73
|
+
* them: a message just sent shows on every device at once.
|
|
74
|
+
*/
|
|
69
75
|
function leanConversation(conversation) {
|
|
70
76
|
const tools = {};
|
|
71
77
|
for (const [id, run] of Object.entries(conversation.tools)) {
|
|
72
78
|
tools[id] = run.result === undefined ? run : { ...run, result: leanResult(run.result) };
|
|
73
79
|
}
|
|
74
|
-
return { ...conversation, messages: leanAll(conversation.messages), tools };
|
|
80
|
+
return { ...conversation, messages: leanAll(conversation.messages, leanShown), tools };
|
|
75
81
|
}
|
|
76
82
|
TaEventUtil.leanConversation = leanConversation;
|
|
77
|
-
|
|
83
|
+
/** A message as a page of the conversation gives it: `leanMessage`, and the images of the user's without their bytes. */
|
|
84
|
+
function leanShown(message) {
|
|
85
|
+
const { role, content } = message;
|
|
86
|
+
if (role !== 'user' || !Array.isArray(content)) {
|
|
87
|
+
return leanMessage(message);
|
|
88
|
+
}
|
|
89
|
+
const known = leaned.get(message);
|
|
90
|
+
if (known) {
|
|
91
|
+
return known;
|
|
92
|
+
}
|
|
93
|
+
const heavy = content.some(block => (block === null || block === void 0 ? void 0 : block.type) === 'image' && block.data);
|
|
94
|
+
const lean = heavy ? { ...message, content: content.map(block => ((block === null || block === void 0 ? void 0 : block.type) === 'image' ? shown(block) : block)) } : message;
|
|
95
|
+
leaned.set(message, lean);
|
|
96
|
+
return lean;
|
|
97
|
+
}
|
|
98
|
+
TaEventUtil.leanShown = leanShown;
|
|
99
|
+
function shown(block) {
|
|
100
|
+
var _a;
|
|
101
|
+
return { type: 'image', mimeType: (_a = block.mimeType) !== null && _a !== void 0 ? _a : '', data: '', ...(block.data ? TaImageSize.of(block.data) : undefined) };
|
|
102
|
+
}
|
|
103
|
+
function leanAll(messages, lean = leanMessage) {
|
|
78
104
|
if (!Array.isArray(messages)) {
|
|
79
105
|
return messages;
|
|
80
106
|
}
|
|
81
|
-
const
|
|
82
|
-
return
|
|
107
|
+
const leant = messages.map(lean);
|
|
108
|
+
return leant.every((message, index) => message === messages[index]) ? messages : leant;
|
|
83
109
|
}
|
|
84
110
|
function withLean(event, key, value) {
|
|
85
111
|
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.js';
|
|
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.js';
|
|
4
4
|
import type { TaSession } from './ta-session.js';
|
|
5
5
|
import { TaWorkingDirectory } from './working-directory.js';
|
|
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>;
|
|
@@ -60,7 +63,12 @@ export declare class TaServerImpl implements TaServer {
|
|
|
60
63
|
getLastAssistantText(sessionId: string): Promise<TaCommandResult<'get_last_assistant_text'>>;
|
|
61
64
|
setSessionName(sessionId: string, name: string): Promise<void>;
|
|
62
65
|
getMessages(sessionId: string): Promise<TaCommandResult<'get_messages'>>;
|
|
63
|
-
getCommands(sessionId: string): Promise<
|
|
66
|
+
getCommands(sessionId: string): Promise<{
|
|
67
|
+
commands: TaSlashCommand[];
|
|
68
|
+
}>;
|
|
69
|
+
getDirectoryCommands(cwd: string): Promise<{
|
|
70
|
+
commands: TaSlashCommand[];
|
|
71
|
+
}>;
|
|
64
72
|
reload(sessionId: string): Promise<void>;
|
|
65
73
|
protected on<T>(sessionId: string, command: (session: TaSession) => T | Promise<T>): Promise<T>;
|
|
66
74
|
protected guard<T>(command: () => Promise<T>): Promise<T>;
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { existsSync } from 'node:fs';
|
|
11
|
-
import { hostname, userInfo } from 'node:os';
|
|
11
|
+
import { homedir, hostname, userInfo } from 'node:os';
|
|
12
12
|
import { PiSdkUtil } from '@celljs/ai-coding-agent';
|
|
13
13
|
import { Autowired } from '@celljs/core';
|
|
14
14
|
import { Rpc } from '@celljs/rpc';
|
|
@@ -16,8 +16,9 @@ import { RpcContext } from '@celljs/rpc/lib/node';
|
|
|
16
16
|
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
17
17
|
import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
|
|
18
18
|
import { TaServer, } from '@celljs/ta-protocol';
|
|
19
|
-
import { TaSessionCatalog, TaSessionRegistry } from './host-protocol.js';
|
|
19
|
+
import { TaSessionCatalog, TaSessionFactory, TaSessionRegistry } from './host-protocol.js';
|
|
20
20
|
import { SessionInfoUtil } from './session-info-util.js';
|
|
21
|
+
import { SlashCommandUtil } from './slash-command-util.js';
|
|
21
22
|
import { TaErrors } from './ta-errors.js';
|
|
22
23
|
import { TaWorkingDirectory } from './working-directory.js';
|
|
23
24
|
/**
|
|
@@ -32,6 +33,7 @@ let TaServerImpl = class TaServerImpl {
|
|
|
32
33
|
cwd: await this.environments.defaultCwd(),
|
|
33
34
|
user: userInfo().username,
|
|
34
35
|
host: hostname().replace(/\.local$/, ''),
|
|
36
|
+
home: homedir(),
|
|
35
37
|
}));
|
|
36
38
|
}
|
|
37
39
|
async setWorkingDirectory(cwd) {
|
|
@@ -46,8 +48,15 @@ let TaServerImpl = class TaServerImpl {
|
|
|
46
48
|
return this.getServerInfo();
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
|
-
async openSession(options) {
|
|
50
|
-
return this.guard(async () =>
|
|
51
|
+
async openSession({ attach, ...options }) {
|
|
52
|
+
return this.guard(async () => {
|
|
53
|
+
const session = await this.sessions.open(options);
|
|
54
|
+
if (!attach) {
|
|
55
|
+
return session.info();
|
|
56
|
+
}
|
|
57
|
+
const attached = session.attach(this.sessions.channel(RpcContext.requireConnection()), undefined, attach);
|
|
58
|
+
return { ...attached.info, attachment: attached };
|
|
59
|
+
});
|
|
51
60
|
}
|
|
52
61
|
closeSession(sessionId) {
|
|
53
62
|
return this.guard(() => this.sessions.close(sessionId));
|
|
@@ -55,10 +64,13 @@ let TaServerImpl = class TaServerImpl {
|
|
|
55
64
|
async listSessions() {
|
|
56
65
|
return this.sessions.list().map(session => session.info());
|
|
57
66
|
}
|
|
58
|
-
|
|
67
|
+
async watchSessions() {
|
|
68
|
+
return this.sessions.watch(RpcContext.requireConnection());
|
|
69
|
+
}
|
|
70
|
+
listSavedSessions(query) {
|
|
59
71
|
return this.guard(async () => {
|
|
60
72
|
const open = new Set(this.sessions.list().flatMap(session => { var _a; return (_a = session.pi.sessionFile) !== null && _a !== void 0 ? _a : []; }));
|
|
61
|
-
return this.catalog.list(open);
|
|
73
|
+
return this.catalog.list(open, query !== null && query !== void 0 ? query : undefined);
|
|
62
74
|
});
|
|
63
75
|
}
|
|
64
76
|
attach(sessionId, afterSeq, options) {
|
|
@@ -67,6 +79,9 @@ let TaServerImpl = class TaServerImpl {
|
|
|
67
79
|
getEarlierMessages(sessionId, before, timestamp, budget) {
|
|
68
80
|
return this.on(sessionId, session => session.earlierMessages(before !== null && before !== void 0 ? before : undefined, timestamp !== null && timestamp !== void 0 ? timestamp : undefined, budget));
|
|
69
81
|
}
|
|
82
|
+
getMessageImage(sessionId, timestamp, index) {
|
|
83
|
+
return this.on(sessionId, session => session.messageImage(timestamp, index));
|
|
84
|
+
}
|
|
70
85
|
detach(sessionId) {
|
|
71
86
|
// Not opened again to be left: a session closed meanwhile has no client.
|
|
72
87
|
return this.guard(async () => {
|
|
@@ -83,7 +98,7 @@ let TaServerImpl = class TaServerImpl {
|
|
|
83
98
|
return this.on(sessionId, session => session.claimClientTool(this.sessions.channel(RpcContext.requireConnection()), id));
|
|
84
99
|
}
|
|
85
100
|
respondClientTool(sessionId, result) {
|
|
86
|
-
return this.on(sessionId, session => session.respondClientTool(result));
|
|
101
|
+
return this.on(sessionId, session => session.respondClientTool(this.sessions.channel(RpcContext.requireConnection()), result));
|
|
87
102
|
}
|
|
88
103
|
prompt(sessionId, input) {
|
|
89
104
|
return this.on(sessionId, session => session.prompt(input));
|
|
@@ -266,17 +281,16 @@ let TaServerImpl = class TaServerImpl {
|
|
|
266
281
|
}
|
|
267
282
|
getCommands(sessionId) {
|
|
268
283
|
return this.on(sessionId, ({ pi }) => ({
|
|
269
|
-
commands:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
...pi.resourceLoader
|
|
275
|
-
.getSkills()
|
|
276
|
-
.skills.map(s => ({ name: `skill:${s.name}`, description: s.description, source: 'skill', sourceInfo: s.sourceInfo })),
|
|
277
|
-
],
|
|
284
|
+
commands: SlashCommandUtil.list({
|
|
285
|
+
commands: pi.extensionRunner.getRegisteredCommands(),
|
|
286
|
+
prompts: pi.promptTemplates,
|
|
287
|
+
skills: pi.resourceLoader.getSkills().skills,
|
|
288
|
+
}),
|
|
278
289
|
}));
|
|
279
290
|
}
|
|
291
|
+
getDirectoryCommands(cwd) {
|
|
292
|
+
return this.guard(async () => ({ commands: await this.factory.commands(cwd) }));
|
|
293
|
+
}
|
|
280
294
|
reload(sessionId) {
|
|
281
295
|
return this.on(sessionId, session => {
|
|
282
296
|
if (session.pi.isStreaming) {
|
|
@@ -308,6 +322,10 @@ __decorate([
|
|
|
308
322
|
Autowired(TaSessionCatalog),
|
|
309
323
|
__metadata("design:type", Object)
|
|
310
324
|
], TaServerImpl.prototype, "catalog", void 0);
|
|
325
|
+
__decorate([
|
|
326
|
+
Autowired(TaSessionFactory),
|
|
327
|
+
__metadata("design:type", Object)
|
|
328
|
+
], TaServerImpl.prototype, "factory", void 0);
|
|
311
329
|
TaServerImpl = __decorate([
|
|
312
330
|
Rpc(TaServer)
|
|
313
331
|
], 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.js';
|
|
6
6
|
import { type TaHostOptions, TaSessionFactory } from './host-protocol.js';
|
|
7
7
|
import { PackageHosts } from './package-hosts.js';
|
|
@@ -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
|
|
@@ -21,6 +21,7 @@ import { PackageHosts } from './package-hosts.js';
|
|
|
21
21
|
import { PiDirectories } from './remote/remote-protocol.js';
|
|
22
22
|
import { SessionCatalogUtil } from './session-catalog.js';
|
|
23
23
|
import { ExecSessionFiles } from './session-files.js';
|
|
24
|
+
import { SlashCommandUtil } from './slash-command-util.js';
|
|
24
25
|
import { TaErrors } from './ta-errors.js';
|
|
25
26
|
import { TaSession } from './ta-session.js';
|
|
26
27
|
export var SessionFileUtil;
|
|
@@ -79,20 +80,7 @@ let DefaultTaSessionFactory = class DefaultTaSessionFactory {
|
|
|
79
80
|
const model = options.model ? this.resolveModel(modelRuntime, options.model) : undefined;
|
|
80
81
|
const runtime = await sdk.createAgentSessionRuntime(async ({ cwd, agentDir: dir, sessionManager: manager, sessionStartEvent }) => {
|
|
81
82
|
var _a;
|
|
82
|
-
const
|
|
83
|
-
const settingsManager = sdk.SettingsManager.create(cwd, dir, { projectTrusted: this.isTrusted(sdk, cwd, dir) });
|
|
84
|
-
const services = await sdk.createAgentSessionServices({
|
|
85
|
-
cwd,
|
|
86
|
-
agentDir: dir,
|
|
87
|
-
settingsManager,
|
|
88
|
-
modelRuntime,
|
|
89
|
-
resourceLoaderOptions: {
|
|
90
|
-
...TaPackages.loaderOptions(dir),
|
|
91
|
-
...(await this.contextFiles(environment, dir)),
|
|
92
|
-
extensionFactories: this.extensionFactories(sdk, environment, cwd, lock),
|
|
93
|
-
appendSystemPrompt: options.appendSystemPrompt ? [options.appendSystemPrompt] : undefined,
|
|
94
|
-
},
|
|
95
|
-
});
|
|
83
|
+
const services = await this.services(sdk, { cwd, agentDir: dir, modelRuntime, lock, appendSystemPrompt: options.appendSystemPrompt });
|
|
96
84
|
const created = await sdk.createAgentSessionFromServices({
|
|
97
85
|
services,
|
|
98
86
|
sessionManager: manager,
|
|
@@ -122,6 +110,46 @@ let DefaultTaSessionFactory = class DefaultTaSessionFactory {
|
|
|
122
110
|
throw error;
|
|
123
111
|
}
|
|
124
112
|
}
|
|
113
|
+
async commands(cwd) {
|
|
114
|
+
var _a;
|
|
115
|
+
var _b;
|
|
116
|
+
const sdk = await PiSdkUtil.load();
|
|
117
|
+
const agentDir = (_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : sdk.getAgentDir();
|
|
118
|
+
const services = await this.services(sdk, {
|
|
119
|
+
cwd: this.directories.toPi(cwd),
|
|
120
|
+
agentDir,
|
|
121
|
+
modelRuntime: await this.modelRuntimeProvider.provide(),
|
|
122
|
+
lock: new SessionLock(),
|
|
123
|
+
commandsOnly: true,
|
|
124
|
+
});
|
|
125
|
+
const loader = services.resourceLoader;
|
|
126
|
+
return SlashCommandUtil.list({
|
|
127
|
+
commands: SlashCommandUtil.invocationNames(loader.getExtensions().extensions.flatMap(extension => [...extension.commands.values()])),
|
|
128
|
+
prompts: loader.getPrompts().prompts,
|
|
129
|
+
skills: loader.getSkills().skills,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* pi's services of a session in `cwd` (a directory of pi): its settings, its resources and extensions with
|
|
134
|
+
* those of Ta. `commandsOnly`: for what a session would have, the context files of another machine not read.
|
|
135
|
+
*/
|
|
136
|
+
async services(sdk, options) {
|
|
137
|
+
const { cwd, agentDir, modelRuntime, lock, appendSystemPrompt, commandsOnly } = options;
|
|
138
|
+
const environment = this.environments.create(this.directories.fromPi(cwd));
|
|
139
|
+
const settingsManager = sdk.SettingsManager.create(cwd, agentDir, { projectTrusted: this.isTrusted(sdk, cwd, agentDir) });
|
|
140
|
+
return sdk.createAgentSessionServices({
|
|
141
|
+
cwd,
|
|
142
|
+
agentDir,
|
|
143
|
+
settingsManager,
|
|
144
|
+
modelRuntime,
|
|
145
|
+
resourceLoaderOptions: {
|
|
146
|
+
...TaPackages.loaderOptions(agentDir),
|
|
147
|
+
...(commandsOnly ? {} : await this.contextFiles(environment, agentDir)),
|
|
148
|
+
extensionFactories: this.extensionFactories(sdk, environment, cwd, lock),
|
|
149
|
+
appendSystemPrompt: appendSystemPrompt ? [appendSystemPrompt] : undefined,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
125
153
|
openSessionManager(sdk, options) {
|
|
126
154
|
if (!options.sessionFile) {
|
|
127
155
|
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.js';
|
|
4
4
|
import { type TaHostOptions, TaSessionFactory, TaSessionRegistry } from './host-protocol.js';
|
|
5
5
|
import { TaSessionHandles } from './session-handles.js';
|
|
6
|
+
import { SessionListFeed } from './session-list-feed.js';
|
|
6
7
|
import type { TaSession } from './ta-session.js';
|
|
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. */
|
|
@@ -14,6 +14,7 @@ import { Autowired, Component, Value } from '@celljs/core';
|
|
|
14
14
|
import { ClientChannel } from './client-channel.js';
|
|
15
15
|
import { TA_HOST_OPTIONS, TaSessionFactory, TaSessionRegistry } from './host-protocol.js';
|
|
16
16
|
import { TaSessionHandles } from './session-handles.js';
|
|
17
|
+
import { SessionListFeed } from './session-list-feed.js';
|
|
17
18
|
import { TaErrors } from './ta-errors.js';
|
|
18
19
|
/**
|
|
19
20
|
* The open sessions. A session's id outlives its memory: closed while idle or by a restart, it opens again
|
|
@@ -29,6 +30,7 @@ let DefaultTaSessionRegistry = class DefaultTaSessionRegistry {
|
|
|
29
30
|
this.closing = new Map();
|
|
30
31
|
/** Sessions opening again under their ids: the calls that come meanwhile wait for the same. */
|
|
31
32
|
this.waking = new Map();
|
|
33
|
+
this.feed = new SessionListFeed(() => this.list().map(session => session.info()));
|
|
32
34
|
}
|
|
33
35
|
open(options) {
|
|
34
36
|
// A file that had a session keeps its id, which pages may still have.
|
|
@@ -67,6 +69,9 @@ let DefaultTaSessionRegistry = class DefaultTaSessionRegistry {
|
|
|
67
69
|
list() {
|
|
68
70
|
return [...this.sessions.values()];
|
|
69
71
|
}
|
|
72
|
+
watch(connection) {
|
|
73
|
+
return this.feed.watch(connection);
|
|
74
|
+
}
|
|
70
75
|
async close(sessionId, idle = false) {
|
|
71
76
|
if (!idle) {
|
|
72
77
|
this.handles.delete(sessionId);
|
|
@@ -76,6 +81,7 @@ let DefaultTaSessionRegistry = class DefaultTaSessionRegistry {
|
|
|
76
81
|
return;
|
|
77
82
|
}
|
|
78
83
|
this.sessions.delete(sessionId);
|
|
84
|
+
this.feed.changed();
|
|
79
85
|
const file = session.pi.sessionFile;
|
|
80
86
|
if (idle && file) {
|
|
81
87
|
// The conversation it has now: pi may have moved to another file since it opened.
|
|
@@ -126,6 +132,8 @@ let DefaultTaSessionRegistry = class DefaultTaSessionRegistry {
|
|
|
126
132
|
try {
|
|
127
133
|
const session = await this.factory.create(options, (ended, idle) => void this.close(ended.id, idle), id);
|
|
128
134
|
this.sessions.set(session.id, session);
|
|
135
|
+
session.onInfoChange(() => this.sessions.get(session.id) === session && this.feed.changed());
|
|
136
|
+
this.feed.changed();
|
|
129
137
|
const sessionFile = session.pi.sessionFile;
|
|
130
138
|
if (sessionFile) {
|
|
131
139
|
this.handles.set(session.id, { sessionFile, cwd: session.cwd, clientTools: options.clientTools });
|
package/esm/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.js';
|
|
4
4
|
import type { ClientToolBroker } from './client-tool-broker.js';
|
|
5
5
|
import { EventLog } from './event-log.js';
|
|
@@ -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/esm/node/ta-session.js
CHANGED
|
@@ -7,6 +7,16 @@ import { RemoteUiContext } from './remote-ui-context.js';
|
|
|
7
7
|
import { SessionCatalogUtil } from './session-catalog.js';
|
|
8
8
|
import { SessionInfoUtil } from './session-info-util.js';
|
|
9
9
|
import { TaEventUtil } from './ta-event-util.js';
|
|
10
|
+
/** The events after which what a list shows of a session (its info) may differ. */
|
|
11
|
+
const INFO_EVENTS = new Set([
|
|
12
|
+
'agent_start',
|
|
13
|
+
'agent_settled',
|
|
14
|
+
'message_end',
|
|
15
|
+
'session_info_changed',
|
|
16
|
+
'session_replaced',
|
|
17
|
+
'extension_ui_request',
|
|
18
|
+
'ui_request_resolved',
|
|
19
|
+
]);
|
|
10
20
|
/**
|
|
11
21
|
* One open session of `ta serve`: pi's runtime, its event log, and the clients attached to it. Its id
|
|
12
22
|
* stays the same while the runtime moves between conversations.
|
|
@@ -20,6 +30,7 @@ export class TaSession {
|
|
|
20
30
|
this.channels = new Set();
|
|
21
31
|
this.live = new LiveRun();
|
|
22
32
|
this.started = false;
|
|
33
|
+
this.infoListeners = new Set();
|
|
23
34
|
this.runtime = context.runtime;
|
|
24
35
|
this.id = (_a = context.id) !== null && _a !== void 0 ? _a : randomUUID();
|
|
25
36
|
// Opened again: its seqs start past any the session gave before (fewer than one per millisecond), so a
|
|
@@ -55,6 +66,7 @@ export class TaSession {
|
|
|
55
66
|
lastMessage: SessionInfoUtil.lastMessage(pi.messages),
|
|
56
67
|
model: model ? `${model.provider}/${model.id}` : undefined,
|
|
57
68
|
isStreaming: pi.isStreaming,
|
|
69
|
+
waiting: this.ui.pendingRequests.length > 0,
|
|
58
70
|
messageCount: pi.messages.length,
|
|
59
71
|
attached: this.channels.size,
|
|
60
72
|
createdAt: this.createdAt,
|
|
@@ -62,6 +74,11 @@ export class TaSession {
|
|
|
62
74
|
group: this.context.group,
|
|
63
75
|
};
|
|
64
76
|
}
|
|
77
|
+
/** What `info` gives may have changed (TaServer.watchSessions). */
|
|
78
|
+
onInfoChange(listener) {
|
|
79
|
+
this.infoListeners.add(listener);
|
|
80
|
+
return () => this.infoListeners.delete(listener);
|
|
81
|
+
}
|
|
65
82
|
attach(channel, afterSeq, options = {}) {
|
|
66
83
|
this.channels.add(channel);
|
|
67
84
|
this.watchIdle();
|
|
@@ -80,6 +97,13 @@ export class TaSession {
|
|
|
80
97
|
earlierMessages(before, timestamp, budget) {
|
|
81
98
|
return MessagePage.before(this.conversation().messages, before, timestamp, budget);
|
|
82
99
|
}
|
|
100
|
+
/** The image of a message of the user that the conversation gives without its bytes (TaShownImage). */
|
|
101
|
+
messageImage(timestamp, index) {
|
|
102
|
+
var _a;
|
|
103
|
+
const message = [...this.pi.messages].reverse().find(candidate => candidate.role === 'user' && candidate.timestamp === timestamp);
|
|
104
|
+
const block = Array.isArray(message === null || message === void 0 ? void 0 : message.content) ? message.content[index] : undefined;
|
|
105
|
+
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;
|
|
106
|
+
}
|
|
83
107
|
/** The conversation of the events sent, as clients get it. */
|
|
84
108
|
conversation() {
|
|
85
109
|
return TaEventUtil.leanConversation(this.live.conversation(this.pi.messages, this.pi.isStreaming));
|
|
@@ -97,8 +121,9 @@ export class TaSession {
|
|
|
97
121
|
claimClientTool(channel, id) {
|
|
98
122
|
return this.channels.has(channel) && this.context.clientTools.claim(id, channel);
|
|
99
123
|
}
|
|
100
|
-
|
|
101
|
-
|
|
124
|
+
/** Only a client attached answers, and only the one that claimed the call when one did. */
|
|
125
|
+
respondClientTool(channel, result) {
|
|
126
|
+
return this.channels.has(channel) && this.context.clientTools.respond(result, channel);
|
|
102
127
|
}
|
|
103
128
|
prompt(input) {
|
|
104
129
|
return this.accept(input, () => new Promise((resolve, reject) => {
|
|
@@ -177,8 +202,15 @@ export class TaSession {
|
|
|
177
202
|
// Its failure is no reason to keep the session: dispose below aborts the run as well.
|
|
178
203
|
await this.within(this.pi.abort().catch(() => undefined));
|
|
179
204
|
}
|
|
180
|
-
|
|
181
|
-
|
|
205
|
+
let disposed = false;
|
|
206
|
+
try {
|
|
207
|
+
disposed = await this.within(this.runtime.dispose());
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
// Late or failed: either way nothing more of pi goes into the file once it is unlocked.
|
|
211
|
+
if (!disposed) {
|
|
212
|
+
this.pi.dispose();
|
|
213
|
+
}
|
|
182
214
|
}
|
|
183
215
|
}
|
|
184
216
|
finally {
|
|
@@ -254,6 +286,11 @@ export class TaSession {
|
|
|
254
286
|
for (const channel of this.channels) {
|
|
255
287
|
channel.send(logged);
|
|
256
288
|
}
|
|
289
|
+
if (INFO_EVENTS.has(event.type)) {
|
|
290
|
+
for (const listener of this.infoListeners) {
|
|
291
|
+
listener();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
257
294
|
}
|
|
258
295
|
isIdle() {
|
|
259
296
|
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;
|
|
@@ -127,11 +127,18 @@ let WebExtensionCatalogImpl = class WebExtensionCatalogImpl {
|
|
|
127
127
|
}
|
|
128
128
|
async packageOf(cwd, id) {
|
|
129
129
|
const { packages } = await this.load(cwd);
|
|
130
|
+
return WebExtensionUtil.describePackage(this.findPackage(packages, id));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The package an id names: its id of listPackages, or the id of one of its web extensions. Every method of a
|
|
134
|
+
* package takes either, so that a client holding a web extension never looks for its package first.
|
|
135
|
+
*/
|
|
136
|
+
findPackage(packages, id, kind = 'package') {
|
|
130
137
|
const pkg = packages.find(candidate => WebExtensionUtil.describePackage(candidate).id === id || WebExtensionUtil.describe(candidate).some(info => info.id === id));
|
|
131
138
|
if (!pkg) {
|
|
132
|
-
throw TaErrors.invalidArgument(`No
|
|
139
|
+
throw TaErrors.invalidArgument(`No ${kind} has the id ${id}.`, 'listPackages lists the ones there are; the package may have moved or gone.');
|
|
133
140
|
}
|
|
134
|
-
return
|
|
141
|
+
return pkg;
|
|
135
142
|
}
|
|
136
143
|
/** A package another computer shared by a link, put in Ta's own temporary directory (RelayShareUtil). */
|
|
137
144
|
async fetchShare(link) {
|
|
@@ -156,12 +163,7 @@ let WebExtensionCatalogImpl = class WebExtensionCatalogImpl {
|
|
|
156
163
|
}
|
|
157
164
|
async findTemporary(cwd, id) {
|
|
158
165
|
const { packages } = await this.load(cwd);
|
|
159
|
-
|
|
160
|
-
(WebExtensionUtil.describePackage(candidate).id === id || WebExtensionUtil.describe(candidate).some(info => info.id === id)));
|
|
161
|
-
if (!pkg) {
|
|
162
|
-
throw TaErrors.invalidArgument(`No temporary package has the id ${id}.`, 'listPackages lists the ones there are; it may have been installed, removed or cleared.');
|
|
163
|
-
}
|
|
164
|
-
return pkg;
|
|
166
|
+
return this.findPackage(packages.filter(candidate => candidate.origin === 'temporary'), id, 'temporary package');
|
|
165
167
|
}
|
|
166
168
|
/** Ta's own directory is deleted, what pi fetched removed, a path of the user's only forgotten. */
|
|
167
169
|
async dropTemporary(record, manager) {
|
|
@@ -176,11 +178,7 @@ let WebExtensionCatalogImpl = class WebExtensionCatalogImpl {
|
|
|
176
178
|
}
|
|
177
179
|
async removePackage(cwd, id) {
|
|
178
180
|
const { packages, manager } = await this.load(cwd);
|
|
179
|
-
|
|
180
|
-
if (!pkg) {
|
|
181
|
-
throw TaErrors.invalidArgument(`No package has the id ${id}.`, 'listPackages lists the ones there are; the package may have moved or gone.');
|
|
182
|
-
}
|
|
183
|
-
await this.removeRoot(pkg, manager);
|
|
181
|
+
await this.removeRoot(this.findPackage(packages, id), manager);
|
|
184
182
|
}
|
|
185
183
|
async list(cwd) {
|
|
186
184
|
const { packages } = await this.load(cwd);
|
|
@@ -191,19 +189,17 @@ let WebExtensionCatalogImpl = class WebExtensionCatalogImpl {
|
|
|
191
189
|
const code = WebExtensionUtil.read(pkg, info.entry);
|
|
192
190
|
return { id, hash: WebExtensionUtil.hash(code), code };
|
|
193
191
|
}
|
|
194
|
-
async remove(cwd, id) {
|
|
195
|
-
const { pkg } = await this.find(cwd, id);
|
|
196
|
-
await this.removeRoot(pkg, (await this.load(cwd)).manager);
|
|
197
|
-
}
|
|
198
192
|
async setEnabled(cwd, nameOrId, enabled) {
|
|
199
193
|
if (TaPackages.builtins().some(pkg => pkg.name === nameOrId)) {
|
|
200
194
|
TaPackages.setEnabled(this.agentDir(), nameOrId, enabled);
|
|
201
195
|
return;
|
|
202
196
|
}
|
|
203
197
|
const loaded = await this.load(cwd);
|
|
204
|
-
const pkg = loaded.packages.find(candidate => candidate.origin !== 'builtin' &&
|
|
198
|
+
const pkg = loaded.packages.find(candidate => candidate.origin !== 'builtin' &&
|
|
199
|
+
candidate.origin !== 'temporary' &&
|
|
200
|
+
(WebExtensionUtil.describePackage(candidate).id === nameOrId || WebExtensionUtil.describe(candidate).some(info => info.id === nameOrId)));
|
|
205
201
|
if (!pkg) {
|
|
206
|
-
throw 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.');
|
|
202
|
+
throw 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.');
|
|
207
203
|
}
|
|
208
204
|
const resources = PackageSwitch.resourcesOf(await this.resolve(loaded.manager), pkg.root);
|
|
209
205
|
if (resources.length === 0) {
|