@dcrays/dcgchat-test 0.3.15 → 0.3.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/index.ts CHANGED
@@ -3,12 +3,11 @@ import { emptyPluginConfigSchema } from 'openclaw/plugin-sdk'
3
3
  import { dcgchatPlugin } from './src/channel.js'
4
4
  import { setDcgchatRuntime, setWorkspaceDir } from './src/utils/global.js'
5
5
  import { monitoringToolMessage } from './src/tool.js'
6
- import { channelInfo, ENV } from './src/utils/constant.js'
7
6
  import { setOpenClawConfig } from './src/utils/global.js'
8
7
  import { startDcgchatGatewaySocket } from './src/gateway/socket.js'
9
8
 
10
9
  const plugin = {
11
- id: channelInfo[ENV],
10
+ id: "dcgchat-test",
12
11
  name: '书灵墨宝',
13
12
  description: '连接 OpenClaw 与 书灵墨宝 产品(WebSocket)',
14
13
  configSchema: emptyPluginConfigSchema(),
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "id": "dcgchat-test",
3
- "channels": ["dcgchat-test"],
3
+ "channels": [
4
+ "dcgchat-test"
5
+ ],
4
6
  "configSchema": {
5
7
  "type": "object",
6
8
  "additionalProperties": false,
7
9
  "properties": {}
8
10
  }
9
- }
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcrays/dcgchat-test",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
@@ -16,12 +16,6 @@
16
16
  "websocket",
17
17
  "ai"
18
18
  ],
19
- "scripts": {
20
- "typecheck": "tsc --noEmit",
21
- "build:production": "npx tsx scripts/build.ts production",
22
- "build:prod": "npx tsx scripts/build.ts production",
23
- "build:test": "npx tsx scripts/build.ts test"
24
- },
25
19
  "dependencies": {
26
20
  "ali-oss": "file:src/libs/ali-oss-6.23.0.tgz",
27
21
  "axios": "file:src/libs/axios-1.13.6.tgz",
@@ -37,18 +31,15 @@
37
31
  "id": "dcgchat-test",
38
32
  "label": "书灵墨宝",
39
33
  "selectionLabel": "书灵墨宝",
40
- "docsPath": "/channels/dcgchat",
34
+ "docsPath": "/channels/dcgchat-test",
41
35
  "docsLabel": "dcgchat-test",
42
36
  "blurb": "连接 OpenClaw 与 书灵墨宝 产品",
43
37
  "order": 80
44
38
  },
45
39
  "install": {
46
40
  "npmSpec": "@dcrays/dcgchat-test",
47
- "localPath": "extensions/dcgchat",
41
+ "localPath": "extensions/dcgchat-test",
48
42
  "defaultChoice": "npm"
49
43
  }
50
- },
51
- "devDependencies": {
52
- "openclaw": "^2026.3.13"
53
44
  }
54
45
  }
package/src/bot.ts CHANGED
@@ -3,6 +3,7 @@ import path from 'node:path'
3
3
  import type { ReplyPayload } from 'openclaw/plugin-sdk'
4
4
  import { createReplyPrefixContext } from 'openclaw/plugin-sdk'
5
5
  import type { InboundMessage } from './types.js'
6
+ import os from 'node:os'
6
7
  import {
7
8
  clearSentMediaKeys,
8
9
  getDcgchatRuntime,
@@ -155,7 +156,7 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
155
156
 
156
157
  const route = core.channel.routing.resolveAgentRoute({
157
158
  cfg: config,
158
- channel: channelInfo[ENV],
159
+ channel: "dcgchat-test",
159
160
  accountId: account.accountId,
160
161
  peer: { kind: 'direct', id: conversationId }
161
162
  })
@@ -234,13 +235,13 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
234
235
  ChatType: 'direct',
235
236
  SenderName: agentDisplayName,
236
237
  SenderId: userId,
237
- Provider: channelInfo[ENV],
238
- Surface: channelInfo[ENV],
238
+ Provider: "dcgchat-test",
239
+ Surface: "dcgchat-test",
239
240
  MessageSid: msg.content.message_id,
240
241
  Timestamp: Date.now(),
241
242
  WasMentioned: true,
242
243
  CommandAuthorized: true,
243
- OriginatingChannel: channelInfo[ENV],
244
+ OriginatingChannel: "dcgchat-test",
244
245
  OriginatingTo: effectiveSessionKey,
245
246
  ...mediaPayload
246
247
  })
@@ -252,7 +253,7 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
252
253
  const prefixContext = createReplyPrefixContext({
253
254
  cfg: config,
254
255
  agentId: effectiveAgentId ?? '',
255
- channel: channelInfo[ENV],
256
+ channel: "dcgchat-test",
256
257
  accountId: account.accountId
257
258
  })
258
259
 
@@ -414,10 +415,12 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
414
415
  const candidates: string[] = [file]
415
416
  candidates.push(path.join(getWorkspaceDir(), file))
416
417
  candidates.push(path.join(getWorkspaceDir(), file.replace(/^\//, '')))
417
- if (process.platform === 'win32') {
418
- const underMobook = file.replace(/^\/mobook\//i, '').replace(/^mobook[\\/]/i, '')
419
- if (underMobook) {
418
+ const underMobook = file.replace(/^\/mobook\//i, '').replace(/^mobook[\\/]/i, '')
419
+ if (underMobook) {
420
+ if (process.platform === 'win32') {
420
421
  candidates.push(path.join('C:\\', 'mobook', underMobook))
422
+ } else if (process.platform === 'darwin') {
423
+ candidates.push(path.join(os.homedir(), 'mobook', underMobook))
421
424
  }
422
425
  }
423
426
  const resolved = candidates.find((p) => fs.existsSync(p))
package/src/channel.ts CHANGED
@@ -5,7 +5,6 @@ import { ossUpload } from './request/oss.js'
5
5
  import { addSentMediaKey, getCronMessageId, getOpenClawConfig, hasSentMediaKey } from './utils/global.js'
6
6
  import { isWsOpen, mergeDefaultParams, mergeSessionParams, sendFinal, wsSendRaw } from './transport.js'
7
7
  import { dcgLogger, setLogger } from './utils/log.js'
8
- import { channelInfo, ENV } from './utils/constant.js'
9
8
  import { getEffectiveMsgParams, getCurrentSessionKey } from './utils/params.js'
10
9
  import { startDcgchatGatewaySocket } from './gateway/socket.js'
11
10
 
@@ -36,7 +35,7 @@ export async function sendDcgchatMedia(opts: DcgchatMediaSendOptions): Promise<v
36
35
  const fileName = mediaUrl?.split(/[\\/]/).pop() || ''
37
36
 
38
37
  try {
39
- const botToken = msgCtx.botToken ?? getOpenClawConfig()?.channels?.[channelInfo[ENV]]?.botToken ?? ''
38
+ const botToken = msgCtx.botToken ?? getOpenClawConfig()?.channels?.["dcgchat-test"]?.botToken ?? ''
40
39
  const url = opts.mediaUrl ? await ossUpload(opts.mediaUrl, botToken, 1) : ''
41
40
  wsSendRaw(msgCtx, {
42
41
  response: opts.text ?? '',
@@ -54,7 +53,7 @@ export async function sendDcgchatMedia(opts: DcgchatMediaSendOptions): Promise<v
54
53
 
55
54
  export function resolveAccount(cfg: OpenClawConfig, accountId?: string | null): ResolvedDcgchatAccount {
56
55
  const id = accountId ?? DEFAULT_ACCOUNT_ID
57
- const raw = (cfg.channels?.[channelInfo[ENV]] as DcgchatConfig | undefined) ?? {}
56
+ const raw = (cfg.channels?.["dcgchat-test"] as DcgchatConfig | undefined) ?? {}
58
57
  return {
59
58
  accountId: id,
60
59
  enabled: raw.enabled !== false,
@@ -68,13 +67,13 @@ export function resolveAccount(cfg: OpenClawConfig, accountId?: string | null):
68
67
  }
69
68
 
70
69
  export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
71
- id: channelInfo[ENV],
70
+ id: "dcgchat-test",
72
71
  meta: {
73
- id: channelInfo[ENV],
72
+ id: "dcgchat-test",
74
73
  label: '书灵墨宝',
75
74
  selectionLabel: '书灵墨宝',
76
75
  docsPath: '/channels/dcgchat',
77
- docsLabel: channelInfo[ENV],
76
+ docsLabel: "dcgchat-test",
78
77
  blurb: '连接 OpenClaw 与 书灵墨宝 产品',
79
78
  order: 80
80
79
  },
@@ -115,7 +114,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
115
114
  channels: {
116
115
  ...cfg.channels,
117
116
  dcgchat: {
118
- ...(cfg.channels?.[channelInfo[ENV]] as Record<string, unknown> | undefined),
117
+ ...(cfg.channels?.["dcgchat-test"] as Record<string, unknown> | undefined),
119
118
  enabled
120
119
  }
121
120
  }
@@ -179,7 +178,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
179
178
  }
180
179
  }
181
180
  return {
182
- channel: channelInfo[ENV],
181
+ channel: "dcgchat-test",
183
182
  messageId: `dcg-${Date.now()}`,
184
183
  chatId: ctx.to
185
184
  }
@@ -189,7 +188,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
189
188
  dcgLogger(`channel sendMedia to ${ctx.to} ${ctx.mediaUrl?.slice(0, 50)}`)
190
189
  await sendDcgchatMedia({ sessionKey: ctx.to ?? '', mediaUrl: ctx.mediaUrl ?? '' })
191
190
  return {
192
- channel: channelInfo[ENV],
191
+ channel: "dcgchat-test",
193
192
  messageId: `dcg-${Date.now()}`,
194
193
  chatId: msgCtx.userId?.toString()
195
194
  }
@@ -127,7 +127,7 @@ function injectBestEffort(params: Record<string, unknown>, sk: string): Record<s
127
127
  ;(newParams.delivery as CronDelivery).bestEffort = true
128
128
  ;(newParams.delivery as CronDelivery).to = sessionId
129
129
  ;(newParams.delivery as CronDelivery).accountId = agentId
130
- ;(newParams.delivery as CronDelivery).channel = channelInfo[ENV]
130
+ ;(newParams.delivery as CronDelivery).channel = "dcgchat-test"
131
131
  newParams.sessionKey = sk
132
132
  return newParams
133
133
  }
@@ -138,7 +138,7 @@ function injectBestEffort(params: Record<string, unknown>, sk: string): Record<s
138
138
  ;(job.delivery as CronDelivery).bestEffort = true
139
139
  ;(newParams.delivery as CronDelivery).to = sessionId
140
140
  ;(newParams.delivery as CronDelivery).accountId = agentId
141
- ;(newParams.delivery as CronDelivery).channel = channelInfo[ENV]
141
+ ;(newParams.delivery as CronDelivery).channel = "dcgchat-test"
142
142
  newParams.sessionKey = sk
143
143
  return newParams
144
144
  }
@@ -176,7 +176,7 @@ export function cronToolCall(event: { toolName: any; params: any; toolCallId: an
176
176
  if (params.command.indexOf('cron create') > -1 || params.command.indexOf('cron add') > -1) {
177
177
  const newParams = JSON.parse(JSON.stringify(params)) as Record<string, unknown>
178
178
  newParams.command =
179
- params.command.replace('--json', '') + ` --session-key ${sk} --channel ${channelInfo[ENV]} --to ${sk} --json`
179
+ params.command.replace('--json', '') + ` --session-key ${sk} --channel ${"dcgchat-test"} --to ${sk} --json`
180
180
  return { params: newParams }
181
181
  } else {
182
182
  return params
@@ -1,9 +1,5 @@
1
1
  export const ENV: 'production' | 'test' | 'develop' = 'test'
2
2
 
3
- export const channelInfo: Record<string, string> = {
4
- production: 'dcgchat',
5
- test: 'dcgchat-test'
6
- }
7
3
 
8
4
  export const systemCommand = ['/new', '/status']
9
5
  export const interruptCommand = ['chat.stop']
@@ -33,7 +33,7 @@ const os = require('os')
33
33
  function getWorkspacePath() {
34
34
  const workspacePath = path.join(
35
35
  os.homedir(),
36
- config?.channels?.[channelInfo[ENV]]?.appId == 110 ? '.mobook' : '.openclaw',
36
+ config?.channels?.["dcgchat-test"]?.appId == 110 ? '.mobook' : '.openclaw',
37
37
  'workspace'
38
38
  )
39
39
  if (fs.existsSync(workspacePath)) {
@@ -123,7 +123,7 @@ export const getSessionKey = (content: any, accountId: string) => {
123
123
 
124
124
  const route = core.channel.routing.resolveAgentRoute({
125
125
  cfg: getOpenClawConfig() as OpenClawConfig,
126
- channel: channelInfo[ENV],
126
+ channel: "dcgchat-test",
127
127
  accountId: accountId || 'default',
128
128
  peer: { kind: 'direct', id: session_id }
129
129
  })
package/src/utils/log.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { RuntimeEnv } from 'openclaw/plugin-sdk'
2
- import { channelInfo, ENV } from './constant.js'
3
2
 
4
3
  let logger: RuntimeEnv | null = null
5
4
 
@@ -11,6 +10,6 @@ export function dcgLogger(message: string, type: 'log' | 'error' = 'log'): void
11
10
  if (logger) {
12
11
  logger[type](`书灵墨宝🚀 ~ [${new Date().toISOString()}] ${message}`)
13
12
  } else {
14
- console[type](`书灵墨宝🚀 ~ ${new Date().toISOString()} [${channelInfo[ENV]}]: ${message}`)
13
+ console[type](`书灵墨宝🚀 ~ ${new Date().toISOString()} [${"dcgchat-test"}]: ${message}`)
15
14
  }
16
15
  }
@@ -12,7 +12,7 @@ let currentSessionKey: string | null = null
12
12
 
13
13
  /** 从 OpenClaw 配置读取当前 channel 的基础参数(唯一来源,供 transport / resolve 等复用) */
14
14
  export function getParamsDefaults(): IMsgParams {
15
- const ch = (getOpenClawConfig()?.channels?.[channelInfo[ENV]] as DcgchatConfig | undefined) ?? {}
15
+ const ch = (getOpenClawConfig()?.channels?.["dcgchat-test"] as DcgchatConfig | undefined) ?? {}
16
16
  return {
17
17
  userId: Number(ch.userId ?? 0),
18
18
  botToken: ch.botToken ?? '',
package/README.md DELETED
@@ -1,83 +0,0 @@
1
- # OpenClaw 书灵墨宝 插件
2
-
3
- 连接 OpenClaw 与 书灵墨宝 产品的通道插件。
4
-
5
- ## 架构
6
-
7
- ```
8
- ┌──────────┐ WebSocket ┌──────────────┐ WebSocket ┌─────────────────────┐
9
- │ Web 前端 │ ←───────────────→ │ 公司后端服务 │ ←───────────────→ │ OpenClaw(工作电脑) │
10
- └──────────┘ └──────────────┘ (OpenClaw 主动连) └─────────────────────┘
11
- ```
12
-
13
- - OpenClaw 插件**主动连接**后端的 WebSocket 服务(不需要公网 IP)
14
- - 后端收到用户消息后转发给 OpenClaw,OpenClaw 回复后发回后端
15
-
16
- ## 快速开始
17
-
18
- ### 1. 安装插件
19
-
20
- ```bash
21
- pnpm openclaw plugins install -l /path/to/openclaw-dcgchat
22
- ```
23
-
24
- ### 2. 配置
25
-
26
- ```bash
27
- openclaw config set channels.dcgchat.enabled true
28
- openclaw config set channels.dcgchat.wsUrl "ws://your-backend:8080/openclaw/ws"
29
- ```
30
-
31
- ### 3. 启动
32
-
33
- ```bash
34
- pnpm openclaw gateway
35
- ```
36
-
37
- ## 消息协议(MVP)
38
-
39
- ### 下行:后端 → OpenClaw(用户消息)
40
-
41
- ```json
42
- { "type": "message", "userId": "user_001", "text": "你好" }
43
- ```
44
-
45
- ### 上行:OpenClaw → 后端(Agent 回复)
46
-
47
- ```json
48
- { "type": "reply", "userId": "user_001", "text": "你好!有什么可以帮你的?" }
49
- ```
50
-
51
- ## 配置项
52
-
53
- | 配置键 | 类型 | 说明 |
54
- |--------|------|------|
55
- | `channels.dcgchat.enabled` | boolean | 是否启用 |
56
- | `channels.dcgchat.wsUrl` | string | 后端 WebSocket 地址 |
57
-
58
- ## 开发
59
-
60
- ```bash
61
- # 安装依赖
62
- pnpm install
63
-
64
- # 类型检查
65
- pnpm typecheck
66
- ```
67
-
68
- ## 文件结构
69
-
70
- - `index.ts` - 插件入口
71
- - `src/channel.ts` - ChannelPlugin 定义
72
- - `src/runtime.ts` - 插件 runtime
73
- - `src/types.ts` - 类型定义
74
- - `src/monitor.ts` - WebSocket 连接与断线重连
75
- - `src/bot.ts` - 消息处理与 Agent 调用
76
-
77
- ## 后续迭代
78
-
79
- - [ ] Token 认证
80
- - [ ] 流式输出
81
- - [ ] Typing 指示
82
- - [ ] messageId 去重
83
- - [ ] 错误消息类型