UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

85 lines (84 loc) 3.45 kB
import { l as normalizeOptionalString } from "./string-coerce-CIXf7egm.js"; import { t as ErrorCodes } from "./gateway-error-details-w0nAGBBp.js"; import { Ri as validateSessionsTitlePrepareParams } from "./src-BiL5aQto.js"; import { d as errorShape } from "./error-codes-Bo8q2D1o.js"; import { t as authorizeGatewaySessionCreation } from "./operator-role-policy-wsr1DeJv.js"; import { H as SessionMutationAuthorizationChangedError } from "./session-sharing-B7MI8hNo.js"; import { t as ModelAccountConnectAuthorityError } from "./model-account-connect-BqlZBB8r.js"; import { t as resolveAgentIdOrRespondError } from "./agent-id-shared-MLgRqPvR.js"; import { n as preparePersonalModelSelection } from "./users-model-account-access-B9iXjlLs.js"; import { t as assertValidParams } from "./validation-pzrlzFvo.js"; import { s as prepareDashboardSessionTitle } from "./dashboard-session-title-DoHAIULX.js"; import { t as resolveRegisteredCatalogCreateTarget } from "./session-catalog-D-2VZMkn.js"; import { r as resolveSessionCreateModelSelection } from "./session-create-service-CM4MxLMO.js"; //#region src/gateway/server-methods/sessions-title.ts const sessionTitleHandlers = { "sessions.title.prepare": async ({ params, respond, context, client, signal }) => { if (!assertValidParams(params, validateSessionsTitlePrepareParams, "sessions.title.prepare", respond)) return; const cfg = context.getRuntimeConfig(); const agent = resolveAgentIdOrRespondError({ rawAgentId: params.agentId, respond, cfg, normalize: normalizeOptionalString }); if (!agent) return; const creationError = authorizeGatewaySessionCreation({ cfg, client, agentId: agent.agentId }); if (creationError) { respond(false, void 0, creationError); return; } if (params.model && params.catalogId) { respond(false, void 0, errorShape(ErrorCodes.INVALID_REQUEST, "sessions.title.prepare catalogId cannot include model")); return; } if (params.incognito || !params.message.trim() || params.message.trim().startsWith("/")) { respond(true, { title: null }); return; } const catalog = params.catalogId ? resolveRegisteredCatalogCreateTarget(params.catalogId, agent.agentId, cfg) : void 0; if (catalog && !catalog.ok) { respond(true, { title: null }); return; } try { const personalSelection = preparePersonalModelSelection({ client, context, signal }, params.model); const assertCurrent = () => { personalSelection?.assertCurrent(); const currentCreationError = authorizeGatewaySessionCreation({ cfg: context.getRuntimeConfig(), client, agentId: agent.agentId }); if (currentCreationError) throw new SessionMutationAuthorizationChangedError(currentCreationError); }; const entry = resolveSessionCreateModelSelection(cfg, agent.agentId, catalog?.target ?? params.model); if (!entry) { respond(true, { title: null }); return; } const title = await prepareDashboardSessionTitle({ cfg, agentId: agent.agentId, entry, userMessage: params.message, abortSignal: signal, assertCurrent }); assertCurrent(); respond(true, { title }); } catch (error) { const failure = error instanceof ModelAccountConnectAuthorityError ? errorShape(ErrorCodes.FORBIDDEN, error.message) : error instanceof SessionMutationAuthorizationChangedError ? error.error : void 0; if (!failure) throw error; respond(false, void 0, failure); } } }; //#endregion export { sessionTitleHandlers };