@dcrays/dcgchat 0.4.8 → 0.4.10
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 +0 -1
- package/package.json +1 -1
- package/src/bot.ts +18 -4
- package/src/skill.ts +1 -2
- package/src/utils/gatewayMsgHanlder.ts +0 -1
package/index.ts
CHANGED
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -47,7 +47,15 @@ export function extractAgentIdFromConversationId(conversationId: string): string
|
|
|
47
47
|
if (idx <= 0) return null
|
|
48
48
|
return conversationId.slice(0, idx)
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
function formatText(text: string): string {
|
|
51
|
+
if (!text) return ''
|
|
52
|
+
const str = String(text).replace(/\s/g, '')
|
|
53
|
+
if (!str) return ''
|
|
54
|
+
if (str.length <= 50) {
|
|
55
|
+
return str
|
|
56
|
+
}
|
|
57
|
+
return str.slice(0, 25) + `...[此处省略${str.length - 50}字]....` + str.slice(-25)
|
|
58
|
+
}
|
|
51
59
|
async function resolveMediaFromUrls(files: TFileInfo[], botToken: string): Promise<MediaInfo[]> {
|
|
52
60
|
const core = getDcgchatRuntime()
|
|
53
61
|
const out: MediaInfo[] = []
|
|
@@ -191,6 +199,14 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
|
|
|
191
199
|
}
|
|
192
200
|
|
|
193
201
|
try {
|
|
202
|
+
if (msg.content.skills_scope.length > 0 && !msg.content?.agent_clone_code && !ignoreToolCommand.includes(text?.trim())) {
|
|
203
|
+
const workspaceDir = getWorkspaceDir()
|
|
204
|
+
const skill = msg.content.skills_scope[0]
|
|
205
|
+
const skillDir = `${workspaceDir}/skills/${skill.skill_code}`
|
|
206
|
+
const skillText = `用户选择使用此技能:"${skill.skill_code}",技能路径是:"${skillDir}",在目录下查找并`
|
|
207
|
+
text = skill.skill_code ? `${skillText} ${text}` : text
|
|
208
|
+
dcgLogger(`skill: text: ${text}`)
|
|
209
|
+
}
|
|
194
210
|
// 处理用户上传的文件
|
|
195
211
|
const files = msg.content.files ?? []
|
|
196
212
|
let mediaPayload: Record<string, unknown> = {}
|
|
@@ -266,6 +282,7 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
|
|
|
266
282
|
sentMediaKeys.add(key)
|
|
267
283
|
await sendDcgchatMedia({ sessionKey: dcgSessionKey, mediaUrl, text: '' })
|
|
268
284
|
}
|
|
285
|
+
dcgLogger(`[deliver]: len=${payload?.text?.length} sessionId=${outboundCtx.sessionId} ${formatText(payload?.text ?? '')}`)
|
|
269
286
|
},
|
|
270
287
|
onError: (err: unknown, info: { kind: string }) => {
|
|
271
288
|
setMsgStatus(dcgSessionKey, 'finished')
|
|
@@ -389,9 +406,6 @@ export async function handleDcgchatMessage(msg: InboundMessage, accountId: strin
|
|
|
389
406
|
const prev = streamChunkIdxBySessionKey.get(dcgSessionKey) ?? 0
|
|
390
407
|
streamChunkIdxBySessionKey.set(dcgSessionKey, prev + 1)
|
|
391
408
|
sendChunk(delta, outboundCtx, prev)
|
|
392
|
-
dcgLogger(
|
|
393
|
-
`[stream]: chunkIdx=${prev} len=${delta.length} sessionId=${outboundCtx.sessionId} ${delta.slice(0, 100)}`
|
|
394
|
-
)
|
|
395
409
|
}
|
|
396
410
|
streamedTextLen = payload.text.length
|
|
397
411
|
} else {
|
package/src/skill.ts
CHANGED
|
@@ -34,14 +34,13 @@ export async function installSkill(params: ISkillParams, msgContent: Record<stri
|
|
|
34
34
|
const { path: cdnUrl, code } = params
|
|
35
35
|
const workspacePath = getWorkspaceDir()
|
|
36
36
|
|
|
37
|
-
const skillDir = path.join(workspacePath, 'skills', code)
|
|
38
|
-
|
|
39
37
|
// 确保 skills 目录存在
|
|
40
38
|
const skillsDir = path.join(workspacePath, 'skills')
|
|
41
39
|
if (!fs.existsSync(skillsDir)) {
|
|
42
40
|
fs.mkdirSync(skillsDir, { recursive: true })
|
|
43
41
|
}
|
|
44
42
|
// 如果目标目录已存在,先删除
|
|
43
|
+
const skillDir = path.join(workspacePath, 'skills', code)
|
|
45
44
|
if (fs.existsSync(skillDir)) {
|
|
46
45
|
fs.rmSync(skillDir, { recursive: true, force: true })
|
|
47
46
|
}
|
|
@@ -15,7 +15,6 @@ export function handleGatewayEventMessage(msg: { event?: string; payload?: Recor
|
|
|
15
15
|
const outboundCtx = getEffectiveMsgParams(sessionKey)
|
|
16
16
|
if (pl.data?.delta) {
|
|
17
17
|
if (outboundCtx.sessionId) {
|
|
18
|
-
dcgLogger(`[Gateway] 收到agent事件: ${JSON.stringify(msg).slice(0, 100)}`)
|
|
19
18
|
sendChunk(pl.data.delta as string, outboundCtx, 0)
|
|
20
19
|
}
|
|
21
20
|
}
|