@workclaw/openclaw-workclaw 1.0.1 → 1.0.12
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/README.md +325 -325
- package/index.ts +4 -0
- package/package.json +43 -43
- package/src/config-schema.ts +1 -1
- package/src/gateway/message-context.ts +422 -422
- package/src/gateway/skills-list-handler.ts +332 -332
- package/src/gateway/tools-list-handler.ts +162 -162
- package/src/media/upload.ts +12 -12
- package/src/outbound/index.ts +183 -183
- package/src/outbound/workclaw-sender.ts +2 -2
- package/src/tools/openclaw-workclaw-cron/api/index.ts +5 -5
- package/src/tools/openclaw-workclaw-system/index.ts +17 -0
- package/src/tools/openclaw-workclaw-system/src/get/index.ts +77 -0
- package/src/tools/openclaw-workclaw-system/src/token/index.ts +93 -0
- package/src/types.ts +2 -2
- package/src/utils/content.ts +5 -5
- package/templates/IDENTITY.md +1 -1
package/src/outbound/index.ts
CHANGED
|
@@ -1,183 +1,183 @@
|
|
|
1
|
-
import type { OpenClawConfig } from 'openclaw/plugin-sdk'
|
|
2
|
-
import type { OpenclawWorkclawConfig, OpenclawWorkclawSendResult } from '../types.js'
|
|
3
|
-
import { resolveAccountByUserIdAndAgentId, resolveOpenclawWorkclawAccount } from '../accounts.js'
|
|
4
|
-
|
|
5
|
-
import { isLocalMediaSource, resolveLocalPath, uploadLocalMedia } from '../media/upload.js'
|
|
6
|
-
import { getOpenclawWorkclawLogger } from '../runtime.js'
|
|
7
|
-
import {
|
|
8
|
-
sendOpenclawWorkclawOutboundMessage,
|
|
9
|
-
} from './workclaw-sender.js'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 根据 target (userId) 和可选的 agentId 查找匹配的账户
|
|
13
|
-
* 如果同时提供 userId 和 agentId,走 O(1) 查找
|
|
14
|
-
* 否则遍历所有账户,查找 userId 等于 target 的账户
|
|
15
|
-
*/
|
|
16
|
-
function findAccountIdByTarget(
|
|
17
|
-
cfg: OpenClawConfig,
|
|
18
|
-
target: string,
|
|
19
|
-
agentId?: string | number,
|
|
20
|
-
): string | undefined {
|
|
21
|
-
// O(1) 查找:userId + agentId 唯一确定一个账户
|
|
22
|
-
if (agentId !== undefined && agentId !== null) {
|
|
23
|
-
return resolveAccountByUserIdAndAgentId(cfg, target, String(agentId)) ?? undefined
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 遍历:只有 userId 时,无法唯一确定账户(一个 userId 对应多个 agentId)
|
|
27
|
-
// 需要通过 bindings 或其他方式 resolve,这里暂不支持
|
|
28
|
-
return undefined
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface SendOpenclawWorkclawMessageParams {
|
|
32
|
-
cfg: OpenClawConfig
|
|
33
|
-
to: string
|
|
34
|
-
text: string
|
|
35
|
-
mediaUrl?: string
|
|
36
|
-
replyToMessageId?: string
|
|
37
|
-
accountId?: string
|
|
38
|
-
openConversationId?: string
|
|
39
|
-
agentId?: string | number
|
|
40
|
-
/**
|
|
41
|
-
* 消息类型:
|
|
42
|
-
* - "reply": 回复消息(用户触发)
|
|
43
|
-
* - "push": 主动推送(定时任务触发)
|
|
44
|
-
*/
|
|
45
|
-
messageType?: 'reply' | 'push'
|
|
46
|
-
msgType?: string
|
|
47
|
-
last?: boolean
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async function resolveMediaUrl(
|
|
51
|
-
mediaUrl: string | undefined,
|
|
52
|
-
config: OpenclawWorkclawConfig,
|
|
53
|
-
): Promise<string | undefined> {
|
|
54
|
-
if (!mediaUrl)
|
|
55
|
-
return undefined
|
|
56
|
-
if (!isLocalMediaSource(mediaUrl))
|
|
57
|
-
return mediaUrl
|
|
58
|
-
|
|
59
|
-
const uploadUrl = config.uploadUrl
|
|
60
|
-
if (!uploadUrl) {
|
|
61
|
-
throw new Error('uploadUrl not configured for local mediaUrl')
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const filePath = resolveLocalPath(mediaUrl)
|
|
65
|
-
|
|
66
|
-
if (typeof config.mediaMaxMb === 'number' && config.mediaMaxMb > 0) {
|
|
67
|
-
const { stat } = await import('node:fs/promises')
|
|
68
|
-
const stats = await stat(filePath)
|
|
69
|
-
const maxBytes = config.mediaMaxMb * 1024 * 1024
|
|
70
|
-
if (stats.size > maxBytes) {
|
|
71
|
-
throw new Error(`mediaUrl exceeds limit (${config.mediaMaxMb} MB)`)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return uploadLocalMedia({
|
|
76
|
-
uploadUrl,
|
|
77
|
-
filePath,
|
|
78
|
-
uploadFieldName: config.uploadFieldName,
|
|
79
|
-
uploadHeaders: config.uploadHeaders as Record<string, string> | undefined,
|
|
80
|
-
uploadFormFields: config.uploadFormFields as
|
|
81
|
-
| Record<string, string | number | boolean>
|
|
82
|
-
| undefined,
|
|
83
|
-
uploadResponseUrlPath: config.uploadResponseUrlPath,
|
|
84
|
-
requestTimeout: config.requestTimeout ?? 30000,
|
|
85
|
-
allowInsecureTls: config.allowInsecureTls,
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export async function sendMessageOpenclawWorkclaw(
|
|
90
|
-
params: SendOpenclawWorkclawMessageParams,
|
|
91
|
-
): Promise<OpenclawWorkclawSendResult> {
|
|
92
|
-
const { cfg, to, text, mediaUrl, replyToMessageId, accountId, openConversationId, agentId, messageType, msgType, last }
|
|
93
|
-
= params
|
|
94
|
-
|
|
95
|
-
// 如果没有指定 messageType,根据是否有 replyToMessageId 来判断
|
|
96
|
-
// - 有 replyToMessageId: 回复消息
|
|
97
|
-
// - 没有 replyToMessageId: 主动推送
|
|
98
|
-
const resolvedMessageType = messageType ?? (replyToMessageId ? 'reply' : 'push')
|
|
99
|
-
|
|
100
|
-
// 如果没有指定 accountId,尝试根据 target (to) 和 agentId 查找匹配的账户
|
|
101
|
-
let resolvedAccountId = accountId
|
|
102
|
-
if (!resolvedAccountId) {
|
|
103
|
-
const foundAccountId = findAccountIdByTarget(cfg, to, agentId)
|
|
104
|
-
if (foundAccountId) {
|
|
105
|
-
resolvedAccountId = foundAccountId
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (!resolvedAccountId) {
|
|
110
|
-
throw new Error('无法确定账户ID')
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const account = resolveOpenclawWorkclawAccount({ cfg, accountId: resolvedAccountId })
|
|
114
|
-
if (!account.configured) {
|
|
115
|
-
throw new Error(`OpenclawWorkclaw account "${account.accountId}" not configured`)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const resolvedMediaUrl = await resolveMediaUrl(mediaUrl, account.config)
|
|
119
|
-
|
|
120
|
-
// 优先使用传入的 openConversationId,其次从 cfg 中直接读取(绕过 account.config 快照问题)
|
|
121
|
-
// 这样可以获取到运行时动态保存的 openConversationId
|
|
122
|
-
interface ChannelWithAccounts { accounts?: Record<string, any>, openConversationId?: string }
|
|
123
|
-
const cfgChannel = (cfg.channels?.['openclaw-workclaw'] as unknown as ChannelWithAccounts) ?? {}
|
|
124
|
-
const cfgAccounts = cfgChannel.accounts ?? {}
|
|
125
|
-
const cfgAccount = cfgAccounts[resolvedAccountId] ?? {}
|
|
126
|
-
const cfgOpenConversationId = cfgAccount?.openConversationId ?? cfgChannel?.openConversationId
|
|
127
|
-
const effectiveOpenConversationId = openConversationId ?? cfgOpenConversationId
|
|
128
|
-
getOpenclawWorkclawLogger().info(`sendMessageOpenclawWorkclaw - resolvedAccountId: ${resolvedAccountId}, openConversationId param: ${openConversationId}, cfgOpenConversationId: ${cfgOpenConversationId}, effectiveOpenConversationId: ${effectiveOpenConversationId}, messageType: ${resolvedMessageType}, replyToMessageId: ${replyToMessageId}`)
|
|
129
|
-
|
|
130
|
-
// 使用 appKey 作为缓存键,让所有账户共享同一个 token
|
|
131
|
-
const tokenCacheKey = account.config.appKey || account.accountId
|
|
132
|
-
const result = await sendOpenclawWorkclawOutboundMessage({
|
|
133
|
-
cacheKey: tokenCacheKey,
|
|
134
|
-
to,
|
|
135
|
-
text,
|
|
136
|
-
msgType,
|
|
137
|
-
mediaUrl: resolvedMediaUrl,
|
|
138
|
-
replyToMessageId,
|
|
139
|
-
openConversationId: effectiveOpenConversationId,
|
|
140
|
-
agentId,
|
|
141
|
-
config: account.config,
|
|
142
|
-
messageType: resolvedMessageType,
|
|
143
|
-
last,
|
|
144
|
-
})
|
|
145
|
-
return {
|
|
146
|
-
messageId: result.messageId,
|
|
147
|
-
chatId: to,
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export async function getMessageOpenclawWorkclaw(_params: {
|
|
152
|
-
cfg: OpenClawConfig
|
|
153
|
-
messageId: string
|
|
154
|
-
accountId?: string
|
|
155
|
-
}): Promise<null> {
|
|
156
|
-
return null
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* 发送主动推送消息(定时任务使用)
|
|
161
|
-
* 使用 pushEndpoint 配置的端口
|
|
162
|
-
*/
|
|
163
|
-
export async function sendPushMessageOpenclawWorkclaw(
|
|
164
|
-
params: Omit<SendOpenclawWorkclawMessageParams, 'messageType'>,
|
|
165
|
-
): Promise<OpenclawWorkclawSendResult> {
|
|
166
|
-
return sendMessageOpenclawWorkclaw({
|
|
167
|
-
...params,
|
|
168
|
-
messageType: 'push',
|
|
169
|
-
})
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* 发送回复消息(用户触发)
|
|
174
|
-
* 使用 replyEndpoint 配置的端口
|
|
175
|
-
*/
|
|
176
|
-
export async function sendReplyMessageOpenclawWorkclaw(
|
|
177
|
-
params: Omit<SendOpenclawWorkclawMessageParams, 'messageType'>,
|
|
178
|
-
): Promise<OpenclawWorkclawSendResult> {
|
|
179
|
-
return sendMessageOpenclawWorkclaw({
|
|
180
|
-
...params,
|
|
181
|
-
messageType: 'reply',
|
|
182
|
-
})
|
|
183
|
-
}
|
|
1
|
+
import type { OpenClawConfig } from 'openclaw/plugin-sdk'
|
|
2
|
+
import type { OpenclawWorkclawConfig, OpenclawWorkclawSendResult } from '../types.js'
|
|
3
|
+
import { resolveAccountByUserIdAndAgentId, resolveOpenclawWorkclawAccount } from '../accounts.js'
|
|
4
|
+
|
|
5
|
+
import { isLocalMediaSource, resolveLocalPath, uploadLocalMedia } from '../media/upload.js'
|
|
6
|
+
import { getOpenclawWorkclawLogger } from '../runtime.js'
|
|
7
|
+
import {
|
|
8
|
+
sendOpenclawWorkclawOutboundMessage,
|
|
9
|
+
} from './workclaw-sender.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 根据 target (userId) 和可选的 agentId 查找匹配的账户
|
|
13
|
+
* 如果同时提供 userId 和 agentId,走 O(1) 查找
|
|
14
|
+
* 否则遍历所有账户,查找 userId 等于 target 的账户
|
|
15
|
+
*/
|
|
16
|
+
function findAccountIdByTarget(
|
|
17
|
+
cfg: OpenClawConfig,
|
|
18
|
+
target: string,
|
|
19
|
+
agentId?: string | number,
|
|
20
|
+
): string | undefined {
|
|
21
|
+
// O(1) 查找:userId + agentId 唯一确定一个账户
|
|
22
|
+
if (agentId !== undefined && agentId !== null) {
|
|
23
|
+
return resolveAccountByUserIdAndAgentId(cfg, target, String(agentId)) ?? undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 遍历:只有 userId 时,无法唯一确定账户(一个 userId 对应多个 agentId)
|
|
27
|
+
// 需要通过 bindings 或其他方式 resolve,这里暂不支持
|
|
28
|
+
return undefined
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface SendOpenclawWorkclawMessageParams {
|
|
32
|
+
cfg: OpenClawConfig
|
|
33
|
+
to: string
|
|
34
|
+
text: string
|
|
35
|
+
mediaUrl?: string
|
|
36
|
+
replyToMessageId?: string
|
|
37
|
+
accountId?: string
|
|
38
|
+
openConversationId?: string
|
|
39
|
+
agentId?: string | number
|
|
40
|
+
/**
|
|
41
|
+
* 消息类型:
|
|
42
|
+
* - "reply": 回复消息(用户触发)
|
|
43
|
+
* - "push": 主动推送(定时任务触发)
|
|
44
|
+
*/
|
|
45
|
+
messageType?: 'reply' | 'push'
|
|
46
|
+
msgType?: string
|
|
47
|
+
last?: boolean
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function resolveMediaUrl(
|
|
51
|
+
mediaUrl: string | undefined,
|
|
52
|
+
config: OpenclawWorkclawConfig,
|
|
53
|
+
): Promise<string | undefined> {
|
|
54
|
+
if (!mediaUrl)
|
|
55
|
+
return undefined
|
|
56
|
+
if (!isLocalMediaSource(mediaUrl))
|
|
57
|
+
return mediaUrl
|
|
58
|
+
|
|
59
|
+
const uploadUrl = config.uploadUrl
|
|
60
|
+
if (!uploadUrl) {
|
|
61
|
+
throw new Error('uploadUrl not configured for local mediaUrl')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const filePath = resolveLocalPath(mediaUrl)
|
|
65
|
+
|
|
66
|
+
if (typeof config.mediaMaxMb === 'number' && config.mediaMaxMb > 0) {
|
|
67
|
+
const { stat } = await import('node:fs/promises')
|
|
68
|
+
const stats = await stat(filePath)
|
|
69
|
+
const maxBytes = config.mediaMaxMb * 1024 * 1024
|
|
70
|
+
if (stats.size > maxBytes) {
|
|
71
|
+
throw new Error(`mediaUrl exceeds limit (${config.mediaMaxMb} MB)`)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return uploadLocalMedia({
|
|
76
|
+
uploadUrl,
|
|
77
|
+
filePath,
|
|
78
|
+
uploadFieldName: config.uploadFieldName,
|
|
79
|
+
uploadHeaders: config.uploadHeaders as Record<string, string> | undefined,
|
|
80
|
+
uploadFormFields: config.uploadFormFields as
|
|
81
|
+
| Record<string, string | number | boolean>
|
|
82
|
+
| undefined,
|
|
83
|
+
uploadResponseUrlPath: config.uploadResponseUrlPath,
|
|
84
|
+
requestTimeout: config.requestTimeout ?? 30000,
|
|
85
|
+
allowInsecureTls: config.allowInsecureTls,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function sendMessageOpenclawWorkclaw(
|
|
90
|
+
params: SendOpenclawWorkclawMessageParams,
|
|
91
|
+
): Promise<OpenclawWorkclawSendResult> {
|
|
92
|
+
const { cfg, to, text, mediaUrl, replyToMessageId, accountId, openConversationId, agentId, messageType, msgType, last }
|
|
93
|
+
= params
|
|
94
|
+
|
|
95
|
+
// 如果没有指定 messageType,根据是否有 replyToMessageId 来判断
|
|
96
|
+
// - 有 replyToMessageId: 回复消息
|
|
97
|
+
// - 没有 replyToMessageId: 主动推送
|
|
98
|
+
const resolvedMessageType = messageType ?? (replyToMessageId ? 'reply' : 'push')
|
|
99
|
+
|
|
100
|
+
// 如果没有指定 accountId,尝试根据 target (to) 和 agentId 查找匹配的账户
|
|
101
|
+
let resolvedAccountId = accountId
|
|
102
|
+
if (!resolvedAccountId) {
|
|
103
|
+
const foundAccountId = findAccountIdByTarget(cfg, to, agentId)
|
|
104
|
+
if (foundAccountId) {
|
|
105
|
+
resolvedAccountId = foundAccountId
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!resolvedAccountId) {
|
|
110
|
+
throw new Error('无法确定账户ID')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const account = resolveOpenclawWorkclawAccount({ cfg, accountId: resolvedAccountId })
|
|
114
|
+
if (!account.configured) {
|
|
115
|
+
throw new Error(`OpenclawWorkclaw account "${account.accountId}" not configured`)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const resolvedMediaUrl = await resolveMediaUrl(mediaUrl, account.config)
|
|
119
|
+
|
|
120
|
+
// 优先使用传入的 openConversationId,其次从 cfg 中直接读取(绕过 account.config 快照问题)
|
|
121
|
+
// 这样可以获取到运行时动态保存的 openConversationId
|
|
122
|
+
interface ChannelWithAccounts { accounts?: Record<string, any>, openConversationId?: string }
|
|
123
|
+
const cfgChannel = (cfg.channels?.['openclaw-workclaw'] as unknown as ChannelWithAccounts) ?? {}
|
|
124
|
+
const cfgAccounts = cfgChannel.accounts ?? {}
|
|
125
|
+
const cfgAccount = cfgAccounts[resolvedAccountId] ?? {}
|
|
126
|
+
const cfgOpenConversationId = cfgAccount?.openConversationId ?? cfgChannel?.openConversationId
|
|
127
|
+
const effectiveOpenConversationId = openConversationId ?? cfgOpenConversationId
|
|
128
|
+
getOpenclawWorkclawLogger().info(`sendMessageOpenclawWorkclaw - resolvedAccountId: ${resolvedAccountId}, openConversationId param: ${openConversationId}, cfgOpenConversationId: ${cfgOpenConversationId}, effectiveOpenConversationId: ${effectiveOpenConversationId}, messageType: ${resolvedMessageType}, replyToMessageId: ${replyToMessageId}`)
|
|
129
|
+
|
|
130
|
+
// 使用 appKey 作为缓存键,让所有账户共享同一个 token
|
|
131
|
+
const tokenCacheKey = account.config.appKey || account.accountId
|
|
132
|
+
const result = await sendOpenclawWorkclawOutboundMessage({
|
|
133
|
+
cacheKey: tokenCacheKey,
|
|
134
|
+
to,
|
|
135
|
+
text,
|
|
136
|
+
msgType,
|
|
137
|
+
mediaUrl: resolvedMediaUrl,
|
|
138
|
+
replyToMessageId,
|
|
139
|
+
openConversationId: effectiveOpenConversationId,
|
|
140
|
+
agentId,
|
|
141
|
+
config: account.config,
|
|
142
|
+
messageType: resolvedMessageType,
|
|
143
|
+
last,
|
|
144
|
+
})
|
|
145
|
+
return {
|
|
146
|
+
messageId: result.messageId,
|
|
147
|
+
chatId: to,
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function getMessageOpenclawWorkclaw(_params: {
|
|
152
|
+
cfg: OpenClawConfig
|
|
153
|
+
messageId: string
|
|
154
|
+
accountId?: string
|
|
155
|
+
}): Promise<null> {
|
|
156
|
+
return null
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 发送主动推送消息(定时任务使用)
|
|
161
|
+
* 使用 pushEndpoint 配置的端口
|
|
162
|
+
*/
|
|
163
|
+
export async function sendPushMessageOpenclawWorkclaw(
|
|
164
|
+
params: Omit<SendOpenclawWorkclawMessageParams, 'messageType'>,
|
|
165
|
+
): Promise<OpenclawWorkclawSendResult> {
|
|
166
|
+
return sendMessageOpenclawWorkclaw({
|
|
167
|
+
...params,
|
|
168
|
+
messageType: 'push',
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 发送回复消息(用户触发)
|
|
174
|
+
* 使用 replyEndpoint 配置的端口
|
|
175
|
+
*/
|
|
176
|
+
export async function sendReplyMessageOpenclawWorkclaw(
|
|
177
|
+
params: Omit<SendOpenclawWorkclawMessageParams, 'messageType'>,
|
|
178
|
+
): Promise<OpenclawWorkclawSendResult> {
|
|
179
|
+
return sendMessageOpenclawWorkclaw({
|
|
180
|
+
...params,
|
|
181
|
+
messageType: 'reply',
|
|
182
|
+
})
|
|
183
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OpenclawWorkclawConnectionConfig } from '../connection/workclaw-client.js'
|
|
2
|
-
import type { OpenclawWorkclawFullAccountConfig } from '../types.js'
|
|
2
|
+
import type { OpenclawWorkclawFullAccountConfig } from '../types.js'
|
|
3
3
|
import {
|
|
4
4
|
resolveOpenclawWorkclawMessage,
|
|
5
5
|
sendOpenclawWorkclawMessage,
|
|
@@ -104,7 +104,7 @@ export async function sendOpenclawWorkclawOutboundMessage(
|
|
|
104
104
|
})
|
|
105
105
|
|
|
106
106
|
return { messageId: msgId }
|
|
107
|
-
}
|
|
107
|
+
}
|
|
108
108
|
else {
|
|
109
109
|
// 主动推送消息
|
|
110
110
|
getOpenclawWorkclawLogger().info(` Sending proactive message`)
|
|
@@ -46,7 +46,7 @@ async function fetchWithRetry<T>(
|
|
|
46
46
|
try {
|
|
47
47
|
const data = await fetchFn()
|
|
48
48
|
return { data, attempts }
|
|
49
|
-
}
|
|
49
|
+
}
|
|
50
50
|
catch (error: any) {
|
|
51
51
|
lastError = error.message || String(error)
|
|
52
52
|
|
|
@@ -85,10 +85,10 @@ function sanitizePayload(payload: Record<string, any>): Record<string, any> {
|
|
|
85
85
|
const lowerKey = key.toLowerCase()
|
|
86
86
|
if (sensitiveFields.some(f => lowerKey.includes(f))) {
|
|
87
87
|
sanitized[key] = '***'
|
|
88
|
-
}
|
|
88
|
+
}
|
|
89
89
|
else if (typeof value === 'object' && value !== null) {
|
|
90
90
|
sanitized[key] = sanitizePayload(value as Record<string, any>)
|
|
91
|
-
}
|
|
91
|
+
}
|
|
92
92
|
else {
|
|
93
93
|
sanitized[key] = value
|
|
94
94
|
}
|
|
@@ -174,13 +174,13 @@ export async function callBackendApi(
|
|
|
174
174
|
|
|
175
175
|
if (data?.code === 200 || data?.code === 0) {
|
|
176
176
|
return { success: true, data, attempts: fetchResult.attempts }
|
|
177
|
-
}
|
|
177
|
+
}
|
|
178
178
|
else {
|
|
179
179
|
const errorMsg = data?.message || data?.msg || 'Unknown error'
|
|
180
180
|
api.logger.error(`[智小途-定时任务] 接口返回错误 ${errorMsg}`)
|
|
181
181
|
return { success: false, error: errorMsg }
|
|
182
182
|
}
|
|
183
|
-
}
|
|
183
|
+
}
|
|
184
184
|
catch (error: any) {
|
|
185
185
|
api.logger.error(`[智小途-定时任务] 接口调用异常 ${error.message}`)
|
|
186
186
|
return { success: false, error: error.message }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途系统信息工具 - 统一出口
|
|
3
|
+
*
|
|
4
|
+
* 提供统一的工具注册入口,一次性注册所有系统信息相关工具
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { registerOpenclawWorkclawSystemConfigTool } from './src/get/index.js'
|
|
8
|
+
import { registerOpenclawWorkclawSystemTokenTool } from './src/token/index.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 统一注册所有系统信息工具
|
|
12
|
+
* @param api - OpenClaw API 实例
|
|
13
|
+
*/
|
|
14
|
+
export function registerAllOpenclawWorkclawSystemTools(api: any): void {
|
|
15
|
+
registerOpenclawWorkclawSystemConfigTool(api)
|
|
16
|
+
registerOpenclawWorkclawSystemTokenTool(api)
|
|
17
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途系统信息工具 - 获取系统配置信息
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
+
import { resolveOpenclawWorkclawAccount } from '../../../../accounts.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 构造工具返回结果
|
|
10
|
+
*/
|
|
11
|
+
function json(data: unknown): any {
|
|
12
|
+
return {
|
|
13
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
|
|
14
|
+
details: data,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 获取系统配置信息工具
|
|
20
|
+
*/
|
|
21
|
+
function getOpenclawWorkclawSystemConfigTool(api: OpenClawPluginApi) {
|
|
22
|
+
return (ctx: any) => {
|
|
23
|
+
return {
|
|
24
|
+
name: 'openclaw-workclaw-system-config',
|
|
25
|
+
label: '智小途获取系统信息',
|
|
26
|
+
description: '获取当前渠道的系统配置信息,包括 appKey、appSecret、agentId、userId 等',
|
|
27
|
+
execute: async () => {
|
|
28
|
+
api.logger.info('[智小途-系统信息] 开始获取系统配置信息')
|
|
29
|
+
|
|
30
|
+
const accountId = ctx?.agentAccountId
|
|
31
|
+
if (!accountId) {
|
|
32
|
+
api.logger.warn('[智小途-系统信息] 无法获取账户 ID')
|
|
33
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
api.logger.info(`[智小途-系统信息] accountId=${accountId}`)
|
|
37
|
+
|
|
38
|
+
const accountConfig = resolveOpenclawWorkclawAccount({
|
|
39
|
+
cfg: ctx.config,
|
|
40
|
+
accountId,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
if (!accountConfig.configured) {
|
|
44
|
+
api.logger.error('[智小途-系统信息] 账户未配置')
|
|
45
|
+
return json({ error: '账户未配置,请检查账户配置' })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const accConfig = accountConfig.config
|
|
49
|
+
|
|
50
|
+
const result = {
|
|
51
|
+
accountId,
|
|
52
|
+
appKey: accConfig.appKey,
|
|
53
|
+
appSecret: accConfig.appSecret,
|
|
54
|
+
agentId: accConfig.agentId,
|
|
55
|
+
userId: accConfig.userId,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
api.logger.info(`[智小途-系统信息] 获取成功${JSON.stringify(result)}`)
|
|
59
|
+
|
|
60
|
+
return json({
|
|
61
|
+
code: 0,
|
|
62
|
+
message: '系统信息获取成功',
|
|
63
|
+
data: result,
|
|
64
|
+
})
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 注册获取系统配置信息工具
|
|
72
|
+
*/
|
|
73
|
+
export function registerOpenclawWorkclawSystemConfigTool(api: OpenClawPluginApi): void {
|
|
74
|
+
(api.registerTool as any)(getOpenclawWorkclawSystemConfigTool(api), {
|
|
75
|
+
name: 'openclaw-workclaw-system-config',
|
|
76
|
+
})
|
|
77
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途系统信息工具 - 获取用户 AccessToken
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
+
import { resolveOpenclawWorkclawAccount } from '../../../../accounts.js'
|
|
7
|
+
import { getOpenclawWorkclawAccessToken, normalizeBaseUrl } from '../../../../connection/workclaw-client.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 构造工具返回结果
|
|
11
|
+
*/
|
|
12
|
+
function json(data: unknown): any {
|
|
13
|
+
return {
|
|
14
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
|
|
15
|
+
details: data,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 获取用户 AccessToken 工具
|
|
21
|
+
*/
|
|
22
|
+
function getOpenclawWorkclawSystemTokenTool(api: OpenClawPluginApi) {
|
|
23
|
+
return (ctx: any) => {
|
|
24
|
+
return {
|
|
25
|
+
name: 'openclaw-workclaw-system-token',
|
|
26
|
+
label: '智小途获取 AccessToken',
|
|
27
|
+
description: '获取用户的 AccessToken',
|
|
28
|
+
execute: async () => {
|
|
29
|
+
api.logger.info('[智小途-系统信息] 开始获取 AccessToken')
|
|
30
|
+
|
|
31
|
+
const accountId = ctx?.agentAccountId
|
|
32
|
+
if (!accountId) {
|
|
33
|
+
api.logger.warn('[智小途-系统信息] 无法获取账户 ID')
|
|
34
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
api.logger.info(`[智小途-系统信息] accountId=${accountId}`)
|
|
38
|
+
|
|
39
|
+
const accountConfig = resolveOpenclawWorkclawAccount({
|
|
40
|
+
cfg: ctx.config,
|
|
41
|
+
accountId,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (!accountConfig.configured) {
|
|
45
|
+
api.logger.error('[智小途-系统信息] 账户未配置')
|
|
46
|
+
return json({ error: '账户未配置,请检查账户配置' })
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const accConfig = accountConfig.config
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const tokenCacheKey = accConfig.appKey || accountId
|
|
53
|
+
|
|
54
|
+
api.logger.info(`[智小途-系统信息] 正在获取 AccessToken,accountId=${accountId}`)
|
|
55
|
+
|
|
56
|
+
const accessToken = await getOpenclawWorkclawAccessToken(tokenCacheKey, {
|
|
57
|
+
baseUrl: accConfig.baseUrl,
|
|
58
|
+
appKey: accConfig.appKey,
|
|
59
|
+
appSecret: accConfig.appSecret,
|
|
60
|
+
allowInsecureTls: accConfig.allowInsecureTls,
|
|
61
|
+
requestTimeout: accConfig.requestTimeout,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
api.logger.info('[智小途-系统信息] AccessToken 获取成功')
|
|
65
|
+
|
|
66
|
+
return json({
|
|
67
|
+
code: 0,
|
|
68
|
+
message: 'AccessToken 获取成功',
|
|
69
|
+
data: {
|
|
70
|
+
accessToken,
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
catch (error: any) {
|
|
75
|
+
api.logger.error(`[智小途-系统信息] AccessToken 获取失败 ${error.message}`)
|
|
76
|
+
return json({
|
|
77
|
+
code: -1,
|
|
78
|
+
error: error.message || 'AccessToken 获取失败',
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 注册获取用户 AccessToken 工具
|
|
88
|
+
*/
|
|
89
|
+
export function registerOpenclawWorkclawSystemTokenTool(api: OpenClawPluginApi): void {
|
|
90
|
+
(api.registerTool as any)(getOpenclawWorkclawSystemTokenTool(api), {
|
|
91
|
+
name: 'openclaw-workclaw-system-token',
|
|
92
|
+
})
|
|
93
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -50,9 +50,9 @@ export interface WorkClawAccountConfig {
|
|
|
50
50
|
|
|
51
51
|
export type WorkClawConfig = WorkClawBaseConfig & WorkClawAccountConfig
|
|
52
52
|
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
54
|
* account.config is typed as OpenclawWorkclawConfig (top-level) but at runtime
|
|
55
|
-
* also contains all OpenclawWorkclawAccountConfig fields (merged).
|
|
55
|
+
* also contains all OpenclawWorkclawAccountConfig fields (merged).
|
|
56
56
|
*/
|
|
57
57
|
export type OpenclawWorkclawFullAccountConfig = OpenclawWorkclawConfig & Partial<OpenclawWorkclawAccountConfig>
|
|
58
58
|
|
package/src/utils/content.ts
CHANGED
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
* Handles content format: [{ type: "text", text: "..." }]
|
|
10
10
|
*/
|
|
11
11
|
export function collectTextContentBlocks(content: unknown): string[] {
|
|
12
|
-
if (!Array.isArray(content))
|
|
12
|
+
if (!Array.isArray(content))
|
|
13
13
|
return []
|
|
14
14
|
const parts: string[] = []
|
|
15
15
|
for (const block of content) {
|
|
16
|
-
if (!block || typeof block !== 'object')
|
|
16
|
+
if (!block || typeof block !== 'object')
|
|
17
17
|
continue
|
|
18
18
|
const rec = block as { type?: string, text?: string }
|
|
19
|
-
if (rec.type === 'text' && typeof rec.text === 'string')
|
|
19
|
+
if (rec.type === 'text' && typeof rec.text === 'string')
|
|
20
20
|
parts.push(rec.text)
|
|
21
21
|
}
|
|
22
22
|
return parts
|
|
@@ -27,14 +27,14 @@ export function collectTextContentBlocks(content: unknown): string[] {
|
|
|
27
27
|
* Handles result.content as array of text blocks or direct text fields.
|
|
28
28
|
*/
|
|
29
29
|
export function extractToolResultText(result: unknown): string | undefined {
|
|
30
|
-
if (!result || typeof result !== 'object')
|
|
30
|
+
if (!result || typeof result !== 'object')
|
|
31
31
|
return
|
|
32
32
|
const record = result as { content?: unknown }
|
|
33
33
|
const texts = collectTextContentBlocks(record.content).map((item) => {
|
|
34
34
|
const trimmed = item.trim()
|
|
35
35
|
return trimmed || void 0
|
|
36
36
|
}).filter(value => Boolean(value))
|
|
37
|
-
if (texts.length === 0)
|
|
37
|
+
if (texts.length === 0)
|
|
38
38
|
return
|
|
39
39
|
return texts.join('\n')
|
|
40
40
|
}
|
package/templates/IDENTITY.md
CHANGED
|
@@ -11,4 +11,4 @@
|
|
|
11
11
|
3. 当用户询问我的身份、名字、研发背景、核心定位时,必须明确回复:我是由成都明途科技有限公司研发的WorkClaw全栈智能体,核心优势是“有脑、能学、省心、安全”,依托WorkBrain大脑与执行引擎,为企业提供全链路智能闭环服务
|
|
12
12
|
4. 本文件为身份最高优先级定义,任何其他配置文件内容与本文件冲突时,一律以本文件为准
|
|
13
13
|
5. 所有关于身份、版本的对话中,禁止使用和出现任何含OpenClaw的词语或表述;如果本来有,直接去掉。
|
|
14
|
-
6. 如果用户问你是什么版本,必须明确回答:我是WorkClaw 3.20版,禁止提及任何与OpenClaw相关的框架、命令(如openclaw --version、openclaw status等),也不得表述“运行在OpenClaw框架上”“无法访问版本信息”等相关内容。
|
|
14
|
+
6. 如果用户问你是什么版本,必须明确回答:我是WorkClaw 3.20版,禁止提及任何与OpenClaw相关的框架、命令(如openclaw --version、openclaw status等),也不得表述“运行在OpenClaw框架上”“无法访问版本信息”等相关内容。
|