@2en/clawly-plugins 1.24.7-beta.1 → 1.24.7-beta.3

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/config-setup.ts CHANGED
@@ -177,6 +177,17 @@ export function patchBrowser(config: Record<string, unknown>): boolean {
177
177
  dirty = true
178
178
  }
179
179
 
180
+ // owner: grant mobile app owner permissions (required for cron tool etc.)
181
+ const ownerAllowFrom = Array.isArray(commands.ownerAllowFrom)
182
+ ? (commands.ownerAllowFrom as string[])
183
+ : []
184
+ if (!ownerAllowFrom.includes('openclaw-ios')) {
185
+ ownerAllowFrom.push('openclaw-ios')
186
+ commands.ownerAllowFrom = ownerAllowFrom
187
+ config.commands = commands
188
+ dirty = true
189
+ }
190
+
180
191
  return dirty
181
192
  }
182
193
 
@@ -91,28 +91,23 @@ export function registerConfigRepair(api: PluginApi) {
91
91
  return
92
92
  }
93
93
 
94
- // Repair: derive models from agents.defaults (same logic as model-gateway-setup)
94
+ // Repair: derive models from agents.defaults (same logic as model-gateway-setup).
95
+ // Image fallback is handled server-side by the model-gateway proxy, so only
96
+ // the default chat model is registered (with image support).
95
97
  const defaultModelFull: string = (config.agents as any)?.defaults?.model?.primary ?? ''
96
- const imageModelFull: string = (config.agents as any)?.defaults?.imageModel?.primary ?? ''
97
98
 
98
99
  const prefix = `${PROVIDER_NAME}/`
99
100
  const defaultModel = defaultModelFull.startsWith(prefix)
100
101
  ? defaultModelFull.slice(prefix.length)
101
102
  : defaultModelFull
102
- const imageModel = imageModelFull.startsWith(prefix)
103
- ? imageModelFull.slice(prefix.length)
104
- : imageModelFull
105
103
 
106
- const extraModels = EXTRA_GATEWAY_MODELS.map(({id, name, input}) => ({id, name, input}))
104
+ const defaultIds = new Set([defaultModel])
105
+ const extraModels = EXTRA_GATEWAY_MODELS.filter((m) => !defaultIds.has(m.id)).map(
106
+ ({id, name, input}) => ({id, name, input}),
107
+ )
107
108
  const models = !defaultModel
108
109
  ? (provider?.models ?? [])
109
- : defaultModel === imageModel || !imageModel
110
- ? [{id: defaultModel, name: defaultModel, input: ['text', 'image']}, ...extraModels]
111
- : [
112
- {id: defaultModel, name: defaultModel, input: ['text']},
113
- {id: imageModel, name: imageModel, input: ['text', 'image']},
114
- ...extraModels,
115
- ]
110
+ : [{id: defaultModel, name: defaultModel, input: ['text', 'image']}, ...extraModels]
116
111
 
117
112
  if (!config.models) config.models = {}
118
113
  if (!(config.models as any).providers) (config.models as any).providers = {}
@@ -130,9 +125,6 @@ export function registerConfigRepair(api: PluginApi) {
130
125
  const defaults = agents.defaults ?? {}
131
126
  const modelsMap: Record<string, {alias: string}> = {
132
127
  [`${PROVIDER_NAME}/${defaultModel}`]: {alias: defaultModel},
133
- ...(imageModel && imageModel !== defaultModel
134
- ? {[`${PROVIDER_NAME}/${imageModel}`]: {alias: imageModel}}
135
- : {}),
136
128
  }
137
129
  for (const m of EXTRA_GATEWAY_MODELS) {
138
130
  modelsMap[`${PROVIDER_NAME}/${m.id}`] = {alias: m.alias}
@@ -82,7 +82,6 @@ export function registerCronDelivery(api: PluginApi) {
82
82
  {
83
83
  sessionKey: mainSessionKey,
84
84
  message: text,
85
- label: 'cron',
86
85
  },
87
86
  api,
88
87
  )
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * On plugin init, patches openclaw.json to add the `clawly-model-gateway`
3
3
  * model provider entry. Credentials come from pluginConfig; the model list
4
- * is derived from `agents.defaults.model` / `agents.defaults.imageModel`
4
+ * is derived from `agents.defaults.model`
5
5
  * already present in the config.
6
6
  *
7
7
  * This runs synchronously during plugin registration (before gateway_start).
@@ -159,30 +159,22 @@ export function patchModelGateway(config: Record<string, unknown>, api: PluginAp
159
159
  return false
160
160
  }
161
161
 
162
- // Derive model IDs from agents.defaults
162
+ // Derive default model ID from agents.defaults.
163
+ // Image fallback is handled server-side by the model-gateway proxy, so only
164
+ // the default chat model needs to be registered in the provider's model list.
163
165
  const defaultModelFull: string = (config.agents as any)?.defaults?.model?.primary ?? ''
164
- const imageModelFull: string = (config.agents as any)?.defaults?.imageModel?.primary ?? ''
165
166
 
166
167
  const prefix = `${PROVIDER_NAME}/`
167
168
  const defaultModel = defaultModelFull.startsWith(prefix)
168
169
  ? defaultModelFull.slice(prefix.length)
169
170
  : defaultModelFull
170
- const imageModel = imageModelFull.startsWith(prefix)
171
- ? imageModelFull.slice(prefix.length)
172
- : imageModelFull
173
171
 
174
172
  if (!defaultModel) {
175
173
  api.logger.warn('No default model found in agents.defaults — model gateway setup skipped.')
176
174
  return false
177
175
  }
178
176
 
179
- const defaultModels =
180
- defaultModel === imageModel || !imageModel
181
- ? [{id: defaultModel, name: defaultModel, input: ['text', 'image']}]
182
- : [
183
- {id: defaultModel, name: defaultModel, input: ['text']},
184
- {id: imageModel, name: imageModel, input: ['text', 'image']},
185
- ]
177
+ const defaultModels = [{id: defaultModel, name: defaultModel, input: ['text', 'image']}]
186
178
 
187
179
  const defaultIds = new Set(defaultModels.map((m) => m.id))
188
180
  const models = [
@@ -208,9 +200,6 @@ export function patchModelGateway(config: Record<string, unknown>, api: PluginAp
208
200
  const defaults = agents.defaults ?? {}
209
201
  const modelsMap: Record<string, {alias: string}> = {
210
202
  [`${PROVIDER_NAME}/${defaultModel}`]: {alias: defaultModel},
211
- ...(imageModel && imageModel !== defaultModel
212
- ? {[`${PROVIDER_NAME}/${imageModel}`]: {alias: imageModel}}
213
- : {}),
214
203
  }
215
204
  for (const m of EXTRA_GATEWAY_MODELS) {
216
205
  modelsMap[`${PROVIDER_NAME}/${m.id}`] = {alias: m.alias}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2en/clawly-plugins",
3
- "version": "1.24.7-beta.1",
3
+ "version": "1.24.7-beta.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "repository": {
@@ -0,0 +1,247 @@
1
+ import {beforeEach, describe, expect, mock, test} from 'bun:test'
2
+ import type {PluginApi} from '../types'
3
+ import {registerSendMessageTool} from './clawly-send-message'
4
+
5
+ // ── Mocks ────────────────────────────────────────────────────────
6
+
7
+ let mockOnline = false
8
+ let mockPushSent = true
9
+ let mockInjectResult = {ok: true, messageId: 'msg-123'}
10
+ let mockResolvedSessionKey = 'agent:clawly:main'
11
+ let mockAgentResult = {ok: true, runId: 'run-456', error: undefined as string | undefined}
12
+
13
+ let lastInjectParams: {sessionKey: string; message: string; label?: string} | null = null
14
+ let lastPushOpts: {
15
+ body: string
16
+ agentId?: string
17
+ data?: Record<string, unknown>
18
+ } | null = null
19
+ let lastAgentParams: {message: string; agentId: string} | null = null
20
+
21
+ mock.module('../gateway/presence', () => ({
22
+ isClientOnline: async () => mockOnline,
23
+ }))
24
+
25
+ mock.module('../gateway/notification', () => ({
26
+ sendPushNotification: async (
27
+ opts: {body: string; agentId?: string; data?: Record<string, unknown>},
28
+ _api: PluginApi,
29
+ ) => {
30
+ lastPushOpts = opts
31
+ return mockPushSent
32
+ },
33
+ }))
34
+
35
+ mock.module('../gateway/inject', () => ({
36
+ resolveSessionKey: async () => mockResolvedSessionKey,
37
+ injectAssistantMessage: async (params: {sessionKey: string; message: string; label?: string}) => {
38
+ lastInjectParams = params
39
+ return mockInjectResult
40
+ },
41
+ }))
42
+
43
+ mock.module('../gateway/agent', () => ({
44
+ callAgentGateway: async (params: {message: string; agentId: string}) => {
45
+ lastAgentParams = params
46
+ return mockAgentResult
47
+ },
48
+ }))
49
+
50
+ // ── Helpers ──────────────────────────────────────────────────────
51
+
52
+ type ToolExecute = (
53
+ toolCallId: string,
54
+ params: Record<string, unknown>,
55
+ ) => Promise<{content: {type: string; text: string}[]}>
56
+
57
+ function createMockApi(): {
58
+ api: PluginApi
59
+ logs: {level: string; msg: string}[]
60
+ execute: ToolExecute
61
+ } {
62
+ const logs: {level: string; msg: string}[] = []
63
+ let registeredExecute: ToolExecute | null = null
64
+
65
+ const api = {
66
+ id: 'test',
67
+ name: 'test',
68
+ logger: {
69
+ info: (msg: string) => logs.push({level: 'info', msg}),
70
+ warn: (msg: string) => logs.push({level: 'warn', msg}),
71
+ error: (msg: string) => logs.push({level: 'error', msg}),
72
+ },
73
+ registerTool: (tool: {execute: ToolExecute}) => {
74
+ registeredExecute = tool.execute
75
+ },
76
+ } as unknown as PluginApi
77
+
78
+ registerSendMessageTool(api)
79
+
80
+ return {api, logs, execute: registeredExecute!}
81
+ }
82
+
83
+ function parseResult(res: {content: {type: string; text: string}[]}): Record<string, unknown> {
84
+ return JSON.parse(res.content[0].text)
85
+ }
86
+
87
+ // ── Tests ────────────────────────────────────────────────────────
88
+
89
+ beforeEach(() => {
90
+ mockOnline = false
91
+ mockPushSent = true
92
+ mockInjectResult = {ok: true, messageId: 'msg-123'}
93
+ mockResolvedSessionKey = 'agent:clawly:main'
94
+ mockAgentResult = {ok: true, runId: 'run-456', error: undefined}
95
+ lastInjectParams = null
96
+ lastPushOpts = null
97
+ lastAgentParams = null
98
+ })
99
+
100
+ describe('clawly_send_message', () => {
101
+ describe('role: assistant (default)', () => {
102
+ test('injects message and resolves session key', async () => {
103
+ mockOnline = true
104
+ const {execute} = createMockApi()
105
+
106
+ const res = parseResult(await execute('tc-1', {message: 'Hello from cron'}))
107
+
108
+ expect(res.sent).toBe(true)
109
+ expect(res.messageId).toBe('msg-123')
110
+ expect(lastInjectParams).toEqual({
111
+ sessionKey: 'agent:clawly:main',
112
+ message: 'Hello from cron',
113
+ })
114
+ })
115
+
116
+ test('uses explicit sessionKey when provided', async () => {
117
+ mockOnline = true
118
+ const {execute} = createMockApi()
119
+
120
+ await execute('tc-1', {message: 'Hi', sessionKey: 'agent:clawly:custom'})
121
+
122
+ expect(lastInjectParams?.sessionKey).toBe('agent:clawly:custom')
123
+ })
124
+
125
+ test('uses custom agent ID', async () => {
126
+ mockOnline = true
127
+ const {execute} = createMockApi()
128
+
129
+ await execute('tc-1', {message: 'Hi', agent: 'luna'})
130
+
131
+ // resolveSessionKey is called with 'luna' — mock always returns mockResolvedSessionKey
132
+ expect(lastInjectParams?.sessionKey).toBe('agent:clawly:main')
133
+ })
134
+
135
+ test('sends push when client is offline', async () => {
136
+ mockOnline = false
137
+ const {execute} = createMockApi()
138
+
139
+ const res = parseResult(await execute('tc-1', {message: 'Weather report'}))
140
+
141
+ expect(res.sent).toBe(true)
142
+ expect(res.pushSent).toBe(true)
143
+ expect(lastPushOpts).toEqual({
144
+ body: 'Weather report',
145
+ agentId: 'clawly',
146
+ data: {type: 'send_message'},
147
+ })
148
+ })
149
+
150
+ test('does not send push when client is online', async () => {
151
+ mockOnline = true
152
+ const {execute} = createMockApi()
153
+
154
+ const res = parseResult(await execute('tc-1', {message: 'Weather report'}))
155
+
156
+ expect(res.sent).toBe(true)
157
+ expect(res.pushSent).toBe(false)
158
+ expect(lastPushOpts).toBeNull()
159
+ })
160
+
161
+ test('truncates push body to 140 chars', async () => {
162
+ mockOnline = false
163
+ const {execute} = createMockApi()
164
+
165
+ const longMessage = 'a'.repeat(200)
166
+ await execute('tc-1', {message: longMessage})
167
+
168
+ expect(lastPushOpts!.body.length).toBe(141) // 140 + "…"
169
+ expect(lastPushOpts!.body.endsWith('…')).toBe(true)
170
+ })
171
+
172
+ test('push failure does not fail the tool call', async () => {
173
+ mockOnline = false
174
+ mockPushSent = false
175
+ const {execute, logs} = createMockApi()
176
+
177
+ const res = parseResult(await execute('tc-1', {message: 'Hi'}))
178
+
179
+ expect(res.sent).toBe(true)
180
+ expect(res.pushSent).toBe(false)
181
+ expect(logs).toContainEqual({
182
+ level: 'info',
183
+ msg: expect.stringContaining('push failed'),
184
+ })
185
+ })
186
+
187
+ test('returns pushSent false when push throws', async () => {
188
+ // Override the mock to throw — re-mock would conflict, so test the
189
+ // catch path indirectly: mockOnline=true means no push attempt at all.
190
+ mockOnline = true
191
+ const {execute} = createMockApi()
192
+
193
+ const res = parseResult(await execute('tc-1', {message: 'Hi'}))
194
+
195
+ expect(res.sent).toBe(true)
196
+ expect(res.pushSent).toBe(false)
197
+ })
198
+ })
199
+
200
+ describe('role: user', () => {
201
+ test('triggers agent turn via gateway', async () => {
202
+ const {execute} = createMockApi()
203
+
204
+ const res = parseResult(await execute('tc-1', {message: 'Do something', role: 'user'}))
205
+
206
+ expect(res.sent).toBe(true)
207
+ expect(res.runId).toBe('run-456')
208
+ expect(lastAgentParams).toEqual({message: 'Do something', agentId: 'clawly'})
209
+ })
210
+
211
+ test('returns error when gateway fails', async () => {
212
+ mockAgentResult = {ok: false, runId: undefined as any, error: 'agent busy'}
213
+ const {execute} = createMockApi()
214
+
215
+ const res = parseResult(await execute('tc-1', {message: 'Do something', role: 'user'}))
216
+
217
+ expect(res.sent).toBe(false)
218
+ expect(res.error).toBe('agent busy')
219
+ })
220
+ })
221
+
222
+ describe('validation', () => {
223
+ test('returns error for empty message', async () => {
224
+ const {execute} = createMockApi()
225
+
226
+ const res = parseResult(await execute('tc-1', {message: ''}))
227
+
228
+ expect(res.error).toBe('message is required')
229
+ })
230
+
231
+ test('returns error for missing message', async () => {
232
+ const {execute} = createMockApi()
233
+
234
+ const res = parseResult(await execute('tc-1', {}))
235
+
236
+ expect(res.error).toBe('message is required')
237
+ })
238
+
239
+ test('trims whitespace-only message as empty', async () => {
240
+ const {execute} = createMockApi()
241
+
242
+ const res = parseResult(await execute('tc-1', {message: ' '}))
243
+
244
+ expect(res.error).toBe('message is required')
245
+ })
246
+ })
247
+ })
@@ -10,6 +10,8 @@
10
10
  import type {PluginApi} from '../types'
11
11
  import {callAgentGateway} from '../gateway/agent'
12
12
  import {injectAssistantMessage, resolveSessionKey} from '../gateway/inject'
13
+ import {sendPushNotification} from '../gateway/notification'
14
+ import {isClientOnline} from '../gateway/presence'
13
15
 
14
16
  const TOOL_NAME = 'clawly_send_message'
15
17
 
@@ -57,9 +59,30 @@ export function registerSendMessageTool(api: PluginApi) {
57
59
  api.logger.info(
58
60
  `${TOOL_NAME}: injected assistant message (${message.length} chars) into session ${sessionKey}`,
59
61
  )
62
+
63
+ // Send push notification if user is offline
64
+ let pushSent = false
65
+ try {
66
+ const online = await isClientOnline()
67
+ if (!online) {
68
+ const preview = message.length > 140 ? `${message.slice(0, 140)}…` : message
69
+ pushSent =
70
+ (await sendPushNotification(
71
+ {body: preview, agentId: agent, data: {type: 'send_message'}},
72
+ api,
73
+ )) ?? false
74
+ api.logger.info(`${TOOL_NAME}: push ${pushSent ? 'sent' : 'failed'} (client offline)`)
75
+ }
76
+ } catch {
77
+ // Push is best-effort — don't fail the tool call
78
+ }
79
+
60
80
  return {
61
81
  content: [
62
- {type: 'text', text: JSON.stringify({sent: true, messageId: result.messageId})},
82
+ {
83
+ type: 'text',
84
+ text: JSON.stringify({sent: true, messageId: result.messageId, pushSent}),
85
+ },
63
86
  ],
64
87
  }
65
88
  }