@mininglamp-oss/octo-runtime 1.1.7 → 1.1.9
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/README.md +3 -1
- package/apps/cli/dist/build-info.json +2 -2
- package/apps/cli/dist/command-tree.js +3 -1
- package/apps/cli/dist/output.js +5 -2
- package/apps/cli/dist/playboard.js +11 -2
- package/dist/public/executor-kernel.d.ts +2 -2
- package/dist/public/executor-kernel.js +1 -1
- package/dist/public/protocol.d.ts +1 -1
- package/dist/public/protocol.js +1 -1
- 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/dist/app-server.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +200 -106
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/async-questions.d.ts +27 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/async-questions.js +205 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.d.ts +30 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.js +223 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-V5W6ZTYC.js → chunk-FGFEM7JP.js} +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-CFKMMCO6.js → chunk-R3PDZLX5.js} +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-LO34KB7D.js → chunk-TSRZVLIG.js} +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +2 -2
- 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/dist/gateway.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/gateway.js +57 -13
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.d.ts +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +4 -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/approval.js +2 -0
- 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/dist/command-tree.js +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +5 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +11 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -24
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/launchd.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/launchd.js +12 -11
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/experience.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +5 -4
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +7 -4
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.js +9 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.js +6 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.d.ts +30 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.js +199 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/rpc.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/rpc.js +16 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +36 -19
- 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 +27 -35
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +5 -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/execution/task.js +14 -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 +77 -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/interaction-card.js +2 -1
- 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/session-command.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/session-command.js +71 -0
- 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/dist/application/im-channel.js +14 -0
- 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-BVxePruX.js} +11 -10
- 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/dist/context-loader.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.js +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +63 -12
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +110 -5
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +7 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +28 -6
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/questions.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/questions.js +84 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.js +11 -5
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/package.json +27 -27
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +156 -4
- 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
|
@@ -8,6 +8,7 @@ import { imBotIdentity } from "../lifecycle/configuration.js";
|
|
|
8
8
|
import { verifyBotIdentity } from "./auth.js";
|
|
9
9
|
import { registerBot, WukongConnection } from "./wukong.js";
|
|
10
10
|
import { acceptsImMessage, groupScope, isRulesNotification, rulesChange } from "./normalize.js";
|
|
11
|
+
import { sessionCommand } from "./session-command.js";
|
|
11
12
|
import { build_im_contexts } from "./contexts.js";
|
|
12
13
|
import { OctoConnector, stableEffectKey } from "./connector.js";
|
|
13
14
|
import { CardSession } from "./card-session.js";
|
|
@@ -26,8 +27,7 @@ import { getGroupMembers } from "./api/conversations.js";
|
|
|
26
27
|
import { getJson } from "./api/client.js";
|
|
27
28
|
import { connectionFailure, ImConnectionError } from "./connection-error.js";
|
|
28
29
|
import { sendReadReceipt } from "./api/messages.js";
|
|
29
|
-
import {
|
|
30
|
-
import { ImSendError } from "../delivery/text-send.js";
|
|
30
|
+
import { ImSendError } from "../delivery/send-error.js";
|
|
31
31
|
import { assistantOutputFingerprint } from "../application/context-gap.js";
|
|
32
32
|
import { observesImScope } from "./normalize.js";
|
|
33
33
|
import { prepareArtifacts } from "../delivery/artifacts.js";
|
|
@@ -60,7 +60,7 @@ export class GatewayTransport {
|
|
|
60
60
|
#messageIdentityCache = new MessageIdentityCache();
|
|
61
61
|
#bindings = new Map();
|
|
62
62
|
constructor(config, credentials, callbacks,
|
|
63
|
-
// Bot
|
|
63
|
+
// Bot 持有任务准备与 REST 投递的期限、凭据及身份,接收 WS 不拥有这些资源。
|
|
64
64
|
deliveryOwner) {
|
|
65
65
|
this.config = config;
|
|
66
66
|
this.credentials = credentials;
|
|
@@ -84,13 +84,14 @@ export class GatewayTransport {
|
|
|
84
84
|
if (!/^bf_[A-Za-z0-9_-]+$/.test(token))
|
|
85
85
|
throw new Error("IM_BOT_TOKEN_INVALID");
|
|
86
86
|
const principal = await verifyBotIdentity(this.config.api_url, token, signal);
|
|
87
|
+
signal.throwIfAborted();
|
|
87
88
|
try {
|
|
88
89
|
if (principal.bot_uid !== this.config.bot_id)
|
|
89
90
|
throw new Error("IM_BOT_IDENTITY_MISMATCH");
|
|
90
91
|
this.callbacks.authorizeSpace?.(principal.space_id);
|
|
91
92
|
}
|
|
92
93
|
catch (error) {
|
|
93
|
-
// REST
|
|
94
|
+
// REST 在核验期间继续使用旧凭据;明确拒绝目标后必须撤销旧任务权限。
|
|
94
95
|
// 只在明确身份/空间拒绝后撤销,网络失败、单纯换 token 和握手失败不走此分支。
|
|
95
96
|
this.deliveryOwner?.identity.revoke();
|
|
96
97
|
this.#deliveryScope.revoke();
|
|
@@ -102,12 +103,18 @@ export class GatewayTransport {
|
|
|
102
103
|
this.identity = `${imBotIdentity(this.config)}:${encodeURIComponent(this.#spaceId)}`;
|
|
103
104
|
// 必须在身份核验及空间准入成功后推进代次;连接失败/再次重连不能复活旧代次。
|
|
104
105
|
this.#deliveryScope = this.deliveryOwner?.identity.accept(this.identity) ?? this.#deliveryScope;
|
|
106
|
+
// 代次与凭据在同一同步段生效,不等待后续注册或 WS 握手。
|
|
107
|
+
this.deliveryOwner?.acceptToken?.(token);
|
|
105
108
|
const registration = await registerBot(this.config.api_url, token, signal);
|
|
106
109
|
const toolEnvironment = octoCliEnvironment(this.config.api_url, token);
|
|
107
110
|
if (signal.aborted)
|
|
108
111
|
return;
|
|
109
|
-
if (registration.robot_id !== this.config.bot_id)
|
|
112
|
+
if (registration.robot_id !== this.config.bot_id) {
|
|
113
|
+
// 注册明确拒绝身份也属于授权撤销;网络/握手失败则保留已核验凭据和任务。
|
|
114
|
+
this.deliveryOwner?.identity.revoke();
|
|
115
|
+
this.#deliveryScope.revoke();
|
|
110
116
|
throw new Error("IM_BOT_IDENTITY_MISMATCH");
|
|
117
|
+
}
|
|
111
118
|
const connection = new WukongConnection((message) => {
|
|
112
119
|
if (this.#closed)
|
|
113
120
|
return;
|
|
@@ -123,24 +130,17 @@ export class GatewayTransport {
|
|
|
123
130
|
return;
|
|
124
131
|
let finalReply;
|
|
125
132
|
let finalOutputCovered = false;
|
|
126
|
-
let replyConnection = connection;
|
|
127
133
|
const deliverySignal = AbortSignal.any([
|
|
128
134
|
this.deliveryOwner?.signal ?? signal,
|
|
129
135
|
this.#deliveryScope.signal
|
|
130
136
|
]);
|
|
131
|
-
//
|
|
132
|
-
const restDelivery = (turnSignal = deliverySignal, obsolete) => new OctoConnector(this.config, token, AbortSignal.any([deliverySignal, turnSignal]),
|
|
137
|
+
// 任务的普通回复、final、进度及失败卡共用 REST 工厂和任务期限。
|
|
138
|
+
const restDelivery = (turnSignal = deliverySignal, obsolete) => new OctoConnector(this.config, token, AbortSignal.any([deliverySignal, turnSignal]), (requestSignal, send) => this.#dispatchRestDelivery(requestSignal, (authorized, botToken) => {
|
|
133
139
|
if (obsolete?.())
|
|
134
140
|
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
135
141
|
return send(authorized, botToken);
|
|
136
142
|
}));
|
|
137
143
|
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
144
|
let historyTurn;
|
|
145
145
|
const outputObserver = (payload) => {
|
|
146
146
|
const turn = historyTurn;
|
|
@@ -149,10 +149,7 @@ export class GatewayTransport {
|
|
|
149
149
|
return (messageSeq) => {
|
|
150
150
|
if (deliverySignal.aborted)
|
|
151
151
|
return;
|
|
152
|
-
|
|
153
|
-
if (!current)
|
|
154
|
-
return;
|
|
155
|
-
current.callbacks.onPosition?.({
|
|
152
|
+
(this.callbacks.onTaskPosition ?? this.callbacks.onPosition)?.({
|
|
156
153
|
conversationId: message.channelId,
|
|
157
154
|
conversationKind: message.channelType === 5 ? "thread" : "group",
|
|
158
155
|
messageSeq,
|
|
@@ -164,8 +161,35 @@ export class GatewayTransport {
|
|
|
164
161
|
});
|
|
165
162
|
};
|
|
166
163
|
};
|
|
164
|
+
// 同一次在途 HTTP 共用 Promise;失败交回当前投递器,只有收尾拥有三次重试预算。
|
|
165
|
+
const sends = new Map();
|
|
166
|
+
const sendMessage = (payload, key, turnSignal, obsolete, observe) => {
|
|
167
|
+
turnSignal.throwIfAborted();
|
|
168
|
+
if (obsolete?.())
|
|
169
|
+
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
170
|
+
if (this.#deliveryScope.isConfirmed(key))
|
|
171
|
+
return Promise.resolve("");
|
|
172
|
+
const pending = sends.get(key);
|
|
173
|
+
if (pending)
|
|
174
|
+
return pending;
|
|
175
|
+
const sending = restDelivery(turnSignal, obsolete)
|
|
176
|
+
.message(message, payload, key, observe)
|
|
177
|
+
.then((id) => {
|
|
178
|
+
this.#deliveryScope.confirm(key);
|
|
179
|
+
sends.delete(key);
|
|
180
|
+
return id;
|
|
181
|
+
}, (error) => {
|
|
182
|
+
sends.delete(key);
|
|
183
|
+
throw error;
|
|
184
|
+
});
|
|
185
|
+
sends.set(key, sending);
|
|
186
|
+
return sending;
|
|
187
|
+
};
|
|
167
188
|
this.callbacks.onMessage({
|
|
168
189
|
messageId: message.messageId,
|
|
190
|
+
...(message.channelType === 2 || message.channelType === 5
|
|
191
|
+
? { sessionControl: sessionCommand(message, this.botId) }
|
|
192
|
+
: {}),
|
|
169
193
|
...(message.channelType === 2 || message.channelType === 5
|
|
170
194
|
? {
|
|
171
195
|
position: { messageSeq: message.messageSeq },
|
|
@@ -176,11 +200,11 @@ export class GatewayTransport {
|
|
|
176
200
|
: {}),
|
|
177
201
|
markRead: (turnSignal) => sendReadReceipt({
|
|
178
202
|
apiUrl: this.config.api_url,
|
|
179
|
-
botToken:
|
|
203
|
+
botToken: this.#taskToken(deliverySignal),
|
|
180
204
|
channelId: message.channelId,
|
|
181
205
|
channelType: message.channelType,
|
|
182
206
|
messageIds: [message.messageId],
|
|
183
|
-
signal: AbortSignal.any([
|
|
207
|
+
signal: AbortSignal.any([deliverySignal, turnSignal])
|
|
184
208
|
}),
|
|
185
209
|
senderId: message.fromUid,
|
|
186
210
|
conversationId: message.channelId,
|
|
@@ -196,12 +220,11 @@ export class GatewayTransport {
|
|
|
196
220
|
: String(message.payload.content),
|
|
197
221
|
...(message.payload.type === 2
|
|
198
222
|
? {
|
|
199
|
-
buildInputs: (turnSignal) => downloadImageInput(message.payload.url, this.config.api_url,
|
|
223
|
+
buildInputs: (turnSignal) => downloadImageInput(message.payload.url, this.config.api_url, this.#taskToken(deliverySignal), AbortSignal.any([deliverySignal, turnSignal]))
|
|
200
224
|
}
|
|
201
225
|
: {}),
|
|
202
226
|
executionEnvironment: () => {
|
|
203
|
-
|
|
204
|
-
throw new Error("IM_CONNECTION_REPLACED");
|
|
227
|
+
deliverySignal.throwIfAborted();
|
|
205
228
|
return { executionEnvOverrides: structuredClone(toolEnvironment) };
|
|
206
229
|
},
|
|
207
230
|
runMetadata: {
|
|
@@ -209,16 +232,6 @@ export class GatewayTransport {
|
|
|
209
232
|
botId: this.config.bot_id,
|
|
210
233
|
channelType: message.channelType
|
|
211
234
|
},
|
|
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
235
|
replyFailure: async (event, effectKey, options) => {
|
|
223
236
|
const rest = restDelivery(options?.signal, options?.obsolete);
|
|
224
237
|
const template = await rest.reasoningTemplate();
|
|
@@ -232,28 +245,21 @@ export class GatewayTransport {
|
|
|
232
245
|
await rest.card(message, template, frame, stableEffectKey(this.identity, message, effectKey, "error"), undefined, 1, false);
|
|
233
246
|
},
|
|
234
247
|
reply: async (text, effectKey, options) => {
|
|
235
|
-
//
|
|
236
|
-
// 空回复/失败等终态提示也遵守该轮取消,不能在 stop 后从等待中恢复发送。
|
|
248
|
+
// 目标归属冻结在原消息,REST 使用 Bot 期限和持有凭据,不等待 WS 恢复。
|
|
237
249
|
const replySignal = options
|
|
238
250
|
? AbortSignal.any([deliverySignal, options.signal])
|
|
239
251
|
: deliverySignal;
|
|
240
252
|
if (options?.obsolete())
|
|
241
253
|
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
254
|
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());
|
|
255
|
+
await sendMessage({ type: 1, content: text }, key, replySignal, options?.obsolete, outputObserver());
|
|
250
256
|
},
|
|
251
257
|
replyFinal: async (text, effectKey, options) => {
|
|
252
258
|
const finalSignal = options
|
|
253
259
|
? AbortSignal.any([deliverySignal, options.signal])
|
|
254
260
|
: deliverySignal;
|
|
255
|
-
//
|
|
256
|
-
|
|
261
|
+
// 准备与投递共用任务身份,切网不取消;停止/换账号不能继续。
|
|
262
|
+
this.#taskToken(finalSignal);
|
|
257
263
|
if (options?.obsolete())
|
|
258
264
|
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
259
265
|
if (finalReply?.key !== effectKey)
|
|
@@ -266,16 +272,18 @@ export class GatewayTransport {
|
|
|
266
272
|
? await prepareArtifacts(text, options.artifacts, finalSignal, (bytes, name, mime, uploadSignal) => uploadChatAttachment(this.config.api_url, token, bytes, name, mime, uploadSignal, this.#dispatchRestDelivery))
|
|
267
273
|
: { text, files: [] };
|
|
268
274
|
const failures = [];
|
|
269
|
-
//
|
|
275
|
+
// 每张最终文件卡首发后最多重试三次;整段准备仅一次,文本重试不重开预算或上传。
|
|
270
276
|
for (const [index, file] of delivered.files.entries()) {
|
|
271
277
|
finalSignal.throwIfAborted();
|
|
272
278
|
if (options?.obsolete())
|
|
273
279
|
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
274
280
|
const key = stableEffectKey(this.identity, message, effectKey, `file:${index}`);
|
|
275
281
|
const receipt = await finalDispatcher.deliver(key, async () => {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
282
|
+
return sendMessage({ type: 8, ...file }, key, finalSignal, () => Boolean(options?.obsolete()), outputObserver(delivered.incomplete ? undefined : { type: 8, ...file }));
|
|
283
|
+
}, {
|
|
284
|
+
attempts: 4,
|
|
285
|
+
obsolete: () => finalSignal.aborted || Boolean(options?.obsolete())
|
|
286
|
+
});
|
|
279
287
|
if (receipt.state !== "delivered")
|
|
280
288
|
failures.push(`${file.name.replace(/[\r\n\x60[\]<>]/g, "_").slice(0, 120)} (${receipt.state}: ${receipt.code ?? "IM_DELIVERY_UNKNOWN"})`);
|
|
281
289
|
}
|
|
@@ -305,13 +313,13 @@ export class GatewayTransport {
|
|
|
305
313
|
})()
|
|
306
314
|
};
|
|
307
315
|
const result = await finalReply.value;
|
|
308
|
-
const current = await this.#resolveDeliveryTransport(finalSignal);
|
|
309
316
|
if (options?.obsolete())
|
|
310
317
|
throw new ImSendError("IM_DELIVERY_CANCELLED", "failed");
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
318
|
+
await sendMessage({
|
|
319
|
+
type: 1,
|
|
320
|
+
content: result.text,
|
|
321
|
+
...(result.mention ? { mention: result.mention } : {})
|
|
322
|
+
}, stableEffectKey(this.identity, message, effectKey, "text"), finalSignal, () => Boolean(options?.obsolete()), outputObserver(finalOutputCovered
|
|
315
323
|
? {
|
|
316
324
|
type: 1,
|
|
317
325
|
content: result.text,
|
|
@@ -321,7 +329,7 @@ export class GatewayTransport {
|
|
|
321
329
|
},
|
|
322
330
|
buildContext: async (turnSignal, options) => ({
|
|
323
331
|
schema: CONTEXT_SCHEMA,
|
|
324
|
-
items: await build_im_contexts(this.scopedConfig, message,
|
|
332
|
+
items: await build_im_contexts(this.scopedConfig, message, this.#taskToken(deliverySignal), AbortSignal.any([deliverySignal, turnSignal]), {
|
|
325
333
|
...options,
|
|
326
334
|
initialSession: options?.initialSession ?? false,
|
|
327
335
|
identityCache: this.#messageIdentityCache
|
|
@@ -451,15 +459,9 @@ export class GatewayTransport {
|
|
|
451
459
|
own,
|
|
452
460
|
...(binding?.turn ? { turn: binding.turn } : {})
|
|
453
461
|
});
|
|
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
462
|
});
|
|
463
|
+
this.#connection = connection;
|
|
464
|
+
this.#api = new OctoConnector(this.config, token, signal);
|
|
463
465
|
this.#delivery = this.deliveryOwner?.dispatcher ?? new ImDeliveryDispatcher(signal);
|
|
464
466
|
this.#typing = new TypingController((address, typingSignal) => this.#api.typing(address, typingSignal), () => this.callbacks.onDiagnostic?.("IM_TYPING_FAILED"));
|
|
465
467
|
const abort = () => {
|
|
@@ -486,18 +488,7 @@ export class GatewayTransport {
|
|
|
486
488
|
...(this.deliveryOwner ? [this.deliveryOwner.signal] : [])
|
|
487
489
|
]);
|
|
488
490
|
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");
|
|
491
|
+
const token = this.#taskToken(requestSignal);
|
|
501
492
|
// 只读取已注入的值,不触发宿主获取/刷新;检查、替换头与 fetch 同步完成。
|
|
502
493
|
return send(requestSignal, token);
|
|
503
494
|
}
|
|
@@ -508,42 +499,19 @@ export class GatewayTransport {
|
|
|
508
499
|
throw error;
|
|
509
500
|
}
|
|
510
501
|
};
|
|
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
|
-
}
|
|
502
|
+
/** 同步读取 Bot 已持有凭据并核验原任务归属;不检查或等待任何 WS 状态。 */
|
|
503
|
+
#taskToken(signal) {
|
|
504
|
+
signal.throwIfAborted();
|
|
545
505
|
this.#deliveryScope.signal.throwIfAborted();
|
|
546
|
-
|
|
506
|
+
this.deliveryOwner?.signal.throwIfAborted();
|
|
507
|
+
const owner = this.deliveryOwner;
|
|
508
|
+
// 身份撤销由 Bot 持有的 deliveryScope 保证,不读取当前 WS 或连接代次。
|
|
509
|
+
const token = owner?.token ? owner.token()?.trim() : this.#token;
|
|
510
|
+
if (!token)
|
|
511
|
+
throw new ImSendError("IM_CREDENTIALS_REQUIRED", "failed");
|
|
512
|
+
if (!/^bf_[A-Za-z0-9_-]+$/.test(token))
|
|
513
|
+
throw new ImSendError("IM_BOT_TOKEN_INVALID", "failed");
|
|
514
|
+
return token;
|
|
547
515
|
}
|
|
548
516
|
async #pollActions(token, signal) {
|
|
549
517
|
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);
|
|
@@ -76,7 +76,8 @@ export function interactionCard(request, settled) {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
export function interactionAnswer(request, action) {
|
|
79
|
-
if (
|
|
79
|
+
if (request.expiresAt === undefined ||
|
|
80
|
+
!Number.isFinite(Date.parse(request.expiresAt)) ||
|
|
80
81
|
Date.parse(request.expiresAt) <= Date.now())
|
|
81
82
|
throw Error("IM_INTERACTION_EXPIRED");
|
|
82
83
|
const outcome = action.actionId.slice("interaction_".length);
|
|
@@ -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)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ImInboundMessage } from "../contracts.js";
|
|
2
|
+
import type { ImMessage } from "./wukong.js";
|
|
3
|
+
type SessionCommand = NonNullable<ImInboundMessage["sessionControl"]>;
|
|
4
|
+
/**
|
|
5
|
+
* 在 Gateway 已完成消息准入后解析当前纯文本;不改变原文,不从名称补造授权。
|
|
6
|
+
* 只有剥离原生提及前缀后的完整输入才是控制命令,含 /stop 的语义文本仍交给 AgentRun。
|
|
7
|
+
*/
|
|
8
|
+
export declare function sessionCommand(message: ImMessage, botId: string): SessionCommand | null;
|
|
9
|
+
export {};
|