{"version":3,"file":"fileMentions.mjs","names":[],"sources":["../../../src/web/lib/fileMentions.ts"],"sourcesContent":["import { MEDIA_TYPES, type MediaKind } from '../../types/media';\nimport { SESSION_REFERENCE_SCHEME } from './sessionMentions';\n\nexport interface FileMention {\n  /** The cwd-relative path as the message spelled it. */\n  path: string;\n  /** How the timeline previews it; 'file' offers a link, 'directory' previews nothing. */\n  kind: MediaKind | 'file' | 'directory';\n}\n\n// An @ token starts the message or follows whitespace, runs to the next\n// whitespace, and sheds the punctuation a sentence hangs on it.\nconst MENTION = /(?:^|\\s)@([^\\s@]+)/gu;\nconst TRAILING_PUNCTUATION = /[.,;:!?)\\]]+$/u;\n\nexport function mediaKindFor(filePath: string): MediaKind | 'file' | 'directory' {\n  // The trailing slash the @ completion writes for a folder. Naming one is\n  // useful to the agent, but there is no asset behind it, and fetching one\n  // only ever produced a \"could not load\" badge under the message.\n  if (filePath.endsWith('/')) return 'directory';\n  const dot = filePath.lastIndexOf('.');\n  if (dot < 0) return 'file';\n  return MEDIA_TYPES[filePath.slice(dot + 1).toLowerCase()]?.kind ?? 'file';\n}\n\n/** The distinct files a message mentions with @, in order of appearance. A session mention names no file. */\nexport function parseFileMentions(text: string): FileMention[] {\n  const seen = new Set<string>();\n  const mentions: FileMention[] = [];\n  for (const match of text.matchAll(MENTION)) {\n    const mentionPath = match[1].replace(TRAILING_PUNCTUATION, '');\n    if (!mentionPath || seen.has(mentionPath) || mentionPath.startsWith(SESSION_REFERENCE_SCHEME)) continue;\n    seen.add(mentionPath);\n    mentions.push({ path: mentionPath, kind: mediaKindFor(mentionPath) });\n  }\n  return mentions;\n}\n"],"mappings":";;;AAYA,MAAM,UAAU;AAChB,MAAM,uBAAuB;AAE7B,SAAgB,aAAa,UAAoD;CAI/E,IAAI,SAAS,SAAS,GAAG,GAAG,OAAO;CACnC,MAAM,MAAM,SAAS,YAAY,GAAG;CACpC,IAAI,MAAM,GAAG,OAAO;CACpB,OAAO,YAAY,SAAS,MAAM,MAAM,CAAC,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ;AACrE;;AAGA,SAAgB,kBAAkB,MAA6B;CAC7D,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,WAA0B,CAAC;CACjC,KAAK,MAAM,SAAS,KAAK,SAAS,OAAO,GAAG;EAC1C,MAAM,cAAc,MAAM,EAAE,CAAC,QAAQ,sBAAsB,EAAE;EAC7D,IAAI,CAAC,eAAe,KAAK,IAAI,WAAW,KAAK,YAAY,WAAA,UAAmC,GAAG;EAC/F,KAAK,IAAI,WAAW;EACpB,SAAS,KAAK;GAAE,MAAM;GAAa,MAAM,aAAa,WAAW;EAAE,CAAC;CACtE;CACA,OAAO;AACT"}