@lythos/agent-adapter-deepseek-serve 0.14.4 → 0.14.5

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.14.4",
3
+ "version": "0.14.5",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "bun test src/ --pass-with-no-tests",
@@ -22,6 +22,6 @@
22
22
  "serve-mode"
23
23
  ],
24
24
  "dependencies": {
25
- "@lythos/agent-adapter": "^0.14.4"
25
+ "@lythos/agent-adapter": "^0.14.5"
26
26
  }
27
27
  }
@@ -60,15 +60,6 @@ function updateThreadMapping(sessionId: string, threadId: string): void {
60
60
  writeLock(lock)
61
61
  }
62
62
 
63
- function isProcessAlive(pid: number): boolean {
64
- try {
65
- process.kill(pid, 0)
66
- return true
67
- } catch {
68
- return false
69
- }
70
- }
71
-
72
63
  // ── Port finder ─────────────────────────────────────────────────────────────
73
64
 
74
65
  async function findFreePort(start: number): Promise<number> {
@@ -100,37 +91,59 @@ async function getVersion(): Promise<string | null> {
100
91
 
101
92
  let cachedPort: number | null = null
102
93
 
103
- async function ensureServeRunning(): Promise<number> {
104
- if (cachedPort !== null) {
105
- // Quick health check
94
+ /** Discover a running daemon by probing known ports. No PID dependency —
95
+ * bunx sandboxes block process.kill(pid, 0) so health-check is the only
96
+ * reliable signal. Tries: cachedPort → lock port → base range. */
97
+ async function discoverRunningDaemon(): Promise<number | null> {
98
+ // Build candidate list: cached + lock file + base range
99
+ const candidates: number[] = []
100
+ if (cachedPort !== null) candidates.push(cachedPort)
101
+
102
+ const lock = readLock()
103
+ if (lock) candidates.push(lock.port)
104
+
105
+ // Also probe a small range around BASE_PORT (catches zombie daemons from
106
+ // previous failed starts that left no lock file)
107
+ for (let p = BASE_PORT; p < BASE_PORT + 4; p++) {
108
+ if (!candidates.includes(p)) candidates.push(p)
109
+ }
110
+
111
+ for (const port of candidates) {
106
112
  try {
107
- const res = await fetch(`http://127.0.0.1:${cachedPort}/health`, { signal: AbortSignal.timeout(2000) })
108
- if (res.ok) return cachedPort
113
+ const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(1000) })
114
+ if (res.ok) return port
109
115
  } catch {}
110
- cachedPort = null
116
+ }
117
+ return null
118
+ }
119
+
120
+ async function ensureServeRunning(): Promise<number> {
121
+ // 1. Try health-check discovery first (no PID — works in bunx sandbox)
122
+ const discovered = await discoverRunningDaemon()
123
+ if (discovered !== null) {
124
+ // Refresh lock file if stale (daemon outlived the lock)
125
+ const lock = readLock()
126
+ if (!lock || lock.port !== discovered) {
127
+ const version = await getVersion()
128
+ writeLock({
129
+ pid: 0, // PID unknown — daemon was discovered, not spawned by us
130
+ port: discovered,
131
+ version: version || 'unknown',
132
+ startedAt: lock?.startedAt || new Date().toISOString(),
133
+ threads: lock?.threads || {},
134
+ })
135
+ }
136
+ cachedPort = discovered
137
+ return discovered
111
138
  }
112
139
 
113
- // Check version
140
+ // 2. No daemon found — start one
114
141
  const version = await getVersion()
115
142
  if (!version) throw new Error('DeepSeek CLI not found. Install: https://github.com/Hmbown/deepseek-tui')
116
143
  if (!version.startsWith('0.8.')) {
117
144
  console.warn(`⚠️ DeepSeek version ${version} — tested on 0.8.14. May behave differently.`)
118
145
  }
119
146
 
120
- // Check lock file
121
- const lock = readLock()
122
- if (lock && isProcessAlive(lock.pid)) {
123
- // Verify health
124
- try {
125
- const res = await fetch(`http://127.0.0.1:${lock.port}/health`, { signal: AbortSignal.timeout(2000) })
126
- if (res.ok) {
127
- cachedPort = lock.port
128
- return lock.port
129
- }
130
- } catch {}
131
- }
132
-
133
- // Start new serve instance
134
147
  const port = await findFreePort(BASE_PORT)
135
148
  console.log(`🔧 Starting DeepSeek serve on port ${port}...`)
136
149