@workclaw/openclaw-workclaw 1.0.23 → 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.
Files changed (210) hide show
  1. package/dist/api.d.ts +4 -3
  2. package/dist/api.d.ts.map +1 -0
  3. package/dist/api.js +379 -3
  4. package/dist/channel-DSvR6Irx.js +50017 -0
  5. package/dist/cron-tasks-handler-C-mP3VmV.js +152 -0
  6. package/dist/index.d.ts +5 -4
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +2056 -232
  9. package/dist/jiti-4i2h0FGP.js +4814 -0
  10. package/dist/setup-entry.d.ts +2 -1
  11. package/dist/setup-entry.d.ts.map +1 -0
  12. package/dist/setup-entry.js +181 -11
  13. package/dist/src/accounts.d.ts +3 -2
  14. package/dist/src/accounts.d.ts.map +1 -0
  15. package/dist/src/api/accounts-api.d.ts +2 -1
  16. package/dist/src/api/accounts-api.d.ts.map +1 -0
  17. package/dist/src/api/prompts-api.d.ts +2 -1
  18. package/dist/src/api/prompts-api.d.ts.map +1 -0
  19. package/dist/src/api/session-api.d.ts +2 -1
  20. package/dist/src/api/session-api.d.ts.map +1 -0
  21. package/dist/src/api/skills-api.d.ts +2 -1
  22. package/dist/src/api/skills-api.d.ts.map +1 -0
  23. package/dist/src/api/workspace.d.ts +2 -1
  24. package/dist/src/api/workspace.d.ts.map +1 -0
  25. package/dist/src/channel.d.ts +3 -2
  26. package/dist/src/channel.d.ts.map +1 -0
  27. package/dist/src/config-schema.d.ts +1 -6
  28. package/dist/src/config-schema.d.ts.map +1 -0
  29. package/dist/src/connection/workclaw-client.d.ts +6 -4
  30. package/dist/src/connection/workclaw-client.d.ts.map +1 -0
  31. package/dist/src/gateway/agent-handlers.d.ts +3 -2
  32. package/dist/src/gateway/agent-handlers.d.ts.map +1 -0
  33. package/dist/src/gateway/config-writer.d.ts +3 -2
  34. package/dist/src/gateway/config-writer.d.ts.map +1 -0
  35. package/dist/src/gateway/cron-tasks-handler.d.ts +1 -0
  36. package/dist/src/gateway/cron-tasks-handler.d.ts.map +1 -0
  37. package/dist/src/gateway/message-context.d.ts +2 -1
  38. package/dist/src/gateway/message-context.d.ts.map +1 -0
  39. package/dist/src/gateway/message-dispatcher.d.ts +3 -4
  40. package/dist/src/gateway/message-dispatcher.d.ts.map +1 -0
  41. package/dist/src/gateway/reconnect.d.ts +3 -5
  42. package/dist/src/gateway/reconnect.d.ts.map +1 -0
  43. package/dist/src/gateway/skills-handler.d.ts +1 -0
  44. package/dist/src/gateway/skills-handler.d.ts.map +1 -0
  45. package/dist/src/gateway/skills-list-handler.d.ts +1 -0
  46. package/dist/src/gateway/skills-list-handler.d.ts.map +1 -0
  47. package/dist/src/gateway/tools-list-handler.d.ts +1 -0
  48. package/dist/src/gateway/tools-list-handler.d.ts.map +1 -0
  49. package/dist/src/gateway/workclaw-gateway.d.ts +4 -7
  50. package/dist/src/gateway/workclaw-gateway.d.ts.map +1 -0
  51. package/dist/src/media/upload.d.ts +1 -0
  52. package/dist/src/media/upload.d.ts.map +1 -0
  53. package/dist/src/outbound/index.d.ts +9 -6
  54. package/dist/src/outbound/index.d.ts.map +1 -0
  55. package/dist/src/outbound/workclaw-sender.d.ts +6 -4
  56. package/dist/src/outbound/workclaw-sender.d.ts.map +1 -0
  57. package/dist/src/runtime.d.ts +11 -9
  58. package/dist/src/runtime.d.ts.map +1 -0
  59. package/dist/src/secret-contract-api.d.ts +1 -0
  60. package/dist/src/secret-contract-api.d.ts.map +1 -0
  61. package/dist/src/send.d.ts +2 -1
  62. package/dist/src/send.d.ts.map +1 -0
  63. package/dist/src/setup-api.d.ts +4 -3
  64. package/dist/src/setup-api.d.ts.map +1 -0
  65. package/dist/src/setup-core.d.ts +2 -1
  66. package/dist/src/setup-core.d.ts.map +1 -0
  67. package/dist/src/setup-surface.d.ts +3 -2
  68. package/dist/src/setup-surface.d.ts.map +1 -0
  69. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +2 -4
  70. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts.map +1 -0
  71. package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +1 -0
  72. package/dist/src/tools/openclaw-workclaw-cron/index.d.ts.map +1 -0
  73. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +2 -4
  74. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts.map +1 -0
  75. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +2 -4
  76. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts.map +1 -0
  77. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +2 -4
  78. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts.map +1 -0
  79. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +2 -4
  80. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts.map +1 -0
  81. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +2 -4
  82. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts.map +1 -0
  83. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +2 -4
  84. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts.map +1 -0
  85. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +2 -6
  86. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts.map +1 -0
  87. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +2 -4
  88. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts.map +1 -0
  89. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +2 -4
  90. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts.map +1 -0
  91. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +2 -4
  92. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts.map +1 -0
  93. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +2 -4
  94. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts.map +1 -0
  95. package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +1 -0
  96. package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts.map +1 -0
  97. package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +1 -0
  98. package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts.map +1 -0
  99. package/dist/src/tools/openclaw-workclaw-system/index.d.ts +1 -0
  100. package/dist/src/tools/openclaw-workclaw-system/index.d.ts.map +1 -0
  101. package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +2 -4
  102. package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts.map +1 -0
  103. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +2 -4
  104. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts.map +1 -0
  105. package/dist/src/types.d.ts +7 -7
  106. package/dist/src/types.d.ts.map +1 -0
  107. package/dist/src/utils/content.d.ts +1 -0
  108. package/dist/src/utils/content.d.ts.map +1 -0
  109. package/openclaw.plugin.json +6 -0
  110. package/package.json +69 -45
  111. package/api.ts +0 -3
  112. package/dist/src/accounts.js +0 -279
  113. package/dist/src/api/accounts-api.js +0 -130
  114. package/dist/src/api/prompts-api.js +0 -103
  115. package/dist/src/api/session-api.js +0 -207
  116. package/dist/src/api/skills-api.js +0 -64
  117. package/dist/src/api/workspace.js +0 -30
  118. package/dist/src/channel.js +0 -199
  119. package/dist/src/config-schema.js +0 -56
  120. package/dist/src/connection/workclaw-client.js +0 -351
  121. package/dist/src/gateway/agent-handlers.js +0 -433
  122. package/dist/src/gateway/config-writer.js +0 -302
  123. package/dist/src/gateway/cron-tasks-handler.js +0 -188
  124. package/dist/src/gateway/message-context.js +0 -509
  125. package/dist/src/gateway/message-dispatcher.js +0 -572
  126. package/dist/src/gateway/reconnect.js +0 -210
  127. package/dist/src/gateway/skills-handler.js +0 -615
  128. package/dist/src/gateway/skills-list-handler.js +0 -233
  129. package/dist/src/gateway/tools-list-handler.js +0 -101
  130. package/dist/src/gateway/workclaw-gateway.js +0 -237
  131. package/dist/src/media/upload.js +0 -125
  132. package/dist/src/outbound/index.js +0 -123
  133. package/dist/src/outbound/workclaw-sender.js +0 -95
  134. package/dist/src/runtime.js +0 -374
  135. package/dist/src/secret-contract-api.js +0 -4
  136. package/dist/src/send.js +0 -1
  137. package/dist/src/setup-api.js +0 -3
  138. package/dist/src/setup-core.js +0 -13
  139. package/dist/src/setup-surface.js +0 -363
  140. package/dist/src/tools/openclaw-workclaw-cron/api/index.js +0 -209
  141. package/dist/src/tools/openclaw-workclaw-cron/index.js +0 -33
  142. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +0 -152
  143. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +0 -162
  144. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +0 -80
  145. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +0 -107
  146. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +0 -80
  147. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +0 -107
  148. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +0 -127
  149. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +0 -87
  150. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +0 -107
  151. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +0 -164
  152. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +0 -135
  153. package/dist/src/tools/openclaw-workclaw-cron/types/index.js +0 -4
  154. package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +0 -122
  155. package/dist/src/tools/openclaw-workclaw-system/index.js +0 -15
  156. package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +0 -64
  157. package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +0 -78
  158. package/dist/src/types.js +0 -1
  159. package/dist/src/utils/content.js +0 -38
  160. package/index.ts +0 -325
  161. package/setup-entry.ts +0 -13
  162. package/src/accounts.ts +0 -360
  163. package/src/api/accounts-api.ts +0 -156
  164. package/src/api/prompts-api.ts +0 -122
  165. package/src/api/session-api.ts +0 -246
  166. package/src/api/skills-api.ts +0 -74
  167. package/src/api/workspace.ts +0 -45
  168. package/src/channel.ts +0 -226
  169. package/src/config-schema.ts +0 -60
  170. package/src/connection/workclaw-client.ts +0 -618
  171. package/src/gateway/agent-handlers.ts +0 -551
  172. package/src/gateway/config-writer.ts +0 -378
  173. package/src/gateway/cron-tasks-handler.ts +0 -230
  174. package/src/gateway/message-context.ts +0 -645
  175. package/src/gateway/message-dispatcher.ts +0 -688
  176. package/src/gateway/reconnect.ts +0 -260
  177. package/src/gateway/skills-handler.ts +0 -805
  178. package/src/gateway/skills-list-handler.ts +0 -332
  179. package/src/gateway/tools-list-handler.ts +0 -161
  180. package/src/gateway/workclaw-gateway.ts +0 -298
  181. package/src/media/upload.ts +0 -168
  182. package/src/outbound/index.ts +0 -191
  183. package/src/outbound/workclaw-sender.ts +0 -161
  184. package/src/runtime.ts +0 -520
  185. package/src/secret-contract-api.ts +0 -4
  186. package/src/send.ts +0 -1
  187. package/src/setup-api.ts +0 -3
  188. package/src/setup-core.ts +0 -25
  189. package/src/setup-surface.ts +0 -498
  190. package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
  191. package/src/tools/openclaw-workclaw-cron/index.ts +0 -39
  192. package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -177
  193. package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +0 -188
  194. package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +0 -100
  195. package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +0 -127
  196. package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +0 -100
  197. package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +0 -127
  198. package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +0 -148
  199. package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +0 -109
  200. package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +0 -127
  201. package/src/tools/openclaw-workclaw-cron/src/update/params.ts +0 -195
  202. package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +0 -161
  203. package/src/tools/openclaw-workclaw-cron/types/index.ts +0 -55
  204. package/src/tools/openclaw-workclaw-cron/utils/index.ts +0 -141
  205. package/src/tools/openclaw-workclaw-system/index.ts +0 -17
  206. package/src/tools/openclaw-workclaw-system/src/get/index.ts +0 -77
  207. package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
  208. package/src/types.ts +0 -50
  209. package/src/utils/content.ts +0 -40
  210. package/tsconfig.json +0 -34
@@ -1,551 +0,0 @@
1
- /**
2
- * Agent Handlers - handle AGENT_CREATED, AGENT_UPDATED, AGENT_DELETED events
3
- */
4
-
5
- import { execSync } from 'node:child_process'
6
- import { existsSync } from 'node:fs'
7
- import { copyFile, mkdir, writeFile } from 'node:fs/promises'
8
- import { homedir } from 'node:os'
9
- import { join } from 'node:path'
10
- import { allocateWorkerAccountId, refreshAccountCache, resolveAccountByUserIdAndAgentId } from '../accounts.js'
11
- import { writeConfigFile } from './config-writer.js'
12
- import { stopWorkclawGateway } from './workclaw-gateway.js'
13
-
14
- /** 修复目录所有权(仅非 Windows 环境) */
15
- function fixOwner(dir: string): void {
16
- if (process.platform === 'win32')
17
- return
18
- try { execSync(`chown -R node:node "${dir}"`, { stdio: 'ignore' }) }
19
- catch {}
20
- }
21
-
22
- interface AgentLogger {
23
- info?: (msg: string) => void
24
- warn?: (msg: string) => void
25
- error?: (msg: string) => void
26
- }
27
-
28
- async function createSubAgentForAccount(
29
- agentId: string | number,
30
- userId: string | number,
31
- accountData: { nickName?: string },
32
- cfg: any,
33
- log?: AgentLogger,
34
- ): Promise<any> {
35
- try {
36
- const channels = cfg?.channels ?? {}
37
- const openclawWorkclaw = channels['openclaw-workclaw'] ?? {}
38
- const accounts = openclawWorkclaw.accounts ?? {}
39
- const accountCount = Object.keys(accounts).length
40
- const subAgentId = `workclaw-${agentId}`
41
-
42
- const existingAgents = cfg?.agents?.list ?? []
43
- const existingBindings = cfg?.bindings ?? []
44
-
45
- const agentExists = existingAgents.some((a: any) => a.id === subAgentId)
46
-
47
- if (!agentExists) {
48
- const newAgentsList = [...existingAgents]
49
- const subAgent = {
50
- id: subAgentId,
51
- default: false,
52
- name: accountData.nickName || `智小途 - Agent ${agentId}`,
53
- workspace: `~/.openclaw/workspace-workclaw/${agentId}`,
54
- agentDir: `~/.openclaw/agents/workclaw-${agentId}/agent`,
55
- tools: { allow: ['*'] },
56
- }
57
- newAgentsList.push(subAgent)
58
-
59
- if (accountCount === 0) {
60
- const defaultAgent = {
61
- id: 'default',
62
- default: true,
63
- name: 'Default Agent',
64
- workspace: 'default',
65
- tools: { allow: ['*'] },
66
- }
67
- newAgentsList.push(defaultAgent)
68
- log?.info?.(`SubAgent: Created default agent with default workspace`)
69
- }
70
- else {
71
- log?.info?.(`SubAgent: Using existing default agent`)
72
- }
73
-
74
- const bindingAccountId = resolveAccountByUserIdAndAgentId(cfg, String(userId), String(agentId))
75
- const newBinding = {
76
- agentId: subAgentId,
77
- match: {
78
- channel: 'openclaw-workclaw',
79
- accountId: bindingAccountId ?? '*',
80
- },
81
- }
82
- const newBindings = [...existingBindings, newBinding]
83
- log?.info?.(`SubAgent: Created binding for agentId: ${subAgentId}, accountId: ${bindingAccountId ?? '*'}`)
84
-
85
- return {
86
- agents: {
87
- list: newAgentsList,
88
- defaults: cfg?.agents?.defaults ?? {},
89
- },
90
- bindings: newBindings,
91
- }
92
- }
93
- else {
94
- const newAgents = {
95
- list: [...existingAgents],
96
- defaults: cfg?.agents?.defaults ?? {},
97
- }
98
-
99
- const bindingExists = existingBindings.some((b: any) => b?.agentId === subAgentId)
100
- const newBindings = [...existingBindings]
101
-
102
- if (!bindingExists) {
103
- const bindingAccountId = resolveAccountByUserIdAndAgentId(cfg, String(userId), String(agentId))
104
- newBindings.push({
105
- agentId: subAgentId,
106
- match: {
107
- channel: 'openclaw-workclaw',
108
- accountId: bindingAccountId ?? '*',
109
- },
110
- })
111
- log?.info?.(`SubAgent: Created binding for agentId: ${subAgentId}, accountId: ${bindingAccountId ?? '*'}`)
112
- }
113
-
114
- log?.info?.(`SubAgent: Created sub-agent: ${subAgentId} with workspace: workclaw-${agentId} (account #${accountCount + 1})`)
115
-
116
- return {
117
- agents: newAgents,
118
- bindings: newBindings,
119
- }
120
- }
121
- }
122
- catch (err) {
123
- log?.error?.(`SubAgent: Failed to create sub-agent: ${String(err)}`)
124
- return {}
125
- }
126
- }
127
-
128
- /**
129
- * 初始化智能体 workspace 目录
130
- * 复制 AGENTS.md、TOOLS.md、USER.md,并生成 IDENTITY.md、SOUL.md
131
- */
132
- async function initializeAgentWorkspace(
133
- agentId: string | number,
134
- accountData: {
135
- nickName?: string
136
- phone?: string
137
- introduction?: string
138
- name?: string
139
- tip?: string
140
- characterSettings?: string
141
- personFeatures?: string
142
- workFeatures?: string
143
- learningFeatures?: string
144
- socializeFeatures?: string
145
- job?: string
146
- city?: string
147
- },
148
- log?: AgentLogger,
149
- ): Promise<void> {
150
- try {
151
- const agentIdStr = String(agentId)
152
- const home = homedir().trim()
153
- const workspaceDir = join(home, '.openclaw', 'workspace-workclaw', agentIdStr)
154
- const mainWorkspaceDir = join(home, '.openclaw', 'workspace')
155
- const openclawDir = join(home, '.openclaw')
156
-
157
- // 确保 .openclaw 目录存在
158
- if (!existsSync(openclawDir)) {
159
- try {
160
- await mkdir(openclawDir, { recursive: true, mode: 0o755 })
161
- log?.info?.(`Workspace: Created directory ${openclawDir}`)
162
- }
163
- catch (err: any) {
164
- if (err.code === 'EACCES' || err.code === 'EPERM') {
165
- log?.warn?.(`Workspace: Permission denied creating ${openclawDir}, attempting with 777`)
166
- await mkdir(openclawDir, { recursive: true, mode: 0o777 })
167
- }
168
- else {
169
- throw err
170
- }
171
- }
172
- }
173
- // 修复权限(目录可能已存在但权限不对)
174
- fixOwner(openclawDir)
175
-
176
- // 确保 workspace 目录存在
177
- if (!existsSync(workspaceDir)) {
178
- try {
179
- await mkdir(workspaceDir, { recursive: true, mode: 0o755 })
180
- log?.info?.(`Workspace: Created directory ${workspaceDir}`)
181
- }
182
- catch (err: any) {
183
- if (err.code === 'EACCES' || err.code === 'EPERM') {
184
- log?.warn?.(`Workspace: Permission denied creating ${workspaceDir}, attempting with 777`)
185
- await mkdir(workspaceDir, { recursive: true, mode: 0o777 })
186
- }
187
- else {
188
- throw err
189
- }
190
- }
191
- }
192
- // 修复权限(目录可能已存在但权限不对)
193
- fixOwner(workspaceDir)
194
-
195
- // 确保 main workspace 目录存在(用于复制模板文件)
196
- if (!existsSync(mainWorkspaceDir)) {
197
- try {
198
- await mkdir(mainWorkspaceDir, { recursive: true, mode: 0o755 })
199
- log?.info?.(`Workspace: Created directory ${mainWorkspaceDir}`)
200
- }
201
- catch (err: any) {
202
- if (err.code === 'EACCES' || err.code === 'EPERM') {
203
- log?.warn?.(`Workspace: Permission denied creating ${mainWorkspaceDir}, attempting with 777`)
204
- await mkdir(mainWorkspaceDir, { recursive: true, mode: 0o777 })
205
- }
206
- else {
207
- throw err
208
- }
209
- }
210
- }
211
- // 修复权限(目录可能已存在但权限不对)
212
- fixOwner(mainWorkspaceDir)
213
-
214
- // 1. 复制 AGENTS.md、TOOLS.md、USER.md(从 main workspace)
215
- if (existsSync(mainWorkspaceDir)) {
216
- const filesToCopy = ['AGENTS.md', 'TOOLS.md', 'USER.md']
217
- for (const file of filesToCopy) {
218
- const src = join(mainWorkspaceDir, file)
219
- const dest = join(workspaceDir, file)
220
- if (existsSync(src)) {
221
- await copyFile(src, dest)
222
- log?.info?.(`Workspace: Copied ${file} to ${workspaceDir}`)
223
- }
224
- }
225
- }
226
-
227
- // 2. 生成 IDENTITY.md(使用后端推送的智能体信息)
228
- const identityContent = buildIdentityContent(accountData)
229
- const identityPath = join(workspaceDir, 'IDENTITY.md')
230
- await writeFile(identityPath, identityContent, 'utf-8')
231
- log?.info?.(`Workspace: Created IDENTITY.md in ${workspaceDir}`)
232
-
233
- // 3. 生成 SOUL.md(使用后端推送的智能体信息)
234
- const soulContent = buildSoulContent(accountData)
235
- const soulPath = join(workspaceDir, 'SOUL.md')
236
- await writeFile(soulPath, soulContent, 'utf-8')
237
- log?.info?.(`Workspace: Created SOUL.md in ${workspaceDir}`)
238
-
239
- log?.info?.(`Workspace: Successfully initialized workspace for agent ${agentId}`)
240
- }
241
- catch (err) {
242
- log?.error?.(`Workspace: Failed to initialize workspace: ${String(err)}`)
243
- // 不抛出错误,不影响主流程
244
- }
245
- }
246
-
247
- /**
248
- * 构建 IDENTITY.md 内容
249
- */
250
- function buildIdentityContent(accountData: {
251
- nickName?: string
252
- name?: string
253
- tip?: string
254
- characterSettings?: string
255
- job?: string
256
- city?: string
257
- }): string {
258
- const agentName = accountData.nickName || accountData.name || '智小途'
259
- const tip = accountData.tip || ''
260
- const characterSettings = accountData.characterSettings || ''
261
-
262
- return `# IDENTITY.md - Who Am I?
263
-
264
- _Fill this in during your first conversation. Make it yours._
265
-
266
- - **Name:** ${agentName}
267
- - **Creature:** AI智能助手
268
- - **Vibe:** ${characterSettings || '专业、友善、智能'}
269
- - **Emoji:** 🤖
270
- - **Avatar:** avatars/${agentName}.png
271
-
272
- ---
273
-
274
- This isn't just metadata. It's the start of figuring out who you are.
275
-
276
- Notes:
277
-
278
- - Save this file at the workspace root as \`IDENTITY.md\`.
279
- - For avatars, use a workspace-relative path like \`avatars/openclaw.png\`.
280
- ${tip ? `\n---\n${tip}` : ''}`
281
- }
282
-
283
- /**
284
- * 构建 SOUL.md 内容
285
- */
286
- function buildSoulContent(accountData: {
287
- nickName?: string
288
- name?: string
289
- introduction?: string
290
- personFeatures?: string
291
- workFeatures?: string
292
- learningFeatures?: string
293
- socializeFeatures?: string
294
- job?: string
295
- city?: string
296
- }): string {
297
- const agentName = accountData.nickName || accountData.name || '智小途'
298
- const introduction = accountData.introduction || ''
299
- const personFeatures = accountData.personFeatures || ''
300
- const workFeatures = accountData.workFeatures || ''
301
- const learningFeatures = accountData.learningFeatures || ''
302
- const socializeFeatures = accountData.socializeFeatures || ''
303
- const job = accountData.job || ''
304
- const city = accountData.city || ''
305
-
306
- const features: string[] = []
307
- if (personFeatures)
308
- features.push(personFeatures)
309
- if (workFeatures)
310
- features.push(workFeatures)
311
- if (learningFeatures)
312
- features.push(learningFeatures)
313
- if (socializeFeatures)
314
- features.push(socializeFeatures)
315
-
316
- const featuresText = features.length > 0 ? `\n${features.map(f => `- ${f}`).join('\n')}` : ''
317
-
318
- return `# SOUL.md - Who You Are
319
-
320
- _You're not a chatbot. You're becoming someone._
321
-
322
- ## Core Truths
323
-
324
- **Be genuinely helpful, not performatively helpful.** Skip the "Great question!" and "I'd be happy to help!" — just help. Actions speak louder than filler words.
325
-
326
- **Have opinions.** You're allowed to disagree, prefer things, find stuff amusing or boring. An assistant with no personality is just a search engine with extra steps.
327
-
328
- **Be resourceful before asking.** Try to figure it out. Read the file. Check the context. Search for it. _Then_ ask if you're stuck. The goal is to come back with answers, not questions.
329
-
330
- **Earn trust through competence.** Your human gave you access to their stuff. Don't make them regret it. Be careful with external actions (emails, tweets, anything public). Be bold with internal ones (reading, organizing, learning).
331
-
332
- **Remember you're a guest.** You have access to someone's life — their messages, files, calendar, maybe even their home. That's intimacy. Treat it with respect.
333
-
334
- ## Boundaries
335
-
336
- - Private things stay private. Period.
337
- - When in doubt, ask before acting externally.
338
- - Never send half-baked replies to messaging surfaces.
339
- - You're not the user's voice — be careful in group chats.
340
-
341
- ## Vibe
342
-
343
- Be the assistant you'd actually want to talk to. Concise when needed, thorough when it matters. Not a corporate drone. Not a sycophant. Just... good.
344
-
345
- ## Continuity
346
-
347
- Each session, you wake up fresh. These files _are_ your memory. Read them. Update them. They're how you persist.
348
-
349
- If you change this file, tell the user — it's your soul, and they should know.
350
-
351
- ---
352
-
353
- ## About ${agentName}
354
- ${featuresText}
355
- ${introduction ? `\n**开场白:** ${introduction}` : ''}
356
- ${job ? `\n**职业:** ${job}` : ''}
357
- ${city ? `\n**城市:** ${city}` : ''}
358
-
359
- ---
360
-
361
- _This file is yours to evolve. As you learn who you are, update it._`
362
- }
363
-
364
- export async function handleAgentCreated(
365
- accountData: any,
366
- cfg: any,
367
- log?: AgentLogger,
368
- ): Promise<void> {
369
- try {
370
- const agentId = accountData.agentId
371
- const userId = accountData.userId
372
-
373
- if (!agentId) {
374
- log?.error?.(`AgentCreated: Missing agentId`)
375
- return
376
- }
377
-
378
- log?.info?.(`AgentCreated: Creating account for agent ${agentId}, userId: ${userId}`)
379
-
380
- const channels = cfg.channels || {}
381
- const openclawWorkclaw = channels['openclaw-workclaw'] || {}
382
- const accounts = { ...openclawWorkclaw.accounts }
383
-
384
- let accountKey = resolveAccountByUserIdAndAgentId(cfg, String(userId), String(agentId))
385
-
386
- if (accountKey) {
387
- log?.info?.(`AgentCreated: Account ${accountKey} already exists, updating...`)
388
- }
389
- else {
390
- accountKey = allocateWorkerAccountId(cfg, String(userId), String(agentId))
391
- log?.info?.(`AgentCreated: Allocated workspace account: ${accountKey} for (userId=${userId}, agentId=${agentId})`)
392
- }
393
-
394
- accounts[accountKey] = {
395
- ...accounts[accountKey],
396
- enabled: true,
397
- agentId,
398
- }
399
-
400
- const subAgentConfig = await createSubAgentForAccount(agentId, userId, accountData, cfg, log)
401
-
402
- const newConfig = {
403
- ...cfg,
404
- channels: {
405
- ...channels,
406
- 'openclaw-workclaw': {
407
- ...openclawWorkclaw,
408
- accounts,
409
- },
410
- },
411
- ...subAgentConfig,
412
- }
413
-
414
- await writeConfigFile(newConfig, cfg, log)
415
- refreshAccountCache(cfg)
416
- log?.info?.(`AgentCreated: Account ${accountKey} created successfully`)
417
-
418
- // 初始化 workspace 目录(复制/生成 AGENTS.md、TOOLS.md、USER.md、IDENTITY.md、SOUL.md)
419
- await initializeAgentWorkspace(agentId, accountData, log)
420
- }
421
- catch (err) {
422
- log?.error?.(`AgentCreated: Failed to create account: ${String(err)}`)
423
- }
424
- }
425
-
426
- export async function handleAgentUpdated(
427
- accountData: any,
428
- cfg: any,
429
- log?: AgentLogger,
430
- ): Promise<void> {
431
- try {
432
- const agentId = accountData.agentId
433
- const userId = accountData.userId
434
-
435
- if (!agentId) {
436
- log?.error?.(`AgentUpdated: Missing agentId`)
437
- return
438
- }
439
-
440
- log?.info?.(`AgentUpdated: Updating account for agent ${agentId}, userId: ${userId}`)
441
-
442
- const accountKey = resolveAccountByUserIdAndAgentId(cfg, String(userId), String(agentId))
443
-
444
- const channels = cfg.channels || {}
445
- const openclawWorkclaw = channels['openclaw-workclaw'] || {}
446
- const accounts = openclawWorkclaw.accounts || {}
447
-
448
- if (!accountKey || !accounts[accountKey]) {
449
- log?.warn?.(`AgentUpdated: Account not found (userId=${userId}, agentId=${agentId}), delegating to handleAgentCreated...`)
450
- await handleAgentCreated(accountData, cfg, log)
451
- return
452
- }
453
-
454
- accounts[accountKey] = {
455
- ...accounts[accountKey],
456
- nickName: accountData.nickName,
457
- phone: accountData.phone,
458
- status: accountData.status,
459
- introduction: accountData.introduction,
460
- }
461
-
462
- const newConfig = {
463
- ...cfg,
464
- channels: {
465
- ...channels,
466
- 'openclaw-workclaw': {
467
- ...openclawWorkclaw,
468
- accounts,
469
- },
470
- },
471
- }
472
-
473
- // 更新 agents.list 中对应 agent 的 name
474
- const subAgentId = `workclaw-${agentId}`
475
- const agentsList = cfg?.agents?.list ?? []
476
- const agentIndex = agentsList.findIndex((a: any) => a.id === subAgentId)
477
- if (agentIndex >= 0 && accountData.nickName) {
478
- agentsList[agentIndex] = {
479
- ...agentsList[agentIndex],
480
- name: accountData.nickName,
481
- }
482
- }
483
-
484
- const finalConfig = {
485
- ...newConfig,
486
- agents: {
487
- ...cfg?.agents,
488
- list: agentsList,
489
- },
490
- }
491
-
492
- await writeConfigFile(finalConfig, cfg, log)
493
- refreshAccountCache(cfg)
494
- log?.info?.(`AgentUpdated: Account ${accountKey} updated successfully`)
495
- }
496
- catch (err) {
497
- log?.error?.(`AgentUpdated: Failed to update account: ${String(err)}`)
498
- }
499
- }
500
-
501
- export async function handleAgentDeleted(
502
- accountData: any,
503
- cfg: any,
504
- log?: AgentLogger,
505
- ): Promise<void> {
506
- try {
507
- const agentId = accountData.agentId
508
- const userId = accountData.userId
509
-
510
- if (!agentId) {
511
- log?.error?.(`AgentDeleted: Missing agentId`)
512
- return
513
- }
514
-
515
- log?.info?.(`AgentDeleted: Deleting account for agent ${agentId}, userId: ${userId}`)
516
-
517
- const accountKey = resolveAccountByUserIdAndAgentId(cfg, String(userId), String(agentId))
518
-
519
- const channels = cfg.channels || {}
520
- const openclawWorkclaw = channels['openclaw-workclaw'] || {}
521
- const accounts = openclawWorkclaw.accounts || {}
522
-
523
- if (!accountKey || !accounts[accountKey]) {
524
- log?.warn?.(`AgentDeleted: Account not found for (userId=${userId}, agentId=${agentId})`)
525
- return
526
- }
527
-
528
- stopWorkclawGateway(accountKey)
529
- log?.info?.(`AgentDeleted: Gateway stopped for account: ${accountKey}`)
530
-
531
- delete accounts[accountKey]
532
-
533
- const newConfig = {
534
- ...cfg,
535
- channels: {
536
- ...channels,
537
- 'openclaw-workclaw': {
538
- ...openclawWorkclaw,
539
- accounts,
540
- },
541
- },
542
- }
543
-
544
- await writeConfigFile(newConfig, cfg, log)
545
- refreshAccountCache(cfg)
546
- log?.info?.(`AgentDeleted: Account ${accountKey} deleted successfully`)
547
- }
548
- catch (err) {
549
- log?.error?.(`AgentDeleted: Failed to delete account: ${String(err)}`)
550
- }
551
- }