@things-factory/figure-service 10.1.277 → 10.1.279
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/package.json +23 -8
- package/dist-server/index.js.map +0 -1
- package/dist-server/migrations/index.js.map +0 -1
- package/dist-server/routers/figure-mesh-router.js.map +0 -1
- package/dist-server/routers/figure-package-router.js.map +0 -1
- package/dist-server/routers/figure-thumbnail-router.js.map +0 -1
- package/dist-server/routes.js.map +0 -1
- package/dist-server/service/figure/event-subscriber.js.map +0 -1
- package/dist-server/service/figure/figure-ai-scenarios-run.js.map +0 -1
- package/dist-server/service/figure/figure-ai-scenarios.js.map +0 -1
- package/dist-server/service/figure/figure-categories.js.map +0 -1
- package/dist-server/service/figure/figure-context.js.map +0 -1
- package/dist-server/service/figure/figure-format.js.map +0 -1
- package/dist-server/service/figure/figure-glb.js.map +0 -1
- package/dist-server/service/figure/figure-history.js.map +0 -1
- package/dist-server/service/figure/figure-llm-provider.js.map +0 -1
- package/dist-server/service/figure/figure-mesh-store.js.map +0 -1
- package/dist-server/service/figure/figure-mutation.js.map +0 -1
- package/dist-server/service/figure/figure-namespace-entity.js.map +0 -1
- package/dist-server/service/figure/figure-namespace-resolver.js.map +0 -1
- package/dist-server/service/figure/figure-namespace.js.map +0 -1
- package/dist-server/service/figure/figure-package-export.js.map +0 -1
- package/dist-server/service/figure/figure-proposal-record.js.map +0 -1
- package/dist-server/service/figure/figure-proposal.js.map +0 -1
- package/dist-server/service/figure/figure-propose-steps.js.map +0 -1
- package/dist-server/service/figure/figure-propose-type.js.map +0 -1
- package/dist-server/service/figure/figure-public.js.map +0 -1
- package/dist-server/service/figure/figure-query.js.map +0 -1
- package/dist-server/service/figure/figure-rename.js.map +0 -1
- package/dist-server/service/figure/figure-replaced-draft.js.map +0 -1
- package/dist-server/service/figure/figure-revert.js.map +0 -1
- package/dist-server/service/figure/figure-subject.js.map +0 -1
- package/dist-server/service/figure/figure-thumbnail-reader.js.map +0 -1
- package/dist-server/service/figure/figure-thumbnail-store.js.map +0 -1
- package/dist-server/service/figure/figure-thumbnail-upgrade.js.map +0 -1
- package/dist-server/service/figure/figure-tools.js.map +0 -1
- package/dist-server/service/figure/figure-type.js.map +0 -1
- package/dist-server/service/figure/figure-write.js.map +0 -1
- package/dist-server/service/figure/figure.js.map +0 -1
- package/dist-server/service/figure/index.js.map +0 -1
- package/dist-server/service/figure-recipe/figure-recipe-resolver.js.map +0 -1
- package/dist-server/service/figure-recipe/figure-recipe-templates.js.map +0 -1
- package/dist-server/service/figure-recipe/figure-recipe-type.js.map +0 -1
- package/dist-server/service/figure-recipe/index.js.map +0 -1
- package/dist-server/service/index.js.map +0 -1
- package/dist-server/tsconfig.tsbuildinfo +0 -1
- package/scripts/build-templates.mts +0 -64
- package/scripts/figure-ai-scenarios-agent.cjs +0 -98
- package/scripts/rename-figures-to-full-names.mjs +0 -211
- package/scripts/templates.test.mts +0 -112
- package/server/index.ts +0 -46
- package/server/migrations/index.ts +0 -9
- package/server/routers/figure-mesh-router.ts +0 -63
- package/server/routers/figure-package-router.ts +0 -53
- package/server/routers/figure-thumbnail-router.ts +0 -159
- package/server/routes.ts +0 -30
- package/server/service/figure/catalog-db.test.ts +0 -162
- package/server/service/figure/event-subscriber.ts +0 -66
- package/server/service/figure/figure-ai-scenarios-run.ts +0 -127
- package/server/service/figure/figure-ai-scenarios.live.test.ts +0 -59
- package/server/service/figure/figure-ai-scenarios.test.ts +0 -109
- package/server/service/figure/figure-ai-scenarios.ts +0 -798
- package/server/service/figure/figure-blueprint-query.test.ts +0 -536
- package/server/service/figure/figure-catalog-seen-db.test.ts +0 -153
- package/server/service/figure/figure-categories.ts +0 -50
- package/server/service/figure/figure-category-db.test.ts +0 -127
- package/server/service/figure/figure-context.test.ts +0 -402
- package/server/service/figure/figure-context.ts +0 -510
- package/server/service/figure/figure-deprecation-db.test.ts +0 -218
- package/server/service/figure/figure-format.test.ts +0 -423
- package/server/service/figure/figure-format.ts +0 -783
- package/server/service/figure/figure-glb.test.ts +0 -112
- package/server/service/figure/figure-glb.ts +0 -251
- package/server/service/figure/figure-history.ts +0 -192
- package/server/service/figure/figure-inspect-db.test.ts +0 -131
- package/server/service/figure/figure-llm-provider.ts +0 -20
- package/server/service/figure/figure-llm-smoke.test.ts +0 -95
- package/server/service/figure/figure-mesh-db.test.ts +0 -246
- package/server/service/figure/figure-mesh-store.ts +0 -91
- package/server/service/figure/figure-mutation.ts +0 -656
- package/server/service/figure/figure-namespace-db.test.ts +0 -315
- package/server/service/figure/figure-namespace-entity.ts +0 -67
- package/server/service/figure/figure-namespace-resolver.ts +0 -54
- package/server/service/figure/figure-namespace.ts +0 -156
- package/server/service/figure/figure-package-export.ts +0 -136
- package/server/service/figure/figure-proposal-db.test.ts +0 -117
- package/server/service/figure/figure-proposal-record.ts +0 -38
- package/server/service/figure/figure-proposal.ts +0 -41
- package/server/service/figure/figure-propose-clips.test.ts +0 -69
- package/server/service/figure/figure-propose-steps.test.ts +0 -324
- package/server/service/figure/figure-propose-steps.ts +0 -354
- package/server/service/figure/figure-propose-type.ts +0 -46
- package/server/service/figure/figure-public-db.test.ts +0 -288
- package/server/service/figure/figure-public.ts +0 -60
- package/server/service/figure/figure-query.ts +0 -511
- package/server/service/figure/figure-release-check.test.ts +0 -63
- package/server/service/figure/figure-release-record-db.test.ts +0 -153
- package/server/service/figure/figure-release-size-db.test.ts +0 -156
- package/server/service/figure/figure-rename-db.test.ts +0 -237
- package/server/service/figure/figure-rename.test.ts +0 -117
- package/server/service/figure/figure-rename.ts +0 -143
- package/server/service/figure/figure-replaced-draft.ts +0 -99
- package/server/service/figure/figure-revert-db.test.ts +0 -163
- package/server/service/figure/figure-revert-race.pg.test.ts +0 -168
- package/server/service/figure/figure-revert.ts +0 -186
- package/server/service/figure/figure-subject.test.ts +0 -41
- package/server/service/figure/figure-subject.ts +0 -21
- package/server/service/figure/figure-thumbnail-db.test.ts +0 -279
- package/server/service/figure/figure-thumbnail-reader.ts +0 -20
- package/server/service/figure/figure-thumbnail-store.ts +0 -111
- package/server/service/figure/figure-thumbnail-upgrade.pg.test.ts +0 -93
- package/server/service/figure/figure-thumbnail-upgrade.ts +0 -70
- package/server/service/figure/figure-tool-doors.test.ts +0 -127
- package/server/service/figure/figure-tools-door-db.test.ts +0 -227
- package/server/service/figure/figure-tools.test.ts +0 -817
- package/server/service/figure/figure-tools.ts +0 -611
- package/server/service/figure/figure-type.ts +0 -241
- package/server/service/figure/figure-write.test.ts +0 -15
- package/server/service/figure/figure-write.ts +0 -131
- package/server/service/figure/figure.ts +0 -241
- package/server/service/figure/index.ts +0 -13
- package/server/service/figure-recipe/figure-recipe-resolver.ts +0 -38
- package/server/service/figure-recipe/figure-recipe-templates.test.ts +0 -47
- package/server/service/figure-recipe/figure-recipe-templates.ts +0 -70
- package/server/service/figure-recipe/figure-recipe-type.ts +0 -31
- package/server/service/figure-recipe/index.ts +0 -3
- package/server/service/index.ts +0 -34
- package/tsconfig.json +0 -14
|
@@ -1,817 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 저작 도구의 **배선**을 못박는다.
|
|
3
|
-
*
|
|
4
|
-
* 도구가 무엇을 계산하는지는 각 진입점의 시험이 이미 잠근다(`figure-propose-steps.test` ·
|
|
5
|
-
* figure-model 의 게이트 시험). 비어 있던 것은 **그 사이를 잇는 줄들**이고, 그 줄이 끊어질 때
|
|
6
|
-
* 나타나는 증상이 실제로 겪은 실패와 1:1 로 대응한다.
|
|
7
|
-
*
|
|
8
|
-
* · guidance → 도구 호출 끊기면 → 「후보를 만들었습니다」라고만 쓰고 화면에는 아무것도 없다
|
|
9
|
-
* · hostContext.figureId → 대상 끊기면 → 화면에 피규어가 떠 있는데 「어느 피규어입니까」를 되묻는다
|
|
10
|
-
* · 도메인 확인 → 대상 끊기면 → 모델이 넘긴 id 로 남의 테넌트를 읽는다
|
|
11
|
-
* · hostContext.context·revision → 제안 끊기면 → 모델러가 모델이 본 버전이 아닌 버전에 명령을 적용한다
|
|
12
|
-
*
|
|
13
|
-
* 실제 모델은 부르지 않는다. 여기서 볼 것은 모델의 솜씨가 아니라 **우리 배선**이다.
|
|
14
|
-
*/
|
|
15
|
-
import { clearToolRegistry, getToolCategories, registryAssistantChat, setAIClientForTesting, toolCallContextFixture } from '@things-factory/ai-client-base'
|
|
16
|
-
|
|
17
|
-
import { __setFigureToolDepsForTest, registerFigureToolCategories } from './figure-tools'
|
|
18
|
-
|
|
19
|
-
/** 도메인 소속을 흉내내는 저장소. 넘긴 id 와 도메인이 맞을 때만 돌려준다. */
|
|
20
|
-
function stubRepository(rows: any[]) {
|
|
21
|
-
return {
|
|
22
|
-
async findOne({ where }: any) {
|
|
23
|
-
return (
|
|
24
|
-
rows.find(row => row.id === where.id && row.domain?.id === where.domain?.id) ?? null
|
|
25
|
-
)
|
|
26
|
-
},
|
|
27
|
-
/* A where list is OR'ed, as typeorm does; an ILike operator is a case-blind pattern with `%` for anything. */
|
|
28
|
-
async find({ where, take }: any) {
|
|
29
|
-
const matches = (value: any, wanted: any) => {
|
|
30
|
-
if (wanted === undefined) return true
|
|
31
|
-
if (wanted?._type === 'ilike') return new RegExp(`^${String(wanted._value).split('%').map(escape).join('.*')}$`, 'i').test(String(value ?? ''))
|
|
32
|
-
return value === wanted
|
|
33
|
-
}
|
|
34
|
-
const escape = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
35
|
-
const one = (row: any, w: any) => row.domain?.id === w.domain?.id && matches(row.name, w.name) && matches(row.type, w.type)
|
|
36
|
-
const found = rows.filter(row => (Array.isArray(where) ? where.some(w => one(row, w)) : one(row, where)))
|
|
37
|
-
return take === undefined ? found : found.slice(0, take)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const MINE = { id: 'domain-mine' }
|
|
43
|
-
const THEIRS = { id: 'domain-theirs' }
|
|
44
|
-
|
|
45
|
-
/** A stored figure: one body on the floor. */
|
|
46
|
-
const SOURCE = (() => {
|
|
47
|
-
const model = require('@hatiolab/figure-model')
|
|
48
|
-
let asset = model.addFigureBox(model.createFigureAsset('Mixer'), { id: 'body', size: { x: 300, y: 400, z: 300 }, position: { x: 0, y: 200, z: 0 } })
|
|
49
|
-
asset = model.applyFigureAuthoring(asset, { kind: 'set-placement', placement: 'floor' })
|
|
50
|
-
return asset
|
|
51
|
-
})()
|
|
52
|
-
|
|
53
|
-
const ROWS = [
|
|
54
|
-
{ id: 'fig-1', type: 'MIXER', name: '믹서', state: 'draft', domain: MINE, source: JSON.stringify(SOURCE) },
|
|
55
|
-
{ id: 'fig-blank', type: 'EMPTY', name: '빈 것', state: 'draft', domain: MINE, source: null },
|
|
56
|
-
{ id: 'fig-other', type: 'SECRET', name: '남의 것', state: 'draft', domain: THEIRS, source: JSON.stringify(SOURCE) }
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
/** A request translator for one locale, read from this package's translations as i18next reads them. */
|
|
60
|
-
function translatorOf(locale: string) {
|
|
61
|
-
const words = require(`../../../translations/${locale}.json`)
|
|
62
|
-
return (key: string, params: Record<string, any> = {}) =>
|
|
63
|
-
String(words[key] ?? params.defaultValue ?? key).replace(/\{(\w+)\}/g, (whole, name) => (name in params ? String(params[name]) : whole))
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** 부른 것을 적어 두는 가짜 제안기. */
|
|
67
|
-
const proposed: any[] = []
|
|
68
|
-
|
|
69
|
-
/* The proposal tool asks the domain's AI agent; here a stand-in answers - the proposer below never calls it. */
|
|
70
|
-
const agentClient: any = { id: 'test:figure', chat: async () => '', generateJSON: async () => ({}), listModels: async () => [] }
|
|
71
|
-
|
|
72
|
-
function install() {
|
|
73
|
-
setAIClientForTesting(agentClient)
|
|
74
|
-
const model = require('@hatiolab/figure-model')
|
|
75
|
-
__setFigureToolDepsForTest({
|
|
76
|
-
getRepository: () => stubRepository(ROWS),
|
|
77
|
-
Figure: class {},
|
|
78
|
-
inspectSource: (json?: string | null) =>
|
|
79
|
-
json ? { blocked: false, findings: [] } : { blocked: true, findings: [{ code: 'no-source', message: '정본이 없다', blocking: true }] },
|
|
80
|
-
proposeFigureSteps: async (input: any) => {
|
|
81
|
-
proposed.push(input)
|
|
82
|
-
return {
|
|
83
|
-
steps: [{ kind: 'rename', name: 'Mixer' }],
|
|
84
|
-
source: { ...model.createFigureAsset(input.base?.name ?? input.name ?? 'Figure') },
|
|
85
|
-
score: { grade: 'B' },
|
|
86
|
-
cost: { triangles: 12 },
|
|
87
|
-
attempts: 1
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
parseSource: require('./figure-format').parseSource,
|
|
91
|
-
figureCostOf: model.figureCostOf,
|
|
92
|
-
figureScoreOf: model.figureScoreOf
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** 등록된 범주에서 도구 하나를 꺼낸다. */
|
|
97
|
-
function toolNamed(name: string) {
|
|
98
|
-
const category = getToolCategories().find((one: any) => one.name === 'figure-authoring')
|
|
99
|
-
if (!category) throw new Error('figure-authoring 범주가 등록되지 않았다')
|
|
100
|
-
const spec = category.specs.find((one: any) => one.name === name)
|
|
101
|
-
if (!spec) throw new Error(`도구 ${name} 이 없다`)
|
|
102
|
-
return spec as any
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/* The shape the door hands a tool (A3) - translator and checked attachments included - built by the door's own fixture. */
|
|
106
|
-
const ctx = (host: any = { figureId: 'fig-1', palette: ['palette.primary'] }, extra: { t?: any; attachments?: any[] } = {}) =>
|
|
107
|
-
toolCallContextFixture({ domainId: MINE.id, host, ...extra })
|
|
108
|
-
|
|
109
|
-
beforeEach(() => {
|
|
110
|
-
clearToolRegistry()
|
|
111
|
-
proposed.length = 0
|
|
112
|
-
install()
|
|
113
|
-
registerFigureToolCategories()
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
afterEach(() => {
|
|
117
|
-
clearToolRegistry()
|
|
118
|
-
setAIClientForTesting(undefined)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
test('실제 registryAssistantChat 경계가 열린 모델 문맥을 Figure 도구에 전달한다', async () => {
|
|
122
|
-
const seen: any[] = []
|
|
123
|
-
let turn = 0
|
|
124
|
-
await registryAssistantChat({
|
|
125
|
-
client: { chatWithTools: async (messages: any[]) => {
|
|
126
|
-
seen.push(messages)
|
|
127
|
-
return turn++ === 0
|
|
128
|
-
? { toolCalls: [{ id: 'read-1', name: 'getFigureSource', arguments: {}, type: 'tool_use' }], stopReason: 'tool_use' }
|
|
129
|
-
: { text: '조회했습니다.', toolCalls: [], stopReason: 'end_turn' }
|
|
130
|
-
} } as any,
|
|
131
|
-
messages: [{ role: 'user', content: '현재 모델을 조회해줘' }],
|
|
132
|
-
systemPrompt: 'Read the current figure.', toolCategories: ['figure-authoring'],
|
|
133
|
-
state: { domain: MINE }, hostContext: { figureId: 'fig-1', draftSource: SOURCE },
|
|
134
|
-
/*
|
|
135
|
-
* 도구가 닿는 문의 권한을 선언한 뒤로(ADR-0071 결정 2), 권한을 물어볼 길을 주지 않으면 그 도구는
|
|
136
|
-
* 닫힌다 — 그것이 맞는 기본값이다. 여기서 보는 것은 권한이 아니라 배선이므로 「가진 사람」으로 둔다.
|
|
137
|
-
*/
|
|
138
|
-
toolAccess: async () => true
|
|
139
|
-
})
|
|
140
|
-
expect(seen).toHaveLength(2)
|
|
141
|
-
expect(JSON.stringify(seen[1])).toContain('MIXER')
|
|
142
|
-
expect(JSON.stringify(seen[1])).not.toContain('FIGURE_TARGET_REQUIRED')
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
/*
|
|
146
|
-
등록된 범주에 도구 넷이 있다는 것과, 넷이 **모델에게 건네졌다**는 것은 다른 사실이다. 그 사이에
|
|
147
|
-
관문이 하나 있다 — `resolveToolScope` 가 도구마다 `doors` 를 부르는 사람의 권한에 물어 통과한 것만
|
|
148
|
-
싣는다(ADR-0071 결정 2). 그래서 등록은 넷인데 대화에 실리는 것은 셋일 수 있고, 그때 화면은 아무
|
|
149
|
-
오류도 내지 않는다 — 모델이 그 도구를 안 부르니 「후보를 만들었습니다」로 끝난다.
|
|
150
|
-
|
|
151
|
-
위의 배선 시험은 도구 하나(`getFigureSource`)가 오간 것으로 그 줄을 확인한다. 나머지 셋이 실렸는지는
|
|
152
|
-
보지 않는다. 그래서 건네진 목록 자체를 여기서 읽는다.
|
|
153
|
-
*/
|
|
154
|
-
describe('모델에게 건네지는 목록', () => {
|
|
155
|
-
/** `chatWithTools(messages, toolDefs, options)` 의 둘째 인자를 그대로 잡는다. */
|
|
156
|
-
async function offeredWith(access: (door: string) => Promise<boolean>) {
|
|
157
|
-
const offered: string[][] = []
|
|
158
|
-
|
|
159
|
-
await registryAssistantChat({
|
|
160
|
-
client: {
|
|
161
|
-
chatWithTools: async (_messages: any[], toolDefs: any[]) => {
|
|
162
|
-
offered.push((toolDefs ?? []).map(one => one.name ?? one.function?.name))
|
|
163
|
-
return { text: '네.', toolCalls: [], stopReason: 'end_turn' }
|
|
164
|
-
}
|
|
165
|
-
} as any,
|
|
166
|
-
messages: [{ role: 'user', content: '무엇을 할 수 있나' }],
|
|
167
|
-
systemPrompt: 'Author figures.',
|
|
168
|
-
toolCategories: ['figure-authoring'],
|
|
169
|
-
state: { domain: MINE },
|
|
170
|
-
hostContext: { figureId: 'fig-1', draftSource: SOURCE },
|
|
171
|
-
toolAccess: access
|
|
172
|
-
} as any)
|
|
173
|
-
|
|
174
|
-
expect(offered).toHaveLength(1)
|
|
175
|
-
return offered[0]!.sort()
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
it('★ 도구 넷이 다 건네진다 — 문을 다 가진 사람에게', async () => {
|
|
179
|
-
expect(await offeredWith(async () => true)).toEqual([
|
|
180
|
-
'getFigureSource',
|
|
181
|
-
'inspectFigure',
|
|
182
|
-
'listFigures',
|
|
183
|
-
'proposeFigureCandidate'
|
|
184
|
-
])
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
/*
|
|
188
|
-
넷이 문 넷을 하나씩 나눠 가지므로, 문 하나를 닫으면 도구 하나만 빠져야 한다. 이 갈래가 없으면
|
|
189
|
-
위 시험은 「관문이 아무것도 안 걸러도」 초록이다.
|
|
190
|
-
|
|
191
|
-
후보를 내는 도구를 닫힌 쪽으로 골랐다. 읽기 권한만 가진 사람이 저작 대화를 열면 목록과 정본과
|
|
192
|
-
검사는 되고 후보 생성은 안 되는 것이 그 사람에게 맞는 모양이다.
|
|
193
|
-
*/
|
|
194
|
-
it('★ 문이 닫힌 도구 하나만 빠진다 — 나머지 셋은 그대로다', async () => {
|
|
195
|
-
const offered = await offeredWith(async door => door !== 'Mutation.proposeFigure')
|
|
196
|
-
|
|
197
|
-
expect(offered).toEqual(['getFigureSource', 'inspectFigure', 'listFigures'])
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
/*
|
|
201
|
-
권한을 물어볼 길이 없으면 문에 닿는 도구는 전부 닫힌다(`resolveToolScope`: `if (!access) return false`).
|
|
202
|
-
figure 의 넷은 전부 문에 닿으므로 하나도 남지 않는다 — 부분만 열리는 일이 없다는 뜻이다.
|
|
203
|
-
*/
|
|
204
|
-
it('물어볼 길이 없으면 하나도 건네지지 않는다', async () => {
|
|
205
|
-
const offered = await offeredWith(undefined as any)
|
|
206
|
-
|
|
207
|
-
expect(offered).toEqual([])
|
|
208
|
-
})
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
describe('범주가 등록된다', () => {
|
|
212
|
-
it('figure-authoring 이 도구 넷과 함께 올라온다', () => {
|
|
213
|
-
const category = getToolCategories().find((one: any) => one.name === 'figure-authoring')!
|
|
214
|
-
|
|
215
|
-
expect(category.specs.map((one: any) => one.name).sort()).toEqual([
|
|
216
|
-
'getFigureSource',
|
|
217
|
-
'inspectFigure',
|
|
218
|
-
'listFigures',
|
|
219
|
-
'proposeFigureCandidate'
|
|
220
|
-
])
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
it('전부 조회 전용이다 — 되돌릴 수 없는 조작이 대화면으로 새지 않는다', () => {
|
|
224
|
-
const category = getToolCategories().find((one: any) => one.name === 'figure-authoring')!
|
|
225
|
-
|
|
226
|
-
expect(category.specs.map((one: any) => one.kind)).toEqual(['read', 'read', 'read', 'read'])
|
|
227
|
-
})
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
/*
|
|
231
|
-
twin 이 이 자리에서 사고를 냈다. 조치 요청에 도구를 부르지 않고 「제안해 두었습니다」라고만 답해
|
|
232
|
-
사용자에게 없는 버튼을 누르라고 안내했다. figure 도 같은 구조다 — 후보 칸은 도구 호출 결과에서만
|
|
233
|
-
만들어진다. 그래서 규율을 도구와 함께 보내고, 그 규율이 실려 있는지를 여기서 못박는다.
|
|
234
|
-
*/
|
|
235
|
-
describe('규율이 도구와 함께 나간다', () => {
|
|
236
|
-
it('후보는 도구 호출로만 생긴다는 것을 규율이 말한다', () => {
|
|
237
|
-
const category = getToolCategories().find((one: any) => one.name === 'figure-authoring')!
|
|
238
|
-
|
|
239
|
-
expect(category.guidance).toBeTruthy()
|
|
240
|
-
expect(category.guidance).toContain('proposeFigureCandidate')
|
|
241
|
-
expect(category.guidance).toMatch(/\*\*false\*\*/)
|
|
242
|
-
expect(category.guidance).toMatch(/exists only as the result of that call/)
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
it('고치기 전에 정본을 읽으라고 말한다 — 이름이 갈리면 배치된 보드가 끊긴다', () => {
|
|
246
|
-
const category = getToolCategories().find((one: any) => one.name === 'figure-authoring')!
|
|
247
|
-
|
|
248
|
-
expect(category.guidance).toContain('getFigureSource')
|
|
249
|
-
expect(category.guidance).toMatch(/breaks the bindings/)
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
/*
|
|
253
|
-
:3300, 2026-10-16, a real model: asked for "폭 600mm, 높이 800mm", the conversation's model passed the step writer
|
|
254
|
-
"폭 Y=600mm, 높이 Z=800mm" -- told to name sizes by axis, it guessed which was up, and the writer's Y is up. The
|
|
255
|
-
person's words go to the writer as they are; the writer knows the figure's axes.
|
|
256
|
-
*/
|
|
257
|
-
it('넘기는 요청은 사람의 말 그대로 — 축을 붙여 옮기지 않는다', () => {
|
|
258
|
-
const category = getToolCategories().find((one: any) => one.name === 'figure-authoring')!
|
|
259
|
-
const prompt = category.specs.find((spec: any) => spec.name === 'proposeFigureCandidate').schema.properties.prompt.description
|
|
260
|
-
|
|
261
|
-
expect(category.guidance).toMatch(/pass the person's words as they are/)
|
|
262
|
-
expect(category.guidance).toMatch(/Y is up/)
|
|
263
|
-
expect(category.guidance).not.toMatch(/Name coordinates and sizes by their X\/Y\/Z axes/)
|
|
264
|
-
expect(prompt).toMatch(/do not turn sizes into axes/)
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
it('타입 이름을 지어내지 말라고 말한다 — 저장되는 식별자다', () => {
|
|
268
|
-
const category = getToolCategories().find((one: any) => one.name === 'figure-authoring')!
|
|
269
|
-
|
|
270
|
-
expect(category.guidance).toContain('listFigures')
|
|
271
|
-
expect(category.guidance).toMatch(/stored identifier/)
|
|
272
|
-
})
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
/*
|
|
276
|
-
What the model reads is written in English (ADR-0061 Figure AI follow-up 5): the category's description and rules,
|
|
277
|
-
each tool's description and argument descriptions, and the control messages a tool returns. The answer's language is
|
|
278
|
-
the request's; a person's own words, figure names and attachments are not translated.
|
|
279
|
-
*/
|
|
280
|
-
describe('모델이 읽는 글은 영어다', () => {
|
|
281
|
-
const hangul = /[\u3131-\u318e\uac00-\ud7a3]/
|
|
282
|
-
|
|
283
|
-
it('범주의 설명과 규율, 도구와 인자의 설명', () => {
|
|
284
|
-
const category = getToolCategories().find((one: any) => one.name === 'figure-authoring')!
|
|
285
|
-
const texts = [
|
|
286
|
-
category.description,
|
|
287
|
-
category.guidance,
|
|
288
|
-
...category.specs.flatMap((spec: any) => [spec.description, ...Object.values(spec.schema?.properties ?? {}).map((one: any) => one.description)])
|
|
289
|
-
]
|
|
290
|
-
for (const text of texts) expect(text).not.toMatch(hangul)
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
it('도구가 돌려주는 제어 메시지', async () => {
|
|
294
|
-
const missing = await toolNamed('getFigureSource').builder({}, ctx({}))
|
|
295
|
-
const notOpen = await toolNamed('proposeFigureCandidate').builder({ prompt: 'fix it', figureId: 'fig-blank' }, ctx(modeller()))
|
|
296
|
-
for (const result of [missing, notOpen]) {
|
|
297
|
-
expect(result.error).toBeTruthy()
|
|
298
|
-
expect(JSON.stringify(result)).not.toMatch(hangul)
|
|
299
|
-
}
|
|
300
|
-
})
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
describe('대화면 문맥에서 대상을 해소한다', () => {
|
|
304
|
-
it('id 를 안 주면 열려 있는 피규어를 읽는다 — 사용자에게 되묻지 않는다', async () => {
|
|
305
|
-
const result = await toolNamed('getFigureSource').builder({}, ctx())
|
|
306
|
-
|
|
307
|
-
expect(result.id).toBe('fig-1')
|
|
308
|
-
expect(result.source.name).toBe('Mixer')
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
it.each(['getFigureSource', 'inspectFigure'])('%s: 목록의 대상 누락은 채팅을 끊지 않고 다음 동작을 안내한다', async name => {
|
|
312
|
-
const result = await toolNamed(name).builder({}, ctx({}))
|
|
313
|
-
expect(result.error).toBe('FIGURE_TARGET_REQUIRED')
|
|
314
|
-
expect(result.nextStep).toContain('listFigures')
|
|
315
|
-
expect(result.nextStep).toContain('create: true')
|
|
316
|
-
expect(result.source).toBeUndefined()
|
|
317
|
-
})
|
|
318
|
-
|
|
319
|
-
it('목록에서 대상을 찾아 다시 호출하면 해당 피규어의 정본을 읽는다', async () => {
|
|
320
|
-
const catalog = await toolNamed('listFigures').builder({}, ctx({}))
|
|
321
|
-
const target = catalog.figures.find((figure: any) => figure.name === '믹서')
|
|
322
|
-
const result = await toolNamed('getFigureSource').builder({ figureId: target.id }, ctx({}))
|
|
323
|
-
expect(result.id).toBe('fig-1')
|
|
324
|
-
expect(result.source.name).toBe('Mixer')
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
it('정본이 없는 피규어는 없다고 말한다 — 지어내지 않는다', async () => {
|
|
328
|
-
const result = await toolNamed('getFigureSource').builder({ figureId: 'fig-blank' }, ctx())
|
|
329
|
-
|
|
330
|
-
expect(result.source).toBeNull()
|
|
331
|
-
expect(result.cost).toBeNull()
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
it('측정한 비용이 함께 온다 — 눈대중으로 세지 않게', async () => {
|
|
335
|
-
const result = await toolNamed('getFigureSource').builder({ figureId: 'fig-1' }, ctx())
|
|
336
|
-
|
|
337
|
-
expect(result.cost.triangles).toBeGreaterThan(0)
|
|
338
|
-
expect(result.cost.groups).toBeGreaterThan(0)
|
|
339
|
-
})
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
/*
|
|
343
|
-
사람이 목록에서 고르는 길에서는 드러나지 않는다. 모델은 대화 내용에 이끌려 임의의 id 를 넘길 수
|
|
344
|
-
있고, 그것을 그대로 믿으면 남의 테넌트를 읽는다.
|
|
345
|
-
*/
|
|
346
|
-
describe('모델이 넘긴 id 를 믿지 않는다', () => {
|
|
347
|
-
it('다른 도메인의 피규어는 못 찾았다고 한다', async () => {
|
|
348
|
-
await expect(toolNamed('getFigureSource').builder({ figureId: 'fig-other' }, ctx())).rejects.toThrow(
|
|
349
|
-
/not found in this tenant/
|
|
350
|
-
)
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
it('발행 판정도 같은 확인을 지난다', async () => {
|
|
354
|
-
await expect(toolNamed('inspectFigure').builder({ figureId: 'fig-other' }, ctx())).rejects.toThrow(
|
|
355
|
-
/not found in this tenant/
|
|
356
|
-
)
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
it('목록은 자기 도메인만 낸다', async () => {
|
|
360
|
-
const result = await toolNamed('listFigures').builder({}, ctx())
|
|
361
|
-
|
|
362
|
-
expect(result.figures.map((one: any) => one.id)).toEqual(['fig-1', 'fig-blank'])
|
|
363
|
-
})
|
|
364
|
-
|
|
365
|
-
it('도구 설명이 저장 전 피규어는 모델러에 열린 것만 읽는다고 말한다', () => {
|
|
366
|
-
const description = toolNamed('getFigureSource').schema.properties.figureId.description
|
|
367
|
-
expect(description).not.toMatch(/never saved is not open/)
|
|
368
|
-
expect(description).toMatch(/not saved yet/)
|
|
369
|
-
})
|
|
370
|
-
|
|
371
|
-
it('도메인 문맥이 없으면 아무것도 읽지 않는다', async () => {
|
|
372
|
-
await expect(toolNamed('listFigures').builder({}, { state: {} })).rejects.toThrow(/domain context is missing/)
|
|
373
|
-
})
|
|
374
|
-
})
|
|
375
|
-
|
|
376
|
-
/*
|
|
377
|
-
The list stops at the most recently changed ones. A figure past that point used to be absent with nothing said - the
|
|
378
|
-
model took the cut list for the whole one and told the person the figure did not exist.
|
|
379
|
-
*/
|
|
380
|
-
describe('목록이 잘릴 때', () => {
|
|
381
|
-
const many = [
|
|
382
|
-
...Array.from({ length: 205 }, (_, i) => ({ id: `fig-n${i}`, type: `NEW_${i}`, name: `새 것 ${i}`, state: 'draft', domain: MINE, source: null })),
|
|
383
|
-
{ id: 'fig-old', type: 'OLD_PRESS', name: 'Roll press', state: 'released', domain: MINE, source: null }
|
|
384
|
-
]
|
|
385
|
-
beforeEach(() => {
|
|
386
|
-
const model = require('@hatiolab/figure-model')
|
|
387
|
-
__setFigureToolDepsForTest({ getRepository: () => stubRepository(many), Figure: class {}, figureCostOf: model.figureCostOf, figureScoreOf: model.figureScoreOf })
|
|
388
|
-
})
|
|
389
|
-
|
|
390
|
-
it('잘렸다고 말한다', async () => {
|
|
391
|
-
const result = await toolNamed('listFigures').builder({}, ctx({}))
|
|
392
|
-
expect(result.figures).toHaveLength(200)
|
|
393
|
-
expect(result.truncated).toBe(true)
|
|
394
|
-
expect(result.note).toMatch(/search/)
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
it('이름이나 타입의 일부로 찾으면 잘린 뒤의 피규어도 나온다 — 대소문자 없이', async () => {
|
|
398
|
-
const byName = await toolNamed('listFigures').builder({ search: 'roll PRESS' }, ctx({}))
|
|
399
|
-
const byType = await toolNamed('listFigures').builder({ search: 'old_press' }, ctx({}))
|
|
400
|
-
expect(byName.figures.map((one: any) => one.id)).toEqual(['fig-old'])
|
|
401
|
-
expect(byType.figures.map((one: any) => one.id)).toEqual(['fig-old'])
|
|
402
|
-
expect(byName.truncated).toBeUndefined()
|
|
403
|
-
})
|
|
404
|
-
|
|
405
|
-
it('찾는 말도 자기 도메인 안에서만 찾는다', async () => {
|
|
406
|
-
__setFigureToolDepsForTest({ getRepository: () => stubRepository(ROWS), Figure: class {} })
|
|
407
|
-
const result = await toolNamed('listFigures').builder({ search: 'secret' }, ctx({}))
|
|
408
|
-
expect(result.figures).toEqual([])
|
|
409
|
-
})
|
|
410
|
-
})
|
|
411
|
-
|
|
412
|
-
/*
|
|
413
|
-
제안은 모델러의 명령 목록이다(ADR-0094). 고치는 제안은 모델러가 모델이 본 버전 위에 한 단계로 적용하므로, 고칠 수
|
|
414
|
-
있는 것은 모델러에 열린 피규어뿐이고 그 버전(context · revision)을 문맥이 싣고 와야 한다.
|
|
415
|
-
*/
|
|
416
|
-
const figureDraft = () => {
|
|
417
|
-
const model = require('@hatiolab/figure-model')
|
|
418
|
-
let asset = model.createFigureAsset('Probe')
|
|
419
|
-
asset = model.addFigureBox(asset, { id: 'body', size: { x: 100, y: 100, z: 100 }, position: { x: 0, y: 50, z: 0 } })
|
|
420
|
-
return asset
|
|
421
|
-
}
|
|
422
|
-
const modeller = (over: any = {}) => ({ figureId: 'fig-1', draftSource: figureDraft(), context: 'ctx-7', revision: 4, ...over })
|
|
423
|
-
|
|
424
|
-
describe('제안을 요청할 때', () => {
|
|
425
|
-
it('열린 피규어를 고치면 그 초안이 제안기에 가고, 모델러가 적용할 버전이 함께 돌아온다', async () => {
|
|
426
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: '다리를 길게' }, ctx(modeller()))
|
|
427
|
-
expect(proposed[0].base.name).toBe('Probe')
|
|
428
|
-
expect(proposed[0].base.version).toBe('figure-asset-1')
|
|
429
|
-
expect(out.context).toBe('ctx-7')
|
|
430
|
-
expect(out.revision).toBe(4)
|
|
431
|
-
expect(out.figureId).toBe('fig-1')
|
|
432
|
-
expect(out.create).toBe(false)
|
|
433
|
-
})
|
|
434
|
-
|
|
435
|
-
it('버전을 모르는 문맥에서는 고치는 제안을 내지 않는다 — 다른 버전에 적용되지 않게', async () => {
|
|
436
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: '다리를 길게' }, ctx(modeller({ revision: undefined })))
|
|
437
|
-
expect(out.error).toBe('FIGURE_NOT_OPEN')
|
|
438
|
-
expect(proposed).toHaveLength(0)
|
|
439
|
-
})
|
|
440
|
-
|
|
441
|
-
it('모델러에 열리지 않은 피규어는 고치지 않고, 열라고 말한다', async () => {
|
|
442
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: '고쳐줘', figureId: 'fig-blank' }, ctx(modeller()))
|
|
443
|
-
expect(out.error).toBe('FIGURE_NOT_OPEN')
|
|
444
|
-
expect(proposed).toHaveLength(0)
|
|
445
|
-
})
|
|
446
|
-
|
|
447
|
-
it('원본이 없는 피규어는 고치지 않는다 — 빈 것을 제안기에 건네지 않는다', async () => {
|
|
448
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: '고쳐줘' }, ctx({ figureId: 'fig-blank', context: 'c', revision: 1 }))
|
|
449
|
-
expect(out.error).toBe('FIGURE_NOT_OPEN')
|
|
450
|
-
expect(proposed).toHaveLength(0)
|
|
451
|
-
})
|
|
452
|
-
|
|
453
|
-
it('목록에서 새 제작은 열린 피규어를 요구하지 않는다', async () => {
|
|
454
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: '믹서를 새로 만들어줘', create: true, name: 'Mixer' }, ctx({}))
|
|
455
|
-
expect(out.proposed).toBe(true)
|
|
456
|
-
expect(proposed[0].base).toBeUndefined()
|
|
457
|
-
expect(proposed[0].name).toBe('Mixer')
|
|
458
|
-
expect(out.create).toBe(true)
|
|
459
|
-
expect(out.context).toBeUndefined()
|
|
460
|
-
})
|
|
461
|
-
|
|
462
|
-
it('figureId null 은 도구 설명대로 새 제작이다', async () => {
|
|
463
|
-
await toolNamed('proposeFigureCandidate').builder({ prompt: '새로 만들어줘', figureId: null }, ctx(modeller()))
|
|
464
|
-
expect(proposed[0].base).toBeUndefined()
|
|
465
|
-
})
|
|
466
|
-
|
|
467
|
-
it('create 를 켜면 열린 피규어가 있어도 새로 만든다 — 열린 것을 덮어쓰는 제안이 오지 않게', async () => {
|
|
468
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: '새 컨베이어', create: true }, ctx(modeller()))
|
|
469
|
-
expect(proposed[0].base).toBeUndefined()
|
|
470
|
-
expect(out.revision).toBeUndefined()
|
|
471
|
-
})
|
|
472
|
-
|
|
473
|
-
it('빈 요청은 거절한다', async () => {
|
|
474
|
-
await expect(toolNamed('proposeFigureCandidate').builder({ prompt: ' ' }, ctx(modeller()))).rejects.toThrow(/prompt is required/)
|
|
475
|
-
})
|
|
476
|
-
|
|
477
|
-
it('남의 피규어를 고치라고 하면 못 찾았다고 한다', async () => {
|
|
478
|
-
await expect(
|
|
479
|
-
toolNamed('proposeFigureCandidate').builder({ prompt: '고쳐줘', figureId: 'fig-other' }, ctx(modeller()))
|
|
480
|
-
).rejects.toThrow(/not found in this tenant/)
|
|
481
|
-
})
|
|
482
|
-
|
|
483
|
-
it('세 번 거절된 끝의 사유가 도구 경계를 넘어간다 — 실패 한 줄만 남지 않게', async () => {
|
|
484
|
-
const { ProposeFigureFailure } = require('./figure-propose-steps')
|
|
485
|
-
const model = require('@hatiolab/figure-model')
|
|
486
|
-
__setFigureToolDepsForTest({
|
|
487
|
-
getRepository: () => stubRepository(ROWS),
|
|
488
|
-
Figure: class {},
|
|
489
|
-
parseSource: require('./figure-format').parseSource,
|
|
490
|
-
proposeFigureSteps: async () => {
|
|
491
|
-
throw new ProposeFigureFailure('The figure could not be made.', ['ATTACH_FACE: steps[4]: attach: faces along x'], 3)
|
|
492
|
-
},
|
|
493
|
-
figureCostOf: model.figureCostOf,
|
|
494
|
-
figureScoreOf: model.figureScoreOf
|
|
495
|
-
})
|
|
496
|
-
await expect(toolNamed('proposeFigureCandidate').builder({ prompt: '고쳐줘' }, ctx(modeller()))).rejects.toThrow(
|
|
497
|
-
/The figure could not be made\.\nATTACH_FACE: steps\[4\]/
|
|
498
|
-
)
|
|
499
|
-
})
|
|
500
|
-
})
|
|
501
|
-
|
|
502
|
-
/*
|
|
503
|
-
제안이 화면에 닿는 길은 하나다 — 도구 결과의 `proposed: true` 가 카드를 만들고, 카드의 실행 단추가
|
|
504
|
-
figure-ui 의 처리기에 넘긴다. 이 표시가 빠지면 제안은 도구 추적 안에 묻히고 화면에는 아무것도 생기지
|
|
505
|
-
않는다. 그때 모델이 「후보를 만들었습니다」라고 쓴 것이 거짓이 된다.
|
|
506
|
-
*/
|
|
507
|
-
describe('제안이 카드가 된다', () => {
|
|
508
|
-
it('proposed 표시와 명령 목록이 함께 온다', async () => {
|
|
509
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: '교반기', create: true }, ctx({}))
|
|
510
|
-
expect(out.proposed).toBe(true)
|
|
511
|
-
expect(out.steps).toEqual([{ kind: 'rename', name: 'Mixer' }])
|
|
512
|
-
})
|
|
513
|
-
|
|
514
|
-
/*
|
|
515
|
-
The card's two lines are sentences a person reads, so the tool writes them with the request's translator
|
|
516
|
-
(ADR-0061, 2026-10-16 decision 1). They were Korean strings in the code: an English screen read Korean.
|
|
517
|
-
*/
|
|
518
|
-
it('★ 카드에 그릴 두 줄이 요청 로케일로, 잰 값으로 온다', async () => {
|
|
519
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: '교반기', create: true, name: 'Mixer' }, ctx({}, { t: translatorOf('ko') }))
|
|
520
|
-
expect(out.label).toBe('Mixer 만들기')
|
|
521
|
-
expect(out.reason).toBe('명령 1개 · 등급 B · 삼각형 12 · 1번에 만들었다')
|
|
522
|
-
})
|
|
523
|
-
|
|
524
|
-
it('★ 같은 제안이 영어 화면에는 영어로 온다 — 글은 코드에 박히지 않는다', async () => {
|
|
525
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: 'mixer', create: true, name: 'Mixer' }, ctx({}, { t: translatorOf('en') }))
|
|
526
|
-
expect(out.label).toBe('Make Mixer')
|
|
527
|
-
expect(out.reason).toBe('1 commands · grade B · 12 triangles · made in 1 tries')
|
|
528
|
-
})
|
|
529
|
-
|
|
530
|
-
it('번역기에 이 글이 없어도 영어 기본값을 쓴다 — 키가 화면에 뜨지 않게', async () => {
|
|
531
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: 'mixer', create: true, name: 'Mixer' }, ctx({}))
|
|
532
|
-
expect(out.label).toBe('Make Mixer')
|
|
533
|
-
expect(out.reason).toBe('1 commands · grade B · 12 triangles · made in 1 tries')
|
|
534
|
-
})
|
|
535
|
-
|
|
536
|
-
it('고치는 것과 만드는 것을 이름으로 가른다', async () => {
|
|
537
|
-
const revise = await toolNamed('proposeFigureCandidate').builder({ prompt: '고쳐줘' }, ctx(modeller(), { t: translatorOf('ko') }))
|
|
538
|
-
const create = await toolNamed('proposeFigureCandidate').builder({ prompt: '만들어줘', create: true }, ctx({}, { t: translatorOf('ko') }))
|
|
539
|
-
expect(revise.label).toBe('Probe 수정')
|
|
540
|
-
expect(create.label).toBe('Figure 만들기')
|
|
541
|
-
})
|
|
542
|
-
|
|
543
|
-
it('카드의 글은 여섯 언어 모두에 있다', () => {
|
|
544
|
-
for (const locale of ['en', 'ko', 'ja', 'zh', 'es', 'ms']) {
|
|
545
|
-
const words = require(`../../../translations/${locale}.json`)
|
|
546
|
-
for (const key of ['figure.proposal.label-create', 'figure.proposal.label-revise', 'figure.proposal.reason']) {
|
|
547
|
-
expect([locale, key, typeof words[key]]).toEqual([locale, key, 'string'])
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
})
|
|
551
|
-
})
|
|
552
|
-
|
|
553
|
-
/*
|
|
554
|
-
A picture the person attached reaches the step generator (ADR-0061, 2026-10-16 decision 2). The dock uploads files by
|
|
555
|
-
attachmentIds and never fills hostContext.image, so the tool reads the server-checked attachments, every image of them.
|
|
556
|
-
*/
|
|
557
|
-
describe('사람이 붙인 그림', () => {
|
|
558
|
-
const FRONT = { id: 'att-1', name: 'front.png', kind: 'image', mediaType: 'image/png', size: 4, data: Buffer.from([1, 2, 3, 4]) }
|
|
559
|
-
const NOTES = { id: 'att-2', name: 'notes.txt', kind: 'text', mediaType: 'text/plain', size: 5, text: 'tall', truncated: false }
|
|
560
|
-
const SIDE = { id: 'att-3', name: 'side.jpg', kind: 'image', mediaType: 'image/jpeg', size: 3, data: Buffer.from([9, 9, 9]) }
|
|
561
|
-
|
|
562
|
-
it('★ 서버가 확인한 첨부의 그림이 모두, 붙인 순서로 제안기에 간다', async () => {
|
|
563
|
-
await toolNamed('proposeFigureCandidate').builder({ prompt: '이 그림처럼', create: true }, ctx({}, { attachments: [FRONT, NOTES, SIDE] }))
|
|
564
|
-
expect(proposed[0].images).toEqual([
|
|
565
|
-
{ data: FRONT.data, mediaType: 'image/png' },
|
|
566
|
-
{ data: SIDE.data, mediaType: 'image/jpeg' }
|
|
567
|
-
])
|
|
568
|
-
})
|
|
569
|
-
|
|
570
|
-
it('★ 화면이 hostContext 에 실은 그림은 제안기에 가지 않는다 — 서버가 확인한 것이 아니다', async () => {
|
|
571
|
-
const host = { image: { data: 'AQIDBA==', mediaType: 'image/png' }, attachments: [{ mediaType: 'image/png', data: 'AQIDBA==' }] }
|
|
572
|
-
await toolNamed('proposeFigureCandidate').builder({ prompt: '이 그림처럼', create: true }, ctx(host))
|
|
573
|
-
expect(proposed[0].images).toBeUndefined()
|
|
574
|
-
})
|
|
575
|
-
|
|
576
|
-
it('그림이 없으면 그림 없이 묻는다', async () => {
|
|
577
|
-
await toolNamed('proposeFigureCandidate').builder({ prompt: '믹서', create: true }, ctx({}, { attachments: [NOTES] }))
|
|
578
|
-
expect(proposed[0].images).toBeUndefined()
|
|
579
|
-
})
|
|
580
|
-
|
|
581
|
-
it('★ 문이 받은 첨부가 도구를 지나 제안기까지 간다 — registryAssistantChat 경계 그대로', async () => {
|
|
582
|
-
let turn = 0
|
|
583
|
-
await registryAssistantChat({
|
|
584
|
-
client: {
|
|
585
|
-
chatWithTools: async () =>
|
|
586
|
-
turn++ === 0
|
|
587
|
-
? { toolCalls: [{ id: 'p-1', name: 'proposeFigureCandidate', arguments: { prompt: '이 그림처럼 만들어줘', create: true }, type: 'tool_use' }], stopReason: 'tool_use' }
|
|
588
|
-
: { text: '후보를 냈습니다.', toolCalls: [], stopReason: 'end_turn' }
|
|
589
|
-
} as any,
|
|
590
|
-
messages: [{ role: 'user', content: '이 그림처럼 만들어줘' }],
|
|
591
|
-
systemPrompt: 'Author figures.',
|
|
592
|
-
toolCategories: ['figure-authoring'],
|
|
593
|
-
state: { domain: MINE },
|
|
594
|
-
hostContext: {},
|
|
595
|
-
attachments: [FRONT] as any,
|
|
596
|
-
toolAccess: async () => true
|
|
597
|
-
})
|
|
598
|
-
expect(proposed).toHaveLength(1)
|
|
599
|
-
expect(proposed[0].images).toEqual([{ data: FRONT.data, mediaType: 'image/png' }])
|
|
600
|
-
})
|
|
601
|
-
})
|
|
602
|
-
|
|
603
|
-
describe('피규어가 모델러에 열려 있을 때', () => {
|
|
604
|
-
it('저장 전 초안을 이 모델로 읽고, 셈으로 잰다', async () => {
|
|
605
|
-
const draft = figureDraft()
|
|
606
|
-
const got = await toolNamed('getFigureSource').builder({}, ctx({ figureId: 'fig-1', draftSource: draft, palette: ['palette.primary'] }))
|
|
607
|
-
expect(got.draft).toBe(true)
|
|
608
|
-
expect(got.cost.triangles).toBe(12)
|
|
609
|
-
expect(got.score.grade).toBe('A')
|
|
610
|
-
})
|
|
611
|
-
|
|
612
|
-
/*
|
|
613
|
-
"This part", "the selected one", "the value I am trying": the screen sends what it has in view with the version it was
|
|
614
|
-
seen on (ADR-0097 §5.6 item 5). The model hears it only through a read tool (ADR-0061 decision 3), so a tool that
|
|
615
|
-
drops it leaves the model guessing which part was meant.
|
|
616
|
-
*/
|
|
617
|
-
it('선택한 부품과 시험 중인 값을 같은 버전에서 본 것일 때 함께 읽는다', async () => {
|
|
618
|
-
const host = modeller({
|
|
619
|
-
selection: { part: 'body', context: 'ctx-7', revision: 4 },
|
|
620
|
-
trying: { clips: { lift: 0.5 }, controls: { height: 300 }, context: 'ctx-7', revision: 4 }
|
|
621
|
-
})
|
|
622
|
-
const got = await toolNamed('getFigureSource').builder({}, ctx(host))
|
|
623
|
-
expect(got.selection).toEqual({ part: 'body' })
|
|
624
|
-
expect(got.trying).toEqual({ clips: { lift: 0.5 }, controls: { height: 300 } })
|
|
625
|
-
})
|
|
626
|
-
|
|
627
|
-
it('다른 버전에서 본 선택이나 초안에 없는 부품은 말하지 않는다 — 없는 부품을 가리키지 않게', async () => {
|
|
628
|
-
const stale = await toolNamed('getFigureSource').builder({}, ctx(modeller({ selection: { part: 'body', context: 'ctx-7', revision: 3 } })))
|
|
629
|
-
const missing = await toolNamed('getFigureSource').builder({}, ctx(modeller({ selection: { part: 'arm', context: 'ctx-7', revision: 4 } })))
|
|
630
|
-
expect(stale.selection).toBeUndefined()
|
|
631
|
-
expect(missing.selection).toBeUndefined()
|
|
632
|
-
})
|
|
633
|
-
|
|
634
|
-
it('시험 값은 수만 싣는다 — 화면이 보낸 것은 믿지 않는 자료다', async () => {
|
|
635
|
-
const got = await toolNamed('getFigureSource').builder(
|
|
636
|
-
{},
|
|
637
|
-
ctx(modeller({ trying: { clips: { lift: 'drop table', open: 1 }, controls: { height: Infinity }, context: 'ctx-7', revision: 4 } }))
|
|
638
|
-
)
|
|
639
|
-
expect(got.trying).toEqual({ clips: { open: 1 } })
|
|
640
|
-
})
|
|
641
|
-
|
|
642
|
-
it('저장된 정본을 읽을 때는 화면의 선택을 붙이지 않는다 — 다른 피규어의 선택일 수 있다', async () => {
|
|
643
|
-
const got = await toolNamed('getFigureSource').builder({ figureId: 'fig-1' }, ctx({ selection: { part: 'body', context: 'c', revision: 1 }, context: 'c', revision: 1 }))
|
|
644
|
-
expect(got.draft).toBe(false)
|
|
645
|
-
expect(got.selection).toBeUndefined()
|
|
646
|
-
})
|
|
647
|
-
|
|
648
|
-
it('고치는 제안에는 선택한 부품이 제안기까지 간다', async () => {
|
|
649
|
-
await toolNamed('proposeFigureCandidate').builder({ prompt: '이것을 더 크게' }, ctx(modeller({ selection: { part: 'body', context: 'ctx-7', revision: 4 } })))
|
|
650
|
-
expect(proposed[0].focus).toEqual({ selection: { part: 'body' } })
|
|
651
|
-
})
|
|
652
|
-
|
|
653
|
-
it('형식을 어긴 초안은 저장 문의 말로 거절한다', async () => {
|
|
654
|
-
const broken = { ...figureDraft(), appearance: [] }
|
|
655
|
-
await expect(toolNamed('getFigureSource').builder({}, ctx({ figureId: 'fig-1', draftSource: broken }))).rejects.toThrow(/unsaved draft is invalid/)
|
|
656
|
-
})
|
|
657
|
-
})
|
|
658
|
-
|
|
659
|
-
/*
|
|
660
|
-
A figure the kernel keeps (1 MiB) can be larger than the model is shown in one read (ADR-0061 2026-10-16 decision 4).
|
|
661
|
-
Until then the tools refused any draft over 100,000 characters: a figure that opened and saved got no read, no
|
|
662
|
-
inspection and no proposal, and saving again did not help. Now it is read as an outline and the parts asked for.
|
|
663
|
-
*/
|
|
664
|
-
describe('피규어가 한 번에 보일 만큼보다 클 때', () => {
|
|
665
|
-
const { FIGURE_CONTEXT_BUDGET } = require('./figure-context')
|
|
666
|
-
const model = require('@hatiolab/figure-model')
|
|
667
|
-
let under: any
|
|
668
|
-
let over: any
|
|
669
|
-
beforeAll(() => {
|
|
670
|
-
let rack = model.createFigureAsset('Rack')
|
|
671
|
-
for (let i = 0; ; i++) {
|
|
672
|
-
const next = model.applyFigureProposal(rack, [
|
|
673
|
-
{ kind: 'add-part', part: { id: `shelf-${i}`, kind: 'box', dimensions: { width: 1200, height: 40, depth: 600 } } },
|
|
674
|
-
i === 0
|
|
675
|
-
? { kind: 'attach', part: 'shelf-0', to: { plane: 'mounting-plane' } }
|
|
676
|
-
: { kind: 'attach', part: `shelf-${i}`, to: { part: `shelf-${i - 1}`, face: 'top' }, gap: 300 }
|
|
677
|
-
])
|
|
678
|
-
if (JSON.stringify(next).length > FIGURE_CONTEXT_BUDGET) {
|
|
679
|
-
under = rack
|
|
680
|
-
over = next
|
|
681
|
-
return
|
|
682
|
-
}
|
|
683
|
-
rack = next
|
|
684
|
-
}
|
|
685
|
-
})
|
|
686
|
-
|
|
687
|
-
it('바로 아래는 원본 전체를 읽는다', async () => {
|
|
688
|
-
const got = await toolNamed('getFigureSource').builder({}, ctx(modeller({ draftSource: under })))
|
|
689
|
-
expect(got.source).toEqual(under)
|
|
690
|
-
expect(got.outline).toBeUndefined()
|
|
691
|
-
})
|
|
692
|
-
|
|
693
|
-
it('바로 위도 거절하지 않는다 — 개요와 고른 부품을 읽고, 잰 값은 전체에서 잰다', async () => {
|
|
694
|
-
const got = await toolNamed('getFigureSource').builder({ parts: ['shelf-3'] }, ctx(modeller({ draftSource: over })))
|
|
695
|
-
expect(got.source).toBeUndefined()
|
|
696
|
-
expect(got.outline.parts).toHaveLength(over.appearance.length)
|
|
697
|
-
expect(Object.keys(got.partSources)).toEqual(['shelf-3'])
|
|
698
|
-
expect(JSON.stringify(got.outline).length).toBeLessThan(FIGURE_CONTEXT_BUDGET)
|
|
699
|
-
expect(got.note).toMatch(/parts/)
|
|
700
|
-
expect(got.cost).toEqual(model.figureCostOf(over))
|
|
701
|
-
expect(JSON.stringify(got).length).toBeLessThan(FIGURE_CONTEXT_BUDGET + 2_000)
|
|
702
|
-
})
|
|
703
|
-
|
|
704
|
-
it('절은 포인터로 읽는다', async () => {
|
|
705
|
-
const got = await toolNamed('getFigureSource').builder({ sections: ['/palette'] }, ctx(modeller({ draftSource: over })))
|
|
706
|
-
expect(got.sectionSources).toEqual({ '/palette': over.palette })
|
|
707
|
-
})
|
|
708
|
-
|
|
709
|
-
it('고른 부품이 없으면 선택한 부품을 읽는다', async () => {
|
|
710
|
-
const got = await toolNamed('getFigureSource').builder({}, ctx(modeller({ draftSource: over, selection: { part: 'shelf-6', context: 'ctx-7', revision: 4 } })))
|
|
711
|
-
expect(Object.keys(got.partSources)).toEqual(['shelf-6'])
|
|
712
|
-
})
|
|
713
|
-
|
|
714
|
-
it('저장된 원본도 같은 예산으로 읽는다', async () => {
|
|
715
|
-
__setFigureToolDepsForTest({
|
|
716
|
-
getRepository: () => stubRepository([{ id: 'fig-big', type: 'RACK', name: 'Rack', state: 'draft', domain: MINE, source: JSON.stringify(over) }]),
|
|
717
|
-
Figure: class {},
|
|
718
|
-
figureCostOf: model.figureCostOf,
|
|
719
|
-
figureScoreOf: model.figureScoreOf
|
|
720
|
-
})
|
|
721
|
-
const got = await toolNamed('getFigureSource').builder({ figureId: 'fig-big' }, ctx({}))
|
|
722
|
-
expect(got.source).toBeUndefined()
|
|
723
|
-
expect(got.outline.chars).toBe(JSON.stringify(over).length)
|
|
724
|
-
})
|
|
725
|
-
|
|
726
|
-
it('검사는 전체 원본으로 하고, 거절하지 않는다', async () => {
|
|
727
|
-
const seen: string[] = []
|
|
728
|
-
__setFigureToolDepsForTest({
|
|
729
|
-
getRepository: () => stubRepository(ROWS),
|
|
730
|
-
Figure: class {},
|
|
731
|
-
parseSource: require('./figure-format').parseSource,
|
|
732
|
-
inspectSource: (json: string) => {
|
|
733
|
-
seen.push(json)
|
|
734
|
-
return { blocked: false, findings: [] }
|
|
735
|
-
}
|
|
736
|
-
})
|
|
737
|
-
const got = await toolNamed('inspectFigure').builder({}, ctx(modeller({ draftSource: over })))
|
|
738
|
-
expect(got.blocked).toBe(false)
|
|
739
|
-
expect(seen[0].length).toBe(JSON.stringify(over).length)
|
|
740
|
-
})
|
|
741
|
-
|
|
742
|
-
it('검사 결과가 예산을 넘으면 앞에서부터 싣고 몇 개 중 몇 개인지 말한다', async () => {
|
|
743
|
-
const findings = Array.from({ length: 2_000 }, (_, i) => ({ code: 'part-outside-room', message: `shelf-${i} stands outside the room declared for the figure`, at: `shelf-${i}`, blocking: true }))
|
|
744
|
-
__setFigureToolDepsForTest({
|
|
745
|
-
getRepository: () => stubRepository(ROWS),
|
|
746
|
-
Figure: class {},
|
|
747
|
-
parseSource: require('./figure-format').parseSource,
|
|
748
|
-
inspectSource: () => ({ blocked: true, findings })
|
|
749
|
-
})
|
|
750
|
-
const got = await toolNamed('inspectFigure').builder({}, ctx(modeller({ draftSource: over })))
|
|
751
|
-
expect(JSON.stringify(got).length).toBeLessThanOrEqual(FIGURE_CONTEXT_BUDGET)
|
|
752
|
-
expect(got.truncated).toEqual({ shown: got.findings.length, total: 2_000 })
|
|
753
|
-
expect(got.findings[0]).toEqual(findings[0])
|
|
754
|
-
})
|
|
755
|
-
|
|
756
|
-
it('고치는 제안에 고른 부품이 제안기까지 가고, 버전은 그대로 돌아온다', async () => {
|
|
757
|
-
const out = await toolNamed('proposeFigureCandidate').builder(
|
|
758
|
-
{ prompt: '3단을 빨갛게', parts: ['shelf-3'], sections: ['/palette', 7] },
|
|
759
|
-
ctx(modeller({ draftSource: over }))
|
|
760
|
-
)
|
|
761
|
-
expect(proposed[0].base).toEqual(over)
|
|
762
|
-
expect(proposed[0].read).toEqual({ parts: ['shelf-3'], sections: ['/palette'] })
|
|
763
|
-
expect(out.revision).toBe(4)
|
|
764
|
-
})
|
|
765
|
-
})
|
|
766
|
-
|
|
767
|
-
/*
|
|
768
|
-
A figure not saved yet is a subject too (ADR-0061 decision 3). The modeller names it by its creation id - the id its
|
|
769
|
-
first save inserts the row under (ADR-0072 decision 6) - so before that save there is no row: the tools read the draft
|
|
770
|
-
the screen sent, through the same door a save goes through. Only the figure open on that screen: an id the model passes
|
|
771
|
-
that has no row and is not the open one is still not found.
|
|
772
|
-
*/
|
|
773
|
-
describe('저장 전 피규어', () => {
|
|
774
|
-
const CREATION = '33333333-3333-4333-8333-333333333333'
|
|
775
|
-
const unsaved = (over: any = {}) => modeller({ figureId: CREATION, editorMode: 'new', ...over })
|
|
776
|
-
|
|
777
|
-
it('★ 화면이 보낸 초안을 읽고 잰다 — 행이 없어도', async () => {
|
|
778
|
-
const got = await toolNamed('getFigureSource').builder({}, ctx(unsaved()))
|
|
779
|
-
expect(got).toMatchObject({ id: CREATION, name: 'Probe', draft: true })
|
|
780
|
-
expect(got.source.version).toBe('figure-asset-1')
|
|
781
|
-
expect(got.cost.triangles).toBe(12)
|
|
782
|
-
})
|
|
783
|
-
|
|
784
|
-
it('선택한 부품도 함께 읽는다 — 「이 부품」이 무엇인지', async () => {
|
|
785
|
-
const got = await toolNamed('getFigureSource').builder({}, ctx(unsaved({ selection: { part: 'body', context: 'ctx-7', revision: 4 } })))
|
|
786
|
-
expect(got.selection).toEqual({ part: 'body' })
|
|
787
|
-
})
|
|
788
|
-
|
|
789
|
-
it('발행 판정도 초안으로 한다', async () => {
|
|
790
|
-
const got = await toolNamed('inspectFigure').builder({}, ctx(unsaved()))
|
|
791
|
-
expect(got).toMatchObject({ blocked: false, draft: true })
|
|
792
|
-
})
|
|
793
|
-
|
|
794
|
-
it('★ 고치는 제안은 그 초안 위에, 모델러가 적용할 버전과 함께 낸다', async () => {
|
|
795
|
-
const out = await toolNamed('proposeFigureCandidate').builder({ prompt: '이 부품을 더 크게' }, ctx(unsaved({ selection: { part: 'body', context: 'ctx-7', revision: 4 } })))
|
|
796
|
-
expect(proposed[0].base.name).toBe('Probe')
|
|
797
|
-
expect(proposed[0].focus).toEqual({ selection: { part: 'body' } })
|
|
798
|
-
expect(out).toMatchObject({ create: false, figureId: CREATION, context: 'ctx-7', revision: 4 })
|
|
799
|
-
})
|
|
800
|
-
|
|
801
|
-
it('형식을 어긴 초안은 저장 문의 말로 거절한다', async () => {
|
|
802
|
-
const broken = { ...figureDraft(), appearance: [] }
|
|
803
|
-
await expect(toolNamed('getFigureSource').builder({}, ctx(unsaved({ draftSource: broken })))).rejects.toThrow(/unsaved draft is invalid/)
|
|
804
|
-
})
|
|
805
|
-
|
|
806
|
-
it('★ 열려 있지 않은 id 는 행이 없으면 못 찾았다고 한다', async () => {
|
|
807
|
-
await expect(toolNamed('getFigureSource').builder({ figureId: CREATION }, ctx(modeller()))).rejects.toThrow(/not found in this tenant/)
|
|
808
|
-
})
|
|
809
|
-
|
|
810
|
-
it('초안을 보내지 않은 화면에서는 못 찾았다고 한다', async () => {
|
|
811
|
-
await expect(toolNamed('getFigureSource').builder({}, ctx({ figureId: CREATION, editorMode: 'new' }))).rejects.toThrow(/not found in this tenant/)
|
|
812
|
-
})
|
|
813
|
-
|
|
814
|
-
it('생성 식별자 꼴이 아닌 이름은 저장 전 피규어로 읽지 않는다', async () => {
|
|
815
|
-
await expect(toolNamed('getFigureSource').builder({}, ctx(unsaved({ figureId: 'fig-unknown' })))).rejects.toThrow(/not found in this tenant/)
|
|
816
|
-
})
|
|
817
|
-
})
|