@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.js CHANGED
@@ -30149,29 +30149,58 @@ function resolveSessionHostAppName(options = {}) {
30149
30149
  var import_session_host_core4 = require("@adhdev/session-host-core");
30150
30150
  var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
30151
30151
  var STARTUP_POLL_MS = 200;
30152
- async function canConnect(endpoint) {
30152
+ var SessionHostCompatibilityError = class extends Error {
30153
+ constructor(message) {
30154
+ super(message);
30155
+ this.name = "SessionHostCompatibilityError";
30156
+ }
30157
+ };
30158
+ function getMissingRequestTypes(diagnostics, requiredRequestTypes) {
30159
+ const supported = new Set(diagnostics?.supportedRequestTypes || []);
30160
+ return requiredRequestTypes.filter((requestType) => !supported.has(requestType));
30161
+ }
30162
+ async function assertRequiredRequestTypes(client, requiredRequestTypes) {
30163
+ if (requiredRequestTypes.length === 0) return;
30164
+ const response = await client.request({
30165
+ type: "get_host_diagnostics",
30166
+ payload: { includeSessions: false }
30167
+ });
30168
+ const missing = getMissingRequestTypes(response.success ? response.result : void 0, requiredRequestTypes);
30169
+ if (missing.length > 0) {
30170
+ const detail = response.success ? "" : ` (${response.error || "capability probe failed"})`;
30171
+ throw new SessionHostCompatibilityError(
30172
+ `Session host does not support required request types: ${missing.join(", ")}${detail}`
30173
+ );
30174
+ }
30175
+ }
30176
+ async function canConnect(endpoint, requiredRequestTypes = []) {
30153
30177
  const client = new import_session_host_core4.SessionHostClient({ endpoint });
30154
30178
  try {
30155
30179
  await client.connect();
30156
- await client.close();
30180
+ await assertRequiredRequestTypes(client, requiredRequestTypes);
30157
30181
  return true;
30158
- } catch {
30182
+ } catch (error) {
30183
+ if (error instanceof SessionHostCompatibilityError) throw error;
30159
30184
  return false;
30185
+ } finally {
30186
+ await client.close().catch(() => {
30187
+ });
30160
30188
  }
30161
30189
  }
30162
- async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
30190
+ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS, requiredRequestTypes = []) {
30163
30191
  const deadline = Date.now() + timeoutMs;
30164
30192
  while (Date.now() < deadline) {
30165
- if (await canConnect(endpoint)) return;
30193
+ if (await canConnect(endpoint, requiredRequestTypes)) return;
30166
30194
  await new Promise((resolve16) => setTimeout(resolve16, STARTUP_POLL_MS));
30167
30195
  }
30168
30196
  throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
30169
30197
  }
30170
30198
  async function ensureSessionHostReady(options) {
30171
30199
  const endpoint = (0, import_session_host_core4.getDefaultSessionHostEndpoint)(options.appName || "adhdev");
30172
- if (await canConnect(endpoint)) return endpoint;
30200
+ const requiredRequestTypes = options.requiredRequestTypes || [];
30201
+ if (await canConnect(endpoint, requiredRequestTypes)) return endpoint;
30173
30202
  options.spawnHost();
30174
- await waitForReady(endpoint, options.timeoutMs);
30203
+ await waitForReady(endpoint, options.timeoutMs, requiredRequestTypes);
30175
30204
  return endpoint;
30176
30205
  }
30177
30206
  async function listHostedCliRuntimes(endpoint) {