xacpp 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Drodreo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # xacpp
2
+
3
+ [中文](./README.zh-CN.md)
4
+
5
+ Agent Control Plane Protocol — TypeScript implementation.
6
+
7
+ xacpp defines the communication protocol between an agent and its peers. It provides a layered architecture for request-response messaging with session management over multiple transport backends.
8
+
9
+ ## Architecture
10
+
11
+ ```
12
+ ┌──────────────────────────────────────────────────────────────┐
13
+ │ Peer (protocol layer) │
14
+ │ Typed operations + session routing │
15
+ ├──────────────────────────────────────────────────────────────┤
16
+ │ Session (session layer) │
17
+ │ Independent session context, sends directly via Transport │
18
+ ├──────────────────────────────────────────────────────────────┤
19
+ │ Transport (transport layer) │
20
+ │ Envelope assembly, id correlation, pending matching │
21
+ ├──────────────────────────────────────────────────────────────┤
22
+ │ Stdio / TCP / WebSocket │
23
+ └──────────────────────────────────────────────────────────────┘
24
+ ```
25
+
26
+ ## Install
27
+
28
+ ```bash
29
+ npm install xacpp
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ### Establish a session (initiator side)
35
+
36
+ ```typescript
37
+ import { XacppPeer, XacppSession, StdioTransport, XacppSessionHandler, XacppResponse } from "xacpp";
38
+
39
+ // Create transport + peer
40
+ const transport = new StdioTransport(process.stdout, process.stdin);
41
+
42
+ const peer = new XacppPeer(transport, {
43
+ async onEstablish(transport, credentials) {
44
+ return { sessionId: "server-session", handler: mySessionHandler };
45
+ },
46
+ });
47
+
48
+ await peer.connect();
49
+
50
+ // Establish a logical session
51
+ const session = await peer.establish(null, mySessionHandler);
52
+
53
+ // Send commands/events through the session
54
+ const response = await session.requestCommand("new_activity");
55
+ await session.requestEvent({ type: "think", content: "Hello!" });
56
+ ```
57
+
58
+ ### Handle incoming requests (responder side)
59
+
60
+ ```typescript
61
+ const sessionHandler: XacppSessionHandler = {
62
+ async onCommand(command) {
63
+ // Handle command
64
+ return { kind: "acknowledge" };
65
+ },
66
+ async onEvent(event) {
67
+ // Handle event
68
+ return { kind: "acknowledge" };
69
+ },
70
+ };
71
+ ```
72
+
73
+ ### TCP Transport (for network communication)
74
+
75
+ ```typescript
76
+ import { SocketTransport } from "xacpp";
77
+
78
+ // Client
79
+ const client = SocketTransport.connectTo(8080, "127.0.0.1");
80
+
81
+ // Server (with accepted socket)
82
+ const server = new SocketTransport(acceptedSocket);
83
+ ```
84
+
85
+ ## API
86
+
87
+ ### Types
88
+
89
+ | Type | Description |
90
+ |------|-------------|
91
+ | `XacppTransport` | Transport interface (`connect`, `disconnect`, `send`, `onRequest`) |
92
+ | `XacppPeer` | Protocol endpoint with session routing |
93
+ | `XacppSession` | Logical session, sends via Transport directly |
94
+ | `XacppSessionHandler` | Handles inbound Command/Event for a session |
95
+ | `EstablishHandler` | Handles Establish handshake requests |
96
+ | `XacppCommand` | Protocol commands (`establish`, `new_activity`, etc.) |
97
+ | `XacppEvent` | Protocol events (think, action_request, question, etc.) |
98
+ | `XacppRequest` | Request payload (`command` or `event`) |
99
+ | `XacppResponse` | Response payload (`established`, `acknowledge`, `action`, etc.) |
100
+ | `XacppError` | Error class with machine-readable codes |
101
+ | `PeerState` | Peer state enum (`Disconnected`, `Connected`) |
102
+
103
+ ### Transports
104
+
105
+ | Class | Description |
106
+ |-------|-------------|
107
+ | `StdioTransport` | stdin/stdout JSONL pipe |
108
+ | `SocketTransport` | TCP socket (`net.Socket`), spawn-per-request concurrency |
109
+
110
+ ## Wire Protocol
111
+
112
+ JSONL (one JSON object per line) with envelope structure:
113
+
114
+ ```json
115
+ {"type":"request","id":"r1","payload":{"kind":"command","payload":{"establish":{"credentials":null}}}}
116
+ {"type":"response","id":"r1","payload":{"kind":"established","sessionId":"s1"}}
117
+ ```
118
+
119
+ ## License
120
+
121
+ MIT
@@ -0,0 +1,121 @@
1
+ # xacpp
2
+
3
+ [English](./README.md)
4
+
5
+ Agent Control Plane Protocol — TypeScript 实现。
6
+
7
+ xacpp 定义了 Agent 与对端之间的通信协议。它提供了分层架构,支持基于请求-响应的消息传递、会话管理,以及多种传输后端。
8
+
9
+ ## 架构
10
+
11
+ ```
12
+ ┌──────────────────────────────────────────────────────────────┐
13
+ │ Peer(协议层) │
14
+ │ 类型化操作 + 会话路由 │
15
+ ├──────────────────────────────────────────────────────────────┤
16
+ │ Session(会话层) │
17
+ │ 独立会话上下文,直达 Transport 收发 │
18
+ ├──────────────────────────────────────────────────────────────┤
19
+ │ Transport(传输层) │
20
+ │ 信封装拆、id 关联、pending 匹配 │
21
+ ├──────────────────────────────────────────────────────────────┤
22
+ │ Stdio / TCP / WebSocket │
23
+ └──────────────────────────────────────────────────────────────┘
24
+ ```
25
+
26
+ ## 安装
27
+
28
+ ```bash
29
+ npm install xacpp
30
+ ```
31
+
32
+ ## 快速开始
33
+
34
+ ### 建立会话(发起方)
35
+
36
+ ```typescript
37
+ import { XacppPeer, XacppSession, StdioTransport, XacppSessionHandler, XacppResponse } from "xacpp";
38
+
39
+ // 创建 Transport + Peer
40
+ const transport = new StdioTransport(process.stdout, process.stdin);
41
+
42
+ const peer = new XacppPeer(transport, {
43
+ async onEstablish(transport, credentials) {
44
+ return { sessionId: "server-session", handler: mySessionHandler };
45
+ },
46
+ });
47
+
48
+ await peer.connect();
49
+
50
+ // 建立逻辑会话
51
+ const session = await peer.establish(null, mySessionHandler);
52
+
53
+ // 通过会话发送命令/事件
54
+ const response = await session.requestCommand("new_activity");
55
+ await session.requestEvent({ type: "think", content: "Hello!" });
56
+ ```
57
+
58
+ ### 处理入站请求(响应方)
59
+
60
+ ```typescript
61
+ const sessionHandler: XacppSessionHandler = {
62
+ async onCommand(command) {
63
+ // 处理命令
64
+ return { kind: "acknowledge" };
65
+ },
66
+ async onEvent(event) {
67
+ // 处理事件
68
+ return { kind: "acknowledge" };
69
+ },
70
+ };
71
+ ```
72
+
73
+ ### TCP 传输(网络通信)
74
+
75
+ ```typescript
76
+ import { SocketTransport } from "xacpp";
77
+
78
+ // 客户端
79
+ const client = SocketTransport.connectTo(8080, "127.0.0.1");
80
+
81
+ // 服务端(使用已 accept 的 socket)
82
+ const server = new SocketTransport(acceptedSocket);
83
+ ```
84
+
85
+ ## API
86
+
87
+ ### 类型
88
+
89
+ | 类型 | 说明 |
90
+ |------|------|
91
+ | `XacppTransport` | 传输层接口(`connect`、`disconnect`、`send`、`onRequest`) |
92
+ | `XacppPeer` | 协议端点,含会话路由 |
93
+ | `XacppSession` | 逻辑会话,直达 Transport 收发 |
94
+ | `XacppSessionHandler` | 处理会话内的入站 Command/Event |
95
+ | `EstablishHandler` | 处理 Establish 握手请求 |
96
+ | `XacppCommand` | 协议命令(`establish`、`new_activity` 等) |
97
+ | `XacppEvent` | 协议事件(think、action_request、question 等) |
98
+ | `XacppRequest` | 请求载荷(`command` 或 `event`) |
99
+ | `XacppResponse` | 响应载荷(`established`、`acknowledge`、`action` 等) |
100
+ | `XacppError` | 错误类,含机器可读错误码 |
101
+ | `PeerState` | Peer 状态枚举(`Disconnected`、`Connected`) |
102
+
103
+ ### 传输实现
104
+
105
+ | 类 | 说明 |
106
+ |---|------|
107
+ | `StdioTransport` | stdin/stdout JSONL 管道 |
108
+ | `SocketTransport` | TCP socket(`net.Socket`),spawn-per-request 并发模型 |
109
+
110
+ ## 线路协议
111
+
112
+ JSONL(每行一个 JSON 对象),信封结构:
113
+
114
+ ```json
115
+ {"type":"request","id":"r1","payload":{"kind":"command","payload":{"establish":{"credentials":null}}}}
116
+ {"type":"response","id":"r1","payload":{"kind":"established","sessionId":"s1"}}
117
+ ```
118
+
119
+ ## 许可证
120
+
121
+ MIT