@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.
Files changed (58) hide show
  1. package/apps/cli/dist/build-info.json +2 -2
  2. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  3. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  4. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  5. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  6. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  7. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  8. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
  9. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  10. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  11. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  12. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  13. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  14. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  15. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
  16. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
  17. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +1 -1
  18. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +1 -1
  19. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.d.ts +2 -0
  20. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +22 -0
  21. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +20 -0
  22. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/service-status.js +14 -1
  23. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  24. package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
  25. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  26. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -24
  27. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  28. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  29. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
  30. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +21 -33
  31. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +3 -4
  32. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/dispatcher.d.ts +4 -0
  33. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/dispatcher.js +29 -6
  34. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/identity.d.ts +1 -1
  35. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/identity.js +2 -2
  36. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/send-error.d.ts +6 -0
  37. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/send-error.js +10 -0
  38. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/card-session.d.ts +3 -2
  39. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/card-session.js +54 -10
  40. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +4 -2
  41. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +73 -109
  42. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connector.d.ts +3 -5
  43. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connector.js +27 -40
  44. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/reasoning-frame.js +42 -7
  45. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +1 -12
  46. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +6 -126
  47. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
  48. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
  49. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/{index-CXTvRGim.js → index-B127MhT-.js} +10 -9
  50. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
  51. package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
  52. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
  53. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  54. package/package.json +27 -27
  55. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/text-send.d.ts +0 -19
  56. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/text-send.js +0 -86
  57. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/presentation/delivery-notice.d.ts +0 -5
  58. package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/presentation/delivery-notice.js +0 -35
@@ -15,7 +15,6 @@ import { MODEL_WAIT_TIMEOUT_MESSAGE } from "../execution/model-wait.js";
15
15
  import { ImDeliveryIdentity } from "../delivery/identity.js";
16
16
  import { ImDeliveryDispatcher } from "../delivery/dispatcher.js";
17
17
  import { ImRunProjector } from "../presentation/run-projector.js";
18
- import { deliveryNotice } from "../presentation/delivery-notice.js";
19
18
  import { MemoryImSessionStore } from "./session-store.js";
20
19
  import { addRulesRecovery, selectRulesContext } from "./rules-context.js";
21
20
  import { planStableContext } from "./stable-context.js";
@@ -65,7 +64,7 @@ export class ImRuntime {
65
64
  #delivery;
66
65
  #cardDelivery;
67
66
  #deliveryIdentity;
68
- // 宿主凭据来源是黑盒;沿原初始化/建联入口保存值,REST 不重新获取或等待 WS 核验。
67
+ // 仅保存已核验 Bot/空间的凭据;候选值核验期间 REST 继续使用旧值,不等待 WS。
69
68
  #restToken;
70
69
  #sessions = new Map();
71
70
  #sessionStore;
@@ -201,7 +200,6 @@ export class ImRuntime {
201
200
  ? this.dependencies.credentials(config, signal)
202
201
  : Promise.resolve(config.bf_token));
203
202
  signal.throwIfAborted();
204
- this.#restToken = token?.trim();
205
203
  return token;
206
204
  };
207
205
  const connector = new GatewayTransport(this.config, credentials, {
@@ -210,6 +208,11 @@ export class ImRuntime {
210
208
  if (connector === this.#connector && !signal.aborted)
211
209
  this.#observePosition(position);
212
210
  },
211
+ onTaskPosition: (position) => {
212
+ // 原任务目标身份生成 key;重连中 current connector 可能尚未核验空间。
213
+ if (!this.#signal.aborted)
214
+ this.#observePosition(position, this.#key(position, connector.identity));
215
+ },
213
216
  onRulesChanged: (change) => {
214
217
  if (connector !== this.#connector || signal.aborted)
215
218
  return;
@@ -237,8 +240,9 @@ export class ImRuntime {
237
240
  dispatcher: this.#cardDelivery,
238
241
  identity: this.#deliveryIdentity,
239
242
  token: () => this.#restToken,
240
- // 只供旧任务选择本 Bot 当前连接;生命周期停止后旧 signal 不会随新 start 复活。
241
- current: () => this.#connector
243
+ acceptToken: (token) => {
244
+ this.#restToken = token;
245
+ }
242
246
  });
243
247
  this.#connector = connector;
244
248
  try {
@@ -373,9 +377,9 @@ export class ImRuntime {
373
377
  this.#drainErrors.push(new Error(code));
374
378
  this.#diagnostic(code, runId);
375
379
  }
376
- #key(message) {
380
+ #key(message, identity = this.#connector.identity) {
377
381
  return [
378
- this.#connector.identity,
382
+ identity,
379
383
  imBotIdentity(this.config),
380
384
  this.config.adapter.adapter_type ?? "",
381
385
  message.conversationKind,
@@ -384,10 +388,9 @@ export class ImRuntime {
384
388
  .map(encodeURIComponent)
385
389
  .join("/");
386
390
  }
387
- #observePosition(position) {
391
+ #observePosition(position, key = this.#key(position)) {
388
392
  if (this.#closed || !validMessageSeq(position.messageSeq))
389
393
  return;
390
- const key = this.#key(position);
391
394
  try {
392
395
  const binding = this.#sessionStore.read(key);
393
396
  if (!binding?.id || !this.#sessionStore.patchGap)
@@ -792,36 +795,21 @@ export class ImRuntime {
792
795
  this.#failureNotifications.set(failure.diagnosticId, notification);
793
796
  return notification;
794
797
  }
795
- async #reply(message, text, effectKey, requireDelivered = false, final = false, allowUnknownNotice = true, finalOptions) {
798
+ async #reply(message, text, effectKey, requireDelivered = false, final = false, finalOptions, runId) {
796
799
  if (this.#closed || this.#signal.aborted || !this.#delivery)
797
800
  return;
798
801
  const receipt = await this.#delivery.deliver(effectKey, () => final && message.replyFinal
799
802
  ? message.replyFinal(text, effectKey, finalOptions)
800
- : message.reply(text, effectKey, finalOptions), { obsolete: finalOptions ? () => finalOptions.obsolete() : undefined });
803
+ : message.reply(text, effectKey, finalOptions), {
804
+ obsolete: finalOptions ? () => finalOptions.obsolete() : undefined,
805
+ ...(finalOptions ? { attempts: 4 } : {})
806
+ });
801
807
  if (finalOptions?.obsolete())
802
808
  return;
803
809
  if (receipt.state !== "delivered") {
804
810
  if (this.#draining)
805
811
  this.#drainErrors.push(new Error(receipt.code ?? "IM_DELIVERY_FAILED"));
806
- this.#diagnostic(receipt.code ?? "IM_DELIVERY_FAILED");
807
- if (allowUnknownNotice &&
808
- receipt.state === "unknown" &&
809
- message.replyDeliveryUnknown &&
810
- !this.#closed &&
811
- !this.#signal.aborted) {
812
- const notice = deliveryNotice();
813
- // 未知通知仍属于原轮最终投递;stop/reset 必须取消在途请求并阻止后续重试。
814
- // 迟到 ACK 与代次过期共用发送边界检查,不能因 REST 独立于 WS 而脱离任务期限。
815
- const noticeSignal = finalOptions
816
- ? AbortSignal.any([this.#signal, finalOptions.signal])
817
- : this.#signal;
818
- const obsolete = () => noticeSignal.aborted ||
819
- Boolean(finalOptions?.obsolete()) ||
820
- Boolean(message.isReplyDelivered?.(effectKey));
821
- const result = await this.#delivery.deliver(`delivery-unknown:${effectKey}`, () => message.replyDeliveryUnknown(notice, `delivery-unknown:${effectKey}`, effectKey, noticeSignal, obsolete), { obsolete });
822
- if (result.state !== "delivered" && !obsolete())
823
- this.#diagnostic("IM_DELIVERY_NOTICE_FAILED");
824
- }
812
+ this.#diagnostic(receipt.code ?? "IM_DELIVERY_FAILED", runId);
825
813
  if (requireDelivered)
826
814
  throw new Error(receipt.code ?? "IM_DELIVERY_FAILED");
827
815
  }
@@ -1133,7 +1121,7 @@ export class ImRuntime {
1133
1121
  };
1134
1122
  try {
1135
1123
  try {
1136
- presentation = message.beginPresentation?.(rootRunId, (code) => this.#diagnostic(code, rootRunId), controls);
1124
+ presentation = message.beginPresentation?.(rootRunId, (code, data) => this.#diagnostic(code, rootRunId, data), controls);
1137
1125
  presentation?.update(snapshot());
1138
1126
  session.activeInvocationId = request.invocationId;
1139
1127
  executionStarted = true;
@@ -1386,11 +1374,11 @@ export class ImRuntime {
1386
1374
  providerSessionId: session.providerSession.sessionId
1387
1375
  });
1388
1376
  // 最终文本拥有独立投递身份,即使进度卡投递失败,也必须尝试回复用户。
1389
- await this.#reply(message, text, `final:${rootRunId}`, false, allowMention, projector.snapshot().terminal !== "cancelled", {
1377
+ await this.#reply(message, text, `final:${rootRunId}`, false, allowMention, {
1390
1378
  artifacts: prepared.artifacts,
1391
1379
  signal: deliverySignal,
1392
1380
  obsolete: () => deliverySignal.aborted || (allowMention && obsolete())
1393
- });
1381
+ }, rootRunId);
1394
1382
  }
1395
1383
  finally {
1396
1384
  if (this.#finalDeliveries.get(key) === delivery)
@@ -96,9 +96,6 @@ export interface ImInboundMessage {
96
96
  reply(text: string, effectKey?: string, options?: Pick<ImFinalReplyOptions, "signal" | "obsolete">): Promise<void>;
97
97
  replyFinal?(text: string, effectKey: string, options?: ImFinalReplyOptions): Promise<void>;
98
98
  replyFailure?(event: CanonicalEvent, effectKey: string, options?: Pick<ImFinalReplyOptions, "signal" | "obsolete">): Promise<void>;
99
- /** 原轮未知通知继承最终投递取消及过期判断,在实际 REST 发送前再次检查。 */
100
- replyDeliveryUnknown?(event: CanonicalEvent, effectKey: string, replyEffectKey: string, signal: AbortSignal, obsolete?: () => boolean): Promise<void>;
101
- isReplyDelivered?(effectKey: string): boolean;
102
99
  buildContext(signal: AbortSignal, options?: {
103
100
  initialSession: boolean;
104
101
  configuredItems?: readonly ContextItem[];
@@ -107,7 +104,7 @@ export interface ImInboundMessage {
107
104
  }): Promise<ContextEnvelope>;
108
105
  executionEnvironment?(): InvokeEnvironment;
109
106
  runMetadata?: Record<string, unknown>;
110
- beginPresentation?(runId: string, onDiagnostic: (code: string) => void, controls: ImRunControls): ImPresentation;
107
+ beginPresentation?(runId: string, onDiagnostic: (code: string, data?: Record<string, unknown>) => void, controls: ImRunControls): ImPresentation;
111
108
  }
112
109
  export interface ImPresentation {
113
110
  interaction?(request: InteractionRequestedPayload): Promise<boolean>;
@@ -135,6 +132,8 @@ export interface ChannelCallbacks {
135
132
  shortId?: string;
136
133
  }): void;
137
134
  onPosition?(position: ImPositionObservation): void;
135
+ /** 已受理任务的 REST 回执位置,归 Bot/任务所有,不要求接收 WS 仍在线。 */
136
+ onTaskPosition?(position: ImPositionObservation): void;
138
137
  authorizeSpace?: (spaceId: string) => void;
139
138
  onMessage(message: ImInboundMessage): void;
140
139
  onDisconnect(code: string, retryable?: boolean): void;
@@ -11,6 +11,10 @@ export declare class ImDeliveryDispatcher {
11
11
  get receiptCount(): number;
12
12
  deliver(effectKey: string, operation: () => Promise<string | void>, options?: {
13
13
  transient?: boolean;
14
+ /** 仅当前 finalMsg/卡片 finish 显式指定剩余尝试数,包含首发,最多四次。 */
15
+ attempts?: 1 | 2 | 3 | 4;
14
16
  obsolete?: () => boolean;
17
+ cardOperation?: "send" | "edit";
18
+ onDiagnostic?: (code: string, data?: Record<string, unknown>) => void;
15
19
  }): Promise<ImDeliveryReceipt>;
16
20
  }
@@ -1,5 +1,6 @@
1
+ import { sanitizeDiagnosticBody } from "@mininglamp-oss/octo-runtime-adapter-sdk";
1
2
  import { OctoApiError } from "../transport/api/errors.js";
2
- import { ImSendError } from "./text-send.js";
3
+ import { ImSendError } from "./send-error.js";
3
4
  export class ImDeliveryDispatcher {
4
5
  signal;
5
6
  #receipts = new Map();
@@ -14,7 +15,7 @@ export class ImDeliveryDispatcher {
14
15
  const previous = this.#receipts.get(effectKey);
15
16
  if (previous?.state === "delivered")
16
17
  return { ...previous };
17
- const attempts = options.transient ? 1 : 3;
18
+ const attempts = options.transient ? 1 : (options.attempts ?? 3);
18
19
  let receipt = { effectKey, state: "pending" };
19
20
  this.#record(receipt);
20
21
  for (let attempt = 0; attempt < attempts && !this.signal.aborted; attempt++) {
@@ -36,12 +37,27 @@ export class ImDeliveryDispatcher {
36
37
  code: error instanceof ImSendError
37
38
  ? error.code
38
39
  : status
39
- ? `IM_HTTP_${status}`
40
+ ? options.cardOperation
41
+ ? `IM_CARD_${options.cardOperation.toUpperCase()}_${status}`
42
+ : `IM_HTTP_${status}`
40
43
  : "IM_DELIVERY_UNKNOWN"
41
44
  };
42
45
  this.#record(receipt);
43
- // WS 已在同一确认窗口完成四次预算,不再叠乘 REST 的重试次数。
44
- if (error instanceof ImSendError)
46
+ // HTTP 状态只描述本次投递,不代表业务永久失败;诊断先脱敏再限长,不记录请求正文。
47
+ try {
48
+ options.onDiagnostic?.(receipt.code, options.cardOperation && error instanceof OctoApiError
49
+ ? {
50
+ path: error.path.split(/[?#]/, 1)[0],
51
+ http_status: error.status,
52
+ response_body: sanitizeDiagnosticBody(error.body)
53
+ }
54
+ : undefined);
55
+ }
56
+ catch {
57
+ /* 诊断回调失败不得改变投递结果或触发额外发送。 */
58
+ }
59
+ // 仅本轮 REST 收尾可重试未知响应;明确取消/拒绝立即结束,不另开确认窗口。
60
+ if (error instanceof ImSendError && !(options.attempts && error.state === "unknown"))
45
61
  break;
46
62
  if (status && status !== 429 && status < 500)
47
63
  break;
@@ -73,8 +89,15 @@ export class ImDeliveryDispatcher {
73
89
  }
74
90
  }
75
91
  }
76
- if (receipt.state === "pending")
92
+ if (receipt.state === "pending") {
77
93
  receipt = { effectKey, state: "failed", code: "IM_DELIVERY_CANCELLED" };
94
+ try {
95
+ options.onDiagnostic?.(receipt.code);
96
+ }
97
+ catch {
98
+ /* 取消诊断同样不能阻断清理。 */
99
+ }
100
+ }
78
101
  this.#record(receipt);
79
102
  return receipt;
80
103
  }
@@ -1,4 +1,4 @@
1
- /** 一次已核验目标身份的投递权限及有界 ACK 账本;更新 token 或重建 WS 不取消。 */
1
+ /** 一次已核验目标身份的投递权限及有界 REST 回执缓存;更新 token 或重建 WS 不取消。 */
2
2
  export declare class ImDeliveryScope {
3
3
  #private;
4
4
  readonly signal: AbortSignal;
@@ -1,5 +1,5 @@
1
- import { ImSendError } from "./text-send.js";
2
- /** 一次已核验目标身份的投递权限及有界 ACK 账本;更新 token 或重建 WS 不取消。 */
1
+ import { ImSendError } from "./send-error.js";
2
+ /** 一次已核验目标身份的投递权限及有界 REST 回执缓存;更新 token 或重建 WS 不取消。 */
3
3
  export class ImDeliveryScope {
4
4
  #abort = new AbortController();
5
5
  #confirmed = new Set();
@@ -0,0 +1,6 @@
1
+ /** REST 投递错误保留本次请求的确认状态;不触发 WS 恢复或重新执行模型。 */
2
+ export declare class ImSendError extends Error {
3
+ readonly code: string;
4
+ readonly state: "failed" | "unknown";
5
+ constructor(code: string, state: "failed" | "unknown");
6
+ }
@@ -0,0 +1,10 @@
1
+ /** REST 投递错误保留本次请求的确认状态;不触发 WS 恢复或重新执行模型。 */
2
+ export class ImSendError extends Error {
3
+ code;
4
+ state;
5
+ constructor(code, state) {
6
+ super(code);
7
+ this.code = code;
8
+ this.state = state;
9
+ }
10
+ }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * 单 Run 卡片会话:首次创建、后续编辑同一消息,并用序号和终态屏障收敛状态。
3
- * 终态卡片失败由 finish 返回,最终文本仍由执行编排投递;回执不代表客户端已经渲染。
3
+ * 终态展示被拒绝时有界降级到精简帧;确认投递后 finish 正常返回,仍失败则保留诊断。
4
+ * 最终文本由执行编排独立投递;服务端回执不代表客户端已经渲染。
4
5
  */
5
6
  import type { ImAddress } from "../contracts.js";
6
7
  import type { OctoConnector } from "./connector.js";
@@ -12,7 +13,7 @@ export declare class CardSession {
12
13
  readonly delivery: ImDeliveryDispatcher;
13
14
  readonly address: ImAddress;
14
15
  readonly effectKey: string;
15
- constructor(connector: OctoConnector, delivery: ImDeliveryDispatcher, address: ImAddress, runId: string, stopTyping: () => void, onDiagnostic: (code: string) => void);
16
+ constructor(connector: OctoConnector, delivery: ImDeliveryDispatcher, address: ImAddress, runId: string, stopTyping: () => void, onDiagnostic: (code: string, data?: Record<string, unknown>) => void);
16
17
  update(snapshot: RunPresentation): void;
17
18
  finish(): Promise<void>;
18
19
  /** 所有者完成 finish 后释放调度/回调;保留 messageId 供已有卡片按钮关联使用。 */
@@ -57,21 +57,65 @@ export class CardSession {
57
57
  // 模板查询期间可能已收到终态;旧快照必须在出站前再次检查。
58
58
  if (!this.#scheduler || (this.#scheduler.terminal && !settled))
59
59
  return;
60
- const seq = ++this.#seq;
61
- const receipt = await this.delivery.deliver(`${this.effectKey}:${seq}`, () => this.connector.card(this.address, template, frame, this.effectKey, this.#messageId, seq, !settled), {
62
- transient: !settled,
63
- obsolete: () => !this.#scheduler || (this.#scheduler.terminal && !settled)
64
- });
60
+ // 同一 finish 的原帧与精简帧共用四次预算,切换展示内容不能重开重试窗口。
61
+ const budget = { remaining: settled ? 4 : 1 };
62
+ let receipt = await this.#deliver(frame, template, settled, budget);
63
+ // 400 不是业务终态。只在明确拒收后替换展示内容再投一次,不重放未知投递或另起可见卡片。
64
+ if (settled &&
65
+ budget.remaining > 0 &&
66
+ receipt.state === "failed" &&
67
+ (receipt.code === "IM_CARD_SEND_400" || receipt.code === "IM_CARD_EDIT_400")) {
68
+ const compact = {
69
+ reasoningId: frame.reasoningId,
70
+ state: frame.state,
71
+ title: "执行结果",
72
+ statusLabel: frame.statusLabel,
73
+ statusTone: frame.statusTone,
74
+ traceExpanded: false,
75
+ traceCollapsed: true,
76
+ collapsedSummary: frame.statusLabel + " · 过程详情暂不可用,请查看最终回复或运行记录。",
77
+ phases: [
78
+ {
79
+ thought: "过程详情暂不可用,请查看最终回复或运行记录。",
80
+ actions: [
81
+ {
82
+ tool: "任务状态",
83
+ detail: frame.statusLabel,
84
+ statusGlyph: "●",
85
+ statusTone: "Accent"
86
+ }
87
+ ]
88
+ }
89
+ ],
90
+ ...(frame.state === "error"
91
+ ? { errorTitle: "执行失败", errorMessage: "请查看最终回复或运行记录。" }
92
+ : {})
93
+ };
94
+ receipt = await this.#deliver(compact, template, settled, budget);
95
+ if (receipt.state === "delivered")
96
+ this.#onDiagnostic?.("IM_CARD_TERMINAL_DEGRADED");
97
+ }
65
98
  if (receipt.state === "delivered") {
66
99
  // 后续更新绑定第一次成功发送的消息,不另起卡片;可见卡片接替 typing 提示。
67
100
  this.#messageId = receipt.messageId;
68
101
  this.#stopTyping?.();
69
102
  }
70
- else {
71
- if (settled)
72
- this.#terminalFailed = true;
73
- this.#onDiagnostic?.(receipt.code ?? "IM_CARD_FAILED");
74
- }
103
+ else if (settled)
104
+ this.#terminalFailed = true;
105
+ }
106
+ /** 沿同一卡片串行发送;降级帧也使用新序号和独立回执,保留取消与旧帧屏障。 */
107
+ #deliver(frame, template, settled, budget) {
108
+ const seq = ++this.#seq;
109
+ return this.delivery.deliver(`${this.effectKey}:${seq}`, () => {
110
+ budget.remaining--;
111
+ return this.connector.card(this.address, template, frame, this.effectKey, this.#messageId, seq, !settled);
112
+ }, {
113
+ transient: !settled,
114
+ ...(settled ? { attempts: budget.remaining } : {}),
115
+ obsolete: () => !this.#scheduler || (this.#scheduler.terminal && !settled),
116
+ cardOperation: this.#messageId ? "edit" : "send",
117
+ onDiagnostic: (code, data) => this.#onDiagnostic?.(code, data)
118
+ });
75
119
  }
76
120
  async finish() {
77
121
  this.#stopTyping?.();
@@ -13,7 +13,8 @@ export declare class GatewayTransport {
13
13
  dispatcher: ImDeliveryDispatcher;
14
14
  identity: ImDeliveryIdentity;
15
15
  token?: () => string | undefined;
16
- current: () => GatewayTransport | undefined;
16
+ /** 身份及空间准入后同步发布凭据;候选值不得提前供旧任务读取。 */
17
+ acceptToken?: (token: string) => void;
17
18
  } | undefined;
18
19
  identity: string;
19
20
  readonly botId: string;
@@ -57,7 +58,8 @@ export declare class GatewayTransport {
57
58
  dispatcher: ImDeliveryDispatcher;
58
59
  identity: ImDeliveryIdentity;
59
60
  token?: () => string | undefined;
60
- current: () => GatewayTransport | undefined;
61
+ /** 身份及空间准入后同步发布凭据;候选值不得提前供旧任务读取。 */
62
+ acceptToken?: (token: string) => void;
61
63
  } | undefined);
62
64
  get status(): {
63
65
  connected: boolean;