@lythos/agent-adapter-deepseek-serve 0.9.36 → 0.9.37
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/deepseek-serve.ts +20 -26
package/package.json
CHANGED
package/src/deepseek-serve.ts
CHANGED
|
@@ -172,43 +172,37 @@ interface DeepSeekEvent {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
async function collectThreadOutput(threadId: string, port: number, timeoutMs: number): Promise<string> {
|
|
175
|
+
// Wait for turn to appear (non-blocking, short poll)
|
|
175
176
|
const deadline = Date.now() + timeoutMs
|
|
177
|
+
let lastSeq = 0
|
|
176
178
|
let output = ''
|
|
179
|
+
let completed = false
|
|
177
180
|
|
|
178
181
|
while (Date.now() < deadline) {
|
|
179
|
-
//
|
|
180
|
-
const
|
|
181
|
-
`http://127.0.0.1:${port}/v1/threads/${threadId}`,
|
|
182
|
+
// Get events since last checkpoint (incremental, not from 0 each time)
|
|
183
|
+
const eventsRes = await fetch(
|
|
184
|
+
`http://127.0.0.1:${port}/v1/threads/${threadId}/events?since_seq=${lastSeq}`,
|
|
182
185
|
{ signal: AbortSignal.timeout(3000) }
|
|
183
186
|
).catch(() => null)
|
|
184
|
-
if (!threadRes?.ok) { await new Promise(r => setTimeout(r, 2000)); continue }
|
|
185
|
-
|
|
186
|
-
const thread = await threadRes.json()
|
|
187
|
-
const turnId = thread.thread?.latest_turn_id ?? thread.latest_turn_id
|
|
188
|
-
if (!turnId) { await new Promise(r => setTimeout(r, 2000)); continue }
|
|
189
187
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (line.startsWith('data: ')) {
|
|
202
|
-
try {
|
|
203
|
-
const event: DeepSeekEvent = JSON.parse(line.slice(6))
|
|
204
|
-
if (event.payload?.delta) output += event.payload.delta
|
|
205
|
-
if (event.event === 'turn.completed') completed = true
|
|
206
|
-
} catch {}
|
|
188
|
+
if (eventsRes?.ok) {
|
|
189
|
+
const text = await eventsRes.text()
|
|
190
|
+
for (const line of text.split('\n')) {
|
|
191
|
+
if (line.startsWith('data: ')) {
|
|
192
|
+
try {
|
|
193
|
+
const event: DeepSeekEvent = JSON.parse(line.slice(6))
|
|
194
|
+
if (event.seq > lastSeq) lastSeq = event.seq
|
|
195
|
+
if (event.payload?.delta) output += event.payload.delta
|
|
196
|
+
if (event.event === 'turn.completed') completed = true
|
|
197
|
+
} catch {}
|
|
198
|
+
}
|
|
207
199
|
}
|
|
208
200
|
}
|
|
201
|
+
|
|
209
202
|
if (completed && output) return output
|
|
210
203
|
|
|
211
|
-
|
|
204
|
+
// Adaptive poll: shorter interval when events are flowing
|
|
205
|
+
await new Promise(r => setTimeout(r, 500))
|
|
212
206
|
}
|
|
213
207
|
|
|
214
208
|
return output || '(timeout)'
|