@dcrays/dcgchat-test 0.2.16 → 0.2.17
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/index.ts +2 -2
- package/package.json +1 -1
- package/src/bot.ts +1 -5
- package/src/monitor.ts +1 -1
- package/src/skill.ts +2 -84
package/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
|
2
2
|
import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
|
|
3
3
|
import { dcgchatPlugin } from "./src/channel.js";
|
|
4
4
|
import { setDcgchatRuntime, setWorkspaceDir } from "./src/runtime.js";
|
|
5
|
-
import { monitoringToolMessage } from "./src/tool.js";
|
|
5
|
+
// import { monitoringToolMessage } from "./src/tool.js";
|
|
6
6
|
|
|
7
7
|
const plugin = {
|
|
8
8
|
id: "dcgchat-test",
|
|
@@ -11,7 +11,7 @@ const plugin = {
|
|
|
11
11
|
configSchema: emptyPluginConfigSchema(),
|
|
12
12
|
register(api: OpenClawPluginApi) {
|
|
13
13
|
setDcgchatRuntime(api.runtime);
|
|
14
|
-
monitoringToolMessage(api);
|
|
14
|
+
// monitoringToolMessage(api);
|
|
15
15
|
api.registerChannel({ plugin: dcgchatPlugin });
|
|
16
16
|
api.registerTool((ctx) => {
|
|
17
17
|
const workspaceDir = ctx.workspaceDir;
|
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -367,7 +367,7 @@ export async function handleDcgchatMessage(params: {
|
|
|
367
367
|
log(`dcgchat[${accountId}]: ctxPayload=${JSON.stringify(ctxPayload)}`);
|
|
368
368
|
|
|
369
369
|
const sentMediaKeys = new Set<string>()
|
|
370
|
-
const getMediaKey = (url: string) => url.split(/[\\/]/).
|
|
370
|
+
const getMediaKey = (url: string) => url.split(/[\\/]/).pop() ?? url
|
|
371
371
|
let textChunk = ''
|
|
372
372
|
|
|
373
373
|
const prefixContext = createReplyPrefixContext({ cfg, agentId: route.agentId });
|
|
@@ -418,10 +418,6 @@ export async function handleDcgchatMessage(params: {
|
|
|
418
418
|
const mediaUrl = mediaList[i];
|
|
419
419
|
const key = getMediaKey(mediaUrl);
|
|
420
420
|
if (sentMediaKeys.has(key)) continue;
|
|
421
|
-
if (!/^https?:\/\//i.test(mediaUrl) && !fs.existsSync(mediaUrl)) {
|
|
422
|
-
log(`dcgchat[${accountId}][deliver]: media file not found, skipping: ${mediaUrl}`);
|
|
423
|
-
continue;
|
|
424
|
-
}
|
|
425
421
|
sentMediaKeys.add(key);
|
|
426
422
|
await sendDcgchatMedia({
|
|
427
423
|
cfg,
|
package/src/monitor.ts
CHANGED
|
@@ -140,7 +140,7 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
|
|
|
140
140
|
const content = { event_type, operation_type, skill_url, skill_code, skill_id, bot_token, websocket_trace_id };
|
|
141
141
|
if (event_type === "skill") {
|
|
142
142
|
if (operation_type === "install" || operation_type === "enable" || operation_type === "update") {
|
|
143
|
-
installSkill({ path: skill_url, code: skill_code }, content
|
|
143
|
+
installSkill({ path: skill_url, code: skill_code }, content);
|
|
144
144
|
} else if (operation_type === "remove" || operation_type === "disable") {
|
|
145
145
|
uninstallSkill({ code: skill_code }, content);
|
|
146
146
|
} else {
|
package/src/skill.ts
CHANGED
|
@@ -5,24 +5,15 @@ import unzipper from 'unzipper';
|
|
|
5
5
|
import { pipeline } from "stream/promises";
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import path from 'path';
|
|
8
|
-
import type { ClawdbotConfig, RuntimeEnv } from "openclaw/plugin-sdk";
|
|
9
8
|
import { logDcgchat } from './log.js';
|
|
10
|
-
import {
|
|
9
|
+
import { getWorkspaceDir } from './runtime.js';
|
|
11
10
|
import { getWsConnection } from './connection.js';
|
|
12
|
-
import { resolveAccount } from './channel.js';
|
|
13
|
-
import { getMsgParams } from './tool.js';
|
|
14
11
|
|
|
15
12
|
type ISkillParams = {
|
|
16
13
|
path: string;
|
|
17
14
|
code: string;
|
|
18
15
|
}
|
|
19
16
|
|
|
20
|
-
type SkillContext = {
|
|
21
|
-
cfg: ClawdbotConfig;
|
|
22
|
-
accountId: string;
|
|
23
|
-
runtime?: RuntimeEnv;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
17
|
function sendEvent(msgContent: Record<string, any>) {
|
|
27
18
|
const ws = getWsConnection()
|
|
28
19
|
if (ws?.readyState === WebSocket.OPEN) {
|
|
@@ -36,77 +27,7 @@ function sendEvent(msgContent: Record<string, any>) {
|
|
|
36
27
|
}
|
|
37
28
|
}
|
|
38
29
|
|
|
39
|
-
async function
|
|
40
|
-
try {
|
|
41
|
-
const core = getDcgchatRuntime();
|
|
42
|
-
const log = ctx.runtime?.log ?? console.log;
|
|
43
|
-
const params = getMsgParams();
|
|
44
|
-
const account = resolveAccount(ctx.cfg, ctx.accountId);
|
|
45
|
-
const userId = String(params.userId);
|
|
46
|
-
|
|
47
|
-
const route = core.channel.routing.resolveAgentRoute({
|
|
48
|
-
cfg: ctx.cfg,
|
|
49
|
-
channel: "dcgchat-test",
|
|
50
|
-
accountId: account.accountId,
|
|
51
|
-
peer: { kind: "direct", id: userId },
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(ctx.cfg);
|
|
55
|
-
const bodyFormatted = core.channel.reply.formatAgentEnvelope({
|
|
56
|
-
channel: "书灵墨宝",
|
|
57
|
-
from: userId,
|
|
58
|
-
timestamp: new Date(),
|
|
59
|
-
envelope: envelopeOptions,
|
|
60
|
-
body: "/new",
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const ctxPayload = core.channel.reply.finalizeInboundContext({
|
|
64
|
-
Body: bodyFormatted,
|
|
65
|
-
RawBody: "/new",
|
|
66
|
-
CommandBody: "/new",
|
|
67
|
-
From: userId,
|
|
68
|
-
To: userId,
|
|
69
|
-
SessionKey: route.sessionKey,
|
|
70
|
-
AccountId: params.sessionId,
|
|
71
|
-
ChatType: "direct",
|
|
72
|
-
SenderName: userId,
|
|
73
|
-
SenderId: userId,
|
|
74
|
-
Provider: "dcgchat-test" as const,
|
|
75
|
-
Surface: "dcgchat-test" as const,
|
|
76
|
-
MessageSid: Date.now().toString(),
|
|
77
|
-
Timestamp: Date.now(),
|
|
78
|
-
WasMentioned: true,
|
|
79
|
-
CommandAuthorized: true,
|
|
80
|
-
OriginatingChannel: "dcgchat-test" as const,
|
|
81
|
-
OriginatingTo: `user:${userId}`,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const noopDispatcher = {
|
|
85
|
-
sendToolResult: () => false,
|
|
86
|
-
sendBlockReply: () => false,
|
|
87
|
-
sendFinalReply: () => false,
|
|
88
|
-
waitForIdle: async () => {},
|
|
89
|
-
getQueuedCounts: () => ({ tool: 0, block: 0, final: 0 }),
|
|
90
|
-
markComplete: () => {},
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
await core.channel.reply.withReplyDispatcher({
|
|
94
|
-
dispatcher: noopDispatcher,
|
|
95
|
-
run: () =>
|
|
96
|
-
core.channel.reply.dispatchReplyFromConfig({
|
|
97
|
-
ctx: ctxPayload,
|
|
98
|
-
cfg: ctx.cfg,
|
|
99
|
-
dispatcher: noopDispatcher,
|
|
100
|
-
}),
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
log(`dcgchat: /new command dispatched silently after skill install`);
|
|
104
|
-
} catch (err) {
|
|
105
|
-
logDcgchat.error(`sendNewSessionCommand failed: ${err}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export async function installSkill(params: ISkillParams, msgContent: Record<string, any>, ctx?: SkillContext) {
|
|
30
|
+
export async function installSkill(params: ISkillParams, msgContent: Record<string, any>) {
|
|
110
31
|
const { path: cdnUrl, code } = params;
|
|
111
32
|
const workspacePath = getWorkspaceDir();
|
|
112
33
|
|
|
@@ -208,9 +129,6 @@ export async function installSkill(params: ISkillParams, msgContent: Record<stri
|
|
|
208
129
|
});
|
|
209
130
|
});
|
|
210
131
|
sendEvent({ ...msgContent, status: 'ok' })
|
|
211
|
-
if (ctx) {
|
|
212
|
-
await sendNewSessionCommand(ctx);
|
|
213
|
-
}
|
|
214
132
|
} catch (error) {
|
|
215
133
|
// 如果安装失败,清理目录
|
|
216
134
|
if (fs.existsSync(skillDir)) {
|