@dcrays/dcgchat-test 0.1.14 → 0.1.16
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/README.md +2 -2
- package/index.ts +3 -3
- package/openclaw.plugin.json +2 -2
- package/package.json +9 -9
- package/src/bot.ts +5 -5
- package/src/channel.ts +12 -17
- package/src/runtime.ts +1 -1
- package/src/skill.ts +1 -1
package/README.md
CHANGED
package/index.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { setDcgchatRuntime, setWorkspaceDir } from "./src/runtime.js";
|
|
|
5
5
|
import { monitoringToolMessage } from "./src/tool.js";
|
|
6
6
|
|
|
7
7
|
const plugin = {
|
|
8
|
-
id: "dcgchat",
|
|
9
|
-
name: "
|
|
10
|
-
description: "连接 OpenClaw 与
|
|
8
|
+
id: "dcgchat-test",
|
|
9
|
+
name: "书灵墨宝",
|
|
10
|
+
description: "连接 OpenClaw 与 书灵墨宝 产品(WebSocket)",
|
|
11
11
|
configSchema: emptyPluginConfigSchema(),
|
|
12
12
|
register(api: OpenClawPluginApi) {
|
|
13
13
|
setDcgchatRuntime(api.runtime);
|
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcrays/dcgchat-test",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "OpenClaw channel plugin for
|
|
5
|
+
"description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
|
|
6
6
|
"main": "index.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"keywords": [
|
|
14
14
|
"openclaw",
|
|
15
|
-
"dcgchat",
|
|
15
|
+
"dcgchat-test",
|
|
16
16
|
"websocket",
|
|
17
17
|
"ai"
|
|
18
18
|
],
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"typecheck": "tsc --noEmit"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"axios": "file:src/libs/axios-1.13.6.tgz",
|
|
23
24
|
"ws": "file:src/libs/ws-8.19.0.tgz",
|
|
24
25
|
"mime-types": "file:src/libs/mime-types-3.0.2.tgz",
|
|
25
26
|
"unzipper": "file:src/libs/unzipper-0.12.3.tgz"
|
|
@@ -29,13 +30,12 @@
|
|
|
29
30
|
"./index.ts"
|
|
30
31
|
],
|
|
31
32
|
"channel": {
|
|
32
|
-
"id": "dcgchat",
|
|
33
|
-
"label": "
|
|
34
|
-
"selectionLabel": "
|
|
33
|
+
"id": "dcgchat-test",
|
|
34
|
+
"label": "书灵墨宝",
|
|
35
|
+
"selectionLabel": "书灵墨宝",
|
|
35
36
|
"docsPath": "/channels/dcgchat",
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"blurb": "连接 OpenClaw 与 DCG Chat 产品",
|
|
37
|
+
"docsLabel": "dcgchat-test",
|
|
38
|
+
"blurb": "连接 OpenClaw 与 书灵墨宝 产品",
|
|
39
39
|
"order": 80
|
|
40
40
|
},
|
|
41
41
|
"install": {
|
package/src/bot.ts
CHANGED
|
@@ -102,7 +102,7 @@ export async function handleDcgchatMessage(params: {
|
|
|
102
102
|
|
|
103
103
|
const route = core.channel.routing.resolveAgentRoute({
|
|
104
104
|
cfg,
|
|
105
|
-
channel: "dcgchat",
|
|
105
|
+
channel: "dcgchat-test",
|
|
106
106
|
accountId: account.accountId,
|
|
107
107
|
peer: { kind: "direct", id: userId },
|
|
108
108
|
});
|
|
@@ -128,7 +128,7 @@ export async function handleDcgchatMessage(params: {
|
|
|
128
128
|
// const messageBody = `${userId}: ${text}`;
|
|
129
129
|
const messageBody = text;
|
|
130
130
|
const bodyFormatted = core.channel.reply.formatAgentEnvelope({
|
|
131
|
-
channel: "
|
|
131
|
+
channel: "书灵墨宝",
|
|
132
132
|
from: userId,
|
|
133
133
|
timestamp: new Date(),
|
|
134
134
|
envelope: envelopeOptions,
|
|
@@ -146,13 +146,13 @@ export async function handleDcgchatMessage(params: {
|
|
|
146
146
|
ChatType: "direct",
|
|
147
147
|
SenderName: userId,
|
|
148
148
|
SenderId: userId,
|
|
149
|
-
Provider: "dcgchat" as const,
|
|
150
|
-
Surface: "dcgchat" as const,
|
|
149
|
+
Provider: "dcgchat-test" as const,
|
|
150
|
+
Surface: "dcgchat-test" as const,
|
|
151
151
|
MessageSid: msg.content.message_id,
|
|
152
152
|
Timestamp: Date.now(),
|
|
153
153
|
WasMentioned: true,
|
|
154
154
|
CommandAuthorized: true,
|
|
155
|
-
OriginatingChannel: "dcgchat" as const,
|
|
155
|
+
OriginatingChannel: "dcgchat-test" as const,
|
|
156
156
|
OriginatingTo: `user:${userId}`,
|
|
157
157
|
...mediaPayload,
|
|
158
158
|
});
|
package/src/channel.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk";
|
|
|
6
6
|
import type { ResolvedDcgchatAccount, DcgchatConfig } from "./types.js";
|
|
7
7
|
import { logDcgchat } from "./log.js";
|
|
8
8
|
import { getWsConnection } from "./connection.js";
|
|
9
|
-
// import { ossUpload } from "./oss.js";
|
|
10
9
|
import { getMsgParams } from "./tool.js";
|
|
11
10
|
|
|
12
11
|
const uploadRoot = resolve('/', "upload");
|
|
@@ -20,17 +19,14 @@ async function ensureMediaInUploadDir(url: string): Promise<string> {
|
|
|
20
19
|
if (!url || /^([a-z][a-z\d+\-.]*):\/\//i.test(url) || !isAbsolute(url)) {
|
|
21
20
|
return url;
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
const sourcePath = resolve(url);
|
|
25
23
|
if (isPathInside(uploadRoot, sourcePath)) {
|
|
26
24
|
return sourcePath;
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
const fileName = basename(sourcePath);
|
|
30
27
|
if (!fileName) {
|
|
31
28
|
return sourcePath;
|
|
32
29
|
}
|
|
33
|
-
|
|
34
30
|
const targetPath = resolve(uploadRoot, fileName);
|
|
35
31
|
if (targetPath === sourcePath) {
|
|
36
32
|
return targetPath;
|
|
@@ -47,13 +43,12 @@ async function ensureMediaInUploadDir(url: string): Promise<string> {
|
|
|
47
43
|
await copyFile(sourcePath, targetPath);
|
|
48
44
|
await unlink(sourcePath);
|
|
49
45
|
}
|
|
50
|
-
|
|
51
46
|
return targetPath;
|
|
52
47
|
}
|
|
53
48
|
|
|
54
49
|
export function resolveAccount(cfg: OpenClawConfig, accountId?: string | null): ResolvedDcgchatAccount {
|
|
55
50
|
const id = accountId ?? DEFAULT_ACCOUNT_ID;
|
|
56
|
-
const raw = (cfg.channels?.["dcgchat"] as DcgchatConfig | undefined) ?? {};
|
|
51
|
+
const raw = (cfg.channels?.["dcgchat-test"] as DcgchatConfig | undefined) ?? {};
|
|
57
52
|
return {
|
|
58
53
|
accountId: id,
|
|
59
54
|
enabled: raw.enabled !== false,
|
|
@@ -67,14 +62,14 @@ export function resolveAccount(cfg: OpenClawConfig, accountId?: string | null):
|
|
|
67
62
|
}
|
|
68
63
|
|
|
69
64
|
export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
70
|
-
id: "dcgchat",
|
|
65
|
+
id: "dcgchat-test",
|
|
71
66
|
meta: {
|
|
72
|
-
id: "dcgchat",
|
|
73
|
-
label: "
|
|
74
|
-
selectionLabel: "
|
|
67
|
+
id: "dcgchat-test",
|
|
68
|
+
label: "书灵墨宝",
|
|
69
|
+
selectionLabel: "书灵墨宝",
|
|
75
70
|
docsPath: "/channels/dcgchat",
|
|
76
|
-
docsLabel: "dcgchat",
|
|
77
|
-
blurb: "连接 OpenClaw 与
|
|
71
|
+
docsLabel: "dcgchat-test",
|
|
72
|
+
blurb: "连接 OpenClaw 与 书灵墨宝 产品",
|
|
78
73
|
order: 80,
|
|
79
74
|
},
|
|
80
75
|
capabilities: {
|
|
@@ -113,8 +108,8 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
113
108
|
...cfg,
|
|
114
109
|
channels: {
|
|
115
110
|
...cfg.channels,
|
|
116
|
-
"dcgchat": {
|
|
117
|
-
...(cfg.channels?.["dcgchat"] as Record<string, unknown> | undefined),
|
|
111
|
+
"dcgchat-test": {
|
|
112
|
+
...(cfg.channels?.["dcgchat-test"] as Record<string, unknown> | undefined),
|
|
118
113
|
enabled,
|
|
119
114
|
},
|
|
120
115
|
},
|
|
@@ -164,7 +159,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
164
159
|
logDcgchat.warn(`[dcgchat][${ctx.accountId ?? DEFAULT_ACCOUNT_ID}] outbound -> ${ws?.readyState}: ${ctx.text}`);
|
|
165
160
|
}
|
|
166
161
|
return {
|
|
167
|
-
channel: "dcgchat",
|
|
162
|
+
channel: "dcgchat-test",
|
|
168
163
|
messageId: `dcg-${Date.now()}`,
|
|
169
164
|
chatId: params.userId.toString(),
|
|
170
165
|
};
|
|
@@ -177,7 +172,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
177
172
|
const {botToken} = resolveAccount(ctx.cfg, ctx.accountId);
|
|
178
173
|
|
|
179
174
|
// try {
|
|
180
|
-
const url = ctx.mediaUrl;
|
|
175
|
+
const url = await ensureMediaInUploadDir(ctx.mediaUrl ?? '');
|
|
181
176
|
const fileName = url?.split(/[\\/]/).pop() || ''
|
|
182
177
|
const content = {
|
|
183
178
|
messageType: "openclaw_bot_chat",
|
|
@@ -215,7 +210,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
215
210
|
logDcgchat.warn(`[dcgchat][${ctx.accountId ?? DEFAULT_ACCOUNT_ID}] outbound -> ${ws?.readyState}: ${ctx.text}`);
|
|
216
211
|
}
|
|
217
212
|
return {
|
|
218
|
-
channel: "dcgchat",
|
|
213
|
+
channel: "dcgchat-test",
|
|
219
214
|
messageId: `dcg-${Date.now()}`,
|
|
220
215
|
chatId: params.userId.toString(),
|
|
221
216
|
};
|
package/src/runtime.ts
CHANGED
|
@@ -34,7 +34,7 @@ export function setDcgchatRuntime(next: PluginRuntime) {
|
|
|
34
34
|
|
|
35
35
|
export function getDcgchatRuntime(): PluginRuntime {
|
|
36
36
|
if (!runtime) {
|
|
37
|
-
throw new Error("
|
|
37
|
+
throw new Error("书灵墨宝 runtime not initialized");
|
|
38
38
|
}
|
|
39
39
|
return runtime;
|
|
40
40
|
}
|
package/src/skill.ts
CHANGED
|
@@ -116,7 +116,7 @@ export async function installSkill(params: ISkillParams, msgContent: Record<stri
|
|
|
116
116
|
reject(err);
|
|
117
117
|
}
|
|
118
118
|
})
|
|
119
|
-
.on("error", (err) => {
|
|
119
|
+
.on("error", (err: { message: any; }) => {
|
|
120
120
|
hasError = true;
|
|
121
121
|
reject(new Error(`解压流错误: ${err.message}`));
|
|
122
122
|
});
|