@lythos/agent-adapter-deepseek-serve 0.9.36 → 0.9.38
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 +6 -1
- package/src/deepseek-serve.ts +37 -28
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lythos/agent-adapter-deepseek-serve",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.38",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "bun test src/ --pass-with-no-tests",
|
|
7
|
+
"test:coverage": "bun test src/ --coverage --coverage-reporter=lcov --coverage-dir=coverage --pass-with-no-tests",
|
|
8
|
+
"test:watch": "bun test src/ --watch"
|
|
9
|
+
},
|
|
5
10
|
"main": "./src/index.ts",
|
|
6
11
|
"exports": {
|
|
7
12
|
".": "./src/index.ts"
|
package/src/deepseek-serve.ts
CHANGED
|
@@ -141,8 +141,8 @@ async function ensureServeRunning(): Promise<number> {
|
|
|
141
141
|
stdin: 'ignore',
|
|
142
142
|
})
|
|
143
143
|
|
|
144
|
-
// Wait for serve to be ready
|
|
145
|
-
for (let i = 0; i <
|
|
144
|
+
// Wait for serve to be ready (up to 60s for CI/cold-start)
|
|
145
|
+
for (let i = 0; i < 120; i++) {
|
|
146
146
|
try {
|
|
147
147
|
const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(1000) })
|
|
148
148
|
if (res.ok) {
|
|
@@ -172,43 +172,52 @@ 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' || event.event === 'turn.completed') completed = true
|
|
197
|
+
} catch {}
|
|
198
|
+
}
|
|
207
199
|
}
|
|
208
200
|
}
|
|
201
|
+
|
|
202
|
+
// Fallback: check thread status directly if SSE didn't signal completion
|
|
203
|
+
if (!completed) {
|
|
204
|
+
try {
|
|
205
|
+
const thRes = await fetch(
|
|
206
|
+
`http://127.0.0.1:${port}/v1/threads/${threadId}`,
|
|
207
|
+
{ signal: AbortSignal.timeout(3000) }
|
|
208
|
+
)
|
|
209
|
+
if (thRes.ok) {
|
|
210
|
+
const th = await thRes.json()
|
|
211
|
+
const turn = th.turns?.[0] ?? th.thread?.latest_turn
|
|
212
|
+
if (turn?.status === 'completed' && output) completed = true
|
|
213
|
+
}
|
|
214
|
+
} catch {}
|
|
215
|
+
}
|
|
216
|
+
|
|
209
217
|
if (completed && output) return output
|
|
210
218
|
|
|
211
|
-
|
|
219
|
+
// Adaptive poll: shorter interval when events are flowing
|
|
220
|
+
await new Promise(r => setTimeout(r, 500))
|
|
212
221
|
}
|
|
213
222
|
|
|
214
223
|
return output || '(timeout)'
|