@celljs/ta-protocol 0.0.0-stage → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/esm/common/index.d.ts +2 -0
- package/esm/common/index.js +3 -0
- package/esm/common/index.js.map +1 -0
- package/esm/common/pi-types.d.ts +8 -0
- package/esm/common/pi-types.js +2 -0
- package/esm/common/pi-types.js.map +1 -0
- package/esm/common/ta-protocol.d.ts +198 -0
- package/esm/common/ta-protocol.js +21 -0
- package/esm/common/ta-protocol.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +19 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/pi-types.d.ts +9 -0
- package/lib/common/pi-types.d.ts.map +1 -0
- package/lib/common/pi-types.js +3 -0
- package/lib/common/pi-types.js.map +1 -0
- package/lib/common/ta-protocol.d.ts +199 -0
- package/lib/common/ta-protocol.d.ts.map +1 -0
- package/lib/common/ta-protocol.js +24 -0
- package/lib/common/ta-protocol.js.map +1 -0
- package/lib/common/ta-protocol.spec.d.ts +2 -0
- package/lib/common/ta-protocol.spec.d.ts.map +1 -0
- package/lib/common/ta-protocol.spec.js +18 -0
- package/lib/common/ta-protocol.spec.js.map +1 -0
- package/package.json +68 -4
- package/src/common/index.ts +2 -0
- package/src/common/pi-types.ts +10 -0
- package/src/common/ta-protocol.spec.ts +17 -0
- package/src/common/ta-protocol.ts +224 -0
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Cell - ta Protocol
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`ta serve` 与客户端之间的协议:只有类型和常量,不加载 pi 和 Node.js 模块,浏览器可用。
|
|
4
|
+
|
|
5
|
+
- 传输:JSON-RPC 2.0 over WebSocket(`TA_WEBSOCKET_PATH`),客户端调用 `TaServer/<方法>`,服务端推送 `TaClient/onEvents`。
|
|
6
|
+
- `TaServer` 的方法除了 `openSession` `closeSession` `listSessions` `attach` `detach` `respondUi` `respondClientTool`,其余都是 pi RPC 模式的同名命令(snake_case 改 camelCase),第一个参数是 `sessionId`,返回值与 pi 相同。
|
|
7
|
+
- 事件:`TaEventEnvelope { sessionId, seq, event }`,`event` 是 pi JSON/RPC 模式的事件或 `extension_ui_request`;ta 只多了 `ui_request_resolved`、`extension_error`、`session_replaced`、`session_closed`、`client_tool_request`(预留)。
|
|
8
|
+
- `prompt` / `steer` / `followUp` 带客户端生成的 `clientMessageId`:重发同一个 id 返回 `duplicate`,不会再执行;回执只表示已受理,回合结束以 `agent_settled` 事件为准。
|
|
9
|
+
- 失败时 JSON-RPC 错误码为 `TA_RPC_ERROR_CODE`,`data` 里有稳定的 `code`(`TaErrorCode`,如 `CELL_TA_SESSION_LOCKED`)和一句处理建议 `hint`。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type ImageContent = import('@earendil-works/pi-ai', { with: { 'resolution-mode': 'import' } }).ImageContent;
|
|
2
|
+
export type JsonAgentSessionEvent = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).JsonAgentSessionEvent;
|
|
3
|
+
export type RpcExtensionUIRequest = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcExtensionUIRequest;
|
|
4
|
+
export type RpcExtensionUIResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcExtensionUIResponse;
|
|
5
|
+
export type RpcResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcResponse;
|
|
6
|
+
export type RpcSessionState = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcSessionState;
|
|
7
|
+
export type AgentSession = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).AgentSession;
|
|
8
|
+
export type ThinkingLevel = AgentSession['thinkingLevel'];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-types.js","sourceRoot":"","sources":["../../src/common/pi-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type { ImageContent, JsonAgentSessionEvent, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, ThinkingLevel } from './pi-types.js';
|
|
2
|
+
export declare const TaServer: unique symbol;
|
|
3
|
+
export declare const TaClient: unique symbol;
|
|
4
|
+
/** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
|
|
5
|
+
export declare const TA_WEBSOCKET_PATH = "/api/ws";
|
|
6
|
+
export declare const TA_SERVER_SERVICE = "TaServer";
|
|
7
|
+
export declare const TA_CLIENT_SERVICE = "TaClient";
|
|
8
|
+
/** The file `ta serve` writes in the agent directory, readable only by its user. */
|
|
9
|
+
export declare const TA_SERVE_FILE = "serve.json";
|
|
10
|
+
/** The contents of {@link TA_SERVE_FILE}: how to reach the running `ta serve`. */
|
|
11
|
+
export interface TaServeInfo {
|
|
12
|
+
url: string;
|
|
13
|
+
token: string;
|
|
14
|
+
pid: number;
|
|
15
|
+
}
|
|
16
|
+
/** The stable `code` of each failure of a {@link TaServer} call. */
|
|
17
|
+
export declare const TaErrorCode: {
|
|
18
|
+
readonly SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND';
|
|
19
|
+
readonly SESSION_LOCKED: 'CELL_TA_SESSION_LOCKED';
|
|
20
|
+
readonly TOO_MANY_SESSIONS: 'CELL_TA_TOO_MANY_SESSIONS';
|
|
21
|
+
readonly MESSAGE_CONFLICT: 'CELL_TA_MESSAGE_CONFLICT';
|
|
22
|
+
readonly MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND';
|
|
23
|
+
readonly INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT';
|
|
24
|
+
readonly COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED';
|
|
25
|
+
};
|
|
26
|
+
export type TaErrorCode = (typeof TaErrorCode)[keyof typeof TaErrorCode];
|
|
27
|
+
/** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
|
|
28
|
+
export declare const TA_RPC_ERROR_CODE = -32050;
|
|
29
|
+
export interface TaErrorData {
|
|
30
|
+
code: TaErrorCode;
|
|
31
|
+
/** One sentence on what to do about it. */
|
|
32
|
+
hint: string;
|
|
33
|
+
}
|
|
34
|
+
/** A command name of pi's RPC mode (`get_state`, `follow_up`, ...). */
|
|
35
|
+
export type TaCommand = Extract<RpcResponse, {
|
|
36
|
+
success: true;
|
|
37
|
+
}>['command'];
|
|
38
|
+
/** What pi's RPC mode answers to a command. */
|
|
39
|
+
export type TaCommandResult<C extends TaCommand> = Extract<RpcResponse, {
|
|
40
|
+
command: C;
|
|
41
|
+
success: true;
|
|
42
|
+
}> extends {
|
|
43
|
+
data: infer D;
|
|
44
|
+
} ? D : undefined;
|
|
45
|
+
export interface TaClientToolDefinition {
|
|
46
|
+
name: string;
|
|
47
|
+
description: string;
|
|
48
|
+
/** JSON schema of the arguments. */
|
|
49
|
+
parameters: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
export interface TaOpenSessionOptions {
|
|
52
|
+
/** Working directory of the session, on the machine of the server. */
|
|
53
|
+
cwd: string;
|
|
54
|
+
/** Opens this session file; default: a new session. */
|
|
55
|
+
sessionFile?: string;
|
|
56
|
+
/** `<provider>/<model id>`; default: pi's settings. */
|
|
57
|
+
model?: string;
|
|
58
|
+
thinkingLevel?: ThinkingLevel;
|
|
59
|
+
/** Tools the client runs; fixed when the session opens, so the tool list stays stable for prompt caching. */
|
|
60
|
+
clientTools?: TaClientToolDefinition[];
|
|
61
|
+
}
|
|
62
|
+
export interface TaSessionInfo {
|
|
63
|
+
/** The id of this open session; stays the same through `newSession`, `switchSession` and `fork`. */
|
|
64
|
+
sessionId: string;
|
|
65
|
+
/** The id of the conversation pi has open now. */
|
|
66
|
+
piSessionId: string;
|
|
67
|
+
cwd: string;
|
|
68
|
+
sessionFile?: string;
|
|
69
|
+
sessionName?: string;
|
|
70
|
+
/** `<provider>/<model id>`. */
|
|
71
|
+
model?: string;
|
|
72
|
+
isStreaming: boolean;
|
|
73
|
+
messageCount: number;
|
|
74
|
+
/** Number of clients attached. */
|
|
75
|
+
attached: number;
|
|
76
|
+
createdAt: number;
|
|
77
|
+
}
|
|
78
|
+
export interface TaPromptInput {
|
|
79
|
+
message: string;
|
|
80
|
+
images?: ImageContent[];
|
|
81
|
+
/** Chosen by the client, unique per message: sending the same one again does not run it again. */
|
|
82
|
+
clientMessageId: string;
|
|
83
|
+
/** What to do when the agent is running; only for `prompt`. Default: `followUp`. */
|
|
84
|
+
streamingBehavior?: 'steer' | 'followUp';
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The server has taken the message; it says nothing about the run. A run is finished at the
|
|
88
|
+
* `agent_settled` event, when its history is on disk.
|
|
89
|
+
*/
|
|
90
|
+
export interface TaPromptReceipt {
|
|
91
|
+
clientMessageId: string;
|
|
92
|
+
/** `accepted`: it runs now; `queued`: after the current work; `duplicate`: this id was taken before. */
|
|
93
|
+
status: 'accepted' | 'queued' | 'duplicate';
|
|
94
|
+
}
|
|
95
|
+
/** An extension's dialog was answered by another client, or expired. */
|
|
96
|
+
export interface TaUiRequestResolved {
|
|
97
|
+
type: 'ui_request_resolved';
|
|
98
|
+
id: string;
|
|
99
|
+
}
|
|
100
|
+
/** An extension threw while handling an event. */
|
|
101
|
+
export interface TaExtensionError {
|
|
102
|
+
type: 'extension_error';
|
|
103
|
+
extensionPath: string;
|
|
104
|
+
event: string;
|
|
105
|
+
error: string;
|
|
106
|
+
}
|
|
107
|
+
/** The open session now shows another conversation (`newSession`, `switchSession`, `fork`, `clone`): read it again. */
|
|
108
|
+
export interface TaSessionReplaced {
|
|
109
|
+
type: 'session_replaced';
|
|
110
|
+
info: TaSessionInfo;
|
|
111
|
+
}
|
|
112
|
+
/** The session was closed; no more events come. */
|
|
113
|
+
export interface TaSessionClosed {
|
|
114
|
+
type: 'session_closed';
|
|
115
|
+
}
|
|
116
|
+
/** The model called a tool of `clientTools`: answer with `respondClientTool`. */
|
|
117
|
+
export interface TaClientToolRequest {
|
|
118
|
+
type: 'client_tool_request';
|
|
119
|
+
id: string;
|
|
120
|
+
toolName: string;
|
|
121
|
+
input: unknown;
|
|
122
|
+
}
|
|
123
|
+
export type TaEvent = JsonAgentSessionEvent | RpcExtensionUIRequest | TaUiRequestResolved | TaExtensionError | TaClientToolRequest | TaSessionReplaced | TaSessionClosed;
|
|
124
|
+
export interface TaEventEnvelope {
|
|
125
|
+
sessionId: string;
|
|
126
|
+
/** Increases by one per event of the session. */
|
|
127
|
+
seq: number;
|
|
128
|
+
event: TaEvent;
|
|
129
|
+
}
|
|
130
|
+
export interface TaAttachResult {
|
|
131
|
+
info: TaSessionInfo;
|
|
132
|
+
/** The events after `afterSeq`. */
|
|
133
|
+
events: TaEventEnvelope[];
|
|
134
|
+
/** The dialogs still waiting for an answer. */
|
|
135
|
+
pendingUi: RpcExtensionUIRequest[];
|
|
136
|
+
/** Seq of the last event of the session. */
|
|
137
|
+
lastSeq: number;
|
|
138
|
+
/** Some events after `afterSeq` are gone: read the conversation again with `getMessages`. */
|
|
139
|
+
gap: boolean;
|
|
140
|
+
}
|
|
141
|
+
export interface TaClientToolResult {
|
|
142
|
+
id: string;
|
|
143
|
+
output: string;
|
|
144
|
+
isError?: boolean;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* `ta serve`, over JSON-RPC 2.0 on a WebSocket. Besides opening, attaching and answering, each method
|
|
148
|
+
* is the command of pi's RPC mode with the same name in camelCase, on the open session `sessionId`.
|
|
149
|
+
*/
|
|
150
|
+
export interface TaServer {
|
|
151
|
+
openSession(options: TaOpenSessionOptions): Promise<TaSessionInfo>;
|
|
152
|
+
closeSession(sessionId: string): Promise<void>;
|
|
153
|
+
listSessions(): Promise<TaSessionInfo[]>;
|
|
154
|
+
/** Starts sending the events of the session to this connection. */
|
|
155
|
+
attach(sessionId: string, afterSeq?: number): Promise<TaAttachResult>;
|
|
156
|
+
detach(sessionId: string): Promise<void>;
|
|
157
|
+
/** Answers a dialog; false when it was answered before or expired. */
|
|
158
|
+
respondUi(sessionId: string, response: RpcExtensionUIResponse): Promise<boolean>;
|
|
159
|
+
/** Answers a call of a client tool; false when nobody waits for it. */
|
|
160
|
+
respondClientTool(sessionId: string, result: TaClientToolResult): Promise<boolean>;
|
|
161
|
+
prompt(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
162
|
+
steer(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
163
|
+
followUp(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
164
|
+
abort(sessionId: string): Promise<void>;
|
|
165
|
+
clearQueue(sessionId: string): Promise<TaCommandResult<'clear_queue'>>;
|
|
166
|
+
newSession(sessionId: string, parentSession?: string): Promise<TaCommandResult<'new_session'>>;
|
|
167
|
+
getState(sessionId: string): Promise<TaCommandResult<'get_state'>>;
|
|
168
|
+
setModel(sessionId: string, provider: string, modelId: string): Promise<TaCommandResult<'set_model'>>;
|
|
169
|
+
cycleModel(sessionId: string): Promise<TaCommandResult<'cycle_model'>>;
|
|
170
|
+
getAvailableModels(sessionId: string): Promise<TaCommandResult<'get_available_models'>>;
|
|
171
|
+
setThinkingLevel(sessionId: string, level: ThinkingLevel): Promise<void>;
|
|
172
|
+
cycleThinkingLevel(sessionId: string): Promise<TaCommandResult<'cycle_thinking_level'>>;
|
|
173
|
+
getAvailableThinkingLevels(sessionId: string): Promise<TaCommandResult<'get_available_thinking_levels'>>;
|
|
174
|
+
setSteeringMode(sessionId: string, mode: 'all' | 'one-at-a-time'): Promise<void>;
|
|
175
|
+
setFollowUpMode(sessionId: string, mode: 'all' | 'one-at-a-time'): Promise<void>;
|
|
176
|
+
compact(sessionId: string, customInstructions?: string): Promise<TaCommandResult<'compact'>>;
|
|
177
|
+
setAutoCompaction(sessionId: string, enabled: boolean): Promise<void>;
|
|
178
|
+
setAutoRetry(sessionId: string, enabled: boolean): Promise<void>;
|
|
179
|
+
abortRetry(sessionId: string): Promise<void>;
|
|
180
|
+
bash(sessionId: string, command: string, excludeFromContext?: boolean): Promise<TaCommandResult<'bash'>>;
|
|
181
|
+
abortBash(sessionId: string): Promise<void>;
|
|
182
|
+
getSessionStats(sessionId: string): Promise<TaCommandResult<'get_session_stats'>>;
|
|
183
|
+
exportHtml(sessionId: string, outputPath?: string): Promise<TaCommandResult<'export_html'>>;
|
|
184
|
+
switchSession(sessionId: string, sessionPath: string): Promise<TaCommandResult<'switch_session'>>;
|
|
185
|
+
fork(sessionId: string, entryId: string): Promise<TaCommandResult<'fork'>>;
|
|
186
|
+
clone(sessionId: string): Promise<TaCommandResult<'clone'>>;
|
|
187
|
+
getForkMessages(sessionId: string): Promise<TaCommandResult<'get_fork_messages'>>;
|
|
188
|
+
getEntries(sessionId: string, since?: string): Promise<TaCommandResult<'get_entries'>>;
|
|
189
|
+
getTree(sessionId: string): Promise<TaCommandResult<'get_tree'>>;
|
|
190
|
+
getLastAssistantText(sessionId: string): Promise<TaCommandResult<'get_last_assistant_text'>>;
|
|
191
|
+
setSessionName(sessionId: string, name: string): Promise<void>;
|
|
192
|
+
getMessages(sessionId: string): Promise<TaCommandResult<'get_messages'>>;
|
|
193
|
+
getCommands(sessionId: string): Promise<TaCommandResult<'get_commands'>>;
|
|
194
|
+
}
|
|
195
|
+
/** What a client implements. Events come in batches: one message per frame, however fast the model streams. */
|
|
196
|
+
export interface TaClient {
|
|
197
|
+
onEvents(events: TaEventEnvelope[]): Promise<void>;
|
|
198
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const TaServer = Symbol('TaServer');
|
|
2
|
+
export const TaClient = Symbol('TaClient');
|
|
3
|
+
/** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
|
|
4
|
+
export const TA_WEBSOCKET_PATH = '/api/ws';
|
|
5
|
+
export const TA_SERVER_SERVICE = 'TaServer';
|
|
6
|
+
export const TA_CLIENT_SERVICE = 'TaClient';
|
|
7
|
+
/** The file `ta serve` writes in the agent directory, readable only by its user. */
|
|
8
|
+
export const TA_SERVE_FILE = 'serve.json';
|
|
9
|
+
/** The stable `code` of each failure of a {@link TaServer} call. */
|
|
10
|
+
export const TaErrorCode = {
|
|
11
|
+
SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND',
|
|
12
|
+
SESSION_LOCKED: 'CELL_TA_SESSION_LOCKED',
|
|
13
|
+
TOO_MANY_SESSIONS: 'CELL_TA_TOO_MANY_SESSIONS',
|
|
14
|
+
MESSAGE_CONFLICT: 'CELL_TA_MESSAGE_CONFLICT',
|
|
15
|
+
MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND',
|
|
16
|
+
INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT',
|
|
17
|
+
COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED',
|
|
18
|
+
};
|
|
19
|
+
/** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
|
|
20
|
+
export const TA_RPC_ERROR_CODE = -32050;
|
|
21
|
+
//# sourceMappingURL=ta-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-protocol.js","sourceRoot":"","sources":["../../src/common/ta-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAE3C,oGAAoG;AACpG,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAC3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAC5C,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAE5C,oFAAoF;AACpF,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC;AAS1C,oEAAoE;AACpE,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,iBAAiB,EAAE,2BAA2B;IAC9C,cAAc,EAAE,wBAAwB;IACxC,iBAAiB,EAAE,2BAA2B;IAC9C,gBAAgB,EAAE,0BAA0B;IAC5C,eAAe,EAAE,yBAAyB;IAC1C,gBAAgB,EAAE,0BAA0B;IAC5C,cAAc,EAAE,wBAAwB;CAClC,CAAC;AAGX,yGAAyG;AACzG,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAK,CAAC"}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./pi-types"), exports);
|
|
18
|
+
__exportStar(require("./ta-protocol"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,gDAA8B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ImageContent = import('@earendil-works/pi-ai', { with: { 'resolution-mode': 'import' } }).ImageContent;
|
|
2
|
+
export type JsonAgentSessionEvent = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).JsonAgentSessionEvent;
|
|
3
|
+
export type RpcExtensionUIRequest = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcExtensionUIRequest;
|
|
4
|
+
export type RpcExtensionUIResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcExtensionUIResponse;
|
|
5
|
+
export type RpcResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcResponse;
|
|
6
|
+
export type RpcSessionState = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).RpcSessionState;
|
|
7
|
+
export type AgentSession = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).AgentSession;
|
|
8
|
+
export type ThinkingLevel = AgentSession['thinkingLevel'];
|
|
9
|
+
//# sourceMappingURL=pi-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-types.d.ts","sourceRoot":"","sources":["../../src/common/pi-types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAAG,OAAO,uBAAuB,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,YAAY,CAAC;AAClH,MAAM,MAAM,qBAAqB,GAAG,OAAO,iCAAiC,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,qBAAqB,CAAC;AAC9I,MAAM,MAAM,qBAAqB,GAAG,OAAO,iCAAiC,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,qBAAqB,CAAC;AAC9I,MAAM,MAAM,sBAAsB,GAAG,OAAO,iCAAiC,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,sBAAsB,CAAC;AAChJ,MAAM,MAAM,WAAW,GAAG,OAAO,iCAAiC,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,WAAW,CAAC;AAC1H,MAAM,MAAM,eAAe,GAAG,OAAO,iCAAiC,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,eAAe,CAAC;AAClI,MAAM,MAAM,YAAY,GAAG,OAAO,iCAAiC,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,YAAY,CAAC;AAC5H,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-types.js","sourceRoot":"","sources":["../../src/common/pi-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type { ImageContent, JsonAgentSessionEvent, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, ThinkingLevel } from './pi-types';
|
|
2
|
+
export declare const TaServer: unique symbol;
|
|
3
|
+
export declare const TaClient: unique symbol;
|
|
4
|
+
/** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
|
|
5
|
+
export declare const TA_WEBSOCKET_PATH = "/api/ws";
|
|
6
|
+
export declare const TA_SERVER_SERVICE = "TaServer";
|
|
7
|
+
export declare const TA_CLIENT_SERVICE = "TaClient";
|
|
8
|
+
/** The file `ta serve` writes in the agent directory, readable only by its user. */
|
|
9
|
+
export declare const TA_SERVE_FILE = "serve.json";
|
|
10
|
+
/** The contents of {@link TA_SERVE_FILE}: how to reach the running `ta serve`. */
|
|
11
|
+
export interface TaServeInfo {
|
|
12
|
+
url: string;
|
|
13
|
+
token: string;
|
|
14
|
+
pid: number;
|
|
15
|
+
}
|
|
16
|
+
/** The stable `code` of each failure of a {@link TaServer} call. */
|
|
17
|
+
export declare const TaErrorCode: {
|
|
18
|
+
readonly SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND';
|
|
19
|
+
readonly SESSION_LOCKED: 'CELL_TA_SESSION_LOCKED';
|
|
20
|
+
readonly TOO_MANY_SESSIONS: 'CELL_TA_TOO_MANY_SESSIONS';
|
|
21
|
+
readonly MESSAGE_CONFLICT: 'CELL_TA_MESSAGE_CONFLICT';
|
|
22
|
+
readonly MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND';
|
|
23
|
+
readonly INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT';
|
|
24
|
+
readonly COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED';
|
|
25
|
+
};
|
|
26
|
+
export type TaErrorCode = (typeof TaErrorCode)[keyof typeof TaErrorCode];
|
|
27
|
+
/** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
|
|
28
|
+
export declare const TA_RPC_ERROR_CODE = -32050;
|
|
29
|
+
export interface TaErrorData {
|
|
30
|
+
code: TaErrorCode;
|
|
31
|
+
/** One sentence on what to do about it. */
|
|
32
|
+
hint: string;
|
|
33
|
+
}
|
|
34
|
+
/** A command name of pi's RPC mode (`get_state`, `follow_up`, ...). */
|
|
35
|
+
export type TaCommand = Extract<RpcResponse, {
|
|
36
|
+
success: true;
|
|
37
|
+
}>['command'];
|
|
38
|
+
/** What pi's RPC mode answers to a command. */
|
|
39
|
+
export type TaCommandResult<C extends TaCommand> = Extract<RpcResponse, {
|
|
40
|
+
command: C;
|
|
41
|
+
success: true;
|
|
42
|
+
}> extends {
|
|
43
|
+
data: infer D;
|
|
44
|
+
} ? D : undefined;
|
|
45
|
+
export interface TaClientToolDefinition {
|
|
46
|
+
name: string;
|
|
47
|
+
description: string;
|
|
48
|
+
/** JSON schema of the arguments. */
|
|
49
|
+
parameters: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
export interface TaOpenSessionOptions {
|
|
52
|
+
/** Working directory of the session, on the machine of the server. */
|
|
53
|
+
cwd: string;
|
|
54
|
+
/** Opens this session file; default: a new session. */
|
|
55
|
+
sessionFile?: string;
|
|
56
|
+
/** `<provider>/<model id>`; default: pi's settings. */
|
|
57
|
+
model?: string;
|
|
58
|
+
thinkingLevel?: ThinkingLevel;
|
|
59
|
+
/** Tools the client runs; fixed when the session opens, so the tool list stays stable for prompt caching. */
|
|
60
|
+
clientTools?: TaClientToolDefinition[];
|
|
61
|
+
}
|
|
62
|
+
export interface TaSessionInfo {
|
|
63
|
+
/** The id of this open session; stays the same through `newSession`, `switchSession` and `fork`. */
|
|
64
|
+
sessionId: string;
|
|
65
|
+
/** The id of the conversation pi has open now. */
|
|
66
|
+
piSessionId: string;
|
|
67
|
+
cwd: string;
|
|
68
|
+
sessionFile?: string;
|
|
69
|
+
sessionName?: string;
|
|
70
|
+
/** `<provider>/<model id>`. */
|
|
71
|
+
model?: string;
|
|
72
|
+
isStreaming: boolean;
|
|
73
|
+
messageCount: number;
|
|
74
|
+
/** Number of clients attached. */
|
|
75
|
+
attached: number;
|
|
76
|
+
createdAt: number;
|
|
77
|
+
}
|
|
78
|
+
export interface TaPromptInput {
|
|
79
|
+
message: string;
|
|
80
|
+
images?: ImageContent[];
|
|
81
|
+
/** Chosen by the client, unique per message: sending the same one again does not run it again. */
|
|
82
|
+
clientMessageId: string;
|
|
83
|
+
/** What to do when the agent is running; only for `prompt`. Default: `followUp`. */
|
|
84
|
+
streamingBehavior?: 'steer' | 'followUp';
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The server has taken the message; it says nothing about the run. A run is finished at the
|
|
88
|
+
* `agent_settled` event, when its history is on disk.
|
|
89
|
+
*/
|
|
90
|
+
export interface TaPromptReceipt {
|
|
91
|
+
clientMessageId: string;
|
|
92
|
+
/** `accepted`: it runs now; `queued`: after the current work; `duplicate`: this id was taken before. */
|
|
93
|
+
status: 'accepted' | 'queued' | 'duplicate';
|
|
94
|
+
}
|
|
95
|
+
/** An extension's dialog was answered by another client, or expired. */
|
|
96
|
+
export interface TaUiRequestResolved {
|
|
97
|
+
type: 'ui_request_resolved';
|
|
98
|
+
id: string;
|
|
99
|
+
}
|
|
100
|
+
/** An extension threw while handling an event. */
|
|
101
|
+
export interface TaExtensionError {
|
|
102
|
+
type: 'extension_error';
|
|
103
|
+
extensionPath: string;
|
|
104
|
+
event: string;
|
|
105
|
+
error: string;
|
|
106
|
+
}
|
|
107
|
+
/** The open session now shows another conversation (`newSession`, `switchSession`, `fork`, `clone`): read it again. */
|
|
108
|
+
export interface TaSessionReplaced {
|
|
109
|
+
type: 'session_replaced';
|
|
110
|
+
info: TaSessionInfo;
|
|
111
|
+
}
|
|
112
|
+
/** The session was closed; no more events come. */
|
|
113
|
+
export interface TaSessionClosed {
|
|
114
|
+
type: 'session_closed';
|
|
115
|
+
}
|
|
116
|
+
/** The model called a tool of `clientTools`: answer with `respondClientTool`. */
|
|
117
|
+
export interface TaClientToolRequest {
|
|
118
|
+
type: 'client_tool_request';
|
|
119
|
+
id: string;
|
|
120
|
+
toolName: string;
|
|
121
|
+
input: unknown;
|
|
122
|
+
}
|
|
123
|
+
export type TaEvent = JsonAgentSessionEvent | RpcExtensionUIRequest | TaUiRequestResolved | TaExtensionError | TaClientToolRequest | TaSessionReplaced | TaSessionClosed;
|
|
124
|
+
export interface TaEventEnvelope {
|
|
125
|
+
sessionId: string;
|
|
126
|
+
/** Increases by one per event of the session. */
|
|
127
|
+
seq: number;
|
|
128
|
+
event: TaEvent;
|
|
129
|
+
}
|
|
130
|
+
export interface TaAttachResult {
|
|
131
|
+
info: TaSessionInfo;
|
|
132
|
+
/** The events after `afterSeq`. */
|
|
133
|
+
events: TaEventEnvelope[];
|
|
134
|
+
/** The dialogs still waiting for an answer. */
|
|
135
|
+
pendingUi: RpcExtensionUIRequest[];
|
|
136
|
+
/** Seq of the last event of the session. */
|
|
137
|
+
lastSeq: number;
|
|
138
|
+
/** Some events after `afterSeq` are gone: read the conversation again with `getMessages`. */
|
|
139
|
+
gap: boolean;
|
|
140
|
+
}
|
|
141
|
+
export interface TaClientToolResult {
|
|
142
|
+
id: string;
|
|
143
|
+
output: string;
|
|
144
|
+
isError?: boolean;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* `ta serve`, over JSON-RPC 2.0 on a WebSocket. Besides opening, attaching and answering, each method
|
|
148
|
+
* is the command of pi's RPC mode with the same name in camelCase, on the open session `sessionId`.
|
|
149
|
+
*/
|
|
150
|
+
export interface TaServer {
|
|
151
|
+
openSession(options: TaOpenSessionOptions): Promise<TaSessionInfo>;
|
|
152
|
+
closeSession(sessionId: string): Promise<void>;
|
|
153
|
+
listSessions(): Promise<TaSessionInfo[]>;
|
|
154
|
+
/** Starts sending the events of the session to this connection. */
|
|
155
|
+
attach(sessionId: string, afterSeq?: number): Promise<TaAttachResult>;
|
|
156
|
+
detach(sessionId: string): Promise<void>;
|
|
157
|
+
/** Answers a dialog; false when it was answered before or expired. */
|
|
158
|
+
respondUi(sessionId: string, response: RpcExtensionUIResponse): Promise<boolean>;
|
|
159
|
+
/** Answers a call of a client tool; false when nobody waits for it. */
|
|
160
|
+
respondClientTool(sessionId: string, result: TaClientToolResult): Promise<boolean>;
|
|
161
|
+
prompt(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
162
|
+
steer(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
163
|
+
followUp(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
164
|
+
abort(sessionId: string): Promise<void>;
|
|
165
|
+
clearQueue(sessionId: string): Promise<TaCommandResult<'clear_queue'>>;
|
|
166
|
+
newSession(sessionId: string, parentSession?: string): Promise<TaCommandResult<'new_session'>>;
|
|
167
|
+
getState(sessionId: string): Promise<TaCommandResult<'get_state'>>;
|
|
168
|
+
setModel(sessionId: string, provider: string, modelId: string): Promise<TaCommandResult<'set_model'>>;
|
|
169
|
+
cycleModel(sessionId: string): Promise<TaCommandResult<'cycle_model'>>;
|
|
170
|
+
getAvailableModels(sessionId: string): Promise<TaCommandResult<'get_available_models'>>;
|
|
171
|
+
setThinkingLevel(sessionId: string, level: ThinkingLevel): Promise<void>;
|
|
172
|
+
cycleThinkingLevel(sessionId: string): Promise<TaCommandResult<'cycle_thinking_level'>>;
|
|
173
|
+
getAvailableThinkingLevels(sessionId: string): Promise<TaCommandResult<'get_available_thinking_levels'>>;
|
|
174
|
+
setSteeringMode(sessionId: string, mode: 'all' | 'one-at-a-time'): Promise<void>;
|
|
175
|
+
setFollowUpMode(sessionId: string, mode: 'all' | 'one-at-a-time'): Promise<void>;
|
|
176
|
+
compact(sessionId: string, customInstructions?: string): Promise<TaCommandResult<'compact'>>;
|
|
177
|
+
setAutoCompaction(sessionId: string, enabled: boolean): Promise<void>;
|
|
178
|
+
setAutoRetry(sessionId: string, enabled: boolean): Promise<void>;
|
|
179
|
+
abortRetry(sessionId: string): Promise<void>;
|
|
180
|
+
bash(sessionId: string, command: string, excludeFromContext?: boolean): Promise<TaCommandResult<'bash'>>;
|
|
181
|
+
abortBash(sessionId: string): Promise<void>;
|
|
182
|
+
getSessionStats(sessionId: string): Promise<TaCommandResult<'get_session_stats'>>;
|
|
183
|
+
exportHtml(sessionId: string, outputPath?: string): Promise<TaCommandResult<'export_html'>>;
|
|
184
|
+
switchSession(sessionId: string, sessionPath: string): Promise<TaCommandResult<'switch_session'>>;
|
|
185
|
+
fork(sessionId: string, entryId: string): Promise<TaCommandResult<'fork'>>;
|
|
186
|
+
clone(sessionId: string): Promise<TaCommandResult<'clone'>>;
|
|
187
|
+
getForkMessages(sessionId: string): Promise<TaCommandResult<'get_fork_messages'>>;
|
|
188
|
+
getEntries(sessionId: string, since?: string): Promise<TaCommandResult<'get_entries'>>;
|
|
189
|
+
getTree(sessionId: string): Promise<TaCommandResult<'get_tree'>>;
|
|
190
|
+
getLastAssistantText(sessionId: string): Promise<TaCommandResult<'get_last_assistant_text'>>;
|
|
191
|
+
setSessionName(sessionId: string, name: string): Promise<void>;
|
|
192
|
+
getMessages(sessionId: string): Promise<TaCommandResult<'get_messages'>>;
|
|
193
|
+
getCommands(sessionId: string): Promise<TaCommandResult<'get_commands'>>;
|
|
194
|
+
}
|
|
195
|
+
/** What a client implements. Events come in batches: one message per frame, however fast the model streams. */
|
|
196
|
+
export interface TaClient {
|
|
197
|
+
onEvents(events: TaEventEnvelope[]): Promise<void>;
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=ta-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-protocol.d.ts","sourceRoot":"","sources":["../../src/common/ta-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEjJ,eAAO,MAAM,QAAQ,eAAqB,CAAC;AAC3C,eAAO,MAAM,QAAQ,eAAqB,CAAC;AAE3C,oGAAoG;AACpG,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAC3C,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAC5C,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAE5C,oFAAoF;AACpF,eAAO,MAAM,aAAa,eAAe,CAAC;AAE1C,kFAAkF;AAClF,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACf;AAED,oEAAoE;AACpE,eAAO,MAAM,WAAW;aACpB,iBAAiB,EAAE,2BA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AO,CAAC,IAAI,CAAC,CAAC;CACtD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TA_RPC_ERROR_CODE = 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
|
+
exports.TaServer = Symbol('TaServer');
|
|
5
|
+
exports.TaClient = Symbol('TaClient');
|
|
6
|
+
/** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
|
|
7
|
+
exports.TA_WEBSOCKET_PATH = '/api/ws';
|
|
8
|
+
exports.TA_SERVER_SERVICE = 'TaServer';
|
|
9
|
+
exports.TA_CLIENT_SERVICE = 'TaClient';
|
|
10
|
+
/** The file `ta serve` writes in the agent directory, readable only by its user. */
|
|
11
|
+
exports.TA_SERVE_FILE = 'serve.json';
|
|
12
|
+
/** The stable `code` of each failure of a {@link TaServer} call. */
|
|
13
|
+
exports.TaErrorCode = {
|
|
14
|
+
SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND',
|
|
15
|
+
SESSION_LOCKED: 'CELL_TA_SESSION_LOCKED',
|
|
16
|
+
TOO_MANY_SESSIONS: 'CELL_TA_TOO_MANY_SESSIONS',
|
|
17
|
+
MESSAGE_CONFLICT: 'CELL_TA_MESSAGE_CONFLICT',
|
|
18
|
+
MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND',
|
|
19
|
+
INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT',
|
|
20
|
+
COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED',
|
|
21
|
+
};
|
|
22
|
+
/** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
|
|
23
|
+
exports.TA_RPC_ERROR_CODE = -32050;
|
|
24
|
+
//# sourceMappingURL=ta-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-protocol.js","sourceRoot":"","sources":["../../src/common/ta-protocol.ts"],"names":[],"mappings":";;;AAEa,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9B,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAE3C,oGAAoG;AACvF,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAC9B,QAAA,iBAAiB,GAAG,UAAU,CAAC;AAC/B,QAAA,iBAAiB,GAAG,UAAU,CAAC;AAE5C,oFAAoF;AACvE,QAAA,aAAa,GAAG,YAAY,CAAC;AAS1C,oEAAoE;AACvD,QAAA,WAAW,GAAG;IACvB,iBAAiB,EAAE,2BAA2B;IAC9C,cAAc,EAAE,wBAAwB;IACxC,iBAAiB,EAAE,2BAA2B;IAC9C,gBAAgB,EAAE,0BAA0B;IAC5C,eAAe,EAAE,yBAAyB;IAC1C,gBAAgB,EAAE,0BAA0B;IAC5C,cAAc,EAAE,wBAAwB;CAClC,CAAC;AAGX,yGAAyG;AAC5F,QAAA,iBAAiB,GAAG,CAAC,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-protocol.spec.d.ts","sourceRoot":"","sources":["../../src/common/ta-protocol.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const ta_protocol_1 = require("./ta-protocol");
|
|
5
|
+
(0, bun_test_1.describe)('ta protocol', () => {
|
|
6
|
+
(0, bun_test_1.it)('names each failure with a distinct CELL_TA_ code', () => {
|
|
7
|
+
const codes = Object.values(ta_protocol_1.TaErrorCode);
|
|
8
|
+
(0, bun_test_1.expect)(new Set(codes).size).toBe(codes.length);
|
|
9
|
+
for (const code of codes) {
|
|
10
|
+
(0, bun_test_1.expect)(code).toStartWith('CELL_TA_');
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
(0, bun_test_1.it)('routes JSON-RPC methods by the names of the service symbols', () => {
|
|
14
|
+
(0, bun_test_1.expect)(ta_protocol_1.TaServer.description).toBe(ta_protocol_1.TA_SERVER_SERVICE);
|
|
15
|
+
(0, bun_test_1.expect)(ta_protocol_1.TaClient.description).toBe(ta_protocol_1.TA_CLIENT_SERVICE);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=ta-protocol.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-protocol.spec.js","sourceRoot":"","sources":["../../src/common/ta-protocol.spec.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAChD,+CAAsG;AAEtG,IAAA,mBAAQ,EAAC,aAAa,EAAE,GAAG,EAAE;IACzB,IAAA,aAAE,EAAC,kDAAkD,EAAE,GAAG,EAAE;QACxD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,yBAAW,CAAC,CAAC;QACzC,IAAA,iBAAM,EAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACvB,IAAA,iBAAM,EAAC,IAAI,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,6DAA6D,EAAE,GAAG,EAAE;QACnE,IAAA,iBAAM,EAAC,sBAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,+BAAiB,CAAC,CAAC;QACrD,IAAA,iBAAM,EAAC,sBAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,+BAAiB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-protocol",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.5.1",
|
|
4
|
+
"description": "The protocol between ta serve and its clients",
|
|
5
|
+
"homepage": "https://github.com/cellbang/cell",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/cellbang/cell/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18.0.0"
|
|
16
|
+
},
|
|
17
|
+
"main": "lib/common/index.js",
|
|
18
|
+
"typings": "lib/common/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"lib",
|
|
21
|
+
"esm",
|
|
22
|
+
"src"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -b && bun ../../scripts/build-esm.ts",
|
|
26
|
+
"clean": "rm -rf lib esm *.tsbuildinfo",
|
|
27
|
+
"test": "bun test ./lib",
|
|
28
|
+
"watch": "tsc -b -w --preserveWatchOutput"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@earendil-works/pi-coding-agent": "^1.5.0",
|
|
33
|
+
"@earendil-works/pi-ai": "^1.5.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@earendil-works/pi-coding-agent": {
|
|
37
|
+
"optional": true
|
|
38
|
+
},
|
|
39
|
+
"@earendil-works/pi-ai": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@earendil-works/pi-coding-agent": "^1.5.0",
|
|
45
|
+
"@earendil-works/pi-ai": "^1.5.0"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"import": "./esm/common/index.js",
|
|
53
|
+
"default": "./lib/common/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./package.json": "./package.json",
|
|
56
|
+
"./lib/common": {
|
|
57
|
+
"import": "./esm/common/index.js",
|
|
58
|
+
"default": "./lib/common/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./lib/*.js": {
|
|
61
|
+
"import": "./esm/*.js",
|
|
62
|
+
"default": "./lib/*.js"
|
|
63
|
+
},
|
|
64
|
+
"./lib/*": {
|
|
65
|
+
"import": "./esm/*.js",
|
|
66
|
+
"default": "./lib/*.js"
|
|
67
|
+
},
|
|
68
|
+
"./*": "./*"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// pi is an ES module package: the CommonJS build of this package can only name its types through
|
|
2
|
+
// import types with `resolution-mode`. Only types: this package loads neither pi nor Node.js modules.
|
|
3
|
+
export type ImageContent = import('@earendil-works/pi-ai', { with: { 'resolution-mode': 'import' }}).ImageContent;
|
|
4
|
+
export type JsonAgentSessionEvent = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).JsonAgentSessionEvent;
|
|
5
|
+
export type RpcExtensionUIRequest = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcExtensionUIRequest;
|
|
6
|
+
export type RpcExtensionUIResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcExtensionUIResponse;
|
|
7
|
+
export type RpcResponse = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcResponse;
|
|
8
|
+
export type RpcSessionState = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).RpcSessionState;
|
|
9
|
+
export type AgentSession = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' }}).AgentSession;
|
|
10
|
+
export type ThinkingLevel = AgentSession['thinkingLevel'];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { TA_CLIENT_SERVICE, TA_SERVER_SERVICE, TaClient, TaErrorCode, TaServer } from './ta-protocol';
|
|
3
|
+
|
|
4
|
+
describe('ta protocol', () => {
|
|
5
|
+
it('names each failure with a distinct CELL_TA_ code', () => {
|
|
6
|
+
const codes = Object.values(TaErrorCode);
|
|
7
|
+
expect(new Set(codes).size).toBe(codes.length);
|
|
8
|
+
for (const code of codes) {
|
|
9
|
+
expect(code).toStartWith('CELL_TA_');
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('routes JSON-RPC methods by the names of the service symbols', () => {
|
|
14
|
+
expect(TaServer.description).toBe(TA_SERVER_SERVICE);
|
|
15
|
+
expect(TaClient.description).toBe(TA_CLIENT_SERVICE);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import type { ImageContent, JsonAgentSessionEvent, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, ThinkingLevel } from './pi-types';
|
|
2
|
+
|
|
3
|
+
export const TaServer = Symbol('TaServer');
|
|
4
|
+
export const TaClient = Symbol('TaClient');
|
|
5
|
+
|
|
6
|
+
/** Path of the WebSocket endpoint of `ta serve`, and the JSON-RPC method prefixes of both sides. */
|
|
7
|
+
export const TA_WEBSOCKET_PATH = '/api/ws';
|
|
8
|
+
export const TA_SERVER_SERVICE = 'TaServer';
|
|
9
|
+
export const TA_CLIENT_SERVICE = 'TaClient';
|
|
10
|
+
|
|
11
|
+
/** The file `ta serve` writes in the agent directory, readable only by its user. */
|
|
12
|
+
export const TA_SERVE_FILE = 'serve.json';
|
|
13
|
+
|
|
14
|
+
/** The contents of {@link TA_SERVE_FILE}: how to reach the running `ta serve`. */
|
|
15
|
+
export interface TaServeInfo {
|
|
16
|
+
url: string;
|
|
17
|
+
token: string;
|
|
18
|
+
pid: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The stable `code` of each failure of a {@link TaServer} call. */
|
|
22
|
+
export const TaErrorCode = {
|
|
23
|
+
SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND',
|
|
24
|
+
SESSION_LOCKED: 'CELL_TA_SESSION_LOCKED',
|
|
25
|
+
TOO_MANY_SESSIONS: 'CELL_TA_TOO_MANY_SESSIONS',
|
|
26
|
+
MESSAGE_CONFLICT: 'CELL_TA_MESSAGE_CONFLICT',
|
|
27
|
+
MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND',
|
|
28
|
+
INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT',
|
|
29
|
+
COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED',
|
|
30
|
+
} as const;
|
|
31
|
+
export type TaErrorCode = (typeof TaErrorCode)[keyof typeof TaErrorCode];
|
|
32
|
+
|
|
33
|
+
/** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
|
|
34
|
+
export const TA_RPC_ERROR_CODE = -32050;
|
|
35
|
+
|
|
36
|
+
export interface TaErrorData {
|
|
37
|
+
code: TaErrorCode;
|
|
38
|
+
/** One sentence on what to do about it. */
|
|
39
|
+
hint: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A command name of pi's RPC mode (`get_state`, `follow_up`, ...). */
|
|
43
|
+
export type TaCommand = Extract<RpcResponse, { success: true }>['command'];
|
|
44
|
+
|
|
45
|
+
/** What pi's RPC mode answers to a command. */
|
|
46
|
+
export type TaCommandResult<C extends TaCommand> = Extract<RpcResponse, { command: C; success: true }> extends { data: infer D } ? D : undefined;
|
|
47
|
+
|
|
48
|
+
export interface TaClientToolDefinition {
|
|
49
|
+
name: string;
|
|
50
|
+
description: string;
|
|
51
|
+
/** JSON schema of the arguments. */
|
|
52
|
+
parameters: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface TaOpenSessionOptions {
|
|
56
|
+
/** Working directory of the session, on the machine of the server. */
|
|
57
|
+
cwd: string;
|
|
58
|
+
/** Opens this session file; default: a new session. */
|
|
59
|
+
sessionFile?: string;
|
|
60
|
+
/** `<provider>/<model id>`; default: pi's settings. */
|
|
61
|
+
model?: string;
|
|
62
|
+
thinkingLevel?: ThinkingLevel;
|
|
63
|
+
/** Tools the client runs; fixed when the session opens, so the tool list stays stable for prompt caching. */
|
|
64
|
+
clientTools?: TaClientToolDefinition[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface TaSessionInfo {
|
|
68
|
+
/** The id of this open session; stays the same through `newSession`, `switchSession` and `fork`. */
|
|
69
|
+
sessionId: string;
|
|
70
|
+
/** The id of the conversation pi has open now. */
|
|
71
|
+
piSessionId: string;
|
|
72
|
+
cwd: string;
|
|
73
|
+
sessionFile?: string;
|
|
74
|
+
sessionName?: string;
|
|
75
|
+
/** `<provider>/<model id>`. */
|
|
76
|
+
model?: string;
|
|
77
|
+
isStreaming: boolean;
|
|
78
|
+
messageCount: number;
|
|
79
|
+
/** Number of clients attached. */
|
|
80
|
+
attached: number;
|
|
81
|
+
createdAt: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface TaPromptInput {
|
|
85
|
+
message: string;
|
|
86
|
+
images?: ImageContent[];
|
|
87
|
+
/** Chosen by the client, unique per message: sending the same one again does not run it again. */
|
|
88
|
+
clientMessageId: string;
|
|
89
|
+
/** What to do when the agent is running; only for `prompt`. Default: `followUp`. */
|
|
90
|
+
streamingBehavior?: 'steer' | 'followUp';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The server has taken the message; it says nothing about the run. A run is finished at the
|
|
95
|
+
* `agent_settled` event, when its history is on disk.
|
|
96
|
+
*/
|
|
97
|
+
export interface TaPromptReceipt {
|
|
98
|
+
clientMessageId: string;
|
|
99
|
+
/** `accepted`: it runs now; `queued`: after the current work; `duplicate`: this id was taken before. */
|
|
100
|
+
status: 'accepted' | 'queued' | 'duplicate';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** An extension's dialog was answered by another client, or expired. */
|
|
104
|
+
export interface TaUiRequestResolved {
|
|
105
|
+
type: 'ui_request_resolved';
|
|
106
|
+
id: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** An extension threw while handling an event. */
|
|
110
|
+
export interface TaExtensionError {
|
|
111
|
+
type: 'extension_error';
|
|
112
|
+
extensionPath: string;
|
|
113
|
+
event: string;
|
|
114
|
+
error: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The open session now shows another conversation (`newSession`, `switchSession`, `fork`, `clone`): read it again. */
|
|
118
|
+
export interface TaSessionReplaced {
|
|
119
|
+
type: 'session_replaced';
|
|
120
|
+
info: TaSessionInfo;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The session was closed; no more events come. */
|
|
124
|
+
export interface TaSessionClosed {
|
|
125
|
+
type: 'session_closed';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The model called a tool of `clientTools`: answer with `respondClientTool`. */
|
|
129
|
+
export interface TaClientToolRequest {
|
|
130
|
+
type: 'client_tool_request';
|
|
131
|
+
id: string;
|
|
132
|
+
toolName: string;
|
|
133
|
+
input: unknown;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export type TaEvent =
|
|
137
|
+
| JsonAgentSessionEvent
|
|
138
|
+
| RpcExtensionUIRequest
|
|
139
|
+
| TaUiRequestResolved
|
|
140
|
+
| TaExtensionError
|
|
141
|
+
| TaClientToolRequest
|
|
142
|
+
| TaSessionReplaced
|
|
143
|
+
| TaSessionClosed;
|
|
144
|
+
|
|
145
|
+
export interface TaEventEnvelope {
|
|
146
|
+
sessionId: string;
|
|
147
|
+
/** Increases by one per event of the session. */
|
|
148
|
+
seq: number;
|
|
149
|
+
event: TaEvent;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface TaAttachResult {
|
|
153
|
+
info: TaSessionInfo;
|
|
154
|
+
/** The events after `afterSeq`. */
|
|
155
|
+
events: TaEventEnvelope[];
|
|
156
|
+
/** The dialogs still waiting for an answer. */
|
|
157
|
+
pendingUi: RpcExtensionUIRequest[];
|
|
158
|
+
/** Seq of the last event of the session. */
|
|
159
|
+
lastSeq: number;
|
|
160
|
+
/** Some events after `afterSeq` are gone: read the conversation again with `getMessages`. */
|
|
161
|
+
gap: boolean;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface TaClientToolResult {
|
|
165
|
+
id: string;
|
|
166
|
+
output: string;
|
|
167
|
+
isError?: boolean;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* `ta serve`, over JSON-RPC 2.0 on a WebSocket. Besides opening, attaching and answering, each method
|
|
172
|
+
* is the command of pi's RPC mode with the same name in camelCase, on the open session `sessionId`.
|
|
173
|
+
*/
|
|
174
|
+
export interface TaServer {
|
|
175
|
+
openSession(options: TaOpenSessionOptions): Promise<TaSessionInfo>;
|
|
176
|
+
closeSession(sessionId: string): Promise<void>;
|
|
177
|
+
listSessions(): Promise<TaSessionInfo[]>;
|
|
178
|
+
/** Starts sending the events of the session to this connection. */
|
|
179
|
+
attach(sessionId: string, afterSeq?: number): Promise<TaAttachResult>;
|
|
180
|
+
detach(sessionId: string): Promise<void>;
|
|
181
|
+
/** Answers a dialog; false when it was answered before or expired. */
|
|
182
|
+
respondUi(sessionId: string, response: RpcExtensionUIResponse): Promise<boolean>;
|
|
183
|
+
/** Answers a call of a client tool; false when nobody waits for it. */
|
|
184
|
+
respondClientTool(sessionId: string, result: TaClientToolResult): Promise<boolean>;
|
|
185
|
+
|
|
186
|
+
prompt(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
187
|
+
steer(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
188
|
+
followUp(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
189
|
+
abort(sessionId: string): Promise<void>;
|
|
190
|
+
clearQueue(sessionId: string): Promise<TaCommandResult<'clear_queue'>>;
|
|
191
|
+
newSession(sessionId: string, parentSession?: string): Promise<TaCommandResult<'new_session'>>;
|
|
192
|
+
getState(sessionId: string): Promise<TaCommandResult<'get_state'>>;
|
|
193
|
+
setModel(sessionId: string, provider: string, modelId: string): Promise<TaCommandResult<'set_model'>>;
|
|
194
|
+
cycleModel(sessionId: string): Promise<TaCommandResult<'cycle_model'>>;
|
|
195
|
+
getAvailableModels(sessionId: string): Promise<TaCommandResult<'get_available_models'>>;
|
|
196
|
+
setThinkingLevel(sessionId: string, level: ThinkingLevel): Promise<void>;
|
|
197
|
+
cycleThinkingLevel(sessionId: string): Promise<TaCommandResult<'cycle_thinking_level'>>;
|
|
198
|
+
getAvailableThinkingLevels(sessionId: string): Promise<TaCommandResult<'get_available_thinking_levels'>>;
|
|
199
|
+
setSteeringMode(sessionId: string, mode: 'all' | 'one-at-a-time'): Promise<void>;
|
|
200
|
+
setFollowUpMode(sessionId: string, mode: 'all' | 'one-at-a-time'): Promise<void>;
|
|
201
|
+
compact(sessionId: string, customInstructions?: string): Promise<TaCommandResult<'compact'>>;
|
|
202
|
+
setAutoCompaction(sessionId: string, enabled: boolean): Promise<void>;
|
|
203
|
+
setAutoRetry(sessionId: string, enabled: boolean): Promise<void>;
|
|
204
|
+
abortRetry(sessionId: string): Promise<void>;
|
|
205
|
+
bash(sessionId: string, command: string, excludeFromContext?: boolean): Promise<TaCommandResult<'bash'>>;
|
|
206
|
+
abortBash(sessionId: string): Promise<void>;
|
|
207
|
+
getSessionStats(sessionId: string): Promise<TaCommandResult<'get_session_stats'>>;
|
|
208
|
+
exportHtml(sessionId: string, outputPath?: string): Promise<TaCommandResult<'export_html'>>;
|
|
209
|
+
switchSession(sessionId: string, sessionPath: string): Promise<TaCommandResult<'switch_session'>>;
|
|
210
|
+
fork(sessionId: string, entryId: string): Promise<TaCommandResult<'fork'>>;
|
|
211
|
+
clone(sessionId: string): Promise<TaCommandResult<'clone'>>;
|
|
212
|
+
getForkMessages(sessionId: string): Promise<TaCommandResult<'get_fork_messages'>>;
|
|
213
|
+
getEntries(sessionId: string, since?: string): Promise<TaCommandResult<'get_entries'>>;
|
|
214
|
+
getTree(sessionId: string): Promise<TaCommandResult<'get_tree'>>;
|
|
215
|
+
getLastAssistantText(sessionId: string): Promise<TaCommandResult<'get_last_assistant_text'>>;
|
|
216
|
+
setSessionName(sessionId: string, name: string): Promise<void>;
|
|
217
|
+
getMessages(sessionId: string): Promise<TaCommandResult<'get_messages'>>;
|
|
218
|
+
getCommands(sessionId: string): Promise<TaCommandResult<'get_commands'>>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** What a client implements. Events come in batches: one message per frame, however fast the model streams. */
|
|
222
|
+
export interface TaClient {
|
|
223
|
+
onEvents(events: TaEventEnvelope[]): Promise<void>;
|
|
224
|
+
}
|