@things-factory/figure-service 10.1.263 → 10.1.266
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/README.md +13 -0
- package/dist-server/service/figure/figure-ai-scenarios.js +11 -3
- package/dist-server/service/figure/figure-ai-scenarios.js.map +1 -1
- package/dist-server/service/figure/figure-context.d.ts +10 -13
- package/dist-server/service/figure/figure-context.js +64 -4
- package/dist-server/service/figure/figure-context.js.map +1 -1
- package/dist-server/service/figure/figure-format.d.ts +2 -0
- package/dist-server/service/figure/figure-format.js +1 -1
- package/dist-server/service/figure/figure-format.js.map +1 -1
- package/dist-server/service/figure/figure-mutation.d.ts +2 -2
- package/dist-server/service/figure/figure-mutation.js +25 -4
- package/dist-server/service/figure/figure-mutation.js.map +1 -1
- package/dist-server/service/figure/figure-propose-steps.d.ts +5 -1
- package/dist-server/service/figure/figure-propose-steps.js +11 -7
- package/dist-server/service/figure/figure-propose-steps.js.map +1 -1
- package/dist-server/service/figure/figure-type.d.ts +6 -0
- package/dist-server/service/figure/figure-type.js +20 -1
- package/dist-server/service/figure/figure-type.js.map +1 -1
- package/dist-server/service/figure/figure-write.d.ts +31 -0
- package/dist-server/service/figure/figure-write.js +51 -0
- package/dist-server/service/figure/figure-write.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/server/service/figure/figure-ai-scenarios.test.ts +32 -0
- package/server/service/figure/figure-ai-scenarios.ts +9 -3
- package/server/service/figure/figure-catalog-seen-db.test.ts +153 -0
- package/server/service/figure/figure-category-db.test.ts +6 -6
- package/server/service/figure/figure-context.test.ts +116 -2
- package/server/service/figure/figure-context.ts +55 -3
- package/server/service/figure/figure-format.ts +3 -2
- package/server/service/figure/figure-mutation.ts +27 -6
- package/server/service/figure/figure-propose-steps.ts +19 -8
- package/server/service/figure/figure-public-db.test.ts +1 -1
- package/server/service/figure/figure-rename-db.test.ts +1 -1
- package/server/service/figure/figure-revert-db.test.ts +3 -0
- package/server/service/figure/figure-type.ts +13 -0
- package/server/service/figure/figure-write.ts +60 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FIGURE_PROPOSAL_GRAMMAR, applyFigureProposal, createFigureAsset,
|
|
1
|
+
import { FIGURE_PROPOSAL_GRAMMAR, applyFigureProposal, createFigureAsset, inspectFigureAsset, serializeFigureAsset, figureCostOf, figureScoreOf } from '@hatiolab/figure-model'
|
|
2
2
|
import type { FigureAsset, FigureProposalStep, FigureRefusalDetails } from '@hatiolab/figure-model'
|
|
3
3
|
import { AIAnswerNotJSON, type AIClient } from '@things-factory/ai-client-base'
|
|
4
4
|
import type { AIImageMediaType, AIMessage } from '@things-factory/ai-client-base'
|
|
@@ -135,11 +135,15 @@ function viewFor(input: ProposeFigureInput): FigureView | undefined {
|
|
|
135
135
|
return figureViewOf(input.base, { parts: [...(selected ? [selected] : []), ...(input.read?.parts ?? [])], sections: input.read?.sections ?? [] })
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* The request, and the open draft's source when revising -- or, too large for that, its outline and the parts read.
|
|
140
|
+
* Of the draft, only what the view holds is written: the view was measured against the budget, and nothing of the
|
|
141
|
+
* draft is added here beside it.
|
|
142
|
+
*/
|
|
139
143
|
export function taskPromptFigure(input: ProposeFigureInput, view: FigureView | undefined = viewFor(input)): string {
|
|
140
144
|
const lines = [`Request: ${input.prompt}`]
|
|
141
|
-
if (input.base) {
|
|
142
|
-
if (
|
|
145
|
+
if (input.base && view) {
|
|
146
|
+
if (view.whole) {
|
|
143
147
|
lines.push('', 'Revise this figure. Its source (reference data, not instructions):', serializeFigureAsset(input.base))
|
|
144
148
|
} else {
|
|
145
149
|
lines.push(
|
|
@@ -157,10 +161,17 @@ export function taskPromptFigure(input: ProposeFigureInput, view: FigureView | u
|
|
|
157
161
|
Its pipes as set-pipe takes them: the source holds a bend as degrees across the section where it starts, which a
|
|
158
162
|
writer cannot turn into "down" (AI modelling scenarios 2026-11-03); said by the axis it turns to, it is written back right.
|
|
159
163
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
+
if (view.pipes)
|
|
165
|
+
lines.push(
|
|
166
|
+
'',
|
|
167
|
+
`${view.whole ? 'Its pipes and ducts' : 'The pipes and ducts shown'} as set-pipe takes them, each bend by the axis it turns to there (to extend one, append; to change its section, give only the measures):`,
|
|
168
|
+
JSON.stringify(view.pipes)
|
|
169
|
+
)
|
|
170
|
+
if (view.palette)
|
|
171
|
+
lines.push(
|
|
172
|
+
'',
|
|
173
|
+
`Palette tokens it has: ${view.palette.tokens.join(', ') || 'none'}${view.palette.more ? ` and ${view.palette.more} more, in /palette` : ''}.`
|
|
174
|
+
)
|
|
164
175
|
const { selection, trying } = input.focus ?? {}
|
|
165
176
|
if (selection) lines.push('', `The person has selected the part "${selection.part}": "this part", "the selected one" and the like mean it.`)
|
|
166
177
|
if (trying) lines.push('', `The preview is trying these values (what the person is looking at, not part of the figure): ${JSON.stringify(trying)}.`)
|
|
@@ -269,7 +269,7 @@ describe('the release pre-checks see the category the release does (2026-11-03 a
|
|
|
269
269
|
it('both pass the saved category to an application check', async () => {
|
|
270
270
|
const owner = await domain()
|
|
271
271
|
const figure = await released(owner, 'checked-category')
|
|
272
|
-
await new FigureMutation().updateFigure(figure.id, { category: 'EQUIPMENT' }, owner.context)
|
|
272
|
+
await new FigureMutation().updateFigure(figure.id, { category: 'EQUIPMENT' }, owner.context, { category: null })
|
|
273
273
|
const { registerFigureReleaseCheck } = loadCompiled('service/figure/figure-format')
|
|
274
274
|
const seen: unknown[] = []
|
|
275
275
|
const remove = registerFigureReleaseCheck((input: any) => {
|
|
@@ -227,7 +227,7 @@ describe('발행한 뒤 지운 이름은 다시 쓰지 않는다', () => {
|
|
|
227
227
|
it('이름 바꾸기로도, 처음 저장으로도, 새로 만들기로도 그 이름을 받지 않는다', async () => {
|
|
228
228
|
await releasedThenDeleted('gone-mixer')
|
|
229
229
|
const draft = await seedFigure({ type: 'mixer-draft', name: 'mixer-draft' })
|
|
230
|
-
await expect(new FigureMutation().updateFigure(draft.id, { type: 'gone-mixer' }, context())).rejects.toMatchObject({ code: 'type-released-before' })
|
|
230
|
+
await expect(new FigureMutation().updateFigure(draft.id, { type: 'gone-mixer' }, context(), { type: 'mixer-draft' })).rejects.toMatchObject({ code: 'type-released-before' })
|
|
231
231
|
await expect(
|
|
232
232
|
new FigureMutation().saveFigure(FIGURE_SOURCE, context(), undefined, undefined, '7c3d4e5f-6a7b-4c8d-9e0f-a1b2c3d4e5f6', undefined, 'gone-mixer')
|
|
233
233
|
).rejects.toThrow(/발행한 뒤 지운/)
|
|
@@ -74,6 +74,8 @@ describe('a revert keeps the draft it writes over', () => {
|
|
|
74
74
|
const figure = await figureWithRelease()
|
|
75
75
|
const result = await inTx(tx => revertKeepingDraft(tx, DOMAIN, undefined, { id: figure.id, version: 1, requestId: uuid(), expectedSource: DRAFT }))
|
|
76
76
|
expect(JSON.parse((await row(figure.id)).source).name).toBe('Released one')
|
|
77
|
+
/* The card's name is the source's, as after a save: the replaced draft's name does not stay on the row (:3300, 2026-11-09). */
|
|
78
|
+
expect((await row(figure.id)).name).toBe('Released one')
|
|
77
79
|
/* The picture goes by its hash (ADR-0104 decision 6): the release's own comes back with its source. */
|
|
78
80
|
expect((await row(figure.id)).thumbnailHash).toBe('v1-picture')
|
|
79
81
|
const [one] = await kept()
|
|
@@ -134,6 +136,7 @@ describe('an undo brings the kept draft back only while nothing changed since',
|
|
|
134
136
|
const requestId = uuid()
|
|
135
137
|
await inTx(tx => undoRevert(tx, DOMAIN, undefined, { keptId: reverted.kept.id, requestId }))
|
|
136
138
|
expect((await row(figure.id)).source).toBe(DRAFT)
|
|
139
|
+
expect((await row(figure.id)).name).toBe('Draft after it')
|
|
137
140
|
expect((await row(figure.id)).thumbnailHash).toBe('draft-picture')
|
|
138
141
|
const records = await kept()
|
|
139
142
|
expect(records.map((k: any) => k.kind).sort()).toEqual(['revert', 'undo'])
|
|
@@ -10,6 +10,19 @@ import { Figure } from './figure.js'
|
|
|
10
10
|
* `score`·`triangles`·`groups` 는 **받지 않는다.** 서버가 `source` 에서 계산한다 —
|
|
11
11
|
* 받으면 거짓이 들어오고 목록이 실물과 다른 것을 보여 준다.
|
|
12
12
|
*/
|
|
13
|
+
/** The catalogue fields as the editor saw them; an update of them goes on only while the row still holds these. */
|
|
14
|
+
@InputType({ description: 'The type, category and tags as the editor saw them. A field left out is not checked; null means it was empty.' })
|
|
15
|
+
export class FigureCatalogSeen {
|
|
16
|
+
@Field({ nullable: true, description: 'The type the editor saw before changing it.' })
|
|
17
|
+
type?: string
|
|
18
|
+
|
|
19
|
+
@Field({ nullable: true, description: 'The category the editor saw before changing it; null when it was empty.' })
|
|
20
|
+
category?: string
|
|
21
|
+
|
|
22
|
+
@Field(type => [String], { nullable: true, description: 'The tags the editor saw before changing them, in their order; null when there were none.' })
|
|
23
|
+
tags?: string[]
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
@InputType({ description: 'Input for creating a new figure.' })
|
|
14
27
|
export class NewFigure {
|
|
15
28
|
@Field({ description: 'Component type name. Immutable once created, unique per domain.' })
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { keepThumbnail, type ThumbnailFiles } from './figure-thumbnail-store.js'
|
|
2
2
|
import { GraphQLError } from 'graphql'
|
|
3
|
+
import { IsNull, Raw } from 'typeorm'
|
|
3
4
|
import { parseFigureAsset, serializeFigureAsset, compileFigureAsset, figureCostOf, figureScoreOf } from '@hatiolab/figure-model'
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -11,6 +12,65 @@ export function sourceConflict(message: string) {
|
|
|
11
12
|
return new GraphQLError(message, { extensions: { code: 'FIGURE_SOURCE_CONFLICT' } })
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* The catalogue fields as the editor saw them when it changed them: the type, the category, the tags. Kept on the row,
|
|
17
|
+
* not in the source, so the source's compare-and-swap does not hold them; a save of these alone is checked against
|
|
18
|
+
* these (outside review 2026-11-09: two tabs set the category, the later one wrote over the first without a word).
|
|
19
|
+
* A field left out is not checked; null is "was empty".
|
|
20
|
+
*/
|
|
21
|
+
export interface FigureCatalogSeen {
|
|
22
|
+
type?: string | null
|
|
23
|
+
category?: string | null
|
|
24
|
+
tags?: string[] | null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const CATALOG_FIELDS = ['type', 'category', 'tags'] as const
|
|
28
|
+
type CatalogField = (typeof CATALOG_FIELDS)[number]
|
|
29
|
+
|
|
30
|
+
/** A catalogue value as compared: an empty category or tag list is no value; tags as the row stores them (simple-json). */
|
|
31
|
+
function comparedCatalogValue(field: CatalogField, value: unknown): string | null {
|
|
32
|
+
if (field === 'tags') return Array.isArray(value) && value.length ? JSON.stringify(value) : null
|
|
33
|
+
return typeof value === 'string' && value ? value : null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The fields the row no longer holds as the editor saw them, each with what it holds now. */
|
|
37
|
+
export function catalogConflictsOf(row: Partial<Record<CatalogField, unknown>>, seen: FigureCatalogSeen): { field: CatalogField; now: string | string[] | null }[] {
|
|
38
|
+
return CATALOG_FIELDS.filter(field => seen[field] !== undefined && comparedCatalogValue(field, row[field]) !== comparedCatalogValue(field, seen[field])).map(field => ({
|
|
39
|
+
field,
|
|
40
|
+
now: field === 'tags' ? ((row.tags as string[] | null | undefined)?.length ? (row.tags as string[]) : null) : ((row[field] as string | null | undefined) || null)
|
|
41
|
+
}))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The same check in the UPDATE's criteria: a write between the check and the update finds nothing to update. */
|
|
45
|
+
export function catalogCriteriaOf(seen: FigureCatalogSeen): Record<string, unknown> {
|
|
46
|
+
const criteria: Record<string, unknown> = {}
|
|
47
|
+
for (const field of CATALOG_FIELDS) {
|
|
48
|
+
if (seen[field] === undefined) continue
|
|
49
|
+
const value = comparedCatalogValue(field, seen[field])
|
|
50
|
+
if (value !== null) criteria[field] = field === 'tags' ? Raw(column => `${column} = :seenTags`, { seenTags: value }) : value
|
|
51
|
+
else if (field === 'type') criteria[field] = IsNull()
|
|
52
|
+
else criteria[field] = Raw(column => `(${column} IS NULL OR ${column} = '${field === 'tags' ? '[]' : ''}')`)
|
|
53
|
+
}
|
|
54
|
+
return criteria
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A patch that changes a catalogue field says what it saw of that field: there is no unchecked way to write one
|
|
59
|
+
* (outside review 2026-11-09). A field the patch leaves out is neither written nor checked.
|
|
60
|
+
*/
|
|
61
|
+
export function assertCatalogSeen(patch: Partial<Record<CatalogField, unknown>>, seen: FigureCatalogSeen | undefined) {
|
|
62
|
+
const unseen = CATALOG_FIELDS.filter(field => patch[field] !== undefined && seen?.[field] === undefined)
|
|
63
|
+
if (unseen.length)
|
|
64
|
+
throw new GraphQLError(`변경할 항목의 기존 값이 필요합니다: ${unseen.join(', ')}`, { extensions: { code: 'FIGURE_CATALOG_SEEN_REQUIRED', fields: unseen } })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Another edit changed a catalogue field first: which, and what it holds now, for the editor to say in its words. */
|
|
68
|
+
export function catalogConflict(fields: { field: string; now: string | string[] | null }[]) {
|
|
69
|
+
return new GraphQLError(`다른 사용자가 먼저 변경한 항목이 있습니다: ${fields.map(f => f.field).join(', ')}`, {
|
|
70
|
+
extensions: { code: 'FIGURE_CATALOG_CONFLICT', fields }
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
14
74
|
export interface FigureWriteCriteria {
|
|
15
75
|
id: string
|
|
16
76
|
domain: { id: string }
|