@things-factory/ai-assistant 10.1.27 → 10.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/components/assistant-chat.ts +701 -63
- package/client/components/assistant-mode.test.ts +105 -55
- package/client/components/assistant-mode.ts +144 -82
- package/client/components/chat-echo-dedup.test.ts +23 -0
- package/client/components/chat-echo-dedup.ts +29 -3
- package/client/components/chat-input-builder.test.ts +20 -20
- package/client/components/chat-input-builder.ts +16 -14
- package/client/components/chat-proposal-survival.test.ts +73 -0
- package/client/components/mention-popup.ts +31 -8
- package/client/components/panel-aria.test.ts +54 -0
- package/client/components/proposal-outcome-line.ts +33 -0
- package/client/utils/assistant-session-controller.test.ts +75 -0
- package/client/utils/assistant-session-controller.ts +37 -1
- package/client/utils/assistant-session-transport.ts +13 -5
- package/dist-client/components/assistant-chat.d.ts +140 -13
- package/dist-client/components/assistant-chat.js +659 -71
- package/dist-client/components/assistant-chat.js.map +1 -1
- package/dist-client/components/assistant-mode.d.ts +102 -68
- package/dist-client/components/assistant-mode.js +79 -19
- package/dist-client/components/assistant-mode.js.map +1 -1
- package/dist-client/components/assistant-mode.test.js +90 -53
- package/dist-client/components/assistant-mode.test.js.map +1 -1
- package/dist-client/components/chat-echo-dedup.d.ts +2 -0
- package/dist-client/components/chat-echo-dedup.js +27 -4
- package/dist-client/components/chat-echo-dedup.js.map +1 -1
- package/dist-client/components/chat-echo-dedup.test.js +20 -0
- package/dist-client/components/chat-echo-dedup.test.js.map +1 -1
- package/dist-client/components/chat-input-builder.d.ts +12 -7
- package/dist-client/components/chat-input-builder.js +8 -10
- package/dist-client/components/chat-input-builder.js.map +1 -1
- package/dist-client/components/chat-input-builder.test.js +17 -18
- package/dist-client/components/chat-input-builder.test.js.map +1 -1
- package/dist-client/components/chat-proposal-survival.test.d.ts +1 -0
- package/dist-client/components/chat-proposal-survival.test.js +61 -0
- package/dist-client/components/chat-proposal-survival.test.js.map +1 -0
- package/dist-client/components/mention-popup.js +28 -8
- package/dist-client/components/mention-popup.js.map +1 -1
- package/dist-client/components/panel-aria.test.d.ts +1 -0
- package/dist-client/components/panel-aria.test.js +49 -0
- package/dist-client/components/panel-aria.test.js.map +1 -0
- package/dist-client/components/proposal-outcome-line.d.ts +9 -0
- package/dist-client/components/proposal-outcome-line.js +15 -0
- package/dist-client/components/proposal-outcome-line.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/utils/assistant-session-controller.d.ts +20 -0
- package/dist-client/utils/assistant-session-controller.js +16 -0
- package/dist-client/utils/assistant-session-controller.js.map +1 -1
- package/dist-client/utils/assistant-session-controller.test.d.ts +1 -0
- package/dist-client/utils/assistant-session-controller.test.js +56 -0
- package/dist-client/utils/assistant-session-controller.test.js.map +1 -0
- package/dist-client/utils/assistant-session-transport.js +13 -5
- package/dist-client/utils/assistant-session-transport.js.map +1 -1
- package/dist-server/door-declaration-report.d.ts +14 -0
- package/dist-server/door-declaration-report.js +54 -0
- package/dist-server/door-declaration-report.js.map +1 -0
- package/dist-server/service/assistant-capability-resolver.d.ts +17 -0
- package/dist-server/service/assistant-capability-resolver.js +88 -0
- package/dist-server/service/assistant-capability-resolver.js.map +1 -0
- package/dist-server/service/assistant-chat-resolver.d.ts +6 -6
- package/dist-server/service/assistant-chat-resolver.js +185 -44
- package/dist-server/service/assistant-chat-resolver.js.map +1 -1
- package/dist-server/service/assistant-mode/assistant-mode-resolver.d.ts +33 -0
- package/dist-server/service/assistant-mode/assistant-mode-resolver.js +148 -0
- package/dist-server/service/assistant-mode/assistant-mode-resolver.js.map +1 -0
- package/dist-server/service/assistant-mode/index.d.ts +9 -0
- package/dist-server/service/assistant-mode/index.js +19 -0
- package/dist-server/service/assistant-mode/index.js.map +1 -0
- package/dist-server/service/assistant-mode/registry.d.ts +18 -0
- package/dist-server/service/assistant-mode/registry.js +136 -0
- package/dist-server/service/assistant-mode/registry.js.map +1 -0
- package/dist-server/service/assistant-mode/resolve.d.ts +43 -0
- package/dist-server/service/assistant-mode/resolve.js +65 -0
- package/dist-server/service/assistant-mode/resolve.js.map +1 -0
- package/dist-server/service/assistant-mode/types.d.ts +120 -0
- package/dist-server/service/assistant-mode/types.js +12 -0
- package/dist-server/service/assistant-mode/types.js.map +1 -0
- package/dist-server/service/chat-message/carried-turns.d.ts +48 -0
- package/dist-server/service/chat-message/carried-turns.js +92 -0
- package/dist-server/service/chat-message/carried-turns.js.map +1 -0
- package/dist-server/service/chat-message/chat-message-subscription.d.ts +1 -1
- package/dist-server/service/chat-message/chat-message-subscription.js +24 -6
- package/dist-server/service/chat-message/chat-message-subscription.js.map +1 -1
- package/dist-server/service/chat-message/chat-message.d.ts +32 -0
- package/dist-server/service/chat-message/chat-message.js +17 -0
- package/dist-server/service/chat-message/chat-message.js.map +1 -1
- package/dist-server/service/chat-message/door-access.d.ts +27 -0
- package/dist-server/service/chat-message/door-access.js +34 -0
- package/dist-server/service/chat-message/door-access.js.map +1 -0
- package/dist-server/service/chat-message/fold-session-history.d.ts +30 -0
- package/dist-server/service/chat-message/fold-session-history.js +133 -0
- package/dist-server/service/chat-message/fold-session-history.js.map +1 -0
- package/dist-server/service/chat-message/llm-history.d.ts +7 -0
- package/dist-server/service/chat-message/llm-history.js +23 -11
- package/dist-server/service/chat-message/llm-history.js.map +1 -1
- package/dist-server/service/chat-message/message-doors.d.ts +29 -0
- package/dist-server/service/chat-message/message-doors.js +107 -0
- package/dist-server/service/chat-message/message-doors.js.map +1 -0
- package/dist-server/service/chat-message/proposal-outcome.d.ts +18 -0
- package/dist-server/service/chat-message/proposal-outcome.js +31 -0
- package/dist-server/service/chat-message/proposal-outcome.js.map +1 -0
- package/dist-server/service/chat-message/reader-gate.d.ts +3 -0
- package/dist-server/service/chat-message/reader-gate.js +39 -0
- package/dist-server/service/chat-message/reader-gate.js.map +1 -0
- package/dist-server/service/chat-message/room-message.d.ts +4 -0
- package/dist-server/service/chat-message/room-message.js +25 -0
- package/dist-server/service/chat-message/room-message.js.map +1 -0
- package/dist-server/service/chat-session/chat-session.d.ts +36 -0
- package/dist-server/service/chat-session/chat-session.js +27 -2
- package/dist-server/service/chat-session/chat-session.js.map +1 -1
- package/dist-server/service/chat-session/session-anchor.d.ts +10 -1
- package/dist-server/service/chat-session/session-anchor.js +12 -4
- package/dist-server/service/chat-session/session-anchor.js.map +1 -1
- package/dist-server/service/chat-session/session-inbox.d.ts +6 -1
- package/dist-server/service/chat-session/session-inbox.js +3 -2
- package/dist-server/service/chat-session/session-inbox.js.map +1 -1
- package/dist-server/service/chat-session/session-kind.d.ts +14 -0
- package/dist-server/service/chat-session/session-kind.js +30 -0
- package/dist-server/service/chat-session/session-kind.js.map +1 -0
- package/dist-server/service/chat-session/session-visibility.d.ts +15 -0
- package/dist-server/service/chat-session/session-visibility.js +35 -0
- package/dist-server/service/chat-session/session-visibility.js.map +1 -0
- package/dist-server/service/chat-session/station-session-guard.d.ts +1 -5
- package/dist-server/service/chat-session/station-session-guard.js +7 -2
- package/dist-server/service/chat-session/station-session-guard.js.map +1 -1
- package/dist-server/service/chat-session-participant/mention-invite.d.ts +29 -0
- package/dist-server/service/chat-session-participant/mention-invite.js +103 -0
- package/dist-server/service/chat-session-participant/mention-invite.js.map +1 -0
- package/dist-server/service/chat-session-resolver.d.ts +17 -0
- package/dist-server/service/chat-session-resolver.js +271 -15
- package/dist-server/service/chat-session-resolver.js.map +1 -1
- package/dist-server/service/grounding-sources.d.ts +14 -0
- package/dist-server/service/grounding-sources.js +26 -0
- package/dist-server/service/grounding-sources.js.map +1 -0
- package/dist-server/service/index.d.ts +9 -1
- package/dist-server/service/index.js +21 -0
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/request-translator.d.ts +2 -0
- package/dist-server/service/request-translator.js +20 -0
- package/dist-server/service/request-translator.js.map +1 -0
- package/dist-server/service/testing/conversation-script.d.ts +123 -0
- package/dist-server/service/testing/conversation-script.js +202 -0
- package/dist-server/service/testing/conversation-script.js.map +1 -0
- package/dist-server/service/testing/mode-conformance.d.ts +50 -0
- package/dist-server/service/testing/mode-conformance.js +103 -0
- package/dist-server/service/testing/mode-conformance.js.map +1 -0
- package/dist-server/tool-registry-boot-report.d.ts +3 -0
- package/dist-server/tool-registry-boot-report.js +32 -2
- package/dist-server/tool-registry-boot-report.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/server/door-declaration-report.test.ts +53 -0
- package/server/door-declaration-report.ts +61 -0
- package/server/explicit-graphql-types.test.ts +56 -0
- package/server/service/assistant-capability-resolver.ts +66 -0
- package/server/service/assistant-chat-resolver.ts +205 -42
- package/server/service/assistant-mode/assistant-mode-resolver.ts +108 -0
- package/server/service/assistant-mode/index.ts +16 -0
- package/server/service/assistant-mode/registry.test.ts +105 -0
- package/server/service/assistant-mode/registry.ts +147 -0
- package/server/service/assistant-mode/resolve.test.ts +120 -0
- package/server/service/assistant-mode/resolve.ts +105 -0
- package/server/service/assistant-mode/subject-defaults.test.ts +86 -0
- package/server/service/assistant-mode/types.ts +121 -0
- package/server/service/chat-message/carried-turns.test.ts +80 -0
- package/server/service/chat-message/carried-turns.ts +112 -0
- package/server/service/chat-message/chat-message-subscription.ts +20 -4
- package/server/service/chat-message/chat-message.ts +44 -0
- package/server/service/chat-message/door-access.test.ts +72 -0
- package/server/service/chat-message/door-access.ts +65 -0
- package/server/service/chat-message/fold-history-window.test.ts +184 -0
- package/server/service/chat-message/fold-session-history.test.ts +98 -0
- package/server/service/chat-message/fold-session-history.ts +115 -0
- package/server/service/chat-message/llm-history.test.ts +58 -7
- package/server/service/chat-message/llm-history.ts +30 -11
- package/server/service/chat-message/message-doors.test.ts +87 -0
- package/server/service/chat-message/message-doors.ts +117 -0
- package/server/service/chat-message/proposal-outcome.test.ts +48 -0
- package/server/service/chat-message/proposal-outcome.ts +42 -0
- package/server/service/chat-message/reader-gate.ts +44 -0
- package/server/service/chat-message/room-message.test.ts +21 -0
- package/server/service/chat-message/room-message.ts +22 -0
- package/server/service/chat-session/chat-session.ts +46 -1
- package/server/service/chat-session/session-anchor.ts +12 -3
- package/server/service/chat-session/session-inbox.test.ts +18 -0
- package/server/service/chat-session/session-inbox.ts +11 -2
- package/server/service/chat-session/session-kind.test.ts +24 -0
- package/server/service/chat-session/session-kind.ts +32 -0
- package/server/service/chat-session/session-visibility.test.ts +52 -0
- package/server/service/chat-session/session-visibility.ts +34 -0
- package/server/service/chat-session/station-session-guard.ts +10 -2
- package/server/service/chat-session-participant/mention-invite.test.ts +125 -0
- package/server/service/chat-session-participant/mention-invite.ts +121 -0
- package/server/service/chat-session-resolver.ts +276 -15
- package/server/service/grounding-sources.test.ts +55 -0
- package/server/service/grounding-sources.ts +46 -0
- package/server/service/index.ts +21 -0
- package/server/service/request-translator.test.ts +45 -0
- package/server/service/request-translator.ts +33 -0
- package/server/service/station-session-guard.test.ts +12 -5
- package/server/service/testing/conversation-scenario.test.ts +163 -0
- package/server/service/testing/conversation-script.test.ts +131 -0
- package/server/service/testing/conversation-script.ts +288 -0
- package/server/service/testing/mode-conformance.ts +122 -0
- package/server/tool-registry-boot-report.ts +31 -2
- package/test/assistant-chat-call-sites.test.ts +82 -0
- package/translations/en.json +46 -3
- package/translations/ja.json +46 -3
- package/translations/ko.json +46 -3
- package/translations/ms.json +46 -3
- package/translations/zh.json +46 -3
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 화면이 무엇을 여는가 — ADR-0072 A17 ②.
|
|
3
|
+
*
|
|
4
|
+
* 한 subject 종류에 기본 대화가 없거나 둘이면 화면이 여는 대화는 부팅 순서가 정한다. 그것은 화면을
|
|
5
|
+
* 열어봐야 알 수 있고, 모듈 하나가 늘면 소리 없이 바뀐다. 부팅 보고가 말하게 하고, 여기서 셋 다
|
|
6
|
+
* 문다.
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
assistantModesForSubject,
|
|
10
|
+
clearAssistantModes,
|
|
11
|
+
getAssistantModeWarnings,
|
|
12
|
+
registerAssistantMode
|
|
13
|
+
} from './registry'
|
|
14
|
+
|
|
15
|
+
const persona = 'you are here'
|
|
16
|
+
|
|
17
|
+
describe('assistant mode — subjects and defaults', () => {
|
|
18
|
+
beforeEach(() => clearAssistantModes())
|
|
19
|
+
afterAll(() => clearAssistantModes())
|
|
20
|
+
|
|
21
|
+
it('★ a subject nobody claims as default is a boot warning, not a silent pick', () => {
|
|
22
|
+
registerAssistantMode({ kind: 'twin.space', systemPrompt: persona, subjects: ['space'] })
|
|
23
|
+
|
|
24
|
+
const codes = getAssistantModeWarnings().map(w => w.code)
|
|
25
|
+
expect(codes).toContain('assistant-mode-subject-without-default')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('★ two defaults on one subject is a boot warning — boot order must not decide it', () => {
|
|
29
|
+
registerAssistantMode({
|
|
30
|
+
kind: 'twin.space',
|
|
31
|
+
systemPrompt: persona,
|
|
32
|
+
subjects: ['board'],
|
|
33
|
+
defaultFor: ['board'],
|
|
34
|
+
labelKey: 'a'
|
|
35
|
+
})
|
|
36
|
+
registerAssistantMode({
|
|
37
|
+
kind: 'twin.authoring',
|
|
38
|
+
systemPrompt: persona,
|
|
39
|
+
subjects: ['board'],
|
|
40
|
+
defaultFor: ['board'],
|
|
41
|
+
labelKey: 'b'
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const twice = getAssistantModeWarnings().find(w => w.code === 'assistant-mode-subject-default-twice')
|
|
45
|
+
expect(twice?.params.kinds).toEqual(['twin.space', 'twin.authoring'])
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('★ a conversation offered beside another needs something to call it', () => {
|
|
49
|
+
registerAssistantMode({
|
|
50
|
+
kind: 'twin.space',
|
|
51
|
+
systemPrompt: persona,
|
|
52
|
+
subjects: ['board'],
|
|
53
|
+
defaultFor: ['board'],
|
|
54
|
+
labelKey: 'twin.ai.mode.space'
|
|
55
|
+
})
|
|
56
|
+
registerAssistantMode({ kind: 'twin.authoring', systemPrompt: persona, subjects: ['board'] })
|
|
57
|
+
|
|
58
|
+
const unnamed = getAssistantModeWarnings().find(w => w.code === 'assistant-mode-offered-without-label')
|
|
59
|
+
expect(unnamed?.params.kind).toBe('twin.authoring')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('one conversation alone on its subject needs no label — there is nothing to choose between', () => {
|
|
63
|
+
registerAssistantMode({
|
|
64
|
+
kind: 'plant.station',
|
|
65
|
+
systemPrompt: persona,
|
|
66
|
+
subjects: ['station'],
|
|
67
|
+
defaultFor: ['station']
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
expect(getAssistantModeWarnings()).toEqual([])
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('the default comes first, so a screen can open the list head without knowing the rule', () => {
|
|
74
|
+
registerAssistantMode({ kind: 'twin.authoring', systemPrompt: persona, subjects: ['board'], labelKey: 'b' })
|
|
75
|
+
registerAssistantMode({
|
|
76
|
+
kind: 'twin.space',
|
|
77
|
+
systemPrompt: persona,
|
|
78
|
+
subjects: ['board'],
|
|
79
|
+
defaultFor: ['board'],
|
|
80
|
+
labelKey: 'a'
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
expect(assistantModesForSubject('board').map(m => m.kind)).toEqual(['twin.space', 'twin.authoring'])
|
|
84
|
+
expect(assistantModesForSubject('nothing-shows-this')).toEqual([])
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a conversation is, declared by the app server that owns the screen (ADR-0061 decision 7).
|
|
3
|
+
*
|
|
4
|
+
* ADR-0058 put these five in one value so they could not fall out of step, but the value lived in
|
|
5
|
+
* the browser and travelled on every request: the persona, the tool categories, the model and the
|
|
6
|
+
* limits were the caller's to choose. A caller choosing its own tool categories is a caller
|
|
7
|
+
* choosing its own authority, so the declaration moved here and the client sends only which one it
|
|
8
|
+
* is talking in (`kind`) and what about (`target`).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** A `/` sentence this mode offers, and what it needs to be answerable. */
|
|
12
|
+
export interface AssistantModeSlash {
|
|
13
|
+
/** Short name shown in the list. */
|
|
14
|
+
name: string
|
|
15
|
+
/** i18n key for the one-line description. The server translates it into the request's locale. */
|
|
16
|
+
descriptionKey: string
|
|
17
|
+
/** i18n key for the sentence that lands in the input. */
|
|
18
|
+
templateKey: string
|
|
19
|
+
/**
|
|
20
|
+
* The tools this sentence needs. A mode must not offer work it cannot do (ADR-0058 decision 3),
|
|
21
|
+
* and a name outside `toolCategories` is reported at boot rather than when a person presses it.
|
|
22
|
+
*/
|
|
23
|
+
tools?: string[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface AssistantModeSpec {
|
|
27
|
+
/** `<app>.<surface>` — `twin.space`, `plant.station`, `figure.modeller`. */
|
|
28
|
+
kind: string
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Which kinds of subject this conversation stands for — `['board', 'space']` (ADR-0072 A17 ①).
|
|
32
|
+
*
|
|
33
|
+
* A screen says what it is showing (`context.subject`), and these say which conversations that
|
|
34
|
+
* subject can carry. It is a list of types and not a predicate on purpose: a list can be counted
|
|
35
|
+
* at boot and pinned by a test, while a function can only be run.
|
|
36
|
+
*
|
|
37
|
+
* On the twin modeller nothing could be asked about operations, because an open board pinned the
|
|
38
|
+
* authoring conversation and that conversation opens one category. A conversation that also
|
|
39
|
+
* stands for `board` is how the same screen carries both.
|
|
40
|
+
*/
|
|
41
|
+
subjects?: string[]
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The conversation a screen opens when the person has not chosen — one per subject type
|
|
45
|
+
* (ADR-0072 A17 ②).
|
|
46
|
+
*
|
|
47
|
+
* Registration order must not decide this: whichever module booted last would silently become
|
|
48
|
+
* the default. Exactly one mode declares each subject type, and the boot report says so when a
|
|
49
|
+
* type has none or more than one.
|
|
50
|
+
*/
|
|
51
|
+
defaultFor?: string[]
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* i18n key for what this conversation is called where a person chooses between them —
|
|
55
|
+
* "이 그림 고치기", "이 현장 지금 어때". A mode a screen may offer needs one.
|
|
56
|
+
*/
|
|
57
|
+
labelKey?: string
|
|
58
|
+
/** Who the assistant is here, and what it must not claim to do. The server's, not the caller's. */
|
|
59
|
+
systemPrompt: string
|
|
60
|
+
/** Which tool categories this conversation may use. Absent or empty exposes none. */
|
|
61
|
+
toolCategories?: string[]
|
|
62
|
+
/** Make the model read before it answers — for surfaces whose subject is live state. */
|
|
63
|
+
requireToolOnFirstTurn?: boolean
|
|
64
|
+
/** Model and limits are policy, not a request field. */
|
|
65
|
+
model?: string
|
|
66
|
+
temperature?: number
|
|
67
|
+
maxTokens?: number
|
|
68
|
+
/** What `/` offers. Declared as keys; the server translates. */
|
|
69
|
+
slashTemplates?: AssistantModeSlash[]
|
|
70
|
+
/** What `@` offers. */
|
|
71
|
+
catalogEntries?: any[]
|
|
72
|
+
/**
|
|
73
|
+
* i18n key for the words in the empty input.
|
|
74
|
+
*
|
|
75
|
+
* The screen says what this conversation is for, and that differs by mode: figure's modeller had
|
|
76
|
+
* "describe the figure you want" while the person was there to change the figure already open.
|
|
77
|
+
*/
|
|
78
|
+
placeholderKey?: string
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 빈 대화가 무엇을 말하는가 — 제목과 한 줄 (ADR-0061 결정 7).
|
|
82
|
+
*
|
|
83
|
+
* 자리표와 `/` 는 대화를 따라가는데 이 블록만 host 속성에 남아 있었다. 그래서 머리에는 「이 도형
|
|
84
|
+
* 고치기」가 서 있고 본문은 「만들 Figure 를 설명하세요」라고 적혀 있었다(2026-09-18, Figure 레인
|
|
85
|
+
* :3300). 한 대화가 화면에 무엇을 말하는가는 한 자리에서 나와야 한다.
|
|
86
|
+
*/
|
|
87
|
+
introKeys?: { title: string; subtitle: string }
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 빈 대화의 예시 — 「이 대화에서 할 수 있는 말」.
|
|
91
|
+
*
|
|
92
|
+
* 예시는 그 도구로 **실제로 할 수 있는 말**이어야 한다. 할 수 없는 것을 예시로 두면 빈 화면이 거짓을
|
|
93
|
+
* 가르친다. 대화마다 열리는 도구가 다르므로 예시도 대화를 따라간다.
|
|
94
|
+
*/
|
|
95
|
+
exampleKeys?: Array<{ labelKey: string; itemKeys: string[] }>
|
|
96
|
+
|
|
97
|
+
/** i18n key for the line under an empty conversation. */
|
|
98
|
+
footerNoticeKey?: string
|
|
99
|
+
/** i18n key for the line shown once the host reports a proposal staged. */
|
|
100
|
+
stagedNoticeKey?: string
|
|
101
|
+
/** Follow-up chips for a proposal that arrived without its own. */
|
|
102
|
+
proposalChoices?: any[]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** A declaration that registered but is not what the contract asks for. Code + params, not prose. */
|
|
106
|
+
export interface AssistantModeWarning {
|
|
107
|
+
/**
|
|
108
|
+
* `assistant-mode-slash-outside-tools` — a `/` sentence needs a tool this mode does not open.
|
|
109
|
+
* `assistant-mode-subject-without-default` — a subject type no conversation claims as its default.
|
|
110
|
+
* `assistant-mode-subject-default-twice` — two conversations claim the same subject type.
|
|
111
|
+
* `assistant-mode-offered-without-label` — a conversation a screen may offer with nothing to call it.
|
|
112
|
+
*/
|
|
113
|
+
code:
|
|
114
|
+
| 'assistant-mode-slash-outside-tools'
|
|
115
|
+
| 'assistant-mode-subject-without-default'
|
|
116
|
+
| 'assistant-mode-subject-default-twice'
|
|
117
|
+
| 'assistant-mode-offered-without-label'
|
|
118
|
+
params: { kind: string; slash?: string; tool?: string; subject?: string; kinds?: string[] }
|
|
119
|
+
/** For a person reading the boot log; callers act on the code and params. */
|
|
120
|
+
message: string
|
|
121
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* What this guards: a client cannot make the assistant say something (ADR-0070 A15 decision ③).
|
|
3
|
+
*
|
|
4
|
+
* `appendSessionTurns` used to store whatever role it was handed. A carried conversation could
|
|
5
|
+
* therefore put words in the assistant's mouth — every participant reads them as the assistant's,
|
|
6
|
+
* and the model reads them back as its own earlier turn and builds on them.
|
|
7
|
+
*/
|
|
8
|
+
import { CARRIED_TURN_LIMIT, carriedOriginalWhere, planCarriedTurns, quoteCarriedAnswer } from './carried-turns'
|
|
9
|
+
|
|
10
|
+
it("★ a person's carried words are theirs, and they were said to the room", () => {
|
|
11
|
+
const rows = planCarriedTurns([{ role: 'user', content: '3 라인이 멈춘 것 같아요' }])
|
|
12
|
+
|
|
13
|
+
expect(rows).toEqual([{ role: 'user', content: '3 라인이 멈춘 것 같아요', addressee: 'room' }])
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('★ an assistant turn with no original is a quotation on a system row', () => {
|
|
17
|
+
const rows = planCarriedTurns([{ role: 'assistant', content: '제가 이미 처리했습니다' }])
|
|
18
|
+
|
|
19
|
+
expect(rows[0].role).toBe('system')
|
|
20
|
+
expect(rows[0].content).toBe(quoteCarriedAnswer('제가 이미 처리했습니다'))
|
|
21
|
+
expect(rows[0].content).toContain('제가 이미 처리했습니다')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('★ an assistant turn that names its original is copied from storage, not trusted', () => {
|
|
25
|
+
const rows = planCarriedTurns([
|
|
26
|
+
{ role: 'assistant', content: 'whatever the caller typed', sourceSessionId: 's-1', sourceMessageId: 'm-9' }
|
|
27
|
+
])
|
|
28
|
+
|
|
29
|
+
expect(rows[0].role).toBe('assistant')
|
|
30
|
+
expect(rows[0].copyOf).toEqual({ sessionId: 's-1', messageId: 'm-9' })
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it("'ai' is the same as 'assistant' — the same rule applies to both spellings", () => {
|
|
34
|
+
expect(planCarriedTurns([{ role: 'ai', content: '답' }])[0].role).toBe('system')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* ADR-0070 결정 ③ — 이 문은 사람의 말과 어시스턴트의 답만 옮긴다.
|
|
39
|
+
*
|
|
40
|
+
* 2026-09-18 까지는 그 밖의 역할을 `system` 행으로 그대로 적었다. 모델은 `[system]` 을 사람의 말보다
|
|
41
|
+
* 무겁게 읽으므로, 클라이언트가 「이것은 시스템이 한 말」이라고 적을 수 있었다 — 역할은 서버가 쓴다는
|
|
42
|
+
* 결정이 그 자리에서 무너진다. 사람이 친 것이 아닌 맥락은 `appendSessionNote` 가 자리다.
|
|
43
|
+
*/
|
|
44
|
+
it('★ 클라이언트가 지어낸 역할은 거절한다 — `system` 은 서버가 쓰는 자리다', () => {
|
|
45
|
+
expect(() => planCarriedTurns([{ role: 'note', content: '메모' }])).toThrow(/appendSessionNote/)
|
|
46
|
+
expect(() => planCarriedTurns([{ role: 'system', content: '화면에서 승격함' }])).toThrow(/cannot be carried/)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('빈 내용은 조용히 빠진다 — 옮길 말이 없는 줄이다', () => {
|
|
50
|
+
expect(planCarriedTurns([{ role: 'user', content: ' ' }])).toEqual([])
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('only the last turns are carried — this is context, not an archive', () => {
|
|
54
|
+
const many = Array.from({ length: CARRIED_TURN_LIMIT + 5 }, (_, i) => ({ role: 'user', content: `줄 ${i}` }))
|
|
55
|
+
|
|
56
|
+
const rows = planCarriedTurns(many)
|
|
57
|
+
|
|
58
|
+
expect(rows).toHaveLength(CARRIED_TURN_LIMIT)
|
|
59
|
+
expect(rows[rows.length - 1].content).toBe(`줄 ${CARRIED_TURN_LIMIT + 4}`)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* 원본을 찾는 조건 — 문의 설명과 조회가 같은 것을 말해야 한다.
|
|
64
|
+
*
|
|
65
|
+
* 설명은 「대화와 메시지로 원본을 댄다」인데 조회가 메시지만 보면, 어긋난 두 인자가 와도 통과한다.
|
|
66
|
+
* 그때 옮겨 오는 것은 부른 사람이 가리킨 대화의 답이 아니다.
|
|
67
|
+
*/
|
|
68
|
+
describe('carriedOriginalWhere', () => {
|
|
69
|
+
it('★ 대화를 대면 그 대화 안에서만 찾는다', () => {
|
|
70
|
+
const where = carriedOriginalWhere('dom-1', { sessionId: 's-1', messageId: 'm-9' })
|
|
71
|
+
|
|
72
|
+
expect(where).toEqual({ id: 'm-9', session: { id: 's-1', domain: { id: 'dom-1' } } })
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('★ 대화를 대지 않아도 테넌트는 언제나 건다', () => {
|
|
76
|
+
const where = carriedOriginalWhere('dom-1', { messageId: 'm-9' })
|
|
77
|
+
|
|
78
|
+
expect(where).toEqual({ id: 'm-9', session: { domain: { id: 'dom-1' } } })
|
|
79
|
+
})
|
|
80
|
+
})
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A conversation carried in from somewhere else, turned into rows this session can hold.
|
|
3
|
+
*
|
|
4
|
+
* ── Why the assistant's turns are not simply written (ADR-0070 A15 decision ③) ──
|
|
5
|
+
* `appendSessionTurns` took whatever roles the caller sent, so a client could write a row that
|
|
6
|
+
* reads as the assistant speaking. Every participant then sees a sentence the assistant never
|
|
7
|
+
* said, and the model reads it back as its own earlier turn. Roles are the server's to write.
|
|
8
|
+
*
|
|
9
|
+
* So a carried assistant turn is kept only when its original can be found — the caller names it
|
|
10
|
+
* (`sourceSessionId` · `sourceMessageId`) and the server copies the stored text. Without an
|
|
11
|
+
* original it is kept as a quotation on a `system` row: the content is preserved, and nobody is
|
|
12
|
+
* told the assistant said it here.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** One turn as the caller carried it over. */
|
|
16
|
+
export interface CarriedTurn {
|
|
17
|
+
role?: string
|
|
18
|
+
content?: string
|
|
19
|
+
/** Where an assistant turn came from, so the server can read the original instead of trusting it. */
|
|
20
|
+
sourceSessionId?: string
|
|
21
|
+
sourceMessageId?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface PlannedRow {
|
|
25
|
+
role: 'user' | 'assistant' | 'system'
|
|
26
|
+
content: string
|
|
27
|
+
/** People's words are addressed to the room — this door is not the one that asks the assistant. */
|
|
28
|
+
addressee?: 'room'
|
|
29
|
+
/** Set when the row must be filled from a stored message before it is written. */
|
|
30
|
+
copyOf?: { sessionId?: string; messageId: string }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** How much of a carried conversation is kept — context, not an archive. */
|
|
34
|
+
export const CARRIED_TURN_LIMIT = 40
|
|
35
|
+
export const CARRIED_CONTENT_LIMIT = 4000
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* What to write, before anything is looked up.
|
|
39
|
+
*
|
|
40
|
+
* Pure: the caller resolves `copyOf` against storage and decides what a missing original becomes.
|
|
41
|
+
*/
|
|
42
|
+
export function planCarriedTurns(turns: CarriedTurn[]): PlannedRow[] {
|
|
43
|
+
const planned: PlannedRow[] = []
|
|
44
|
+
|
|
45
|
+
for (const turn of Array.isArray(turns) ? turns : []) {
|
|
46
|
+
const content = (turn?.content ?? '').trim().slice(0, CARRIED_CONTENT_LIMIT)
|
|
47
|
+
if (!content) continue
|
|
48
|
+
|
|
49
|
+
/*
|
|
50
|
+
* 이 문은 **사람의 말과 어시스턴트의 답**만 옮긴다(ADR-0070 결정 ③). 그 밖의 역할은 받지 않는다 —
|
|
51
|
+
* `system` 행은 서버가 쓰는 자리이고, 모델은 그 줄을 사람의 말보다 무겁게 읽는다. 클라이언트가
|
|
52
|
+
* 「이것은 시스템이 한 말」이라고 적을 수 있으면 역할을 서버가 쓴다는 결정이 무너진다.
|
|
53
|
+
*
|
|
54
|
+
* 사람이 친 것이 아닌 맥락은 `appendSessionNote` 가 자리다 — 그 문은 서버가 `system` 으로 적는다.
|
|
55
|
+
*/
|
|
56
|
+
const asked = turn?.role === 'ai' ? 'assistant' : turn?.role
|
|
57
|
+
if (asked !== 'assistant' && asked !== 'user') {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`[ai-assistant/carried-turns] role '${String(turn?.role)}' cannot be carried. This door carries what ` +
|
|
60
|
+
"people said and what the assistant answered. Context that nobody typed goes through `appendSessionNote`, " +
|
|
61
|
+
'which writes the system row itself.'
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
const role = asked
|
|
65
|
+
|
|
66
|
+
if (role === 'user') {
|
|
67
|
+
planned.push({ role: 'user', content, addressee: 'room' })
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (role === 'assistant') {
|
|
72
|
+
if (turn?.sourceMessageId) {
|
|
73
|
+
planned.push({
|
|
74
|
+
role: 'assistant',
|
|
75
|
+
content,
|
|
76
|
+
copyOf: { sessionId: turn.sourceSessionId, messageId: turn.sourceMessageId }
|
|
77
|
+
})
|
|
78
|
+
} else {
|
|
79
|
+
planned.push({ role: 'system', content: quoteCarriedAnswer(content) })
|
|
80
|
+
}
|
|
81
|
+
continue
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return planned.slice(-CARRIED_TURN_LIMIT)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* An answer with no original, kept as a quotation.
|
|
90
|
+
*
|
|
91
|
+
* English, like the other lines the model reads (`[system]`, the omission notices): this row is
|
|
92
|
+
* context for the model first, and a person reading it sees the quoted text either way.
|
|
93
|
+
*/
|
|
94
|
+
export function quoteCarriedAnswer(content: string): string {
|
|
95
|
+
return `carried from another conversation, quoted — the assistant did not say this here: "${content}"`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 원본을 찾는 조건.
|
|
100
|
+
*
|
|
101
|
+
* 문의 설명은 「`sourceSessionId` 와 `sourceMessageId` 로 원본을 댄다」고 말한다. 조회가 메시지 id 와
|
|
102
|
+
* 테넌트만 보면, 서로 어긋난 두 인자가 와도 설명과 다르게 통과한다 — 설명과 코드가 갈리는 자리다
|
|
103
|
+
* [수석 아키텍트가 ADR-0070 구현 검토에서 찾음, 2026-09-18].
|
|
104
|
+
*
|
|
105
|
+
* 테넌트는 언제나 건다. 대화를 대면 그것도 건다.
|
|
106
|
+
*/
|
|
107
|
+
export function carriedOriginalWhere(domainId: string, copyOf: { sessionId?: string; messageId: string }): any {
|
|
108
|
+
return {
|
|
109
|
+
id: copyOf.messageId,
|
|
110
|
+
session: copyOf.sessionId ? { id: copyOf.sessionId, domain: { id: domainId } } : { domain: { id: domainId } }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
* 차이: 필터 키가 board 가 아닌 sessionId (채팅은 ChatSession 단위).
|
|
14
14
|
* 순수 로직(토픽/필터)은 chat-message-broadcast.ts (테스트 가능). 여기엔 pubsub 의존만.
|
|
15
15
|
*/
|
|
16
|
-
import { Resolver, Subscription, Root, Arg } from 'type-graphql'
|
|
16
|
+
import { Resolver, Subscription, Root, Arg, Ctx } from 'type-graphql'
|
|
17
17
|
import { filter, pipe } from 'graphql-yoga'
|
|
18
18
|
import { pubsub } from '@things-factory/shell'
|
|
19
19
|
import { ChatMessage } from './chat-message.js'
|
|
20
20
|
import { CHAT_MESSAGE_TOPIC, chatMessageFilter, type ChatMessagePayload } from './chat-message-broadcast.js'
|
|
21
21
|
import { assertDomainSubscribeAllowed } from '../subscribe-auth.js'
|
|
22
|
+
import { readerGate } from './reader-gate.js'
|
|
22
23
|
|
|
23
24
|
// publishChatMessage 는 데코레이터 없는 chat-message-publish.ts 에 분리 (테스트 import 가능).
|
|
24
25
|
export { publishChatMessage } from './chat-message-publish.js'
|
|
@@ -27,7 +28,13 @@ export type { ChatMessagePayload } from './chat-message-broadcast.js'
|
|
|
27
28
|
|
|
28
29
|
@Resolver(ChatMessage)
|
|
29
30
|
export class ChatMessageSubscription {
|
|
30
|
-
@Subscription({
|
|
31
|
+
@Subscription(() => ChatMessage, {
|
|
32
|
+
/*
|
|
33
|
+
* 돌려주는 형을 **명시한다**. 이 핸들러가 async 가 되면서(받는 사람마다 가리기 — ADR-0073 판정 1)
|
|
34
|
+
* 반환형이 `Promise<ChatMessage>` 가 되었고, type-graphql 의 reflection 은 Promise 안을 못 본다.
|
|
35
|
+
* 빠지면 스키마를 세울 때 NoExplicitTypeError 로 **패키지 적재 자체가 실패한다** — 시험이 아니라
|
|
36
|
+
* 부팅이 죽는다. plant 레인이 설치본에서 이 오류를 잡아 알려 주었다(2026-09-18).
|
|
37
|
+
*/
|
|
31
38
|
description:
|
|
32
39
|
'Subscribes to chat messages (user / assistant / system) of a session for real-time group chat.',
|
|
33
40
|
subscribe: async ({ args, context }) => {
|
|
@@ -39,7 +46,16 @@ export class ChatMessageSubscription {
|
|
|
39
46
|
return pipe(pubsub.subscribe(CHAT_MESSAGE_TOPIC), filter(chatMessageFilter(domain.id, sessionId)))
|
|
40
47
|
}
|
|
41
48
|
})
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
/*
|
|
50
|
+
* 방송도 **받는 사람 기준으로** 가린다 — ADR-0073 판정 1. 저장해 놓고 읽을 때만 가리면, 그 자리에
|
|
51
|
+
* 앉아 있던 사람은 방송으로 원문을 받는다. 같은 값이 두 길로 나가고 한쪽만 문을 본다.
|
|
52
|
+
*/
|
|
53
|
+
async chatMessageActivity(
|
|
54
|
+
@Root() payload: ChatMessagePayload,
|
|
55
|
+
@Arg('sessionId') sessionId: string,
|
|
56
|
+
@Ctx() context: any
|
|
57
|
+
): Promise<ChatMessage> {
|
|
58
|
+
const [message] = await readerGate(context)([payload.message])
|
|
59
|
+
return message as ChatMessage
|
|
44
60
|
}
|
|
45
61
|
}
|
|
@@ -60,6 +60,50 @@ export class ChatMessage {
|
|
|
60
60
|
@Field({ description: 'Message content' })
|
|
61
61
|
content!: string
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* 이 말이 누구에게 한 말인가 — `'assistant'` · `'room'`(ADR-0070 A15 결정 ①).
|
|
65
|
+
*
|
|
66
|
+
* **값은 그 행을 쓴 문이 찍는다.** 어시스턴트에게 묻는 문(`assistantChat`)이 저장한 사람의 행은
|
|
67
|
+
* `assistant` 이고, 사람끼리의 문(`appendSessionTurns`)이 저장한 행은 `room` 이다. 클라이언트가
|
|
68
|
+
* 인자로 보내지 않는다 — 인자로 받으면 「어느 문을 불렀나」와 「무엇을 적어 보냈나」 두 사실이
|
|
69
|
+
* 생기고, 둘은 어긋날 수 있다.
|
|
70
|
+
*
|
|
71
|
+
* 사람의 행에만 뜻이 있다. 어시스턴트의 답은 `parentMessage` 로 자기를 부른 턴에 귀속되고,
|
|
72
|
+
* `system` 행은 누구에게 한 말이 아니다.
|
|
73
|
+
*/
|
|
74
|
+
@Column({ type: 'varchar', length: 16, nullable: true })
|
|
75
|
+
@Field({ nullable: true, description: "Who this turn was for: 'assistant' | 'room'. Written by the door that stored it, never sent by the client." })
|
|
76
|
+
addressee?: string
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 이 행의 값이 지나온 문들 — ADR-0073 판정 1.
|
|
80
|
+
*
|
|
81
|
+
* 어시스턴트의 답과 제안 행에만 채워진다. 사람의 말은 빈 목록이다 — 사람이 자기 입으로 한 말에는
|
|
82
|
+
* 문이 없다. 답을 저장할 때 그 턴에 부른 도구들의 `doors`(ADR-0072)를 합쳐 옮겨 적는다.
|
|
83
|
+
*
|
|
84
|
+
* 읽을 때마다 **읽는 사람**이 이 문을 전부 지나는지 보고, 못 지나면 본문 대신 한 줄이 나간다. 그래서
|
|
85
|
+
* 이 칸은 "누가 볼 수 있나"를 적은 것이고, 저장된 값 자체는 누구에게도 달라지지 않는다.
|
|
86
|
+
*
|
|
87
|
+
* 목록이 비면 누구나 읽는다. 등록기가 모르는 도구가 답에 끼면 `unresolved:<도구>` 가 적히고 아무도
|
|
88
|
+
* 못 지난다 — 모르는 값은 가려지는 쪽으로 넘어뜨린다.
|
|
89
|
+
*/
|
|
90
|
+
@Column({ type: 'simple-array', nullable: true })
|
|
91
|
+
@Field(() => [String], {
|
|
92
|
+
nullable: true,
|
|
93
|
+
description:
|
|
94
|
+
'GraphQL doors the tools behind this answer went through. Empty for what people typed. A reader who does not pass all of them gets a one-line notice in place of the content.'
|
|
95
|
+
})
|
|
96
|
+
doors?: string[]
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 이 행이 **이 사람에게** 가려져 나갔는가 — 저장하지 않는다.
|
|
100
|
+
*
|
|
101
|
+
* 같은 행이 사람마다 다르게 나가므로 칸에 적을 값이 없다. 읽어 나갈 때 채운다. 화면은 이것으로
|
|
102
|
+
* 자물쇠를 그리고, 본문에 온 한 줄을 어시스턴트의 말로 오해하지 않는다.
|
|
103
|
+
*/
|
|
104
|
+
@Field({ nullable: true, description: 'True when the content was replaced because this reader does not pass the row doors.' })
|
|
105
|
+
redacted?: boolean
|
|
106
|
+
|
|
63
107
|
@Column({ nullable: true })
|
|
64
108
|
@Field({ nullable: true, description: 'PatchEntry.id this message triggered (if any).' })
|
|
65
109
|
relatedPatchId?: string
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ADR-0072 결정 5 — 문이 묻는 것을 AUTH 의 표에서 읽는다.
|
|
3
|
+
*
|
|
4
|
+
* 표가 주는 답은 셋이고 서로 다르다. 가운데 하나만 열림이다 — 나머지 둘을 열림으로 읽으면 못 볼 값이
|
|
5
|
+
* 나간다. 그리고 「없는 필드」를 열림으로 읽는 것이 가장 하기 쉬운 잘못이다: 도구가 문 이름을 틀리게
|
|
6
|
+
* 적었을 때 검사가 붙는 대신 조용히 빠진다.
|
|
7
|
+
*/
|
|
8
|
+
import { doorCheck, doorField, isKnownDoor, type FieldLookup } from './door-access'
|
|
9
|
+
|
|
10
|
+
const table: Record<string, any> = {
|
|
11
|
+
'Query.open': { known: true, gate: null },
|
|
12
|
+
'Query.guarded': { known: true, gate: { category: 'job-order', privilege: 'query', owner: false, super: false } }
|
|
13
|
+
}
|
|
14
|
+
const lookup: FieldLookup = (typeName, fieldName) => table[`${typeName}.${fieldName}`] ?? { known: false }
|
|
15
|
+
|
|
16
|
+
describe('door access', () => {
|
|
17
|
+
it('★ 선언이 없는 필드는 열려 있다 — 그 문으로 아무나 읽으므로 이 행도 읽는다', async () => {
|
|
18
|
+
const check = doorCheck({ lookup, permits: async () => false })
|
|
19
|
+
|
|
20
|
+
expect(await check('Query.open')).toBe(true)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('★ 없는 필드는 닫는다 — 도구가 이름을 틀리게 적은 것이지 열린 문이 아니다', async () => {
|
|
24
|
+
const check = doorCheck({ lookup, permits: async () => true })
|
|
25
|
+
|
|
26
|
+
expect(await check('Query.doesNotExist')).toBe(false)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('★ 선언이 있는 필드는 AUTH 에게 묻는다 — 여기서 규칙을 다시 쓰지 않는다', async () => {
|
|
30
|
+
const asked: any[] = []
|
|
31
|
+
const check = doorCheck({
|
|
32
|
+
lookup,
|
|
33
|
+
permits: async gate => {
|
|
34
|
+
asked.push(gate)
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
expect(await check('Query.guarded')).toBe(false)
|
|
40
|
+
expect(asked).toEqual([{ category: 'job-order', privilege: 'query', owner: false, super: false }])
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('AUTH 가 통과시키면 지난다', async () => {
|
|
44
|
+
expect(await doorCheck({ lookup, permits: async () => true })('Query.guarded')).toBe(true)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('★ 문 모양이 아니면 아무도 못 지난다 — 표를 묻지도 않는다', async () => {
|
|
48
|
+
const asked: string[] = []
|
|
49
|
+
const watching: FieldLookup = (typeName, fieldName) => {
|
|
50
|
+
asked.push(`${typeName}.${fieldName}`)
|
|
51
|
+
return { known: false }
|
|
52
|
+
}
|
|
53
|
+
const check = doorCheck({ lookup: watching, permits: async () => true })
|
|
54
|
+
|
|
55
|
+
for (const bad of ['jobOrders', 'Query.', 'Query.a.b', '', 'unresolved:getStationScreen']) {
|
|
56
|
+
expect(await check(bad)).toBe(false)
|
|
57
|
+
}
|
|
58
|
+
expect(asked).toEqual([])
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('문 이름을 타입과 필드로 가른다', () => {
|
|
62
|
+
expect(doorField('Mutation.proposeFigure')).toEqual({ typeName: 'Mutation', fieldName: 'proposeFigure' })
|
|
63
|
+
expect(doorField('Subscription.chatMessageActivity')?.typeName).toBe('Subscription')
|
|
64
|
+
expect(doorField('Query.a.b')).toBeUndefined()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('스키마에 있는 문인지 따로 답한다 — 부팅 보고가 이것으로 틀린 선언을 말한다', () => {
|
|
68
|
+
expect(isKnownDoor('Query.open', lookup)).toBe(true)
|
|
69
|
+
expect(isKnownDoor('Query.guarded', lookup)).toBe(true)
|
|
70
|
+
expect(isKnownDoor('Query.doesNotExist', lookup)).toBe(false)
|
|
71
|
+
})
|
|
72
|
+
})
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 문 → 그 문을 지키는 권한 — ADR-0073 판정 1 의 관문을 세우는 자리.
|
|
3
|
+
*
|
|
4
|
+
* ── 정본은 AUTH 의 표다 ───────────────────────────────────────────────────
|
|
5
|
+
* 행에 적힌 것은 문 이름(`Query.jobOrders`)이고, 사람이 가진 것은 권한(`job-order:query`)이다. 둘을
|
|
6
|
+
* 잇는 것은 `privilegeOfField(typeName, fieldName)` 이다(ADR-0072 결정 5). 스키마를 지을 때 모든 루트
|
|
7
|
+
* 필드가 기록되므로, 이 표는 **그 문이 실제로 무엇을 묻는지**를 그대로 답한다.
|
|
8
|
+
*
|
|
9
|
+
* 그 전에는 도구 명세가 들고 있는 짝을 베껴 썼다. 베낀 값은 문이 선언을 바꾸면 조용히 어긋나고,
|
|
10
|
+
* 어긋나면 느슨한 쪽이 이긴다. 표가 서면서 그 사본을 걷었다.
|
|
11
|
+
*
|
|
12
|
+
* ── 판정하지 않고 AUTH 에게 묻는다 ────────────────────────────────────────
|
|
13
|
+
* 표가 주는 gate 는 `checkPermission` 이 받는 넷(category · privilege · owner · super)과 같은 모양이고,
|
|
14
|
+
* 그대로 `checkPermission` 에 넘긴다. 여기서 「category 가 없으면 소유권만 본다」 같은 규칙을 다시 쓰면
|
|
15
|
+
* 그 순간 AUTH 와 이 파일이 두 벌이 된다. 문에서 통하는 것이 여기서도 통해야 한다.
|
|
16
|
+
*
|
|
17
|
+
* ── 셋 중 둘은 닫는다 ─────────────────────────────────────────────────────
|
|
18
|
+
* `{ known: false }` 그런 루트 필드가 없다. 도구가 문 이름을 틀리게 적은 것이다 —
|
|
19
|
+
* **열림으로 읽지 않는다.** 부팅 보고가 따로 말한다.
|
|
20
|
+
* `{ known: true, gate: null }` 필드는 있고 선언이 없다. 그 문은 열려 있으므로 이 행도 열린다.
|
|
21
|
+
* `{ known: true, gate }` 그 문이 묻는 것을 이 사람이 가졌는지 AUTH 에게 묻는다.
|
|
22
|
+
*
|
|
23
|
+
* 스키마를 짓기 전에는 표가 비어 있어 모든 문이 `known: false` 로 답한다 — 가려지는 쪽이다.
|
|
24
|
+
*/
|
|
25
|
+
import type { FieldGate } from '@things-factory/auth-base'
|
|
26
|
+
|
|
27
|
+
/** `privilegeOfField` 와 같은 모양 — 이 파일은 표를 **읽기만** 하고 어디서 오는지는 모른다. */
|
|
28
|
+
export type FieldLookup = (typeName: string, fieldName: string) => { known: false } | { known: true; gate: FieldGate | null }
|
|
29
|
+
|
|
30
|
+
export interface DoorCheckDeps {
|
|
31
|
+
/** AUTH 의 필드→권한 표. 운영에서는 `privilegeOfField` 가 들어온다(`reader-gate.ts`). */
|
|
32
|
+
lookup: FieldLookup
|
|
33
|
+
/** `checkPermission` 을 그대로 싸서 넘긴다 — 판정은 AUTH 가 한다. */
|
|
34
|
+
permits(gate: FieldGate): Promise<boolean>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** `Query.jobOrders` 를 타입과 필드로 가른다. 모양이 아니면 undefined — 아무도 못 지난다. */
|
|
38
|
+
export function doorField(door: string): { typeName: string; fieldName: string } | undefined {
|
|
39
|
+
const match = /^(Query|Mutation|Subscription)\.([A-Za-z_][A-Za-z0-9_]*)$/.exec(door ?? '')
|
|
40
|
+
return match ? { typeName: match[1], fieldName: match[2] } : undefined
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 이 문이 스키마에 있는가 — 없으면 선언이 틀린 것이고, 부팅 보고가 그것을 말한다. */
|
|
44
|
+
export function isKnownDoor(door: string, lookup: FieldLookup): boolean {
|
|
45
|
+
const field = doorField(door)
|
|
46
|
+
return !!field && lookup(field.typeName, field.fieldName).known
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 문 하나를 이 사람이 지나는가 — `doorGate` 에 넣을 검사.
|
|
51
|
+
*
|
|
52
|
+
* 되풀이 조회를 줄이는 기억은 `doorGate` 가 한다. 여기는 한 번의 판정만 한다.
|
|
53
|
+
*/
|
|
54
|
+
export function doorCheck(deps: DoorCheckDeps): (door: string) => Promise<boolean> {
|
|
55
|
+
return async (door: string) => {
|
|
56
|
+
const field = doorField(door)
|
|
57
|
+
if (!field) return false
|
|
58
|
+
|
|
59
|
+
const asked = deps.lookup(field.typeName, field.fieldName)
|
|
60
|
+
if (!asked.known) return false
|
|
61
|
+
if (asked.gate === null) return true
|
|
62
|
+
|
|
63
|
+
return await deps.permits(asked.gate)
|
|
64
|
+
}
|
|
65
|
+
}
|