@things-factory/ai-assistant 10.1.26 → 10.1.28
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 +653 -59
- package/client/components/assistant-mode.test.ts +86 -55
- package/client/components/assistant-mode.ts +124 -82
- package/client/components/chat-echo-dedup.test.ts +23 -0
- package/client/components/chat-echo-dedup.ts +29 -3
- package/client/components/chat-input-builder.test.ts +20 -20
- package/client/components/chat-input-builder.ts +16 -14
- package/client/components/chat-proposal-survival.test.ts +73 -0
- package/client/components/mention-popup.ts +31 -8
- package/client/components/panel-aria.test.ts +34 -0
- package/client/components/proposal-outcome-line.ts +33 -0
- package/client/utils/assistant-session-controller.test.ts +75 -0
- package/client/utils/assistant-session-controller.ts +23 -0
- package/client/utils/assistant-session-transport.ts +11 -3
- package/dist-client/components/assistant-chat.d.ts +128 -13
- package/dist-client/components/assistant-chat.js +613 -67
- package/dist-client/components/assistant-chat.js.map +1 -1
- package/dist-client/components/assistant-mode.d.ts +80 -68
- package/dist-client/components/assistant-mode.js +63 -19
- package/dist-client/components/assistant-mode.js.map +1 -1
- package/dist-client/components/assistant-mode.test.js +74 -53
- package/dist-client/components/assistant-mode.test.js.map +1 -1
- package/dist-client/components/chat-echo-dedup.d.ts +2 -0
- package/dist-client/components/chat-echo-dedup.js +27 -4
- package/dist-client/components/chat-echo-dedup.js.map +1 -1
- package/dist-client/components/chat-echo-dedup.test.js +20 -0
- package/dist-client/components/chat-echo-dedup.test.js.map +1 -1
- package/dist-client/components/chat-input-builder.d.ts +12 -7
- package/dist-client/components/chat-input-builder.js +8 -10
- package/dist-client/components/chat-input-builder.js.map +1 -1
- package/dist-client/components/chat-input-builder.test.js +17 -18
- package/dist-client/components/chat-input-builder.test.js.map +1 -1
- package/dist-client/components/chat-proposal-survival.test.d.ts +1 -0
- package/dist-client/components/chat-proposal-survival.test.js +61 -0
- package/dist-client/components/chat-proposal-survival.test.js.map +1 -0
- package/dist-client/components/mention-popup.js +28 -8
- package/dist-client/components/mention-popup.js.map +1 -1
- package/dist-client/components/panel-aria.test.d.ts +1 -0
- package/dist-client/components/panel-aria.test.js +31 -0
- package/dist-client/components/panel-aria.test.js.map +1 -0
- package/dist-client/components/proposal-outcome-line.d.ts +9 -0
- package/dist-client/components/proposal-outcome-line.js +15 -0
- package/dist-client/components/proposal-outcome-line.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/utils/assistant-session-controller.d.ts +10 -0
- package/dist-client/utils/assistant-session-controller.js +16 -0
- package/dist-client/utils/assistant-session-controller.js.map +1 -1
- package/dist-client/utils/assistant-session-controller.test.d.ts +1 -0
- package/dist-client/utils/assistant-session-controller.test.js +56 -0
- package/dist-client/utils/assistant-session-controller.test.js.map +1 -0
- package/dist-client/utils/assistant-session-transport.js +11 -3
- package/dist-client/utils/assistant-session-transport.js.map +1 -1
- package/dist-server/service/assistant-capability-resolver.d.ts +17 -0
- package/dist-server/service/assistant-capability-resolver.js +88 -0
- package/dist-server/service/assistant-capability-resolver.js.map +1 -0
- package/dist-server/service/assistant-chat-resolver.d.ts +6 -6
- package/dist-server/service/assistant-chat-resolver.js +166 -44
- package/dist-server/service/assistant-chat-resolver.js.map +1 -1
- package/dist-server/service/assistant-mode/assistant-mode-resolver.d.ts +25 -0
- package/dist-server/service/assistant-mode/assistant-mode-resolver.js +140 -0
- package/dist-server/service/assistant-mode/assistant-mode-resolver.js.map +1 -0
- package/dist-server/service/assistant-mode/index.d.ts +9 -0
- package/dist-server/service/assistant-mode/index.js +19 -0
- package/dist-server/service/assistant-mode/index.js.map +1 -0
- package/dist-server/service/assistant-mode/registry.d.ts +18 -0
- package/dist-server/service/assistant-mode/registry.js +136 -0
- package/dist-server/service/assistant-mode/registry.js.map +1 -0
- package/dist-server/service/assistant-mode/resolve.d.ts +33 -0
- package/dist-server/service/assistant-mode/resolve.js +60 -0
- package/dist-server/service/assistant-mode/resolve.js.map +1 -0
- package/dist-server/service/assistant-mode/types.d.ts +99 -0
- package/dist-server/service/assistant-mode/types.js +12 -0
- package/dist-server/service/assistant-mode/types.js.map +1 -0
- package/dist-server/service/chat-message/carried-turns.d.ts +48 -0
- package/dist-server/service/chat-message/carried-turns.js +80 -0
- package/dist-server/service/chat-message/carried-turns.js.map +1 -0
- package/dist-server/service/chat-message/chat-message-subscription.d.ts +1 -1
- package/dist-server/service/chat-message/chat-message-subscription.js +24 -6
- package/dist-server/service/chat-message/chat-message-subscription.js.map +1 -1
- package/dist-server/service/chat-message/chat-message.d.ts +32 -0
- package/dist-server/service/chat-message/chat-message.js +17 -0
- package/dist-server/service/chat-message/chat-message.js.map +1 -1
- package/dist-server/service/chat-message/door-access.d.ts +15 -0
- package/dist-server/service/chat-message/door-access.js +26 -0
- package/dist-server/service/chat-message/door-access.js.map +1 -0
- package/dist-server/service/chat-message/fold-session-history.d.ts +30 -0
- package/dist-server/service/chat-message/fold-session-history.js +133 -0
- package/dist-server/service/chat-message/fold-session-history.js.map +1 -0
- package/dist-server/service/chat-message/llm-history.d.ts +7 -0
- package/dist-server/service/chat-message/llm-history.js +23 -11
- package/dist-server/service/chat-message/llm-history.js.map +1 -1
- package/dist-server/service/chat-message/message-doors.d.ts +29 -0
- package/dist-server/service/chat-message/message-doors.js +107 -0
- package/dist-server/service/chat-message/message-doors.js.map +1 -0
- package/dist-server/service/chat-message/proposal-outcome.d.ts +18 -0
- package/dist-server/service/chat-message/proposal-outcome.js +31 -0
- package/dist-server/service/chat-message/proposal-outcome.js.map +1 -0
- package/dist-server/service/chat-message/reader-gate.d.ts +3 -0
- package/dist-server/service/chat-message/reader-gate.js +37 -0
- package/dist-server/service/chat-message/reader-gate.js.map +1 -0
- package/dist-server/service/chat-message/room-message.d.ts +4 -0
- package/dist-server/service/chat-message/room-message.js +25 -0
- package/dist-server/service/chat-message/room-message.js.map +1 -0
- package/dist-server/service/chat-session/chat-session.d.ts +24 -0
- package/dist-server/service/chat-session/chat-session.js +26 -2
- package/dist-server/service/chat-session/chat-session.js.map +1 -1
- package/dist-server/service/chat-session/session-inbox.d.ts +4 -1
- package/dist-server/service/chat-session/session-inbox.js +3 -2
- package/dist-server/service/chat-session/session-inbox.js.map +1 -1
- package/dist-server/service/chat-session/session-visibility.d.ts +15 -0
- package/dist-server/service/chat-session/session-visibility.js +28 -0
- package/dist-server/service/chat-session/session-visibility.js.map +1 -0
- package/dist-server/service/chat-session/station-session-guard.d.ts +1 -5
- package/dist-server/service/chat-session/station-session-guard.js +7 -2
- package/dist-server/service/chat-session/station-session-guard.js.map +1 -1
- package/dist-server/service/chat-session-participant/mention-invite.d.ts +29 -0
- package/dist-server/service/chat-session-participant/mention-invite.js +103 -0
- package/dist-server/service/chat-session-participant/mention-invite.js.map +1 -0
- package/dist-server/service/chat-session-resolver.d.ts +15 -0
- package/dist-server/service/chat-session-resolver.js +267 -15
- package/dist-server/service/chat-session-resolver.js.map +1 -1
- package/dist-server/service/grounding-sources.d.ts +14 -0
- package/dist-server/service/grounding-sources.js +26 -0
- package/dist-server/service/grounding-sources.js.map +1 -0
- package/dist-server/service/index.d.ts +8 -1
- package/dist-server/service/index.js +19 -0
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/request-translator.d.ts +2 -0
- package/dist-server/service/request-translator.js +20 -0
- package/dist-server/service/request-translator.js.map +1 -0
- package/dist-server/service/testing/conversation-script.d.ts +123 -0
- package/dist-server/service/testing/conversation-script.js +202 -0
- package/dist-server/service/testing/conversation-script.js.map +1 -0
- package/dist-server/service/testing/mode-conformance.d.ts +40 -0
- package/dist-server/service/testing/mode-conformance.js +90 -0
- package/dist-server/service/testing/mode-conformance.js.map +1 -0
- package/dist-server/tool-registry-boot-report.d.ts +3 -0
- package/dist-server/tool-registry-boot-report.js +25 -2
- package/dist-server/tool-registry-boot-report.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/server/explicit-graphql-types.test.ts +56 -0
- package/server/service/assistant-capability-resolver.ts +66 -0
- package/server/service/assistant-chat-resolver.ts +184 -42
- package/server/service/assistant-mode/assistant-mode-resolver.ts +102 -0
- package/server/service/assistant-mode/index.ts +16 -0
- package/server/service/assistant-mode/registry.test.ts +105 -0
- package/server/service/assistant-mode/registry.ts +147 -0
- package/server/service/assistant-mode/resolve.test.ts +78 -0
- package/server/service/assistant-mode/resolve.ts +96 -0
- package/server/service/assistant-mode/subject-defaults.test.ts +86 -0
- package/server/service/assistant-mode/types.ts +103 -0
- package/server/service/chat-message/carried-turns.test.ts +69 -0
- package/server/service/chat-message/carried-turns.ts +99 -0
- package/server/service/chat-message/chat-message-subscription.ts +20 -4
- package/server/service/chat-message/chat-message.ts +44 -0
- package/server/service/chat-message/door-access.ts +45 -0
- package/server/service/chat-message/fold-session-history.test.ts +98 -0
- package/server/service/chat-message/fold-session-history.ts +115 -0
- package/server/service/chat-message/llm-history.test.ts +58 -7
- package/server/service/chat-message/llm-history.ts +30 -11
- package/server/service/chat-message/message-doors.test.ts +87 -0
- package/server/service/chat-message/message-doors.ts +117 -0
- package/server/service/chat-message/proposal-outcome.test.ts +48 -0
- package/server/service/chat-message/proposal-outcome.ts +42 -0
- package/server/service/chat-message/reader-gate.ts +42 -0
- package/server/service/chat-message/room-message.test.ts +21 -0
- package/server/service/chat-message/room-message.ts +22 -0
- package/server/service/chat-session/chat-session.ts +31 -1
- package/server/service/chat-session/session-inbox.test.ts +18 -0
- package/server/service/chat-session/session-inbox.ts +9 -2
- package/server/service/chat-session/session-visibility.test.ts +36 -0
- package/server/service/chat-session/session-visibility.ts +26 -0
- package/server/service/chat-session/station-session-guard.ts +10 -2
- package/server/service/chat-session-participant/mention-invite.test.ts +125 -0
- package/server/service/chat-session-participant/mention-invite.ts +121 -0
- package/server/service/chat-session-resolver.ts +272 -15
- package/server/service/grounding-sources.test.ts +55 -0
- package/server/service/grounding-sources.ts +46 -0
- package/server/service/index.ts +19 -0
- package/server/service/request-translator.test.ts +45 -0
- package/server/service/request-translator.ts +33 -0
- package/server/service/station-session-guard.test.ts +12 -5
- package/server/service/testing/conversation-scenario.test.ts +163 -0
- package/server/service/testing/conversation-script.test.ts +131 -0
- package/server/service/testing/conversation-script.ts +288 -0
- package/server/service/testing/mode-conformance.ts +107 -0
- package/server/tool-registry-boot-report.ts +25 -2
- package/test/assistant-chat-call-sites.test.ts +82 -0
- package/translations/en.json +44 -2
- package/translations/ja.json +44 -2
- package/translations/ko.json +44 -2
- package/translations/ms.json +44 -2
- package/translations/zh.json +44 -2
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* What this guards: `@name` in a conversation brings that person in — and only when the person
|
|
3
|
+
* typing it is in the room themselves (ADR-0071 decision 1).
|
|
4
|
+
*
|
|
5
|
+
* Until this moved out of the board product, `@name` in a twin deliberation added nobody at all,
|
|
6
|
+
* and the person who typed it had every reason to think they had called a colleague in.
|
|
7
|
+
*/
|
|
8
|
+
import { extractMentionUserIds, inviteMentionedUsers, newParticipantUserIds } from './mention-invite'
|
|
9
|
+
|
|
10
|
+
const marker = (id: string) => `@someone{userId:${id}}`
|
|
11
|
+
|
|
12
|
+
function participants(rows: any[]) {
|
|
13
|
+
const saved: any[] = []
|
|
14
|
+
const updated: any[] = []
|
|
15
|
+
return {
|
|
16
|
+
saved,
|
|
17
|
+
updated,
|
|
18
|
+
repo: {
|
|
19
|
+
find: async () => rows,
|
|
20
|
+
save: async (row: any) => saved.push(row),
|
|
21
|
+
update: async (id: string, patch: any) => updated.push({ id, patch })
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const owner = { id: 'p1', userId: 'me', role: 'owner' }
|
|
27
|
+
|
|
28
|
+
it('★ a mentioned colleague joins as a member', async () => {
|
|
29
|
+
const { repo, saved } = participants([owner])
|
|
30
|
+
|
|
31
|
+
const result = await inviteMentionedUsers({
|
|
32
|
+
content: `${marker('u2')} 이것 좀 봐주세요`,
|
|
33
|
+
sessionId: 's1',
|
|
34
|
+
domainId: 'dom-1',
|
|
35
|
+
inviter: { id: 'me' },
|
|
36
|
+
participants: repo
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
expect(result.invited).toEqual(['u2'])
|
|
40
|
+
expect(saved[0]).toMatchObject({ role: 'member', user: { id: 'u2' } })
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('★ 공개 대화에서는 자리에 상관없이 이름을 부를 수 있다 — 줄 것이 없으므로 조건도 없다', async () => {
|
|
44
|
+
/* 보기만 하던 사람도, 아직 앉지 않은 사람도 부른다. ADR-0073 이 자격 검사를 걷어냈다. */
|
|
45
|
+
for (const inviter of [{ id: 'me' }, { id: 'stranger' }]) {
|
|
46
|
+
const { repo, saved } = participants([{ id: 'p9', userId: 'me', role: 'viewer' }])
|
|
47
|
+
|
|
48
|
+
const result = await inviteMentionedUsers({
|
|
49
|
+
content: marker('u2'),
|
|
50
|
+
sessionId: 's1',
|
|
51
|
+
domainId: 'dom-1',
|
|
52
|
+
inviter,
|
|
53
|
+
participants: repo
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
expect(result).toEqual({ invited: ['u2'] })
|
|
57
|
+
expect(saved[0]).toMatchObject({ role: 'member', user: { id: 'u2' } })
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('★ 비공개 대화에서는 이름만 알리고 앉히지 않는다 — 거기서는 앉히는 일이 접근을 주는 일이다', async () => {
|
|
62
|
+
const { repo, saved } = participants([owner])
|
|
63
|
+
|
|
64
|
+
const result = await inviteMentionedUsers({
|
|
65
|
+
content: marker('u2'),
|
|
66
|
+
sessionId: 's1',
|
|
67
|
+
domainId: 'dom-1',
|
|
68
|
+
inviter: { id: 'me' },
|
|
69
|
+
participants: repo,
|
|
70
|
+
visibility: 'private'
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
expect(result).toEqual({ invited: [], notSeated: ['u2'] })
|
|
74
|
+
expect(saved).toEqual([])
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('★ someone who left is brought back, not added twice', async () => {
|
|
78
|
+
const { repo, saved, updated } = participants([owner, { id: 'p2', userId: 'u2', role: 'member', deletedAt: new Date() }])
|
|
79
|
+
|
|
80
|
+
const result = await inviteMentionedUsers({
|
|
81
|
+
content: marker('u2'),
|
|
82
|
+
sessionId: 's1',
|
|
83
|
+
domainId: 'dom-1',
|
|
84
|
+
inviter: { id: 'me' },
|
|
85
|
+
participants: repo
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
expect(result.invited).toEqual(['u2'])
|
|
89
|
+
expect(saved).toEqual([])
|
|
90
|
+
expect(updated[0]).toMatchObject({ id: 'p2', patch: { deletedAt: null, role: 'member' } })
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('mentioning someone already here, or yourself, invites nobody', async () => {
|
|
94
|
+
const { repo, saved } = participants([owner, { id: 'p2', userId: 'u2', role: 'member' }])
|
|
95
|
+
|
|
96
|
+
const result = await inviteMentionedUsers({
|
|
97
|
+
content: `${marker('u2')} ${marker('me')}`,
|
|
98
|
+
sessionId: 's1',
|
|
99
|
+
domainId: 'dom-1',
|
|
100
|
+
inviter: { id: 'me' },
|
|
101
|
+
participants: repo
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
expect(result).toEqual({ invited: [] })
|
|
105
|
+
expect(saved).toEqual([])
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('a turn with no mention reads nothing and touches nothing', async () => {
|
|
109
|
+
const { repo } = participants([owner])
|
|
110
|
+
|
|
111
|
+
expect(await inviteMentionedUsers({ content: '그냥 한 말', sessionId: 's1', domainId: 'dom-1', inviter: { id: 'me' }, participants: repo })).toEqual({
|
|
112
|
+
invited: []
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
describe('the pure parts', () => {
|
|
117
|
+
it('reads each mentioned id once, in the order they appear', () => {
|
|
118
|
+
expect(extractMentionUserIds(`${marker('a')} ${marker('b')} ${marker('a')}`)).toEqual(['a', 'b'])
|
|
119
|
+
expect(extractMentionUserIds(undefined)).toEqual([])
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('leaves out who is already here and who is asking', () => {
|
|
123
|
+
expect(newParticipantUserIds(['a', 'b', 'me'], ['b'], 'me')).toEqual(['a'])
|
|
124
|
+
})
|
|
125
|
+
})
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Mentioning someone tells them (ADR-0071 decision 1, as amended by ADR-0073).
|
|
3
|
+
*
|
|
4
|
+
* The machinery existed in the board product only: `@name` in a board chat added a participant and
|
|
5
|
+
* sent them an invite, and the same `@name` in a twin deliberation added nobody. The person typing
|
|
6
|
+
* it had every reason to believe they had called a colleague in.
|
|
7
|
+
*
|
|
8
|
+
* ── What a mention is now ─────────────────────────────────────────────────────
|
|
9
|
+
* A conversation in the domain is open: anyone may walk in, with nothing to approve and nobody to
|
|
10
|
+
* ask (ADR-0073 decision 2). So a mention grants nothing — it points. It seats the named person so
|
|
11
|
+
* the conversation reaches their list, and it tells them their name came up. Somebody who was never
|
|
12
|
+
* mentioned can read the same room by opening it.
|
|
13
|
+
*
|
|
14
|
+
* Two rules survive the amendment:
|
|
15
|
+
* ① only a door that stores **a person's turn** mentions — never the model, a tool, or the
|
|
16
|
+
* assistant's own answer. What the assistant writes must not seat people.
|
|
17
|
+
* ② whoever is named joins as a member and is told.
|
|
18
|
+
*
|
|
19
|
+
* What went: the inviter's own role (there is nothing to hand out), the refusal verdicts, and the
|
|
20
|
+
* notice shown before sending. A private conversation is the one place a mention cannot seat
|
|
21
|
+
* someone — there the named person is told and stays outside until an owner opens it.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** 본문에서 `@user{userId:UUID}` 마커의 userId 를 뽑는다 — 첫 등장 순, 중복 제거. */
|
|
25
|
+
export function extractMentionUserIds(text: string | null | undefined): string[] {
|
|
26
|
+
if (!text) return []
|
|
27
|
+
const re = /\{userId:([^}\s]+)\}/g
|
|
28
|
+
const seen = new Set<string>()
|
|
29
|
+
const out: string[] = []
|
|
30
|
+
let m: RegExpExecArray | null
|
|
31
|
+
while ((m = re.exec(text)) !== null) {
|
|
32
|
+
const id = m[1]
|
|
33
|
+
if (!seen.has(id)) {
|
|
34
|
+
seen.add(id)
|
|
35
|
+
out.push(id)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return out
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 멘션된 사람 중 **아직 참여자가 아니고 자기 자신도 아닌** 새 사람만. */
|
|
42
|
+
export function newParticipantUserIds(
|
|
43
|
+
mentioned: ReadonlyArray<string>,
|
|
44
|
+
existing: ReadonlyArray<string>,
|
|
45
|
+
selfUserId?: string | null
|
|
46
|
+
): string[] {
|
|
47
|
+
const have = new Set(existing)
|
|
48
|
+
if (selfUserId) have.add(selfUserId)
|
|
49
|
+
const out: string[] = []
|
|
50
|
+
const seen = new Set<string>()
|
|
51
|
+
for (const id of mentioned) {
|
|
52
|
+
if (!id || have.has(id) || seen.has(id)) continue
|
|
53
|
+
seen.add(id)
|
|
54
|
+
out.push(id)
|
|
55
|
+
}
|
|
56
|
+
return out
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface MentionInviteResult {
|
|
60
|
+
/** 이번에 새로 앉은 사람들. 알림은 이들에게 간다. */
|
|
61
|
+
invited: string[]
|
|
62
|
+
/** 비공개 대화라 앉히지 못한 사람들 — 이름은 불렸고 방에는 못 들어온다. 화면이 그대로 말한다. */
|
|
63
|
+
notSeated?: string[]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface MentionInviteInput {
|
|
67
|
+
/** 저장된 **사람의 말**. 어시스턴트의 답이나 도구 결과를 여기에 넘기지 않는다(조건 ①). */
|
|
68
|
+
content: string
|
|
69
|
+
sessionId: string
|
|
70
|
+
domainId: string
|
|
71
|
+
inviter: { id?: string } | undefined | null
|
|
72
|
+
/** 참여자 저장소 — 시험이 가짜를 넣는다. */
|
|
73
|
+
participants: any
|
|
74
|
+
/** 이 대화가 공개인가(ADR-0073 판정 2). 비공개면 이름만 알리고 앉히지 않는다. */
|
|
75
|
+
visibility?: string | null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 멘션된 사람을 참여자로 앉힌다.
|
|
80
|
+
*
|
|
81
|
+
* 나갔던 사람(soft delete)은 되살린다 — 다시 부른 것이지 새 사람이 아니다.
|
|
82
|
+
*/
|
|
83
|
+
export async function inviteMentionedUsers(input: MentionInviteInput): Promise<MentionInviteResult> {
|
|
84
|
+
const mentioned = extractMentionUserIds(input.content)
|
|
85
|
+
if (mentioned.length === 0) return { invited: [] }
|
|
86
|
+
|
|
87
|
+
const repo = input.participants
|
|
88
|
+
const existing = await repo.find({
|
|
89
|
+
where: { session: { id: input.sessionId } as any, domain: { id: input.domainId } as any },
|
|
90
|
+
withDeleted: true
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const activeIds = existing.filter((row: any) => !row.deletedAt).map((row: any) => row.userId).filter(Boolean)
|
|
94
|
+
const fresh = newParticipantUserIds(mentioned, activeIds, input.inviter?.id)
|
|
95
|
+
if (fresh.length === 0) return { invited: [] }
|
|
96
|
+
|
|
97
|
+
/*
|
|
98
|
+
* 비공개 대화에서는 이름을 불러도 앉히지 않는다. 공개 대화에서는 앉히는 일이 아무것도 주지 않지만
|
|
99
|
+
* (누구나 들어온다), 비공개에서는 그것이 곧 접근을 주는 일이다. 부르는 사람이 아니라 owner 가 열
|
|
100
|
+
* 일이다 — 이름이 불렸다는 것만 알린다.
|
|
101
|
+
*/
|
|
102
|
+
if ((input.visibility ?? 'open') !== 'open') return { invited: [], notSeated: fresh }
|
|
103
|
+
|
|
104
|
+
for (const userId of fresh) {
|
|
105
|
+
const prior = existing.find((row: any) => row.userId === userId && row.deletedAt)
|
|
106
|
+
if (prior) {
|
|
107
|
+
await repo.update(prior.id, { deletedAt: null, role: 'member', updater: input.inviter } as any)
|
|
108
|
+
} else {
|
|
109
|
+
await repo.save({
|
|
110
|
+
domain: { id: input.domainId } as any,
|
|
111
|
+
session: { id: input.sessionId } as any,
|
|
112
|
+
user: { id: userId } as any,
|
|
113
|
+
role: 'member',
|
|
114
|
+
creator: input.inviter,
|
|
115
|
+
updater: input.inviter
|
|
116
|
+
} as any)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return { invited: fresh }
|
|
121
|
+
}
|
|
@@ -15,6 +15,30 @@ import { In } from 'typeorm'
|
|
|
15
15
|
import { ChatSession } from './chat-session/chat-session.js'
|
|
16
16
|
import { anchorColumns, anchorWhere } from './chat-session/session-anchor.js'
|
|
17
17
|
import { buildInbox, applyHidden, activityPatch, searchInbox, INBOX_SCAN_CAP } from './chat-session/session-inbox.js'
|
|
18
|
+
import { carriedOriginalWhere, planCarriedTurns, quoteCarriedAnswer } from './chat-message/carried-turns.js'
|
|
19
|
+
import { roomMessageBody } from './chat-message/room-message.js'
|
|
20
|
+
import { readerGate } from './chat-message/reader-gate.js'
|
|
21
|
+
import { initialVisibility, mayReadSession, SESSION_VISIBILITIES } from './chat-session/session-visibility.js'
|
|
22
|
+
import { inviteMentionedUsers } from './chat-session-participant/mention-invite.js'
|
|
23
|
+
import { buildInviteNotification } from './chat-session-participant/invite-notification.js'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 초대 알림 — 발송은 호스트의 기전을 그대로 쓴다(중복 구현 금지).
|
|
27
|
+
*
|
|
28
|
+
* 알림이 안 가도 초대 자체는 이미 일어났다. 그래서 실패를 삼키되, 초대를 되돌리지는 않는다 —
|
|
29
|
+
* 참여자 목록이 정본이고 알림은 그것을 알리는 편지다.
|
|
30
|
+
*/
|
|
31
|
+
async function notifyInvited(context: any, invited: string[], inviter: any): Promise<void> {
|
|
32
|
+
if (invited.length === 0) return
|
|
33
|
+
const payload = buildInviteNotification(invited, undefined, inviter)
|
|
34
|
+
if (!payload) return
|
|
35
|
+
try {
|
|
36
|
+
await context.state?.notify?.(payload)
|
|
37
|
+
} catch {
|
|
38
|
+
/* 편지가 못 갔다고 방에 들어온 사실이 취소되지는 않는다. */
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
import { formatProposalOutcomeLine, PROPOSAL_VERDICTS, type ProposalOutcome } from './chat-message/proposal-outcome.js'
|
|
18
42
|
import { publishSessionActivity } from './chat-session/session-activity-publish.js'
|
|
19
43
|
import { ChatMessage } from './chat-message/chat-message.js'
|
|
20
44
|
import { ChatSessionParticipant } from './chat-session-participant/chat-session-participant.js'
|
|
@@ -46,6 +70,10 @@ class ChatSessionInboxEntry {
|
|
|
46
70
|
@Field({ nullable: true, description: 'Short preview of the last message.' })
|
|
47
71
|
lastMessagePreview?: string
|
|
48
72
|
|
|
73
|
+
/** 미리보기가 이 사람에게 가려져 나갔는가 — 목록도 대화와 같은 관문을 지난다(ADR-0073 판정 1). */
|
|
74
|
+
@Field({ nullable: true, description: 'True when the preview was replaced because this reader does not pass the doors of the message it came from.' })
|
|
75
|
+
previewRedacted?: boolean
|
|
76
|
+
|
|
49
77
|
@Field({ nullable: true, description: 'Session creation timestamp.' })
|
|
50
78
|
createdAt?: Date
|
|
51
79
|
|
|
@@ -206,7 +234,22 @@ export class ChatSessionResolver {
|
|
|
206
234
|
mine: createdByMe.has(entry.id)
|
|
207
235
|
}))
|
|
208
236
|
/* showHidden=true 로 불러 **전체**를 얻는다 — 숨김 여부 판정을 두 곳에 복제하지 않기 위함. */
|
|
209
|
-
|
|
237
|
+
const shown = applyHidden(entries as any, hiddenAt, true) as any[]
|
|
238
|
+
|
|
239
|
+
/*
|
|
240
|
+
* 목록도 같은 관문을 지난다 — ADR-0073 판정 1. 미리보기는 그 답을 **다시 읽는 두 번째 길**이고,
|
|
241
|
+
* 한 길만 막으면 같은 문장이 다른 길로 그대로 나간다. 미리보기 자리를 `content` 로 바꿔 넣고
|
|
242
|
+
* 가려진 것만 되돌려 담는다.
|
|
243
|
+
*/
|
|
244
|
+
const gate = readerGate(context)
|
|
245
|
+
const judged = await gate(
|
|
246
|
+
shown.map(entry => ({ doors: entry.lastMessageDoors, content: entry.lastMessagePreview ?? '' }))
|
|
247
|
+
)
|
|
248
|
+
return shown.map((entry, index) => ({
|
|
249
|
+
...entry,
|
|
250
|
+
lastMessagePreview: judged[index].content,
|
|
251
|
+
previewRedacted: (judged[index] as any).redacted === true
|
|
252
|
+
})) as any
|
|
210
253
|
}
|
|
211
254
|
|
|
212
255
|
/**
|
|
@@ -297,6 +340,52 @@ export class ChatSessionResolver {
|
|
|
297
340
|
* 변경은 **meta 활동**으로 방송한다 — 모든 참여자 목록에 즉시 반영되지만 안 읽음 배지는 올리지 않는다
|
|
298
341
|
* (이름 변경을 "새 소식" 으로 알리면 소음이다).
|
|
299
342
|
*/
|
|
343
|
+
/**
|
|
344
|
+
* 이 대화를 도메인 안 누구나 읽게 할 것인가 — ADR-0073 판정 2.
|
|
345
|
+
*
|
|
346
|
+
* owner 만 바꾼다. 이름 바꾸기는 어느 참여자나 하지만(되돌릴 수 있고 값을 드러내지 않는다), 공개로
|
|
347
|
+
* 바꾸는 일은 이미 쓰인 글을 도메인 전체에 여는 일이다 — 되돌려도 읽힌 것은 읽힌 것이다.
|
|
348
|
+
*
|
|
349
|
+
* 화면은 공개로 바꾸기 전에 한 줄을 먼저 보인다(문구는 클라이언트가 가진다). 그 한 줄은 이 문이
|
|
350
|
+
* 강제하지 않는다 — 문이 막을 수 있는 것은 누가 바꾸느냐까지다.
|
|
351
|
+
*/
|
|
352
|
+
@Mutation(() => Boolean, {
|
|
353
|
+
description:
|
|
354
|
+
"Open this conversation to everyone in the domain, or close it to its participants. Only the owner may change it. Opening exposes what is already written — the screen says so before asking. Door checks on assistant answers are unaffected (ADR-0073)."
|
|
355
|
+
})
|
|
356
|
+
@Directive('@privilege(category: "ai-assistant", privilege: "mutation")')
|
|
357
|
+
async setSessionVisibility(
|
|
358
|
+
@Arg('sessionId') sessionId: string,
|
|
359
|
+
@Arg('visibility') visibility: string,
|
|
360
|
+
@Ctx() context: ResolverContext
|
|
361
|
+
): Promise<boolean> {
|
|
362
|
+
const { domain, user } = context.state
|
|
363
|
+
if (!SESSION_VISIBILITIES.includes(visibility as any)) {
|
|
364
|
+
throw new Error(`unknown visibility '${visibility}' — use ${SESSION_VISIBILITIES.join(' or ')}`)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const session = await getRepository(ChatSession).findOneBy({ id: sessionId, domain: { id: domain.id } as any })
|
|
368
|
+
if (!session) return false
|
|
369
|
+
|
|
370
|
+
const mine = await getRepository(ChatSessionParticipant).findOne({
|
|
371
|
+
where: { domain: { id: domain.id } as any, session: { id: sessionId } as any, user: { id: user.id } as any }
|
|
372
|
+
})
|
|
373
|
+
if (mine?.role !== 'owner') return false
|
|
374
|
+
|
|
375
|
+
if ((session as any).visibility === visibility) return true
|
|
376
|
+
|
|
377
|
+
await getRepository(ChatSession).update(sessionId, { visibility, updater: user } as any)
|
|
378
|
+
publishSessionActivity({
|
|
379
|
+
domainId: domain.id,
|
|
380
|
+
sessionId,
|
|
381
|
+
kind: 'meta',
|
|
382
|
+
anchorType: (session as any).anchorType,
|
|
383
|
+
anchorId: (session as any).anchorId,
|
|
384
|
+
actorId: user?.id
|
|
385
|
+
} as any)
|
|
386
|
+
return true
|
|
387
|
+
}
|
|
388
|
+
|
|
300
389
|
@Mutation(() => Boolean, {
|
|
301
390
|
description:
|
|
302
391
|
'Rename a chat session. Any participant may rename it — the name is the topic label of a shared deliberation and the change is reversible. Broadcast as meta activity so every participant sees it without raising unread badges.'
|
|
@@ -354,7 +443,7 @@ export class ChatSessionResolver {
|
|
|
354
443
|
|
|
355
444
|
@Query(() => [User], {
|
|
356
445
|
description:
|
|
357
|
-
'List users in the current domain for `@` mention popup.
|
|
446
|
+
'List users in the current domain for the `@` mention popup. Anyone with the chat privilege may search here; this is separate from the admin-only users().'
|
|
358
447
|
})
|
|
359
448
|
@Directive('@privilege(category: "ai-assistant", privilege: "query")')
|
|
360
449
|
async domainUsersForMention(
|
|
@@ -415,13 +504,25 @@ export class ChatSessionResolver {
|
|
|
415
504
|
@Arg('offset', () => Int, { nullable: true, defaultValue: 0 }) offset: number,
|
|
416
505
|
@Ctx() context: ResolverContext
|
|
417
506
|
): Promise<ChatMessage[]> {
|
|
418
|
-
const { domain } = context.state
|
|
507
|
+
const { domain, user } = context.state
|
|
419
508
|
const session = await getRepository(ChatSession).findOneBy({
|
|
420
509
|
id: sessionId,
|
|
421
510
|
domain: { id: domain.id }
|
|
422
511
|
})
|
|
423
512
|
if (!session) return []
|
|
424
|
-
|
|
513
|
+
|
|
514
|
+
/*
|
|
515
|
+
* 공개 대화는 도메인 안이면 누구나 읽는다 — 초대 절차가 없다(ADR-0073 판정 2). 비공개 대화는
|
|
516
|
+
* 참여자만. 여기서 막히는 것은 **방**이고, 방에 들어온 뒤 값을 읽는 일은 아래 문 판정이 따로 본다.
|
|
517
|
+
*/
|
|
518
|
+
if ((session as any).visibility === 'private') {
|
|
519
|
+
const part = await getRepository(ChatSessionParticipant).findOne({
|
|
520
|
+
where: { session: { id: sessionId } as any, user: { id: user.id } as any, domain: { id: domain.id } as any }
|
|
521
|
+
})
|
|
522
|
+
if (!mayReadSession((session as any).visibility, !!part)) return []
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const rows = await getRepository(ChatMessage).find({
|
|
425
526
|
where: { session: { id: sessionId } as any },
|
|
426
527
|
// creator: 그룹챗 발신자 표시(name) + 자기 여부 판정(email). 내부 관리키(id)에 의존하지 않는다.
|
|
427
528
|
relations: { creator: true },
|
|
@@ -429,6 +530,12 @@ export class ChatSessionResolver {
|
|
|
429
530
|
take: limit,
|
|
430
531
|
skip: offset
|
|
431
532
|
})
|
|
533
|
+
|
|
534
|
+
/*
|
|
535
|
+
* 어시스턴트의 답은 도구 결과를 평문으로 옮겨 적은 것이다. 읽는 사람이 그 도구가 지난 문을 못 지나면
|
|
536
|
+
* 본문 대신 한 줄이 나간다 — 행이 있다는 사실은 보이고 값만 안 보인다(ADR-0073 판정 1).
|
|
537
|
+
*/
|
|
538
|
+
return await readerGate(context)(rows)
|
|
432
539
|
}
|
|
433
540
|
|
|
434
541
|
@Directive('@transaction')
|
|
@@ -451,6 +558,8 @@ export class ChatSessionResolver {
|
|
|
451
558
|
const session = await repo.save({
|
|
452
559
|
domain,
|
|
453
560
|
...anchorColumns(anchorType, anchorId),
|
|
561
|
+
/* 앵커가 있는 대화는 공개로 태어난다 — ADR-0073 판정 2. */
|
|
562
|
+
visibility: initialVisibility({ anchorType }),
|
|
454
563
|
creator: user,
|
|
455
564
|
updater: user
|
|
456
565
|
} as any)
|
|
@@ -469,13 +578,13 @@ export class ChatSessionResolver {
|
|
|
469
578
|
@Directive('@transaction')
|
|
470
579
|
@Mutation(() => ChatSession, {
|
|
471
580
|
description:
|
|
472
|
-
'Always create a new AI chat session anchored to a target (no idempotent reuse). For multi-session UX —
|
|
581
|
+
'Always create a new AI chat session anchored to a target (no idempotent reuse). For multi-session UX — opening another tab.'
|
|
473
582
|
})
|
|
474
583
|
@Directive('@privilege(category: "ai-assistant", privilege: "mutation")')
|
|
475
584
|
async createAISession(
|
|
476
585
|
@Arg('anchorType') anchorType: string,
|
|
477
586
|
@Arg('anchorId') anchorId: string,
|
|
478
|
-
@Arg('name', { nullable: true, description: 'Optional name
|
|
587
|
+
@Arg('name', { nullable: true, description: 'Optional name. Defaults to a generated one, numbered within the anchor.' }) name: string | undefined,
|
|
479
588
|
@Ctx() context: ResolverContext
|
|
480
589
|
): Promise<ChatSession> {
|
|
481
590
|
const { domain, user, tx } = context.state
|
|
@@ -485,12 +594,14 @@ export class ChatSessionResolver {
|
|
|
485
594
|
let finalName = name?.trim()
|
|
486
595
|
if (!finalName) {
|
|
487
596
|
const count = await repo.count({ where: anchorWhere(domain.id, anchorType, anchorId) })
|
|
488
|
-
|
|
597
|
+
/* The name is stored, so it is written in the language of whoever created it (context.t), and read back as is. */
|
|
598
|
+
finalName = context.t('ai-assistant.session.default-name', { n: count + 1, defaultValue: 'conversation {n}' })
|
|
489
599
|
}
|
|
490
600
|
|
|
491
601
|
const session = await repo.save({
|
|
492
602
|
domain,
|
|
493
603
|
...anchorColumns(anchorType, anchorId),
|
|
604
|
+
visibility: initialVisibility({ anchorType }),
|
|
494
605
|
creator: user,
|
|
495
606
|
updater: user,
|
|
496
607
|
name: finalName
|
|
@@ -525,6 +636,124 @@ export class ChatSessionResolver {
|
|
|
525
636
|
return true
|
|
526
637
|
}
|
|
527
638
|
|
|
639
|
+
@Directive('@transaction')
|
|
640
|
+
@Mutation(() => Boolean, {
|
|
641
|
+
description:
|
|
642
|
+
"What the host did with a proposal the assistant made. The host calls this once per card it was asked to run; the server records it as a system row, so the panel shows it, a refreshed panel still shows it, and the model reads on its next turn that its proposal was refused instead of assuming it landed (ADR-0070)."
|
|
643
|
+
})
|
|
644
|
+
@Directive('@privilege(category: "ai-assistant", privilege: "mutation")')
|
|
645
|
+
async reportProposalOutcome(
|
|
646
|
+
@Arg('sessionId') sessionId: string,
|
|
647
|
+
@Arg('proposalKey') proposalKey: string,
|
|
648
|
+
@Arg('outcome', () => GraphQLJSON) outcome: ProposalOutcome,
|
|
649
|
+
@Ctx() context: ResolverContext
|
|
650
|
+
): Promise<boolean> {
|
|
651
|
+
const { domain, user, tx } = context.state
|
|
652
|
+
const session = await getRepository(ChatSession, tx).findOneBy({ id: sessionId, domain: { id: domain.id } })
|
|
653
|
+
if (!session) throw new Error(`ChatSession ${sessionId} not found`)
|
|
654
|
+
|
|
655
|
+
const key = (proposalKey ?? '').trim()
|
|
656
|
+
if (!key) return false
|
|
657
|
+
|
|
658
|
+
/*
|
|
659
|
+
* 낱말은 ADR-0042 의 것에 `declined` 하나다. 모르는 낱말을 받으면 그대로 적지 않는다 — 카드가
|
|
660
|
+
* 읽지 못하는 상태가 되고, 그때 화면은 아무 말도 못 한다.
|
|
661
|
+
*/
|
|
662
|
+
if (!PROPOSAL_VERDICTS.includes(outcome?.verdict as any)) {
|
|
663
|
+
throw new Error(
|
|
664
|
+
`[ai-assistant] '${outcome?.verdict}' is not a proposal verdict. Use one of ${PROPOSAL_VERDICTS.join(', ')}.`
|
|
665
|
+
)
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const body = formatProposalOutcomeLine(key, outcome)
|
|
669
|
+
|
|
670
|
+
const previousLast = await getRepository(ChatMessage, tx).findOne({
|
|
671
|
+
where: { session: { id: session.id } as any },
|
|
672
|
+
order: { createdAt: 'DESC' }
|
|
673
|
+
})
|
|
674
|
+
const sysMsg = await getRepository(ChatMessage, tx).save({
|
|
675
|
+
session: { id: session.id } as any,
|
|
676
|
+
role: 'system',
|
|
677
|
+
content: body,
|
|
678
|
+
creator: user,
|
|
679
|
+
updater: user,
|
|
680
|
+
parentMessage: previousLast ? ({ id: previousLast.id } as any) : undefined
|
|
681
|
+
} as any)
|
|
682
|
+
|
|
683
|
+
/* 목록의 미리보기는 사람의 말로 두는 편이 낫다 — 이 줄은 기계의 기록이다. 방송만 한다. */
|
|
684
|
+
publishChatMessage({ domainId: domain.id, sessionId: session.id, message: sysMsg })
|
|
685
|
+
return true
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
@Directive('@transaction')
|
|
689
|
+
@Mutation(() => String, {
|
|
690
|
+
nullable: true,
|
|
691
|
+
description:
|
|
692
|
+
"Say something to the people in this session. The turn is stored as the speaker's, addressed to the room, and the assistant is not called — it reads the line as context the next time someone asks it something. Returns the stored message id, or null when there was nothing to say (ADR-0070)."
|
|
693
|
+
})
|
|
694
|
+
@Directive('@privilege(category: "ai-assistant", privilege: "mutation")')
|
|
695
|
+
async sayToRoom(
|
|
696
|
+
@Arg('sessionId') sessionId: string,
|
|
697
|
+
@Arg('content') content: string,
|
|
698
|
+
@Ctx() context: ResolverContext
|
|
699
|
+
): Promise<string | null> {
|
|
700
|
+
const { domain, user, tx } = context.state
|
|
701
|
+
const session = await getRepository(ChatSession, tx).findOneBy({ id: sessionId, domain: { id: domain.id } })
|
|
702
|
+
if (!session) throw new Error(`ChatSession ${sessionId} not found`)
|
|
703
|
+
|
|
704
|
+
const body = roomMessageBody(content)
|
|
705
|
+
if (!body) return null
|
|
706
|
+
|
|
707
|
+
const previousLast = await getRepository(ChatMessage, tx).findOne({
|
|
708
|
+
where: { session: { id: session.id } as any },
|
|
709
|
+
order: { createdAt: 'DESC' }
|
|
710
|
+
})
|
|
711
|
+
const saved = await getRepository(ChatMessage, tx).save({
|
|
712
|
+
session: { id: session.id } as any,
|
|
713
|
+
role: 'user',
|
|
714
|
+
content: body,
|
|
715
|
+
/* 대상은 문이 정한다 — 이 문은 사람들에게 하는 말이다(ADR-0070 A15 결정 ①). */
|
|
716
|
+
addressee: 'room',
|
|
717
|
+
creator: user,
|
|
718
|
+
updater: user,
|
|
719
|
+
parentMessage: previousLast ? ({ id: previousLast.id } as any) : undefined
|
|
720
|
+
} as any)
|
|
721
|
+
|
|
722
|
+
/*
|
|
723
|
+
* 멘션은 사람을 불러들인다 — **사람의 말을 저장하는 문**만 이것을 한다(ADR-0071 결정 1 ①).
|
|
724
|
+
* 초대는 방에 있는 사람(owner · member)만 할 수 있고, 거절되면 그 사실이 화면으로 돌아간다.
|
|
725
|
+
*/
|
|
726
|
+
const invite = await inviteMentionedUsers({
|
|
727
|
+
content: body,
|
|
728
|
+
sessionId: session.id!,
|
|
729
|
+
domainId: domain.id,
|
|
730
|
+
inviter: user,
|
|
731
|
+
participants: getRepository(ChatSessionParticipant, tx),
|
|
732
|
+
/* 비공개 대화에서는 이름만 닿는다 — ADR-0073 판정 2. */
|
|
733
|
+
visibility: (session as any).visibility
|
|
734
|
+
})
|
|
735
|
+
await notifyInvited(context, invite.invited, user)
|
|
736
|
+
|
|
737
|
+
/* 사람의 말이다 — 목록의 최근 활동과 다른 참여자의 안 읽음이 이것으로 움직인다. */
|
|
738
|
+
try {
|
|
739
|
+
await getRepository(ChatSession, tx).update(session.id!, activityPatch(body) as any)
|
|
740
|
+
} catch {
|
|
741
|
+
/* 목록이 한 박자 늦는 것이 말을 못 하게 할 이유는 아니다. */
|
|
742
|
+
}
|
|
743
|
+
publishSessionActivity({
|
|
744
|
+
domainId: domain.id,
|
|
745
|
+
sessionId: session.id!,
|
|
746
|
+
kind: 'message',
|
|
747
|
+
anchorType: (session as any).anchorType,
|
|
748
|
+
anchorId: (session as any).anchorId,
|
|
749
|
+
preview: body,
|
|
750
|
+
actorId: user?.id
|
|
751
|
+
})
|
|
752
|
+
publishChatMessage({ domainId: domain.id, sessionId: session.id, message: saved })
|
|
753
|
+
|
|
754
|
+
return saved.id ?? null
|
|
755
|
+
}
|
|
756
|
+
|
|
528
757
|
@Directive('@transaction')
|
|
529
758
|
@Mutation(() => Boolean, {
|
|
530
759
|
description:
|
|
@@ -578,7 +807,7 @@ export class ChatSessionResolver {
|
|
|
578
807
|
@Directive('@transaction')
|
|
579
808
|
@Mutation(() => Boolean, {
|
|
580
809
|
description:
|
|
581
|
-
|
|
810
|
+
"Carry a conversation from another surface into this session as its own turns, preserving order. A person's turns are stored as theirs, addressed to the room. An assistant turn is stored as the assistant's only when it names its original (sourceSessionId, sourceMessageId) and the server can read it; otherwise it is kept as a quotation on a system row — roles are the server's to write (ADR-0070)."
|
|
582
811
|
})
|
|
583
812
|
@Directive('@privilege(category: "ai-assistant", privilege: "mutation")')
|
|
584
813
|
async appendSessionTurns(
|
|
@@ -593,13 +822,34 @@ export class ChatSessionResolver {
|
|
|
593
822
|
/* 옮겨온 대화는 **그 대화의 발언 그대로** 들어간다 — 한 덩어리 기록으로 뭉치면 사람이 읽을 수 없고
|
|
594
823
|
* (화면 하나를 잡아먹는 이탤릭 덩어리), 마크다운도 죽는다. 대신 개수·길이는 제한한다: 맥락 전달이
|
|
595
824
|
* 목적이고 전문 보존이 아니다. */
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
825
|
+
/* **역할은 서버가 쓴다**(ADR-0070 A15 결정 ③). 어시스턴트의 답은 원본을 읽어 복사하고, 원본이 없으면
|
|
826
|
+
* 인용문으로 `system` 행에 남긴다 — 클라이언트가 보낸 글자를 어시스턴트의 말로 저장하지 않는다. */
|
|
827
|
+
const planned = planCarriedTurns(turns as any)
|
|
828
|
+
const rows: { role: string; content: string; addressee?: string; doors?: string[] }[] = []
|
|
829
|
+
/* 옮겨 적힌 원문이 소급해서 공개되지 않게, 받는 대화는 이 순간부터 비공개다 — ADR-0073 판정 2. */
|
|
830
|
+
let carried = false
|
|
831
|
+
for (const row of planned) {
|
|
832
|
+
if (!row.copyOf) {
|
|
833
|
+
rows.push({ role: row.role, content: row.content, addressee: row.addressee })
|
|
834
|
+
continue
|
|
835
|
+
}
|
|
836
|
+
/* 원본은 이 테넌트 안에서만 찾는다 — 남의 도메인 메시지를 옮겨 오는 길이 되지 않게. */
|
|
837
|
+
const original = await getRepository(ChatMessage, tx).findOne({
|
|
838
|
+
where: carriedOriginalWhere(domain.id, row.copyOf),
|
|
839
|
+
relations: ['session']
|
|
840
|
+
})
|
|
841
|
+
carried = true
|
|
842
|
+
if (original && original.role === 'assistant') {
|
|
843
|
+
/*
|
|
844
|
+
* 답과 함께 **그 답이 지나온 문**을 옮긴다 — ADR-0073 판정 1. 문을 두고 글만 옮기면, 문 하나를
|
|
845
|
+
* 지나 얻은 값이 문 없는 행이 되어 아무나 읽는다. 옮겨 적기가 권한을 씻는 길이 된다.
|
|
846
|
+
*/
|
|
847
|
+
rows.push({ role: 'assistant', content: original.content, doors: (original as any).doors ?? [] })
|
|
848
|
+
} else {
|
|
849
|
+
/* 인용문에도 원문의 문을 실어 둔다 — 인용이라고 값이 달라지지 않는다. */
|
|
850
|
+
rows.push({ role: 'system', content: quoteCarriedAnswer(row.content), doors: (original as any)?.doors ?? [] })
|
|
851
|
+
}
|
|
852
|
+
}
|
|
603
853
|
if (!rows.length) return false
|
|
604
854
|
|
|
605
855
|
let previous = await getRepository(ChatMessage, tx).findOne({
|
|
@@ -612,6 +862,9 @@ export class ChatSessionResolver {
|
|
|
612
862
|
session: { id: session.id } as any,
|
|
613
863
|
role: row.role,
|
|
614
864
|
content: row.content,
|
|
865
|
+
/* 사람의 말은 방을 향한 것이다 — 이 문은 어시스턴트를 부르는 문이 아니다. */
|
|
866
|
+
addressee: row.addressee,
|
|
867
|
+
doors: row.doors,
|
|
615
868
|
creator: user,
|
|
616
869
|
updater: user,
|
|
617
870
|
parentMessage: previous ? ({ id: previous.id } as any) : undefined
|
|
@@ -619,6 +872,10 @@ export class ChatSessionResolver {
|
|
|
619
872
|
saved.push(previous!)
|
|
620
873
|
}
|
|
621
874
|
|
|
875
|
+
if (carried && (session as any).visibility !== 'private') {
|
|
876
|
+
await getRepository(ChatSession, tx).update(session.id!, { visibility: 'private', updater: user } as any)
|
|
877
|
+
}
|
|
878
|
+
|
|
622
879
|
/* 활동은 마지막 발언 기준 한 번만 — 옮긴 줄마다 목록을 흔들 이유가 없다. */
|
|
623
880
|
const last = rows[rows.length - 1]
|
|
624
881
|
try {
|