@celljs/ta-host 4.12.0 → 4.13.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 (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
package/README.en.md CHANGED
@@ -14,6 +14,7 @@ The server-side component of `ta serve`. It is functionally equivalent to Codex'
14
14
  | `RelayBridge` | `@Rpc(TaRelayServer)`: reads `relay.json` from the agent directory. When paired devices exist, it connects to Relay and opens a connection to `/api/ws` on this machine for each device (see [@celljs/ta-relay](../ta-relay/README.md)). The `pair` and `unpair` commands work the same as `ta pair`. If no Relay is provided, it uses `https://relay.cellbang.com`. |
15
15
  | `TaWorkingDirectory` | The working directory set by `setWorkingDirectory`, recorded in `ta.json` in the agent directory (`workingDirectory`), persists across restarts. Open sessions are unaffected. |
16
16
  | `TaSessionRegistry` | Manages open sessions. Rejects requests when exceeding `maxSessions`, closes sessions that are idle (no clients, not running, no pending dialogs) for longer than `idleTimeoutMs`. Session files are retained. A session closed while idle or by a restart of ta serve keeps its id (`TaSessionHandles`, `ta-sessions.json` in the agent directory, the latest 200): the next call with that id opens it again from its file, so clients never notice it closed; only `closeSession`, an extension ending the session, or a deleted session file give `CELL_TA_SESSION_NOT_FOUND`. |
17
+ | `TaSessionResume` | Carries on the runs a restart cut off: a session is written into `ta-running.json` of the agent directory as its run starts (with the messages the user queued) and struck off when it ends; a stop (or crash) of ta serve leaves the list as it is. At the next start, once it listens, each session of the list opens again under its id, gets a custom message `TA_RESUME_MESSAGE` (`ta-resume`) telling the model that a restart of Ta cut it off and to carry on from where it stopped, and starts a turn; what was queued is queued again. The web client shows the message as a mark, "Carried on after Ta restarted". A session closed for good is not carried on, nor a run that went down with ta serve twice in a row (a crash, not a stop) |
17
18
  | `TaSessionFactory` | Assembles sessions the same way the pi command does: project trust, settings, extensions, themes. All sessions share one model runtime. Opened again from its file alone, a session keeps the role (`ta-role`) and group (`ta-group`) written in it. Can be replaced by `rebind`. |
18
19
  | `TaSession` | One open session: event log, acknowledgments, connected clients. After `newSession`/`fork`/`switchSession` the id remains unchanged and broadcasts `session_replaced`. The `navigateTree` command (pi's `/tree`) also broadcasts when switching branches within the same session. |
19
20
  | `RemoteUiContext` | The pi extension's `ctx.ui`: dialogs are broadcast to all clients. The first response takes effect; if timed out, the default value from the extension is used. |
@@ -24,7 +25,7 @@ The server-side component of `ta serve`. It is functionally equivalent to Codex'
24
25
  | Temporary packages (`openTemporaryPackage` / `updateTemporaryPackage` / `installTemporaryPackage` / `get`, `setTemporaryRetention`) | Packages opened without installing (`TemporaryStore`, see docs/design/ta-launcher.md): a source of npm or Git is fetched with `install` of pi's package manager but not added to the `packages` setting, a path is only noted, and what an agent makes is in `temporary/<name>/` of the agent directory; `temporary.json` notes each (its source, when it was opened and used, whether it is kept in Mine). They are listed with `origin: 'temporary'` and `activation: 'open'`, and only their web part runs. `installTemporaryPackage` adds the source to the `packages` setting (moves what an agent made to `extensions/`); `removePackage` deletes Ta's own directory, remove what pi fetched, and only forget a path of the user. `TemporaryPurge` clears, 30 seconds after the start and every 12 hours, those unused for longer than the retention (30 days by default, 0 for never) and not kept in Mine. |
25
26
  | Sharing (`TaRelayServer.sharePackage` / `unsharePackage`) | A link of an extension of this computer: packed first to check it is at most 8 MB, noted in relay.json for 7 days; `RelayBridge` packs it when the other side asks and sends it end to end through the relay ([@celljs/ta-relay](../ta-relay/README.en.md)); `openTemporaryPackage` fetches such a link and unpacks it in `temporary/` |
26
27
  | Packages (`listPackages` / `installPackage` / `removePackage`) | Lists all packages loaded by pi (with or without web extensions) and includes `resources` (`extensions`, `web`, `skills`, `prompts`, `themes`). The `installPackage` command works the same as `ta install` (`project` is `-l`, only for trusted projects). Every method of a package (`removePackage`, `setPackageEnabled`, those of temporary packages) takes its id of `listPackages` or the id of one of its web extensions. |
27
- | Package host service (`callPackageHost`) | Calls methods on objects returned by the built-in package `pi.host` (arguments and return values are JSON), for use by its web extensions. Methods that cannot be called are `dispose`, `constructor`, methods starting with `_`, or methods built into objects. |
28
+ | Package host service (`callPackageHost`) | Calls methods on objects returned by the built-in package `pi.host` (arguments and return values are JSON), for use by its web extensions, and by the hosts of other packages through `TaExtensionHost.callPackageHost` (`TaExtensionHost` also has `installPackage` / `removePackage`, and `updateSettings`, which rewrites the user's settings.json under pi's lock, for sync). Methods that cannot be called are `dispose`, `constructor`, methods starting with `_`, or methods built into objects. |
28
29
  | Toggles (`setPackageEnabled`) | Ta's built-in pi packages ([`TaPackages`](../ta-harness/README.md)) are toggled by name and listed with `origin: 'builtin'`. They can only be toggled, not removed. The toggle state is saved to `ta.json` in the agent directory (`disabledPackages`). Other packages are toggled by the id from `listPackages` and work the same as `ta config`, writing each resource individually to pi's settings (`PackageSwitch`: paths in `extensions/` are written as `+path` / `-path` to the `extensions` list, items in `packages` are written to that item's filter). The terminal `ta` recognizes this as well. Packages with no pi loading and only web extensions are recorded in `ta.json`'s `disabledWeb`. `enabled`: set to true when pi loads any resource from it (for web-only packages check `disabledWeb`). Disabled packages' web extensions are not loaded. Takes effect after session `reload`. |
29
30
  | `TaSettingsStore`(`TaSettingsStoreImpl`) | `getSettings` / `updateSettings`: ta's settings (keys listed in `TA_SETTINGS`) are pi's `settings.json`, user-level in the agent directory, project-level in `<cwd>/.ta/`. Changes only the provided keys (set to `null` to delete; an empty object deletes the file thereafter). Preserves other content and uses atomic writes via temporary file. Only one write happens at a time. During writes, it acquires the same file lock as pi (`<file>.lock` directory, considered stale after 10 seconds), so the terminal `ta` changing settings simultaneously does not overwrite (pi rereads within the lock and only writes back the keys it changed). Does not overwrite unreadable files. At project level, pi requests trust for projects that have not been trusted (with extensions, skills, etc.). Writing without requiring trust is treated as trusting (otherwise pi will not read). After writing, it notifies related sessions' `SettingsManager` to reload (model and reasoning level take effect for new sessions). |
30
31
  | `ExtensionDataStore`(`ExtensionDataStoreImpl`) | `getExtensionData` / `setExtensionData`: data stored on the server for packages (web extensions' `pi.storage`). One file per package at `<agentDir>/extension-data/<package name>.json` (mode 0600), with serial writes to the same file. Set values to `null` to delete keys. 4 MB limit per package. When `cwd` is provided, it is data for that directory at `extension-data/directories/<dir name>-<hash>/<package name>.json`. The hash includes the execution environment, so same-name directories do not interfere when running remotely. Notifications include `cwd`. |
@@ -95,4 +96,4 @@ Which cloud storage to use has not yet been decided, so `TaSessionFactory` has n
95
96
 
96
97
  - When there are no available models (model service not signed in, no model selected), pi's error will mention the `/login` command and its documentation path in the terminal. This is changed here to `CELL_TA_NOT_SIGNED_IN` with a prompt to sign in first using `TaAuthServer`.
97
98
  - The deduplication table, event log, and pending dialogs are all in memory. After service restart, dialogs become invalid (extensions receive the default value), and clients should call `getMessages` first to verify before deciding to resend.
98
- - When executing remotely, pi's resources (`AGENTS.md`, project `.ta/` settings and skills) still read from the same paths on the host machine. Project resources on the execution machine rely on a custom ResourceLoader (not yet implemented).
99
+ - When executing remotely, pi's resources (`AGENTS.md`, project `.ta/` settings and skills) still read from the same paths on the host machine. Project resources on the execution machine rely on a custom ResourceLoader (not yet implemented).
package/README.md CHANGED
@@ -14,6 +14,7 @@
14
14
  | `RelayBridge` | `@Rpc(TaRelayServer)`:读 agent 目录的 `relay.json`,有配对的设备时连上 Relay,并替每台设备开一条到本机 `/api/ws` 的连接(见 [@celljs/ta-relay](../ta-relay/README.md));`pair` / `unpair` 与 `ta pair` 相同,没给 Relay 时用 `https://relay.cellbang.com` |
15
15
  | `TaWorkingDirectory` | `setWorkingDirectory` 设的工作目录,记在 agent 目录的 `ta.json`(`workingDirectory`),跨重启保留;已经打开的会话不受影响 |
16
16
  | `TaSessionRegistry` | 打开的会话;超过 `maxSessions` 拒绝,空闲(无客户端、无运行、无待答对话框)超过 `idleTimeoutMs` 关闭,会话文件保留;空闲关闭或 ta serve 重启关掉的会话保留原 id(`TaSessionHandles`,存在 agent 目录的 `ta-sessions.json`,最近 200 个),下次有调用用这个 id 时从会话文件原样重新打开,客户端感觉不到它关过;只有 `closeSession`、扩展结束会话或会话文件已删时才回 `CELL_TA_SESSION_NOT_FOUND` |
17
+ | `TaSessionResume` | 让重启打断的任务接着做:会话一开始运行就记进 agent 目录的 `ta-running.json`(连同用户排队的消息),运行结束才划掉;ta serve 停止(或崩溃)时名单原样留下。下次启动、开始监听后,名单里的会话按原 id 重新打开,加一条 `TA_RESUME_MESSAGE`(`ta-resume`)自定义消息告诉模型"Ta 重启打断了你,从停下的地方接着做"并开始新一轮,排队的消息重新排上;Web 端把这条消息显示成"Ta 重启后接着做"的标记。已经彻底关闭的会话不再继续;连续 2 次跟着 ta serve 一起倒下(崩溃,不算正常停止)的运行不再继续 |
17
18
  | `TaSessionFactory` | 像 pi 命令那样装配会话:项目信任、设置、扩展、主题;所有会话共用一个模型运行时。只按会话文件重新打开时,沿用文件里记下的角色(`ta-role`)和分组(`ta-group`)。可 `rebind` 替换 |
18
19
  | `TaSession` | 一个打开的会话:事件日志、回执、已连接的客户端;`newSession`/`fork`/`switchSession` 后 id 不变,并发 `session_replaced`;`navigateTree`(pi 的 `/tree`)在同一会话里换分支后也发 |
19
20
  | `RemoteUiContext` | pi 扩展的 `ctx.ui`:对话框广播给所有客户端,第一个回答生效,超时按扩展给的默认值 |
@@ -24,7 +25,7 @@
24
25
  | 包(`listPackages` / `installPackage` / `removePackage`) | 列出 pi 加载的所有包(不论有没有 Web 扩展),带 `resources`(`extensions`、`web`、`skills`、`prompts`、`themes`);`installPackage` 与 `ta install` 相同(`project` 即 `-l`,只在受信任的项目);包的各个方法(`removePackage`、`setPackageEnabled`、临时包的方法)都接受 `listPackages` 给的包 id,或它某个 Web 扩展的 id |
25
26
  | 临时包(`openTemporaryPackage` / `updateTemporaryPackage` / `installTemporaryPackage` / `get`、`setTemporaryRetention`) | 不安装、打开即用的包(`TemporaryStore`,见 docs/design/ta-launcher.md):npm、Git 来源用 pi 包管理器的 `install` 拉下来但不写进 `packages` 设置,本地路径只记录,Agent 做的放在 agent 目录的 `temporary/<名字>/`;记录在 `temporary.json`(来源、打开和使用时间、是否收进"我的")。以 `origin: 'temporary'`、`activation: 'open'` 列出,只运行 Web 部分。`installTemporaryPackage` 把来源加进 `packages` 设置(Agent 做的移到 `extensions/`);`removePackage` 删掉 Ta 自己的目录、移除 pi 拉下来的包,用户的路径只是忘掉。`TemporaryPurge` 在启动 30 秒后和每 12 小时清掉超过保留天数(默认 30 天,0 为从不)没用过、也没收进"我的"的 |
26
27
  | 分享(`TaRelayServer.sharePackage` / `unsharePackage`) | 本机扩展的分享链接:先打包检查不超过 8 MB,在 relay.json 记一条 7 天的分享,`RelayBridge` 在对方来取时打包、经中继端到端发送([@celljs/ta-relay](../ta-relay/README.md));`openTemporaryPackage` 收到这种链接时取回、解包到 `temporary/` |
27
- | 包的服务端(`callPackageHost`) | 调用内置包 `pi.host` 返回的对象上的方法(参数、返回值都是 JSON),供它的 Web 扩展使用;`dispose`、`constructor`、`_` 开头的和对象自带的方法不能调用 |
28
+ | 包的服务端(`callPackageHost`) | 调用内置包 `pi.host` 返回的对象上的方法(参数、返回值都是 JSON),供它的 Web 扩展使用,别的包的服务端也经 `TaExtensionHost.callPackageHost` 调用(`TaExtensionHost` 还有 `installPackage` / `removePackage`,以及按 pi 的锁整体改写用户 settings.json 的 `updateSettings`,供设备同步用);`dispose`、`constructor`、`_` 开头的和对象自带的方法不能调用 |
28
29
  | 开关(`setPackageEnabled`) | Ta 自带的 pi 包([`TaPackages`](../ta-harness/README.md))按名字开关,以 `origin: 'builtin'` 列出,只能开关、不能移除,开关存在 agent 目录的 `ta.json`(`disabledPackages`)。其他包按 `listPackages` 的 id 开关,和 `ta config` 一样逐个资源写进 pi 的设置(`PackageSwitch`:`extensions/` 里的写 `+路径` / `-路径` 到 `extensions` 等列表,`packages` 里的写进该条目的过滤),所以终端里的 `ta` 也认;pi 什么都不加载、只有 Web 扩展的包记在 `ta.json` 的 `disabledWeb`。`enabled`:pi 加载它的任一资源时为开(只有 Web 扩展的看 `disabledWeb`),关掉的包的 Web 扩展不加载。会话 `reload` 后生效 |
29
30
  | `TaSettingsStore`(`TaSettingsStoreImpl`) | `getSettings` / `updateSettings`:ta 的设置(`TA_SETTINGS` 列出的键)就是 pi 的 `settings.json`,用户层在 agent 目录、项目层在 `<cwd>/.ta/`;只改给出的键(`null` 删除,空对象随之删掉),其余内容原样保留,整文件经临时文件写入、同一时间只写一次,写时持有与 pi 相同的文件锁(`<文件>.lock` 目录,超过 10 秒视为失效),所以终端里的 `ta` 同时改设置不会互相覆盖(pi 在锁内重读文件、只写回它改过的键);读不了的文件不覆盖。项目层:pi 会询问信任的项目(有扩展、技能等)未被信任时拒绝写入,没有需要询问的内容时写入即记为信任(否则 pi 不读)。写入后让相关会话的 `SettingsManager` 重新加载(模型与思考强度对新会话生效) |
30
31
  | `ExtensionDataStore`(`ExtensionDataStoreImpl`) | `getExtensionData` / `setExtensionData`:包存在服务器上的小数据(Web 扩展的 `pi.storage`),每个包一个 `<agentDir>/extension-data/<包名>.json`(权限 0600),同一文件串行写入;值为 `null` 删除该键;每个包上限 4 MB。带 `cwd` 时是该目录的数据(`pi.storage.directory(cwd)`),存在 `extension-data/directories/<目录名>-<哈希>/<包名>.json`,哈希含执行环境,远程执行时同名目录互不影响;变更通知带上 `cwd` |
@@ -95,4 +96,4 @@ ta:
95
96
 
96
97
  - 没有可用的模型(模型服务没登录、没选模型)时,pi 的报错会提到终端里的 `/login` 和它的文档路径;这里改成 `CELL_TA_NOT_SIGNED_IN`,提示先用 `TaAuthServer` 登录。
97
98
  - 去重表、事件日志和待答对话框都在内存里:服务重启后对话框作废(扩展拿到默认值),客户端应先 `getMessages` 核对再决定是否重发。
98
- - 远程执行时,pi 的资源(`AGENTS.md`、项目 `.ta/` 设置与 Skills)仍从宿主上同名路径读取;执行机上的项目资源要靠自定义 ResourceLoader(尚未实现)。
99
+ - 远程执行时,pi 的资源(`AGENTS.md`、项目 `.ta/` 设置与 Skills)仍从宿主上同名路径读取;执行机上的项目资源要靠自定义 ResourceLoader(尚未实现)。
@@ -1,5 +1,6 @@
1
1
  import type { RpcConnection } from '@celljs/rpc/lib/node';
2
2
  import { ExtensionDataStore } from './extension-data.js';
3
+ import { TaVisibility } from './team/team-protocol.js';
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. */
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { Autowired, Component } from '@celljs/core';
11
11
  import { TaClient } from '@celljs/ta-protocol';
12
12
  import { ExtensionDataStore } from './extension-data.js';
13
+ import { TaVisibility } from './team/team-protocol.js';
13
14
  export const ExtensionDataNotifier = Symbol('ExtensionDataNotifier');
14
15
  /** At most one notice per connection in this time, with the keys that changed meanwhile. */
15
16
  const NOTICE_MS = 250;
@@ -83,8 +84,9 @@ let ExtensionDataNotifierImpl = class ExtensionDataNotifierImpl {
83
84
  changed(name, key, cwd) {
84
85
  const scope = ExtensionDataScope.of(name, cwd);
85
86
  for (const [connection, watcher] of this.watchers) {
86
- if (watcher.scopes.has(scope)) {
87
- watcher.batch.add(name, key, cwd);
87
+ const told = watcher.scopes.has(scope) ? this.visibility.dataName(connection, name, key) : undefined;
88
+ if (told !== undefined) {
89
+ watcher.batch.add(told, key, cwd);
88
90
  this.schedule(connection, watcher);
89
91
  }
90
92
  }
@@ -112,6 +114,10 @@ __decorate([
112
114
  Autowired(ExtensionDataStore),
113
115
  __metadata("design:type", Object)
114
116
  ], ExtensionDataNotifierImpl.prototype, "store", void 0);
117
+ __decorate([
118
+ Autowired({ id: TaVisibility, detached: true }),
119
+ __metadata("design:type", Object)
120
+ ], ExtensionDataNotifierImpl.prototype, "visibility", void 0);
115
121
  ExtensionDataNotifierImpl = __decorate([
116
122
  Component(ExtensionDataNotifier)
117
123
  ], ExtensionDataNotifierImpl);
@@ -33,7 +33,7 @@ let ExtensionProvidersImpl = class ExtensionProvidersImpl {
33
33
  agentDir,
34
34
  settingsManager: sdk.SettingsManager.create(cwd, agentDir, { projectTrusted: false }),
35
35
  modelRuntime: await this.modelRuntimeProvider.provide(),
36
- resourceLoaderOptions: TaPackages.loaderOptions(agentDir),
36
+ resourceLoaderOptions: TaPackages.loaderOptions(agentDir, { loadSkills: sdk.loadSkillsFromDir }),
37
37
  });
38
38
  }
39
39
  };
@@ -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.js';
4
4
  import type { TaSession } from './ta-session.js';
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,3 +100,10 @@ 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
+ }
@@ -2,6 +2,7 @@ export const TaSessionFactory = Symbol('TaSessionFactory');
2
2
  export const TaSessionRegistry = Symbol('TaSessionRegistry');
3
3
  export const TaSessionCatalog = Symbol('TaSessionCatalog');
4
4
  export const WebExtensionCatalog = Symbol('WebExtensionCatalog');
5
+ export const KeepAwake = Symbol('KeepAwake');
5
6
  export const TA_HOST_OPTIONS = 'ta.host';
6
7
  export const TA_EXEC_OPTIONS = 'ta.exec';
7
8
  //# sourceMappingURL=host-protocol.js.map
@@ -7,6 +7,7 @@ export * from './extension-data.js';
7
7
  export * from './extension-data-notifier.js';
8
8
  export * from './extension-providers.js';
9
9
  export * from './host-protocol.js';
10
+ export * from './keep-awake.js';
10
11
  export * from './package-host-extension.js';
11
12
  export * from './package-hosts.js';
12
13
  export * from './package-server-impl.js';
@@ -19,6 +20,7 @@ export * from './session-catalog.js';
19
20
  export * from './session-files.js';
20
21
  export * from './session-handles.js';
21
22
  export * from './session-info-util.js';
23
+ export * from './session-resume.js';
22
24
  export * from './session-storage/index.js';
23
25
  export * from './settings-server-impl.js';
24
26
  export * from './settings-store.js';
@@ -30,6 +32,7 @@ export * from './ta-server-impl.js';
30
32
  export * from './ta-session.js';
31
33
  export * from './ta-session-factory.js';
32
34
  export * from './ta-session-registry.js';
35
+ export * from './team/index.js';
33
36
  export * from './temporary-packages.js';
34
37
  export * from './temporary-purge.js';
35
38
  export * from './terminal-protocol.js';
package/esm/node/index.js CHANGED
@@ -7,6 +7,7 @@ export * from './extension-data.js';
7
7
  export * from './extension-data-notifier.js';
8
8
  export * from './extension-providers.js';
9
9
  export * from './host-protocol.js';
10
+ export * from './keep-awake.js';
10
11
  export * from './package-host-extension.js';
11
12
  export * from './package-hosts.js';
12
13
  export * from './package-server-impl.js';
@@ -19,6 +20,7 @@ export * from './session-catalog.js';
19
20
  export * from './session-files.js';
20
21
  export * from './session-handles.js';
21
22
  export * from './session-info-util.js';
23
+ export * from './session-resume.js';
22
24
  export * from './session-storage/index.js';
23
25
  export * from './settings-server-impl.js';
24
26
  export * from './settings-store.js';
@@ -30,6 +32,7 @@ export * from './ta-server-impl.js';
30
32
  export * from './ta-session.js';
31
33
  export * from './ta-session-factory.js';
32
34
  export * from './ta-session-registry.js';
35
+ export * from './team/index.js';
33
36
  export * from './temporary-packages.js';
34
37
  export * from './temporary-purge.js';
35
38
  export * from './terminal-protocol.js';
@@ -0,0 +1,44 @@
1
+ import { type ChildProcess } from 'node:child_process';
2
+ import { type Application, ApplicationLifecycle } from '@celljs/core';
3
+ import { KeepAwake, TaSessionRegistry } from './host-protocol.js';
4
+ import { type RelayBridge } from './relay-bridge.js';
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
+ }
@@ -0,0 +1,112 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { spawn } from 'node:child_process';
11
+ import { ApplicationLifecycle, Autowired, Component } from '@celljs/core';
12
+ import { KeepAwake, TaSessionRegistry } from './host-protocol.js';
13
+ import { RELAY_BRIDGE } from './relay-bridge.js';
14
+ export var KeepAwakeUtil;
15
+ (function (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
+ KeepAwakeUtil.DEVICE_GRACE_MS = 30 * 60000;
18
+ /** Only macOS: `caffeinate` holds the assertion of the system, and lets it go when ta serve exits. */
19
+ function supported(platform = process.platform) {
20
+ return platform === 'darwin';
21
+ }
22
+ KeepAwakeUtil.supported = supported;
23
+ function wanted(state) {
24
+ return state.enabled && (state.running || (state.deviceAt > 0 && state.now - state.deviceAt < KeepAwakeUtil.DEVICE_GRACE_MS));
25
+ }
26
+ KeepAwakeUtil.wanted = wanted;
27
+ })(KeepAwakeUtil || (KeepAwakeUtil = {}));
28
+ /** How often what keeps the computer awake is looked at. */
29
+ const CHECK_MS = 15000;
30
+ /**
31
+ * Keeps the computer from sleeping while idle as long as a session runs or a paired device was connected of
32
+ * late: asleep, ta serve answers no phone, and a phone that cannot reach it cannot wake it. It holds
33
+ * `caffeinate -i` (idle sleep only: the display sleeps, a closed lid sleeps), which ends with ta serve.
34
+ * Turned off in relay.json (TaRelayServer.setKeepAwake); nothing where it is not supported.
35
+ */
36
+ let KeepAwakeImpl = class KeepAwakeImpl {
37
+ constructor() {
38
+ this.deviceAt = 0;
39
+ }
40
+ get supported() {
41
+ return KeepAwakeUtil.supported();
42
+ }
43
+ /** Whether the computer is kept awake now. */
44
+ get held() {
45
+ return this.child !== undefined;
46
+ }
47
+ onStart() {
48
+ var _a, _b;
49
+ if (!this.supported) {
50
+ return;
51
+ }
52
+ this.timer = setInterval(() => this.check(), CHECK_MS);
53
+ (_b = (_a = this.timer).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
54
+ }
55
+ onStop() {
56
+ clearInterval(this.timer);
57
+ this.release();
58
+ }
59
+ check(now = Date.now()) {
60
+ if (!this.supported) {
61
+ return;
62
+ }
63
+ if (this.bridge.devicesOpen > 0) {
64
+ this.deviceAt = now;
65
+ }
66
+ const running = this.sessions.list().some(session => session.pi.isStreaming);
67
+ const enabled = this.bridge.store.read().keepAwake !== false;
68
+ if (KeepAwakeUtil.wanted({ enabled, running, deviceAt: this.deviceAt, now })) {
69
+ this.hold();
70
+ }
71
+ else {
72
+ this.release();
73
+ }
74
+ }
75
+ hold() {
76
+ if (this.child) {
77
+ return;
78
+ }
79
+ const child = this.spawn();
80
+ this.child = child;
81
+ const ended = () => {
82
+ if (this.child === child) {
83
+ this.child = undefined;
84
+ }
85
+ };
86
+ child.once('error', ended);
87
+ child.once('exit', ended);
88
+ child.unref();
89
+ }
90
+ release() {
91
+ const child = this.child;
92
+ this.child = undefined;
93
+ child === null || child === void 0 ? void 0 : child.kill();
94
+ }
95
+ /** `-w`: it ends when this process does, killed too. */
96
+ spawn() {
97
+ return spawn('/usr/bin/caffeinate', ['-i', '-w', String(process.pid)], { stdio: 'ignore' });
98
+ }
99
+ };
100
+ __decorate([
101
+ Autowired(RELAY_BRIDGE),
102
+ __metadata("design:type", Function)
103
+ ], KeepAwakeImpl.prototype, "bridge", void 0);
104
+ __decorate([
105
+ Autowired(TaSessionRegistry),
106
+ __metadata("design:type", Object)
107
+ ], KeepAwakeImpl.prototype, "sessions", void 0);
108
+ KeepAwakeImpl = __decorate([
109
+ Component([KeepAwake, ApplicationLifecycle])
110
+ ], KeepAwakeImpl);
111
+ export { KeepAwakeImpl };
112
+ //# sourceMappingURL=keep-awake.js.map
@@ -8,9 +8,11 @@ export class PackageHostExtension {
8
8
  }
9
9
  register(pi) {
10
10
  pi.events.on(TA_HOST_EVENT, data => {
11
+ var _a;
11
12
  const request = data;
12
13
  if (typeof (request === null || request === void 0 ? void 0 : request.name) === 'string' && typeof request.resolve === 'function') {
13
14
  const resolve = request.resolve;
15
+ (_a = request.heard) === null || _a === void 0 ? void 0 : _a.call(request);
14
16
  void this.hosts.answer(request.name).then(answer => resolve({ ...answer, files: this.files }));
15
17
  }
16
18
  });
@@ -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.js';
5
+ import { TaSessionRegistry } from './host-protocol.js';
5
6
  import { type RelayBridge } from './relay-bridge.js';
6
7
  import { PiDirectories } from './remote/remote-protocol.js';
7
8
  import { type RoomsBridge } from './rooms-bridge.js';
9
+ import { TaSettingsStore } from './settings-store.js';
10
+ import { TaHostTeamProvider } from './team/team-protocol.js';
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>;
@@ -15,12 +15,15 @@ import { CODING_AGENT_OPTIONS, PiSdkUtil } from '@celljs/ai-coding-agent';
15
15
  import { ApplicationLifecycle, Autowired, Component, Value } from '@celljs/core';
16
16
  import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
17
17
  import { TaPackages } from '@celljs/ta-harness/lib/node/ta-packages';
18
- import { TaPackageServer, TaServer } from '@celljs/ta-protocol';
18
+ import { TaMessageSource, TaPackageServer, TaServer, } from '@celljs/ta-protocol';
19
19
  import { ExtensionDataStore } from './extension-data.js';
20
+ import { TaSessionRegistry } from './host-protocol.js';
20
21
  import { RELAY_BRIDGE } from './relay-bridge.js';
21
22
  import { PiDirectories } from './remote/remote-protocol.js';
22
23
  import { ROOMS_BRIDGE } from './rooms-bridge.js';
24
+ import { TaSettingsStore } from './settings-store.js';
23
25
  import { TaErrors } from './ta-errors.js';
26
+ import { TaHostTeamProvider } from './team/team-protocol.js';
24
27
  export const PackageHosts = Symbol('PackageHosts');
25
28
  export var PackageHostUtil;
26
29
  (function (PackageHostUtil) {
@@ -44,6 +47,25 @@ export var PackageHostUtil;
44
47
  }
45
48
  }
46
49
  PackageHostUtil.sessionCwd = sessionCwd;
50
+ /** A turn starting or ending, of the events of a session (TaExtensionHost.onSessionEvent); undefined for any other event. */
51
+ function turnEvent(session, event) {
52
+ if (event.type !== 'agent_start' && event.type !== 'agent_settled') {
53
+ return undefined;
54
+ }
55
+ const { sessionFile, group } = session.info();
56
+ const base = { sessionId: session.id, cwd: session.cwd, ...(sessionFile ? { sessionFile } : {}), ...(group ? { group } : {}) };
57
+ if (event.type === 'agent_start') {
58
+ return { type: 'turn_start', ...base };
59
+ }
60
+ const last = [...session.pi.messages].reverse().find(message => message.role === 'assistant');
61
+ return {
62
+ type: 'turn_end',
63
+ ...base,
64
+ ...((last === null || last === void 0 ? void 0 : last.stopReason) === 'error' ? { error: last.errorMessage || 'The turn failed.' } : {}),
65
+ ...((last === null || last === void 0 ? void 0 : last.stopReason) === 'aborted' ? { aborted: true } : {}),
66
+ };
67
+ }
68
+ PackageHostUtil.turnEvent = turnEvent;
47
69
  /** The file of `pi.host`, inside the package; undefined when it has none. */
48
70
  function entry(root) {
49
71
  var _a, _b;
@@ -90,7 +112,7 @@ let PackageHostsImpl = class PackageHostsImpl {
90
112
  }
91
113
  async answer(name) {
92
114
  var _a;
93
- return { host: this.host(), service: await ((_a = this.running.get(name)) === null || _a === void 0 ? void 0 : _a.service) };
115
+ return { host: this.hostOf(name), service: await ((_a = this.running.get(name)) === null || _a === void 0 ? void 0 : _a.service) };
94
116
  }
95
117
  async call(name, method, params) {
96
118
  var _a;
@@ -118,7 +140,7 @@ let PackageHostsImpl = class PackageHostsImpl {
118
140
  try {
119
141
  const module = await import(pathToFileURL(file).href);
120
142
  const factory = ((_a = module.default) !== null && _a !== void 0 ? _a : module);
121
- return (_b = (await factory(this.host()))) !== null && _b !== void 0 ? _b : undefined;
143
+ return (_b = (await factory(this.hostOf(name)))) !== null && _b !== void 0 ? _b : undefined;
122
144
  }
123
145
  catch (error) {
124
146
  console.error(`The host of ${name} failed: ${error instanceof Error ? error.message : error}`);
@@ -140,6 +162,16 @@ let PackageHostsImpl = class PackageHostsImpl {
140
162
  console.error(`The host of ${name} failed to stop: ${error instanceof Error ? error.message : error}`);
141
163
  }
142
164
  }
165
+ /** The host as one package has it: what it sends to a conversation as the user says it came from that package. */
166
+ hostOf(name) {
167
+ const host = this.host();
168
+ const mark = (input) => ({ ...input, message: TaMessageSource.mark(input.message, name) });
169
+ return {
170
+ ...host,
171
+ prompt: (sessionId, input) => host.prompt(sessionId, mark(input)),
172
+ followUp: (sessionId, input) => host.followUp(sessionId, mark(input)),
173
+ };
174
+ }
143
175
  host() {
144
176
  if (!this.extensionHost) {
145
177
  const server = this.server;
@@ -151,8 +183,11 @@ let PackageHostsImpl = class PackageHostsImpl {
151
183
  return cwd === undefined ? undefined : this.directories.fromPi(cwd);
152
184
  },
153
185
  listPackages: cwd => packages.listPackages(cwd),
186
+ // Another package's host, by its name: what it documents in its README, as its web extension calls it.
187
+ callPackageHost: (name, method, params = []) => this.call(name, method, params),
154
188
  shares: this.relay.shares,
155
189
  rooms: this.roomsBridge.rooms,
190
+ relays: this.relay.extensionRelays,
156
191
  sessionMessages: file => this.sessionMessages(file),
157
192
  createSession: (cwd, messages, name) => this.createSession(cwd, messages, name),
158
193
  getServerInfo: () => server.getServerInfo(),
@@ -168,6 +203,17 @@ let PackageHostsImpl = class PackageHostsImpl {
168
203
  getExtensionData: (name, key, cwd) => packages.getExtensionData(name, key, cwd),
169
204
  setExtensionData: (name, key, value, cwd) => packages.setExtensionData(name, key, value, cwd),
170
205
  onExtensionData: listener => this.data.onChange(listener),
206
+ onSessionEvent: listener => this.sessions.onSessionEvent((session, event) => {
207
+ const turn = PackageHostUtil.turnEvent(session, event);
208
+ if (turn) {
209
+ listener(turn);
210
+ }
211
+ }),
212
+ presence: () => ({ pages: this.sessions.watching, seenAt: this.sessions.watchedAt }),
213
+ team: this.teamProvider.team,
214
+ installPackage: (source, scope, cwd) => packages.installPackage(source, scope, cwd),
215
+ removePackage: (id, cwd) => packages.removePackage(id, cwd),
216
+ updateSettings: update => this.settings.rewriteUser(update),
171
217
  };
172
218
  }
173
219
  return this.extensionHost;
@@ -227,6 +273,18 @@ __decorate([
227
273
  Autowired({ id: ROOMS_BRIDGE, detached: true }),
228
274
  __metadata("design:type", Function)
229
275
  ], PackageHostsImpl.prototype, "roomsBridge", void 0);
276
+ __decorate([
277
+ Autowired({ id: TaSettingsStore, detached: true }),
278
+ __metadata("design:type", Object)
279
+ ], PackageHostsImpl.prototype, "settings", void 0);
280
+ __decorate([
281
+ Autowired({ id: TaSessionRegistry, detached: true }),
282
+ __metadata("design:type", Object)
283
+ ], PackageHostsImpl.prototype, "sessions", void 0);
284
+ __decorate([
285
+ Autowired({ id: TaHostTeamProvider, detached: true }),
286
+ __metadata("design:type", Object)
287
+ ], PackageHostsImpl.prototype, "teamProvider", void 0);
230
288
  PackageHostsImpl = __decorate([
231
289
  Component([PackageHosts, ApplicationLifecycle])
232
290
  ], PackageHostsImpl);