@dcrays/dcgchat-test 0.3.34 → 0.3.35
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/package.json +1 -1
- package/src/monitor.ts +7 -9
- package/src/session.ts +19 -0
- package/src/utils/global.ts +1 -1
package/package.json
CHANGED
package/src/monitor.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { dcgLogger } from './utils/log.js'
|
|
|
9
9
|
import { onDisabledCronJob, onEnabledCronJob, onRemoveCronJob, onRunCronJob } from './cron.js'
|
|
10
10
|
import { ignoreToolCommand } from './utils/constant.js'
|
|
11
11
|
import { isWsOpen } from './transport.js'
|
|
12
|
+
import { onRemoveSession } from './session.js'
|
|
12
13
|
|
|
13
14
|
export type MonitorDcgchatOpts = {
|
|
14
15
|
config?: ClawdbotConfig
|
|
@@ -142,15 +143,7 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
|
|
|
142
143
|
const { event_type, operation_type } = parsed.content ? parsed.content : ({} as Record<string, any>)
|
|
143
144
|
if (event_type === 'skill') {
|
|
144
145
|
const { skill_url, skill_code, skill_id, bot_token, websocket_trace_id } = parsed.content
|
|
145
|
-
const content = {
|
|
146
|
-
event_type,
|
|
147
|
-
operation_type,
|
|
148
|
-
skill_url,
|
|
149
|
-
skill_code,
|
|
150
|
-
skill_id,
|
|
151
|
-
bot_token,
|
|
152
|
-
websocket_trace_id
|
|
153
|
-
}
|
|
146
|
+
const content = { event_type, operation_type, skill_url, skill_code, skill_id, bot_token, websocket_trace_id }
|
|
154
147
|
if (operation_type === 'install' || operation_type === 'enable' || operation_type === 'update') {
|
|
155
148
|
installSkill({ path: skill_url, code: skill_code }, content)
|
|
156
149
|
} else if (operation_type === 'remove' || operation_type === 'disable') {
|
|
@@ -169,6 +162,11 @@ export async function monitorDcgchatProvider(opts: MonitorDcgchatOpts): Promise<
|
|
|
169
162
|
} else if (operation_type === 'run') {
|
|
170
163
|
await onRunCronJob(job_id, message_id)
|
|
171
164
|
}
|
|
165
|
+
} else if (event_type === 'session') {
|
|
166
|
+
const { agent_id, session_id, agent_clone_code } = parsed.content
|
|
167
|
+
if (operation_type === 'remove') {
|
|
168
|
+
await onRemoveSession({ agent_id, session_id, agent_clone_code, account_id: accountId })
|
|
169
|
+
}
|
|
172
170
|
} else {
|
|
173
171
|
dcgLogger(`openclaw_bot_event unknown operation_type: ${operation_type}, ${data.toString()}`)
|
|
174
172
|
}
|
package/src/session.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { sendMessageToGateway } from './gateway/socket.js'
|
|
2
|
+
import { getSessionKey } from './utils/global.js'
|
|
3
|
+
import { dcgLogger } from './utils/log.js'
|
|
4
|
+
|
|
5
|
+
interface TSession {
|
|
6
|
+
agent_id: string
|
|
7
|
+
session_id: string
|
|
8
|
+
agent_clone_code?: string
|
|
9
|
+
account_id?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const onRemoveSession = async ({ agent_id, session_id, agent_clone_code, account_id }: TSession) => {
|
|
13
|
+
const sessionKey = getSessionKey({ agent_id, session_id }, account_id)
|
|
14
|
+
if (!session_id) {
|
|
15
|
+
dcgLogger('onRemoveSession: empty session_id', 'error')
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
sendMessageToGateway(JSON.stringify({ method: 'sessions.delete', params: { key: sessionKey, deleteTranscript: true } }))
|
|
19
|
+
}
|
package/src/utils/global.ts
CHANGED
|
@@ -117,7 +117,7 @@ export function clearSentMediaKeys(messageId?: string) {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export const getSessionKey = (content: any, accountId
|
|
120
|
+
export const getSessionKey = (content: any, accountId?: string) => {
|
|
121
121
|
const { real_mobook, agent_id, conversation_id, session_id } = content
|
|
122
122
|
const core = getDcgchatRuntime()
|
|
123
123
|
|