@eyeclaw/eyeclaw 2.0.6 → 2.0.8
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/package.json +1 -1
- package/src/channel.ts +8 -38
- package/src/client.ts +6 -5
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -191,7 +191,7 @@ export const eyeclawPlugin: ChannelPlugin<ResolvedEyeClawAccount> = {
|
|
|
191
191
|
'agent',
|
|
192
192
|
'--session-id', 'eyeclaw-web-chat',
|
|
193
193
|
'--message', message,
|
|
194
|
-
|
|
194
|
+
// No --json flag: use plain text streaming output
|
|
195
195
|
])
|
|
196
196
|
|
|
197
197
|
let outputBuffer = ''
|
|
@@ -205,32 +205,13 @@ export const eyeclawPlugin: ChannelPlugin<ResolvedEyeClawAccount> = {
|
|
|
205
205
|
const text = data.toString()
|
|
206
206
|
outputBuffer += text
|
|
207
207
|
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
// Send the text in chunks
|
|
216
|
-
const chunkSize = 50 // Send ~50 chars at a time
|
|
217
|
-
for (let i = 0; i < response.length; i += chunkSize) {
|
|
218
|
-
const chunk = response.substring(i, i + chunkSize)
|
|
219
|
-
client.sendStreamChunk('stream_chunk', streamId, chunk)
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
outputBuffer = '' // Clear buffer after successful parse
|
|
223
|
-
} catch (e) {
|
|
224
|
-
// Not valid JSON yet, check if we have complete lines to send
|
|
225
|
-
const lines = outputBuffer.split('\n')
|
|
226
|
-
// Keep last incomplete line in buffer
|
|
227
|
-
if (lines.length > 1) {
|
|
228
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
229
|
-
if (lines[i].trim()) {
|
|
230
|
-
client.sendStreamChunk('stream_chunk', streamId, lines[i] + '\n')
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
outputBuffer = lines[lines.length - 1]
|
|
208
|
+
// Send text chunks as they arrive (real-time streaming)
|
|
209
|
+
const lines = text.split('\n')
|
|
210
|
+
for (const line of lines) {
|
|
211
|
+
const trimmed = line.trim()
|
|
212
|
+
if (trimmed && !trimmed.startsWith('{') && !trimmed.startsWith('[')) {
|
|
213
|
+
// Skip JSON-like lines, send only plain text
|
|
214
|
+
client.sendStreamChunk('stream_chunk', streamId, line + '\n')
|
|
234
215
|
}
|
|
235
216
|
}
|
|
236
217
|
} catch (error) {
|
|
@@ -251,17 +232,6 @@ export const eyeclawPlugin: ChannelPlugin<ResolvedEyeClawAccount> = {
|
|
|
251
232
|
// Handle process completion
|
|
252
233
|
agentProcess.on('close', (code: number) => {
|
|
253
234
|
try {
|
|
254
|
-
// Send any remaining buffered content
|
|
255
|
-
if (outputBuffer.trim()) {
|
|
256
|
-
try {
|
|
257
|
-
const parsed = JSON.parse(outputBuffer)
|
|
258
|
-
const response = parsed.result?.payloads?.[0]?.text || outputBuffer.trim()
|
|
259
|
-
client.sendStreamChunk('stream_chunk', streamId, response)
|
|
260
|
-
} catch (e) {
|
|
261
|
-
client.sendStreamChunk('stream_chunk', streamId, outputBuffer.trim())
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
235
|
// Send stream_end event
|
|
266
236
|
client.sendStreamChunk('stream_end', streamId, '')
|
|
267
237
|
|
package/src/client.ts
CHANGED
|
@@ -130,7 +130,7 @@ export class EyeClawClient {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
private handleExecuteCommand(message: Record<string, unknown>): void {
|
|
133
|
+
private async handleExecuteCommand(message: Record<string, unknown>): Promise<void> {
|
|
134
134
|
const command = message.command as string
|
|
135
135
|
const params = (message.params as Record<string, unknown>) || {}
|
|
136
136
|
|
|
@@ -144,8 +144,8 @@ export class EyeClawClient {
|
|
|
144
144
|
// Send user message acknowledgment
|
|
145
145
|
this.sendLog('info', `收到消息: ${userMessage}`)
|
|
146
146
|
|
|
147
|
-
// Call OpenClaw Agent via callback
|
|
148
|
-
this.handleChatMessage(userMessage)
|
|
147
|
+
// Call OpenClaw Agent via callback and wait for completion
|
|
148
|
+
await this.handleChatMessage(userMessage)
|
|
149
149
|
break
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -184,11 +184,12 @@ export class EyeClawClient {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
private handleChatMessage(userMessage: string): void {
|
|
187
|
+
private async handleChatMessage(userMessage: string): Promise<void> {
|
|
188
188
|
// This will be called by OpenClaw channel plugin via sendAgent
|
|
189
189
|
if (this.sendAgentCallback) {
|
|
190
190
|
this.logger.info('🤖 Calling OpenClaw Agent...')
|
|
191
|
-
this.sendAgentCallback(userMessage)
|
|
191
|
+
await this.sendAgentCallback(userMessage)
|
|
192
|
+
this.logger.info('✅ OpenClaw Agent completed')
|
|
192
193
|
} else {
|
|
193
194
|
// Fallback: simple echo if not running in OpenClaw context
|
|
194
195
|
this.logger.warn('No OpenClaw Agent available, using echo mode')
|