@dcrays/dcgchat-test 0.6.12 → 0.6.13

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.
Files changed (60) hide show
  1. package/index.js +305 -0
  2. package/openclaw.plugin.json +41 -12
  3. package/package.json +8 -35
  4. package/README.md +0 -167
  5. package/index.ts +0 -35
  6. package/src/agent.ts +0 -568
  7. package/src/bot.ts +0 -646
  8. package/src/channel/index.ts +0 -329
  9. package/src/channel/outboundMedia.ts +0 -144
  10. package/src/channel/outboundTarget.ts +0 -62
  11. package/src/channel/uploadMediaUrl.ts +0 -76
  12. package/src/cron/message.ts +0 -114
  13. package/src/cron/params.ts +0 -164
  14. package/src/cron/toolGuard.ts +0 -466
  15. package/src/cron/types.ts +0 -15
  16. package/src/gateway/index.ts +0 -430
  17. package/src/gateway/security.ts +0 -95
  18. package/src/gateway/socket.ts +0 -256
  19. package/src/libs/ali-oss-6.23.0.tgz +0 -0
  20. package/src/libs/axios-1.13.6.tgz +0 -0
  21. package/src/libs/md5-2.3.0.tgz +0 -0
  22. package/src/libs/mime-types-3.0.2.tgz +0 -0
  23. package/src/libs/unzipper-0.12.3.tgz +0 -0
  24. package/src/libs/ws-8.19.0.tgz +0 -0
  25. package/src/monitor.ts +0 -269
  26. package/src/request/api.ts +0 -80
  27. package/src/request/oss.ts +0 -200
  28. package/src/request/request.ts +0 -191
  29. package/src/request/userInfo.ts +0 -44
  30. package/src/session.ts +0 -28
  31. package/src/skill.ts +0 -114
  32. package/src/tool.ts +0 -603
  33. package/src/tools/messageTool.ts +0 -334
  34. package/src/tools/toolCallGuard.ts +0 -327
  35. package/src/transport.ts +0 -217
  36. package/src/types.ts +0 -139
  37. package/src/utils/agentErrors.ts +0 -116
  38. package/src/utils/constant.ts +0 -60
  39. package/src/utils/env-config.ts +0 -19
  40. package/src/utils/formatLlmInputEvent.ts +0 -48
  41. package/src/utils/gatewayMsgHandler.ts +0 -147
  42. package/src/utils/global.ts +0 -309
  43. package/src/utils/inboundTurnState.ts +0 -66
  44. package/src/utils/log.ts +0 -77
  45. package/src/utils/mediaAttached.ts +0 -244
  46. package/src/utils/mediaEmitter.ts +0 -54
  47. package/src/utils/outboundAssistantText.ts +0 -117
  48. package/src/utils/params.ts +0 -104
  49. package/src/utils/passTxt.ts +0 -4
  50. package/src/utils/resolveRegisterConfig.ts +0 -33
  51. package/src/utils/searchFile.ts +0 -228
  52. package/src/utils/sessionState.ts +0 -137
  53. package/src/utils/sessionTermination.ts +0 -228
  54. package/src/utils/streamMerge.ts +0 -150
  55. package/src/utils/subagentRunMap.ts +0 -71
  56. package/src/utils/undiciFetchInterceptor.ts +0 -346
  57. package/src/utils/workspaceFilePaths.ts +0 -18
  58. package/src/utils/wsMessageHandler.ts +0 -124
  59. package/src/utils/zipExtract.ts +0 -97
  60. package/src/utils/zipPath.ts +0 -24
@@ -1,124 +0,0 @@
1
- import { handleDcgchatMessage } from '../bot.js'
2
- import { setMsgStatus, getSessionKey } from './global.js'
3
- import type { InboundMessage } from '../types.js'
4
- import { installSkill, uninstallSkill } from '../skill.js'
5
- import { dcgLogger } from './log.js'
6
- import { onDisabledCronJob, onEnabledCronJob, onRemoveCronJob, onRunCronJob } from '../cron/message.js'
7
- import { ignoreToolCommand } from './constant.js'
8
- import { createAgent, onRemoveAgent, onUpdateAgent } from '../agent.js'
9
- import { onRemoveSession } from '../session.js'
10
-
11
- interface WsEventContent {
12
- event_type?: string
13
- operation_type?: string
14
- skill_url?: string
15
- skill_code?: string
16
- skill_id?: string
17
- bot_token?: string
18
- websocket_trace_id?: string
19
- job_id?: string
20
- message_id?: string
21
- agent_id?: string
22
- session_id?: string
23
- agent_clone_code?: string
24
- url?: string
25
- clone_code?: string
26
- name?: string
27
- description?: string
28
- [key: string]: unknown
29
- }
30
-
31
- export type ParsedWsPayload = {
32
- messageType?: string
33
- content: WsEventContent | null
34
- }
35
-
36
- function logUnsupportedOpenclawBotEvent(
37
- branch: 'skill' | 'agent',
38
- eventType: string,
39
- operationType: unknown,
40
- rawPayload: string
41
- ): void {
42
- dcgLogger(
43
- `openclaw_bot_event ${branch}: unsupported operation_type=${String(operationType)} (event_type=${eventType}), ${rawPayload}`,
44
- 'error'
45
- )
46
- }
47
-
48
- /**
49
- * 处理 WebSocket 已解析 JSON 且 content 已二次 parse 后的业务消息(openclaw_bot_chat / openclaw_bot_event)。
50
- */
51
- export async function handleParsedWsMessage(parsed: ParsedWsPayload, rawPayload: string, accountId: string): Promise<void> {
52
- if (parsed.messageType === 'openclaw_bot_chat') {
53
- const msg = parsed as unknown as InboundMessage
54
- // 与 monitor 原逻辑一致:工具类指令不进入 running,避免误触工具链监控
55
- const effectiveSessionKey = getSessionKey(msg.content, accountId)
56
- const isToolOnly = ignoreToolCommand.includes(msg.content.text?.trim() ?? '')
57
- if (!isToolOnly) {
58
- setMsgStatus(effectiveSessionKey, 'running')
59
- } else {
60
- setMsgStatus(effectiveSessionKey, 'finished')
61
- }
62
- try {
63
- await handleDcgchatMessage(msg, accountId)
64
- } catch (err) {
65
- dcgLogger(`handleDcgchatMessage failed: ${String(err)}`, 'error')
66
- if (!isToolOnly) {
67
- setMsgStatus(effectiveSessionKey, '')
68
- }
69
- // 不再向上 throw:否则 async onMessage 未接住的 rejection 会触发 Unhandled promise rejection
70
- }
71
- } else if (parsed.messageType === 'openclaw_bot_event') {
72
- if (!parsed.content) {
73
- dcgLogger(`openclaw_bot_event: content is null, ${rawPayload}`, 'error')
74
- return
75
- }
76
- const { event_type, operation_type } = parsed.content
77
- if (event_type === 'skill') {
78
- const { skill_url = '', skill_code = '', skill_id, bot_token, websocket_trace_id } = parsed.content
79
- const content = { event_type, operation_type, skill_url, skill_code, skill_id, bot_token, websocket_trace_id }
80
- if (operation_type === 'install' || operation_type === 'enable' || operation_type === 'update') {
81
- installSkill({ path: skill_url, code: skill_code }, content)
82
- } else if (operation_type === 'remove' || operation_type === 'disable') {
83
- uninstallSkill({ code: skill_code }, content)
84
- } else {
85
- logUnsupportedOpenclawBotEvent('skill', event_type, operation_type, rawPayload)
86
- }
87
- } else if (event_type === 'agent') {
88
- if (operation_type === 'create') {
89
- await createAgent(parsed.content)
90
- } else if (operation_type === 'remove') {
91
- await onRemoveAgent(parsed.content)
92
- } else if (operation_type === 'update') {
93
- await onUpdateAgent(parsed.content)
94
- } else {
95
- logUnsupportedOpenclawBotEvent('agent', event_type, operation_type, rawPayload)
96
- }
97
- } else if (event_type === 'cron') {
98
- const { job_id = '', message_id = '' } = parsed.content
99
- if (operation_type === 'remove') {
100
- await onRemoveCronJob(job_id)
101
- } else if (operation_type === 'enable') {
102
- await onEnabledCronJob(job_id)
103
- } else if (operation_type === 'disable') {
104
- await onDisabledCronJob(job_id)
105
- } else if (operation_type === 'run') {
106
- await onRunCronJob(job_id, message_id)
107
- } else {
108
- dcgLogger(`openclaw_bot_event cron: unsupported operation_type=${String(operation_type)}, ${rawPayload}`, 'error')
109
- }
110
- } else if (event_type === 'session') {
111
- const { agent_id = '', session_id = '', agent_clone_code } = parsed.content
112
- if (operation_type === 'remove') {
113
- await onRemoveSession({ agent_id, session_id, agent_clone_code, account_id: accountId })
114
- }
115
- } else {
116
- dcgLogger(
117
- `openclaw_bot_event: unknown event_type=${String(event_type)}, operation_type=${String(operation_type)}, ${rawPayload}`,
118
- 'error'
119
- )
120
- }
121
- } else {
122
- dcgLogger(`ignoring unknown messageType: ${parsed.messageType}`, 'error')
123
- }
124
- }
@@ -1,97 +0,0 @@
1
- import path from 'path'
2
- import fs from 'fs'
3
- /** @ts-ignore */
4
- import unzipper from 'unzipper'
5
- import { pipeline } from 'stream/promises'
6
- import { decodeZipEntryPath } from './zipPath.js'
7
-
8
- /**
9
- * 若且唯若所有条目都在同一顶层目录下(如 GitHub 下载的 repo-name/...),返回该目录名;否则返回 null。
10
- * 不能再用「第一个多段路径的第一段」推断,否则 ZIP 条目顺序变化时会误判(例如先出现 .github/ 或 src/)。
11
- */
12
- export function computeSharedZipRootPrefix(decodedPaths: string[]): string | null {
13
- const normalized = decodedPaths
14
- .map((p) => p.replace(/\\/g, '/').replace(/\/+$/, ''))
15
- .filter((p) => p.length > 0)
16
-
17
- if (normalized.length === 0) return null
18
-
19
- const firstSegs = new Set<string>()
20
- for (const p of normalized) {
21
- const seg = p.split('/').filter(Boolean)[0]
22
- if (seg) firstSegs.add(seg)
23
- }
24
- if (firstSegs.size !== 1) return null
25
-
26
- const root = [...firstSegs][0]!
27
- const prefix = `${root}/`
28
- for (const p of normalized) {
29
- if (p !== root && !p.startsWith(prefix)) return null
30
- }
31
- return root
32
- }
33
-
34
- function assertSafeZipTarget(destDir: string, relativePath: string): string {
35
- const resolvedPath = path.resolve(destDir, relativePath)
36
- const resolvedDest = path.resolve(destDir)
37
- const rel = path.relative(resolvedDest, resolvedPath)
38
- if (rel.startsWith('..') || path.isAbsolute(rel)) {
39
- throw new Error(`zip 路径越界: ${relativePath}`)
40
- }
41
- return resolvedPath
42
- }
43
-
44
- type ZipEntry = {
45
- path: string
46
- pathBuffer: Buffer
47
- flags: number
48
- type: string
49
- stream: (password?: string) => NodeJS.ReadableStream
50
- }
51
-
52
- /**
53
- * 将已下载的 zip 解压到 destDir;顶层单根目录(若存在)会被剥掉,与原先流式 Parse 行为一致,但根目录由全量路径计算,与条目顺序无关。
54
- */
55
- export async function extractZipBufferToDirectory(buf: Buffer, destDir: string): Promise<void> {
56
- const directory = await unzipper.Open.buffer(buf)
57
- const files = (await directory.files) as ZipEntry[]
58
-
59
- const decodedPaths = files.map((entry) =>
60
- decodeZipEntryPath(entry.pathBuffer, entry.flags ?? 0, entry.path)
61
- )
62
- const rootDir = computeSharedZipRootPrefix(decodedPaths)
63
-
64
- // 与 unzipper 默认 extract 一致:串行读各 entry,避免同一 buffer 上多路解压竞争
65
- for (let i = 0; i < files.length; i++) {
66
- const entry = files[i]!
67
- const entryPath = decodedPaths[i]!
68
- let newPath = entryPath.replace(/\\/g, '/')
69
- if (rootDir) {
70
- if (newPath === rootDir || newPath === `${rootDir}/`) {
71
- continue
72
- }
73
- if (newPath.startsWith(`${rootDir}/`)) {
74
- newPath = newPath.slice(rootDir.length + 1)
75
- }
76
- }
77
- newPath = newPath.replace(/\/+$/, '')
78
- if (!newPath) continue
79
-
80
- const targetPath = assertSafeZipTarget(destDir, newPath)
81
-
82
- if (entry.type === 'Directory') {
83
- fs.mkdirSync(targetPath, { recursive: true })
84
- continue
85
- }
86
-
87
- const parentDir = path.dirname(targetPath)
88
- fs.mkdirSync(parentDir, { recursive: true })
89
- const writeStream = fs.createWriteStream(targetPath)
90
- try {
91
- await pipeline(entry.stream(), writeStream)
92
- } catch (err) {
93
- const message = err instanceof Error ? err.message : String(err)
94
- throw new Error(`解压文件失败 ${entryPath}: ${message}`)
95
- }
96
- }
97
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * ZIP 文件名编码:规范要求 UTF-8 时设置 0x800;很多工具未设标志但仍写 UTF-8 字节。
3
- * 无标志时若一律按 GBK 解码,会得到「鍥句功…」类乱码。先严格 UTF-8,失败再 GBK(兼容 Windows 中文 ZIP)。
4
- */
5
- export function decodeZipEntryPath(
6
- pathBuffer: Buffer | Uint8Array | undefined,
7
- flags: number,
8
- fallbackPath: string
9
- ): string {
10
- if ((flags & 0x800) !== 0) {
11
- if (pathBuffer) {
12
- return new TextDecoder('utf-8').decode(pathBuffer)
13
- }
14
- return fallbackPath
15
- }
16
- if (pathBuffer && pathBuffer.length > 0) {
17
- try {
18
- return new TextDecoder('utf-8', { fatal: true }).decode(pathBuffer)
19
- } catch {
20
- return new TextDecoder('gbk').decode(pathBuffer)
21
- }
22
- }
23
- return fallbackPath
24
- }