dsh-im-ops/plugin-src/host/harness-connection.mjs
oliver bf73b0c0af
Some checks are pending
CI / Test, build, and verify package (push) Waiting to run
fix: improve WhatsApp settings and isolate IM host authentication
2026-10-11 17:03:38 +08:00

22 lines
898 B
JavaScript

import { modernHarnessApi } from './modern-harness-api.mjs';
import { runHarnessHostOperation } from './harness-host-context.mjs';
function optionalService(ctx, name) {
if (ctx && Object.hasOwn(ctx, name)) return ctx[name];
return typeof ctx?.get === 'function' ? ctx.get(name) : undefined;
}
/** Connect to this Host directly unless an external Harness URL was configured. */
export function harnessConnection(ctx, config = {}) {
if (config.harnessBaseUrl !== undefined) {
return { baseUrl: new URL(config.harnessBaseUrl) };
}
const apiProxy = optionalService(ctx, 'apiProxy') ?? modernHarnessApi(ctx);
return {
apiProxy,
runHostOperation: (operation) => runHarnessHostOperation(ctx, operation),
// Cordis child contexts share one root; different Hosts must not share
// ownership of pending questions and approvals.
interactionScope: ctx.root ?? ctx,
};
}