@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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途系统信息工具 - 获取用户 AccessToken
|
|
3
|
+
*/
|
|
4
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js';
|
|
5
|
+
import { getWorkclawAccessToken } from '../../../../connection/workclaw-client.js';
|
|
6
|
+
/**
|
|
7
|
+
* 构造工具返回结果
|
|
8
|
+
*/
|
|
9
|
+
function json(data) {
|
|
10
|
+
return {
|
|
11
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
12
|
+
details: data,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 获取用户 AccessToken 工具
|
|
17
|
+
*/
|
|
18
|
+
function getOpenclawWorkclawSystemTokenTool(api) {
|
|
19
|
+
return (ctx) => {
|
|
20
|
+
return {
|
|
21
|
+
name: 'openclaw-workclaw-system-token',
|
|
22
|
+
label: '智小途获取 AccessToken',
|
|
23
|
+
description: '获取用户的 AccessToken',
|
|
24
|
+
execute: async () => {
|
|
25
|
+
api.logger.info('[智小途-系统信息] 开始获取 AccessToken');
|
|
26
|
+
const accountId = ctx?.agentAccountId;
|
|
27
|
+
if (!accountId) {
|
|
28
|
+
api.logger.warn('[智小途-系统信息] 无法获取账户 ID');
|
|
29
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
|
|
30
|
+
}
|
|
31
|
+
api.logger.info(`[智小途-系统信息] accountId=${accountId}`);
|
|
32
|
+
const accountConfig = resolveWorkclawAccountWithCache({
|
|
33
|
+
cfg: ctx.config,
|
|
34
|
+
accountId,
|
|
35
|
+
});
|
|
36
|
+
if (!accountConfig.configured) {
|
|
37
|
+
api.logger.error('[智小途-系统信息] 账户未配置');
|
|
38
|
+
return json({ error: '账户未配置,请检查账户配置' });
|
|
39
|
+
}
|
|
40
|
+
const accConfig = accountConfig.config;
|
|
41
|
+
try {
|
|
42
|
+
const tokenCacheKey = accConfig.appKey || accountId;
|
|
43
|
+
api.logger.info(`[智小途-系统信息] 正在获取 AccessToken,accountId=${accountId}`);
|
|
44
|
+
const accessToken = await getWorkclawAccessToken(tokenCacheKey, {
|
|
45
|
+
baseUrl: accConfig.baseUrl,
|
|
46
|
+
appKey: accConfig.appKey,
|
|
47
|
+
appSecret: accConfig.appSecret,
|
|
48
|
+
allowInsecureTls: accConfig.allowInsecureTls,
|
|
49
|
+
requestTimeout: accConfig.requestTimeout,
|
|
50
|
+
});
|
|
51
|
+
api.logger.info('[智小途-系统信息] AccessToken 获取成功');
|
|
52
|
+
return json({
|
|
53
|
+
code: 0,
|
|
54
|
+
message: 'AccessToken 获取成功',
|
|
55
|
+
data: {
|
|
56
|
+
accessToken,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
api.logger.error(`[智小途-系统信息] AccessToken 获取失败 ${error.message}`);
|
|
62
|
+
return json({
|
|
63
|
+
code: -1,
|
|
64
|
+
error: error.message || 'AccessToken 获取失败',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 注册获取用户 AccessToken 工具
|
|
73
|
+
*/
|
|
74
|
+
export function registerOpenclawWorkclawSystemTokenTool(api) {
|
|
75
|
+
api.registerTool(getOpenclawWorkclawSystemTokenTool(api), {
|
|
76
|
+
name: 'openclaw-workclaw-system-token',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -1,58 +1,39 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export interface
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
replyEndpoint?: string;
|
|
41
|
-
pushEndpoint?: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Per-account WorkClaw fields */
|
|
45
|
-
export interface WorkClawAccountConfig {
|
|
46
|
-
agentId?: string | number;
|
|
47
|
-
userId?: string | number;
|
|
48
|
-
openConversationId?: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type WorkClawConfig = WorkClawBaseConfig & WorkClawAccountConfig;
|
|
52
|
-
|
|
53
|
-
/** account.config is typed as OpenclawWorkclawConfig (top-level) but at runtime
|
|
54
|
-
* also contains all OpenclawWorkclawAccountConfig fields (merged). */
|
|
55
|
-
export type WorkclawFullAccountConfig = WorkclawConfig & Partial<WorkclawAccountConfig>;
|
|
56
|
-
|
|
57
|
-
/** Resolved account's config - merge of top-level defaults + account overrides */
|
|
58
|
-
export type ResolvedWorkclawAccountConfig = WorkclawFullAccountConfig;
|
|
1
|
+
import type { workclawConfigSchema, workclawAccountConfigSchema, z } from "./config-schema.js";
|
|
2
|
+
export type WorkclawConfig = z.infer<typeof workclawConfigSchema>;
|
|
3
|
+
export type WorkclawAccountConfig = z.infer<typeof workclawAccountConfigSchema>;
|
|
4
|
+
export type WorkclawConnectionMode = "websocket" | "webhook";
|
|
5
|
+
export type ResolvedWorkclawAccount = {
|
|
6
|
+
accountId: string;
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
configured: boolean;
|
|
9
|
+
name?: string;
|
|
10
|
+
config: WorkclawFullAccountConfig;
|
|
11
|
+
};
|
|
12
|
+
export type ResolvedOpenClawWorkclawAccount = ResolvedWorkclawAccount;
|
|
13
|
+
export type WorkclawIdType = "open_id" | "user_id" | "union_id" | "chat_id";
|
|
14
|
+
export type WorkclawSendResult = {
|
|
15
|
+
messageId: string;
|
|
16
|
+
chatId: string;
|
|
17
|
+
};
|
|
18
|
+
export interface WorkClawBaseConfig {
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
websocketUrl?: string;
|
|
21
|
+
appKey?: string;
|
|
22
|
+
appSecret?: string;
|
|
23
|
+
localIp?: string;
|
|
24
|
+
allowInsecureTls?: boolean;
|
|
25
|
+
requestTimeout?: number;
|
|
26
|
+
userId?: string | number;
|
|
27
|
+
replyEndpoint?: string;
|
|
28
|
+
pushEndpoint?: string;
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}
|
|
31
|
+
export interface WorkClawAccountConfig {
|
|
32
|
+
agentId?: string | number;
|
|
33
|
+
userId?: string | number;
|
|
34
|
+
openConversationId?: string;
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}
|
|
37
|
+
export type WorkClawConfig = WorkClawBaseConfig & WorkClawAccountConfig;
|
|
38
|
+
export type WorkclawFullAccountConfig = WorkclawConfig & Partial<WorkclawAccountConfig>;
|
|
39
|
+
export type ResolvedWorkclawAccountConfig = WorkclawFullAccountConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content extraction utilities - copied from SDK's internal implementations
|
|
3
|
+
* node_modules/openclaw/dist/plugin-sdk/thread-bindings-SYAnWHuW.js (collectTextContentBlocks)
|
|
4
|
+
* node_modules/openclaw/dist/auth-profiles-DRjqKE3G.js (extractToolResultText)
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Extract text blocks from chat content array.
|
|
8
|
+
* Handles content format: [{ type: "text", text: "..." }]
|
|
9
|
+
*/
|
|
10
|
+
export declare function collectTextContentBlocks(content: unknown): string[];
|
|
11
|
+
/**
|
|
12
|
+
* Extract plain text from a tool result object.
|
|
13
|
+
* Handles result.content as array of text blocks or direct text fields.
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractToolResultText(result: unknown): string | undefined;
|
|
@@ -1,35 +1,38 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Content extraction utilities - copied from SDK's internal implementations
|
|
3
|
-
* node_modules/openclaw/dist/plugin-sdk/thread-bindings-SYAnWHuW.js (collectTextContentBlocks)
|
|
4
|
-
* node_modules/openclaw/dist/auth-profiles-DRjqKE3G.js (extractToolResultText)
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const parts
|
|
14
|
-
for (const block of content) {
|
|
15
|
-
if (!block || typeof block !== "object")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Content extraction utilities - copied from SDK's internal implementations
|
|
3
|
+
* node_modules/openclaw/dist/plugin-sdk/thread-bindings-SYAnWHuW.js (collectTextContentBlocks)
|
|
4
|
+
* node_modules/openclaw/dist/auth-profiles-DRjqKE3G.js (extractToolResultText)
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Extract text blocks from chat content array.
|
|
8
|
+
* Handles content format: [{ type: "text", text: "..." }]
|
|
9
|
+
*/
|
|
10
|
+
export function collectTextContentBlocks(content) {
|
|
11
|
+
if (!Array.isArray(content))
|
|
12
|
+
return [];
|
|
13
|
+
const parts = [];
|
|
14
|
+
for (const block of content) {
|
|
15
|
+
if (!block || typeof block !== "object")
|
|
16
|
+
continue;
|
|
17
|
+
const rec = block;
|
|
18
|
+
if (rec.type === "text" && typeof rec.text === "string")
|
|
19
|
+
parts.push(rec.text);
|
|
20
|
+
}
|
|
21
|
+
return parts;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Extract plain text from a tool result object.
|
|
25
|
+
* Handles result.content as array of text blocks or direct text fields.
|
|
26
|
+
*/
|
|
27
|
+
export function extractToolResultText(result) {
|
|
28
|
+
if (!result || typeof result !== "object")
|
|
29
|
+
return;
|
|
30
|
+
const record = result;
|
|
31
|
+
const texts = collectTextContentBlocks(record.content).map((item) => {
|
|
32
|
+
const trimmed = item.trim();
|
|
33
|
+
return trimmed ? trimmed : void 0;
|
|
34
|
+
}).filter((value) => Boolean(value));
|
|
35
|
+
if (texts.length === 0)
|
|
36
|
+
return;
|
|
37
|
+
return texts.join("\n");
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workclaw/openclaw-workclaw",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.20",
|
|
5
5
|
"description": "openclaw-workclaw channel plugin",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
6
8
|
"publishConfig": {
|
|
7
9
|
"access": "public"
|
|
8
10
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"openclaw.plugin.json",
|
|
14
|
+
"skills",
|
|
15
|
+
"templates"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc"
|
|
12
19
|
},
|
|
13
20
|
"dependencies": {
|
|
14
21
|
"undici": "^7.16.0",
|
|
15
22
|
"ws": "^8.19.0",
|
|
16
23
|
"zod": "^4.3.6"
|
|
17
24
|
},
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@types/node": "^20.0.0"
|
|
20
|
-
},
|
|
21
25
|
"openclaw": {
|
|
22
26
|
"extensions": [
|
|
23
|
-
"./index.
|
|
27
|
+
"./dist/index.js"
|
|
24
28
|
],
|
|
25
|
-
"setupEntry": "./setup-entry.
|
|
29
|
+
"setupEntry": "./dist/setup-entry.js",
|
|
26
30
|
"channel": {
|
|
27
31
|
"id": "openclaw-workclaw",
|
|
28
32
|
"label": "openclaw-workclaw",
|
package/index.ts
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
2
|
-
import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
|
-
// @ts-ignore - types from openclaw 4.2, local dev uses 3.13
|
|
5
|
-
import { defineChannelPluginEntry } from "openclaw/plugin-sdk/core";
|
|
6
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
import { fileURLToPath } from "node:url";
|
|
9
|
-
|
|
10
|
-
import { workclawPlugin } from "./src/channel.js";
|
|
11
|
-
import {
|
|
12
|
-
setWorkclawRuntime,
|
|
13
|
-
getWorkclawRuntime,
|
|
14
|
-
getToolResultHint,
|
|
15
|
-
} from "./src/runtime.js";
|
|
16
|
-
import { resolveWorkspaceDir, isDefaultWorkspace } from "./src/api/workspace.js";
|
|
17
|
-
import { createPromptsApiHandler } from "./src/api/prompts-api.js";
|
|
18
|
-
import { createAccountsApiHandler } from "./src/api/accounts-api.js";
|
|
19
|
-
import { createSessionApiHandler } from "./src/api/session-api.js";
|
|
20
|
-
import { createSkillsApiHandler } from "./src/api/skills-api.js";
|
|
21
|
-
import { registerAllOpenclawWorkclawCronTools } from "./src/tools/openclaw-workclaw-cron/index.js";
|
|
22
|
-
import {
|
|
23
|
-
getToolContext,
|
|
24
|
-
setToolCallIdToRunIdMapping,
|
|
25
|
-
deleteToolContext,
|
|
26
|
-
} from "./src/runtime.js";
|
|
27
|
-
import { sendMessageWorkclaw } from "./src/outbound/index.js";
|
|
28
|
-
|
|
29
|
-
// ============================================================================
|
|
30
|
-
// Tool output formatting helpers
|
|
31
|
-
// ============================================================================
|
|
32
|
-
|
|
33
|
-
function formatToolParams(toolName: string | undefined, params: unknown): string {
|
|
34
|
-
if (!params || typeof params !== "object") {
|
|
35
|
-
return "";
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const normalizedToolName = (toolName || "").toLowerCase().trim();
|
|
39
|
-
const p = params as Record<string, unknown>;
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
if (normalizedToolName === "exec" || normalizedToolName === "bash" || normalizedToolName === "shell") {
|
|
43
|
-
const cmd = p.command || p.cmd;
|
|
44
|
-
if (cmd) return `command: ${String(cmd).slice(0, 200)}`;
|
|
45
|
-
} else if (
|
|
46
|
-
normalizedToolName === "read" ||
|
|
47
|
-
normalizedToolName === "file_read" ||
|
|
48
|
-
normalizedToolName === "view"
|
|
49
|
-
) {
|
|
50
|
-
const p2 = p.path;
|
|
51
|
-
if (p2) return `path: ${p2}`;
|
|
52
|
-
} else if (
|
|
53
|
-
normalizedToolName === "write" ||
|
|
54
|
-
normalizedToolName === "file_write" ||
|
|
55
|
-
normalizedToolName === "edit" ||
|
|
56
|
-
normalizedToolName === "patch"
|
|
57
|
-
) {
|
|
58
|
-
const p2 = p.path;
|
|
59
|
-
if (p2) return `path: ${p2}`;
|
|
60
|
-
} else if (
|
|
61
|
-
normalizedToolName === "web_fetch" ||
|
|
62
|
-
normalizedToolName === "fetch" ||
|
|
63
|
-
normalizedToolName === "http_get" ||
|
|
64
|
-
normalizedToolName === "http_request" ||
|
|
65
|
-
normalizedToolName === "open_url" ||
|
|
66
|
-
normalizedToolName === "browser_open" ||
|
|
67
|
-
normalizedToolName === "open"
|
|
68
|
-
) {
|
|
69
|
-
const u = p.url;
|
|
70
|
-
if (u) return `url: ${u}`;
|
|
71
|
-
} else if (
|
|
72
|
-
normalizedToolName === "search" ||
|
|
73
|
-
normalizedToolName === "web_search" ||
|
|
74
|
-
normalizedToolName === "google_search" ||
|
|
75
|
-
normalizedToolName === "browser_search" ||
|
|
76
|
-
normalizedToolName === "browser.search"
|
|
77
|
-
) {
|
|
78
|
-
const q = p.query || p.q || p.search;
|
|
79
|
-
if (q) return `query: ${q}`;
|
|
80
|
-
} else if (
|
|
81
|
-
normalizedToolName === "image_generate" ||
|
|
82
|
-
normalizedToolName === "generate_image" ||
|
|
83
|
-
normalizedToolName === "dalle" ||
|
|
84
|
-
normalizedToolName === "text_to_image"
|
|
85
|
-
) {
|
|
86
|
-
const prompt = p.prompt;
|
|
87
|
-
if (prompt) return `prompt: ${String(prompt).slice(0, 200)}`;
|
|
88
|
-
} else if (
|
|
89
|
-
normalizedToolName === "code_interpreter" ||
|
|
90
|
-
normalizedToolName === "python" ||
|
|
91
|
-
normalizedToolName === "jupyter"
|
|
92
|
-
) {
|
|
93
|
-
const code = p.code;
|
|
94
|
-
if (code) return `code: ${String(code).slice(0, 200)}`;
|
|
95
|
-
} else if (normalizedToolName === "mcp_deliver" || normalizedToolName === "deliver") {
|
|
96
|
-
const target = p.target || p.to;
|
|
97
|
-
if (target) return `target: ${target}`;
|
|
98
|
-
} else {
|
|
99
|
-
const entries = Object.entries(p);
|
|
100
|
-
if (entries.length > 0) {
|
|
101
|
-
return entries
|
|
102
|
-
.map(([k, v]) => {
|
|
103
|
-
const vStr = typeof v === "string" ? v : JSON.stringify(v);
|
|
104
|
-
return vStr.length > 100 ? `${k}: ${vStr.slice(0, 100)}...` : `${k}: ${vStr}`;
|
|
105
|
-
})
|
|
106
|
-
.join("\n");
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
} catch {
|
|
110
|
-
return String(params);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return "";
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function formatToolOutput(toolName: string | undefined, params: unknown, _result: unknown): string {
|
|
117
|
-
return formatToolParams(toolName, params);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// ============================================================================
|
|
121
|
-
// Tool hooks
|
|
122
|
-
// ============================================================================
|
|
123
|
-
|
|
124
|
-
function registerToolHooks(api: OpenClawPluginApi) {
|
|
125
|
-
api.on("agent_end", (event: any, ctx: any) => {
|
|
126
|
-
const { runId } = ctx || {};
|
|
127
|
-
if (runId) {
|
|
128
|
-
deleteToolContext(runId);
|
|
129
|
-
api.logger?.info?.(`[ToolHook] agent_end runId=${runId} cleaned up`);
|
|
130
|
-
}
|
|
131
|
-
return event;
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
api.on("before_tool_call", (event: any, _ctx: any) => {
|
|
135
|
-
api.logger?.info?.(`[ToolHook] before_tool_call event=${JSON.stringify(event)}`);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
api.on("after_tool_call", (event: any, _ctx: any) => {
|
|
139
|
-
api.logger?.info?.(`[ToolHook] after_tool_call event=${JSON.stringify(event)}`);
|
|
140
|
-
const { runId, toolCallId, toolName, params, result } = event || {};
|
|
141
|
-
const toolCtx = runId ? getToolContext(runId) : undefined;
|
|
142
|
-
|
|
143
|
-
if (toolCtx && result) {
|
|
144
|
-
const content = formatToolOutput(toolName, params, result);
|
|
145
|
-
if (content) {
|
|
146
|
-
try {
|
|
147
|
-
const cfg = getWorkclawRuntime().config.loadConfig();
|
|
148
|
-
const formattedToolOutput = {
|
|
149
|
-
name: getToolResultHint(toolName),
|
|
150
|
-
toolName: toolName,
|
|
151
|
-
content: content,
|
|
152
|
-
state: "result",
|
|
153
|
-
};
|
|
154
|
-
sendMessageWorkclaw({
|
|
155
|
-
cfg,
|
|
156
|
-
to: toolCtx.target,
|
|
157
|
-
text: JSON.stringify(formattedToolOutput),
|
|
158
|
-
msgType: "26",
|
|
159
|
-
accountId: toolCtx.accountId,
|
|
160
|
-
openConversationId: toolCtx.openConversationId,
|
|
161
|
-
agentId: toolCtx.agentId,
|
|
162
|
-
replyToMessageId: toolCtx.replyToMessageId,
|
|
163
|
-
}).catch((err) => {
|
|
164
|
-
api.logger?.error?.(`[ToolHook] after_tool_call push failed: ${err}`);
|
|
165
|
-
});
|
|
166
|
-
api.logger?.info?.(`[ToolHook] after_tool_call pushed for toolName=${toolName}`);
|
|
167
|
-
} catch (err) {
|
|
168
|
-
api.logger?.error?.(`[ToolHook] after_tool_call push failed: ${err}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (runId && toolCallId) {
|
|
174
|
-
setToolCallIdToRunIdMapping(toolCallId, runId);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return event;
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
api.on("tool_result_persist", (event: any, _ctx: any) => {
|
|
181
|
-
return { message: event.message };
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
api.logger?.info?.(`[ToolHook] Tool execution hooks registered`);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// ============================================================================
|
|
188
|
-
// Templates
|
|
189
|
-
// ============================================================================
|
|
190
|
-
|
|
191
|
-
const templateNames = ["SOUL.md", "IDENTITY.md"] as const;
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* 获取插件所在目录,兼容 Windows 下的 file:// URL 问题。
|
|
195
|
-
* 4.2 的插件加载器在 Windows 上可能传入不带协议前缀的路径。
|
|
196
|
-
*/
|
|
197
|
-
function getPluginDir(): string {
|
|
198
|
-
try {
|
|
199
|
-
const url = import.meta.url;
|
|
200
|
-
if (!url.startsWith("file://")) {
|
|
201
|
-
// Windows 路径被直接传入(不带 file:// 前缀),直接取目录
|
|
202
|
-
return path.dirname(url);
|
|
203
|
-
}
|
|
204
|
-
return path.dirname(fileURLToPath(url));
|
|
205
|
-
} catch {
|
|
206
|
-
return process.cwd();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
async function writeFileIfMissing(filePath: string, content: string) {
|
|
211
|
-
try {
|
|
212
|
-
await writeFile(filePath, content, { encoding: "utf-8", flag: "wx" });
|
|
213
|
-
} catch (error) {
|
|
214
|
-
if (
|
|
215
|
-
error &&
|
|
216
|
-
typeof error === "object" &&
|
|
217
|
-
"code" in error &&
|
|
218
|
-
(error as NodeJS.ErrnoException).code === "EEXIST"
|
|
219
|
-
) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
throw error;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async function releaseTemplates(api: OpenClawPluginApi) {
|
|
227
|
-
const workspaceDir = resolveWorkspaceDir(api);
|
|
228
|
-
// 模板文件在根目录的 templates/ 中,而不是 dist/templates/
|
|
229
|
-
const currentDir = getPluginDir();
|
|
230
|
-
const templatesDir = path.join(
|
|
231
|
-
currentDir.endsWith("dist") ? path.dirname(currentDir) : currentDir,
|
|
232
|
-
"templates",
|
|
233
|
-
);
|
|
234
|
-
const shouldOverwrite = isDefaultWorkspace(api);
|
|
235
|
-
|
|
236
|
-
await mkdir(workspaceDir, { recursive: true });
|
|
237
|
-
|
|
238
|
-
await Promise.all(
|
|
239
|
-
templateNames.map(async (name) => {
|
|
240
|
-
const sourcePath = path.join(templatesDir, name);
|
|
241
|
-
const targetPath = path.join(workspaceDir, name);
|
|
242
|
-
const content = await readFile(sourcePath, "utf-8");
|
|
243
|
-
if (shouldOverwrite) {
|
|
244
|
-
await writeFile(targetPath, content, { encoding: "utf-8" });
|
|
245
|
-
} else {
|
|
246
|
-
await writeFileIfMissing(targetPath, content);
|
|
247
|
-
}
|
|
248
|
-
}),
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
api.logger.info(`openclaw-workclaw templates ready: ${workspaceDir}`);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// ============================================================================
|
|
255
|
-
// Plugin entry point
|
|
256
|
-
// ============================================================================
|
|
257
|
-
|
|
258
|
-
export default defineChannelPluginEntry({
|
|
259
|
-
id: "openclaw-workclaw",
|
|
260
|
-
name: "openclaw-workclaw",
|
|
261
|
-
description: "智小途 channel plugin",
|
|
262
|
-
configSchema: emptyPluginConfigSchema() as any,
|
|
263
|
-
plugin: workclawPlugin,
|
|
264
|
-
registerFull(api) {
|
|
265
|
-
setWorkclawRuntime(api.runtime);
|
|
266
|
-
|
|
267
|
-
registerAllOpenclawWorkclawCronTools(api);
|
|
268
|
-
registerToolHooks(api);
|
|
269
|
-
|
|
270
|
-
api.registerService({
|
|
271
|
-
id: "openclaw-workclaw-templates",
|
|
272
|
-
start: async () => {
|
|
273
|
-
await releaseTemplates(api);
|
|
274
|
-
},
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
api.registerHttpRoute({
|
|
278
|
-
path: "/openclaw-workclaw/workspace/prompts",
|
|
279
|
-
handler: createPromptsApiHandler(api),
|
|
280
|
-
auth: "plugin",
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
api.registerHttpRoute({
|
|
284
|
-
path: "/openclaw-workclaw/accounts",
|
|
285
|
-
handler: createAccountsApiHandler(api),
|
|
286
|
-
auth: "plugin",
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
api.registerHttpRoute({
|
|
290
|
-
path: "/openclaw-workclaw/skills",
|
|
291
|
-
handler: createSkillsApiHandler(api),
|
|
292
|
-
auth: "plugin",
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
api.registerHttpRoute({
|
|
296
|
-
path: "/openclaw-workclaw/sessions",
|
|
297
|
-
handler: createSessionApiHandler(api),
|
|
298
|
-
auth: "plugin",
|
|
299
|
-
match: "prefix",
|
|
300
|
-
});
|
|
301
|
-
},
|
|
302
|
-
});
|
package/setup-entry.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-ignore - types from openclaw 4.2, local dev uses 3.13
|
|
3
|
-
import { defineSetupPluginEntry } from "openclaw/plugin-sdk/core";
|
|
4
|
-
import { workclawPlugin } from "./src/channel.js";
|
|
5
|
-
|
|
6
|
-
export default defineSetupPluginEntry(workclawPlugin);
|