@celljs/ta-protocol 4.7.0 → 4.9.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 +2 -2
- package/README.md +2 -2
- package/esm/common/access-protocol.d.ts +73 -0
- package/esm/common/access-protocol.js +9 -0
- package/esm/common/gateway-protocol.d.ts +81 -0
- package/esm/common/gateway-protocol.js +3 -0
- package/esm/common/index.d.ts +2 -0
- package/esm/common/index.js +2 -0
- package/esm/common/location.d.ts +5 -0
- package/esm/common/location.js +12 -0
- package/esm/common/package-protocol.d.ts +60 -1
- package/esm/common/package-protocol.js +12 -0
- package/esm/common/relay-protocol.d.ts +17 -0
- package/esm/common/settings-protocol.d.ts +9 -0
- package/esm/common/ta-extension-host.d.ts +40 -3
- package/esm/common/ta-extension-host.js +13 -0
- package/esm/common/ta-protocol.d.ts +115 -4
- package/esm/common/ta-protocol.js +33 -0
- package/esm/common/workspace-protocol.d.ts +28 -1
- package/esm/common/workspace-protocol.js +21 -0
- package/lib/common/access-protocol.d.ts +74 -0
- package/lib/common/access-protocol.js +12 -0
- package/lib/common/gateway-protocol.d.ts +82 -0
- package/lib/common/gateway-protocol.js +6 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/common/location.d.ts +5 -0
- package/lib/common/location.js +12 -0
- package/lib/common/package-protocol.d.ts +60 -1
- package/lib/common/package-protocol.js +13 -1
- package/lib/common/relay-protocol.d.ts +17 -0
- package/lib/common/settings-protocol.d.ts +9 -0
- package/lib/common/ta-extension-host.d.ts +40 -3
- package/lib/common/ta-extension-host.js +14 -1
- package/lib/common/ta-protocol.d.ts +115 -4
- package/lib/common/ta-protocol.js +34 -1
- package/lib/common/workspace-protocol.d.ts +28 -1
- package/lib/common/workspace-protocol.js +22 -1
- package/package.json +3 -2
- package/esm/common/auth-protocol.js.map +0 -1
- package/esm/common/index.js.map +0 -1
- package/esm/common/location.js.map +0 -1
- package/esm/common/package-protocol.js.map +0 -1
- package/esm/common/pi-types.js.map +0 -1
- package/esm/common/relay-protocol.js.map +0 -1
- package/esm/common/remote-protocol.js.map +0 -1
- package/esm/common/settings-protocol.js.map +0 -1
- package/esm/common/ta-extension-host.js.map +0 -1
- package/esm/common/ta-protocol.js.map +0 -1
- package/esm/common/workspace-protocol.js.map +0 -1
- package/lib/common/auth-protocol.d.ts.map +0 -1
- package/lib/common/auth-protocol.js.map +0 -1
- package/lib/common/index.d.ts.map +0 -1
- package/lib/common/index.js.map +0 -1
- package/lib/common/location.d.ts.map +0 -1
- package/lib/common/location.js.map +0 -1
- package/lib/common/location.spec.d.ts +0 -2
- package/lib/common/location.spec.d.ts.map +0 -1
- package/lib/common/location.spec.js +0 -58
- package/lib/common/location.spec.js.map +0 -1
- package/lib/common/package-protocol.d.ts.map +0 -1
- package/lib/common/package-protocol.js.map +0 -1
- package/lib/common/pi-types.d.ts.map +0 -1
- package/lib/common/pi-types.js.map +0 -1
- package/lib/common/relay-protocol.d.ts.map +0 -1
- package/lib/common/relay-protocol.js.map +0 -1
- package/lib/common/remote-protocol.d.ts.map +0 -1
- package/lib/common/remote-protocol.js.map +0 -1
- package/lib/common/settings-protocol.d.ts.map +0 -1
- package/lib/common/settings-protocol.js.map +0 -1
- package/lib/common/ta-extension-host.d.ts.map +0 -1
- package/lib/common/ta-extension-host.js.map +0 -1
- package/lib/common/ta-protocol.d.ts.map +0 -1
- package/lib/common/ta-protocol.js.map +0 -1
- package/lib/common/ta-protocol.spec.d.ts +0 -2
- package/lib/common/ta-protocol.spec.d.ts.map +0 -1
- package/lib/common/ta-protocol.spec.js +0 -41
- package/lib/common/ta-protocol.spec.js.map +0 -1
- package/lib/common/workspace-protocol.d.ts.map +0 -1
- package/lib/common/workspace-protocol.js.map +0 -1
- package/src/common/auth-protocol.ts +0 -56
- package/src/common/index.ts +0 -10
- package/src/common/location.spec.ts +0 -62
- package/src/common/location.ts +0 -177
- package/src/common/package-protocol.ts +0 -99
- package/src/common/pi-types.ts +0 -11
- package/src/common/relay-protocol.ts +0 -28
- package/src/common/remote-protocol.ts +0 -76
- package/src/common/settings-protocol.ts +0 -66
- package/src/common/ta-extension-host.ts +0 -54
- package/src/common/ta-protocol.spec.ts +0 -48
- package/src/common/ta-protocol.ts +0 -347
- package/src/common/workspace-protocol.ts +0 -102
package/README.en.md
CHANGED
|
@@ -4,8 +4,8 @@ Protocol between `ta serve` and clients: types and constants only, with no pi or
|
|
|
4
4
|
|
|
5
5
|
- **Transport**: one WebSocket (`TA_WEBSOCKET_PATH`) with JSON-RPC 2.0 messages. Method names are `<service>/<method>`, and the server pushes `TaClient/onEvents` etc. HTTP-based calls are not offered; only workspace file bytes travel HTTP (`TA_FILES_PATH`, for images and iframes in pages to load via relative URLs).
|
|
6
6
|
- **Services**: `TaServer` (sessions—pi's RPC commands), `TaWorkspaceServer` (files and commands in directories), `TaTerminalServer` (terminals), `TaSettingsServer` (pi's `settings.json`), `TaPackageServer` (packages, web extensions, and package data), `TaAuthServer` (login to model services, same as pi's `/login` and `/logout`), `TaRelayServer` (paired devices via Relay, same as `ta pair`), `TaRemoteServer` (hosts for `ssh://` directories, ssh prompts, port forwarding). Capabilities outside sessions split into separate services by responsibility, not added to `TaServer`.
|
|
7
|
-
- **`TaServer` methods**: besides `openSession`, `closeSession`, `listSessions`, `attach`, `detach`, `respondUi`, and `respondClientTool`, the rest are pi RPC mode commands with the same name (snake_case → camelCase, see `PiCommandMethod`). The first parameter is `sessionId`, and return values match pi's; when pi adds an RPC command and `TaServer` lacks the method, this package's tests won't compile. `setWorkingDirectory` sets ta serve's working directory (`TaServerInfo.cwd`, used when clients don't specify one, persists across restarts). Session operations not in pi RPC: `forkToFile` (saves the forked session to a file, current session untouched, then open with `openSession`), `navigateTree` (same as pi's `/tree`, returns `editorText`), `fork` has an optional `position` (`at` keeps the selected item, like pi's `/clone` but optional for any item).
|
|
8
|
-
- **Events**: `TaEventEnvelope { sessionId, seq, event }`, where `event` is a pi JSON/RPC mode event or `extension_ui_request`. Ta adds only `ui_request_resolved`, `extension_error`, `session_replaced`, `session_closed`, and `client_tool_request` (reserved).
|
|
7
|
+
- **`TaServer` methods**: besides `openSession`, `closeSession`, `listSessions`, `attach`, `detach`, `respondUi`, and `respondClientTool`, the rest are pi RPC mode commands with the same name (snake_case → camelCase, see `PiCommandMethod`). The first parameter is `sessionId`, and return values match pi's; when pi adds an RPC command and `TaServer` lacks the method, this package's tests won't compile. `listSavedSessions` lists the conversations in pi's session files that are not open (closed while idle, or before a restart); `openSession` with their `sessionFile` opens them again. A session a package opened for its `group` gets a pi custom entry `ta-group` in its file, so the list carries its `group` and the package reopens it with its role; the role it was opened with (`appendSystemPrompt`) gets an entry `ta-role`, and opened again with only its `sessionFile` (a bot passing a message to a closed conversation of an agent) a session keeps the role and group written there. The page of the double keeps the session file of its conversation in the data `TA_DOUBLE_FILE` (`assistant.file` of `@celljs/ta-web`), by which packages on the server find the double. `setWorkingDirectory` sets ta serve's working directory (`TaServerInfo.cwd`, used when clients don't specify one, persists across restarts). Session operations not in pi RPC: `forkToFile` (saves the forked session to a file, current session untouched, then open with `openSession`), `navigateTree` (same as pi's `/tree`, returns `editorText`), `fork` has an optional `position` (`at` keeps the selected item, like pi's `/clone` but optional for any item).
|
|
8
|
+
- **Events**: `TaEventEnvelope { sessionId, seq, event }`, where `event` is a pi JSON/RPC mode event or `extension_ui_request`. Ta adds only `ui_request_resolved`, `extension_error`, `session_replaced`, `session_reloaded`, `session_closed`, and `client_tool_request` (reserved).
|
|
9
9
|
- **`prompt` / `steer` / `followUp`**: carry client-generated `clientMessageId`. Retrying with the same ID returns `duplicate` and doesn't re-execute. Receipt only means accepted; the round end is marked by the `agent_settled` event.
|
|
10
10
|
- **Locations** (`cwd`): a path is either local or on another machine in the form `ssh://<host>/<absolute-path>` (`TaLocation` parses, handles parent/child, and names).
|
|
11
11
|
- **Errors**: the JSON-RPC error code is `TA_RPC_ERROR_CODE`. The `data` field includes a stable `code` (`TaErrorCode`, e.g., `CELL_TA_SESSION_LOCKED`) and a one-line handling hint. When no model is available or the model service isn't signed in, the code is `CELL_TA_NOT_SIGNED_IN`; clients open the login page accordingly. `CELL_TA_CONNECTION_LOST` is client-generated: the call didn't reach ta serve, or the connection dropped before the result arrived.
|
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
- 传输:一条 WebSocket(`TA_WEBSOCKET_PATH`)上的 JSON-RPC 2.0,方法名是 `<服务>/<方法>`,服务端推送 `TaClient/onEvents` 等。不提供 HTTP 形式的调用;只有工作区文件的字节走 HTTP(`TA_FILES_PATH`,供页面里的图片、iframe 用相对地址加载)。
|
|
6
6
|
- 服务:`TaServer`(会话,即 pi 的 RPC 命令)、`TaWorkspaceServer`(目录里的文件与命令)、`TaTerminalServer`(终端)、`TaSettingsServer`(pi 的 `settings.json`)、`TaPackageServer`(包、Web 扩展与包的数据)、`TaAuthServer`(登录模型服务,同 pi 的 `/login` `/logout`)、`TaRelayServer`(经 Relay 配对设备,同 `ta pair`)、`TaRemoteServer`(`ssh://` 目录的主机、ssh 的提问、端口转发)。会话之外的能力按职责各成一个服务,不往 `TaServer` 里加。
|
|
7
|
-
- `TaServer` 的方法除了 `openSession` `closeSession` `listSessions` `attach` `detach` `respondUi` `respondClientTool`,其余都是 pi RPC 模式的同名命令(snake_case 改 camelCase,见 `PiCommandMethod`),第一个参数是 `sessionId`,返回值与 pi 相同;pi 新增 RPC 命令而 `TaServer` 没有对应方法时,本包的测试编译不过。`setWorkingDirectory` 设置 ta serve 的工作目录(`TaServerInfo.cwd`,客户端没指定目录时在这里开对话,跨重启保留)。pi RPC 没有的会话操作:`forkToFile`(把 fork 出的对话另存成会话文件,当前会话不动,再用 `openSession` 打开),`navigateTree`(同 pi 的 `/tree`,返回 `editorText`),`fork` 多一个可选的 `position`(`at` 保留所选条目,同 pi 的 `/clone` 但可选任意条目)。
|
|
8
|
-
- 事件:`TaEventEnvelope { sessionId, seq, event }`,`event` 是 pi JSON/RPC 模式的事件或 `extension_ui_request`;Ta 只多了 `ui_request_resolved`、`extension_error`、`session_replaced`、`session_closed`、`client_tool_request`(预留)。
|
|
7
|
+
- `TaServer` 的方法除了 `openSession` `closeSession` `listSessions` `attach` `detach` `respondUi` `respondClientTool`,其余都是 pi RPC 模式的同名命令(snake_case 改 camelCase,见 `PiCommandMethod`),第一个参数是 `sessionId`,返回值与 pi 相同;pi 新增 RPC 命令而 `TaServer` 没有对应方法时,本包的测试编译不过。`listSavedSessions` 列出 pi 会话文件里没打开的对话(空闲回收或重启前关掉的),用其 `sessionFile` 调 `openSession` 即可重新打开;包按分组(`group`)打开的会话会在文件里记一条 pi 的自定义条目 `ta-group`,列表里带上 `group`,由该包自己带着角色重新打开;打开时给的角色(`appendSystemPrompt`)也记一条 `ta-role`,只给 `sessionFile` 重新打开时(如机器人把消息转进一个已关闭的智能体对话)沿用记下的角色和分组。分身的页面把分身对话的会话文件存在包数据 `TA_DOUBLE_FILE`(`@celljs/ta-web` 的 `assistant.file`)里,服务端的包据此找到分身。`setWorkingDirectory` 设置 ta serve 的工作目录(`TaServerInfo.cwd`,客户端没指定目录时在这里开对话,跨重启保留)。pi RPC 没有的会话操作:`forkToFile`(把 fork 出的对话另存成会话文件,当前会话不动,再用 `openSession` 打开),`navigateTree`(同 pi 的 `/tree`,返回 `editorText`),`fork` 多一个可选的 `position`(`at` 保留所选条目,同 pi 的 `/clone` 但可选任意条目)。
|
|
8
|
+
- 事件:`TaEventEnvelope { sessionId, seq, event }`,`event` 是 pi JSON/RPC 模式的事件或 `extension_ui_request`;Ta 只多了 `ui_request_resolved`、`extension_error`、`session_replaced`、`session_reloaded`、`session_closed`、`client_tool_request`(预留)。
|
|
9
9
|
- `prompt` / `steer` / `followUp` 带客户端生成的 `clientMessageId`:重发同一个 id 返回 `duplicate`,不会再执行;回执只表示已受理,回合结束以 `agent_settled` 事件为准。
|
|
10
10
|
- 目录(`cwd`)是位置:本机路径,或另一台机器的 `ssh://<host>/<绝对路径>`(`TaLocation` 解析、上下级、名字)。
|
|
11
11
|
- 失败时 JSON-RPC 错误码为 `TA_RPC_ERROR_CODE`,`data` 里有稳定的 `code`(`TaErrorCode`,如 `CELL_TA_SESSION_LOCKED`)和一句处理建议 `hint`。没有可用的模型或模型服务没登录时是 `CELL_TA_NOT_SIGNED_IN`,客户端据此打开登录页。`CELL_TA_CONNECTION_LOST` 由客户端产生:调用没能送到 ta serve,或连接断开时还没收到结果。
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare const TaAccessServer: unique symbol;
|
|
2
|
+
export declare const TA_ACCESS_SERVICE = "TaAccessServer";
|
|
3
|
+
/**
|
|
4
|
+
* Where a browser signs in with an account: `GET` it for the ways this ta serve offers ({@link TaSignInWays}),
|
|
5
|
+
* `GET <path>/<provider>` to go to the provider, which comes back to `<path>/<provider>/callback`. These are
|
|
6
|
+
* pages the browser goes to, not calls: they need no token, and give one.
|
|
7
|
+
*/
|
|
8
|
+
export declare const TA_SIGN_IN_PATH = "/sign-in";
|
|
9
|
+
/** What a sign-in that did not let the browser in says in the fragment of the page it comes back to. */
|
|
10
|
+
export type TaSignInOutcome = 'denied' | 'failed';
|
|
11
|
+
/** A way to sign in: `github`, `google`, `wechat`, `oidc` (a provider of the operator's). */
|
|
12
|
+
export interface TaSignInProvider {
|
|
13
|
+
id: string;
|
|
14
|
+
/** What the button says: GitHub, Google, WeChat, or the name of the operator's provider. */
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
/** The answer of `GET` {@link TA_SIGN_IN_PATH}. */
|
|
18
|
+
export interface TaSignInWays {
|
|
19
|
+
providers: TaSignInProvider[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* An account let in: `github:<login>`, `google:<email>`, `wechat:<id>`, `oidc:<email>`; `google:*@<domain>`
|
|
23
|
+
* lets in every address of the domain. Those of `TA_ALLOWED_USERS` (`env`) are not removed here.
|
|
24
|
+
*/
|
|
25
|
+
export interface TaAccessAccount {
|
|
26
|
+
id: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
avatar?: string;
|
|
29
|
+
source: 'env' | 'added';
|
|
30
|
+
addedAt?: number;
|
|
31
|
+
}
|
|
32
|
+
/** Someone who signed in and is not let in yet: one tap lets them in. */
|
|
33
|
+
export interface TaAccessRequest {
|
|
34
|
+
id: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
avatar?: string;
|
|
37
|
+
at: number;
|
|
38
|
+
}
|
|
39
|
+
/** A browser signed in with an account; it stays signed in until it is signed out or its account removed. */
|
|
40
|
+
export interface TaAccessSignIn {
|
|
41
|
+
id: string;
|
|
42
|
+
account: string;
|
|
43
|
+
name?: string;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
lastUsedAt: number;
|
|
46
|
+
/** The user agent of the browser it signed in from. */
|
|
47
|
+
device?: string;
|
|
48
|
+
/** The connection that asks. */
|
|
49
|
+
current: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface TaAccessInfo {
|
|
52
|
+
providers: TaSignInProvider[];
|
|
53
|
+
/** May let accounts in and out: anyone in with ta serve, administrators behind a gateway. */
|
|
54
|
+
canManage?: boolean;
|
|
55
|
+
accounts: TaAccessAccount[];
|
|
56
|
+
requests: TaAccessRequest[];
|
|
57
|
+
signIns: TaAccessSignIn[];
|
|
58
|
+
}
|
|
59
|
+
/** Who may reach this ta serve with an account, for whoever is in (with the token, or an account let in). */
|
|
60
|
+
export interface TaAccessServer {
|
|
61
|
+
getAccess(): Promise<TaAccessInfo>;
|
|
62
|
+
/**
|
|
63
|
+
* Where the browser goes to sign in with `provider` and let that account in at once: the owner, in with
|
|
64
|
+
* the token, adds an account of their own. The link works once, for a few minutes.
|
|
65
|
+
*/
|
|
66
|
+
bindUrl(provider: string): Promise<string>;
|
|
67
|
+
/** Lets the account in (a request, or one typed); its request goes. */
|
|
68
|
+
allow(account: string, name?: string): Promise<void>;
|
|
69
|
+
dismiss(account: string): Promise<void>;
|
|
70
|
+
/** An account added here is no longer let in; its browsers are signed out at once. */
|
|
71
|
+
disallow(account: string): Promise<void>;
|
|
72
|
+
signOut(signInId: string): Promise<void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const TaAccessServer = Symbol('TaAccessServer');
|
|
2
|
+
export const TA_ACCESS_SERVICE = 'TaAccessServer';
|
|
3
|
+
/**
|
|
4
|
+
* Where a browser signs in with an account: `GET` it for the ways this ta serve offers ({@link TaSignInWays}),
|
|
5
|
+
* `GET <path>/<provider>` to go to the provider, which comes back to `<path>/<provider>/callback`. These are
|
|
6
|
+
* pages the browser goes to, not calls: they need no token, and give one.
|
|
7
|
+
*/
|
|
8
|
+
export const TA_SIGN_IN_PATH = '/sign-in';
|
|
9
|
+
//# sourceMappingURL=access-protocol.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export declare const TaGatewayServer: unique symbol;
|
|
2
|
+
export declare const TA_GATEWAY_SERVICE = "TaGatewayServer";
|
|
3
|
+
/**
|
|
4
|
+
* Where the Ta of a tenant runs: a sandbox of the gateway's provider (a container, a machine), or a Ta service
|
|
5
|
+
* of the user's own. `starting` until it answers; `failed` with `error` when it did not start.
|
|
6
|
+
*/
|
|
7
|
+
export type TaEnvironmentStatus = 'starting' | 'running' | 'stopped' | 'failed';
|
|
8
|
+
/** A provider of sandboxes of the gateway that a user may run their Ta in (`sandboxes.json`). */
|
|
9
|
+
export interface TaEnvironmentOption {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
/** `docker`, `command`, `local`, or that of a module. */
|
|
13
|
+
type: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The environment a user picks: one of the gateway's providers, or a Ta service of their own, reached at
|
|
17
|
+
* `url` (http or https, as `ta serve` there serves) with its access token, as a model of one's own is an
|
|
18
|
+
* endpoint and a key in pi's models.json.
|
|
19
|
+
*/
|
|
20
|
+
export type TaEnvironmentChoice = {
|
|
21
|
+
provider: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'ta';
|
|
24
|
+
url: string;
|
|
25
|
+
token: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
};
|
|
28
|
+
export interface TaEnvironmentInfo {
|
|
29
|
+
/** The provider of the gateway, or `own` for a Ta service of the user's. */
|
|
30
|
+
provider: string;
|
|
31
|
+
name: string;
|
|
32
|
+
status: TaEnvironmentStatus;
|
|
33
|
+
error?: string;
|
|
34
|
+
/** That of a Ta service of the user's; never its token. */
|
|
35
|
+
url?: string;
|
|
36
|
+
}
|
|
37
|
+
/** A tenant, as an administrator sees it: one per account, its own sandbox. */
|
|
38
|
+
export interface TaGatewayTenant {
|
|
39
|
+
id: string;
|
|
40
|
+
account: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
environment: TaEnvironmentInfo;
|
|
43
|
+
/** Browsers connected now. */
|
|
44
|
+
connections: number;
|
|
45
|
+
createdAt: number;
|
|
46
|
+
lastActiveAt?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface TaGatewayInfo {
|
|
49
|
+
account: {
|
|
50
|
+
id: string;
|
|
51
|
+
name?: string;
|
|
52
|
+
avatar?: string;
|
|
53
|
+
};
|
|
54
|
+
tenant: string;
|
|
55
|
+
environment: TaEnvironmentInfo;
|
|
56
|
+
/** The providers of the gateway one may pick. */
|
|
57
|
+
options: TaEnvironmentOption[];
|
|
58
|
+
/** Whether a Ta service of one's own may be used (`ownEnvironments` of sandboxes.json). */
|
|
59
|
+
own: boolean;
|
|
60
|
+
/** May let accounts in (TA_GATEWAY_ADMINS) and see the tenants. */
|
|
61
|
+
admin: boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* `ta gateway`: each account that signs in is a tenant with a Ta of its own, in a sandbox of its own, which
|
|
65
|
+
* the gateway starts on its first connection and to which it forwards the connection. This service is the
|
|
66
|
+
* gateway's own, on the same WebSocket: a Ta service without a gateway does not have it.
|
|
67
|
+
*/
|
|
68
|
+
export interface TaGatewayServer {
|
|
69
|
+
getGateway(): Promise<TaGatewayInfo>;
|
|
70
|
+
/**
|
|
71
|
+
* Runs the Ta of this tenant elsewhere from now on. Its sessions, model accounts and files are those of
|
|
72
|
+
* the environment: another starts without them. The connections of the tenant are closed, to connect again.
|
|
73
|
+
*/
|
|
74
|
+
setEnvironment(choice: TaEnvironmentChoice): Promise<TaGatewayInfo>;
|
|
75
|
+
/** Starts the environment again: stopped first when it runs. */
|
|
76
|
+
restartEnvironment(): Promise<TaGatewayInfo>;
|
|
77
|
+
/** For administrators. */
|
|
78
|
+
listTenants(): Promise<TaGatewayTenant[]>;
|
|
79
|
+
/** For administrators: stops the sandbox of a tenant, which starts again when it connects. */
|
|
80
|
+
stopTenant(tenantId: string): Promise<void>;
|
|
81
|
+
}
|
package/esm/common/index.d.ts
CHANGED
package/esm/common/index.js
CHANGED
package/esm/common/location.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ export declare namespace TaLocation {
|
|
|
33
33
|
function readHost(input: string): HostInput;
|
|
34
34
|
/** `ssh://<host><path>`; `path` absolute, or empty for the home directory. */
|
|
35
35
|
function ssh(host: string, path?: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* A host as a list shows it, short: the name of the machine, without the user, the port and the domain
|
|
38
|
+
* (`me@dev.example.com:2222` is `dev`); an address whole.
|
|
39
|
+
*/
|
|
40
|
+
function hostLabel(host: string): string;
|
|
36
41
|
/** The host of a remote location; undefined for this machine. */
|
|
37
42
|
function host(location: string): string | undefined;
|
|
38
43
|
/** The path inside its machine. */
|
package/esm/common/location.js
CHANGED
|
@@ -114,6 +114,18 @@ export var TaLocation;
|
|
|
114
114
|
return `${TaLocation.SSH}${host}${path ? normalize(path) : ''}`;
|
|
115
115
|
}
|
|
116
116
|
TaLocation.ssh = ssh;
|
|
117
|
+
/**
|
|
118
|
+
* A host as a list shows it, short: the name of the machine, without the user, the port and the domain
|
|
119
|
+
* (`me@dev.example.com:2222` is `dev`); an address whole.
|
|
120
|
+
*/
|
|
121
|
+
function hostLabel(host) {
|
|
122
|
+
const name = host
|
|
123
|
+
.replace(/^[^@]*@/, '')
|
|
124
|
+
.replace(/^\[(.*)\](?::\d+)?$/, '$1')
|
|
125
|
+
.replace(/^([^:]*):\d+$/, '$1');
|
|
126
|
+
return /^[\d.]+$/.test(name) || name.includes(':') ? name : name.split('.')[0] || name;
|
|
127
|
+
}
|
|
128
|
+
TaLocation.hostLabel = hostLabel;
|
|
117
129
|
/** The host of a remote location; undefined for this machine. */
|
|
118
130
|
function host(location) {
|
|
119
131
|
var _a;
|
|
@@ -17,8 +17,10 @@ export interface TaWebExtensionInfo {
|
|
|
17
17
|
/**
|
|
18
18
|
* `package`: a package of pi's `packages` setting (`ta install`). `directory`: a directory in `extensions/`.
|
|
19
19
|
* `builtin`: a package that comes with ta; it can be turned off (setPackageEnabled), not removed.
|
|
20
|
+
* `temporary`: opened without installing (openTemporaryPackage): only its web extension runs, started when
|
|
21
|
+
* one of its pages opens, and it goes after a while unused unless kept (TaTemporaryInfo).
|
|
20
22
|
*/
|
|
21
|
-
origin: 'package' | 'directory' | 'builtin';
|
|
23
|
+
origin: 'package' | 'directory' | 'builtin' | 'temporary';
|
|
22
24
|
/** False for a built-in package that is turned off; the others are always on. */
|
|
23
25
|
enabled: boolean;
|
|
24
26
|
/** The source in the `packages` setting, or the directory. */
|
|
@@ -27,15 +29,51 @@ export interface TaWebExtensionInfo {
|
|
|
27
29
|
entry: string;
|
|
28
30
|
/** Changes when the file changes. */
|
|
29
31
|
hash: string;
|
|
32
|
+
/** What the user calls its package, `pi.title` of its package.json. */
|
|
33
|
+
title?: TaPackageText;
|
|
34
|
+
/** The name of an icon of the web client's `pi.ui.icons`, `pi.icon` of its package.json. */
|
|
35
|
+
icon?: string;
|
|
36
|
+
/**
|
|
37
|
+
* When the web client runs it: `startup` (default) as the page loads; `open` once one of its pages
|
|
38
|
+
* opens, `pi.webActivation` of its package.json. A temporary one always on `open`.
|
|
39
|
+
*/
|
|
40
|
+
activation: 'startup' | 'open';
|
|
41
|
+
/** For a temporary package. */
|
|
42
|
+
temporary?: TaTemporaryInfo;
|
|
43
|
+
}
|
|
44
|
+
/** Where a temporary package came from: the market, a link someone shared, or an agent that made it for the user. */
|
|
45
|
+
export type TaTemporaryFrom = 'market' | 'link' | 'agent';
|
|
46
|
+
/** A package opened without installing (TaWebExtensionInfo.origin `temporary`). */
|
|
47
|
+
export interface TaTemporaryInfo {
|
|
48
|
+
/** What it was opened from: `npm:<name>`, `git:<repository>`, a URL of a repository, a path. */
|
|
49
|
+
source: string;
|
|
50
|
+
from: TaTemporaryFrom;
|
|
51
|
+
/** Milliseconds since the epoch. */
|
|
52
|
+
openedAt: number;
|
|
53
|
+
usedAt: number;
|
|
54
|
+
/** In the user's own (the launcher's `Mine`): never cleared for want of use. */
|
|
55
|
+
kept: boolean;
|
|
30
56
|
}
|
|
31
57
|
/** What a package holds: pi extensions, web extensions, skills, prompt templates, themes. */
|
|
32
58
|
export type TaPackageResource = 'extensions' | 'web' | 'skills' | 'prompts' | 'themes';
|
|
59
|
+
/** Text of a package for people, as `pi.title` and `pi.summary` of its package.json give it: one string, or one per language (`en`, `zh-CN`). */
|
|
60
|
+
export type TaPackageText = string | Readonly<Record<string, string>>;
|
|
61
|
+
export declare namespace TaPackageTextUtil {
|
|
62
|
+
/** The text in a language such as `zh-CN`: that language, else its first part (`zh`), else English, else the first there is. */
|
|
63
|
+
function pick(text: TaPackageText | undefined, language: string): string | undefined;
|
|
64
|
+
}
|
|
33
65
|
/** A pi package that Ta loads, whether it has a web extension or not. */
|
|
34
66
|
export interface TaPackageInfo {
|
|
35
67
|
/** Stable while the package stays where it is. */
|
|
36
68
|
id: string;
|
|
37
69
|
/** The `name` of its package.json, or the name of its directory. */
|
|
38
70
|
name: string;
|
|
71
|
+
/** What the user calls it, `pi.title` of its package.json; lists show {@link name} without it. */
|
|
72
|
+
title?: TaPackageText;
|
|
73
|
+
/** What it does and where it shows, in a sentence for the user, `pi.summary` of its package.json. */
|
|
74
|
+
summary?: TaPackageText;
|
|
75
|
+
/** The name of an icon of the web client's `pi.ui.icons`, `pi.icon` of its package.json. */
|
|
76
|
+
icon?: string;
|
|
39
77
|
description?: string;
|
|
40
78
|
version?: string;
|
|
41
79
|
scope: 'user' | 'project';
|
|
@@ -47,6 +85,8 @@ export interface TaPackageInfo {
|
|
|
47
85
|
source: string;
|
|
48
86
|
/** Its directory, on the machine of the server. */
|
|
49
87
|
root: string;
|
|
88
|
+
/** For a temporary package. */
|
|
89
|
+
temporary?: TaTemporaryInfo;
|
|
50
90
|
/** What it holds, by its package.json or, without `pi` there, by the directories pi looks in. */
|
|
51
91
|
resources: TaPackageResource[];
|
|
52
92
|
}
|
|
@@ -89,4 +129,23 @@ export interface TaPackageServer {
|
|
|
89
129
|
*/
|
|
90
130
|
getExtensionData(name: string, key: string, cwd?: string): Promise<unknown>;
|
|
91
131
|
setExtensionData(name: string, key: string, value: unknown, cwd?: string): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Opens a package without installing it, as a mini program is: fetched as `installPackage` does (a path is
|
|
134
|
+
* only noted), not added to pi's `packages` setting, so that only its web extension runs. Its web
|
|
135
|
+
* extensions, those of a package already installed or open from that source too.
|
|
136
|
+
*/
|
|
137
|
+
openTemporaryPackage(source: string, from: TaTemporaryFrom): Promise<TaWebExtensionInfo[]>;
|
|
138
|
+
/** A temporary package (by its id of listPackages or of one of its web extensions) was used now, or kept or not. */
|
|
139
|
+
updateTemporaryPackage(id: string, change: {
|
|
140
|
+
used?: boolean;
|
|
141
|
+
kept?: boolean;
|
|
142
|
+
}): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Installs a temporary package for the user: its source added to pi's `packages` setting, or, made by an
|
|
145
|
+
* agent, its directory moved to `extensions/`. Sessions pick it up on reload.
|
|
146
|
+
*/
|
|
147
|
+
installTemporaryPackage(id: string): Promise<void>;
|
|
148
|
+
/** After how many days unused a temporary package not kept goes; 0: never. */
|
|
149
|
+
getTemporaryRetention(): Promise<number>;
|
|
150
|
+
setTemporaryRetention(days: number): Promise<void>;
|
|
92
151
|
}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
export const TaPackageServer = Symbol('TaPackageServer');
|
|
2
2
|
export const TA_PACKAGE_SERVICE = 'TaPackageServer';
|
|
3
|
+
export var TaPackageTextUtil;
|
|
4
|
+
(function (TaPackageTextUtil) {
|
|
5
|
+
/** The text in a language such as `zh-CN`: that language, else its first part (`zh`), else English, else the first there is. */
|
|
6
|
+
function pick(text, language) {
|
|
7
|
+
var _a, _b, _c, _d;
|
|
8
|
+
if (text === undefined || typeof text === 'string') {
|
|
9
|
+
return text;
|
|
10
|
+
}
|
|
11
|
+
return (_d = (_c = (_b = (_a = text[language]) !== null && _a !== void 0 ? _a : text[language.split('-')[0]]) !== null && _b !== void 0 ? _b : text.en) !== null && _c !== void 0 ? _c : text['en-US']) !== null && _d !== void 0 ? _d : Object.values(text)[0];
|
|
12
|
+
}
|
|
13
|
+
TaPackageTextUtil.pick = pick;
|
|
14
|
+
})(TaPackageTextUtil || (TaPackageTextUtil = {}));
|
|
3
15
|
//# sourceMappingURL=package-protocol.js.map
|
|
@@ -25,4 +25,21 @@ export interface TaRelayServer {
|
|
|
25
25
|
}>;
|
|
26
26
|
/** The device can no longer reach this ta serve, at once. */
|
|
27
27
|
unpair(deviceId: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* A link of a package of this computer (by its id of listPackages, or of one of its web extensions), for
|
|
30
|
+
* another computer to open it without installing: its files go from here to there through the relay, end to
|
|
31
|
+
* end, while this ta serve runs and the link lasts; nothing is kept on the relay. The link of before while it lasts.
|
|
32
|
+
*/
|
|
33
|
+
sharePackage(id: string): Promise<TaPackageShare>;
|
|
34
|
+
/** The links of a package no longer work. */
|
|
35
|
+
unsharePackage(id: string): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/** A package handed on by a link (TaRelayServer.sharePackage). */
|
|
38
|
+
export interface TaPackageShare {
|
|
39
|
+
/** `https://<relay>/share#…`, the key in the fragment: what `openTemporaryPackage` takes on the other computer. */
|
|
40
|
+
link: string;
|
|
41
|
+
/** Milliseconds since the epoch. */
|
|
42
|
+
expiresAt: number;
|
|
43
|
+
/** The largest package that goes, in bytes. */
|
|
44
|
+
maxBytes: number;
|
|
28
45
|
}
|
|
@@ -28,6 +28,10 @@ export interface TaSettingsSnapshot {
|
|
|
28
28
|
projectTrusted: boolean;
|
|
29
29
|
/** `<provider>/<model id>` of the models with credentials, for the model setting. */
|
|
30
30
|
models: string[];
|
|
31
|
+
/** The names of those of `models` that have one other than their id. */
|
|
32
|
+
modelNames?: Record<string, string>;
|
|
33
|
+
/** By id, the names of the providers of `models` (`Kimi For Coding` for `kimi-coding`), as the lists of models group them. */
|
|
34
|
+
providerNames?: Record<string, string>;
|
|
31
35
|
}
|
|
32
36
|
/** The settings of ta in pi's `settings.json` files, on the same WebSocket as {@link TaServer}. */
|
|
33
37
|
export interface TaSettingsServer {
|
|
@@ -39,4 +43,9 @@ export interface TaSettingsServer {
|
|
|
39
43
|
* level are for new sessions.
|
|
40
44
|
*/
|
|
41
45
|
updateSettings(scope: TaSettingsScope, changes: Record<string, unknown>, cwd?: string): Promise<TaSettingsSnapshot>;
|
|
46
|
+
/**
|
|
47
|
+
* The language the user reads (`zh-CN`, `en-US`), for what the server and the pi packages it runs say:
|
|
48
|
+
* it is `TA_LANGUAGE` of the process of ta serve, which they read. The client that set it last wins.
|
|
49
|
+
*/
|
|
50
|
+
setLanguage(language: string): Promise<void>;
|
|
42
51
|
}
|
|
@@ -2,10 +2,10 @@ import type { TaPackageServer } from './package-protocol.js';
|
|
|
2
2
|
import type { TaServer } from './ta-protocol.js';
|
|
3
3
|
/**
|
|
4
4
|
* What `ta serve` gives the server side of a package: the sessions and the data of packages, in its own
|
|
5
|
-
* process, without a token. A subset of TaServer and TaPackageServer: it can open
|
|
6
|
-
*
|
|
5
|
+
* process, without a token. A subset of TaServer and TaPackageServer: it can open, drive, stop and close
|
|
6
|
+
* sessions (best those it opened: closing one takes it from every client), not remove anything.
|
|
7
7
|
*/
|
|
8
|
-
export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listSessions' | 'openSession' | 'setSessionName' | 'prompt' | 'followUp' | 'getState' | 'getLastAssistantText'>, Pick<TaPackageServer, 'getExtensionData' | 'setExtensionData' | 'listPackages'> {
|
|
8
|
+
export interface TaExtensionHost extends Pick<TaServer, 'getServerInfo' | 'listSessions' | 'openSession' | 'closeSession' | 'setSessionName' | 'prompt' | 'followUp' | 'abort' | 'getState' | 'getLastAssistantText'>, Pick<TaPackageServer, 'getExtensionData' | 'setExtensionData' | 'listPackages'> {
|
|
9
9
|
/** The agent directory of Ta (`~/.ta/agent`): its `extensions/` holds the packages of the user. */
|
|
10
10
|
readonly agentDir: string;
|
|
11
11
|
/** Where the conversation of a session file works, as clients name it (a path or an `ssh://` location), without opening it; undefined when it cannot be read. */
|
|
@@ -34,6 +34,28 @@ export type TaPackageHostFactory = (host: TaExtensionHost) => TaPackageService |
|
|
|
34
34
|
* and the extension should say its tools need `ta serve`.
|
|
35
35
|
*/
|
|
36
36
|
export declare const TA_HOST_EVENT = "ta:host";
|
|
37
|
+
/**
|
|
38
|
+
* The event of pi's `pi.events` by which an extension whose tools change files without pi's `edit` and
|
|
39
|
+
* `write` (another coding agent's own tools, ta-agents) says which, as soon as it knows and before the
|
|
40
|
+
* write if it can: `pi.events.emit(TA_FILE_WRITE_EVENT, file)`. The list of changed files (ta-changes)
|
|
41
|
+
* keeps what the file holds then.
|
|
42
|
+
*/
|
|
43
|
+
export declare const TA_FILE_WRITE_EVENT = "ta:file-write";
|
|
44
|
+
/**
|
|
45
|
+
* Where the web client keeps the session file of the double's conversation: in the data of packages
|
|
46
|
+
* (TaExtensionHost.getExtensionData), under this package name and key; a JSON string, empty before the
|
|
47
|
+
* double first opened. The server side of a package that sends to the double reads it there.
|
|
48
|
+
*/
|
|
49
|
+
export declare const TA_DOUBLE_FILE: {
|
|
50
|
+
readonly name: '@celljs/ta-web';
|
|
51
|
+
readonly key: 'assistant.file';
|
|
52
|
+
};
|
|
53
|
+
export interface TaFileWrite {
|
|
54
|
+
/** Absolute, on the machine where the session's tools work. */
|
|
55
|
+
path: string;
|
|
56
|
+
/** Its text before the change, when known (a diff of the agent); null: there was no file. */
|
|
57
|
+
before?: string | null;
|
|
58
|
+
}
|
|
37
59
|
export interface TaHostRequest {
|
|
38
60
|
/** The `name` of the package.json. */
|
|
39
61
|
name: string;
|
|
@@ -43,4 +65,19 @@ export interface TaHostAnswer {
|
|
|
43
65
|
host: TaExtensionHost;
|
|
44
66
|
/** What the module of `pi.host` of the package returned; undefined when it has none or failed. */
|
|
45
67
|
service?: TaPackageService;
|
|
68
|
+
/** The files of the session that asked, where its tools read and write. */
|
|
69
|
+
files: TaSessionFiles;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The files of a session where its tools work: on the machine of `ta serve`, or on the one of an
|
|
73
|
+
* `ssh://` directory (ExecEnvironment). Paths are those {@link resolve} gives.
|
|
74
|
+
*/
|
|
75
|
+
export interface TaSessionFiles {
|
|
76
|
+
/** The path a tool of the session (read, edit, write) works on for a path of its arguments. */
|
|
77
|
+
resolve(path: string): string;
|
|
78
|
+
/** The bytes of a file; undefined when there is no file there. */
|
|
79
|
+
read(path: string): Promise<Uint8Array | undefined>;
|
|
80
|
+
/** Writes a file, and the directories it needs. */
|
|
81
|
+
write(path: string, data: Uint8Array): Promise<void>;
|
|
82
|
+
remove(path: string): Promise<void>;
|
|
46
83
|
}
|
|
@@ -5,4 +5,17 @@
|
|
|
5
5
|
* and the extension should say its tools need `ta serve`.
|
|
6
6
|
*/
|
|
7
7
|
export const TA_HOST_EVENT = 'ta:host';
|
|
8
|
+
/**
|
|
9
|
+
* The event of pi's `pi.events` by which an extension whose tools change files without pi's `edit` and
|
|
10
|
+
* `write` (another coding agent's own tools, ta-agents) says which, as soon as it knows and before the
|
|
11
|
+
* write if it can: `pi.events.emit(TA_FILE_WRITE_EVENT, file)`. The list of changed files (ta-changes)
|
|
12
|
+
* keeps what the file holds then.
|
|
13
|
+
*/
|
|
14
|
+
export const TA_FILE_WRITE_EVENT = 'ta:file-write';
|
|
15
|
+
/**
|
|
16
|
+
* Where the web client keeps the session file of the double's conversation: in the data of packages
|
|
17
|
+
* (TaExtensionHost.getExtensionData), under this package name and key; a JSON string, empty before the
|
|
18
|
+
* double first opened. The server side of a package that sends to the double reads it there.
|
|
19
|
+
*/
|
|
20
|
+
export const TA_DOUBLE_FILE = { name: '@celljs/ta-web', key: 'assistant.file' };
|
|
8
21
|
//# sourceMappingURL=ta-extension-host.js.map
|