@things-factory/ai-assistant 10.1.6

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.
Files changed (164) hide show
  1. package/client/components/board-ai-chat.test.ts +149 -0
  2. package/client/components/board-ai-chat.ts +3228 -0
  3. package/client/components/chat-defaults.ts +27 -0
  4. package/client/components/chat-echo-dedup.test.ts +230 -0
  5. package/client/components/chat-echo-dedup.ts +155 -0
  6. package/client/components/chat-input-builder.ts +69 -0
  7. package/client/components/markdown.test.ts +518 -0
  8. package/client/components/markdown.ts +508 -0
  9. package/client/components/mention-popup-helpers.ts +433 -0
  10. package/client/components/mention-popup.test.ts +588 -0
  11. package/client/components/mention-popup.ts +238 -0
  12. package/client/index.ts +14 -0
  13. package/client/tsconfig.json +13 -0
  14. package/client/utils/board-edit-patch.ts +374 -0
  15. package/dist-client/components/board-ai-chat.d.ts +423 -0
  16. package/dist-client/components/board-ai-chat.js +3034 -0
  17. package/dist-client/components/board-ai-chat.js.map +1 -0
  18. package/dist-client/components/board-ai-chat.test.d.ts +1 -0
  19. package/dist-client/components/board-ai-chat.test.js +138 -0
  20. package/dist-client/components/board-ai-chat.test.js.map +1 -0
  21. package/dist-client/components/chat-defaults.d.ts +8 -0
  22. package/dist-client/components/chat-defaults.js +22 -0
  23. package/dist-client/components/chat-defaults.js.map +1 -0
  24. package/dist-client/components/chat-echo-dedup.d.ts +54 -0
  25. package/dist-client/components/chat-echo-dedup.js +115 -0
  26. package/dist-client/components/chat-echo-dedup.js.map +1 -0
  27. package/dist-client/components/chat-echo-dedup.test.d.ts +1 -0
  28. package/dist-client/components/chat-echo-dedup.test.js +203 -0
  29. package/dist-client/components/chat-echo-dedup.test.js.map +1 -0
  30. package/dist-client/components/chat-input-builder.d.ts +55 -0
  31. package/dist-client/components/chat-input-builder.js +32 -0
  32. package/dist-client/components/chat-input-builder.js.map +1 -0
  33. package/dist-client/components/markdown.d.ts +60 -0
  34. package/dist-client/components/markdown.js +422 -0
  35. package/dist-client/components/markdown.js.map +1 -0
  36. package/dist-client/components/markdown.test.d.ts +1 -0
  37. package/dist-client/components/markdown.test.js +418 -0
  38. package/dist-client/components/markdown.test.js.map +1 -0
  39. package/dist-client/components/mention-popup-helpers.d.ts +165 -0
  40. package/dist-client/components/mention-popup-helpers.js +330 -0
  41. package/dist-client/components/mention-popup-helpers.js.map +1 -0
  42. package/dist-client/components/mention-popup.d.ts +35 -0
  43. package/dist-client/components/mention-popup.js +223 -0
  44. package/dist-client/components/mention-popup.js.map +1 -0
  45. package/dist-client/components/mention-popup.test.d.ts +1 -0
  46. package/dist-client/components/mention-popup.test.js +474 -0
  47. package/dist-client/components/mention-popup.test.js.map +1 -0
  48. package/dist-client/index.d.ts +14 -0
  49. package/dist-client/index.js +15 -0
  50. package/dist-client/index.js.map +1 -0
  51. package/dist-client/tsconfig.tsbuildinfo +1 -0
  52. package/dist-client/utils/board-edit-patch.d.ts +157 -0
  53. package/dist-client/utils/board-edit-patch.js +284 -0
  54. package/dist-client/utils/board-edit-patch.js.map +1 -0
  55. package/dist-server/index.d.ts +28 -0
  56. package/dist-server/index.js +32 -0
  57. package/dist-server/index.js.map +1 -0
  58. package/dist-server/service/chat-message/chat-message-broadcast.d.ts +13 -0
  59. package/dist-server/service/chat-message/chat-message-broadcast.js +13 -0
  60. package/dist-server/service/chat-message/chat-message-broadcast.js.map +1 -0
  61. package/dist-server/service/chat-message/chat-message-publish.d.ts +6 -0
  62. package/dist-server/service/chat-message/chat-message-publish.js +27 -0
  63. package/dist-server/service/chat-message/chat-message-publish.js.map +1 -0
  64. package/dist-server/service/chat-message/chat-message-subscription.d.ts +8 -0
  65. package/dist-server/service/chat-message/chat-message-subscription.js +57 -0
  66. package/dist-server/service/chat-message/chat-message-subscription.js.map +1 -0
  67. package/dist-server/service/chat-message/chat-message.d.ts +68 -0
  68. package/dist-server/service/chat-message/chat-message.js +172 -0
  69. package/dist-server/service/chat-message/chat-message.js.map +1 -0
  70. package/dist-server/service/chat-message/fold-history.d.ts +43 -0
  71. package/dist-server/service/chat-message/fold-history.js +33 -0
  72. package/dist-server/service/chat-message/fold-history.js.map +1 -0
  73. package/dist-server/service/chat-message/history-summary.d.ts +43 -0
  74. package/dist-server/service/chat-message/history-summary.js +77 -0
  75. package/dist-server/service/chat-message/history-summary.js.map +1 -0
  76. package/dist-server/service/chat-message/index.d.ts +5 -0
  77. package/dist-server/service/chat-message/index.js +12 -0
  78. package/dist-server/service/chat-message/index.js.map +1 -0
  79. package/dist-server/service/chat-message/llm-history.d.ts +46 -0
  80. package/dist-server/service/chat-message/llm-history.js +87 -0
  81. package/dist-server/service/chat-message/llm-history.js.map +1 -0
  82. package/dist-server/service/chat-session/chat-session.d.ts +60 -0
  83. package/dist-server/service/chat-session/chat-session.js +159 -0
  84. package/dist-server/service/chat-session/chat-session.js.map +1 -0
  85. package/dist-server/service/chat-session/index.d.ts +3 -0
  86. package/dist-server/service/chat-session/index.js +7 -0
  87. package/dist-server/service/chat-session/index.js.map +1 -0
  88. package/dist-server/service/chat-session/session-activity-broadcast.d.ts +30 -0
  89. package/dist-server/service/chat-session/session-activity-broadcast.js +34 -0
  90. package/dist-server/service/chat-session/session-activity-broadcast.js.map +1 -0
  91. package/dist-server/service/chat-session/session-activity-publish.d.ts +12 -0
  92. package/dist-server/service/chat-session/session-activity-publish.js +37 -0
  93. package/dist-server/service/chat-session/session-activity-publish.js.map +1 -0
  94. package/dist-server/service/chat-session/session-activity-subscription.d.ts +14 -0
  95. package/dist-server/service/chat-session/session-activity-subscription.js +87 -0
  96. package/dist-server/service/chat-session/session-activity-subscription.js.map +1 -0
  97. package/dist-server/service/chat-session/session-anchor.d.ts +26 -0
  98. package/dist-server/service/chat-session/session-anchor.js +100 -0
  99. package/dist-server/service/chat-session/session-anchor.js.map +1 -0
  100. package/dist-server/service/chat-session/session-inbox.d.ts +80 -0
  101. package/dist-server/service/chat-session/session-inbox.js +133 -0
  102. package/dist-server/service/chat-session/session-inbox.js.map +1 -0
  103. package/dist-server/service/chat-session-participant/chat-session-participant.d.ts +49 -0
  104. package/dist-server/service/chat-session-participant/chat-session-participant.js +141 -0
  105. package/dist-server/service/chat-session-participant/chat-session-participant.js.map +1 -0
  106. package/dist-server/service/chat-session-participant/index.d.ts +4 -0
  107. package/dist-server/service/chat-session-participant/index.js +10 -0
  108. package/dist-server/service/chat-session-participant/index.js.map +1 -0
  109. package/dist-server/service/chat-session-participant/invite-notification.d.ts +27 -0
  110. package/dist-server/service/chat-session-participant/invite-notification.js +30 -0
  111. package/dist-server/service/chat-session-participant/invite-notification.js.map +1 -0
  112. package/dist-server/service/chat-session-participant/presence.d.ts +4 -0
  113. package/dist-server/service/chat-session-participant/presence.js +22 -0
  114. package/dist-server/service/chat-session-participant/presence.js.map +1 -0
  115. package/dist-server/service/chat-session-resolver.d.ts +93 -0
  116. package/dist-server/service/chat-session-resolver.js +706 -0
  117. package/dist-server/service/chat-session-resolver.js.map +1 -0
  118. package/dist-server/service/index.d.ts +24 -0
  119. package/dist-server/service/index.js +39 -0
  120. package/dist-server/service/index.js.map +1 -0
  121. package/dist-server/service/subscribe-auth.d.ts +14 -0
  122. package/dist-server/service/subscribe-auth.js +33 -0
  123. package/dist-server/service/subscribe-auth.js.map +1 -0
  124. package/dist-server/service/types.d.ts +5 -0
  125. package/dist-server/service/types.js +12 -0
  126. package/dist-server/service/types.js.map +1 -0
  127. package/dist-server/tsconfig.tsbuildinfo +1 -0
  128. package/package.json +48 -0
  129. package/server/index.ts +28 -0
  130. package/server/service/chat-message/chat-message-broadcast.integration.test.ts +73 -0
  131. package/server/service/chat-message/chat-message-broadcast.test.ts +40 -0
  132. package/server/service/chat-message/chat-message-broadcast.ts +27 -0
  133. package/server/service/chat-message/chat-message-publish.ts +22 -0
  134. package/server/service/chat-message/chat-message-subscription.ts +45 -0
  135. package/server/service/chat-message/chat-message.ts +195 -0
  136. package/server/service/chat-message/fold-history.test.ts +98 -0
  137. package/server/service/chat-message/fold-history.ts +77 -0
  138. package/server/service/chat-message/history-summary.test.ts +127 -0
  139. package/server/service/chat-message/history-summary.ts +100 -0
  140. package/server/service/chat-message/index.ts +12 -0
  141. package/server/service/chat-message/llm-history.test.ts +194 -0
  142. package/server/service/chat-message/llm-history.ts +163 -0
  143. package/server/service/chat-session/chat-session.ts +193 -0
  144. package/server/service/chat-session/index.ts +5 -0
  145. package/server/service/chat-session/session-activity-broadcast.ts +57 -0
  146. package/server/service/chat-session/session-activity-publish.ts +44 -0
  147. package/server/service/chat-session/session-activity-subscription.ts +67 -0
  148. package/server/service/chat-session/session-anchor.ts +106 -0
  149. package/server/service/chat-session/session-inbox.test.ts +185 -0
  150. package/server/service/chat-session/session-inbox.ts +161 -0
  151. package/server/service/chat-session-participant/chat-session-participant.ts +135 -0
  152. package/server/service/chat-session-participant/index.ts +6 -0
  153. package/server/service/chat-session-participant/invite-notification.test.ts +30 -0
  154. package/server/service/chat-session-participant/invite-notification.ts +48 -0
  155. package/server/service/chat-session-participant/presence.test.ts +39 -0
  156. package/server/service/chat-session-participant/presence.ts +21 -0
  157. package/server/service/chat-session-resolver.ts +644 -0
  158. package/server/service/index.ts +37 -0
  159. package/server/service/session-anchor.test.ts +133 -0
  160. package/server/service/subscribe-auth.test.ts +57 -0
  161. package/server/service/subscribe-auth.ts +34 -0
  162. package/server/service/types.ts +15 -0
  163. package/things-factory.config.js +1 -0
  164. package/tsconfig.json +9 -0
@@ -0,0 +1,706 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatSessionResolver = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /**
6
+ * ChatSession lifecycle resolver — start/get/recordDirectPatch/revertPatch + 메시지·패치 페이징 query.
7
+ *
8
+ * 핵심: `recordDirectPatch` — 사용자가 모델러에서 직접 편집 시 클라이언트가 호출.
9
+ * 이게 PatchEntry(source:'user-direct') + system 메시지 자동 추가 → AI 가 모든 변경을 인지.
10
+ */
11
+ const type_graphql_1 = require("type-graphql");
12
+ const graphql_scalars_1 = require("graphql-scalars");
13
+ const auth_base_1 = require("@things-factory/auth-base");
14
+ const get_domain_users_js_1 = require("@things-factory/auth-base/dist-server/utils/get-domain-users.js");
15
+ const shell_1 = require("@things-factory/shell");
16
+ const typeorm_1 = require("typeorm");
17
+ const chat_session_js_1 = require("./chat-session/chat-session.js");
18
+ const session_anchor_js_1 = require("./chat-session/session-anchor.js");
19
+ const session_inbox_js_1 = require("./chat-session/session-inbox.js");
20
+ const session_activity_publish_js_1 = require("./chat-session/session-activity-publish.js");
21
+ const chat_message_js_1 = require("./chat-message/chat-message.js");
22
+ const chat_session_participant_js_1 = require("./chat-session-participant/chat-session-participant.js");
23
+ const chat_message_publish_js_1 = require("./chat-message/chat-message-publish.js");
24
+ let ChatSessionInboxEntry = class ChatSessionInboxEntry {
25
+ };
26
+ tslib_1.__decorate([
27
+ (0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true, description: 'Session id.' }),
28
+ tslib_1.__metadata("design:type", String)
29
+ ], ChatSessionInboxEntry.prototype, "id", void 0);
30
+ tslib_1.__decorate([
31
+ (0, type_graphql_1.Field)({ nullable: true, description: 'User-given session name (tab label).' }),
32
+ tslib_1.__metadata("design:type", String)
33
+ ], ChatSessionInboxEntry.prototype, "name", void 0);
34
+ tslib_1.__decorate([
35
+ (0, type_graphql_1.Field)({ nullable: true, description: "What the session is anchored to: 'board' | 'space' | 'instance' | 'none'." }),
36
+ tslib_1.__metadata("design:type", String)
37
+ ], ChatSessionInboxEntry.prototype, "anchorType", void 0);
38
+ tslib_1.__decorate([
39
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Id of the anchored target.' }),
40
+ tslib_1.__metadata("design:type", String)
41
+ ], ChatSessionInboxEntry.prototype, "anchorId", void 0);
42
+ tslib_1.__decorate([
43
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Connected board id (board-anchored sessions).' }),
44
+ tslib_1.__metadata("design:type", String)
45
+ ], ChatSessionInboxEntry.prototype, "boardId", void 0);
46
+ tslib_1.__decorate([
47
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Timestamp of the last message (list ordering / unread comparison).' }),
48
+ tslib_1.__metadata("design:type", Date)
49
+ ], ChatSessionInboxEntry.prototype, "lastMessageAt", void 0);
50
+ tslib_1.__decorate([
51
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Short preview of the last message.' }),
52
+ tslib_1.__metadata("design:type", String)
53
+ ], ChatSessionInboxEntry.prototype, "lastMessagePreview", void 0);
54
+ tslib_1.__decorate([
55
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Session creation timestamp.' }),
56
+ tslib_1.__metadata("design:type", Date)
57
+ ], ChatSessionInboxEntry.prototype, "createdAt", void 0);
58
+ tslib_1.__decorate([
59
+ (0, type_graphql_1.Field)({ description: 'Whether this viewer has unread activity in the session.' }),
60
+ tslib_1.__metadata("design:type", Boolean)
61
+ ], ChatSessionInboxEntry.prototype, "unread", void 0);
62
+ tslib_1.__decorate([
63
+ (0, type_graphql_1.Field)({ description: 'Whether this viewer is a participant of the session (non-participants get no unread state).' }),
64
+ tslib_1.__metadata("design:type", Boolean)
65
+ ], ChatSessionInboxEntry.prototype, "participant", void 0);
66
+ tslib_1.__decorate([
67
+ (0, type_graphql_1.Field)({ description: 'Whether this viewer created the session — only the creator may delete it.' }),
68
+ tslib_1.__metadata("design:type", Boolean)
69
+ ], ChatSessionInboxEntry.prototype, "mine", void 0);
70
+ tslib_1.__decorate([
71
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Whether this viewer hid the session from their own list (only returned when showHidden is on).' }),
72
+ tslib_1.__metadata("design:type", Boolean)
73
+ ], ChatSessionInboxEntry.prototype, "hidden", void 0);
74
+ ChatSessionInboxEntry = tslib_1.__decorate([
75
+ (0, type_graphql_1.ObjectType)({
76
+ description: 'Session list entry for the inbox — a session plus this viewer\'s unread state. Ordered by recent activity so a user can find where to go back to.'
77
+ })
78
+ ], ChatSessionInboxEntry);
79
+ let ChatSessionResolver = class ChatSessionResolver {
80
+ async chatSession(id, context) {
81
+ const { domain } = context.state;
82
+ return (await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({ id, domain: { id: domain.id } })) ?? null;
83
+ }
84
+ async chatSessionsByAnchor(anchorType, anchorId, context) {
85
+ const { domain } = context.state;
86
+ return await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).find({
87
+ where: (0, session_anchor_js_1.anchorWhere)(domain.id, anchorType, anchorId),
88
+ order: { createdAt: 'ASC' }
89
+ });
90
+ }
91
+ /**
92
+ * 받은편지함 — 앵커의 세션 목록 + 내 안 읽음 상태. 최근 활동순.
93
+ * 집계 쿼리를 쓰지 않는다: 세션의 비정규화된 lastMessageAt 과 내 참여자 lastReadAt 을 **값 비교**한다
94
+ * (5개 DB 드라이버 지원 때문에 group by/MAX 를 목록 경로에 두지 않는다).
95
+ */
96
+ async chatSessionInbox(anchorType, anchorId, context, showHidden, search, mineOnly, limit, offset) {
97
+ const filtered = await this._inboxFiltered(anchorType, anchorId, context, { showHidden, search, mineOnly });
98
+ const from = Math.max(0, offset ?? 0);
99
+ const size = Math.min(Math.max(1, limit ?? 50), 200);
100
+ return filtered.slice(from, from + size);
101
+ }
102
+ /**
103
+ * 필터를 통과한 **전체 개수** — "더 보기" 가 남았는지, 검색 결과가 몇 건인지.
104
+ *
105
+ * 목록과 같은 요청에 담아 가져가므로 왕복은 늘지 않는다. 개수를 모르면 사용자는 목록의 끝이
106
+ * 페이지의 끝인지 자료의 끝인지 구별할 수 없다.
107
+ */
108
+ async chatSessionInboxTotal(anchorType, anchorId, context, showHidden, search, mineOnly) {
109
+ return (await this._inboxFiltered(anchorType, anchorId, context, { showHidden, search, mineOnly })).length;
110
+ }
111
+ /** 필터 적용(페이지 전) — 목록·개수가 **같은 규칙**을 쓰도록 한 곳에 둔다(어긋나면 "더 보기" 가 거짓말이 된다). */
112
+ async _inboxFiltered(anchorType, anchorId, context, opts) {
113
+ const all = await this._inboxEntries(anchorType, anchorId, context);
114
+ let entries = opts.showHidden ? all : all.filter(e => !e.hidden);
115
+ if (opts.mineOnly)
116
+ entries = entries.filter(e => e.mine);
117
+ return (0, session_inbox_js_1.searchInbox)(entries, opts.search);
118
+ }
119
+ /**
120
+ * 내가 숨긴 대화 수 — 필터에 "몇 개가 접혀 있는지" 를 보여주기 위한 값.
121
+ *
122
+ * 숨긴 것이 몇 개인지 모르면 필터를 눌러 볼 이유가 생기지 않는다(숨긴 사실 자체를 잊는다).
123
+ * 목록 조회와 **같은 요청**에 담아 가져갈 수 있으므로 왕복은 늘지 않는다.
124
+ */
125
+ async hiddenSessionCount(anchorType, anchorId, context) {
126
+ const all = await this._inboxEntries(anchorType, anchorId, context);
127
+ return all.filter(e => e.hidden).length;
128
+ }
129
+ /** 목록 조립 — 숨김 표시까지 붙인 **전체**. 목록·개수 두 진입점이 같은 규칙을 쓰도록 한 곳에 둔다. */
130
+ async _inboxEntries(anchorType, anchorId, context) {
131
+ const { domain, user } = context.state;
132
+ /* 조회 상한 — 한 앵커의 대화가 아무리 늘어도 한 번에 이만큼만 훑는다. 최근 활동순으로 자른다
133
+ * (오래된 대화가 잘리는 것이 최근 대화가 잘리는 것보다 낫다). 정렬·검색·페이지는 순수 로직이 한다. */
134
+ const sessions = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).find({
135
+ where: (0, session_anchor_js_1.anchorWhere)(domain.id, anchorType, anchorId),
136
+ order: { lastMessageAt: 'DESC' },
137
+ take: session_inbox_js_1.INBOX_SCAN_CAP
138
+ });
139
+ if (sessions.length === 0)
140
+ return [];
141
+ const rows = await (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant).find({
142
+ where: { domain: { id: domain.id }, user: { id: user.id }, session: { id: (0, typeorm_1.In)(sessions.map(s => s.id)) } }
143
+ });
144
+ /* 'viewer' 는 대화에 낀 사람이 아니다 — 숨김을 기록하려고 만든 행이므로 읽음·안 읽음 판정에서 뺀다.
145
+ * (참여자가 아닌 사람에게 남의 협의 배지를 띄우지 않는다.) */
146
+ const participations = rows.filter(r => r.role !== 'viewer');
147
+ const hiddenAt = new Map(rows.map(r => [r.sessionId, r.hiddenAt]));
148
+ /* 내가 만든 대화인지 표시 — 삭제 버튼을 보일지 결정하는 UI 힌트(권한은 서버가 다시 판정한다). */
149
+ const createdByMe = new Set(sessions.filter(s => s.creatorId === user?.id).map(s => s.id));
150
+ const entries = (0, session_inbox_js_1.buildInbox)(sessions, participations).map(entry => ({
151
+ ...entry,
152
+ mine: createdByMe.has(entry.id)
153
+ }));
154
+ /* showHidden=true 로 불러 **전체**를 얻는다 — 숨김 여부 판정을 두 곳에 복제하지 않기 위함. */
155
+ return (0, session_inbox_js_1.applyHidden)(entries, hiddenAt, true);
156
+ }
157
+ /**
158
+ * 세션 삭제 — **만든 사람만.**
159
+ *
160
+ * 협의는 여럿의 기록이고 삭제는 화면에서 되돌릴 수 없다. 그래서 권한을 좁힌다(이름 변경은 되돌릴 수
161
+ * 있어서 누구나 할 수 있는 것과 대비). 권한이 없는 사람에게는 `hideAISession`(내 목록에서만 숨김)이
162
+ * 있다 — 남의 기록을 지우지 않고 자기 목록을 정리하는 길.
163
+ *
164
+ * 소프트 삭제(deletedAt)다 — 메시지·패치는 세션을 통해서만 도달하므로 함께 사라지고, 잘못 지운 경우
165
+ * 데이터로는 남아 있다. 다른 참여자 목록에서도 사라져야 하므로 meta 활동으로 방송한다.
166
+ */
167
+ async deleteAISession(sessionId, context) {
168
+ const { domain, user } = context.state;
169
+ const repo = (0, shell_1.getRepository)(chat_session_js_1.ChatSession);
170
+ const session = await repo.findOneBy({ id: sessionId, domain: { id: domain.id } });
171
+ if (!session)
172
+ return false;
173
+ if (!user?.id || session.creatorId !== user.id) {
174
+ /* 조용한 무동작이 아니라 명시 실패 — 지워진 줄 알고 넘어가면 안 된다. */
175
+ throw new Error('Only the user who created this session may delete it. Hide it from your own list instead.');
176
+ }
177
+ await repo.softDelete(sessionId);
178
+ (0, session_activity_publish_js_1.publishSessionActivity)({
179
+ domainId: domain.id,
180
+ sessionId,
181
+ kind: 'meta',
182
+ anchorType: session.anchorType,
183
+ anchorId: session.anchorId,
184
+ actorId: user?.id
185
+ });
186
+ return true;
187
+ }
188
+ /**
189
+ * 내 목록에서 숨기기·되돌리기 — **나에게만** 적용된다(대화·다른 참여자 목록은 그대로).
190
+ *
191
+ * 참여자가 아니어도 숨길 수 있어야 한다 — 목록에는 같은 공간의 남의 협의도 보이고, 그것을 정리하는
192
+ * 것은 남에게 아무 영향이 없다. 그 경우 'viewer' 역할로 기록만 남긴다(참여자 명부·배지에는 들지 않는다).
193
+ */
194
+ async hideAISession(sessionId, context, hidden) {
195
+ const { domain, user } = context.state;
196
+ if (!user?.id)
197
+ return false;
198
+ const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({ id: sessionId, domain: { id: domain.id } });
199
+ if (!session)
200
+ return false;
201
+ const repo = (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant);
202
+ const existing = await repo.findOne({
203
+ where: { domain: { id: domain.id }, session: { id: sessionId }, user: { id: user.id } }
204
+ });
205
+ const hiddenAt = hidden === false ? null : new Date();
206
+ if (existing) {
207
+ await repo.update(existing.id, { hiddenAt, updater: user });
208
+ }
209
+ else {
210
+ if (hidden === false)
211
+ return true; // 숨긴 적이 없으면 되돌릴 것도 없다
212
+ await repo.save({
213
+ domain: { id: domain.id },
214
+ session: { id: sessionId },
215
+ user: { id: user.id },
216
+ role: 'viewer', // 대화에 낀 것이 아니라 숨김만 기록한다
217
+ hiddenAt,
218
+ creator: user,
219
+ updater: user
220
+ });
221
+ }
222
+ return true;
223
+ }
224
+ /**
225
+ * 세션 이름 변경 — **참여자 누구나** 할 수 있다.
226
+ *
227
+ * 왜 소유자 전용이 아닌가: 이름은 대화의 주제표이고 협의는 여럿이 한다. 논의가 흘러 주제가 달라졌는데
228
+ * 만든 사람만 고칠 수 있으면 그 사람이 없을 때 목록이 계속 어긋난다. 되돌릴 수 있는 변경이고 대화
229
+ * 내용에 영향이 없으므로 권한을 좁힐 이유가 없다(되돌릴 수 없는 것만 좁힌다).
230
+ *
231
+ * 변경은 **meta 활동**으로 방송한다 — 모든 참여자 목록에 즉시 반영되지만 안 읽음 배지는 올리지 않는다
232
+ * (이름 변경을 "새 소식" 으로 알리면 소음이다).
233
+ */
234
+ async renameAISession(sessionId, name, context) {
235
+ const { domain, user } = context.state;
236
+ const trimmed = (name ?? '').trim().slice(0, 200);
237
+ if (!trimmed)
238
+ return false; // 빈 이름으로 지우지 않는다 — 지우려면 별도 의도가 필요하다
239
+ const participant = await (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant).findOne({
240
+ where: { domain: { id: domain.id }, session: { id: sessionId }, user: { id: user.id } }
241
+ });
242
+ if (!participant)
243
+ return false; // 참여자가 아니면 남의 대화 제목을 바꿀 수 없다
244
+ const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({ id: sessionId, domain: { id: domain.id } });
245
+ if (!session)
246
+ return false;
247
+ await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).update(sessionId, { name: trimmed, updater: user });
248
+ (0, session_activity_publish_js_1.publishSessionActivity)({
249
+ domainId: domain.id,
250
+ sessionId,
251
+ kind: 'meta',
252
+ anchorType: session.anchorType,
253
+ anchorId: session.anchorId,
254
+ actorId: user?.id
255
+ });
256
+ return true;
257
+ }
258
+ /**
259
+ * 읽은 지점 갱신 — 이 세션을 여기까지 읽었다. 멱등(여러 번 호출해도 최신 시각으로만 이동).
260
+ * 접속 표시(lastSeenAt)와 분리한다 — 창을 열어 두고 화면을 안 볼 수 있다.
261
+ */
262
+ async markSessionRead(sessionId, context) {
263
+ const { domain, user } = context.state;
264
+ const repo = (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant);
265
+ const mine = await repo.findOne({
266
+ where: { domain: { id: domain.id }, session: { id: sessionId }, user: { id: user.id } }
267
+ });
268
+ /* 참여자가 아니면 읽음 상태를 만들지 않는다 — 참여하지 않은 대화에 내 읽음 지점을 남기지 않는다. */
269
+ if (!mine)
270
+ return false;
271
+ await repo.update(mine.id, { lastReadAt: new Date(), updater: user });
272
+ return true;
273
+ }
274
+ async domainUsersForMention(query, limit, context) {
275
+ const { domain } = context.state;
276
+ const qb = (0, get_domain_users_js_1.buildDomainUsersQueryBuilder)(domain.id, 'USER');
277
+ if (query?.trim()) {
278
+ const q = `%${query.trim().toLowerCase()}%`;
279
+ qb.andWhere('(LOWER(USER.name) LIKE :q OR LOWER(USER.email) LIKE :q)', { q });
280
+ }
281
+ qb.orderBy('USER.name', 'ASC').limit(limit);
282
+ return await qb.getMany();
283
+ }
284
+ async chatSessionParticipants(sessionId, context) {
285
+ const { domain } = context.state;
286
+ const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({
287
+ id: sessionId,
288
+ domain: { id: domain.id }
289
+ });
290
+ if (!session)
291
+ return [];
292
+ return await (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant).find({
293
+ where: { session: { id: sessionId }, domain: { id: domain.id } },
294
+ order: { createdAt: 'ASC' }
295
+ });
296
+ }
297
+ async touchPresence(sessionId, context) {
298
+ const { domain, user } = context.state;
299
+ const repo = (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant);
300
+ const part = await repo.findOne({
301
+ where: { session: { id: sessionId }, user: { id: user.id }, domain: { id: domain.id } }
302
+ });
303
+ if (!part)
304
+ return false; // 참여자가 아니면 heartbeat 무시 (초대 전)
305
+ await repo.update(part.id, { lastSeenAt: new Date(), updater: user });
306
+ return true;
307
+ }
308
+ async chatMessages(sessionId, limit, offset, context) {
309
+ const { domain } = context.state;
310
+ const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession).findOneBy({
311
+ id: sessionId,
312
+ domain: { id: domain.id }
313
+ });
314
+ if (!session)
315
+ return [];
316
+ return await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage).find({
317
+ where: { session: { id: sessionId } },
318
+ // creator: 그룹챗 발신자 표시(name) + 자기 여부 판정(email). 내부 관리키(id)에 의존하지 않는다.
319
+ relations: { creator: true },
320
+ order: { createdAt: 'ASC' },
321
+ take: limit,
322
+ skip: offset
323
+ });
324
+ }
325
+ async startAISession(anchorType, anchorId, context) {
326
+ const { domain, user, tx } = context.state;
327
+ const repo = (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx);
328
+ const existing = await repo.findOneBy((0, session_anchor_js_1.anchorWhere)(domain.id, anchorType, anchorId));
329
+ if (existing)
330
+ return existing;
331
+ const session = await repo.save({
332
+ domain,
333
+ ...(0, session_anchor_js_1.anchorColumns)(anchorType, anchorId),
334
+ creator: user,
335
+ updater: user
336
+ });
337
+ // creator 를 owner participant 로 자동 등록 — 다자간 채팅 기반.
338
+ await (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant, tx).save({
339
+ domain,
340
+ session: { id: session.id },
341
+ user,
342
+ role: 'owner',
343
+ creator: user,
344
+ updater: user
345
+ });
346
+ return session;
347
+ }
348
+ async createAISession(anchorType, anchorId, name, context) {
349
+ const { domain, user, tx } = context.state;
350
+ const repo = (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx);
351
+ // 이름 미지정 시 자동 생성 — **같은 앵커**의 기존 세션 수 + 1.
352
+ let finalName = name?.trim();
353
+ if (!finalName) {
354
+ const count = await repo.count({ where: (0, session_anchor_js_1.anchorWhere)(domain.id, anchorType, anchorId) });
355
+ finalName = `세션 ${count + 1}`;
356
+ }
357
+ const session = await repo.save({
358
+ domain,
359
+ ...(0, session_anchor_js_1.anchorColumns)(anchorType, anchorId),
360
+ creator: user,
361
+ updater: user,
362
+ name: finalName
363
+ });
364
+ // creator 를 owner participant 로 자동 등록.
365
+ await (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant, tx).save({
366
+ domain,
367
+ session: { id: session.id },
368
+ user,
369
+ role: 'owner',
370
+ creator: user,
371
+ updater: user
372
+ });
373
+ return session;
374
+ }
375
+ async renameChatSession(sessionId, name, context) {
376
+ const { domain, user, tx } = context.state;
377
+ const repo = (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx);
378
+ const session = await repo.findOneBy({ id: sessionId, domain: { id: domain.id } });
379
+ if (!session)
380
+ throw new Error(`ChatSession ${sessionId} not found`);
381
+ await repo.update(sessionId, { name: name.trim() || null, updater: user });
382
+ return true;
383
+ }
384
+ async appendSessionNote(sessionId, content, context) {
385
+ const { domain, user, tx } = context.state;
386
+ const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).findOneBy({ id: sessionId, domain: { id: domain.id } });
387
+ if (!session)
388
+ throw new Error(`ChatSession ${sessionId} not found`);
389
+ /* 프롬프트가 한 기록으로 폭증하지 않도록 자른다 — 맥락 전달이 목적이고 전문 보존이 아니다. */
390
+ const body = (content ?? '').trim().slice(0, 4000);
391
+ if (!body)
392
+ return false;
393
+ const previousLast = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).findOne({
394
+ where: { session: { id: session.id } },
395
+ order: { createdAt: 'DESC' }
396
+ });
397
+ const sysMsg = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).save({
398
+ session: { id: session.id },
399
+ role: 'system',
400
+ content: body,
401
+ creator: user,
402
+ updater: user,
403
+ parentMessage: previousLast ? { id: previousLast.id } : undefined
404
+ });
405
+ /* 활동 갱신 + 방송 — 다른 참여자 목록·안 읽음과 열려 있는 화면의 transcript 일관성. best-effort. */
406
+ try {
407
+ await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).update(session.id, (0, session_inbox_js_1.activityPatch)(body));
408
+ }
409
+ catch {
410
+ /* 기록 자체를 막지 않는다 */
411
+ }
412
+ (0, session_activity_publish_js_1.publishSessionActivity)({
413
+ domainId: domain.id,
414
+ sessionId: session.id,
415
+ kind: 'message',
416
+ anchorType: session.anchorType,
417
+ anchorId: session.anchorId,
418
+ preview: body,
419
+ actorId: user?.id
420
+ });
421
+ (0, chat_message_publish_js_1.publishChatMessage)({ domainId: domain.id, sessionId: session.id, message: sysMsg });
422
+ return true;
423
+ }
424
+ async appendSessionTurns(sessionId, turns, context) {
425
+ const { domain, user, tx } = context.state;
426
+ const session = await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).findOneBy({ id: sessionId, domain: { id: domain.id } });
427
+ if (!session)
428
+ throw new Error(`ChatSession ${sessionId} not found`);
429
+ /* 옮겨온 대화는 **그 대화의 발언 그대로** 들어간다 — 한 덩어리 기록으로 뭉치면 사람이 읽을 수 없고
430
+ * (화면 하나를 잡아먹는 이탤릭 덩어리), 마크다운도 죽는다. 대신 개수·길이는 제한한다: 맥락 전달이
431
+ * 목적이고 전문 보존이 아니다. */
432
+ const rows = (Array.isArray(turns) ? turns : [])
433
+ .map(t => ({
434
+ role: t?.role === 'ai' || t?.role === 'assistant' ? 'assistant' : t?.role === 'user' ? 'user' : 'system',
435
+ content: (t?.content ?? '').trim().slice(0, 4000)
436
+ }))
437
+ .filter(t => t.content)
438
+ .slice(-40);
439
+ if (!rows.length)
440
+ return false;
441
+ let previous = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).findOne({
442
+ where: { session: { id: session.id } },
443
+ order: { createdAt: 'DESC' }
444
+ });
445
+ const saved = [];
446
+ for (const row of rows) {
447
+ previous = await (0, shell_1.getRepository)(chat_message_js_1.ChatMessage, tx).save({
448
+ session: { id: session.id },
449
+ role: row.role,
450
+ content: row.content,
451
+ creator: user,
452
+ updater: user,
453
+ parentMessage: previous ? { id: previous.id } : undefined
454
+ });
455
+ saved.push(previous);
456
+ }
457
+ /* 활동은 마지막 발언 기준 한 번만 — 옮긴 줄마다 목록을 흔들 이유가 없다. */
458
+ const last = rows[rows.length - 1];
459
+ try {
460
+ await (0, shell_1.getRepository)(chat_session_js_1.ChatSession, tx).update(session.id, (0, session_inbox_js_1.activityPatch)(last.content));
461
+ }
462
+ catch {
463
+ /* best-effort — 옮기기 자체를 막지 않는다 */
464
+ }
465
+ (0, session_activity_publish_js_1.publishSessionActivity)({
466
+ domainId: domain.id,
467
+ sessionId: session.id,
468
+ kind: 'message',
469
+ anchorType: session.anchorType,
470
+ anchorId: session.anchorId,
471
+ preview: last.content,
472
+ actorId: user?.id
473
+ });
474
+ for (const message of saved) {
475
+ (0, chat_message_publish_js_1.publishChatMessage)({ domainId: domain.id, sessionId: session.id, message });
476
+ }
477
+ return true;
478
+ }
479
+ };
480
+ exports.ChatSessionResolver = ChatSessionResolver;
481
+ tslib_1.__decorate([
482
+ (0, type_graphql_1.Query)(() => chat_session_js_1.ChatSession, { nullable: true, description: 'Get AI chat session by id.' }),
483
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query", legacy: "board-ai")'),
484
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
485
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
486
+ tslib_1.__metadata("design:type", Function),
487
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
488
+ tslib_1.__metadata("design:returntype", Promise)
489
+ ], ChatSessionResolver.prototype, "chatSession", null);
490
+ tslib_1.__decorate([
491
+ (0, type_graphql_1.Query)(() => [chat_session_js_1.ChatSession], {
492
+ description: 'List AI chat sessions anchored to a target (oldest first). Anchor decides the nature and the history boundary of the conversation: board = authoring, space = the site and the twins running there. Board anchor also matches legacy rows that only have boardId.'
493
+ }),
494
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query", legacy: "board-ai")'),
495
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('anchorType')),
496
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('anchorId')),
497
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
498
+ tslib_1.__metadata("design:type", Function),
499
+ tslib_1.__metadata("design:paramtypes", [String, String, Object]),
500
+ tslib_1.__metadata("design:returntype", Promise)
501
+ ], ChatSessionResolver.prototype, "chatSessionsByAnchor", null);
502
+ tslib_1.__decorate([
503
+ (0, type_graphql_1.Query)(() => [ChatSessionInboxEntry], {
504
+ description: "List sessions anchored to a target with this viewer's unread state, most recent activity first. Supports free-text search over name and last preview, a mine-only filter, hidden inclusion, and paging. Uses the denormalized last-activity timestamp compared against the viewer's read point — no per-session aggregation."
505
+ }),
506
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query", legacy: "board-ai")'),
507
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('anchorType')),
508
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('anchorId')),
509
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
510
+ tslib_1.__param(3, (0, type_graphql_1.Arg)('showHidden', { nullable: true })),
511
+ tslib_1.__param(4, (0, type_graphql_1.Arg)('search', { nullable: true })),
512
+ tslib_1.__param(5, (0, type_graphql_1.Arg)('mineOnly', { nullable: true })),
513
+ tslib_1.__param(6, (0, type_graphql_1.Arg)('limit', () => type_graphql_1.Int, { nullable: true })),
514
+ tslib_1.__param(7, (0, type_graphql_1.Arg)('offset', () => type_graphql_1.Int, { nullable: true })),
515
+ tslib_1.__metadata("design:type", Function),
516
+ tslib_1.__metadata("design:paramtypes", [String, String, Object, Boolean, String, Boolean, Number, Number]),
517
+ tslib_1.__metadata("design:returntype", Promise)
518
+ ], ChatSessionResolver.prototype, "chatSessionInbox", null);
519
+ tslib_1.__decorate([
520
+ (0, type_graphql_1.Query)(() => type_graphql_1.Int, {
521
+ description: 'Total number of sessions matching the same filters as chatSessionInbox (before paging). Request it alongside the list so the UI can tell "end of page" from "end of data".'
522
+ }),
523
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query", legacy: "board-ai")'),
524
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('anchorType')),
525
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('anchorId')),
526
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
527
+ tslib_1.__param(3, (0, type_graphql_1.Arg)('showHidden', { nullable: true })),
528
+ tslib_1.__param(4, (0, type_graphql_1.Arg)('search', { nullable: true })),
529
+ tslib_1.__param(5, (0, type_graphql_1.Arg)('mineOnly', { nullable: true })),
530
+ tslib_1.__metadata("design:type", Function),
531
+ tslib_1.__metadata("design:paramtypes", [String, String, Object, Boolean, String, Boolean]),
532
+ tslib_1.__metadata("design:returntype", Promise)
533
+ ], ChatSessionResolver.prototype, "chatSessionInboxTotal", null);
534
+ tslib_1.__decorate([
535
+ (0, type_graphql_1.Query)(() => type_graphql_1.Int, {
536
+ description: "Number of sessions on this anchor that the caller has hidden and that have had no activity since. Meant to be requested alongside chatSessionInbox in the same operation so the filter can say how many are folded away."
537
+ }),
538
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query", legacy: "board-ai")'),
539
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('anchorType')),
540
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('anchorId')),
541
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
542
+ tslib_1.__metadata("design:type", Function),
543
+ tslib_1.__metadata("design:paramtypes", [String, String, Object]),
544
+ tslib_1.__metadata("design:returntype", Promise)
545
+ ], ChatSessionResolver.prototype, "hiddenSessionCount", null);
546
+ tslib_1.__decorate([
547
+ (0, type_graphql_1.Mutation)(() => Boolean, {
548
+ description: 'Delete a chat session — creator only, since a shared deliberation cannot be un-deleted from the UI. Participants who are not the creator can hide it from their own list instead (hideAISession). Soft delete; broadcast as meta activity so every list drops it.'
549
+ }),
550
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation", legacy: "board-ai")'),
551
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
552
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
553
+ tslib_1.__metadata("design:type", Function),
554
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
555
+ tslib_1.__metadata("design:returntype", Promise)
556
+ ], ChatSessionResolver.prototype, "deleteAISession", null);
557
+ tslib_1.__decorate([
558
+ (0, type_graphql_1.Mutation)(() => Boolean, {
559
+ description: 'Hide (or unhide) a session from the calling user\'s own list. Per-user and reversible — the session and other participants are unaffected. Activity newer than the hide makes it reappear; the inbox filter (showHidden) reveals hidden ones.'
560
+ }),
561
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation", legacy: "board-ai")'),
562
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
563
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
564
+ tslib_1.__param(2, (0, type_graphql_1.Arg)('hidden', { nullable: true })),
565
+ tslib_1.__metadata("design:type", Function),
566
+ tslib_1.__metadata("design:paramtypes", [String, Object, Boolean]),
567
+ tslib_1.__metadata("design:returntype", Promise)
568
+ ], ChatSessionResolver.prototype, "hideAISession", null);
569
+ tslib_1.__decorate([
570
+ (0, type_graphql_1.Mutation)(() => Boolean, {
571
+ 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.'
572
+ }),
573
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation", legacy: "board-ai")'),
574
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
575
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('name')),
576
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
577
+ tslib_1.__metadata("design:type", Function),
578
+ tslib_1.__metadata("design:paramtypes", [String, String, Object]),
579
+ tslib_1.__metadata("design:returntype", Promise)
580
+ ], ChatSessionResolver.prototype, "renameAISession", null);
581
+ tslib_1.__decorate([
582
+ (0, type_graphql_1.Mutation)(() => Boolean, {
583
+ description: "Mark a session as read up to now for the current user. Idempotent. Distinct from presence (lastSeenAt) — a window can be open without being read."
584
+ }),
585
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation", legacy: "board-ai")'),
586
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
587
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
588
+ tslib_1.__metadata("design:type", Function),
589
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
590
+ tslib_1.__metadata("design:returntype", Promise)
591
+ ], ChatSessionResolver.prototype, "markSessionRead", null);
592
+ tslib_1.__decorate([
593
+ (0, type_graphql_1.Query)(() => [auth_base_1.User], {
594
+ description: 'List users in the current domain for `@` mention popup. board-ai 권한이면 누구나 멘션용 검색 가능 (관리자 전용 users() 와 별도).'
595
+ }),
596
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query", legacy: "board-ai")'),
597
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('query', { nullable: true, description: 'Substring to match against name/email (case-insensitive). Empty → all.' })),
598
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('limit', () => type_graphql_1.Int, { nullable: true, defaultValue: 50 })),
599
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
600
+ tslib_1.__metadata("design:type", Function),
601
+ tslib_1.__metadata("design:paramtypes", [String, Number, Object]),
602
+ tslib_1.__metadata("design:returntype", Promise)
603
+ ], ChatSessionResolver.prototype, "domainUsersForMention", null);
604
+ tslib_1.__decorate([
605
+ (0, type_graphql_1.Query)(() => [chat_session_participant_js_1.ChatSessionParticipant], {
606
+ description: 'List participants of a ChatSession (members / owner).'
607
+ }),
608
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query", legacy: "board-ai")'),
609
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
610
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
611
+ tslib_1.__metadata("design:type", Function),
612
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
613
+ tslib_1.__metadata("design:returntype", Promise)
614
+ ], ChatSessionResolver.prototype, "chatSessionParticipants", null);
615
+ tslib_1.__decorate([
616
+ (0, type_graphql_1.Mutation)(() => Boolean, {
617
+ description: 'Presence heartbeat — bump current user\'s lastSeenAt in the session (online indicator).'
618
+ }),
619
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation", legacy: "board-ai")'),
620
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
621
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
622
+ tslib_1.__metadata("design:type", Function),
623
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
624
+ tslib_1.__metadata("design:returntype", Promise)
625
+ ], ChatSessionResolver.prototype, "touchPresence", null);
626
+ tslib_1.__decorate([
627
+ (0, type_graphql_1.Query)(() => [chat_message_js_1.ChatMessage], { description: 'List chat messages of a session, oldest first.' }),
628
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query", legacy: "board-ai")'),
629
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
630
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('limit', () => type_graphql_1.Int, { nullable: true, defaultValue: 100 })),
631
+ tslib_1.__param(2, (0, type_graphql_1.Arg)('offset', () => type_graphql_1.Int, { nullable: true, defaultValue: 0 })),
632
+ tslib_1.__param(3, (0, type_graphql_1.Ctx)()),
633
+ tslib_1.__metadata("design:type", Function),
634
+ tslib_1.__metadata("design:paramtypes", [String, Number, Number, Object]),
635
+ tslib_1.__metadata("design:returntype", Promise)
636
+ ], ChatSessionResolver.prototype, "chatMessages", null);
637
+ tslib_1.__decorate([
638
+ (0, type_graphql_1.Directive)('@transaction'),
639
+ (0, type_graphql_1.Mutation)(() => chat_session_js_1.ChatSession, {
640
+ description: 'Start (or get existing) AI chat session anchored to a target. Idempotent — returns first existing or creates one. Use anchorType board for board authoring, space for a site (its co-located twins).'
641
+ }),
642
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation", legacy: "board-ai")'),
643
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('anchorType')),
644
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('anchorId')),
645
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
646
+ tslib_1.__metadata("design:type", Function),
647
+ tslib_1.__metadata("design:paramtypes", [String, String, Object]),
648
+ tslib_1.__metadata("design:returntype", Promise)
649
+ ], ChatSessionResolver.prototype, "startAISession", null);
650
+ tslib_1.__decorate([
651
+ (0, type_graphql_1.Directive)('@transaction'),
652
+ (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 — 새 탭 열기.'
654
+ }),
655
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation", legacy: "board-ai")'),
656
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('anchorType')),
657
+ 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 (defaults to auto-generated `세션 N`).' })),
659
+ tslib_1.__param(3, (0, type_graphql_1.Ctx)()),
660
+ tslib_1.__metadata("design:type", Function),
661
+ tslib_1.__metadata("design:paramtypes", [String, String, String, Object]),
662
+ tslib_1.__metadata("design:returntype", Promise)
663
+ ], ChatSessionResolver.prototype, "createAISession", null);
664
+ tslib_1.__decorate([
665
+ (0, type_graphql_1.Directive)('@transaction'),
666
+ (0, type_graphql_1.Mutation)(() => Boolean, {
667
+ description: 'Rename a ChatSession (tab label).'
668
+ }),
669
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation", legacy: "board-ai")'),
670
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
671
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('name')),
672
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
673
+ tslib_1.__metadata("design:type", Function),
674
+ tslib_1.__metadata("design:paramtypes", [String, String, Object]),
675
+ tslib_1.__metadata("design:returntype", Promise)
676
+ ], ChatSessionResolver.prototype, "renameChatSession", null);
677
+ tslib_1.__decorate([
678
+ (0, type_graphql_1.Directive)('@transaction'),
679
+ (0, type_graphql_1.Mutation)(() => Boolean, {
680
+ description: 'Append a system note to a session — context that did not come from a participant typing (e.g. a conversation carried over from another surface, an external state change). The AI sees it as part of the shared history.'
681
+ }),
682
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation", legacy: "board-ai")'),
683
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
684
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('content')),
685
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
686
+ tslib_1.__metadata("design:type", Function),
687
+ tslib_1.__metadata("design:paramtypes", [String, String, Object]),
688
+ tslib_1.__metadata("design:returntype", Promise)
689
+ ], ChatSessionResolver.prototype, "appendSessionNote", null);
690
+ tslib_1.__decorate([
691
+ (0, type_graphql_1.Directive)('@transaction'),
692
+ (0, type_graphql_1.Mutation)(() => Boolean, {
693
+ description: 'Carry a conversation from another surface into this session as its own turns (user / assistant), preserving order. Use when a lightweight exchange is promoted into a persistent discussion — the participants should read it as the conversation continuing, not as a machine dump.'
694
+ }),
695
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "mutation", legacy: "board-ai")'),
696
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('sessionId')),
697
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('turns', () => graphql_scalars_1.GraphQLJSON)),
698
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
699
+ tslib_1.__metadata("design:type", Function),
700
+ tslib_1.__metadata("design:paramtypes", [String, Array, Object]),
701
+ tslib_1.__metadata("design:returntype", Promise)
702
+ ], ChatSessionResolver.prototype, "appendSessionTurns", null);
703
+ exports.ChatSessionResolver = ChatSessionResolver = tslib_1.__decorate([
704
+ (0, type_graphql_1.Resolver)()
705
+ ], ChatSessionResolver);
706
+ //# sourceMappingURL=chat-session-resolver.js.map