@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lythos/agent-adapter-deepseek-serve",
3
- "version": "0.9.36",
3
+ "version": "0.9.37",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "exports": {
@@ -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
- // Check if turn is complete
180
- const threadRes = await fetch(
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
- // Collect all events so far
191
- const eventsRes = await fetch(
192
- `http://127.0.0.1:${port}/v1/threads/${threadId}/events?since_seq=0`,
193
- { signal: AbortSignal.timeout(5000) }
194
- ).catch(() => null)
195
- if (!eventsRes?.ok) { await new Promise(r => setTimeout(r, 2000)); continue }
196
-
197
- const text = await eventsRes.text()
198
- let completed = false
199
- output = ''
200
- for (const line of text.split('\n')) {
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
- await new Promise(r => setTimeout(r, 2000))
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)'