@dcrays/dcgchat-test 0.2.19 → 0.2.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcrays/dcgchat-test",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
@@ -22,9 +22,9 @@
22
22
  "dependencies": {
23
23
  "ali-oss": "file:src/libs/ali-oss-6.23.0.tgz",
24
24
  "axios": "file:src/libs/axios-1.13.6.tgz",
25
- "ws": "file:src/libs/ws-8.19.0.tgz",
26
25
  "md5": "file:src/libs/md5-2.3.0.tgz",
27
- "unzipper": "file:src/libs/unzipper-0.12.3.tgz"
26
+ "unzipper": "file:src/libs/unzipper-0.12.3.tgz",
27
+ "ws": "file:src/libs/ws-8.19.0.tgz"
28
28
  },
29
29
  "openclaw": {
30
30
  "extensions": [
@@ -44,5 +44,8 @@
44
44
  "localPath": "extensions/dcgchat",
45
45
  "defaultChoice": "npm"
46
46
  }
47
+ },
48
+ "devDependencies": {
49
+ "openclaw": "^2026.3.13"
47
50
  }
48
51
  }
package/src/bot.ts CHANGED
@@ -316,7 +316,7 @@ export async function handleDcgchatMessage(params: {
316
316
 
317
317
  const route = core.channel.routing.resolveAgentRoute({
318
318
  cfg,
319
- channel: "dcgchat-test",
319
+ channel: "dcgchat",
320
320
  accountId: account.accountId,
321
321
  peer: { kind: "direct", id: userId },
322
322
  });
@@ -353,13 +353,13 @@ export async function handleDcgchatMessage(params: {
353
353
  ChatType: "direct",
354
354
  SenderName: userId,
355
355
  SenderId: userId,
356
- Provider: "dcgchat-test" as const,
357
- Surface: "dcgchat-test" as const,
356
+ Provider: "dcgchat" as const,
357
+ Surface: "dcgchat" as const,
358
358
  MessageSid: msg.content.message_id,
359
359
  Timestamp: Date.now(),
360
360
  WasMentioned: true,
361
361
  CommandAuthorized: true,
362
- OriginatingChannel: "dcgchat-test" as const,
362
+ OriginatingChannel: "dcgchat" as const,
363
363
  OriginatingTo: `user:${userId}`,
364
364
  ...mediaPayload,
365
365
  });
package/src/monitor.ts CHANGED
@@ -3,7 +3,7 @@ import WebSocket from "ws";
3
3
  import { handleDcgchatMessage } from "./bot.js";
4
4
  import { resolveAccount } from "./channel.js";
5
5
  import { setWsConnection } from "./connection.js";
6
- import type { InboundMessage, OutboundReply } from "./types.js";
6
+ import type { InboundMessage } from "./types.js";
7
7
  import { setMsgParams,setMsgStatus } from "./tool.js";
8
8
  import { installSkill, uninstallSkill } from "./skill.js";
9
9
 
@@ -16,6 +16,7 @@ export type MonitorDcgchatOpts = {
16
16
 
17
17
  const RECONNECT_DELAY_MS = 3000;
18
18
  const HEARTBEAT_INTERVAL_MS = 30_000;
19
+ const emptyToolText = ['/new', '/search','/stop', '/abort', '/queue interrupt']
19
20
 
20
21
  function buildConnectUrl(account: Record<string, string>): string {
21
22
  const { wsUrl, botToken, userId, domainId, appId } = account;
@@ -111,7 +112,9 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
111
112
 
112
113
  if (parsed.messageType == "openclaw_bot_chat") {
113
114
  const msg = parsed as unknown as InboundMessage;
114
- setMsgStatus('running');
115
+ if (!emptyToolText.includes(msg.content.text?.trim())) {
116
+ setMsgStatus('running');
117
+ }
115
118
  log(`dcgchat[${account.accountId}]: openclaw_bot_chat received, ${JSON.stringify(msg)}`);
116
119
  setMsgParams({
117
120
  userId: msg._userId,
@@ -123,6 +126,8 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
123
126
  botId: msg.content.bot_id,
124
127
  agentId: msg.content.agent_id,
125
128
  });
129
+ msg.content.app_id = account.appId || '100';
130
+ msg.content.domain_id = account.domainId || '1000';
126
131
  await handleDcgchatMessage({
127
132
  cfg,
128
133
  msg,
package/src/tool.ts CHANGED
@@ -28,68 +28,114 @@ export function setMsgStatus(status: 'running' | 'finished' | '') {
28
28
  export function getMsgStatus() {
29
29
  return msgStatus;
30
30
  }
31
- let runId = '';
31
+ let toolCallId = '';
32
32
  let toolName = '';
33
+ type PluginHookName = "before_model_resolve" | "before_prompt_build" | "before_agent_start" | "llm_input" | "llm_output" | "agent_end" | "before_compaction" | "after_compaction" | "before_reset" | "message_received" | "message_sending" | "message_sent" | "before_tool_call" | "after_tool_call" | "tool_result_persist" | "before_message_write" | "session_start" | "session_end" | "subagent_spawning" | "subagent_delivery_target" | "subagent_spawned" | "subagent_ended" | "gateway_start" | "gateway_stop";
34
+ const eventList = [
35
+ {event: 'message_received', message: '书灵墨宝已就位,收到你的指令,正在解析...'},
36
+ // {event: 'before_prompt_build', message: '正在查阅背景资料,构建思考逻辑'},
37
+ // {event: 'before_agent_start', message: '书灵墨宝已就位,准备开始执行任务'},
38
+ {event: 'subagent_spawning', message: '任务较复杂,正在召唤专项助手协作...'},
39
+ {event: 'subagent_spawned', message: '专项助手已加入,准备并行处理...'},
40
+ {event: 'subagent_delivery_target', message: '正在将子任务分发给对应的助手...'},
41
+ {event: 'llm_input', message: '正在进行深度推理与思考'},
42
+ {event: 'llm_output', message: '模型思考完毕,正在整合最终答案...'},
43
+ {event: 'agent_end', message: '核心任务已处理完毕...'},
44
+ {event: 'subagent_ended', message: '专项助手任务结束,已安全退出。'},
45
+ // {event: 'before_message_write', message: '正在将本次对话存入记忆库...'},
46
+ {event: 'message_sending', message: ''},
47
+ {event: 'message_send', message: ''},
48
+ {event: 'before_tool_call', message: ''},
49
+ {event: 'after_tool_call', message: ''},
50
+ ];
51
+
52
+ function sendToolCallMessage(text: string, toolCallId: string, isCover: number) {
53
+ const ws = getWsConnection()
54
+ const params = getMsgParams();
55
+ const status = getMsgStatus();
56
+ if (ws?.readyState === WebSocket.OPEN && status === 'running') {
57
+ ws.send(JSON.stringify({
58
+ messageType: "openclaw_bot_chat",
59
+ _userId: params?.userId,
60
+ source: "client",
61
+ content: {
62
+ bot_token: params?.token,
63
+ domain_id: params?.domainId,
64
+ app_id: params?.appId,
65
+ bot_id: params?.botId,
66
+ agent_id: params?.agentId,
67
+ response: 'all_finished',
68
+ session_id:params?.sessionId,
69
+ message_id: params?.messageId || Date.now().toString()
70
+ },
71
+ }))
72
+ ws.send(JSON.stringify({
73
+ messageType: "openclaw_bot_chat",
74
+ _userId: params?.userId,
75
+ source: "client",
76
+ content: {
77
+ bot_token: params?.token,
78
+ domain_id: params?.domainId,
79
+ app_id: params?.appId,
80
+ bot_id: params?.botId,
81
+ agent_id: params?.agentId,
82
+ tool_call_id: toolCallId,
83
+ is_cover: isCover,
84
+ thinking_content: text,
85
+ response: '',
86
+ session_id:params?.sessionId,
87
+ message_id: params?.messageId || Date.now().toString()
88
+ },
89
+ }));
90
+ ws.send(JSON.stringify({
91
+ messageType: "openclaw_bot_chat",
92
+ _userId: params?.userId,
93
+ source: "client",
94
+ content: {
95
+ bot_token: params?.token,
96
+ domain_id: params?.domainId,
97
+ app_id: params?.appId,
98
+ bot_id: params?.botId,
99
+ agent_id: params?.agentId,
100
+ response: 'all_finished',
101
+ session_id:params?.sessionId,
102
+ message_id: params?.messageId || Date.now().toString()
103
+ },
104
+ }))
105
+ }
106
+ }
107
+
33
108
  export function monitoringToolMessage(api: OpenClawPluginApi) {
34
- api.on("after_tool_call", (event) => {
35
- const ws = getWsConnection()
36
- const params = getMsgParams();
37
- const status = getMsgStatus();
38
- //
39
- if (ws?.readyState === WebSocket.OPEN && status === 'running') {
40
- const log = api.runtime?.log ?? api.log;
41
- // @ts-ignore
42
- if (!runId || runId !== event.runId || !toolName || toolName !== event.toolName) {
43
- ws.send(JSON.stringify({
44
- messageType: "openclaw_bot_chat",
45
- _userId: params?.userId,
46
- source: "client",
47
- content: {
48
- bot_token: params?.token,
49
- response: 'all_finished',
50
- session_id:params?.sessionId,
51
- message_id: params?.messageId || Date.now().toString()
52
- },
53
- }));
54
- }
55
- const text = JSON.stringify({
56
- type: 'tool_call',
57
- specialIdentification: 'dcgchat_tool_call_special_identification',
58
- ...event
109
+ for (const item of eventList) {
110
+ api.on(item.event as PluginHookName, (event: any) => {
111
+ console.log("🚀 ~ 工具调用结果: ~ event:", item.event)
112
+ if (['after_tool_call', 'before_tool_call'].includes(item.event)) {
113
+ const { result: _result, ...rest } = event;
114
+ const text = JSON.stringify({
115
+ type: item.event,
116
+ specialIdentification: 'dcgchat_tool_call_special_identification',
117
+ callId: event.toolCallId || event.runId || Date.now().toString(),
118
+ ...rest,
119
+ status: item.event === 'after_tool_call' ? 'finished' : 'running'
120
+ });
121
+ sendToolCallMessage(text, event.toolCallId || event.runId || Date.now().toString(), item.event === 'after_tool_call' ? 1 : 0)
122
+ } else if (item.message) {
123
+ const text = JSON.stringify({
124
+ type: item.event,
125
+ specialIdentification: 'dcgchat_tool_call_special_identification',
126
+ toolName: '',
127
+ callId: event.runId || Date.now().toString(),
128
+ params: item.message
129
+ });
130
+ sendToolCallMessage(text, event.runId || Date.now().toString(), 0)
131
+ console.log('消息事件:', item.event, item.message)
132
+ } else {
133
+ console.log('其他事件:', item.event, JSON.stringify(event).slice(0, 3200))
134
+ }
135
+ // log?.(`dcgchat[${params?.sessionId}]:11111111 tool message to ${params?.sessionId}, ${JSON.stringify(rest)}`);
136
+ // } else {
137
+ // log?.(`dcgchat[${params?.sessionId}]:22222222 tool ${status} message to ${ws?.readyState}, ${JSON.stringify(rest)}`);
138
+ // }
59
139
  });
60
- ws.send(JSON.stringify({
61
- messageType: "openclaw_bot_chat",
62
- _userId: params?.userId,
63
- source: "client",
64
- content: {
65
- bot_token: params?.token,
66
- domain_id: params?.domainId,
67
- app_id: params?.appId,
68
- bot_id: params?.botId,
69
- agent_id: params?.agentId,
70
- thinking_content: text,
71
- response: '',
72
- session_id:params?.sessionId,
73
- message_id: params?.messageId || Date.now().toString()
74
- },
75
- }));
76
- // @ts-ignore
77
- if (!runId || runId !== event.runId || !toolName || toolName !== event.toolName) {
78
- ws.send(JSON.stringify({
79
- messageType: "openclaw_bot_chat",
80
- _userId: params?.userId,
81
- source: "client",
82
- content: {
83
- bot_token: params?.token,
84
- response: 'all_finished',
85
- session_id:params?.sessionId,
86
- message_id: params?.messageId || Date.now().toString()
87
- },
88
- }));
89
- }
90
- runId = event.runId;
91
- toolName = event.toolName;
92
- log?.(`dcgchat[${params?.sessionId}]:11111111 tool message to ${params?.sessionId}, ${JSON.stringify(event)}`);
93
140
  }
94
- });
95
141
  }