@things-factory/ai-assistant 10.1.270 → 10.1.272
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/components/assistant-chat.ts +18 -6
- package/client/components/assistant-dock.ts +15 -1
- package/client/components/proposal-request.test.ts +12 -1
- package/client/setup-assistant-dock.ts +30 -15
- package/client/utils/addressed-draft.test.ts +31 -0
- package/client/utils/assistant-ask.ts +7 -0
- package/client/utils/assistant-request-context.ts +10 -0
- package/dist-client/components/assistant-chat.d.ts +6 -0
- package/dist-client/components/assistant-chat.js +23 -6
- package/dist-client/components/assistant-chat.js.map +1 -1
- package/dist-client/components/assistant-dock.js +15 -0
- package/dist-client/components/assistant-dock.js.map +1 -1
- package/dist-client/components/proposal-request.test.js +11 -1
- package/dist-client/components/proposal-request.test.js.map +1 -1
- package/dist-client/setup-assistant-dock.js +30 -15
- package/dist-client/setup-assistant-dock.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/utils/addressed-draft.test.d.ts +1 -0
- package/dist-client/utils/addressed-draft.test.js +27 -0
- package/dist-client/utils/addressed-draft.test.js.map +1 -0
- package/dist-client/utils/assistant-ask.d.ts +10 -0
- package/dist-client/utils/assistant-ask.js.map +1 -1
- package/dist-client/utils/assistant-request-context.d.ts +12 -0
- package/dist-client/utils/assistant-request-context.js +11 -0
- package/dist-client/utils/assistant-request-context.js.map +1 -1
- package/dist-server/service/assistant-chat-resolver.js +5 -2
- package/dist-server/service/assistant-chat-resolver.js.map +1 -1
- package/dist-server/service/assistant-mode/index.d.ts +1 -0
- package/dist-server/service/assistant-mode/index.js +4 -1
- package/dist-server/service/assistant-mode/index.js.map +1 -1
- package/dist-server/service/assistant-mode/turn-lines.d.ts +12 -0
- package/dist-server/service/assistant-mode/turn-lines.js +38 -0
- package/dist-server/service/assistant-mode/turn-lines.js.map +1 -0
- package/dist-server/service/chat-message/index.d.ts +1 -0
- package/dist-server/service/chat-message/index.js +3 -1
- package/dist-server/service/chat-message/index.js.map +1 -1
- package/dist-server/service/chat-message/room-turn.d.ts +31 -0
- package/dist-server/service/chat-message/room-turn.js +30 -0
- package/dist-server/service/chat-message/room-turn.js.map +1 -0
- package/dist-server/service/chat-session-participant/invite-notification.d.ts +20 -4
- package/dist-server/service/chat-session-participant/invite-notification.js +17 -12
- package/dist-server/service/chat-session-participant/invite-notification.js.map +1 -1
- package/dist-server/service/chat-session-participant/mention-invite.d.ts +2 -0
- package/dist-server/service/chat-session-participant/mention-invite.js +5 -0
- package/dist-server/service/chat-session-participant/mention-invite.js.map +1 -1
- package/dist-server/service/chat-session-resolver.d.ts +5 -0
- package/dist-server/service/chat-session-resolver.js +56 -3
- package/dist-server/service/chat-session-resolver.js.map +1 -1
- package/dist-server/service/data-entry/entry-apply.d.ts +2 -0
- package/dist-server/service/data-entry/entry-apply.js +1 -1
- package/dist-server/service/data-entry/entry-apply.js.map +1 -1
- package/dist-server/service/data-entry/entry-resolver.js +2 -1
- package/dist-server/service/data-entry/entry-resolver.js.map +1 -1
- package/dist-server/service/data-entry/entry-target.d.ts +7 -2
- package/dist-server/service/data-entry/entry-target.js.map +1 -1
- package/dist-server/service/people/index.d.ts +2 -0
- package/dist-server/service/people/index.js +9 -1
- package/dist-server/service/people/index.js.map +1 -1
- package/dist-server/service/people/person-subject.d.ts +34 -0
- package/dist-server/service/people/person-subject.js +89 -0
- package/dist-server/service/people/person-subject.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/server/service/assistant-chat-resolver.ts +5 -2
- package/server/service/assistant-mode/index.ts +1 -0
- package/server/service/assistant-mode/open-subject-door.test.ts +7 -2
- package/server/service/assistant-mode/turn-lines.ts +43 -0
- package/server/service/chat-message/index.ts +1 -0
- package/server/service/chat-message/room-turn.ts +42 -0
- package/server/service/chat-session/group-room.test.ts +4 -4
- package/server/service/chat-session-participant/invite-notification.test.ts +12 -12
- package/server/service/chat-session-participant/invite-notification.ts +25 -11
- package/server/service/chat-session-participant/mention-invite.ts +5 -0
- package/server/service/chat-session-resolver.ts +50 -3
- package/server/service/data-entry/entry-apply.ts +3 -1
- package/server/service/data-entry/entry-resolver.ts +2 -1
- package/server/service/data-entry/entry-target.ts +5 -2
- package/server/service/people/index.ts +2 -0
- package/server/service/people/person-subject.test.ts +163 -0
- package/server/service/people/person-subject.ts +88 -0
- package/test/assistant-request-context.test.ts +1 -1
- package/test/open-doors.test.ts +3 -1
- package/translations/en.json +2 -0
- package/translations/es.json +2 -0
- package/translations/ja.json +2 -0
- package/translations/ko.json +2 -0
- package/translations/ms.json +2 -0
- package/translations/zh.json +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/ai-assistant",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.272",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"things-factory": true,
|
|
6
6
|
"author": "heartyoh",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"@operato/shell": "^10.29.69",
|
|
37
37
|
"@operato/styles": "^10.0.0",
|
|
38
38
|
"@operato/utils": "^10.29.76",
|
|
39
|
-
"@things-factory/ai-client-base": "^10.1.
|
|
39
|
+
"@things-factory/ai-client-base": "^10.1.272",
|
|
40
40
|
"@things-factory/apptool-base": "^10.1.270",
|
|
41
|
-
"@things-factory/attachment-base": "^10.1.
|
|
42
|
-
"@things-factory/auth-base": "^10.1.
|
|
41
|
+
"@things-factory/attachment-base": "^10.1.271",
|
|
42
|
+
"@things-factory/auth-base": "^10.1.271",
|
|
43
43
|
"@things-factory/env": "^10.1.149",
|
|
44
44
|
"@things-factory/help": "^10.1.270",
|
|
45
|
-
"@things-factory/setting-base": "^10.1.
|
|
45
|
+
"@things-factory/setting-base": "^10.1.271",
|
|
46
46
|
"@things-factory/shell": "^10.1.270",
|
|
47
47
|
"dompurify": "^3.0.0",
|
|
48
48
|
"exceljs": "4.2.0",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"copyfiles": "^2.4.1",
|
|
60
60
|
"rimraf": "^5.0.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "f87fefe0687eedf52a25cda1c54d59efabaf3dc2"
|
|
63
63
|
}
|
|
@@ -29,6 +29,7 @@ import '@things-factory/auth-base'
|
|
|
29
29
|
import { getRepository, rethrowSpoken } from '@things-factory/shell'
|
|
30
30
|
import { aiClientFor, findToolSpec, openSubjectLine, OPEN_TOOLS, registryAssistantChat, type AgentClient } from '@things-factory/ai-client-base'
|
|
31
31
|
|
|
32
|
+
import { turnLinesOf } from './assistant-mode/turn-lines.js'
|
|
32
33
|
import { ChatSession } from './chat-session/chat-session.js'
|
|
33
34
|
import { assertStationSession } from './chat-session/station-session-guard.js'
|
|
34
35
|
import { ChatMessage } from './chat-message/chat-message.js'
|
|
@@ -321,7 +322,9 @@ export class AssistantChatResolver {
|
|
|
321
322
|
state: context.state
|
|
322
323
|
})
|
|
323
324
|
: undefined
|
|
324
|
-
|
|
325
|
+
/* What the person has in front of them besides the subject - the screen's unread notices (ADR-0199 amendment 1). */
|
|
326
|
+
const screenLines = await turnLinesOf({ page: input.page, state: context.state })
|
|
327
|
+
const systemPrompt = turnSystemPrompt(settings.systemPrompt, { subjectLine: [subjectLine, ...screenLines].filter(Boolean).join('\n\n') || undefined, page: input.page })
|
|
325
328
|
|
|
326
329
|
const lastUserMessage = input.messages[input.messages.length - 1]
|
|
327
330
|
let userMessageId: string | undefined
|
|
@@ -395,7 +398,7 @@ export class AssistantChatResolver {
|
|
|
395
398
|
visibility: (session as any).visibility
|
|
396
399
|
})
|
|
397
400
|
/* 편지가 못 갔다고 방에 들어온 사실이 취소되지는 않는다(`sendInviteNotification`). */
|
|
398
|
-
await sendInviteNotification((context.state as any)?.
|
|
401
|
+
await sendInviteNotification((context.state as any)?.sendNotice, invite.invited, user, (session as any)?.name, undefined, requestTranslator(context))
|
|
399
402
|
|
|
400
403
|
publishChatMessage({ domainId: domain.id, sessionId: session.id, message: saved } as any)
|
|
401
404
|
publishSessionActivity({
|
|
@@ -19,3 +19,4 @@ export { recordSubjectDescriber, registerRecordSubject, type RecordSubject } fro
|
|
|
19
19
|
export { ABSENCE_RULE, FINISH_RULE, NEXT_REQUEST_RULE, SELECTION_RULE, SPEAKER_RULE, conversationPrompt, isPersonRequest, splitNextRequest } from './screen-rules.js'
|
|
20
20
|
export type { AssistantModeSpec, AssistantModeSlash, AssistantModeWarning, UnattendedLimits } from './types.js'
|
|
21
21
|
export type { AssistantModeRef, ModeSettings, AssistantModeView, AssistantModeSlashView, Translate } from './resolve.js'
|
|
22
|
+
export { registerTurnLine, turnLinesOf, type TurnLine, type TurnLineInput } from './turn-lines.js'
|
|
@@ -12,8 +12,13 @@ describe('the door', () => {
|
|
|
12
12
|
expect(block).toMatch(/anchorType: \(session as any\)\.anchorType/)
|
|
13
13
|
expect(block).toMatch(/anchorId: \(session as any\)\.anchorId/)
|
|
14
14
|
expect(block).not.toMatch(/hostContext/)
|
|
15
|
-
/*
|
|
16
|
-
|
|
15
|
+
/*
|
|
16
|
+
* The page adds its category's rule, never a line of the screen's. A module's line (the screen's unread notices,
|
|
17
|
+
* ADR-0199 amendment 1) is read on the server from the asker's own records - the page only narrows them; nothing
|
|
18
|
+
* the screen sent goes in.
|
|
19
|
+
*/
|
|
20
|
+
expect(door).toMatch(/const screenLines = await turnLinesOf\(\{ page: input\.page, state: context\.state \}\)/)
|
|
21
|
+
expect(door).toMatch(/const systemPrompt = turnSystemPrompt\(settings\.systemPrompt, \{ subjectLine: \[subjectLine, \.\.\.screenLines\]\.filter\(Boolean\)\.join\('\\n\\n'\) \|\| undefined, page: input\.page \}\)/)
|
|
17
22
|
})
|
|
18
23
|
|
|
19
24
|
it('★ the model and the grounding check both read the prompt with the line', () => {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Lines a module adds to one turn's system prompt, after the open subject's - what the person has in front of them that
|
|
3
|
+
* the conversation does not hold. notification says the unread notices of the screen the dock is on, so the assistant
|
|
4
|
+
* knows what the person was told there (ADR-0199 amendment 1).
|
|
5
|
+
*
|
|
6
|
+
* A line is the module's to build from the asker's own records, read as them; a value a person typed goes in as data.
|
|
7
|
+
* One that fails is left out - a turn is never refused for a line.
|
|
8
|
+
*/
|
|
9
|
+
import { logger } from '@things-factory/env'
|
|
10
|
+
|
|
11
|
+
export interface TurnLineInput {
|
|
12
|
+
/** The application's route of the open page, as the dock sends it - it only narrows what is the asker's own. */
|
|
13
|
+
page?: string
|
|
14
|
+
/** The request state - domain and user. */
|
|
15
|
+
state: any
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type TurnLine = (input: TurnLineInput) => string | undefined | Promise<string | undefined>
|
|
19
|
+
|
|
20
|
+
const lines = new Map<string, TurnLine>()
|
|
21
|
+
|
|
22
|
+
/** A module adds its line, by name - a second registration of the name replaces the first. */
|
|
23
|
+
export function registerTurnLine(name: string, line: TurnLine): void {
|
|
24
|
+
lines.set(name, line)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function turnLinesOf(input: TurnLineInput): Promise<string[]> {
|
|
28
|
+
const said: string[] = []
|
|
29
|
+
for (const [name, line] of lines) {
|
|
30
|
+
try {
|
|
31
|
+
const one = await line(input)
|
|
32
|
+
if (one) said.push(one)
|
|
33
|
+
} catch (error: any) {
|
|
34
|
+
logger.error(`[ai-assistant/turn-lines] ${name} failed: ${error?.message ?? error}`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return said
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Test only. */
|
|
41
|
+
export function clearTurnLines(): void {
|
|
42
|
+
lines.clear()
|
|
43
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A person spoke to the people of a conversation - told to the modules that wait for it. worklist closes a question it
|
|
3
|
+
* handed to that person once they answer in the conversation it came from (ADR-0200 decision 3).
|
|
4
|
+
*
|
|
5
|
+
* Only the door that stores words to the room tells (`sendRoomMessage`): what the person asks the assistant - polish
|
|
6
|
+
* my draft - is not their answer.
|
|
7
|
+
*/
|
|
8
|
+
import { logger } from '@things-factory/env'
|
|
9
|
+
|
|
10
|
+
export interface RoomTurn {
|
|
11
|
+
domain: { id: string }
|
|
12
|
+
/** Who spoke. */
|
|
13
|
+
user: { id: string; name?: string; email?: string }
|
|
14
|
+
session: { id: string; anchorType?: string | null; anchorId?: string | null }
|
|
15
|
+
/** The message as stored. */
|
|
16
|
+
message: { id: string; content: string }
|
|
17
|
+
/** The request's transaction - a listener writes in it, so the turn and what it closed stand or fall together. */
|
|
18
|
+
tx?: any
|
|
19
|
+
/** The request's translator. */
|
|
20
|
+
t?: (key: string, options?: any) => string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Listener = (turn: RoomTurn) => void | Promise<void>
|
|
24
|
+
|
|
25
|
+
const listeners = new Set<Listener>()
|
|
26
|
+
|
|
27
|
+
/** A module waits for people's words in conversations. Answers the way to stop. */
|
|
28
|
+
export function onRoomTurn(listener: Listener): () => void {
|
|
29
|
+
listeners.add(listener)
|
|
30
|
+
return () => listeners.delete(listener)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Every listener hears the turn; one that fails is logged and does not stop the person's words. */
|
|
34
|
+
export async function tellRoomTurn(turn: RoomTurn): Promise<void> {
|
|
35
|
+
for (const listener of listeners) {
|
|
36
|
+
try {
|
|
37
|
+
await listener(turn)
|
|
38
|
+
} catch (error: any) {
|
|
39
|
+
logger.error(`[ai-assistant/room-turn] a listener failed for session ${turn.session.id}: ${error?.message ?? error}`)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -41,8 +41,8 @@ let enteredAs: string[]
|
|
|
41
41
|
const doors = new ChatSessionResolver()
|
|
42
42
|
const entry = new EntryProposalResolver()
|
|
43
43
|
|
|
44
|
-
/** A request as that person - the state a door reads. `
|
|
45
|
-
const as = (user: any) => ({ state: { domain, user,
|
|
44
|
+
/** A request as that person - the state a door reads. `sendNotice` (notification) keeps what an invite sends. */
|
|
45
|
+
const as = (user: any) => ({ state: { domain, user, sendNotice: (notice: any) => notices.push({ receivers: notice.receivers.map((one: any) => one.id), body: notice.words('ko').body }) } }) as any
|
|
46
46
|
|
|
47
47
|
beforeAll(async () => {
|
|
48
48
|
db = new TypeOrmDataSource({
|
|
@@ -131,7 +131,7 @@ describe('a group conversation', () => {
|
|
|
131
131
|
|
|
132
132
|
it('★ the owner brings someone in - they are told, and from then on they read and write', async () => {
|
|
133
133
|
expect(await doors.inviteToAISession(session.id, [guest.id], as(owner))).toEqual([guest.id])
|
|
134
|
-
expect(notices
|
|
134
|
+
expect(notices).toHaveLength(1)
|
|
135
135
|
expect(notices[0].receivers).toEqual([guest.id])
|
|
136
136
|
expect(notices[0].body).toContain('pricing')
|
|
137
137
|
|
|
@@ -163,7 +163,7 @@ describe('a group conversation', () => {
|
|
|
163
163
|
it("the owner's mention seats, as the invite does", async () => {
|
|
164
164
|
await doors.sayToRoom(session.id, `see @guest{userId:${guest.id}}`, undefined, as(owner))
|
|
165
165
|
expect(await roomHears(guest)).toBe(true)
|
|
166
|
-
expect(notices.map(n => n.receivers)).toEqual([[guest.id]
|
|
166
|
+
expect(notices.map(n => n.receivers)).toEqual([[guest.id]])
|
|
167
167
|
})
|
|
168
168
|
|
|
169
169
|
it('a person outside the domain is not seated', async () => {
|
|
@@ -44,23 +44,23 @@ describe('an invite outside a board', () => {
|
|
|
44
44
|
})
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
describe('sendInviteNotification —
|
|
48
|
-
test('★ the invite
|
|
47
|
+
describe('sendInviteNotification — one kept notice', () => {
|
|
48
|
+
test('★ the invite is one notice to the people seated, kept by notification, at the board when there is one', async () => {
|
|
49
49
|
const sent: any[] = []
|
|
50
|
-
await sendInviteNotification(
|
|
51
|
-
expect(sent
|
|
52
|
-
expect(sent.
|
|
50
|
+
await sendInviteNotification(notice => void sent.push(notice), ['u1', 'u2'], { name: 'Kim' }, 'pricing', 'board-7')
|
|
51
|
+
expect(sent).toHaveLength(1)
|
|
52
|
+
expect(sent[0]).toMatchObject({ type: 'board-collab-invite', receivers: [{ id: 'u1' }, { id: 'u2' }], address: 'board-modeller/board-7' })
|
|
53
|
+
expect(sent[0].words('ko')).toMatchObject({ subject: 'Board collaboration invite', summary: 'Kim invited you to collaborate on a board.' })
|
|
53
54
|
})
|
|
54
55
|
|
|
55
|
-
test('a
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (payload.mode === 'foreground') throw new Error('down')
|
|
59
|
-
sent.push(payload)
|
|
56
|
+
test('a notice that fails does not undo the seat, and nobody to tell sends nothing', async () => {
|
|
57
|
+
await sendInviteNotification(() => {
|
|
58
|
+
throw new Error('down')
|
|
60
59
|
}, ['u1'], null)
|
|
61
|
-
|
|
62
|
-
await sendInviteNotification(
|
|
60
|
+
const sent: any[] = []
|
|
61
|
+
await sendInviteNotification(notice => void sent.push(notice), [], null)
|
|
63
62
|
await sendInviteNotification(undefined, ['u1'], null)
|
|
63
|
+
expect(sent).toEqual([])
|
|
64
64
|
})
|
|
65
65
|
})
|
|
66
66
|
|
|
@@ -76,15 +76,24 @@ export function buildInviteNotification(
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/** notification's `sendNotice` (ADR-0164 amendment 1) - the request state carries it when notification is loaded. */
|
|
80
|
+
export type SendNotice = (notice: {
|
|
81
|
+
type: string
|
|
82
|
+
receivers: { id: string }[]
|
|
83
|
+
words: (lng: string) => { subject: string; summary: string; body: string; action: string; note: string }
|
|
84
|
+
address: string
|
|
85
|
+
label: string
|
|
86
|
+
}) => unknown
|
|
87
|
+
|
|
79
88
|
/**
|
|
80
|
-
* Tell the people just seated -
|
|
81
|
-
*
|
|
82
|
-
*
|
|
89
|
+
* Tell the people just seated - kept for each of them, so their inbox has it on every device, live to the screens they
|
|
90
|
+
* have open and by web push (notification's `sendNotice`). Until 2026-11-11 the invite went as a live signal and a
|
|
91
|
+
* push only: one not looking at the app when invited never saw it in the inbox.
|
|
83
92
|
*
|
|
84
93
|
* A letter that does not arrive does not undo the seat - the roster is the record, the notice only tells of it.
|
|
85
94
|
*/
|
|
86
95
|
export async function sendInviteNotification(
|
|
87
|
-
|
|
96
|
+
sendNotice: SendNotice | undefined,
|
|
88
97
|
userIds: string[],
|
|
89
98
|
inviter: Inviter | undefined | null,
|
|
90
99
|
sessionName?: string | null,
|
|
@@ -93,12 +102,17 @@ export async function sendInviteNotification(
|
|
|
93
102
|
t?: InviteTranslate
|
|
94
103
|
): Promise<void> {
|
|
95
104
|
const payload = buildInviteNotification(userIds, boardId, inviter, sessionName, t)
|
|
96
|
-
if (!payload ||
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/* the
|
|
102
|
-
|
|
105
|
+
if (!payload || typeof sendNotice !== 'function') return
|
|
106
|
+
try {
|
|
107
|
+
await sendNotice({
|
|
108
|
+
type: payload.type,
|
|
109
|
+
receivers: payload.receivers.map(id => ({ id })),
|
|
110
|
+
/* the inviting request's language - the people of one domain read one (see above) */
|
|
111
|
+
words: () => ({ subject: payload.title, summary: payload.body, body: payload.body, action: payload.title, note: '' }),
|
|
112
|
+
address: payload.url ?? '',
|
|
113
|
+
label: `${payload.type} to ${payload.receivers.length}`
|
|
114
|
+
})
|
|
115
|
+
} catch {
|
|
116
|
+
/* the seat stands */
|
|
103
117
|
}
|
|
104
118
|
}
|
|
@@ -27,6 +27,11 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import { isOpenRoom, maySeat } from '../chat-session/session-visibility.js'
|
|
29
29
|
|
|
30
|
+
/** The text as a person reads it - `@Admin{userId:UUID}` is `@Admin`. Kept where a turn's words are stored as an answer. */
|
|
31
|
+
export function withoutMentionIds(text: string): string {
|
|
32
|
+
return text.replace(/\{userId:[^}\s]+\}/g, '')
|
|
33
|
+
}
|
|
34
|
+
|
|
30
35
|
/** 본문에서 `@user{userId:UUID}` 마커의 userId 를 뽑는다 — 첫 등장 순, 중복 제거. */
|
|
31
36
|
export function extractMentionUserIds(text: string | null | undefined): string[] {
|
|
32
37
|
if (!text) return []
|
|
@@ -21,6 +21,8 @@ import { roomMessageBody } from './chat-message/room-message.js'
|
|
|
21
21
|
import { readerGate } from './chat-message/reader-gate.js'
|
|
22
22
|
import { requestTranslator } from './request-translator.js'
|
|
23
23
|
import { initialVisibility, isOpenRoom, mayReadSession, maySeat, SESSION_VISIBILITIES } from './chat-session/session-visibility.js'
|
|
24
|
+
import { PERSON_ROOM_REFUSALS, personOfAnchor, personRoomRefusal, personSeatOf } from './people/person-subject.js'
|
|
25
|
+
import { tellRoomTurn } from './chat-message/room-turn.js'
|
|
24
26
|
import { seatParticipants, seatTurn } from './chat-session-participant/mention-invite.js'
|
|
25
27
|
import { CHAT_TYPING_TOPIC, typingNotice } from './chat-message/chat-typing.js'
|
|
26
28
|
import { sendInviteNotification } from './chat-session-participant/invite-notification.js'
|
|
@@ -41,7 +43,7 @@ const inboxReads = new WeakMap<object, Map<string, Promise<any[]>>>()
|
|
|
41
43
|
|
|
42
44
|
/** 초대 알림 — 발송은 호스트의 기전을 그대로 쓴다(`sendInviteNotification`, 문 셋이 같은 한 곳). */
|
|
43
45
|
async function notifyInvited(context: any, invited: string[], inviter: any, sessionName?: string): Promise<void> {
|
|
44
|
-
await sendInviteNotification(context.state?.
|
|
46
|
+
await sendInviteNotification((context.state as any)?.sendNotice, invited, inviter, sessionName, undefined, requestTranslator(context))
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/**
|
|
@@ -223,6 +225,29 @@ function attachmentRefusalMessage(refusal: AttachmentRefusal, context: any): str
|
|
|
223
225
|
}
|
|
224
226
|
}
|
|
225
227
|
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* A conversation about someone seats them as it is made - they read whatever is asked of their records (ADR-0200).
|
|
231
|
+
* Their seat is a member's, given by the one who started it, as an invite gives it.
|
|
232
|
+
*/
|
|
233
|
+
async function seatPersonOf(session: any, starter: any, tx: any): Promise<void> {
|
|
234
|
+
const seat = personSeatOf(session.anchorType, session.anchorId, starter)
|
|
235
|
+
if (!seat) return
|
|
236
|
+
await getRepository(ChatSessionParticipant, tx).save({
|
|
237
|
+
domain: session.domain,
|
|
238
|
+
session: { id: session.id } as any,
|
|
239
|
+
user: { id: seat.userId } as any,
|
|
240
|
+
role: 'member',
|
|
241
|
+
creator: starter,
|
|
242
|
+
updater: starter
|
|
243
|
+
} as any)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** A conversation about someone stays a group they sit in - said in the asker's words when a change would undo that. */
|
|
247
|
+
function refusePersonRoom(session: any, change: { visibility?: string; removing?: string }, context: ResolverContext): void {
|
|
248
|
+
const refusal = session && personRoomRefusal({ ...session, creatorId: session.creatorId }, change)
|
|
249
|
+
if (refusal) throw new Error(requestTranslator(context)(`ai-assistant.text.${refusal}`, { defaultValue: PERSON_ROOM_REFUSALS[refusal] }))
|
|
250
|
+
}
|
|
226
251
|
@Resolver()
|
|
227
252
|
export class ChatSessionResolver {
|
|
228
253
|
@Query(() => ChatSession, { nullable: true, description: 'Get AI chat session by id.' })
|
|
@@ -628,6 +653,7 @@ export class ChatSessionResolver {
|
|
|
628
653
|
if (mine?.role !== 'owner') return false
|
|
629
654
|
|
|
630
655
|
if ((session as any).visibility === visibility) return true
|
|
656
|
+
refusePersonRoom(session, { visibility }, context)
|
|
631
657
|
|
|
632
658
|
/*
|
|
633
659
|
* Private is the owner's alone (ADR-0073 decision 3). The members leave with the change - a private room
|
|
@@ -724,6 +750,7 @@ export class ChatSessionResolver {
|
|
|
724
750
|
}
|
|
725
751
|
const theirs = seats.find(seat => (seat as any).userId === userId && seat.role === 'member')
|
|
726
752
|
if (!theirs) return false
|
|
753
|
+
refusePersonRoom(await getRepository(ChatSession).findOneBy({ id: sessionId, domain: { id: domain.id } as any }), { removing: userId }, context)
|
|
727
754
|
return await this._leave(sessionId, theirs, context)
|
|
728
755
|
}
|
|
729
756
|
|
|
@@ -745,6 +772,7 @@ export class ChatSessionResolver {
|
|
|
745
772
|
throw new Error(requestTranslator(context)('ai-assistant.text.owner-cannot-leave', { defaultValue: 'you started this conversation, so you cannot leave it. delete it, or make it private.' }))
|
|
746
773
|
}
|
|
747
774
|
if (mine?.role !== 'member') return false
|
|
775
|
+
refusePersonRoom(await getRepository(ChatSession).findOneBy({ id: sessionId, domain: { id: domain.id } as any }), { removing: user.id }, context)
|
|
748
776
|
return await this._leave(sessionId, mine, context)
|
|
749
777
|
}
|
|
750
778
|
|
|
@@ -900,6 +928,22 @@ export class ChatSessionResolver {
|
|
|
900
928
|
return maySeat((session as any).visibility, seat?.role)
|
|
901
929
|
}
|
|
902
930
|
|
|
931
|
+
/**
|
|
932
|
+
* The person this conversation is about, who always reads it (ADR-0200) - the screen offers no way to send them out,
|
|
933
|
+
* and keeps no copy of the rule. The doors refuse again.
|
|
934
|
+
*/
|
|
935
|
+
@Query(() => String, {
|
|
936
|
+
nullable: true,
|
|
937
|
+
description: 'The user this conversation is about, who cannot be sent out of it - none for any other conversation. A hint for the screen; the doors decide again.'
|
|
938
|
+
})
|
|
939
|
+
@Directive('@privilege(category: "ai-assistant", privilege: "query", domainOwnerGranted: true)')
|
|
940
|
+
async keptInAISession(@Arg('sessionId') sessionId: string, @Ctx() context: ResolverContext): Promise<string | null> {
|
|
941
|
+
const { domain } = context.state
|
|
942
|
+
const session: any = await getRepository(ChatSession).findOneBy({ id: sessionId, domain: { id: domain.id } as any })
|
|
943
|
+
const personId = session && personOfAnchor(session.anchorType, session.anchorId)
|
|
944
|
+
return personId && personRoomRefusal(session, { removing: personId }) ? personId : null
|
|
945
|
+
}
|
|
946
|
+
|
|
903
947
|
@Mutation(() => Boolean, {
|
|
904
948
|
description: 'Presence heartbeat — bump current user\'s lastSeenAt in the session (online indicator).'
|
|
905
949
|
})
|
|
@@ -977,7 +1021,7 @@ export class ChatSessionResolver {
|
|
|
977
1021
|
domain,
|
|
978
1022
|
...anchorColumns(anchorType, anchorId),
|
|
979
1023
|
/* 새 대화는 비공개로 태어난다 — 공개는 owner 가 고른다(ADR-0073 결정 2, 2026-09-30 고침). */
|
|
980
|
-
visibility: initialVisibility({ anchorType }),
|
|
1024
|
+
visibility: personSeatOf(anchorType, anchorId, user)?.visibility ?? initialVisibility({ anchorType }),
|
|
981
1025
|
creator: user,
|
|
982
1026
|
updater: user
|
|
983
1027
|
} as any)
|
|
@@ -990,6 +1034,7 @@ export class ChatSessionResolver {
|
|
|
990
1034
|
creator: user,
|
|
991
1035
|
updater: user
|
|
992
1036
|
} as any)
|
|
1037
|
+
await seatPersonOf(session, user, tx)
|
|
993
1038
|
return session
|
|
994
1039
|
}
|
|
995
1040
|
|
|
@@ -1014,7 +1059,7 @@ export class ChatSessionResolver {
|
|
|
1014
1059
|
const session = await repo.save({
|
|
1015
1060
|
domain,
|
|
1016
1061
|
...anchorColumns(anchorType, anchorId),
|
|
1017
|
-
visibility: initialVisibility({ anchorType }),
|
|
1062
|
+
visibility: personSeatOf(anchorType, anchorId, user)?.visibility ?? initialVisibility({ anchorType }),
|
|
1018
1063
|
creator: user,
|
|
1019
1064
|
updater: user,
|
|
1020
1065
|
name: finalName
|
|
@@ -1028,6 +1073,7 @@ export class ChatSessionResolver {
|
|
|
1028
1073
|
creator: user,
|
|
1029
1074
|
updater: user
|
|
1030
1075
|
} as any)
|
|
1076
|
+
await seatPersonOf(session, user, tx)
|
|
1031
1077
|
return session
|
|
1032
1078
|
}
|
|
1033
1079
|
|
|
@@ -1233,6 +1279,7 @@ export class ChatSessionResolver {
|
|
|
1233
1279
|
visibility: (session as any).visibility
|
|
1234
1280
|
})
|
|
1235
1281
|
await notifyInvited(context, invite.invited, user, (session as any).name)
|
|
1282
|
+
await tellRoomTurn({ domain, user, session: session as any, message: saved as any, tx, t: requestTranslator(context) })
|
|
1236
1283
|
|
|
1237
1284
|
/* 사람의 말이다 — 목록의 최근 활동과 다른 참여자의 안 읽음이 이것으로 움직인다. */
|
|
1238
1285
|
try {
|
|
@@ -61,6 +61,8 @@ export interface EntryApplyDeps {
|
|
|
61
61
|
report?(message: string, error: unknown): void
|
|
62
62
|
/** The fingerprint of what the AI 작업 패널 showed, when the person reviewed it there - entered only if the proposal is still that one. */
|
|
63
63
|
reviewedHash?: string
|
|
64
|
+
/** The conversation the card is in - a row about the conversation itself takes it (a question handed on, ADR-0200). */
|
|
65
|
+
sessionId?: string
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
const nothing = (verdict: EntryApplyOutcome['verdict'], errorCode: string): EntryApplyOutcome => ({ verdict, errorCode, applied: 0, missed: 0, rows: [] })
|
|
@@ -155,7 +157,7 @@ export async function applyEntryProposal(key: string, deps: EntryApplyDeps, targ
|
|
|
155
157
|
continue
|
|
156
158
|
}
|
|
157
159
|
try {
|
|
158
|
-
const answer = await deps.execute(target.mutation, target.variables!(row))
|
|
160
|
+
const answer = await deps.execute(target.mutation, target.variables!(row, { sessionId: deps.sessionId }))
|
|
159
161
|
if (answer.errors?.length) {
|
|
160
162
|
results.push({ index: row.index, ok: false, error: answer.errors.map(one => one.message).join('; ') || 'refused' })
|
|
161
163
|
continue
|
|
@@ -67,7 +67,8 @@ export class EntryProposalResolver {
|
|
|
67
67
|
*/
|
|
68
68
|
execute: runAsCaller(context),
|
|
69
69
|
report: (message, error) => logger.error(message, error),
|
|
70
|
-
reviewedHash: reviewedHash || undefined
|
|
70
|
+
reviewedHash: reviewedHash || undefined,
|
|
71
|
+
sessionId: session.id
|
|
71
72
|
})
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -159,8 +159,11 @@ export interface EntryTarget {
|
|
|
159
159
|
* to a person typing it in.
|
|
160
160
|
*/
|
|
161
161
|
mutation: string
|
|
162
|
-
/**
|
|
163
|
-
|
|
162
|
+
/**
|
|
163
|
+
* The mutation's variables for one row. Absent when the target enters rows by group (below). `card.sessionId` is the
|
|
164
|
+
* conversation the card was pressed in - for a record about the conversation itself, never a value the model wrote.
|
|
165
|
+
*/
|
|
166
|
+
variables?(row: EntryRow, card?: { sessionId?: string }): Record<string, unknown>
|
|
164
167
|
/** What the conversation says of an entered row - its id and a short name. */
|
|
165
168
|
appliedOf?(data: any, row: EntryRow): EntryApplied | undefined
|
|
166
169
|
/**
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
import { registerReadTarget } from '../data-read/read-tools.js'
|
|
6
6
|
import { peopleReadTarget } from './people-read.js'
|
|
7
7
|
import './invite-tools.js'
|
|
8
|
+
import './person-subject.js'
|
|
8
9
|
|
|
9
10
|
registerReadTarget(peopleReadTarget())
|
|
10
11
|
|
|
11
12
|
export * from './people-keys.js'
|
|
12
13
|
export { peopleReadTarget, PEOPLE_SELECTION } from './people-read.js'
|
|
14
|
+
export { PERSON_AXIS, PERSON_QUESTION_KEY, PERSON_GUIDANCE, personOfAnchor, personSeatOf, personRoomRefusal } from './person-subject.js'
|
|
13
15
|
export { proposeInvite, findPeopleNamed, inviteCategory, MAX_INVITE_CANDIDATES, type InviteCandidate } from './invite-tools.js'
|