@celljs/ta-host 4.10.0 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +4 -4
- package/README.md +4 -4
- package/esm/node/client-tool-broker.d.ts +6 -2
- package/esm/node/client-tool-broker.js +11 -4
- package/esm/node/host-protocol.d.ts +12 -7
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/package-hosts.d.ts +6 -0
- package/esm/node/package-hosts.js +36 -1
- package/esm/node/package-server-impl.d.ts +0 -1
- package/esm/node/package-server-impl.js +0 -3
- package/esm/node/relay-bridge.d.ts +12 -2
- package/esm/node/relay-bridge.js +93 -3
- package/esm/node/rooms-bridge.d.ts +60 -0
- package/esm/node/rooms-bridge.js +155 -0
- package/esm/node/session-catalog.d.ts +7 -3
- package/esm/node/session-catalog.js +12 -4
- package/esm/node/session-info-util.d.ts +2 -1
- package/esm/node/session-info-util.js +34 -7
- package/esm/node/session-list-feed.d.ts +28 -0
- package/esm/node/session-list-feed.js +62 -0
- package/esm/node/sign-in/sign-in-flow.d.ts +2 -0
- package/esm/node/sign-in/sign-in-flow.js +9 -0
- package/esm/node/sign-in/sign-in-provider.js +3 -2
- package/esm/node/slash-command-util.d.ts +43 -0
- package/esm/node/slash-command-util.js +105 -0
- package/esm/node/ta-event-util.d.ts +9 -2
- package/esm/node/ta-event-util.js +31 -5
- package/esm/node/ta-server-impl.d.ts +13 -5
- package/esm/node/ta-server-impl.js +34 -16
- package/esm/node/ta-session-factory.d.ts +16 -1
- package/esm/node/ta-session-factory.js +42 -14
- package/esm/node/ta-session-registry.d.ts +4 -1
- package/esm/node/ta-session-registry.js +8 -0
- package/esm/node/ta-session.d.ts +8 -2
- package/esm/node/ta-session.js +41 -4
- package/esm/node/web-extension-catalog.d.ts +5 -1
- package/esm/node/web-extension-catalog.js +15 -19
- package/esm/node/web-extension-util.js +7 -3
- package/esm/node/workspace-files.d.ts +16 -12
- package/esm/node/workspace-files.js +14 -10
- package/esm/node/workspace-protocol.d.ts +1 -1
- package/lib/node/client-tool-broker.d.ts +6 -2
- package/lib/node/client-tool-broker.js +11 -4
- package/lib/node/host-protocol.d.ts +12 -7
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/package-hosts.d.ts +6 -0
- package/lib/node/package-hosts.js +35 -0
- package/lib/node/package-server-impl.d.ts +0 -1
- package/lib/node/package-server-impl.js +0 -3
- package/lib/node/relay-bridge.d.ts +12 -2
- package/lib/node/relay-bridge.js +91 -1
- package/lib/node/rooms-bridge.d.ts +61 -0
- package/lib/node/rooms-bridge.js +158 -0
- package/lib/node/session-catalog.d.ts +7 -3
- package/lib/node/session-catalog.js +12 -4
- package/lib/node/session-info-util.d.ts +2 -1
- package/lib/node/session-info-util.js +34 -7
- package/lib/node/session-list-feed.d.ts +29 -0
- package/lib/node/session-list-feed.js +66 -0
- package/lib/node/sign-in/sign-in-flow.d.ts +2 -0
- package/lib/node/sign-in/sign-in-flow.js +10 -1
- package/lib/node/sign-in/sign-in-provider.js +3 -2
- package/lib/node/slash-command-util.d.ts +44 -0
- package/lib/node/slash-command-util.js +108 -0
- package/lib/node/ta-event-util.d.ts +9 -2
- package/lib/node/ta-event-util.js +31 -5
- package/lib/node/ta-server-impl.d.ts +13 -5
- package/lib/node/ta-server-impl.js +32 -14
- package/lib/node/ta-session-factory.d.ts +16 -1
- package/lib/node/ta-session-factory.js +42 -14
- package/lib/node/ta-session-registry.d.ts +4 -1
- package/lib/node/ta-session-registry.js +8 -0
- package/lib/node/ta-session.d.ts +8 -2
- package/lib/node/ta-session.js +41 -4
- package/lib/node/web-extension-catalog.d.ts +5 -1
- package/lib/node/web-extension-catalog.js +15 -19
- package/lib/node/web-extension-util.js +7 -3
- package/lib/node/workspace-files.d.ts +16 -12
- package/lib/node/workspace-files.js +13 -9
- package/lib/node/workspace-protocol.d.ts +1 -1
- package/package.json +10 -10
package/README.en.md
CHANGED
|
@@ -20,10 +20,10 @@ The server-side component of `ta serve`. It is functionally equivalent to Codex'
|
|
|
20
20
|
| `EventLog` / `ClientChannel` | Each session retains recent events in bytes for reconnection recovery. Each client merges into a frame every 30ms and sends the next frame after the client acknowledges. Clients that fall too far behind are disconnected to force reconnection. |
|
|
21
21
|
| `TaAccess` | Validates tokens (WebSocket handshake and HTTP), listens on localhost and validates the `Host` header to prevent DNS rebinding, writes `serve.json`. The token and port are saved to `serve-state.json` and reused on the next startup. It also takes the tokens of browsers signed in with an account (`TaSignIn`). Listening on an address of the network (not this machine), it prints at start the link that signs in with the token (`TA_PUBLIC_URL`, else `http://localhost:<port>`; without the token when it comes from `TA_SERVE_TOKEN`) and the ways to sign in with an account |
|
|
22
22
|
| `TaSignIn` / `SignInMiddleware` / `TaAccessServerImpl` | Signing in with an account, see "Signing In with Accounts" below. The flow (`SignInFlow`) and the pages (`SignInPages`) need no Cell: [`ta gateway`](../ta-gateway/README.en.md) uses the same |
|
|
23
|
-
| `WebExtensionCatalog`(`WebExtensionCatalogImpl`) | `listWebExtensions` / `readWebExtension
|
|
24
|
-
| 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`
|
|
23
|
+
| `WebExtensionCatalog`(`WebExtensionCatalogImpl`) | `listWebExtensions` / `readWebExtension`: finds web extensions in packages using pi's package loading method (`packages` setting and `extensions/` directory, project packages only when trusted). Reads only declared, in-package files that are under 2 MB. |
|
|
24
|
+
| 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
25
|
| 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
|
-
| 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).
|
|
26
|
+
| 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
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
28
|
| 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
29
|
| `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). |
|
|
@@ -67,7 +67,7 @@ When `ta serve` runs in the cloud or on a server, besides the token, people can
|
|
|
67
67
|
| `TA_GITHUB_CLIENT_ID` / `TA_GITHUB_CLIENT_SECRET` | A GitHub OAuth App; the account is `github:<login>`. `TA_GITHUB_URL` points to a GitHub Enterprise Server |
|
|
68
68
|
| `TA_GOOGLE_CLIENT_ID` / `TA_GOOGLE_CLIENT_SECRET` | A Google OAuth client (web application); the account is `google:<email>`, verified addresses only |
|
|
69
69
|
| `TA_WECHAT_APP_ID` / `TA_WECHAT_APP_SECRET` | A website app of the WeChat Open Platform (sign-in by scanning); the account is `wechat:<unionid>`, or the openid when the app has no unionid |
|
|
70
|
-
| `TA_OIDC_ISSUER` / `TA_OIDC_CLIENT_ID` / `TA_OIDC_CLIENT_SECRET` / `TA_OIDC_NAME` | Any OpenID Connect provider (Microsoft Entra, Okta, Keycloak, Authing...), its endpoints found at `<issuer>/.well-known/openid-configuration`; the account is `oidc:<verified email
|
|
70
|
+
| `TA_OIDC_ISSUER` / `TA_OIDC_CLIENT_ID` / `TA_OIDC_CLIENT_SECRET` / `TA_OIDC_NAME` | Any OpenID Connect provider (Microsoft Entra, Okta, Keycloak, Authing...), its endpoints found at `<issuer>/.well-known/openid-configuration`; the account is `oidc:<verified email>` (the provider says `email_verified: true`), else `oidc:<sub>`; `TA_OIDC_NAME` is the name on the button |
|
|
71
71
|
| `TA_ALLOWED_USERS` | The accounts that may sign in, separated by commas or spaces, such as `github:octocat,google:*@example.com` (`*@<domain>` lets in a whole domain). They can also be added under Settings, Access in the web client |
|
|
72
72
|
|
|
73
73
|
The flow:
|
package/README.md
CHANGED
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
| `EventLog` / `ClientChannel` | 每个会话按字节保留最近的事件供重连补发;每个客户端每 30ms 合并成一帧,等客户端应答后再发下一帧,落后过多则断开让其重连 |
|
|
21
21
|
| `TaAccess` | token 校验(WebSocket 握手与 HTTP)、监听本机时校验 `Host` 防 DNS rebinding、写 `serve.json`;token 与端口记进 `serve-state.json`,下次启动沿用。还接受用账号登录的浏览器的 token(`TaSignIn`)。监听网络地址(不是本机)时,启动后打印带 token 的登录链接(`TA_PUBLIC_URL`,没有时用 `http://localhost:<端口>`;token 来自 `TA_SERVE_TOKEN` 时不打印 token)和可用的账号登录方式 |
|
|
22
22
|
| `TaSignIn` / `SignInMiddleware` / `TaAccessServerImpl` | 用账号登录,见下文「账号登录」。流程(`SignInFlow`)和跳转页(`SignInPages`)不依赖 Cell,[`ta gateway`](../ta-gateway/README.md) 用的是同一份 |
|
|
23
|
-
| `WebExtensionCatalog`(`WebExtensionCatalogImpl`) | `listWebExtensions` / `readWebExtension
|
|
24
|
-
| 包(`listPackages` / `installPackage` / `removePackage`) | 列出 pi 加载的所有包(不论有没有 Web 扩展),带 `resources`(`extensions`、`web`、`skills`、`prompts`、`themes`);`installPackage` 与 `ta install` 相同(`project` 即 `-l
|
|
25
|
-
| 临时包(`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`
|
|
23
|
+
| `WebExtensionCatalog`(`WebExtensionCatalogImpl`) | `listWebExtensions` / `readWebExtension`:按 pi 加载包的方式(`packages` 设置与 `extensions/` 目录,项目的只在受信任时)找出包里的 Web 扩展(`package.json` 的 `pi.web`,或 `web/` 下的模块);只读声明过、在包内、不超过 2 MB 的文件 |
|
|
24
|
+
| 包(`listPackages` / `installPackage` / `removePackage`) | 列出 pi 加载的所有包(不论有没有 Web 扩展),带 `resources`(`extensions`、`web`、`skills`、`prompts`、`themes`);`installPackage` 与 `ta install` 相同(`project` 即 `-l`,只在受信任的项目);包的各个方法(`removePackage`、`setPackageEnabled`、临时包的方法)都接受 `listPackages` 给的包 id,或它某个 Web 扩展的 id |
|
|
25
|
+
| 临时包(`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
26
|
| 分享(`TaRelayServer.sharePackage` / `unsharePackage`) | 本机扩展的分享链接:先打包检查不超过 8 MB,在 relay.json 记一条 7 天的分享,`RelayBridge` 在对方来取时打包、经中继端到端发送([@celljs/ta-relay](../ta-relay/README.md));`openTemporaryPackage` 收到这种链接时取回、解包到 `temporary/` |
|
|
27
27
|
| 包的服务端(`callPackageHost`) | 调用内置包 `pi.host` 返回的对象上的方法(参数、返回值都是 JSON),供它的 Web 扩展使用;`dispose`、`constructor`、`_` 开头的和对象自带的方法不能调用 |
|
|
28
28
|
| 开关(`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` 后生效 |
|
|
@@ -67,7 +67,7 @@ ta:
|
|
|
67
67
|
| `TA_GITHUB_CLIENT_ID` / `TA_GITHUB_CLIENT_SECRET` | GitHub 的 OAuth App;账号是 `github:<用户名>`。`TA_GITHUB_URL` 指向 GitHub Enterprise Server |
|
|
68
68
|
| `TA_GOOGLE_CLIENT_ID` / `TA_GOOGLE_CLIENT_SECRET` | Google 的 OAuth 客户端(Web 应用);账号是 `google:<邮箱>`,只认验证过的邮箱 |
|
|
69
69
|
| `TA_WECHAT_APP_ID` / `TA_WECHAT_APP_SECRET` | 微信开放平台的网站应用(扫码登录);账号是 `wechat:<unionid>`,应用没有 unionid 时是 openid |
|
|
70
|
-
| `TA_OIDC_ISSUER` / `TA_OIDC_CLIENT_ID` / `TA_OIDC_CLIENT_SECRET` / `TA_OIDC_NAME` | 任意 OpenID Connect 服务(Microsoft Entra、Okta、Keycloak、Authing……),从 `<issuer>/.well-known/openid-configuration` 找到端点;账号是 `oidc
|
|
70
|
+
| `TA_OIDC_ISSUER` / `TA_OIDC_CLIENT_ID` / `TA_OIDC_CLIENT_SECRET` / `TA_OIDC_NAME` | 任意 OpenID Connect 服务(Microsoft Entra、Okta、Keycloak、Authing……),从 `<issuer>/.well-known/openid-configuration` 找到端点;账号是 `oidc:<验证过的邮箱>`(服务方明确给出 `email_verified: true`),没有时是 `oidc:<sub>`;`TA_OIDC_NAME` 是按钮上的名字 |
|
|
71
71
|
| `TA_ALLOWED_USERS` | 允许登录的账号,逗号或空格分隔,如 `github:octocat,google:*@example.com`(`*@<域名>` 允许整个域名)。也可以在 Web 客户端的 设置 → 访问 里添加 |
|
|
72
72
|
|
|
73
73
|
流程:
|
|
@@ -29,8 +29,12 @@ export declare class ClientToolBroker {
|
|
|
29
29
|
claim(id: string, runner: object): boolean;
|
|
30
30
|
/** `runner` left the session: the calls it took and did not answer go to the others again. */
|
|
31
31
|
release(runner: object): void;
|
|
32
|
-
/**
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* False when nobody waits for this call, or another client took it: only the runner that claimed a call
|
|
34
|
+
* answers it, so that a page that did not run it cannot put an answer of its own in its place. A call nobody
|
|
35
|
+
* claimed (a client from before claims, or a result sent again after a reconnect) takes the first answer.
|
|
36
|
+
*/
|
|
37
|
+
respond(result: TaClientToolResult, runner?: object): boolean;
|
|
34
38
|
cancelAll(): void;
|
|
35
39
|
protected call(toolName: string, id: string, input: unknown, signal?: AbortSignal): Promise<{
|
|
36
40
|
content: {
|
|
@@ -60,11 +60,18 @@ export class ClientToolBroker {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
/**
|
|
64
|
-
|
|
63
|
+
/**
|
|
64
|
+
* False when nobody waits for this call, or another client took it: only the runner that claimed a call
|
|
65
|
+
* answers it, so that a page that did not run it cannot put an answer of its own in its place. A call nobody
|
|
66
|
+
* claimed (a client from before claims, or a result sent again after a reconnect) takes the first answer.
|
|
67
|
+
*/
|
|
68
|
+
respond(result, runner) {
|
|
65
69
|
const call = this.pending.get(result.id);
|
|
66
|
-
call
|
|
67
|
-
|
|
70
|
+
if (!call || (call.runner && call.runner !== runner)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
call.settle(result);
|
|
74
|
+
return true;
|
|
68
75
|
}
|
|
69
76
|
cancelAll() {
|
|
70
77
|
for (const call of [...this.pending.values()]) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
2
|
-
import type { TaOpenSessionOptions, TaPackageInfo, TaSavedSessionInfo, TaSettingsScope, TaTemporaryFrom, TaWebExtensionInfo, TaWebExtensionSource } from '@celljs/ta-protocol';
|
|
2
|
+
import type { 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;
|
|
@@ -28,6 +28,8 @@ export interface TaExecOptions {
|
|
|
28
28
|
export interface TaSessionFactory {
|
|
29
29
|
/** `id`: the id the session had, when it opens again under it. */
|
|
30
30
|
create(options: TaOpenSessionOptions, requestClose: (session: TaSession, idle?: boolean) => void, id?: string): Promise<TaSession>;
|
|
31
|
+
/** The commands of the `/` menu a session created in `cwd` would have, without creating one (TaServer.getDirectoryCommands). */
|
|
32
|
+
commands(cwd: string): Promise<TaSlashCommand[]>;
|
|
31
33
|
}
|
|
32
34
|
/** The open sessions. */
|
|
33
35
|
export interface TaSessionRegistry {
|
|
@@ -41,6 +43,8 @@ export interface TaSessionRegistry {
|
|
|
41
43
|
*/
|
|
42
44
|
resolve(sessionId: string): Promise<TaSession>;
|
|
43
45
|
list(): TaSession[];
|
|
46
|
+
/** The infos of the open sessions; the connection is told of each change from now on (TaServer.watchSessions). */
|
|
47
|
+
watch(connection: RpcConnection): TaSessionInfo[];
|
|
44
48
|
/** `idle`: closed to save its memory (idle, or the service stops), it keeps its id and opens again when called; otherwise for good. */
|
|
45
49
|
close(sessionId: string, idle?: boolean): Promise<void>;
|
|
46
50
|
/** As the service stops: each keeps its id, and opens again when called after the restart. */
|
|
@@ -49,24 +53,25 @@ export interface TaSessionRegistry {
|
|
|
49
53
|
}
|
|
50
54
|
/** The conversations pi keeps in its session files, open or not. */
|
|
51
55
|
export interface TaSessionCatalog {
|
|
52
|
-
/**
|
|
53
|
-
|
|
56
|
+
/**
|
|
57
|
+
* The latest first, without the files of `open` (sessions open now, which are listed as such), and only
|
|
58
|
+
* those in the window of `query`.
|
|
59
|
+
*/
|
|
60
|
+
list(open?: ReadonlySet<string>, query?: TaSavedSessionQuery): Promise<TaSavedSessionInfo[]>;
|
|
54
61
|
}
|
|
55
62
|
/** The packages pi loads in a directory, and their web extensions. */
|
|
56
63
|
export interface WebExtensionCatalog {
|
|
57
64
|
packages(cwd: string): Promise<TaPackageInfo[]>;
|
|
58
65
|
/** As `ta install`, with `-l` for `project`. */
|
|
59
66
|
install(cwd: string, source: string, scope: TaSettingsScope): Promise<void>;
|
|
60
|
-
/** A package of {@link packages}, not a built-in one. */
|
|
67
|
+
/** A package of {@link packages} by its id or the id of one of its web extensions, not a built-in one: those turn off with {@link setEnabled}. */
|
|
61
68
|
removePackage(cwd: string, id: string): Promise<void>;
|
|
62
69
|
list(cwd: string): Promise<TaWebExtensionInfo[]>;
|
|
63
70
|
/** Only the file of an extension the list has: an id names no other file. */
|
|
64
71
|
read(cwd: string, id: string): Promise<TaWebExtensionSource>;
|
|
65
|
-
/** Not a built-in package: those turn off with {@link setEnabled}. */
|
|
66
|
-
remove(cwd: string, id: string): Promise<void>;
|
|
67
72
|
/**
|
|
68
73
|
* Turns a package on or off: a built-in one by its name, in ta's settings (TaPackages); another by its
|
|
69
|
-
* id, in pi's settings as `pi config` does (PackageSwitch), or in ta's when pi loads nothing of it.
|
|
74
|
+
* id (or that of one of its web extensions), in pi's settings as `pi config` does (PackageSwitch), or in ta's when pi loads nothing of it.
|
|
70
75
|
*/
|
|
71
76
|
setEnabled(cwd: string, nameOrId: string, enabled: boolean): Promise<void>;
|
|
72
77
|
/** A package of {@link packages} by its id, or the id of one of its web extensions. */
|
package/esm/node/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './receipt-book.js';
|
|
|
14
14
|
export * from './relay-bridge.js';
|
|
15
15
|
export * from './remote/index.js';
|
|
16
16
|
export * from './remote-ui-context.js';
|
|
17
|
+
export * from './rooms-bridge.js';
|
|
17
18
|
export * from './session-catalog.js';
|
|
18
19
|
export * from './session-files.js';
|
|
19
20
|
export * from './session-handles.js';
|
package/esm/node/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export * from './receipt-book.js';
|
|
|
14
14
|
export * from './relay-bridge.js';
|
|
15
15
|
export * from './remote/index.js';
|
|
16
16
|
export * from './remote-ui-context.js';
|
|
17
|
+
export * from './rooms-bridge.js';
|
|
17
18
|
export * from './session-catalog.js';
|
|
18
19
|
export * from './session-files.js';
|
|
19
20
|
export * from './session-handles.js';
|
|
@@ -2,7 +2,9 @@ import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
|
|
|
2
2
|
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
3
3
|
import { type TaExtensionHost, type TaHostAnswer, TaPackageServer, type TaPackageService, TaServer } from '@celljs/ta-protocol';
|
|
4
4
|
import { ExtensionDataStore } from './extension-data.js';
|
|
5
|
+
import { type RelayBridge } from './relay-bridge.js';
|
|
5
6
|
import { PiDirectories } from './remote/remote-protocol.js';
|
|
7
|
+
import { type RoomsBridge } from './rooms-bridge.js';
|
|
6
8
|
export declare const PackageHosts: unique symbol;
|
|
7
9
|
/**
|
|
8
10
|
* The server side of built-in packages under `ta serve`: the module a package names in `pi.host` of its
|
|
@@ -33,6 +35,8 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
|
|
|
33
35
|
protected readonly data: ExtensionDataStore;
|
|
34
36
|
protected readonly server: TaServer;
|
|
35
37
|
protected readonly packages: TaPackageServer;
|
|
38
|
+
protected readonly relay: RelayBridge;
|
|
39
|
+
protected readonly roomsBridge: RoomsBridge;
|
|
36
40
|
protected readonly running: Map<string, Running>;
|
|
37
41
|
protected extensionHost?: TaExtensionHost;
|
|
38
42
|
onStart(): Promise<void>;
|
|
@@ -43,6 +47,8 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
|
|
|
43
47
|
protected start(name: string, file: string): Running;
|
|
44
48
|
protected stop(name: string): Promise<void>;
|
|
45
49
|
protected host(): TaExtensionHost;
|
|
50
|
+
protected sessionMessages(file: string): Promise<unknown[]>;
|
|
51
|
+
protected createSession(cwd: string, messages: readonly unknown[], name?: string): Promise<string>;
|
|
46
52
|
protected agentDir(): string;
|
|
47
53
|
}
|
|
48
54
|
export {};
|
|
@@ -11,13 +11,15 @@ import { readFileSync } from 'node:fs';
|
|
|
11
11
|
import { open } from 'node:fs/promises';
|
|
12
12
|
import { join, relative, resolve, sep } from 'node:path';
|
|
13
13
|
import { pathToFileURL } from 'node:url';
|
|
14
|
-
import { CODING_AGENT_OPTIONS } from '@celljs/ai-coding-agent';
|
|
14
|
+
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
18
|
import { TaPackageServer, TaServer } from '@celljs/ta-protocol';
|
|
19
19
|
import { ExtensionDataStore } from './extension-data.js';
|
|
20
|
+
import { RELAY_BRIDGE } from './relay-bridge.js';
|
|
20
21
|
import { PiDirectories } from './remote/remote-protocol.js';
|
|
22
|
+
import { ROOMS_BRIDGE } from './rooms-bridge.js';
|
|
21
23
|
import { TaErrors } from './ta-errors.js';
|
|
22
24
|
export const PackageHosts = Symbol('PackageHosts');
|
|
23
25
|
export var PackageHostUtil;
|
|
@@ -149,6 +151,10 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
149
151
|
return cwd === undefined ? undefined : this.directories.fromPi(cwd);
|
|
150
152
|
},
|
|
151
153
|
listPackages: cwd => packages.listPackages(cwd),
|
|
154
|
+
shares: this.relay.shares,
|
|
155
|
+
rooms: this.roomsBridge.rooms,
|
|
156
|
+
sessionMessages: file => this.sessionMessages(file),
|
|
157
|
+
createSession: (cwd, messages, name) => this.createSession(cwd, messages, name),
|
|
152
158
|
getServerInfo: () => server.getServerInfo(),
|
|
153
159
|
listSessions: () => server.listSessions(),
|
|
154
160
|
openSession: options => server.openSession(options),
|
|
@@ -166,6 +172,27 @@ let PackageHostsImpl = class PackageHostsImpl {
|
|
|
166
172
|
}
|
|
167
173
|
return this.extensionHost;
|
|
168
174
|
}
|
|
175
|
+
async sessionMessages(file) {
|
|
176
|
+
const manager = (await PiSdkUtil.load()).SessionManager.open(file);
|
|
177
|
+
return manager.getBranch().flatMap(entry => (entry.type === 'message' ? [entry.message] : []));
|
|
178
|
+
}
|
|
179
|
+
async createSession(cwd, messages, name) {
|
|
180
|
+
if (!messages.some(message => message.role === 'assistant')) {
|
|
181
|
+
throw TaErrors.invalidArgument('A conversation needs an answer of the agent to be kept.', 'Pass the messages of a conversation that has one.');
|
|
182
|
+
}
|
|
183
|
+
const manager = (await PiSdkUtil.load()).SessionManager.create(this.directories.toPi(cwd));
|
|
184
|
+
for (const message of messages) {
|
|
185
|
+
manager.appendMessage(message);
|
|
186
|
+
}
|
|
187
|
+
if (name === null || name === void 0 ? void 0 : name.trim()) {
|
|
188
|
+
manager.appendSessionInfo(name.trim());
|
|
189
|
+
}
|
|
190
|
+
const file = manager.getSessionFile();
|
|
191
|
+
if (!file) {
|
|
192
|
+
throw TaErrors.commandFailed(new Error('pi kept no file of the conversation.'));
|
|
193
|
+
}
|
|
194
|
+
return file;
|
|
195
|
+
}
|
|
169
196
|
agentDir() {
|
|
170
197
|
var _a;
|
|
171
198
|
var _b;
|
|
@@ -192,6 +219,14 @@ __decorate([
|
|
|
192
219
|
Autowired({ id: TaPackageServer, detached: true }),
|
|
193
220
|
__metadata("design:type", Object)
|
|
194
221
|
], PackageHostsImpl.prototype, "packages", void 0);
|
|
222
|
+
__decorate([
|
|
223
|
+
Autowired({ id: RELAY_BRIDGE, detached: true }),
|
|
224
|
+
__metadata("design:type", Function)
|
|
225
|
+
], PackageHostsImpl.prototype, "relay", void 0);
|
|
226
|
+
__decorate([
|
|
227
|
+
Autowired({ id: ROOMS_BRIDGE, detached: true }),
|
|
228
|
+
__metadata("design:type", Function)
|
|
229
|
+
], PackageHostsImpl.prototype, "roomsBridge", void 0);
|
|
195
230
|
PackageHostsImpl = __decorate([
|
|
196
231
|
Component([PackageHosts, ApplicationLifecycle])
|
|
197
232
|
], PackageHostsImpl);
|
|
@@ -13,7 +13,6 @@ export declare class TaPackageServerImpl implements TaPackageServer {
|
|
|
13
13
|
protected readonly packageHosts: PackageHosts;
|
|
14
14
|
listWebExtensions(cwd?: string): Promise<TaWebExtensionInfo[]>;
|
|
15
15
|
readWebExtension(id: string, cwd?: string): Promise<TaWebExtensionSource>;
|
|
16
|
-
removeWebExtension(id: string, cwd?: string): Promise<void>;
|
|
17
16
|
setPackageEnabled(nameOrId: string, enabled: boolean, cwd?: string): Promise<void>;
|
|
18
17
|
listPackages(cwd?: string): Promise<TaPackageInfo[]>;
|
|
19
18
|
installPackage(source: string, scope: TaSettingsScope, cwd?: string): Promise<void>;
|
|
@@ -25,9 +25,6 @@ let TaPackageServerImpl = class TaPackageServerImpl {
|
|
|
25
25
|
readWebExtension(id, cwd) {
|
|
26
26
|
return TaErrors.guard(async () => this.webExtensions.read(await this.cwd(cwd), id));
|
|
27
27
|
}
|
|
28
|
-
removeWebExtension(id, cwd) {
|
|
29
|
-
return TaErrors.guard(async () => this.webExtensions.remove(await this.cwd(cwd), id));
|
|
30
|
-
}
|
|
31
28
|
setPackageEnabled(nameOrId, enabled, cwd) {
|
|
32
29
|
return TaErrors.guard(async () => {
|
|
33
30
|
await this.webExtensions.setEnabled(await this.cwd(cwd), nameOrId, enabled);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Server } from 'node:http';
|
|
2
2
|
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
3
3
|
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
4
|
-
import { type TaPackageShare, type TaRelayDevice, type TaRelayInfo, TaRelayServer } from '@celljs/ta-protocol';
|
|
5
|
-
import { RelayHost, RelayStore } from '@celljs/ta-relay/lib/node';
|
|
4
|
+
import { type TaPackageShare, type TaRelayDevice, type TaRelayInfo, TaRelayServer, type TaSharedContent, type TaShareInfo, type TaShareInput, type TaShares } from '@celljs/ta-protocol';
|
|
5
|
+
import { type RelayContentShare, RelayHost, RelayHubs, type RelayPublicIdentity, RelayStore } from '@celljs/ta-relay/lib/node';
|
|
6
6
|
import { ServerAware } from '@celljs/web/lib/node';
|
|
7
7
|
import { WebExtensionCatalog } from './host-protocol.js';
|
|
8
8
|
import { type TaAccess } from './ta-access.js';
|
|
@@ -16,7 +16,11 @@ export declare const RELAY_BRIDGE: unique symbol;
|
|
|
16
16
|
export declare class RelayBridge implements ServerAware, ApplicationLifecycle<Application> {
|
|
17
17
|
protected readonly access: TaAccess;
|
|
18
18
|
readonly store: RelayStore;
|
|
19
|
+
/** The identity, friends and rooms of this Ta (RoomsBridge runs them): shares with Ta friends need them too. */
|
|
20
|
+
readonly hubs: RelayHubs;
|
|
19
21
|
protected host?: RelayHost;
|
|
22
|
+
/** Content shared by links (TaExtensionHost.shares): kept in the agent directory, handed on by this server, a copy sealed on the relay if asked. */
|
|
23
|
+
readonly shares: TaShares;
|
|
20
24
|
get online(): boolean;
|
|
21
25
|
/** relay.json changed here: no need to wait for the watch. */
|
|
22
26
|
refresh(): void;
|
|
@@ -24,6 +28,12 @@ export declare class RelayBridge implements ServerAware, ApplicationLifecycle<Ap
|
|
|
24
28
|
onStop(): Promise<void>;
|
|
25
29
|
/** A package as it goes by a link: a gzipped tar of its directory, without node_modules and .git. */
|
|
26
30
|
static pack(root: string): Promise<Uint8Array>;
|
|
31
|
+
protected share(input: TaShareInput): Promise<TaShareInfo>;
|
|
32
|
+
protected unshare(id: string): Promise<boolean>;
|
|
33
|
+
protected open(text: string, password?: string): Promise<TaSharedContent>;
|
|
34
|
+
/** The Ta friends of these ids, as this Ta keeps them. */
|
|
35
|
+
protected friendsOf(ids: readonly string[] | undefined): RelayPublicIdentity[];
|
|
36
|
+
protected info(content: RelayContentShare): TaShareInfo;
|
|
27
37
|
protected start(server: Server): void;
|
|
28
38
|
}
|
|
29
39
|
/** `ta pair` for clients: the devices of relay.json, which RelayBridge serves. Their keys never leave, but in the link of a new one. */
|
package/esm/node/relay-bridge.js
CHANGED
|
@@ -15,8 +15,8 @@ import { Rpc } from '@celljs/rpc';
|
|
|
15
15
|
import { ExecEnvironmentFactory } from '@celljs/ta-exec';
|
|
16
16
|
import { PackageArchive } from '@celljs/ta-harness/lib/node/package-archive';
|
|
17
17
|
import { TaBrand } from '@celljs/ta-harness/lib/node/ta-brand';
|
|
18
|
-
import { TA_WEBSOCKET_PATH, TaRelayServer } from '@celljs/ta-protocol';
|
|
19
|
-
import { RELAY_DEFAULT_URL, RELAY_SHARE_MAX_BYTES, RelayHost, RelayPairingUtil, RelayShareUtil, RelayStore } from '@celljs/ta-relay/lib/node';
|
|
18
|
+
import { TA_WEBSOCKET_PATH, TaRelayServer, } from '@celljs/ta-protocol';
|
|
19
|
+
import { RELAY_CONTENT_MAX_BYTES, RELAY_DEFAULT_URL, RELAY_SHARE_MAX_BYTES, RelayBlobClient, RelayBytes, RelayContentError, RelayContentUtil, RelayHost, RelayHubFiles, RelayHubs, RelayPairingUtil, RelayShareUtil, RelayStore, } from '@celljs/ta-relay/lib/node';
|
|
20
20
|
import { ServerAware } from '@celljs/web/lib/node';
|
|
21
21
|
import { WebExtensionCatalog } from './host-protocol.js';
|
|
22
22
|
import { TA_ACCESS } from './ta-access.js';
|
|
@@ -33,6 +33,19 @@ const WATCH_INTERVAL_MS = 2000;
|
|
|
33
33
|
let RelayBridge = RelayBridge_1 = class RelayBridge {
|
|
34
34
|
constructor() {
|
|
35
35
|
this.store = new RelayStore(TaBrand.agentDir());
|
|
36
|
+
/** The identity, friends and rooms of this Ta (RoomsBridge runs them): shares with Ta friends need them too. */
|
|
37
|
+
this.hubs = new RelayHubs({
|
|
38
|
+
store: new RelayHubFiles(TaBrand.agentDir()),
|
|
39
|
+
name: RelayHubFiles.userName,
|
|
40
|
+
relay: () => { var _a; return (_a = this.store.read().url) !== null && _a !== void 0 ? _a : RELAY_DEFAULT_URL; },
|
|
41
|
+
});
|
|
42
|
+
/** Content shared by links (TaExtensionHost.shares): kept in the agent directory, handed on by this server, a copy sealed on the relay if asked. */
|
|
43
|
+
this.shares = {
|
|
44
|
+
create: input => this.share(input),
|
|
45
|
+
list: async () => this.store.contents().map(content => this.info(content)),
|
|
46
|
+
remove: async (id) => this.unshare(id),
|
|
47
|
+
open: (link, password) => this.open(link, password),
|
|
48
|
+
};
|
|
36
49
|
}
|
|
37
50
|
get online() {
|
|
38
51
|
var _a;
|
|
@@ -62,10 +75,87 @@ let RelayBridge = RelayBridge_1 = class RelayBridge {
|
|
|
62
75
|
static async pack(root) {
|
|
63
76
|
return PackageArchive.pack(basename(root), PackageArchive.collect(root));
|
|
64
77
|
}
|
|
78
|
+
async share(input) {
|
|
79
|
+
if (input.data.length > RELAY_CONTENT_MAX_BYTES) {
|
|
80
|
+
throw new RelayContentError('large', `It is ${(input.data.length / 1024 / 1024).toFixed(1)} MB, more than the ${RELAY_CONTENT_MAX_BYTES / 1024 / 1024} MB a link takes.`);
|
|
81
|
+
}
|
|
82
|
+
const createdAt = Date.now();
|
|
83
|
+
const people = input.access === 'people' ? this.friendsOf(input.people) : undefined;
|
|
84
|
+
if (people && people.length === 0) {
|
|
85
|
+
throw new RelayContentError('people', 'Choose the Ta friends to share it with: none of them is a friend of this Ta.');
|
|
86
|
+
}
|
|
87
|
+
const { content, link } = await this.store.addContent({ ...input, createdAt, people, ...(people ? { identity: await this.hubs.identity() } : {}) }, createdAt);
|
|
88
|
+
if (content.offline) {
|
|
89
|
+
const key = RelayBytes.fromBase64(content.key);
|
|
90
|
+
try {
|
|
91
|
+
await RelayBlobClient.put({
|
|
92
|
+
relay: link.relay,
|
|
93
|
+
share: content.id,
|
|
94
|
+
token: content.offline.token,
|
|
95
|
+
authHash: await RelayContentUtil.sha256(await RelayContentUtil.authToken(key)),
|
|
96
|
+
expiresAt: content.offline.expiresAt,
|
|
97
|
+
bytes: await RelayContentUtil.seal(key, { kind: content.kind, title: content.title, type: content.type, createdAt, data: input.data }),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
this.store.removeContent(content.id);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
this.refresh();
|
|
106
|
+
return this.info(content);
|
|
107
|
+
}
|
|
108
|
+
async unshare(id) {
|
|
109
|
+
const { url } = this.store.read();
|
|
110
|
+
const content = this.store.removeContent(id);
|
|
111
|
+
this.refresh();
|
|
112
|
+
if (content === null || content === void 0 ? void 0 : content.offline) {
|
|
113
|
+
await RelayBlobClient.remove(url !== null && url !== void 0 ? url : RELAY_DEFAULT_URL, content.id, content.offline.token).catch(() => undefined);
|
|
114
|
+
}
|
|
115
|
+
return !!content;
|
|
116
|
+
}
|
|
117
|
+
async open(text, password) {
|
|
118
|
+
var _a;
|
|
119
|
+
const link = RelayContentUtil.parse(text);
|
|
120
|
+
const own = ((_a = this.store.read().host) === null || _a === void 0 ? void 0 : _a.id) === link.host ? this.store.content(link.share) : undefined;
|
|
121
|
+
const data = own && this.store.contentData(own);
|
|
122
|
+
if (own && data) {
|
|
123
|
+
return { kind: own.kind, title: own.title, type: own.type, createdAt: own.createdAt, data };
|
|
124
|
+
}
|
|
125
|
+
if (link.access === 'people') {
|
|
126
|
+
// Its key is made with the key of the one who shared it, one of this Ta's friends: else it is not for this Ta.
|
|
127
|
+
const owner = this.hubs.friends().find(friend => friend.id === link.owner);
|
|
128
|
+
if (!owner) {
|
|
129
|
+
throw new RelayContentError('people', 'Only the Ta friends it was shared with open it, in their own Ta.');
|
|
130
|
+
}
|
|
131
|
+
return RelayContentUtil.fetch(link, { people: { identity: await this.hubs.identity(), ownerBox: owner.box } });
|
|
132
|
+
}
|
|
133
|
+
return RelayContentUtil.fetch(link, { password });
|
|
134
|
+
}
|
|
135
|
+
/** The Ta friends of these ids, as this Ta keeps them. */
|
|
136
|
+
friendsOf(ids) {
|
|
137
|
+
const wanted = new Set(Array.isArray(ids) ? ids : []);
|
|
138
|
+
return this.hubs.friends().filter(friend => wanted.has(friend.id));
|
|
139
|
+
}
|
|
140
|
+
info(content) {
|
|
141
|
+
return {
|
|
142
|
+
id: content.id,
|
|
143
|
+
kind: content.kind,
|
|
144
|
+
title: content.title,
|
|
145
|
+
...(content.type ? { type: content.type } : {}),
|
|
146
|
+
access: content.access,
|
|
147
|
+
size: content.size,
|
|
148
|
+
createdAt: content.createdAt,
|
|
149
|
+
...(content.expiresAt ? { expiresAt: content.expiresAt } : {}),
|
|
150
|
+
offline: !!content.offline,
|
|
151
|
+
link: RelayContentUtil.link(this.store.contentLink(content)),
|
|
152
|
+
...(content.people ? { people: content.people.map(person => person.name) } : {}),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
65
155
|
start(server) {
|
|
66
156
|
const { port } = server.address();
|
|
67
157
|
const localUrl = `ws://127.0.0.1:${port}${TA_WEBSOCKET_PATH}?token=${encodeURIComponent(this.access.token)}`;
|
|
68
|
-
const host = new RelayHost({ store: this.store, localUrl, sharePackage: share => RelayBridge_1.pack(share.root) });
|
|
158
|
+
const host = new RelayHost({ store: this.store, localUrl, sharePackage: share => RelayBridge_1.pack(share.root), shareContent: true });
|
|
69
159
|
this.host = host;
|
|
70
160
|
host.start();
|
|
71
161
|
watchFile(this.store.file, { interval: WATCH_INTERVAL_MS }, () => host.refresh());
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
2
|
+
import { type RpcConnection } from '@celljs/rpc/lib/node';
|
|
3
|
+
import { type TaFriend, type TaIdentity, type TaRoomEvent, type TaRoomInfo, type TaRoomRequest, TaRoomServer, type TaRooms, type TaRoomValue, type TaRoomWatch } from '@celljs/ta-protocol';
|
|
4
|
+
import type { RelayHubs } from '@celljs/ta-relay/lib/node';
|
|
5
|
+
import { type RelayBridge } from './relay-bridge.js';
|
|
6
|
+
/** The id of {@link RoomsBridge}. */
|
|
7
|
+
export declare const ROOMS_BRIDGE: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* The rooms of this Ta (docs/design/ta-link.md 3): RelayHubs, connected to its rooms while ta serve runs, so that
|
|
10
|
+
* the owner hears who asks to join without a page open; the clients that watch hear what happens in them, and
|
|
11
|
+
* the server side of packages has them as TaExtensionHost.rooms.
|
|
12
|
+
*/
|
|
13
|
+
export declare class RoomsBridge implements ApplicationLifecycle<Application> {
|
|
14
|
+
protected readonly relay: RelayBridge;
|
|
15
|
+
/** The connections that watch, and what they hear: messages and the state too, or the state of some keys. */
|
|
16
|
+
protected readonly watchers: Map<RpcConnection, TaRoomWatch>;
|
|
17
|
+
get hubs(): RelayHubs;
|
|
18
|
+
readonly rooms: TaRooms;
|
|
19
|
+
onStart(): void;
|
|
20
|
+
onStop(): void;
|
|
21
|
+
/** `watch` undefined: no more. */
|
|
22
|
+
watch(connection: RpcConnection, watch: TaRoomWatch | undefined): void;
|
|
23
|
+
protected broadcast(event: TaRoomEvent): void;
|
|
24
|
+
protected static identity({ id, name }: TaIdentity): TaIdentity;
|
|
25
|
+
}
|
|
26
|
+
/** The rooms for clients (TaRoomServer): those of RoomsBridge, what goes wrong said as the errors of Ta. */
|
|
27
|
+
export declare class TaRoomServerImpl implements TaRoomServer {
|
|
28
|
+
protected readonly bridge: RoomsBridge;
|
|
29
|
+
protected get rooms(): TaRooms;
|
|
30
|
+
getIdentity(): Promise<TaIdentity>;
|
|
31
|
+
setName(name: string): Promise<TaIdentity>;
|
|
32
|
+
listRooms(): Promise<TaRoomInfo[]>;
|
|
33
|
+
createRoom(input: {
|
|
34
|
+
kind: string;
|
|
35
|
+
title: string;
|
|
36
|
+
view?: string;
|
|
37
|
+
}): Promise<TaRoomInfo>;
|
|
38
|
+
invite(room: string, options?: {
|
|
39
|
+
days?: number;
|
|
40
|
+
renew?: boolean;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
link: string;
|
|
43
|
+
expiresAt: number;
|
|
44
|
+
}>;
|
|
45
|
+
join(link: string): Promise<TaRoomInfo>;
|
|
46
|
+
listRequests(): Promise<TaRoomRequest[]>;
|
|
47
|
+
answer(room: string, ask: string, accept: boolean): Promise<void>;
|
|
48
|
+
removeMember(room: string, member: string): Promise<void>;
|
|
49
|
+
leave(room: string): Promise<void>;
|
|
50
|
+
send(room: string, data: unknown, to?: string): Promise<void>;
|
|
51
|
+
getState(room: string, prefix?: string): Promise<Record<string, TaRoomValue>>;
|
|
52
|
+
setState(room: string, key: string, value: unknown, version?: number): Promise<{
|
|
53
|
+
ok: boolean;
|
|
54
|
+
version: number;
|
|
55
|
+
}>;
|
|
56
|
+
listFriends(): Promise<TaFriend[]>;
|
|
57
|
+
removeFriend(id: string): Promise<boolean>;
|
|
58
|
+
watch(messages?: boolean, state?: string[]): Promise<void>;
|
|
59
|
+
unwatch(): Promise<void>;
|
|
60
|
+
}
|