@adhdev/daemon-core 0.9.76-rc.51 → 0.9.76-rc.53

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.mjs CHANGED
@@ -29963,29 +29963,58 @@ import {
29963
29963
  } from "@adhdev/session-host-core";
29964
29964
  var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
29965
29965
  var STARTUP_POLL_MS = 200;
29966
- async function canConnect(endpoint) {
29966
+ var SessionHostCompatibilityError = class extends Error {
29967
+ constructor(message) {
29968
+ super(message);
29969
+ this.name = "SessionHostCompatibilityError";
29970
+ }
29971
+ };
29972
+ function getMissingRequestTypes(diagnostics, requiredRequestTypes) {
29973
+ const supported = new Set(diagnostics?.supportedRequestTypes || []);
29974
+ return requiredRequestTypes.filter((requestType) => !supported.has(requestType));
29975
+ }
29976
+ async function assertRequiredRequestTypes(client, requiredRequestTypes) {
29977
+ if (requiredRequestTypes.length === 0) return;
29978
+ const response = await client.request({
29979
+ type: "get_host_diagnostics",
29980
+ payload: { includeSessions: false }
29981
+ });
29982
+ const missing = getMissingRequestTypes(response.success ? response.result : void 0, requiredRequestTypes);
29983
+ if (missing.length > 0) {
29984
+ const detail = response.success ? "" : ` (${response.error || "capability probe failed"})`;
29985
+ throw new SessionHostCompatibilityError(
29986
+ `Session host does not support required request types: ${missing.join(", ")}${detail}`
29987
+ );
29988
+ }
29989
+ }
29990
+ async function canConnect(endpoint, requiredRequestTypes = []) {
29967
29991
  const client = new SessionHostClient2({ endpoint });
29968
29992
  try {
29969
29993
  await client.connect();
29970
- await client.close();
29994
+ await assertRequiredRequestTypes(client, requiredRequestTypes);
29971
29995
  return true;
29972
- } catch {
29996
+ } catch (error) {
29997
+ if (error instanceof SessionHostCompatibilityError) throw error;
29973
29998
  return false;
29999
+ } finally {
30000
+ await client.close().catch(() => {
30001
+ });
29974
30002
  }
29975
30003
  }
29976
- async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
30004
+ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS, requiredRequestTypes = []) {
29977
30005
  const deadline = Date.now() + timeoutMs;
29978
30006
  while (Date.now() < deadline) {
29979
- if (await canConnect(endpoint)) return;
30007
+ if (await canConnect(endpoint, requiredRequestTypes)) return;
29980
30008
  await new Promise((resolve16) => setTimeout(resolve16, STARTUP_POLL_MS));
29981
30009
  }
29982
30010
  throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
29983
30011
  }
29984
30012
  async function ensureSessionHostReady(options) {
29985
30013
  const endpoint = getDefaultSessionHostEndpoint(options.appName || "adhdev");
29986
- if (await canConnect(endpoint)) return endpoint;
30014
+ const requiredRequestTypes = options.requiredRequestTypes || [];
30015
+ if (await canConnect(endpoint, requiredRequestTypes)) return endpoint;
29987
30016
  options.spawnHost();
29988
- await waitForReady(endpoint, options.timeoutMs);
30017
+ await waitForReady(endpoint, options.timeoutMs, requiredRequestTypes);
29989
30018
  return endpoint;
29990
30019
  }
29991
30020
  async function listHostedCliRuntimes(endpoint) {