@things-factory/ai-assistant 10.1.271 → 10.1.273
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/components/assistant-chat.ts +18 -6
- package/client/components/assistant-dock.ts +15 -1
- package/client/components/proposal-request.test.ts +12 -1
- package/client/utils/addressed-draft.test.ts +31 -0
- package/client/utils/assistant-ask.ts +7 -0
- package/client/utils/assistant-request-context.ts +10 -0
- package/dist-client/components/assistant-chat.d.ts +6 -0
- package/dist-client/components/assistant-chat.js +23 -6
- package/dist-client/components/assistant-chat.js.map +1 -1
- package/dist-client/components/assistant-dock.js +15 -0
- package/dist-client/components/assistant-dock.js.map +1 -1
- package/dist-client/components/proposal-request.test.js +11 -1
- package/dist-client/components/proposal-request.test.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/utils/addressed-draft.test.d.ts +1 -0
- package/dist-client/utils/addressed-draft.test.js +27 -0
- package/dist-client/utils/addressed-draft.test.js.map +1 -0
- package/dist-client/utils/assistant-ask.d.ts +10 -0
- package/dist-client/utils/assistant-ask.js.map +1 -1
- package/dist-client/utils/assistant-request-context.d.ts +12 -0
- package/dist-client/utils/assistant-request-context.js +11 -0
- package/dist-client/utils/assistant-request-context.js.map +1 -1
- package/dist-server/service/assistant-chat-resolver.js +5 -2
- package/dist-server/service/assistant-chat-resolver.js.map +1 -1
- package/dist-server/service/assistant-mode/index.d.ts +1 -0
- package/dist-server/service/assistant-mode/index.js +4 -1
- package/dist-server/service/assistant-mode/index.js.map +1 -1
- package/dist-server/service/assistant-mode/mode-categories.d.ts +4 -3
- package/dist-server/service/assistant-mode/mode-categories.js +15 -5
- package/dist-server/service/assistant-mode/mode-categories.js.map +1 -1
- package/dist-server/service/assistant-mode/turn-lines.d.ts +12 -0
- package/dist-server/service/assistant-mode/turn-lines.js +38 -0
- package/dist-server/service/assistant-mode/turn-lines.js.map +1 -0
- package/dist-server/service/chat-message/index.d.ts +1 -0
- package/dist-server/service/chat-message/index.js +3 -1
- package/dist-server/service/chat-message/index.js.map +1 -1
- package/dist-server/service/chat-message/message-doors.d.ts +14 -5
- package/dist-server/service/chat-message/message-doors.js +19 -6
- package/dist-server/service/chat-message/message-doors.js.map +1 -1
- package/dist-server/service/chat-message/room-turn.d.ts +31 -0
- package/dist-server/service/chat-message/room-turn.js +30 -0
- package/dist-server/service/chat-message/room-turn.js.map +1 -0
- package/dist-server/service/chat-session-participant/mention-invite.d.ts +2 -0
- package/dist-server/service/chat-session-participant/mention-invite.js +5 -0
- package/dist-server/service/chat-session-participant/mention-invite.js.map +1 -1
- package/dist-server/service/chat-session-resolver.d.ts +5 -0
- package/dist-server/service/chat-session-resolver.js +55 -2
- package/dist-server/service/chat-session-resolver.js.map +1 -1
- package/dist-server/service/data-entry/entry-apply.d.ts +2 -0
- package/dist-server/service/data-entry/entry-apply.js +1 -1
- package/dist-server/service/data-entry/entry-apply.js.map +1 -1
- package/dist-server/service/data-entry/entry-resolver.js +2 -1
- package/dist-server/service/data-entry/entry-resolver.js.map +1 -1
- package/dist-server/service/data-entry/entry-target.d.ts +7 -2
- package/dist-server/service/data-entry/entry-target.js.map +1 -1
- package/dist-server/service/data-read/read-target.d.ts +6 -0
- package/dist-server/service/data-read/read-target.js.map +1 -1
- package/dist-server/service/people/index.d.ts +2 -0
- package/dist-server/service/people/index.js +9 -1
- package/dist-server/service/people/index.js.map +1 -1
- package/dist-server/service/people/person-subject.d.ts +34 -0
- package/dist-server/service/people/person-subject.js +89 -0
- package/dist-server/service/people/person-subject.js.map +1 -0
- package/dist-server/service/unattended-run/run-unattended.js +1 -1
- package/dist-server/service/unattended-run/run-unattended.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/server/service/assistant-chat-resolver.ts +5 -2
- package/server/service/assistant-mode/index.ts +1 -0
- package/server/service/assistant-mode/mode-categories.ts +16 -5
- package/server/service/assistant-mode/mode-front.test.ts +35 -0
- package/server/service/assistant-mode/open-subject-door.test.ts +7 -2
- package/server/service/assistant-mode/turn-lines.ts +43 -0
- package/server/service/chat-message/index.ts +1 -0
- package/server/service/chat-message/message-doors.test.ts +40 -3
- package/server/service/chat-message/message-doors.ts +26 -6
- package/server/service/chat-message/room-turn.ts +42 -0
- package/server/service/chat-session-participant/mention-invite.ts +5 -0
- package/server/service/chat-session-resolver.ts +49 -2
- package/server/service/data-entry/entry-apply.ts +3 -1
- package/server/service/data-entry/entry-resolver.ts +2 -1
- package/server/service/data-entry/entry-target.ts +5 -2
- package/server/service/data-read/read-target.ts +6 -0
- package/server/service/people/index.ts +2 -0
- package/server/service/people/person-subject.test.ts +163 -0
- package/server/service/people/person-subject.ts +88 -0
- package/server/service/unattended-run/run-unattended.test.ts +2 -1
- package/server/service/unattended-run/run-unattended.ts +1 -1
- package/test/assistant-request-context.test.ts +1 -1
- package/test/open-doors.test.ts +3 -1
- package/translations/en.json +2 -0
- package/translations/es.json +2 -0
- package/translations/ja.json +2 -0
- package/translations/ko.json +2 -0
- package/translations/ms.json +2 -0
- package/translations/zh.json +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mode-categories.js","sourceRoot":"","sources":["../../../server/service/assistant-mode/mode-categories.ts"],"names":[],"mappings":";;;AA4BA,oEAEC;AAED,4DAEC;AAED,kEAEC;AAGD,4CAGC;AAMD,gDAcC;AAQD,4DAEC;AAsBD,0CAWC;AASD,4CAQC;AAaD,kDAqBC;AAGD,kCAKC;AAtKD,0GAA0G;AAC1G,mEAA6D;AAC7D,gEAAwE;AACxE,iEAA8D;AAC9D,6DAA4D;AAsB5D,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAgC,CAAA;AAEtE,SAAgB,4BAA4B,CAAC,QAA8B;IACzE,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AACrD,CAAC;AAED,SAAgB,wBAAwB;IACtC,OAAO,CAAC,GAAG,sBAAsB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AG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IACpE,OAAO,CAAC,EAAE,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAA;AAC9F,CAAC","sourcesContent":["/* Read by the resolver and by the boot report, so the report and the conversation open the same tools. */\nimport { entryTargetOf } from '../data-entry/entry-target.js'\nimport { detailReadOf, readTargetOf } from '../data-read/read-target.js'\nimport { HELP_CATEGORY } from '../help-documents/help-keys.js'\nimport { PEOPLE_CATEGORIES } from '../people/people-keys.js'\n/**\n * A category another package opens in every conversation - a dashboard card (ADR-0160 decision 9). It is in reach of\n * every conversation; it is put in front only on the pages it names, and found with `openTools` elsewhere (ADR-0061\n * decision 9). Never in an unattended run: its tools are proposals, and nobody is there to press the card.\n */\nexport interface ConversationCategory {\n name: string\n /** The application routes whose conversations put it in front (`my-dashboard`). */\n frontPages?: string[]\n /**\n * The axes of the records whose selection or anchor puts it in front (`dashboard-card`) - a card picked to change is\n * changed by this category's tools, wherever the dock is open.\n */\n frontAxes?: string[]\n /**\n * What a turn asked from one of its front pages must end in - said in that turn's system prompt only. On 나의 대시보드\n * a request to see a figure is a card; asked 「이번 달 지출 합계」 there, the model answered 「0원」 in words (2026-10-25).\n */\n pageRule?: string\n}\n\nconst conversationCategories = new Map<string, ConversationCategory>()\n\nexport function registerConversationCategory(category: ConversationCategory): void {\n conversationCategories.set(category.name, category)\n}\n\nexport function conversationCategoriesOf(): ConversationCategory[] {\n return [...conversationCategories.values()]\n}\n\nexport function clearConversationCategories(): void {\n conversationCategories.clear()\n}\n\n/** The system prompt of one turn - the mode's, the open record's line, and the rules of the page it is asked from. */\nexport function turnSystemPrompt(modePrompt: string, screen: { page?: string; subjectLine?: string } = {}): string {\n const pageRules = screen.page ? conversationCategoriesOf().filter(one => one.pageRule && (one.frontPages ?? []).includes(screen.page!)).map(one => one.pageRule!) : []\n return [modePrompt, screen.subjectLine, ...pageRules].filter(Boolean).join('\\n\\n')\n}\n\n/**\n * The categories a mode opens: its own, the AI 작업 패널 (design/ai/workspace.md), the attachment reader when it\n * takes files (design/ai/shared-dock.md §9-4), and one propose tool per record it may enter (design/ai/data-entry.md).\n */\nexport function modeToolCategories(mode: { toolCategories?: string[]; attachments?: { kinds?: string[] }; entryTargets?: string[]; readTargets?: string[] }): string[] | undefined {\n const extra = [\n /* Every conversation may put a large result on the AI 작업 패널 (design/ai/workspace.md). */\n 'assistant-workspace',\n /* Every conversation may read who works here and offer to bring one of them in (people/, ADR-0073 decision 3). */\n ...PEOPLE_CATEGORIES,\n /* Every conversation may read the application's help (ADR-0181). */\n HELP_CATEGORY,\n ...(mode.attachments?.kinds?.length ? ['chat-attachments'] : []),\n ...(mode.entryTargets ?? []).map(key => `data-entry:${key}`),\n ...(mode.readTargets ?? []).map(key => `data-read:${key}`),\n ...conversationCategoriesOf().map(one => one.name)\n ]\n return [...new Set([...(mode.toolCategories ?? []), ...extra])]\n}\n\n/**\n * The categories an unattended run of a mode opens: its own and the lists it reads (design/ai/unattended-run.md §3).\n *\n * Not the 입력안 tools - nobody is there to press the card - nor the AI 작업 패널 or the attachment reader: there is no\n * conversation for a card or a file to belong to.\n */\nexport function unattendedToolCategories(mode: { toolCategories?: string[]; readTargets?: string[] }): string[] {\n return [...new Set([...(mode.toolCategories ?? []), ...(mode.readTargets ?? []).map(key => `data-read:${key}`)])]\n}\n\n/** The screen a turn is asked from - the page the dock is on, and the record its conversation is anchored to. */\nexport interface TurnScreen {\n /** The application's route of the open page (`cash-transaction-list`), as the dock sends it. */\n page?: string\n /** The axis of the record the conversation is anchored to (`contract` of `subject` · `contract:<id>`), from the stored anchor. */\n subjectAxis?: string\n /** The axes of the records the latest selection named (`contract` of `[keys] contracts contract:<id>`) - `selectionAxesOf`. */\n selectionAxes?: string[]\n}\n\n/** The line of a selection note the model reads - the client's `SELECTION_KEYS_PREFIX` (assistant-selection.ts). */\nexport const SELECTION_KEYS_LINE = '[keys]'\n\n/**\n * The axes of the records the latest selection note names (「AI와 작업」, shared-dock §2-11-1): a list hands its rows as\n * `<axis>:<uuid>`, so the rows' list is read with the tool of that axis. Put in front like an anchored record's - picked\n * on 미수금, the contracts' read was not in front, and the model looked for them among attachments and a dashboard's cards\n * before it opened the right tool (2026-10-25). A note is the server's (`appendSessionNote`, system); a person's words\n * are never read for it.\n */\nexport function selectionAxesOf(rows: { role?: string; content?: string | null }[]): string[] {\n for (let i = rows.length - 1; i >= 0; i--) {\n if (rows[i].role !== 'system') continue\n const line = String(rows[i].content ?? '')\n .split('\\n')\n .find(one => one.startsWith(SELECTION_KEYS_LINE))\n if (!line) continue\n const keys = line.slice(SELECTION_KEYS_LINE.length).trim().split(/\\s+/)\n return [...new Set(keys.map(one => one.match(/^([a-z0-9-]+):/)?.[1]).filter((one): one is string => !!one))]\n }\n return []\n}\n\ntype FrontMode = { toolCategories?: string[]; attachments?: { kinds?: string[] }; entryTargets?: string[]; readTargets?: string[] }\n\n/**\n * The records the open screen is about, among those the mode reads and enters (ADR-0061 decision 9). Nothing new is\n * declared: a read target's screen route is the page that lists it, and a key's last part is the axis of its record\n * (`office.contract` is the record of the axis `contract`) - reading and entering one record share its key.\n */\nexport function screenTargetKeys(mode: FrontMode, screen: TurnScreen, routeOf: (key: string) => string | undefined = key => readTargetOf(key)?.screen?.route): string[] {\n const keys = [...new Set([...(mode.readTargets ?? []), ...(mode.entryTargets ?? [])])]\n return keys.filter(\n key =>\n (!!screen.page && routeOf(key) === screen.page) ||\n (!!screen.subjectAxis && axesOfKey(mode, key).includes(screen.subjectAxis)) ||\n (!!screen.selectionAxes?.length && axesOfKey(mode, key).some(axis => screen.selectionAxes!.includes(axis)))\n )\n}\n\n/** The records a key is about: its last part, and the axes a card joins or a whole answer covers (EntryTarget.axes · DetailRead.axes). */\nfunction axesOfKey(mode: FrontMode, key: string): string[] {\n const card = (mode.entryTargets ?? []).includes(key) ? entryTargetOf(key)?.axes ?? [] : []\n const answer = (mode.readTargets ?? []).includes(key) ? detailReadOf(key)?.axes ?? [] : []\n return [key.split('.').pop()!, ...card, ...answer]\n}\n\n/**\n * The categories a turn puts in front when the mode's tools do not fit in one call: the mode's own, the AI 작업 패널, the\n * people list and the invite card, the attachment reader, and the open screen's records. The rest the model opens with `openTools`.\n */\nexport function modeFrontCategories(mode: FrontMode, screen: TurnScreen = {}): string[] {\n const keys = screenTargetKeys(mode, screen)\n return [\n ...new Set([\n ...(mode.toolCategories ?? []),\n 'assistant-workspace',\n /*\n * Two tools, always in front: 「정연희 초대해 줘」 asked in a conversation whose tools did not fit got the answer that\n * there was no tool to look people up (2026-10-24).\n */\n ...PEOPLE_CATEGORIES,\n /* Two tools, always in front: 「지출결의는 어디서 올려?」 is asked on any screen (ADR-0181). */\n HELP_CATEGORY,\n ...(mode.attachments?.kinds?.length ? ['chat-attachments'] : []),\n ...keys.filter(key => (mode.readTargets ?? []).includes(key)).map(key => `data-read:${key}`),\n ...keys.filter(key => (mode.entryTargets ?? []).includes(key)).map(key => `data-entry:${key}`),\n ...conversationCategoriesOf()\n .filter(one => (!!screen.page && (one.frontPages ?? []).includes(screen.page)) || (one.frontAxes ?? []).some(axis => axis === screen.subjectAxis || !!screen.selectionAxes?.includes(axis)))\n .map(one => one.name)\n ])\n ]\n}\n\n/** Each screen the mode could be asked from - a page that lists one of its records, a record's axis - for the boot report. */\nexport function modeScreens(mode: FrontMode, routeOf: (key: string) => string | undefined = key => readTargetOf(key)?.screen?.route): TurnScreen[] {\n const keys = [...new Set([...(mode.readTargets ?? []), ...(mode.entryTargets ?? [])])]\n const pages = [...new Set([...keys.map(routeOf), ...conversationCategoriesOf().flatMap(one => one.frontPages ?? [])].filter(Boolean) as string[])]\n const axes = [...new Set(keys.flatMap(key => axesOfKey(mode, key)))]\n return [{}, ...pages.map(page => ({ page })), ...axes.map(subjectAxis => ({ subjectAxis }))]\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mode-categories.js","sourceRoot":"","sources":["../../../server/service/assistant-mode/mode-categories.ts"],"names":[],"mappings":";;;AA4BA,oEAEC;AAED,4DAEC;AAED,kEAEC;AAGD,4CAGC;AAMD,gDAcC;AAQD,4DAEC;AAsBD,0CAWC;AAUD,4CAQC;AAuBD,kDAqBC;AAGD,kCAKC;AAjLD,0GAA0G;AAC1G,mEAA6D;AAC7D,gEAAwE;AACxE,iEAA8D;AAC9D,6DAA4D;AAsB5D,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAgC,CAAA;AAEtE,SAAgB,4BAA4B,CAAC,QAA8B;IACzE,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AACrD,CAAC;AAED,SAAgB,wBAAwB;IACtC,OAAO,CAAC,GAAG,sBAAsB,CAAC,MAAM,EAAE,CAAC,CAAA;AAC7C,CAAC;AAED,SAAgB,2BAA2B;IACzC,sBAAsB,CAAC,KAAK,EAAE,CAAA;AAChC,CAAC;AAED,sHAAsH;AACtH,SAAgB,gBAAgB,CAAC,UAAkB,EAAE,SAAkD,EAAE;IACvG,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,wBAAwB,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACtK,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG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,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACxJ,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IACpE,OAAO,CAAC,EAAE,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAA;AAC9F,CAAC","sourcesContent":["/* Read by the resolver and by the boot report, so the report and the conversation open the same tools. */\nimport { entryTargetOf } from '../data-entry/entry-target.js'\nimport { detailReadOf, readTargetOf } from '../data-read/read-target.js'\nimport { HELP_CATEGORY } from '../help-documents/help-keys.js'\nimport { PEOPLE_CATEGORIES } from '../people/people-keys.js'\n/**\n * A category another package opens in every conversation - a dashboard card (ADR-0160 decision 9). It is in reach of\n * every conversation; it is put in front only on the pages it names, and found with `openTools` elsewhere (ADR-0061\n * decision 9). Never in an unattended run: its tools are proposals, and nobody is there to press the card.\n */\nexport interface ConversationCategory {\n name: string\n /** The application routes whose conversations put it in front (`my-dashboard`). */\n frontPages?: string[]\n /**\n * The axes of the records whose selection or anchor puts it in front (`dashboard-card`) - a card picked to change is\n * changed by this category's tools, wherever the dock is open.\n */\n frontAxes?: string[]\n /**\n * What a turn asked from one of its front pages must end in - said in that turn's system prompt only. On 나의 대시보드\n * a request to see a figure is a card; asked 「이번 달 지출 합계」 there, the model answered 「0원」 in words (2026-10-25).\n */\n pageRule?: string\n}\n\nconst conversationCategories = new Map<string, ConversationCategory>()\n\nexport function registerConversationCategory(category: ConversationCategory): void {\n conversationCategories.set(category.name, category)\n}\n\nexport function conversationCategoriesOf(): ConversationCategory[] {\n return [...conversationCategories.values()]\n}\n\nexport function clearConversationCategories(): void {\n conversationCategories.clear()\n}\n\n/** The system prompt of one turn - the mode's, the open record's line, and the rules of the page it is asked from. */\nexport function turnSystemPrompt(modePrompt: string, screen: { page?: string; subjectLine?: string } = {}): string {\n const pageRules = screen.page ? conversationCategoriesOf().filter(one => one.pageRule && (one.frontPages ?? []).includes(screen.page!)).map(one => one.pageRule!) : []\n return [modePrompt, screen.subjectLine, ...pageRules].filter(Boolean).join('\\n\\n')\n}\n\n/**\n * The categories a mode opens: its own, the AI 작업 패널 (design/ai/workspace.md), the attachment reader when it\n * takes files (design/ai/shared-dock.md §9-4), and one propose tool per record it may enter (design/ai/data-entry.md).\n */\nexport function modeToolCategories(mode: { toolCategories?: string[]; attachments?: { kinds?: string[] }; entryTargets?: string[]; readTargets?: string[] }): string[] | undefined {\n const extra = [\n /* Every conversation may put a large result on the AI 작업 패널 (design/ai/workspace.md). */\n 'assistant-workspace',\n /* Every conversation may read who works here and offer to bring one of them in (people/, ADR-0073 decision 3). */\n ...PEOPLE_CATEGORIES,\n /* Every conversation may read the application's help (ADR-0181). */\n HELP_CATEGORY,\n ...(mode.attachments?.kinds?.length ? ['chat-attachments'] : []),\n ...(mode.entryTargets ?? []).map(key => `data-entry:${key}`),\n ...(mode.readTargets ?? []).map(key => `data-read:${key}`),\n ...conversationCategoriesOf().map(one => one.name)\n ]\n return [...new Set([...(mode.toolCategories ?? []), ...extra])]\n}\n\n/**\n * The categories an unattended run of a mode opens: its own and the lists it reads (design/ai/unattended-run.md §3).\n *\n * Not the 입력안 tools - nobody is there to press the card - nor the AI 작업 패널 or the attachment reader: there is no\n * conversation for a card or a file to belong to.\n */\nexport function unattendedToolCategories(mode: { toolCategories?: string[]; readTargets?: string[] }): string[] {\n return [...new Set([...(mode.toolCategories ?? []), ...(mode.readTargets ?? []).map(key => `data-read:${key}`)])]\n}\n\n/** The screen a turn is asked from - the page the dock is on, and the record its conversation is anchored to. */\nexport interface TurnScreen {\n /** The application's route of the open page (`cash-transaction-list`), as the dock sends it. */\n page?: string\n /** The axis of the record the conversation is anchored to (`contract` of `subject` · `contract:<id>`), from the stored anchor. */\n subjectAxis?: string\n /** The axes of the records the latest selection named (`contract` of `[keys] contracts contract:<id>`) - `selectionAxesOf`. */\n selectionAxes?: string[]\n}\n\n/** The line of a selection note the model reads - the client's `SELECTION_KEYS_PREFIX` (assistant-selection.ts). */\nexport const SELECTION_KEYS_LINE = '[keys]'\n\n/**\n * The axes of the records the latest selection note names (「AI와 작업」, shared-dock §2-11-1): a list hands its rows as\n * `<axis>:<uuid>`, so the rows' list is read with the tool of that axis. Put in front like an anchored record's - picked\n * on 미수금, the contracts' read was not in front, and the model looked for them among attachments and a dashboard's cards\n * before it opened the right tool (2026-10-25). A note is the server's (`appendSessionNote`, system); a person's words\n * are never read for it.\n */\nexport function selectionAxesOf(rows: { role?: string; content?: string | null }[]): string[] {\n for (let i = rows.length - 1; i >= 0; i--) {\n if (rows[i].role !== 'system') continue\n const line = String(rows[i].content ?? '')\n .split('\\n')\n .find(one => one.startsWith(SELECTION_KEYS_LINE))\n if (!line) continue\n const keys = line.slice(SELECTION_KEYS_LINE.length).trim().split(/\\s+/)\n return [...new Set(keys.map(one => one.match(/^([a-z0-9-]+):/)?.[1]).filter((one): one is string => !!one))]\n }\n return []\n}\n\ntype FrontMode = { toolCategories?: string[]; attachments?: { kinds?: string[] }; entryTargets?: string[]; readTargets?: string[] }\n\n/**\n * The records the open screen is about, among those the mode reads and enters (ADR-0061 decision 9). A key's page is\n * the screen that lists its records (ReadTarget.screen.route), the screen a card's records are seen on\n * (EntryTarget.screen) and the pages a read of one record names (DetailRead.frontPages); a key's last part is the axis\n * of its record (`office.contract` is the record of the axis `contract`) - reading and entering one record share its key.\n */\nexport function screenTargetKeys(mode: FrontMode, screen: TurnScreen, routeOf: (key: string) => string | undefined = key => readTargetOf(key)?.screen?.route): string[] {\n const keys = [...new Set([...(mode.readTargets ?? []), ...(mode.entryTargets ?? [])])]\n return keys.filter(\n key =>\n (!!screen.page && pagesOfKey(mode, key, routeOf).includes(screen.page)) ||\n (!!screen.subjectAxis && axesOfKey(mode, key).includes(screen.subjectAxis)) ||\n (!!screen.selectionAxes?.length && axesOfKey(mode, key).some(axis => screen.selectionAxes!.includes(axis)))\n )\n}\n\n/**\n * The pages a key is in front on. A card's own screen counts as its page: on 내 주간업무보고 the report line card was\n * not in front, the model opened it with `openTools`, and the answer that followed was hidden (2026-11-12).\n */\nfunction pagesOfKey(mode: FrontMode, key: string, routeOf: (key: string) => string | undefined): string[] {\n const card = (mode.entryTargets ?? []).includes(key) ? entryTargetOf(key)?.screen : undefined\n const answer = (mode.readTargets ?? []).includes(key) ? detailReadOf(key)?.frontPages ?? [] : []\n return [routeOf(key), card, ...answer].filter((page): page is string => !!page)\n}\n\n/** The records a key is about: its last part, and the axes a card joins or a whole answer covers (EntryTarget.axes · DetailRead.axes). */\nfunction axesOfKey(mode: FrontMode, key: string): string[] {\n const card = (mode.entryTargets ?? []).includes(key) ? entryTargetOf(key)?.axes ?? [] : []\n const answer = (mode.readTargets ?? []).includes(key) ? detailReadOf(key)?.axes ?? [] : []\n return [key.split('.').pop()!, ...card, ...answer]\n}\n\n/**\n * The categories a turn puts in front when the mode's tools do not fit in one call: the mode's own, the AI 작업 패널, the\n * people list and the invite card, the attachment reader, and the open screen's records. The rest the model opens with `openTools`.\n */\nexport function modeFrontCategories(mode: FrontMode, screen: TurnScreen = {}): string[] {\n const keys = screenTargetKeys(mode, screen)\n return [\n ...new Set([\n ...(mode.toolCategories ?? []),\n 'assistant-workspace',\n /*\n * Two tools, always in front: 「정연희 초대해 줘」 asked in a conversation whose tools did not fit got the answer that\n * there was no tool to look people up (2026-10-24).\n */\n ...PEOPLE_CATEGORIES,\n /* Two tools, always in front: 「지출결의는 어디서 올려?」 is asked on any screen (ADR-0181). */\n HELP_CATEGORY,\n ...(mode.attachments?.kinds?.length ? ['chat-attachments'] : []),\n ...keys.filter(key => (mode.readTargets ?? []).includes(key)).map(key => `data-read:${key}`),\n ...keys.filter(key => (mode.entryTargets ?? []).includes(key)).map(key => `data-entry:${key}`),\n ...conversationCategoriesOf()\n .filter(one => (!!screen.page && (one.frontPages ?? []).includes(screen.page)) || (one.frontAxes ?? []).some(axis => axis === screen.subjectAxis || !!screen.selectionAxes?.includes(axis)))\n .map(one => one.name)\n ])\n ]\n}\n\n/** Each screen the mode could be asked from - a page that lists one of its records, a record's axis - for the boot report. */\nexport function modeScreens(mode: FrontMode, routeOf: (key: string) => string | undefined = key => readTargetOf(key)?.screen?.route): TurnScreen[] {\n const keys = [...new Set([...(mode.readTargets ?? []), ...(mode.entryTargets ?? [])])]\n const pages = [...new Set([...keys.flatMap(key => pagesOfKey(mode, key, routeOf)), ...conversationCategoriesOf().flatMap(one => one.frontPages ?? [])])]\n const axes = [...new Set(keys.flatMap(key => axesOfKey(mode, key)))]\n return [{}, ...pages.map(page => ({ page })), ...axes.map(subjectAxis => ({ subjectAxis }))]\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface TurnLineInput {
|
|
2
|
+
/** The application's route of the open page, as the dock sends it - it only narrows what is the asker's own. */
|
|
3
|
+
page?: string;
|
|
4
|
+
/** The request state - domain and user. */
|
|
5
|
+
state: any;
|
|
6
|
+
}
|
|
7
|
+
export type TurnLine = (input: TurnLineInput) => string | undefined | Promise<string | undefined>;
|
|
8
|
+
/** A module adds its line, by name - a second registration of the name replaces the first. */
|
|
9
|
+
export declare function registerTurnLine(name: string, line: TurnLine): void;
|
|
10
|
+
export declare function turnLinesOf(input: TurnLineInput): Promise<string[]>;
|
|
11
|
+
/** Test only. */
|
|
12
|
+
export declare function clearTurnLines(): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerTurnLine = registerTurnLine;
|
|
4
|
+
exports.turnLinesOf = turnLinesOf;
|
|
5
|
+
exports.clearTurnLines = clearTurnLines;
|
|
6
|
+
/*
|
|
7
|
+
* Lines a module adds to one turn's system prompt, after the open subject's - what the person has in front of them that
|
|
8
|
+
* the conversation does not hold. notification says the unread notices of the screen the dock is on, so the assistant
|
|
9
|
+
* knows what the person was told there (ADR-0199 amendment 1).
|
|
10
|
+
*
|
|
11
|
+
* A line is the module's to build from the asker's own records, read as them; a value a person typed goes in as data.
|
|
12
|
+
* One that fails is left out - a turn is never refused for a line.
|
|
13
|
+
*/
|
|
14
|
+
const env_1 = require("@things-factory/env");
|
|
15
|
+
const lines = new Map();
|
|
16
|
+
/** A module adds its line, by name - a second registration of the name replaces the first. */
|
|
17
|
+
function registerTurnLine(name, line) {
|
|
18
|
+
lines.set(name, line);
|
|
19
|
+
}
|
|
20
|
+
async function turnLinesOf(input) {
|
|
21
|
+
const said = [];
|
|
22
|
+
for (const [name, line] of lines) {
|
|
23
|
+
try {
|
|
24
|
+
const one = await line(input);
|
|
25
|
+
if (one)
|
|
26
|
+
said.push(one);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
env_1.logger.error(`[ai-assistant/turn-lines] ${name} failed: ${error?.message ?? error}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return said;
|
|
33
|
+
}
|
|
34
|
+
/** Test only. */
|
|
35
|
+
function clearTurnLines() {
|
|
36
|
+
lines.clear();
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=turn-lines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-lines.js","sourceRoot":"","sources":["../../../server/service/assistant-mode/turn-lines.ts"],"names":[],"mappings":";;AAsBA,4CAEC;AAED,kCAWC;AAGD,wCAEC;AA1CD;;;;;;;GAOG;AACH,6CAA4C;AAW5C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAA;AAEzC,8FAA8F;AAC9F,SAAgB,gBAAgB,CAAC,IAAY,EAAE,IAAc;IAC3D,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACvB,CAAC;AAEM,KAAK,UAAU,WAAW,CAAC,KAAoB;IACpD,MAAM,IAAI,GAAa,EAAE,CAAA;IACzB,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC;QACjC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,CAAA;YAC7B,IAAI,GAAG;gBAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACzB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,YAAM,CAAC,KAAK,CAAC,6BAA6B,IAAI,YAAY,KAAK,EAAE,OAAO,IAAI,KAAK,EAAE,CAAC,CAAA;QACtF,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,iBAAiB;AACjB,SAAgB,cAAc;IAC5B,KAAK,CAAC,KAAK,EAAE,CAAA;AACf,CAAC","sourcesContent":["/*\n * Lines a module adds to one turn's system prompt, after the open subject's - what the person has in front of them that\n * the conversation does not hold. notification says the unread notices of the screen the dock is on, so the assistant\n * knows what the person was told there (ADR-0199 amendment 1).\n *\n * A line is the module's to build from the asker's own records, read as them; a value a person typed goes in as data.\n * One that fails is left out - a turn is never refused for a line.\n */\nimport { logger } from '@things-factory/env'\n\nexport interface TurnLineInput {\n /** The application's route of the open page, as the dock sends it - it only narrows what is the asker's own. */\n page?: string\n /** The request state - domain and user. */\n state: any\n}\n\nexport type TurnLine = (input: TurnLineInput) => string | undefined | Promise<string | undefined>\n\nconst lines = new Map<string, TurnLine>()\n\n/** A module adds its line, by name - a second registration of the name replaces the first. */\nexport function registerTurnLine(name: string, line: TurnLine): void {\n lines.set(name, line)\n}\n\nexport async function turnLinesOf(input: TurnLineInput): Promise<string[]> {\n const said: string[] = []\n for (const [name, line] of lines) {\n try {\n const one = await line(input)\n if (one) said.push(one)\n } catch (error: any) {\n logger.error(`[ai-assistant/turn-lines] ${name} failed: ${error?.message ?? error}`)\n }\n }\n return said\n}\n\n/** Test only. */\nexport function clearTurnLines(): void {\n lines.clear()\n}\n"]}
|
|
@@ -3,3 +3,4 @@ export { ChatMessage };
|
|
|
3
3
|
export { ChatMessageSubscription, publishChatMessage, CHAT_MESSAGE_TOPIC, chatMessageFilter } from './chat-message-subscription.js';
|
|
4
4
|
export type { ChatMessagePayload } from './chat-message-subscription.js';
|
|
5
5
|
export declare const entities: (typeof ChatMessage)[];
|
|
6
|
+
export { onRoomTurn, type RoomTurn } from './room-turn.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.entities = exports.chatMessageFilter = exports.CHAT_MESSAGE_TOPIC = exports.publishChatMessage = exports.ChatMessageSubscription = exports.ChatMessage = void 0;
|
|
3
|
+
exports.onRoomTurn = exports.entities = exports.chatMessageFilter = exports.CHAT_MESSAGE_TOPIC = exports.publishChatMessage = exports.ChatMessageSubscription = exports.ChatMessage = void 0;
|
|
4
4
|
const chat_message_js_1 = require("./chat-message.js");
|
|
5
5
|
Object.defineProperty(exports, "ChatMessage", { enumerable: true, get: function () { return chat_message_js_1.ChatMessage; } });
|
|
6
6
|
var chat_message_subscription_js_1 = require("./chat-message-subscription.js");
|
|
@@ -9,4 +9,6 @@ Object.defineProperty(exports, "publishChatMessage", { enumerable: true, get: fu
|
|
|
9
9
|
Object.defineProperty(exports, "CHAT_MESSAGE_TOPIC", { enumerable: true, get: function () { return chat_message_subscription_js_1.CHAT_MESSAGE_TOPIC; } });
|
|
10
10
|
Object.defineProperty(exports, "chatMessageFilter", { enumerable: true, get: function () { return chat_message_subscription_js_1.chatMessageFilter; } });
|
|
11
11
|
exports.entities = [chat_message_js_1.ChatMessage];
|
|
12
|
+
var room_turn_js_1 = require("./room-turn.js");
|
|
13
|
+
Object.defineProperty(exports, "onRoomTurn", { enumerable: true, get: function () { return room_turn_js_1.onRoomTurn; } });
|
|
12
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/chat-message/index.ts"],"names":[],"mappings":";;;AAAA,uDAA+C;AAEtC,4FAFA,6BAAW,OAEA;AACpB,+EAKuC;AAJrC,uIAAA,uBAAuB,OAAA;AACvB,kIAAA,kBAAkB,OAAA;AAClB,kIAAA,kBAAkB,OAAA;AAClB,iIAAA,iBAAiB,OAAA;AAIN,QAAA,QAAQ,GAAG,CAAC,6BAAW,CAAC,CAAA","sourcesContent":["import { ChatMessage } from './chat-message.js'\n\nexport { ChatMessage }\nexport {\n ChatMessageSubscription,\n publishChatMessage,\n CHAT_MESSAGE_TOPIC,\n chatMessageFilter\n} from './chat-message-subscription.js'\nexport type { ChatMessagePayload } from './chat-message-subscription.js'\n\nexport const entities = [ChatMessage]\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/chat-message/index.ts"],"names":[],"mappings":";;;AAAA,uDAA+C;AAEtC,4FAFA,6BAAW,OAEA;AACpB,+EAKuC;AAJrC,uIAAA,uBAAuB,OAAA;AACvB,kIAAA,kBAAkB,OAAA;AAClB,kIAAA,kBAAkB,OAAA;AAClB,iIAAA,iBAAiB,OAAA;AAIN,QAAA,QAAQ,GAAG,CAAC,6BAAW,CAAC,CAAA;AACrC,+CAA0D;AAAjD,0GAAA,UAAU,OAAA","sourcesContent":["import { ChatMessage } from './chat-message.js'\n\nexport { ChatMessage }\nexport {\n ChatMessageSubscription,\n publishChatMessage,\n CHAT_MESSAGE_TOPIC,\n chatMessageFilter\n} from './chat-message-subscription.js'\nexport type { ChatMessagePayload } from './chat-message-subscription.js'\n\nexport const entities = [ChatMessage]\nexport { onRoomTurn, type RoomTurn } from './room-turn.js'\n"]}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
/** 답에 실린 도구 한 번 — 이름과 어떻게 끝났는가(agentic loop 의 ToolUsage). */
|
|
2
|
+
export interface AnswerToolUse {
|
|
3
|
+
name: string;
|
|
4
|
+
outcome?: string;
|
|
5
|
+
}
|
|
1
6
|
/**
|
|
2
|
-
* 이 답이 지난 문들 —
|
|
7
|
+
* 이 답이 지난 문들 — 값을 읽은 도구들의 문을 합친다(중복 없이, 정렬).
|
|
8
|
+
*
|
|
9
|
+
* 도구 꺼내기(`openTools`, ADR-0061 결정 9)는 도구 이름을 열 뿐 값을 읽지 않는다. 등록기에 없으므로
|
|
10
|
+
* 아래 규칙대로 두면 아무도 못 지나는 자리가 되어, 꺼내기를 쓴 답은 묻는 사람 본인까지 누구도 못
|
|
11
|
+
* 읽었다(2026-11-12 운영: 가려진 답 22건 중 19건).
|
|
3
12
|
*
|
|
4
|
-
* 등록기에 없는 도구가 답에 끼면 그 도구가 무엇을 읽었는지 알 길이 없다. 그때 `[]`(누구나
|
|
5
|
-
* 적으면 모르는 값이 공개된다. 아무도 못 지나는 이름을 적어 **가려지는 쪽**으로 넘어뜨리고,
|
|
6
|
-
* 원인을 실어 둔다.
|
|
13
|
+
* 등록기에 없는 도구가 값을 읽고 답에 끼면 그 도구가 무엇을 읽었는지 알 길이 없다. 그때 `[]`(누구나
|
|
14
|
+
* 읽는 답)로 적으면 모르는 값이 공개된다. 아무도 못 지나는 이름을 적어 **가려지는 쪽**으로 넘어뜨리고,
|
|
15
|
+
* 이름에 원인을 실어 둔다.
|
|
7
16
|
*/
|
|
8
|
-
export declare function doorsForAnswer(
|
|
17
|
+
export declare function doorsForAnswer(usages: readonly AnswerToolUse[], doorsOf: (name: string) => string[] | undefined): string[];
|
|
9
18
|
/**
|
|
10
19
|
* 한 요청 안에서 (사람, 문) 별로 한 번만 묻는 관문.
|
|
11
20
|
*
|
|
@@ -28,18 +28,31 @@ exports.doorsForAnswer = doorsForAnswer;
|
|
|
28
28
|
exports.doorGate = doorGate;
|
|
29
29
|
exports.passesRow = passesRow;
|
|
30
30
|
exports.redactByDoors = redactByDoors;
|
|
31
|
+
const ai_client_base_1 = require("@things-factory/ai-client-base");
|
|
31
32
|
/** 문 이름으로 보이지 않는 값 — 등록되지 않은 도구가 답에 끼었을 때. */
|
|
32
33
|
const UNRESOLVED = 'unresolved:';
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
+
* 값을 읽지 않은 호출 — 거절·오류로 끝난 호출은 결과에 데이터가 없다(무엇이 빠졌는지·왜 못 했는지만).
|
|
36
|
+
* 그 문을 답에 적으면 그 문을 못 지나는 사람, 곧 **거절당한 본인**에게 자기 답이 가려진다(2026-11-12
|
|
37
|
+
* 운영: 직원 목록 조회가 거절된 답이 묻는 사람에게 가려짐).
|
|
38
|
+
*/
|
|
39
|
+
const READ_NOTHING = new Set(['rejected', 'error']);
|
|
40
|
+
/**
|
|
41
|
+
* 이 답이 지난 문들 — 값을 읽은 도구들의 문을 합친다(중복 없이, 정렬).
|
|
35
42
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
43
|
+
* 도구 꺼내기(`openTools`, ADR-0061 결정 9)는 도구 이름을 열 뿐 값을 읽지 않는다. 등록기에 없으므로
|
|
44
|
+
* 아래 규칙대로 두면 아무도 못 지나는 자리가 되어, 꺼내기를 쓴 답은 묻는 사람 본인까지 누구도 못
|
|
45
|
+
* 읽었다(2026-11-12 운영: 가려진 답 22건 중 19건).
|
|
46
|
+
*
|
|
47
|
+
* 등록기에 없는 도구가 값을 읽고 답에 끼면 그 도구가 무엇을 읽었는지 알 길이 없다. 그때 `[]`(누구나
|
|
48
|
+
* 읽는 답)로 적으면 모르는 값이 공개된다. 아무도 못 지나는 이름을 적어 **가려지는 쪽**으로 넘어뜨리고,
|
|
49
|
+
* 이름에 원인을 실어 둔다.
|
|
39
50
|
*/
|
|
40
|
-
function doorsForAnswer(
|
|
51
|
+
function doorsForAnswer(usages, doorsOf) {
|
|
41
52
|
const doors = new Set();
|
|
42
|
-
for (const name of
|
|
53
|
+
for (const { name, outcome } of usages) {
|
|
54
|
+
if (!name || name === ai_client_base_1.OPEN_TOOLS || (outcome && READ_NOTHING.has(outcome)))
|
|
55
|
+
continue;
|
|
43
56
|
const declared = doorsOf(name);
|
|
44
57
|
if (declared === undefined)
|
|
45
58
|
doors.add(`${UNRESOLVED}${name}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-doors.js","sourceRoot":"","sources":["../../../server/service/chat-message/message-doors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;
|
|
1
|
+
{"version":3,"file":"message-doors.js","sourceRoot":"","sources":["../../../server/service/chat-message/message-doors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AA+BH,wCAWC;AASD,4BAcC;AAGD,8BAKC;AAgBD,sCAwBC;AA/GD,mEAA2D;AAE3D,8CAA8C;AAC9C,MAAM,UAAU,GAAG,aAAa,CAAA;AAQhC;;;;GAIG;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;AAEnD;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAAC,MAAgC,EAAE,OAA+C;IAC9G,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IAE/B,KAAK,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,MAAM,EAAE,CAAC;QACvC,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,2BAAU,IAAI,CAAC,OAAO,IAAI,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAAE,SAAQ;QACpF,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9B,IAAI,QAAQ,KAAK,SAAS;YAAE,KAAK,CAAC,GAAG,CAAC,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC,CAAA;;YACxD,KAAK,MAAM,IAAI,IAAI,QA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G,CAAC,KAAK,IAAI,EAAE,CAAA;QAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;YACzD,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACb,SAAQ;QACV,CAAC;QAED,MAAM,MAAM,GAAQ,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;QACtD,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;YACnC,IAAI,KAAK,IAAI,MAAM;gBAAE,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAA;QAC3C,CAAC;QACD,6CAA6C;QAC7C,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAA;QACtB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAClB,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["/*\n * 답에 실린 문 — ADR-0073 판정 1.\n *\n * ── 무엇을 막는가 ─────────────────────────────────────────────────────────\n * 대화방은 도메인 안에서 공개다(ADR-0073 판정 2). 그런데 대화 안에는 어시스턴트가 도구 결과로 근거를\n * 대고 쓴 답이 들어 있고, 그 근거는 **부른 사람의 문**을 지나 얻은 값이다. 도구는 문을 지켰는데\n * 어시스턴트의 문장이 그 값을 이미 평문으로 적어 놓았다. 나중에 읽는 사람은 자기가 못 여는 문 너머의\n * 값을 어시스턴트의 말로 읽는다 — 도구 권한을 다 지켜도 **글로 새는 길**이다.\n *\n * 그래서 답 행에 그 답을 만든 도구들이 지난 문 목록을 적어 두고(사람의 말은 `[]`), 읽는 사람이 그 문을\n * 전부 지나는지 볼 때마다 확인한다. 못 지나면 본문 대신 한 줄이 나간다 — **행이 있다는 사실은 보이고\n * 값만 안 보인다.** 방에 무슨 일이 있었는지는 알 수 있고, 값은 자기 권한만큼만 읽는다.\n *\n * ── 시점은 뜻이 없다 ──────────────────────────────────────────────────────\n * 언제 들어왔는지로 가르지 않는다. 오전에 있었든 방금 들어왔든, 볼 수 있는 것은 본다. 권한이 나중에\n * 붙으면 그때부터 보이고, 떨어지면 그때부터 안 보인다. 저장된 행은 그대로 있고 **보는 일만** 달라진다.\n *\n * ── 모델이 읽는 이력도 같다 ───────────────────────────────────────────────\n * 부른 사람이 못 여는 문의 답은 모델에게도 가리고 보낸다. 가리지 않으면 모델이 그 값을 다음 답에 옮겨\n * 적어서, 문을 한 번도 안 지난 사람이 값을 갖게 된다. 가린 자리를 지우지 않고 한 줄로 남기는 이유도\n * 같다 — 모델이 \"그런 말 한 적 없다\"고 답하면 그것은 거짓말이다.\n *\n * 이 파일은 저장소·엔티티를 모르는 순수 판정이다.\n */\n\nimport { OPEN_TOOLS } from '@things-factory/ai-client-base'\n\n/** 문 이름으로 보이지 않는 값 — 등록되지 않은 도구가 답에 끼었을 때. */\nconst UNRESOLVED = 'unresolved:'\n\n/** 답에 실린 도구 한 번 — 이름과 어떻게 끝났는가(agentic loop 의 ToolUsage). */\nexport interface AnswerToolUse {\n name: string\n outcome?: string\n}\n\n/**\n * 값을 읽지 않은 호출 — 거절·오류로 끝난 호출은 결과에 데이터가 없다(무엇이 빠졌는지·왜 못 했는지만).\n * 그 문을 답에 적으면 그 문을 못 지나는 사람, 곧 **거절당한 본인**에게 자기 답이 가려진다(2026-11-12\n * 운영: 직원 목록 조회가 거절된 답이 묻는 사람에게 가려짐).\n */\nconst READ_NOTHING = new Set(['rejected', 'error'])\n\n/**\n * 이 답이 지난 문들 — 값을 읽은 도구들의 문을 합친다(중복 없이, 정렬).\n *\n * 도구 꺼내기(`openTools`, ADR-0061 결정 9)는 도구 이름을 열 뿐 값을 읽지 않는다. 등록기에 없으므로\n * 아래 규칙대로 두면 아무도 못 지나는 자리가 되어, 꺼내기를 쓴 답은 묻는 사람 본인까지 누구도 못\n * 읽었다(2026-11-12 운영: 가려진 답 22건 중 19건).\n *\n * 등록기에 없는 도구가 값을 읽고 답에 끼면 그 도구가 무엇을 읽었는지 알 길이 없다. 그때 `[]`(누구나\n * 읽는 답)로 적으면 모르는 값이 공개된다. 아무도 못 지나는 이름을 적어 **가려지는 쪽**으로 넘어뜨리고,\n * 이름에 원인을 실어 둔다.\n */\nexport function doorsForAnswer(usages: readonly AnswerToolUse[], doorsOf: (name: string) => string[] | undefined): string[] {\n const doors = new Set<string>()\n\n for (const { name, outcome } of usages) {\n if (!name || name === OPEN_TOOLS || (outcome && READ_NOTHING.has(outcome))) continue\n const declared = doorsOf(name)\n if (declared === undefined) doors.add(`${UNRESOLVED}${name}`)\n else for (const door of declared) doors.add(door)\n }\n\n return [...doors].sort()\n}\n\n/**\n * 한 요청 안에서 (사람, 문) 별로 한 번만 묻는 관문.\n *\n * 한 화면이 백 줄을 읽고 그 줄들이 같은 문 서넛을 가리킨다. 줄마다 물으면 권한 조회가 백 번 간다.\n * 같은 요청 안에서 답이 바뀔 일은 없으므로 문 하나에 한 번 묻고 그 답을 쓴다. 관문은 요청마다 새로\n * 만든다 — 프로세스가 들고 있으면 권한이 바뀌어도 낡은 답을 준다.\n */\nexport function doorGate(check: (door: string) => Promise<boolean>): (door: string) => Promise<boolean> {\n const asked = new Map<string, Promise<boolean>>()\n\n return (door: string) => {\n /* 등록되지 않은 도구의 자리는 물을 것도 없다 — 지나는 사람이 없다. */\n if (door.startsWith(UNRESOLVED)) return Promise.resolve(false)\n\n let answer = asked.get(door)\n if (!answer) {\n answer = check(door)\n asked.set(door, answer)\n }\n return answer\n }\n}\n\n/** 이 사람이 이 행을 열 수 있나 — 적힌 문을 **전부** 지나야 한다(AND). */\nexport async function passesRow(doors: readonly string[] | null | undefined, gate: (door: string) => Promise<boolean>): Promise<boolean> {\n for (const door of doors ?? []) {\n if (!(await gate(door))) return false\n }\n return true\n}\n\n/** 문 판정에 필요한 만큼만 — 엔티티를 이 자리로 끌고 오지 않는다. */\nexport interface DoorReadableRow {\n doors?: string[] | null\n content?: string | null\n}\n\n/** 가린 행에서 값이 실려 있는 칸들 — 본문만 지우고 두면 그리로 새어 나간다. */\nconst VALUE_CARRYING = ['extra', 'proposals', 'grounding', 'patchEntryId', 'importSessionId'] as const\n\n/**\n * 못 지나는 행의 값을 가린다 — 행은 남기고 본문을 한 줄로 바꾼다.\n *\n * `notice` 는 부르는 쪽이 번역해 넘긴다(서버 번역, 화면 말은 서버가 만든다 — ADR-0061 결정 7).\n */\nexport async function redactByDoors<T extends DoorReadableRow>(\n rows: readonly T[],\n gate: (door: string) => Promise<boolean>,\n notice: (doors: string[]) => string\n): Promise<T[]> {\n const out: T[] = []\n\n for (const row of rows) {\n const doors = row.doors ?? []\n if (doors.length === 0 || (await passesRow(doors, gate))) {\n out.push(row)\n continue\n }\n\n const hidden: any = { ...row, content: notice(doors) }\n for (const field of VALUE_CARRYING) {\n if (field in hidden) hidden[field] = null\n }\n /* 가려졌다는 것 자체는 사실이다. 화면이 자물쇠를 그릴 수 있게 남긴다. */\n hidden.redacted = true\n out.push(hidden)\n }\n\n return out\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface RoomTurn {
|
|
2
|
+
domain: {
|
|
3
|
+
id: string;
|
|
4
|
+
};
|
|
5
|
+
/** Who spoke. */
|
|
6
|
+
user: {
|
|
7
|
+
id: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
};
|
|
11
|
+
session: {
|
|
12
|
+
id: string;
|
|
13
|
+
anchorType?: string | null;
|
|
14
|
+
anchorId?: string | null;
|
|
15
|
+
};
|
|
16
|
+
/** The message as stored. */
|
|
17
|
+
message: {
|
|
18
|
+
id: string;
|
|
19
|
+
content: string;
|
|
20
|
+
};
|
|
21
|
+
/** The request's transaction - a listener writes in it, so the turn and what it closed stand or fall together. */
|
|
22
|
+
tx?: any;
|
|
23
|
+
/** The request's translator. */
|
|
24
|
+
t?: (key: string, options?: any) => string;
|
|
25
|
+
}
|
|
26
|
+
type Listener = (turn: RoomTurn) => void | Promise<void>;
|
|
27
|
+
/** A module waits for people's words in conversations. Answers the way to stop. */
|
|
28
|
+
export declare function onRoomTurn(listener: Listener): () => void;
|
|
29
|
+
/** Every listener hears the turn; one that fails is logged and does not stop the person's words. */
|
|
30
|
+
export declare function tellRoomTurn(turn: RoomTurn): Promise<void>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onRoomTurn = onRoomTurn;
|
|
4
|
+
exports.tellRoomTurn = tellRoomTurn;
|
|
5
|
+
/*
|
|
6
|
+
* A person spoke to the people of a conversation - told to the modules that wait for it. worklist closes a question it
|
|
7
|
+
* handed to that person once they answer in the conversation it came from (ADR-0200 decision 3).
|
|
8
|
+
*
|
|
9
|
+
* Only the door that stores words to the room tells (`sendRoomMessage`): what the person asks the assistant - polish
|
|
10
|
+
* my draft - is not their answer.
|
|
11
|
+
*/
|
|
12
|
+
const env_1 = require("@things-factory/env");
|
|
13
|
+
const listeners = new Set();
|
|
14
|
+
/** A module waits for people's words in conversations. Answers the way to stop. */
|
|
15
|
+
function onRoomTurn(listener) {
|
|
16
|
+
listeners.add(listener);
|
|
17
|
+
return () => listeners.delete(listener);
|
|
18
|
+
}
|
|
19
|
+
/** Every listener hears the turn; one that fails is logged and does not stop the person's words. */
|
|
20
|
+
async function tellRoomTurn(turn) {
|
|
21
|
+
for (const listener of listeners) {
|
|
22
|
+
try {
|
|
23
|
+
await listener(turn);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
env_1.logger.error(`[ai-assistant/room-turn] a listener failed for session ${turn.session.id}: ${error?.message ?? error}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=room-turn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-turn.js","sourceRoot":"","sources":["../../../server/service/chat-message/room-turn.ts"],"names":[],"mappings":";;AA2BA,gCAGC;AAGD,oCAQC;AAzCD;;;;;;GAMG;AACH,6CAA4C;AAiB5C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAY,CAAA;AAErC,mFAAmF;AACnF,SAAgB,UAAU,CAAC,QAAkB;IAC3C,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACvB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;AACzC,CAAC;AAED,oGAAoG;AAC7F,KAAK,UAAU,YAAY,CAAC,IAAc;IAC/C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,IAAI,CAAC;YACH,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAA;QACtB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,YAAM,CAAC,KAAK,CAAC,0DAA0D,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,KAAK,EAAE,OAAO,IAAI,KAAK,EAAE,CAAC,CAAA;QACvH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/*\n * A person spoke to the people of a conversation - told to the modules that wait for it. worklist closes a question it\n * handed to that person once they answer in the conversation it came from (ADR-0200 decision 3).\n *\n * Only the door that stores words to the room tells (`sendRoomMessage`): what the person asks the assistant - polish\n * my draft - is not their answer.\n */\nimport { logger } from '@things-factory/env'\n\nexport interface RoomTurn {\n domain: { id: string }\n /** Who spoke. */\n user: { id: string; name?: string; email?: string }\n session: { id: string; anchorType?: string | null; anchorId?: string | null }\n /** The message as stored. */\n message: { id: string; content: string }\n /** The request's transaction - a listener writes in it, so the turn and what it closed stand or fall together. */\n tx?: any\n /** The request's translator. */\n t?: (key: string, options?: any) => string\n}\n\ntype Listener = (turn: RoomTurn) => void | Promise<void>\n\nconst listeners = new Set<Listener>()\n\n/** A module waits for people's words in conversations. Answers the way to stop. */\nexport function onRoomTurn(listener: Listener): () => void {\n listeners.add(listener)\n return () => listeners.delete(listener)\n}\n\n/** Every listener hears the turn; one that fails is logged and does not stop the person's words. */\nexport async function tellRoomTurn(turn: RoomTurn): Promise<void> {\n for (const listener of listeners) {\n try {\n await listener(turn)\n } catch (error: any) {\n logger.error(`[ai-assistant/room-turn] a listener failed for session ${turn.session.id}: ${error?.message ?? error}`)\n }\n }\n}\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** The text as a person reads it - `@Admin{userId:UUID}` is `@Admin`. Kept where a turn's words are stored as an answer. */
|
|
2
|
+
export declare function withoutMentionIds(text: string): string;
|
|
1
3
|
/** 본문에서 `@user{userId:UUID}` 마커의 userId 를 뽑는다 — 첫 등장 순, 중복 제거. */
|
|
2
4
|
export declare function extractMentionUserIds(text: string | null | undefined): string[];
|
|
3
5
|
/** 멘션된 사람 중 **아직 참여자가 아니고 자기 자신도 아닌** 새 사람만. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withoutMentionIds = withoutMentionIds;
|
|
3
4
|
exports.extractMentionUserIds = extractMentionUserIds;
|
|
4
5
|
exports.newParticipantUserIds = newParticipantUserIds;
|
|
5
6
|
exports.inviteMentionedUsers = inviteMentionedUsers;
|
|
@@ -34,6 +35,10 @@ exports.seatWriter = seatWriter;
|
|
|
34
35
|
* under the same rule - two ways in, one seat.
|
|
35
36
|
*/
|
|
36
37
|
const session_visibility_js_1 = require("../chat-session/session-visibility.js");
|
|
38
|
+
/** The text as a person reads it - `@Admin{userId:UUID}` is `@Admin`. Kept where a turn's words are stored as an answer. */
|
|
39
|
+
function withoutMentionIds(text) {
|
|
40
|
+
return text.replace(/\{userId:[^}\s]+\}/g, '');
|
|
41
|
+
}
|
|
37
42
|
/** 본문에서 `@user{userId:UUID}` 마커의 userId 를 뽑는다 — 첫 등장 순, 중복 제거. */
|
|
38
43
|
function extractMentionUserIds(text) {
|
|
39
44
|
if (!text)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mention-invite.js","sourceRoot":"","sources":["../../../server/service/chat-session-participant/mention-invite.ts"],"names":[],"mappings":";;AA8BA,sDAcC;AAGD,sDAeC;AAsBD,oDAIC;AAmBD,4CAuBC;AAUD,4BAGC;AAGD,gCAWC;AA7JD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,iFAA2E;AAE3E,kEAAkE;AAClE,SAAgB,qBAAqB,CAAC,IAA+B;IACnE,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,MAAM,EAAE,GAAG,uBAAuB,CAAA;IAClC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,IAAI,CAAyB,CAAA;IAC7B,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACpC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QACf,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YACZ,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACd,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,gDAAgD;AAChD,SAAgB,qBAAqB,CACnC,SAAgC,EAChC,QAA+B,EAC/B,UAA0B;IAE1B,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC9B,IAAI,UAAU;QAAE,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IACpC,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;QAC3B,IAAI,CAAC,EAAE,IAAI,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CAAC,CAAA;IACX,CAAC;AACH,CAAC","sourcesContent":["/*\n * Mentioning someone tells them (ADR-0071 decision 1, as amended by ADR-0073).\n *\n * The machinery existed in the board product only: `@name` in a board chat added a participant and\n * sent them an invite, and the same `@name` in a twin deliberation added nobody. The person typing\n * it had every reason to believe they had called a colleague in.\n *\n * ── What a mention is now ─────────────────────────────────────────────────────\n * A conversation in the domain is open: anyone may walk in, with nothing to approve and nobody to\n * ask (ADR-0073 decision 2). So a mention grants nothing — it points. It seats the named person so\n * the conversation reaches their list, and it tells them their name came up. Somebody who was never\n * mentioned can read the same room by opening it.\n *\n * Two rules survive the amendment:\n * ① only a door that stores **a person's turn** mentions — never the model, a tool, or the\n * assistant's own answer. What the assistant writes must not seat people.\n * ② whoever is named joins as a member and is told.\n *\n * What went: the inviter's own role (there is nothing to hand out), the refusal verdicts, and the\n * notice shown before sending. A private conversation is the one place a mention cannot seat\n * someone — there the named person is told and stays outside until an owner opens it.\n *\n * ── A group (2026-10-24, ADR-0073 decision 3) ──────────────────────────────────\n * In a group the seat is the key, so who seats is asked again: the owner's mention seats, a member's\n * tells (`maySeat`). The invite door (`inviteToAISession`) seats through the same `seatParticipants`\n * under the same rule - two ways in, one seat.\n */\nimport { isOpenRoom, maySeat } from '../chat-session/session-visibility.js'\n\n/** 본문에서 `@user{userId:UUID}` 마커의 userId 를 뽑는다 — 첫 등장 순, 중복 제거. */\nexport function extractMentionUserIds(text: string | null | undefined): string[] {\n if (!text) return []\n const re = /\\{userId:([^}\\s]+)\\}/g\n const seen = new Set<string>()\n const out: string[] = []\n let m: RegExpExecArray | null\n while ((m = re.exec(text)) !== null) {\n const id = m[1]\n if (!seen.has(id)) {\n seen.add(id)\n out.push(id)\n }\n }\n return out\n}\n\n/** 멘션된 사람 중 **아직 참여자가 아니고 자기 자신도 아닌** 새 사람만. */\nexport function newParticipantUserIds(\n mentioned: ReadonlyArray<string>,\n existing: ReadonlyArray<string>,\n selfUserId?: string | null\n): string[] {\n const have = new Set(existing)\n if (selfUserId) have.add(selfUserId)\n const out: string[] = []\n const seen = new Set<string>()\n for (const id of mentioned) {\n if (!id || have.has(id) || seen.has(id)) continue\n seen.add(id)\n out.push(id)\n }\n return out\n}\n\nexport interface MentionInviteResult {\n /** 이번에 새로 앉은 사람들. 알림은 이들에게 간다. */\n invited: string[]\n /** 앉힐 수 없는 방이거나 부른 사람에게 그 자리가 없어 앉히지 못한 사람들 — 이름은 불렸고 방에는 못 들어온다. */\n notSeated?: string[]\n}\n\nexport interface MentionInviteInput {\n /** 저장된 **사람의 말**. 어시스턴트의 답이나 도구 결과를 여기에 넘기지 않는다(조건 ①). */\n content: string\n sessionId: string\n domainId: string\n inviter: { id?: string } | undefined | null\n /** 참여자 저장소 — 시험이 가짜를 넣는다. */\n participants: any\n /** 이 대화의 공개 범위(ADR-0073). 그룹은 owner 의 멘션만, 비공개는 아무의 멘션도 앉히지 않는다. */\n visibility?: string | null\n}\n\n/** 멘션된 사람을 참여자로 앉힌다 — 앉힐 수 있는 방이고 부른 사람에게 그 자리가 있을 때만(`maySeat`). */\nexport async function inviteMentionedUsers(input: MentionInviteInput): Promise<MentionInviteResult> {\n const mentioned = extractMentionUserIds(input.content)\n if (mentioned.length === 0) return { invited: [] }\n return seatParticipants({ ...input, userIds: mentioned })\n}\n\nexport interface SeatInput {\n sessionId: string\n domainId: string\n inviter: { id?: string } | undefined | null\n /** 앉힐 사람들. 이미 앉은 사람과 부른 사람 자신은 빠진다. */\n userIds: ReadonlyArray<string>\n participants: any\n visibility?: string | null\n}\n\n/**\n * 사람을 앉힌다 — 멘션과 초대 단추가 함께 쓰는 한 곳.\n *\n * 규칙은 `maySeat` 한 줄이다: 공개 방은 누구나, 그룹은 owner 만, 비공개는 아무도. 앉히지 못하면\n * 아무것도 쓰지 않고 그 사람들을 `notSeated` 로 돌려준다 — 화면이 그대로 말한다.\n * 나갔던 사람(soft delete)은 되살린다 — 다시 부른 것이지 새 사람이 아니다.\n */\nexport async function seatParticipants(input: SeatInput): Promise<MentionInviteResult> {\n const repo = input.participants\n const existing = await repo.find({\n where: { session: { id: input.sessionId } as any, domain: { id: input.domainId } as any },\n withDeleted: true\n })\n\n /* A hide-only `viewer` row is not a seat - the person is brought in over it, as a member. */\n const seated = existing.filter((row: any) => !row.deletedAt && row.role !== 'viewer')\n const activeIds = seated.map((row: any) => row.userId).filter(Boolean)\n const fresh = newParticipantUserIds(input.userIds, activeIds, input.inviter?.id)\n if (fresh.length === 0) return { invited: [] }\n\n /*\n * 공개 방에서 앉히는 일은 아무것도 주지 않지만(누구나 들어온다), 그룹과 비공개에서는 그것이 곧 접근을\n * 주는 일이다. 그룹에서는 owner 가 주고, 비공개에서는 아무도 주지 않는다 — 이름이 불렸다는 것만 남는다.\n */\n const inviterRole = seated.find((row: any) => row.userId === input.inviter?.id)?.role\n if (!maySeat(input.visibility, inviterRole)) return { invited: [], notSeated: fresh }\n\n for (const userId of fresh) await writeMemberSeat(repo, existing, input, userId)\n\n return { invited: fresh }\n}\n\n/**\n * The seats a person's turn gives - what every door that stores a person's words calls.\n *\n * The writer first: in an open room anyone may walk in and speak, and until 2026-10-24 speaking seated nobody. A\n * conversation four people wrote in showed two in its roster - the one who started it and the one who was\n * mentioned - and the other two had no presence, no unread badge and no activity notice. In a group or private\n * room the writer is seated already (the write gate let them in by their seat). Then the people mentioned.\n */\nexport async function seatTurn(input: MentionInviteInput): Promise<MentionInviteResult> {\n await seatWriter(input)\n return inviteMentionedUsers(input)\n}\n\n/** Seat the person who spoke, in an open room only - there the seat grants nothing, it records who took part. */\nexport async function seatWriter(input: Omit<SeatInput, 'userIds'>): Promise<boolean> {\n const writerId = input.inviter?.id\n if (!writerId || !isOpenRoom(input.visibility)) return false\n const repo = input.participants\n const existing = await repo.find({\n where: { session: { id: input.sessionId } as any, domain: { id: input.domainId } as any },\n withDeleted: true\n })\n if (existing.some((row: any) => row.userId === writerId && !row.deletedAt && row.role !== 'viewer')) return false\n await writeMemberSeat(repo, existing, input, writerId)\n return true\n}\n\n/** One member seat: someone who left (soft delete) or only hid it (`viewer`) is brought back on that row, never a second one. */\nasync function writeMemberSeat(repo: any, existing: any[], input: { sessionId: string; domainId: string; inviter: { id?: string } | undefined | null }, userId: string) {\n const prior = existing.find((row: any) => row.userId === userId && (row.deletedAt || row.role === 'viewer'))\n if (prior) {\n await repo.update(prior.id, { deletedAt: null, role: 'member', updater: input.inviter } as any)\n } else {\n await repo.save({\n domain: { id: input.domainId } as any,\n session: { id: input.sessionId } as any,\n user: { id: userId } as any,\n role: 'member',\n creator: input.inviter,\n updater: input.inviter\n } as any)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mention-invite.js","sourceRoot":"","sources":["../../../server/service/chat-session-participant/mention-invite.ts"],"names":[],"mappings":";;AA8BA,8CAEC;AAGD,sDAcC;AAGD,sDAeC;AAsBD,oDAIC;AAmBD,4CAuBC;AAUD,4BAGC;AAGD,gCAWC;AAlKD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,iFAA2E;AAE3E,4HAA4H;AAC5H,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAA;AAChD,CAAC;AAED,kEAAkE;AAClE,SAAgB,qBAAqB,CAAC,IAA+B;IACnE,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,MAAM,EAAE,GAAG,uBAAuB,CAAA;IAClC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,IAAI,CAAyB,CAAA;IAC7B,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACpC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QACf,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAClB,IAAI,C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AAK,EAAE,CAAC;QACV,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAS,CAAC,CAAA;IACjG,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,QAAQ,EAAS;YACrC,OAAO,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,SAAS,EAAS;YACvC,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAS;YAC3B,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,OAAO,EAAE,KAAK,CAAC,OAAO;SAChB,CAAC,CAAA;IACX,CAAC;AACH,CAAC","sourcesContent":["/*\n * Mentioning someone tells them (ADR-0071 decision 1, as amended by ADR-0073).\n *\n * The machinery existed in the board product only: `@name` in a board chat added a participant and\n * sent them an invite, and the same `@name` in a twin deliberation added nobody. The person typing\n * it had every reason to believe they had called a colleague in.\n *\n * ── What a mention is now ─────────────────────────────────────────────────────\n * A conversation in the domain is open: anyone may walk in, with nothing to approve and nobody to\n * ask (ADR-0073 decision 2). So a mention grants nothing — it points. It seats the named person so\n * the conversation reaches their list, and it tells them their name came up. Somebody who was never\n * mentioned can read the same room by opening it.\n *\n * Two rules survive the amendment:\n * ① only a door that stores **a person's turn** mentions — never the model, a tool, or the\n * assistant's own answer. What the assistant writes must not seat people.\n * ② whoever is named joins as a member and is told.\n *\n * What went: the inviter's own role (there is nothing to hand out), the refusal verdicts, and the\n * notice shown before sending. A private conversation is the one place a mention cannot seat\n * someone — there the named person is told and stays outside until an owner opens it.\n *\n * ── A group (2026-10-24, ADR-0073 decision 3) ──────────────────────────────────\n * In a group the seat is the key, so who seats is asked again: the owner's mention seats, a member's\n * tells (`maySeat`). The invite door (`inviteToAISession`) seats through the same `seatParticipants`\n * under the same rule - two ways in, one seat.\n */\nimport { isOpenRoom, maySeat } from '../chat-session/session-visibility.js'\n\n/** The text as a person reads it - `@Admin{userId:UUID}` is `@Admin`. Kept where a turn's words are stored as an answer. */\nexport function withoutMentionIds(text: string): string {\n return text.replace(/\\{userId:[^}\\s]+\\}/g, '')\n}\n\n/** 본문에서 `@user{userId:UUID}` 마커의 userId 를 뽑는다 — 첫 등장 순, 중복 제거. */\nexport function extractMentionUserIds(text: string | null | undefined): string[] {\n if (!text) return []\n const re = /\\{userId:([^}\\s]+)\\}/g\n const seen = new Set<string>()\n const out: string[] = []\n let m: RegExpExecArray | null\n while ((m = re.exec(text)) !== null) {\n const id = m[1]\n if (!seen.has(id)) {\n seen.add(id)\n out.push(id)\n }\n }\n return out\n}\n\n/** 멘션된 사람 중 **아직 참여자가 아니고 자기 자신도 아닌** 새 사람만. */\nexport function newParticipantUserIds(\n mentioned: ReadonlyArray<string>,\n existing: ReadonlyArray<string>,\n selfUserId?: string | null\n): string[] {\n const have = new Set(existing)\n if (selfUserId) have.add(selfUserId)\n const out: string[] = []\n const seen = new Set<string>()\n for (const id of mentioned) {\n if (!id || have.has(id) || seen.has(id)) continue\n seen.add(id)\n out.push(id)\n }\n return out\n}\n\nexport interface MentionInviteResult {\n /** 이번에 새로 앉은 사람들. 알림은 이들에게 간다. */\n invited: string[]\n /** 앉힐 수 없는 방이거나 부른 사람에게 그 자리가 없어 앉히지 못한 사람들 — 이름은 불렸고 방에는 못 들어온다. */\n notSeated?: string[]\n}\n\nexport interface MentionInviteInput {\n /** 저장된 **사람의 말**. 어시스턴트의 답이나 도구 결과를 여기에 넘기지 않는다(조건 ①). */\n content: string\n sessionId: string\n domainId: string\n inviter: { id?: string } | undefined | null\n /** 참여자 저장소 — 시험이 가짜를 넣는다. */\n participants: any\n /** 이 대화의 공개 범위(ADR-0073). 그룹은 owner 의 멘션만, 비공개는 아무의 멘션도 앉히지 않는다. */\n visibility?: string | null\n}\n\n/** 멘션된 사람을 참여자로 앉힌다 — 앉힐 수 있는 방이고 부른 사람에게 그 자리가 있을 때만(`maySeat`). */\nexport async function inviteMentionedUsers(input: MentionInviteInput): Promise<MentionInviteResult> {\n const mentioned = extractMentionUserIds(input.content)\n if (mentioned.length === 0) return { invited: [] }\n return seatParticipants({ ...input, userIds: mentioned })\n}\n\nexport interface SeatInput {\n sessionId: string\n domainId: string\n inviter: { id?: string } | undefined | null\n /** 앉힐 사람들. 이미 앉은 사람과 부른 사람 자신은 빠진다. */\n userIds: ReadonlyArray<string>\n participants: any\n visibility?: string | null\n}\n\n/**\n * 사람을 앉힌다 — 멘션과 초대 단추가 함께 쓰는 한 곳.\n *\n * 규칙은 `maySeat` 한 줄이다: 공개 방은 누구나, 그룹은 owner 만, 비공개는 아무도. 앉히지 못하면\n * 아무것도 쓰지 않고 그 사람들을 `notSeated` 로 돌려준다 — 화면이 그대로 말한다.\n * 나갔던 사람(soft delete)은 되살린다 — 다시 부른 것이지 새 사람이 아니다.\n */\nexport async function seatParticipants(input: SeatInput): Promise<MentionInviteResult> {\n const repo = input.participants\n const existing = await repo.find({\n where: { session: { id: input.sessionId } as any, domain: { id: input.domainId } as any },\n withDeleted: true\n })\n\n /* A hide-only `viewer` row is not a seat - the person is brought in over it, as a member. */\n const seated = existing.filter((row: any) => !row.deletedAt && row.role !== 'viewer')\n const activeIds = seated.map((row: any) => row.userId).filter(Boolean)\n const fresh = newParticipantUserIds(input.userIds, activeIds, input.inviter?.id)\n if (fresh.length === 0) return { invited: [] }\n\n /*\n * 공개 방에서 앉히는 일은 아무것도 주지 않지만(누구나 들어온다), 그룹과 비공개에서는 그것이 곧 접근을\n * 주는 일이다. 그룹에서는 owner 가 주고, 비공개에서는 아무도 주지 않는다 — 이름이 불렸다는 것만 남는다.\n */\n const inviterRole = seated.find((row: any) => row.userId === input.inviter?.id)?.role\n if (!maySeat(input.visibility, inviterRole)) return { invited: [], notSeated: fresh }\n\n for (const userId of fresh) await writeMemberSeat(repo, existing, input, userId)\n\n return { invited: fresh }\n}\n\n/**\n * The seats a person's turn gives - what every door that stores a person's words calls.\n *\n * The writer first: in an open room anyone may walk in and speak, and until 2026-10-24 speaking seated nobody. A\n * conversation four people wrote in showed two in its roster - the one who started it and the one who was\n * mentioned - and the other two had no presence, no unread badge and no activity notice. In a group or private\n * room the writer is seated already (the write gate let them in by their seat). Then the people mentioned.\n */\nexport async function seatTurn(input: MentionInviteInput): Promise<MentionInviteResult> {\n await seatWriter(input)\n return inviteMentionedUsers(input)\n}\n\n/** Seat the person who spoke, in an open room only - there the seat grants nothing, it records who took part. */\nexport async function seatWriter(input: Omit<SeatInput, 'userIds'>): Promise<boolean> {\n const writerId = input.inviter?.id\n if (!writerId || !isOpenRoom(input.visibility)) return false\n const repo = input.participants\n const existing = await repo.find({\n where: { session: { id: input.sessionId } as any, domain: { id: input.domainId } as any },\n withDeleted: true\n })\n if (existing.some((row: any) => row.userId === writerId && !row.deletedAt && row.role !== 'viewer')) return false\n await writeMemberSeat(repo, existing, input, writerId)\n return true\n}\n\n/** One member seat: someone who left (soft delete) or only hid it (`viewer`) is brought back on that row, never a second one. */\nasync function writeMemberSeat(repo: any, existing: any[], input: { sessionId: string; domainId: string; inviter: { id?: string } | undefined | null }, userId: string) {\n const prior = existing.find((row: any) => row.userId === userId && (row.deletedAt || row.role === 'viewer'))\n if (prior) {\n await repo.update(prior.id, { deletedAt: null, role: 'member', updater: input.inviter } as any)\n } else {\n await repo.save({\n domain: { id: input.domainId } as any,\n session: { id: input.sessionId } as any,\n user: { id: userId } as any,\n role: 'member',\n creator: input.inviter,\n updater: input.inviter\n } as any)\n }\n}\n"]}
|
|
@@ -152,6 +152,11 @@ export declare class ChatSessionResolver {
|
|
|
152
152
|
* rule (`maySeat`). The invite button and the line under a mention read it; the doors decide again.
|
|
153
153
|
*/
|
|
154
154
|
mayInviteToAISession(sessionId: string, context: ResolverContext): Promise<boolean>;
|
|
155
|
+
/**
|
|
156
|
+
* The person this conversation is about, who always reads it (ADR-0200) - the screen offers no way to send them out,
|
|
157
|
+
* and keeps no copy of the rule. The doors refuse again.
|
|
158
|
+
*/
|
|
159
|
+
keptInAISession(sessionId: string, context: ResolverContext): Promise<string | null>;
|
|
155
160
|
touchPresence(sessionId: string, context: ResolverContext): Promise<boolean>;
|
|
156
161
|
chatMessages(sessionId: string, limit: number, offset: number, context: ResolverContext): Promise<ChatMessage[]>;
|
|
157
162
|
startAISession(anchorType: string, anchorId: string, context: ResolverContext): Promise<ChatSession>;
|
|
@@ -23,6 +23,8 @@ const room_message_js_1 = require("./chat-message/room-message.js");
|
|
|
23
23
|
const reader_gate_js_1 = require("./chat-message/reader-gate.js");
|
|
24
24
|
const request_translator_js_1 = require("./request-translator.js");
|
|
25
25
|
const session_visibility_js_1 = require("./chat-session/session-visibility.js");
|
|
26
|
+
const person_subject_js_1 = require("./people/person-subject.js");
|
|
27
|
+
const room_turn_js_1 = require("./chat-message/room-turn.js");
|
|
26
28
|
const mention_invite_js_1 = require("./chat-session-participant/mention-invite.js");
|
|
27
29
|
const chat_typing_js_1 = require("./chat-message/chat-typing.js");
|
|
28
30
|
const invite_notification_js_1 = require("./chat-session-participant/invite-notification.js");
|
|
@@ -241,6 +243,29 @@ function attachmentRefusalMessage(refusal, context) {
|
|
|
241
243
|
return t('ai-assistant.text.too-many-attachments', { max: refusal.maxFiles, defaultValue: 'at most {max} files can be sent at once.' });
|
|
242
244
|
}
|
|
243
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* A conversation about someone seats them as it is made - they read whatever is asked of their records (ADR-0200).
|
|
248
|
+
* Their seat is a member's, given by the one who started it, as an invite gives it.
|
|
249
|
+
*/
|
|
250
|
+
async function seatPersonOf(session, starter, tx) {
|
|
251
|
+
const seat = (0, person_subject_js_1.personSeatOf)(session.anchorType, session.anchorId, starter);
|
|
252
|
+
if (!seat)
|
|
253
|
+
return;
|
|
254
|
+
await (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant, tx).save({
|
|
255
|
+
domain: session.domain,
|
|
256
|
+
session: { id: session.id },
|
|
257
|
+
user: { id: seat.userId },
|
|
258
|
+
role: 'member',
|
|
259
|
+
creator: starter,
|
|
260
|
+
updater: starter
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/** A conversation about someone stays a group they sit in - said in the asker's words when a change would undo that. */
|
|
264
|
+
function refusePersonRoom(session, change, context) {
|
|
265
|
+
const refusal = session && (0, person_subject_js_1.personRoomRefusal)({ ...session, creatorId: session.creatorId }, change);
|
|
266
|
+
if (refusal)
|
|
267
|
+
throw new Error((0, request_translator_js_1.requestTranslator)(context)(`ai-assistant.text.${refusal}`, { defaultValue: person_subject_js_1.PERSON_ROOM_REFUSALS[refusal] }));
|
|
268
|
+
}
|
|
244
269
|
let ChatSessionResolver = class ChatSessionResolver {
|
|
245
270
|
async chatSession(id, context) {
|
|
246
271
|
const { domain, user } = context.state;
|
|
@@ -529,6 +554,7 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
529
554
|
return false;
|
|
530
555
|
if (session.visibility === visibility)
|
|
531
556
|
return true;
|
|
557
|
+
refusePersonRoom(session, { visibility }, context);
|
|
532
558
|
/*
|
|
533
559
|
* Private is the owner's alone (ADR-0073 decision 3). The members leave with the change - a private room
|
|
534
560
|
* with people still seated in it would be a group under another name. Bringing them back is inviting
|
|
@@ -602,6 +628,7 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
602
628
|
const theirs = seats.find(seat => seat.userId === userId && seat.role === 'member');
|
|
603
629
|
if (!theirs)
|
|
604
630
|
return false;
|
|
631
|
+
refusePersonRoom(await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({ id: sessionId, domain: { id: domain.id } }), { removing: userId }, context);
|
|
605
632
|
return await this._leave(sessionId, theirs, context);
|
|
606
633
|
}
|
|
607
634
|
/**
|
|
@@ -620,6 +647,7 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
620
647
|
}
|
|
621
648
|
if (mine?.role !== 'member')
|
|
622
649
|
return false;
|
|
650
|
+
refusePersonRoom(await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({ id: sessionId, domain: { id: domain.id } }), { removing: user.id }, context);
|
|
623
651
|
return await this._leave(sessionId, mine, context);
|
|
624
652
|
}
|
|
625
653
|
async _leave(sessionId, seat, context) {
|
|
@@ -734,6 +762,16 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
734
762
|
});
|
|
735
763
|
return (0, session_visibility_js_1.maySeat)(session.visibility, seat?.role);
|
|
736
764
|
}
|
|
765
|
+
/**
|
|
766
|
+
* The person this conversation is about, who always reads it (ADR-0200) - the screen offers no way to send them out,
|
|
767
|
+
* and keeps no copy of the rule. The doors refuse again.
|
|
768
|
+
*/
|
|
769
|
+
async keptInAISession(sessionId, context) {
|
|
770
|
+
const { domain } = context.state;
|
|
771
|
+
const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({ id: sessionId, domain: { id: domain.id } });
|
|
772
|
+
const personId = session && (0, person_subject_js_1.personOfAnchor)(session.anchorType, session.anchorId);
|
|
773
|
+
return personId && (0, person_subject_js_1.personRoomRefusal)(session, { removing: personId }) ? personId : null;
|
|
774
|
+
}
|
|
737
775
|
async touchPresence(sessionId, context) {
|
|
738
776
|
const { domain, user } = context.state;
|
|
739
777
|
const repo = (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant);
|
|
@@ -787,7 +825,7 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
787
825
|
domain,
|
|
788
826
|
...(0, session_anchor_js_1.anchorColumns)(anchorType, anchorId),
|
|
789
827
|
/* 새 대화는 비공개로 태어난다 — 공개는 owner 가 고른다(ADR-0073 결정 2, 2026-09-30 고침). */
|
|
790
|
-
visibility: (0, session_visibility_js_1.initialVisibility)({ anchorType }),
|
|
828
|
+
visibility: (0, person_subject_js_1.personSeatOf)(anchorType, anchorId, user)?.visibility ?? (0, session_visibility_js_1.initialVisibility)({ anchorType }),
|
|
791
829
|
creator: user,
|
|
792
830
|
updater: user
|
|
793
831
|
});
|
|
@@ -800,6 +838,7 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
800
838
|
creator: user,
|
|
801
839
|
updater: user
|
|
802
840
|
});
|
|
841
|
+
await seatPersonOf(session, user, tx);
|
|
803
842
|
return session;
|
|
804
843
|
}
|
|
805
844
|
async createAISession(anchorType, anchorId, name, context) {
|
|
@@ -810,7 +849,7 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
810
849
|
const session = await repo.save({
|
|
811
850
|
domain,
|
|
812
851
|
...(0, session_anchor_js_1.anchorColumns)(anchorType, anchorId),
|
|
813
|
-
visibility: (0, session_visibility_js_1.initialVisibility)({ anchorType }),
|
|
852
|
+
visibility: (0, person_subject_js_1.personSeatOf)(anchorType, anchorId, user)?.visibility ?? (0, session_visibility_js_1.initialVisibility)({ anchorType }),
|
|
814
853
|
creator: user,
|
|
815
854
|
updater: user,
|
|
816
855
|
name: finalName
|
|
@@ -824,6 +863,7 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
824
863
|
creator: user,
|
|
825
864
|
updater: user
|
|
826
865
|
});
|
|
866
|
+
await seatPersonOf(session, user, tx);
|
|
827
867
|
return session;
|
|
828
868
|
}
|
|
829
869
|
async renameChatSession(sessionId, name, context) {
|
|
@@ -965,6 +1005,7 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
965
1005
|
visibility: session.visibility
|
|
966
1006
|
});
|
|
967
1007
|
await notifyInvited(context, invite.invited, user, session.name);
|
|
1008
|
+
await (0, room_turn_js_1.tellRoomTurn)({ domain, user, session: session, message: saved, tx, t: (0, request_translator_js_1.requestTranslator)(context) });
|
|
968
1009
|
/* 사람의 말이다 — 목록의 최근 활동과 다른 참여자의 안 읽음이 이것으로 움직인다. */
|
|
969
1010
|
try {
|
|
970
1011
|
await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).update(session.id, (0, session_inbox_js_1.activityPatch)(body));
|
|
@@ -1377,6 +1418,18 @@ tslib_1.__decorate([
|
|
|
1377
1418
|
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
1378
1419
|
tslib_1.__metadata("design:returntype", Promise)
|
|
1379
1420
|
], ChatSessionResolver.prototype, "mayInviteToAISession", null);
|
|
1421
|
+
tslib_1.__decorate([
|
|
1422
|
+
(0, type_graphql_1.Query)(() => String, {
|
|
1423
|
+
nullable: true,
|
|
1424
|
+
description: 'The user this conversation is about, who cannot be sent out of it - none for any other conversation. A hint for the screen; the doors decide again.'
|
|
1425
|
+
}),
|
|
1426
|
+
(0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query", domainOwnerGranted: true)'),
|
|
1427
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
|
|
1428
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
1429
|
+
tslib_1.__metadata("design:type", Function),
|
|
1430
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
1431
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
1432
|
+
], ChatSessionResolver.prototype, "keptInAISession", null);
|
|
1380
1433
|
tslib_1.__decorate([
|
|
1381
1434
|
(0, type_graphql_1.Mutation)(() => Boolean, {
|
|
1382
1435
|
description: 'Presence heartbeat — bump current user\'s lastSeenAt in the session (online indicator).'
|