@workclaw/openclaw-workclaw 1.0.20 → 1.0.202

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.
Files changed (53) hide show
  1. package/api.ts +3 -0
  2. package/index.ts +326 -0
  3. package/package.json +3 -11
  4. package/setup-entry.ts +13 -0
  5. package/src/accounts.ts +360 -0
  6. package/src/api/accounts-api.ts +156 -0
  7. package/src/api/prompts-api.ts +122 -0
  8. package/src/api/session-api.ts +246 -0
  9. package/src/api/skills-api.ts +74 -0
  10. package/src/api/workspace.ts +45 -0
  11. package/src/channel.ts +226 -0
  12. package/src/config-schema.ts +62 -0
  13. package/src/connection/workclaw-client.ts +618 -0
  14. package/src/gateway/agent-handlers.ts +551 -0
  15. package/src/gateway/config-writer.ts +378 -0
  16. package/src/gateway/cron-tasks-handler.ts +230 -0
  17. package/src/gateway/message-context.ts +645 -0
  18. package/src/gateway/message-dispatcher.ts +688 -0
  19. package/src/gateway/reconnect.ts +260 -0
  20. package/src/gateway/skills-handler.ts +805 -0
  21. package/src/gateway/skills-list-handler.ts +332 -0
  22. package/src/gateway/tools-list-handler.ts +161 -0
  23. package/src/gateway/workclaw-gateway.ts +305 -0
  24. package/src/media/upload.ts +168 -0
  25. package/src/outbound/index.ts +191 -0
  26. package/src/outbound/workclaw-sender.ts +161 -0
  27. package/src/runtime.ts +520 -0
  28. package/src/secret-contract-api.ts +4 -0
  29. package/src/send.ts +1 -0
  30. package/src/setup-api.ts +3 -0
  31. package/src/setup-core.ts +25 -0
  32. package/src/setup-surface.ts +499 -0
  33. package/src/tools/openclaw-workclaw-cron/api/index.ts +326 -0
  34. package/src/tools/openclaw-workclaw-cron/index.ts +39 -0
  35. package/src/tools/openclaw-workclaw-cron/src/add/params.ts +177 -0
  36. package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +188 -0
  37. package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +100 -0
  38. package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +127 -0
  39. package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +100 -0
  40. package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +127 -0
  41. package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +148 -0
  42. package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +109 -0
  43. package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +127 -0
  44. package/src/tools/openclaw-workclaw-cron/src/update/params.ts +195 -0
  45. package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +161 -0
  46. package/src/tools/openclaw-workclaw-cron/types/index.ts +55 -0
  47. package/src/tools/openclaw-workclaw-cron/utils/index.ts +141 -0
  48. package/src/tools/openclaw-workclaw-system/index.ts +17 -0
  49. package/src/tools/openclaw-workclaw-system/src/get/index.ts +77 -0
  50. package/src/tools/openclaw-workclaw-system/src/token/index.ts +93 -0
  51. package/src/types.ts +52 -0
  52. package/src/utils/content.ts +40 -0
  53. package/tsconfig.json +34 -0
package/api.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { workclawPlugin } from './src/channel.js'
2
+ export * from './src/setup-core.js'
3
+ export * from './src/setup-surface.js'
package/index.ts ADDED
@@ -0,0 +1,326 @@
1
+ import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
2
+ import { mkdir, readFile, writeFile } from 'node:fs/promises'
3
+ import path from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
5
+ import { emptyPluginConfigSchema } from 'openclaw/plugin-sdk'
6
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
+ // @ts-ignore - types from openclaw 4.2, local dev uses 3.13
8
+ import { defineChannelPluginEntry } from 'openclaw/plugin-sdk/core'
9
+
10
+ import { createAccountsApiHandler } from './src/api/accounts-api.js'
11
+ import { createPromptsApiHandler } from './src/api/prompts-api.js'
12
+ import { createSessionApiHandler } from './src/api/session-api.js'
13
+ import { createSkillsApiHandler } from './src/api/skills-api.js'
14
+ import { isDefaultWorkspace, resolveWorkspaceDir } from './src/api/workspace.js'
15
+ import { workclawPlugin } from './src/channel.js'
16
+ import { sendMessageWorkclaw } from './src/outbound/index.js'
17
+ import {
18
+ deleteToolContext,
19
+ getToolContext,
20
+ getToolResultHint,
21
+ getWorkclawLogger,
22
+ getWorkclawRuntime,
23
+ setToolCallIdToRunIdMapping,
24
+ setWorkclawRuntime,
25
+ } from './src/runtime.js'
26
+
27
+ import { registerAllOpenclawWorkclawCronTools } from './src/tools/openclaw-workclaw-cron/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)
45
+ return `command: ${String(cmd).slice(0, 200)}`
46
+ }
47
+ else if (
48
+ normalizedToolName === 'read'
49
+ || normalizedToolName === 'file_read'
50
+ || normalizedToolName === 'view'
51
+ ) {
52
+ const p2 = p.path
53
+ if (p2)
54
+ return `path: ${p2}`
55
+ }
56
+ else if (
57
+ normalizedToolName === 'write'
58
+ || normalizedToolName === 'file_write'
59
+ || normalizedToolName === 'edit'
60
+ || normalizedToolName === 'patch'
61
+ ) {
62
+ const p2 = p.path
63
+ if (p2)
64
+ return `path: ${p2}`
65
+ }
66
+ else if (
67
+ normalizedToolName === 'web_fetch'
68
+ || normalizedToolName === 'fetch'
69
+ || normalizedToolName === 'http_get'
70
+ || normalizedToolName === 'http_request'
71
+ || normalizedToolName === 'open_url'
72
+ || normalizedToolName === 'browser_open'
73
+ || normalizedToolName === 'open'
74
+ ) {
75
+ const u = p.url
76
+ if (u)
77
+ return `url: ${u}`
78
+ }
79
+ else if (
80
+ normalizedToolName === 'search'
81
+ || normalizedToolName === 'web_search'
82
+ || normalizedToolName === 'google_search'
83
+ || normalizedToolName === 'browser_search'
84
+ || normalizedToolName === 'browser.search'
85
+ ) {
86
+ const q = p.query || p.q || p.search
87
+ if (q)
88
+ return `query: ${q}`
89
+ }
90
+ else if (
91
+ normalizedToolName === 'image_generate'
92
+ || normalizedToolName === 'generate_image'
93
+ || normalizedToolName === 'dalle'
94
+ || normalizedToolName === 'text_to_image'
95
+ ) {
96
+ const prompt = p.prompt
97
+ if (prompt)
98
+ return `prompt: ${String(prompt).slice(0, 200)}`
99
+ }
100
+ else if (
101
+ normalizedToolName === 'code_interpreter'
102
+ || normalizedToolName === 'python'
103
+ || normalizedToolName === 'jupyter'
104
+ ) {
105
+ const code = p.code
106
+ if (code)
107
+ return `code: ${String(code).slice(0, 200)}`
108
+ }
109
+ else if (normalizedToolName === 'mcp_deliver' || normalizedToolName === 'deliver') {
110
+ const target = p.target || p.to
111
+ if (target)
112
+ return `target: ${target}`
113
+ }
114
+ else {
115
+ const entries = Object.entries(p)
116
+ if (entries.length > 0) {
117
+ return entries
118
+ .map(([k, v]) => {
119
+ const vStr = typeof v === 'string' ? v : JSON.stringify(v)
120
+ return vStr.length > 100 ? `${k}: ${vStr.slice(0, 100)}...` : `${k}: ${vStr}`
121
+ })
122
+ .join('\n')
123
+ }
124
+ }
125
+ }
126
+ catch {
127
+ return String(params)
128
+ }
129
+
130
+ return ''
131
+ }
132
+
133
+ function formatToolOutput(toolName: string | undefined, params: unknown, _result: unknown): string {
134
+ return formatToolParams(toolName, params)
135
+ }
136
+
137
+ // ============================================================================
138
+ // Tool hooks
139
+ // ============================================================================
140
+
141
+ function registerToolHooks(api: OpenClawPluginApi) {
142
+ api.on('agent_end', (event: any, ctx: any) => {
143
+ const { runId } = ctx || {}
144
+ if (runId) {
145
+ deleteToolContext(runId)
146
+ api.logger?.info?.(`[ToolHook] agent_end runId=${runId} cleaned up`)
147
+ }
148
+ return event
149
+ })
150
+
151
+ api.on('before_tool_call', (event: any, _ctx: any) => {
152
+ api.logger?.info?.(`[ToolHook] before_tool_call event=${JSON.stringify(event)}`)
153
+ })
154
+
155
+ api.on('after_tool_call', (event: any, _ctx: any) => {
156
+ api.logger?.info?.(`[ToolHook] after_tool_call event=${JSON.stringify(event)}`)
157
+ const { runId, toolCallId, toolName, params, result } = event || {}
158
+ const toolCtx = runId ? getToolContext(runId) : undefined
159
+
160
+ if (toolCtx && result) {
161
+ const content = formatToolOutput(toolName, params, result)
162
+ if (content) {
163
+ try {
164
+ const cfg = getWorkclawRuntime().config.loadConfig()
165
+ const formattedToolOutput = {
166
+ name: getToolResultHint(toolName),
167
+ toolName,
168
+ content,
169
+ state: 'result',
170
+ }
171
+ sendMessageWorkclaw({
172
+ cfg,
173
+ to: toolCtx.target,
174
+ text: JSON.stringify(formattedToolOutput),
175
+ msgType: '26',
176
+ accountId: toolCtx.accountId,
177
+ openConversationId: toolCtx.openConversationId,
178
+ agentId: toolCtx.agentId,
179
+ replyToMessageId: toolCtx.replyToMessageId,
180
+ last: false,
181
+ source: 'after_tool_call',
182
+ }).catch((err) => {
183
+ api.logger?.error?.(`[ToolHook] after_tool_call push failed: ${err}`)
184
+ })
185
+ api.logger?.info?.(`[ToolHook] after_tool_call pushed for toolName=${toolName}`)
186
+ }
187
+ catch (err) {
188
+ api.logger?.error?.(`[ToolHook] after_tool_call push failed: ${err}`)
189
+ }
190
+ }
191
+ }
192
+
193
+ if (runId && toolCallId) {
194
+ setToolCallIdToRunIdMapping(toolCallId, runId)
195
+ }
196
+
197
+ return event
198
+ })
199
+
200
+ api.on('tool_result_persist', (event: any, _ctx: any) => {
201
+ return { message: event.message }
202
+ })
203
+
204
+ api.logger?.info?.(`[ToolHook] Tool execution hooks registered`)
205
+ }
206
+
207
+ // ============================================================================
208
+ // Templates
209
+ // ============================================================================
210
+
211
+ const templateNames = ['SOUL.md', 'IDENTITY.md'] as const
212
+
213
+ /**
214
+ * 获取插件所在目录,兼容 Windows 下的 file:// URL 问题。
215
+ * 4.2 的插件加载器在 Windows 上可能传入不带协议前缀的路径。
216
+ */
217
+ function getPluginDir(): string {
218
+ try {
219
+ const url = import.meta.url
220
+ if (!url.startsWith('file://')) {
221
+ // Windows 路径被直接传入(不带 file:// 前缀),直接取目录
222
+ return path.dirname(url)
223
+ }
224
+ return path.dirname(fileURLToPath(url))
225
+ }
226
+ catch {
227
+ return process.cwd()
228
+ }
229
+ }
230
+
231
+ async function writeFileIfMissing(filePath: string, content: string) {
232
+ try {
233
+ await writeFile(filePath, content, { encoding: 'utf-8', flag: 'wx' })
234
+ }
235
+ catch (error) {
236
+ if (
237
+ error
238
+ && typeof error === 'object'
239
+ && 'code' in error
240
+ && (error as NodeJS.ErrnoException).code === 'EEXIST'
241
+ ) {
242
+ return
243
+ }
244
+ throw error
245
+ }
246
+ }
247
+
248
+ async function releaseTemplates(api: OpenClawPluginApi) {
249
+ const workspaceDir = resolveWorkspaceDir(api)
250
+ getWorkclawLogger().info(`workspaceDir: ${workspaceDir}`)
251
+ // 模板文件在根目录的 templates/ 中,而不是 dist/templates/
252
+ const currentDir = getPluginDir()
253
+ const templatesDir = path.join(
254
+ currentDir.endsWith('dist') ? path.dirname(currentDir) : currentDir,
255
+ 'templates',
256
+ )
257
+ const shouldOverwrite = isDefaultWorkspace(api)
258
+
259
+ await mkdir(workspaceDir, { recursive: true })
260
+
261
+ await Promise.all(
262
+ templateNames.map(async (name) => {
263
+ const sourcePath = path.join(templatesDir, name)
264
+ const targetPath = path.join(workspaceDir, name)
265
+ const content = await readFile(sourcePath, 'utf-8')
266
+ if (shouldOverwrite) {
267
+ await writeFile(targetPath, content, { encoding: 'utf-8' })
268
+ }
269
+ else {
270
+ await writeFileIfMissing(targetPath, content)
271
+ }
272
+ }),
273
+ )
274
+
275
+ api.logger.info(`openclaw-workclaw templates ready: ${workspaceDir}`)
276
+ }
277
+
278
+ // ============================================================================
279
+ // Plugin entry point
280
+ // ============================================================================
281
+
282
+ export default defineChannelPluginEntry({
283
+ id: 'openclaw-workclaw',
284
+ name: 'openclaw-workclaw',
285
+ description: '智小途 channel plugin',
286
+ configSchema: emptyPluginConfigSchema() as any,
287
+ plugin: workclawPlugin,
288
+ registerFull(api) {
289
+ setWorkclawRuntime(api.runtime)
290
+
291
+ registerAllOpenclawWorkclawCronTools(api)
292
+ registerToolHooks(api)
293
+
294
+ api.registerService({
295
+ id: 'openclaw-workclaw-templates',
296
+ start: async () => {
297
+ await releaseTemplates(api)
298
+ },
299
+ })
300
+
301
+ api.registerHttpRoute({
302
+ path: '/openclaw-workclaw/workspace/prompts',
303
+ handler: createPromptsApiHandler(api),
304
+ auth: 'plugin',
305
+ })
306
+
307
+ api.registerHttpRoute({
308
+ path: '/openclaw-workclaw/accounts',
309
+ handler: createAccountsApiHandler(api),
310
+ auth: 'plugin',
311
+ })
312
+
313
+ api.registerHttpRoute({
314
+ path: '/openclaw-workclaw/skills',
315
+ handler: createSkillsApiHandler(api),
316
+ auth: 'plugin',
317
+ })
318
+
319
+ api.registerHttpRoute({
320
+ path: '/openclaw-workclaw/sessions',
321
+ handler: createSessionApiHandler(api),
322
+ auth: 'plugin',
323
+ match: 'prefix',
324
+ })
325
+ },
326
+ })
package/package.json CHANGED
@@ -1,19 +1,11 @@
1
1
  {
2
2
  "name": "@workclaw/openclaw-workclaw",
3
3
  "type": "module",
4
- "version": "1.0.20",
4
+ "version": "1.0.202",
5
5
  "description": "openclaw-workclaw channel plugin",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
6
  "publishConfig": {
9
7
  "access": "public"
10
8
  },
11
- "files": [
12
- "dist",
13
- "openclaw.plugin.json",
14
- "skills",
15
- "templates"
16
- ],
17
9
  "scripts": {
18
10
  "build": "tsc"
19
11
  },
@@ -24,9 +16,9 @@
24
16
  },
25
17
  "openclaw": {
26
18
  "extensions": [
27
- "./dist/index.js"
19
+ "./index.ts"
28
20
  ],
29
- "setupEntry": "./dist/setup-entry.js",
21
+ "setupEntry": "./src/setup-entry.ts",
30
22
  "channel": {
31
23
  "id": "openclaw-workclaw",
32
24
  "label": "openclaw-workclaw",
package/setup-entry.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { defineBundledChannelSetupEntry } from 'openclaw/plugin-sdk/channel-entry-contract'
2
+
3
+ export default defineBundledChannelSetupEntry({
4
+ importMetaUrl: import.meta.url,
5
+ plugin: {
6
+ specifier: './api.js',
7
+ exportName: 'workclawPlugin',
8
+ },
9
+ secrets: {
10
+ specifier: './src/secret-contract-api.js',
11
+ exportName: 'channelSecrets',
12
+ },
13
+ })