@lightupai/polaris 0.0.24 → 0.0.25
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/daemon/daemon.ts +12 -35
package/package.json
CHANGED
package/src/daemon/daemon.ts
CHANGED
|
@@ -346,43 +346,20 @@ export function startDaemon(port = Number(process.env.POLARIS_DAEMON_PORT ?? 432
|
|
|
346
346
|
let mapping = sessions.get(ccSessionId);
|
|
347
347
|
if (!mapping || !mapping.project) {
|
|
348
348
|
// CC session_id doesn't match any registered MCP client.
|
|
349
|
-
//
|
|
350
|
-
//
|
|
349
|
+
// The MCP server uses a different UUID than CC's session_id.
|
|
350
|
+
// Try to find the MCP session that this CC session belongs to.
|
|
351
|
+
// Heuristic: if only one connected session exists, route to it.
|
|
352
|
+
// Otherwise, drop the event — the user needs to /polaris join first.
|
|
351
353
|
const connectedSessions = Array.from(sessions.values()).filter((m) => m.project);
|
|
352
|
-
if (connectedSessions.length ===
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
// Create the session on the API
|
|
361
|
-
const serviceUrl = getServiceUrl();
|
|
362
|
-
try {
|
|
363
|
-
const createRes = await fetch(`${serviceUrl}/projects/${template.project}/sessions`, {
|
|
364
|
-
method: "POST",
|
|
365
|
-
headers: await authHeaders(),
|
|
366
|
-
body: JSON.stringify({ name: newSession, driver: template.user }),
|
|
367
|
-
});
|
|
368
|
-
if (!createRes.ok && createRes.status !== 409) {
|
|
369
|
-
return json({ status: "session_create_failed" });
|
|
370
|
-
}
|
|
371
|
-
} catch {
|
|
372
|
-
return json({ status: "api_unreachable" });
|
|
354
|
+
if (connectedSessions.length === 1) {
|
|
355
|
+
mapping = connectedSessions[0];
|
|
356
|
+
// Remember this mapping for future events from this CC session
|
|
357
|
+
sessions.set(ccSessionId, { ...mapping, ccSessionId });
|
|
358
|
+
} else {
|
|
359
|
+
// Multiple or zero sessions — can't determine which one.
|
|
360
|
+
// Drop silently; events will flow once /polaris join maps the session.
|
|
361
|
+
return json({ status: connectedSessions.length > 0 ? "ambiguous" : "not_connected" });
|
|
373
362
|
}
|
|
374
|
-
|
|
375
|
-
mapping = {
|
|
376
|
-
ccSessionId,
|
|
377
|
-
project: template.project,
|
|
378
|
-
session: newSession,
|
|
379
|
-
user: template.user,
|
|
380
|
-
agent: template.agent,
|
|
381
|
-
slackChannel: template.slackChannel,
|
|
382
|
-
ws: null,
|
|
383
|
-
};
|
|
384
|
-
sessions.set(ccSessionId, mapping);
|
|
385
|
-
console.error(`[daemon] Auto-created session ${template.project}/${newSession} for CC session ${ccSessionId.slice(0, 8)}`);
|
|
386
363
|
}
|
|
387
364
|
|
|
388
365
|
// Determine sender: human for prompts, agent for everything else
|