@things-factory/figure-service 10.1.278 → 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.
Files changed (149) hide show
  1. package/package.json +23 -8
  2. package/coverage/clover.xml +0 -6
  3. package/coverage/coverage-final.json +0 -1
  4. package/coverage/lcov-report/base.css +0 -224
  5. package/coverage/lcov-report/block-navigation.js +0 -87
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +0 -101
  8. package/coverage/lcov-report/prettify.css +0 -1
  9. package/coverage/lcov-report/prettify.js +0 -2
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +0 -210
  12. package/coverage/lcov.info +0 -0
  13. package/dist-server/index.js.map +0 -1
  14. package/dist-server/migrations/index.js.map +0 -1
  15. package/dist-server/routers/figure-mesh-router.js.map +0 -1
  16. package/dist-server/routers/figure-package-router.js.map +0 -1
  17. package/dist-server/routers/figure-thumbnail-router.js.map +0 -1
  18. package/dist-server/routes.js.map +0 -1
  19. package/dist-server/service/figure/event-subscriber.js.map +0 -1
  20. package/dist-server/service/figure/figure-ai-scenarios-run.js.map +0 -1
  21. package/dist-server/service/figure/figure-ai-scenarios.js.map +0 -1
  22. package/dist-server/service/figure/figure-categories.js.map +0 -1
  23. package/dist-server/service/figure/figure-context.js.map +0 -1
  24. package/dist-server/service/figure/figure-format.js.map +0 -1
  25. package/dist-server/service/figure/figure-glb.js.map +0 -1
  26. package/dist-server/service/figure/figure-history.js.map +0 -1
  27. package/dist-server/service/figure/figure-llm-provider.js.map +0 -1
  28. package/dist-server/service/figure/figure-mesh-store.js.map +0 -1
  29. package/dist-server/service/figure/figure-mutation.js.map +0 -1
  30. package/dist-server/service/figure/figure-namespace-entity.js.map +0 -1
  31. package/dist-server/service/figure/figure-namespace-resolver.js.map +0 -1
  32. package/dist-server/service/figure/figure-namespace.js.map +0 -1
  33. package/dist-server/service/figure/figure-package-export.js.map +0 -1
  34. package/dist-server/service/figure/figure-proposal-record.js.map +0 -1
  35. package/dist-server/service/figure/figure-proposal.js.map +0 -1
  36. package/dist-server/service/figure/figure-propose-steps.js.map +0 -1
  37. package/dist-server/service/figure/figure-propose-type.js.map +0 -1
  38. package/dist-server/service/figure/figure-public.js.map +0 -1
  39. package/dist-server/service/figure/figure-query.js.map +0 -1
  40. package/dist-server/service/figure/figure-rename.js.map +0 -1
  41. package/dist-server/service/figure/figure-replaced-draft.js.map +0 -1
  42. package/dist-server/service/figure/figure-revert.js.map +0 -1
  43. package/dist-server/service/figure/figure-subject.js.map +0 -1
  44. package/dist-server/service/figure/figure-thumbnail-reader.js.map +0 -1
  45. package/dist-server/service/figure/figure-thumbnail-store.js.map +0 -1
  46. package/dist-server/service/figure/figure-thumbnail-upgrade.js.map +0 -1
  47. package/dist-server/service/figure/figure-tools.js.map +0 -1
  48. package/dist-server/service/figure/figure-type.js.map +0 -1
  49. package/dist-server/service/figure/figure-write.js.map +0 -1
  50. package/dist-server/service/figure/figure.js.map +0 -1
  51. package/dist-server/service/figure/index.js.map +0 -1
  52. package/dist-server/service/figure-recipe/figure-recipe-resolver.js.map +0 -1
  53. package/dist-server/service/figure-recipe/figure-recipe-templates.js.map +0 -1
  54. package/dist-server/service/figure-recipe/figure-recipe-type.js.map +0 -1
  55. package/dist-server/service/figure-recipe/index.js.map +0 -1
  56. package/dist-server/service/index.js.map +0 -1
  57. package/dist-server/tsconfig.tsbuildinfo +0 -1
  58. package/logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json +0 -15
  59. package/logs/application-2026-09-14-23.log +0 -0
  60. package/logs/figure-ai-scenarios/2026-11-03T09-31-35-151Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1167
  61. package/logs/figure-ai-scenarios/2026-11-03T09-39-05-265Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -904
  62. package/logs/figure-ai-scenarios/2026-11-03T09-41-49-107Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1629
  63. package/logs/figure-ai-scenarios/2026-11-03T09-58-26-681Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4412
  64. package/logs/figure-ai-scenarios/2026-11-03T10-16-46-212Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4513
  65. package/logs/figure-ai-scenarios/2026-11-03T10-21-07-872Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4202
  66. package/logs/figure-ai-scenarios/2026-11-03T10-25-21-721Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1665
  67. package/logs/figure-ai-scenarios/2026-11-09T01-28-51-664Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4484
  68. package/scripts/build-templates.mts +0 -64
  69. package/scripts/figure-ai-scenarios-agent.cjs +0 -98
  70. package/scripts/rename-figures-to-full-names.mjs +0 -211
  71. package/scripts/templates.test.mts +0 -112
  72. package/server/index.ts +0 -46
  73. package/server/migrations/index.ts +0 -9
  74. package/server/routers/figure-mesh-router.ts +0 -63
  75. package/server/routers/figure-package-router.ts +0 -53
  76. package/server/routers/figure-thumbnail-router.ts +0 -159
  77. package/server/routes.ts +0 -30
  78. package/server/service/figure/catalog-db.test.ts +0 -162
  79. package/server/service/figure/event-subscriber.ts +0 -66
  80. package/server/service/figure/figure-ai-scenarios-run.ts +0 -127
  81. package/server/service/figure/figure-ai-scenarios.live.test.ts +0 -59
  82. package/server/service/figure/figure-ai-scenarios.test.ts +0 -109
  83. package/server/service/figure/figure-ai-scenarios.ts +0 -798
  84. package/server/service/figure/figure-blueprint-query.test.ts +0 -536
  85. package/server/service/figure/figure-catalog-seen-db.test.ts +0 -153
  86. package/server/service/figure/figure-categories.ts +0 -50
  87. package/server/service/figure/figure-category-db.test.ts +0 -127
  88. package/server/service/figure/figure-context.test.ts +0 -402
  89. package/server/service/figure/figure-context.ts +0 -510
  90. package/server/service/figure/figure-deprecation-db.test.ts +0 -218
  91. package/server/service/figure/figure-format.test.ts +0 -423
  92. package/server/service/figure/figure-format.ts +0 -783
  93. package/server/service/figure/figure-glb.test.ts +0 -112
  94. package/server/service/figure/figure-glb.ts +0 -251
  95. package/server/service/figure/figure-history.ts +0 -192
  96. package/server/service/figure/figure-inspect-db.test.ts +0 -131
  97. package/server/service/figure/figure-llm-provider.ts +0 -20
  98. package/server/service/figure/figure-llm-smoke.test.ts +0 -95
  99. package/server/service/figure/figure-mesh-db.test.ts +0 -246
  100. package/server/service/figure/figure-mesh-store.ts +0 -91
  101. package/server/service/figure/figure-mutation.ts +0 -656
  102. package/server/service/figure/figure-namespace-db.test.ts +0 -315
  103. package/server/service/figure/figure-namespace-entity.ts +0 -67
  104. package/server/service/figure/figure-namespace-resolver.ts +0 -54
  105. package/server/service/figure/figure-namespace.ts +0 -156
  106. package/server/service/figure/figure-package-export.ts +0 -136
  107. package/server/service/figure/figure-proposal-db.test.ts +0 -117
  108. package/server/service/figure/figure-proposal-record.ts +0 -38
  109. package/server/service/figure/figure-proposal.ts +0 -41
  110. package/server/service/figure/figure-propose-clips.test.ts +0 -69
  111. package/server/service/figure/figure-propose-steps.test.ts +0 -324
  112. package/server/service/figure/figure-propose-steps.ts +0 -354
  113. package/server/service/figure/figure-propose-type.ts +0 -46
  114. package/server/service/figure/figure-public-db.test.ts +0 -288
  115. package/server/service/figure/figure-public.ts +0 -60
  116. package/server/service/figure/figure-query.ts +0 -511
  117. package/server/service/figure/figure-release-check.test.ts +0 -63
  118. package/server/service/figure/figure-release-record-db.test.ts +0 -153
  119. package/server/service/figure/figure-release-size-db.test.ts +0 -156
  120. package/server/service/figure/figure-rename-db.test.ts +0 -237
  121. package/server/service/figure/figure-rename.test.ts +0 -117
  122. package/server/service/figure/figure-rename.ts +0 -143
  123. package/server/service/figure/figure-replaced-draft.ts +0 -99
  124. package/server/service/figure/figure-revert-db.test.ts +0 -163
  125. package/server/service/figure/figure-revert-race.pg.test.ts +0 -168
  126. package/server/service/figure/figure-revert.ts +0 -186
  127. package/server/service/figure/figure-subject.test.ts +0 -41
  128. package/server/service/figure/figure-subject.ts +0 -21
  129. package/server/service/figure/figure-thumbnail-db.test.ts +0 -279
  130. package/server/service/figure/figure-thumbnail-reader.ts +0 -20
  131. package/server/service/figure/figure-thumbnail-store.ts +0 -111
  132. package/server/service/figure/figure-thumbnail-upgrade.pg.test.ts +0 -93
  133. package/server/service/figure/figure-thumbnail-upgrade.ts +0 -70
  134. package/server/service/figure/figure-tool-doors.test.ts +0 -127
  135. package/server/service/figure/figure-tools-door-db.test.ts +0 -227
  136. package/server/service/figure/figure-tools.test.ts +0 -817
  137. package/server/service/figure/figure-tools.ts +0 -611
  138. package/server/service/figure/figure-type.ts +0 -241
  139. package/server/service/figure/figure-write.test.ts +0 -15
  140. package/server/service/figure/figure-write.ts +0 -131
  141. package/server/service/figure/figure.ts +0 -241
  142. package/server/service/figure/index.ts +0 -13
  143. package/server/service/figure-recipe/figure-recipe-resolver.ts +0 -38
  144. package/server/service/figure-recipe/figure-recipe-templates.test.ts +0 -47
  145. package/server/service/figure-recipe/figure-recipe-templates.ts +0 -70
  146. package/server/service/figure-recipe/figure-recipe-type.ts +0 -31
  147. package/server/service/figure-recipe/index.ts +0 -3
  148. package/server/service/index.ts +0 -34
  149. package/tsconfig.json +0 -14
@@ -1,136 +0,0 @@
1
- import JSZip from 'jszip'
2
- import { In } from 'typeorm'
3
-
4
- import {
5
- figureFilesOf,
6
- formatFigureRef,
7
- parseFigureRef,
8
- writeFigurePackage,
9
- type FigurePackageBlobFile,
10
- type FigurePackageRelease,
11
- type FigureRef
12
- } from '@hatiolab/figure-model'
13
- import { getRepository, Refusal } from '@things-factory/shell'
14
-
15
- import { Figure } from './figure.js'
16
- import { FigureHistory } from './figure-history.js'
17
- import { sha256Of, thumbnailAttachmentOf, thumbnailFiles, type ThumbnailFiles } from './figure-thumbnail-store.js'
18
- import { meshAttachmentOf } from './figure-mesh-store.js'
19
- import { GLB_MIMETYPE } from './figure-glb.js'
20
- import { publicFigureOfName } from './figure-public.js'
21
-
22
- /** The most releases one package carries. */
23
- export const FIGURE_PACKAGE_MAX = 200
24
-
25
- export interface FigurePackageRequest {
26
- readonly refs: readonly string[]
27
- readonly domain: { id: string; parentId?: string; subdomain?: string }
28
- readonly exportedBy: string | null
29
- /** The address a board server can get these releases from again (`figure.publicUrl`). */
30
- readonly sourceUrl: string
31
- readonly now?: Date
32
- readonly files?: ThumbnailFiles
33
- }
34
-
35
- /**
36
- * Released figures as one package file a board server imports (ADR-0114 결정 3·16).
37
- *
38
- * Only released versions travel, read from the release history -- the draft being edited is never exported. The
39
- * figures are the ones this domain can read: its own and its parent's, the scope of `figureBlueprint`.
40
- */
41
- export async function figurePackageOf(request: FigurePackageRequest): Promise<{ name: string; bytes: Buffer }> {
42
- const refs = [...new Set(request.refs)]
43
- if (refs.length === 0 || refs.length > FIGURE_PACKAGE_MAX) {
44
- throw new Refusal('figure-package-size', { count: refs.length, max: FIGURE_PACKAGE_MAX }, 'a package carries 1 to {max} releases, not {count}.')
45
- }
46
-
47
- const files = request.files ?? thumbnailFiles()
48
- const releases: FigurePackageRelease[] = []
49
- const blobs = new Map<string, FigurePackageBlobFile>()
50
-
51
- for (const text of refs) {
52
- const ref = parseFigureRef(text)
53
- if (!ref) throw new Refusal('figure-ref-malformed', { ref: text }, '{ref} is not a release reference of the form namespace/type@version.')
54
- const { figure, history } = await releaseOf(ref, request.domain)
55
- if (history.thumbnailHash && !blobs.has(history.thumbnailHash)) {
56
- const picture = await thumbnailAttachmentOf({ getRepository }, figure.domainId!, history.thumbnailHash)
57
- if (picture) {
58
- const bytes = await files.read(picture.path)
59
- if (sha256Of(bytes) === history.thumbnailHash) blobs.set(history.thumbnailHash, { bytes, contentType: picture.mimetype })
60
- }
61
- }
62
- /*
63
- Every file the release draws from goes with it (ADR-0129 decision 5). Looked for in the figure's own domain, then
64
- the asker's; one that is gone, or whose bytes are not its hash, refuses the package -- a board could not draw it.
65
- */
66
- for (const hash of figureFilesOf(JSON.parse(history.source!))) {
67
- if (blobs.has(hash)) continue
68
- const kept = await meshAttachmentOf({ getRepository }, [figure.domainId!, request.domain.id], hash)
69
- const bytes = kept ? await files.read(kept.path!) : undefined
70
- if (!bytes || sha256Of(bytes) !== hash)
71
- throw new Refusal('figure-package-mesh-missing', { ref: formatFigureRef(ref), hash }, '{ref} draws from a mesh file this server does not hold: {hash}.')
72
- blobs.set(hash, { bytes, contentType: GLB_MIMETYPE })
73
- }
74
- releases.push(packageReleaseOf(ref, figure, history, blobs))
75
- }
76
-
77
- const packed = writeFigurePackage(
78
- {
79
- source: { url: request.sourceUrl, domain: request.domain.subdomain ?? '' },
80
- exportedAt: (request.now ?? new Date()).toISOString(),
81
- exportedBy: request.exportedBy,
82
- releases,
83
- blobs
84
- },
85
- bytes => sha256Of(Buffer.from(bytes))
86
- )
87
-
88
- const zip = new JSZip()
89
- for (const [path, bytes] of packed) zip.file(path, bytes, { createFolders: false })
90
- const bytes = await zip.generateAsync({ type: 'nodebuffer', compression: 'DEFLATE' })
91
- const name = refs.length === 1 ? `${refs[0]!.replace(/[/@]/g, '_')}.figpkg` : `figures-${refs.length}.figpkg`
92
- return { name, bytes }
93
- }
94
-
95
- async function releaseOf(ref: FigureRef, domain: FigurePackageRequest['domain']): Promise<{ figure: Figure; history: FigureHistory }> {
96
- /* Its own or its parent's, or another domain's public figure (G2): a package is made of what this domain may read. */
97
- const figure =
98
- (await getRepository(Figure).findOne({
99
- where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, type: ref.type, namespace: ref.namespace }
100
- })) ?? (await publicFigureOfName(ref.namespace, ref.type))
101
- const history = figure
102
- ? await getRepository(FigureHistory).findOne({ where: { originalId: figure.id, state: 'released', version: ref.version } })
103
- : null
104
- if (!figure || !history?.source) {
105
- throw new Refusal('figure-package-release-not-found', { ref: formatFigureRef(ref) }, '{ref} is not a release this domain can read.')
106
- }
107
- return { figure, history }
108
- }
109
-
110
- function packageReleaseOf(
111
- ref: FigureRef,
112
- figure: Figure,
113
- history: FigureHistory,
114
- blobs: ReadonlyMap<string, FigurePackageBlobFile>
115
- ): FigurePackageRelease {
116
- const json = (text: string | null | undefined) => (text ? JSON.parse(text) : null)
117
- return {
118
- ref: formatFigureRef(ref),
119
- name: history.name ?? figure.name ?? formatFigureRef(ref),
120
- names: history.names ?? null,
121
- description: history.description ?? null,
122
- category: history.category ?? null,
123
- source: history.source!,
124
- assetFormat: history.assetFormat ?? json(history.source)?.version ?? '',
125
- kernelVersion: history.kernelVersion ?? null,
126
- metrics: json(history.metrics),
127
- topView: json(history.topView),
128
- changes: json(history.changes),
129
- thumbnail: history.thumbnailHash && blobs.has(history.thumbnailHash) ? history.thumbnailHash : null,
130
- deprecated: !!figure.deprecated,
131
- supersededBy: figure.supersededBy && figure.namespace ? `${figure.namespace}/${figure.supersededBy}` : null,
132
- /* The history row copies the figure's own createdAt; the save that released this version is its updatedAt. */
133
- releasedAt: new Date(history.updatedAt ?? history.createdAt ?? Date.now()).toISOString(),
134
- comment: history.comment ?? null
135
- }
136
- }
@@ -1,117 +0,0 @@
1
- /**
2
- * What became of an AI proposal, on sqlite through the save door itself (ADR-0097 §5.6 item 5; AI lane, 2026-09-27).
3
- * A save records the proposals its source holds, in its transaction; the same proposal taken twice never makes two
4
- * figures, because a new figure made from it is created under its key.
5
- */
6
- import type { DataSource } from 'typeorm'
7
-
8
- const { DataSource: TypeOrmDataSource } = require('typeorm')
9
- const shell = require('@things-factory/shell')
10
- const authBase = require('@things-factory/auth-base')
11
- const settingBase = require('@things-factory/setting-base')
12
- const { createFigureAsset, addFigureBox, serializeFigureAsset } = require('@hatiolab/figure-model')
13
-
14
- let FigureNamespace: any
15
- let dataSource: DataSource | null = null
16
- let Figure: any
17
- let FigureHistory: any
18
- let FigureProposalRecord: any
19
- let FigureMutation: any
20
- let FigureQuery: any
21
-
22
- function loadCompiled(modulePath: string): any {
23
- const { existsSync } = require('fs')
24
- const { join } = require('path')
25
- const resolved = join(__dirname, '..', '..', '..', 'dist-server', `${modulePath}.js`)
26
- if (!existsSync(resolved))
27
- throw new Error(`figure-service 산출물이 없다: ${resolved}\n먼저 빌드할 것:\n yarn workspace @things-factory/figure-service build:server`)
28
- return require(resolved)
29
- }
30
-
31
- beforeAll(async () => {
32
- Figure = loadCompiled('service/figure/figure').Figure
33
- FigureNamespace = loadCompiled('service/figure/figure-namespace-entity').FigureNamespace
34
- FigureHistory = loadCompiled('service/figure/figure-history').FigureHistory
35
- FigureProposalRecord = loadCompiled('service/figure/figure-proposal-record').FigureProposalRecord
36
- FigureMutation = loadCompiled('service/figure/figure-mutation').FigureMutation
37
- FigureQuery = loadCompiled('service/figure/figure-query').FigureQuery
38
- dataSource = new TypeOrmDataSource({
39
- type: 'sqlite',
40
- database: ':memory:',
41
- synchronize: true,
42
- dropSchema: true,
43
- namingStrategy: new shell.NamingStrategy(),
44
- entities: [...shell.entities, ...authBase.entities, ...settingBase.entities, Figure, FigureHistory, FigureProposalRecord, FigureNamespace],
45
- logging: false
46
- })
47
- await dataSource.initialize()
48
- })
49
-
50
- afterAll(async () => {
51
- await dataSource?.destroy()
52
- dataSource = null
53
- })
54
-
55
- /** The domain's own default namespace, its subdomain, that every figure here is created and released under (G1). */
56
- async function namespaced(domain: any) {
57
- await dataSource!.getRepository(FigureNamespace).save({ domain, name: domain.subdomain, state: 'active', isDefault: true })
58
- return domain
59
- }
60
-
61
- let DOMAIN: { id: string }
62
- beforeEach(async () => {
63
- await dataSource!.synchronize(true)
64
- DOMAIN = { id: (await namespaced(await dataSource!.getRepository(shell.Domain).save({ name: 'proposal-probe', subdomain: 'proposal-probe' }))).id }
65
- })
66
-
67
- const text = (name: string, height = 100) =>
68
- serializeFigureAsset(addFigureBox(createFigureAsset(name), { id: 'body', size: { x: 100, y: height, z: 100 }, position: { x: 0, y: height / 2, z: 0 } }))
69
- const uuid = () => require('crypto').randomUUID()
70
- /* Through the door, in a transaction of its own as `@transaction` gives it. */
71
- const save = (source: string, { id, expectedSource, creationId, proposalKeys }: { id?: string; expectedSource?: string; creationId?: string; proposalKeys?: string[] }) =>
72
- dataSource!.transaction(tx =>
73
- new FigureMutation().saveFigure(source, { state: { domain: DOMAIN, user: undefined, tx } }, id, expectedSource, creationId, undefined, undefined, proposalKeys)
74
- )
75
- const outcome = (proposalKey: string) => new FigureQuery().figureProposalOutcome(proposalKey, { state: { domain: DOMAIN, tx: dataSource!.manager } })
76
- const records = () => dataSource!.getRepository(FigureProposalRecord).count()
77
-
78
- describe('a save records the proposals its source holds', () => {
79
- it('recorded with the save, once per figure however often it is saved again', async () => {
80
- const key = uuid()
81
- const first = await save(text('A'), { creationId: uuid(), proposalKeys: [key] })
82
- await save(text('A', 200), { id: first.id, expectedSource: first.source, proposalKeys: [key] })
83
- const found = await outcome(key)
84
- expect(found.map((f: any) => f.figureId)).toEqual([first.id])
85
- expect(found[0].name).toBe('A')
86
- expect(await records()).toBe(1)
87
- })
88
-
89
- it('a save refused records nothing -- the record is in its transaction', async () => {
90
- const figure = await save(text('A'), { creationId: uuid() })
91
- const key = uuid()
92
- await expect(save(text('B'), { id: figure.id, expectedSource: 'stale', proposalKeys: [key] })).rejects.toMatchObject({
93
- extensions: { code: 'FIGURE_SOURCE_CONFLICT' }
94
- })
95
- expect(await outcome(key)).toEqual([])
96
- })
97
-
98
- it('a key not of the tool’s making is not recorded; a proposal never saved has no outcome', async () => {
99
- await save(text('A'), { creationId: uuid(), proposalKeys: ['not-a-key'] })
100
- expect(await records()).toBe(0)
101
- expect(await outcome(uuid())).toEqual([])
102
- })
103
- })
104
-
105
- describe('the same new-figure proposal taken twice makes one figure', () => {
106
- it('created under the proposal key: the second take meets the first figure, never a second one', async () => {
107
- const key = uuid()
108
- const once = await save(text('From AI'), { creationId: key, proposalKeys: [key] })
109
- /* Taken again after a reload, the same steps: the same row answers. */
110
- const again = await save(text('From AI'), { creationId: key, proposalKeys: [key] })
111
- expect(again.id).toBe(once.id)
112
- /* Taken again and changed before saving: refused, not a second figure. */
113
- await expect(save(text('From AI, changed', 300), { creationId: key, proposalKeys: [key] })).rejects.toThrow(/이미 다른 내용으로 저장되었습니다/)
114
- expect(await dataSource!.getRepository(Figure).count()).toBe(1)
115
- expect((await outcome(key)).map((f: any) => f.figureId)).toEqual([key])
116
- })
117
- })
@@ -1,38 +0,0 @@
1
- import { CreateDateColumn, Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId } from 'typeorm'
2
- import { Field, ID, ObjectType } from 'type-graphql'
3
-
4
- import { Domain } from '@things-factory/shell'
5
-
6
- /**
7
- * An AI proposal saved into a figure (ADR-0097 §5.6 item 5; AI lane, 2026-09-27).
8
- *
9
- * Written by the save that holds the proposal's step, in the same transaction: a proposal applied and then undone, or
10
- * never saved, has none. So "what became of it" is answered from the server -- after a reload too -- and never from
11
- * the dock's memory. A proposal saved into the same figure again is one record.
12
- */
13
- @Entity()
14
- @Index('ix_figure_proposal_record_0', (record: FigureProposalRecord) => [record.domain, record.proposalKey, record.figureId], { unique: true })
15
- @ObjectType({ description: 'An AI proposal saved into a figure.' })
16
- export class FigureProposalRecord {
17
- @PrimaryGeneratedColumn('uuid')
18
- @Field(type => ID, { description: 'Unique identifier of the record.' })
19
- readonly id?: string
20
-
21
- @ManyToOne(type => Domain)
22
- domain?: Domain
23
-
24
- @RelationId((record: FigureProposalRecord) => record.domain)
25
- domainId?: string
26
-
27
- @Column()
28
- @Field({ description: 'The key the proposal was given when it was made.' })
29
- proposalKey?: string
30
-
31
- @Column()
32
- @Field({ description: 'The figure it was saved into.' })
33
- figureId?: string
34
-
35
- @CreateDateColumn()
36
- @Field({ nullable: true, description: 'When the save that held it was made.' })
37
- recordedAt?: Date
38
- }
@@ -1,41 +0,0 @@
1
- import type { EntityManager } from 'typeorm'
2
- import { In } from 'typeorm'
3
-
4
- import { Figure } from './figure.js'
5
- import { FigureProposalRecord } from './figure-proposal-record.js'
6
-
7
- /*
8
- * What became of an AI proposal (ADR-0097 §5.6 item 5; AI lane, 2026-09-27): the saves that held its step. The key is the
9
- * one `proposeFigureCandidate` gave it. This record is what keeps one proposal one figure (ADR-0061 decision 3, ruled
10
- * 2026-10-16): a new figure taken from it in the modeller keeps its own creation id, the anchor of its conversation, so
11
- * the modeller reads this before it runs a new figure's card again and opens the figure found. Only a new figure opened
12
- * for a proposal from another screen is still created under the key.
13
- */
14
-
15
- const KEY = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
16
-
17
- /** Records, in the save's transaction, the proposals its source holds. Keys not of the tool's making are not recorded. */
18
- export async function recordProposals(tx: EntityManager, domain: { id: string }, figureId: string, keys?: readonly string[]) {
19
- const wanted = [...new Set((keys ?? []).filter(key => KEY.test(key)))]
20
- if (!wanted.length) return
21
- const records = tx.getRepository(FigureProposalRecord)
22
- const already = new Set(
23
- (await records.find({ where: { domain: { id: domain.id }, figureId, proposalKey: In(wanted) } })).map(record => record.proposalKey)
24
- )
25
- const fresh = wanted.filter(key => !already.has(key))
26
- if (fresh.length) await records.insert(fresh.map(proposalKey => ({ domain: { id: domain.id }, figureId, proposalKey })))
27
- }
28
-
29
- /** The figures a proposal was saved into, with their names as they are now. None: not saved -- or not known here. */
30
- export async function proposalOutcomeOf(tx: EntityManager, domain: { id: string }, proposalKey: string) {
31
- const records = await tx.getRepository(FigureProposalRecord).find({ where: { domain: { id: domain.id }, proposalKey }, order: { recordedAt: 'ASC' } })
32
- if (!records.length) return []
33
- const figures = await tx.getRepository(Figure).find({ where: { domain: { id: domain.id }, id: In(records.map(r => r.figureId!)) } })
34
- const byId = new Map(figures.map(f => [f.id, f]))
35
- return records.map(record => ({
36
- figureId: record.figureId!,
37
- recordedAt: record.recordedAt,
38
- type: byId.get(record.figureId!)?.type,
39
- name: byId.get(record.figureId!)?.name
40
- }))
41
- }
@@ -1,69 +0,0 @@
1
- /**
2
- * figure-propose-steps and clips (designer 2026-09-27): an AI answer that would stop a clip is refused whole, and the
3
- * model is told it may not -- never how to agree. An answer that stops none keeps every clip. Consent the model writes
4
- * into its answer is read as nothing.
5
- */
6
- import { addFigureBox, applyFigureAuthoring, createFigureAsset, editFigurePart } from '@hatiolab/figure-model'
7
- import type { FigureAsset } from '@hatiolab/figure-model'
8
- import type { AIClient } from '@things-factory/ai-client-base'
9
-
10
- import { ProposeFigureFailure, judgeFigureAnswer, proposeFigureSteps } from './figure-propose-steps'
11
-
12
- function stubClient(answers: unknown[]): AIClient & { calls: number; sent: any[][] } {
13
- const client = {
14
- id: 'stub',
15
- calls: 0,
16
- sent: [] as any[][],
17
- async chat() {
18
- return ''
19
- },
20
- async generateJSON(messages: any[]) {
21
- client.sent.push(JSON.parse(JSON.stringify(messages)))
22
- return answers[Math.min(client.calls++, answers.length - 1)]
23
- }
24
- }
25
- return client as unknown as AIClient & { calls: number; sent: any[][] }
26
- }
27
-
28
- function door(): FigureAsset {
29
- let a = createFigureAsset('Door')
30
- a = addFigureBox(a, { id: 'frame', size: { x: 1000, y: 100, z: 200 }, position: { x: 0, y: 50, z: 0 } })
31
- a = addFigureBox(a, { id: 'leaf', size: { x: 900, y: 1800, z: 40 }, position: { x: 0, y: 1000, z: 0 } })
32
- a = addFigureBox(a, { id: 'sign', size: { x: 200, y: 100, z: 10 }, position: { x: 0, y: 2200, z: 200 } })
33
- a = applyFigureAuthoring(a, { kind: 'attach', part: 'leaf', to: { part: 'frame', face: 'top' } })
34
- const j = a.joints!.find(k => k.body1.part === 'leaf')!
35
- a = applyFigureAuthoring(a, { kind: 'set-joint', joint: { ...j, motion: [{ type: 'revolute', axis: 'Y', state: { id: 'open' } }] } })
36
- return editFigurePart(a, { kind: 'set-driver', state: 'open', clip: 'swing', duration: 2, keys: [{ seconds: 0, value: 0 }, { seconds: 2, value: 80 }] })
37
- }
38
- const lossy = { steps: [{ kind: 'rename', name: 'Door by AI' }, { kind: 'remove-part', target: 'leaf' }] }
39
-
40
- describe('an AI answer and the clips of the draft it revises', () => {
41
- it('an answer that would stop a clip is refused whole, and the model is told it may not -- not how to agree', () => {
42
- const base = door()
43
- const judged = judgeFigureAnswer(base, lossy, true)
44
- expect(judged.source).toBeUndefined()
45
- expect(judged.reasons.join('\n')).toMatch(/CLIPS_DROPPED: .*swing.*may never remove a clip; only the person can/)
46
- expect(judged.reasons.join('\n')).not.toMatch(/dropClips/)
47
- expect(base.drivers?.map(d => d.clip)).toEqual(['swing'])
48
- })
49
-
50
- it('asked three times and three times lossy, nothing comes back: no half-made figure to save', async () => {
51
- const client = stubClient([lossy])
52
- await expect(proposeFigureSteps({ client, prompt: '문을 없애 줘', base: door() })).rejects.toBeInstanceOf(ProposeFigureFailure)
53
- expect(client.calls).toBe(3)
54
- expect(JSON.stringify(client.sent)).not.toMatch(/dropClips/)
55
- })
56
-
57
- it('consent the model writes into its answer is read as nothing', () => {
58
- const judged = judgeFigureAnswer(door(), { ...lossy, dropClips: ['swing/open'], steps: lossy.steps.map(s => ({ ...s, dropClips: ['swing/open'] })) }, true)
59
- expect(judged.source).toBeUndefined()
60
- expect(judged.reasons.join('\n')).toMatch(/^CLIPS_DROPPED/)
61
- })
62
-
63
- it('an answer that stops no clip keeps every clip, a rename of the part it hangs from included', async () => {
64
- const base = door()
65
- const client = stubClient([{ steps: [{ kind: 'rename', name: 'Door 2' }, { kind: 'nudge-part', part: 'sign', by: { x: 50 } }, { kind: 'rename-part', target: 'frame', name: 'jamb' }] }])
66
- const made = await proposeFigureSteps({ client, prompt: '이름을 바꿔 줘', base })
67
- expect(made.source.drivers).toEqual(base.drivers)
68
- })
69
- })