@celljs/ta-protocol 4.9.1 → 4.10.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 +3 -3
- package/esm/common/location.d.ts +7 -0
- package/esm/common/location.js +20 -0
- package/esm/common/remote-protocol.d.ts +4 -1
- package/esm/common/ta-protocol.d.ts +44 -3
- package/esm/common/ta-protocol.js +51 -0
- package/esm/common/workspace-protocol.d.ts +2 -1
- package/lib/common/location.d.ts +7 -0
- package/lib/common/location.js +20 -0
- package/lib/common/remote-protocol.d.ts +4 -1
- package/lib/common/ta-protocol.d.ts +44 -3
- package/lib/common/ta-protocol.js +52 -1
- package/lib/common/workspace-protocol.d.ts +2 -1
- package/package.json +5 -5
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. `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).
|
|
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 (with the `sessionId` they had). A session closed while idle or by a restart also opens again by itself when any method is called with its old `sessionId`; only one closed with `closeSession`, or whose file is gone, gives `CELL_TA_SESSION_NOT_FOUND`. 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`, `working_message` (what an extension says the agent does, with pi's `setWorkingMessage`), 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` 没有对应方法时,本包的测试编译不过。`listSavedSessions` 列出 pi 会话文件里没打开的对话(空闲回收或重启前关掉的),用其 `sessionFile` 调 `openSession`
|
|
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`(预留)。
|
|
7
|
+
- `TaServer` 的方法除了 `openSession` `closeSession` `listSessions` `attach` `detach` `respondUi` `respondClientTool`,其余都是 pi RPC 模式的同名命令(snake_case 改 camelCase,见 `PiCommandMethod`),第一个参数是 `sessionId`,返回值与 pi 相同;pi 新增 RPC 命令而 `TaServer` 没有对应方法时,本包的测试编译不过。`listSavedSessions` 列出 pi 会话文件里没打开的对话(空闲回收或重启前关掉的),用其 `sessionFile` 调 `openSession` 即可重新打开(拿回它原来的 `sessionId`);空闲回收或重启关掉的会话,直接用原 `sessionId` 调任何方法也会自动重新打开,只有被 `closeSession` 关掉或会话文件已删的才报 `CELL_TA_SESSION_NOT_FOUND`;包按分组(`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`、`working_message`(扩展用 pi 的 `setWorkingMessage` 说明正在做什么)、`client_tool_request`(预留)。
|
|
9
9
|
- `prompt` / `steer` / `followUp` 带客户端生成的 `clientMessageId`:重发同一个 id 返回 `duplicate`,不会再执行;回执只表示已受理,回合结束以 `agent_settled` 事件为准。
|
|
10
10
|
- 目录(`cwd`)是位置:本机路径,或另一台机器的 `ssh://<host>/<绝对路径>`(`TaLocation` 解析、上下级、名字)。
|
|
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,或连接断开时还没收到结果。
|
|
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,或连接断开时还没收到结果。
|
package/esm/common/location.d.ts
CHANGED
|
@@ -47,4 +47,11 @@ export declare namespace TaLocation {
|
|
|
47
47
|
function child(location: string, name: string): string;
|
|
48
48
|
/** The last name of the path; the host for its home directory. */
|
|
49
49
|
function basename(location: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* What a location names under the home directory of its machine, as a shell and git read `~`: `~`,
|
|
52
|
+
* `~/src`, `ssh://<host>` and `ssh://<host>/~/src` are `''` and `'src'`; undefined for any other.
|
|
53
|
+
*/
|
|
54
|
+
function homeRelative(location: string): string | undefined;
|
|
55
|
+
/** Whether a location names its directory whole: not `~`, not relative, not the home of a host. */
|
|
56
|
+
function isAbsolute(location: string): boolean;
|
|
50
57
|
}
|
package/esm/common/location.js
CHANGED
|
@@ -165,6 +165,26 @@ export var TaLocation;
|
|
|
165
165
|
return name || (remote === null || remote === void 0 ? void 0 : remote.host) || location;
|
|
166
166
|
}
|
|
167
167
|
TaLocation.basename = basename;
|
|
168
|
+
/**
|
|
169
|
+
* What a location names under the home directory of its machine, as a shell and git read `~`: `~`,
|
|
170
|
+
* `~/src`, `ssh://<host>` and `ssh://<host>/~/src` are `''` and `'src'`; undefined for any other.
|
|
171
|
+
*/
|
|
172
|
+
function homeRelative(location) {
|
|
173
|
+
var _a;
|
|
174
|
+
const remote = parse(location);
|
|
175
|
+
const path = remote ? (remote.path ? remote.path.slice(1) : '~') : location;
|
|
176
|
+
const match = /^~(?:[\\/]+(.*))?$/.exec(path);
|
|
177
|
+
return match ? ((_a = match[1]) !== null && _a !== void 0 ? _a : '').replace(/[\\/]+$/, '') : undefined;
|
|
178
|
+
}
|
|
179
|
+
TaLocation.homeRelative = homeRelative;
|
|
180
|
+
/** Whether a location names its directory whole: not `~`, not relative, not the home of a host. */
|
|
181
|
+
function isAbsolute(location) {
|
|
182
|
+
if (homeRelative(location) !== undefined) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
|
|
186
|
+
}
|
|
187
|
+
TaLocation.isAbsolute = isAbsolute;
|
|
168
188
|
function parentPath(path) {
|
|
169
189
|
const trimmed = path.replace(/[\\/]+$/, '');
|
|
170
190
|
const at = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'));
|
|
@@ -67,7 +67,10 @@ export interface TaRemoteServer {
|
|
|
67
67
|
addHost(host: string): Promise<void>;
|
|
68
68
|
/** Disconnects from a host and drops it from the list; one of ~/.ssh/config stays there. */
|
|
69
69
|
removeHost(host: string): Promise<void>;
|
|
70
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* A location as the user wrote it, whole: `~/src`, `ssh://<host>` (its home), `ssh://<host>/~/src`, or a path
|
|
72
|
+
* relative to the default directory; one already whole as it is. Connects to the host when it needs its home.
|
|
73
|
+
*/
|
|
71
74
|
resolveLocation(location: string): Promise<string>;
|
|
72
75
|
/**
|
|
73
76
|
* A port of the machine of `cwd` on the machine of ta serve, for a page served there: the same port
|
|
@@ -38,6 +38,14 @@ export declare const TaErrorCode: {
|
|
|
38
38
|
readonly MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND';
|
|
39
39
|
readonly INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT';
|
|
40
40
|
readonly COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED';
|
|
41
|
+
/** Compacting found nothing to compact: the conversation is still short. */
|
|
42
|
+
readonly NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT';
|
|
43
|
+
/** Compacting found nothing to compact: nothing came after the last compaction. */
|
|
44
|
+
readonly ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED';
|
|
45
|
+
/** The session is answering or compacting, which has to end first. */
|
|
46
|
+
readonly SESSION_BUSY: 'CELL_TA_SESSION_BUSY';
|
|
47
|
+
/** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
|
|
48
|
+
readonly CANCELLED: 'CELL_TA_CANCELLED';
|
|
41
49
|
/** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
|
|
42
50
|
readonly NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN';
|
|
43
51
|
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
@@ -117,6 +125,8 @@ export interface TaSessionInfo {
|
|
|
117
125
|
sessionName?: string;
|
|
118
126
|
/** The first line of the first message of the user, which a list shows when the session has no name. */
|
|
119
127
|
firstMessage?: string;
|
|
128
|
+
/** The last thing said in it, by the user or the agent, on one line: what a list shows under its title. */
|
|
129
|
+
lastMessage?: string;
|
|
120
130
|
/** `<provider>/<model id>`. */
|
|
121
131
|
model?: string;
|
|
122
132
|
isStreaming: boolean;
|
|
@@ -140,6 +150,8 @@ export interface TaSavedSessionInfo {
|
|
|
140
150
|
sessionName?: string;
|
|
141
151
|
/** The first line of the first message of the user. */
|
|
142
152
|
firstMessage?: string;
|
|
153
|
+
/** TaSessionInfo.lastMessage. */
|
|
154
|
+
lastMessage?: string;
|
|
143
155
|
messageCount: number;
|
|
144
156
|
createdAt: number;
|
|
145
157
|
/** When the last message came; `createdAt` before the first. */
|
|
@@ -165,6 +177,24 @@ export declare namespace TaMessageContext {
|
|
|
165
177
|
/** The message without its context: what the user sees of it. */
|
|
166
178
|
function strip(message: string): string;
|
|
167
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* pi adds a line to the text of a message of the user for each image it took, for the model's sake: how big
|
|
182
|
+
* the image was before it made it smaller, and what it was converted from. Clients leave them out.
|
|
183
|
+
*/
|
|
184
|
+
export declare namespace TaImageNote {
|
|
185
|
+
/** The text without the notes of its images: what the user sees of it. */
|
|
186
|
+
function strip(text: string): string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
190
|
+
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
191
|
+
*/
|
|
192
|
+
export declare namespace TaAgentSummary {
|
|
193
|
+
/** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
|
|
194
|
+
function read(text: string): string | undefined;
|
|
195
|
+
/** The text without the summary it starts with. */
|
|
196
|
+
function strip(text: string): string;
|
|
197
|
+
}
|
|
168
198
|
/** A skill the user ran with `/skill:name`, as pi puts it in the message: the skill's file, then what the user wrote. */
|
|
169
199
|
export interface TaSkillUse {
|
|
170
200
|
name: string;
|
|
@@ -187,8 +217,11 @@ export declare namespace TaSkillUse {
|
|
|
187
217
|
*/
|
|
188
218
|
export interface TaPromptReceipt {
|
|
189
219
|
clientMessageId: string;
|
|
190
|
-
/**
|
|
191
|
-
|
|
220
|
+
/**
|
|
221
|
+
* `accepted`: it runs now; `queued`: after the current work; `duplicate`: this id was taken before;
|
|
222
|
+
* `handled`: a command or an extension took it, and no message of the user comes of it.
|
|
223
|
+
*/
|
|
224
|
+
status: 'accepted' | 'queued' | 'duplicate' | 'handled';
|
|
192
225
|
}
|
|
193
226
|
/** An extension's dialog was answered by another client, or expired. */
|
|
194
227
|
export interface TaUiRequestResolved {
|
|
@@ -218,6 +251,14 @@ export interface TaSessionReloaded {
|
|
|
218
251
|
export interface TaSessionClosed {
|
|
219
252
|
type: 'session_closed';
|
|
220
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* What the agent is doing while it works, from an extension (pi's `setWorkingMessage`), as starting the
|
|
256
|
+
* program of an external agent; none: the client's own words again.
|
|
257
|
+
*/
|
|
258
|
+
export interface TaWorkingMessage {
|
|
259
|
+
type: 'working_message';
|
|
260
|
+
message?: string;
|
|
261
|
+
}
|
|
221
262
|
/**
|
|
222
263
|
* The model called a tool of `clientTools`: a client that runs it takes it with `claimClientTool`, so
|
|
223
264
|
* that one client runs it, however many are attached, and answers with `respondClientTool`. When that
|
|
@@ -236,7 +277,7 @@ export interface TaClientToolResolved {
|
|
|
236
277
|
type: 'client_tool_resolved';
|
|
237
278
|
id: string;
|
|
238
279
|
}
|
|
239
|
-
export type TaEvent = JsonAgentSessionEvent | RpcExtensionUIRequest | TaUiRequestResolved | TaExtensionError | TaClientToolRequest | TaClientToolResolved | TaSessionReplaced | TaSessionReloaded | TaSessionClosed;
|
|
280
|
+
export type TaEvent = JsonAgentSessionEvent | RpcExtensionUIRequest | TaUiRequestResolved | TaExtensionError | TaClientToolRequest | TaClientToolResolved | TaSessionReplaced | TaSessionReloaded | TaSessionClosed | TaWorkingMessage;
|
|
240
281
|
export interface TaEventEnvelope {
|
|
241
282
|
sessionId: string;
|
|
242
283
|
/** Increases by one per event of the session. */
|
|
@@ -15,6 +15,14 @@ export const TaErrorCode = {
|
|
|
15
15
|
MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND',
|
|
16
16
|
INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT',
|
|
17
17
|
COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED',
|
|
18
|
+
/** Compacting found nothing to compact: the conversation is still short. */
|
|
19
|
+
NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT',
|
|
20
|
+
/** Compacting found nothing to compact: nothing came after the last compaction. */
|
|
21
|
+
ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED',
|
|
22
|
+
/** The session is answering or compacting, which has to end first. */
|
|
23
|
+
SESSION_BUSY: 'CELL_TA_SESSION_BUSY',
|
|
24
|
+
/** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
|
|
25
|
+
CANCELLED: 'CELL_TA_CANCELLED',
|
|
18
26
|
/** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
|
|
19
27
|
NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN',
|
|
20
28
|
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
@@ -53,6 +61,49 @@ export var TaMessageContext;
|
|
|
53
61
|
}
|
|
54
62
|
TaMessageContext.strip = strip;
|
|
55
63
|
})(TaMessageContext || (TaMessageContext = {}));
|
|
64
|
+
/**
|
|
65
|
+
* pi adds a line to the text of a message of the user for each image it took, for the model's sake: how big
|
|
66
|
+
* the image was before it made it smaller, and what it was converted from. Clients leave them out.
|
|
67
|
+
*/
|
|
68
|
+
export var TaImageNote;
|
|
69
|
+
(function (TaImageNote) {
|
|
70
|
+
const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
|
|
71
|
+
/** The text without the notes of its images: what the user sees of it. */
|
|
72
|
+
function strip(text) {
|
|
73
|
+
const lines = text.split('\n');
|
|
74
|
+
const kept = lines.filter(line => !NOTE.test(line.trim()));
|
|
75
|
+
if (kept.length === lines.length) {
|
|
76
|
+
return text;
|
|
77
|
+
}
|
|
78
|
+
return kept.join('\n').replace(/\n+$/, '').replace(/^\n+/, '');
|
|
79
|
+
}
|
|
80
|
+
TaImageNote.strip = strip;
|
|
81
|
+
})(TaImageNote || (TaImageNote = {}));
|
|
82
|
+
/**
|
|
83
|
+
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
84
|
+
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
85
|
+
*/
|
|
86
|
+
export var TaAgentSummary;
|
|
87
|
+
(function (TaAgentSummary) {
|
|
88
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
89
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
90
|
+
/** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
|
|
91
|
+
function read(text) {
|
|
92
|
+
if (!START.test(text)) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
return text
|
|
96
|
+
.replace(/<\/?(?:conversation_history_summary|summary)>/g, '')
|
|
97
|
+
.replace(/<\/?\w*$/, '')
|
|
98
|
+
.trim();
|
|
99
|
+
}
|
|
100
|
+
TaAgentSummary.read = read;
|
|
101
|
+
/** The text without the summary it starts with. */
|
|
102
|
+
function strip(text) {
|
|
103
|
+
return text.replace(BLOCK, '');
|
|
104
|
+
}
|
|
105
|
+
TaAgentSummary.strip = strip;
|
|
106
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
56
107
|
/** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
|
|
57
108
|
export var TaSkillUse;
|
|
58
109
|
(function (TaSkillUse) {
|
|
@@ -82,7 +82,8 @@ export interface TaWorkspaceServer {
|
|
|
82
82
|
* A URL of this server, under {@link TA_FILES_PATH}, that answers the bytes of a file of `cwd`, for
|
|
83
83
|
* what the page shows as it is: an image, a video, a page with what it loads next to it. The URL needs
|
|
84
84
|
* no token, so that a page loads the files beside it with relative URLs; each `cwd` has its own
|
|
85
|
-
* secret part.
|
|
85
|
+
* secret part. A file outside `cwd` (an absolute path an agent wrote) is served from the directory
|
|
86
|
+
* it is in, which has a secret part of its own. Pages are answered sandboxed: they run in an origin of their own, not the server's.
|
|
86
87
|
*/
|
|
87
88
|
fileUrl(path: string, cwd?: string): Promise<string>;
|
|
88
89
|
/** Paths of files whose name matches `query` loosely, best first; ignored files are left out. */
|
package/lib/common/location.d.ts
CHANGED
|
@@ -47,5 +47,12 @@ export declare namespace TaLocation {
|
|
|
47
47
|
function child(location: string, name: string): string;
|
|
48
48
|
/** The last name of the path; the host for its home directory. */
|
|
49
49
|
function basename(location: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* What a location names under the home directory of its machine, as a shell and git read `~`: `~`,
|
|
52
|
+
* `~/src`, `ssh://<host>` and `ssh://<host>/~/src` are `''` and `'src'`; undefined for any other.
|
|
53
|
+
*/
|
|
54
|
+
function homeRelative(location: string): string | undefined;
|
|
55
|
+
/** Whether a location names its directory whole: not `~`, not relative, not the home of a host. */
|
|
56
|
+
function isAbsolute(location: string): boolean;
|
|
50
57
|
}
|
|
51
58
|
//# sourceMappingURL=location.d.ts.map
|
package/lib/common/location.js
CHANGED
|
@@ -168,6 +168,26 @@ var TaLocation;
|
|
|
168
168
|
return name || (remote === null || remote === void 0 ? void 0 : remote.host) || location;
|
|
169
169
|
}
|
|
170
170
|
TaLocation.basename = basename;
|
|
171
|
+
/**
|
|
172
|
+
* What a location names under the home directory of its machine, as a shell and git read `~`: `~`,
|
|
173
|
+
* `~/src`, `ssh://<host>` and `ssh://<host>/~/src` are `''` and `'src'`; undefined for any other.
|
|
174
|
+
*/
|
|
175
|
+
function homeRelative(location) {
|
|
176
|
+
var _a;
|
|
177
|
+
const remote = parse(location);
|
|
178
|
+
const path = remote ? (remote.path ? remote.path.slice(1) : '~') : location;
|
|
179
|
+
const match = /^~(?:[\\/]+(.*))?$/.exec(path);
|
|
180
|
+
return match ? ((_a = match[1]) !== null && _a !== void 0 ? _a : '').replace(/[\\/]+$/, '') : undefined;
|
|
181
|
+
}
|
|
182
|
+
TaLocation.homeRelative = homeRelative;
|
|
183
|
+
/** Whether a location names its directory whole: not `~`, not relative, not the home of a host. */
|
|
184
|
+
function isAbsolute(location) {
|
|
185
|
+
if (homeRelative(location) !== undefined) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
|
|
189
|
+
}
|
|
190
|
+
TaLocation.isAbsolute = isAbsolute;
|
|
171
191
|
function parentPath(path) {
|
|
172
192
|
const trimmed = path.replace(/[\\/]+$/, '');
|
|
173
193
|
const at = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'));
|
|
@@ -67,7 +67,10 @@ export interface TaRemoteServer {
|
|
|
67
67
|
addHost(host: string): Promise<void>;
|
|
68
68
|
/** Disconnects from a host and drops it from the list; one of ~/.ssh/config stays there. */
|
|
69
69
|
removeHost(host: string): Promise<void>;
|
|
70
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* A location as the user wrote it, whole: `~/src`, `ssh://<host>` (its home), `ssh://<host>/~/src`, or a path
|
|
72
|
+
* relative to the default directory; one already whole as it is. Connects to the host when it needs its home.
|
|
73
|
+
*/
|
|
71
74
|
resolveLocation(location: string): Promise<string>;
|
|
72
75
|
/**
|
|
73
76
|
* A port of the machine of `cwd` on the machine of ta serve, for a page served there: the same port
|
|
@@ -38,6 +38,14 @@ export declare const TaErrorCode: {
|
|
|
38
38
|
readonly MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND';
|
|
39
39
|
readonly INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT';
|
|
40
40
|
readonly COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED';
|
|
41
|
+
/** Compacting found nothing to compact: the conversation is still short. */
|
|
42
|
+
readonly NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT';
|
|
43
|
+
/** Compacting found nothing to compact: nothing came after the last compaction. */
|
|
44
|
+
readonly ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED';
|
|
45
|
+
/** The session is answering or compacting, which has to end first. */
|
|
46
|
+
readonly SESSION_BUSY: 'CELL_TA_SESSION_BUSY';
|
|
47
|
+
/** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
|
|
48
|
+
readonly CANCELLED: 'CELL_TA_CANCELLED';
|
|
41
49
|
/** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
|
|
42
50
|
readonly NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN';
|
|
43
51
|
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
@@ -117,6 +125,8 @@ export interface TaSessionInfo {
|
|
|
117
125
|
sessionName?: string;
|
|
118
126
|
/** The first line of the first message of the user, which a list shows when the session has no name. */
|
|
119
127
|
firstMessage?: string;
|
|
128
|
+
/** The last thing said in it, by the user or the agent, on one line: what a list shows under its title. */
|
|
129
|
+
lastMessage?: string;
|
|
120
130
|
/** `<provider>/<model id>`. */
|
|
121
131
|
model?: string;
|
|
122
132
|
isStreaming: boolean;
|
|
@@ -140,6 +150,8 @@ export interface TaSavedSessionInfo {
|
|
|
140
150
|
sessionName?: string;
|
|
141
151
|
/** The first line of the first message of the user. */
|
|
142
152
|
firstMessage?: string;
|
|
153
|
+
/** TaSessionInfo.lastMessage. */
|
|
154
|
+
lastMessage?: string;
|
|
143
155
|
messageCount: number;
|
|
144
156
|
createdAt: number;
|
|
145
157
|
/** When the last message came; `createdAt` before the first. */
|
|
@@ -165,6 +177,24 @@ export declare namespace TaMessageContext {
|
|
|
165
177
|
/** The message without its context: what the user sees of it. */
|
|
166
178
|
function strip(message: string): string;
|
|
167
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* pi adds a line to the text of a message of the user for each image it took, for the model's sake: how big
|
|
182
|
+
* the image was before it made it smaller, and what it was converted from. Clients leave them out.
|
|
183
|
+
*/
|
|
184
|
+
export declare namespace TaImageNote {
|
|
185
|
+
/** The text without the notes of its images: what the user sees of it. */
|
|
186
|
+
function strip(text: string): string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
190
|
+
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
191
|
+
*/
|
|
192
|
+
export declare namespace TaAgentSummary {
|
|
193
|
+
/** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
|
|
194
|
+
function read(text: string): string | undefined;
|
|
195
|
+
/** The text without the summary it starts with. */
|
|
196
|
+
function strip(text: string): string;
|
|
197
|
+
}
|
|
168
198
|
/** A skill the user ran with `/skill:name`, as pi puts it in the message: the skill's file, then what the user wrote. */
|
|
169
199
|
export interface TaSkillUse {
|
|
170
200
|
name: string;
|
|
@@ -187,8 +217,11 @@ export declare namespace TaSkillUse {
|
|
|
187
217
|
*/
|
|
188
218
|
export interface TaPromptReceipt {
|
|
189
219
|
clientMessageId: string;
|
|
190
|
-
/**
|
|
191
|
-
|
|
220
|
+
/**
|
|
221
|
+
* `accepted`: it runs now; `queued`: after the current work; `duplicate`: this id was taken before;
|
|
222
|
+
* `handled`: a command or an extension took it, and no message of the user comes of it.
|
|
223
|
+
*/
|
|
224
|
+
status: 'accepted' | 'queued' | 'duplicate' | 'handled';
|
|
192
225
|
}
|
|
193
226
|
/** An extension's dialog was answered by another client, or expired. */
|
|
194
227
|
export interface TaUiRequestResolved {
|
|
@@ -218,6 +251,14 @@ export interface TaSessionReloaded {
|
|
|
218
251
|
export interface TaSessionClosed {
|
|
219
252
|
type: 'session_closed';
|
|
220
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* What the agent is doing while it works, from an extension (pi's `setWorkingMessage`), as starting the
|
|
256
|
+
* program of an external agent; none: the client's own words again.
|
|
257
|
+
*/
|
|
258
|
+
export interface TaWorkingMessage {
|
|
259
|
+
type: 'working_message';
|
|
260
|
+
message?: string;
|
|
261
|
+
}
|
|
221
262
|
/**
|
|
222
263
|
* The model called a tool of `clientTools`: a client that runs it takes it with `claimClientTool`, so
|
|
223
264
|
* that one client runs it, however many are attached, and answers with `respondClientTool`. When that
|
|
@@ -236,7 +277,7 @@ export interface TaClientToolResolved {
|
|
|
236
277
|
type: 'client_tool_resolved';
|
|
237
278
|
id: string;
|
|
238
279
|
}
|
|
239
|
-
export type TaEvent = JsonAgentSessionEvent | RpcExtensionUIRequest | TaUiRequestResolved | TaExtensionError | TaClientToolRequest | TaClientToolResolved | TaSessionReplaced | TaSessionReloaded | TaSessionClosed;
|
|
280
|
+
export type TaEvent = JsonAgentSessionEvent | RpcExtensionUIRequest | TaUiRequestResolved | TaExtensionError | TaClientToolRequest | TaClientToolResolved | TaSessionReplaced | TaSessionReloaded | TaSessionClosed | TaWorkingMessage;
|
|
240
281
|
export interface TaEventEnvelope {
|
|
241
282
|
sessionId: string;
|
|
242
283
|
/** Increases by one per event of the session. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TaSkillUse = exports.TaMessageContext = exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = exports.TA_SERVE_FILE = exports.TA_CLIENT_SERVICE = exports.TA_SERVER_SERVICE = exports.TA_WEBSOCKET_PATH = exports.TaClient = exports.TaServer = void 0;
|
|
3
|
+
exports.TaSkillUse = exports.TaAgentSummary = exports.TaImageNote = exports.TaMessageContext = exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = exports.TA_SERVE_FILE = exports.TA_CLIENT_SERVICE = exports.TA_SERVER_SERVICE = exports.TA_WEBSOCKET_PATH = exports.TaClient = exports.TaServer = void 0;
|
|
4
4
|
exports.TaServer = Symbol('TaServer');
|
|
5
5
|
exports.TaClient = Symbol('TaClient');
|
|
6
6
|
/** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
|
|
@@ -18,6 +18,14 @@ exports.TaErrorCode = {
|
|
|
18
18
|
MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND',
|
|
19
19
|
INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT',
|
|
20
20
|
COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED',
|
|
21
|
+
/** Compacting found nothing to compact: the conversation is still short. */
|
|
22
|
+
NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT',
|
|
23
|
+
/** Compacting found nothing to compact: nothing came after the last compaction. */
|
|
24
|
+
ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED',
|
|
25
|
+
/** The session is answering or compacting, which has to end first. */
|
|
26
|
+
SESSION_BUSY: 'CELL_TA_SESSION_BUSY',
|
|
27
|
+
/** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
|
|
28
|
+
CANCELLED: 'CELL_TA_CANCELLED',
|
|
21
29
|
/** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
|
|
22
30
|
NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN',
|
|
23
31
|
/** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
|
|
@@ -56,6 +64,49 @@ var TaMessageContext;
|
|
|
56
64
|
}
|
|
57
65
|
TaMessageContext.strip = strip;
|
|
58
66
|
})(TaMessageContext || (exports.TaMessageContext = TaMessageContext = {}));
|
|
67
|
+
/**
|
|
68
|
+
* pi adds a line to the text of a message of the user for each image it took, for the model's sake: how big
|
|
69
|
+
* the image was before it made it smaller, and what it was converted from. Clients leave them out.
|
|
70
|
+
*/
|
|
71
|
+
var TaImageNote;
|
|
72
|
+
(function (TaImageNote) {
|
|
73
|
+
const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
|
|
74
|
+
/** The text without the notes of its images: what the user sees of it. */
|
|
75
|
+
function strip(text) {
|
|
76
|
+
const lines = text.split('\n');
|
|
77
|
+
const kept = lines.filter(line => !NOTE.test(line.trim()));
|
|
78
|
+
if (kept.length === lines.length) {
|
|
79
|
+
return text;
|
|
80
|
+
}
|
|
81
|
+
return kept.join('\n').replace(/\n+$/, '').replace(/^\n+/, '');
|
|
82
|
+
}
|
|
83
|
+
TaImageNote.strip = strip;
|
|
84
|
+
})(TaImageNote || (exports.TaImageNote = TaImageNote = {}));
|
|
85
|
+
/**
|
|
86
|
+
* An external agent that compacts its own context says the summary it goes on from as text, in tags
|
|
87
|
+
* (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
|
|
88
|
+
*/
|
|
89
|
+
var TaAgentSummary;
|
|
90
|
+
(function (TaAgentSummary) {
|
|
91
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
92
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
93
|
+
/** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
|
|
94
|
+
function read(text) {
|
|
95
|
+
if (!START.test(text)) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return text
|
|
99
|
+
.replace(/<\/?(?:conversation_history_summary|summary)>/g, '')
|
|
100
|
+
.replace(/<\/?\w*$/, '')
|
|
101
|
+
.trim();
|
|
102
|
+
}
|
|
103
|
+
TaAgentSummary.read = read;
|
|
104
|
+
/** The text without the summary it starts with. */
|
|
105
|
+
function strip(text) {
|
|
106
|
+
return text.replace(BLOCK, '');
|
|
107
|
+
}
|
|
108
|
+
TaAgentSummary.strip = strip;
|
|
109
|
+
})(TaAgentSummary || (exports.TaAgentSummary = TaAgentSummary = {}));
|
|
59
110
|
/** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
|
|
60
111
|
var TaSkillUse;
|
|
61
112
|
(function (TaSkillUse) {
|
|
@@ -82,7 +82,8 @@ export interface TaWorkspaceServer {
|
|
|
82
82
|
* A URL of this server, under {@link TA_FILES_PATH}, that answers the bytes of a file of `cwd`, for
|
|
83
83
|
* what the page shows as it is: an image, a video, a page with what it loads next to it. The URL needs
|
|
84
84
|
* no token, so that a page loads the files beside it with relative URLs; each `cwd` has its own
|
|
85
|
-
* secret part.
|
|
85
|
+
* secret part. A file outside `cwd` (an absolute path an agent wrote) is served from the directory
|
|
86
|
+
* it is in, which has a secret part of its own. Pages are answered sandboxed: they run in an origin of their own, not the server's.
|
|
86
87
|
*/
|
|
87
88
|
fileUrl(path: string, cwd?: string): Promise<string>;
|
|
88
89
|
/** Paths of files whose name matches `query` loosely, best first; ignored files are left out. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-protocol",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"description": "The protocol between ta serve and its clients",
|
|
5
5
|
"homepage": "https://github.com/cellbang/cell",
|
|
6
6
|
"bugs": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@earendil-works/pi-coding-agent": "^1.5.
|
|
34
|
-
"@earendil-works/pi-ai": "^1.5.
|
|
33
|
+
"@earendil-works/pi-coding-agent": "^1.5.2",
|
|
34
|
+
"@earendil-works/pi-ai": "^1.5.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@earendil-works/pi-coding-agent": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@earendil-works/pi-coding-agent": "^1.5.
|
|
46
|
-
"@earendil-works/pi-ai": "^1.5.
|
|
45
|
+
"@earendil-works/pi-coding-agent": "^1.5.2",
|
|
46
|
+
"@earendil-works/pi-ai": "^1.5.2"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|