@celljs/ta-host 4.15.2 → 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.
Files changed (105) hide show
  1. package/esm/node/app-commands.d.ts +111 -0
  2. package/esm/node/app-commands.js +629 -0
  3. package/esm/node/delegate-extension.d.ts +11 -0
  4. package/esm/node/delegate-extension.js +33 -0
  5. package/esm/node/directory-relocator.d.ts +49 -0
  6. package/esm/node/directory-relocator.js +267 -0
  7. package/esm/node/exec-endpoint.d.ts +14 -0
  8. package/esm/node/exec-endpoint.js +48 -0
  9. package/esm/node/extension-providers.d.ts +16 -1
  10. package/esm/node/extension-providers.js +23 -3
  11. package/esm/node/gateway-models.d.ts +38 -0
  12. package/esm/node/gateway-models.js +124 -0
  13. package/esm/node/index.d.ts +8 -0
  14. package/esm/node/index.js +8 -0
  15. package/esm/node/keep-awake.d.ts +5 -1
  16. package/esm/node/keep-awake.js +18 -2
  17. package/esm/node/message-page.d.ts +6 -1
  18. package/esm/node/message-page.js +50 -2
  19. package/esm/node/package-hosts.d.ts +6 -0
  20. package/esm/node/package-hosts.js +35 -0
  21. package/esm/node/package-webhooks.d.ts +26 -0
  22. package/esm/node/package-webhooks.js +101 -0
  23. package/esm/node/page-book.d.ts +48 -0
  24. package/esm/node/page-book.js +117 -0
  25. package/esm/node/relay-bridge.d.ts +2 -0
  26. package/esm/node/relay-bridge.js +35 -1
  27. package/esm/node/remote/cloud-hosts.d.ts +40 -0
  28. package/esm/node/remote/cloud-hosts.js +99 -0
  29. package/esm/node/remote/index.d.ts +1 -0
  30. package/esm/node/remote/index.js +1 -0
  31. package/esm/node/remote/pi-directories.d.ts +2 -1
  32. package/esm/node/remote/pi-directories.js +7 -2
  33. package/esm/node/remote/remote-hosts.d.ts +5 -0
  34. package/esm/node/remote/remote-hosts.js +71 -2
  35. package/esm/node/remote/remote-protocol.d.ts +2 -0
  36. package/esm/node/remote/remote-server-impl.d.ts +1 -0
  37. package/esm/node/remote/remote-server-impl.js +3 -0
  38. package/esm/node/rooms-bridge.d.ts +3 -0
  39. package/esm/node/rooms-bridge.js +4 -0
  40. package/esm/node/session-info-util.d.ts +3 -1
  41. package/esm/node/session-info-util.js +32 -6
  42. package/esm/node/ta-server-impl.d.ts +5 -1
  43. package/esm/node/ta-server-impl.js +22 -0
  44. package/esm/node/ta-session-factory.d.ts +13 -1
  45. package/esm/node/ta-session-factory.js +39 -4
  46. package/esm/node/ta-session.d.ts +2 -0
  47. package/esm/node/ta-session.js +1 -0
  48. package/esm/node/team/team-calls.js +23 -0
  49. package/esm/node/voice-bridge.d.ts +68 -0
  50. package/esm/node/voice-bridge.js +273 -0
  51. package/esm/node/voices-file.d.ts +33 -0
  52. package/esm/node/voices-file.js +89 -0
  53. package/lib/node/app-commands.d.ts +112 -0
  54. package/lib/node/app-commands.js +633 -0
  55. package/lib/node/delegate-extension.d.ts +12 -0
  56. package/lib/node/delegate-extension.js +37 -0
  57. package/lib/node/directory-relocator.d.ts +50 -0
  58. package/lib/node/directory-relocator.js +270 -0
  59. package/lib/node/exec-endpoint.d.ts +15 -0
  60. package/lib/node/exec-endpoint.js +51 -0
  61. package/lib/node/extension-providers.d.ts +16 -1
  62. package/lib/node/extension-providers.js +23 -3
  63. package/lib/node/gateway-models.d.ts +39 -0
  64. package/lib/node/gateway-models.js +127 -0
  65. package/lib/node/index.d.ts +8 -0
  66. package/lib/node/index.js +8 -0
  67. package/lib/node/keep-awake.d.ts +5 -1
  68. package/lib/node/keep-awake.js +18 -2
  69. package/lib/node/message-page.d.ts +6 -1
  70. package/lib/node/message-page.js +50 -2
  71. package/lib/node/package-hosts.d.ts +6 -0
  72. package/lib/node/package-hosts.js +35 -0
  73. package/lib/node/package-webhooks.d.ts +27 -0
  74. package/lib/node/package-webhooks.js +104 -0
  75. package/lib/node/page-book.d.ts +49 -0
  76. package/lib/node/page-book.js +120 -0
  77. package/lib/node/relay-bridge.d.ts +2 -0
  78. package/lib/node/relay-bridge.js +34 -0
  79. package/lib/node/remote/cloud-hosts.d.ts +41 -0
  80. package/lib/node/remote/cloud-hosts.js +103 -0
  81. package/lib/node/remote/index.d.ts +1 -0
  82. package/lib/node/remote/index.js +1 -0
  83. package/lib/node/remote/pi-directories.d.ts +2 -1
  84. package/lib/node/remote/pi-directories.js +7 -2
  85. package/lib/node/remote/remote-hosts.d.ts +5 -0
  86. package/lib/node/remote/remote-hosts.js +71 -2
  87. package/lib/node/remote/remote-protocol.d.ts +2 -0
  88. package/lib/node/remote/remote-server-impl.d.ts +1 -0
  89. package/lib/node/remote/remote-server-impl.js +3 -0
  90. package/lib/node/rooms-bridge.d.ts +3 -0
  91. package/lib/node/rooms-bridge.js +4 -0
  92. package/lib/node/session-info-util.d.ts +3 -1
  93. package/lib/node/session-info-util.js +31 -5
  94. package/lib/node/ta-server-impl.d.ts +5 -1
  95. package/lib/node/ta-server-impl.js +22 -0
  96. package/lib/node/ta-session-factory.d.ts +13 -1
  97. package/lib/node/ta-session-factory.js +38 -3
  98. package/lib/node/ta-session.d.ts +2 -0
  99. package/lib/node/ta-session.js +1 -0
  100. package/lib/node/team/team-calls.js +23 -0
  101. package/lib/node/voice-bridge.d.ts +69 -0
  102. package/lib/node/voice-bridge.js +274 -0
  103. package/lib/node/voices-file.d.ts +34 -0
  104. package/lib/node/voices-file.js +93 -0
  105. package/package.json +10 -10
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DelegateExtension = void 0;
4
+ const ta_protocol_1 = require("@celljs/ta-protocol");
5
+ /**
6
+ * Holds the double to how much the user wants it to hand out (Settings.delegate): in a session whose role has the
7
+ * mark of a level (TaDelegateUtil.mark), its calls of the tools that change files are turned down, and those of its
8
+ * own tools past the steps of a run, each with what to do instead. Other sessions (tasks, chats, agents) have no
9
+ * mark and are left alone.
10
+ */
11
+ class DelegateExtension {
12
+ constructor() {
13
+ this.name = 'ta-delegate';
14
+ }
15
+ register(pi) {
16
+ let steps = 0;
17
+ pi.on('agent_start', () => {
18
+ steps = 0;
19
+ });
20
+ pi.on('tool_call', (event, ctx) => {
21
+ const level = ta_protocol_1.TaDelegateUtil.levelOf(ctx.getSystemPrompt());
22
+ if (!level) {
23
+ return undefined;
24
+ }
25
+ const reason = ta_protocol_1.TaDelegateUtil.refusal(level, event.toolName, steps);
26
+ if (reason) {
27
+ return { block: true, reason };
28
+ }
29
+ if (ta_protocol_1.TaDelegateUtil.WORK_TOOLS.includes(event.toolName)) {
30
+ steps++;
31
+ }
32
+ return undefined;
33
+ });
34
+ }
35
+ }
36
+ exports.DelegateExtension = DelegateExtension;
37
+ //# sourceMappingURL=delegate-extension.js.map
@@ -0,0 +1,50 @@
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';
5
+ import { type TaExecOptions, TaSessionRegistry } from './host-protocol';
6
+ import { PiDirectories } from './remote/remote-protocol';
7
+ import { TaSessionHandles } from './session-handles';
8
+ import { TaWorkingDirectory } from './working-directory';
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
+ }
50
+ //# sourceMappingURL=directory-relocator.d.ts.map
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TaDirectoryRelocatorImpl = exports.DirectoryRelocatorUtil = exports.TaDirectoryRelocator = void 0;
13
+ const promises_1 = require("node:fs/promises");
14
+ const node_path_1 = require("node:path");
15
+ const ai_coding_agent_1 = require("@celljs/ai-coding-agent");
16
+ const core_1 = require("@celljs/core");
17
+ const ta_exec_1 = require("@celljs/ta-exec");
18
+ const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
19
+ const ta_protocol_1 = require("@celljs/ta-protocol");
20
+ const extension_data_1 = require("./extension-data");
21
+ const host_protocol_1 = require("./host-protocol");
22
+ const remote_protocol_1 = require("./remote/remote-protocol");
23
+ const session_handles_1 = require("./session-handles");
24
+ const ta_errors_1 = require("./ta-errors");
25
+ const working_directory_1 = require("./working-directory");
26
+ exports.TaDirectoryRelocator = Symbol('TaDirectoryRelocator');
27
+ /** The first line of a session file of pi is its header; it is read without the rest. */
28
+ const HEADER_BYTES = 64 * 1024;
29
+ var DirectoryRelocatorUtil;
30
+ (function (DirectoryRelocatorUtil) {
31
+ /** pi's folder of the sessions of a directory (SessionManager's getDefaultSessionDirPath), its name. */
32
+ function sessionDir(cwd) {
33
+ return `--${cwd.replace(/^[/\\]/, '').replace(/[/\\:]/g, '-')}--`;
34
+ }
35
+ DirectoryRelocatorUtil.sessionDir = sessionDir;
36
+ /** The directory of a session file, from its header; undefined for what is not a session of pi. */
37
+ async function headerCwd(file) {
38
+ const handle = await (0, promises_1.open)(file, 'r').catch(() => undefined);
39
+ if (!handle) {
40
+ return undefined;
41
+ }
42
+ try {
43
+ const buffer = Buffer.alloc(HEADER_BYTES);
44
+ const { bytesRead } = await handle.read(buffer, 0, HEADER_BYTES, 0);
45
+ const text = buffer.subarray(0, bytesRead).toString('utf8');
46
+ const end = text.indexOf('\n');
47
+ const header = JSON.parse(end < 0 ? text : text.slice(0, end));
48
+ return header.type === 'session' && typeof header.cwd === 'string' ? header.cwd : undefined;
49
+ }
50
+ catch (_a) {
51
+ return undefined;
52
+ }
53
+ finally {
54
+ await handle.close();
55
+ }
56
+ }
57
+ DirectoryRelocatorUtil.headerCwd = headerCwd;
58
+ /** The file with its header in \`cwd\`; the rest as it was. */
59
+ function withCwd(text, cwd) {
60
+ const end = text.indexOf('\n');
61
+ const header = JSON.parse(end < 0 ? text : text.slice(0, end));
62
+ return JSON.stringify({ ...header, cwd }) + (end < 0 ? '' : text.slice(end));
63
+ }
64
+ DirectoryRelocatorUtil.withCwd = withCwd;
65
+ })(DirectoryRelocatorUtil || (exports.DirectoryRelocatorUtil = DirectoryRelocatorUtil = {}));
66
+ let TaDirectoryRelocatorImpl = class TaDirectoryRelocatorImpl {
67
+ constructor() {
68
+ /** One at a time: two would move the same files. */
69
+ this.running = Promise.resolve();
70
+ }
71
+ relocate(from, to) {
72
+ const next = this.running.catch(() => undefined).then(() => this.move(from, to));
73
+ this.running = next.then(() => undefined, () => undefined);
74
+ return next;
75
+ }
76
+ async move(from, to) {
77
+ var _a;
78
+ const old = typeof from === 'string' ? from.trim() : '';
79
+ const target = typeof to === 'string' && to.trim() ? await this.environments.resolve(to.trim()) : '';
80
+ const env = target ? this.environments.create(target) : undefined;
81
+ if (!old || !env || !((_a = (await env.stat(env.cwd))) === null || _a === void 0 ? void 0 : _a.isDirectory)) {
82
+ throw ta_errors_1.TaErrors.invalidArgument(`${to} is not a directory.`, 'Pass the directory as it was, and one that exists now: a path, or an ssh:// location.');
83
+ }
84
+ const fromPi = ta_protocol_1.TaLocation.isRemote(old) ? this.directories.toPi(old) : old;
85
+ const toPi = this.directories.toPi(target);
86
+ if (fromPi === toPi || ta_protocol_1.TaPathMap.under(toPi, fromPi)) {
87
+ throw ta_errors_1.TaErrors.invalidArgument(`${target} is ${old} or in it.`, 'Pass another directory, not one inside the old one.');
88
+ }
89
+ const pairs = [[fromPi, toPi]];
90
+ if (old !== fromPi) {
91
+ pairs.push([old, target]);
92
+ }
93
+ const result = { conversations: 0, busy: 0, data: 0, files: {} };
94
+ const cwds = new Map([[fromPi, toPi]]);
95
+ const root = (0, node_path_1.join)(this.agentDir(), 'sessions');
96
+ for (const file of await this.sessionFiles(root)) {
97
+ const cwd = await DirectoryRelocatorUtil.headerCwd(file);
98
+ if (cwd === undefined || !ta_protocol_1.TaPathMap.under(cwd, fromPi)) {
99
+ continue;
100
+ }
101
+ const cwdNow = ta_protocol_1.TaPathMap.path(cwd, pairs);
102
+ if (await this.moveSession(file, (0, node_path_1.join)(root, DirectoryRelocatorUtil.sessionDir(cwdNow), (0, node_path_1.basename)(file)), cwdNow, result)) {
103
+ cwds.set(cwd, cwdNow);
104
+ }
105
+ }
106
+ const filePairs = Object.entries(result.files);
107
+ result.data = await this.moveData([...filePairs, ...pairs], cwds);
108
+ const working = this.workingDirectory.get();
109
+ if (working) {
110
+ const moved = ta_protocol_1.TaPathMap.path(working, pairs);
111
+ if (moved !== working) {
112
+ this.workingDirectory.set(moved);
113
+ }
114
+ }
115
+ return result;
116
+ }
117
+ /** 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. */
118
+ async moveSession(file, next, cwd, result) {
119
+ var _a;
120
+ const open = this.sessions.list().find(session => session.pi.sessionFile === file);
121
+ if (open === null || open === void 0 ? void 0 : open.pi.isStreaming) {
122
+ result.busy++;
123
+ return false;
124
+ }
125
+ if (file === next || (await (0, promises_1.stat)(next).catch(() => undefined))) {
126
+ return false;
127
+ }
128
+ const id = (_a = open === null || open === void 0 ? void 0 : open.id) !== null && _a !== void 0 ? _a : this.handles.idOf(file);
129
+ if (open) {
130
+ await this.sessions.close(open.id, true);
131
+ }
132
+ const text = await (0, promises_1.readFile)(file, 'utf8');
133
+ await this.write(next, DirectoryRelocatorUtil.withCwd(text, cwd));
134
+ await (0, promises_1.rm)(file, { force: true });
135
+ await (0, promises_1.rmdir)((0, node_path_1.dirname)(file)).catch(() => undefined);
136
+ if (id) {
137
+ const handle = this.handles.get(id);
138
+ this.handles.set(id, { ...handle, sessionFile: next, cwd: this.directories.fromPi(cwd) });
139
+ }
140
+ result.files[file] = next;
141
+ result.conversations++;
142
+ return true;
143
+ }
144
+ /**
145
+ * The data of packages with the paths mapped, key by key through the store (pages hear of each): the files of
146
+ * every package, and those of the directories moved, into the data of their new directory.
147
+ */
148
+ async moveData(pairs, cwds) {
149
+ var _a;
150
+ var _b;
151
+ const changed = new Set();
152
+ const root = (0, node_path_1.join)(this.agentDir(), 'extension-data');
153
+ for (const name of await this.packageFiles(root, false)) {
154
+ const values = extension_data_1.ExtensionDataUtil.parse(await (0, promises_1.readFile)((0, node_path_1.join)(root, `${name}.json`), 'utf8').catch(() => undefined));
155
+ if (await this.rewrite(name, values, pairs)) {
156
+ changed.add(name);
157
+ }
158
+ }
159
+ const environment = (_b = (_a = this.execOptions) === null || _a === void 0 ? void 0 : _a.url) !== null && _b !== void 0 ? _b : '';
160
+ for (const [cwd, cwdNow] of cwds) {
161
+ const before = this.directories.fromPi(cwd);
162
+ const dir = (0, node_path_1.join)(root, 'directories', extension_data_1.ExtensionDataUtil.directoryId(before, environment));
163
+ const names = await this.packageFiles(dir, true);
164
+ for (const name of names) {
165
+ const values = extension_data_1.ExtensionDataUtil.parse(await (0, promises_1.readFile)((0, node_path_1.join)(dir, `${name}.json`), 'utf8').catch(() => undefined));
166
+ await this.rewrite(name, values, pairs, this.directories.fromPi(cwdNow), true);
167
+ changed.add(name);
168
+ }
169
+ if (names.length) {
170
+ await (0, promises_1.rm)(dir, { recursive: true, force: true });
171
+ }
172
+ }
173
+ return changed.size;
174
+ }
175
+ /** \`all\`: every key goes, into the data of the directory \`cwd\`; otherwise only what changed, in place. */
176
+ async rewrite(name, values, pairs, cwd, all = false) {
177
+ let changed = false;
178
+ for (const [key, value] of Object.entries(values)) {
179
+ const keyNow = ta_protocol_1.TaPathMap.json(key, pairs);
180
+ const valueNow = ta_protocol_1.TaPathMap.json(value, pairs);
181
+ if (!all && keyNow === key && JSON.stringify(valueNow) === JSON.stringify(value)) {
182
+ continue;
183
+ }
184
+ if (!all && keyNow !== key) {
185
+ await this.data.set(name, key, null, cwd);
186
+ }
187
+ await this.data.set(name, keyNow, valueNow, cwd);
188
+ changed = true;
189
+ }
190
+ return changed;
191
+ }
192
+ /** The packages with a file of data in \`root\`, by name (\`@scope/name\` in a folder of its scope); not the data of directories. */
193
+ async packageFiles(root, directory) {
194
+ const names = [];
195
+ for (const entry of await (0, promises_1.readdir)(root, { withFileTypes: true }).catch(() => [])) {
196
+ if (entry.isFile() && entry.name.endsWith('.json')) {
197
+ names.push(entry.name.slice(0, -'.json'.length));
198
+ }
199
+ else if (entry.isDirectory() && entry.name.startsWith('@') && (directory || entry.name !== 'directories')) {
200
+ for (const inner of await (0, promises_1.readdir)((0, node_path_1.join)(root, entry.name)).catch(() => [])) {
201
+ if (inner.endsWith('.json')) {
202
+ names.push(`${entry.name}/${inner.slice(0, -'.json'.length)}`);
203
+ }
204
+ }
205
+ }
206
+ }
207
+ return names;
208
+ }
209
+ async sessionFiles(root) {
210
+ const files = [];
211
+ for (const dir of await (0, promises_1.readdir)(root, { withFileTypes: true }).catch(() => [])) {
212
+ if (dir.isDirectory()) {
213
+ for (const name of await (0, promises_1.readdir)((0, node_path_1.join)(root, dir.name)).catch(() => [])) {
214
+ if (name.endsWith('.jsonl')) {
215
+ files.push((0, node_path_1.join)(root, dir.name, name));
216
+ }
217
+ }
218
+ }
219
+ }
220
+ return files;
221
+ }
222
+ async write(file, text) {
223
+ await (0, promises_1.mkdir)((0, node_path_1.dirname)(file), { recursive: true });
224
+ const temporary = `${file}.ta-relocate-${process.pid}`;
225
+ await (0, promises_1.writeFile)(temporary, text);
226
+ await (0, promises_1.rename)(temporary, file);
227
+ }
228
+ agentDir() {
229
+ var _a;
230
+ var _b;
231
+ return (_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : ta_brand_1.TaBrand.agentDir();
232
+ }
233
+ };
234
+ exports.TaDirectoryRelocatorImpl = TaDirectoryRelocatorImpl;
235
+ __decorate([
236
+ (0, core_1.Value)(ai_coding_agent_1.CODING_AGENT_OPTIONS),
237
+ __metadata("design:type", Object)
238
+ ], TaDirectoryRelocatorImpl.prototype, "codingAgentOptions", void 0);
239
+ __decorate([
240
+ (0, core_1.Value)(host_protocol_1.TA_EXEC_OPTIONS),
241
+ __metadata("design:type", Object)
242
+ ], TaDirectoryRelocatorImpl.prototype, "execOptions", void 0);
243
+ __decorate([
244
+ (0, core_1.Autowired)(host_protocol_1.TaSessionRegistry),
245
+ __metadata("design:type", Object)
246
+ ], TaDirectoryRelocatorImpl.prototype, "sessions", void 0);
247
+ __decorate([
248
+ (0, core_1.Autowired)(session_handles_1.TaSessionHandles),
249
+ __metadata("design:type", Object)
250
+ ], TaDirectoryRelocatorImpl.prototype, "handles", void 0);
251
+ __decorate([
252
+ (0, core_1.Autowired)(extension_data_1.ExtensionDataStore),
253
+ __metadata("design:type", Object)
254
+ ], TaDirectoryRelocatorImpl.prototype, "data", void 0);
255
+ __decorate([
256
+ (0, core_1.Autowired)(remote_protocol_1.PiDirectories),
257
+ __metadata("design:type", Object)
258
+ ], TaDirectoryRelocatorImpl.prototype, "directories", void 0);
259
+ __decorate([
260
+ (0, core_1.Autowired)(working_directory_1.TaWorkingDirectory),
261
+ __metadata("design:type", Object)
262
+ ], TaDirectoryRelocatorImpl.prototype, "workingDirectory", void 0);
263
+ __decorate([
264
+ (0, core_1.Autowired)(ta_exec_1.ExecEnvironmentFactory),
265
+ __metadata("design:type", Object)
266
+ ], TaDirectoryRelocatorImpl.prototype, "environments", void 0);
267
+ exports.TaDirectoryRelocatorImpl = TaDirectoryRelocatorImpl = __decorate([
268
+ (0, core_1.Component)(exports.TaDirectoryRelocator)
269
+ ], TaDirectoryRelocatorImpl);
270
+ //# sourceMappingURL=directory-relocator.js.map
@@ -0,0 +1,15 @@
1
+ import type { Server } from 'node:http';
2
+ import { ExecServer } from '@celljs/ta-exec';
3
+ import { ServerAware } from '@celljs/web/lib/node';
4
+ import { type TaAccess } from './ta-access';
5
+ /**
6
+ * `/api/exec` of ta serve: its machine as the exec server of another Ta (a cloud workspace, `ta://<name>`), whose
7
+ * agent stays there while commands and files are here. Its owner's token only: what it opens is a shell. A gateway
8
+ * forwards it to the sandbox of the account that asks (GatewayExecProxy).
9
+ */
10
+ export declare class TaExecEndpoint implements ServerAware {
11
+ protected readonly access: TaAccess;
12
+ protected exec?: ExecServer;
13
+ setServer(server: Server): Promise<void>;
14
+ }
15
+ //# sourceMappingURL=exec-endpoint.d.ts.map
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TaExecEndpoint = void 0;
13
+ const core_1 = require("@celljs/core");
14
+ const ta_exec_1 = require("@celljs/ta-exec");
15
+ const ta_protocol_1 = require("@celljs/ta-protocol");
16
+ const node_1 = require("@celljs/web/lib/node");
17
+ const cloud_hosts_1 = require("./remote/cloud-hosts");
18
+ const ta_access_1 = require("./ta-access");
19
+ /**
20
+ * `/api/exec` of ta serve: its machine as the exec server of another Ta (a cloud workspace, `ta://<name>`), whose
21
+ * agent stays there while commands and files are here. Its owner's token only: what it opens is a shell. A gateway
22
+ * forwards it to the sandbox of the account that asks (GatewayExecProxy).
23
+ */
24
+ let TaExecEndpoint = class TaExecEndpoint {
25
+ async setServer(server) {
26
+ if (typeof (server === null || server === void 0 ? void 0 : server.on) !== 'function') {
27
+ return;
28
+ }
29
+ server.on('upgrade', (request, socket, head) => {
30
+ var _a, _b;
31
+ const path = ((_a = request.url) !== null && _a !== void 0 ? _a : '/').split('?')[0];
32
+ if (path === cloud_hosts_1.TA_EXEC_PATH) {
33
+ (_b = this.exec) !== null && _b !== void 0 ? _b : (this.exec = new ta_exec_1.ExecServer({ token: this.access.token, cwd: process.cwd() }));
34
+ this.exec.accept(request, socket, head);
35
+ }
36
+ else if (path !== ta_protocol_1.TA_WEBSOCKET_PATH && server.listenerCount('upgrade') <= 2) {
37
+ // Nobody else answers it: the RPC socket answers only its own path while another listens too.
38
+ socket.destroy();
39
+ }
40
+ });
41
+ }
42
+ };
43
+ exports.TaExecEndpoint = TaExecEndpoint;
44
+ __decorate([
45
+ (0, core_1.Autowired)(ta_access_1.TA_ACCESS),
46
+ __metadata("design:type", Function)
47
+ ], TaExecEndpoint.prototype, "access", void 0);
48
+ exports.TaExecEndpoint = TaExecEndpoint = __decorate([
49
+ (0, core_1.Component)(node_1.ServerAware)
50
+ ], TaExecEndpoint);
51
+ //# sourceMappingURL=exec-endpoint.js.map
@@ -1,23 +1,38 @@
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
- /** Loads the extensions of the user once, for the providers they register; later calls wait for that. */
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 {};
23
38
  //# sourceMappingURL=extension-providers.d.ts.map
@@ -16,10 +16,29 @@ const core_1 = require("@celljs/core");
16
16
  const ta_harness_1 = require("@celljs/ta-harness");
17
17
  exports.ExtensionProviders = Symbol('ExtensionProviders');
18
18
  let ExtensionProvidersImpl = class ExtensionProvidersImpl {
19
- ensure() {
19
+ async ensure() {
20
20
  var _a;
21
21
  (_a = this.loading) !== null && _a !== void 0 ? _a : (this.loading = this.load().catch(() => undefined));
22
- return this.loading;
22
+ await this.loading;
23
+ await this.flush();
24
+ }
25
+ /** What the extensions registered since they loaded, into the model runtime, as pi does when they load. */
26
+ async flush() {
27
+ const pending = this.pending;
28
+ if (!(pending === null || pending === void 0 ? void 0 : pending.pendingProviderRegistrations.length)) {
29
+ return;
30
+ }
31
+ const registrations = pending.pendingProviderRegistrations;
32
+ pending.pendingProviderRegistrations = [];
33
+ const runtime = await this.modelRuntimeProvider.provide();
34
+ for (const { name, config } of registrations) {
35
+ try {
36
+ runtime.registerProvider(name, config);
37
+ }
38
+ catch (_a) {
39
+ // As pi does: a provider that does not register is left out.
40
+ }
41
+ }
23
42
  }
24
43
  /**
25
44
  * pi's services of a directory without a project (the home directory, its project resources not
@@ -31,13 +50,14 @@ let ExtensionProvidersImpl = class ExtensionProvidersImpl {
31
50
  const sdk = await ai_coding_agent_1.PiSdkUtil.load();
32
51
  const agentDir = (_b = (_a = this.codingAgentOptions) === null || _a === void 0 ? void 0 : _a.agentDir) !== null && _b !== void 0 ? _b : sdk.getAgentDir();
33
52
  const cwd = (0, node_os_1.homedir)();
34
- await sdk.createAgentSessionServices({
53
+ const services = await sdk.createAgentSessionServices({
35
54
  cwd,
36
55
  agentDir,
37
56
  settingsManager: sdk.SettingsManager.create(cwd, agentDir, { projectTrusted: false }),
38
57
  modelRuntime: await this.modelRuntimeProvider.provide(),
39
58
  resourceLoaderOptions: ta_harness_1.TaPackages.loaderOptions(agentDir, { loadSkills: sdk.loadSkillsFromDir }),
40
59
  });
60
+ this.pending = services.resourceLoader.getExtensions().runtime;
41
61
  }
42
62
  };
43
63
  exports.ExtensionProvidersImpl = ExtensionProvidersImpl;
@@ -0,0 +1,39 @@
1
+ import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
2
+ import { type Application, ApplicationLifecycle } from '@celljs/core';
3
+ interface Catalog {
4
+ providers?: {
5
+ id: string;
6
+ name?: string;
7
+ api: string;
8
+ models: Record<string, unknown>[];
9
+ }[];
10
+ }
11
+ type Json = Record<string, unknown>;
12
+ export declare namespace GatewayModelsUtil {
13
+ const URL_ENV = "TA_MODEL_PROXY_URL";
14
+ const KEY_ENV = "TA_MODEL_PROXY_KEY";
15
+ /**
16
+ * models.json with the providers of the gateway, each at the gateway (`<url>/api/models/<id>`) with the model key of
17
+ * this sandbox: those it gave before and no longer does go; those of the user stay.
18
+ */
19
+ function apply(models: Json, catalog: Catalog, url: string, key: string, before: string[]): {
20
+ models: Json;
21
+ managed: string[];
22
+ };
23
+ /** settings.json with the first model of the gateway as the default, when it has none. */
24
+ function defaults(settings: Json, catalog: Catalog): Json | undefined;
25
+ }
26
+ /**
27
+ * The models of a gateway, for a Ta in its sandbox (docs/design/ta-cloud.md 3.4): with TA_MODEL_PROXY_URL and
28
+ * TA_MODEL_PROXY_KEY, ta serve reads the catalog of the gateway as it starts and puts its providers in pi's
29
+ * models.json, at the gateway with the model key of this sandbox. The keys of the providers stay with the gateway,
30
+ * which counts what each call takes. The two variables leave the environment, so that no command sees them.
31
+ */
32
+ export declare class GatewayModels implements ApplicationLifecycle<Application> {
33
+ protected readonly codingAgentOptions?: CodingAgentOptions;
34
+ onStart(): Promise<void>;
35
+ protected read(file: string): Json;
36
+ protected write(file: string, data: Json): void;
37
+ }
38
+ export {};
39
+ //# sourceMappingURL=gateway-models.d.ts.map