@celljs/ta-host 4.16.0 → 4.17.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/esm/node/app-commands.d.ts +111 -0
- package/esm/node/app-commands.js +629 -0
- package/esm/node/delegate-extension.d.ts +11 -0
- package/esm/node/delegate-extension.js +33 -0
- package/esm/node/directory-relocator.d.ts +49 -0
- package/esm/node/directory-relocator.js +267 -0
- package/esm/node/extension-providers.d.ts +16 -1
- package/esm/node/extension-providers.js +23 -3
- package/esm/node/index.d.ts +6 -0
- package/esm/node/index.js +6 -0
- package/esm/node/keep-awake.d.ts +5 -1
- package/esm/node/keep-awake.js +18 -2
- package/esm/node/message-page.d.ts +6 -1
- package/esm/node/message-page.js +50 -2
- package/esm/node/package-hosts.d.ts +6 -0
- package/esm/node/package-hosts.js +35 -0
- package/esm/node/package-webhooks.d.ts +26 -0
- package/esm/node/package-webhooks.js +101 -0
- package/esm/node/page-book.d.ts +48 -0
- package/esm/node/page-book.js +117 -0
- package/esm/node/relay-bridge.d.ts +2 -0
- package/esm/node/relay-bridge.js +35 -1
- package/esm/node/rooms-bridge.d.ts +3 -0
- package/esm/node/rooms-bridge.js +4 -0
- package/esm/node/session-info-util.d.ts +3 -1
- package/esm/node/session-info-util.js +32 -6
- package/esm/node/ta-server-impl.d.ts +5 -1
- package/esm/node/ta-server-impl.js +22 -0
- package/esm/node/ta-session-factory.d.ts +13 -1
- package/esm/node/ta-session-factory.js +39 -4
- package/esm/node/ta-session.d.ts +2 -0
- package/esm/node/ta-session.js +1 -0
- package/esm/node/team/team-calls.js +22 -0
- package/esm/node/voice-bridge.d.ts +68 -0
- package/esm/node/voice-bridge.js +273 -0
- package/esm/node/voices-file.d.ts +33 -0
- package/esm/node/voices-file.js +89 -0
- package/lib/node/app-commands.d.ts +112 -0
- package/lib/node/app-commands.js +633 -0
- package/lib/node/delegate-extension.d.ts +12 -0
- package/lib/node/delegate-extension.js +37 -0
- package/lib/node/directory-relocator.d.ts +50 -0
- package/lib/node/directory-relocator.js +270 -0
- package/lib/node/extension-providers.d.ts +16 -1
- package/lib/node/extension-providers.js +23 -3
- package/lib/node/index.d.ts +6 -0
- package/lib/node/index.js +6 -0
- package/lib/node/keep-awake.d.ts +5 -1
- package/lib/node/keep-awake.js +18 -2
- package/lib/node/message-page.d.ts +6 -1
- package/lib/node/message-page.js +50 -2
- package/lib/node/package-hosts.d.ts +6 -0
- package/lib/node/package-hosts.js +35 -0
- package/lib/node/package-webhooks.d.ts +27 -0
- package/lib/node/package-webhooks.js +104 -0
- package/lib/node/page-book.d.ts +49 -0
- package/lib/node/page-book.js +120 -0
- package/lib/node/relay-bridge.d.ts +2 -0
- package/lib/node/relay-bridge.js +34 -0
- package/lib/node/rooms-bridge.d.ts +3 -0
- package/lib/node/rooms-bridge.js +4 -0
- package/lib/node/session-info-util.d.ts +3 -1
- package/lib/node/session-info-util.js +31 -5
- package/lib/node/ta-server-impl.d.ts +5 -1
- package/lib/node/ta-server-impl.js +22 -0
- package/lib/node/ta-session-factory.d.ts +13 -1
- package/lib/node/ta-session-factory.js +38 -3
- package/lib/node/ta-session.d.ts +2 -0
- package/lib/node/ta-session.js +1 -0
- package/lib/node/team/team-calls.js +22 -0
- package/lib/node/voice-bridge.d.ts +69 -0
- package/lib/node/voice-bridge.js +274 -0
- package/lib/node/voices-file.d.ts +34 -0
- package/lib/node/voices-file.js +93 -0
- package/package.json +10 -10
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TaDelegateUtil } from '@celljs/ta-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Holds the double to how much the user wants it to hand out (Settings.delegate): in a session whose role has the
|
|
4
|
+
* mark of a level (TaDelegateUtil.mark), its calls of the tools that change files are turned down, and those of its
|
|
5
|
+
* own tools past the steps of a run, each with what to do instead. Other sessions (tasks, chats, agents) have no
|
|
6
|
+
* mark and are left alone.
|
|
7
|
+
*/
|
|
8
|
+
export class DelegateExtension {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.name = 'ta-delegate';
|
|
11
|
+
}
|
|
12
|
+
register(pi) {
|
|
13
|
+
let steps = 0;
|
|
14
|
+
pi.on('agent_start', () => {
|
|
15
|
+
steps = 0;
|
|
16
|
+
});
|
|
17
|
+
pi.on('tool_call', (event, ctx) => {
|
|
18
|
+
const level = TaDelegateUtil.levelOf(ctx.getSystemPrompt());
|
|
19
|
+
if (!level) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const reason = TaDelegateUtil.refusal(level, event.toolName, steps);
|
|
23
|
+
if (reason) {
|
|
24
|
+
return { block: true, reason };
|
|
25
|
+
}
|
|
26
|
+
if (TaDelegateUtil.WORK_TOOLS.includes(event.toolName)) {
|
|
27
|
+
steps++;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=delegate-extension.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
|
|
2
|
+
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
3
|
+
import { TaPathMap, type TaRelocateResult } from '@celljs/ta-protocol';
|
|
4
|
+
import { ExtensionDataStore } from './extension-data.js';
|
|
5
|
+
import { type TaExecOptions, TaSessionRegistry } from './host-protocol.js';
|
|
6
|
+
import { PiDirectories } from './remote/remote-protocol.js';
|
|
7
|
+
import { TaSessionHandles } from './session-handles.js';
|
|
8
|
+
import { TaWorkingDirectory } from './working-directory.js';
|
|
9
|
+
export declare const TaDirectoryRelocator: unique symbol;
|
|
10
|
+
/** TaServer.relocateDirectory: what of Ta names a directory, made another. */
|
|
11
|
+
export interface TaDirectoryRelocator {
|
|
12
|
+
relocate(from: string, to: string): Promise<TaRelocateResult>;
|
|
13
|
+
}
|
|
14
|
+
export declare namespace DirectoryRelocatorUtil {
|
|
15
|
+
/** pi's folder of the sessions of a directory (SessionManager's getDefaultSessionDirPath), its name. */
|
|
16
|
+
function sessionDir(cwd: string): string;
|
|
17
|
+
/** The directory of a session file, from its header; undefined for what is not a session of pi. */
|
|
18
|
+
function headerCwd(file: string): Promise<string | undefined>;
|
|
19
|
+
/** The file with its header in \`cwd\`; the rest as it was. */
|
|
20
|
+
function withCwd(text: string, cwd: string): string;
|
|
21
|
+
}
|
|
22
|
+
export declare class TaDirectoryRelocatorImpl implements TaDirectoryRelocator {
|
|
23
|
+
protected readonly codingAgentOptions?: CodingAgentOptions;
|
|
24
|
+
protected readonly execOptions?: TaExecOptions;
|
|
25
|
+
protected readonly sessions: TaSessionRegistry;
|
|
26
|
+
protected readonly handles: TaSessionHandles;
|
|
27
|
+
protected readonly data: ExtensionDataStore;
|
|
28
|
+
protected readonly directories: PiDirectories;
|
|
29
|
+
protected readonly workingDirectory: TaWorkingDirectory;
|
|
30
|
+
protected readonly environments: ExecEnvironmentFactory;
|
|
31
|
+
/** One at a time: two would move the same files. */
|
|
32
|
+
protected running: Promise<void>;
|
|
33
|
+
relocate(from: string, to: string): Promise<TaRelocateResult>;
|
|
34
|
+
protected move(from: string, to: string): Promise<TaRelocateResult>;
|
|
35
|
+
/** A session file into the folder of its new directory, its header saying so; one open idle closes first and opens again there under its id. */
|
|
36
|
+
protected moveSession(file: string, next: string, cwd: string, result: TaRelocateResult): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* The data of packages with the paths mapped, key by key through the store (pages hear of each): the files of
|
|
39
|
+
* every package, and those of the directories moved, into the data of their new directory.
|
|
40
|
+
*/
|
|
41
|
+
protected moveData(pairs: TaPathMap.Pair[], cwds: Map<string, string>): Promise<number>;
|
|
42
|
+
/** \`all\`: every key goes, into the data of the directory \`cwd\`; otherwise only what changed, in place. */
|
|
43
|
+
protected rewrite(name: string, values: Record<string, unknown>, pairs: TaPathMap.Pair[], cwd?: string, all?: boolean): Promise<boolean>;
|
|
44
|
+
/** The packages with a file of data in \`root\`, by name (\`@scope/name\` in a folder of its scope); not the data of directories. */
|
|
45
|
+
protected packageFiles(root: string, directory: boolean): Promise<string[]>;
|
|
46
|
+
protected sessionFiles(root: string): Promise<string[]>;
|
|
47
|
+
protected write(file: string, text: string): Promise<void>;
|
|
48
|
+
protected agentDir(): string;
|
|
49
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { mkdir, open, readdir, readFile, rename, rm, rmdir, stat, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { basename, dirname, join } from 'node:path';
|
|
12
|
+
import { CODING_AGENT_OPTIONS } from '@celljs/ai-coding-agent';
|
|
13
|
+
import { Autowired, Component, Value } from '@celljs/core';
|
|
14
|
+
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
15
|
+
import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
|
|
16
|
+
import { TaLocation, TaPathMap } from '@celljs/ta-protocol';
|
|
17
|
+
import { ExtensionDataStore, ExtensionDataUtil } from './extension-data.js';
|
|
18
|
+
import { TA_EXEC_OPTIONS, TaSessionRegistry } from './host-protocol.js';
|
|
19
|
+
import { PiDirectories } from './remote/remote-protocol.js';
|
|
20
|
+
import { TaSessionHandles } from './session-handles.js';
|
|
21
|
+
import { TaErrors } from './ta-errors.js';
|
|
22
|
+
import { TaWorkingDirectory } from './working-directory.js';
|
|
23
|
+
export const TaDirectoryRelocator = Symbol('TaDirectoryRelocator');
|
|
24
|
+
/** The first line of a session file of pi is its header; it is read without the rest. */
|
|
25
|
+
const HEADER_BYTES = 64 * 1024;
|
|
26
|
+
export var DirectoryRelocatorUtil;
|
|
27
|
+
(function (DirectoryRelocatorUtil) {
|
|
28
|
+
/** pi's folder of the sessions of a directory (SessionManager's getDefaultSessionDirPath), its name. */
|
|
29
|
+
function sessionDir(cwd) {
|
|
30
|
+
return `--${cwd.replace(/^[/\\]/, '').replace(/[/\\:]/g, '-')}--`;
|
|
31
|
+
}
|
|
32
|
+
DirectoryRelocatorUtil.sessionDir = sessionDir;
|
|
33
|
+
/** The directory of a session file, from its header; undefined for what is not a session of pi. */
|
|
34
|
+
async function headerCwd(file) {
|
|
35
|
+
const handle = await open(file, 'r').catch(() => undefined);
|
|
36
|
+
if (!handle) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const buffer = Buffer.alloc(HEADER_BYTES);
|
|
41
|
+
const { bytesRead } = await handle.read(buffer, 0, HEADER_BYTES, 0);
|
|
42
|
+
const text = buffer.subarray(0, bytesRead).toString('utf8');
|
|
43
|
+
const end = text.indexOf('\n');
|
|
44
|
+
const header = JSON.parse(end < 0 ? text : text.slice(0, end));
|
|
45
|
+
return header.type === 'session' && typeof header.cwd === 'string' ? header.cwd : undefined;
|
|
46
|
+
}
|
|
47
|
+
catch (_a) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
await handle.close();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
DirectoryRelocatorUtil.headerCwd = headerCwd;
|
|
55
|
+
/** The file with its header in \`cwd\`; the rest as it was. */
|
|
56
|
+
function withCwd(text, cwd) {
|
|
57
|
+
const end = text.indexOf('\n');
|
|
58
|
+
const header = JSON.parse(end < 0 ? text : text.slice(0, end));
|
|
59
|
+
return JSON.stringify({ ...header, cwd }) + (end < 0 ? '' : text.slice(end));
|
|
60
|
+
}
|
|
61
|
+
DirectoryRelocatorUtil.withCwd = withCwd;
|
|
62
|
+
})(DirectoryRelocatorUtil || (DirectoryRelocatorUtil = {}));
|
|
63
|
+
let TaDirectoryRelocatorImpl = class TaDirectoryRelocatorImpl {
|
|
64
|
+
constructor() {
|
|
65
|
+
/** One at a time: two would move the same files. */
|
|
66
|
+
this.running = Promise.resolve();
|
|
67
|
+
}
|
|
68
|
+
relocate(from, to) {
|
|
69
|
+
const next = this.running.catch(() => undefined).then(() => this.move(from, to));
|
|
70
|
+
this.running = next.then(() => undefined, () => undefined);
|
|
71
|
+
return next;
|
|
72
|
+
}
|
|
73
|
+
async move(from, to) {
|
|
74
|
+
var _a;
|
|
75
|
+
const old = typeof from === 'string' ? from.trim() : '';
|
|
76
|
+
const target = typeof to === 'string' && to.trim() ? await this.environments.resolve(to.trim()) : '';
|
|
77
|
+
const env = target ? this.environments.create(target) : undefined;
|
|
78
|
+
if (!old || !env || !((_a = (await env.stat(env.cwd))) === null || _a === void 0 ? void 0 : _a.isDirectory)) {
|
|
79
|
+
throw TaErrors.invalidArgument(`${to} is not a directory.`, 'Pass the directory as it was, and one that exists now: a path, or an ssh:// location.');
|
|
80
|
+
}
|
|
81
|
+
const fromPi = TaLocation.isRemote(old) ? this.directories.toPi(old) : old;
|
|
82
|
+
const toPi = this.directories.toPi(target);
|
|
83
|
+
if (fromPi === toPi || TaPathMap.under(toPi, fromPi)) {
|
|
84
|
+
throw TaErrors.invalidArgument(`${target} is ${old} or in it.`, 'Pass another directory, not one inside the old one.');
|
|
85
|
+
}
|
|
86
|
+
const pairs = [[fromPi, toPi]];
|
|
87
|
+
if (old !== fromPi) {
|
|
88
|
+
pairs.push([old, target]);
|
|
89
|
+
}
|
|
90
|
+
const result = { conversations: 0, busy: 0, data: 0, files: {} };
|
|
91
|
+
const cwds = new Map([[fromPi, toPi]]);
|
|
92
|
+
const root = join(this.agentDir(), 'sessions');
|
|
93
|
+
for (const file of await this.sessionFiles(root)) {
|
|
94
|
+
const cwd = await DirectoryRelocatorUtil.headerCwd(file);
|
|
95
|
+
if (cwd === undefined || !TaPathMap.under(cwd, fromPi)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const cwdNow = TaPathMap.path(cwd, pairs);
|
|
99
|
+
if (await this.moveSession(file, join(root, DirectoryRelocatorUtil.sessionDir(cwdNow), basename(file)), cwdNow, result)) {
|
|
100
|
+
cwds.set(cwd, cwdNow);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const filePairs = Object.entries(result.files);
|
|
104
|
+
result.data = await this.moveData([...filePairs, ...pairs], cwds);
|
|
105
|
+
const working = this.workingDirectory.get();
|
|
106
|
+
if (working) {
|
|
107
|
+
const moved = TaPathMap.path(working, pairs);
|
|
108
|
+
if (moved !== working) {
|
|
109
|
+
this.workingDirectory.set(moved);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
/** A session file into the folder of its new directory, its header saying so; one open idle closes first and opens again there under its id. */
|
|
115
|
+
async moveSession(file, next, cwd, result) {
|
|
116
|
+
var _a;
|
|
117
|
+
const open = this.sessions.list().find(session => session.pi.sessionFile === file);
|
|
118
|
+
if (open === null || open === void 0 ? void 0 : open.pi.isStreaming) {
|
|
119
|
+
result.busy++;
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (file === next || (await stat(next).catch(() => undefined))) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
const id = (_a = open === null || open === void 0 ? void 0 : open.id) !== null && _a !== void 0 ? _a : this.handles.idOf(file);
|
|
126
|
+
if (open) {
|
|
127
|
+
await this.sessions.close(open.id, true);
|
|
128
|
+
}
|
|
129
|
+
const text = await readFile(file, 'utf8');
|
|
130
|
+
await this.write(next, DirectoryRelocatorUtil.withCwd(text, cwd));
|
|
131
|
+
await rm(file, { force: true });
|
|
132
|
+
await rmdir(dirname(file)).catch(() => undefined);
|
|
133
|
+
if (id) {
|
|
134
|
+
const handle = this.handles.get(id);
|
|
135
|
+
this.handles.set(id, { ...handle, sessionFile: next, cwd: this.directories.fromPi(cwd) });
|
|
136
|
+
}
|
|
137
|
+
result.files[file] = next;
|
|
138
|
+
result.conversations++;
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The data of packages with the paths mapped, key by key through the store (pages hear of each): the files of
|
|
143
|
+
* every package, and those of the directories moved, into the data of their new directory.
|
|
144
|
+
*/
|
|
145
|
+
async moveData(pairs, cwds) {
|
|
146
|
+
var _a;
|
|
147
|
+
var _b;
|
|
148
|
+
const changed = new Set();
|
|
149
|
+
const root = join(this.agentDir(), 'extension-data');
|
|
150
|
+
for (const name of await this.packageFiles(root, false)) {
|
|
151
|
+
const values = ExtensionDataUtil.parse(await readFile(join(root, `${name}.json`), 'utf8').catch(() => undefined));
|
|
152
|
+
if (await this.rewrite(name, values, pairs)) {
|
|
153
|
+
changed.add(name);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const environment = (_b = (_a = this.execOptions) === null || _a === void 0 ? void 0 : _a.url) !== null && _b !== void 0 ? _b : '';
|
|
157
|
+
for (const [cwd, cwdNow] of cwds) {
|
|
158
|
+
const before = this.directories.fromPi(cwd);
|
|
159
|
+
const dir = join(root, 'directories', ExtensionDataUtil.directoryId(before, environment));
|
|
160
|
+
const names = await this.packageFiles(dir, true);
|
|
161
|
+
for (const name of names) {
|
|
162
|
+
const values = ExtensionDataUtil.parse(await readFile(join(dir, `${name}.json`), 'utf8').catch(() => undefined));
|
|
163
|
+
await this.rewrite(name, values, pairs, this.directories.fromPi(cwdNow), true);
|
|
164
|
+
changed.add(name);
|
|
165
|
+
}
|
|
166
|
+
if (names.length) {
|
|
167
|
+
await rm(dir, { recursive: true, force: true });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return changed.size;
|
|
171
|
+
}
|
|
172
|
+
/** \`all\`: every key goes, into the data of the directory \`cwd\`; otherwise only what changed, in place. */
|
|
173
|
+
async rewrite(name, values, pairs, cwd, all = false) {
|
|
174
|
+
let changed = false;
|
|
175
|
+
for (const [key, value] of Object.entries(values)) {
|
|
176
|
+
const keyNow = TaPathMap.json(key, pairs);
|
|
177
|
+
const valueNow = TaPathMap.json(value, pairs);
|
|
178
|
+
if (!all && keyNow === key && JSON.stringify(valueNow) === JSON.stringify(value)) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (!all && keyNow !== key) {
|
|
182
|
+
await this.data.set(name, key, null, cwd);
|
|
183
|
+
}
|
|
184
|
+
await this.data.set(name, keyNow, valueNow, cwd);
|
|
185
|
+
changed = true;
|
|
186
|
+
}
|
|
187
|
+
return changed;
|
|
188
|
+
}
|
|
189
|
+
/** The packages with a file of data in \`root\`, by name (\`@scope/name\` in a folder of its scope); not the data of directories. */
|
|
190
|
+
async packageFiles(root, directory) {
|
|
191
|
+
const names = [];
|
|
192
|
+
for (const entry of await readdir(root, { withFileTypes: true }).catch(() => [])) {
|
|
193
|
+
if (entry.isFile() && entry.name.endsWith('.json')) {
|
|
194
|
+
names.push(entry.name.slice(0, -'.json'.length));
|
|
195
|
+
}
|
|
196
|
+
else if (entry.isDirectory() && entry.name.startsWith('@') && (directory || entry.name !== 'directories')) {
|
|
197
|
+
for (const inner of await readdir(join(root, entry.name)).catch(() => [])) {
|
|
198
|
+
if (inner.endsWith('.json')) {
|
|
199
|
+
names.push(`${entry.name}/${inner.slice(0, -'.json'.length)}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return names;
|
|
205
|
+
}
|
|
206
|
+
async sessionFiles(root) {
|
|
207
|
+
const files = [];
|
|
208
|
+
for (const dir of await readdir(root, { withFileTypes: true }).catch(() => [])) {
|
|
209
|
+
if (dir.isDirectory()) {
|
|
210
|
+
for (const name of await readdir(join(root, dir.name)).catch(() => [])) {
|
|
211
|
+
if (name.endsWith('.jsonl')) {
|
|
212
|
+
files.push(join(root, dir.name, name));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return files;
|
|
218
|
+
}
|
|
219
|
+
async write(file, text) {
|
|
220
|
+
await mkdir(dirname(file), { recursive: true });
|
|
221
|
+
const temporary = `${file}.ta-relocate-${process.pid}`;
|
|
222
|
+
await writeFile(temporary, text);
|
|
223
|
+
await rename(temporary, file);
|
|
224
|
+
}
|
|
225
|
+
agentDir() {
|
|
226
|
+
var _a;
|
|
227
|
+
var _b;
|
|
228
|
+
return (_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : TaBrand.agentDir();
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
__decorate([
|
|
232
|
+
Value(CODING_AGENT_OPTIONS),
|
|
233
|
+
__metadata("design:type", Object)
|
|
234
|
+
], TaDirectoryRelocatorImpl.prototype, "codingAgentOptions", void 0);
|
|
235
|
+
__decorate([
|
|
236
|
+
Value(TA_EXEC_OPTIONS),
|
|
237
|
+
__metadata("design:type", Object)
|
|
238
|
+
], TaDirectoryRelocatorImpl.prototype, "execOptions", void 0);
|
|
239
|
+
__decorate([
|
|
240
|
+
Autowired(TaSessionRegistry),
|
|
241
|
+
__metadata("design:type", Object)
|
|
242
|
+
], TaDirectoryRelocatorImpl.prototype, "sessions", void 0);
|
|
243
|
+
__decorate([
|
|
244
|
+
Autowired(TaSessionHandles),
|
|
245
|
+
__metadata("design:type", Object)
|
|
246
|
+
], TaDirectoryRelocatorImpl.prototype, "handles", void 0);
|
|
247
|
+
__decorate([
|
|
248
|
+
Autowired(ExtensionDataStore),
|
|
249
|
+
__metadata("design:type", Object)
|
|
250
|
+
], TaDirectoryRelocatorImpl.prototype, "data", void 0);
|
|
251
|
+
__decorate([
|
|
252
|
+
Autowired(PiDirectories),
|
|
253
|
+
__metadata("design:type", Object)
|
|
254
|
+
], TaDirectoryRelocatorImpl.prototype, "directories", void 0);
|
|
255
|
+
__decorate([
|
|
256
|
+
Autowired(TaWorkingDirectory),
|
|
257
|
+
__metadata("design:type", Object)
|
|
258
|
+
], TaDirectoryRelocatorImpl.prototype, "workingDirectory", void 0);
|
|
259
|
+
__decorate([
|
|
260
|
+
Autowired(ExecEnvironmentFactory),
|
|
261
|
+
__metadata("design:type", Object)
|
|
262
|
+
], TaDirectoryRelocatorImpl.prototype, "environments", void 0);
|
|
263
|
+
TaDirectoryRelocatorImpl = __decorate([
|
|
264
|
+
Component(TaDirectoryRelocator)
|
|
265
|
+
], TaDirectoryRelocatorImpl);
|
|
266
|
+
export { TaDirectoryRelocatorImpl };
|
|
267
|
+
//# sourceMappingURL=directory-relocator.js.map
|
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
import { type CodingAgentOptions, ModelRuntimeProvider } from '@celljs/ai-coding-agent';
|
|
2
2
|
export declare const ExtensionProviders: unique symbol;
|
|
3
|
+
/** The part of pi's extension runtime that holds what extensions register before a session binds them. */
|
|
4
|
+
interface PendingProviders {
|
|
5
|
+
pendingProviderRegistrations: {
|
|
6
|
+
name: string;
|
|
7
|
+
config: unknown;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* The model providers that pi packages register (`pi.registerProvider`), before any session: pi registers
|
|
5
12
|
* them in the model runtime that the sessions of ta serve share when it loads a session's extensions, so
|
|
6
13
|
* until a session opened, a client would see none of them (no sign-in, no model to pick).
|
|
7
14
|
*/
|
|
8
15
|
export interface ExtensionProviders {
|
|
9
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Loads the extensions of the user once, for the providers they register; later calls wait for that, and take
|
|
18
|
+
* those they registered since (ta-agents, once it installed an agent).
|
|
19
|
+
*/
|
|
10
20
|
ensure(): Promise<void>;
|
|
11
21
|
}
|
|
12
22
|
export declare class ExtensionProvidersImpl implements ExtensionProviders {
|
|
13
23
|
protected readonly codingAgentOptions?: CodingAgentOptions;
|
|
14
24
|
protected readonly modelRuntimeProvider: ModelRuntimeProvider;
|
|
15
25
|
protected loading?: Promise<void>;
|
|
26
|
+
/** Where the extensions loaded without a session keep what they register later: pi flushes it only when a session binds them. */
|
|
27
|
+
protected pending?: PendingProviders;
|
|
16
28
|
ensure(): Promise<void>;
|
|
29
|
+
/** What the extensions registered since they loaded, into the model runtime, as pi does when they load. */
|
|
30
|
+
protected flush(): Promise<void>;
|
|
17
31
|
/**
|
|
18
32
|
* pi's services of a directory without a project (the home directory, its project resources not
|
|
19
33
|
* trusted): the built-in packages and those of the user's settings, as a session loads them.
|
|
20
34
|
*/
|
|
21
35
|
protected load(): Promise<void>;
|
|
22
36
|
}
|
|
37
|
+
export {};
|
|
@@ -13,10 +13,29 @@ import { Autowired, Component, Value } from '@celljs/core';
|
|
|
13
13
|
import { TaPackages } from '@celljs/ta-harness';
|
|
14
14
|
export const ExtensionProviders = Symbol('ExtensionProviders');
|
|
15
15
|
let ExtensionProvidersImpl = class ExtensionProvidersImpl {
|
|
16
|
-
ensure() {
|
|
16
|
+
async ensure() {
|
|
17
17
|
var _a;
|
|
18
18
|
(_a = this.loading) !== null && _a !== void 0 ? _a : (this.loading = this.load().catch(() => undefined));
|
|
19
|
-
|
|
19
|
+
await this.loading;
|
|
20
|
+
await this.flush();
|
|
21
|
+
}
|
|
22
|
+
/** What the extensions registered since they loaded, into the model runtime, as pi does when they load. */
|
|
23
|
+
async flush() {
|
|
24
|
+
const pending = this.pending;
|
|
25
|
+
if (!(pending === null || pending === void 0 ? void 0 : pending.pendingProviderRegistrations.length)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const registrations = pending.pendingProviderRegistrations;
|
|
29
|
+
pending.pendingProviderRegistrations = [];
|
|
30
|
+
const runtime = await this.modelRuntimeProvider.provide();
|
|
31
|
+
for (const { name, config } of registrations) {
|
|
32
|
+
try {
|
|
33
|
+
runtime.registerProvider(name, config);
|
|
34
|
+
}
|
|
35
|
+
catch (_a) {
|
|
36
|
+
// As pi does: a provider that does not register is left out.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
20
39
|
}
|
|
21
40
|
/**
|
|
22
41
|
* pi's services of a directory without a project (the home directory, its project resources not
|
|
@@ -28,13 +47,14 @@ let ExtensionProvidersImpl = class ExtensionProvidersImpl {
|
|
|
28
47
|
const sdk = await PiSdkUtil.load();
|
|
29
48
|
const agentDir = (_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : sdk.getAgentDir();
|
|
30
49
|
const cwd = homedir();
|
|
31
|
-
await sdk.createAgentSessionServices({
|
|
50
|
+
const services = await sdk.createAgentSessionServices({
|
|
32
51
|
cwd,
|
|
33
52
|
agentDir,
|
|
34
53
|
settingsManager: sdk.SettingsManager.create(cwd, agentDir, { projectTrusted: false }),
|
|
35
54
|
modelRuntime: await this.modelRuntimeProvider.provide(),
|
|
36
55
|
resourceLoaderOptions: TaPackages.loaderOptions(agentDir, { loadSkills: sdk.loadSkillsFromDir }),
|
|
37
56
|
});
|
|
57
|
+
this.pending = services.resourceLoader.getExtensions().runtime;
|
|
38
58
|
}
|
|
39
59
|
};
|
|
40
60
|
__decorate([
|
package/esm/node/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export * from './app-commands.js';
|
|
1
2
|
export * from './auth-server-impl.js';
|
|
2
3
|
export * from './client-channel.js';
|
|
3
4
|
export * from './client-tool-broker.js';
|
|
5
|
+
export * from './directory-relocator.js';
|
|
4
6
|
export * from './event-log.js';
|
|
5
7
|
export * from './exec-endpoint.js';
|
|
6
8
|
export * from './exec-environment-factory.js';
|
|
@@ -13,6 +15,8 @@ export * from './keep-awake.js';
|
|
|
13
15
|
export * from './package-host-extension.js';
|
|
14
16
|
export * from './package-hosts.js';
|
|
15
17
|
export * from './package-server-impl.js';
|
|
18
|
+
export * from './package-webhooks.js';
|
|
19
|
+
export * from './page-book.js';
|
|
16
20
|
export * from './presence-book.js';
|
|
17
21
|
export * from './presence-server-impl.js';
|
|
18
22
|
export * from './receipt-book.js';
|
|
@@ -44,6 +48,8 @@ export * from './terminal-protocol.js';
|
|
|
44
48
|
export * from './terminal-service.js';
|
|
45
49
|
export * from './terminal-util.js';
|
|
46
50
|
export * from './usage/index.js';
|
|
51
|
+
export * from './voice-bridge.js';
|
|
52
|
+
export * from './voices-file.js';
|
|
47
53
|
export * from './web-extension-catalog.js';
|
|
48
54
|
export * from './web-extension-util.js';
|
|
49
55
|
export * from './working-directory.js';
|
package/esm/node/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export * from './app-commands.js';
|
|
1
2
|
export * from './auth-server-impl.js';
|
|
2
3
|
export * from './client-channel.js';
|
|
3
4
|
export * from './client-tool-broker.js';
|
|
5
|
+
export * from './directory-relocator.js';
|
|
4
6
|
export * from './event-log.js';
|
|
5
7
|
export * from './exec-endpoint.js';
|
|
6
8
|
export * from './exec-environment-factory.js';
|
|
@@ -13,6 +15,8 @@ export * from './keep-awake.js';
|
|
|
13
15
|
export * from './package-host-extension.js';
|
|
14
16
|
export * from './package-hosts.js';
|
|
15
17
|
export * from './package-server-impl.js';
|
|
18
|
+
export * from './package-webhooks.js';
|
|
19
|
+
export * from './page-book.js';
|
|
16
20
|
export * from './presence-book.js';
|
|
17
21
|
export * from './presence-server-impl.js';
|
|
18
22
|
export * from './receipt-book.js';
|
|
@@ -44,6 +48,8 @@ export * from './terminal-protocol.js';
|
|
|
44
48
|
export * from './terminal-service.js';
|
|
45
49
|
export * from './terminal-util.js';
|
|
46
50
|
export * from './usage/index.js';
|
|
51
|
+
export * from './voice-bridge.js';
|
|
52
|
+
export * from './voices-file.js';
|
|
47
53
|
export * from './web-extension-catalog.js';
|
|
48
54
|
export * from './web-extension-util.js';
|
|
49
55
|
export * from './working-directory.js';
|
package/esm/node/keep-awake.d.ts
CHANGED
|
@@ -22,7 +22,9 @@ export declare namespace KeepAwakeUtil {
|
|
|
22
22
|
/**
|
|
23
23
|
* Keeps the computer from sleeping while idle as long as a session runs or a paired device was connected of
|
|
24
24
|
* late: asleep, ta serve answers no phone, and a phone that cannot reach it cannot wake it. It holds
|
|
25
|
-
* `caffeinate -i
|
|
25
|
+
* `caffeinate -i -s`, which ends with ta serve: idle sleep, and on power any sleep but of a closed lid, since a Mac
|
|
26
|
+
* that slept wakes only in the dark for minutes, where an assertion of idle sleep does not keep it; the display
|
|
27
|
+
* still sleeps. Stopping while it held it, it leaves one of BRIDGE_S, for the Ta that starts after.
|
|
26
28
|
* Turned off in relay.json (TaRelayServer.setKeepAwake); nothing where it is not supported.
|
|
27
29
|
*/
|
|
28
30
|
export declare class KeepAwakeImpl implements KeepAwake, ApplicationLifecycle<Application> {
|
|
@@ -41,4 +43,6 @@ export declare class KeepAwakeImpl implements KeepAwake, ApplicationLifecycle<Ap
|
|
|
41
43
|
protected release(): void;
|
|
42
44
|
/** `-w`: it ends when this process does, killed too. */
|
|
43
45
|
protected spawn(): ChildProcess;
|
|
46
|
+
/** Awake for a while after this process, on its own. */
|
|
47
|
+
protected spawnBridge(): ChildProcess;
|
|
44
48
|
}
|
package/esm/node/keep-awake.js
CHANGED
|
@@ -27,10 +27,17 @@ export var KeepAwakeUtil;
|
|
|
27
27
|
})(KeepAwakeUtil || (KeepAwakeUtil = {}));
|
|
28
28
|
/** How often what keeps the computer awake is looked at. */
|
|
29
29
|
const CHECK_MS = 15000;
|
|
30
|
+
/**
|
|
31
|
+
* How long the computer stays awake after ta serve stops while it held it: a restart of Ta (an update, Restart Ta)
|
|
32
|
+
* takes seconds, and a Mac idle past its sleep time falls asleep the moment the assertion goes, before the new one.
|
|
33
|
+
*/
|
|
34
|
+
const BRIDGE_S = 120;
|
|
30
35
|
/**
|
|
31
36
|
* Keeps the computer from sleeping while idle as long as a session runs or a paired device was connected of
|
|
32
37
|
* late: asleep, ta serve answers no phone, and a phone that cannot reach it cannot wake it. It holds
|
|
33
|
-
* `caffeinate -i
|
|
38
|
+
* `caffeinate -i -s`, which ends with ta serve: idle sleep, and on power any sleep but of a closed lid, since a Mac
|
|
39
|
+
* that slept wakes only in the dark for minutes, where an assertion of idle sleep does not keep it; the display
|
|
40
|
+
* still sleeps. Stopping while it held it, it leaves one of BRIDGE_S, for the Ta that starts after.
|
|
34
41
|
* Turned off in relay.json (TaRelayServer.setKeepAwake); nothing where it is not supported.
|
|
35
42
|
*/
|
|
36
43
|
let KeepAwakeImpl = class KeepAwakeImpl {
|
|
@@ -51,10 +58,15 @@ let KeepAwakeImpl = class KeepAwakeImpl {
|
|
|
51
58
|
}
|
|
52
59
|
this.timer = setInterval(() => this.check(), CHECK_MS);
|
|
53
60
|
(_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
61
|
+
this.check();
|
|
54
62
|
}
|
|
55
63
|
onStop() {
|
|
56
64
|
clearInterval(this.timer);
|
|
65
|
+
const held = this.held;
|
|
57
66
|
this.release();
|
|
67
|
+
if (held) {
|
|
68
|
+
this.spawnBridge().unref();
|
|
69
|
+
}
|
|
58
70
|
}
|
|
59
71
|
check(now = Date.now()) {
|
|
60
72
|
if (!this.supported) {
|
|
@@ -94,7 +106,11 @@ let KeepAwakeImpl = class KeepAwakeImpl {
|
|
|
94
106
|
}
|
|
95
107
|
/** `-w`: it ends when this process does, killed too. */
|
|
96
108
|
spawn() {
|
|
97
|
-
return spawn('/usr/bin/caffeinate', ['-i', '-w', String(process.pid)], { stdio: 'ignore' });
|
|
109
|
+
return spawn('/usr/bin/caffeinate', ['-i', '-s', '-w', String(process.pid)], { stdio: 'ignore' });
|
|
110
|
+
}
|
|
111
|
+
/** Awake for a while after this process, on its own. */
|
|
112
|
+
spawnBridge() {
|
|
113
|
+
return spawn('/usr/bin/caffeinate', ['-i', '-s', '-t', String(BRIDGE_S)], { stdio: 'ignore', detached: true });
|
|
98
114
|
}
|
|
99
115
|
};
|
|
100
116
|
__decorate([
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TaConversation, TaMessage, TaMessagePage } from '@celljs/ta-protocol';
|
|
1
|
+
import type { TaConversation, TaMessage, TaMessagePage, TaTurnHead } from '@celljs/ta-protocol';
|
|
2
2
|
/**
|
|
3
3
|
* The parts of a long conversation a client loads one at a time, the latest first: about so many bytes
|
|
4
4
|
* of JSON each, as the client gets them.
|
|
@@ -10,6 +10,11 @@ export declare namespace MessagePage {
|
|
|
10
10
|
* asked for their turn if that takes no more than twice the budget, so that a turn shows whole.
|
|
11
11
|
*/
|
|
12
12
|
function start(messages: readonly TaMessage[], end: number, budget: number): number;
|
|
13
|
+
/**
|
|
14
|
+
* When the messages from `from` start in the middle of a turn (the first of the user or the agent among them
|
|
15
|
+
* is a step of it): the message of the user that asked for the turn.
|
|
16
|
+
*/
|
|
17
|
+
function head(messages: readonly TaMessage[], from: number): TaTurnHead | undefined;
|
|
13
18
|
/** The latest part of a conversation, or all of it without a budget. */
|
|
14
19
|
function recent(conversation: TaConversation, budget: number | undefined): TaConversation;
|
|
15
20
|
/** The part before message `before`, found again by its timestamp if messages came or went before it. */
|
package/esm/node/message-page.js
CHANGED
|
@@ -42,13 +42,60 @@ export var MessagePage;
|
|
|
42
42
|
return start;
|
|
43
43
|
}
|
|
44
44
|
MessagePage.start = start;
|
|
45
|
+
/**
|
|
46
|
+
* A message of the user that the agent was given on the way, after the result of a tool it was written before:
|
|
47
|
+
* a step of the turn, not the start of another (as the web page reads it).
|
|
48
|
+
*/
|
|
49
|
+
function steered(messages, index) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (role(messages[index]) !== 'user') {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
for (let before = index - 1; before >= 0; before--) {
|
|
55
|
+
const was = (_a = role(messages[before])) !== null && _a !== void 0 ? _a : '';
|
|
56
|
+
if (was === 'user') {
|
|
57
|
+
return steered(messages, before);
|
|
58
|
+
}
|
|
59
|
+
if (TURN_ROLES.has(was)) {
|
|
60
|
+
const at = timestamp(messages[index]);
|
|
61
|
+
const came = timestamp(messages[before]);
|
|
62
|
+
return was === 'toolResult' && at !== undefined && came !== undefined && at < came;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* When the messages from `from` start in the middle of a turn (the first of the user or the agent among them
|
|
69
|
+
* is a step of it): the message of the user that asked for the turn.
|
|
70
|
+
*/
|
|
71
|
+
function head(messages, from) {
|
|
72
|
+
var _a;
|
|
73
|
+
let first = from;
|
|
74
|
+
while (first < messages.length && role(messages[first]) !== 'user' && !TURN_ROLES.has((_a = role(messages[first])) !== null && _a !== void 0 ? _a : '')) {
|
|
75
|
+
first++;
|
|
76
|
+
}
|
|
77
|
+
if (from <= 0 || first >= messages.length || (role(messages[first]) === 'user' && !steered(messages, first))) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
for (let index = from - 1; index >= 0; index--) {
|
|
81
|
+
if (role(messages[index]) === 'user' && !steered(messages, index)) {
|
|
82
|
+
return { index, message: messages[index] };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
MessagePage.head = head;
|
|
45
88
|
/** The latest part of a conversation, or all of it without a budget. */
|
|
46
89
|
function recent(conversation, budget) {
|
|
47
90
|
if (!budget || budget <= 0) {
|
|
48
91
|
return conversation;
|
|
49
92
|
}
|
|
50
93
|
const from = start(conversation.messages, conversation.messages.length, budget);
|
|
51
|
-
|
|
94
|
+
if (from === 0) {
|
|
95
|
+
return conversation;
|
|
96
|
+
}
|
|
97
|
+
const turn = head(conversation.messages, from);
|
|
98
|
+
return { ...conversation, messages: conversation.messages.slice(from), start: from, ...(turn ? { head: turn } : {}) };
|
|
52
99
|
}
|
|
53
100
|
MessagePage.recent = recent;
|
|
54
101
|
/** The part before message `before`, found again by its timestamp if messages came or went before it. */
|
|
@@ -64,7 +111,8 @@ export var MessagePage;
|
|
|
64
111
|
}
|
|
65
112
|
}
|
|
66
113
|
const from = start(messages, end, Math.max(1, budget));
|
|
67
|
-
|
|
114
|
+
const turn = head(messages, from);
|
|
115
|
+
return { messages: messages.slice(from, end), start: from, found: true, ...(turn ? { head: turn } : {}) };
|
|
68
116
|
}
|
|
69
117
|
MessagePage.before = before;
|
|
70
118
|
})(MessagePage || (MessagePage = {}));
|