@dcrays/dcgchat-test 0.1.15 → 0.1.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/README.md +2 -2
- package/index.ts +3 -3
- package/openclaw.plugin.json +2 -2
- package/package.json +9 -9
- package/src/bot.ts +11 -9
- package/src/channel.ts +14 -14
- 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.17",
|
|
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
|
@@ -8,7 +8,7 @@ import { resolveAccount } from "./channel.js";
|
|
|
8
8
|
import { setMsgStatus } from "./tool.js";
|
|
9
9
|
import mime from "mime-types"
|
|
10
10
|
|
|
11
|
-
const targetPath = path.join(os.homedir()
|
|
11
|
+
const targetPath = path.join(os.homedir());
|
|
12
12
|
|
|
13
13
|
type MediaInfo = {
|
|
14
14
|
path: string;
|
|
@@ -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
|
});
|
|
@@ -126,19 +126,21 @@ export async function handleDcgchatMessage(params: {
|
|
|
126
126
|
|
|
127
127
|
const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(cfg);
|
|
128
128
|
// const messageBody = `${userId}: ${text}`;
|
|
129
|
+
// 补充消息
|
|
130
|
+
const supplementMessage = `\n<br/> 如果有文件生成,直接将文件生成到 ${targetPath}/upload 目录下,并将文件发送给我,如果没有生成文件请忽略`;
|
|
129
131
|
const messageBody = text;
|
|
130
132
|
const bodyFormatted = core.channel.reply.formatAgentEnvelope({
|
|
131
|
-
channel: "
|
|
133
|
+
channel: "书灵墨宝",
|
|
132
134
|
from: userId,
|
|
133
135
|
timestamp: new Date(),
|
|
134
136
|
envelope: envelopeOptions,
|
|
135
|
-
body: messageBody,
|
|
137
|
+
body: messageBody + supplementMessage,
|
|
136
138
|
});
|
|
137
139
|
|
|
138
140
|
const ctxPayload = core.channel.reply.finalizeInboundContext({
|
|
139
141
|
Body: bodyFormatted,
|
|
140
|
-
RawBody: text,
|
|
141
|
-
CommandBody: text,
|
|
142
|
+
RawBody: text + supplementMessage,
|
|
143
|
+
CommandBody: text + supplementMessage,
|
|
142
144
|
From: userId,
|
|
143
145
|
To: userId,
|
|
144
146
|
SessionKey: route.sessionKey,
|
|
@@ -146,13 +148,13 @@ export async function handleDcgchatMessage(params: {
|
|
|
146
148
|
ChatType: "direct",
|
|
147
149
|
SenderName: userId,
|
|
148
150
|
SenderId: userId,
|
|
149
|
-
Provider: "dcgchat" as const,
|
|
150
|
-
Surface: "dcgchat" as const,
|
|
151
|
+
Provider: "dcgchat-test" as const,
|
|
152
|
+
Surface: "dcgchat-test" as const,
|
|
151
153
|
MessageSid: msg.content.message_id,
|
|
152
154
|
Timestamp: Date.now(),
|
|
153
155
|
WasMentioned: true,
|
|
154
156
|
CommandAuthorized: true,
|
|
155
|
-
OriginatingChannel: "dcgchat" as const,
|
|
157
|
+
OriginatingChannel: "dcgchat-test" as const,
|
|
156
158
|
OriginatingTo: `user:${userId}`,
|
|
157
159
|
...mediaPayload,
|
|
158
160
|
});
|
package/src/channel.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { copyFile, mkdir, rename, unlink } from "node:fs/promises";
|
|
2
2
|
import { basename, dirname, isAbsolute, relative, resolve } from "node:path";
|
|
3
|
-
import
|
|
3
|
+
import os from "node:os";
|
|
4
4
|
import type { ChannelPlugin, OpenClawConfig } from "openclaw/plugin-sdk";
|
|
5
5
|
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
|
-
const uploadRoot = resolve(
|
|
11
|
+
const uploadRoot = resolve(os.homedir(), "upload");
|
|
12
|
+
logDcgchat.info(`uploadRoot: ${uploadRoot}`);
|
|
13
13
|
|
|
14
14
|
function isPathInside(parentPath: string, targetPath: string): boolean {
|
|
15
15
|
const relativePath = relative(parentPath, targetPath);
|
|
@@ -49,7 +49,7 @@ async function ensureMediaInUploadDir(url: string): Promise<string> {
|
|
|
49
49
|
|
|
50
50
|
export function resolveAccount(cfg: OpenClawConfig, accountId?: string | null): ResolvedDcgchatAccount {
|
|
51
51
|
const id = accountId ?? DEFAULT_ACCOUNT_ID;
|
|
52
|
-
const raw = (cfg.channels?.["dcgchat"] as DcgchatConfig | undefined) ?? {};
|
|
52
|
+
const raw = (cfg.channels?.["dcgchat-test"] as DcgchatConfig | undefined) ?? {};
|
|
53
53
|
return {
|
|
54
54
|
accountId: id,
|
|
55
55
|
enabled: raw.enabled !== false,
|
|
@@ -63,14 +63,14 @@ export function resolveAccount(cfg: OpenClawConfig, accountId?: string | null):
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
66
|
-
id: "dcgchat",
|
|
66
|
+
id: "dcgchat-test",
|
|
67
67
|
meta: {
|
|
68
|
-
id: "dcgchat",
|
|
69
|
-
label: "
|
|
70
|
-
selectionLabel: "
|
|
68
|
+
id: "dcgchat-test",
|
|
69
|
+
label: "书灵墨宝",
|
|
70
|
+
selectionLabel: "书灵墨宝",
|
|
71
71
|
docsPath: "/channels/dcgchat",
|
|
72
|
-
docsLabel: "dcgchat",
|
|
73
|
-
blurb: "连接 OpenClaw 与
|
|
72
|
+
docsLabel: "dcgchat-test",
|
|
73
|
+
blurb: "连接 OpenClaw 与 书灵墨宝 产品",
|
|
74
74
|
order: 80,
|
|
75
75
|
},
|
|
76
76
|
capabilities: {
|
|
@@ -109,8 +109,8 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
109
109
|
...cfg,
|
|
110
110
|
channels: {
|
|
111
111
|
...cfg.channels,
|
|
112
|
-
"dcgchat": {
|
|
113
|
-
...(cfg.channels?.["dcgchat"] as Record<string, unknown> | undefined),
|
|
112
|
+
"dcgchat-test": {
|
|
113
|
+
...(cfg.channels?.["dcgchat-test"] as Record<string, unknown> | undefined),
|
|
114
114
|
enabled,
|
|
115
115
|
},
|
|
116
116
|
},
|
|
@@ -160,7 +160,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
160
160
|
logDcgchat.warn(`[dcgchat][${ctx.accountId ?? DEFAULT_ACCOUNT_ID}] outbound -> ${ws?.readyState}: ${ctx.text}`);
|
|
161
161
|
}
|
|
162
162
|
return {
|
|
163
|
-
channel: "dcgchat",
|
|
163
|
+
channel: "dcgchat-test",
|
|
164
164
|
messageId: `dcg-${Date.now()}`,
|
|
165
165
|
chatId: params.userId.toString(),
|
|
166
166
|
};
|
|
@@ -211,7 +211,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
|
|
|
211
211
|
logDcgchat.warn(`[dcgchat][${ctx.accountId ?? DEFAULT_ACCOUNT_ID}] outbound -> ${ws?.readyState}: ${ctx.text}`);
|
|
212
212
|
}
|
|
213
213
|
return {
|
|
214
|
-
channel: "dcgchat",
|
|
214
|
+
channel: "dcgchat-test",
|
|
215
215
|
messageId: `dcg-${Date.now()}`,
|
|
216
216
|
chatId: params.userId.toString(),
|
|
217
217
|
};
|
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
|
});
|