@things-factory/ai-assistant 10.1.27 → 10.1.29
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 +701 -63
- package/client/components/assistant-mode.test.ts +105 -55
- package/client/components/assistant-mode.ts +144 -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 +54 -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 +37 -1
- package/client/utils/assistant-session-transport.ts +13 -5
- package/dist-client/components/assistant-chat.d.ts +140 -13
- package/dist-client/components/assistant-chat.js +659 -71
- package/dist-client/components/assistant-chat.js.map +1 -1
- package/dist-client/components/assistant-mode.d.ts +102 -68
- package/dist-client/components/assistant-mode.js +79 -19
- package/dist-client/components/assistant-mode.js.map +1 -1
- package/dist-client/components/assistant-mode.test.js +90 -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 +49 -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 +20 -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 +13 -5
- package/dist-client/utils/assistant-session-transport.js.map +1 -1
- package/dist-server/door-declaration-report.d.ts +14 -0
- package/dist-server/door-declaration-report.js +54 -0
- package/dist-server/door-declaration-report.js.map +1 -0
- 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 +185 -44
- package/dist-server/service/assistant-chat-resolver.js.map +1 -1
- package/dist-server/service/assistant-mode/assistant-mode-resolver.d.ts +33 -0
- package/dist-server/service/assistant-mode/assistant-mode-resolver.js +148 -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 +43 -0
- package/dist-server/service/assistant-mode/resolve.js +65 -0
- package/dist-server/service/assistant-mode/resolve.js.map +1 -0
- package/dist-server/service/assistant-mode/types.d.ts +120 -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 +92 -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 +27 -0
- package/dist-server/service/chat-message/door-access.js +34 -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 +39 -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 +36 -0
- package/dist-server/service/chat-session/chat-session.js +27 -2
- package/dist-server/service/chat-session/chat-session.js.map +1 -1
- package/dist-server/service/chat-session/session-anchor.d.ts +10 -1
- package/dist-server/service/chat-session/session-anchor.js +12 -4
- package/dist-server/service/chat-session/session-anchor.js.map +1 -1
- package/dist-server/service/chat-session/session-inbox.d.ts +6 -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-kind.d.ts +14 -0
- package/dist-server/service/chat-session/session-kind.js +30 -0
- package/dist-server/service/chat-session/session-kind.js.map +1 -0
- package/dist-server/service/chat-session/session-visibility.d.ts +15 -0
- package/dist-server/service/chat-session/session-visibility.js +35 -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 +17 -0
- package/dist-server/service/chat-session-resolver.js +271 -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 +9 -1
- package/dist-server/service/index.js +21 -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 +50 -0
- package/dist-server/service/testing/mode-conformance.js +103 -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 +32 -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/door-declaration-report.test.ts +53 -0
- package/server/door-declaration-report.ts +61 -0
- 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 +205 -42
- package/server/service/assistant-mode/assistant-mode-resolver.ts +108 -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 +120 -0
- package/server/service/assistant-mode/resolve.ts +105 -0
- package/server/service/assistant-mode/subject-defaults.test.ts +86 -0
- package/server/service/assistant-mode/types.ts +121 -0
- package/server/service/chat-message/carried-turns.test.ts +80 -0
- package/server/service/chat-message/carried-turns.ts +112 -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.test.ts +72 -0
- package/server/service/chat-message/door-access.ts +65 -0
- package/server/service/chat-message/fold-history-window.test.ts +184 -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 +44 -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 +46 -1
- package/server/service/chat-session/session-anchor.ts +12 -3
- package/server/service/chat-session/session-inbox.test.ts +18 -0
- package/server/service/chat-session/session-inbox.ts +11 -2
- package/server/service/chat-session/session-kind.test.ts +24 -0
- package/server/service/chat-session/session-kind.ts +32 -0
- package/server/service/chat-session/session-visibility.test.ts +52 -0
- package/server/service/chat-session/session-visibility.ts +34 -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 +276 -15
- package/server/service/grounding-sources.test.ts +55 -0
- package/server/service/grounding-sources.ts +46 -0
- package/server/service/index.ts +21 -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 +122 -0
- package/server/tool-registry-boot-report.ts +31 -2
- package/test/assistant-chat-call-sites.test.ts +82 -0
- package/translations/en.json +46 -3
- package/translations/ja.json +46 -3
- package/translations/ko.json +46 -3
- package/translations/ms.json +46 -3
- package/translations/zh.json +46 -3
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Mentioning someone tells them (ADR-0071 decision 1, as amended by ADR-0073).
|
|
4
|
+
*
|
|
5
|
+
* The machinery existed in the board product only: `@name` in a board chat added a participant and
|
|
6
|
+
* sent them an invite, and the same `@name` in a twin deliberation added nobody. The person typing
|
|
7
|
+
* it had every reason to believe they had called a colleague in.
|
|
8
|
+
*
|
|
9
|
+
* ── What a mention is now ─────────────────────────────────────────────────────
|
|
10
|
+
* A conversation in the domain is open: anyone may walk in, with nothing to approve and nobody to
|
|
11
|
+
* ask (ADR-0073 decision 2). So a mention grants nothing — it points. It seats the named person so
|
|
12
|
+
* the conversation reaches their list, and it tells them their name came up. Somebody who was never
|
|
13
|
+
* mentioned can read the same room by opening it.
|
|
14
|
+
*
|
|
15
|
+
* Two rules survive the amendment:
|
|
16
|
+
* ① only a door that stores **a person's turn** mentions — never the model, a tool, or the
|
|
17
|
+
* assistant's own answer. What the assistant writes must not seat people.
|
|
18
|
+
* ② whoever is named joins as a member and is told.
|
|
19
|
+
*
|
|
20
|
+
* What went: the inviter's own role (there is nothing to hand out), the refusal verdicts, and the
|
|
21
|
+
* notice shown before sending. A private conversation is the one place a mention cannot seat
|
|
22
|
+
* someone — there the named person is told and stays outside until an owner opens it.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.extractMentionUserIds = extractMentionUserIds;
|
|
26
|
+
exports.newParticipantUserIds = newParticipantUserIds;
|
|
27
|
+
exports.inviteMentionedUsers = inviteMentionedUsers;
|
|
28
|
+
/** 본문에서 `@user{userId:UUID}` 마커의 userId 를 뽑는다 — 첫 등장 순, 중복 제거. */
|
|
29
|
+
function extractMentionUserIds(text) {
|
|
30
|
+
if (!text)
|
|
31
|
+
return [];
|
|
32
|
+
const re = /\{userId:([^}\s]+)\}/g;
|
|
33
|
+
const seen = new Set();
|
|
34
|
+
const out = [];
|
|
35
|
+
let m;
|
|
36
|
+
while ((m = re.exec(text)) !== null) {
|
|
37
|
+
const id = m[1];
|
|
38
|
+
if (!seen.has(id)) {
|
|
39
|
+
seen.add(id);
|
|
40
|
+
out.push(id);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
/** 멘션된 사람 중 **아직 참여자가 아니고 자기 자신도 아닌** 새 사람만. */
|
|
46
|
+
function newParticipantUserIds(mentioned, existing, selfUserId) {
|
|
47
|
+
const have = new Set(existing);
|
|
48
|
+
if (selfUserId)
|
|
49
|
+
have.add(selfUserId);
|
|
50
|
+
const out = [];
|
|
51
|
+
const seen = new Set();
|
|
52
|
+
for (const id of mentioned) {
|
|
53
|
+
if (!id || have.has(id) || seen.has(id))
|
|
54
|
+
continue;
|
|
55
|
+
seen.add(id);
|
|
56
|
+
out.push(id);
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 멘션된 사람을 참여자로 앉힌다.
|
|
62
|
+
*
|
|
63
|
+
* 나갔던 사람(soft delete)은 되살린다 — 다시 부른 것이지 새 사람이 아니다.
|
|
64
|
+
*/
|
|
65
|
+
async function inviteMentionedUsers(input) {
|
|
66
|
+
const mentioned = extractMentionUserIds(input.content);
|
|
67
|
+
if (mentioned.length === 0)
|
|
68
|
+
return { invited: [] };
|
|
69
|
+
const repo = input.participants;
|
|
70
|
+
const existing = await repo.find({
|
|
71
|
+
where: { session: { id: input.sessionId }, domain: { id: input.domainId } },
|
|
72
|
+
withDeleted: true
|
|
73
|
+
});
|
|
74
|
+
const activeIds = existing.filter((row) => !row.deletedAt).map((row) => row.userId).filter(Boolean);
|
|
75
|
+
const fresh = newParticipantUserIds(mentioned, activeIds, input.inviter?.id);
|
|
76
|
+
if (fresh.length === 0)
|
|
77
|
+
return { invited: [] };
|
|
78
|
+
/*
|
|
79
|
+
* 비공개 대화에서는 이름을 불러도 앉히지 않는다. 공개 대화에서는 앉히는 일이 아무것도 주지 않지만
|
|
80
|
+
* (누구나 들어온다), 비공개에서는 그것이 곧 접근을 주는 일이다. 부르는 사람이 아니라 owner 가 열
|
|
81
|
+
* 일이다 — 이름이 불렸다는 것만 알린다.
|
|
82
|
+
*/
|
|
83
|
+
if ((input.visibility ?? 'open') !== 'open')
|
|
84
|
+
return { invited: [], notSeated: fresh };
|
|
85
|
+
for (const userId of fresh) {
|
|
86
|
+
const prior = existing.find((row) => row.userId === userId && row.deletedAt);
|
|
87
|
+
if (prior) {
|
|
88
|
+
await repo.update(prior.id, { deletedAt: null, role: 'member', updater: input.inviter });
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
await repo.save({
|
|
92
|
+
domain: { id: input.domainId },
|
|
93
|
+
session: { id: input.sessionId },
|
|
94
|
+
user: { id: userId },
|
|
95
|
+
role: 'member',
|
|
96
|
+
creator: input.inviter,
|
|
97
|
+
updater: input.inviter
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { invited: fresh };
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=mention-invite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mention-invite.js","sourceRoot":"","sources":["../../../server/service/chat-session-participant/mention-invite.ts"],"names":[],"mappings":"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","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\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 판정 2). 비공개면 이름만 알리고 앉히지 않는다. */\n visibility?: string | null\n}\n\n/**\n * 멘션된 사람을 참여자로 앉힌다.\n *\n * 나갔던 사람(soft delete)은 되살린다 — 다시 부른 것이지 새 사람이 아니다.\n */\nexport async function inviteMentionedUsers(input: MentionInviteInput): Promise<MentionInviteResult> {\n const mentioned = extractMentionUserIds(input.content)\n if (mentioned.length === 0) return { invited: [] }\n\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 const activeIds = existing.filter((row: any) => !row.deletedAt).map((row: any) => row.userId).filter(Boolean)\n const fresh = newParticipantUserIds(mentioned, activeIds, input.inviter?.id)\n if (fresh.length === 0) return { invited: [] }\n\n /*\n * 비공개 대화에서는 이름을 불러도 앉히지 않는다. 공개 대화에서는 앉히는 일이 아무것도 주지 않지만\n * (누구나 들어온다), 비공개에서는 그것이 곧 접근을 주는 일이다. 부르는 사람이 아니라 owner 가 열\n * 일이다 — 이름이 불렸다는 것만 알린다.\n */\n if ((input.visibility ?? 'open') !== 'open') return { invited: [], notSeated: fresh }\n\n for (const userId of fresh) {\n const prior = existing.find((row: any) => row.userId === userId && row.deletedAt)\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\n return { invited: fresh }\n}\n"]}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { User } from '@things-factory/auth-base';
|
|
2
2
|
import { ChatSession } from './chat-session/chat-session.js';
|
|
3
|
+
import { type ProposalOutcome } from './chat-message/proposal-outcome.js';
|
|
3
4
|
import { ChatMessage } from './chat-message/chat-message.js';
|
|
4
5
|
import { ChatSessionParticipant } from './chat-session-participant/chat-session-participant.js';
|
|
5
6
|
declare class ChatSessionInboxEntry {
|
|
6
7
|
id?: string;
|
|
7
8
|
name?: string;
|
|
9
|
+
/** 어느 대화인가 — 목록에서 고른 것이 지금 열린 대화와 다르면 화면이 그 대화로 따라간다. */
|
|
10
|
+
kind?: string;
|
|
8
11
|
anchorType?: string;
|
|
9
12
|
anchorId?: string;
|
|
10
13
|
boardId?: string;
|
|
11
14
|
lastMessageAt?: Date;
|
|
12
15
|
lastMessagePreview?: string;
|
|
16
|
+
/** 미리보기가 이 사람에게 가려져 나갔는가 — 목록도 대화와 같은 관문을 지난다(ADR-0073 판정 1). */
|
|
17
|
+
previewRedacted?: boolean;
|
|
13
18
|
createdAt?: Date;
|
|
14
19
|
unread: boolean;
|
|
15
20
|
participant: boolean;
|
|
@@ -71,6 +76,16 @@ export declare class ChatSessionResolver {
|
|
|
71
76
|
* 변경은 **meta 활동**으로 방송한다 — 모든 참여자 목록에 즉시 반영되지만 안 읽음 배지는 올리지 않는다
|
|
72
77
|
* (이름 변경을 "새 소식" 으로 알리면 소음이다).
|
|
73
78
|
*/
|
|
79
|
+
/**
|
|
80
|
+
* 이 대화를 도메인 안 누구나 읽게 할 것인가 — ADR-0073 판정 2.
|
|
81
|
+
*
|
|
82
|
+
* owner 만 바꾼다. 이름 바꾸기는 어느 참여자나 하지만(되돌릴 수 있고 값을 드러내지 않는다), 공개로
|
|
83
|
+
* 바꾸는 일은 이미 쓰인 글을 도메인 전체에 여는 일이다 — 되돌려도 읽힌 것은 읽힌 것이다.
|
|
84
|
+
*
|
|
85
|
+
* 화면은 공개로 바꾸기 전에 한 줄을 먼저 보인다(문구는 클라이언트가 가진다). 그 한 줄은 이 문이
|
|
86
|
+
* 강제하지 않는다 — 문이 막을 수 있는 것은 누가 바꾸느냐까지다.
|
|
87
|
+
*/
|
|
88
|
+
setSessionVisibility(sessionId: string, visibility: string, context: ResolverContext): Promise<boolean>;
|
|
74
89
|
renameAISession(sessionId: string, name: string, context: ResolverContext): Promise<boolean>;
|
|
75
90
|
/**
|
|
76
91
|
* 읽은 지점 갱신 — 이 세션을 여기까지 읽었다. 멱등(여러 번 호출해도 최신 시각으로만 이동).
|
|
@@ -84,6 +99,8 @@ export declare class ChatSessionResolver {
|
|
|
84
99
|
startAISession(anchorType: string, anchorId: string, context: ResolverContext): Promise<ChatSession>;
|
|
85
100
|
createAISession(anchorType: string, anchorId: string, name: string | undefined, context: ResolverContext): Promise<ChatSession>;
|
|
86
101
|
renameChatSession(sessionId: string, name: string, context: ResolverContext): Promise<boolean>;
|
|
102
|
+
reportProposalOutcome(sessionId: string, proposalKey: string, outcome: ProposalOutcome, context: ResolverContext): Promise<boolean>;
|
|
103
|
+
sayToRoom(sessionId: string, content: string, context: ResolverContext): Promise<string | null>;
|
|
87
104
|
appendSessionNote(sessionId: string, content: string, context: ResolverContext): Promise<boolean>;
|
|
88
105
|
appendSessionTurns(sessionId: string, turns: {
|
|
89
106
|
role?: string;
|
|
@@ -17,6 +17,32 @@ const typeorm_1 = require("typeorm");
|
|
|
17
17
|
const chat_session_js_1 = require("./chat-session/chat-session.js");
|
|
18
18
|
const session_anchor_js_1 = require("./chat-session/session-anchor.js");
|
|
19
19
|
const session_inbox_js_1 = require("./chat-session/session-inbox.js");
|
|
20
|
+
const carried_turns_js_1 = require("./chat-message/carried-turns.js");
|
|
21
|
+
const room_message_js_1 = require("./chat-message/room-message.js");
|
|
22
|
+
const reader_gate_js_1 = require("./chat-message/reader-gate.js");
|
|
23
|
+
const session_visibility_js_1 = require("./chat-session/session-visibility.js");
|
|
24
|
+
const mention_invite_js_1 = require("./chat-session-participant/mention-invite.js");
|
|
25
|
+
const invite_notification_js_1 = require("./chat-session-participant/invite-notification.js");
|
|
26
|
+
/**
|
|
27
|
+
* 초대 알림 — 발송은 호스트의 기전을 그대로 쓴다(중복 구현 금지).
|
|
28
|
+
*
|
|
29
|
+
* 알림이 안 가도 초대 자체는 이미 일어났다. 그래서 실패를 삼키되, 초대를 되돌리지는 않는다 —
|
|
30
|
+
* 참여자 목록이 정본이고 알림은 그것을 알리는 편지다.
|
|
31
|
+
*/
|
|
32
|
+
async function notifyInvited(context, invited, inviter) {
|
|
33
|
+
if (invited.length === 0)
|
|
34
|
+
return;
|
|
35
|
+
const payload = (0, invite_notification_js_1.buildInviteNotification)(invited, undefined, inviter);
|
|
36
|
+
if (!payload)
|
|
37
|
+
return;
|
|
38
|
+
try {
|
|
39
|
+
await context.state?.notify?.(payload);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
/* 편지가 못 갔다고 방에 들어온 사실이 취소되지는 않는다. */
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const proposal_outcome_js_1 = require("./chat-message/proposal-outcome.js");
|
|
20
46
|
const session_activity_publish_js_1 = require("./chat-session/session-activity-publish.js");
|
|
21
47
|
const chat_message_js_1 = require("./chat-message/chat-message.js");
|
|
22
48
|
const chat_session_participant_js_1 = require("./chat-session-participant/chat-session-participant.js");
|
|
@@ -31,6 +57,10 @@ tslib_1.__decorate([
|
|
|
31
57
|
(0, type_graphql_1.Field)({ nullable: true, description: 'User-given session name (tab label).' }),
|
|
32
58
|
tslib_1.__metadata("design:type", String)
|
|
33
59
|
], ChatSessionInboxEntry.prototype, "name", void 0);
|
|
60
|
+
tslib_1.__decorate([
|
|
61
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Which conversation this session is — the registered mode kind.' }),
|
|
62
|
+
tslib_1.__metadata("design:type", String)
|
|
63
|
+
], ChatSessionInboxEntry.prototype, "kind", void 0);
|
|
34
64
|
tslib_1.__decorate([
|
|
35
65
|
(0, type_graphql_1.Field)({ nullable: true, description: "What the session is anchored to: 'board' | 'space' | 'instance' | 'none'." }),
|
|
36
66
|
tslib_1.__metadata("design:type", String)
|
|
@@ -51,6 +81,10 @@ tslib_1.__decorate([
|
|
|
51
81
|
(0, type_graphql_1.Field)({ nullable: true, description: 'Short preview of the last message.' }),
|
|
52
82
|
tslib_1.__metadata("design:type", String)
|
|
53
83
|
], ChatSessionInboxEntry.prototype, "lastMessagePreview", void 0);
|
|
84
|
+
tslib_1.__decorate([
|
|
85
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'True when the preview was replaced because this reader does not pass the doors of the message it came from.' }),
|
|
86
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
87
|
+
], ChatSessionInboxEntry.prototype, "previewRedacted", void 0);
|
|
54
88
|
tslib_1.__decorate([
|
|
55
89
|
(0, type_graphql_1.Field)({ nullable: true, description: 'Session creation timestamp.' }),
|
|
56
90
|
tslib_1.__metadata("design:type", Date)
|
|
@@ -152,7 +186,19 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
152
186
|
mine: createdByMe.has(entry.id)
|
|
153
187
|
}));
|
|
154
188
|
/* showHidden=true 로 불러 **전체**를 얻는다 — 숨김 여부 판정을 두 곳에 복제하지 않기 위함. */
|
|
155
|
-
|
|
189
|
+
const shown = (0, session_inbox_js_1.applyHidden)(entries, hiddenAt, true);
|
|
190
|
+
/*
|
|
191
|
+
* 목록도 같은 관문을 지난다 — ADR-0073 판정 1. 미리보기는 그 답을 **다시 읽는 두 번째 길**이고,
|
|
192
|
+
* 한 길만 막으면 같은 문장이 다른 길로 그대로 나간다. 미리보기 자리를 `content` 로 바꿔 넣고
|
|
193
|
+
* 가려진 것만 되돌려 담는다.
|
|
194
|
+
*/
|
|
195
|
+
const gate = (0, reader_gate_js_1.readerGate)(context);
|
|
196
|
+
const judged = await gate(shown.map(entry => ({ doors: entry.lastMessageDoors, content: entry.lastMessagePreview ?? '' })));
|
|
197
|
+
return shown.map((entry, index) => ({
|
|
198
|
+
...entry,
|
|
199
|
+
lastMessagePreview: judged[index].content,
|
|
200
|
+
previewRedacted: judged[index].redacted === true
|
|
201
|
+
}));
|
|
156
202
|
}
|
|
157
203
|
/**
|
|
158
204
|
* 세션 삭제 — **만든 사람만.**
|
|
@@ -231,6 +277,41 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
231
277
|
* 변경은 **meta 활동**으로 방송한다 — 모든 참여자 목록에 즉시 반영되지만 안 읽음 배지는 올리지 않는다
|
|
232
278
|
* (이름 변경을 "새 소식" 으로 알리면 소음이다).
|
|
233
279
|
*/
|
|
280
|
+
/**
|
|
281
|
+
* 이 대화를 도메인 안 누구나 읽게 할 것인가 — ADR-0073 판정 2.
|
|
282
|
+
*
|
|
283
|
+
* owner 만 바꾼다. 이름 바꾸기는 어느 참여자나 하지만(되돌릴 수 있고 값을 드러내지 않는다), 공개로
|
|
284
|
+
* 바꾸는 일은 이미 쓰인 글을 도메인 전체에 여는 일이다 — 되돌려도 읽힌 것은 읽힌 것이다.
|
|
285
|
+
*
|
|
286
|
+
* 화면은 공개로 바꾸기 전에 한 줄을 먼저 보인다(문구는 클라이언트가 가진다). 그 한 줄은 이 문이
|
|
287
|
+
* 강제하지 않는다 — 문이 막을 수 있는 것은 누가 바꾸느냐까지다.
|
|
288
|
+
*/
|
|
289
|
+
async setSessionVisibility(sessionId, visibility, context) {
|
|
290
|
+
const { domain, user } = context.state;
|
|
291
|
+
if (!session_visibility_js_1.SESSION_VISIBILITIES.includes(visibility)) {
|
|
292
|
+
throw new Error(`unknown visibility '${visibility}' — use ${session_visibility_js_1.SESSION_VISIBILITIES.join(' or ')}`);
|
|
293
|
+
}
|
|
294
|
+
const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({ id: sessionId, domain: { id: domain.id } });
|
|
295
|
+
if (!session)
|
|
296
|
+
return false;
|
|
297
|
+
const mine = await (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant).findOne({
|
|
298
|
+
where: { domain: { id: domain.id }, session: { id: sessionId }, user: { id: user.id } }
|
|
299
|
+
});
|
|
300
|
+
if (mine?.role !== 'owner')
|
|
301
|
+
return false;
|
|
302
|
+
if (session.visibility === visibility)
|
|
303
|
+
return true;
|
|
304
|
+
await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).update(sessionId, { visibility, updater: user });
|
|
305
|
+
(0, session_activity_publish_js_1.publishSessionActivity)({
|
|
306
|
+
domainId: domain.id,
|
|
307
|
+
sessionId,
|
|
308
|
+
kind: 'meta',
|
|
309
|
+
anchorType: session.anchorType,
|
|
310
|
+
anchorId: session.anchorId,
|
|
311
|
+
actorId: user?.id
|
|
312
|
+
});
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
234
315
|
async renameAISession(sessionId, name, context) {
|
|
235
316
|
const { domain, user } = context.state;
|
|
236
317
|
const trimmed = (name ?? '').trim().slice(0, 200);
|
|
@@ -306,14 +387,25 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
306
387
|
return true;
|
|
307
388
|
}
|
|
308
389
|
async chatMessages(sessionId, limit, offset, context) {
|
|
309
|
-
const { domain } = context.state;
|
|
390
|
+
const { domain, user } = context.state;
|
|
310
391
|
const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({
|
|
311
392
|
id: sessionId,
|
|
312
393
|
domain: { id: domain.id }
|
|
313
394
|
});
|
|
314
395
|
if (!session)
|
|
315
396
|
return [];
|
|
316
|
-
|
|
397
|
+
/*
|
|
398
|
+
* 공개 대화는 도메인 안이면 누구나 읽는다 — 초대 절차가 없다(ADR-0073 판정 2). 비공개 대화는
|
|
399
|
+
* 참여자만. 여기서 막히는 것은 **방**이고, 방에 들어온 뒤 값을 읽는 일은 아래 문 판정이 따로 본다.
|
|
400
|
+
*/
|
|
401
|
+
if (session.visibility === 'private') {
|
|
402
|
+
const part = await (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant).findOne({
|
|
403
|
+
where: { session: { id: sessionId }, user: { id: user.id }, domain: { id: domain.id } }
|
|
404
|
+
});
|
|
405
|
+
if (!(0, session_visibility_js_1.mayReadSession)(session.visibility, !!part))
|
|
406
|
+
return [];
|
|
407
|
+
}
|
|
408
|
+
const rows = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage).find({
|
|
317
409
|
where: { session: { id: sessionId } },
|
|
318
410
|
// creator: 그룹챗 발신자 표시(name) + 자기 여부 판정(email). 내부 관리키(id)에 의존하지 않는다.
|
|
319
411
|
relations: { creator: true },
|
|
@@ -321,6 +413,11 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
321
413
|
take: limit,
|
|
322
414
|
skip: offset
|
|
323
415
|
});
|
|
416
|
+
/*
|
|
417
|
+
* 어시스턴트의 답은 도구 결과를 평문으로 옮겨 적은 것이다. 읽는 사람이 그 도구가 지난 문을 못 지나면
|
|
418
|
+
* 본문 대신 한 줄이 나간다 — 행이 있다는 사실은 보이고 값만 안 보인다(ADR-0073 판정 1).
|
|
419
|
+
*/
|
|
420
|
+
return await (0, reader_gate_js_1.readerGate)(context)(rows);
|
|
324
421
|
}
|
|
325
422
|
async startAISession(anchorType, anchorId, context) {
|
|
326
423
|
const { domain, user, tx } = context.state;
|
|
@@ -331,6 +428,8 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
331
428
|
const session = await repo.save({
|
|
332
429
|
domain,
|
|
333
430
|
...(0, session_anchor_js_1.anchorColumns)(anchorType, anchorId),
|
|
431
|
+
/* 앵커가 있는 대화는 공개로 태어난다 — ADR-0073 판정 2. */
|
|
432
|
+
visibility: (0, session_visibility_js_1.initialVisibility)({ anchorType }),
|
|
334
433
|
creator: user,
|
|
335
434
|
updater: user
|
|
336
435
|
});
|
|
@@ -352,11 +451,13 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
352
451
|
let finalName = name?.trim();
|
|
353
452
|
if (!finalName) {
|
|
354
453
|
const count = await repo.count({ where: (0, session_anchor_js_1.anchorWhere)(domain.id, anchorType, anchorId) });
|
|
355
|
-
|
|
454
|
+
/* The name is stored, so it is written in the language of whoever created it (context.t), and read back as is. */
|
|
455
|
+
finalName = context.t('ai-assistant.session.default-name', { n: count + 1, defaultValue: 'conversation {n}' });
|
|
356
456
|
}
|
|
357
457
|
const session = await repo.save({
|
|
358
458
|
domain,
|
|
359
459
|
...(0, session_anchor_js_1.anchorColumns)(anchorType, anchorId),
|
|
460
|
+
visibility: (0, session_visibility_js_1.initialVisibility)({ anchorType }),
|
|
360
461
|
creator: user,
|
|
361
462
|
updater: user,
|
|
362
463
|
name: finalName
|
|
@@ -381,6 +482,93 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
381
482
|
await repo.update(sessionId, { name: name.trim() || null, updater: user });
|
|
382
483
|
return true;
|
|
383
484
|
}
|
|
485
|
+
async reportProposalOutcome(sessionId, proposalKey, outcome, context) {
|
|
486
|
+
const { domain, user, tx } = context.state;
|
|
487
|
+
const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).findOneBy({ id: sessionId, domain: { id: domain.id } });
|
|
488
|
+
if (!session)
|
|
489
|
+
throw new Error(`ChatSession ${sessionId} not found`);
|
|
490
|
+
const key = (proposalKey ?? '').trim();
|
|
491
|
+
if (!key)
|
|
492
|
+
return false;
|
|
493
|
+
/*
|
|
494
|
+
* 낱말은 ADR-0042 의 것에 `declined` 하나다. 모르는 낱말을 받으면 그대로 적지 않는다 — 카드가
|
|
495
|
+
* 읽지 못하는 상태가 되고, 그때 화면은 아무 말도 못 한다.
|
|
496
|
+
*/
|
|
497
|
+
if (!proposal_outcome_js_1.PROPOSAL_VERDICTS.includes(outcome?.verdict)) {
|
|
498
|
+
throw new Error(`[ai-assistant] '${outcome?.verdict}' is not a proposal verdict. Use one of ${proposal_outcome_js_1.PROPOSAL_VERDICTS.join(', ')}.`);
|
|
499
|
+
}
|
|
500
|
+
const body = (0, proposal_outcome_js_1.formatProposalOutcomeLine)(key, outcome);
|
|
501
|
+
const previousLast = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).findOne({
|
|
502
|
+
where: { session: { id: session.id } },
|
|
503
|
+
order: { createdAt: 'DESC' }
|
|
504
|
+
});
|
|
505
|
+
const sysMsg = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).save({
|
|
506
|
+
session: { id: session.id },
|
|
507
|
+
role: 'system',
|
|
508
|
+
content: body,
|
|
509
|
+
creator: user,
|
|
510
|
+
updater: user,
|
|
511
|
+
parentMessage: previousLast ? { id: previousLast.id } : undefined
|
|
512
|
+
});
|
|
513
|
+
/* 목록의 미리보기는 사람의 말로 두는 편이 낫다 — 이 줄은 기계의 기록이다. 방송만 한다. */
|
|
514
|
+
(0, chat_message_publish_js_1.publishChatMessage)({ domainId: domain.id, sessionId: session.id, message: sysMsg });
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
async sayToRoom(sessionId, content, context) {
|
|
518
|
+
const { domain, user, tx } = context.state;
|
|
519
|
+
const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).findOneBy({ id: sessionId, domain: { id: domain.id } });
|
|
520
|
+
if (!session)
|
|
521
|
+
throw new Error(`ChatSession ${sessionId} not found`);
|
|
522
|
+
const body = (0, room_message_js_1.roomMessageBody)(content);
|
|
523
|
+
if (!body)
|
|
524
|
+
return null;
|
|
525
|
+
const previousLast = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).findOne({
|
|
526
|
+
where: { session: { id: session.id } },
|
|
527
|
+
order: { createdAt: 'DESC' }
|
|
528
|
+
});
|
|
529
|
+
const saved = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).save({
|
|
530
|
+
session: { id: session.id },
|
|
531
|
+
role: 'user',
|
|
532
|
+
content: body,
|
|
533
|
+
/* 대상은 문이 정한다 — 이 문은 사람들에게 하는 말이다(ADR-0070 A15 결정 ①). */
|
|
534
|
+
addressee: 'room',
|
|
535
|
+
creator: user,
|
|
536
|
+
updater: user,
|
|
537
|
+
parentMessage: previousLast ? { id: previousLast.id } : undefined
|
|
538
|
+
});
|
|
539
|
+
/*
|
|
540
|
+
* 멘션은 사람을 불러들인다 — **사람의 말을 저장하는 문**만 이것을 한다(ADR-0071 결정 1 ①).
|
|
541
|
+
* 초대는 방에 있는 사람(owner · member)만 할 수 있고, 거절되면 그 사실이 화면으로 돌아간다.
|
|
542
|
+
*/
|
|
543
|
+
const invite = await (0, mention_invite_js_1.inviteMentionedUsers)({
|
|
544
|
+
content: body,
|
|
545
|
+
sessionId: session.id,
|
|
546
|
+
domainId: domain.id,
|
|
547
|
+
inviter: user,
|
|
548
|
+
participants: (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant, tx),
|
|
549
|
+
/* 비공개 대화에서는 이름만 닿는다 — ADR-0073 판정 2. */
|
|
550
|
+
visibility: session.visibility
|
|
551
|
+
});
|
|
552
|
+
await notifyInvited(context, invite.invited, user);
|
|
553
|
+
/* 사람의 말이다 — 목록의 최근 활동과 다른 참여자의 안 읽음이 이것으로 움직인다. */
|
|
554
|
+
try {
|
|
555
|
+
await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).update(session.id, (0, session_inbox_js_1.activityPatch)(body));
|
|
556
|
+
}
|
|
557
|
+
catch {
|
|
558
|
+
/* 목록이 한 박자 늦는 것이 말을 못 하게 할 이유는 아니다. */
|
|
559
|
+
}
|
|
560
|
+
(0, session_activity_publish_js_1.publishSessionActivity)({
|
|
561
|
+
domainId: domain.id,
|
|
562
|
+
sessionId: session.id,
|
|
563
|
+
kind: 'message',
|
|
564
|
+
anchorType: session.anchorType,
|
|
565
|
+
anchorId: session.anchorId,
|
|
566
|
+
preview: body,
|
|
567
|
+
actorId: user?.id
|
|
568
|
+
});
|
|
569
|
+
(0, chat_message_publish_js_1.publishChatMessage)({ domainId: domain.id, sessionId: session.id, message: saved });
|
|
570
|
+
return saved.id ?? null;
|
|
571
|
+
}
|
|
384
572
|
async appendSessionNote(sessionId, content, context) {
|
|
385
573
|
const { domain, user, tx } = context.state;
|
|
386
574
|
const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).findOneBy({ id: sessionId, domain: { id: domain.id } });
|
|
@@ -429,13 +617,35 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
429
617
|
/* 옮겨온 대화는 **그 대화의 발언 그대로** 들어간다 — 한 덩어리 기록으로 뭉치면 사람이 읽을 수 없고
|
|
430
618
|
* (화면 하나를 잡아먹는 이탤릭 덩어리), 마크다운도 죽는다. 대신 개수·길이는 제한한다: 맥락 전달이
|
|
431
619
|
* 목적이고 전문 보존이 아니다. */
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
620
|
+
/* **역할은 서버가 쓴다**(ADR-0070 A15 결정 ③). 어시스턴트의 답은 원본을 읽어 복사하고, 원본이 없으면
|
|
621
|
+
* 인용문으로 `system` 행에 남긴다 — 클라이언트가 보낸 글자를 어시스턴트의 말로 저장하지 않는다. */
|
|
622
|
+
const planned = (0, carried_turns_js_1.planCarriedTurns)(turns);
|
|
623
|
+
const rows = [];
|
|
624
|
+
/* 옮겨 적힌 원문이 소급해서 공개되지 않게, 받는 대화는 이 순간부터 비공개다 — ADR-0073 판정 2. */
|
|
625
|
+
let carried = false;
|
|
626
|
+
for (const row of planned) {
|
|
627
|
+
if (!row.copyOf) {
|
|
628
|
+
rows.push({ role: row.role, content: row.content, addressee: row.addressee });
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
/* 원본은 이 테넌트 안에서만 찾는다 — 남의 도메인 메시지를 옮겨 오는 길이 되지 않게. */
|
|
632
|
+
const original = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).findOne({
|
|
633
|
+
where: (0, carried_turns_js_1.carriedOriginalWhere)(domain.id, row.copyOf),
|
|
634
|
+
relations: ['session']
|
|
635
|
+
});
|
|
636
|
+
carried = true;
|
|
637
|
+
if (original && original.role === 'assistant') {
|
|
638
|
+
/*
|
|
639
|
+
* 답과 함께 **그 답이 지나온 문**을 옮긴다 — ADR-0073 판정 1. 문을 두고 글만 옮기면, 문 하나를
|
|
640
|
+
* 지나 얻은 값이 문 없는 행이 되어 아무나 읽는다. 옮겨 적기가 권한을 씻는 길이 된다.
|
|
641
|
+
*/
|
|
642
|
+
rows.push({ role: 'assistant', content: original.content, doors: original.doors ?? [] });
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
/* 인용문에도 원문의 문을 실어 둔다 — 인용이라고 값이 달라지지 않는다. */
|
|
646
|
+
rows.push({ role: 'system', content: (0, carried_turns_js_1.quoteCarriedAnswer)(row.content), doors: original?.doors ?? [] });
|
|
647
|
+
}
|
|
648
|
+
}
|
|
439
649
|
if (!rows.length)
|
|
440
650
|
return false;
|
|
441
651
|
let previous = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).findOne({
|
|
@@ -448,12 +658,18 @@ let ChatSessionResolver = class ChatSessionResolver {
|
|
|
448
658
|
session: { id: session.id },
|
|
449
659
|
role: row.role,
|
|
450
660
|
content: row.content,
|
|
661
|
+
/* 사람의 말은 방을 향한 것이다 — 이 문은 어시스턴트를 부르는 문이 아니다. */
|
|
662
|
+
addressee: row.addressee,
|
|
663
|
+
doors: row.doors,
|
|
451
664
|
creator: user,
|
|
452
665
|
updater: user,
|
|
453
666
|
parentMessage: previous ? { id: previous.id } : undefined
|
|
454
667
|
});
|
|
455
668
|
saved.push(previous);
|
|
456
669
|
}
|
|
670
|
+
if (carried && session.visibility !== 'private') {
|
|
671
|
+
await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).update(session.id, { visibility: 'private', updater: user });
|
|
672
|
+
}
|
|
457
673
|
/* 활동은 마지막 발언 기준 한 번만 — 옮긴 줄마다 목록을 흔들 이유가 없다. */
|
|
458
674
|
const last = rows[rows.length - 1];
|
|
459
675
|
try {
|
|
@@ -566,6 +782,18 @@ tslib_1.__decorate([
|
|
|
566
782
|
tslib_1.__metadata("design:paramtypes", [String, Object, Boolean]),
|
|
567
783
|
tslib_1.__metadata("design:returntype", Promise)
|
|
568
784
|
], ChatSessionResolver.prototype, "hideAISession", null);
|
|
785
|
+
tslib_1.__decorate([
|
|
786
|
+
(0, type_graphql_1.Mutation)(() => Boolean, {
|
|
787
|
+
description: "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)."
|
|
788
|
+
}),
|
|
789
|
+
(0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation")'),
|
|
790
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
|
|
791
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('visibility')),
|
|
792
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
793
|
+
tslib_1.__metadata("design:type", Function),
|
|
794
|
+
tslib_1.__metadata("design:paramtypes", [String, String, Object]),
|
|
795
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
796
|
+
], ChatSessionResolver.prototype, "setSessionVisibility", null);
|
|
569
797
|
tslib_1.__decorate([
|
|
570
798
|
(0, type_graphql_1.Mutation)(() => Boolean, {
|
|
571
799
|
description: '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.'
|
|
@@ -591,7 +819,7 @@ tslib_1.__decorate([
|
|
|
591
819
|
], ChatSessionResolver.prototype, "markSessionRead", null);
|
|
592
820
|
tslib_1.__decorate([
|
|
593
821
|
(0, type_graphql_1.Query)(() => [auth_base_1.User], {
|
|
594
|
-
description: 'List users in the current domain for `@` mention popup.
|
|
822
|
+
description: '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().'
|
|
595
823
|
}),
|
|
596
824
|
(0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query")'),
|
|
597
825
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('query', { nullable: true, description: 'Substring to match against name/email (case-insensitive). Empty → all.' })),
|
|
@@ -650,12 +878,12 @@ tslib_1.__decorate([
|
|
|
650
878
|
tslib_1.__decorate([
|
|
651
879
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
652
880
|
(0, type_graphql_1.Mutation)(() => chat_session_js_1.ChatSession, {
|
|
653
|
-
description: 'Always create a new AI chat session anchored to a target (no idempotent reuse). For multi-session UX —
|
|
881
|
+
description: 'Always create a new AI chat session anchored to a target (no idempotent reuse). For multi-session UX — opening another tab.'
|
|
654
882
|
}),
|
|
655
883
|
(0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation")'),
|
|
656
884
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('anchorType')),
|
|
657
885
|
tslib_1.__param(1, (0, type_graphql_1.Arg)('anchorId')),
|
|
658
|
-
tslib_1.__param(2, (0, type_graphql_1.Arg)('name', { nullable: true, description: 'Optional name
|
|
886
|
+
tslib_1.__param(2, (0, type_graphql_1.Arg)('name', { nullable: true, description: 'Optional name. Defaults to a generated one, numbered within the anchor.' })),
|
|
659
887
|
tslib_1.__param(3, (0, type_graphql_1.Ctx)()),
|
|
660
888
|
tslib_1.__metadata("design:type", Function),
|
|
661
889
|
tslib_1.__metadata("design:paramtypes", [String, String, String, Object]),
|
|
@@ -674,6 +902,34 @@ tslib_1.__decorate([
|
|
|
674
902
|
tslib_1.__metadata("design:paramtypes", [String, String, Object]),
|
|
675
903
|
tslib_1.__metadata("design:returntype", Promise)
|
|
676
904
|
], ChatSessionResolver.prototype, "renameChatSession", null);
|
|
905
|
+
tslib_1.__decorate([
|
|
906
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
907
|
+
(0, type_graphql_1.Mutation)(() => Boolean, {
|
|
908
|
+
description: "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)."
|
|
909
|
+
}),
|
|
910
|
+
(0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation")'),
|
|
911
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
|
|
912
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('proposalKey')),
|
|
913
|
+
tslib_1.__param(2, (0, type_graphql_1.Arg)('outcome', () => graphql_scalars_1.GraphQLJSON)),
|
|
914
|
+
tslib_1.__param(3, (0, type_graphql_1.Ctx)()),
|
|
915
|
+
tslib_1.__metadata("design:type", Function),
|
|
916
|
+
tslib_1.__metadata("design:paramtypes", [String, String, Object, Object]),
|
|
917
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
918
|
+
], ChatSessionResolver.prototype, "reportProposalOutcome", null);
|
|
919
|
+
tslib_1.__decorate([
|
|
920
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
921
|
+
(0, type_graphql_1.Mutation)(() => String, {
|
|
922
|
+
nullable: true,
|
|
923
|
+
description: "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)."
|
|
924
|
+
}),
|
|
925
|
+
(0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation")'),
|
|
926
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
|
|
927
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('content')),
|
|
928
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
929
|
+
tslib_1.__metadata("design:type", Function),
|
|
930
|
+
tslib_1.__metadata("design:paramtypes", [String, String, Object]),
|
|
931
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
932
|
+
], ChatSessionResolver.prototype, "sayToRoom", null);
|
|
677
933
|
tslib_1.__decorate([
|
|
678
934
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
679
935
|
(0, type_graphql_1.Mutation)(() => Boolean, {
|
|
@@ -690,7 +946,7 @@ tslib_1.__decorate([
|
|
|
690
946
|
tslib_1.__decorate([
|
|
691
947
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
692
948
|
(0, type_graphql_1.Mutation)(() => Boolean, {
|
|
693
|
-
description:
|
|
949
|
+
description: "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)."
|
|
694
950
|
}),
|
|
695
951
|
(0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation")'),
|
|
696
952
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
|