pixel-office-openclaw 0.1.0 → 0.1.1

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 (3) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -2
  3. package/server.js +16 -51
package/README.md CHANGED
@@ -45,7 +45,7 @@ npx pixel-office-openclaw
45
45
  ### From source
46
46
 
47
47
  ```bash
48
- git clone https://github.com/neomatrix25/pixel-office.git
48
+ git clone https://github.com/neomatrix25/pixel-office-openclaw.git
49
49
  cd pixel-office
50
50
  npm install
51
51
  npm run build
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixel-office-openclaw",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Watch your OpenClaw AI agents work in a pixel-art virtual office",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,7 +34,7 @@
34
34
  ],
35
35
  "repository": {
36
36
  "type": "git",
37
- "url": "https://github.com/neomatrix25/pixel-office"
37
+ "url": "https://github.com/neomatrix25/pixel-office-openclaw"
38
38
  },
39
39
  "author": "Tridents Lab",
40
40
  "license": "MIT",
package/server.js CHANGED
@@ -238,59 +238,24 @@ app.post('/api/send', async (req, res) => {
238
238
  const safeAgentId = String(agentId).replace(/[^a-zA-Z0-9_-]/g, '')
239
239
  const safeMessage = String(message).slice(0, 2000)
240
240
 
241
- // Use OpenClaw gateway API to send message to the agent's session
242
- const GATEWAY_URL = process.env.OPENCLAW_GATEWAY_URL || 'http://127.0.0.1:18789'
243
- const GATEWAY_TOKEN = process.env.OPENCLAW_GATEWAY_TOKEN || ''
244
-
245
- // Find the agent's most recent session key
246
- const sessionKey = getActiveSessionKey(safeAgentId)
247
-
241
+ // Send via OpenClaw CLI (gateway is WebSocket-only, no REST endpoint)
248
242
  try {
249
- // Use sessions_send via the gateway API
250
- const payload = {
251
- message: safeMessage,
252
- ...(sessionKey ? { label: safeAgentId } : { label: safeAgentId }),
243
+ console.log(`[bridge] Sending to ${safeAgentId} via CLI: ${safeMessage.slice(0, 50)}...`)
244
+ const cliResult = execFileSync('openclaw', ['agent', '--agent', safeAgentId, '--message', safeMessage, '--json'],
245
+ { timeout: 120000, stdio: ['pipe', 'pipe', 'pipe'], encoding: 'utf-8' }
246
+ )
247
+ console.log(`[bridge] Sent to ${safeAgentId} (CLI OK)`)
248
+ try {
249
+ const parsed = JSON.parse(cliResult)
250
+ const reply = parsed.result?.payloads?.[0]?.text
251
+ || parsed.reply || parsed.text || parsed.result || cliResult.trim()
252
+ return res.json({ ok: true, agentId: safeAgentId, reply })
253
+ } catch {
254
+ return res.json({ ok: true, agentId: safeAgentId, reply: cliResult.trim() })
253
255
  }
254
-
255
- const resp = await fetch(`${GATEWAY_URL}/api/sessions/send`, {
256
- method: 'POST',
257
- headers: {
258
- 'Content-Type': 'application/json',
259
- ...(GATEWAY_TOKEN ? { 'Authorization': `Bearer ${GATEWAY_TOKEN}` } : {}),
260
- },
261
- body: JSON.stringify(payload),
262
- })
263
-
264
- if (!resp.ok) {
265
- const body = await resp.text()
266
- console.error(`[bridge] Gateway send failed for ${safeAgentId}: ${resp.status} ${body.slice(0, 200)}`)
267
- // Fallback to CLI — use --json to capture the agent's reply
268
- try {
269
- const cliResult = execFileSync('openclaw', ['agent', '--agent', safeAgentId, '--message', safeMessage, '--json'],
270
- { timeout: 120000, stdio: ['pipe', 'pipe', 'pipe'], encoding: 'utf-8' }
271
- )
272
- console.log(`[bridge] Sent to ${safeAgentId} (CLI): ${safeMessage.slice(0, 50)}...`)
273
- try {
274
- const parsed = JSON.parse(cliResult)
275
- // OpenClaw CLI returns { result: { payloads: [{ text: "..." }] } }
276
- const reply = parsed.result?.payloads?.[0]?.text
277
- || parsed.reply || parsed.text || parsed.result || cliResult.trim()
278
- return res.json({ ok: true, agentId: safeAgentId, reply })
279
- } catch {
280
- return res.json({ ok: true, agentId: safeAgentId, reply: cliResult.trim() })
281
- }
282
- } catch (cliErr) {
283
- return res.status(500).json({ error: 'Failed to send message', detail: cliErr.message?.slice(0, 200) || body.slice(0, 200) })
284
- }
285
- }
286
-
287
- const result = await resp.json()
288
- console.log(`[bridge] Sent to ${safeAgentId} via gateway: ${safeMessage.slice(0, 50)}...`)
289
- res.json({ ok: true, agentId: safeAgentId, reply: result.reply || result.text || null })
290
- } catch (err) {
291
- const detail = err.message || 'Send failed'
292
- console.error(`[bridge] Send error for ${safeAgentId}:`, detail)
293
- res.status(500).json({ error: 'Failed to send message', detail: detail.slice(0, 200) })
256
+ } catch (cliErr) {
257
+ console.error(`[bridge] CLI send failed for ${safeAgentId}:`, cliErr.message?.slice(0, 200))
258
+ return res.status(500).json({ error: 'Failed to send message', detail: cliErr.message?.slice(0, 200) || 'CLI error' })
294
259
  }
295
260
  })
296
261