@celljs/ta-host 4.12.0 → 4.13.1

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 (129) hide show
  1. package/README.en.md +3 -2
  2. package/README.md +3 -2
  3. package/esm/node/extension-data-notifier.d.ts +3 -0
  4. package/esm/node/extension-data-notifier.js +8 -2
  5. package/esm/node/extension-providers.js +1 -1
  6. package/esm/node/host-protocol.d.ts +20 -1
  7. package/esm/node/host-protocol.js +1 -0
  8. package/esm/node/index.d.ts +3 -0
  9. package/esm/node/index.js +3 -0
  10. package/esm/node/keep-awake.d.ts +44 -0
  11. package/esm/node/keep-awake.js +112 -0
  12. package/esm/node/package-host-extension.js +2 -0
  13. package/esm/node/package-hosts.d.ts +23 -1
  14. package/esm/node/package-hosts.js +61 -3
  15. package/esm/node/relay-bridge.d.ts +37 -3
  16. package/esm/node/relay-bridge.js +271 -10
  17. package/esm/node/rooms-bridge.d.ts +13 -2
  18. package/esm/node/rooms-bridge.js +34 -4
  19. package/esm/node/session-catalog.d.ts +1 -1
  20. package/esm/node/session-catalog.js +5 -0
  21. package/esm/node/session-list-feed.d.ts +11 -1
  22. package/esm/node/session-list-feed.js +17 -3
  23. package/esm/node/session-resume.d.ts +52 -0
  24. package/esm/node/session-resume.js +174 -0
  25. package/esm/node/settings-store.d.ts +3 -0
  26. package/esm/node/settings-store.js +22 -0
  27. package/esm/node/ta-errors.d.ts +1 -0
  28. package/esm/node/ta-errors.js +4 -0
  29. package/esm/node/ta-server-impl.d.ts +9 -0
  30. package/esm/node/ta-server-impl.js +52 -7
  31. package/esm/node/ta-session-factory.js +5 -2
  32. package/esm/node/ta-session-registry.d.ts +12 -1
  33. package/esm/node/ta-session-registry.js +30 -1
  34. package/esm/node/ta-session.d.ts +3 -0
  35. package/esm/node/ta-session.js +16 -0
  36. package/esm/node/team/authority.d.ts +19 -0
  37. package/esm/node/team/authority.js +79 -0
  38. package/esm/node/team/call-util.d.ts +23 -0
  39. package/esm/node/team/call-util.js +88 -0
  40. package/esm/node/team/connections.d.ts +15 -0
  41. package/esm/node/team/connections.js +81 -0
  42. package/esm/node/team/host-team.d.ts +13 -0
  43. package/esm/node/team/host-team.js +69 -0
  44. package/esm/node/team/index.d.ts +13 -0
  45. package/esm/node/team/index.js +14 -0
  46. package/esm/node/team/member-devices.d.ts +11 -0
  47. package/esm/node/team/member-devices.js +56 -0
  48. package/esm/node/team/package-permissions.d.ts +23 -0
  49. package/esm/node/team/package-permissions.js +75 -0
  50. package/esm/node/team/principals.d.ts +22 -0
  51. package/esm/node/team/principals.js +72 -0
  52. package/esm/node/team/run-actors.d.ts +21 -0
  53. package/esm/node/team/run-actors.js +100 -0
  54. package/esm/node/team/shared-data.d.ts +18 -0
  55. package/esm/node/team/shared-data.js +55 -0
  56. package/esm/node/team/team-calls.d.ts +33 -0
  57. package/esm/node/team/team-calls.js +266 -0
  58. package/esm/node/team/team-gate.d.ts +31 -0
  59. package/esm/node/team/team-gate.js +177 -0
  60. package/esm/node/team/team-protocol.d.ts +89 -0
  61. package/esm/node/team/team-protocol.js +27 -0
  62. package/esm/node/team/visibility.d.ts +13 -0
  63. package/esm/node/team/visibility.js +50 -0
  64. package/esm/node/terminal-service.d.ts +5 -0
  65. package/esm/node/terminal-service.js +11 -2
  66. package/lib/node/extension-data-notifier.d.ts +3 -0
  67. package/lib/node/extension-data-notifier.js +8 -2
  68. package/lib/node/extension-providers.js +1 -1
  69. package/lib/node/host-protocol.d.ts +20 -1
  70. package/lib/node/host-protocol.js +2 -1
  71. package/lib/node/index.d.ts +3 -0
  72. package/lib/node/index.js +3 -0
  73. package/lib/node/keep-awake.d.ts +45 -0
  74. package/lib/node/keep-awake.js +115 -0
  75. package/lib/node/package-host-extension.js +2 -0
  76. package/lib/node/package-hosts.d.ts +23 -1
  77. package/lib/node/package-hosts.js +60 -2
  78. package/lib/node/relay-bridge.d.ts +37 -3
  79. package/lib/node/relay-bridge.js +269 -8
  80. package/lib/node/rooms-bridge.d.ts +13 -2
  81. package/lib/node/rooms-bridge.js +34 -4
  82. package/lib/node/session-catalog.d.ts +1 -1
  83. package/lib/node/session-catalog.js +5 -0
  84. package/lib/node/session-list-feed.d.ts +11 -1
  85. package/lib/node/session-list-feed.js +17 -3
  86. package/lib/node/session-resume.d.ts +53 -0
  87. package/lib/node/session-resume.js +177 -0
  88. package/lib/node/settings-store.d.ts +3 -0
  89. package/lib/node/settings-store.js +22 -0
  90. package/lib/node/ta-errors.d.ts +1 -0
  91. package/lib/node/ta-errors.js +4 -0
  92. package/lib/node/ta-server-impl.d.ts +9 -0
  93. package/lib/node/ta-server-impl.js +52 -7
  94. package/lib/node/ta-session-factory.js +4 -1
  95. package/lib/node/ta-session-registry.d.ts +12 -1
  96. package/lib/node/ta-session-registry.js +30 -1
  97. package/lib/node/ta-session.d.ts +3 -0
  98. package/lib/node/ta-session.js +16 -0
  99. package/lib/node/team/authority.d.ts +20 -0
  100. package/lib/node/team/authority.js +82 -0
  101. package/lib/node/team/call-util.d.ts +24 -0
  102. package/lib/node/team/call-util.js +91 -0
  103. package/lib/node/team/connections.d.ts +16 -0
  104. package/lib/node/team/connections.js +84 -0
  105. package/lib/node/team/host-team.d.ts +14 -0
  106. package/lib/node/team/host-team.js +72 -0
  107. package/lib/node/team/index.d.ts +14 -0
  108. package/lib/node/team/index.js +30 -0
  109. package/lib/node/team/member-devices.d.ts +12 -0
  110. package/lib/node/team/member-devices.js +59 -0
  111. package/lib/node/team/package-permissions.d.ts +24 -0
  112. package/lib/node/team/package-permissions.js +78 -0
  113. package/lib/node/team/principals.d.ts +23 -0
  114. package/lib/node/team/principals.js +75 -0
  115. package/lib/node/team/run-actors.d.ts +22 -0
  116. package/lib/node/team/run-actors.js +103 -0
  117. package/lib/node/team/shared-data.d.ts +19 -0
  118. package/lib/node/team/shared-data.js +58 -0
  119. package/lib/node/team/team-calls.d.ts +34 -0
  120. package/lib/node/team/team-calls.js +270 -0
  121. package/lib/node/team/team-gate.d.ts +32 -0
  122. package/lib/node/team/team-gate.js +180 -0
  123. package/lib/node/team/team-protocol.d.ts +90 -0
  124. package/lib/node/team/team-protocol.js +30 -0
  125. package/lib/node/team/visibility.d.ts +14 -0
  126. package/lib/node/team/visibility.js +53 -0
  127. package/lib/node/terminal-service.d.ts +5 -0
  128. package/lib/node/terminal-service.js +11 -2
  129. package/package.json +14 -10
@@ -2,6 +2,7 @@ import { type Application, ApplicationLifecycle } from '@celljs/core';
2
2
  import type { RpcConnection } from '@celljs/rpc/lib/node';
3
3
  import { type ExecEnvironment, ExecEnvironmentFactory, type ExecProcess } from '@celljs/ta-exec';
4
4
  import { type TaOpenTerminalOptions, type TaTerminalInfo } from '@celljs/ta-protocol';
5
+ import { TaPrincipals } from './team/team-protocol.js';
5
6
  import { TaTerminals } from './terminal-protocol.js';
6
7
  import { PipeDiscipline, type TerminalPlatform, TtyMarker } from './terminal-util.js';
7
8
  /** How long a shell waits for a connection after its own dropped. */
@@ -12,6 +13,8 @@ declare class Terminal {
12
13
  readonly platform: TerminalPlatform;
13
14
  readonly process: ExecProcess;
14
15
  owner?: RpcConnection;
16
+ /** Who opened it (TaTerminals.whoOf): only a connection of the same takes it once its own dropped. */
17
+ principal: string;
15
18
  orphanTimer?: ReturnType<typeof setTimeout>;
16
19
  pending: string;
17
20
  /** The last output, for a page that takes the shell again after its own went (a reload). */
@@ -41,6 +44,8 @@ export declare class DefaultTaTerminals implements TaTerminals, ApplicationLifec
41
44
  /** By machine: `''` for this one (or the exec server), else the host of `ssh://`. */
42
45
  protected readonly platforms: Map<string, Promise<TerminalPlatform>>;
43
46
  protected nextId: number;
47
+ /** Who makes the calls of a connection: one let in takes no shell of the user's (docs/design/ta-team.md). */
48
+ protected readonly principals: TaPrincipals;
44
49
  open(connection: RpcConnection, options: TaOpenTerminalOptions & {
45
50
  cwd: string;
46
51
  }): Promise<TaTerminalInfo>;
@@ -13,6 +13,7 @@ import { ApplicationLifecycle, Autowired, Component } from '@celljs/core';
13
13
  import { ExecEnvironmentFactory } from '@celljs/ta-exec';
14
14
  import { TaClient, TaLocation } from '@celljs/ta-protocol';
15
15
  import { TaErrors } from './ta-errors.js';
16
+ import { TaPrincipals } from './team/team-protocol.js';
16
17
  import { TaTerminals } from './terminal-protocol.js';
17
18
  import { PipeDiscipline, TerminalUtil, TtyMarker } from './terminal-util.js';
18
19
  /** How long a shell waits for a connection after its own dropped. */
@@ -29,6 +30,8 @@ class Terminal {
29
30
  this.env = env;
30
31
  this.platform = platform;
31
32
  this.process = process;
33
+ /** Who opened it (TaTerminals.whoOf): only a connection of the same takes it once its own dropped. */
34
+ this.principal = 'owner';
32
35
  this.pending = '';
33
36
  /** The last output, for a page that takes the shell again after its own went (a reload). */
34
37
  this.history = '';
@@ -62,6 +65,7 @@ let DefaultTaTerminals = class DefaultTaTerminals {
62
65
  // `pty`: false when the shell runs on pipes, so that the view can say why some programs behave otherwise.
63
66
  const info = { terminalId: `t${++this.nextId}`, cwd: options.cwd, shell: platform.shell, pty: launch.pty };
64
67
  const terminal = new Terminal(info, env, platform, env.spawn(launch.command, launch.args), launch.pty, connection);
68
+ terminal.principal = this.principals.of(connection);
65
69
  this.terminals.set(info.terminalId, terminal);
66
70
  this.watch(connection);
67
71
  const receive = (data) => this.output(terminal, terminal.decoder.decode(data, { stream: true }));
@@ -99,8 +103,9 @@ let DefaultTaTerminals = class DefaultTaTerminals {
99
103
  }
100
104
  list(connection) {
101
105
  const own = [];
106
+ const who = this.principals.of(connection);
102
107
  for (const terminal of this.terminals.values()) {
103
- if (!terminal.owner) {
108
+ if (!terminal.owner && terminal.principal === who) {
104
109
  this.adopt(terminal, connection);
105
110
  }
106
111
  if (terminal.owner === connection) {
@@ -118,7 +123,7 @@ let DefaultTaTerminals = class DefaultTaTerminals {
118
123
  /** The shell of this connection, or one nobody has: it becomes this connection's. */
119
124
  require(connection, terminalId) {
120
125
  const terminal = this.terminals.get(terminalId);
121
- if (!terminal || (terminal.owner && terminal.owner !== connection)) {
126
+ if (!terminal || (terminal.owner && terminal.owner !== connection) || (!terminal.owner && terminal.principal !== this.principals.of(connection))) {
122
127
  throw TaErrors.invalidArgument(`No terminal of this connection has the id ${terminalId}.`, 'Open one with openTerminal; listTerminals has those still open.');
123
128
  }
124
129
  if (!terminal.owner) {
@@ -269,6 +274,10 @@ __decorate([
269
274
  Autowired(ExecEnvironmentFactory),
270
275
  __metadata("design:type", Object)
271
276
  ], DefaultTaTerminals.prototype, "environments", void 0);
277
+ __decorate([
278
+ Autowired({ id: TaPrincipals, detached: true }),
279
+ __metadata("design:type", Object)
280
+ ], DefaultTaTerminals.prototype, "principals", void 0);
272
281
  DefaultTaTerminals = __decorate([
273
282
  Component([TaTerminals, ApplicationLifecycle])
274
283
  ], DefaultTaTerminals);
@@ -1,5 +1,6 @@
1
1
  import type { RpcConnection } from '@celljs/rpc/lib/node';
2
2
  import { ExtensionDataStore } from './extension-data';
3
+ import { TaVisibility } from './team/team-protocol';
3
4
  export declare const ExtensionDataNotifier: unique symbol;
4
5
  /** Tells the clients which keys of the data of packages changed (TaClient.onExtensionData). */
5
6
  export interface ExtensionDataNotifier {
@@ -33,6 +34,8 @@ export declare class ExtensionDataNotifierImpl implements ExtensionDataNotifier
33
34
  protected readonly store: ExtensionDataStore;
34
35
  protected readonly watchers: Map<RpcConnection, Watcher>;
35
36
  protected unsubscribe?: () => void;
37
+ /** The package each connection is told of (docs/design/ta-team.md): those let in keep data of their own under another name. */
38
+ protected readonly visibility: TaVisibility;
36
39
  watch(connection: RpcConnection, name: string, cwd?: string): void;
37
40
  protected changed(name: string, key: string, cwd?: string): void;
38
41
  /** The first change leaves at once; the next ones wait for the rest of the interval. */
@@ -13,6 +13,7 @@ exports.ExtensionDataNotifierImpl = exports.ExtensionDataBatch = exports.Extensi
13
13
  const core_1 = require("@celljs/core");
14
14
  const ta_protocol_1 = require("@celljs/ta-protocol");
15
15
  const extension_data_1 = require("./extension-data");
16
+ const team_protocol_1 = require("./team/team-protocol");
16
17
  exports.ExtensionDataNotifier = Symbol('ExtensionDataNotifier');
17
18
  /** At most one notice per connection in this time, with the keys that changed meanwhile. */
18
19
  const NOTICE_MS = 250;
@@ -87,8 +88,9 @@ let ExtensionDataNotifierImpl = class ExtensionDataNotifierImpl {
87
88
  changed(name, key, cwd) {
88
89
  const scope = ExtensionDataScope.of(name, cwd);
89
90
  for (const [connection, watcher] of this.watchers) {
90
- if (watcher.scopes.has(scope)) {
91
- watcher.batch.add(name, key, cwd);
91
+ const told = watcher.scopes.has(scope) ? this.visibility.dataName(connection, name, key) : undefined;
92
+ if (told !== undefined) {
93
+ watcher.batch.add(told, key, cwd);
92
94
  this.schedule(connection, watcher);
93
95
  }
94
96
  }
@@ -117,6 +119,10 @@ __decorate([
117
119
  (0, core_1.Autowired)(extension_data_1.ExtensionDataStore),
118
120
  __metadata("design:type", Object)
119
121
  ], ExtensionDataNotifierImpl.prototype, "store", void 0);
122
+ __decorate([
123
+ (0, core_1.Autowired)({ id: team_protocol_1.TaVisibility, detached: true }),
124
+ __metadata("design:type", Object)
125
+ ], ExtensionDataNotifierImpl.prototype, "visibility", void 0);
120
126
  exports.ExtensionDataNotifierImpl = ExtensionDataNotifierImpl = __decorate([
121
127
  (0, core_1.Component)(exports.ExtensionDataNotifier)
122
128
  ], ExtensionDataNotifierImpl);
@@ -36,7 +36,7 @@ let ExtensionProvidersImpl = class ExtensionProvidersImpl {
36
36
  agentDir,
37
37
  settingsManager: sdk.SettingsManager.create(cwd, agentDir, { projectTrusted: false }),
38
38
  modelRuntime: await this.modelRuntimeProvider.provide(),
39
- resourceLoaderOptions: ta_harness_1.TaPackages.loaderOptions(agentDir),
39
+ resourceLoaderOptions: ta_harness_1.TaPackages.loaderOptions(agentDir, { loadSkills: sdk.loadSkillsFromDir }),
40
40
  });
41
41
  }
42
42
  };
@@ -1,11 +1,12 @@
1
1
  import type { RpcConnection } from '@celljs/rpc/lib/node';
2
- import type { TaOpenSessionOptions, TaPackageInfo, TaSavedSessionInfo, TaSavedSessionQuery, TaSessionInfo, TaSettingsScope, TaSlashCommand, TaTemporaryFrom, TaWebExtensionInfo, TaWebExtensionSource } from '@celljs/ta-protocol';
2
+ import type { TaEvent, TaOpenSessionOptions, TaPackageInfo, TaSavedSessionInfo, TaSavedSessionQuery, TaSessionInfo, TaSettingsScope, TaSlashCommand, TaTemporaryFrom, TaWebExtensionInfo, TaWebExtensionSource } from '@celljs/ta-protocol';
3
3
  import type { ClientChannel } from './client-channel';
4
4
  import type { TaSession } from './ta-session';
5
5
  export declare const TaSessionFactory: unique symbol;
6
6
  export declare const TaSessionRegistry: unique symbol;
7
7
  export declare const TaSessionCatalog: unique symbol;
8
8
  export declare const WebExtensionCatalog: unique symbol;
9
+ export declare const KeepAwake: unique symbol;
9
10
  export declare const TA_HOST_OPTIONS = "ta.host";
10
11
  export declare const TA_EXEC_OPTIONS = "ta.exec";
11
12
  /** `ta.host`. */
@@ -50,6 +51,17 @@ export interface TaSessionRegistry {
50
51
  /** As the service stops: each keeps its id, and opens again when called after the restart. */
51
52
  closeAll(): Promise<void>;
52
53
  channel(connection: RpcConnection): ClientChannel;
54
+ /** Every event of every open session, as it comes. */
55
+ onSessionEvent(listener: (session: TaSession, event: TaEvent) => void): () => void;
56
+ /** The connections watching the list of sessions now: the pages of Ta open, on any device. */
57
+ readonly watching: number;
58
+ /** `Date.now()` time a page last watched, now while one does; 0 for never. */
59
+ readonly watchedAt: number;
60
+ /** The file and the directory of a session by its id, open or closed while idle; undefined for one not known. */
61
+ locate(sessionId: string): {
62
+ sessionFile?: string;
63
+ cwd: string;
64
+ } | undefined;
53
65
  }
54
66
  /** The conversations pi keeps in its session files, open or not. */
55
67
  export interface TaSessionCatalog {
@@ -88,4 +100,11 @@ export interface WebExtensionCatalog {
88
100
  readonly temporaryRetention: number;
89
101
  setTemporaryRetention(days: number): void;
90
102
  }
103
+ /** Keeps the computer from sleeping while idle for the devices that reach it (KeepAwakeImpl). */
104
+ export interface KeepAwake {
105
+ /** Whether this computer can be kept awake: only macOS. */
106
+ readonly supported: boolean;
107
+ /** Holds or lets go as things are now: at once after the setting changed. */
108
+ check(): void;
109
+ }
91
110
  //# sourceMappingURL=host-protocol.d.ts.map
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TA_EXEC_OPTIONS = exports.TA_HOST_OPTIONS = exports.WebExtensionCatalog = exports.TaSessionCatalog = exports.TaSessionRegistry = exports.TaSessionFactory = void 0;
3
+ exports.TA_EXEC_OPTIONS = exports.TA_HOST_OPTIONS = exports.KeepAwake = exports.WebExtensionCatalog = exports.TaSessionCatalog = exports.TaSessionRegistry = exports.TaSessionFactory = void 0;
4
4
  exports.TaSessionFactory = Symbol('TaSessionFactory');
5
5
  exports.TaSessionRegistry = Symbol('TaSessionRegistry');
6
6
  exports.TaSessionCatalog = Symbol('TaSessionCatalog');
7
7
  exports.WebExtensionCatalog = Symbol('WebExtensionCatalog');
8
+ exports.KeepAwake = Symbol('KeepAwake');
8
9
  exports.TA_HOST_OPTIONS = 'ta.host';
9
10
  exports.TA_EXEC_OPTIONS = 'ta.exec';
10
11
  //# sourceMappingURL=host-protocol.js.map
@@ -7,6 +7,7 @@ export * from './extension-data';
7
7
  export * from './extension-data-notifier';
8
8
  export * from './extension-providers';
9
9
  export * from './host-protocol';
10
+ export * from './keep-awake';
10
11
  export * from './package-host-extension';
11
12
  export * from './package-hosts';
12
13
  export * from './package-server-impl';
@@ -19,6 +20,7 @@ export * from './session-catalog';
19
20
  export * from './session-files';
20
21
  export * from './session-handles';
21
22
  export * from './session-info-util';
23
+ export * from './session-resume';
22
24
  export * from './session-storage';
23
25
  export * from './settings-server-impl';
24
26
  export * from './settings-store';
@@ -30,6 +32,7 @@ export * from './ta-server-impl';
30
32
  export * from './ta-session';
31
33
  export * from './ta-session-factory';
32
34
  export * from './ta-session-registry';
35
+ export * from './team';
33
36
  export * from './temporary-packages';
34
37
  export * from './temporary-purge';
35
38
  export * from './terminal-protocol';
package/lib/node/index.js CHANGED
@@ -23,6 +23,7 @@ __exportStar(require("./extension-data"), exports);
23
23
  __exportStar(require("./extension-data-notifier"), exports);
24
24
  __exportStar(require("./extension-providers"), exports);
25
25
  __exportStar(require("./host-protocol"), exports);
26
+ __exportStar(require("./keep-awake"), exports);
26
27
  __exportStar(require("./package-host-extension"), exports);
27
28
  __exportStar(require("./package-hosts"), exports);
28
29
  __exportStar(require("./package-server-impl"), exports);
@@ -35,6 +36,7 @@ __exportStar(require("./session-catalog"), exports);
35
36
  __exportStar(require("./session-files"), exports);
36
37
  __exportStar(require("./session-handles"), exports);
37
38
  __exportStar(require("./session-info-util"), exports);
39
+ __exportStar(require("./session-resume"), exports);
38
40
  __exportStar(require("./session-storage"), exports);
39
41
  __exportStar(require("./settings-server-impl"), exports);
40
42
  __exportStar(require("./settings-store"), exports);
@@ -46,6 +48,7 @@ __exportStar(require("./ta-server-impl"), exports);
46
48
  __exportStar(require("./ta-session"), exports);
47
49
  __exportStar(require("./ta-session-factory"), exports);
48
50
  __exportStar(require("./ta-session-registry"), exports);
51
+ __exportStar(require("./team"), exports);
49
52
  __exportStar(require("./temporary-packages"), exports);
50
53
  __exportStar(require("./temporary-purge"), exports);
51
54
  __exportStar(require("./terminal-protocol"), exports);
@@ -0,0 +1,45 @@
1
+ import { type ChildProcess } from 'node:child_process';
2
+ import { type Application, ApplicationLifecycle } from '@celljs/core';
3
+ import { KeepAwake, TaSessionRegistry } from './host-protocol';
4
+ import { type RelayBridge } from './relay-bridge';
5
+ /** What KeepAwakeUtil.wanted weighs. */
6
+ export interface KeepAwakeState {
7
+ /** Not turned off (RelayConfig.keepAwake). */
8
+ enabled: boolean;
9
+ /** A session is answering. */
10
+ running: boolean;
11
+ /** When a paired device was last seen connected, 0 for never. */
12
+ deviceAt: number;
13
+ now: number;
14
+ }
15
+ export declare namespace KeepAwakeUtil {
16
+ /** How long after a device left the computer stays awake: a phone put away a while comes back to a Ta that answers. */
17
+ const DEVICE_GRACE_MS: number;
18
+ /** Only macOS: `caffeinate` holds the assertion of the system, and lets it go when ta serve exits. */
19
+ function supported(platform?: string): boolean;
20
+ function wanted(state: KeepAwakeState): boolean;
21
+ }
22
+ /**
23
+ * Keeps the computer from sleeping while idle as long as a session runs or a paired device was connected of
24
+ * 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
+ * Turned off in relay.json (TaRelayServer.setKeepAwake); nothing where it is not supported.
27
+ */
28
+ export declare class KeepAwakeImpl implements KeepAwake, ApplicationLifecycle<Application> {
29
+ protected readonly bridge: RelayBridge;
30
+ protected readonly sessions: TaSessionRegistry;
31
+ protected deviceAt: number;
32
+ protected timer?: ReturnType<typeof setInterval>;
33
+ protected child?: ChildProcess;
34
+ get supported(): boolean;
35
+ /** Whether the computer is kept awake now. */
36
+ get held(): boolean;
37
+ onStart(): void;
38
+ onStop(): void;
39
+ check(now?: number): void;
40
+ protected hold(): void;
41
+ protected release(): void;
42
+ /** `-w`: it ends when this process does, killed too. */
43
+ protected spawn(): ChildProcess;
44
+ }
45
+ //# sourceMappingURL=keep-awake.d.ts.map
@@ -0,0 +1,115 @@
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.KeepAwakeImpl = exports.KeepAwakeUtil = void 0;
13
+ const node_child_process_1 = require("node:child_process");
14
+ const core_1 = require("@celljs/core");
15
+ const host_protocol_1 = require("./host-protocol");
16
+ const relay_bridge_1 = require("./relay-bridge");
17
+ var KeepAwakeUtil;
18
+ (function (KeepAwakeUtil) {
19
+ /** How long after a device left the computer stays awake: a phone put away a while comes back to a Ta that answers. */
20
+ KeepAwakeUtil.DEVICE_GRACE_MS = 30 * 60000;
21
+ /** Only macOS: `caffeinate` holds the assertion of the system, and lets it go when ta serve exits. */
22
+ function supported(platform = process.platform) {
23
+ return platform === 'darwin';
24
+ }
25
+ KeepAwakeUtil.supported = supported;
26
+ function wanted(state) {
27
+ return state.enabled && (state.running || (state.deviceAt > 0 && state.now - state.deviceAt < KeepAwakeUtil.DEVICE_GRACE_MS));
28
+ }
29
+ KeepAwakeUtil.wanted = wanted;
30
+ })(KeepAwakeUtil || (exports.KeepAwakeUtil = KeepAwakeUtil = {}));
31
+ /** How often what keeps the computer awake is looked at. */
32
+ const CHECK_MS = 15000;
33
+ /**
34
+ * Keeps the computer from sleeping while idle as long as a session runs or a paired device was connected of
35
+ * late: asleep, ta serve answers no phone, and a phone that cannot reach it cannot wake it. It holds
36
+ * `caffeinate -i` (idle sleep only: the display sleeps, a closed lid sleeps), which ends with ta serve.
37
+ * Turned off in relay.json (TaRelayServer.setKeepAwake); nothing where it is not supported.
38
+ */
39
+ let KeepAwakeImpl = class KeepAwakeImpl {
40
+ constructor() {
41
+ this.deviceAt = 0;
42
+ }
43
+ get supported() {
44
+ return KeepAwakeUtil.supported();
45
+ }
46
+ /** Whether the computer is kept awake now. */
47
+ get held() {
48
+ return this.child !== undefined;
49
+ }
50
+ onStart() {
51
+ var _a, _b;
52
+ if (!this.supported) {
53
+ return;
54
+ }
55
+ this.timer = setInterval(() => this.check(), CHECK_MS);
56
+ (_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
57
+ }
58
+ onStop() {
59
+ clearInterval(this.timer);
60
+ this.release();
61
+ }
62
+ check(now = Date.now()) {
63
+ if (!this.supported) {
64
+ return;
65
+ }
66
+ if (this.bridge.devicesOpen > 0) {
67
+ this.deviceAt = now;
68
+ }
69
+ const running = this.sessions.list().some(session => session.pi.isStreaming);
70
+ const enabled = this.bridge.store.read().keepAwake !== false;
71
+ if (KeepAwakeUtil.wanted({ enabled, running, deviceAt: this.deviceAt, now })) {
72
+ this.hold();
73
+ }
74
+ else {
75
+ this.release();
76
+ }
77
+ }
78
+ hold() {
79
+ if (this.child) {
80
+ return;
81
+ }
82
+ const child = this.spawn();
83
+ this.child = child;
84
+ const ended = () => {
85
+ if (this.child === child) {
86
+ this.child = undefined;
87
+ }
88
+ };
89
+ child.once('error', ended);
90
+ child.once('exit', ended);
91
+ child.unref();
92
+ }
93
+ release() {
94
+ const child = this.child;
95
+ this.child = undefined;
96
+ child === null || child === void 0 ? void 0 : child.kill();
97
+ }
98
+ /** `-w`: it ends when this process does, killed too. */
99
+ spawn() {
100
+ return (0, node_child_process_1.spawn)('/usr/bin/caffeinate', ['-i', '-w', String(process.pid)], { stdio: 'ignore' });
101
+ }
102
+ };
103
+ exports.KeepAwakeImpl = KeepAwakeImpl;
104
+ __decorate([
105
+ (0, core_1.Autowired)(relay_bridge_1.RELAY_BRIDGE),
106
+ __metadata("design:type", Function)
107
+ ], KeepAwakeImpl.prototype, "bridge", void 0);
108
+ __decorate([
109
+ (0, core_1.Autowired)(host_protocol_1.TaSessionRegistry),
110
+ __metadata("design:type", Object)
111
+ ], KeepAwakeImpl.prototype, "sessions", void 0);
112
+ exports.KeepAwakeImpl = KeepAwakeImpl = __decorate([
113
+ (0, core_1.Component)([host_protocol_1.KeepAwake, core_1.ApplicationLifecycle])
114
+ ], KeepAwakeImpl);
115
+ //# sourceMappingURL=keep-awake.js.map
@@ -11,9 +11,11 @@ class PackageHostExtension {
11
11
  }
12
12
  register(pi) {
13
13
  pi.events.on(ta_protocol_1.TA_HOST_EVENT, data => {
14
+ var _a;
14
15
  const request = data;
15
16
  if (typeof (request === null || request === void 0 ? void 0 : request.name) === 'string' && typeof request.resolve === 'function') {
16
17
  const resolve = request.resolve;
18
+ (_a = request.heard) === null || _a === void 0 ? void 0 : _a.call(request);
17
19
  void this.hosts.answer(request.name).then(answer => resolve({ ...answer, files: this.files }));
18
20
  }
19
21
  });
@@ -1,10 +1,13 @@
1
1
  import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
2
2
  import { type Application, ApplicationLifecycle } from '@celljs/core';
3
- import { type TaExtensionHost, type TaHostAnswer, TaPackageServer, type TaPackageService, TaServer } from '@celljs/ta-protocol';
3
+ import { type TaExtensionHost, type TaHostAnswer, type TaHostSessionEvent, TaPackageServer, type TaPackageService, TaServer } from '@celljs/ta-protocol';
4
4
  import { ExtensionDataStore } from './extension-data';
5
+ import { TaSessionRegistry } from './host-protocol';
5
6
  import { type RelayBridge } from './relay-bridge';
6
7
  import { PiDirectories } from './remote/remote-protocol';
7
8
  import { type RoomsBridge } from './rooms-bridge';
9
+ import { TaSettingsStore } from './settings-store';
10
+ import { TaHostTeamProvider } from './team/team-protocol';
8
11
  export declare const PackageHosts: unique symbol;
9
12
  /**
10
13
  * The server side of built-in packages under `ta serve`: the module a package names in `pi.host` of its
@@ -23,6 +26,20 @@ export interface PackageHosts {
23
26
  export declare namespace PackageHostUtil {
24
27
  /** The `cwd` of the header of a pi session file; undefined when it has none. */
25
28
  function sessionCwd(file: string): Promise<string | undefined>;
29
+ /** A turn starting or ending, of the events of a session (TaExtensionHost.onSessionEvent); undefined for any other event. */
30
+ function turnEvent(session: {
31
+ id: string;
32
+ cwd: string;
33
+ info(): {
34
+ sessionFile?: string;
35
+ group?: string;
36
+ };
37
+ pi: {
38
+ messages: readonly unknown[];
39
+ };
40
+ }, event: {
41
+ type: string;
42
+ }): TaHostSessionEvent | undefined;
26
43
  /** The file of `pi.host`, inside the package; undefined when it has none. */
27
44
  function entry(root: string): string | undefined;
28
45
  }
@@ -37,6 +54,9 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
37
54
  protected readonly packages: TaPackageServer;
38
55
  protected readonly relay: RelayBridge;
39
56
  protected readonly roomsBridge: RoomsBridge;
57
+ protected readonly settings: TaSettingsStore;
58
+ protected readonly sessions: TaSessionRegistry;
59
+ protected readonly teamProvider: TaHostTeamProvider;
40
60
  protected readonly running: Map<string, Running>;
41
61
  protected extensionHost?: TaExtensionHost;
42
62
  onStart(): Promise<void>;
@@ -46,6 +66,8 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
46
66
  call(name: string, method: string, params: unknown[]): Promise<unknown>;
47
67
  protected start(name: string, file: string): Running;
48
68
  protected stop(name: string): Promise<void>;
69
+ /** The host as one package has it: what it sends to a conversation as the user says it came from that package. */
70
+ protected hostOf(name: string): TaExtensionHost;
49
71
  protected host(): TaExtensionHost;
50
72
  protected sessionMessages(file: string): Promise<unknown[]>;
51
73
  protected createSession(cwd: string, messages: readonly unknown[], name?: string): Promise<string>;
@@ -20,10 +20,13 @@ const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
20
20
  const ta_packages_1 = require("@celljs/ta-harness/lib/node/ta-packages");
21
21
  const ta_protocol_1 = require("@celljs/ta-protocol");
22
22
  const extension_data_1 = require("./extension-data");
23
+ const host_protocol_1 = require("./host-protocol");
23
24
  const relay_bridge_1 = require("./relay-bridge");
24
25
  const remote_protocol_1 = require("./remote/remote-protocol");
25
26
  const rooms_bridge_1 = require("./rooms-bridge");
27
+ const settings_store_1 = require("./settings-store");
26
28
  const ta_errors_1 = require("./ta-errors");
29
+ const team_protocol_1 = require("./team/team-protocol");
27
30
  exports.PackageHosts = Symbol('PackageHosts');
28
31
  var PackageHostUtil;
29
32
  (function (PackageHostUtil) {
@@ -47,6 +50,25 @@ var PackageHostUtil;
47
50
  }
48
51
  }
49
52
  PackageHostUtil.sessionCwd = sessionCwd;
53
+ /** A turn starting or ending, of the events of a session (TaExtensionHost.onSessionEvent); undefined for any other event. */
54
+ function turnEvent(session, event) {
55
+ if (event.type !== 'agent_start' && event.type !== 'agent_settled') {
56
+ return undefined;
57
+ }
58
+ const { sessionFile, group } = session.info();
59
+ const base = { sessionId: session.id, cwd: session.cwd, ...(sessionFile ? { sessionFile } : {}), ...(group ? { group } : {}) };
60
+ if (event.type === 'agent_start') {
61
+ return { type: 'turn_start', ...base };
62
+ }
63
+ const last = [...session.pi.messages].reverse().find(message => message.role === 'assistant');
64
+ return {
65
+ type: 'turn_end',
66
+ ...base,
67
+ ...((last === null || last === void 0 ? void 0 : last.stopReason) === 'error' ? { error: last.errorMessage || 'The turn failed.' } : {}),
68
+ ...((last === null || last === void 0 ? void 0 : last.stopReason) === 'aborted' ? { aborted: true } : {}),
69
+ };
70
+ }
71
+ PackageHostUtil.turnEvent = turnEvent;
50
72
  /** The file of `pi.host`, inside the package; undefined when it has none. */
51
73
  function entry(root) {
52
74
  var _a, _b;
@@ -93,7 +115,7 @@ let PackageHostsImpl = class PackageHostsImpl {
93
115
  }
94
116
  async answer(name) {
95
117
  var _a;
96
- return { host: this.host(), service: await ((_a = this.running.get(name)) === null || _a === void 0 ? void 0 : _a.service) };
118
+ return { host: this.hostOf(name), service: await ((_a = this.running.get(name)) === null || _a === void 0 ? void 0 : _a.service) };
97
119
  }
98
120
  async call(name, method, params) {
99
121
  var _a;
@@ -121,7 +143,7 @@ let PackageHostsImpl = class PackageHostsImpl {
121
143
  try {
122
144
  const module = await import((0, node_url_1.pathToFileURL)(file).href);
123
145
  const factory = ((_a = module.default) !== null && _a !== void 0 ? _a : module);
124
- return (_b = (await factory(this.host()))) !== null && _b !== void 0 ? _b : undefined;
146
+ return (_b = (await factory(this.hostOf(name)))) !== null && _b !== void 0 ? _b : undefined;
125
147
  }
126
148
  catch (error) {
127
149
  console.error(`The host of ${name} failed: ${error instanceof Error ? error.message : error}`);
@@ -143,6 +165,16 @@ let PackageHostsImpl = class PackageHostsImpl {
143
165
  console.error(`The host of ${name} failed to stop: ${error instanceof Error ? error.message : error}`);
144
166
  }
145
167
  }
168
+ /** The host as one package has it: what it sends to a conversation as the user says it came from that package. */
169
+ hostOf(name) {
170
+ const host = this.host();
171
+ const mark = (input) => ({ ...input, message: ta_protocol_1.TaMessageSource.mark(input.message, name) });
172
+ return {
173
+ ...host,
174
+ prompt: (sessionId, input) => host.prompt(sessionId, mark(input)),
175
+ followUp: (sessionId, input) => host.followUp(sessionId, mark(input)),
176
+ };
177
+ }
146
178
  host() {
147
179
  if (!this.extensionHost) {
148
180
  const server = this.server;
@@ -154,8 +186,11 @@ let PackageHostsImpl = class PackageHostsImpl {
154
186
  return cwd === undefined ? undefined : this.directories.fromPi(cwd);
155
187
  },
156
188
  listPackages: cwd => packages.listPackages(cwd),
189
+ // Another package's host, by its name: what it documents in its README, as its web extension calls it.
190
+ callPackageHost: (name, method, params = []) => this.call(name, method, params),
157
191
  shares: this.relay.shares,
158
192
  rooms: this.roomsBridge.rooms,
193
+ relays: this.relay.extensionRelays,
159
194
  sessionMessages: file => this.sessionMessages(file),
160
195
  createSession: (cwd, messages, name) => this.createSession(cwd, messages, name),
161
196
  getServerInfo: () => server.getServerInfo(),
@@ -171,6 +206,17 @@ let PackageHostsImpl = class PackageHostsImpl {
171
206
  getExtensionData: (name, key, cwd) => packages.getExtensionData(name, key, cwd),
172
207
  setExtensionData: (name, key, value, cwd) => packages.setExtensionData(name, key, value, cwd),
173
208
  onExtensionData: listener => this.data.onChange(listener),
209
+ onSessionEvent: listener => this.sessions.onSessionEvent((session, event) => {
210
+ const turn = PackageHostUtil.turnEvent(session, event);
211
+ if (turn) {
212
+ listener(turn);
213
+ }
214
+ }),
215
+ presence: () => ({ pages: this.sessions.watching, seenAt: this.sessions.watchedAt }),
216
+ team: this.teamProvider.team,
217
+ installPackage: (source, scope, cwd) => packages.installPackage(source, scope, cwd),
218
+ removePackage: (id, cwd) => packages.removePackage(id, cwd),
219
+ updateSettings: update => this.settings.rewriteUser(update),
174
220
  };
175
221
  }
176
222
  return this.extensionHost;
@@ -231,6 +277,18 @@ __decorate([
231
277
  (0, core_1.Autowired)({ id: rooms_bridge_1.ROOMS_BRIDGE, detached: true }),
232
278
  __metadata("design:type", Function)
233
279
  ], PackageHostsImpl.prototype, "roomsBridge", void 0);
280
+ __decorate([
281
+ (0, core_1.Autowired)({ id: settings_store_1.TaSettingsStore, detached: true }),
282
+ __metadata("design:type", Object)
283
+ ], PackageHostsImpl.prototype, "settings", void 0);
284
+ __decorate([
285
+ (0, core_1.Autowired)({ id: host_protocol_1.TaSessionRegistry, detached: true }),
286
+ __metadata("design:type", Object)
287
+ ], PackageHostsImpl.prototype, "sessions", void 0);
288
+ __decorate([
289
+ (0, core_1.Autowired)({ id: team_protocol_1.TaHostTeamProvider, detached: true }),
290
+ __metadata("design:type", Object)
291
+ ], PackageHostsImpl.prototype, "teamProvider", void 0);
234
292
  exports.PackageHostsImpl = PackageHostsImpl = __decorate([
235
293
  (0, core_1.Component)([exports.PackageHosts, core_1.ApplicationLifecycle])
236
294
  ], PackageHostsImpl);