openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
61 lines (60 loc) • 2.73 kB
JavaScript
import { n as getDatabaseEngineSelection } from "./context-DE59wyBs.mjs";
import { i as GATEWAY_CLIENT_NAMES, r as GATEWAY_CLIENT_MODES } from "./client-info-Cm1BcrMm.mjs";
import { n as resolveGatewayLocalPortOverride } from "./gateway-port-option-D-9uSBm2.mjs";
import { f as isImplicitLocalGatewayTarget, m as assertGatewayCliMessageContext, r as callGateway } from "./call-DVCK1deJ.mjs";
import { r as withProgress } from "./progress-DZHhZ1Fk.mjs";
import { n as parseTimeoutMsWithFallback } from "./parse-timeout-qqSdJSy9.mjs";
//#region src/cli/gateway-rpc.runtime.ts
const DEFAULT_GATEWAY_RPC_TIMEOUT_MS = 3e4;
/** Database-free RPCs do not need the local store's credentials. */
async function prepareCliGatewayStateAccess() {
if (getDatabaseEngineSelection()) return;
const { readConfigSnapshotForEngineSelection: e } = await import("./config-preflight-snapshot-DXY8QhxC.mjs");
const t = await e(process.env, { isolateEnv: false });
if (!getDatabaseEngineSelection()) {
const { createConfigReadError: e } = await import("./io.invalid-config-DHUoEji6.mjs");
throw e(t);
}
}
async function isImplicitLocalGatewayTargetFromCliRuntime(e) {
return await isImplicitLocalGatewayTarget({
config: e.config,
url: e.url,
localPortOverride: resolveGatewayLocalPortOverride(e)
});
}
async function callGatewayFromCliRuntime(e, t, n, r) {
assertGatewayCliMessageContext(e, n);
const i = resolveGatewayLocalPortOverride(t);
const a = r?.progress ?? t.json !== true;
const o = r?.timeoutMs !== void 0 ? r.timeoutMs : t.timeout === null ? null : parseTimeoutMsWithFallback(t.timeout, r?.defaultTimeoutMs ?? DEFAULT_GATEWAY_RPC_TIMEOUT_MS, { invalidType: "error" });
return await withProgress({
label: r?.label ?? `Gateway ${e}`,
indeterminate: true,
enabled: a
}, async () => await callGateway({
config: t.config,
url: t.url,
expectUrl: t.expectUrl,
token: t.token,
password: t.password,
method: e,
params: n,
deviceIdentity: r?.deviceIdentity,
beforeDeviceIdentityLoad: prepareCliGatewayStateAccess,
expectFinal: r?.expectFinal ?? Boolean(t.expectFinal),
scopes: r?.scopes,
useStoredDeviceAuth: r?.useStoredDeviceAuth,
requiredStoredDeviceAuthScopes: r?.requiredStoredDeviceAuthScopes,
requireLocalBackendSharedAuth: r?.requireLocalBackendSharedAuth,
allowLocalBackendAuthNone: r?.clientName === void 0 && r?.mode === void 0,
sharedStateMode: r?.sharedStateMode,
signal: r?.signal,
timeoutMs: o,
localPortOverride: i,
clientName: r?.clientName ?? GATEWAY_CLIENT_NAMES.CLI,
mode: r?.mode ?? GATEWAY_CLIENT_MODES.CLI
}));
}
//#endregion
export { isImplicitLocalGatewayTargetFromCliRuntime as n, prepareCliGatewayStateAccess as r, callGatewayFromCliRuntime as t };