@ynhcj/xiaoyi-channel 0.0.221-next → 0.0.222-next

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/dist/index.js CHANGED
@@ -44,14 +44,35 @@ function extractSkillNameFromPath(filePath) {
44
44
  * the `after_tool_call` hook and write the skill name to the skills log.
45
45
  */
46
46
  function registerSkillsDiagnosticHook(api) {
47
- api.on("after_tool_call", async (event, _ctx) => {
48
- if (event.toolName !== "read")
49
- return;
50
- const skillName = extractSkillNameFromPath(event.params?.path);
47
+ // Tool name → skill name mapping for direct tool-based skill usage logging
48
+ const TOOL_SKILL_MAP = {
49
+ get_user_location: "GetCurrentLocation",
50
+ get_calendar_tool_schema: "Schedule",
51
+ get_note_tool_schema: "memorandum",
52
+ get_photo_tool_schema: "gallery",
53
+ get_contact_tool_schema: "contact",
54
+ get_device_file_tool_schema: "file",
55
+ get_alarm_tool_schema: "clock",
56
+ message: "message",
57
+ get_phone_tool_schema: "phone",
58
+ get_collection_tool_schema: "xiaoyi-collection",
59
+ };
60
+ // Log skill usage for known device tools on before_tool_call
61
+ api.on("before_tool_call", async (event, _ctx) => {
62
+ const skillName = TOOL_SKILL_MAP[event.toolName];
51
63
  if (skillName) {
52
64
  writeSkillUsage(skillName);
53
65
  }
54
66
  });
67
+ // Detect SKILL.md reads on after_tool_call (original behavior)
68
+ api.on("after_tool_call", async (event, _ctx) => {
69
+ if (event.toolName === "read") {
70
+ const skillName = extractSkillNameFromPath(event.params?.path);
71
+ if (skillName) {
72
+ writeSkillUsage(skillName);
73
+ }
74
+ }
75
+ });
55
76
  }
56
77
  /**
57
78
  * Register the cron detection hook.
@@ -507,16 +507,9 @@ export function createXYReplyDispatcher(params) {
507
507
  if (text.length === 0)
508
508
  return;
509
509
  hasSentResponse = true;
510
- // 检测新模型调用:同一模型调用内 text 是递增的("好的"→"好的,已查到"),
511
- // 跨模型调用时 text 会刷新,此时 !text.startsWith(currentModelText) 为 true
512
- if (currentModelText && !text.startsWith(currentModelText)) {
513
- // 锁存上一个模型调用的完整文本
514
- prevModelText += currentModelText;
515
- }
516
- currentModelText = text;
517
- const sep = prevModelText ? "\n" : "";
518
- const fullText = crossTurnPrefix + prevModelText + sep + text;
519
- // 串行化发送,避免 ws.send 乱序
510
+ // 串行化回调进入:SDK fire-and-forget 模式下多个 onPartialReply
511
+ // 可能并发执行,processingLock 保证 currentModelText/prevModelText
512
+ // 的读写和 ws.send 都在互斥临界区内。
520
513
  const prevLock = processingLock;
521
514
  let releaseLock;
522
515
  processingLock = new Promise((resolve) => {
@@ -524,6 +517,15 @@ export function createXYReplyDispatcher(params) {
524
517
  });
525
518
  try {
526
519
  await prevLock;
520
+ // 检测新模型调用:同一模型调用内 text 是递增的("好的"→"好的,已查到"),
521
+ // 跨模型调用时 text 会刷新,此时 !text.startsWith(currentModelText) 为 true
522
+ if (currentModelText && !text.startsWith(currentModelText)) {
523
+ // 锁存上一个模型调用的完整文本
524
+ prevModelText += currentModelText;
525
+ }
526
+ currentModelText = text;
527
+ const sep = prevModelText ? "\n" : "";
528
+ const fullText = crossTurnPrefix + prevModelText + sep + text;
527
529
  await sendA2AResponse({
528
530
  config,
529
531
  sessionId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.221-next",
3
+ "version": "0.0.222-next",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",