@things-factory/figure-service 10.1.48 → 10.1.49

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/figure-service",
3
- "version": "10.1.48",
3
+ "version": "10.1.49",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "@things-factory:registry": "https://registry.npmjs.org"
@@ -23,7 +23,7 @@
23
23
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
24
24
  },
25
25
  "dependencies": {
26
- "@hatiolab/figure-model": "^0.1.54",
26
+ "@hatiolab/figure-model": "^0.1.55",
27
27
  "@operato/typeorm-history": "^10.0.0",
28
28
  "@things-factory/ai-client-base": "^10.1.39",
29
29
  "@things-factory/auth-base": "^10.1.47",
@@ -33,5 +33,5 @@
33
33
  "graphql-upload": "^15.0.2",
34
34
  "koa-router": "^7.4.0"
35
35
  },
36
- "gitHead": "448b0d568a1816d25aa49f3b6233d8086d6011f9"
36
+ "gitHead": "f9b29dcbdfecbfdd72e33bbcf74aea05331da75f"
37
37
  }
@@ -79,7 +79,10 @@ function install() {
79
79
  costOf: model.costOf,
80
80
  scoreOf: model.scoreOf,
81
81
  validate: model.validate,
82
- isPlaceholderType: model.isPlaceholderType
82
+ isPlaceholderType: model.isPlaceholderType,
83
+ parseAnySource: require('./figure-format').parseAnySource,
84
+ v3CostOf: model.v3CostOf,
85
+ v3ScoreOf: model.v3ScoreOf
83
86
  })
84
87
  }
85
88
 
@@ -505,3 +508,38 @@ describe('후보가 카드가 된다', () => {
505
508
  expect(proposed[0].refine).toBe(false)
506
509
  })
507
510
  })
511
+
512
+ /*
513
+ V3 도형이 열려 있을 때(사용자 2026-09-24: 도크가 V3 초안에 「type 이 없다 · base 가 없다」 로 답했다). 읽기는 V3 로 읽고
514
+ 잰다. 후보 제안은 아직 V2 만 쓰므로 지어내지 않고 그렇다고 말한다.
515
+ */
516
+ describe('V3 도형이 열려 있을 때', () => {
517
+ const v3Draft = () => {
518
+ const model = require('@hatiolab/figure-model')
519
+ let asset = model.createV3Asset('Probe')
520
+ asset = model.addV3Box(asset, { id: 'body', size: { x: 100, y: 100, z: 100 }, position: { x: 0, y: 50, z: 0 } })
521
+ return asset
522
+ }
523
+
524
+ it('저장 전 V3 초안을 V3 로 읽고, V3 셈으로 잰다', async () => {
525
+ const draft = v3Draft()
526
+ const got = await toolNamed('getFigureSource').builder({}, ctx({ figureId: 'fig-1', draftSource: draft, palette: ['palette.primary'] }))
527
+ expect(got.format).toBe('v3')
528
+ expect(got.draft).toBe(true)
529
+ expect(got.cost.triangles).toBe(12)
530
+ expect(got.score.grade).toBe('A')
531
+ })
532
+
533
+ it('형식을 어긴 V3 초안은 V3 의 말로 거절한다 — V2 파서의 말이 아니다', async () => {
534
+ const broken = { ...v3Draft(), appearance: [] }
535
+ await expect(toolNamed('getFigureSource').builder({}, ctx({ figureId: 'fig-1', draftSource: broken, palette: ['palette.primary'] }))).rejects.toThrow(/V3 draft/)
536
+ await expect(toolNamed('getFigureSource').builder({}, ctx({ figureId: 'fig-1', draftSource: broken, palette: ['palette.primary'] }))).rejects.not.toThrow(/base 가 없다/)
537
+ })
538
+
539
+ it('후보 제안은 V3 도형에 V2 후보를 지어내지 않고, 아직 못 한다고 말한다', async () => {
540
+ const got = await toolNamed('proposeFigureCandidate').builder({ prompt: '다리를 길게' }, ctx({ figureId: 'fig-1', draftSource: v3Draft(), palette: ['palette.primary'] }))
541
+ expect(got.error).toBe('V3_PROPOSAL_UNAVAILABLE')
542
+ expect(proposed).toHaveLength(0)
543
+ })
544
+ })
545
+
@@ -62,6 +62,9 @@ function getDeps(): any {
62
62
  complaint. The tool's own contract is unchanged: it reads, it never saves (ADR-0087).
63
63
  */
64
64
  inspectSource: format.inspectAnySource,
65
+ parseAnySource: format.parseAnySource,
66
+ v3CostOf: model.v3CostOf,
67
+ v3ScoreOf: model.v3ScoreOf,
65
68
  proposeFigure: propose.proposeFigure,
66
69
  compile: model.compile,
67
70
  costOf: model.costOf,
@@ -153,6 +156,23 @@ async function resolveFigureTarget(figureId: string | undefined, domainId: strin
153
156
  * 찾은 뒤에만 보며, Figure의 불변 type과 형식 검증을 다시 확인한다. 검증되지 않은 큰 객체를 LLM
154
157
  * 프롬프트로 옮기면 비용만 태우고, DB에 있던 Figure와 다른 것을 고친다고 잘못 말할 수 있다.
155
158
  */
159
+ /** A V3 asset names its format in `version`; a V2 FigureSource carries a number there. */
160
+ const isV3 = (source: any) => source?.version === 'figure-v3-asset-1'
161
+
162
+ /**
163
+ * The V2 proposer writes V2 figures; a V3 figure open in the modeller is not something it can revise or add to. Said as
164
+ * what is true, with what the assistant can do instead -- not a V2 parser's complaint about a V3 asset (user,
165
+ * 2026-09-24: the dock answered 「type 이 없다 · base 가 없다」 for a V3 draft).
166
+ */
167
+ function v3ProposalUnavailable() {
168
+ return {
169
+ error: 'V3_PROPOSAL_UNAVAILABLE',
170
+ message: '이 도형은 V3 형식입니다. AI 후보 제안은 아직 V2 도형만 만들 수 있어 이 도형을 고치는 후보를 낼 수 없습니다.',
171
+ nextStep:
172
+ 'Tell the person plainly that candidate proposals do not support V3 figures yet. You can still read the figure (getFigureSource) and explain whether it may be released and why (inspectFigure). Do not produce a V2 candidate for a V3 figure.'
173
+ }
174
+ }
175
+
156
176
  function sourceForTool(row: any, host: any): { source: any; draft: boolean } {
157
177
  const isMatch = host?.figureId === row.id || (!row.id && host?.editorMode === 'new') || (!row.id && !host?.figureId)
158
178
  const draft = isMatch ? host?.draftSource : undefined
@@ -169,6 +189,17 @@ function sourceForTool(row: any, host: any): { source: any; draft: boolean } {
169
189
  throw new Error('the unsaved draft is too large to safely review')
170
190
  }
171
191
 
192
+ /* A V3 draft is checked as V3 -- the same door a save goes through. It names no type; the row does. */
193
+ if (isV3(draft)) {
194
+ try {
195
+ getDeps().parseAnySource(serialized)
196
+ } catch (e: any) {
197
+ const findings = Array.isArray(e?.findings) ? e.findings.map((one: any) => one.message).join(' · ') : String(e?.message ?? e)
198
+ throw new Error(`the unsaved V3 draft is invalid: ${findings}`)
199
+ }
200
+ return { source: draft, draft: true }
201
+ }
202
+
172
203
  const { validate, isPlaceholderType } = getDeps()
173
204
  const checked = validate(draft)
174
205
  if (checked.errors.length > 0) {
@@ -306,6 +337,22 @@ function figureToolSpecs(): ToolSpec[] {
306
337
  return { id: row.id, type: row.type, name: row.name, source: null, cost: null }
307
338
  }
308
339
 
340
+ if (isV3(current.source)) {
341
+ /* A V3 asset is measured as V3 -- triangles, draw groups, and its grade against one screen. */
342
+ const { v3CostOf, v3ScoreOf } = getDeps()
343
+ return {
344
+ id: row.id,
345
+ type: row.type,
346
+ name: row.name,
347
+ state: row.state,
348
+ format: 'v3',
349
+ source: current.source,
350
+ draft: current.draft,
351
+ cost: v3CostOf(current.source),
352
+ score: v3ScoreOf(current.source) ?? null
353
+ }
354
+ }
355
+
309
356
  const { compile, costOf, scoreOf } = getDeps()
310
357
  const blueprint = compile(current.source)
311
358
 
@@ -339,7 +386,7 @@ function figureToolSpecs(): ToolSpec[] {
339
386
 
340
387
  const current = sourceForTool(row, ctx?.host)
341
388
  const { inspectSource } = getDeps()
342
- return { ...inspectSource(current.source ? JSON.stringify(current.source) : null), draft: current.draft }
389
+ return { ...inspectSource(current.source ? JSON.stringify(current.source) : null, null, undefined, row.type), draft: current.draft }
343
390
  }
344
391
  },
345
392
  {
@@ -391,6 +438,7 @@ function figureToolSpecs(): ToolSpec[] {
391
438
  base = sourceForTool(row, ctx?.host).source ?? undefined
392
439
  }
393
440
  }
441
+ if (isV3(base) || (args?.create !== true && isV3(ctx?.host?.draftSource))) return v3ProposalUnavailable()
394
442
 
395
443
  const palette = Array.isArray(ctx?.host?.palette) ? ctx.host.palette : []
396
444
  if (palette.length === 0) {