@things-factory/figure-service 10.1.9 → 10.1.13
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/dist-server/service/figure/figure-tools.js +49 -16
- package/dist-server/service/figure/figure-tools.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server/service/figure/figure-ai-flow.test.ts +1 -3
- package/server/service/figure/figure-tools.test.ts +72 -4
- package/server/service/figure/figure-tools.ts +47 -17
|
@@ -99,7 +99,7 @@ async function figureInDomain(figureId, domainId) {
|
|
|
99
99
|
* 프롬프트로 옮기면 비용만 태우고, DB에 있던 Figure와 다른 것을 고친다고 잘못 말할 수 있다.
|
|
100
100
|
*/
|
|
101
101
|
function sourceForTool(row, host) {
|
|
102
|
-
const draft = host?.draftSource;
|
|
102
|
+
const draft = host?.figureId === row.id ? host?.draftSource : undefined;
|
|
103
103
|
if (!draft) {
|
|
104
104
|
return { source: row.source ? JSON.parse(row.source) : null, draft: false };
|
|
105
105
|
}
|
|
@@ -144,12 +144,27 @@ function figureIdFrom(args, host) {
|
|
|
144
144
|
const open = typeof host?.figureId === 'string' ? host.figureId.trim() : '';
|
|
145
145
|
if (open)
|
|
146
146
|
return open;
|
|
147
|
-
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
function missingFigureTarget() {
|
|
150
|
+
return {
|
|
151
|
+
error: 'FIGURE_TARGET_REQUIRED',
|
|
152
|
+
message: '현재 화면에는 선택된 도형이 없습니다.',
|
|
153
|
+
nextStep: 'For an existing figure, call listFigures and match the user’s requested name or type; ask which figure only if ambiguous. For a new figure, call proposeFigureCandidate with create: true and the user’s prompt. Do not invent an id or repeat this call without a target.'
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function unsavedFigure(host) {
|
|
157
|
+
if (host?.editorMode !== 'new' || host?.figureId || !host?.draftSource)
|
|
158
|
+
return undefined;
|
|
159
|
+
const row = { id: host.figureId, type: host.draftSource.type, name: '', state: 'draft' };
|
|
160
|
+
// Reuse size, shape and vocabulary validation before trusting browser content.
|
|
161
|
+
const current = sourceForTool(row, host);
|
|
162
|
+
return { ...row, source: JSON.stringify(current.source) };
|
|
148
163
|
}
|
|
149
164
|
const FIGURE_ID_ARG = {
|
|
150
165
|
figureId: {
|
|
151
166
|
type: 'string',
|
|
152
|
-
description: 'The figure to read. Omit
|
|
167
|
+
description: 'The figure to read. Omit when host context has an open figureId or an unsaved new editor draft. On the catalog, first resolve the user’s requested figure with listFigures.'
|
|
153
168
|
}
|
|
154
169
|
};
|
|
155
170
|
/**
|
|
@@ -195,9 +210,11 @@ function figureToolSpecs() {
|
|
|
195
210
|
schema: { type: 'object', properties: { ...FIGURE_ID_ARG } },
|
|
196
211
|
builder: async (args, ctx) => {
|
|
197
212
|
const domainId = requireDomainId(ctx?.state);
|
|
198
|
-
const figureId = figureIdFrom(args, ctx?.
|
|
199
|
-
const row = await figureInDomain(figureId, domainId);
|
|
200
|
-
|
|
213
|
+
const figureId = figureIdFrom(args, ctx?.host);
|
|
214
|
+
const row = figureId ? await figureInDomain(figureId, domainId) : unsavedFigure(ctx?.host);
|
|
215
|
+
if (!row)
|
|
216
|
+
return missingFigureTarget();
|
|
217
|
+
const current = sourceForTool(row, ctx?.host);
|
|
201
218
|
if (!current.source) {
|
|
202
219
|
// 저장된 정본이 없는 상태가 실제로 있다(새로 만들고 저장 안 한 것). 지어내지 않는다.
|
|
203
220
|
return { id: row.id, type: row.type, name: row.name, source: null, cost: null };
|
|
@@ -225,9 +242,11 @@ function figureToolSpecs() {
|
|
|
225
242
|
schema: { type: 'object', properties: { ...FIGURE_ID_ARG } },
|
|
226
243
|
builder: async (args, ctx) => {
|
|
227
244
|
const domainId = requireDomainId(ctx?.state);
|
|
228
|
-
const figureId = figureIdFrom(args, ctx?.
|
|
229
|
-
const row = await figureInDomain(figureId, domainId);
|
|
230
|
-
|
|
245
|
+
const figureId = figureIdFrom(args, ctx?.host);
|
|
246
|
+
const row = figureId ? await figureInDomain(figureId, domainId) : unsavedFigure(ctx?.host);
|
|
247
|
+
if (!row)
|
|
248
|
+
return missingFigureTarget();
|
|
249
|
+
const current = sourceForTool(row, ctx?.host);
|
|
231
250
|
const { inspectSource } = getDeps();
|
|
232
251
|
return { ...inspectSource(current.source ? JSON.stringify(current.source) : null), draft: current.draft };
|
|
233
252
|
}
|
|
@@ -271,14 +290,19 @@ function figureToolSpecs() {
|
|
|
271
290
|
후보가 온다.
|
|
272
291
|
*/
|
|
273
292
|
let base;
|
|
274
|
-
if (!args?.create) {
|
|
275
|
-
const open = typeof args?.figureId === 'string' ? args.figureId : ctx?.
|
|
293
|
+
if (!args?.create && args?.figureId !== null) {
|
|
294
|
+
const open = typeof args?.figureId === 'string' ? args.figureId : ctx?.host?.figureId;
|
|
276
295
|
if (typeof open === 'string' && open.trim()) {
|
|
277
296
|
const row = await figureInDomain(open.trim(), domainId);
|
|
278
|
-
base = sourceForTool(row, ctx?.
|
|
297
|
+
base = sourceForTool(row, ctx?.host).source ?? undefined;
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
const draft = unsavedFigure(ctx?.host);
|
|
301
|
+
if (draft)
|
|
302
|
+
base = JSON.parse(draft.source);
|
|
279
303
|
}
|
|
280
304
|
}
|
|
281
|
-
const palette = Array.isArray(ctx?.
|
|
305
|
+
const palette = Array.isArray(ctx?.host?.palette) ? ctx.host.palette : [];
|
|
282
306
|
if (palette.length === 0) {
|
|
283
307
|
/*
|
|
284
308
|
팔레트를 모르면 모델이 색을 지어내고, 그 후보는 그리는 시점에 `resolveToken` 이 던진다 —
|
|
@@ -287,7 +311,7 @@ function figureToolSpecs() {
|
|
|
287
311
|
throw new Error('the palette is missing from the host context — the candidate would invent colours');
|
|
288
312
|
}
|
|
289
313
|
const { proposeFigure } = getDeps();
|
|
290
|
-
const feedback = feedbackForTool(ctx?.
|
|
314
|
+
const feedback = feedbackForTool(ctx?.host, base ? figureIdFrom(args, ctx?.host) : undefined);
|
|
291
315
|
const result = await proposeFigure({
|
|
292
316
|
prompt,
|
|
293
317
|
palette,
|
|
@@ -309,7 +333,12 @@ function figureToolSpecs() {
|
|
|
309
333
|
label: base ? `${result.source.type} 고치기` : `${result.source.type} 만들기`,
|
|
310
334
|
reason: `등급 ${result.score.grade} · 삼각형 ${result.cost.triangles} · ` +
|
|
311
335
|
`한 도면 ${result.cost.at.drawCalls}회 · ${result.attempts}번에 만들었다`,
|
|
312
|
-
args: {
|
|
336
|
+
args: {
|
|
337
|
+
baseSource: base ? JSON.stringify(base) : undefined,
|
|
338
|
+
prompt, figureId: base ? figureIdFrom(args, ctx?.host) : undefined,
|
|
339
|
+
draftType: base && ctx?.host?.editorMode === 'new' && !figureIdFrom(args, ctx?.host)
|
|
340
|
+
? base.type : undefined
|
|
341
|
+
},
|
|
313
342
|
source: result.source,
|
|
314
343
|
score: result.score,
|
|
315
344
|
cost: result.cost,
|
|
@@ -334,10 +363,14 @@ function registerFigureToolCategories() {
|
|
|
334
363
|
description: '저작 중인 Figure 의 정본·비용·발행 판정 조회와 후보 제안(저장 아님).',
|
|
335
364
|
guidance: [
|
|
336
365
|
'- **도형을 만들거나 고쳐 달라는 요청에는 반드시 `proposeFigureCandidate` 를 호출한다.**',
|
|
366
|
+
' 후보는 도구 호출 결과에서만 생긴다.',
|
|
337
367
|
' 호출 없이 "후보를 만들었습니다" · "적용 버튼을 누르세요" 라고 쓰는 것은 **거짓이다** — 화면에 후보 칸이 생기지 않으므로 사용자는 존재하지 않는 버튼을 찾는다.',
|
|
338
|
-
' 후보
|
|
368
|
+
' 도크에서는 후보 카드의 버튼을 눌러야 모델러 비교 화면이 열린다. 아직 열지 않은 비교 화면이 이미 보인다고 말하지 않는다.',
|
|
369
|
+
' 요청한 부품만 바뀌었다고 추측하지 않는다. 후보와 원본을 비교한 근거가 없으면 변경 범위는 비교 화면에서 확인하도록 안내한다.',
|
|
339
370
|
'- 정본을 직접 저장하지 않는다. 후보만 내고, 받을지 버릴지는 저작자가 화면에서 정한다.',
|
|
371
|
+
'- 좌표와 크기는 X/Y/Z 축 이름으로 정확하게 표시한다. 확인되지 않은 가로·세로·높이 의미를 임의로 붙이지 않는다.',
|
|
340
372
|
'- **고치라는 요청이면 먼저 `getFigureSource` 를 부른다.** 읽지 않고 고치면 짐작을 상대로 후보를 내게 되고, 부품 이름이 갈려 이미 배치된 보드의 바인딩이 끊긴다.',
|
|
373
|
+
'- 목록 화면에는 열린 도형이 없다. 기존 도형을 조회·수정할 때는 `listFigures`에서 사용자가 말한 이름·타입의 id를 찾는다. 대상이 모호할 때만 어느 도형인지 묻는다. 새 제작 요청에는 기존 정본을 조회하지 않고 `proposeFigureCandidate`를 create: true로 호출한다.',
|
|
341
374
|
'- 타입 이름을 지어내지 않는다 — `listFigures` 로 확인한다. **타입 이름은 저장되는 식별자**이고 보드가 그 이름으로 도형을 찾는다.',
|
|
342
375
|
'- 발행이 안 되는 이유를 물으면 `inspectFigure` 를 부른다. 판정 없이 "발행할 수 있습니다"라고 말하지 않는다.',
|
|
343
376
|
' 판정의 각 항목은 **왜 문제인지와 무엇을 바꾸면 되는지**를 함께 담고 있다. 그대로 전한다 — 요약하면 저작자가 어느 부품의 어느 축을 고칠지 다시 찾아야 한다.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figure-tools.js","sourceRoot":"","sources":["../../../server/service/figure/figure-tools.ts"],"names":[],"mappings":";;AAiEA,gEAEC;AA6RD,oEAmBC;AAnXD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,mEAAuG;AAEvG;;;EAGE;AACF,IAAI,KAAsB,CAAA;AAE1B,SAAS,OAAO;IACd,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,8DAA8D;QAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;QAC9C,8DAA8D;QAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAA;QAC/C,8DAA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AAE,MAAM,CAAC,UAAU;oBAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ;iBAC1B,CAAA;YACH,CAAC;SACF;KACY,CAAA;AACjB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,4BAA4B;IAC1C,MAAM,SAAS,GAAiB;QAC9B,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE,8CAA8C;QAC3D,QAAQ,EAAE;YACR,iEAAiE;YACjE,mGAAmG;YACnG,sEAAsE;YACtE,oDAAoD;YACpD,yGAAyG;YACzG,qFAAqF;YACrF,yEAAyE;YACzE,gGAAgG;YAChG,gEAAgE;SACjE,CAAC,IAAI,CAAC,IAAI,CAAC;QACZ,KAAK,EAAE,eAAe,EAAE;KACzB,CAAA;IAED,IAAA,qCAAoB,EAAC,SAAS,CAAC,CAAA;AACjC,CAAC","sourcesContent":["/*\n * figure 저작 도구를 어시스턴트 도구 레지스트리에 등록 — **대화면(도크)에서 저작을 돕기 위함.**\n *\n * 왜 필요한가: `proposeFigure` 는 한 번 시키고 한 번 받는다. 그것으로 되는 일이 있지만, 저작은\n * 대개 「이걸 이렇게 고쳐 봐 → 무게가 얼마나 되나 → 발행은 되나」처럼 여러 차례 오간다. 그 대화를\n * 하려면 어시스턴트가 **지금 무엇이 있는지 읽을 수 있어야** 한다. 읽지 못하면 매번 사람이 정본을\n * 붙여 넣어야 하고, 그러면 대화가 아니다.\n *\n * 능력을 복제하지 않는다. figure-service 가 이미 가진 진입점(`inspectSource` · `proposeFigure` ·\n * 조회)을 레지스트리에 투영한다.\n *\n * ── 전부 조회·제안 전용이다 ─────────────────────────────────────────────────\n * 정본을 고치는 도구를 넣지 않는다. 형식의 설계가 그렇게 정해져 있다 — 어시스턴트는 **후보**를\n * 내고, 받을지 버릴지는 저작자가 정한다(`figure-propose.ts`). 되돌릴 수 없는 조작이 대화면으로\n * 새지 않으므로 전부 `kind: 'read'` 다.\n *\n * 저장은 저작면이 `updateFigure` 로 한다. 그 mutation 은 `figure:mutation` 이 지키고, 대화는\n * `ai-assistant:mutation` 이 지킨다 — 서로 다른 질문이라 서로 다른 권한이 지킨다. figure 가 board\n * 의 권한을 빌리지 않는다.\n *\n * ── 규율을 도구와 함께 보낸다 ───────────────────────────────────────────────\n * 도구 목록만으로는 「언제 반드시 불러야 하는지」를 모른다. twin 이 그 공백에서 사고를 냈다 —\n * 조치 요청에 도구를 부르지 않고 「제안해 두었습니다」라고만 답해, 사용자에게 **없는 버튼을 누르라고\n * 안내했다.** figure 도 똑같은 자리가 있다: 후보 화면(「지금 / 후보」 두 칸)은 **도구 호출 결과에서만**\n * 만들어진다. 문장으로는 아무 일도 일어나지 않는다.\n *\n * ── LLM 이 넘긴 id 를 믿지 않는다 ───────────────────────────────────────────\n * 사람이 목록에서 고르는 길에서는 드러나지 않지만, 모델은 대화 내용에 이끌려 임의의 id 를 넘길 수\n * 있다. 그래서 호출자 도메인 소속을 먼저 확인한다.\n */\nimport { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'\n\n/*\n 서버 의존성은 lazy require 다. 등록은 부팅 초반에 평가되고 그때 typeorm DataSource 가 준비되지\n 않았을 수 있다(board-import · twin-ai 와 같은 정책).\n*/\nlet _deps: any | undefined\n\nfunction getDeps(): any {\n if (!_deps) {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const shell = require('@things-factory/shell')\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const model = require('@hatiolab/figure-model')\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const entity = require('./figure.js')\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const gate = require('./figure-gate.js')\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const propose = require('./figure-propose.js')\n _deps = {\n getRepository: shell.getRepository,\n Figure: entity.Figure,\n inspectSource: gate.inspectSource,\n proposeFigure: propose.proposeFigure,\n compile: model.compile,\n costOf: model.costOf,\n scoreOf: model.scoreOf,\n validate: model.validate\n }\n }\n return _deps\n}\n\n/** 시험·검증 하네스 전용 주입 시임. 운영 경로에서 호출 금지. */\nexport function __setFigureToolDepsForTest(deps: any): void {\n _deps = deps\n}\n\nfunction requireDomainId(state: any): string {\n const id = state?.domain?.id\n if (!id) {\n // 도메인을 모르면 무엇을 읽어도 남의 것일 수 있다. 조용히 넘기지 않는다.\n throw new Error('domain context is missing — the figure tools cannot resolve tenant scope')\n }\n return id\n}\n\n/**\n * 이 도형이 호출자 도메인 것인가.\n *\n * 모델이 넘긴 id 를 그대로 쓰지 않는다. 없으면 못 찾았다고 말한다 — 「권한이 없다」와 구별해\n * 알려 줄 것이 없다(다른 테넌트에 그 id 가 있다는 사실 자체가 알려 줄 것이 아니다).\n */\nasync function figureInDomain(figureId: string, domainId: string): Promise<any> {\n const { getRepository, Figure } = getDeps()\n const found = await getRepository(Figure).findOne({\n where: { id: figureId, domain: { id: domainId } }\n })\n if (!found) {\n throw new Error(`figure not found in this tenant: ${figureId}`)\n }\n return found\n}\n\n/**\n * 모델러가 아직 저장하지 않은 source를 도구가 읽는 유일한 길.\n *\n * host context는 브라우저가 보낸 값이므로 권한 근거가 될 수 없다. 먼저 `row`를 현재 도메인에서\n * 찾은 뒤에만 보며, Figure의 불변 type과 형식 검증을 다시 확인한다. 검증되지 않은 큰 객체를 LLM\n * 프롬프트로 옮기면 비용만 태우고, DB에 있던 Figure와 다른 것을 고친다고 잘못 말할 수 있다.\n */\nfunction sourceForTool(row: any, host: any): { source: any; draft: boolean } {\n const draft = host?.draftSource\n if (!draft) {\n return { source: row.source ? JSON.parse(row.source) : null, draft: false }\n }\n\n if (typeof draft !== 'object' || Array.isArray(draft)) {\n throw new Error('the unsaved draft is not a FigureSource object')\n }\n\n const serialized = JSON.stringify(draft)\n if (serialized.length > 100_000) {\n throw new Error('the unsaved draft is too large to safely review')\n }\n\n const { validate } = getDeps()\n const checked = validate(draft)\n if (checked.errors.length > 0) {\n throw new Error(`the unsaved draft is invalid: ${checked.errors.map((one: any) => one.message).join(' · ')}`)\n }\n if (draft.type !== row.type) {\n throw new Error(`the unsaved draft type '${draft.type}' does not match Figure '${row.type}'`)\n }\n\n return { source: draft, draft: true }\n}\n\n/**\n * 후보를 냈던 바로 그 Figure의 세션 반응만 후보 생성기에 넘긴다.\n *\n * 도크의 host context는 브라우저 값이므로 이 함수는 접근 권한을 판단하지 않는다. 이미 현재\n * 도메인에서 Figure를 찾은 뒤, `proposeFigure`가 다시 길이·형식을 정리할 참고 데이터만 건넨다.\n */\nfunction feedbackForTool(host: any, figureId?: string): unknown[] | undefined {\n if (!figureId || host?.figureId !== figureId || !Array.isArray(host?.proposalFeedback)) return undefined\n return host.proposalFeedback.slice(-5)\n}\n\n/**\n * 무엇을 고치라는 것인지 대화면 문맥에서 해소한다.\n *\n * 모델이 대상을 안 줬으면 **저작면이 지금 열고 있는 도형**이다. 사용자에게 식별자를 되묻지\n * 않는다 — 화면에 그 도형이 떠 있는데 「어느 도형입니까」를 묻는 것은 문맥을 안 읽은 것이다.\n */\nfunction figureIdFrom(args: any, host: any): string {\n const said = typeof args?.figureId === 'string' ? args.figureId.trim() : ''\n if (said) return said\n\n const open = typeof host?.figureId === 'string' ? host.figureId.trim() : ''\n if (open) return open\n\n throw new Error('figureId is required: this surface has no figure open to resolve it from')\n}\n\nconst FIGURE_ID_ARG = {\n figureId: {\n type: 'string',\n description: 'The figure to read. Omit to use the one open in the editor.'\n }\n} as const\n\n/**\n * 도구 넷.\n *\n * 목록 · 정본 · 발행 판정 · 후보. 저작 대화에서 실제로 묻는 것이 그 넷이다 — 「무엇이 있나」\n * 「지금 어떻게 생겼나」 「발행이 왜 안 되나」 「이렇게 고쳐 봐」.\n */\nfunction figureToolSpecs(): ToolSpec[] {\n return [\n {\n kind: 'read',\n name: 'listFigures',\n description:\n 'Lists the figures in this tenant with their type names, states and part counts. ' +\n 'Call it before naming a type — type names are stored identifiers and must not be invented.',\n schema: { type: 'object', properties: {} },\n builder: async (_args: any, ctx: any) => {\n const domainId = requireDomainId(ctx?.state)\n const { getRepository, Figure } = getDeps()\n const rows = await getRepository(Figure).find({\n where: { domain: { id: domainId } },\n order: { updatedAt: 'DESC' },\n take: 200\n })\n return {\n figures: rows.map((row: any) => ({\n id: row.id,\n type: row.type,\n name: row.name,\n state: row.state,\n score: row.score,\n triangles: row.triangles\n }))\n }\n }\n },\n {\n kind: 'read',\n name: 'getFigureSource',\n description:\n 'Returns the canonical FigureSource of one figure, with its measured cost ' +\n '(triangles, draw calls, how many fit on one board). Call it before proposing a revision — ' +\n 'revising without reading it means proposing against a guess.',\n schema: { type: 'object', properties: { ...FIGURE_ID_ARG } },\n builder: async (args: any, ctx: any) => {\n const domainId = requireDomainId(ctx?.state)\n const figureId = figureIdFrom(args, ctx?.state?.host)\n const row = await figureInDomain(figureId, domainId)\n\n const current = sourceForTool(row, ctx?.state?.host)\n if (!current.source) {\n // 저장된 정본이 없는 상태가 실제로 있다(새로 만들고 저장 안 한 것). 지어내지 않는다.\n return { id: row.id, type: row.type, name: row.name, source: null, cost: null }\n }\n\n const { compile, costOf, scoreOf } = getDeps()\n const blueprint = compile(current.source)\n\n return {\n id: row.id,\n type: row.type,\n name: row.name,\n state: row.state,\n source: current.source,\n draft: current.draft,\n cost: costOf(blueprint, 100),\n score: scoreOf(blueprint)\n }\n }\n },\n {\n kind: 'read',\n name: 'inspectFigure',\n description:\n 'Says whether a figure may be released and, when it may not, what is wrong — each finding ' +\n 'carries why it is a problem and what to change. Call it when asked about releasing, or ' +\n 'when asked to fix a figure that will not release.',\n schema: { type: 'object', properties: { ...FIGURE_ID_ARG } },\n builder: async (args: any, ctx: any) => {\n const domainId = requireDomainId(ctx?.state)\n const figureId = figureIdFrom(args, ctx?.state?.host)\n const row = await figureInDomain(figureId, domainId)\n\n const current = sourceForTool(row, ctx?.state?.host)\n const { inspectSource } = getDeps()\n return { ...inspectSource(current.source ? JSON.stringify(current.source) : null), draft: current.draft }\n }\n },\n {\n kind: 'read',\n name: 'proposeFigureCandidate',\n description:\n 'Asks for a figure candidate from a description, optionally revising an existing one. ' +\n 'Returns the candidate with its score and cost. NOTHING IS SAVED — the author accepts or ' +\n 'discards it on screen. This is the only way a candidate reaches the screen.',\n schema: {\n type: 'object',\n properties: {\n prompt: {\n type: 'string',\n description: 'What to make or change, in the words the author used.'\n },\n figureId: {\n type: 'string',\n description: 'Revise this figure. Omit to revise the one open in the editor; pass null to create anew.'\n },\n type: {\n type: 'string',\n description: 'Type name for a new figure. Check listFigures first — it is a stored identifier.'\n },\n create: {\n type: 'boolean',\n description: 'True to create rather than revise, even with a figure open.'\n }\n },\n required: ['prompt']\n },\n builder: async (args: any, ctx: any) => {\n const domainId = requireDomainId(ctx?.state)\n const prompt = typeof args?.prompt === 'string' ? args.prompt.trim() : ''\n if (!prompt) throw new Error('prompt is required: there is nothing to ask for')\n\n /*\n 고치는 것인지 만드는 것인지를 **문맥에서 정한다.** 열린 도형이 있으면 고치는 것이 기본이고,\n 모델이 `create` 를 켜면 만드는 것이다. 이것을 모델의 짐작에 맡기면 열려 있는 도형을 덮어쓰는\n 후보가 온다.\n */\n let base: unknown\n if (!args?.create) {\n const open = typeof args?.figureId === 'string' ? args.figureId : ctx?.state?.host?.figureId\n if (typeof open === 'string' && open.trim()) {\n const row = await figureInDomain(open.trim(), domainId)\n base = sourceForTool(row, ctx?.state?.host).source ?? undefined\n }\n }\n\n const palette = Array.isArray(ctx?.state?.host?.palette) ? ctx.state.host.palette : []\n if (palette.length === 0) {\n /*\n 팔레트를 모르면 모델이 색을 지어내고, 그 후보는 그리는 시점에 `resolveToken` 이 던진다 —\n 저장까지 되고 나서 화면에서 죽는다. 빈 목록으로 진행하지 않는다.\n */\n throw new Error('the palette is missing from the host context — the candidate would invent colours')\n }\n\n const { proposeFigure } = getDeps()\n const feedback = feedbackForTool(ctx?.state?.host, base ? figureIdFrom(args, ctx?.state?.host) : undefined)\n const result = await proposeFigure({\n prompt,\n palette,\n base,\n type: typeof args?.type === 'string' ? args.type : undefined,\n feedback,\n refine: !!feedback?.length\n })\n\n /*\n **`proposed: true` 가 카드를 만든다.** 이 표시가 없으면 후보는 도구 추적 안에 묻히고,\n 화면에는 아무것도 생기지 않는다 — 그러면 모델이 「후보를 만들었습니다」라고 쓴 것이\n 거짓말이 된다(사용자가 없는 단추를 찾는다).\n\n `label`·`reason` 이 카드에 그려지는 두 줄이고, `args` 는 같은 제안을 두 번 세지 않기\n 위한 열쇠의 일부다 — 같은 요청을 두 번 내면 카드가 하나로 접힌다.\n */\n return {\n proposed: true,\n label: base ? `${result.source.type} 고치기` : `${result.source.type} 만들기`,\n reason:\n `등급 ${result.score.grade} · 삼각형 ${result.cost.triangles} · ` +\n `한 도면 ${result.cost.at.drawCalls}회 · ${result.attempts}번에 만들었다`,\n args: { prompt, figureId: base ? figureIdFrom(args, ctx?.state?.host) : undefined },\n source: result.source,\n score: result.score,\n cost: result.cost,\n quality: result.quality,\n violations: result.violations,\n attempts: result.attempts\n }\n }\n }\n ] as ToolSpec[]\n}\n\n/**\n * 등록 — 부팅 시 1회.\n *\n * 범주가 하나다. twin 은 관찰과 생성을 둘로 갈랐는데(운영 협의에 생성 도구가 들려 있으면 대화의\n * 성격이 흐려진다), figure 의 대화면은 저작면 하나뿐이고 그 자리에서 읽기와 후보 요청이 함께 필요하다.\n * 대화면이 늘면 그때 가른다.\n */\nexport function registerFigureToolCategories(): void {\n const authoring: ToolCategory = {\n name: 'figure-authoring',\n description: '저작 중인 Figure 의 정본·비용·발행 판정 조회와 후보 제안(저장 아님).',\n guidance: [\n '- **도형을 만들거나 고쳐 달라는 요청에는 반드시 `proposeFigureCandidate` 를 호출한다.**',\n ' 호출 없이 \"후보를 만들었습니다\" · \"적용 버튼을 누르세요\" 라고 쓰는 것은 **거짓이다** — 화면에 후보 칸이 생기지 않으므로 사용자는 존재하지 않는 버튼을 찾는다.',\n ' 후보 화면(「지금 / 후보」 두 칸)은 **도구 호출 결과에서만** 만들어진다. 문장으로는 아무 일도 일어나지 않는다.',\n '- 정본을 직접 저장하지 않는다. 후보만 내고, 받을지 버릴지는 저작자가 화면에서 정한다.',\n '- **고치라는 요청이면 먼저 `getFigureSource` 를 부른다.** 읽지 않고 고치면 짐작을 상대로 후보를 내게 되고, 부품 이름이 갈려 이미 배치된 보드의 바인딩이 끊긴다.',\n '- 타입 이름을 지어내지 않는다 — `listFigures` 로 확인한다. **타입 이름은 저장되는 식별자**이고 보드가 그 이름으로 도형을 찾는다.',\n '- 발행이 안 되는 이유를 물으면 `inspectFigure` 를 부른다. 판정 없이 \"발행할 수 있습니다\"라고 말하지 않는다.',\n ' 판정의 각 항목은 **왜 문제인지와 무엇을 바꾸면 되는지**를 함께 담고 있다. 그대로 전한다 — 요약하면 저작자가 어느 부품의 어느 축을 고칠지 다시 찾아야 한다.',\n '- 무게·삼각형 수를 물으면 `getFigureSource` 의 `cost` 를 쓴다. 눈대중으로 세지 않는다.'\n ].join('\\n'),\n specs: figureToolSpecs()\n }\n\n registerToolCategory(authoring)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"figure-tools.js","sourceRoot":"","sources":["../../../server/service/figure/figure-tools.ts"],"names":[],"mappings":";;AAiEA,gEAEC;AAuTD,oEAuBC;AAjZD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,mEAAuG;AAEvG;;;EAGE;AACF,IAAI,KAAsB,CAAA;AAE1B,SAAS,OAAO;IACd,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,8DAA8D;QAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;QAC9C,8DAA8D;QAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAA;QAC/C,8DAA8D;QAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;QACrC,8DAA8D;QAC9D,MAAM,IAAI,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;QACxC,8DAA8D;QAC9D,MAAM,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;QAC9C,KAAK,GAAG;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Q;iBAC1B,CAAA;YACH,CAAC;SACF;KACY,CAAA;AACjB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,4BAA4B;IAC1C,MAAM,SAAS,GAAiB;QAC9B,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE,8CAA8C;QAC3D,QAAQ,EAAE;YACR,iEAAiE;YACjE,wBAAwB;YACxB,mGAAmG;YACnG,yEAAyE;YACzE,0EAA0E;YAC1E,oDAAoD;YACpD,qEAAqE;YACrE,yGAAyG;YACzG,8KAA8K;YAC9K,qFAAqF;YACrF,yEAAyE;YACzE,gGAAgG;YAChG,gEAAgE;SACjE,CAAC,IAAI,CAAC,IAAI,CAAC;QACZ,KAAK,EAAE,eAAe,EAAE;KACzB,CAAA;IAED,IAAA,qCAAoB,EAAC,SAAS,CAAC,CAAA;AACjC,CAAC","sourcesContent":["/*\n * figure 저작 도구를 어시스턴트 도구 레지스트리에 등록 — **대화면(도크)에서 저작을 돕기 위함.**\n *\n * 왜 필요한가: `proposeFigure` 는 한 번 시키고 한 번 받는다. 그것으로 되는 일이 있지만, 저작은\n * 대개 「이걸 이렇게 고쳐 봐 → 무게가 얼마나 되나 → 발행은 되나」처럼 여러 차례 오간다. 그 대화를\n * 하려면 어시스턴트가 **지금 무엇이 있는지 읽을 수 있어야** 한다. 읽지 못하면 매번 사람이 정본을\n * 붙여 넣어야 하고, 그러면 대화가 아니다.\n *\n * 능력을 복제하지 않는다. figure-service 가 이미 가진 진입점(`inspectSource` · `proposeFigure` ·\n * 조회)을 레지스트리에 투영한다.\n *\n * ── 전부 조회·제안 전용이다 ─────────────────────────────────────────────────\n * 정본을 고치는 도구를 넣지 않는다. 형식의 설계가 그렇게 정해져 있다 — 어시스턴트는 **후보**를\n * 내고, 받을지 버릴지는 저작자가 정한다(`figure-propose.ts`). 되돌릴 수 없는 조작이 대화면으로\n * 새지 않으므로 전부 `kind: 'read'` 다.\n *\n * 저장은 저작면이 `updateFigure` 로 한다. 그 mutation 은 `figure:mutation` 이 지키고, 대화는\n * `ai-assistant:mutation` 이 지킨다 — 서로 다른 질문이라 서로 다른 권한이 지킨다. figure 가 board\n * 의 권한을 빌리지 않는다.\n *\n * ── 규율을 도구와 함께 보낸다 ───────────────────────────────────────────────\n * 도구 목록만으로는 「언제 반드시 불러야 하는지」를 모른다. twin 이 그 공백에서 사고를 냈다 —\n * 조치 요청에 도구를 부르지 않고 「제안해 두었습니다」라고만 답해, 사용자에게 **없는 버튼을 누르라고\n * 안내했다.** figure 도 똑같은 자리가 있다: 후보 화면(「지금 / 후보」 두 칸)은 **도구 호출 결과에서만**\n * 만들어진다. 문장으로는 아무 일도 일어나지 않는다.\n *\n * ── LLM 이 넘긴 id 를 믿지 않는다 ───────────────────────────────────────────\n * 사람이 목록에서 고르는 길에서는 드러나지 않지만, 모델은 대화 내용에 이끌려 임의의 id 를 넘길 수\n * 있다. 그래서 호출자 도메인 소속을 먼저 확인한다.\n */\nimport { registerToolCategory, type ToolCategory, type ToolSpec } from '@things-factory/ai-client-base'\n\n/*\n 서버 의존성은 lazy require 다. 등록은 부팅 초반에 평가되고 그때 typeorm DataSource 가 준비되지\n 않았을 수 있다(board-import · twin-ai 와 같은 정책).\n*/\nlet _deps: any | undefined\n\nfunction getDeps(): any {\n if (!_deps) {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const shell = require('@things-factory/shell')\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const model = require('@hatiolab/figure-model')\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const entity = require('./figure.js')\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const gate = require('./figure-gate.js')\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const propose = require('./figure-propose.js')\n _deps = {\n getRepository: shell.getRepository,\n Figure: entity.Figure,\n inspectSource: gate.inspectSource,\n proposeFigure: propose.proposeFigure,\n compile: model.compile,\n costOf: model.costOf,\n scoreOf: model.scoreOf,\n validate: model.validate\n }\n }\n return _deps\n}\n\n/** 시험·검증 하네스 전용 주입 시임. 운영 경로에서 호출 금지. */\nexport function __setFigureToolDepsForTest(deps: any): void {\n _deps = deps\n}\n\nfunction requireDomainId(state: any): string {\n const id = state?.domain?.id\n if (!id) {\n // 도메인을 모르면 무엇을 읽어도 남의 것일 수 있다. 조용히 넘기지 않는다.\n throw new Error('domain context is missing — the figure tools cannot resolve tenant scope')\n }\n return id\n}\n\n/**\n * 이 도형이 호출자 도메인 것인가.\n *\n * 모델이 넘긴 id 를 그대로 쓰지 않는다. 없으면 못 찾았다고 말한다 — 「권한이 없다」와 구별해\n * 알려 줄 것이 없다(다른 테넌트에 그 id 가 있다는 사실 자체가 알려 줄 것이 아니다).\n */\nasync function figureInDomain(figureId: string, domainId: string): Promise<any> {\n const { getRepository, Figure } = getDeps()\n const found = await getRepository(Figure).findOne({\n where: { id: figureId, domain: { id: domainId } }\n })\n if (!found) {\n throw new Error(`figure not found in this tenant: ${figureId}`)\n }\n return found\n}\n\n/**\n * 모델러가 아직 저장하지 않은 source를 도구가 읽는 유일한 길.\n *\n * host context는 브라우저가 보낸 값이므로 권한 근거가 될 수 없다. 먼저 `row`를 현재 도메인에서\n * 찾은 뒤에만 보며, Figure의 불변 type과 형식 검증을 다시 확인한다. 검증되지 않은 큰 객체를 LLM\n * 프롬프트로 옮기면 비용만 태우고, DB에 있던 Figure와 다른 것을 고친다고 잘못 말할 수 있다.\n */\nfunction sourceForTool(row: any, host: any): { source: any; draft: boolean } {\n const draft = host?.figureId === row.id ? host?.draftSource : undefined\n if (!draft) {\n return { source: row.source ? JSON.parse(row.source) : null, draft: false }\n }\n\n if (typeof draft !== 'object' || Array.isArray(draft)) {\n throw new Error('the unsaved draft is not a FigureSource object')\n }\n\n const serialized = JSON.stringify(draft)\n if (serialized.length > 100_000) {\n throw new Error('the unsaved draft is too large to safely review')\n }\n\n const { validate } = getDeps()\n const checked = validate(draft)\n if (checked.errors.length > 0) {\n throw new Error(`the unsaved draft is invalid: ${checked.errors.map((one: any) => one.message).join(' · ')}`)\n }\n if (draft.type !== row.type) {\n throw new Error(`the unsaved draft type '${draft.type}' does not match Figure '${row.type}'`)\n }\n\n return { source: draft, draft: true }\n}\n\n/**\n * 후보를 냈던 바로 그 Figure의 세션 반응만 후보 생성기에 넘긴다.\n *\n * 도크의 host context는 브라우저 값이므로 이 함수는 접근 권한을 판단하지 않는다. 이미 현재\n * 도메인에서 Figure를 찾은 뒤, `proposeFigure`가 다시 길이·형식을 정리할 참고 데이터만 건넨다.\n */\nfunction feedbackForTool(host: any, figureId?: string): unknown[] | undefined {\n if (!figureId || host?.figureId !== figureId || !Array.isArray(host?.proposalFeedback)) return undefined\n return host.proposalFeedback.slice(-5)\n}\n\n/**\n * 무엇을 고치라는 것인지 대화면 문맥에서 해소한다.\n *\n * 모델이 대상을 안 줬으면 **저작면이 지금 열고 있는 도형**이다. 사용자에게 식별자를 되묻지\n * 않는다 — 화면에 그 도형이 떠 있는데 「어느 도형입니까」를 묻는 것은 문맥을 안 읽은 것이다.\n */\nfunction figureIdFrom(args: any, host: any): string | undefined {\n const said = typeof args?.figureId === 'string' ? args.figureId.trim() : ''\n if (said) return said\n\n const open = typeof host?.figureId === 'string' ? host.figureId.trim() : ''\n if (open) return open\n\n return undefined\n}\n\nfunction missingFigureTarget() {\n return {\n error: 'FIGURE_TARGET_REQUIRED',\n message: '현재 화면에는 선택된 도형이 없습니다.',\n nextStep: 'For an existing figure, call listFigures and match the user’s requested name or type; ask which figure only if ambiguous. For a new figure, call proposeFigureCandidate with create: true and the user’s prompt. Do not invent an id or repeat this call without a target.'\n }\n}\n\nfunction unsavedFigure(host: any): any | undefined {\n if (host?.editorMode !== 'new' || host?.figureId || !host?.draftSource) return undefined\n const row = { id: host.figureId, type: host.draftSource.type, name: '', state: 'draft' }\n // Reuse size, shape and vocabulary validation before trusting browser content.\n const current = sourceForTool(row, host)\n return { ...row, source: JSON.stringify(current.source) }\n}\n\nconst FIGURE_ID_ARG = {\n figureId: {\n type: 'string',\n description: 'The figure to read. Omit when host context has an open figureId or an unsaved new editor draft. On the catalog, first resolve the user’s requested figure with listFigures.'\n }\n} as const\n\n/**\n * 도구 넷.\n *\n * 목록 · 정본 · 발행 판정 · 후보. 저작 대화에서 실제로 묻는 것이 그 넷이다 — 「무엇이 있나」\n * 「지금 어떻게 생겼나」 「발행이 왜 안 되나」 「이렇게 고쳐 봐」.\n */\nfunction figureToolSpecs(): ToolSpec[] {\n return [\n {\n kind: 'read',\n name: 'listFigures',\n description:\n 'Lists the figures in this tenant with their type names, states and part counts. ' +\n 'Call it before naming a type — type names are stored identifiers and must not be invented.',\n schema: { type: 'object', properties: {} },\n builder: async (_args: any, ctx: any) => {\n const domainId = requireDomainId(ctx?.state)\n const { getRepository, Figure } = getDeps()\n const rows = await getRepository(Figure).find({\n where: { domain: { id: domainId } },\n order: { updatedAt: 'DESC' },\n take: 200\n })\n return {\n figures: rows.map((row: any) => ({\n id: row.id,\n type: row.type,\n name: row.name,\n state: row.state,\n score: row.score,\n triangles: row.triangles\n }))\n }\n }\n },\n {\n kind: 'read',\n name: 'getFigureSource',\n description:\n 'Returns the canonical FigureSource of one figure, with its measured cost ' +\n '(triangles, draw calls, how many fit on one board). Call it before proposing a revision — ' +\n 'revising without reading it means proposing against a guess.',\n schema: { type: 'object', properties: { ...FIGURE_ID_ARG } },\n builder: async (args: any, ctx: any) => {\n const domainId = requireDomainId(ctx?.state)\n const figureId = figureIdFrom(args, ctx?.host)\n const row = figureId ? await figureInDomain(figureId, domainId) : unsavedFigure(ctx?.host)\n if (!row) return missingFigureTarget()\n\n const current = sourceForTool(row, ctx?.host)\n if (!current.source) {\n // 저장된 정본이 없는 상태가 실제로 있다(새로 만들고 저장 안 한 것). 지어내지 않는다.\n return { id: row.id, type: row.type, name: row.name, source: null, cost: null }\n }\n\n const { compile, costOf, scoreOf } = getDeps()\n const blueprint = compile(current.source)\n\n return {\n id: row.id,\n type: row.type,\n name: row.name,\n state: row.state,\n source: current.source,\n draft: current.draft,\n cost: costOf(blueprint, 100),\n score: scoreOf(blueprint)\n }\n }\n },\n {\n kind: 'read',\n name: 'inspectFigure',\n description:\n 'Says whether a figure may be released and, when it may not, what is wrong — each finding ' +\n 'carries why it is a problem and what to change. Call it when asked about releasing, or ' +\n 'when asked to fix a figure that will not release.',\n schema: { type: 'object', properties: { ...FIGURE_ID_ARG } },\n builder: async (args: any, ctx: any) => {\n const domainId = requireDomainId(ctx?.state)\n const figureId = figureIdFrom(args, ctx?.host)\n const row = figureId ? await figureInDomain(figureId, domainId) : unsavedFigure(ctx?.host)\n if (!row) return missingFigureTarget()\n\n const current = sourceForTool(row, ctx?.host)\n const { inspectSource } = getDeps()\n return { ...inspectSource(current.source ? JSON.stringify(current.source) : null), draft: current.draft }\n }\n },\n {\n kind: 'read',\n name: 'proposeFigureCandidate',\n description:\n 'Asks for a figure candidate from a description, optionally revising an existing one. ' +\n 'Returns the candidate with its score and cost. NOTHING IS SAVED — the author accepts or ' +\n 'discards it on screen. This is the only way a candidate reaches the screen.',\n schema: {\n type: 'object',\n properties: {\n prompt: {\n type: 'string',\n description: 'What to make or change, in the words the author used.'\n },\n figureId: {\n type: 'string',\n description: 'Revise this figure. Omit to revise the one open in the editor; pass null to create anew.'\n },\n type: {\n type: 'string',\n description: 'Type name for a new figure. Check listFigures first — it is a stored identifier.'\n },\n create: {\n type: 'boolean',\n description: 'True to create rather than revise, even with a figure open.'\n }\n },\n required: ['prompt']\n },\n builder: async (args: any, ctx: any) => {\n const domainId = requireDomainId(ctx?.state)\n const prompt = typeof args?.prompt === 'string' ? args.prompt.trim() : ''\n if (!prompt) throw new Error('prompt is required: there is nothing to ask for')\n\n /*\n 고치는 것인지 만드는 것인지를 **문맥에서 정한다.** 열린 도형이 있으면 고치는 것이 기본이고,\n 모델이 `create` 를 켜면 만드는 것이다. 이것을 모델의 짐작에 맡기면 열려 있는 도형을 덮어쓰는\n 후보가 온다.\n */\n let base: unknown\n if (!args?.create && args?.figureId !== null) {\n const open = typeof args?.figureId === 'string' ? args.figureId : ctx?.host?.figureId\n if (typeof open === 'string' && open.trim()) {\n const row = await figureInDomain(open.trim(), domainId)\n base = sourceForTool(row, ctx?.host).source ?? undefined\n } else {\n const draft = unsavedFigure(ctx?.host)\n if (draft) base = JSON.parse(draft.source)\n }\n }\n\n const palette = Array.isArray(ctx?.host?.palette) ? ctx.host.palette : []\n if (palette.length === 0) {\n /*\n 팔레트를 모르면 모델이 색을 지어내고, 그 후보는 그리는 시점에 `resolveToken` 이 던진다 —\n 저장까지 되고 나서 화면에서 죽는다. 빈 목록으로 진행하지 않는다.\n */\n throw new Error('the palette is missing from the host context — the candidate would invent colours')\n }\n\n const { proposeFigure } = getDeps()\n const feedback = feedbackForTool(ctx?.host, base ? figureIdFrom(args, ctx?.host) : undefined)\n const result = await proposeFigure({\n prompt,\n palette,\n base,\n type: typeof args?.type === 'string' ? args.type : undefined,\n feedback,\n refine: !!feedback?.length\n })\n\n /*\n **`proposed: true` 가 카드를 만든다.** 이 표시가 없으면 후보는 도구 추적 안에 묻히고,\n 화면에는 아무것도 생기지 않는다 — 그러면 모델이 「후보를 만들었습니다」라고 쓴 것이\n 거짓말이 된다(사용자가 없는 단추를 찾는다).\n\n `label`·`reason` 이 카드에 그려지는 두 줄이고, `args` 는 같은 제안을 두 번 세지 않기\n 위한 열쇠의 일부다 — 같은 요청을 두 번 내면 카드가 하나로 접힌다.\n */\n return {\n proposed: true,\n label: base ? `${result.source.type} 고치기` : `${result.source.type} 만들기`,\n reason:\n `등급 ${result.score.grade} · 삼각형 ${result.cost.triangles} · ` +\n `한 도면 ${result.cost.at.drawCalls}회 · ${result.attempts}번에 만들었다`,\n args: {\n baseSource: base ? JSON.stringify(base) : undefined,\n prompt, figureId: base ? figureIdFrom(args, ctx?.host) : undefined,\n draftType: base && ctx?.host?.editorMode === 'new' && !figureIdFrom(args, ctx?.host)\n ? (base as any).type : undefined\n },\n source: result.source,\n score: result.score,\n cost: result.cost,\n quality: result.quality,\n violations: result.violations,\n attempts: result.attempts\n }\n }\n }\n ] as ToolSpec[]\n}\n\n/**\n * 등록 — 부팅 시 1회.\n *\n * 범주가 하나다. twin 은 관찰과 생성을 둘로 갈랐는데(운영 협의에 생성 도구가 들려 있으면 대화의\n * 성격이 흐려진다), figure 의 대화면은 저작면 하나뿐이고 그 자리에서 읽기와 후보 요청이 함께 필요하다.\n * 대화면이 늘면 그때 가른다.\n */\nexport function registerFigureToolCategories(): void {\n const authoring: ToolCategory = {\n name: 'figure-authoring',\n description: '저작 중인 Figure 의 정본·비용·발행 판정 조회와 후보 제안(저장 아님).',\n guidance: [\n '- **도형을 만들거나 고쳐 달라는 요청에는 반드시 `proposeFigureCandidate` 를 호출한다.**',\n ' 후보는 도구 호출 결과에서만 생긴다.',\n ' 호출 없이 \"후보를 만들었습니다\" · \"적용 버튼을 누르세요\" 라고 쓰는 것은 **거짓이다** — 화면에 후보 칸이 생기지 않으므로 사용자는 존재하지 않는 버튼을 찾는다.',\n ' 도크에서는 후보 카드의 버튼을 눌러야 모델러 비교 화면이 열린다. 아직 열지 않은 비교 화면이 이미 보인다고 말하지 않는다.',\n ' 요청한 부품만 바뀌었다고 추측하지 않는다. 후보와 원본을 비교한 근거가 없으면 변경 범위는 비교 화면에서 확인하도록 안내한다.',\n '- 정본을 직접 저장하지 않는다. 후보만 내고, 받을지 버릴지는 저작자가 화면에서 정한다.',\n '- 좌표와 크기는 X/Y/Z 축 이름으로 정확하게 표시한다. 확인되지 않은 가로·세로·높이 의미를 임의로 붙이지 않는다.',\n '- **고치라는 요청이면 먼저 `getFigureSource` 를 부른다.** 읽지 않고 고치면 짐작을 상대로 후보를 내게 되고, 부품 이름이 갈려 이미 배치된 보드의 바인딩이 끊긴다.',\n '- 목록 화면에는 열린 도형이 없다. 기존 도형을 조회·수정할 때는 `listFigures`에서 사용자가 말한 이름·타입의 id를 찾는다. 대상이 모호할 때만 어느 도형인지 묻는다. 새 제작 요청에는 기존 정본을 조회하지 않고 `proposeFigureCandidate`를 create: true로 호출한다.',\n '- 타입 이름을 지어내지 않는다 — `listFigures` 로 확인한다. **타입 이름은 저장되는 식별자**이고 보드가 그 이름으로 도형을 찾는다.',\n '- 발행이 안 되는 이유를 물으면 `inspectFigure` 를 부른다. 판정 없이 \"발행할 수 있습니다\"라고 말하지 않는다.',\n ' 판정의 각 항목은 **왜 문제인지와 무엇을 바꾸면 되는지**를 함께 담고 있다. 그대로 전한다 — 요약하면 저작자가 어느 부품의 어느 축을 고칠지 다시 찾아야 한다.',\n '- 무게·삼각형 수를 물으면 `getFigureSource` 의 `cost` 를 쓴다. 눈대중으로 세지 않는다.'\n ].join('\\n'),\n specs: figureToolSpecs()\n }\n\n registerToolCategory(authoring)\n}\n"]}
|