openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 1.69 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { r as normalizeAgentIdStrict } from "./agent-id-CQjtp2ft.mjs";
import "./session-key-CqAyZeVk.mjs";
import { i as listAgentIds } from "./agent-roster-t1ooUdXp.mjs";
import { A as tryResolveLegacyCompatibilityAgentId, _ as resolveDefaultAgentId, t as AgentSelectionRequiredError } from "./agent-scope-config-DmXgFGKP.mjs";
import "./agent-scope-BwB8YH6y.mjs";
import { t as ErrorCodes } from "./gateway-error-details-B69XiHdh.mjs";
import { p as errorShape } from "./error-codes-BzF7aRQ0.mjs";
//#region src/gateway/server-methods/agent-id-shared.ts
function resolveConfiguredAgentIdOrRespondError(e, t, n) {
const r = normalizeAgentIdStrict(e);
if (r.ok && listAgentIds(t).includes(r.value)) return r.value;
n(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, `agent "${e}" not found`));
return null;
}
function resolveAgentIdOrRespondError(e) {
const t = listAgentIds(e.cfg);
const n = normalizeOptionalString(e.rawAgentId) ?? "";
let r;
try {
r = n || tryResolveLegacyCompatibilityAgentId(e.cfg) || resolveDefaultAgentId(e.cfg, {
surface: "this Gateway request",
hint: "Set agentId to one of the configured agents."
});
} catch (t) {
if (!(t instanceof AgentSelectionRequiredError)) throw t;
e.respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, t.message));
return null;
}
if (n && !t.includes(r)) {
e.respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, `unknown agent id "${n}"`));
return null;
}
return {
cfg: e.cfg,
agentId: r
};
}
//#endregion
export { resolveConfiguredAgentIdOrRespondError as n, resolveAgentIdOrRespondError as t };