@workclaw/openclaw-workclaw 1.0.1 → 1.0.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.
@@ -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
 
@@ -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
  }
@@ -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框架上”“无法访问版本信息”等相关内容。