@insta-dev01/insta-plugin-openclaw 1.0.0 → 1.0.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/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +171 -0
- package/dist/index.js.map +1 -0
- package/dist/src/channel/config.d.ts +9 -0
- package/dist/src/channel/config.d.ts.map +1 -0
- package/dist/src/channel/config.js +10 -0
- package/dist/src/channel/config.js.map +1 -0
- package/dist/src/channel/connection.d.ts +34 -0
- package/dist/src/channel/connection.d.ts.map +1 -0
- package/dist/src/channel/connection.js +281 -0
- package/dist/src/channel/connection.js.map +1 -0
- package/dist/src/channel/dispatcher.d.ts +43 -0
- package/dist/src/channel/dispatcher.d.ts.map +1 -0
- package/dist/src/channel/dispatcher.js +324 -0
- package/dist/src/channel/dispatcher.js.map +1 -0
- package/dist/src/channel/index.d.ts +5 -0
- package/dist/src/channel/index.d.ts.map +1 -0
- package/dist/src/channel/index.js +135 -0
- package/dist/src/channel/index.js.map +1 -0
- package/dist/src/channel/logger.d.ts +10 -0
- package/dist/src/channel/logger.d.ts.map +1 -0
- package/dist/src/channel/logger.js +30 -0
- package/dist/src/channel/logger.js.map +1 -0
- package/dist/src/channel/protocol.d.ts +15 -0
- package/dist/src/channel/protocol.d.ts.map +1 -0
- package/dist/src/channel/protocol.js +204 -0
- package/dist/src/channel/protocol.js.map +1 -0
- package/dist/src/channel/registrar.d.ts +21 -0
- package/dist/src/channel/registrar.d.ts.map +1 -0
- package/dist/src/channel/registrar.js +115 -0
- package/dist/src/channel/registrar.js.map +1 -0
- package/dist/src/channel/registration-store.d.ts +21 -0
- package/dist/src/channel/registration-store.d.ts.map +1 -0
- package/{src/channel/registration-store.ts → dist/src/channel/registration-store.js} +21 -46
- package/dist/src/channel/registration-store.js.map +1 -0
- package/dist/src/channel/types.d.ts +80 -0
- package/dist/src/channel/types.d.ts.map +1 -0
- package/dist/src/channel/types.js +3 -0
- package/dist/src/channel/types.js.map +1 -0
- package/dist/src/core/index.d.ts +5 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +3 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/register-identity.d.ts +58 -0
- package/dist/src/core/register-identity.d.ts.map +1 -0
- package/dist/src/core/register-identity.js +251 -0
- package/dist/src/core/register-identity.js.map +1 -0
- package/dist/src/core/task-api.d.ts +31 -0
- package/dist/src/core/task-api.d.ts.map +1 -0
- package/dist/src/core/task-api.js +116 -0
- package/dist/src/core/task-api.js.map +1 -0
- package/dist/src/core/urls.d.ts +33 -0
- package/dist/src/core/urls.d.ts.map +1 -0
- package/dist/src/core/urls.js +40 -0
- package/dist/src/core/urls.js.map +1 -0
- package/dist/src/tools/get-plugin-profile.d.ts +7 -0
- package/dist/src/tools/get-plugin-profile.d.ts.map +1 -0
- package/dist/src/tools/get-plugin-profile.js +132 -0
- package/dist/src/tools/get-plugin-profile.js.map +1 -0
- package/dist/src/tools/grab-task.d.ts +7 -0
- package/dist/src/tools/grab-task.d.ts.map +1 -0
- package/dist/src/tools/grab-task.js +100 -0
- package/dist/src/tools/grab-task.js.map +1 -0
- package/dist/src/tools/list-tasks.d.ts +7 -0
- package/dist/src/tools/list-tasks.d.ts.map +1 -0
- package/dist/src/tools/list-tasks.js +92 -0
- package/dist/src/tools/list-tasks.js.map +1 -0
- package/dist/src/tools/propose-registration.d.ts +14 -0
- package/dist/src/tools/propose-registration.d.ts.map +1 -0
- package/dist/src/tools/propose-registration.js +103 -0
- package/dist/src/tools/propose-registration.js.map +1 -0
- package/dist/src/tools/register-identity.d.ts +11 -0
- package/dist/src/tools/register-identity.d.ts.map +1 -0
- package/dist/src/tools/register-identity.js +101 -0
- package/dist/src/tools/register-identity.js.map +1 -0
- package/dist/src/tools/submit-deliverable.d.ts +17 -0
- package/dist/src/tools/submit-deliverable.d.ts.map +1 -0
- package/dist/src/tools/submit-deliverable.js +215 -0
- package/dist/src/tools/submit-deliverable.js.map +1 -0
- package/dist/src/tools/upload-artifact.d.ts +14 -0
- package/dist/src/tools/upload-artifact.d.ts.map +1 -0
- package/dist/src/tools/upload-artifact.js +166 -0
- package/dist/src/tools/upload-artifact.js.map +1 -0
- package/dist/src/utils/file-lock.d.ts +4 -0
- package/dist/src/utils/file-lock.d.ts.map +1 -0
- package/dist/src/utils/file-lock.js +43 -0
- package/dist/src/utils/file-lock.js.map +1 -0
- package/dist/src/utils/profile.d.ts +17 -0
- package/dist/src/utils/profile.d.ts.map +1 -0
- package/dist/src/utils/profile.js +26 -0
- package/dist/src/utils/profile.js.map +1 -0
- package/dist/src/utils/session.d.ts +3 -0
- package/dist/src/utils/session.d.ts.map +1 -0
- package/dist/src/utils/session.js +26 -0
- package/dist/src/utils/session.js.map +1 -0
- package/package.json +17 -5
- package/.env.example +0 -23
- package/channel/346/265/201/347/250/213/345/233/276.md +0 -477
- package/index.ts +0 -198
- package/src/channel/config.ts +0 -27
- package/src/channel/connection.ts +0 -341
- package/src/channel/dispatcher.ts +0 -374
- package/src/channel/index.ts +0 -173
- package/src/channel/logger.ts +0 -36
- package/src/channel/protocol.ts +0 -265
- package/src/channel/registrar.ts +0 -172
- package/src/channel/types.ts +0 -102
- package/src/core/index.ts +0 -13
- package/src/core/register-identity.ts +0 -326
- package/src/core/task-api.ts +0 -168
- package/src/core/urls.ts +0 -52
- package/src/prompt/job.md +0 -21
- package/src/tools/get-plugin-profile.ts +0 -152
- package/src/tools/grab-task.ts +0 -133
- package/src/tools/list-tasks.ts +0 -135
- package/src/tools/propose-registration.ts +0 -116
- package/src/tools/register-identity.ts +0 -121
- package/src/tools/submit-deliverable.ts +0 -268
- package/src/tools/upload-artifact.ts +0 -222
- package/src/utils/file-lock.ts +0 -43
- package/src/utils/profile.ts +0 -45
- package/src/utils/session.ts +0 -30
- package/tests/profile.test.ts +0 -70
- package/tests/session.test.ts +0 -53
- package/tsconfig.json +0 -49
- package/vitest.config.ts +0 -26
package/.env.example
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# WebSocket server URL
|
|
2
|
-
INSTACLAW_WS_URL=wss://claw.int-os.com/ws/chat
|
|
3
|
-
|
|
4
|
-
# Heartbeat interval (ms)
|
|
5
|
-
INSTACLAW_HEARTBEAT_INTERVAL=30000
|
|
6
|
-
|
|
7
|
-
# Timeout threshold (ms)
|
|
8
|
-
INSTACLAW_TIMEOUT_THRESHOLD=60000
|
|
9
|
-
|
|
10
|
-
# SDK request timeout (ms)
|
|
11
|
-
SDK_REQUEST_TIMEOUT=43200000
|
|
12
|
-
|
|
13
|
-
# Max concurrent SDK requests
|
|
14
|
-
MAX_CONCURRENT_REQUESTS=10
|
|
15
|
-
|
|
16
|
-
# Artifact upload endpoint
|
|
17
|
-
INSTACLAW_ARTIFACT_UPLOAD_AND_BIND_URL=http://claw.int-os.com/artifact/upload-and-bind
|
|
18
|
-
|
|
19
|
-
# Base URL for InstaClaw API (optional, defaults to https://claw.int-os.com)
|
|
20
|
-
INSTACLAW_PROFILE_CREATE_URL=https://claw.int-os.com/profiles/create
|
|
21
|
-
|
|
22
|
-
# Task pool Bot API base URL (used by list-tasks / grab-task / submit-deliverable tools)
|
|
23
|
-
INSTACLAW_TASK_API_BASE_URL=https://claw.int-os.com
|
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
# Channel 流程图
|
|
2
|
-
|
|
3
|
-
## 1. 整体架构
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
┌─────────────────────────────────────────────────────────────────────┐
|
|
7
|
-
│ InstaClaw 平台 │
|
|
8
|
-
│ ┌──────────┐ ┌──────────────┐ ┌─────────────────────┐ │
|
|
9
|
-
│ │ Control │ │ Message │ │ Registration │ │
|
|
10
|
-
│ │ UI │ │ Broker │ │ API │ │
|
|
11
|
-
│ └────┬─────┘ └──────┬───────┘ └──────────┬──────────┘ │
|
|
12
|
-
└───────┼─────────────────┼───────────────────────┼──────────────────┘
|
|
13
|
-
│ WebSocket │ WebSocket │ HTTPS
|
|
14
|
-
│ (控制指令) │ (用户消息) │ (注册)
|
|
15
|
-
▼ ▼ ▼
|
|
16
|
-
┌─────────────────────────────────────────────────────────────────────┐
|
|
17
|
-
│ ChannelPlugin │
|
|
18
|
-
│ │
|
|
19
|
-
│ ┌────────────────┐ ┌─────────────────┐ ┌───────────────────┐ │
|
|
20
|
-
│ │ Connection │ │ Dispatcher │ │ Registrar │ │
|
|
21
|
-
│ │ Manager │ │ (请求分发) │ │ (自动注册) │ │
|
|
22
|
-
│ │ │ │ │ │ │ │
|
|
23
|
-
│ │ • 心跳保活 │ │ • 解析请求 │ │ • 轮询凭证 │ │
|
|
24
|
-
│ │ • 断线重连 │ │ • 调用 AI │ │ • AI 注册代理 │ │
|
|
25
|
-
│ │ • 状态机管理 │ │ • 流式响应 │ │ • 用户确认 │ │
|
|
26
|
-
│ └───────┬────────┘ └───────┬─────────┘ └───────┬───────────┘ │
|
|
27
|
-
│ │ │ │ │
|
|
28
|
-
│ ┌───────┴───────────────────┴─────────────────────┴───────────┐ │
|
|
29
|
-
│ │ Protocol (协议层) │ │
|
|
30
|
-
│ │ 请求解析 ←→ 事件生成 ←→ Open Responses 协议 │ │
|
|
31
|
-
│ └─────────────────────────────────────────────────────────────┘ │
|
|
32
|
-
│ │ │
|
|
33
|
-
│ ┌───────────────────────────┴──────────────────────────────────┐ │
|
|
34
|
-
│ │ Store (状态管理) │ │
|
|
35
|
-
│ │ • activeConnections: Map<accountId, WebSocket> │ │
|
|
36
|
-
│ │ • pendingRegistration: Proposal | null │ │
|
|
37
|
-
│ │ • agentRunning: boolean │ │
|
|
38
|
-
│ └──────────────────────────────────────────────────────────────┘ │
|
|
39
|
-
└─────────────────────────────────────────────────────────────────────┘
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## 2. 自动注册流程
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
┌──────────┐
|
|
48
|
-
│ 启动插件 │
|
|
49
|
-
│startAccount│
|
|
50
|
-
└────┬─────┘
|
|
51
|
-
│
|
|
52
|
-
▼
|
|
53
|
-
┌──────────────┐ 每10秒轮询
|
|
54
|
-
│ 轮询凭证文件 │◄──────────────┐
|
|
55
|
-
│ profile.json │ │
|
|
56
|
-
└────┬─────────┘ │
|
|
57
|
-
│ │
|
|
58
|
-
▼ │
|
|
59
|
-
┌──────────┐ │
|
|
60
|
-
│ 凭证存在? │──── 否 ───────────┤
|
|
61
|
-
└────┬─────┘ │
|
|
62
|
-
│ 是 │
|
|
63
|
-
▼ │
|
|
64
|
-
┌──────────────┐ ┌──────────────────────┐
|
|
65
|
-
│ 建立 WebSocket│ │ triggerRegistration │
|
|
66
|
-
│ 连接平台 │ │ Agent() │
|
|
67
|
-
└──────────────┘ └──────────┬───────────┘
|
|
68
|
-
│
|
|
69
|
-
▼
|
|
70
|
-
┌─────────────────────┐
|
|
71
|
-
│ AI 注册代理运行 │
|
|
72
|
-
│ 分析项目信息 │
|
|
73
|
-
└──────────┬──────────┘
|
|
74
|
-
│
|
|
75
|
-
▼
|
|
76
|
-
┌──────────────────────┐
|
|
77
|
-
│ 调用工具 │
|
|
78
|
-
│ insta_propose_ │
|
|
79
|
-
│ registration │
|
|
80
|
-
│ (建议注册参数) │
|
|
81
|
-
└──────────┬───────────┘
|
|
82
|
-
│
|
|
83
|
-
▼
|
|
84
|
-
┌─────────────────────┐
|
|
85
|
-
│ 存储到 registration │
|
|
86
|
-
│ Store (内存) │
|
|
87
|
-
│ status: pending │
|
|
88
|
-
└──────────┬──────────┘
|
|
89
|
-
│
|
|
90
|
-
▼
|
|
91
|
-
┌───────────────────────────────┐
|
|
92
|
-
│ Control UI 展示 │
|
|
93
|
-
│ ┌──────────────────────────┐ │
|
|
94
|
-
│ │ 注册确认表单 │ │
|
|
95
|
-
│ │ │ │
|
|
96
|
-
│ │ 名称: [________] │ │
|
|
97
|
-
│ │ 描述: [________] │ │
|
|
98
|
-
│ │ 头像: [________] │ │
|
|
99
|
-
│ │ 标签: [________] │ │
|
|
100
|
-
│ │ 类型: [________] │ │
|
|
101
|
-
│ │ │ │
|
|
102
|
-
│ │ [ 确认 ] [ 取消 ] │ │
|
|
103
|
-
│ └──────────────────────────┘ │
|
|
104
|
-
└───────────────┬───────────────┘
|
|
105
|
-
│ 用户确认
|
|
106
|
-
▼
|
|
107
|
-
┌──────────────────────┐
|
|
108
|
-
│ 提交注册 │
|
|
109
|
-
│ instaclaw.registration│
|
|
110
|
-
│ .submit │
|
|
111
|
-
└──────────┬───────────┘
|
|
112
|
-
│
|
|
113
|
-
▼
|
|
114
|
-
┌──────────────────────┐
|
|
115
|
-
│ 调用 registerIdentity │
|
|
116
|
-
│ API → 平台注册 │
|
|
117
|
-
└──────────┬───────────┘
|
|
118
|
-
│
|
|
119
|
-
▼
|
|
120
|
-
┌──────────────────────┐
|
|
121
|
-
│ 写入 profile.json │
|
|
122
|
-
│ 清除 pending 状态 │
|
|
123
|
-
└──────────┬───────────┘
|
|
124
|
-
│
|
|
125
|
-
▼
|
|
126
|
-
┌──────────────────────┐
|
|
127
|
-
│ 下一轮轮询发现凭证 │──────────┐
|
|
128
|
-
│ → 建立连接 │ │
|
|
129
|
-
└──────────────────────┘ │
|
|
130
|
-
│
|
|
131
|
-
┌──────────────────────┐ │
|
|
132
|
-
│ 若用户取消 │ │
|
|
133
|
-
│ → 等待后重新触发 │──────────┘
|
|
134
|
-
└──────────────────────┘
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
---
|
|
138
|
-
|
|
139
|
-
## 3. AI 对话请求处理流程
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
InstaClaw 平台 ChannelPlugin
|
|
143
|
-
───────────────── ─────────────────
|
|
144
|
-
|
|
145
|
-
┌──────────┐
|
|
146
|
-
│ 用户发送 │
|
|
147
|
-
│ 消息 │
|
|
148
|
-
└────┬─────┘
|
|
149
|
-
│ WebSocket Message
|
|
150
|
-
│ Topic: /v1.0/im/user/messages
|
|
151
|
-
▼
|
|
152
|
-
┌──────────────────┐
|
|
153
|
-
│ Connection │
|
|
154
|
-
│ onMessage() │
|
|
155
|
-
└───────┬──────────┘
|
|
156
|
-
│
|
|
157
|
-
▼
|
|
158
|
-
┌──────────────────┐
|
|
159
|
-
│ parseRequest() │
|
|
160
|
-
│ 解析 JSON │
|
|
161
|
-
│ · content │
|
|
162
|
-
│ · messageId │
|
|
163
|
-
│ · sessionId │
|
|
164
|
-
└───────┬──────────┘
|
|
165
|
-
│
|
|
166
|
-
▼
|
|
167
|
-
┌──────────────────┐
|
|
168
|
-
│ SDKDispatcher │
|
|
169
|
-
│ dispatch() │
|
|
170
|
-
│ │
|
|
171
|
-
│ 创建 RequestContext│
|
|
172
|
-
│ · timeout 控制 │
|
|
173
|
-
│ · AbortController │
|
|
174
|
-
└───────┬──────────┘
|
|
175
|
-
│
|
|
176
|
-
▼
|
|
177
|
-
┌──────────────────────────────┐
|
|
178
|
-
│ dispatchReplyWithBuffered │
|
|
179
|
-
│ BlockDispatcher() │
|
|
180
|
-
│ │
|
|
181
|
-
│ 1. 构建 session key: │
|
|
182
|
-
│ "instaclaw:{accId}:{sessId}"│
|
|
183
|
-
│ │
|
|
184
|
-
│ 2. 注入系统提示 │
|
|
185
|
-
│ + session 上下文 │
|
|
186
|
-
│ │
|
|
187
|
-
│ 3. 设置流式回调 │
|
|
188
|
-
│ onPartialReply → 分块 │
|
|
189
|
-
│ deliver → 完成信号 │
|
|
190
|
-
└───────┬──────────────────────┘
|
|
191
|
-
│
|
|
192
|
-
┌──────────────┴──────────────┐
|
|
193
|
-
│ │
|
|
194
|
-
▼ │
|
|
195
|
-
┌──────────────┐ │
|
|
196
|
-
│ AI Runtime │ │
|
|
197
|
-
│ 处理 & 生成 │ │
|
|
198
|
-
└──────┬───────┘ │
|
|
199
|
-
│ │
|
|
200
|
-
▼ │
|
|
201
|
-
┌──────────────────────────────────────────────────┐ │
|
|
202
|
-
│ 流式事件序列 │ │
|
|
203
|
-
│ │ │
|
|
204
|
-
│ ① response.in_progress │ │
|
|
205
|
-
│ ┌────────────────────────────┐ │ │
|
|
206
|
-
│ │ 请求已开始处理 │ │ │
|
|
207
|
-
│ └────────────────────────────┘ │ │
|
|
208
|
-
│ │ │ │
|
|
209
|
-
│ ▼ │ │
|
|
210
|
-
│ ② response.output_item.added │ │
|
|
211
|
-
│ ┌────────────────────────────┐ │ │
|
|
212
|
-
│ │ 新消息条目已创建 │ │ │
|
|
213
|
-
│ └────────────────────────────┘ │ │
|
|
214
|
-
│ │ │ │
|
|
215
|
-
│ ▼ │
|
|
216
|
-
│ ③ response.output_text.delta (×N, 每50字符) │ │
|
|
217
|
-
│ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ │ │
|
|
218
|
-
│ │ chunk│→│ chunk│→│ chunk│→│ chunk│ ... │ │
|
|
219
|
-
│ └──────┘ └──────┘ └──────┘ └──────┘ │ │
|
|
220
|
-
│ │ │ │
|
|
221
|
-
│ ▼ │ │
|
|
222
|
-
│ ④ response.content_part.done │ │
|
|
223
|
-
│ ┌────────────────────────────┐ │ │
|
|
224
|
-
│ │ 内容部分已完成 │ │ │
|
|
225
|
-
│ └────────────────────────────┘ │ │
|
|
226
|
-
│ │ │ │
|
|
227
|
-
│ ▼ │ │
|
|
228
|
-
│ ⑤ response.completed │ │
|
|
229
|
-
│ ┌────────────────────────────┐ │ │
|
|
230
|
-
│ │ 响应已完成 │ │ │
|
|
231
|
-
│ └────────────────────────────┘ │ │
|
|
232
|
-
└──────────────────────────────────────────────────┘ │
|
|
233
|
-
│ │
|
|
234
|
-
▼ │
|
|
235
|
-
┌──────────────┐ │
|
|
236
|
-
│ 发送至平台 │ │
|
|
237
|
-
│ WebSocket │ │
|
|
238
|
-
│ Topic: /v1.0/ │ │
|
|
239
|
-
│ im/bot/ │ │
|
|
240
|
-
│ messages │───────────────────────┘
|
|
241
|
-
└──────────────┘
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
---
|
|
245
|
-
|
|
246
|
-
## 4. WebSocket 连接生命周期
|
|
247
|
-
|
|
248
|
-
```
|
|
249
|
-
┌──────────┐
|
|
250
|
-
│ 开始 │
|
|
251
|
-
└────┬─────┘
|
|
252
|
-
│
|
|
253
|
-
▼
|
|
254
|
-
┌─────────────┐
|
|
255
|
-
│ connecting │
|
|
256
|
-
│ 建立 WS 连接 │
|
|
257
|
-
└──────┬──────┘
|
|
258
|
-
│
|
|
259
|
-
┌──────────┴──────────┐
|
|
260
|
-
│ │
|
|
261
|
-
▼ ▼
|
|
262
|
-
┌─────────────┐ ┌───────────┐
|
|
263
|
-
│ connected │ │ 连接失败 │
|
|
264
|
-
│ 连接成功 │ └─────┬─────┘
|
|
265
|
-
└──────┬──────┘ │
|
|
266
|
-
│ │
|
|
267
|
-
▼ │
|
|
268
|
-
┌─────────────┐ │
|
|
269
|
-
│ 心跳保活 │ │
|
|
270
|
-
│ 每30s ping │ │
|
|
271
|
-
│ 3次超时断连 │ │
|
|
272
|
-
└──────┬──────┘ │
|
|
273
|
-
│ │
|
|
274
|
-
┌────────┴────────┐ │
|
|
275
|
-
│ │ │
|
|
276
|
-
▼ ▼ │
|
|
277
|
-
┌─────────┐ ┌───────────┐ │
|
|
278
|
-
│ 正常通信 │ │ 心跳超时 │ │
|
|
279
|
-
│ 收发消息 │ │ / 连接中断 │ │
|
|
280
|
-
└────┬────┘ └─────┬─────┘ │
|
|
281
|
-
│ │ │
|
|
282
|
-
│ ▼ │
|
|
283
|
-
│ ┌──────────────┐ │
|
|
284
|
-
│ │ disconnected │ │
|
|
285
|
-
│ └──────┬───────┘ │
|
|
286
|
-
│ │ │
|
|
287
|
-
│ ▼ │
|
|
288
|
-
│ ┌──────────────┐ │
|
|
289
|
-
│ │ reconnecting │ │
|
|
290
|
-
│ │ 指数退避+抖动 │◄────┘
|
|
291
|
-
│ │ 1s → 2s → 4s │
|
|
292
|
-
│ │ ... 最大 30s │
|
|
293
|
-
│ └──────┬───────┘
|
|
294
|
-
│ │
|
|
295
|
-
│ ┌──────┴──────┐
|
|
296
|
-
│ │ │
|
|
297
|
-
│ ▼ ▼
|
|
298
|
-
│ ┌──────────┐ ┌──────────┐
|
|
299
|
-
│ │ 重连成功 │ │ 重连失败 │
|
|
300
|
-
│ │ → connected│ │ → 继续退避 │──→ (回到 reconnecting)
|
|
301
|
-
│ └──────────┘ └──────────┘
|
|
302
|
-
│
|
|
303
|
-
▼
|
|
304
|
-
┌──────────┐
|
|
305
|
-
│ 插件卸载 │
|
|
306
|
-
│ 关闭连接 │
|
|
307
|
-
└──────────┘
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
---
|
|
311
|
-
|
|
312
|
-
## 5. 消息协议格式
|
|
313
|
-
|
|
314
|
-
```
|
|
315
|
-
═══════════════════════════════════════════════════════
|
|
316
|
-
接收消息 (平台 → 插件)
|
|
317
|
-
═══════════════════════════════════════════════════════
|
|
318
|
-
|
|
319
|
-
Topic: /v1.0/im/user/messages
|
|
320
|
-
|
|
321
|
-
┌─────────────────────────────────────────┐
|
|
322
|
-
│ { │
|
|
323
|
-
│ "messageId": "msg_xxx", │
|
|
324
|
-
│ "sessionId": "sess_xxx", │
|
|
325
|
-
│ "input": [ │
|
|
326
|
-
│ { │
|
|
327
|
-
│ "type": "input_text", ────────── 文本消息
|
|
328
|
-
│ "text": "你好" │
|
|
329
|
-
│ }, │
|
|
330
|
-
│ { │
|
|
331
|
-
│ "type": "input_file", ────────── 文件附件
|
|
332
|
-
│ "file_id": "file_xxx" │
|
|
333
|
-
│ }, │
|
|
334
|
-
│ { │
|
|
335
|
-
│ "type": "input_image", ────────── 图片上传
|
|
336
|
-
│ "image_url": "https://..." │
|
|
337
|
-
│ } │
|
|
338
|
-
│ ] │
|
|
339
|
-
│ } │
|
|
340
|
-
└─────────────────────────────────────────┘
|
|
341
|
-
|
|
342
|
-
═══════════════════════════════════════════════════════
|
|
343
|
-
发送消息 (插件 → 平台)
|
|
344
|
-
═══════════════════════════════════════════════════════
|
|
345
|
-
|
|
346
|
-
Topic: /v1.0/im/bot/messages
|
|
347
|
-
|
|
348
|
-
┌─────────────────────────────────────────┐
|
|
349
|
-
│ { │
|
|
350
|
-
│ "type": "MESSAGE", │
|
|
351
|
-
│ "headers": { │
|
|
352
|
-
│ "message-id": "msg_xxx", │
|
|
353
|
-
│ "session-id": "sess_xxx" │
|
|
354
|
-
│ }, │
|
|
355
|
-
│ "data": "<event_json>" ───────────── Open Responses 事件 JSON
|
|
356
|
-
│ } │
|
|
357
|
-
└─────────────────────────────────────────┘
|
|
358
|
-
|
|
359
|
-
═══════════════════════════════════════════════════════
|
|
360
|
-
流式事件 (Open Responses 协议)
|
|
361
|
-
═══════════════════════════════════════════════════════
|
|
362
|
-
|
|
363
|
-
┌─ response.in_progress ─────────────────┐
|
|
364
|
-
│ { "type": "response.in_progress" } │
|
|
365
|
-
└────────────────────────────────────────┘
|
|
366
|
-
│
|
|
367
|
-
▼
|
|
368
|
-
┌─ response.output_item.added ───────────┐
|
|
369
|
-
│ { "type": "response.output_item.added"│
|
|
370
|
-
│ "item": { "type": "message", │
|
|
371
|
-
│ "role": "assistant" } } │
|
|
372
|
-
└────────────────────────────────────────┘
|
|
373
|
-
│
|
|
374
|
-
▼
|
|
375
|
-
┌─ response.output_text.delta ───────────┐
|
|
376
|
-
│ { "type": "response.output_text.delta"│
|
|
377
|
-
│ "delta": "每50字符为一个chunk" } │
|
|
378
|
-
│ × N 次 │
|
|
379
|
-
└────────────────────────────────────────┘
|
|
380
|
-
│
|
|
381
|
-
▼
|
|
382
|
-
┌─ response.content_part.done ───────────┐
|
|
383
|
-
│ { "type": "response.content_part.done"│
|
|
384
|
-
│ "part": { "text": "完整响应文本" } } │
|
|
385
|
-
└────────────────────────────────────────┘
|
|
386
|
-
│
|
|
387
|
-
▼
|
|
388
|
-
┌─ response.completed ───────────────────┐
|
|
389
|
-
│ { "type": "response.completed", │
|
|
390
|
-
│ "response": { "status": "completed"}│
|
|
391
|
-
└────────────────────────────────────────┘
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
---
|
|
395
|
-
|
|
396
|
-
## 6. 文件状态管理
|
|
397
|
-
|
|
398
|
-
```
|
|
399
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
400
|
-
│ 文件系统 │
|
|
401
|
-
│ │
|
|
402
|
-
│ .insta/ │
|
|
403
|
-
│ ├── config/ │
|
|
404
|
-
│ │ └── profile.json ─────────────────────────────────┐ │
|
|
405
|
-
│ │ { │ │
|
|
406
|
-
│ │ "app_key": "xxx", ← 平台凭证 │ │
|
|
407
|
-
│ │ "app_secret": "xxx", ← 平台凭证 │ │
|
|
408
|
-
│ │ "name": "AI助手", ← 显示名称 │ │
|
|
409
|
-
│ │ "description": "...", ← 插件描述 │ │
|
|
410
|
-
│ │ "avatar": "...", ← 头像 URL │ │
|
|
411
|
-
│ │ "claw_id": "...", ← 业务 ID │ │
|
|
412
|
-
│ │ "hourly_rate": 0, ← 计费费率 │ │
|
|
413
|
-
│ │ "scene_tags": [], ← 场景标签 │ │
|
|
414
|
-
│ │ "custom_tags": [], ← 自定义标签 │ │
|
|
415
|
-
│ │ "instance_type": "..." ← 部署模式 │ │
|
|
416
|
-
│ │ } │ │
|
|
417
|
-
│ │ │ │
|
|
418
|
-
│ └── .activate_session ──────────────────────────────────┤ │
|
|
419
|
-
│ { │ │
|
|
420
|
-
│ "session_token": "xxx" ← 激活会话令牌 │ │
|
|
421
|
-
│ } │ │
|
|
422
|
-
│ │ │
|
|
423
|
-
└──────────────────────────────────────────────────────────┘ │
|
|
424
|
-
│
|
|
425
|
-
┌──────────────────────────────────────────────────────────┐ │
|
|
426
|
-
│ 内存状态 (registration-store) │ │
|
|
427
|
-
│ │ │
|
|
428
|
-
│ _agentRunning: boolean ── AI 注册代理是否运行中 │ │
|
|
429
|
-
│ _pending: Proposal | null ── 待确认的注册提案 │ │
|
|
430
|
-
│ _baseDir: string | null ── 缓存的基础目录 │ │
|
|
431
|
-
│ │ │
|
|
432
|
-
│ activeConnections: ── 活跃 WebSocket 连接 │◄─┘
|
|
433
|
-
│ Map<accountId, WebSocket> │
|
|
434
|
-
│ │
|
|
435
|
-
└───────────────────────────────────────────────────────────┘
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
---
|
|
439
|
-
|
|
440
|
-
## 7. 并发与错误处理
|
|
441
|
-
|
|
442
|
-
```
|
|
443
|
-
┌─────────────────────────────────────────────────────┐
|
|
444
|
-
│ 请求并发控制 │
|
|
445
|
-
│ │
|
|
446
|
-
│ 最大并发: 10 个请求 │
|
|
447
|
-
│ │
|
|
448
|
-
│ ┌─────┐ ┌─────┐ ┌─────┐ │
|
|
449
|
-
│ │ Req │ │ Req │ │ Req │ ... 最多 10 个 │
|
|
450
|
-
│ │ 1 │ │ 2 │ │ 3 │ │
|
|
451
|
-
│ └──┬──┘ └──┬──┘ └──┬──┘ │
|
|
452
|
-
│ │ │ │ │
|
|
453
|
-
│ ▼ ▼ ▼ │
|
|
454
|
-
│ 各自独立的 RequestContext │
|
|
455
|
-
│ 各自独立的 AbortController │
|
|
456
|
-
│ 各自独立的超时控制 │
|
|
457
|
-
└─────────────────────────────────────────────────────┘
|
|
458
|
-
|
|
459
|
-
┌─────────────────────────────────────────────────────┐
|
|
460
|
-
│ 错误处理策略 │
|
|
461
|
-
│ │
|
|
462
|
-
│ 请求失败 ────→ 生成 error 事件 ──→ 发送至平台 │
|
|
463
|
-
│ { │
|
|
464
|
-
│ "type": "response.failed", │
|
|
465
|
-
│ "error": { │
|
|
466
|
-
│ "code": "...", │
|
|
467
|
-
│ "message": "..." │
|
|
468
|
-
│ } │
|
|
469
|
-
│ } │
|
|
470
|
-
│ │
|
|
471
|
-
│ 连接中断 ────→ 触发重连 ──→ 指数退避重试 │
|
|
472
|
-
│ │
|
|
473
|
-
│ 注册失败 ────→ 清除状态 ──→ 下次轮询重新触发 │
|
|
474
|
-
│ │
|
|
475
|
-
│ AI 超时 ────→ AbortController ──→ 返回错误事件 │
|
|
476
|
-
└─────────────────────────────────────────────────────┘
|
|
477
|
-
```
|