@celljs/ta-host 0.0.0-stage → 4.5.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.md +33 -2
- package/cell.schema.json +33 -0
- package/cell.yml +14 -0
- package/esm/node/client-channel.d.ts +31 -0
- package/esm/node/client-channel.js +84 -0
- package/esm/node/client-channel.js.map +1 -0
- package/esm/node/event-log.d.ts +28 -0
- package/esm/node/event-log.js +48 -0
- package/esm/node/event-log.js.map +1 -0
- package/esm/node/host-protocol.d.ts +27 -0
- package/esm/node/host-protocol.js +4 -0
- package/esm/node/host-protocol.js.map +1 -0
- package/esm/node/index.d.ts +13 -0
- package/esm/node/index.js +14 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/local-exec-environment-factory.d.ts +4 -0
- package/esm/node/local-exec-environment-factory.js +18 -0
- package/esm/node/local-exec-environment-factory.js.map +1 -0
- package/esm/node/module.d.ts +3 -0
- package/esm/node/module.js +4 -0
- package/esm/node/module.js.map +1 -0
- package/esm/node/receipt-book.d.ts +12 -0
- package/esm/node/receipt-book.js +38 -0
- package/esm/node/receipt-book.js.map +1 -0
- package/esm/node/remote-ui-context.d.ts +63 -0
- package/esm/node/remote-ui-context.js +130 -0
- package/esm/node/remote-ui-context.js.map +1 -0
- package/esm/node/ta-access.d.ts +30 -0
- package/esm/node/ta-access.js +107 -0
- package/esm/node/ta-access.js.map +1 -0
- package/esm/node/ta-errors.d.ts +11 -0
- package/esm/node/ta-errors.js +44 -0
- package/esm/node/ta-errors.js.map +1 -0
- package/esm/node/ta-event-util.d.ts +11 -0
- package/esm/node/ta-event-util.js +20 -0
- package/esm/node/ta-event-util.js.map +1 -0
- package/esm/node/ta-server-impl.d.ts +50 -0
- package/esm/node/ta-server-impl.js +226 -0
- package/esm/node/ta-server-impl.js.map +1 -0
- package/esm/node/ta-session-factory.d.ts +32 -0
- package/esm/node/ta-session-factory.js +151 -0
- package/esm/node/ta-session-factory.js.map +1 -0
- package/esm/node/ta-session-registry.d.ts +20 -0
- package/esm/node/ta-session-registry.js +85 -0
- package/esm/node/ta-session-registry.js.map +1 -0
- package/esm/node/ta-session.d.ts +53 -0
- package/esm/node/ta-session.js +157 -0
- package/esm/node/ta-session.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/node/client-channel.d.ts +32 -0
- package/lib/node/client-channel.d.ts.map +1 -0
- package/lib/node/client-channel.js +88 -0
- package/lib/node/client-channel.js.map +1 -0
- package/lib/node/client-channel.spec.d.ts +2 -0
- package/lib/node/client-channel.spec.d.ts.map +1 -0
- package/lib/node/client-channel.spec.js +106 -0
- package/lib/node/client-channel.spec.js.map +1 -0
- package/lib/node/event-log.d.ts +29 -0
- package/lib/node/event-log.d.ts.map +1 -0
- package/lib/node/event-log.js +52 -0
- package/lib/node/event-log.js.map +1 -0
- package/lib/node/event-log.spec.d.ts +2 -0
- package/lib/node/event-log.spec.d.ts.map +1 -0
- package/lib/node/event-log.spec.js +48 -0
- package/lib/node/event-log.spec.js.map +1 -0
- package/lib/node/host-protocol.d.ts +28 -0
- package/lib/node/host-protocol.d.ts.map +1 -0
- package/lib/node/host-protocol.js +7 -0
- package/lib/node/host-protocol.js.map +1 -0
- package/lib/node/index.d.ts +14 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +30 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/local-exec-environment-factory.d.ts +5 -0
- package/lib/node/local-exec-environment-factory.d.ts.map +1 -0
- package/lib/node/local-exec-environment-factory.js +21 -0
- package/lib/node/local-exec-environment-factory.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +6 -0
- package/lib/node/module.js.map +1 -0
- package/lib/node/receipt-book.d.ts +13 -0
- package/lib/node/receipt-book.d.ts.map +1 -0
- package/lib/node/receipt-book.js +42 -0
- package/lib/node/receipt-book.js.map +1 -0
- package/lib/node/receipt-book.spec.d.ts +2 -0
- package/lib/node/receipt-book.spec.d.ts.map +1 -0
- package/lib/node/receipt-book.spec.js +39 -0
- package/lib/node/receipt-book.spec.js.map +1 -0
- package/lib/node/remote-ui-context.d.ts +64 -0
- package/lib/node/remote-ui-context.d.ts.map +1 -0
- package/lib/node/remote-ui-context.js +134 -0
- package/lib/node/remote-ui-context.js.map +1 -0
- package/lib/node/remote-ui-context.spec.d.ts +2 -0
- package/lib/node/remote-ui-context.spec.d.ts.map +1 -0
- package/lib/node/remote-ui-context.spec.js +62 -0
- package/lib/node/remote-ui-context.spec.js.map +1 -0
- package/lib/node/ta-access.d.ts +31 -0
- package/lib/node/ta-access.d.ts.map +1 -0
- package/lib/node/ta-access.js +110 -0
- package/lib/node/ta-access.js.map +1 -0
- package/lib/node/ta-access.spec.d.ts +2 -0
- package/lib/node/ta-access.spec.d.ts.map +1 -0
- package/lib/node/ta-access.spec.js +25 -0
- package/lib/node/ta-access.spec.js.map +1 -0
- package/lib/node/ta-errors.d.ts +12 -0
- package/lib/node/ta-errors.d.ts.map +1 -0
- package/lib/node/ta-errors.js +47 -0
- package/lib/node/ta-errors.js.map +1 -0
- package/lib/node/ta-event-util.d.ts +12 -0
- package/lib/node/ta-event-util.d.ts.map +1 -0
- package/lib/node/ta-event-util.js +23 -0
- package/lib/node/ta-event-util.js.map +1 -0
- package/lib/node/ta-event-util.spec.d.ts +2 -0
- package/lib/node/ta-event-util.spec.d.ts.map +1 -0
- package/lib/node/ta-event-util.spec.js +28 -0
- package/lib/node/ta-event-util.spec.js.map +1 -0
- package/lib/node/ta-server-impl.d.ts +51 -0
- package/lib/node/ta-server-impl.d.ts.map +1 -0
- package/lib/node/ta-server-impl.js +229 -0
- package/lib/node/ta-server-impl.js.map +1 -0
- package/lib/node/ta-session-factory.d.ts +33 -0
- package/lib/node/ta-session-factory.d.ts.map +1 -0
- package/lib/node/ta-session-factory.js +154 -0
- package/lib/node/ta-session-factory.js.map +1 -0
- package/lib/node/ta-session-registry.d.ts +21 -0
- package/lib/node/ta-session-registry.d.ts.map +1 -0
- package/lib/node/ta-session-registry.js +86 -0
- package/lib/node/ta-session-registry.js.map +1 -0
- package/lib/node/ta-session.d.ts +54 -0
- package/lib/node/ta-session.d.ts.map +1 -0
- package/lib/node/ta-session.js +161 -0
- package/lib/node/ta-session.js.map +1 -0
- package/package.json +80 -4
- package/src/node/client-channel.spec.ts +117 -0
- package/src/node/client-channel.ts +94 -0
- package/src/node/event-log.spec.ts +52 -0
- package/src/node/event-log.ts +59 -0
- package/src/node/host-protocol.ts +32 -0
- package/src/node/index.ts +13 -0
- package/src/node/local-exec-environment-factory.ts +9 -0
- package/src/node/module.ts +4 -0
- package/src/node/receipt-book.spec.ts +41 -0
- package/src/node/receipt-book.ts +40 -0
- package/src/node/remote-ui-context.spec.ts +68 -0
- package/src/node/remote-ui-context.ts +168 -0
- package/src/node/ta-access.spec.ts +27 -0
- package/src/node/ta-access.ts +98 -0
- package/src/node/ta-errors.ts +55 -0
- package/src/node/ta-event-util.spec.ts +29 -0
- package/src/node/ta-event-util.ts +23 -0
- package/src/node/ta-server-impl.ts +264 -0
- package/src/node/ta-session-factory.ts +156 -0
- package/src/node/ta-session-registry.ts +75 -0
- package/src/node/ta-session.ts +193 -0
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Cell - ta Host
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`ta serve` 的服务端,作用相当于 Codex 的 app-server:pi 只有 stdio 上的 RPC 模式(一个进程一个会话、一个控制方),本组件补上多会话、多客户端、断线补发、远程审批、幂等回执和会话锁。命令与事件的语义和 pi RPC 模式一致。
|
|
4
|
+
|
|
5
|
+
## 组件
|
|
6
|
+
|
|
7
|
+
| 组件 | 作用 |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| `TaServerImpl` | `@Rpc(TaServer)`,各命令转给 pi 的 `AgentSession` / `AgentSessionRuntime` |
|
|
10
|
+
| `TaSessionRegistry` | 打开的会话;超过 `maxSessions` 拒绝,空闲(无客户端、无运行、无待答对话框)超过 `idleTimeoutMs` 关闭,会话文件保留 |
|
|
11
|
+
| `TaSessionFactory` | 像 pi 命令那样装配会话:项目信任、设置、扩展、主题;所有会话共用一个模型运行时。可 `rebind` 替换 |
|
|
12
|
+
| `TaSession` | 一个打开的会话:事件日志、回执、已连接的客户端;`newSession`/`fork`/`switchSession` 后 id 不变,并发 `session_replaced` |
|
|
13
|
+
| `RemoteUiContext` | pi 扩展的 `ctx.ui`:对话框广播给所有客户端,第一个回答生效,超时按扩展给的默认值 |
|
|
14
|
+
| `EventLog` / `ClientChannel` | 每个会话按字节保留最近的事件供重连补发;每个客户端每 30ms 合并成一帧,等客户端应答后再发下一帧,落后过多则断开让其重连 |
|
|
15
|
+
| `TaAccess` | token 校验(WebSocket 握手与 HTTP)、监听本机时校验 `Host` 防 DNS rebinding、写 `serve.json` |
|
|
16
|
+
| `LocalExecEnvironmentFactory` | 工具在本机执行;绑定别的 `ExecEnvironmentFactory` 可让工具在别处执行 |
|
|
17
|
+
|
|
18
|
+
每个会话加载的扩展与 `ta` 命令相同:pi 命令自带的 codemode、tool search、MCP(pi 的 SDK 不自动加载它们;执行环境不在本机时 stdio MCP 服务在执行环境里启动),ta 的内置扩展,以及 `AgentExtension`、`AgentTool` 组件(@celljs/ai-coding-agent)。
|
|
19
|
+
|
|
20
|
+
## 配置
|
|
21
|
+
|
|
22
|
+
```yaml
|
|
23
|
+
ta:
|
|
24
|
+
host:
|
|
25
|
+
maxSessions: 32
|
|
26
|
+
idleTimeoutMs: 600000
|
|
27
|
+
eventBufferBytes: 524288 # 每个会话可补发的事件量
|
|
28
|
+
clientBacklogBytes: 8388608 # 每个客户端允许积压的量
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 已知限制
|
|
32
|
+
|
|
33
|
+
- 去重表、事件日志和待答对话框都在内存里:服务重启后对话框作废(扩展拿到默认值),客户端应先 `getMessages` 核对再决定是否重发。
|
|
34
|
+
- 客户端工具(`clientTools`)协议已定义,尚未实现,传入会报 `CELL_TA_INVALID_ARGUMENT`。
|
package/cell.schema.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"properties": {
|
|
4
|
+
"ta": {
|
|
5
|
+
"type": "object",
|
|
6
|
+
"description": "ta.",
|
|
7
|
+
"properties": {
|
|
8
|
+
"host": {
|
|
9
|
+
"type": "object",
|
|
10
|
+
"description": "ta serve.",
|
|
11
|
+
"properties": {
|
|
12
|
+
"maxSessions": {
|
|
13
|
+
"type": "integer",
|
|
14
|
+
"description": "Open sessions at most; more are refused with CELL_TA_TOO_MANY_SESSIONS."
|
|
15
|
+
},
|
|
16
|
+
"idleTimeoutMs": {
|
|
17
|
+
"type": "integer",
|
|
18
|
+
"description": "A session with no client attached and no work is closed after this; its file stays."
|
|
19
|
+
},
|
|
20
|
+
"eventBufferBytes": {
|
|
21
|
+
"type": "integer",
|
|
22
|
+
"description": "Latest events kept per session, for clients that reconnect."
|
|
23
|
+
},
|
|
24
|
+
"clientBacklogBytes": {
|
|
25
|
+
"type": "integer",
|
|
26
|
+
"description": "A client this far behind is disconnected, and catches up when it reconnects."
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
package/cell.yml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
rpc:
|
|
2
|
+
transport: websocket
|
|
3
|
+
websocket:
|
|
4
|
+
# A prompt can carry images.
|
|
5
|
+
maxPayload: 33554432
|
|
6
|
+
ta:
|
|
7
|
+
host:
|
|
8
|
+
maxSessions: 32
|
|
9
|
+
# A session nobody is attached to and that is not working is closed after this; its file stays.
|
|
10
|
+
idleTimeoutMs: 600000
|
|
11
|
+
# Per session: what a client that reconnects can catch up on.
|
|
12
|
+
eventBufferBytes: 524288
|
|
13
|
+
# Per client: a client this far behind is disconnected, and catches up when it reconnects.
|
|
14
|
+
clientBacklogBytes: 8388608
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
2
|
+
import { type TaEventEnvelope } from '@celljs/ta-protocol';
|
|
3
|
+
import type { LoggedEvent } from './event-log.js';
|
|
4
|
+
/**
|
|
5
|
+
* Events on their way to one client, one message at a time: the next leaves when the client has
|
|
6
|
+
* answered the last, so that a slow client costs a bounded queue and nothing while no events flow.
|
|
7
|
+
* A model streams hundreds of deltas a second: streamed events leave at most once per interval, the
|
|
8
|
+
* first of them at once. Other events (a message starts, a tool ends, a dialog opens) leave at once,
|
|
9
|
+
* with what is queued, so that nothing a user waits for is delayed.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ClientChannel {
|
|
12
|
+
readonly connection: RpcConnection;
|
|
13
|
+
protected readonly maxBacklogBytes: number;
|
|
14
|
+
protected queue: TaEventEnvelope[];
|
|
15
|
+
protected queuedBytes: number;
|
|
16
|
+
protected timer?: ReturnType<typeof setTimeout>;
|
|
17
|
+
protected sending: boolean;
|
|
18
|
+
protected lastFlushAt: number;
|
|
19
|
+
/** When the timer fires, on the clock of `performance.now()`. */
|
|
20
|
+
protected dueAt: number;
|
|
21
|
+
/** The queue holds an event that should not wait. */
|
|
22
|
+
protected urgent: boolean;
|
|
23
|
+
/** The queue holds a streamed event. */
|
|
24
|
+
protected streamed: boolean;
|
|
25
|
+
constructor(connection: RpcConnection, maxBacklogBytes: number);
|
|
26
|
+
send(logged: LoggedEvent): void;
|
|
27
|
+
/** A timer, not a direct send: the events of the same turn of the event loop leave together. */
|
|
28
|
+
protected schedule(): void;
|
|
29
|
+
protected flush(): void;
|
|
30
|
+
protected clear(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { TaClient } from '@celljs/ta-protocol';
|
|
2
|
+
const FLUSH_INTERVAL_MS = 30;
|
|
3
|
+
/** The events that come by the hundred while a model or a tool streams; the others leave at once. */
|
|
4
|
+
const STREAMED_EVENTS = new Set(['message_update', 'tool_execution_update']);
|
|
5
|
+
/**
|
|
6
|
+
* Events on their way to one client, one message at a time: the next leaves when the client has
|
|
7
|
+
* answered the last, so that a slow client costs a bounded queue and nothing while no events flow.
|
|
8
|
+
* A model streams hundreds of deltas a second: streamed events leave at most once per interval, the
|
|
9
|
+
* first of them at once. Other events (a message starts, a tool ends, a dialog opens) leave at once,
|
|
10
|
+
* with what is queued, so that nothing a user waits for is delayed.
|
|
11
|
+
*/
|
|
12
|
+
export class ClientChannel {
|
|
13
|
+
constructor(connection, maxBacklogBytes) {
|
|
14
|
+
this.connection = connection;
|
|
15
|
+
this.maxBacklogBytes = maxBacklogBytes;
|
|
16
|
+
this.queue = [];
|
|
17
|
+
this.queuedBytes = 0;
|
|
18
|
+
this.sending = false;
|
|
19
|
+
this.lastFlushAt = Number.NEGATIVE_INFINITY;
|
|
20
|
+
/** When the timer fires, on the clock of `performance.now()`. */
|
|
21
|
+
this.dueAt = 0;
|
|
22
|
+
/** The queue holds an event that should not wait. */
|
|
23
|
+
this.urgent = false;
|
|
24
|
+
/** The queue holds a streamed event. */
|
|
25
|
+
this.streamed = false;
|
|
26
|
+
}
|
|
27
|
+
send(logged) {
|
|
28
|
+
this.queue.push(logged.envelope);
|
|
29
|
+
this.queuedBytes += logged.size;
|
|
30
|
+
if (this.queuedBytes > this.maxBacklogBytes) {
|
|
31
|
+
this.clear();
|
|
32
|
+
this.connection.close(1013, 'The client is too far behind; attach again with the last seq it has.');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const streamed = STREAMED_EVENTS.has(logged.envelope.event.type);
|
|
36
|
+
this.streamed || (this.streamed = streamed);
|
|
37
|
+
this.urgent || (this.urgent = !streamed);
|
|
38
|
+
this.schedule();
|
|
39
|
+
}
|
|
40
|
+
/** A timer, not a direct send: the events of the same turn of the event loop leave together. */
|
|
41
|
+
schedule() {
|
|
42
|
+
const due = this.urgent ? 0 : this.lastFlushAt + FLUSH_INTERVAL_MS;
|
|
43
|
+
if (this.timer !== undefined && this.dueAt <= due) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
clearTimeout(this.timer);
|
|
47
|
+
this.dueAt = due;
|
|
48
|
+
this.timer = setTimeout(() => this.flush(), Math.max(0, due - performance.now()));
|
|
49
|
+
}
|
|
50
|
+
flush() {
|
|
51
|
+
this.timer = undefined;
|
|
52
|
+
if (this.sending || !this.queue.length || this.connection.closed) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const batch = this.queue;
|
|
56
|
+
this.queue = [];
|
|
57
|
+
this.queuedBytes = 0;
|
|
58
|
+
if (this.streamed) {
|
|
59
|
+
this.lastFlushAt = performance.now();
|
|
60
|
+
}
|
|
61
|
+
this.urgent = false;
|
|
62
|
+
this.streamed = false;
|
|
63
|
+
this.sending = true;
|
|
64
|
+
this.connection
|
|
65
|
+
.client(TaClient)
|
|
66
|
+
.onEvents(batch)
|
|
67
|
+
.catch(() => undefined)
|
|
68
|
+
.finally(() => {
|
|
69
|
+
this.sending = false;
|
|
70
|
+
if (this.queue.length) {
|
|
71
|
+
this.schedule();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
clear() {
|
|
76
|
+
clearTimeout(this.timer);
|
|
77
|
+
this.timer = undefined;
|
|
78
|
+
this.queue = [];
|
|
79
|
+
this.queuedBytes = 0;
|
|
80
|
+
this.urgent = false;
|
|
81
|
+
this.streamed = false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=client-channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-channel.js","sourceRoot":"","sources":["../../src/node/client-channel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAwB,MAAM,qBAAqB,CAAC;AAGrE,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,qGAAqG;AACrG,MAAM,eAAe,GAAG,IAAI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I,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;gBACpB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpB,CAAC;QACL,CAAC,CAAC,CAAC;IACX,CAAC;IAES,KAAK;QACX,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IAC1B,CAAC;CACJ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TaEvent, TaEventEnvelope } from '@celljs/ta-protocol';
|
|
2
|
+
export interface LoggedEvent {
|
|
3
|
+
envelope: TaEventEnvelope;
|
|
4
|
+
/** Approximate size in bytes. */
|
|
5
|
+
size: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The latest events of a session, by size, so that a client that reconnects can catch up. Only that:
|
|
9
|
+
* what happened is in the session file, and a client that fell further behind reads it again.
|
|
10
|
+
*/
|
|
11
|
+
export declare class EventLog {
|
|
12
|
+
protected readonly sessionId: string;
|
|
13
|
+
protected readonly maxBytes: number;
|
|
14
|
+
protected entries: LoggedEvent[];
|
|
15
|
+
protected head: number;
|
|
16
|
+
protected bytes: number;
|
|
17
|
+
protected seq: number;
|
|
18
|
+
constructor(sessionId: string, maxBytes: number);
|
|
19
|
+
get lastSeq(): number;
|
|
20
|
+
append(event: TaEvent): LoggedEvent;
|
|
21
|
+
/** The events after `afterSeq`; `gap` when some of them are gone. */
|
|
22
|
+
since(afterSeq: number): {
|
|
23
|
+
events: TaEventEnvelope[];
|
|
24
|
+
gap: boolean;
|
|
25
|
+
};
|
|
26
|
+
/** Deltas are most of the events and their size is known; the others are rare enough to measure. */
|
|
27
|
+
protected sizeOf(event: TaEvent): number;
|
|
28
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The latest events of a session, by size, so that a client that reconnects can catch up. Only that:
|
|
3
|
+
* what happened is in the session file, and a client that fell further behind reads it again.
|
|
4
|
+
*/
|
|
5
|
+
export class EventLog {
|
|
6
|
+
constructor(sessionId, maxBytes) {
|
|
7
|
+
this.sessionId = sessionId;
|
|
8
|
+
this.maxBytes = maxBytes;
|
|
9
|
+
this.entries = [];
|
|
10
|
+
this.head = 0;
|
|
11
|
+
this.bytes = 0;
|
|
12
|
+
this.seq = 0;
|
|
13
|
+
}
|
|
14
|
+
get lastSeq() {
|
|
15
|
+
return this.seq;
|
|
16
|
+
}
|
|
17
|
+
append(event) {
|
|
18
|
+
const logged = { envelope: { sessionId: this.sessionId, seq: ++this.seq, event }, size: this.sizeOf(event) };
|
|
19
|
+
this.entries.push(logged);
|
|
20
|
+
this.bytes += logged.size;
|
|
21
|
+
while (this.bytes > this.maxBytes && this.entries.length - this.head > 1) {
|
|
22
|
+
this.bytes -= this.entries[this.head++].size;
|
|
23
|
+
}
|
|
24
|
+
if (this.head > 1024 && this.head * 2 > this.entries.length) {
|
|
25
|
+
this.entries = this.entries.slice(this.head);
|
|
26
|
+
this.head = 0;
|
|
27
|
+
}
|
|
28
|
+
return logged;
|
|
29
|
+
}
|
|
30
|
+
/** The events after `afterSeq`; `gap` when some of them are gone. */
|
|
31
|
+
since(afterSeq) {
|
|
32
|
+
const oldest = this.head < this.entries.length ? this.entries[this.head].envelope.seq : this.seq + 1;
|
|
33
|
+
if (afterSeq + 1 < oldest || afterSeq > this.seq) {
|
|
34
|
+
return { events: [], gap: true };
|
|
35
|
+
}
|
|
36
|
+
return { events: this.entries.slice(this.head + afterSeq + 1 - oldest).map(entry => entry.envelope), gap: false };
|
|
37
|
+
}
|
|
38
|
+
/** Deltas are most of the events and their size is known; the others are rare enough to measure. */
|
|
39
|
+
sizeOf(event) {
|
|
40
|
+
var _a;
|
|
41
|
+
if (event.type === 'message_update') {
|
|
42
|
+
const delta = event.assistantMessageEvent.delta;
|
|
43
|
+
return 256 + ((_a = delta === null || delta === void 0 ? void 0 : delta.length) !== null && _a !== void 0 ? _a : 0);
|
|
44
|
+
}
|
|
45
|
+
return JSON.stringify(event).length;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=event-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-log.js","sourceRoot":"","sources":["../../src/node/event-log.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,OAAO,QAAQ;IAMjB,YACuB,SAAiB,EACjB,QAAgB;QADhB,cAAS,GAAT,SAAS,CAAQ;QACjB,aAAQ,GAAR,QAAQ,CAAQ;QAP7B,YAAO,GAAkB,EAAE,CAAC;QAC5B,SAAI,GAAG,CAAC,CAAC;QACT,UAAK,GAAG,CAAC,CAAC;QACV,QAAG,GAAG,CAAC,CAAC;IAKf,CAAC;IAEJ,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IAED,MAAM,CAAC,KAAc;QACjB,MAAM,MAAM,GAAG,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7G,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC;QAC1B,OAAO,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YACvE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IA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AAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,mCAAI,CAAC,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IACxC,CAAC;CACJ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
2
|
+
import type { TaOpenSessionOptions } from '@celljs/ta-protocol';
|
|
3
|
+
import type { ClientChannel } from './client-channel.js';
|
|
4
|
+
import type { TaSession } from './ta-session.js';
|
|
5
|
+
export declare const TaSessionFactory: unique symbol;
|
|
6
|
+
export declare const TaSessionRegistry: unique symbol;
|
|
7
|
+
export declare const TA_HOST_OPTIONS = "ta.host";
|
|
8
|
+
/** `ta.host`. */
|
|
9
|
+
export interface TaHostOptions {
|
|
10
|
+
maxSessions: number;
|
|
11
|
+
idleTimeoutMs: number;
|
|
12
|
+
eventBufferBytes: number;
|
|
13
|
+
clientBacklogBytes: number;
|
|
14
|
+
}
|
|
15
|
+
export interface TaSessionFactory {
|
|
16
|
+
create(options: TaOpenSessionOptions, requestClose: (session: TaSession) => void): Promise<TaSession>;
|
|
17
|
+
}
|
|
18
|
+
/** The open sessions. */
|
|
19
|
+
export interface TaSessionRegistry {
|
|
20
|
+
open(options: TaOpenSessionOptions): Promise<TaSession>;
|
|
21
|
+
/** Throws CELL_TA_SESSION_NOT_FOUND. */
|
|
22
|
+
require(sessionId: string): TaSession;
|
|
23
|
+
list(): TaSession[];
|
|
24
|
+
close(sessionId: string): Promise<void>;
|
|
25
|
+
closeAll(): Promise<void>;
|
|
26
|
+
channel(connection: RpcConnection): ClientChannel;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-protocol.js","sourceRoot":"","sources":["../../src/node/host-protocol.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAE7D,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './client-channel.js';
|
|
2
|
+
export * from './event-log.js';
|
|
3
|
+
export * from './host-protocol.js';
|
|
4
|
+
export * from './local-exec-environment-factory.js';
|
|
5
|
+
export * from './receipt-book.js';
|
|
6
|
+
export * from './remote-ui-context.js';
|
|
7
|
+
export * from './ta-access.js';
|
|
8
|
+
export * from './ta-errors.js';
|
|
9
|
+
export * from './ta-event-util.js';
|
|
10
|
+
export * from './ta-server-impl.js';
|
|
11
|
+
export * from './ta-session.js';
|
|
12
|
+
export * from './ta-session-factory.js';
|
|
13
|
+
export * from './ta-session-registry.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './client-channel.js';
|
|
2
|
+
export * from './event-log.js';
|
|
3
|
+
export * from './host-protocol.js';
|
|
4
|
+
export * from './local-exec-environment-factory.js';
|
|
5
|
+
export * from './receipt-book.js';
|
|
6
|
+
export * from './remote-ui-context.js';
|
|
7
|
+
export * from './ta-access.js';
|
|
8
|
+
export * from './ta-errors.js';
|
|
9
|
+
export * from './ta-event-util.js';
|
|
10
|
+
export * from './ta-server-impl.js';
|
|
11
|
+
export * from './ta-session.js';
|
|
12
|
+
export * from './ta-session-factory.js';
|
|
13
|
+
export * from './ta-session-registry.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kCAAkC,CAAC;AACjD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Component } from '@celljs/core';
|
|
8
|
+
import { ExecEnvironmentFactory, LocalExecEnvironment } from '@celljs/ta-exec';
|
|
9
|
+
let LocalExecEnvironmentFactory = class LocalExecEnvironmentFactory {
|
|
10
|
+
create(cwd) {
|
|
11
|
+
return new LocalExecEnvironment(cwd);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
LocalExecEnvironmentFactory = __decorate([
|
|
15
|
+
Component(ExecEnvironmentFactory)
|
|
16
|
+
], LocalExecEnvironmentFactory);
|
|
17
|
+
export { LocalExecEnvironmentFactory };
|
|
18
|
+
//# sourceMappingURL=local-exec-environment-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-exec-environment-factory.js","sourceRoot":"","sources":["../../src/node/local-exec-environment-factory.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAwB,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG9F,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IACpC,MAAM,CAAC,GAAW;QACd,OAAO,IAAI,oBAAoB,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;CACJ,CAAA;AAJY,2BAA2B;IADvC,SAAS,CAAC,sBAAsB,CAAC;GACrB,2BAA2B,CAIvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,SAAS,CAAC;AAEjB,eAAe,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TaPromptInput, TaPromptReceipt } from '@celljs/ta-protocol';
|
|
2
|
+
/** The messages a session has taken, by the id the client gave them; a resend does not run twice. Holds hashes, not messages. */
|
|
3
|
+
export declare class ReceiptBook {
|
|
4
|
+
protected readonly capacity: number;
|
|
5
|
+
protected readonly seen: Map<string, string>;
|
|
6
|
+
constructor(capacity?: number);
|
|
7
|
+
/** The receipt of a message taken before; undefined for a new one, which is now recorded. */
|
|
8
|
+
take(input: TaPromptInput): TaPromptReceipt | undefined;
|
|
9
|
+
/** The message was refused: the client may send it again. */
|
|
10
|
+
forget(clientMessageId: string): void;
|
|
11
|
+
protected hash(input: TaPromptInput): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { TaErrors } from './ta-errors.js';
|
|
3
|
+
/** The messages a session has taken, by the id the client gave them; a resend does not run twice. Holds hashes, not messages. */
|
|
4
|
+
export class ReceiptBook {
|
|
5
|
+
constructor(capacity = 256) {
|
|
6
|
+
this.capacity = capacity;
|
|
7
|
+
this.seen = new Map();
|
|
8
|
+
}
|
|
9
|
+
/** The receipt of a message taken before; undefined for a new one, which is now recorded. */
|
|
10
|
+
take(input) {
|
|
11
|
+
const hash = this.hash(input);
|
|
12
|
+
const seen = this.seen.get(input.clientMessageId);
|
|
13
|
+
if (seen === hash) {
|
|
14
|
+
return { clientMessageId: input.clientMessageId, status: 'duplicate' };
|
|
15
|
+
}
|
|
16
|
+
if (seen !== undefined) {
|
|
17
|
+
throw TaErrors.messageConflict(input.clientMessageId);
|
|
18
|
+
}
|
|
19
|
+
this.seen.set(input.clientMessageId, hash);
|
|
20
|
+
if (this.seen.size > this.capacity) {
|
|
21
|
+
this.seen.delete(this.seen.keys().next().value);
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/** The message was refused: the client may send it again. */
|
|
26
|
+
forget(clientMessageId) {
|
|
27
|
+
this.seen.delete(clientMessageId);
|
|
28
|
+
}
|
|
29
|
+
hash(input) {
|
|
30
|
+
var _a;
|
|
31
|
+
const hash = createHash('sha1').update(input.message);
|
|
32
|
+
for (const image of (_a = input.images) !== null && _a !== void 0 ? _a : []) {
|
|
33
|
+
hash.update(image.data);
|
|
34
|
+
}
|
|
35
|
+
return hash.digest('base64');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=receipt-book.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receipt-book.js","sourceRoot":"","sources":["../../src/node/receipt-book.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,iIAAiI;AACjI,MAAM,OAAO,WAAW;IAGpB,YAA+B,QAAQ,GAAG,GAAG;QAAd,aAAQ,GAAR,QAAQ,CAAM;QAF1B,SAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEJ,CAAC;IAEjD,6FAA6F;IAC7F,IAAI,CAAC,KAAoB;QACrB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,C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with: { 'resolution-mode': 'import' } }).ExtensionUIContext;
|
|
3
|
+
type DialogOptions = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).ExtensionUIDialogOptions;
|
|
4
|
+
interface PendingDialog {
|
|
5
|
+
request: RpcExtensionUIRequest;
|
|
6
|
+
settle(response: RpcExtensionUIResponse | undefined): void;
|
|
7
|
+
}
|
|
8
|
+
type DialogRequest = RpcExtensionUIRequest extends infer R ? (R extends {
|
|
9
|
+
id: string;
|
|
10
|
+
} ? Omit<R, 'id' | 'type'> : never) : never;
|
|
11
|
+
/**
|
|
12
|
+
* pi's extension UI for clients that are not this process. It has the shape of pi's RPC mode, with one
|
|
13
|
+
* difference: a dialog goes to every attached client, the first answer counts, and the others are told.
|
|
14
|
+
* A dialog nobody answers ends at its timeout, as the extension asked.
|
|
15
|
+
*/
|
|
16
|
+
export declare class RemoteUiContext implements ExtensionUIContext {
|
|
17
|
+
protected readonly publish: (event: TaEvent) => void;
|
|
18
|
+
protected readonly pending: Map<string, PendingDialog>;
|
|
19
|
+
readonly theme: import("@earendil-works/pi-coding-agent").Theme;
|
|
20
|
+
constructor(publish: (event: TaEvent) => void);
|
|
21
|
+
get pendingRequests(): RpcExtensionUIRequest[];
|
|
22
|
+
/** False when the dialog was answered before or ended. */
|
|
23
|
+
respond(response: RpcExtensionUIResponse): boolean;
|
|
24
|
+
/** Ends the open dialogs as if they timed out: the extensions go on, with their defaults. */
|
|
25
|
+
cancelAll(): void;
|
|
26
|
+
select(title: string, options: string[], opts?: DialogOptions): Promise<string | undefined>;
|
|
27
|
+
confirm(title: string, message: string, opts?: DialogOptions): Promise<boolean>;
|
|
28
|
+
input(title: string, placeholder?: string, opts?: DialogOptions): Promise<string | undefined>;
|
|
29
|
+
editor(title: string, prefill?: string): Promise<string | undefined>;
|
|
30
|
+
notify(message: string, type?: 'info' | 'warning' | 'error'): void;
|
|
31
|
+
setStatus(key: string, text: string | undefined): void;
|
|
32
|
+
setWidget(key: string, content: unknown, options?: {
|
|
33
|
+
placement?: 'aboveEditor' | 'belowEditor';
|
|
34
|
+
}): void;
|
|
35
|
+
setTitle(title: string): void;
|
|
36
|
+
setEditorText(text: string): void;
|
|
37
|
+
pasteToEditor(text: string): void;
|
|
38
|
+
getEditorText(): string;
|
|
39
|
+
onTerminalInput(): () => void;
|
|
40
|
+
setWorkingMessage(): void;
|
|
41
|
+
setWorkingVisible(): void;
|
|
42
|
+
setWorkingIndicator(): void;
|
|
43
|
+
setHiddenThinkingLabel(): void;
|
|
44
|
+
setFooter(): void;
|
|
45
|
+
setHeader(): void;
|
|
46
|
+
addAutocompleteProvider(): void;
|
|
47
|
+
setEditorComponent(): void;
|
|
48
|
+
getEditorComponent(): undefined;
|
|
49
|
+
custom(): Promise<never>;
|
|
50
|
+
getAllThemes(): [];
|
|
51
|
+
getTheme(): undefined;
|
|
52
|
+
setTheme(): {
|
|
53
|
+
success: boolean;
|
|
54
|
+
error: string;
|
|
55
|
+
};
|
|
56
|
+
getToolsExpanded(): boolean;
|
|
57
|
+
setToolsExpanded(): void;
|
|
58
|
+
protected tell(request: DialogRequest): void;
|
|
59
|
+
protected dialog<T>(request: DialogRequest, options: DialogOptions | undefined, fallback: T, parse: (response: Exclude<RpcExtensionUIResponse, {
|
|
60
|
+
cancelled: true;
|
|
61
|
+
}>) => T): Promise<T>;
|
|
62
|
+
}
|
|
63
|
+
export {};
|