@workclaw/openclaw-workclaw 1.0.25 → 1.0.26
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/dist/api.d.ts +4 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +379 -0
- package/dist/channel-DSvR6Irx.js +50017 -0
- package/dist/cron-tasks-handler-C-mP3VmV.js +152 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2088 -0
- package/dist/jiti-4i2h0FGP.js +4814 -0
- package/dist/setup-entry.d.ts +3 -0
- package/dist/setup-entry.d.ts.map +1 -0
- package/dist/setup-entry.js +182 -0
- package/dist/src/accounts.d.ts +67 -0
- package/dist/src/accounts.d.ts.map +1 -0
- package/dist/src/api/accounts-api.d.ts +3 -0
- package/dist/src/api/accounts-api.d.ts.map +1 -0
- package/dist/src/api/prompts-api.d.ts +3 -0
- package/dist/src/api/prompts-api.d.ts.map +1 -0
- package/dist/src/api/session-api.d.ts +3 -0
- package/dist/src/api/session-api.d.ts.map +1 -0
- package/dist/src/api/skills-api.d.ts +3 -0
- package/dist/src/api/skills-api.d.ts.map +1 -0
- package/dist/src/api/workspace.d.ts +4 -0
- package/dist/src/api/workspace.d.ts.map +1 -0
- package/dist/src/channel.d.ts +12 -0
- package/dist/src/channel.d.ts.map +1 -0
- package/dist/src/config-schema.d.ts +88 -0
- package/dist/src/config-schema.d.ts.map +1 -0
- package/dist/src/connection/workclaw-client.d.ts +149 -0
- package/dist/src/connection/workclaw-client.d.ts.map +1 -0
- package/dist/src/gateway/agent-handlers.d.ts +13 -0
- package/dist/src/gateway/agent-handlers.d.ts.map +1 -0
- package/dist/src/gateway/config-writer.d.ts +72 -0
- package/dist/src/gateway/config-writer.d.ts.map +1 -0
- package/dist/src/gateway/cron-tasks-handler.d.ts +20 -0
- package/dist/src/gateway/cron-tasks-handler.d.ts.map +1 -0
- package/dist/src/gateway/message-context.d.ts +81 -0
- package/dist/src/gateway/message-context.d.ts.map +1 -0
- package/dist/src/gateway/message-dispatcher.d.ts +17 -0
- package/dist/src/gateway/message-dispatcher.d.ts.map +1 -0
- package/dist/src/gateway/reconnect.d.ts +25 -0
- package/dist/src/gateway/reconnect.d.ts.map +1 -0
- package/dist/src/gateway/skills-handler.d.ts +30 -0
- package/dist/src/gateway/skills-handler.d.ts.map +1 -0
- package/dist/src/gateway/skills-list-handler.d.ts +28 -0
- package/dist/src/gateway/skills-list-handler.d.ts.map +1 -0
- package/dist/src/gateway/tools-list-handler.d.ts +31 -0
- package/dist/src/gateway/tools-list-handler.d.ts.map +1 -0
- package/dist/src/gateway/workclaw-gateway.d.ts +11 -0
- package/dist/src/gateway/workclaw-gateway.d.ts.map +1 -0
- package/dist/src/media/upload.d.ts +14 -0
- package/dist/src/media/upload.d.ts.map +1 -0
- package/dist/src/outbound/index.d.ts +39 -0
- package/dist/src/outbound/index.d.ts.map +1 -0
- package/dist/src/outbound/workclaw-sender.d.ts +38 -0
- package/dist/src/outbound/workclaw-sender.d.ts.map +1 -0
- package/dist/src/runtime.d.ts +118 -0
- package/dist/src/runtime.d.ts.map +1 -0
- package/dist/src/secret-contract-api.d.ts +5 -0
- package/dist/src/secret-contract-api.d.ts.map +1 -0
- package/{src/send.ts → dist/src/send.d.ts} +2 -1
- package/dist/src/send.d.ts.map +1 -0
- package/dist/src/setup-api.d.ts +4 -0
- package/dist/src/setup-api.d.ts.map +1 -0
- package/dist/src/setup-core.d.ts +4 -0
- package/dist/src/setup-core.d.ts.map +1 -0
- package/dist/src/setup-surface.d.ts +8 -0
- package/dist/src/setup-surface.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +91 -0
- package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +11 -0
- package/dist/src/tools/openclaw-workclaw-cron/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +16 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +12 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +12 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +12 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +12 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +13 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +12 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +12 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +15 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +16 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +53 -0
- package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +41 -0
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-system/index.d.ts +11 -0
- package/dist/src/tools/openclaw-workclaw-system/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +6 -0
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +6 -0
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts.map +1 -0
- package/dist/src/types.d.ts +39 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils/content.d.ts +16 -0
- package/dist/src/utils/content.d.ts.map +1 -0
- package/openclaw.plugin.json +6 -0
- package/package.json +69 -45
- package/api.ts +0 -3
- package/index.ts +0 -325
- package/setup-entry.ts +0 -13
- package/src/accounts.ts +0 -360
- package/src/api/accounts-api.ts +0 -156
- package/src/api/prompts-api.ts +0 -122
- package/src/api/session-api.ts +0 -246
- package/src/api/skills-api.ts +0 -74
- package/src/api/workspace.ts +0 -45
- package/src/channel.ts +0 -226
- package/src/config-schema.ts +0 -60
- package/src/connection/workclaw-client.ts +0 -618
- package/src/gateway/agent-handlers.ts +0 -551
- package/src/gateway/config-writer.ts +0 -378
- package/src/gateway/cron-tasks-handler.ts +0 -230
- package/src/gateway/message-context.ts +0 -645
- package/src/gateway/message-dispatcher.ts +0 -688
- package/src/gateway/reconnect.ts +0 -260
- package/src/gateway/skills-handler.ts +0 -805
- package/src/gateway/skills-list-handler.ts +0 -332
- package/src/gateway/tools-list-handler.ts +0 -161
- package/src/gateway/workclaw-gateway.ts +0 -304
- package/src/media/upload.ts +0 -168
- package/src/outbound/index.ts +0 -191
- package/src/outbound/workclaw-sender.ts +0 -161
- package/src/runtime.ts +0 -520
- package/src/secret-contract-api.ts +0 -4
- package/src/setup-api.ts +0 -3
- package/src/setup-core.ts +0 -25
- package/src/setup-surface.ts +0 -498
- package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
- package/src/tools/openclaw-workclaw-cron/index.ts +0 -39
- package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -177
- package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +0 -188
- package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +0 -100
- package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +0 -127
- package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +0 -100
- package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +0 -127
- package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +0 -148
- package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +0 -109
- package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +0 -127
- package/src/tools/openclaw-workclaw-cron/src/update/params.ts +0 -195
- package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +0 -161
- package/src/tools/openclaw-workclaw-cron/types/index.ts +0 -55
- package/src/tools/openclaw-workclaw-cron/utils/index.ts +0 -141
- package/src/tools/openclaw-workclaw-system/index.ts +0 -17
- package/src/tools/openclaw-workclaw-system/src/get/index.ts +0 -77
- package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
- package/src/types.ts +0 -50
- package/src/utils/content.ts +0 -40
- package/tsconfig.json +0 -34
package/src/setup-core.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ChannelSetupAdapter, OpenClawConfig } from 'openclaw/plugin-sdk/setup'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
DEFAULT_ACCOUNT_ID,
|
|
5
|
-
|
|
6
|
-
} from 'openclaw/plugin-sdk/setup'
|
|
7
|
-
import { resolveDefaultWorkclawAccountId } from './accounts.js'
|
|
8
|
-
import { patchWorkclawConfig } from './setup-surface.js'
|
|
9
|
-
|
|
10
|
-
export function setWorkclawNamedAccountEnabled(
|
|
11
|
-
cfg: OpenClawConfig,
|
|
12
|
-
accountId: string,
|
|
13
|
-
enabled: boolean,
|
|
14
|
-
): OpenClawConfig {
|
|
15
|
-
return patchWorkclawConfig(cfg, accountId, { enabled })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const workclawSetupAdapter: ChannelSetupAdapter = {
|
|
19
|
-
resolveAccountId: ({ cfg, accountId }) =>
|
|
20
|
-
accountId?.trim() || resolveDefaultWorkclawAccountId(cfg),
|
|
21
|
-
applyAccountConfig: ({ cfg, accountId }) => {
|
|
22
|
-
const isDefault = !accountId || accountId === DEFAULT_ACCOUNT_ID
|
|
23
|
-
return patchWorkclawConfig(cfg, isDefault ? DEFAULT_ACCOUNT_ID : accountId, { enabled: true })
|
|
24
|
-
},
|
|
25
|
-
}
|
package/src/setup-surface.ts
DELETED
|
@@ -1,498 +0,0 @@
|
|
|
1
|
-
import type { ChannelSetupWizard, OpenClawConfig } from 'openclaw/plugin-sdk/setup'
|
|
2
|
-
import type { WorkclawConfig } from './types.js'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
DEFAULT_ACCOUNT_ID,
|
|
6
|
-
formatDocsLink,
|
|
7
|
-
|
|
8
|
-
patchTopLevelChannelConfigSection,
|
|
9
|
-
} from 'openclaw/plugin-sdk/setup'
|
|
10
|
-
import { inspectWorkclawCredentials, resolveDefaultWorkclawAccountId } from './accounts.js'
|
|
11
|
-
import { doFetchJson } from './connection/workclaw-client.js'
|
|
12
|
-
|
|
13
|
-
const channel = 'openclaw-workclaw' as const
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 规范化字符串值
|
|
17
|
-
*/
|
|
18
|
-
function normalizeString(value: unknown): string | undefined {
|
|
19
|
-
if (typeof value !== 'string') {
|
|
20
|
-
return undefined
|
|
21
|
-
}
|
|
22
|
-
const trimmed = value.trim()
|
|
23
|
-
return trimmed || undefined
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function trimTrailingSlash(value: string): string {
|
|
27
|
-
return value.endsWith('/') ? value.slice(0, -1) : value
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function resolveSetupApiBases(cfg: OpenClawConfig): {
|
|
31
|
-
authBaseUrl: string
|
|
32
|
-
openApiBaseUrl: string
|
|
33
|
-
allowInsecureTls?: boolean
|
|
34
|
-
requestTimeout?: number
|
|
35
|
-
} {
|
|
36
|
-
const workclawCfg = cfg.channels?.['openclaw-workclaw'] as WorkclawConfig | undefined
|
|
37
|
-
const configuredBaseUrl
|
|
38
|
-
= normalizeString(workclawCfg?.baseUrl)
|
|
39
|
-
?? normalizeString(process.env.WORKCLAW_BASE_URL)
|
|
40
|
-
const configuredAuthBaseUrl = normalizeString(process.env.WORKCLAW_AUTH_BASE_URL)
|
|
41
|
-
const configuredOpenApiBaseUrl = normalizeString(process.env.WORKCLAW_OPEN_API_BASE_URL)
|
|
42
|
-
|
|
43
|
-
const defaultAuthBaseUrl = 'https://workbrain.cn/backend-api'
|
|
44
|
-
const defaultOpenApiBaseUrl = `${defaultAuthBaseUrl}/open-apis`
|
|
45
|
-
|
|
46
|
-
const fromBaseUrl = (() => {
|
|
47
|
-
if (!configuredBaseUrl) {
|
|
48
|
-
return null
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const normalized = trimTrailingSlash(configuredBaseUrl)
|
|
52
|
-
if (normalized.endsWith('/open-apis')) {
|
|
53
|
-
return {
|
|
54
|
-
authBaseUrl: normalized.slice(0, -'/open-apis'.length),
|
|
55
|
-
openApiBaseUrl: normalized,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
authBaseUrl: normalized,
|
|
61
|
-
openApiBaseUrl: `${normalized}/open-apis`,
|
|
62
|
-
}
|
|
63
|
-
})()
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
authBaseUrl: trimTrailingSlash(
|
|
67
|
-
configuredAuthBaseUrl ?? fromBaseUrl?.authBaseUrl ?? defaultAuthBaseUrl,
|
|
68
|
-
),
|
|
69
|
-
openApiBaseUrl: trimTrailingSlash(
|
|
70
|
-
configuredOpenApiBaseUrl ?? fromBaseUrl?.openApiBaseUrl ?? defaultOpenApiBaseUrl,
|
|
71
|
-
),
|
|
72
|
-
allowInsecureTls: workclawCfg?.allowInsecureTls,
|
|
73
|
-
requestTimeout: workclawCfg?.requestTimeout,
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* 检查 Workclaw 是否已配置
|
|
79
|
-
*/
|
|
80
|
-
function isWorkclawConfigured(cfg: OpenClawConfig): boolean {
|
|
81
|
-
const workclawCfg = cfg.channels?.['openclaw-workclaw'] as WorkclawConfig | undefined
|
|
82
|
-
|
|
83
|
-
// 检查字符串值是否已配置
|
|
84
|
-
const isConfigured = (value: unknown): boolean => {
|
|
85
|
-
const asString = normalizeString(value)
|
|
86
|
-
return !!asString
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const topLevelConfigured
|
|
90
|
-
= isConfigured(workclawCfg?.appKey)
|
|
91
|
-
&& isConfigured(workclawCfg?.appSecret)
|
|
92
|
-
|
|
93
|
-
const accountConfigured = Object.values(workclawCfg?.accounts ?? {}).some((account) => {
|
|
94
|
-
if (!account || typeof account !== 'object') {
|
|
95
|
-
return false
|
|
96
|
-
}
|
|
97
|
-
const hasOwnAppKey = Object.prototype.hasOwnProperty.call(account, 'appKey')
|
|
98
|
-
const hasOwnAppSecret = Object.prototype.hasOwnProperty.call(account, 'appSecret')
|
|
99
|
-
const accountAppKeyConfigured = hasOwnAppKey
|
|
100
|
-
? isConfigured((account as Record<string, unknown>).appKey)
|
|
101
|
-
: isConfigured(workclawCfg?.appKey)
|
|
102
|
-
const accountSecretConfigured = hasOwnAppSecret
|
|
103
|
-
? isConfigured((account as Record<string, unknown>).appSecret)
|
|
104
|
-
: isConfigured(workclawCfg?.appSecret)
|
|
105
|
-
return accountAppKeyConfigured && accountSecretConfigured
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
return topLevelConfigured || accountConfigured
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* 修补 Workclaw 配置
|
|
113
|
-
*/
|
|
114
|
-
export function patchWorkclawConfig(
|
|
115
|
-
cfg: OpenClawConfig,
|
|
116
|
-
accountId: string,
|
|
117
|
-
patch: Record<string, unknown>,
|
|
118
|
-
): OpenClawConfig {
|
|
119
|
-
const workclawCfg = cfg.channels?.['openclaw-workclaw'] as WorkclawConfig | undefined
|
|
120
|
-
if (accountId === DEFAULT_ACCOUNT_ID) {
|
|
121
|
-
return patchTopLevelChannelConfigSection({
|
|
122
|
-
cfg,
|
|
123
|
-
channel,
|
|
124
|
-
enabled: true,
|
|
125
|
-
patch,
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
const nextAccountPatch = {
|
|
129
|
-
...(workclawCfg?.accounts?.[accountId] as Record<string, unknown> | undefined),
|
|
130
|
-
enabled: true,
|
|
131
|
-
...patch,
|
|
132
|
-
}
|
|
133
|
-
return patchTopLevelChannelConfigSection({
|
|
134
|
-
cfg,
|
|
135
|
-
channel,
|
|
136
|
-
enabled: true,
|
|
137
|
-
patch: {
|
|
138
|
-
accounts: {
|
|
139
|
-
...workclawCfg?.accounts,
|
|
140
|
-
[accountId]: nextAccountPatch,
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
})
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
type WizardPrompter = Parameters<NonNullable<ChannelSetupWizard['finalize']>>[0]['prompter']
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* 提示凭证帮助信息
|
|
150
|
-
*/
|
|
151
|
-
async function noteWorkclawCredentialHelp(prompter: WizardPrompter): Promise<void> {
|
|
152
|
-
await prompter.note(
|
|
153
|
-
[
|
|
154
|
-
'智小途插件安装引导',
|
|
155
|
-
'',
|
|
156
|
-
'准备事项:',
|
|
157
|
-
'1. 访问 workbrain.cn 获取 App Key 和 App Secret',
|
|
158
|
-
'2. 确保您的账号已开通智小途服务',
|
|
159
|
-
'3. 准备好您的手机号(用于获取配置信息)',
|
|
160
|
-
'',
|
|
161
|
-
`文档: ${formatDocsLink('/channels/openclaw-workclaw', '智小途')}`,
|
|
162
|
-
].join('\n'),
|
|
163
|
-
'智小途配置',
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* 提示 App Key 输入
|
|
169
|
-
*/
|
|
170
|
-
async function promptWorkclawAppKey(params: {
|
|
171
|
-
prompter: WizardPrompter
|
|
172
|
-
initialValue?: string
|
|
173
|
-
}): Promise<string> {
|
|
174
|
-
return (
|
|
175
|
-
await params.prompter.text({
|
|
176
|
-
message: '智小途 App Key',
|
|
177
|
-
initialValue: params.initialValue,
|
|
178
|
-
validate: value => (value?.trim() ? undefined : 'App Key 不能为空'),
|
|
179
|
-
})
|
|
180
|
-
).trim()
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* 提示 App Secret 输入
|
|
185
|
-
*/
|
|
186
|
-
async function promptWorkclawAppSecret(params: {
|
|
187
|
-
prompter: WizardPrompter
|
|
188
|
-
initialValue?: string
|
|
189
|
-
}): Promise<string> {
|
|
190
|
-
return (
|
|
191
|
-
await params.prompter.text({
|
|
192
|
-
message: '智小途 App Secret',
|
|
193
|
-
initialValue: params.initialValue,
|
|
194
|
-
validate: value => (value?.trim() ? undefined : 'App Secret 不能为空'),
|
|
195
|
-
})
|
|
196
|
-
).trim()
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* 提示手机号输入
|
|
201
|
-
*/
|
|
202
|
-
async function promptWorkclawPhone(params: {
|
|
203
|
-
prompter: WizardPrompter
|
|
204
|
-
initialValue?: string
|
|
205
|
-
}): Promise<string> {
|
|
206
|
-
return (
|
|
207
|
-
await params.prompter.text({
|
|
208
|
-
message: '智小途手机号',
|
|
209
|
-
initialValue: params.initialValue,
|
|
210
|
-
validate: (value) => {
|
|
211
|
-
if (!value?.trim())
|
|
212
|
-
return '手机号不能为空'
|
|
213
|
-
if (!/^1[3-9]\d{9}$/.test(value.trim()))
|
|
214
|
-
return '请输入正确的手机号格式'
|
|
215
|
-
return undefined
|
|
216
|
-
},
|
|
217
|
-
})
|
|
218
|
-
).trim()
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* 通过手机号获取 agentId 和 userId
|
|
223
|
-
*/
|
|
224
|
-
async function fetchAgentInfoByPhone(cfg: OpenClawConfig, appKey: string, appSecret: string, phone: string, prompter: WizardPrompter): Promise<{
|
|
225
|
-
agentId?: string
|
|
226
|
-
userId?: string
|
|
227
|
-
} | null> {
|
|
228
|
-
prompter.note?.('正在通过手机号获取配置信息...', '获取配置')
|
|
229
|
-
|
|
230
|
-
try {
|
|
231
|
-
const { authBaseUrl, openApiBaseUrl, allowInsecureTls, requestTimeout }
|
|
232
|
-
= resolveSetupApiBases(cfg)
|
|
233
|
-
|
|
234
|
-
// 1. 获取 access token
|
|
235
|
-
const tokenData = await doFetchJson(
|
|
236
|
-
`${authBaseUrl}/authen/v1/access_token/internal`,
|
|
237
|
-
{
|
|
238
|
-
method: 'POST',
|
|
239
|
-
headers: {
|
|
240
|
-
'Content-Type': 'application/json',
|
|
241
|
-
},
|
|
242
|
-
body: JSON.stringify({
|
|
243
|
-
app_key: appKey,
|
|
244
|
-
app_secret: appSecret,
|
|
245
|
-
}),
|
|
246
|
-
},
|
|
247
|
-
allowInsecureTls,
|
|
248
|
-
requestTimeout,
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
if (tokenData.code !== 200 || !tokenData.data?.accessToken) {
|
|
252
|
-
prompter.note?.(`获取 Token 失败: ${tokenData.message || '未知错误'}`, '获取配置')
|
|
253
|
-
return null
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const accessToken = tokenData.data.accessToken
|
|
257
|
-
|
|
258
|
-
// 2. 通过手机号获取 agentId 和 userId
|
|
259
|
-
const agentData = await doFetchJson(
|
|
260
|
-
`${openApiBaseUrl}/instance/local/agentInf`,
|
|
261
|
-
{
|
|
262
|
-
method: 'POST',
|
|
263
|
-
headers: {
|
|
264
|
-
'Content-Type': 'application/json',
|
|
265
|
-
'Authorization': `Bearer ${accessToken}`,
|
|
266
|
-
},
|
|
267
|
-
body: JSON.stringify({
|
|
268
|
-
appKey,
|
|
269
|
-
phone,
|
|
270
|
-
}),
|
|
271
|
-
},
|
|
272
|
-
allowInsecureTls,
|
|
273
|
-
requestTimeout,
|
|
274
|
-
)
|
|
275
|
-
|
|
276
|
-
if (agentData.code !== 200 || !agentData.data) {
|
|
277
|
-
prompter.note?.(`获取配置信息失败: ${agentData.message || '未知错误'}`, '获取配置')
|
|
278
|
-
return null
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
prompter.note?.(`成功获取配置信息`, '获取配置')
|
|
282
|
-
|
|
283
|
-
return {
|
|
284
|
-
agentId: agentData.data.agentId,
|
|
285
|
-
userId: agentData.data.userId,
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
catch (error) {
|
|
289
|
-
prompter.note?.(`获取配置失败: ${(error as Error).message}`, '获取配置')
|
|
290
|
-
return null
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* 运行新应用流程
|
|
296
|
-
*/
|
|
297
|
-
async function runNewAppFlow(params: {
|
|
298
|
-
cfg: OpenClawConfig
|
|
299
|
-
prompter: WizardPrompter
|
|
300
|
-
options?: Parameters<NonNullable<ChannelSetupWizard['finalize']>>[0]['options']
|
|
301
|
-
}): Promise<{ cfg: OpenClawConfig }> {
|
|
302
|
-
const { prompter } = params
|
|
303
|
-
let next = params.cfg
|
|
304
|
-
|
|
305
|
-
// 1. 显示帮助信息
|
|
306
|
-
await noteWorkclawCredentialHelp(prompter)
|
|
307
|
-
|
|
308
|
-
// 2. 获取 App Key
|
|
309
|
-
const appKey = await promptWorkclawAppKey({
|
|
310
|
-
prompter,
|
|
311
|
-
initialValue: normalizeString(process.env.WORKCLAW_APP_KEY),
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
// 3. 获取 App Secret
|
|
315
|
-
const appSecret = await promptWorkclawAppSecret({
|
|
316
|
-
prompter,
|
|
317
|
-
initialValue: normalizeString(process.env.WORKCLAW_APP_SECRET),
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
// 4. 获取手机号(通过手机号获取 agentId 和 userId)
|
|
321
|
-
const phone = await promptWorkclawPhone({
|
|
322
|
-
prompter,
|
|
323
|
-
initialValue: normalizeString(process.env.WORKCLAW_PHONE),
|
|
324
|
-
})
|
|
325
|
-
|
|
326
|
-
// 5. 配置基础信息
|
|
327
|
-
next = patchWorkclawConfig(next, DEFAULT_ACCOUNT_ID, {
|
|
328
|
-
appKey,
|
|
329
|
-
appSecret,
|
|
330
|
-
enabled: true,
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
// 6. 通过手机号获取 agentId 和 userId
|
|
334
|
-
const agentInfo = await fetchAgentInfoByPhone(next, appKey, appSecret, phone, prompter)
|
|
335
|
-
|
|
336
|
-
if (agentInfo) {
|
|
337
|
-
// 更新配置中的 agentId 和 userId
|
|
338
|
-
const accountConfig: Record<string, unknown> = {
|
|
339
|
-
enabled: true,
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (agentInfo.agentId) {
|
|
343
|
-
accountConfig.agentId = agentInfo.agentId
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (agentInfo.userId) {
|
|
347
|
-
accountConfig.userId = agentInfo.userId
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
next = patchWorkclawConfig(next, DEFAULT_ACCOUNT_ID, accountConfig)
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// 6. DM 策略固定为 open
|
|
354
|
-
next = patchWorkclawConfig(next, DEFAULT_ACCOUNT_ID, {
|
|
355
|
-
dmPolicy: 'open',
|
|
356
|
-
allowFrom: ['*'],
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
await prompter.note('智小途配置完成!', '')
|
|
360
|
-
|
|
361
|
-
return { cfg: next }
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* 运行编辑配置流程
|
|
366
|
-
*/
|
|
367
|
-
async function runEditFlow(params: {
|
|
368
|
-
cfg: OpenClawConfig
|
|
369
|
-
prompter: WizardPrompter
|
|
370
|
-
options?: Parameters<NonNullable<ChannelSetupWizard['finalize']>>[0]['options']
|
|
371
|
-
}): Promise<{ cfg: OpenClawConfig } | null> {
|
|
372
|
-
const workclawCfg = params.cfg.channels?.['openclaw-workclaw'] as WorkclawConfig | undefined
|
|
373
|
-
const existingAppKey = workclawCfg?.appKey
|
|
374
|
-
|
|
375
|
-
await params.prompter.note(
|
|
376
|
-
`当前配置的 App Key: ${existingAppKey ?? '(未配置)'}`,
|
|
377
|
-
'智小途配置',
|
|
378
|
-
)
|
|
379
|
-
|
|
380
|
-
const useExisting = await params.prompter.confirm({
|
|
381
|
-
message: `使用现有的智小途配置 (App Key: ${existingAppKey})?`,
|
|
382
|
-
initialValue: true,
|
|
383
|
-
})
|
|
384
|
-
|
|
385
|
-
if (!useExisting) {
|
|
386
|
-
return runNewAppFlow(params)
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
await params.prompter.note('保持现有配置不变。', '')
|
|
390
|
-
return { cfg: params.cfg }
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* 运行凭证探测流程
|
|
395
|
-
*/
|
|
396
|
-
async function runProbeFlow(params: {
|
|
397
|
-
cfg: OpenClawConfig
|
|
398
|
-
prompter: WizardPrompter
|
|
399
|
-
}): Promise<OpenClawConfig> {
|
|
400
|
-
const workclawCfg = params.cfg.channels?.['openclaw-workclaw'] as WorkclawConfig | undefined
|
|
401
|
-
const resolvedCredentials = inspectWorkclawCredentials(workclawCfg)
|
|
402
|
-
|
|
403
|
-
if (resolvedCredentials) {
|
|
404
|
-
try {
|
|
405
|
-
const probeResult = await resolvedCredentials()
|
|
406
|
-
params.prompter.note(
|
|
407
|
-
`智小途连接测试成功! ${probeResult.botName ? `Bot名称: ${probeResult.botName}` : ''}`,
|
|
408
|
-
'连接测试',
|
|
409
|
-
)
|
|
410
|
-
}
|
|
411
|
-
catch {
|
|
412
|
-
params.prompter.note('智小途连接测试失败,请检查配置。', '连接测试')
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return params.cfg
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
export { workclawSetupAdapter } from './setup-core.js'
|
|
420
|
-
|
|
421
|
-
export const workclawSetupWizard: ChannelSetupWizard = {
|
|
422
|
-
channel,
|
|
423
|
-
resolveAccountIdForConfigure: ({ accountOverride, defaultAccountId, cfg }) =>
|
|
424
|
-
(typeof accountOverride === 'string' && accountOverride.trim()
|
|
425
|
-
? accountOverride.trim()
|
|
426
|
-
: undefined)
|
|
427
|
-
?? resolveDefaultWorkclawAccountId(cfg)
|
|
428
|
-
?? defaultAccountId,
|
|
429
|
-
resolveShouldPromptAccountIds: () => false,
|
|
430
|
-
status: {
|
|
431
|
-
configuredLabel: '已配置',
|
|
432
|
-
unconfiguredLabel: '需要配置',
|
|
433
|
-
configuredHint: '已配置',
|
|
434
|
-
unconfiguredHint: '需要凭证',
|
|
435
|
-
configuredScore: 2,
|
|
436
|
-
unconfiguredScore: 0,
|
|
437
|
-
resolveConfigured: ({ cfg }) => isWorkclawConfigured(cfg),
|
|
438
|
-
resolveStatusLines: async ({ cfg, configured }) => {
|
|
439
|
-
const workclawCfg = cfg.channels?.['openclaw-workclaw'] as WorkclawConfig | undefined
|
|
440
|
-
const resolvedCredentials = inspectWorkclawCredentials(workclawCfg)
|
|
441
|
-
let probeResult = null
|
|
442
|
-
if (configured && resolvedCredentials) {
|
|
443
|
-
try {
|
|
444
|
-
probeResult = await resolvedCredentials()
|
|
445
|
-
}
|
|
446
|
-
catch {}
|
|
447
|
-
}
|
|
448
|
-
if (!configured) {
|
|
449
|
-
return ['智小途: 需要 App Key 和 App Secret']
|
|
450
|
-
}
|
|
451
|
-
if (probeResult?.ok) {
|
|
452
|
-
return [`智小途: 已连接${probeResult.botName ? ` (${probeResult.botName})` : ''}`]
|
|
453
|
-
}
|
|
454
|
-
return ['智小途: 已配置 (连接未验证)']
|
|
455
|
-
},
|
|
456
|
-
},
|
|
457
|
-
|
|
458
|
-
prepare: async ({ cfg, credentialValues }) => {
|
|
459
|
-
const alreadyConfigured = isWorkclawConfigured(cfg)
|
|
460
|
-
|
|
461
|
-
if (alreadyConfigured) {
|
|
462
|
-
return {
|
|
463
|
-
credentialValues: { ...credentialValues, _flow: 'edit' },
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
return {
|
|
468
|
-
credentialValues: { ...credentialValues, _flow: 'new' },
|
|
469
|
-
}
|
|
470
|
-
},
|
|
471
|
-
|
|
472
|
-
credentials: [],
|
|
473
|
-
|
|
474
|
-
finalize: async ({ cfg, prompter, options, credentialValues }) => {
|
|
475
|
-
const flow = credentialValues._flow ?? 'new'
|
|
476
|
-
|
|
477
|
-
if (flow === 'edit') {
|
|
478
|
-
const result = await runEditFlow({ cfg, prompter, options })
|
|
479
|
-
if (result === null) {
|
|
480
|
-
return { cfg }
|
|
481
|
-
}
|
|
482
|
-
cfg = result.cfg
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
cfg = (await runNewAppFlow({ cfg, prompter, options })).cfg
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
await runProbeFlow({ cfg, prompter })
|
|
489
|
-
return { cfg }
|
|
490
|
-
},
|
|
491
|
-
|
|
492
|
-
disable: cfg =>
|
|
493
|
-
patchTopLevelChannelConfigSection({
|
|
494
|
-
cfg,
|
|
495
|
-
channel,
|
|
496
|
-
patch: { enabled: false },
|
|
497
|
-
}),
|
|
498
|
-
}
|