@dcrays/dcgchat-test 0.2.20 → 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 +1 -1
- package/src/monitor.ts +7 -2
- package/src/tool.ts +105 -63
package/package.json
CHANGED
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
|
|
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
|
-
|
|
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
|
@@ -30,70 +30,112 @@ export function getMsgStatus() {
|
|
|
30
30
|
}
|
|
31
31
|
let toolCallId = '';
|
|
32
32
|
let toolName = '';
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
}
|
|
38
107
|
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
108
|
+
export function monitoringToolMessage(api: OpenClawPluginApi) {
|
|
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
|
+
// }
|
|
61
139
|
});
|
|
62
|
-
ws.send(JSON.stringify({
|
|
63
|
-
messageType: "openclaw_bot_chat",
|
|
64
|
-
_userId: params?.userId,
|
|
65
|
-
source: "client",
|
|
66
|
-
content: {
|
|
67
|
-
bot_token: params?.token,
|
|
68
|
-
domain_id: params?.domainId,
|
|
69
|
-
app_id: params?.appId,
|
|
70
|
-
bot_id: params?.botId,
|
|
71
|
-
agent_id: params?.agentId,
|
|
72
|
-
thinking_content: text,
|
|
73
|
-
response: '',
|
|
74
|
-
session_id:params?.sessionId,
|
|
75
|
-
message_id: params?.messageId || Date.now().toString()
|
|
76
|
-
},
|
|
77
|
-
}));
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
if (!toolCallId || toolCallId !== event.toolCallId || !toolName || toolName !== event.toolName) {
|
|
80
|
-
ws.send(JSON.stringify({
|
|
81
|
-
messageType: "openclaw_bot_chat",
|
|
82
|
-
_userId: params?.userId,
|
|
83
|
-
source: "client",
|
|
84
|
-
content: {
|
|
85
|
-
bot_token: params?.token,
|
|
86
|
-
response: 'all_finished',
|
|
87
|
-
session_id:params?.sessionId,
|
|
88
|
-
message_id: params?.messageId || Date.now().toString()
|
|
89
|
-
},
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
toolCallId = event.toolCallId;
|
|
93
|
-
toolName = event.toolName;
|
|
94
|
-
log?.(`dcgchat[${params?.sessionId}]:11111111 tool message to ${params?.sessionId}, ${JSON.stringify(rest)}`);
|
|
95
|
-
} else {
|
|
96
|
-
log?.(`dcgchat[${params?.sessionId}]:22222222 tool ${status} message to ${ws?.readyState}, ${JSON.stringify(rest)}`);
|
|
97
140
|
}
|
|
98
|
-
});
|
|
99
141
|
}
|