openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 1.92 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-1VuiLaaR.mjs";
import { r as normalizeAgentIdStrict } from "./agent-id-D1-Q6vR4.mjs";
import "./session-key-DY3MOX4N.mjs";
import { i as listAgentIds } from "./agent-roster-DH6r_8f4.mjs";
import { T as tryResolveLegacyCompatibilityAgentId, g as resolveDefaultAgentId, t as AgentSelectionRequiredError } from "./agent-scope-config-BEk6-ThS.mjs";
import "./agent-scope-bJOokm5r.mjs";
import { t as ErrorCodes } from "./gateway-error-details-gTekQWj2.mjs";
import { d as errorShape } from "./error-codes-D0WRV4Bq.mjs";
//#region src/gateway/server-methods/agent-id-shared.ts
function resolveConfiguredAgentIdOrRespondError(rawAgentId, cfg, respond) {
const normalized = normalizeAgentIdStrict(rawAgentId);
if (normalized.ok && listAgentIds(cfg).includes(normalized.value)) return normalized.value;
respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, `agent "${rawAgentId}" not found`));
return null;
}
function resolveAgentIdOrRespondError(params) {
const knownAgents = listAgentIds(params.cfg);
const requestedAgentId = normalizeOptionalString(params.rawAgentId) ?? "";
let agentId;
try {
agentId = requestedAgentId || tryResolveLegacyCompatibilityAgentId(params.cfg) || resolveDefaultAgentId(params.cfg, {
surface: "this Gateway request",
hint: "Set agentId to one of the configured agents."
});
} catch (error) {
if (!(error instanceof AgentSelectionRequiredError)) throw error;
params.respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, error.message));
return null;
}
if (requestedAgentId && !knownAgents.includes(agentId)) {
params.respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, `unknown agent id "${requestedAgentId}"`));
return null;
}
return {
cfg: params.cfg,
agentId
};
}
//#endregion
export { resolveConfiguredAgentIdOrRespondError as n, resolveAgentIdOrRespondError as t };