@celljs/ta-host 4.16.0 → 4.18.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 (179) hide show
  1. package/esm/node/app-commands.d.ts +111 -0
  2. package/esm/node/app-commands.js +646 -0
  3. package/esm/node/credentials.d.ts +12 -0
  4. package/esm/node/credentials.js +35 -0
  5. package/esm/node/delegate-extension.d.ts +11 -0
  6. package/esm/node/delegate-extension.js +33 -0
  7. package/esm/node/directory-relocator.d.ts +49 -0
  8. package/esm/node/directory-relocator.js +267 -0
  9. package/esm/node/extension-providers.d.ts +16 -1
  10. package/esm/node/extension-providers.js +23 -3
  11. package/esm/node/index.d.ts +8 -0
  12. package/esm/node/index.js +8 -0
  13. package/esm/node/keep-awake.d.ts +8 -1
  14. package/esm/node/keep-awake.js +24 -3
  15. package/esm/node/message-page.d.ts +6 -1
  16. package/esm/node/message-page.js +50 -2
  17. package/esm/node/package-hosts.d.ts +8 -0
  18. package/esm/node/package-hosts.js +41 -0
  19. package/esm/node/package-webhooks.d.ts +26 -0
  20. package/esm/node/package-webhooks.js +101 -0
  21. package/esm/node/page-book.d.ts +48 -0
  22. package/esm/node/page-book.js +117 -0
  23. package/esm/node/relay-bridge.d.ts +2 -0
  24. package/esm/node/relay-bridge.js +35 -1
  25. package/esm/node/rooms-bridge.d.ts +13 -1
  26. package/esm/node/rooms-bridge.js +29 -0
  27. package/esm/node/screen-share/desktop-picture.d.ts +51 -0
  28. package/esm/node/screen-share/desktop-picture.js +133 -0
  29. package/esm/node/screen-share/desktop-session.d.ts +128 -0
  30. package/esm/node/screen-share/desktop-session.js +437 -0
  31. package/esm/node/screen-share/desktop-targets.d.ts +24 -0
  32. package/esm/node/screen-share/desktop-targets.js +80 -0
  33. package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
  34. package/esm/node/screen-share/desktop-viewer.js +339 -0
  35. package/esm/node/screen-share/index.d.ts +8 -0
  36. package/esm/node/screen-share/index.js +9 -0
  37. package/esm/node/screen-share/rfb-client.d.ts +54 -0
  38. package/esm/node/screen-share/rfb-client.js +179 -0
  39. package/esm/node/screen-share/rfb-des.d.ts +11 -0
  40. package/esm/node/screen-share/rfb-des.js +143 -0
  41. package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
  42. package/esm/node/screen-share/rfb-encodings.js +288 -0
  43. package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
  44. package/esm/node/screen-share/rfb-framebuffer.js +53 -0
  45. package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
  46. package/esm/node/screen-share/rfb-protocol.js +36 -0
  47. package/esm/node/screen-share/rfb-reader.d.ts +34 -0
  48. package/esm/node/screen-share/rfb-reader.js +110 -0
  49. package/esm/node/screen-share/rfb-security.d.ts +30 -0
  50. package/esm/node/screen-share/rfb-security.js +136 -0
  51. package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
  52. package/esm/node/screen-share/rfb-test-server.js +116 -0
  53. package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
  54. package/esm/node/screen-share/screen-share-server-impl.js +76 -0
  55. package/esm/node/screen-share/screen-shares.d.ts +123 -0
  56. package/esm/node/screen-share/screen-shares.js +463 -0
  57. package/esm/node/session-info-util.d.ts +10 -9
  58. package/esm/node/session-info-util.js +16 -68
  59. package/esm/node/settings-store.d.ts +1 -1
  60. package/esm/node/settings-store.js +7 -4
  61. package/esm/node/sign-in/access-store.d.ts +1 -1
  62. package/esm/node/sign-in/access-store.js +4 -1
  63. package/esm/node/sign-in/index.d.ts +2 -0
  64. package/esm/node/sign-in/index.js +2 -0
  65. package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
  66. package/esm/node/sign-in/polled-sign-in.js +83 -0
  67. package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
  68. package/esm/node/sign-in/sign-in-devices.js +113 -0
  69. package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
  70. package/esm/node/sign-in/sign-in-flow.js +79 -4
  71. package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
  72. package/esm/node/sign-in/sign-in-pages.js +137 -8
  73. package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
  74. package/esm/node/sign-in/sign-in-provider.js +15 -0
  75. package/esm/node/sources-extension.d.ts +10 -0
  76. package/esm/node/sources-extension.js +18 -0
  77. package/esm/node/ta-server-impl.d.ts +5 -1
  78. package/esm/node/ta-server-impl.js +25 -3
  79. package/esm/node/ta-session-factory.d.ts +13 -1
  80. package/esm/node/ta-session-factory.js +41 -4
  81. package/esm/node/ta-session.d.ts +2 -0
  82. package/esm/node/ta-session.js +1 -0
  83. package/esm/node/team/team-calls.js +49 -0
  84. package/esm/node/voice-bridge.d.ts +70 -0
  85. package/esm/node/voice-bridge.js +280 -0
  86. package/esm/node/voices-file.d.ts +38 -0
  87. package/esm/node/voices-file.js +100 -0
  88. package/esm/node/working-directory.d.ts +8 -2
  89. package/esm/node/working-directory.js +7 -0
  90. package/lib/node/app-commands.d.ts +112 -0
  91. package/lib/node/app-commands.js +650 -0
  92. package/lib/node/credentials.d.ts +13 -0
  93. package/lib/node/credentials.js +38 -0
  94. package/lib/node/delegate-extension.d.ts +12 -0
  95. package/lib/node/delegate-extension.js +37 -0
  96. package/lib/node/directory-relocator.d.ts +50 -0
  97. package/lib/node/directory-relocator.js +270 -0
  98. package/lib/node/extension-providers.d.ts +16 -1
  99. package/lib/node/extension-providers.js +23 -3
  100. package/lib/node/index.d.ts +8 -0
  101. package/lib/node/index.js +8 -0
  102. package/lib/node/keep-awake.d.ts +8 -1
  103. package/lib/node/keep-awake.js +24 -3
  104. package/lib/node/message-page.d.ts +6 -1
  105. package/lib/node/message-page.js +50 -2
  106. package/lib/node/package-hosts.d.ts +8 -0
  107. package/lib/node/package-hosts.js +41 -0
  108. package/lib/node/package-webhooks.d.ts +27 -0
  109. package/lib/node/package-webhooks.js +104 -0
  110. package/lib/node/page-book.d.ts +49 -0
  111. package/lib/node/page-book.js +120 -0
  112. package/lib/node/relay-bridge.d.ts +2 -0
  113. package/lib/node/relay-bridge.js +34 -0
  114. package/lib/node/rooms-bridge.d.ts +13 -1
  115. package/lib/node/rooms-bridge.js +29 -0
  116. package/lib/node/screen-share/desktop-picture.d.ts +52 -0
  117. package/lib/node/screen-share/desktop-picture.js +136 -0
  118. package/lib/node/screen-share/desktop-session.d.ts +129 -0
  119. package/lib/node/screen-share/desktop-session.js +442 -0
  120. package/lib/node/screen-share/desktop-targets.d.ts +25 -0
  121. package/lib/node/screen-share/desktop-targets.js +84 -0
  122. package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
  123. package/lib/node/screen-share/desktop-viewer.js +343 -0
  124. package/lib/node/screen-share/index.d.ts +9 -0
  125. package/lib/node/screen-share/index.js +25 -0
  126. package/lib/node/screen-share/rfb-client.d.ts +55 -0
  127. package/lib/node/screen-share/rfb-client.js +183 -0
  128. package/lib/node/screen-share/rfb-des.d.ts +12 -0
  129. package/lib/node/screen-share/rfb-des.js +146 -0
  130. package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
  131. package/lib/node/screen-share/rfb-encodings.js +295 -0
  132. package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
  133. package/lib/node/screen-share/rfb-framebuffer.js +57 -0
  134. package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
  135. package/lib/node/screen-share/rfb-protocol.js +39 -0
  136. package/lib/node/screen-share/rfb-reader.d.ts +35 -0
  137. package/lib/node/screen-share/rfb-reader.js +115 -0
  138. package/lib/node/screen-share/rfb-security.d.ts +31 -0
  139. package/lib/node/screen-share/rfb-security.js +141 -0
  140. package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
  141. package/lib/node/screen-share/rfb-test-server.js +120 -0
  142. package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
  143. package/lib/node/screen-share/screen-share-server-impl.js +79 -0
  144. package/lib/node/screen-share/screen-shares.d.ts +124 -0
  145. package/lib/node/screen-share/screen-shares.js +464 -0
  146. package/lib/node/session-info-util.d.ts +10 -9
  147. package/lib/node/session-info-util.js +15 -67
  148. package/lib/node/settings-store.d.ts +1 -1
  149. package/lib/node/settings-store.js +6 -3
  150. package/lib/node/sign-in/access-store.d.ts +1 -1
  151. package/lib/node/sign-in/access-store.js +4 -1
  152. package/lib/node/sign-in/index.d.ts +2 -0
  153. package/lib/node/sign-in/index.js +2 -0
  154. package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
  155. package/lib/node/sign-in/polled-sign-in.js +87 -0
  156. package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
  157. package/lib/node/sign-in/sign-in-devices.js +117 -0
  158. package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
  159. package/lib/node/sign-in/sign-in-flow.js +80 -5
  160. package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
  161. package/lib/node/sign-in/sign-in-pages.js +136 -7
  162. package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
  163. package/lib/node/sign-in/sign-in-provider.js +15 -0
  164. package/lib/node/sources-extension.d.ts +11 -0
  165. package/lib/node/sources-extension.js +22 -0
  166. package/lib/node/ta-server-impl.d.ts +5 -1
  167. package/lib/node/ta-server-impl.js +24 -2
  168. package/lib/node/ta-session-factory.d.ts +13 -1
  169. package/lib/node/ta-session-factory.js +40 -3
  170. package/lib/node/ta-session.d.ts +2 -0
  171. package/lib/node/ta-session.js +1 -0
  172. package/lib/node/team/team-calls.js +49 -0
  173. package/lib/node/voice-bridge.d.ts +71 -0
  174. package/lib/node/voice-bridge.js +281 -0
  175. package/lib/node/voices-file.d.ts +39 -0
  176. package/lib/node/voices-file.js +104 -0
  177. package/lib/node/working-directory.d.ts +8 -2
  178. package/lib/node/working-directory.js +7 -0
  179. package/package.json +14 -10
@@ -0,0 +1,38 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.TaCredentials = void 0;
10
+ const core_1 = require("@celljs/core");
11
+ /**
12
+ * The store of the sign-ins Ta gives by itself (TaExtensionHost.credentials): a package registers it (the vault of
13
+ * ta-secrets); without one, nothing is kept and every sign-in is asked.
14
+ */
15
+ let TaCredentials = class TaCredentials {
16
+ constructor() {
17
+ /** For the server side of packages (TaExtensionHost.credentials). */
18
+ this.extension = {
19
+ register: store => {
20
+ this.registered = store;
21
+ return () => {
22
+ if (this.registered === store) {
23
+ this.registered = undefined;
24
+ }
25
+ };
26
+ },
27
+ };
28
+ }
29
+ /** The store there is now; undefined while no package keeps sign-ins. */
30
+ get store() {
31
+ return this.registered;
32
+ }
33
+ };
34
+ exports.TaCredentials = TaCredentials;
35
+ exports.TaCredentials = TaCredentials = __decorate([
36
+ (0, core_1.Component)()
37
+ ], TaCredentials);
38
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1,12 @@
1
+ import type { ExtensionAPI, TaExtension } from '@celljs/ta-harness';
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 declare class DelegateExtension implements TaExtension {
9
+ readonly name = "ta-delegate";
10
+ register(pi: ExtensionAPI): void;
11
+ }
12
+ //# sourceMappingURL=delegate-extension.d.ts.map
@@ -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
@@ -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;
@@ -1,6 +1,9 @@
1
+ export * from './app-commands';
1
2
  export * from './auth-server-impl';
2
3
  export * from './client-channel';
3
4
  export * from './client-tool-broker';
5
+ export * from './credentials';
6
+ export * from './directory-relocator';
4
7
  export * from './event-log';
5
8
  export * from './exec-endpoint';
6
9
  export * from './exec-environment-factory';
@@ -13,6 +16,8 @@ export * from './keep-awake';
13
16
  export * from './package-host-extension';
14
17
  export * from './package-hosts';
15
18
  export * from './package-server-impl';
19
+ export * from './package-webhooks';
20
+ export * from './page-book';
16
21
  export * from './presence-book';
17
22
  export * from './presence-server-impl';
18
23
  export * from './receipt-book';
@@ -20,6 +25,7 @@ export * from './relay-bridge';
20
25
  export * from './remote';
21
26
  export * from './remote-ui-context';
22
27
  export * from './rooms-bridge';
28
+ export * from './screen-share';
23
29
  export * from './serve-updates';
24
30
  export * from './session-catalog';
25
31
  export * from './session-files';
@@ -44,6 +50,8 @@ export * from './terminal-protocol';
44
50
  export * from './terminal-service';
45
51
  export * from './terminal-util';
46
52
  export * from './usage';
53
+ export * from './voice-bridge';
54
+ export * from './voices-file';
47
55
  export * from './web-extension-catalog';
48
56
  export * from './web-extension-util';
49
57
  export * from './working-directory';
package/lib/node/index.js CHANGED
@@ -14,9 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./app-commands"), exports);
17
18
  __exportStar(require("./auth-server-impl"), exports);
18
19
  __exportStar(require("./client-channel"), exports);
19
20
  __exportStar(require("./client-tool-broker"), exports);
21
+ __exportStar(require("./credentials"), exports);
22
+ __exportStar(require("./directory-relocator"), exports);
20
23
  __exportStar(require("./event-log"), exports);
21
24
  __exportStar(require("./exec-endpoint"), exports);
22
25
  __exportStar(require("./exec-environment-factory"), exports);
@@ -29,6 +32,8 @@ __exportStar(require("./keep-awake"), exports);
29
32
  __exportStar(require("./package-host-extension"), exports);
30
33
  __exportStar(require("./package-hosts"), exports);
31
34
  __exportStar(require("./package-server-impl"), exports);
35
+ __exportStar(require("./package-webhooks"), exports);
36
+ __exportStar(require("./page-book"), exports);
32
37
  __exportStar(require("./presence-book"), exports);
33
38
  __exportStar(require("./presence-server-impl"), exports);
34
39
  __exportStar(require("./receipt-book"), exports);
@@ -36,6 +41,7 @@ __exportStar(require("./relay-bridge"), exports);
36
41
  __exportStar(require("./remote"), exports);
37
42
  __exportStar(require("./remote-ui-context"), exports);
38
43
  __exportStar(require("./rooms-bridge"), exports);
44
+ __exportStar(require("./screen-share"), exports);
39
45
  __exportStar(require("./serve-updates"), exports);
40
46
  __exportStar(require("./session-catalog"), exports);
41
47
  __exportStar(require("./session-files"), exports);
@@ -60,6 +66,8 @@ __exportStar(require("./terminal-protocol"), exports);
60
66
  __exportStar(require("./terminal-service"), exports);
61
67
  __exportStar(require("./terminal-util"), exports);
62
68
  __exportStar(require("./usage"), exports);
69
+ __exportStar(require("./voice-bridge"), exports);
70
+ __exportStar(require("./voices-file"), exports);
63
71
  __exportStar(require("./web-extension-catalog"), exports);
64
72
  __exportStar(require("./web-extension-util"), exports);
65
73
  __exportStar(require("./working-directory"), exports);
@@ -2,6 +2,7 @@ import { type ChildProcess } from 'node:child_process';
2
2
  import { type Application, ApplicationLifecycle } from '@celljs/core';
3
3
  import { KeepAwake, TaSessionRegistry } from './host-protocol';
4
4
  import { type RelayBridge } from './relay-bridge';
5
+ import { ScreenShares } from './screen-share/screen-shares';
5
6
  /** What KeepAwakeUtil.wanted weighs. */
6
7
  export interface KeepAwakeState {
7
8
  /** Not turned off (RelayConfig.keepAwake). */
@@ -22,12 +23,16 @@ export declare namespace KeepAwakeUtil {
22
23
  /**
23
24
  * Keeps the computer from sleeping while idle as long as a session runs or a paired device was connected of
24
25
  * late: asleep, ta serve answers no phone, and a phone that cannot reach it cannot wake it. It holds
25
- * `caffeinate -i` (idle sleep only: the display sleeps, a closed lid sleeps), which ends with ta serve.
26
+ * `caffeinate -i -s`, which ends with ta serve: idle sleep, and on power any sleep but of a closed lid, since a Mac
27
+ * that slept wakes only in the dark for minutes, where an assertion of idle sleep does not keep it; the display
28
+ * still sleeps. Stopping while it held it, it leaves one of BRIDGE_S, for the Ta that starts after.
26
29
  * Turned off in relay.json (TaRelayServer.setKeepAwake); nothing where it is not supported.
27
30
  */
28
31
  export declare class KeepAwakeImpl implements KeepAwake, ApplicationLifecycle<Application> {
29
32
  protected readonly bridge: RelayBridge;
30
33
  protected readonly sessions: TaSessionRegistry;
34
+ /** A page looking at a desktop keeps the computer awake as a session that runs does. */
35
+ protected readonly desktops: ScreenShares;
31
36
  protected deviceAt: number;
32
37
  protected timer?: ReturnType<typeof setInterval>;
33
38
  protected child?: ChildProcess;
@@ -41,5 +46,7 @@ export declare class KeepAwakeImpl implements KeepAwake, ApplicationLifecycle<Ap
41
46
  protected release(): void;
42
47
  /** `-w`: it ends when this process does, killed too. */
43
48
  protected spawn(): ChildProcess;
49
+ /** Awake for a while after this process, on its own. */
50
+ protected spawnBridge(): ChildProcess;
44
51
  }
45
52
  //# sourceMappingURL=keep-awake.d.ts.map