@things-factory/ai-assistant 10.1.26 → 10.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/client/components/assistant-chat.ts +653 -59
  2. package/client/components/assistant-mode.test.ts +86 -55
  3. package/client/components/assistant-mode.ts +124 -82
  4. package/client/components/chat-echo-dedup.test.ts +23 -0
  5. package/client/components/chat-echo-dedup.ts +29 -3
  6. package/client/components/chat-input-builder.test.ts +20 -20
  7. package/client/components/chat-input-builder.ts +16 -14
  8. package/client/components/chat-proposal-survival.test.ts +73 -0
  9. package/client/components/mention-popup.ts +31 -8
  10. package/client/components/panel-aria.test.ts +34 -0
  11. package/client/components/proposal-outcome-line.ts +33 -0
  12. package/client/utils/assistant-session-controller.test.ts +75 -0
  13. package/client/utils/assistant-session-controller.ts +23 -0
  14. package/client/utils/assistant-session-transport.ts +11 -3
  15. package/dist-client/components/assistant-chat.d.ts +128 -13
  16. package/dist-client/components/assistant-chat.js +613 -67
  17. package/dist-client/components/assistant-chat.js.map +1 -1
  18. package/dist-client/components/assistant-mode.d.ts +80 -68
  19. package/dist-client/components/assistant-mode.js +63 -19
  20. package/dist-client/components/assistant-mode.js.map +1 -1
  21. package/dist-client/components/assistant-mode.test.js +74 -53
  22. package/dist-client/components/assistant-mode.test.js.map +1 -1
  23. package/dist-client/components/chat-echo-dedup.d.ts +2 -0
  24. package/dist-client/components/chat-echo-dedup.js +27 -4
  25. package/dist-client/components/chat-echo-dedup.js.map +1 -1
  26. package/dist-client/components/chat-echo-dedup.test.js +20 -0
  27. package/dist-client/components/chat-echo-dedup.test.js.map +1 -1
  28. package/dist-client/components/chat-input-builder.d.ts +12 -7
  29. package/dist-client/components/chat-input-builder.js +8 -10
  30. package/dist-client/components/chat-input-builder.js.map +1 -1
  31. package/dist-client/components/chat-input-builder.test.js +17 -18
  32. package/dist-client/components/chat-input-builder.test.js.map +1 -1
  33. package/dist-client/components/chat-proposal-survival.test.d.ts +1 -0
  34. package/dist-client/components/chat-proposal-survival.test.js +61 -0
  35. package/dist-client/components/chat-proposal-survival.test.js.map +1 -0
  36. package/dist-client/components/mention-popup.js +28 -8
  37. package/dist-client/components/mention-popup.js.map +1 -1
  38. package/dist-client/components/panel-aria.test.d.ts +1 -0
  39. package/dist-client/components/panel-aria.test.js +31 -0
  40. package/dist-client/components/panel-aria.test.js.map +1 -0
  41. package/dist-client/components/proposal-outcome-line.d.ts +9 -0
  42. package/dist-client/components/proposal-outcome-line.js +15 -0
  43. package/dist-client/components/proposal-outcome-line.js.map +1 -0
  44. package/dist-client/tsconfig.tsbuildinfo +1 -1
  45. package/dist-client/utils/assistant-session-controller.d.ts +10 -0
  46. package/dist-client/utils/assistant-session-controller.js +16 -0
  47. package/dist-client/utils/assistant-session-controller.js.map +1 -1
  48. package/dist-client/utils/assistant-session-controller.test.d.ts +1 -0
  49. package/dist-client/utils/assistant-session-controller.test.js +56 -0
  50. package/dist-client/utils/assistant-session-controller.test.js.map +1 -0
  51. package/dist-client/utils/assistant-session-transport.js +11 -3
  52. package/dist-client/utils/assistant-session-transport.js.map +1 -1
  53. package/dist-server/service/assistant-capability-resolver.d.ts +17 -0
  54. package/dist-server/service/assistant-capability-resolver.js +88 -0
  55. package/dist-server/service/assistant-capability-resolver.js.map +1 -0
  56. package/dist-server/service/assistant-chat-resolver.d.ts +6 -6
  57. package/dist-server/service/assistant-chat-resolver.js +166 -44
  58. package/dist-server/service/assistant-chat-resolver.js.map +1 -1
  59. package/dist-server/service/assistant-mode/assistant-mode-resolver.d.ts +25 -0
  60. package/dist-server/service/assistant-mode/assistant-mode-resolver.js +140 -0
  61. package/dist-server/service/assistant-mode/assistant-mode-resolver.js.map +1 -0
  62. package/dist-server/service/assistant-mode/index.d.ts +9 -0
  63. package/dist-server/service/assistant-mode/index.js +19 -0
  64. package/dist-server/service/assistant-mode/index.js.map +1 -0
  65. package/dist-server/service/assistant-mode/registry.d.ts +18 -0
  66. package/dist-server/service/assistant-mode/registry.js +136 -0
  67. package/dist-server/service/assistant-mode/registry.js.map +1 -0
  68. package/dist-server/service/assistant-mode/resolve.d.ts +33 -0
  69. package/dist-server/service/assistant-mode/resolve.js +60 -0
  70. package/dist-server/service/assistant-mode/resolve.js.map +1 -0
  71. package/dist-server/service/assistant-mode/types.d.ts +99 -0
  72. package/dist-server/service/assistant-mode/types.js +12 -0
  73. package/dist-server/service/assistant-mode/types.js.map +1 -0
  74. package/dist-server/service/chat-message/carried-turns.d.ts +48 -0
  75. package/dist-server/service/chat-message/carried-turns.js +80 -0
  76. package/dist-server/service/chat-message/carried-turns.js.map +1 -0
  77. package/dist-server/service/chat-message/chat-message-subscription.d.ts +1 -1
  78. package/dist-server/service/chat-message/chat-message-subscription.js +24 -6
  79. package/dist-server/service/chat-message/chat-message-subscription.js.map +1 -1
  80. package/dist-server/service/chat-message/chat-message.d.ts +32 -0
  81. package/dist-server/service/chat-message/chat-message.js +17 -0
  82. package/dist-server/service/chat-message/chat-message.js.map +1 -1
  83. package/dist-server/service/chat-message/door-access.d.ts +15 -0
  84. package/dist-server/service/chat-message/door-access.js +26 -0
  85. package/dist-server/service/chat-message/door-access.js.map +1 -0
  86. package/dist-server/service/chat-message/fold-session-history.d.ts +30 -0
  87. package/dist-server/service/chat-message/fold-session-history.js +133 -0
  88. package/dist-server/service/chat-message/fold-session-history.js.map +1 -0
  89. package/dist-server/service/chat-message/llm-history.d.ts +7 -0
  90. package/dist-server/service/chat-message/llm-history.js +23 -11
  91. package/dist-server/service/chat-message/llm-history.js.map +1 -1
  92. package/dist-server/service/chat-message/message-doors.d.ts +29 -0
  93. package/dist-server/service/chat-message/message-doors.js +107 -0
  94. package/dist-server/service/chat-message/message-doors.js.map +1 -0
  95. package/dist-server/service/chat-message/proposal-outcome.d.ts +18 -0
  96. package/dist-server/service/chat-message/proposal-outcome.js +31 -0
  97. package/dist-server/service/chat-message/proposal-outcome.js.map +1 -0
  98. package/dist-server/service/chat-message/reader-gate.d.ts +3 -0
  99. package/dist-server/service/chat-message/reader-gate.js +37 -0
  100. package/dist-server/service/chat-message/reader-gate.js.map +1 -0
  101. package/dist-server/service/chat-message/room-message.d.ts +4 -0
  102. package/dist-server/service/chat-message/room-message.js +25 -0
  103. package/dist-server/service/chat-message/room-message.js.map +1 -0
  104. package/dist-server/service/chat-session/chat-session.d.ts +24 -0
  105. package/dist-server/service/chat-session/chat-session.js +26 -2
  106. package/dist-server/service/chat-session/chat-session.js.map +1 -1
  107. package/dist-server/service/chat-session/session-inbox.d.ts +4 -1
  108. package/dist-server/service/chat-session/session-inbox.js +3 -2
  109. package/dist-server/service/chat-session/session-inbox.js.map +1 -1
  110. package/dist-server/service/chat-session/session-visibility.d.ts +15 -0
  111. package/dist-server/service/chat-session/session-visibility.js +28 -0
  112. package/dist-server/service/chat-session/session-visibility.js.map +1 -0
  113. package/dist-server/service/chat-session/station-session-guard.d.ts +1 -5
  114. package/dist-server/service/chat-session/station-session-guard.js +7 -2
  115. package/dist-server/service/chat-session/station-session-guard.js.map +1 -1
  116. package/dist-server/service/chat-session-participant/mention-invite.d.ts +29 -0
  117. package/dist-server/service/chat-session-participant/mention-invite.js +103 -0
  118. package/dist-server/service/chat-session-participant/mention-invite.js.map +1 -0
  119. package/dist-server/service/chat-session-resolver.d.ts +15 -0
  120. package/dist-server/service/chat-session-resolver.js +267 -15
  121. package/dist-server/service/chat-session-resolver.js.map +1 -1
  122. package/dist-server/service/grounding-sources.d.ts +14 -0
  123. package/dist-server/service/grounding-sources.js +26 -0
  124. package/dist-server/service/grounding-sources.js.map +1 -0
  125. package/dist-server/service/index.d.ts +8 -1
  126. package/dist-server/service/index.js +19 -0
  127. package/dist-server/service/index.js.map +1 -1
  128. package/dist-server/service/request-translator.d.ts +2 -0
  129. package/dist-server/service/request-translator.js +20 -0
  130. package/dist-server/service/request-translator.js.map +1 -0
  131. package/dist-server/service/testing/conversation-script.d.ts +123 -0
  132. package/dist-server/service/testing/conversation-script.js +202 -0
  133. package/dist-server/service/testing/conversation-script.js.map +1 -0
  134. package/dist-server/service/testing/mode-conformance.d.ts +40 -0
  135. package/dist-server/service/testing/mode-conformance.js +90 -0
  136. package/dist-server/service/testing/mode-conformance.js.map +1 -0
  137. package/dist-server/tool-registry-boot-report.d.ts +3 -0
  138. package/dist-server/tool-registry-boot-report.js +25 -2
  139. package/dist-server/tool-registry-boot-report.js.map +1 -1
  140. package/dist-server/tsconfig.tsbuildinfo +1 -1
  141. package/package.json +5 -5
  142. package/server/explicit-graphql-types.test.ts +56 -0
  143. package/server/service/assistant-capability-resolver.ts +66 -0
  144. package/server/service/assistant-chat-resolver.ts +184 -42
  145. package/server/service/assistant-mode/assistant-mode-resolver.ts +102 -0
  146. package/server/service/assistant-mode/index.ts +16 -0
  147. package/server/service/assistant-mode/registry.test.ts +105 -0
  148. package/server/service/assistant-mode/registry.ts +147 -0
  149. package/server/service/assistant-mode/resolve.test.ts +78 -0
  150. package/server/service/assistant-mode/resolve.ts +96 -0
  151. package/server/service/assistant-mode/subject-defaults.test.ts +86 -0
  152. package/server/service/assistant-mode/types.ts +103 -0
  153. package/server/service/chat-message/carried-turns.test.ts +69 -0
  154. package/server/service/chat-message/carried-turns.ts +99 -0
  155. package/server/service/chat-message/chat-message-subscription.ts +20 -4
  156. package/server/service/chat-message/chat-message.ts +44 -0
  157. package/server/service/chat-message/door-access.ts +45 -0
  158. package/server/service/chat-message/fold-session-history.test.ts +98 -0
  159. package/server/service/chat-message/fold-session-history.ts +115 -0
  160. package/server/service/chat-message/llm-history.test.ts +58 -7
  161. package/server/service/chat-message/llm-history.ts +30 -11
  162. package/server/service/chat-message/message-doors.test.ts +87 -0
  163. package/server/service/chat-message/message-doors.ts +117 -0
  164. package/server/service/chat-message/proposal-outcome.test.ts +48 -0
  165. package/server/service/chat-message/proposal-outcome.ts +42 -0
  166. package/server/service/chat-message/reader-gate.ts +42 -0
  167. package/server/service/chat-message/room-message.test.ts +21 -0
  168. package/server/service/chat-message/room-message.ts +22 -0
  169. package/server/service/chat-session/chat-session.ts +31 -1
  170. package/server/service/chat-session/session-inbox.test.ts +18 -0
  171. package/server/service/chat-session/session-inbox.ts +9 -2
  172. package/server/service/chat-session/session-visibility.test.ts +36 -0
  173. package/server/service/chat-session/session-visibility.ts +26 -0
  174. package/server/service/chat-session/station-session-guard.ts +10 -2
  175. package/server/service/chat-session-participant/mention-invite.test.ts +125 -0
  176. package/server/service/chat-session-participant/mention-invite.ts +121 -0
  177. package/server/service/chat-session-resolver.ts +272 -15
  178. package/server/service/grounding-sources.test.ts +55 -0
  179. package/server/service/grounding-sources.ts +46 -0
  180. package/server/service/index.ts +19 -0
  181. package/server/service/request-translator.test.ts +45 -0
  182. package/server/service/request-translator.ts +33 -0
  183. package/server/service/station-session-guard.test.ts +12 -5
  184. package/server/service/testing/conversation-scenario.test.ts +163 -0
  185. package/server/service/testing/conversation-script.test.ts +131 -0
  186. package/server/service/testing/conversation-script.ts +288 -0
  187. package/server/service/testing/mode-conformance.ts +107 -0
  188. package/server/tool-registry-boot-report.ts +25 -2
  189. package/test/assistant-chat-call-sites.test.ts +82 -0
  190. package/translations/en.json +44 -2
  191. package/translations/ja.json +44 -2
  192. package/translations/ko.json +44 -2
  193. package/translations/ms.json +44 -2
  194. package/translations/zh.json +44 -2
@@ -36,10 +36,20 @@ const chat_session_js_1 = require("./chat-session/chat-session.js");
36
36
  const station_session_guard_js_1 = require("./chat-session/station-session-guard.js");
37
37
  const chat_message_js_1 = require("./chat-message/chat-message.js");
38
38
  const llm_history_js_1 = require("./chat-message/llm-history.js");
39
+ const history_summary_js_1 = require("./chat-message/history-summary.js");
40
+ const fold_session_history_js_1 = require("./chat-message/fold-session-history.js");
41
+ const grounding_sources_js_1 = require("./grounding-sources.js");
39
42
  const chat_message_publish_js_1 = require("./chat-message/chat-message-publish.js");
40
43
  const session_activity_publish_js_1 = require("./chat-session/session-activity-publish.js");
41
44
  const session_inbox_js_1 = require("./chat-session/session-inbox.js");
42
45
  const tool_access_js_1 = require("./tool-access.js");
46
+ const chat_session_participant_js_1 = require("./chat-session-participant/chat-session-participant.js");
47
+ const message_doors_js_1 = require("./chat-message/message-doors.js");
48
+ const reader_gate_js_1 = require("./chat-message/reader-gate.js");
49
+ const mention_invite_js_1 = require("./chat-session-participant/mention-invite.js");
50
+ const invite_notification_js_1 = require("./chat-session-participant/invite-notification.js");
51
+ const resolve_js_1 = require("./assistant-mode/resolve.js");
52
+ const request_translator_js_1 = require("./request-translator.js");
43
53
  /**
44
54
  * How many stored messages reach the model.
45
55
  *
@@ -61,6 +71,22 @@ tslib_1.__decorate([
61
71
  AssistantMessageInput = tslib_1.__decorate([
62
72
  (0, type_graphql_1.InputType)()
63
73
  ], AssistantMessageInput);
74
+ let AssistantModeInput = class AssistantModeInput {
75
+ };
76
+ tslib_1.__decorate([
77
+ (0, type_graphql_1.Field)({ description: 'A mode kind the app server registered — `<app>.<surface>`, e.g. "twin.space".' }),
78
+ tslib_1.__metadata("design:type", String)
79
+ ], AssistantModeInput.prototype, "kind", void 0);
80
+ tslib_1.__decorate([
81
+ (0, type_graphql_1.Field)({
82
+ nullable: true,
83
+ description: 'What this conversation is about — the space, the station, the model being edited. With `kind` it is the conversation\'s lifetime: when either changes the screen closes the conversation and starts another.'
84
+ }),
85
+ tslib_1.__metadata("design:type", String)
86
+ ], AssistantModeInput.prototype, "target", void 0);
87
+ AssistantModeInput = tslib_1.__decorate([
88
+ (0, type_graphql_1.InputType)({ description: 'Which conversation this is, and what it is about.' })
89
+ ], AssistantModeInput);
64
90
  let AssistantChatInput = class AssistantChatInput {
65
91
  };
66
92
  tslib_1.__decorate([
@@ -77,18 +103,11 @@ tslib_1.__decorate([
77
103
  tslib_1.__metadata("design:type", Array)
78
104
  ], AssistantChatInput.prototype, "messages", void 0);
79
105
  tslib_1.__decorate([
80
- (0, type_graphql_1.Field)({
81
- description: 'Who the assistant is on this surface, in the words of the product that owns the screen. The rules for using each tool come from whoever registered it and are appended by the server.'
82
- }),
83
- tslib_1.__metadata("design:type", String)
84
- ], AssistantChatInput.prototype, "systemPrompt", void 0);
85
- tslib_1.__decorate([
86
- (0, type_graphql_1.Field)(() => [String], {
87
- nullable: true,
88
- description: 'Registered tool categories this conversation may use (registerToolCategory names, e.g. ["figure-authoring"]). Omitted or empty allows none — a plain conversation. A tool that declares a privilege is offered only to a caller who holds it.'
106
+ (0, type_graphql_1.Field)(() => AssistantModeInput, {
107
+ description: 'Which conversation this is. The persona, the tool categories, the model and the limits come from the mode the app server registered (ADR-0061 decision 7) a caller choosing its own tool categories would be a caller choosing its own authority.'
89
108
  }),
90
- tslib_1.__metadata("design:type", Array)
91
- ], AssistantChatInput.prototype, "toolCategories", void 0);
109
+ tslib_1.__metadata("design:type", AssistantModeInput)
110
+ ], AssistantChatInput.prototype, "mode", void 0);
92
111
  tslib_1.__decorate([
93
112
  (0, type_graphql_1.Field)(() => graphql_scalars_1.GraphQLJSON, {
94
113
  nullable: true,
@@ -103,25 +122,6 @@ tslib_1.__decorate([
103
122
  }),
104
123
  tslib_1.__metadata("design:type", String)
105
124
  ], AssistantChatInput.prototype, "truncateAfterMessageId", void 0);
106
- tslib_1.__decorate([
107
- (0, type_graphql_1.Field)({
108
- nullable: true,
109
- description: 'Require a tool call before the model may answer. For surfaces that report live state, where an unchecked assertion reads the same as a checked one.'
110
- }),
111
- tslib_1.__metadata("design:type", Boolean)
112
- ], AssistantChatInput.prototype, "requireGroundingTools", void 0);
113
- tslib_1.__decorate([
114
- (0, type_graphql_1.Field)({ nullable: true, description: 'Model identifier override. Falls back to the configured default.' }),
115
- tslib_1.__metadata("design:type", String)
116
- ], AssistantChatInput.prototype, "model", void 0);
117
- tslib_1.__decorate([
118
- (0, type_graphql_1.Field)({ nullable: true, description: 'Sampling temperature override.' }),
119
- tslib_1.__metadata("design:type", Number)
120
- ], AssistantChatInput.prototype, "temperature", void 0);
121
- tslib_1.__decorate([
122
- (0, type_graphql_1.Field)({ nullable: true, description: 'Max output tokens per call.' }),
123
- tslib_1.__metadata("design:type", Number)
124
- ], AssistantChatInput.prototype, "maxTokens", void 0);
125
125
  AssistantChatInput = tslib_1.__decorate([
126
126
  (0, type_graphql_1.InputType)({ description: 'One turn of a conversation that has no document of its own.' })
127
127
  ], AssistantChatInput);
@@ -147,6 +147,13 @@ tslib_1.__decorate([
147
147
  (0, type_graphql_1.Field)({ nullable: true, description: 'Stored ChatMessage id of the reply.' }),
148
148
  tslib_1.__metadata("design:type", String)
149
149
  ], AssistantChatOutput.prototype, "assistantMessageId", void 0);
150
+ tslib_1.__decorate([
151
+ (0, type_graphql_1.Field)(() => graphql_scalars_1.GraphQLJSON, {
152
+ nullable: true,
153
+ description: 'Set when this turn did not fit: { omitted, summarized } — how many earlier messages the model did not see, and whether a summary stood in for them. Without it the person watches the conversation lose its beginning in silence, while the model is told.'
154
+ }),
155
+ tslib_1.__metadata("design:type", Object)
156
+ ], AssistantChatOutput.prototype, "historyFolded", void 0);
150
157
  tslib_1.__decorate([
151
158
  (0, type_graphql_1.Field)(() => graphql_scalars_1.GraphQLJSON, {
152
159
  nullable: true,
@@ -199,6 +206,13 @@ let AssistantChatResolver = class AssistantChatResolver {
199
206
  if (!client) {
200
207
  throw new Error('No AI client configured. Set config.aiClient = { provider, model, apiKey } or call setDefaultAIClient(...).');
201
208
  }
209
+ /*
210
+ * Read the declaration before anything is stored. A kind this server does not have is a
211
+ * mismatched deployment, and the person should see that instead of a conversation with no
212
+ * persona and no tools.
213
+ */
214
+ const t = (0, request_translator_js_1.requestTranslator)(context);
215
+ const settings = (0, resolve_js_1.resolveModeSettings)(input.mode, t);
202
216
  const { domain, user } = context.state;
203
217
  const sessionRepo = (0, shell_1.getRepository)(chat_session_js_1.ChatSession);
204
218
  const messageRepo = (0, shell_1.getRepository)(chat_message_js_1.ChatMessage);
@@ -208,14 +222,18 @@ let AssistantChatResolver = class AssistantChatResolver {
208
222
  if (!found)
209
223
  throw new Error(`ChatSession ${input.sessionId} not found`);
210
224
  if (found.anchorType === 'figure' && input.hostContext?.figureId !== found.anchorId) {
211
- throw new Error(' 대화는 다른 Figure의 이력입니다. 현재 모델의 대화를 다시 여세요.');
225
+ throw new Error(context.t('ai-assistant.text.other-figure-history', {
226
+ defaultValue: 'this conversation belongs to another figure. open the conversation of the model you have open.'
227
+ }));
212
228
  }
213
229
  if (found.anchorType === 'application' && (input.hostContext?.app !== found.anchorId || input.hostContext?.figureId)) {
214
- throw new Error('애플리케이션 대화와 모델 대화를 구분해서 다시 여세요.');
230
+ throw new Error(context.t('ai-assistant.text.application-vs-model-history', {
231
+ defaultValue: 'this conversation is about the application, not about a model. open the one you want.'
232
+ }));
215
233
  }
216
234
  session = found;
217
235
  }
218
- (0, station_session_guard_js_1.assertStationSession)(session, input.hostContext);
236
+ (0, station_session_guard_js_1.assertStationSession)(session, input.hostContext, t);
219
237
  const lastUserMessage = input.messages[input.messages.length - 1];
220
238
  let userMessageId;
221
239
  if (session && lastUserMessage?.role === 'user') {
@@ -227,6 +245,12 @@ let AssistantChatResolver = class AssistantChatResolver {
227
245
  session: { id: session.id },
228
246
  role: 'user',
229
247
  content: lastUserMessage.content,
248
+ /*
249
+ * This door is the one people call to ask the assistant, so a turn stored here was for the
250
+ * assistant (ADR-0070 A15 decision ①). The value comes from which door was called, never
251
+ * from the request — two sources for one fact can disagree.
252
+ */
253
+ addressee: 'assistant',
230
254
  creator: user,
231
255
  updater: user,
232
256
  parentMessage: previousLast ? { id: previousLast.id } : undefined
@@ -246,6 +270,28 @@ let AssistantChatResolver = class AssistantChatResolver {
246
270
  catch {
247
271
  /* noop */
248
272
  }
273
+ /*
274
+ * 사람이 `@이름` 으로 부른 사람은 이 대화에 들어온다(ADR-0071 결정 1). 이 문은 **사람의 턴**을
275
+ * 저장하는 문이라 그 일을 한다 — 모델의 답이나 도구 결과는 아무도 초대하지 않는다.
276
+ */
277
+ const invite = await (0, mention_invite_js_1.inviteMentionedUsers)({
278
+ content: lastUserMessage.content,
279
+ sessionId: session.id,
280
+ domainId: domain.id,
281
+ inviter: user,
282
+ participants: (0, shell_1.getRepository)(chat_session_participant_js_1.ChatSessionParticipant),
283
+ visibility: session.visibility
284
+ });
285
+ if (invite.invited.length > 0) {
286
+ const payload = (0, invite_notification_js_1.buildInviteNotification)(invite.invited, undefined, user);
287
+ try {
288
+ if (payload)
289
+ await context.state?.notify?.(payload);
290
+ }
291
+ catch {
292
+ /* 편지가 못 갔다고 방에 들어온 사실이 취소되지는 않는다. */
293
+ }
294
+ }
249
295
  (0, chat_message_publish_js_1.publishChatMessage)({ domainId: domain.id, sessionId: session.id, message: saved });
250
296
  (0, session_activity_publish_js_1.publishSessionActivity)({
251
297
  domainId: domain.id,
@@ -257,12 +303,47 @@ let AssistantChatResolver = class AssistantChatResolver {
257
303
  actorId: user?.id
258
304
  });
259
305
  }
260
- const conversation = session
261
- ? (0, llm_history_js_1.buildLlmHistory)(await messageRepo.find({
306
+ /*
307
+ * 이번 턴에 상한 밖으로 밀려난 것이 있는가 — 화면이 「대화가 길어졌다」를 알릴 근거다.
308
+ *
309
+ * 이 문은 그 사실을 내지 않았다. 대화창에는 그 안내를 그리는 자리가 있고(`historyFolded`), 보드
310
+ * 문만 그 값을 채웠다. 그래서 앱의 대화는 앞부분이 잘려 나가도 **사람에게는 아무 말도 하지 않았다** —
311
+ * 모델에게는 「N 개 생략」을 적어 보내면서.
312
+ */
313
+ const readRows = session
314
+ ? await messageRepo.find({
262
315
  where: { session: { id: session.id } },
263
316
  order: { createdAt: 'ASC' },
264
317
  relations: ['creator']
265
- }), {
318
+ })
319
+ : [];
320
+ /*
321
+ * 모델이 읽는 이력도 **부른 사람** 기준으로 가린다 — ADR-0073 판정 1. 가리지 않으면, 문을 한 번도
322
+ * 안 지난 사람이 "아까 그 수 다시 말해 줘" 한 마디로 값을 가져간다. 모델이 옮겨 적는 순간 그 값은
323
+ * 문 없는 새 답이 된다. 가린 자리를 지우지 않고 한 줄로 남기는 이유도 같다 — 지우면 모델이 그런
324
+ * 말이 없었다고 답하고, 그것은 거짓말이다.
325
+ */
326
+ const storedRows = await (0, reader_gate_js_1.readerGate)(context)(readRows);
327
+ const capped = (0, history_summary_js_1.splitByCap)(storedRows.map(row => ({ id: row.id, role: row.role, content: row.content ?? '' })), LLM_HISTORY_MAX_TURNS);
328
+ const historyFolded = capped.dropped.length > 0
329
+ ? { omitted: capped.dropped.length, summarized: Boolean(session?.lastSummary) }
330
+ : undefined;
331
+ const conversation = session
332
+ ? (0, llm_history_js_1.buildLlmHistory)(
333
+ /*
334
+ * The model reads who spoke and who they spoke to. The entity carries the speaker as a
335
+ * relation and the addressee as a column; the history wants them as plain fields, and
336
+ * without this mapping every line arrived unattributed — a room of people read as one
337
+ * voice (ADR-0070 A15 decision ②).
338
+ */
339
+ storedRows.map(message => ({
340
+ id: message.id,
341
+ role: message.role,
342
+ content: message.content,
343
+ senderId: message.creator?.id,
344
+ senderName: message.creator?.name,
345
+ addressee: message.addressee
346
+ })), {
266
347
  maxTurns: LLM_HISTORY_MAX_TURNS,
267
348
  truncateAfterMessageId: input.truncateAfterMessageId,
268
349
  /* The message just stored is this turn's question — truncation must never drop it. */
@@ -287,22 +368,46 @@ let AssistantChatResolver = class AssistantChatResolver {
287
368
  const result = await (0, ai_client_base_1.registryAssistantChat)({
288
369
  client,
289
370
  messages: conversation,
290
- systemPrompt: input.systemPrompt,
291
- toolCategories: input.toolCategories,
371
+ systemPrompt: settings.systemPrompt,
372
+ toolCategories: settings.toolCategories,
292
373
  toolAccess: (0, tool_access_js_1.toolAccessFor)(context),
374
+ /* The stop notice is a sentence a person reads — the server writes it in their language (ADR-0054). */
375
+ t,
293
376
  hostContext: input.hostContext,
377
+ /*
378
+ * 근거는 도구 결과만이 아니다 — 시스템 프롬프트 · 이 대화의 말 · 화면이 보낸 스냅숏도 근거다
379
+ * (`ai-client-base/utils/grounding`). 이 문은 그 셋을 넘기지 않아, **사람이 방금 타이핑한
380
+ * 식별자**를 되받아 적은 답이 「근거 없음」으로 표시됐다. 그런 경고가 몇 번 나오면 사람이 경고
381
+ * 자체를 안 보게 된다.
382
+ */
383
+ groundingSources: (0, grounding_sources_js_1.groundingSourcesFor)({
384
+ systemPrompt: settings.systemPrompt,
385
+ messages: conversation,
386
+ hostContext: input.hostContext
387
+ }),
294
388
  state: context.state,
295
- model: input.model,
296
- temperature: input.temperature,
297
- maxTokens: input.maxTokens,
298
- requireToolOnFirstTurn: input.requireGroundingTools
389
+ model: settings.model,
390
+ temperature: settings.temperature,
391
+ maxTokens: settings.maxTokens,
392
+ requireToolOnFirstTurn: settings.requireToolOnFirstTurn
299
393
  });
394
+ /*
395
+ * 이 답이 지나온 문 — ADR-0073 판정 1. 행에도, 목록 미리보기에도 같은 값이 간다. 한쪽만 적으면
396
+ * 가려진 답이 목록에는 그대로 뜬다.
397
+ */
398
+ const answerDoors = (0, message_doors_js_1.doorsForAnswer)((result.loop.toolUsages ?? []).map((usage) => usage?.name).filter(Boolean), name => (0, ai_client_base_1.findToolSpec)(name, settings.toolCategories)?.doors);
300
399
  let assistantMessageId;
301
400
  if (session) {
302
401
  const stored = await messageRepo.save({
303
402
  session: { id: session.id },
304
403
  role: 'assistant',
305
404
  content: result.reply,
405
+ /*
406
+ * 이 답이 지나온 문을 함께 적는다 — ADR-0073 판정 1. 방은 도메인 안에서 공개이므로, 이 문장이
407
+ * 실어 나르는 값을 나중에 읽는 사람이 열 수 있는지 판정할 근거가 행에 있어야 한다. 적지 않으면
408
+ * 빈 목록이 되고, 빈 목록은 누구나 읽는다는 뜻이다.
409
+ */
410
+ doors: answerDoors,
306
411
  toolUsages: result.loop.toolUsages?.length ? JSON.stringify(result.loop.toolUsages) : undefined,
307
412
  groundingWarnings: result.groundingWarnings?.length ? JSON.stringify(result.groundingWarnings) : undefined,
308
413
  creator: user,
@@ -324,7 +429,23 @@ let AssistantChatResolver = class AssistantChatResolver {
324
429
  await sessionRepo.update(session.id, {
325
430
  aiClientId: client.id,
326
431
  updater: user,
327
- ...(0, session_inbox_js_1.activityPatch)(result.reply)
432
+ ...(0, session_inbox_js_1.activityPatch)(result.reply, new Date(), answerDoors)
433
+ });
434
+ /*
435
+ * 상한 밖으로 밀려난 앞부분을 요약으로 접는다 — **답을 돌려준 뒤**에 한다(사용자 대기 시간에
436
+ * 요약 호출을 얹지 않는다). 기다리지 않으므로 실패해도 대화에는 영향이 없다: 요약이 없으면 다음
437
+ * 턴이 「N 개 생략」으로 정직하게 알린다.
438
+ *
439
+ * 이 문에는 이 호출이 없었다. 조각은 다 있었는데(상한 · 생략 알림 · `lastSummary` · 순수 규칙)
440
+ * 부르는 쪽이 보드 제품 하나뿐이어서, 앱의 대화는 며칠이 지나도 앞부분을 요약하지 않고 매 턴
441
+ * 「생략했다」고만 말했다 — 협의가 길어질수록 처음에 합의한 것이 먼저 사라진다.
442
+ */
443
+ void (0, fold_session_history_js_1.foldSessionHistory)({
444
+ sessionId: session.id,
445
+ domainId: domain.id,
446
+ client,
447
+ maxTurns: LLM_HISTORY_MAX_TURNS,
448
+ locale: context.state?.locale
328
449
  });
329
450
  }
330
451
  return {
@@ -336,7 +457,8 @@ let AssistantChatResolver = class AssistantChatResolver {
336
457
  toolUsages: result.loop.toolUsages?.length ? result.loop.toolUsages : null,
337
458
  offeredTools: result.offeredTools,
338
459
  proposals: result.loop.proposals?.length ? result.loop.proposals : null,
339
- groundingWarnings: result.groundingWarnings?.length ? result.groundingWarnings : null
460
+ groundingWarnings: result.groundingWarnings?.length ? result.groundingWarnings : null,
461
+ historyFolded: historyFolded ?? null
340
462
  };
341
463
  }
342
464
  };
@@ -1 +1 @@
1
- {"version":3,"file":"assistant-chat-resolver.js","sourceRoot":"","sources":["../../server/service/assistant-chat-resolver.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,+CAAoG;AACpG,qDAA6C;AAC7C,qCAAkC;AAElC,6CAA4C;AAC5C,iDAAqD;AACrD,mEAAyH;AAEzH,oEAA4D;AAC5D,sFAA8E;AAC9E,oEAA4D;AAC5D,kEAA+D;AAC/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U,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI;YAC1E,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;YACvE,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI;SACtF,CAAA;IACH,CAAC;CACF,CAAA;AAlLY,sDAAqB;AAiB1B;IAVL,IAAA,uBAAQ,EAAC,GAAG,EAAE,CAAC,mBAAmB,EAAE;QACnC,WAAW,EACT,0JAA0J;KAC7J,CAAC;IACF;;;;OAIG;;IACF,IAAA,wBAAS,EAAC,6DAA6D,CAAC;IACpD,mBAAA,IAAA,kBAAG,EAAC,OAAO,CAAC,CAAA;IAA6B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAA1B,kBAAkB;;0DAgK1D;gCAjLU,qBAAqB;IADjC,IAAA,uBAAQ,GAAE;GACE,qBAAqB,CAkLjC","sourcesContent":["/*\n * The neutral door into a conversation.\n *\n * ── Why this exists (2026-09-11) ───────────────────────────────────────────────\n * The chat component moved here from `board-ai`, but the only mutation it could call stayed\n * behind. operato-figure mounted the dock, registered four tools, and got\n * `Cannot query field \"boardAIChat\" on type \"Mutation\"` — it does not load board-ai. The twin has\n * the same shape and it does not show: its space deliberation runs through board-ai's door purely\n * because the board authoring half of the same product already loaded that package.\n *\n * ── Why the board resolver was not moved ───────────────────────────────────────\n * `board-ai-resolver.ts` is 692 lines and the larger part of it is board authoring itself:\n * `currentBoard` as a BoardModel, PatchEntry, board patch broadcasts, refid injection for\n * component mentions. Moving that here would teach this package the board document, which is the\n * dependency we just cut, pointing the other way.\n *\n * So the door moved and the editor did not. `boardAIChat` stays in board-ai for board authoring;\n * this one is for a surface that asks questions and runs registered tools.\n *\n * ── What this is not ───────────────────────────────────────────────────────────\n * It has no document, so it takes no document and returns no patch. Tools that write to a\n * document are not offered here — `registryAssistantChat` enforces that, and it decides what may\n * be dispatched from the same list it offers, so the two cannot drift apart.\n */\nimport { Arg, Ctx, Directive, Field, InputType, Mutation, ObjectType, Resolver } from 'type-graphql'\nimport { GraphQLJSON } from 'graphql-scalars'\nimport '@things-factory/auth-base'\n\nimport { config } from '@things-factory/env'\nimport { getRepository } from '@things-factory/shell'\nimport { createAIClient, getDefaultAIClient, registryAssistantChat, type AIClient } from '@things-factory/ai-client-base'\n\nimport { ChatSession } from './chat-session/chat-session.js'\nimport { assertStationSession } from './chat-session/station-session-guard.js'\nimport { ChatMessage } from './chat-message/chat-message.js'\nimport { buildLlmHistory } from './chat-message/llm-history.js'\nimport { publishChatMessage } from './chat-message/chat-message-publish.js'\nimport { publishSessionActivity } from './chat-session/session-activity-publish.js'\nimport { activityPatch, autoSessionName } from './chat-session/session-inbox.js'\nimport { toolAccessFor } from './tool-access.js'\n\n/**\n * How many stored messages reach the model.\n *\n * A deliberation runs for days. Without a cap the prompt grows without bound and the oldest turns\n * bury the recent ones. Kept the same as the board conversation's cap so the two surfaces of one\n * product do not remember differently.\n */\nconst LLM_HISTORY_MAX_TURNS = 40\n\n@InputType()\nclass AssistantMessageInput {\n @Field({ description: \"Role: 'user' or 'assistant'\" })\n role: string\n\n @Field({ description: 'Message content' })\n content: string\n}\n\n@InputType({ description: 'One turn of a conversation that has no document of its own.' })\nclass AssistantChatInput {\n @Field({\n nullable: true,\n description: 'ChatSession id. Omit for a one-off question with no persistence.'\n })\n sessionId?: string\n\n @Field(() => [AssistantMessageInput], {\n description:\n 'Conversation, newest last. For a persisted session only the last user message is appended; the rest is read from storage.'\n })\n messages: AssistantMessageInput[]\n\n @Field({\n description:\n 'Who the assistant is on this surface, in the words of the product that owns the screen. The rules for using each tool come from whoever registered it and are appended by the server.'\n })\n systemPrompt: string\n\n @Field(() => [String], {\n nullable: true,\n description:\n 'Registered tool categories this conversation may use (registerToolCategory names, e.g. [\"figure-authoring\"]). Omitted or empty allows none — a plain conversation. A tool that declares a privilege is offered only to a caller who holds it.'\n })\n toolCategories?: string[]\n\n @Field(() => GraphQLJSON, {\n nullable: true,\n description:\n 'What this surface is looking at (e.g. { figureId } while modelling). Tools read it so the model never has to ask the user for identifiers. Client-supplied — never used for authorization; a tool verifies the scope belongs to the caller tenant.'\n })\n hostContext?: any\n\n @Field({\n nullable: true,\n description:\n 'Last message to keep from the stored history. The client keeps its own truncation when a user edits a message, so pass the last kept id to hide the retracted span from the model.'\n })\n truncateAfterMessageId?: string\n\n @Field({\n nullable: true,\n description:\n 'Require a tool call before the model may answer. For surfaces that report live state, where an unchecked assertion reads the same as a checked one.'\n })\n requireGroundingTools?: boolean\n\n @Field({ nullable: true, description: 'Model identifier override. Falls back to the configured default.' })\n model?: string\n\n @Field({ nullable: true, description: 'Sampling temperature override.' })\n temperature?: number\n\n @Field({ nullable: true, description: 'Max output tokens per call.' })\n maxTokens?: number\n}\n\n@ObjectType()\nclass AssistantChatOutput {\n @Field({ description: 'The reply, including the notice when the loop stopped early.' })\n reply: string\n\n @Field({ description: 'AI client identifier (provider:model).' })\n clientId: string\n\n @Field({ nullable: true, description: 'Echo of the session id, when persisted.' })\n sessionId?: string\n\n @Field({ nullable: true, description: 'Stored ChatMessage id of the user input.' })\n userMessageId?: string\n\n @Field({ nullable: true, description: 'Stored ChatMessage id of the reply.' })\n assistantMessageId?: string\n\n @Field(() => GraphQLJSON, {\n nullable: true,\n description: 'Tool usages during the turn — {name, arguments, result, kind}. The surface shows them foldably.'\n })\n toolUsages?: any\n\n @Field(() => [String], {\n nullable: true,\n description:\n 'Tool names offered to the model this turn. A surface that expected a category and sees it missing here knows the registration did not happen, rather than reading a vague answer as a refusal.'\n })\n offeredTools?: string[]\n\n @Field(() => GraphQLJSON, {\n nullable: true,\n description:\n 'Actions a tool recorded without executing — each carries what the tool returned alongside `proposed: true`. The surface renders a confirm button; executing is the user\\'s act.'\n })\n proposals?: any\n\n @Field(() => GraphQLJSON, {\n nullable: true,\n description:\n 'Identifiers in the reply that appear in nothing the model received. Hallucination candidates surfaced to the user; the reply itself is not altered. Null when the answer is grounded.'\n })\n groundingWarnings?: any\n}\n\nfunction resolveAIClient(): AIClient | undefined {\n const existing = getDefaultAIClient()\n if (existing) return existing\n const cfg = config.get('aiClient', null) as any\n if (cfg && cfg.provider) return createAIClient(cfg)\n return undefined\n}\n\n@Resolver()\nexport class AssistantChatResolver {\n /*\n * No `@transaction`, for the same reason the board conversation has none: a model call takes\n * seconds to tens of seconds, and holding a write lock for that long collides with everything\n * else on SQLite. Writes are short and around the call. For a conversation, a partly stored\n * history is safer than a lost one.\n */\n @Mutation(() => AssistantChatOutput, {\n description:\n 'Ask the assistant a question on a surface that has no document of its own. Tools come from the registry; with a sessionId the conversation is persisted.'\n })\n /*\n * `ai-assistant:mutation` — the same door as the board conversation's, which moved here on\n * 2026-09-10. No `legacy` alias: this operation is new, so no one was ever passing under an old\n * name, and declaring an alias would open a second name that nothing needs.\n */\n @Directive('@privilege(category: \"ai-assistant\", privilege: \"mutation\")')\n async assistantChat(@Arg('input') input: AssistantChatInput, @Ctx() context: any): Promise<AssistantChatOutput> {\n const client = resolveAIClient()\n if (!client) {\n throw new Error(\n 'No AI client configured. Set config.aiClient = { provider, model, apiKey } or call setDefaultAIClient(...).'\n )\n }\n\n const { domain, user } = context.state\n const sessionRepo = getRepository(ChatSession)\n const messageRepo = getRepository(ChatMessage)\n\n let session: ChatSession | undefined\n if (input.sessionId) {\n const found = await sessionRepo.findOneBy({ id: input.sessionId, domain: { id: domain.id } as any })\n if (!found) throw new Error(`ChatSession ${input.sessionId} not found`)\n if (found.anchorType === 'figure' && input.hostContext?.figureId !== found.anchorId) {\n throw new Error('이 대화는 다른 Figure의 이력입니다. 현재 모델의 대화를 다시 여세요.')\n }\n if (found.anchorType === 'application' && (input.hostContext?.app !== found.anchorId || input.hostContext?.figureId)) {\n throw new Error('애플리케이션 대화와 모델 대화를 구분해서 다시 여세요.')\n }\n session = found\n }\n\n assertStationSession(session, input.hostContext)\n\n const lastUserMessage = input.messages[input.messages.length - 1]\n let userMessageId: string | undefined\n\n if (session && lastUserMessage?.role === 'user') {\n const previousLast = await messageRepo.findOne({\n where: { session: { id: session.id } as any },\n order: { createdAt: 'DESC' }\n })\n const saved = await messageRepo.save({\n session: { id: session.id } as any,\n role: 'user',\n content: lastUserMessage.content,\n creator: user,\n updater: user,\n parentMessage: previousLast ? ({ id: previousLast.id } as any) : undefined\n })\n userMessageId = saved.id\n\n /*\n * Session activity is denormalised for the list: most-recent ordering and another\n * participant's unread badge read it. Best effort — a conversation must not fail because a\n * list sorts one position late.\n */\n try {\n const patch: any = activityPatch(lastUserMessage.content)\n if (!session.name) patch.name = autoSessionName(lastUserMessage.content)\n await sessionRepo.update(session.id!, patch)\n } catch {\n /* noop */\n }\n\n publishChatMessage({ domainId: domain.id, sessionId: session.id, message: saved } as any)\n publishSessionActivity({\n domainId: domain.id,\n sessionId: session.id!,\n kind: 'message',\n anchorType: (session as any).anchorType,\n anchorId: (session as any).anchorId,\n preview: lastUserMessage.content,\n actorId: user?.id\n })\n }\n\n const conversation = session\n ? buildLlmHistory(\n await messageRepo.find({\n where: { session: { id: session.id } as any },\n order: { createdAt: 'ASC' },\n relations: ['creator']\n }),\n {\n maxTurns: LLM_HISTORY_MAX_TURNS,\n truncateAfterMessageId: input.truncateAfterMessageId,\n /* The message just stored is this turn's question — truncation must never drop it. */\n keepMessageIds: userMessageId ? [userMessageId] : undefined,\n summary: (session as any).lastSummary\n ? { text: (session as any).lastSummary, upToMessageId: (session as any).summaryUpToMessageId }\n : undefined\n }\n )\n : input.messages.map(message => ({ role: message.role as any, content: message.content }))\n\n if (input.hostContext?.image?.data && conversation.length > 0) {\n const last = conversation[conversation.length - 1]\n if (last.role === 'user' && typeof last.content === 'string') {\n const raw = input.hostContext.image\n const rawData = typeof raw.data === 'string' ? raw.data.replace(/^data:image\\/[a-zA-Z]+;base64,/, '') : raw.data\n const buf = typeof rawData === 'string' ? Buffer.from(rawData, 'base64') : Buffer.from(rawData)\n last.content = [\n { type: 'text', text: last.content },\n { type: 'image', source: { kind: 'base64', data: buf, mediaType: raw.mediaType || 'image/png' } }\n ] as any\n }\n }\n\n const result = await registryAssistantChat({\n client,\n messages: conversation as any,\n systemPrompt: input.systemPrompt,\n toolCategories: input.toolCategories,\n toolAccess: toolAccessFor(context),\n hostContext: input.hostContext,\n state: context.state,\n model: input.model,\n temperature: input.temperature,\n maxTokens: input.maxTokens,\n requireToolOnFirstTurn: input.requireGroundingTools\n })\n\n let assistantMessageId: string | undefined\n if (session) {\n const stored = await messageRepo.save({\n session: { id: session.id } as any,\n role: 'assistant',\n content: result.reply,\n toolUsages: result.loop.toolUsages?.length ? JSON.stringify(result.loop.toolUsages) : undefined,\n groundingWarnings: result.groundingWarnings?.length ? JSON.stringify(result.groundingWarnings) : undefined,\n creator: user,\n updater: user,\n parentMessage: userMessageId ? ({ id: userMessageId } as any) : undefined\n })\n assistantMessageId = stored.id\n\n publishChatMessage({ domainId: domain.id, sessionId: session.id, message: stored } as any)\n /* The reply is session activity too. Leaving it out shows other participants \"nothing new\". */\n publishSessionActivity({\n domainId: domain.id,\n sessionId: session.id!,\n kind: 'message',\n anchorType: (session as any).anchorType,\n anchorId: (session as any).anchorId,\n preview: result.reply,\n actorId: user?.id\n })\n\n await sessionRepo.update(session.id!, {\n aiClientId: client.id,\n updater: user,\n ...activityPatch(result.reply)\n } as any)\n }\n\n return {\n reply: result.reply,\n clientId: client.id,\n sessionId: session?.id,\n userMessageId,\n assistantMessageId,\n toolUsages: result.loop.toolUsages?.length ? result.loop.toolUsages : null,\n offeredTools: result.offeredTools,\n proposals: result.loop.proposals?.length ? result.loop.proposals : null,\n groundingWarnings: result.groundingWarnings?.length ? result.groundingWarnings : null\n }\n }\n}\n"]}
1
+ {"version":3,"file":"assistant-chat-resolver.js","sourceRoot":"","sources":["../../server/service/assistant-chat-resolver.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,+CAAoG;AACpG,qDAA6C;AAC7C,qCAAkC;AAElC,6CAA4C;AAC5C,iDAAqD;AACrD,mEAMuC;AAEvC,oEAA4D;AAC5D,sFAA8E;AAC9E,oEAA4D;AAC5D,kEAA+D;AAC/D,0EAA8D;AAC9D,oFAA2E;AAC3E,iEAA4D;AAC5D,oFAA2E;AAC3E,4FAAmF;AACnF,sEAAgF;AAChF,qDAAgD;AAChD,wGAA+F;AAC/F,sEAAgE;AAChE,kEAA0D;AAC1D,oFAAmF;AACnF,8FAA2F;AAC3F,4DAAiE;AACjE,mEAA2D;AAE3D;;;;;;GAMG;AACH,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAGhC,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;CAM1B,CAAA;AAJC;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,6BAA6B,EAAE,CAAC;;mDAC1C;AAGZ;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC;;sDAC3B;AALX,qBAAqB;IAD1B,IAAA,wBAAS,GAAE;GACN,qBAAqB,CAM1B;AAGD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;CAUvB,CAAA;AARC;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,+EAA+E,EAAE,CAAC;;gDAC5F;AAOZ;IALC,IAAA,oBAAK,EAAC;QACL,QAAQ,EAAE,IAAI;QACd,WAAW,EACT,8MAA8M;KACjN,CAAC;;kDACa;AATX,kBAAkB;IADvB,IAAA,wBAAS,EAAC,EAAE,WAAW,EAAE,mDAAmD,EAAE,CAAC;GAC1E,kBAAkB,CAUvB;AAGD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;CAiCvB,CAAA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I;YACrF,aAAa,EAAE,aAAa,IAAI,IAAI;SACrC,CAAA;IACH,CAAC;CACF,CAAA;AAlTY,sDAAqB;AAiB1B;IAVL,IAAA,uBAAQ,EAAC,GAAG,EAAE,CAAC,mBAAmB,EAAE;QACnC,WAAW,EACT,0JAA0J;KAC7J,CAAC;IACF;;;;OAIG;;IACF,IAAA,wBAAS,EAAC,6DAA6D,CAAC;IACpD,mBAAA,IAAA,kBAAG,EAAC,OAAO,CAAC,CAAA;IAA6B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAA1B,kBAAkB;;0DAgS1D;gCAjTU,qBAAqB;IADjC,IAAA,uBAAQ,GAAE;GACE,qBAAqB,CAkTjC","sourcesContent":["/*\n * The neutral door into a conversation.\n *\n * ── Why this exists (2026-09-11) ───────────────────────────────────────────────\n * The chat component moved here from `board-ai`, but the only mutation it could call stayed\n * behind. operato-figure mounted the dock, registered four tools, and got\n * `Cannot query field \"boardAIChat\" on type \"Mutation\"` — it does not load board-ai. The twin has\n * the same shape and it does not show: its space deliberation runs through board-ai's door purely\n * because the board authoring half of the same product already loaded that package.\n *\n * ── Why the board resolver was not moved ───────────────────────────────────────\n * `board-ai-resolver.ts` is 692 lines and the larger part of it is board authoring itself:\n * `currentBoard` as a BoardModel, PatchEntry, board patch broadcasts, refid injection for\n * component mentions. Moving that here would teach this package the board document, which is the\n * dependency we just cut, pointing the other way.\n *\n * So the door moved and the editor did not. `boardAIChat` stays in board-ai for board authoring;\n * this one is for a surface that asks questions and runs registered tools.\n *\n * ── What this is not ───────────────────────────────────────────────────────────\n * It has no document, so it takes no document and returns no patch. Tools that write to a\n * document are not offered here — `registryAssistantChat` enforces that, and it decides what may\n * be dispatched from the same list it offers, so the two cannot drift apart.\n */\nimport { Arg, Ctx, Directive, Field, InputType, Mutation, ObjectType, Resolver } from 'type-graphql'\nimport { GraphQLJSON } from 'graphql-scalars'\nimport '@things-factory/auth-base'\n\nimport { config } from '@things-factory/env'\nimport { getRepository } from '@things-factory/shell'\nimport {\n createAIClient,\n findToolSpec,\n getDefaultAIClient,\n registryAssistantChat,\n type AIClient\n} from '@things-factory/ai-client-base'\n\nimport { ChatSession } from './chat-session/chat-session.js'\nimport { assertStationSession } from './chat-session/station-session-guard.js'\nimport { ChatMessage } from './chat-message/chat-message.js'\nimport { buildLlmHistory } from './chat-message/llm-history.js'\nimport { splitByCap } from './chat-message/history-summary.js'\nimport { foldSessionHistory } from './chat-message/fold-session-history.js'\nimport { groundingSourcesFor } from './grounding-sources.js'\nimport { publishChatMessage } from './chat-message/chat-message-publish.js'\nimport { publishSessionActivity } from './chat-session/session-activity-publish.js'\nimport { activityPatch, autoSessionName } from './chat-session/session-inbox.js'\nimport { toolAccessFor } from './tool-access.js'\nimport { ChatSessionParticipant } from './chat-session-participant/chat-session-participant.js'\nimport { doorsForAnswer } from './chat-message/message-doors.js'\nimport { readerGate } from './chat-message/reader-gate.js'\nimport { inviteMentionedUsers } from './chat-session-participant/mention-invite.js'\nimport { buildInviteNotification } from './chat-session-participant/invite-notification.js'\nimport { resolveModeSettings } from './assistant-mode/resolve.js'\nimport { requestTranslator } from './request-translator.js'\n\n/**\n * How many stored messages reach the model.\n *\n * A deliberation runs for days. Without a cap the prompt grows without bound and the oldest turns\n * bury the recent ones. Kept the same as the board conversation's cap so the two surfaces of one\n * product do not remember differently.\n */\nconst LLM_HISTORY_MAX_TURNS = 40\n\n@InputType()\nclass AssistantMessageInput {\n @Field({ description: \"Role: 'user' or 'assistant'\" })\n role: string\n\n @Field({ description: 'Message content' })\n content: string\n}\n\n@InputType({ description: 'Which conversation this is, and what it is about.' })\nclass AssistantModeInput {\n @Field({ description: 'A mode kind the app server registered — `<app>.<surface>`, e.g. \"twin.space\".' })\n kind: string\n\n @Field({\n nullable: true,\n description:\n 'What this conversation is about — the space, the station, the model being edited. With `kind` it is the conversation\\'s lifetime: when either changes the screen closes the conversation and starts another.'\n })\n target?: string\n}\n\n@InputType({ description: 'One turn of a conversation that has no document of its own.' })\nclass AssistantChatInput {\n @Field({\n nullable: true,\n description: 'ChatSession id. Omit for a one-off question with no persistence.'\n })\n sessionId?: string\n\n @Field(() => [AssistantMessageInput], {\n description:\n 'Conversation, newest last. For a persisted session only the last user message is appended; the rest is read from storage.'\n })\n messages: AssistantMessageInput[]\n\n @Field(() => AssistantModeInput, {\n description:\n 'Which conversation this is. The persona, the tool categories, the model and the limits come from the mode the app server registered (ADR-0061 decision 7) — a caller choosing its own tool categories would be a caller choosing its own authority.'\n })\n mode: AssistantModeInput\n\n @Field(() => GraphQLJSON, {\n nullable: true,\n description:\n 'What this surface is looking at (e.g. { figureId } while modelling). Tools read it so the model never has to ask the user for identifiers. Client-supplied — never used for authorization; a tool verifies the scope belongs to the caller tenant.'\n })\n hostContext?: any\n\n @Field({\n nullable: true,\n description:\n 'Last message to keep from the stored history. The client keeps its own truncation when a user edits a message, so pass the last kept id to hide the retracted span from the model.'\n })\n truncateAfterMessageId?: string\n\n}\n\n@ObjectType()\nclass AssistantChatOutput {\n @Field({ description: 'The reply, including the notice when the loop stopped early.' })\n reply: string\n\n @Field({ description: 'AI client identifier (provider:model).' })\n clientId: string\n\n @Field({ nullable: true, description: 'Echo of the session id, when persisted.' })\n sessionId?: string\n\n @Field({ nullable: true, description: 'Stored ChatMessage id of the user input.' })\n userMessageId?: string\n\n @Field({ nullable: true, description: 'Stored ChatMessage id of the reply.' })\n assistantMessageId?: string\n\n @Field(() => GraphQLJSON, {\n nullable: true,\n description:\n 'Set when this turn did not fit: { omitted, summarized } — how many earlier messages the model did not see, and whether a summary stood in for them. Without it the person watches the conversation lose its beginning in silence, while the model is told.'\n })\n historyFolded?: any\n\n @Field(() => GraphQLJSON, {\n nullable: true,\n description: 'Tool usages during the turn — {name, arguments, result, kind}. The surface shows them foldably.'\n })\n toolUsages?: any\n\n @Field(() => [String], {\n nullable: true,\n description:\n 'Tool names offered to the model this turn. A surface that expected a category and sees it missing here knows the registration did not happen, rather than reading a vague answer as a refusal.'\n })\n offeredTools?: string[]\n\n @Field(() => GraphQLJSON, {\n nullable: true,\n description:\n 'Actions a tool recorded without executing — each carries what the tool returned alongside `proposed: true`. The surface renders a confirm button; executing is the user\\'s act.'\n })\n proposals?: any\n\n @Field(() => GraphQLJSON, {\n nullable: true,\n description:\n 'Identifiers in the reply that appear in nothing the model received. Hallucination candidates surfaced to the user; the reply itself is not altered. Null when the answer is grounded.'\n })\n groundingWarnings?: any\n}\n\nfunction resolveAIClient(): AIClient | undefined {\n const existing = getDefaultAIClient()\n if (existing) return existing\n const cfg = config.get('aiClient', null) as any\n if (cfg && cfg.provider) return createAIClient(cfg)\n return undefined\n}\n\n@Resolver()\nexport class AssistantChatResolver {\n /*\n * No `@transaction`, for the same reason the board conversation has none: a model call takes\n * seconds to tens of seconds, and holding a write lock for that long collides with everything\n * else on SQLite. Writes are short and around the call. For a conversation, a partly stored\n * history is safer than a lost one.\n */\n @Mutation(() => AssistantChatOutput, {\n description:\n 'Ask the assistant a question on a surface that has no document of its own. Tools come from the registry; with a sessionId the conversation is persisted.'\n })\n /*\n * `ai-assistant:mutation` — the same door as the board conversation's, which moved here on\n * 2026-09-10. No `legacy` alias: this operation is new, so no one was ever passing under an old\n * name, and declaring an alias would open a second name that nothing needs.\n */\n @Directive('@privilege(category: \"ai-assistant\", privilege: \"mutation\")')\n async assistantChat(@Arg('input') input: AssistantChatInput, @Ctx() context: any): Promise<AssistantChatOutput> {\n const client = resolveAIClient()\n if (!client) {\n throw new Error(\n 'No AI client configured. Set config.aiClient = { provider, model, apiKey } or call setDefaultAIClient(...).'\n )\n }\n\n /*\n * Read the declaration before anything is stored. A kind this server does not have is a\n * mismatched deployment, and the person should see that instead of a conversation with no\n * persona and no tools.\n */\n const t = requestTranslator(context)\n const settings = resolveModeSettings(input.mode, t)\n\n const { domain, user } = context.state\n const sessionRepo = getRepository(ChatSession)\n const messageRepo = getRepository(ChatMessage)\n\n let session: ChatSession | undefined\n if (input.sessionId) {\n const found = await sessionRepo.findOneBy({ id: input.sessionId, domain: { id: domain.id } as any })\n if (!found) throw new Error(`ChatSession ${input.sessionId} not found`)\n if (found.anchorType === 'figure' && input.hostContext?.figureId !== found.anchorId) {\n throw new Error(\n context.t('ai-assistant.text.other-figure-history', {\n defaultValue: 'this conversation belongs to another figure. open the conversation of the model you have open.'\n })\n )\n }\n if (found.anchorType === 'application' && (input.hostContext?.app !== found.anchorId || input.hostContext?.figureId)) {\n throw new Error(\n context.t('ai-assistant.text.application-vs-model-history', {\n defaultValue: 'this conversation is about the application, not about a model. open the one you want.'\n })\n )\n }\n session = found\n }\n\n assertStationSession(session, input.hostContext, t)\n\n const lastUserMessage = input.messages[input.messages.length - 1]\n let userMessageId: string | undefined\n\n if (session && lastUserMessage?.role === 'user') {\n const previousLast = await messageRepo.findOne({\n where: { session: { id: session.id } as any },\n order: { createdAt: 'DESC' }\n })\n const saved = await messageRepo.save({\n session: { id: session.id } as any,\n role: 'user',\n content: lastUserMessage.content,\n /*\n * This door is the one people call to ask the assistant, so a turn stored here was for the\n * assistant (ADR-0070 A15 decision ①). The value comes from which door was called, never\n * from the request — two sources for one fact can disagree.\n */\n addressee: 'assistant',\n creator: user,\n updater: user,\n parentMessage: previousLast ? ({ id: previousLast.id } as any) : undefined\n })\n userMessageId = saved.id\n\n /*\n * Session activity is denormalised for the list: most-recent ordering and another\n * participant's unread badge read it. Best effort — a conversation must not fail because a\n * list sorts one position late.\n */\n try {\n const patch: any = activityPatch(lastUserMessage.content)\n if (!session.name) patch.name = autoSessionName(lastUserMessage.content)\n await sessionRepo.update(session.id!, patch)\n } catch {\n /* noop */\n }\n\n /*\n * 사람이 `@이름` 으로 부른 사람은 이 대화에 들어온다(ADR-0071 결정 1). 이 문은 **사람의 턴**을\n * 저장하는 문이라 그 일을 한다 — 모델의 답이나 도구 결과는 아무도 초대하지 않는다.\n */\n const invite = await inviteMentionedUsers({\n content: lastUserMessage.content,\n sessionId: session.id!,\n domainId: domain.id,\n inviter: user,\n participants: getRepository(ChatSessionParticipant),\n visibility: (session as any).visibility\n })\n if (invite.invited.length > 0) {\n const payload = buildInviteNotification(invite.invited, undefined, user)\n try {\n if (payload) await (context.state as any)?.notify?.(payload)\n } catch {\n /* 편지가 못 갔다고 방에 들어온 사실이 취소되지는 않는다. */\n }\n }\n\n publishChatMessage({ domainId: domain.id, sessionId: session.id, message: saved } as any)\n publishSessionActivity({\n domainId: domain.id,\n sessionId: session.id!,\n kind: 'message',\n anchorType: (session as any).anchorType,\n anchorId: (session as any).anchorId,\n preview: lastUserMessage.content,\n actorId: user?.id\n })\n }\n\n /*\n * 이번 턴에 상한 밖으로 밀려난 것이 있는가 — 화면이 「대화가 길어졌다」를 알릴 근거다.\n *\n * 이 문은 그 사실을 내지 않았다. 대화창에는 그 안내를 그리는 자리가 있고(`historyFolded`), 보드\n * 문만 그 값을 채웠다. 그래서 앱의 대화는 앞부분이 잘려 나가도 **사람에게는 아무 말도 하지 않았다** —\n * 모델에게는 「N 개 생략」을 적어 보내면서.\n */\n const readRows = session\n ? await messageRepo.find({\n where: { session: { id: session.id } as any },\n order: { createdAt: 'ASC' },\n relations: ['creator']\n })\n : []\n /*\n * 모델이 읽는 이력도 **부른 사람** 기준으로 가린다 — ADR-0073 판정 1. 가리지 않으면, 문을 한 번도\n * 안 지난 사람이 \"아까 그 수 다시 말해 줘\" 한 마디로 값을 가져간다. 모델이 옮겨 적는 순간 그 값은\n * 문 없는 새 답이 된다. 가린 자리를 지우지 않고 한 줄로 남기는 이유도 같다 — 지우면 모델이 그런\n * 말이 없었다고 답하고, 그것은 거짓말이다.\n */\n const storedRows = await readerGate(context)(readRows)\n const capped = splitByCap(\n storedRows.map(row => ({ id: row.id, role: row.role, content: row.content ?? '' })),\n LLM_HISTORY_MAX_TURNS\n )\n const historyFolded =\n capped.dropped.length > 0\n ? { omitted: capped.dropped.length, summarized: Boolean((session as any)?.lastSummary) }\n : undefined\n\n const conversation = session\n ? buildLlmHistory(\n /*\n * The model reads who spoke and who they spoke to. The entity carries the speaker as a\n * relation and the addressee as a column; the history wants them as plain fields, and\n * without this mapping every line arrived unattributed — a room of people read as one\n * voice (ADR-0070 A15 decision ②).\n */\n storedRows.map(message => ({\n id: message.id,\n role: message.role,\n content: message.content,\n senderId: (message as any).creator?.id,\n senderName: (message as any).creator?.name,\n addressee: (message as any).addressee\n })),\n {\n maxTurns: LLM_HISTORY_MAX_TURNS,\n truncateAfterMessageId: input.truncateAfterMessageId,\n /* The message just stored is this turn's question — truncation must never drop it. */\n keepMessageIds: userMessageId ? [userMessageId] : undefined,\n summary: (session as any).lastSummary\n ? { text: (session as any).lastSummary, upToMessageId: (session as any).summaryUpToMessageId }\n : undefined\n }\n )\n : input.messages.map(message => ({ role: message.role as any, content: message.content }))\n\n if (input.hostContext?.image?.data && conversation.length > 0) {\n const last = conversation[conversation.length - 1]\n if (last.role === 'user' && typeof last.content === 'string') {\n const raw = input.hostContext.image\n const rawData = typeof raw.data === 'string' ? raw.data.replace(/^data:image\\/[a-zA-Z]+;base64,/, '') : raw.data\n const buf = typeof rawData === 'string' ? Buffer.from(rawData, 'base64') : Buffer.from(rawData)\n last.content = [\n { type: 'text', text: last.content },\n { type: 'image', source: { kind: 'base64', data: buf, mediaType: raw.mediaType || 'image/png' } }\n ] as any\n }\n }\n\n const result = await registryAssistantChat({\n client,\n messages: conversation as any,\n systemPrompt: settings.systemPrompt,\n toolCategories: settings.toolCategories,\n toolAccess: toolAccessFor(context),\n /* The stop notice is a sentence a person reads — the server writes it in their language (ADR-0054). */\n t,\n hostContext: input.hostContext,\n /*\n * 근거는 도구 결과만이 아니다 — 시스템 프롬프트 · 이 대화의 말 · 화면이 보낸 스냅숏도 근거다\n * (`ai-client-base/utils/grounding`). 이 문은 그 셋을 넘기지 않아, **사람이 방금 타이핑한\n * 식별자**를 되받아 적은 답이 「근거 없음」으로 표시됐다. 그런 경고가 몇 번 나오면 사람이 경고\n * 자체를 안 보게 된다.\n */\n groundingSources: groundingSourcesFor({\n systemPrompt: settings.systemPrompt,\n messages: conversation as any,\n hostContext: input.hostContext\n }),\n state: context.state,\n model: settings.model,\n temperature: settings.temperature,\n maxTokens: settings.maxTokens,\n requireToolOnFirstTurn: settings.requireToolOnFirstTurn\n })\n\n /*\n * 이 답이 지나온 문 — ADR-0073 판정 1. 행에도, 목록 미리보기에도 같은 값이 간다. 한쪽만 적으면\n * 가려진 답이 목록에는 그대로 뜬다.\n */\n const answerDoors = doorsForAnswer(\n (result.loop.toolUsages ?? []).map((usage: any) => usage?.name).filter(Boolean),\n name => (findToolSpec(name, settings.toolCategories) as any)?.doors\n )\n\n let assistantMessageId: string | undefined\n if (session) {\n const stored = await messageRepo.save({\n session: { id: session.id } as any,\n role: 'assistant',\n content: result.reply,\n /*\n * 이 답이 지나온 문을 함께 적는다 — ADR-0073 판정 1. 방은 도메인 안에서 공개이므로, 이 문장이\n * 실어 나르는 값을 나중에 읽는 사람이 열 수 있는지 판정할 근거가 행에 있어야 한다. 적지 않으면\n * 빈 목록이 되고, 빈 목록은 누구나 읽는다는 뜻이다.\n */\n doors: answerDoors,\n toolUsages: result.loop.toolUsages?.length ? JSON.stringify(result.loop.toolUsages) : undefined,\n groundingWarnings: result.groundingWarnings?.length ? JSON.stringify(result.groundingWarnings) : undefined,\n creator: user,\n updater: user,\n parentMessage: userMessageId ? ({ id: userMessageId } as any) : undefined\n })\n assistantMessageId = stored.id\n\n publishChatMessage({ domainId: domain.id, sessionId: session.id, message: stored } as any)\n /* The reply is session activity too. Leaving it out shows other participants \"nothing new\". */\n publishSessionActivity({\n domainId: domain.id,\n sessionId: session.id!,\n kind: 'message',\n anchorType: (session as any).anchorType,\n anchorId: (session as any).anchorId,\n preview: result.reply,\n actorId: user?.id\n })\n\n await sessionRepo.update(session.id!, {\n aiClientId: client.id,\n updater: user,\n ...activityPatch(result.reply, new Date(), answerDoors)\n } as any)\n\n /*\n * 상한 밖으로 밀려난 앞부분을 요약으로 접는다 — **답을 돌려준 뒤**에 한다(사용자 대기 시간에\n * 요약 호출을 얹지 않는다). 기다리지 않으므로 실패해도 대화에는 영향이 없다: 요약이 없으면 다음\n * 턴이 「N 개 생략」으로 정직하게 알린다.\n *\n * 이 문에는 이 호출이 없었다. 조각은 다 있었는데(상한 · 생략 알림 · `lastSummary` · 순수 규칙)\n * 부르는 쪽이 보드 제품 하나뿐이어서, 앱의 대화는 며칠이 지나도 앞부분을 요약하지 않고 매 턴\n * 「생략했다」고만 말했다 — 협의가 길어질수록 처음에 합의한 것이 먼저 사라진다.\n */\n void foldSessionHistory({\n sessionId: session.id!,\n domainId: domain.id,\n client,\n maxTurns: LLM_HISTORY_MAX_TURNS,\n locale: context.state?.locale\n })\n }\n\n return {\n reply: result.reply,\n clientId: client.id,\n sessionId: session?.id,\n userMessageId,\n assistantMessageId,\n toolUsages: result.loop.toolUsages?.length ? result.loop.toolUsages : null,\n offeredTools: result.offeredTools,\n proposals: result.loop.proposals?.length ? result.loop.proposals : null,\n groundingWarnings: result.groundingWarnings?.length ? result.groundingWarnings : null,\n historyFolded: historyFolded ?? null\n }\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import '@things-factory/auth-base';
2
+ declare class AssistantModeSlashView {
3
+ name: string;
4
+ description: string;
5
+ template: string;
6
+ }
7
+ declare class AssistantModeView {
8
+ kind: string;
9
+ slashTemplates: AssistantModeSlashView[];
10
+ catalogEntries: any[];
11
+ proposalChoices: any[];
12
+ placeholder?: string;
13
+ footerNotice?: string;
14
+ stagedNotice?: string;
15
+ }
16
+ declare class AssistantModeChoice {
17
+ kind: string;
18
+ label: string;
19
+ isDefault: boolean;
20
+ }
21
+ export declare class AssistantModeResolver {
22
+ assistantModes(subject: string, context: any): Promise<AssistantModeChoice[]>;
23
+ assistantMode(kind: string, context: any): Promise<AssistantModeView>;
24
+ }
25
+ export {};
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AssistantModeResolver = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /*
6
+ * The screen asks what its conversation offers.
7
+ *
8
+ * The `/` sentences, the `@` catalog and the two notices used to travel from the browser into the
9
+ * request, which meant the screen and the door could describe the same conversation differently.
10
+ * They are declared once, in the mode, as i18n keys — and this query hands them over already
11
+ * written in the request's locale (ADR-0054, and the same rule A11 applied to the stop notice).
12
+ * The persona, the tool categories and the limits stay on the server: nothing here returns them.
13
+ */
14
+ const type_graphql_1 = require("type-graphql");
15
+ const graphql_scalars_1 = require("graphql-scalars");
16
+ require("@things-factory/auth-base");
17
+ const resolve_js_1 = require("./resolve.js");
18
+ const registry_js_1 = require("./registry.js");
19
+ const request_translator_js_1 = require("../request-translator.js");
20
+ let AssistantModeSlashView = class AssistantModeSlashView {
21
+ };
22
+ tslib_1.__decorate([
23
+ (0, type_graphql_1.Field)({ description: 'Short name shown in the list.' }),
24
+ tslib_1.__metadata("design:type", String)
25
+ ], AssistantModeSlashView.prototype, "name", void 0);
26
+ tslib_1.__decorate([
27
+ (0, type_graphql_1.Field)({ description: 'One line about what it does.' }),
28
+ tslib_1.__metadata("design:type", String)
29
+ ], AssistantModeSlashView.prototype, "description", void 0);
30
+ tslib_1.__decorate([
31
+ (0, type_graphql_1.Field)({ description: 'The sentence that lands in the input.' }),
32
+ tslib_1.__metadata("design:type", String)
33
+ ], AssistantModeSlashView.prototype, "template", void 0);
34
+ AssistantModeSlashView = tslib_1.__decorate([
35
+ (0, type_graphql_1.ObjectType)({ description: 'One `/` sentence, in the words of this request.' })
36
+ ], AssistantModeSlashView);
37
+ let AssistantModeView = class AssistantModeView {
38
+ };
39
+ tslib_1.__decorate([
40
+ (0, type_graphql_1.Field)({ description: 'The mode kind this describes.' }),
41
+ tslib_1.__metadata("design:type", String)
42
+ ], AssistantModeView.prototype, "kind", void 0);
43
+ tslib_1.__decorate([
44
+ (0, type_graphql_1.Field)(() => [AssistantModeSlashView], { description: 'What `/` offers.' }),
45
+ tslib_1.__metadata("design:type", Array)
46
+ ], AssistantModeView.prototype, "slashTemplates", void 0);
47
+ tslib_1.__decorate([
48
+ (0, type_graphql_1.Field)(() => graphql_scalars_1.GraphQLJSON, { description: 'What `@` offers.' }),
49
+ tslib_1.__metadata("design:type", Array)
50
+ ], AssistantModeView.prototype, "catalogEntries", void 0);
51
+ tslib_1.__decorate([
52
+ (0, type_graphql_1.Field)(() => graphql_scalars_1.GraphQLJSON, { description: 'Follow-up chips for a proposal that arrived without its own.' }),
53
+ tslib_1.__metadata("design:type", Array)
54
+ ], AssistantModeView.prototype, "proposalChoices", void 0);
55
+ tslib_1.__decorate([
56
+ (0, type_graphql_1.Field)({ nullable: true, description: 'What the empty input says — what this conversation is for.' }),
57
+ tslib_1.__metadata("design:type", String)
58
+ ], AssistantModeView.prototype, "placeholder", void 0);
59
+ tslib_1.__decorate([
60
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The line under an empty conversation.' }),
61
+ tslib_1.__metadata("design:type", String)
62
+ ], AssistantModeView.prototype, "footerNotice", void 0);
63
+ tslib_1.__decorate([
64
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The line shown once the host reports a proposal staged.' }),
65
+ tslib_1.__metadata("design:type", String)
66
+ ], AssistantModeView.prototype, "stagedNotice", void 0);
67
+ AssistantModeView = tslib_1.__decorate([
68
+ (0, type_graphql_1.ObjectType)({ description: 'What a conversation offers on screen.' })
69
+ ], AssistantModeView);
70
+ let AssistantModeChoice = class AssistantModeChoice {
71
+ };
72
+ tslib_1.__decorate([
73
+ (0, type_graphql_1.Field)({ description: 'The mode kind to open.' }),
74
+ tslib_1.__metadata("design:type", String)
75
+ ], AssistantModeChoice.prototype, "kind", void 0);
76
+ tslib_1.__decorate([
77
+ (0, type_graphql_1.Field)({ description: 'What to call it where a person chooses — already in the words of this request.' }),
78
+ tslib_1.__metadata("design:type", String)
79
+ ], AssistantModeChoice.prototype, "label", void 0);
80
+ tslib_1.__decorate([
81
+ (0, type_graphql_1.Field)({ description: 'Whether this is the one to open when the person has not chosen.' }),
82
+ tslib_1.__metadata("design:type", Boolean)
83
+ ], AssistantModeChoice.prototype, "isDefault", void 0);
84
+ AssistantModeChoice = tslib_1.__decorate([
85
+ (0, type_graphql_1.ObjectType)({ description: 'A conversation a screen may open for what it is showing.' })
86
+ ], AssistantModeChoice);
87
+ let AssistantModeResolver = class AssistantModeResolver {
88
+ /*
89
+ * 이 화면이 보여 주는 것으로 열 수 있는 대화들 — ADR-0072 A17 ①.
90
+ *
91
+ * 화면은 자기가 무엇을 보여 주는지(`subject`)만 안다. 그 위에 어느 대화가 서는지는 앱 서버가
92
+ * 선언한다. 화면이 종류 목록을 손으로 들고 있으면, 대화를 하나 더 세운 날 그 화면만 모른 채로 남는다.
93
+ *
94
+ * 하나만 오면 고르개를 내지 않는다 — 고를 것이 없는 고르개는 자리만 차지한다.
95
+ */
96
+ async assistantModes(subject, context) {
97
+ const t = (0, request_translator_js_1.requestTranslator)(context);
98
+ return (0, registry_js_1.assistantModesForSubject)(subject).map(mode => ({
99
+ kind: mode.kind,
100
+ /*
101
+ * 이름이 없는 대화는 종류를 그대로 쓴다. 부팅 보고가 이미 그것을 경고로 말하므로 여기서 숨기지
102
+ * 않는다 — 화면에 `twin.space` 가 뜨면 그것이 빠진 선언을 가리킨다.
103
+ */
104
+ label: mode.labelKey ? t(mode.labelKey) : mode.kind,
105
+ isDefault: (mode.defaultFor ?? []).includes(subject)
106
+ }));
107
+ }
108
+ async assistantMode(kind, context) {
109
+ return (0, resolve_js_1.assistantModeView)(kind, (0, request_translator_js_1.requestTranslator)(context));
110
+ }
111
+ };
112
+ exports.AssistantModeResolver = AssistantModeResolver;
113
+ tslib_1.__decorate([
114
+ (0, type_graphql_1.Query)(() => [AssistantModeChoice], {
115
+ description: 'Conversations that stand for this kind of subject, the default first. A screen showing one subject opens the head of this list and offers the rest; a single entry means there is nothing to choose.'
116
+ }),
117
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query")'),
118
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('subject')),
119
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
120
+ tslib_1.__metadata("design:type", Function),
121
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
122
+ tslib_1.__metadata("design:returntype", Promise)
123
+ ], AssistantModeResolver.prototype, "assistantModes", null);
124
+ tslib_1.__decorate([
125
+ (0, type_graphql_1.Query)(() => AssistantModeView, {
126
+ description: 'What this conversation offers on screen — `/` sentences, the `@` catalog and the notices, translated.'
127
+ })
128
+ /* Reading what a conversation offers is reading, and the same door the session list uses. */
129
+ ,
130
+ (0, type_graphql_1.Directive)('@privilege(category: "ai-assistant", privilege: "query")'),
131
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('kind')),
132
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
133
+ tslib_1.__metadata("design:type", Function),
134
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
135
+ tslib_1.__metadata("design:returntype", Promise)
136
+ ], AssistantModeResolver.prototype, "assistantMode", null);
137
+ exports.AssistantModeResolver = AssistantModeResolver = tslib_1.__decorate([
138
+ (0, type_graphql_1.Resolver)()
139
+ ], AssistantModeResolver);
140
+ //# sourceMappingURL=assistant-mode-resolver.js.map