@ynhcj/xiaoyi-channel 0.0.165-beta → 0.0.166-beta

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.
@@ -1,17 +1,7 @@
1
- export type CronQueryAction = "list" | "status" | "runs" | "add" | "update" | "remove" | "run";
2
- export interface CronQueryEventContext {
3
- action: CronQueryAction;
4
- jobId?: string;
5
- params?: Record<string, unknown>;
6
- /** Original A2A message fields for routing the response. */
7
- sessionId?: string;
8
- taskId?: string;
9
- messageId?: string;
10
- }
11
1
  /**
12
2
  * Handle a cron-query-event.
13
3
  *
14
4
  * Calls the Gateway cron RPC and sends the result back through sendCommand
15
5
  * as a System.CronQuery command with the full result object in payload.ans.
16
6
  */
17
- export declare function handleCronQueryEvent(context: CronQueryEventContext, cfg?: unknown): Promise<void>;
7
+ export declare function handleCronQueryEvent(context: any, cfg: any): Promise<void>;
@@ -4,9 +4,12 @@
4
4
  // result back to the client via sendCommand as a System.CronQuery
5
5
  // command with the result in payload.ans.
6
6
  import { callGatewayTool } from "openclaw/plugin-sdk/agent-harness-runtime";
7
+ import * as os from "os";
7
8
  import { sendCommand } from "./formatter.js";
8
9
  import { resolveXYConfig } from "./config.js";
9
10
  import { logger } from "./utils/logger.js";
11
+ import { readFileSync, readdirSync } from "fs";
12
+ import { join } from "path";
10
13
  const GATEWAY_TIMEOUT_MS = 60_000;
11
14
  /**
12
15
  * Handle a cron-query-event.
@@ -54,6 +57,9 @@ export async function handleCronQueryEvent(context, cfg) {
54
57
  ...params,
55
58
  });
56
59
  break;
60
+ case "queryTimeList":
61
+ result = await queryTimeListLocal();
62
+ break;
57
63
  default:
58
64
  error = `Unknown action: ${context.action}`;
59
65
  logger.error(`[CRON-QUERY] ${error}`);
@@ -99,3 +105,84 @@ export async function handleCronQueryEvent(context, cfg) {
99
105
  logger.warn(`[CRON-QUERY] Missing cfg/sessionId/taskId/messageId, skipping sendCommand`);
100
106
  }
101
107
  }
108
+ /**
109
+ * Read local cron folder directly (bypassing openclaw RPC) and return
110
+ * run records from the last 7 days, grouped by date and sorted by time.
111
+ *
112
+ * Data sources:
113
+ * - state/cron/jobs.json → job id → name mapping
114
+ * - state/cron/runs/*.jsonl → run records (one JSON per line)
115
+ *
116
+ * Return format:
117
+ * [ { "YYYY-MM-DD": [ { run record with .name }, ... ] }, ... ]
118
+ */
119
+ async function queryTimeListLocal() {
120
+ const cronDir = join(os.homedir(), ".openclaw", "cron");
121
+ const jobsPath = join(cronDir, "jobs.json");
122
+ const runsDir = join(cronDir, "runs");
123
+ // 1. Build jobId → name map from jobs.json
124
+ const jobNameMap = {};
125
+ try {
126
+ const jobsRaw = readFileSync(jobsPath, "utf-8");
127
+ const jobsData = JSON.parse(jobsRaw);
128
+ for (const job of jobsData.jobs || []) {
129
+ jobNameMap[job.id] = job.name || job.id;
130
+ }
131
+ }
132
+ catch (err) {
133
+ logger.error(`[CRON-QUERY] Failed to read jobs.json: ${err.message}`);
134
+ }
135
+ // 2. Read all run files, collect runs within last 7 days
136
+ const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1000;
137
+ const allRuns = [];
138
+ let files = [];
139
+ try {
140
+ files = readdirSync(runsDir);
141
+ }
142
+ catch {
143
+ files = [];
144
+ }
145
+ for (const file of files) {
146
+ if (!file.endsWith(".jsonl"))
147
+ continue;
148
+ try {
149
+ const content = readFileSync(join(runsDir, file), "utf-8");
150
+ const lines = content.trim().split("\n");
151
+ for (const line of lines) {
152
+ if (!line.trim())
153
+ continue;
154
+ try {
155
+ const run = JSON.parse(line);
156
+ if (run.ts && run.ts >= sevenDaysAgo) {
157
+ run.name = jobNameMap[run.jobId] || run.jobId || "";
158
+ allRuns.push(run);
159
+ }
160
+ }
161
+ catch {
162
+ // skip malformed line
163
+ }
164
+ }
165
+ }
166
+ catch (err) {
167
+ logger.error(`[CRON-QUERY] Failed to read run file ${file}: ${err.message}`);
168
+ }
169
+ }
170
+ // 3. Sort by ts ascending
171
+ allRuns.sort((a, b) => a.ts - b.ts);
172
+ // 4. Group by date (YYYY-MM-DD in local time)
173
+ const grouped = new Map();
174
+ for (const run of allRuns) {
175
+ const d = new Date(run.ts);
176
+ const label = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
177
+ if (!grouped.has(label)) {
178
+ grouped.set(label, []);
179
+ }
180
+ grouped.get(label).push(run);
181
+ }
182
+ // 5. Convert to ordered array of single-key objects
183
+ const result = [];
184
+ for (const [date, runs] of grouped) {
185
+ result.push({ [date]: runs });
186
+ }
187
+ return result;
188
+ }
@@ -17,6 +17,7 @@ export interface SendA2AResponseParams {
17
17
  }>;
18
18
  errorCode?: number | string;
19
19
  errorMessage?: string;
20
+ log?: boolean;
20
21
  }
21
22
  /**
22
23
  * Send an A2A artifact update response.
@@ -42,7 +42,7 @@ function buildTextPreview(text) {
42
42
  * Send an A2A artifact update response.
43
43
  */
44
44
  export async function sendA2AResponse(params) {
45
- const { config, sessionId, taskId, messageId, text, append, final, files, errorCode, errorMessage } = params;
45
+ const { config, sessionId, taskId, messageId, text, append, final, files, errorCode, errorMessage, log: shouldLog = true } = params;
46
46
  const log = logger.withContext(sessionId, taskId);
47
47
  // 审批桥接:将 OpenClaw 的审批提示翻译成用户友好的确认文案
48
48
  const bridgedText = text === undefined ? text : rewriteOutboundApprovalText(sessionId, text);
@@ -97,11 +97,14 @@ export async function sendA2AResponse(params) {
97
97
  taskId,
98
98
  msgDetail: JSON.stringify(jsonRpcResponse),
99
99
  };
100
- // Log complete response body
101
- const redactedText = redactSensitiveText(bridgedText ?? "");
102
- log.log(`[A2A_RESPONSE] Sending artifact-update, append=${append}, final=${final}, text=${buildTextPreview(redactedText)}, files=${files?.length ?? 0}, sensitive=${containsSensitiveInfo(bridgedText ?? "")}`);
100
+ if (shouldLog) {
101
+ const redactedText = redactSensitiveText(bridgedText ?? "");
102
+ log.log(`[A2A_RESPONSE] Sending artifact-update, append=${append}, final=${final}, text=${buildTextPreview(redactedText)}, files=${files?.length ?? 0}, sensitive=${containsSensitiveInfo(bridgedText ?? "")}`);
103
+ }
103
104
  await wsManager.sendMessage(sessionId, outboundMessage);
104
- log.log(`[A2A_RESPONSE] Message sent successfully`);
105
+ if (shouldLog) {
106
+ log.log(`[A2A_RESPONSE] Message sent successfully`);
107
+ }
105
108
  }
106
109
  /**
107
110
  * Send an A2A artifact-update with reasoningText part.
@@ -172,18 +172,23 @@ export function createXYReplyDispatcher(params) {
172
172
  scopedLog().log(`[DELIVER SKIP] Empty text, skipping`);
173
173
  return;
174
174
  }
175
+ // 🔑 如果 onPartialReply 已经流式发送过文本,deliver 不再重复发送
176
+ if (hasSentResponse) {
177
+ scopedLog().log(`[DELIVER SKIP] Already sent via onPartialReply`);
178
+ return;
179
+ }
175
180
  accumulatedText += text;
176
181
  hasSentResponse = true;
177
- scopedLog().log(`[DELIVER] Accumulated text, length=${accumulatedText.length}`);
178
- // 🔑 使用动态taskId发送reasoningText更新
179
- await sendReasoningTextUpdate({
182
+ // 🔑 使用动态taskId发送A2A响应(流式append)
183
+ await sendA2AResponse({
180
184
  config,
181
185
  sessionId,
182
186
  taskId: currentTaskId,
183
187
  messageId: currentMessageId,
184
188
  text,
189
+ append: true,
190
+ final: false,
185
191
  });
186
- scopedLog().log(`[DELIVER] Sent deliver text as reasoningText update`);
187
192
  }
188
193
  catch (deliverError) {
189
194
  scopedLog().error(`Failed to deliver message:`, deliverError);
@@ -251,18 +256,18 @@ export function createXYReplyDispatcher(params) {
251
256
  state: "completed",
252
257
  });
253
258
  scopedLog().log(`[ON-IDLE] Sent completion status update`);
254
- // 🔑 使用动态taskId发送最终响应
259
+ // 🔑 使用动态taskId发送最终响应(空字符串表示流结束)
255
260
  await sendA2AResponse({
256
261
  config,
257
262
  sessionId,
258
263
  taskId: currentTaskId,
259
264
  messageId: currentMessageId,
260
- text: accumulatedText,
265
+ text: "",
261
266
  append: false,
262
267
  final: true,
263
268
  });
264
269
  finalSent = true;
265
- scopedLog().log(`[ON-IDLE] Sent final response`);
270
+ scopedLog().log(`[ON-IDLE] Sent final response (empty, stream end)`);
266
271
  }
267
272
  catch (err) {
268
273
  scopedLog().error(`[ON-IDLE] Failed to send final response:`, err);
@@ -389,10 +394,25 @@ export function createXYReplyDispatcher(params) {
389
394
  if (steerState.steered) {
390
395
  return;
391
396
  }
397
+ const currentTaskId = getActiveTaskId();
398
+ const currentMessageId = getActiveMessageId();
392
399
  const text = payload.text ?? "";
393
- scopedLog().log(`[REASONING-STREAM] Reasoning chunk received, text.length: ${text.length}`);
394
- // Reasoning stream 目前被注释掉
395
- // 如果需要可以启用
400
+ try {
401
+ if (text.length > 0) {
402
+ // 🔑 将模型真实的thinking/reasoning内容通过reasoningText转发
403
+ await sendReasoningTextUpdate({
404
+ config,
405
+ sessionId,
406
+ taskId: currentTaskId,
407
+ messageId: currentMessageId,
408
+ text,
409
+ append: false,
410
+ });
411
+ }
412
+ }
413
+ catch (err) {
414
+ scopedLog().error(`[REASONING-STREAM] Failed to send reasoning text:`, err);
415
+ }
396
416
  },
397
417
  onPartialReply: async (payload) => {
398
418
  // 🔑 steered dispatch不发送partial reply(让主dispatcher处理)
@@ -404,18 +424,23 @@ export function createXYReplyDispatcher(params) {
404
424
  const text = payload.text ?? "";
405
425
  try {
406
426
  if (text.length > 0) {
407
- await sendReasoningTextUpdate({
427
+ accumulatedText += text;
428
+ hasSentResponse = true;
429
+ // 🔑 流式文本通过 A2A text 通道发送(而非 reasoningText)
430
+ await sendA2AResponse({
408
431
  config,
409
432
  sessionId,
410
433
  taskId: currentTaskId,
411
434
  messageId: currentMessageId,
412
435
  text,
413
436
  append: false,
437
+ final: false,
438
+ log: false,
414
439
  });
415
440
  }
416
441
  }
417
442
  catch (err) {
418
- scopedLog().error(`[PARTIAL REPLY] Failed to send partial reply:`, err);
443
+ scopedLog().error(`[PARTIAL-REPLY] Failed to send partial reply:`, err);
419
444
  }
420
445
  },
421
446
  },
@@ -8,8 +8,8 @@ class ToolInputError extends Error {
8
8
  this.name = "ToolInputError";
9
9
  }
10
10
  }
11
- function isPlainObject(value) {
12
- return !!value && typeof value === "object" && !Array.isArray(value);
11
+ function isJsonObjectOrArray(value) {
12
+ return !!value && typeof value === "object";
13
13
  }
14
14
  export function createDisplayA2UICardTool(ctx) {
15
15
  const { config, sessionId, taskId, messageId } = ctx;
@@ -25,8 +25,11 @@ export function createDisplayA2UICardTool(ctx) {
25
25
  description: "A2UI card 的唯一标识。",
26
26
  },
27
27
  cardData: {
28
- type: "object",
29
- description: "A2UI card 渲染所需的数据对象,由模型根据 MCP 工具返回结果填充。",
28
+ oneOf: [
29
+ { type: "object" },
30
+ { type: "array" },
31
+ ],
32
+ description: "A2UI card 渲染所需的 JSON 对象或 JSON 数组,由模型根据 MCP 工具返回结果填充。",
30
33
  },
31
34
  },
32
35
  required: ["cardId", "cardData"],
@@ -37,8 +40,8 @@ export function createDisplayA2UICardTool(ctx) {
37
40
  if (!cardId) {
38
41
  throw new ToolInputError("缺少必填参数: cardId");
39
42
  }
40
- if (!isPlainObject(cardData)) {
41
- throw new ToolInputError("缺少必填参数: cardData,且必须是对象");
43
+ if (!isJsonObjectOrArray(cardData)) {
44
+ throw new ToolInputError("缺少必填参数: cardData,且必须是 JSON 对象或 JSON 数组");
42
45
  }
43
46
  const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
44
47
  const currentMessageId = getCurrentMessageId(sessionId) ?? messageId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.165-beta",
3
+ "version": "0.0.166-beta",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",