{"version":3,"file":"attachmentNotes.cjs","names":[],"sources":["../../../src/web/lib/attachmentNotes.ts"],"sourcesContent":["/**\n * The sentences the composer appends so the agent can find each attachment on disk, and the\n * reverse: reading them back out of a sent message so the transcript shows what the person\n * wrote, not the agent's directions. Both sides live here so the format cannot drift.\n */\n\nexport function toolPathHint(path: string): string {\n  return `To send it to a tool's file parameter, pass {\"path\": ${JSON.stringify(path)}}.`;\n}\n\nexport interface AttachedFileNote {\n  name: string;\n  mimeType: string;\n  size: number;\n  path: string;\n}\n\nexport interface UserMessageParts {\n  /** What the person wrote, with the agent-only notes removed. */\n  text: string;\n  /** Binary files the person attached, drawn as chips. */\n  files: AttachedFileNote[];\n}\n\n// A JSON string literal, as toolPathHint writes the path.\nconst PATH = String.raw`\"(?:[^\"\\\\]|\\\\.)*\"`;\nconst HINT = String.raw`To send it to a tool's file parameter, pass \\{\"path\": (${PATH})\\}\\.`;\n// Each note is a whole paragraph: the composer joins parts with a blank line.\nconst paragraph = (body: string) => new RegExp(String.raw`(?:^|\\n\\n)${body}(?=\\n\\n|$)`, 'gu');\nconst IMAGE_NOTE = paragraph(String.raw`Attached image \"[^\\n]*?\" is also saved at [^\\n]*? ${HINT}`);\nconst TEXT_NOTE = paragraph(String.raw`\"[^\\n]*?\" is also saved at [^\\n]*? ${HINT}`);\nconst FILE_NOTE = paragraph(String.raw`Attached file \"([^\\n]*?)\" \\(([^,\\n]+), (\\d+) bytes\\) saved at [^\\n]*? ${HINT}`);\n/** Sent in place of a message when the person attached only images. */\nconst IMAGE_ONLY = 'Please review the attached image.';\n\n/** Splits a sent user message into the person's words and their attachments. */\nexport function userMessageParts(message: string, hasImages: boolean): UserMessageParts {\n  const files: AttachedFileNote[] = [];\n  let text = message.replace(FILE_NOTE, (_, name: string, mimeType: string, size: string, path: string) => {\n    files.push({ name, mimeType, size: Number(size), path: JSON.parse(path) as string });\n    return '';\n  });\n  text = text.replace(IMAGE_NOTE, '').replace(TEXT_NOTE, '').trim();\n  if (hasImages && text === IMAGE_ONLY) text = '';\n  return { text, files };\n}\n"],"mappings":";;;;;;AAMA,SAAgB,aAAa,MAAsB;CACjD,OAAO,wDAAwD,KAAK,UAAU,IAAI,EAAE;AACtF;AAiBA,MAAM,OAAO,OAAO,GAAG;AACvB,MAAM,OAAO,OAAO,GAAG,0DAA0D,KAAK;AAEtF,MAAM,aAAa,SAAiB,IAAI,OAAO,OAAO,GAAG,aAAa,KAAK,aAAa,IAAI;AAC5F,MAAM,aAAa,UAAU,OAAO,GAAG,qDAAqD,MAAM;AAClG,MAAM,YAAY,UAAU,OAAO,GAAG,sCAAsC,MAAM;AAClF,MAAM,YAAY,UAAU,OAAO,GAAG,yEAAyE,MAAM;;AAErH,MAAM,aAAa;;AAGnB,SAAgB,iBAAiB,SAAiB,WAAsC;CACtF,MAAM,QAA4B,CAAC;CACnC,IAAI,OAAO,QAAQ,QAAQ,YAAY,GAAG,MAAc,UAAkB,MAAc,SAAiB;EACvG,MAAM,KAAK;GAAE;GAAM;GAAU,MAAM,OAAO,IAAI;GAAG,MAAM,KAAK,MAAM,IAAI;EAAY,CAAC;EACnF,OAAO;CACT,CAAC;CACD,OAAO,KAAK,QAAQ,YAAY,EAAE,CAAC,CAAC,QAAQ,WAAW,EAAE,CAAC,CAAC,KAAK;CAChE,IAAI,aAAa,SAAS,YAAY,OAAO;CAC7C,OAAO;EAAE;EAAM;CAAM;AACvB"}