@oyasmi/pipiclaw 0.6.7-beta.1 → 0.6.7-beta.3

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/README.md CHANGED
@@ -210,7 +210,7 @@ $env:PIPICLAW_SHELL = "C:\Program Files\Git\bin\bash.exe"
210
210
  "cardTemplateKey": "content",
211
211
  "allowFrom": [],
212
212
  "busyMessageDefault": "steer",
213
- "progressDisplay": "full"
213
+ "responseMode": "full_progress_then_plain_final"
214
214
  }
215
215
  ```
216
216
 
@@ -231,8 +231,8 @@ $env:PIPICLAW_SHELL = "C:\Program Files\Git\bin\bash.exe"
231
231
  设为 `[]` 或删除时表示允许所有人
232
232
  - `busyMessageDefault`
233
233
  设为 `"steer"`(默认)或 `"followUp"` / `"followup"`。控制 Agent 忙碌时普通消息的默认处理方式;答疑机器人场景建议设为 `"followUp"`。
234
- - `progressDisplay`
235
- 设为 `"full"`(默认)或 `"rolling"`。控制 AI Card 进度展示方式;`"rolling"` 模式下执行中只显示最近 3 条进展,完成后收起为一行摘要。
234
+ - `responseMode`
235
+ 设为 `"full_progress_then_plain_final"`(默认)、`"rolling_progress_then_plain_final"` 或 `"final_card_only"`。统一控制过程展示与最终投递:`rolling` 执行中只显示最近 3 条进展并在完成后收起为一行摘要;`final_card_only` 不展示过程,最终答案直接写入 AI Card。
236
236
 
237
237
  推荐把 AI Card 一起配上,这样在钉钉里能直接看到过程更新。只有在排查接入链路时,才建议临时把 `cardTemplateId` 留空。
238
238
 
@@ -21,7 +21,7 @@ These are handled directly by the DingTalk transport/runtime layer.
21
21
 
22
22
  While a task is running, plain messages use the configured busy-message default. The default is \`steer\`; set \`busyMessageDefault\` in channel.json to \`followUp\` or \`followup\` to queue plain messages after the current task.
23
23
 
24
- Set \`progressDisplay\` in channel.json to \`rolling\` for compact AI Card progress: recent entries while running, then a short summary after completion.
24
+ Set \`responseMode\` in channel.json to control output shape: \`full_progress_then_plain_final\` (default) streams full progress then sends a plain final message; \`rolling_progress_then_plain_final\` shows only the most recent progress entries, then a short summary; \`final_card_only\` hides progress and delivers the final answer in the AI Card.
25
25
 
26
26
  ## Session Commands
27
27
 
@@ -33,7 +33,8 @@ function mergeAssistantUsage(runState, usage) {
33
33
  }
34
34
  export async function handleSessionEvent(event, context) {
35
35
  const { ctx, logCtx, queue, pendingTools, store, runState, memoryLifecycle } = context;
36
- const finalCardOnly = ctx.responseMode === "final_card_only";
36
+ const showProgress = ctx.progressStyle !== "none";
37
+ const finalToCard = ctx.finalDelivery === "card";
37
38
  if (isToolExecutionStartEvent(event)) {
38
39
  const label = extractLabelFromArgs(event.args) || event.toolName;
39
40
  pendingTools.set(event.toolCallId, {
@@ -43,7 +44,7 @@ export async function handleSessionEvent(event, context) {
43
44
  });
44
45
  memoryLifecycle.noteToolCall();
45
46
  log.logToolStart(logCtx, event.toolName, label, isRecord(event.args) ? event.args : {});
46
- if (!finalCardOnly) {
47
+ if (showProgress) {
47
48
  queue.enqueue(() => ctx.respond(formatProgressEntry("tool", label), false), "tool label");
48
49
  }
49
50
  return;
@@ -56,7 +57,7 @@ export async function handleSessionEvent(event, context) {
56
57
  if (!partialText.trim()) {
57
58
  return;
58
59
  }
59
- if (!finalCardOnly) {
60
+ if (showProgress) {
60
61
  queue.enqueue(() => ctx.respond(formatProgressEntry("tool", partialText), false), "tool update");
61
62
  }
62
63
  return;
@@ -117,7 +118,7 @@ export async function handleSessionEvent(event, context) {
117
118
  else {
118
119
  log.logToolSuccess(logCtx, event.toolName, durationMs, resultStr);
119
120
  }
120
- if (treatAsError && !finalCardOnly) {
121
+ if (treatAsError && showProgress) {
121
122
  queue.enqueue(() => ctx.respond(formatProgressEntry("error", truncate(resultStr, 200)), false), "tool error");
122
123
  }
123
124
  return;
@@ -134,7 +135,7 @@ export async function handleSessionEvent(event, context) {
134
135
  runState.finalOutcome = { kind: "final", text: commandResultText };
135
136
  log.logResponse(logCtx, commandResultText);
136
137
  queue.enqueue(async () => {
137
- if (finalCardOnly) {
138
+ if (finalToCard) {
138
139
  await ctx.replaceMessage(commandResultText);
139
140
  }
140
141
  else {
@@ -173,13 +174,13 @@ export async function handleSessionEvent(event, context) {
173
174
  }
174
175
  }
175
176
  const text = textParts.join("\n");
176
- if (!finalCardOnly) {
177
+ if (showProgress) {
177
178
  for (const thinking of thinkingParts) {
178
179
  log.logThinking(logCtx, thinking);
179
180
  queue.enqueue(() => ctx.respond(formatProgressEntry("thinking", thinking), false), "thinking");
180
181
  }
181
182
  }
182
- if (text.trim() && (hasToolCalls || finalCardOnly)) {
183
+ if (text.trim() && hasToolCalls && showProgress) {
183
184
  queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", text), false), "assistant progress");
184
185
  }
185
186
  }
@@ -210,7 +211,7 @@ export async function handleSessionEvent(event, context) {
210
211
  memoryLifecycle.noteCompletedAssistantTurn();
211
212
  log.logResponse(logCtx, finalText);
212
213
  queue.enqueue(async () => {
213
- if (finalCardOnly) {
214
+ if (finalToCard) {
214
215
  await ctx.replaceMessage(finalText);
215
216
  runState.finalResponseDelivered = true;
216
217
  }
@@ -227,7 +228,7 @@ export async function handleSessionEvent(event, context) {
227
228
  if (isAutoCompactionStartEvent(event)) {
228
229
  const label = "Compacting context...";
229
230
  log.logInfo(`Compaction started (reason: ${event.reason})`);
230
- if (!finalCardOnly) {
231
+ if (showProgress) {
231
232
  queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", label), false), "compaction start");
232
233
  }
233
234
  return;
@@ -243,7 +244,7 @@ export async function handleSessionEvent(event, context) {
243
244
  else if (event.errorMessage) {
244
245
  runState.lastCompactionError = event.errorMessage;
245
246
  log.logWarning("Compaction failed", event.errorMessage);
246
- if (!finalCardOnly) {
247
+ if (showProgress) {
247
248
  queue.enqueue(() => ctx.respond(formatProgressEntry("error", truncate(event.errorMessage ?? "Compaction failed", 200)), false), "compaction error");
248
249
  }
249
250
  }
@@ -251,7 +252,7 @@ export async function handleSessionEvent(event, context) {
251
252
  }
252
253
  if (isAutoRetryStartEvent(event)) {
253
254
  log.logWarning(`Retrying (${event.attempt}/${event.maxAttempts})`, event.errorMessage);
254
- if (!finalCardOnly) {
255
+ if (showProgress) {
255
256
  queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", `Retrying (${event.attempt}/${event.maxAttempts})...`), false), "retry");
256
257
  }
257
258
  }
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ export { findExactModelReferenceMatch, findModelReferenceMatch, formatModelList,
15
15
  export { APP_HOME_DIR, APP_NAME, AUTH_CONFIG_PATH, CHANNEL_CONFIG_PATH, MODELS_CONFIG_PATH, SECURITY_CONFIG_PATH, SETTINGS_CONFIG_PATH, SUB_AGENTS_DIR, SUB_AGENTS_DIR_NAME, TOOLS_CONFIG_PATH, WORKSPACE_DIR, } from "./paths.js";
16
16
  export { ensureChannelDir, getChannelDir, getChannelDirName, } from "./runtime/channel-paths.js";
17
17
  export { createDingTalkContext } from "./runtime/delivery.js";
18
- export { type BusyMessageDefaultConfig, type BusyMessageMode, DingTalkBot, type DingTalkConfig, type DingTalkContext, type DingTalkEvent, type DingTalkHandler, isBusyMessageDefaultConfig, isProgressDisplayConfig, normalizeBusyMessageDefault, normalizeProgressDisplay, type ProgressDisplayMode, } from "./runtime/dingtalk.js";
18
+ export { type BusyMessageDefaultConfig, type BusyMessageMode, DingTalkBot, type DingTalkConfig, type DingTalkContext, type DingTalkEvent, type DingTalkHandler, type FinalDelivery, finalDeliveryOf, isBusyMessageDefaultConfig, isResponseModeConfig, normalizeBusyMessageDefault, normalizeResponseMode, type ProgressStyle, progressStyleOf, type ResponseMode, } from "./runtime/dingtalk.js";
19
19
  export { createEventsWatcher, type EventAction, EventsWatcher, type ImmediateEvent, type OneShotEvent, type PeriodicEvent, type ScheduledEvent, } from "./runtime/events.js";
20
20
  export { ChannelStore, type LoggedMessage, type LoggedSubAgentRun } from "./runtime/store.js";
21
21
  export { createExecutor, type ExecOptions, type ExecResult, type Executor, parseSandboxArg, type SandboxConfig, validateSandbox, } from "./sandbox.js";
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ export { findExactModelReferenceMatch, findModelReferenceMatch, formatModelList,
15
15
  export { APP_HOME_DIR, APP_NAME, AUTH_CONFIG_PATH, CHANNEL_CONFIG_PATH, MODELS_CONFIG_PATH, SECURITY_CONFIG_PATH, SETTINGS_CONFIG_PATH, SUB_AGENTS_DIR, SUB_AGENTS_DIR_NAME, TOOLS_CONFIG_PATH, WORKSPACE_DIR, } from "./paths.js";
16
16
  export { ensureChannelDir, getChannelDir, getChannelDirName, } from "./runtime/channel-paths.js";
17
17
  export { createDingTalkContext } from "./runtime/delivery.js";
18
- export { DingTalkBot, isBusyMessageDefaultConfig, isProgressDisplayConfig, normalizeBusyMessageDefault, normalizeProgressDisplay, } from "./runtime/dingtalk.js";
18
+ export { DingTalkBot, finalDeliveryOf, isBusyMessageDefaultConfig, isResponseModeConfig, normalizeBusyMessageDefault, normalizeResponseMode, progressStyleOf, } from "./runtime/dingtalk.js";
19
19
  export { createEventsWatcher, EventsWatcher, } from "./runtime/events.js";
20
20
  export { ChannelStore } from "./runtime/store.js";
21
21
  export { createExecutor, parseSandboxArg, validateSandbox, } from "./sandbox.js";
@@ -14,7 +14,7 @@ import { formatConfigDiagnostic } from "../shared/config-diagnostics.js";
14
14
  import { loadToolsConfigWithDiagnostics } from "../tools/config.js";
15
15
  import { ensureChannelDir } from "./channel-paths.js";
16
16
  import { createDingTalkContext } from "./delivery.js";
17
- import { DingTalkBot, isBusyMessageDefaultConfig, isProgressDisplayConfig, isResponseModeConfig, normalizeBusyMessageDefault, normalizeProgressDisplay, normalizeResponseMode, } from "./dingtalk.js";
17
+ import { DingTalkBot, isBusyMessageDefaultConfig, isResponseModeConfig, normalizeBusyMessageDefault, normalizeResponseMode, } from "./dingtalk.js";
18
18
  import { createEventsWatcher } from "./events.js";
19
19
  import { ChannelStore } from "./store.js";
20
20
  const DEFAULT_SOUL = `# SOUL.md
@@ -103,8 +103,7 @@ const CHANNEL_CONFIG_TEMPLATE = {
103
103
  cardTemplateKey: "content",
104
104
  allowFrom: ["your-staff-id"],
105
105
  busyMessageDefault: "steer",
106
- progressDisplay: "full",
107
- responseMode: "progress_then_plain_final",
106
+ responseMode: "full_progress_then_plain_final",
108
107
  cardAutoLayout: true,
109
108
  };
110
109
  const MODELS_CONFIG_TEMPLATE = { providers: {} };
@@ -244,13 +243,9 @@ function listChannelConfigIssues(config) {
244
243
  if (busyMessageDefault !== undefined && !isBusyMessageDefaultConfig(busyMessageDefault)) {
245
244
  issues.push('Invalid `busyMessageDefault`: expected "steer", "followUp", or "followup".');
246
245
  }
247
- const progressDisplay = config.progressDisplay;
248
- if (progressDisplay !== undefined && !isProgressDisplayConfig(progressDisplay)) {
249
- issues.push('Invalid `progressDisplay`: expected "full" or "rolling".');
250
- }
251
246
  const responseMode = config.responseMode;
252
247
  if (responseMode !== undefined && !isResponseModeConfig(responseMode)) {
253
- issues.push('Invalid `responseMode`: expected "progress_then_plain_final" or "final_card_only".');
248
+ issues.push('Invalid `responseMode`: expected "full_progress_then_plain_final", "rolling_progress_then_plain_final", or "final_card_only".');
254
249
  }
255
250
  const cardAutoLayout = config.cardAutoLayout;
256
251
  if (cardAutoLayout !== undefined && typeof cardAutoLayout !== "boolean") {
@@ -291,7 +286,6 @@ export function loadConfig(paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
291
286
  parsed.cardTemplateKey = parsed.cardTemplateKey || "content";
292
287
  parsed.robotCode = parsed.robotCode?.trim() ? parsed.robotCode : parsed.clientId;
293
288
  parsed.busyMessageDefault = normalizeBusyMessageDefault(parsed.busyMessageDefault);
294
- parsed.progressDisplay = normalizeProgressDisplay(parsed.progressDisplay);
295
289
  parsed.responseMode = normalizeResponseMode(parsed.responseMode);
296
290
  parsed.cardAutoLayout = parsed.cardAutoLayout ?? true;
297
291
  if (Array.isArray(parsed.allowFrom)) {
@@ -58,7 +58,8 @@ class ChannelDeliveryController {
58
58
  primeCard: (delayMs) => this.primeCard(delayMs),
59
59
  flush: async () => this.flush(),
60
60
  close: async () => this.close(),
61
- responseMode: this.bot.responseMode,
61
+ progressStyle: this.bot.progressStyle,
62
+ finalDelivery: this.bot.finalDelivery,
62
63
  };
63
64
  }
64
65
  primeCard(delayMs) {
@@ -100,6 +101,10 @@ class ChannelDeliveryController {
100
101
  async appendProgress(text, shouldLog) {
101
102
  if (this.closed || this.finalResponseDelivered || !text.trim())
102
103
  return;
104
+ // Final-card-only mode shows no progress; ignore any stray progress writes
105
+ // so we never create or flicker a card before the final replacement.
106
+ if (this.bot.progressStyle === "none")
107
+ return;
103
108
  this.clearCardWarmup();
104
109
  if (this.progressStartedAt === 0) {
105
110
  this.progressStartedAt = Date.now();
@@ -112,7 +117,7 @@ class ChannelDeliveryController {
112
117
  }
113
118
  this.progressSegments.push(text);
114
119
  this.progressTextDirty = true;
115
- if (this.bot.progressDisplay === "rolling") {
120
+ if (this.bot.progressStyle === "rolling") {
116
121
  this.trimToRecentEntries(ROLLING_WINDOW_SIZE);
117
122
  }
118
123
  if (this.progressWindowStartedAt === 0) {
@@ -226,8 +231,8 @@ class ChannelDeliveryController {
226
231
  }
227
232
  else if (mode === "finalize-existing") {
228
233
  if (content || this.cardWarmupTriggered) {
229
- const finalProgressText = this.bot.progressDisplay === "rolling" ? this.buildSummaryText("Done") : progressText;
230
- touchedRemote = await this.bot.replaceCard(this.event.channelId, content || this.bot.progressDisplay === "rolling" ? finalProgressText : NO_CONTENT, true);
234
+ const finalProgressText = this.bot.progressStyle === "rolling" ? this.buildSummaryText("Done") : progressText;
235
+ touchedRemote = await this.bot.replaceCard(this.event.channelId, content || this.bot.progressStyle === "rolling" ? finalProgressText : NO_CONTENT, true);
231
236
  if (!touchedRemote) {
232
237
  this.bot.discardCard(this.event.channelId);
233
238
  }
@@ -1,12 +1,13 @@
1
1
  export type BusyMessageMode = "steer" | "followUp";
2
2
  export type BusyMessageDefaultConfig = BusyMessageMode | "followup";
3
- export type ProgressDisplayMode = "full" | "rolling";
4
- export type ResponseMode = "progress_then_plain_final" | "final_card_only";
3
+ export type ResponseMode = "full_progress_then_plain_final" | "rolling_progress_then_plain_final" | "final_card_only";
4
+ export type ProgressStyle = "full" | "rolling" | "none";
5
+ export type FinalDelivery = "plain" | "card";
6
+ export declare function progressStyleOf(mode: ResponseMode): ProgressStyle;
7
+ export declare function finalDeliveryOf(mode: ResponseMode): FinalDelivery;
5
8
  export declare function isBusyMessageDefaultConfig(value: unknown): value is BusyMessageDefaultConfig;
6
- export declare function isProgressDisplayConfig(value: unknown): value is ProgressDisplayMode;
7
9
  export declare function isResponseModeConfig(value: unknown): value is ResponseMode;
8
10
  export declare function normalizeBusyMessageDefault(value: unknown): BusyMessageMode;
9
- export declare function normalizeProgressDisplay(value: unknown): ProgressDisplayMode;
10
11
  export declare function normalizeResponseMode(value: unknown): ResponseMode;
11
12
  export interface DingTalkConfig {
12
13
  clientId: string;
@@ -17,7 +18,6 @@ export interface DingTalkConfig {
17
18
  allowFrom?: string[];
18
19
  stateDir?: string;
19
20
  busyMessageDefault?: BusyMessageDefaultConfig;
20
- progressDisplay?: ProgressDisplayMode;
21
21
  responseMode?: ResponseMode;
22
22
  cardAutoLayout?: boolean;
23
23
  }
@@ -51,7 +51,8 @@ export interface DingTalkContext {
51
51
  primeCard: (delayMs: number) => void;
52
52
  flush: () => Promise<void>;
53
53
  close: () => Promise<void>;
54
- responseMode: ResponseMode;
54
+ progressStyle: ProgressStyle;
55
+ finalDelivery: FinalDelivery;
55
56
  }
56
57
  export type BusyMessageResult = {
57
58
  kind: "handled";
@@ -79,6 +80,8 @@ export declare class DingTalkBot {
79
80
  private activeMessageProcessing;
80
81
  private keepAliveTimer;
81
82
  private reconnectTimer;
83
+ private reconnectDelayTimer;
84
+ private reconnectDelayResolve;
82
85
  private isReconnecting;
83
86
  private isStopped;
84
87
  private reconnectAttempts;
@@ -87,8 +90,9 @@ export declare class DingTalkBot {
87
90
  private processedIdsOrder;
88
91
  constructor(handler: DingTalkHandler, config: DingTalkConfig);
89
92
  get busyMessageDefault(): BusyMessageMode;
90
- get progressDisplay(): ProgressDisplayMode;
91
93
  get responseMode(): ResponseMode;
94
+ get progressStyle(): ProgressStyle;
95
+ get finalDelivery(): FinalDelivery;
92
96
  /**
93
97
  * Mark an ID as processed. Returns true if this is a new ID, false if already seen.
94
98
  * Maintains a FIFO buffer of at most 200 entries.
@@ -100,6 +104,7 @@ export declare class DingTalkBot {
100
104
  private setTrackedInterval;
101
105
  private clearKeepAliveTimer;
102
106
  private clearReconnectTimer;
107
+ private clearReconnectDelay;
103
108
  private clearAllTimers;
104
109
  private sleep;
105
110
  private waitForDelay;
@@ -15,14 +15,26 @@ import { parseBuiltInCommand, renderBuiltInHelp } from "../agent/commands.js";
15
15
  import * as log from "../log.js";
16
16
  import { isRecord } from "../shared/type-guards.js";
17
17
  import { getChannelDir } from "./channel-paths.js";
18
+ const RESPONSE_MODE_VALUES = [
19
+ "full_progress_then_plain_final",
20
+ "rolling_progress_then_plain_final",
21
+ "final_card_only",
22
+ ];
23
+ export function progressStyleOf(mode) {
24
+ if (mode === "final_card_only")
25
+ return "none";
26
+ if (mode === "rolling_progress_then_plain_final")
27
+ return "rolling";
28
+ return "full";
29
+ }
30
+ export function finalDeliveryOf(mode) {
31
+ return mode === "final_card_only" ? "card" : "plain";
32
+ }
18
33
  export function isBusyMessageDefaultConfig(value) {
19
34
  return value === "steer" || value === "followUp" || value === "followup";
20
35
  }
21
- export function isProgressDisplayConfig(value) {
22
- return value === "full" || value === "rolling";
23
- }
24
36
  export function isResponseModeConfig(value) {
25
- return value === "progress_then_plain_final" || value === "final_card_only";
37
+ return typeof value === "string" && RESPONSE_MODE_VALUES.includes(value);
26
38
  }
27
39
  export function normalizeBusyMessageDefault(value) {
28
40
  if (value === undefined) {
@@ -36,23 +48,14 @@ export function normalizeBusyMessageDefault(value) {
36
48
  }
37
49
  throw new Error('Invalid `busyMessageDefault`: expected "steer", "followUp", or "followup".');
38
50
  }
39
- export function normalizeProgressDisplay(value) {
40
- if (value === undefined) {
41
- return "full";
42
- }
43
- if (isProgressDisplayConfig(value)) {
44
- return value;
45
- }
46
- throw new Error('Invalid `progressDisplay`: expected "full" or "rolling".');
47
- }
48
51
  export function normalizeResponseMode(value) {
49
52
  if (value === undefined) {
50
- return "progress_then_plain_final";
53
+ return "full_progress_then_plain_final";
51
54
  }
52
55
  if (isResponseModeConfig(value)) {
53
56
  return value;
54
57
  }
55
- throw new Error('Invalid `responseMode`: expected "progress_then_plain_final" or "final_card_only".');
58
+ throw new Error('Invalid `responseMode`: expected "full_progress_then_plain_final", "rolling_progress_then_plain_final", or "final_card_only".');
56
59
  }
57
60
  class ChannelQueue {
58
61
  constructor() {
@@ -121,6 +124,12 @@ export class DingTalkBot {
121
124
  this.activeMessageProcessing = false;
122
125
  this.keepAliveTimer = null;
123
126
  this.reconnectTimer = null;
127
+ // Dedicated timer for the in-flight backoff sleep inside doReconnect, kept
128
+ // separate from reconnectTimer so an external scheduleReconnect() (e.g. a
129
+ // WebSocket close event) can never clear the sleep out from under an active
130
+ // attempt and leave isReconnecting stuck true forever.
131
+ this.reconnectDelayTimer = null;
132
+ this.reconnectDelayResolve = null;
124
133
  this.isReconnecting = false;
125
134
  this.isStopped = false;
126
135
  this.reconnectAttempts = 0;
@@ -132,7 +141,6 @@ export class DingTalkBot {
132
141
  this.config = {
133
142
  ...config,
134
143
  busyMessageDefault: normalizeBusyMessageDefault(config.busyMessageDefault),
135
- progressDisplay: normalizeProgressDisplay(config.progressDisplay),
136
144
  responseMode: normalizeResponseMode(config.responseMode),
137
145
  cardAutoLayout: config.cardAutoLayout ?? true,
138
146
  };
@@ -140,12 +148,15 @@ export class DingTalkBot {
140
148
  get busyMessageDefault() {
141
149
  return normalizeBusyMessageDefault(this.config.busyMessageDefault);
142
150
  }
143
- get progressDisplay() {
144
- return normalizeProgressDisplay(this.config.progressDisplay);
145
- }
146
151
  get responseMode() {
147
152
  return normalizeResponseMode(this.config.responseMode);
148
153
  }
154
+ get progressStyle() {
155
+ return progressStyleOf(this.responseMode);
156
+ }
157
+ get finalDelivery() {
158
+ return finalDeliveryOf(this.responseMode);
159
+ }
149
160
  /**
150
161
  * Mark an ID as processed. Returns true if this is a new ID, false if already seen.
151
162
  * Maintains a FIFO buffer of at most 200 entries.
@@ -197,9 +208,24 @@ export class DingTalkBot {
197
208
  this.reconnectTimer = null;
198
209
  }
199
210
  }
211
+ // Cancel the backoff sleep and resolve its pending promise so the awaiting
212
+ // doReconnect unblocks (and then bails on the isStopped/!client re-check)
213
+ // instead of hanging forever.
214
+ clearReconnectDelay() {
215
+ if (this.reconnectDelayTimer) {
216
+ clearTimeout(this.reconnectDelayTimer);
217
+ this.reconnectDelayTimer = null;
218
+ }
219
+ if (this.reconnectDelayResolve) {
220
+ const resolve = this.reconnectDelayResolve;
221
+ this.reconnectDelayResolve = null;
222
+ resolve();
223
+ }
224
+ }
200
225
  clearAllTimers() {
201
226
  this.clearKeepAliveTimer();
202
227
  this.clearReconnectTimer();
228
+ this.clearReconnectDelay();
203
229
  }
204
230
  async sleep(delayMs) {
205
231
  await new Promise((resolve) => {
@@ -209,8 +235,10 @@ export class DingTalkBot {
209
235
  }
210
236
  async waitForDelay(delayMs) {
211
237
  await new Promise((resolve) => {
212
- this.reconnectTimer = this.setTrackedTimeout(() => {
213
- this.reconnectTimer = null;
238
+ this.reconnectDelayResolve = resolve;
239
+ this.reconnectDelayTimer = this.setTrackedTimeout(() => {
240
+ this.reconnectDelayTimer = null;
241
+ this.reconnectDelayResolve = null;
214
242
  resolve();
215
243
  }, delayMs);
216
244
  });
@@ -294,6 +322,13 @@ export class DingTalkBot {
294
322
  if (this.isStopped) {
295
323
  return;
296
324
  }
325
+ // An attempt is already in flight; it owns the retry loop and will
326
+ // reschedule itself on failure. Scheduling here would be redundant and,
327
+ // worse, tear down a just-established socket if the attempt has already
328
+ // succeeded by the time this fires.
329
+ if (this.isReconnecting) {
330
+ return;
331
+ }
297
332
  this.clearReconnectTimer();
298
333
  this.reconnectTimer = this.setTrackedTimeout(() => {
299
334
  this.reconnectTimer = null;
@@ -400,7 +435,13 @@ export class DingTalkBot {
400
435
  return;
401
436
  const elapsed = Date.now() - this.lastSocketAvailableTime;
402
437
  if (elapsed > 90 * 1000 && !this.activeMessageProcessing) {
403
- log.logWarning("DingTalk: connection timeout detected (>90s). Keeping active where possible...");
438
+ // No pong / activity for >90s: the socket is (half-)dead and may
439
+ // never emit a close event. Proactively force a reconnect instead
440
+ // of waiting indefinitely. scheduleReconnect no-ops if an attempt
441
+ // is already in flight or the bot has stopped.
442
+ log.logWarning("DingTalk: connection timeout detected (>90s); forcing reconnect.");
443
+ this.scheduleReconnect(1000, true);
444
+ return;
404
445
  }
405
446
  try {
406
447
  const s = this.getSocket();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.6.7-beta.1",
3
+ "version": "0.6.7-beta.3",
4
4
  "description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
5
5
  "type": "module",
6
6
  "bin": {