@adhdev/daemon-core 0.7.17 → 0.7.18
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/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/session-host/runtime-support.ts +71 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -124,6 +124,8 @@ export { NodePtyTransportFactory } from './cli-adapters/pty-transport.js';
|
|
|
124
124
|
export type { PtyRuntimeTransport, PtyTransportFactory, PtySpawnOptions } from './cli-adapters/pty-transport.js';
|
|
125
125
|
export { SessionHostPtyTransportFactory } from './cli-adapters/session-host-transport.js';
|
|
126
126
|
export type { HostedCliRuntimeDescriptor, CliTransportFactoryParams } from './commands/cli-manager.js';
|
|
127
|
+
export { ensureSessionHostReady, listHostedCliRuntimes } from './session-host/runtime-support.js';
|
|
128
|
+
export type { SessionHostEndpoint } from '@adhdev/session-host-core';
|
|
127
129
|
|
|
128
130
|
// ── Installer ──
|
|
129
131
|
export { getAIExtensions, installExtensions, launchIDE, isExtensionInstalled } from './installer.js';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SessionHostClient,
|
|
3
|
+
getDefaultSessionHostEndpoint,
|
|
4
|
+
type SessionHostEndpoint,
|
|
5
|
+
type SessionHostRecord,
|
|
6
|
+
} from '@adhdev/session-host-core';
|
|
7
|
+
import type { HostedCliRuntimeDescriptor } from '../commands/cli-manager.js';
|
|
8
|
+
|
|
9
|
+
const STARTUP_TIMEOUT_MS = 8000;
|
|
10
|
+
const STARTUP_POLL_MS = 200;
|
|
11
|
+
|
|
12
|
+
async function canConnect(endpoint: SessionHostEndpoint): Promise<boolean> {
|
|
13
|
+
const client = new SessionHostClient({ endpoint });
|
|
14
|
+
try {
|
|
15
|
+
await client.connect();
|
|
16
|
+
await client.close();
|
|
17
|
+
return true;
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function waitForReady(endpoint: SessionHostEndpoint, timeoutMs = STARTUP_TIMEOUT_MS): Promise<void> {
|
|
24
|
+
const deadline = Date.now() + timeoutMs;
|
|
25
|
+
while (Date.now() < deadline) {
|
|
26
|
+
if (await canConnect(endpoint)) return;
|
|
27
|
+
await new Promise((resolve) => setTimeout(resolve, STARTUP_POLL_MS));
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function ensureSessionHostReady(options: {
|
|
33
|
+
appName?: string;
|
|
34
|
+
spawnHost: () => void;
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
}): Promise<SessionHostEndpoint> {
|
|
37
|
+
const endpoint = getDefaultSessionHostEndpoint(options.appName || 'adhdev');
|
|
38
|
+
if (await canConnect(endpoint)) return endpoint;
|
|
39
|
+
options.spawnHost();
|
|
40
|
+
await waitForReady(endpoint, options.timeoutMs);
|
|
41
|
+
return endpoint;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function listHostedCliRuntimes(endpoint: SessionHostEndpoint): Promise<HostedCliRuntimeDescriptor[]> {
|
|
45
|
+
const client = new SessionHostClient({ endpoint });
|
|
46
|
+
try {
|
|
47
|
+
const response = await client.request<SessionHostRecord[]>({
|
|
48
|
+
type: 'list_sessions',
|
|
49
|
+
payload: {},
|
|
50
|
+
});
|
|
51
|
+
if (!response.success || !response.result) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
return response.result
|
|
55
|
+
.filter((record) => record.category === 'cli' && ['running', 'interrupted'].includes(record.lifecycle))
|
|
56
|
+
.sort((a, b) => b.lastActivityAt - a.lastActivityAt)
|
|
57
|
+
.map((record) => ({
|
|
58
|
+
runtimeId: record.sessionId,
|
|
59
|
+
runtimeKey: record.runtimeKey,
|
|
60
|
+
displayName: record.displayName,
|
|
61
|
+
workspaceLabel: record.workspaceLabel,
|
|
62
|
+
lifecycle: record.lifecycle,
|
|
63
|
+
recoveryState: typeof record.meta?.runtimeRecoveryState === 'string' ? String(record.meta.runtimeRecoveryState) : null,
|
|
64
|
+
cliType: record.providerType,
|
|
65
|
+
workspace: record.workspace,
|
|
66
|
+
cliArgs: Array.isArray(record.meta?.cliArgs) ? (record.meta.cliArgs as string[]) : [],
|
|
67
|
+
}));
|
|
68
|
+
} finally {
|
|
69
|
+
await client.close().catch(() => {});
|
|
70
|
+
}
|
|
71
|
+
}
|