UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.71 kB
import{r as truncateUtf16Safe}from"./utf16-slice-DA3Mllbx.mjs";import{o as resolveSessionTitleSource}from"./session-actor-memory-owner-yGnpeolI.mjs"; //!src/gateway/derive-goal-session-title.ts const DERIVED_GOAL_TITLE_MAX_LEN=60;const HOST_ENVELOPE_PREFIXES=[`# agents.md instructions for `,`<environment_context>`,`<permissions instructions>`,`<skills_instructions>`,`<apps_instructions>`,`<plugins_instructions>`,`<recommended_plugins>`,`<external_openclaw_`,`openclaw runtime context`];const TASK_VERBS=/* @__PURE__ */ new Set([`add`,`analyze`,`build`,`check`,`compare`,`create`,`debug`,`design`,`draft`,`explain`,`find`,`fix`,`give`,`help`,`implement`,`investigate`,`list`,`make`,`plan`,`prepare`,`recommend`,`recover`,`rename`,`resume`,`review`,`summarize`,`test`,`update`,`write`]);function truncateTitle(e){if(e.length<=DERIVED_GOAL_TITLE_MAX_LEN)return e;const t=truncateUtf16Safe(e,59);const n=t.lastIndexOf(` `);if(n>DERIVED_GOAL_TITLE_MAX_LEN*.6)return`${t.slice(0,n)}…`;return`${t}…`}function isHostEnvelope(e){const t=e.trimStart().toLowerCase();return HOST_ENVELOPE_PREFIXES.some(e=>t.startsWith(e))}function toSentenceCase(e){if(!e)return e;const t=e[0];if(!t||t!==t.toLowerCase())return e;return`${t.toUpperCase()}${e.slice(1)}`}function pickGoalSentence(e){const t=e.split(/(?<=[.!?])\s+/);for(const e of t){const t=e.replace(/^["'`([{]+/,``).split(/\s+/)[0]?.toLowerCase();if(t&&TASK_VERBS.has(t))return e.trim()}return e}function deriveGoalSessionTitle(e){if(!e)return;const t=resolveSessionTitleSource(e)?.replace(/\s+/g,` `).trim();if(!t||isHostEnvelope(t))return;const n=pickGoalSentence(t);if(!n)return;return truncateTitle(toSentenceCase(n))}export{deriveGoalSessionTitle as t};