@dcrays/dcgchat-test 0.2.29 → 0.2.31

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
@@ -15,6 +15,7 @@ const plugin = {
15
15
  monitoringToolMessage(api)
16
16
  setOpenClawConfig(api.config)
17
17
  api.registerChannel({ plugin: dcgchatPlugin })
18
+ setWorkspaceDir(api.config?.agents?.defaults?.workspace)
18
19
  api.registerTool((ctx) => {
19
20
  const workspaceDir = ctx.workspaceDir
20
21
  setWorkspaceDir(workspaceDir)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcrays/dcgchat-test",
3
- "version": "0.2.29",
3
+ "version": "0.2.31",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
package/src/bot.ts CHANGED
@@ -3,11 +3,18 @@ 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 { clearSentMediaKeys, getDcgchatRuntime, getOpenClawConfig, getWorkspaceDir, setMsgStatus } from './utils/global.js'
6
+ import {
7
+ clearSentMediaKeys,
8
+ getDcgchatRuntime,
9
+ getOpenClawConfig,
10
+ getWorkspaceDir,
11
+ getWsConnection,
12
+ setMsgStatus
13
+ } from './utils/global.js'
7
14
  import { resolveAccount, sendDcgchatMedia } from './channel.js'
8
15
  import { generateSignUrl } from './request/api.js'
9
16
  import { extractMobookFiles } from './utils/searchFile.js'
10
- import { createMsgContext, sendChunk, sendFinal, sendText as sendTextMsg, sendError } from './transport.js'
17
+ import { createMsgContext, sendChunk, sendFinal, sendText as sendTextMsg, sendError, sendText } from './transport.js'
11
18
  import { dcgLogger } from './utils/log.js'
12
19
  import { channelInfo, systemCommand, interruptCommand, ENV } from './utils/constant.js'
13
20
 
@@ -229,8 +236,6 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
229
236
  humanDelay: core.channel.reply.resolveHumanDelayConfig(config, route.agentId),
230
237
  onReplyStart: async () => {},
231
238
  deliver: async (payload: ReplyPayload, info) => {
232
- dcgLogger(`[deliver]: kind=${info.kind}, text=${payload.text?.length ?? 0} chars, ${payload.text?.slice(0, 100)}`)
233
- // Media from the outbound pipeline (post-streaming)
234
239
  const mediaList = resolveReplyMediaList(payload)
235
240
  for (const mediaUrl of mediaList) {
236
241
  const key = getMediaKey(mediaUrl)
@@ -238,7 +243,6 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
238
243
  sentMediaKeys.add(key)
239
244
  await sendDcgchatMedia({ msgCtx, mediaUrl, text: '' })
240
245
  }
241
- sendFinal(msgCtx)
242
246
  },
243
247
  onError: (err: unknown, info: { kind: string }) => {
244
248
  dcgLogger(`${info.kind} reply failed: ${String(err)}`, 'error')
@@ -332,8 +336,8 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
332
336
  }
333
337
  await sendDcgchatMedia({ msgCtx, mediaUrl: resolved, text: '' })
334
338
  }
335
- sendFinal(msgCtx)
336
339
  }
340
+ sendFinal(msgCtx)
337
341
  clearSentMediaKeys(msg.content.message_id)
338
342
  setMsgStatus('finished')
339
343
 
package/src/channel.ts CHANGED
@@ -14,8 +14,6 @@ export type DcgchatMediaSendOptions = {
14
14
 
15
15
  export async function sendDcgchatMedia(opts: DcgchatMediaSendOptions): Promise<void> {
16
16
  const { msgCtx } = opts
17
- console.log('🚀 ~ sendDcgchatMedia ~ msgCtx:', msgCtx)
18
-
19
17
  if (!isWsOpen()) {
20
18
  dcgLogger(`outbound media skipped -> ws not open: ${opts.mediaUrl ?? ''}`)
21
19
  return
@@ -158,8 +156,7 @@ export const dcgchatPlugin: ChannelPlugin<ResolvedDcgchatAccount> = {
158
156
  const msgCtx = createOutboundMsgContext(ctx.cfg, ctx.accountId)
159
157
  if (isWsOpen()) {
160
158
  wsSendRaw(msgCtx, { response: ctx.text })
161
- sendFinal(msgCtx)
162
- dcgLogger(`channel sendText to ${msgCtx.userId}`)
159
+ dcgLogger(`channel sendText to ${msgCtx.userId} ${ctx.text?.slice(0, 50)}`)
163
160
  }
164
161
  return {
165
162
  channel: "dcgchat-test",
package/src/skill.ts CHANGED
@@ -66,7 +66,6 @@ export async function installSkill(params: ISkillParams, msgContent: Record<stri
66
66
  entry.autodrain()
67
67
  return
68
68
  }
69
-
70
69
  try {
71
70
  const flags = entry.props?.flags ?? 0
72
71
  const isUtf8 = (flags & 0x800) !== 0
@@ -82,9 +81,7 @@ export async function installSkill(params: ISkillParams, msgContent: Record<stri
82
81
  if (!rootDir && pathParts.length > 1) {
83
82
  rootDir = pathParts[0]
84
83
  }
85
-
86
84
  let newPath = entryPath
87
-
88
85
  // 移除顶层文件夹
89
86
  if (rootDir && entryPath.startsWith(rootDir + '/')) {
90
87
  newPath = entryPath.slice(rootDir.length + 1)
@@ -139,10 +136,7 @@ export async function installSkill(params: ISkillParams, msgContent: Record<stri
139
136
  }
140
137
  }
141
138
 
142
- export function uninstallSkill(
143
- params: Omit<ISkillParams, 'path'>,
144
- msgContent: Record<string, any>
145
- ) {
139
+ export function uninstallSkill(params: Omit<ISkillParams, 'path'>, msgContent: Record<string, any>) {
146
140
  const { code } = params
147
141
 
148
142
  const workspacePath = getWorkspaceDir()
package/src/tool.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
2
2
  import { getMsgParams, getMsgStatus, getWsConnection } from './utils/global.js'
3
3
  import { dcgLogger } from './utils/log.js'
4
- import { isWsOpen } from './transport.js'
4
+ import { isWsOpen, sendFinal, sendText } from './transport.js'
5
5
 
6
6
  let toolCallId = ''
7
7
  let toolName = ''
@@ -97,27 +97,20 @@ export function monitoringToolMessage(api: OpenClawPluginApi) {
97
97
  } else if (item.event) {
98
98
  if (item.event === 'llm_output') {
99
99
  if (event.lastAssistant?.errorMessage === '429-账户额度耗尽') {
100
- const ws = getWsConnection()
101
100
  const params = getMsgParams()
102
- if (isWsOpen()) {
103
- ws?.send(
104
- JSON.stringify({
105
- messageType: 'openclaw_bot_cost',
106
- _userId: params?.userId,
107
- source: 'client',
108
- content: {
109
- bot_token: params?.token,
110
- domain_id: params?.domainId,
111
- app_id: params?.appId,
112
- bot_id: params?.botId,
113
- agent_id: params?.agentId,
114
- response: '您的余额不足,请充值后继续使用',
115
- session_id: params?.sessionId,
116
- message_id: params?.messageId || Date.now().toString()
117
- }
118
- })
119
- )
101
+ const message = '您的积分已消耗完,您可以通过充值积分来继续使用'
102
+ const ctx = {
103
+ userId: params.userId,
104
+ botToken: params.token,
105
+ domainId: params.domainId,
106
+ appId: params.appId,
107
+ botId: params.botId,
108
+ agentId: params.agentId,
109
+ sessionId: params.sessionId,
110
+ messageId: params.messageId
120
111
  }
112
+ sendText(ctx, message, { message_tags: { insufficient_balance: 1 }, is_finish: -1 })
113
+ sendFinal(ctx)
121
114
  return
122
115
  }
123
116
  }
package/src/transport.ts CHANGED
@@ -99,8 +99,8 @@ export function sendFinal(ctx: DcgchatMsgContext): boolean {
99
99
  return wsSend(ctx, { response: '', state: 'final' })
100
100
  }
101
101
 
102
- export function sendText(ctx: DcgchatMsgContext, text: string): boolean {
103
- return wsSend(ctx, { response: text })
102
+ export function sendText(ctx: DcgchatMsgContext, text: string, event?: Record<string, unknown>): boolean {
103
+ return wsSend(ctx, { response: text, ...event })
104
104
  }
105
105
 
106
106
  export function sendError(ctx: DcgchatMsgContext, errorMsg: string): boolean {
@@ -22,16 +22,21 @@ export function getOpenClawConfig(): OpenClawConfig | null {
22
22
  return config
23
23
  }
24
24
 
25
- import type { ChannelLogSink, OpenClawConfig, PluginRuntime } from 'openclaw/plugin-sdk'
25
+ import type { OpenClawConfig, PluginRuntime } from 'openclaw/plugin-sdk'
26
26
  import { dcgLogger } from './log.js'
27
27
  import { IMsgParams } from '../types.js'
28
+ import { channelInfo, ENV } from './constant.js'
28
29
 
29
30
  const path = require('path')
30
31
  const fs = require('fs')
31
32
  const os = require('os')
32
33
 
33
34
  function getWorkspacePath() {
34
- const workspacePath = path.join(os.homedir(), '.openclaw', 'workspace')
35
+ const workspacePath = path.join(
36
+ os.homedir(),
37
+ config?.channels?.["dcgchat-test"]?.appId == 110 ? '.mobook' : '.openclaw',
38
+ 'workspace'
39
+ )
35
40
  if (fs.existsSync(workspacePath)) {
36
41
  return workspacePath
37
42
  }