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AACD,EAAA;AACA,EAAA;AAEO,EAAA;AACN,IAAA;AACD,EAAA;AACD;ADhCS;AACA;AACA;AACA;AACA","file":"/Users/shyun/comcom/ain-enterprise/ain-adk/dist/cjs/chunk-YLFNJ4LB.cjs","sourcesContent":[null,"import type { MemoryModule } from \"@/modules\";\nimport { MessageRole, type ThreadObject } from \"@/types/memory\";\nimport { renderDocument } from \"@/utils/document-render\";\nimport { loggers } from \"@/utils/logger\";\nimport { createTextMessage } from \"@/utils/thread-messages\";\n\nconst ATTACHED_DOCUMENTS_FOOTER = `---\n위 첨부 문서는 사용자가 이 대화에 참조용으로 첨부한 것이다. 문서의 서술 내용에 대한 질문에는 이 내용을 근거로 답하라. 단, 최신 수치·집계·조회가 필요한 질문에는 문서의 숫자를 그대로 답하지 말고 사용 가능한 도구를 사용하라.`;\n\n/**\n * Collects attached document ids for the current turn: ids recorded on\n * earlier messages' `metadata.documentIds` / `metadata.documentId`\n * (chronological), then the current request's ids. Deduped, order-preserving.\n */\nexport function collectAttachedDocumentIds(\n\tthread: ThreadObject,\n\trequestDocumentIds?: string[],\n): string[] {\n\tconst ids: string[] = [];\n\tconst seen = new Set<string>();\n\tconst add = (id: unknown) => {\n\t\tif (typeof id === \"string\" && id && !seen.has(id)) {\n\t\t\tseen.add(id);\n\t\t\tids.push(id);\n\t\t}\n\t};\n\tfor (const message of thread.messages) {\n\t\tconst metaIds = message.metadata?.documentIds;\n\t\tif (Array.isArray(metaIds)) {\n\t\t\tfor (const id of metaIds) add(id);\n\t\t}\n\t\t// A workflow result message records its output document under the\n\t\t// singular `documentId` (workflow-execution.service.ts) and stores the\n\t\t// message itself as a reference-only document part. Treating it as an\n\t\t// attachment is what lets follow-up turns discuss the workflow output —\n\t\t// and it applies retroactively to threads written before this change.\n\t\tadd(message.metadata?.documentId);\n\t}\n\tfor (const id of requestDocumentIds ?? []) add(id);\n\treturn ids;\n}\n\n/**\n * Resolves the attached documents to fresh rendered text and pushes ONE\n * in-memory USER message onto `thread.messages` so fulfillment sees the\n * bodies. Never persisted — intent triggering (which runs before this) and\n * stored history keep only the short display text.\n *\n * Isolation point: if the injection strategy changes (system-prompt\n * grounding, provider-native document parts), only this function changes.\n *\n * Authorization: resolution is deliberately read-open — ids are resolved via\n * `getDocument` without a per-user ownership check, matching the deployment's\n * role-based read-open document policy (cross-user document conversations are\n * a supported flow). Deployments that need owner-only attachment must enforce\n * authorization before passing ids into the query pipeline.\n */\nexport async function injectAttachedDocuments(\n\tmemoryModule: MemoryModule,\n\tthread: ThreadObject,\n\trequestDocumentIds?: string[],\n\tfilterText?: (text: string) => Promise<string>,\n): Promise<void> {\n\tconst documentIds = collectAttachedDocumentIds(thread, requestDocumentIds);\n\tif (documentIds.length === 0) return;\n\n\tconst documentMemory = memoryModule.getDocumentMemory();\n\tif (!documentMemory) {\n\t\tloggers.intent.warn(\n\t\t\t\"Attached documents requested but document memory is not configured\",\n\t\t\t{ documentIds },\n\t\t);\n\t\treturn;\n\t}\n\n\tconst sections: string[] = [];\n\tfor (let i = 0; i < documentIds.length; i++) {\n\t\tconst id = documentIds[i];\n\t\tconst label = `[첨부 문서 ${i + 1}]`;\n\t\tlet document: Awaited<ReturnType<typeof documentMemory.getDocument>>;\n\t\ttry {\n\t\t\tdocument = await documentMemory.getDocument(id);\n\t\t} catch (error) {\n\t\t\tloggers.intent.warn(\"Failed to resolve attached document\", { id, error });\n\t\t}\n\t\tif (!document) {\n\t\t\tsections.push(\n\t\t\t\t`${label} '${id}' — 문서를 찾을 수 없음(삭제되었을 수 있음). 사용자에게 이 사실을 알려라.`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet rendered = renderDocument(document);\n\t\tif (filterText) rendered = await filterText(rendered);\n\t\tsections.push(\n\t\t\t`${label} 제목: ${document.title} (최종 수정: ${document.updatedAt})\\n${rendered}`,\n\t\t);\n\n\t\tconst advice = document.advice?.content?.trim();\n\t\tif (advice) {\n\t\t\tsections.push(\n\t\t\t\t`${label.slice(0, -1)} - AI advice]\\n${filterText ? await filterText(advice) : advice}`,\n\t\t\t);\n\t\t}\n\t}\n\tsections.push(ATTACHED_DOCUMENTS_FOOTER);\n\n\tthread.messages.push(\n\t\tcreateTextMessage(MessageRole.USER, sections.join(\"\\n\\n\")),\n\t);\n}\n"]}