@oyasmi/pipiclaw 0.6.6 → 0.6.7-beta.0

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.
@@ -33,6 +33,7 @@ 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
37
  if (isToolExecutionStartEvent(event)) {
37
38
  const label = extractLabelFromArgs(event.args) || event.toolName;
38
39
  pendingTools.set(event.toolCallId, {
@@ -42,7 +43,9 @@ export async function handleSessionEvent(event, context) {
42
43
  });
43
44
  memoryLifecycle.noteToolCall();
44
45
  log.logToolStart(logCtx, event.toolName, label, isRecord(event.args) ? event.args : {});
45
- queue.enqueue(() => ctx.respond(formatProgressEntry("tool", label), false), "tool label");
46
+ if (!finalCardOnly) {
47
+ queue.enqueue(() => ctx.respond(formatProgressEntry("tool", label), false), "tool label");
48
+ }
46
49
  return;
47
50
  }
48
51
  if (isToolExecutionUpdateEvent(event)) {
@@ -53,7 +56,9 @@ export async function handleSessionEvent(event, context) {
53
56
  if (!partialText.trim()) {
54
57
  return;
55
58
  }
56
- queue.enqueue(() => ctx.respond(formatProgressEntry("tool", partialText), false), "tool update");
59
+ if (!finalCardOnly) {
60
+ queue.enqueue(() => ctx.respond(formatProgressEntry("tool", partialText), false), "tool update");
61
+ }
57
62
  return;
58
63
  }
59
64
  if (isToolExecutionEndEvent(event)) {
@@ -112,7 +117,7 @@ export async function handleSessionEvent(event, context) {
112
117
  else {
113
118
  log.logToolSuccess(logCtx, event.toolName, durationMs, resultStr);
114
119
  }
115
- if (treatAsError) {
120
+ if (treatAsError && !finalCardOnly) {
116
121
  queue.enqueue(() => ctx.respond(formatProgressEntry("error", truncate(resultStr, 200)), false), "tool error");
117
122
  }
118
123
  return;
@@ -129,10 +134,15 @@ export async function handleSessionEvent(event, context) {
129
134
  runState.finalOutcome = { kind: "final", text: commandResultText };
130
135
  log.logResponse(logCtx, commandResultText);
131
136
  queue.enqueue(async () => {
132
- const delivered = await ctx.respondPlain(commandResultText);
133
- if (!delivered) {
137
+ if (finalCardOnly) {
134
138
  await ctx.replaceMessage(commandResultText);
135
139
  }
140
+ else {
141
+ const delivered = await ctx.respondPlain(commandResultText);
142
+ if (!delivered) {
143
+ await ctx.replaceMessage(commandResultText);
144
+ }
145
+ }
136
146
  runState.finalResponseDelivered = true;
137
147
  }, "command result");
138
148
  return;
@@ -163,11 +173,13 @@ export async function handleSessionEvent(event, context) {
163
173
  }
164
174
  }
165
175
  const text = textParts.join("\n");
166
- for (const thinking of thinkingParts) {
167
- log.logThinking(logCtx, thinking);
168
- queue.enqueue(() => ctx.respond(formatProgressEntry("thinking", thinking), false), "thinking");
176
+ if (!finalCardOnly) {
177
+ for (const thinking of thinkingParts) {
178
+ log.logThinking(logCtx, thinking);
179
+ queue.enqueue(() => ctx.respond(formatProgressEntry("thinking", thinking), false), "thinking");
180
+ }
169
181
  }
170
- if (hasToolCalls && text.trim()) {
182
+ if (text.trim() && (hasToolCalls || finalCardOnly)) {
171
183
  queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", text), false), "assistant progress");
172
184
  }
173
185
  }
@@ -198,10 +210,16 @@ export async function handleSessionEvent(event, context) {
198
210
  memoryLifecycle.noteCompletedAssistantTurn();
199
211
  log.logResponse(logCtx, finalText);
200
212
  queue.enqueue(async () => {
201
- const delivered = await ctx.respondPlain(finalText);
202
- if (delivered) {
213
+ if (finalCardOnly) {
214
+ await ctx.replaceMessage(finalText);
203
215
  runState.finalResponseDelivered = true;
204
216
  }
217
+ else {
218
+ const delivered = await ctx.respondPlain(finalText);
219
+ if (delivered) {
220
+ runState.finalResponseDelivered = true;
221
+ }
222
+ }
205
223
  }, "final response");
206
224
  }
207
225
  return;
@@ -209,7 +227,9 @@ export async function handleSessionEvent(event, context) {
209
227
  if (isAutoCompactionStartEvent(event)) {
210
228
  const label = "Compacting context...";
211
229
  log.logInfo(`Compaction started (reason: ${event.reason})`);
212
- queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", label), false), "compaction start");
230
+ if (!finalCardOnly) {
231
+ queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", label), false), "compaction start");
232
+ }
213
233
  return;
214
234
  }
215
235
  if (isAutoCompactionEndEvent(event)) {
@@ -223,12 +243,16 @@ export async function handleSessionEvent(event, context) {
223
243
  else if (event.errorMessage) {
224
244
  runState.lastCompactionError = event.errorMessage;
225
245
  log.logWarning("Compaction failed", event.errorMessage);
226
- queue.enqueue(() => ctx.respond(formatProgressEntry("error", truncate(event.errorMessage ?? "Compaction failed", 200)), false), "compaction error");
246
+ if (!finalCardOnly) {
247
+ queue.enqueue(() => ctx.respond(formatProgressEntry("error", truncate(event.errorMessage ?? "Compaction failed", 200)), false), "compaction error");
248
+ }
227
249
  }
228
250
  return;
229
251
  }
230
252
  if (isAutoRetryStartEvent(event)) {
231
253
  log.logWarning(`Retrying (${event.attempt}/${event.maxAttempts})`, event.errorMessage);
232
- queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", `Retrying (${event.attempt}/${event.maxAttempts})...`), false), "retry");
254
+ if (!finalCardOnly) {
255
+ queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", `Retrying (${event.attempt}/${event.maxAttempts})...`), false), "retry");
256
+ }
233
257
  }
234
258
  }
@@ -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, normalizeBusyMessageDefault, normalizeProgressDisplay, } from "./dingtalk.js";
17
+ import { DingTalkBot, isBusyMessageDefaultConfig, isProgressDisplayConfig, isResponseModeConfig, normalizeBusyMessageDefault, normalizeProgressDisplay, 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
@@ -104,6 +104,8 @@ const CHANNEL_CONFIG_TEMPLATE = {
104
104
  allowFrom: ["your-staff-id"],
105
105
  busyMessageDefault: "steer",
106
106
  progressDisplay: "full",
107
+ responseMode: "progress_then_plain_final",
108
+ cardAutoLayout: true,
107
109
  };
108
110
  const MODELS_CONFIG_TEMPLATE = { providers: {} };
109
111
  const TOOLS_CONFIG_TEMPLATE = {
@@ -246,6 +248,14 @@ function listChannelConfigIssues(config) {
246
248
  if (progressDisplay !== undefined && !isProgressDisplayConfig(progressDisplay)) {
247
249
  issues.push('Invalid `progressDisplay`: expected "full" or "rolling".');
248
250
  }
251
+ const responseMode = config.responseMode;
252
+ if (responseMode !== undefined && !isResponseModeConfig(responseMode)) {
253
+ issues.push('Invalid `responseMode`: expected "progress_then_plain_final" or "final_card_only".');
254
+ }
255
+ const cardAutoLayout = config.cardAutoLayout;
256
+ if (cardAutoLayout !== undefined && typeof cardAutoLayout !== "boolean") {
257
+ issues.push("Invalid `cardAutoLayout`: expected boolean.");
258
+ }
249
259
  return issues;
250
260
  }
251
261
  export function printBootstrapSummary(result, io = console, paths = DEFAULT_BOOTSTRAP_PATHS) {
@@ -282,6 +292,8 @@ export function loadConfig(paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
282
292
  parsed.robotCode = parsed.robotCode?.trim() ? parsed.robotCode : parsed.clientId;
283
293
  parsed.busyMessageDefault = normalizeBusyMessageDefault(parsed.busyMessageDefault);
284
294
  parsed.progressDisplay = normalizeProgressDisplay(parsed.progressDisplay);
295
+ parsed.responseMode = normalizeResponseMode(parsed.responseMode);
296
+ parsed.cardAutoLayout = parsed.cardAutoLayout ?? true;
285
297
  if (Array.isArray(parsed.allowFrom)) {
286
298
  parsed.allowFrom = parsed.allowFrom.filter((value) => value.trim().length > 0);
287
299
  }
@@ -58,6 +58,7 @@ 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
62
  };
62
63
  }
63
64
  primeCard(delayMs) {
@@ -1,10 +1,13 @@
1
1
  export type BusyMessageMode = "steer" | "followUp";
2
2
  export type BusyMessageDefaultConfig = BusyMessageMode | "followup";
3
3
  export type ProgressDisplayMode = "full" | "rolling";
4
+ export type ResponseMode = "progress_then_plain_final" | "final_card_only";
4
5
  export declare function isBusyMessageDefaultConfig(value: unknown): value is BusyMessageDefaultConfig;
5
6
  export declare function isProgressDisplayConfig(value: unknown): value is ProgressDisplayMode;
7
+ export declare function isResponseModeConfig(value: unknown): value is ResponseMode;
6
8
  export declare function normalizeBusyMessageDefault(value: unknown): BusyMessageMode;
7
9
  export declare function normalizeProgressDisplay(value: unknown): ProgressDisplayMode;
10
+ export declare function normalizeResponseMode(value: unknown): ResponseMode;
8
11
  export interface DingTalkConfig {
9
12
  clientId: string;
10
13
  clientSecret: string;
@@ -15,6 +18,8 @@ export interface DingTalkConfig {
15
18
  stateDir?: string;
16
19
  busyMessageDefault?: BusyMessageDefaultConfig;
17
20
  progressDisplay?: ProgressDisplayMode;
21
+ responseMode?: ResponseMode;
22
+ cardAutoLayout?: boolean;
18
23
  }
19
24
  export interface DingTalkEvent {
20
25
  type: "dm" | "group";
@@ -46,6 +51,7 @@ export interface DingTalkContext {
46
51
  primeCard: (delayMs: number) => void;
47
52
  flush: () => Promise<void>;
48
53
  close: () => Promise<void>;
54
+ responseMode: ResponseMode;
49
55
  }
50
56
  export type BusyMessageResult = {
51
57
  kind: "handled";
@@ -82,6 +88,7 @@ export declare class DingTalkBot {
82
88
  constructor(handler: DingTalkHandler, config: DingTalkConfig);
83
89
  get busyMessageDefault(): BusyMessageMode;
84
90
  get progressDisplay(): ProgressDisplayMode;
91
+ get responseMode(): ResponseMode;
85
92
  /**
86
93
  * Mark an ID as processed. Returns true if this is a new ID, false if already seen.
87
94
  * Maintains a FIFO buffer of at most 200 entries.
@@ -21,6 +21,9 @@ export function isBusyMessageDefaultConfig(value) {
21
21
  export function isProgressDisplayConfig(value) {
22
22
  return value === "full" || value === "rolling";
23
23
  }
24
+ export function isResponseModeConfig(value) {
25
+ return value === "progress_then_plain_final" || value === "final_card_only";
26
+ }
24
27
  export function normalizeBusyMessageDefault(value) {
25
28
  if (value === undefined) {
26
29
  return "steer";
@@ -42,6 +45,15 @@ export function normalizeProgressDisplay(value) {
42
45
  }
43
46
  throw new Error('Invalid `progressDisplay`: expected "full" or "rolling".');
44
47
  }
48
+ export function normalizeResponseMode(value) {
49
+ if (value === undefined) {
50
+ return "progress_then_plain_final";
51
+ }
52
+ if (isResponseModeConfig(value)) {
53
+ return value;
54
+ }
55
+ throw new Error('Invalid `responseMode`: expected "progress_then_plain_final" or "final_card_only".');
56
+ }
45
57
  class ChannelQueue {
46
58
  constructor() {
47
59
  this.queue = [];
@@ -121,6 +133,8 @@ export class DingTalkBot {
121
133
  ...config,
122
134
  busyMessageDefault: normalizeBusyMessageDefault(config.busyMessageDefault),
123
135
  progressDisplay: normalizeProgressDisplay(config.progressDisplay),
136
+ responseMode: normalizeResponseMode(config.responseMode),
137
+ cardAutoLayout: config.cardAutoLayout ?? true,
124
138
  };
125
139
  }
126
140
  get busyMessageDefault() {
@@ -129,6 +143,9 @@ export class DingTalkBot {
129
143
  get progressDisplay() {
130
144
  return normalizeProgressDisplay(this.config.progressDisplay);
131
145
  }
146
+ get responseMode() {
147
+ return normalizeResponseMode(this.config.responseMode);
148
+ }
132
149
  /**
133
150
  * Mark an ID as processed. Returns true if this is a new ID, false if already seen.
134
151
  * Maintains a FIFO buffer of at most 200 entries.
@@ -665,7 +682,11 @@ export class DingTalkBot {
665
682
  const body = {
666
683
  cardTemplateId: this.config.cardTemplateId,
667
684
  outTrackId: instanceId,
668
- cardData: { cardParamMap: {} },
685
+ cardData: {
686
+ cardParamMap: {
687
+ autoLayout: String(this.config.cardAutoLayout ?? true),
688
+ },
689
+ },
669
690
  callbackType: "STREAM",
670
691
  imGroupOpenSpaceModel: { supportForward: true },
671
692
  imRobotOpenSpaceModel: { supportForward: true },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.6.6",
3
+ "version": "0.6.7-beta.0",
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": {