@workclaw/openclaw-workclaw 1.0.18 → 1.0.20
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 +30 -11
- package/dist/api.d.ts +3 -0
- package/dist/api.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +264 -0
- package/dist/setup-entry.d.ts +2 -0
- package/dist/setup-entry.js +12 -0
- package/dist/src/accounts.d.ts +66 -0
- package/dist/src/accounts.js +279 -0
- package/dist/src/api/accounts-api.d.ts +2 -0
- package/dist/src/api/accounts-api.js +130 -0
- package/dist/src/api/prompts-api.d.ts +2 -0
- package/dist/src/api/prompts-api.js +103 -0
- package/dist/src/api/session-api.d.ts +2 -0
- package/dist/src/api/session-api.js +207 -0
- package/dist/src/api/skills-api.d.ts +2 -0
- package/dist/src/api/skills-api.js +64 -0
- package/dist/src/api/workspace.d.ts +3 -0
- package/dist/src/api/workspace.js +30 -0
- package/dist/src/channel.d.ts +11 -0
- package/{src/channel.ts → dist/src/channel.js} +199 -225
- package/dist/src/config-schema.d.ts +93 -0
- package/dist/src/config-schema.js +56 -0
- package/dist/src/connection/workclaw-client.d.ts +147 -0
- package/dist/src/connection/workclaw-client.js +351 -0
- package/dist/src/gateway/agent-handlers.d.ts +12 -0
- package/{src/gateway/agent-handlers.ts → dist/src/gateway/agent-handlers.js} +372 -462
- package/dist/src/gateway/config-writer.d.ts +71 -0
- package/dist/src/gateway/config-writer.js +302 -0
- package/dist/src/gateway/cron-tasks-handler.d.ts +19 -0
- package/dist/src/gateway/cron-tasks-handler.js +188 -0
- package/dist/src/gateway/message-context.d.ts +80 -0
- package/{src/gateway/message-context.ts → dist/src/gateway/message-context.js} +509 -594
- package/dist/src/gateway/message-dispatcher.d.ts +18 -0
- package/dist/src/gateway/message-dispatcher.js +572 -0
- package/dist/src/gateway/reconnect.d.ts +27 -0
- package/{src/gateway/reconnect.ts → dist/src/gateway/reconnect.js} +210 -253
- package/dist/src/gateway/skills-handler.d.ts +29 -0
- package/dist/src/gateway/skills-handler.js +615 -0
- package/dist/src/gateway/skills-list-handler.d.ts +27 -0
- package/dist/src/gateway/skills-list-handler.js +233 -0
- package/dist/src/gateway/tools-list-handler.d.ts +30 -0
- package/dist/src/gateway/tools-list-handler.js +101 -0
- package/dist/src/gateway/workclaw-gateway.d.ts +14 -0
- package/dist/src/gateway/workclaw-gateway.js +237 -0
- package/dist/src/media/upload.d.ts +13 -0
- package/dist/src/media/upload.js +125 -0
- package/dist/src/outbound/index.d.ts +36 -0
- package/dist/src/outbound/index.js +123 -0
- package/dist/src/outbound/workclaw-sender.d.ts +36 -0
- package/{src/outbound/workclaw-sender.ts → dist/src/outbound/workclaw-sender.js} +95 -158
- package/dist/src/runtime.d.ts +116 -0
- package/dist/src/runtime.js +374 -0
- package/dist/src/secret-contract-api.d.ts +4 -0
- package/dist/src/secret-contract-api.js +4 -0
- package/{src/send.ts → dist/src/send.d.ts} +1 -1
- package/dist/src/send.js +1 -0
- package/dist/src/setup-api.d.ts +3 -0
- package/dist/src/setup-api.js +3 -0
- package/dist/src/setup-core.d.ts +3 -0
- package/dist/src/setup-core.js +13 -0
- package/dist/src/setup-surface.d.ts +7 -0
- package/dist/src/setup-surface.js +363 -0
- package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +93 -0
- package/dist/src/tools/openclaw-workclaw-cron/api/index.js +209 -0
- package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +10 -0
- package/{src/tools/openclaw-workclaw-cron/index.ts → dist/src/tools/openclaw-workclaw-cron/index.js} +33 -39
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +16 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +152 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +18 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +162 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +80 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +107 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +80 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +107 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +17 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +127 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +87 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +107 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +17 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +164 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +18 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +135 -0
- package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +52 -0
- package/dist/src/tools/openclaw-workclaw-cron/types/index.js +4 -0
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +40 -0
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +122 -0
- package/dist/src/tools/openclaw-workclaw-system/index.d.ts +10 -0
- package/{src/tools/openclaw-workclaw-system/index.ts → dist/src/tools/openclaw-workclaw-system/index.js} +15 -17
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +8 -0
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +64 -0
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +8 -0
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +78 -0
- package/{src/types.ts → dist/src/types.d.ts} +39 -58
- package/dist/src/types.js +1 -0
- package/dist/src/utils/content.d.ts +15 -0
- package/{src/utils/content.ts → dist/src/utils/content.js} +38 -35
- package/package.json +13 -9
- package/index.ts +0 -302
- package/setup-entry.ts +0 -6
- package/src/accounts.ts +0 -312
- package/src/api/accounts-api.ts +0 -156
- package/src/api/prompts-api.ts +0 -116
- package/src/api/session-api.ts +0 -238
- package/src/api/skills-api.ts +0 -72
- package/src/api/workspace.ts +0 -41
- package/src/config-schema.ts +0 -110
- package/src/connection/workclaw-client.ts +0 -643
- package/src/gateway/config-writer.ts +0 -296
- package/src/gateway/message-dispatcher.ts +0 -641
- package/src/gateway/skills-handler.ts +0 -741
- package/src/gateway/skills-list-handler.ts +0 -332
- package/src/gateway/tools-list-handler.ts +0 -160
- package/src/gateway/workclaw-gateway.ts +0 -367
- package/src/media/upload.ts +0 -157
- package/src/outbound/index.ts +0 -185
- package/src/runtime.ts +0 -497
- package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
- 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/src/get/index.ts +0 -77
- package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
- package/tests/accounts.test.ts +0 -285
- package/tests/message-context.test.ts +0 -313
- package/tests/reconnect.test.ts +0 -257
- package/tests/workclaw-client.test.ts +0 -112
- package/tsconfig.json +0 -14
- package/vitest.config.ts +0 -8
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 智小途系统信息工具 - 获取系统配置信息
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
-
import { resolveWorkclawAccountWithCache } 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 = resolveWorkclawAccountWithCache({
|
|
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
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 智小途系统信息工具 - 获取用户 AccessToken
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
-
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js'
|
|
7
|
-
import { getWorkclawAccessToken } 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 = resolveWorkclawAccountWithCache({
|
|
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 getWorkclawAccessToken(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/tests/accounts.test.ts
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for account config resolution and lookup cache.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, expect, it, beforeEach } from 'vitest';
|
|
6
|
-
import type { OpenClawConfig } from 'openclaw/plugin-sdk';
|
|
7
|
-
import {
|
|
8
|
-
normalizeAccountId,
|
|
9
|
-
buildAccountMap,
|
|
10
|
-
resolveAccountByUserIdAndAgentId,
|
|
11
|
-
allocateWorkerAccountId,
|
|
12
|
-
resolveWorkclawAccount,
|
|
13
|
-
listWorkclawAccountIds,
|
|
14
|
-
isWorkclawAccountConfigured,
|
|
15
|
-
listEnabledWorkclawAccounts,
|
|
16
|
-
} from '../src/accounts.js';
|
|
17
|
-
|
|
18
|
-
function makeCfg(workclaw: Record<string, unknown>): OpenClawConfig {
|
|
19
|
-
return { channels: { 'openclaw-workclaw': workclaw } } as unknown as OpenClawConfig;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
// normalizeAccountId
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
|
|
26
|
-
describe('normalizeAccountId', () => {
|
|
27
|
-
it('trims whitespace', () => {
|
|
28
|
-
expect(normalizeAccountId(' default ')).toBe('default');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('leaves normal IDs unchanged', () => {
|
|
32
|
-
expect(normalizeAccountId('workspace-1')).toBe('workspace-1');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('coerces non-string to string', () => {
|
|
36
|
-
expect(normalizeAccountId(123 as any)).toBe('123');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// ---------------------------------------------------------------------------
|
|
41
|
-
// isWorkclawAccountConfigured
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
|
|
44
|
-
describe('isWorkclawAccountConfigured', () => {
|
|
45
|
-
it('returns true when appKey and appSecret are present', () => {
|
|
46
|
-
expect(isWorkclawAccountConfigured({ appKey: 'key123', appSecret: 'secret123' })).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('returns false when appKey is missing', () => {
|
|
50
|
-
expect(isWorkclawAccountConfigured({ appSecret: 'secret' })).toBe(false);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('returns false when appSecret is missing', () => {
|
|
54
|
-
expect(isWorkclawAccountConfigured({ appKey: 'key' })).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('returns false when both are empty strings', () => {
|
|
58
|
-
expect(isWorkclawAccountConfigured({ appKey: '', appSecret: '' })).toBe(false);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('returns false when values are only whitespace', () => {
|
|
62
|
-
expect(isWorkclawAccountConfigured({ appKey: ' ', appSecret: ' ' })).toBe(false);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// ---------------------------------------------------------------------------
|
|
67
|
-
// listWorkclawAccountIds
|
|
68
|
-
// ---------------------------------------------------------------------------
|
|
69
|
-
|
|
70
|
-
describe('listWorkclawAccountIds', () => {
|
|
71
|
-
it('returns sorted account IDs when accounts are configured', () => {
|
|
72
|
-
const cfg = makeCfg({
|
|
73
|
-
appKey: 'key',
|
|
74
|
-
appSecret: 'secret',
|
|
75
|
-
accounts: {
|
|
76
|
-
'workspace-2': { appKey: 'k2', appSecret: 's2' },
|
|
77
|
-
'default': { appKey: 'kd', appSecret: 'sd' },
|
|
78
|
-
'workspace-1': { appKey: 'k1', appSecret: 's1' },
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
const ids = listWorkclawAccountIds(cfg);
|
|
82
|
-
expect(ids).toEqual(['default', 'workspace-1', 'workspace-2']);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('returns [default] when no accounts configured but plugin has appKey+appSecret', () => {
|
|
86
|
-
const cfg = makeCfg({ appKey: 'key', appSecret: 'secret' });
|
|
87
|
-
const ids = listWorkclawAccountIds(cfg);
|
|
88
|
-
expect(ids).toContain('default');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('returns [default] when channel config is empty', () => {
|
|
92
|
-
const cfg = makeCfg({});
|
|
93
|
-
const ids = listWorkclawAccountIds(cfg);
|
|
94
|
-
expect(ids).toContain('default');
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// ---------------------------------------------------------------------------
|
|
99
|
-
// resolveWorkclawAccount — config merging
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
|
|
102
|
-
describe('resolveWorkclawAccount', () => {
|
|
103
|
-
it('account-level fields override top-level fields', () => {
|
|
104
|
-
const cfg = makeCfg({
|
|
105
|
-
appKey: 'top-key',
|
|
106
|
-
appSecret: 'top-secret',
|
|
107
|
-
baseUrl: 'http://top.example.com',
|
|
108
|
-
accounts: {
|
|
109
|
-
'bot-a': { appKey: 'a-key', appSecret: 'a-secret', baseUrl: 'http://a.example.com' },
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
const account = resolveWorkclawAccount({ cfg, accountId: 'bot-a' });
|
|
113
|
-
expect(account.config.appKey).toBe('a-key');
|
|
114
|
-
expect(account.config.baseUrl).toBe('http://a.example.com');
|
|
115
|
-
expect(account.configured).toBe(true);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('account inherits top-level fields not overridden', () => {
|
|
119
|
-
const cfg = makeCfg({
|
|
120
|
-
appKey: 'top-key',
|
|
121
|
-
appSecret: 'top-secret',
|
|
122
|
-
baseUrl: 'http://top.example.com',
|
|
123
|
-
accounts: {
|
|
124
|
-
'bot-a': { appKey: 'a-key', appSecret: 'a-secret' },
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
const account = resolveWorkclawAccount({ cfg, accountId: 'bot-a' });
|
|
128
|
-
expect(account.config.baseUrl).toBe('http://top.example.com');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('account is not configured when appKey/appSecret missing after merge', () => {
|
|
132
|
-
const cfg = makeCfg({
|
|
133
|
-
accounts: {
|
|
134
|
-
'bot-empty': {},
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
const account = resolveWorkclawAccount({ cfg, accountId: 'bot-empty' });
|
|
138
|
-
expect(account.configured).toBe(false);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('account is disabled when top-level enabled=false', () => {
|
|
142
|
-
const cfg = makeCfg({
|
|
143
|
-
enabled: false,
|
|
144
|
-
appKey: 'key',
|
|
145
|
-
appSecret: 'secret',
|
|
146
|
-
accounts: {
|
|
147
|
-
'bot-a': { appKey: 'ak', appSecret: 'as' },
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
const account = resolveWorkclawAccount({ cfg, accountId: 'bot-a' });
|
|
151
|
-
expect(account.enabled).toBe(false);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('account is disabled when account-level enabled=false', () => {
|
|
155
|
-
const cfg = makeCfg({
|
|
156
|
-
appKey: 'key',
|
|
157
|
-
appSecret: 'secret',
|
|
158
|
-
accounts: {
|
|
159
|
-
'bot-off': { appKey: 'ak', appSecret: 'as', enabled: false },
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
const account = resolveWorkclawAccount({ cfg, accountId: 'bot-off' });
|
|
163
|
-
expect(account.enabled).toBe(false);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('accountId is normalized (trimmed)', () => {
|
|
167
|
-
const cfg = makeCfg({
|
|
168
|
-
accounts: {
|
|
169
|
-
'bot-a': { appKey: 'ak', appSecret: 'as' },
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
const account = resolveWorkclawAccount({ cfg, accountId: ' bot-a ' });
|
|
173
|
-
expect(account.accountId).toBe('bot-a');
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// ---------------------------------------------------------------------------
|
|
178
|
-
// listEnabledWorkclawAccounts
|
|
179
|
-
// ---------------------------------------------------------------------------
|
|
180
|
-
|
|
181
|
-
describe('listEnabledWorkclawAccounts', () => {
|
|
182
|
-
it('returns only enabled and configured accounts', () => {
|
|
183
|
-
// No top-level appKey/appSecret so 'unconfigured' stays unconfigured (no inheritance)
|
|
184
|
-
const cfg = makeCfg({
|
|
185
|
-
accounts: {
|
|
186
|
-
'active': { appKey: 'ak', appSecret: 'as' },
|
|
187
|
-
'disabled': { appKey: 'dk', appSecret: 'ds', enabled: false },
|
|
188
|
-
'unconfigured': {},
|
|
189
|
-
},
|
|
190
|
-
});
|
|
191
|
-
const accounts = listEnabledWorkclawAccounts(cfg);
|
|
192
|
-
const ids = accounts.map(a => a.accountId);
|
|
193
|
-
expect(ids).toContain('active');
|
|
194
|
-
expect(ids).not.toContain('disabled');
|
|
195
|
-
expect(ids).not.toContain('unconfigured');
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// ---------------------------------------------------------------------------
|
|
200
|
-
// buildAccountMap + resolveAccountByUserIdAndAgentId
|
|
201
|
-
// ---------------------------------------------------------------------------
|
|
202
|
-
|
|
203
|
-
describe('buildAccountMap + resolveAccountByUserIdAndAgentId', () => {
|
|
204
|
-
beforeEach(() => {
|
|
205
|
-
// Reset state by calling buildAccountMap with empty config
|
|
206
|
-
buildAccountMap(makeCfg({}));
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('resolves accountId from userId+agentId after buildAccountMap', () => {
|
|
210
|
-
const cfg = makeCfg({
|
|
211
|
-
accounts: {
|
|
212
|
-
'workspace-1': { appKey: 'k', appSecret: 's', userId: 'user-123', agentId: '456' },
|
|
213
|
-
},
|
|
214
|
-
});
|
|
215
|
-
buildAccountMap(cfg);
|
|
216
|
-
const result = resolveAccountByUserIdAndAgentId(cfg, 'user-123', '456');
|
|
217
|
-
expect(result).toBe('workspace-1');
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('returns null when no matching account', () => {
|
|
221
|
-
const cfg = makeCfg({
|
|
222
|
-
accounts: {
|
|
223
|
-
'workspace-1': { appKey: 'k', appSecret: 's', userId: 'user-123', agentId: '456' },
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
buildAccountMap(cfg);
|
|
227
|
-
const result = resolveAccountByUserIdAndAgentId(cfg, 'user-999', '456');
|
|
228
|
-
expect(result).toBeNull();
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('caches lookup on second call', () => {
|
|
232
|
-
const cfg = makeCfg({
|
|
233
|
-
accounts: {
|
|
234
|
-
'workspace-1': { appKey: 'k', appSecret: 's', userId: 'user-abc', agentId: '789' },
|
|
235
|
-
},
|
|
236
|
-
});
|
|
237
|
-
buildAccountMap(cfg);
|
|
238
|
-
// First call
|
|
239
|
-
expect(resolveAccountByUserIdAndAgentId(cfg, 'user-abc', '789')).toBe('workspace-1');
|
|
240
|
-
// Second call (from cache)
|
|
241
|
-
expect(resolveAccountByUserIdAndAgentId(cfg, 'user-abc', '789')).toBe('workspace-1');
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
// ---------------------------------------------------------------------------
|
|
246
|
-
// allocateWorkerAccountId
|
|
247
|
-
// ---------------------------------------------------------------------------
|
|
248
|
-
|
|
249
|
-
describe('allocateWorkerAccountId', () => {
|
|
250
|
-
beforeEach(() => {
|
|
251
|
-
buildAccountMap(makeCfg({}));
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('allocates workspace-1 on fresh state', () => {
|
|
255
|
-
const cfg = makeCfg({});
|
|
256
|
-
const id = allocateWorkerAccountId(cfg, 'user-1', 'agent-1');
|
|
257
|
-
expect(id).toBe('workspace-1');
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it('increments on each allocation', () => {
|
|
261
|
-
const cfg = makeCfg({});
|
|
262
|
-
const id1 = allocateWorkerAccountId(cfg, 'user-1', 'agent-1');
|
|
263
|
-
const id2 = allocateWorkerAccountId(cfg, 'user-2', 'agent-2');
|
|
264
|
-
expect(id1).toBe('workspace-1');
|
|
265
|
-
expect(id2).toBe('workspace-2');
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it('allocated account is immediately resolvable', () => {
|
|
269
|
-
const cfg = makeCfg({});
|
|
270
|
-
allocateWorkerAccountId(cfg, 'user-x', 'agent-x');
|
|
271
|
-
const result = resolveAccountByUserIdAndAgentId(cfg, 'user-x', 'agent-x');
|
|
272
|
-
expect(result).toBe('workspace-1');
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('nextWorkspaceNum continues from existing accounts', () => {
|
|
276
|
-
const cfg = makeCfg({
|
|
277
|
-
accounts: {
|
|
278
|
-
'workspace-5': { appKey: 'k', appSecret: 's', userId: 'u', agentId: '1' },
|
|
279
|
-
},
|
|
280
|
-
});
|
|
281
|
-
buildAccountMap(cfg);
|
|
282
|
-
const id = allocateWorkerAccountId(cfg, 'user-new', 'agent-new');
|
|
283
|
-
expect(id).toBe('workspace-6');
|
|
284
|
-
});
|
|
285
|
-
});
|