@mininglamp-oss/octo-runtime 1.1.7 → 1.1.8
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/apps/cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +22 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +20 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.js +14 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -24
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +21 -33
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +3 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/dispatcher.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/dispatcher.js +29 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/identity.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/identity.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/send-error.d.ts +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/send-error.js +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/card-session.d.ts +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/card-session.js +54 -10
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +4 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +73 -109
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connector.d.ts +3 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connector.js +27 -40
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/reasoning-frame.js +42 -7
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +1 -12
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +6 -126
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/{index-CXTvRGim.js → index-B127MhT-.js} +10 -9
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/package.json +27 -27
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/text-send.d.ts +0 -19
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/text-send.js +0 -86
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/presentation/delivery-notice.d.ts +0 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/presentation/delivery-notice.js +0 -35
package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js
CHANGED
|
@@ -26,8 +26,7 @@ import { getGroupMembers } from "./api/conversations.js";
|
|
|
26
26
|
import { getJson } from "./api/client.js";
|
|
27
27
|
import { connectionFailure, ImConnectionError } from "./connection-error.js";
|
|
28
28
|
import { sendReadReceipt } from "./api/messages.js";
|
|
29
|
-
import {
|
|
30
|
-
import { ImSendError } from "../delivery/text-send.js";
|
|
29
|
+
import { ImSendError } from "../delivery/send-error.js";
|
|
31
30
|
import { assistantOutputFingerprint } from "../application/context-gap.js";
|
|
32
31
|
import { observesImScope } from "./normalize.js";
|
|
33
32
|
import { prepareArtifacts } from "../delivery/artifacts.js";
|
|
@@ -60,7 +59,7 @@ export class GatewayTransport {
|
|
|
60
59
|
#messageIdentityCache = new MessageIdentityCache();
|
|
61
60
|
#bindings = new Map();
|
|
62
61
|
constructor(config, credentials, callbacks,
|
|
63
|
-
// Bot
|
|
62
|
+
// Bot 持有任务准备与 REST 投递的期限、凭据及身份,接收 WS 不拥有这些资源。
|
|
64
63
|
deliveryOwner) {
|
|
65
64
|
this.config = config;
|
|
66
65
|
this.credentials = credentials;
|
|
@@ -84,13 +83,14 @@ export class GatewayTransport {
|
|
|
84
83
|
if (!/^bf_[A-Za-z0-9_-]+$/.test(token))
|
|
85
84
|
throw new Error("IM_BOT_TOKEN_INVALID");
|
|
86
85
|
const principal = await verifyBotIdentity(this.config.api_url, token, signal);
|
|
86
|
+
signal.throwIfAborted();
|
|
87
87
|
try {
|
|
88
88
|
if (principal.bot_uid !== this.config.bot_id)
|
|
89
89
|
throw new Error("IM_BOT_IDENTITY_MISMATCH");
|
|
90
90
|
this.callbacks.authorizeSpace?.(principal.space_id);
|
|
91
91
|
}
|
|
92
92
|
catch (error) {
|
|
93
|
-
// REST
|
|
93
|
+
// REST 在核验期间继续使用旧凭据;明确拒绝目标后必须撤销旧任务权限。
|
|
94
94
|
// 只在明确身份/空间拒绝后撤销,网络失败、单纯换 token 和握手失败不走此分支。
|
|
95
95
|
this.deliveryOwner?.identity.revoke();
|
|
96
96
|
this.#deliveryScope.revoke();
|
|
@@ -102,12 +102,18 @@ export class GatewayTransport {
|
|
|
102
102
|
this.identity = `${imBotIdentity(this.config)}:${encodeURIComponent(this.#spaceId)}`;
|
|
103
103
|
// 必须在身份核验及空间准入成功后推进代次;连接失败/再次重连不能复活旧代次。
|
|
104
104
|
this.#deliveryScope = this.deliveryOwner?.identity.accept(this.identity) ?? this.#deliveryScope;
|
|
105
|
+
// 代次与凭据在同一同步段生效,不等待后续注册或 WS 握手。
|
|
106
|
+
this.deliveryOwner?.acceptToken?.(token);
|
|
105
107
|
const registration = await registerBot(this.config.api_url, token, signal);
|
|
106
108
|
const toolEnvironment = octoCliEnvironment(this.config.api_url, token);
|
|
107
109
|
if (signal.aborted)
|
|
108
110
|
return;
|
|
109
|
-
if (registration.robot_id !== this.config.bot_id)
|
|
111
|
+
if (registration.robot_id !== this.config.bot_id) {
|
|
112
|
+
// 注册明确拒绝身份也属于授权撤销;网络/握手失败则保留已核验凭据和任务。
|
|
113
|
+
this.deliveryOwner?.identity.revoke();
|
|
114
|
+
this.#deliveryScope.revoke();
|
|
110
115
|
throw new Error("IM_BOT_IDENTITY_MISMATCH");
|
|
116
|
+
}
|
|
111
117
|
const connection = new WukongConnection((message) => {
|
|
112
118
|
if (this.#closed)
|
|
113
119
|
return;
|
|
@@ -123,24 +129,17 @@ export class GatewayTransport {
|
|
|
123
129
|
return;
|
|
124
130
|
let finalReply;
|
|
125
131
|
let finalOutputCovered = false;
|
|
126
|
-
let replyConnection = connection;
|
|
127
132
|
const deliverySignal = AbortSignal.any([
|
|
128
133
|
this.deliveryOwner?.signal ?? signal,
|
|
129
134
|
this.#deliveryScope.signal
|
|
130
135
|
]);
|
|
131
|
-
//
|
|
132
|
-
const restDelivery = (turnSignal = deliverySignal, obsolete) => new OctoConnector(this.config, token, AbortSignal.any([deliverySignal, turnSignal]),
|
|
136
|
+
// 任务的普通回复、final、进度及失败卡共用 REST 工厂和任务期限。
|
|
137
|
+
const restDelivery = (turnSignal = deliverySignal, obsolete) => new OctoConnector(this.config, token, AbortSignal.any([deliverySignal, turnSignal]), (requestSignal, send) => this.#dispatchRestDelivery(requestSignal, (authorized, botToken) => {
|
|
133
138
|
if (obsolete?.())
|
|
134
139
|
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
135
140
|
return send(authorized, botToken);
|
|
136
141
|
}));
|
|
137
142
|
const finalDispatcher = this.#delivery;
|
|
138
|
-
const replyDelivered = (effectKey) => {
|
|
139
|
-
const key = stableEffectKey(this.identity, message, effectKey, "text");
|
|
140
|
-
return (this.#deliveryScope.isConfirmed(key) ||
|
|
141
|
-
connection.isDelivered(key) ||
|
|
142
|
-
replyConnection.isDelivered(key));
|
|
143
|
-
};
|
|
144
143
|
let historyTurn;
|
|
145
144
|
const outputObserver = (payload) => {
|
|
146
145
|
const turn = historyTurn;
|
|
@@ -149,10 +148,7 @@ export class GatewayTransport {
|
|
|
149
148
|
return (messageSeq) => {
|
|
150
149
|
if (deliverySignal.aborted)
|
|
151
150
|
return;
|
|
152
|
-
|
|
153
|
-
if (!current)
|
|
154
|
-
return;
|
|
155
|
-
current.callbacks.onPosition?.({
|
|
151
|
+
(this.callbacks.onTaskPosition ?? this.callbacks.onPosition)?.({
|
|
156
152
|
conversationId: message.channelId,
|
|
157
153
|
conversationKind: message.channelType === 5 ? "thread" : "group",
|
|
158
154
|
messageSeq,
|
|
@@ -164,6 +160,30 @@ export class GatewayTransport {
|
|
|
164
160
|
});
|
|
165
161
|
};
|
|
166
162
|
};
|
|
163
|
+
// 同一次在途 HTTP 共用 Promise;失败交回当前投递器,只有收尾拥有三次重试预算。
|
|
164
|
+
const sends = new Map();
|
|
165
|
+
const sendMessage = (payload, key, turnSignal, obsolete, observe) => {
|
|
166
|
+
turnSignal.throwIfAborted();
|
|
167
|
+
if (obsolete?.())
|
|
168
|
+
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
169
|
+
if (this.#deliveryScope.isConfirmed(key))
|
|
170
|
+
return Promise.resolve("");
|
|
171
|
+
const pending = sends.get(key);
|
|
172
|
+
if (pending)
|
|
173
|
+
return pending;
|
|
174
|
+
const sending = restDelivery(turnSignal, obsolete)
|
|
175
|
+
.message(message, payload, key, observe)
|
|
176
|
+
.then((id) => {
|
|
177
|
+
this.#deliveryScope.confirm(key);
|
|
178
|
+
sends.delete(key);
|
|
179
|
+
return id;
|
|
180
|
+
}, (error) => {
|
|
181
|
+
sends.delete(key);
|
|
182
|
+
throw error;
|
|
183
|
+
});
|
|
184
|
+
sends.set(key, sending);
|
|
185
|
+
return sending;
|
|
186
|
+
};
|
|
167
187
|
this.callbacks.onMessage({
|
|
168
188
|
messageId: message.messageId,
|
|
169
189
|
...(message.channelType === 2 || message.channelType === 5
|
|
@@ -176,11 +196,11 @@ export class GatewayTransport {
|
|
|
176
196
|
: {}),
|
|
177
197
|
markRead: (turnSignal) => sendReadReceipt({
|
|
178
198
|
apiUrl: this.config.api_url,
|
|
179
|
-
botToken:
|
|
199
|
+
botToken: this.#taskToken(deliverySignal),
|
|
180
200
|
channelId: message.channelId,
|
|
181
201
|
channelType: message.channelType,
|
|
182
202
|
messageIds: [message.messageId],
|
|
183
|
-
signal: AbortSignal.any([
|
|
203
|
+
signal: AbortSignal.any([deliverySignal, turnSignal])
|
|
184
204
|
}),
|
|
185
205
|
senderId: message.fromUid,
|
|
186
206
|
conversationId: message.channelId,
|
|
@@ -196,12 +216,11 @@ export class GatewayTransport {
|
|
|
196
216
|
: String(message.payload.content),
|
|
197
217
|
...(message.payload.type === 2
|
|
198
218
|
? {
|
|
199
|
-
buildInputs: (turnSignal) => downloadImageInput(message.payload.url, this.config.api_url,
|
|
219
|
+
buildInputs: (turnSignal) => downloadImageInput(message.payload.url, this.config.api_url, this.#taskToken(deliverySignal), AbortSignal.any([deliverySignal, turnSignal]))
|
|
200
220
|
}
|
|
201
221
|
: {}),
|
|
202
222
|
executionEnvironment: () => {
|
|
203
|
-
|
|
204
|
-
throw new Error("IM_CONNECTION_REPLACED");
|
|
223
|
+
deliverySignal.throwIfAborted();
|
|
205
224
|
return { executionEnvOverrides: structuredClone(toolEnvironment) };
|
|
206
225
|
},
|
|
207
226
|
runMetadata: {
|
|
@@ -209,16 +228,6 @@ export class GatewayTransport {
|
|
|
209
228
|
botId: this.config.bot_id,
|
|
210
229
|
channelType: message.channelType
|
|
211
230
|
},
|
|
212
|
-
isReplyDelivered: replyDelivered,
|
|
213
|
-
replyDeliveryUnknown: async (event, effectKey, replyEffectKey, deliverySignal, obsolete) => {
|
|
214
|
-
const noticeObsolete = () => deliverySignal.aborted || Boolean(obsolete?.()) || replyDelivered(replyEffectKey);
|
|
215
|
-
if (noticeObsolete())
|
|
216
|
-
return;
|
|
217
|
-
const rest = restDelivery(deliverySignal, noticeObsolete);
|
|
218
|
-
const sent = await rest.displayCard(message, deliveryNoticeCard(event), stableEffectKey(this.identity, message, effectKey, "delivery"), noticeObsolete);
|
|
219
|
-
if (!sent && !noticeObsolete())
|
|
220
|
-
throw new ImSendError("IM_DELIVERY_NOTICE_UNSUPPORTED", "failed");
|
|
221
|
-
},
|
|
222
231
|
replyFailure: async (event, effectKey, options) => {
|
|
223
232
|
const rest = restDelivery(options?.signal, options?.obsolete);
|
|
224
233
|
const template = await rest.reasoningTemplate();
|
|
@@ -232,28 +241,21 @@ export class GatewayTransport {
|
|
|
232
241
|
await rest.card(message, template, frame, stableEffectKey(this.identity, message, effectKey, "error"), undefined, 1, false);
|
|
233
242
|
},
|
|
234
243
|
reply: async (text, effectKey, options) => {
|
|
235
|
-
//
|
|
236
|
-
// 空回复/失败等终态提示也遵守该轮取消,不能在 stop 后从等待中恢复发送。
|
|
244
|
+
// 目标归属冻结在原消息,REST 使用 Bot 期限和持有凭据,不等待 WS 恢复。
|
|
237
245
|
const replySignal = options
|
|
238
246
|
? AbortSignal.any([deliverySignal, options.signal])
|
|
239
247
|
: deliverySignal;
|
|
240
248
|
if (options?.obsolete())
|
|
241
249
|
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
242
|
-
const current = await this.#resolveDeliveryTransport(replySignal);
|
|
243
|
-
if (options?.obsolete())
|
|
244
|
-
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
245
|
-
replyConnection = current.#connection;
|
|
246
250
|
const key = stableEffectKey(this.identity, message, effectKey ?? message.messageId, "text");
|
|
247
|
-
|
|
248
|
-
return;
|
|
249
|
-
await replyConnection.sendText(message.channelId, message.channelType, text, key, this.#spaceId, undefined, replySignal, outputObserver());
|
|
251
|
+
await sendMessage({ type: 1, content: text }, key, replySignal, options?.obsolete, outputObserver());
|
|
250
252
|
},
|
|
251
253
|
replyFinal: async (text, effectKey, options) => {
|
|
252
254
|
const finalSignal = options
|
|
253
255
|
? AbortSignal.any([deliverySignal, options.signal])
|
|
254
256
|
: deliverySignal;
|
|
255
|
-
//
|
|
256
|
-
|
|
257
|
+
// 准备与投递共用任务身份,切网不取消;停止/换账号不能继续。
|
|
258
|
+
this.#taskToken(finalSignal);
|
|
257
259
|
if (options?.obsolete())
|
|
258
260
|
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
259
261
|
if (finalReply?.key !== effectKey)
|
|
@@ -266,16 +268,18 @@ export class GatewayTransport {
|
|
|
266
268
|
? await prepareArtifacts(text, options.artifacts, finalSignal, (bytes, name, mime, uploadSignal) => uploadChatAttachment(this.config.api_url, token, bytes, name, mime, uploadSignal, this.#dispatchRestDelivery))
|
|
267
269
|
: { text, files: [] };
|
|
268
270
|
const failures = [];
|
|
269
|
-
//
|
|
271
|
+
// 每张最终文件卡首发后最多重试三次;整段准备仅一次,文本重试不重开预算或上传。
|
|
270
272
|
for (const [index, file] of delivered.files.entries()) {
|
|
271
273
|
finalSignal.throwIfAborted();
|
|
272
274
|
if (options?.obsolete())
|
|
273
275
|
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
274
276
|
const key = stableEffectKey(this.identity, message, effectKey, `file:${index}`);
|
|
275
277
|
const receipt = await finalDispatcher.deliver(key, async () => {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
278
|
+
return sendMessage({ type: 8, ...file }, key, finalSignal, () => Boolean(options?.obsolete()), outputObserver(delivered.incomplete ? undefined : { type: 8, ...file }));
|
|
279
|
+
}, {
|
|
280
|
+
attempts: 4,
|
|
281
|
+
obsolete: () => finalSignal.aborted || Boolean(options?.obsolete())
|
|
282
|
+
});
|
|
279
283
|
if (receipt.state !== "delivered")
|
|
280
284
|
failures.push(`${file.name.replace(/[\r\n\x60[\]<>]/g, "_").slice(0, 120)} (${receipt.state}: ${receipt.code ?? "IM_DELIVERY_UNKNOWN"})`);
|
|
281
285
|
}
|
|
@@ -305,13 +309,13 @@ export class GatewayTransport {
|
|
|
305
309
|
})()
|
|
306
310
|
};
|
|
307
311
|
const result = await finalReply.value;
|
|
308
|
-
const current = await this.#resolveDeliveryTransport(finalSignal);
|
|
309
312
|
if (options?.obsolete())
|
|
310
313
|
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
314
|
+
await sendMessage({
|
|
315
|
+
type: 1,
|
|
316
|
+
content: result.text,
|
|
317
|
+
...(result.mention ? { mention: result.mention } : {})
|
|
318
|
+
}, stableEffectKey(this.identity, message, effectKey, "text"), finalSignal, () => Boolean(options?.obsolete()), outputObserver(finalOutputCovered
|
|
315
319
|
? {
|
|
316
320
|
type: 1,
|
|
317
321
|
content: result.text,
|
|
@@ -321,7 +325,7 @@ export class GatewayTransport {
|
|
|
321
325
|
},
|
|
322
326
|
buildContext: async (turnSignal, options) => ({
|
|
323
327
|
schema: CONTEXT_SCHEMA,
|
|
324
|
-
items: await build_im_contexts(this.scopedConfig, message,
|
|
328
|
+
items: await build_im_contexts(this.scopedConfig, message, this.#taskToken(deliverySignal), AbortSignal.any([deliverySignal, turnSignal]), {
|
|
325
329
|
...options,
|
|
326
330
|
initialSession: options?.initialSession ?? false,
|
|
327
331
|
identityCache: this.#messageIdentityCache
|
|
@@ -451,15 +455,9 @@ export class GatewayTransport {
|
|
|
451
455
|
own,
|
|
452
456
|
...(binding?.turn ? { turn: binding.turn } : {})
|
|
453
457
|
});
|
|
454
|
-
},
|
|
455
|
-
// ACK 写入身份代次账本,旧连接释放后不丢失中间连接已确认的 effect。
|
|
456
|
-
(key) => this.#deliveryScope.confirm(key));
|
|
457
|
-
this.#connection = connection;
|
|
458
|
-
this.#api = new OctoConnector(this.config, token, signal, async (address, text, effectKey) => {
|
|
459
|
-
if (this.#closed || signal.aborted)
|
|
460
|
-
throw new Error("IM_CONNECTION_REPLACED");
|
|
461
|
-
await connection.sendText(address.channelId, address.channelType, text, effectKey, this.#spaceId);
|
|
462
458
|
});
|
|
459
|
+
this.#connection = connection;
|
|
460
|
+
this.#api = new OctoConnector(this.config, token, signal);
|
|
463
461
|
this.#delivery = this.deliveryOwner?.dispatcher ?? new ImDeliveryDispatcher(signal);
|
|
464
462
|
this.#typing = new TypingController((address, typingSignal) => this.#api.typing(address, typingSignal), () => this.callbacks.onDiagnostic?.("IM_TYPING_FAILED"));
|
|
465
463
|
const abort = () => {
|
|
@@ -486,18 +484,7 @@ export class GatewayTransport {
|
|
|
486
484
|
...(this.deliveryOwner ? [this.deliveryOwner.signal] : [])
|
|
487
485
|
]);
|
|
488
486
|
try {
|
|
489
|
-
requestSignal
|
|
490
|
-
const owner = this.deliveryOwner;
|
|
491
|
-
const current = owner?.current();
|
|
492
|
-
if (current &&
|
|
493
|
-
(imBotIdentity(current.config) !== imBotIdentity(this.config) ||
|
|
494
|
-
(current.#token && current.identity !== this.identity)))
|
|
495
|
-
throw new ImSendError("IM_CONNECTION_IDENTITY_CHANGED", "failed");
|
|
496
|
-
const token = owner?.token ? owner.token()?.trim() : this.#token;
|
|
497
|
-
if (!token)
|
|
498
|
-
throw new Error("IM_CREDENTIALS_REQUIRED");
|
|
499
|
-
if (!/^bf_[A-Za-z0-9_-]+$/.test(token))
|
|
500
|
-
throw new Error("IM_BOT_TOKEN_INVALID");
|
|
487
|
+
const token = this.#taskToken(requestSignal);
|
|
501
488
|
// 只读取已注入的值,不触发宿主获取/刷新;检查、替换头与 fetch 同步完成。
|
|
502
489
|
return send(requestSignal, token);
|
|
503
490
|
}
|
|
@@ -508,42 +495,19 @@ export class GatewayTransport {
|
|
|
508
495
|
throw error;
|
|
509
496
|
}
|
|
510
497
|
};
|
|
511
|
-
/**
|
|
512
|
-
#
|
|
513
|
-
|
|
514
|
-
if (rejectIdentityChange)
|
|
515
|
-
this.#deliveryScope.signal.throwIfAborted();
|
|
516
|
-
return undefined;
|
|
517
|
-
}
|
|
518
|
-
const current = this.deliveryOwner ? this.deliveryOwner.current() : this;
|
|
519
|
-
if (!current || current.#closed || !current.#connected || !current.#connection?.connected)
|
|
520
|
-
return undefined;
|
|
521
|
-
if (current.identity !== this.identity || current.#token !== this.#token) {
|
|
522
|
-
if (rejectIdentityChange)
|
|
523
|
-
throw new ImSendError("IM_CONNECTION_IDENTITY_CHANGED", "failed");
|
|
524
|
-
return undefined;
|
|
525
|
-
}
|
|
526
|
-
return current;
|
|
527
|
-
}
|
|
528
|
-
async #resolveDeliveryTransport(signal) {
|
|
529
|
-
const deadline = performance.now() + 15_000;
|
|
530
|
-
while (!signal.aborted) {
|
|
531
|
-
const current = this.#currentDeliveryTransport();
|
|
532
|
-
if (current)
|
|
533
|
-
return current;
|
|
534
|
-
// 等待发生在首次发送之前;已开始发送的 unknown 由原确认窗口处理,不能跨连接重放。
|
|
535
|
-
const remaining = deadline - performance.now();
|
|
536
|
-
if (!this.deliveryOwner || remaining <= 0)
|
|
537
|
-
throw new ImSendError("IM_CONNECTION_UNAVAILABLE", "failed");
|
|
538
|
-
try {
|
|
539
|
-
await delay(Math.min(100, remaining), undefined, { signal });
|
|
540
|
-
}
|
|
541
|
-
catch {
|
|
542
|
-
break;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
498
|
+
/** 同步读取 Bot 已持有凭据并核验原任务归属;不检查或等待任何 WS 状态。 */
|
|
499
|
+
#taskToken(signal) {
|
|
500
|
+
signal.throwIfAborted();
|
|
545
501
|
this.#deliveryScope.signal.throwIfAborted();
|
|
546
|
-
|
|
502
|
+
this.deliveryOwner?.signal.throwIfAborted();
|
|
503
|
+
const owner = this.deliveryOwner;
|
|
504
|
+
// 身份撤销由 Bot 持有的 deliveryScope 保证,不读取当前 WS 或连接代次。
|
|
505
|
+
const token = owner?.token ? owner.token()?.trim() : this.#token;
|
|
506
|
+
if (!token)
|
|
507
|
+
throw new ImSendError("IM_CREDENTIALS_REQUIRED", "failed");
|
|
508
|
+
if (!/^bf_[A-Za-z0-9_-]+$/.test(token))
|
|
509
|
+
throw new ImSendError("IM_BOT_TOKEN_INVALID", "failed");
|
|
510
|
+
return token;
|
|
547
511
|
}
|
|
548
512
|
async #pollActions(token, signal) {
|
|
549
513
|
if (this.config.cards === false)
|
|
@@ -6,15 +6,13 @@ export declare class OctoConnector {
|
|
|
6
6
|
readonly config: OctoBotConfig;
|
|
7
7
|
readonly token: string;
|
|
8
8
|
readonly signal: AbortSignal;
|
|
9
|
-
readonly sendWsText: (address: ImAddress, text: string, effectKey: string) => Promise<void>;
|
|
10
9
|
readonly dispatchRequest?: HttpRequestDispatch | undefined;
|
|
11
|
-
constructor(config: OctoBotConfig, token: string, signal: AbortSignal,
|
|
10
|
+
constructor(config: OctoBotConfig, token: string, signal: AbortSignal, dispatchRequest?: HttpRequestDispatch | undefined);
|
|
12
11
|
reasoningTemplate(): Promise<ReasoningTemplate | undefined>;
|
|
13
12
|
typing(address: ImAddress, signal: AbortSignal): Promise<void>;
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
/** 任务文本/文件经 REST 投递;返回真实消息 ID,位置可选,不以 WS ACK 确认。 */
|
|
14
|
+
message(address: ImAddress, payload: Record<string, unknown>, effectKey: string, onPosition?: (sequence: number) => void): Promise<string>;
|
|
16
15
|
interactionCard(address: ImAddress, card: Record<string, unknown>, effectKey: string, messageId?: string): Promise<string | undefined>;
|
|
17
|
-
displayCard(address: ImAddress, card: Record<string, unknown>, effectKey: string, obsolete?: () => boolean): Promise<string | undefined>;
|
|
18
16
|
card(address: ImAddress, template: ReasoningTemplate, frame: ReasoningFrame, effectKey: string, messageId?: string, seq?: number, transient?: boolean): Promise<string>;
|
|
19
17
|
}
|
|
20
18
|
export declare function stableEffectKey(endpointId: string, address: ImAddress, runId: string, kind: string): string;
|
package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connector.js
CHANGED
|
@@ -4,24 +4,23 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { getCardProfile, sendTemplateCardMessage, editTemplateCardMessage } from "./api/cards.js";
|
|
7
|
-
import {
|
|
7
|
+
import { sendTyping } from "./api/messages.js";
|
|
8
8
|
import { selectReasoningTemplate } from "./cards.js";
|
|
9
9
|
import { postJson } from "./api/client.js";
|
|
10
|
-
import { ImSendError } from "../delivery/
|
|
10
|
+
import { ImSendError } from "../delivery/send-error.js";
|
|
11
|
+
import { OctoApiError } from "./api/errors.js";
|
|
11
12
|
export class OctoConnector {
|
|
12
13
|
config;
|
|
13
14
|
token;
|
|
14
15
|
signal;
|
|
15
|
-
sendWsText;
|
|
16
16
|
dispatchRequest;
|
|
17
17
|
#profile;
|
|
18
|
-
constructor(config, token, signal,
|
|
18
|
+
constructor(config, token, signal,
|
|
19
19
|
// 跨 WS 的 REST 使用 Bot 持有凭据及任务期限,不把 WS 状态当作 HTTP 准入。
|
|
20
20
|
dispatchRequest) {
|
|
21
21
|
this.config = config;
|
|
22
22
|
this.token = token;
|
|
23
23
|
this.signal = signal;
|
|
24
|
-
this.sendWsText = sendWsText;
|
|
25
24
|
this.dispatchRequest = dispatchRequest;
|
|
26
25
|
}
|
|
27
26
|
async reasoningTemplate() {
|
|
@@ -55,30 +54,30 @@ export class OctoConnector {
|
|
|
55
54
|
dispatchRequest: this.#dispatch
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
/** 任务文本/文件经 REST 投递;返回真实消息 ID,位置可选,不以 WS ACK 确认。 */
|
|
58
|
+
async message(address, payload, effectKey, onPosition) {
|
|
59
|
+
const receipt = await postJson(this.config.api_url, this.token, "/v1/bot/sendMessage", {
|
|
60
|
+
channel_id: address.channelId,
|
|
61
|
+
channel_type: address.channelType,
|
|
62
|
+
payload,
|
|
63
|
+
client_msg_no: effectKey
|
|
64
|
+
}, this.signal, { dispatchRequest: this.#dispatch, retryOn429: false }).catch((error) => {
|
|
65
|
+
// 无有效回应不标记送达;仅外层当前收尾可用同一消息身份进行有限 REST 重试。
|
|
66
|
+
if (error instanceof ImSendError)
|
|
67
|
+
throw error;
|
|
68
|
+
if (error instanceof OctoApiError && error.status < 500)
|
|
69
|
+
throw error;
|
|
70
|
+
throw new ImSendError("IM_DELIVERY_UNKNOWN", "unknown");
|
|
70
71
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const id = receipt?.message_id;
|
|
73
|
+
if (!((typeof id === "string" && id.trim()) || (Number.isSafeInteger(id) && Number(id) > 0)))
|
|
74
|
+
throw new ImSendError("IM_DELIVERY_RECEIPT_UNKNOWN", "unknown");
|
|
75
|
+
const sequence = receipt?.message_seq;
|
|
76
|
+
if (Number.isSafeInteger(sequence) && sequence > 0)
|
|
77
|
+
onPosition?.(sequence);
|
|
78
|
+
return String(id);
|
|
74
79
|
}
|
|
75
80
|
async interactionCard(address, card, effectKey, messageId) {
|
|
76
|
-
return this.#rawCard(address, card, effectKey, messageId, true);
|
|
77
|
-
}
|
|
78
|
-
async displayCard(address, card, effectKey, obsolete) {
|
|
79
|
-
return this.#rawCard(address, card, effectKey, undefined, false, obsolete);
|
|
80
|
-
}
|
|
81
|
-
async #rawCard(address, card, effectKey, messageId, interactive, obsolete) {
|
|
82
81
|
if (this.config.cards === false)
|
|
83
82
|
return;
|
|
84
83
|
const profile = await getCardProfile({
|
|
@@ -89,11 +88,9 @@ export class OctoConnector {
|
|
|
89
88
|
});
|
|
90
89
|
// 身份代次撤销不是能力不支持;保留取消原因供调用方区分已阻止的旧身份写入。
|
|
91
90
|
this.signal.throwIfAborted();
|
|
92
|
-
if (obsolete?.())
|
|
93
|
-
return;
|
|
94
91
|
if (!profile.available ||
|
|
95
92
|
!profile.enabled ||
|
|
96
|
-
!
|
|
93
|
+
!profile.config?.interaction_enabled ||
|
|
97
94
|
!profile.profiles?.includes("octo/v2"))
|
|
98
95
|
return;
|
|
99
96
|
const payload = {
|
|
@@ -114,18 +111,8 @@ export class OctoConnector {
|
|
|
114
111
|
: { payload, client_msg_no: effectKey })
|
|
115
112
|
}, this.signal, {
|
|
116
113
|
retryOn429: false,
|
|
117
|
-
dispatchRequest:
|
|
118
|
-
if (obsolete?.())
|
|
119
|
-
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
120
|
-
return send(authorized, botToken);
|
|
121
|
-
})
|
|
122
|
-
}).catch((error) => {
|
|
123
|
-
if (obsolete?.())
|
|
124
|
-
return undefined;
|
|
125
|
-
throw error;
|
|
114
|
+
dispatchRequest: this.#dispatch
|
|
126
115
|
});
|
|
127
|
-
if (obsolete?.() && !result)
|
|
128
|
-
return;
|
|
129
116
|
if (!messageId && !result?.message_id)
|
|
130
117
|
throw Error("IM_DELIVERY_RECEIPT_UNKNOWN");
|
|
131
118
|
return messageId ?? String(result.message_id);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
// Port of octo-agent-app-channel/internal/transport/progress.go display rules.
|
|
6
6
|
import { failureMessage } from "@mininglamp-oss/octo-runtime-protocol";
|
|
7
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
7
8
|
import { MODEL_WAIT_TIMEOUT_MESSAGE } from "../execution/model-wait.js";
|
|
8
9
|
import { clampRunes, compactRunes } from "../presentation/run-projector.js";
|
|
9
10
|
export function formatDuration(ms) {
|
|
@@ -14,8 +15,32 @@ export function formatDuration(ms) {
|
|
|
14
15
|
return `${(ms / 1000).toFixed(1).replace(/\.0$/, "")}s`;
|
|
15
16
|
return `${Math.floor(ms / 60_000)}m ${Math.floor((ms % 60_000) / 1000)}s`;
|
|
16
17
|
}
|
|
18
|
+
/** 进度只展示文字;产物链接与图片由独立 final 交付,不能进入服务端卡片的 URL 校验面。 */
|
|
19
|
+
function plainText(text) {
|
|
20
|
+
const read = (node) => {
|
|
21
|
+
if (node.type === "definition")
|
|
22
|
+
return "";
|
|
23
|
+
if (node.type === "break")
|
|
24
|
+
return "\n";
|
|
25
|
+
return (node.value ??
|
|
26
|
+
node.alt ??
|
|
27
|
+
node.children
|
|
28
|
+
?.map(read)
|
|
29
|
+
.join(["root", "list", "blockquote"].includes(node.type) ? "\n" : "") ??
|
|
30
|
+
"");
|
|
31
|
+
};
|
|
32
|
+
return read(fromMarkdown(text));
|
|
33
|
+
}
|
|
34
|
+
function literalText(text) {
|
|
35
|
+
// code/HTML/标签本身也可能含 Markdown;还原可读文字后转义,避免再次被模板解释为链接。
|
|
36
|
+
return (plainText(text)
|
|
37
|
+
.trim()
|
|
38
|
+
.replace(/[\\`*[\]<>]/g, "\\$&")
|
|
39
|
+
// 单词内部的下划线不是 emphasis;保留诊断编号等标识的原样表达。
|
|
40
|
+
.replace(/(?<![\p{L}\p{N}])_|_(?![\p{L}\p{N}])/gu, "\\$&") || "—");
|
|
41
|
+
}
|
|
17
42
|
function thought(text) {
|
|
18
|
-
text = text.replace(/\s+/g, " ").trim();
|
|
43
|
+
text = plainText(text).replace(/\s+/g, " ").trim();
|
|
19
44
|
if (/OPENCLAW_INTERNAL/i.test(text))
|
|
20
45
|
return "Reasoning summary hidden";
|
|
21
46
|
return text ? compactRunes(text, 180) : "—";
|
|
@@ -199,6 +224,7 @@ export function buildReasoningFrame(snapshot, template) {
|
|
|
199
224
|
progressText: (snapshot.label ?? label) + (elapsed ? " · 已耗时 " + elapsed : ""),
|
|
200
225
|
phases: reasoningPhases(snapshot)
|
|
201
226
|
};
|
|
227
|
+
let errorIdentity = "";
|
|
202
228
|
if (snapshot.phase === "accepted" && !snapshot.terminal) {
|
|
203
229
|
// 第一帧立即显示思考中,只展示状态,不伪造 reasoning 内容或计数。
|
|
204
230
|
frame.title = "思考中";
|
|
@@ -276,11 +302,10 @@ export function buildReasoningFrame(snapshot, template) {
|
|
|
276
302
|
]
|
|
277
303
|
}
|
|
278
304
|
];
|
|
279
|
-
|
|
280
|
-
?
|
|
305
|
+
errorIdentity = snapshot.failure
|
|
306
|
+
? "\n" +
|
|
307
|
+
literalText(`错误码:${snapshot.failure.code}\n诊断编号:${snapshot.failure.diagnosticId}`)
|
|
281
308
|
: "";
|
|
282
|
-
frame.errorMessage =
|
|
283
|
-
clampRunes(frame.errorMessage, Math.max(1, 121 - Array.from(identity).length)) + identity;
|
|
284
309
|
}
|
|
285
310
|
}
|
|
286
311
|
const thoughtMax = template.ref.version === "0.4.0" ? 4000 : 280;
|
|
@@ -347,6 +372,7 @@ export function buildReasoningFrame(snapshot, template) {
|
|
|
347
372
|
if (confirmed) {
|
|
348
373
|
frame.errorTitle = "请求超时";
|
|
349
374
|
frame.errorMessage = MODEL_WAIT_TIMEOUT_MESSAGE + detail;
|
|
375
|
+
errorIdentity = "";
|
|
350
376
|
delete frame.progressText;
|
|
351
377
|
}
|
|
352
378
|
else if (!snapshot.resultUnknown) {
|
|
@@ -357,8 +383,17 @@ export function buildReasoningFrame(snapshot, template) {
|
|
|
357
383
|
else
|
|
358
384
|
frame.collapsedSummary += detail;
|
|
359
385
|
}
|
|
360
|
-
|
|
361
|
-
|
|
386
|
+
// 转换发生在展示副本上,并先于字符/字节预算;不改 projector 的原正文或附件交付输入。
|
|
387
|
+
for (const phase of frame.phases) {
|
|
388
|
+
phase.thought = clampRunes(literalText(phase.thought), thoughtMax);
|
|
389
|
+
for (const action of phase.actions) {
|
|
390
|
+
action.tool = clampRunes(literalText(action.tool), 81);
|
|
391
|
+
action.detail = clampRunes(literalText(action.detail), 192);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (frame.errorMessage)
|
|
395
|
+
frame.errorMessage =
|
|
396
|
+
clampRunes(literalText(frame.errorMessage), Math.max(1, 121 - Array.from(errorIdentity).length)) + errorIdentity;
|
|
362
397
|
let total = frame.phases.reduce((size, phase) => size + Array.from(phase.thought).length, 0);
|
|
363
398
|
for (const phase of frame.phases) {
|
|
364
399
|
if (total <= 540)
|
package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ImTextMention } from "./mentions.js";
|
|
2
1
|
export interface ImMessage {
|
|
3
2
|
messageId: string;
|
|
4
3
|
messageSeq: number;
|
|
@@ -30,7 +29,6 @@ export declare class WukongConnection {
|
|
|
30
29
|
clientMsgNo: string;
|
|
31
30
|
spaceId?: unknown;
|
|
32
31
|
}) => void) | undefined;
|
|
33
|
-
readonly onDelivered?: ((clientMsgNo: string) => void) | undefined;
|
|
34
32
|
constructor(onMessage: (message: ImMessage) => void, onDisconnect?: (error: Error) => void, onPosition?: ((position: {
|
|
35
33
|
channelId: string;
|
|
36
34
|
channelType: number;
|
|
@@ -39,17 +37,8 @@ export declare class WukongConnection {
|
|
|
39
37
|
messageId: string;
|
|
40
38
|
clientMsgNo: string;
|
|
41
39
|
spaceId?: unknown;
|
|
42
|
-
}) => void) | undefined
|
|
40
|
+
}) => void) | undefined);
|
|
43
41
|
get connected(): boolean;
|
|
44
42
|
connect(registration: BotRegistration): Promise<void>;
|
|
45
|
-
sendText(channelId: string, channelType: number, text: string, clientMsgNo?: string, spaceId?: string, mention?: ImTextMention, signal?: AbortSignal, onPosition?: (sequence: number) => void): Promise<string>;
|
|
46
|
-
/** 原生文件消息复用文本的加密、稳定编号、ACK/迟到确认和取消窗口;不使用互动卡服务。 */
|
|
47
|
-
sendFile(channelId: string, channelType: number, file: {
|
|
48
|
-
url: string;
|
|
49
|
-
name: string;
|
|
50
|
-
size: number;
|
|
51
|
-
extension: string;
|
|
52
|
-
}, clientMsgNo: string, spaceId?: string, signal?: AbortSignal, onPosition?: (sequence: number) => void): Promise<string>;
|
|
53
|
-
isDelivered(clientMsgNo: string): boolean;
|
|
54
43
|
close(): Promise<void>;
|
|
55
44
|
}
|