@things-factory/figure-service 10.1.3 → 10.1.6
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/coverage/clover.xml +6 -0
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +101 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +0 -0
- package/dist-server/index.d.ts +2 -0
- package/dist-server/index.js +13 -0
- package/dist-server/index.js.map +1 -1
- package/dist-server/routers/figure-thumbnail-router.d.ts +24 -0
- package/dist-server/routers/figure-thumbnail-router.js +93 -0
- package/dist-server/routers/figure-thumbnail-router.js.map +1 -0
- package/dist-server/routes.d.ts +1 -0
- package/dist-server/routes.js +21 -0
- package/dist-server/routes.js.map +1 -0
- package/dist-server/service/figure/event-subscriber.d.ts +21 -0
- package/dist-server/service/figure/event-subscriber.js +51 -0
- package/dist-server/service/figure/event-subscriber.js.map +1 -0
- package/dist-server/service/figure/figure-gate.d.ts +55 -0
- package/dist-server/service/figure/figure-gate.js +64 -0
- package/dist-server/service/figure/figure-gate.js.map +1 -0
- package/dist-server/service/figure/figure-history.d.ts +43 -0
- package/dist-server/service/figure/figure-history.js +155 -0
- package/dist-server/service/figure/figure-history.js.map +1 -0
- package/dist-server/service/figure/figure-mutation.d.ts +45 -0
- package/dist-server/service/figure/figure-mutation.js +174 -1
- package/dist-server/service/figure/figure-mutation.js.map +1 -1
- package/dist-server/service/figure/figure-query.d.ts +24 -1
- package/dist-server/service/figure/figure-query.js +75 -0
- package/dist-server/service/figure/figure-query.js.map +1 -1
- package/dist-server/service/figure/figure-tools.d.ts +10 -0
- package/dist-server/service/figure/figure-tools.js +304 -0
- package/dist-server/service/figure/figure-tools.js.map +1 -0
- package/dist-server/service/figure/figure-type.d.ts +25 -1
- package/dist-server/service/figure/figure-type.js +58 -5
- package/dist-server/service/figure/figure-type.js.map +1 -1
- package/dist-server/service/figure/figure.d.ts +9 -0
- package/dist-server/service/figure/figure.js +15 -3
- package/dist-server/service/figure/figure.js.map +1 -1
- package/dist-server/service/figure/index.d.ts +4 -1
- package/dist-server/service/figure/index.js +5 -2
- package/dist-server/service/figure/index.js.map +1 -1
- package/dist-server/service/index.d.ts +6 -2
- package/dist-server/service/index.js +17 -2
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +9 -6
- package/server/index.ts +13 -0
- package/server/routers/figure-thumbnail-router.ts +110 -0
- package/server/routes.ts +24 -0
- package/server/service/figure/event-subscriber.ts +49 -0
- package/server/service/figure/figure-gate.ts +119 -0
- package/server/service/figure/figure-history.ts +130 -0
- package/server/service/figure/figure-mutation.ts +180 -1
- package/server/service/figure/figure-propose.test.ts +136 -4
- package/server/service/figure/figure-query.ts +63 -1
- package/server/service/figure/figure-tools.test.ts +284 -0
- package/server/service/figure/figure-tools.ts +320 -0
- package/server/service/figure/figure-type.ts +49 -2
- package/server/service/figure/figure.ts +15 -3
- package/server/service/figure/index.ts +4 -1
- package/server/service/index.ts +23 -2
|
@@ -6,6 +6,8 @@ const typeorm_1 = require("typeorm");
|
|
|
6
6
|
const type_graphql_1 = require("type-graphql");
|
|
7
7
|
const shell_1 = require("@things-factory/shell");
|
|
8
8
|
const figure_js_1 = require("./figure.js");
|
|
9
|
+
const figure_history_js_1 = require("./figure-history.js");
|
|
10
|
+
const figure_gate_js_1 = require("./figure-gate.js");
|
|
9
11
|
const figure_type_js_1 = require("./figure-type.js");
|
|
10
12
|
let FigureQuery = class FigureQuery {
|
|
11
13
|
async figure(id, context) {
|
|
@@ -35,6 +37,52 @@ let FigureQuery = class FigureQuery {
|
|
|
35
37
|
*
|
|
36
38
|
* `state` 로 걸러지지 않는다 — `draft` 인 Figure 의 이름도 이미 점유된 것이다.
|
|
37
39
|
*/
|
|
40
|
+
/**
|
|
41
|
+
* 발행된 판들 — 최근 것부터.
|
|
42
|
+
*
|
|
43
|
+
* 저작 중 저장은 여기 없다. 판본은 발행에서만 생기므로(`releaseFigure`), 이 목록이 곧
|
|
44
|
+
* 「이 도형이 몇 번 약속되었나」다.
|
|
45
|
+
*/
|
|
46
|
+
async figureVersions(id, context) {
|
|
47
|
+
const { domain } = context.state;
|
|
48
|
+
return await (0, shell_1.getRepository)(figure_history_js_1.FigureHistory).find({
|
|
49
|
+
where: { domain: { id: (0, typeorm_1.In)([domain.id, domain.parentId].filter(Boolean)) }, originalId: id },
|
|
50
|
+
relations: ['updater'],
|
|
51
|
+
order: { version: 'DESC' },
|
|
52
|
+
take: 10
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 지금 소비처가 쓰는 판.
|
|
57
|
+
*
|
|
58
|
+
* 도형의 현재 정본은 저작 중일 수 있다(초안). 배치된 것이 보는 것은 **마지막으로 발행된 판**이고,
|
|
59
|
+
* 그것을 이 자리가 답한다.
|
|
60
|
+
*/
|
|
61
|
+
async figureReleased(id, context) {
|
|
62
|
+
const { domain } = context.state;
|
|
63
|
+
return await (0, shell_1.getRepository)(figure_history_js_1.FigureHistory).findOne({
|
|
64
|
+
where: { domain: { id: (0, typeorm_1.In)([domain.id, domain.parentId].filter(Boolean)) }, originalId: id },
|
|
65
|
+
order: { version: 'DESC' }
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 발행해도 되나 — **누르기 전에** 묻는 자리.
|
|
70
|
+
*
|
|
71
|
+
* 판정은 `figure-gate.ts` 가 하고 이 자리는 정본을 꺼내 넘긴다. 같은 판정을 `releaseFigure` 도
|
|
72
|
+
* 부른다 — 화면이 물어 보고 통과했더라도 그 사이에 정본이 바뀌었을 수 있으므로, 막는 것은 언제나
|
|
73
|
+
* 뮤테이션이다. 이 질의는 **이유를 미리 보여 주기 위한 것**이고 허가증이 아니다.
|
|
74
|
+
*/
|
|
75
|
+
async inspectFigure(id, context) {
|
|
76
|
+
const { domain } = context.state;
|
|
77
|
+
const figure = await (0, shell_1.getRepository)(figure_js_1.Figure).findOne({
|
|
78
|
+
where: { domain: { id: (0, typeorm_1.In)([domain.id, domain.parentId].filter(Boolean)) }, id },
|
|
79
|
+
select: { id: true, source: true }
|
|
80
|
+
});
|
|
81
|
+
if (!figure) {
|
|
82
|
+
throw new Error(`Figure ${id} 를 찾을 수 없다`);
|
|
83
|
+
}
|
|
84
|
+
return (0, figure_gate_js_1.inspectSource)(figure.source);
|
|
85
|
+
}
|
|
38
86
|
async figureTypeNames(context) {
|
|
39
87
|
const { domain } = context.state;
|
|
40
88
|
const rows = await (0, shell_1.getRepository)(figure_js_1.Figure).find({
|
|
@@ -63,6 +111,33 @@ tslib_1.__decorate([
|
|
|
63
111
|
tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
|
|
64
112
|
tslib_1.__metadata("design:returntype", Promise)
|
|
65
113
|
], FigureQuery.prototype, "figures", null);
|
|
114
|
+
tslib_1.__decorate([
|
|
115
|
+
(0, type_graphql_1.Directive)('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)'),
|
|
116
|
+
(0, type_graphql_1.Query)(returns => [figure_history_js_1.FigureHistory], { description: 'Released versions of a figure, newest first.' }),
|
|
117
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
118
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
119
|
+
tslib_1.__metadata("design:type", Function),
|
|
120
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
121
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
122
|
+
], FigureQuery.prototype, "figureVersions", null);
|
|
123
|
+
tslib_1.__decorate([
|
|
124
|
+
(0, type_graphql_1.Directive)('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)'),
|
|
125
|
+
(0, type_graphql_1.Query)(returns => figure_history_js_1.FigureHistory, { nullable: true, description: 'The most recently released version of a figure.' }),
|
|
126
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
127
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
128
|
+
tslib_1.__metadata("design:type", Function),
|
|
129
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
130
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
131
|
+
], FigureQuery.prototype, "figureReleased", null);
|
|
132
|
+
tslib_1.__decorate([
|
|
133
|
+
(0, type_graphql_1.Directive)('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)'),
|
|
134
|
+
(0, type_graphql_1.Query)(returns => figure_type_js_1.FigureInspection, { description: 'Whether a figure may be released, with the reasons.' }),
|
|
135
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
136
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
137
|
+
tslib_1.__metadata("design:type", Function),
|
|
138
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
139
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
140
|
+
], FigureQuery.prototype, "inspectFigure", null);
|
|
66
141
|
tslib_1.__decorate([
|
|
67
142
|
(0, type_graphql_1.Directive)('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)'),
|
|
68
143
|
(0, type_graphql_1.Query)(returns => [String], { description: 'All figure type names in scope — used to check name collisions before create.' }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figure-query.js","sourceRoot":"","sources":["../../../server/service/figure/figure-query.ts"],"names":[],"mappings":";;;;AAAA,qCAA4B;AAC5B,+CAAyE;AAEzE,iDAAuG;AAEvG,2CAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"figure-query.js","sourceRoot":"","sources":["../../../server/service/figure/figure-query.ts"],"names":[],"mappings":";;;;AAAA,qCAA4B;A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CA8GvB","sourcesContent":["import { In } from 'typeorm'\nimport { Args, Arg, Ctx, Directive, Query, Resolver } from 'type-graphql'\n\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\n\nimport { Figure } from './figure.js'\nimport { FigureHistory } from './figure-history.js'\nimport { inspectSource } from './figure-gate.js'\nimport { FigureInspection, FigureList } from './figure-type.js'\n\n@Resolver(Figure)\nexport class FigureQuery {\n @Directive('@privilege(category: \"figure\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => Figure, { nullable: true, description: 'Finds a single figure by its ID.' })\n async figure(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Figure> {\n const { domain } = context.state\n\n // 부모 도메인의 Figure 도 보인다 — Board 와 같은 범위 규칙이다.\n return await getRepository(Figure).findOne({\n where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id }\n })\n }\n\n @Directive('@privilege(category: \"figure\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => FigureList, { description: 'Lists figures. Sortable by score, triangles, name, updatedAt.' })\n async figures(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<FigureList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n repository: getRepository(Figure),\n params,\n domain,\n alias: 'figure',\n searchables: ['type', 'name', 'description', 'category']\n })\n\n const [items, total] = await queryBuilder.getManyAndCount()\n\n return { items, total }\n }\n\n /**\n * 등록된 타입 이름 목록.\n *\n * 저작 화면이 **새 타입 이름이 이미 쓰이는지** 물어보는 데 쓴다. `type` 은 저장되는\n * 식별자라 만든 뒤에 고칠 수 없으므로, 만들기 전에 알려 줘야 한다.\n *\n * `state` 로 걸러지지 않는다 — `draft` 인 Figure 의 이름도 이미 점유된 것이다.\n */\n /**\n * 발행된 판들 — 최근 것부터.\n *\n * 저작 중 저장은 여기 없다. 판본은 발행에서만 생기므로(`releaseFigure`), 이 목록이 곧\n * 「이 도형이 몇 번 약속되었나」다.\n */\n @Directive('@privilege(category: \"figure\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => [FigureHistory], { description: 'Released versions of a figure, newest first.' })\n async figureVersions(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<FigureHistory[]> {\n const { domain } = context.state\n\n return await getRepository(FigureHistory).find({\n where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, originalId: id },\n relations: ['updater'],\n order: { version: 'DESC' },\n take: 10\n })\n }\n\n /**\n * 지금 소비처가 쓰는 판.\n *\n * 도형의 현재 정본은 저작 중일 수 있다(초안). 배치된 것이 보는 것은 **마지막으로 발행된 판**이고,\n * 그것을 이 자리가 답한다.\n */\n @Directive('@privilege(category: \"figure\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => FigureHistory, { nullable: true, description: 'The most recently released version of a figure.' })\n async figureReleased(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<FigureHistory> {\n const { domain } = context.state\n\n return await getRepository(FigureHistory).findOne({\n where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, originalId: id },\n order: { version: 'DESC' }\n })\n }\n\n /**\n * 발행해도 되나 — **누르기 전에** 묻는 자리.\n *\n * 판정은 `figure-gate.ts` 가 하고 이 자리는 정본을 꺼내 넘긴다. 같은 판정을 `releaseFigure` 도\n * 부른다 — 화면이 물어 보고 통과했더라도 그 사이에 정본이 바뀌었을 수 있으므로, 막는 것은 언제나\n * 뮤테이션이다. 이 질의는 **이유를 미리 보여 주기 위한 것**이고 허가증이 아니다.\n */\n @Directive('@privilege(category: \"figure\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => FigureInspection, { description: 'Whether a figure may be released, with the reasons.' })\n async inspectFigure(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<FigureInspection> {\n const { domain } = context.state\n\n const figure = await getRepository(Figure).findOne({\n where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id },\n select: { id: true, source: true }\n })\n\n if (!figure) {\n throw new Error(`Figure ${id} 를 찾을 수 없다`)\n }\n\n return inspectSource(figure.source)\n }\n\n @Directive('@privilege(category: \"figure\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => [String], { description: 'All figure type names in scope — used to check name collisions before create.' })\n async figureTypeNames(@Ctx() context: ResolverContext): Promise<string[]> {\n const { domain } = context.state\n\n const rows = await getRepository(Figure).find({\n where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) } },\n select: { type: true }\n })\n\n return rows.map(r => r.type).filter(Boolean)\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** 시험·검증 하네스 전용 주입 시임. 운영 경로에서 호출 금지. */
|
|
2
|
+
export declare function __setFigureToolDepsForTest(deps: any): void;
|
|
3
|
+
/**
|
|
4
|
+
* 등록 — 부팅 시 1회.
|
|
5
|
+
*
|
|
6
|
+
* 범주가 하나다. twin 은 관찰과 생성을 둘로 갈랐는데(운영 협의에 생성 도구가 들려 있으면 대화의
|
|
7
|
+
* 성격이 흐려진다), figure 의 대화면은 저작면 하나뿐이고 그 자리에서 읽기와 후보 요청이 함께 필요하다.
|
|
8
|
+
* 대화면이 늘면 그때 가른다.
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerFigureToolCategories(): void;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__setFigureToolDepsForTest = __setFigureToolDepsForTest;
|
|
4
|
+
exports.registerFigureToolCategories = registerFigureToolCategories;
|
|
5
|
+
/*
|
|
6
|
+
* figure 저작 도구를 어시스턴트 도구 레지스트리에 등록 — **대화면(도크)에서 저작을 돕기 위함.**
|
|
7
|
+
*
|
|
8
|
+
* 왜 필요한가: `proposeFigure` 는 한 번 시키고 한 번 받는다. 그것으로 되는 일이 있지만, 저작은
|
|
9
|
+
* 대개 「이걸 이렇게 고쳐 봐 → 무게가 얼마나 되나 → 발행은 되나」처럼 여러 차례 오간다. 그 대화를
|
|
10
|
+
* 하려면 어시스턴트가 **지금 무엇이 있는지 읽을 수 있어야** 한다. 읽지 못하면 매번 사람이 정본을
|
|
11
|
+
* 붙여 넣어야 하고, 그러면 대화가 아니다.
|
|
12
|
+
*
|
|
13
|
+
* 능력을 복제하지 않는다. figure-service 가 이미 가진 진입점(`inspectSource` · `proposeFigure` ·
|
|
14
|
+
* 조회)을 레지스트리에 투영한다.
|
|
15
|
+
*
|
|
16
|
+
* ── 전부 조회·제안 전용이다 ─────────────────────────────────────────────────
|
|
17
|
+
* 정본을 고치는 도구를 넣지 않는다. 형식의 설계가 그렇게 정해져 있다 — 어시스턴트는 **후보**를
|
|
18
|
+
* 내고, 받을지 버릴지는 저작자가 정한다(`figure-propose.ts`). 되돌릴 수 없는 조작이 대화면으로
|
|
19
|
+
* 새지 않으므로 전부 `kind: 'read'` 다.
|
|
20
|
+
*
|
|
21
|
+
* 저장은 저작면이 `updateFigure` 로 한다. 그 mutation 은 `figure:mutation` 이 지키고, 대화는
|
|
22
|
+
* `ai-assistant:mutation` 이 지킨다 — 서로 다른 질문이라 서로 다른 권한이 지킨다. figure 가 board
|
|
23
|
+
* 의 권한을 빌리지 않는다.
|
|
24
|
+
*
|
|
25
|
+
* ── 규율을 도구와 함께 보낸다 ───────────────────────────────────────────────
|
|
26
|
+
* 도구 목록만으로는 「언제 반드시 불러야 하는지」를 모른다. twin 이 그 공백에서 사고를 냈다 —
|
|
27
|
+
* 조치 요청에 도구를 부르지 않고 「제안해 두었습니다」라고만 답해, 사용자에게 **없는 버튼을 누르라고
|
|
28
|
+
* 안내했다.** figure 도 똑같은 자리가 있다: 후보 화면(「지금 / 후보」 두 칸)은 **도구 호출 결과에서만**
|
|
29
|
+
* 만들어진다. 문장으로는 아무 일도 일어나지 않는다.
|
|
30
|
+
*
|
|
31
|
+
* ── LLM 이 넘긴 id 를 믿지 않는다 ───────────────────────────────────────────
|
|
32
|
+
* 사람이 목록에서 고르는 길에서는 드러나지 않지만, 모델은 대화 내용에 이끌려 임의의 id 를 넘길 수
|
|
33
|
+
* 있다. 그래서 호출자 도메인 소속을 먼저 확인한다.
|
|
34
|
+
*/
|
|
35
|
+
const ai_client_base_1 = require("@things-factory/ai-client-base");
|
|
36
|
+
/*
|
|
37
|
+
서버 의존성은 lazy require 다. 등록은 부팅 초반에 평가되고 그때 typeorm DataSource 가 준비되지
|
|
38
|
+
않았을 수 있다(board-import · twin-ai 와 같은 정책).
|
|
39
|
+
*/
|
|
40
|
+
let _deps;
|
|
41
|
+
function getDeps() {
|
|
42
|
+
if (!_deps) {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
44
|
+
const shell = require('@things-factory/shell');
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
46
|
+
const model = require('@hatiolab/figure-model');
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
48
|
+
const entity = require('./figure.js');
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
50
|
+
const gate = require('./figure-gate.js');
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
52
|
+
const propose = require('./figure-propose.js');
|
|
53
|
+
_deps = {
|
|
54
|
+
getRepository: shell.getRepository,
|
|
55
|
+
Figure: entity.Figure,
|
|
56
|
+
inspectSource: gate.inspectSource,
|
|
57
|
+
proposeFigure: propose.proposeFigure,
|
|
58
|
+
compile: model.compile,
|
|
59
|
+
costOf: model.costOf,
|
|
60
|
+
scoreOf: model.scoreOf
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return _deps;
|
|
64
|
+
}
|
|
65
|
+
/** 시험·검증 하네스 전용 주입 시임. 운영 경로에서 호출 금지. */
|
|
66
|
+
function __setFigureToolDepsForTest(deps) {
|
|
67
|
+
_deps = deps;
|
|
68
|
+
}
|
|
69
|
+
function requireDomainId(state) {
|
|
70
|
+
const id = state?.domain?.id;
|
|
71
|
+
if (!id) {
|
|
72
|
+
// 도메인을 모르면 무엇을 읽어도 남의 것일 수 있다. 조용히 넘기지 않는다.
|
|
73
|
+
throw new Error('domain context is missing — the figure tools cannot resolve tenant scope');
|
|
74
|
+
}
|
|
75
|
+
return id;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 이 도형이 호출자 도메인 것인가.
|
|
79
|
+
*
|
|
80
|
+
* 모델이 넘긴 id 를 그대로 쓰지 않는다. 없으면 못 찾았다고 말한다 — 「권한이 없다」와 구별해
|
|
81
|
+
* 알려 줄 것이 없다(다른 테넌트에 그 id 가 있다는 사실 자체가 알려 줄 것이 아니다).
|
|
82
|
+
*/
|
|
83
|
+
async function figureInDomain(figureId, domainId) {
|
|
84
|
+
const { getRepository, Figure } = getDeps();
|
|
85
|
+
const found = await getRepository(Figure).findOne({
|
|
86
|
+
where: { id: figureId, domain: { id: domainId } }
|
|
87
|
+
});
|
|
88
|
+
if (!found) {
|
|
89
|
+
throw new Error(`figure not found in this tenant: ${figureId}`);
|
|
90
|
+
}
|
|
91
|
+
return found;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 무엇을 고치라는 것인지 대화면 문맥에서 해소한다.
|
|
95
|
+
*
|
|
96
|
+
* 모델이 대상을 안 줬으면 **저작면이 지금 열고 있는 도형**이다. 사용자에게 식별자를 되묻지
|
|
97
|
+
* 않는다 — 화면에 그 도형이 떠 있는데 「어느 도형입니까」를 묻는 것은 문맥을 안 읽은 것이다.
|
|
98
|
+
*/
|
|
99
|
+
function figureIdFrom(args, host) {
|
|
100
|
+
const said = typeof args?.figureId === 'string' ? args.figureId.trim() : '';
|
|
101
|
+
if (said)
|
|
102
|
+
return said;
|
|
103
|
+
const open = typeof host?.figureId === 'string' ? host.figureId.trim() : '';
|
|
104
|
+
if (open)
|
|
105
|
+
return open;
|
|
106
|
+
throw new Error('figureId is required: this surface has no figure open to resolve it from');
|
|
107
|
+
}
|
|
108
|
+
const FIGURE_ID_ARG = {
|
|
109
|
+
figureId: {
|
|
110
|
+
type: 'string',
|
|
111
|
+
description: 'The figure to read. Omit to use the one open in the editor.'
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* 도구 넷.
|
|
116
|
+
*
|
|
117
|
+
* 목록 · 정본 · 발행 판정 · 후보. 저작 대화에서 실제로 묻는 것이 그 넷이다 — 「무엇이 있나」
|
|
118
|
+
* 「지금 어떻게 생겼나」 「발행이 왜 안 되나」 「이렇게 고쳐 봐」.
|
|
119
|
+
*/
|
|
120
|
+
function figureToolSpecs() {
|
|
121
|
+
return [
|
|
122
|
+
{
|
|
123
|
+
kind: 'read',
|
|
124
|
+
name: 'listFigures',
|
|
125
|
+
description: 'Lists the figures in this tenant with their type names, states and part counts. ' +
|
|
126
|
+
'Call it before naming a type — type names are stored identifiers and must not be invented.',
|
|
127
|
+
schema: { type: 'object', properties: {} },
|
|
128
|
+
builder: async (_args, ctx) => {
|
|
129
|
+
const domainId = requireDomainId(ctx?.state);
|
|
130
|
+
const { getRepository, Figure } = getDeps();
|
|
131
|
+
const rows = await getRepository(Figure).find({
|
|
132
|
+
where: { domain: { id: domainId } },
|
|
133
|
+
order: { updatedAt: 'DESC' },
|
|
134
|
+
take: 200
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
figures: rows.map((row) => ({
|
|
138
|
+
id: row.id,
|
|
139
|
+
type: row.type,
|
|
140
|
+
name: row.name,
|
|
141
|
+
state: row.state,
|
|
142
|
+
score: row.score,
|
|
143
|
+
triangles: row.triangles
|
|
144
|
+
}))
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
kind: 'read',
|
|
150
|
+
name: 'getFigureSource',
|
|
151
|
+
description: 'Returns the canonical FigureSource of one figure, with its measured cost ' +
|
|
152
|
+
'(triangles, draw calls, how many fit on one board). Call it before proposing a revision — ' +
|
|
153
|
+
'revising without reading it means proposing against a guess.',
|
|
154
|
+
schema: { type: 'object', properties: { ...FIGURE_ID_ARG } },
|
|
155
|
+
builder: async (args, ctx) => {
|
|
156
|
+
const domainId = requireDomainId(ctx?.state);
|
|
157
|
+
const figureId = figureIdFrom(args, ctx?.state?.host);
|
|
158
|
+
const row = await figureInDomain(figureId, domainId);
|
|
159
|
+
if (!row.source) {
|
|
160
|
+
// 저장된 정본이 없는 상태가 실제로 있다(새로 만들고 저장 안 한 것). 지어내지 않는다.
|
|
161
|
+
return { id: row.id, type: row.type, name: row.name, source: null, cost: null };
|
|
162
|
+
}
|
|
163
|
+
const { compile, costOf, scoreOf } = getDeps();
|
|
164
|
+
const source = JSON.parse(row.source);
|
|
165
|
+
const blueprint = compile(source);
|
|
166
|
+
return {
|
|
167
|
+
id: row.id,
|
|
168
|
+
type: row.type,
|
|
169
|
+
name: row.name,
|
|
170
|
+
state: row.state,
|
|
171
|
+
source,
|
|
172
|
+
cost: costOf(blueprint, 100),
|
|
173
|
+
score: scoreOf(blueprint)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
kind: 'read',
|
|
179
|
+
name: 'inspectFigure',
|
|
180
|
+
description: 'Says whether a figure may be released and, when it may not, what is wrong — each finding ' +
|
|
181
|
+
'carries why it is a problem and what to change. Call it when asked about releasing, or ' +
|
|
182
|
+
'when asked to fix a figure that will not release.',
|
|
183
|
+
schema: { type: 'object', properties: { ...FIGURE_ID_ARG } },
|
|
184
|
+
builder: async (args, ctx) => {
|
|
185
|
+
const domainId = requireDomainId(ctx?.state);
|
|
186
|
+
const figureId = figureIdFrom(args, ctx?.state?.host);
|
|
187
|
+
const row = await figureInDomain(figureId, domainId);
|
|
188
|
+
const { inspectSource } = getDeps();
|
|
189
|
+
return inspectSource(row.source);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
kind: 'read',
|
|
194
|
+
name: 'proposeFigureCandidate',
|
|
195
|
+
description: 'Asks for a figure candidate from a description, optionally revising an existing one. ' +
|
|
196
|
+
'Returns the candidate with its score and cost. NOTHING IS SAVED — the author accepts or ' +
|
|
197
|
+
'discards it on screen. This is the only way a candidate reaches the screen.',
|
|
198
|
+
schema: {
|
|
199
|
+
type: 'object',
|
|
200
|
+
properties: {
|
|
201
|
+
prompt: {
|
|
202
|
+
type: 'string',
|
|
203
|
+
description: 'What to make or change, in the words the author used.'
|
|
204
|
+
},
|
|
205
|
+
figureId: {
|
|
206
|
+
type: 'string',
|
|
207
|
+
description: 'Revise this figure. Omit to revise the one open in the editor; pass null to create anew.'
|
|
208
|
+
},
|
|
209
|
+
type: {
|
|
210
|
+
type: 'string',
|
|
211
|
+
description: 'Type name for a new figure. Check listFigures first — it is a stored identifier.'
|
|
212
|
+
},
|
|
213
|
+
create: {
|
|
214
|
+
type: 'boolean',
|
|
215
|
+
description: 'True to create rather than revise, even with a figure open.'
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
required: ['prompt']
|
|
219
|
+
},
|
|
220
|
+
builder: async (args, ctx) => {
|
|
221
|
+
const domainId = requireDomainId(ctx?.state);
|
|
222
|
+
const prompt = typeof args?.prompt === 'string' ? args.prompt.trim() : '';
|
|
223
|
+
if (!prompt)
|
|
224
|
+
throw new Error('prompt is required: there is nothing to ask for');
|
|
225
|
+
/*
|
|
226
|
+
고치는 것인지 만드는 것인지를 **문맥에서 정한다.** 열린 도형이 있으면 고치는 것이 기본이고,
|
|
227
|
+
모델이 `create` 를 켜면 만드는 것이다. 이것을 모델의 짐작에 맡기면 열려 있는 도형을 덮어쓰는
|
|
228
|
+
후보가 온다.
|
|
229
|
+
*/
|
|
230
|
+
let base;
|
|
231
|
+
if (!args?.create) {
|
|
232
|
+
const open = typeof args?.figureId === 'string' ? args.figureId : ctx?.state?.host?.figureId;
|
|
233
|
+
if (typeof open === 'string' && open.trim()) {
|
|
234
|
+
const row = await figureInDomain(open.trim(), domainId);
|
|
235
|
+
if (row.source)
|
|
236
|
+
base = JSON.parse(row.source);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const palette = Array.isArray(ctx?.state?.host?.palette) ? ctx.state.host.palette : [];
|
|
240
|
+
if (palette.length === 0) {
|
|
241
|
+
/*
|
|
242
|
+
팔레트를 모르면 모델이 색을 지어내고, 그 후보는 그리는 시점에 `resolveToken` 이 던진다 —
|
|
243
|
+
저장까지 되고 나서 화면에서 죽는다. 빈 목록으로 진행하지 않는다.
|
|
244
|
+
*/
|
|
245
|
+
throw new Error('the palette is missing from the host context — the candidate would invent colours');
|
|
246
|
+
}
|
|
247
|
+
const { proposeFigure } = getDeps();
|
|
248
|
+
const result = await proposeFigure({
|
|
249
|
+
prompt,
|
|
250
|
+
palette,
|
|
251
|
+
base,
|
|
252
|
+
type: typeof args?.type === 'string' ? args.type : undefined
|
|
253
|
+
});
|
|
254
|
+
/*
|
|
255
|
+
**`proposed: true` 가 카드를 만든다.** 이 표시가 없으면 후보는 도구 추적 안에 묻히고,
|
|
256
|
+
화면에는 아무것도 생기지 않는다 — 그러면 모델이 「후보를 만들었습니다」라고 쓴 것이
|
|
257
|
+
거짓말이 된다(사용자가 없는 단추를 찾는다).
|
|
258
|
+
|
|
259
|
+
`label`·`reason` 이 카드에 그려지는 두 줄이고, `args` 는 같은 제안을 두 번 세지 않기
|
|
260
|
+
위한 열쇠의 일부다 — 같은 요청을 두 번 내면 카드가 하나로 접힌다.
|
|
261
|
+
*/
|
|
262
|
+
return {
|
|
263
|
+
proposed: true,
|
|
264
|
+
label: base ? `${result.source.type} 고치기` : `${result.source.type} 만들기`,
|
|
265
|
+
reason: `등급 ${result.score.grade} · 삼각형 ${result.cost.triangles} · ` +
|
|
266
|
+
`한 도면 ${result.cost.at.drawCalls}회 · ${result.attempts}번에 만들었다`,
|
|
267
|
+
args: { prompt, figureId: base ? figureIdFrom(args, ctx?.state?.host) : undefined },
|
|
268
|
+
source: result.source,
|
|
269
|
+
score: result.score,
|
|
270
|
+
cost: result.cost,
|
|
271
|
+
violations: result.violations,
|
|
272
|
+
attempts: result.attempts
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
];
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* 등록 — 부팅 시 1회.
|
|
280
|
+
*
|
|
281
|
+
* 범주가 하나다. twin 은 관찰과 생성을 둘로 갈랐는데(운영 협의에 생성 도구가 들려 있으면 대화의
|
|
282
|
+
* 성격이 흐려진다), figure 의 대화면은 저작면 하나뿐이고 그 자리에서 읽기와 후보 요청이 함께 필요하다.
|
|
283
|
+
* 대화면이 늘면 그때 가른다.
|
|
284
|
+
*/
|
|
285
|
+
function registerFigureToolCategories() {
|
|
286
|
+
const authoring = {
|
|
287
|
+
name: 'figure-authoring',
|
|
288
|
+
description: '저작 중인 Figure 의 정본·비용·발행 판정 조회와 후보 제안(저장 아님).',
|
|
289
|
+
guidance: [
|
|
290
|
+
'- **도형을 만들거나 고쳐 달라는 요청에는 반드시 `proposeFigureCandidate` 를 호출한다.**',
|
|
291
|
+
' 호출 없이 "후보를 만들었습니다" · "적용 버튼을 누르세요" 라고 쓰는 것은 **거짓이다** — 화면에 후보 칸이 생기지 않으므로 사용자는 존재하지 않는 버튼을 찾는다.',
|
|
292
|
+
' 후보 화면(「지금 / 후보」 두 칸)은 **도구 호출 결과에서만** 만들어진다. 문장으로는 아무 일도 일어나지 않는다.',
|
|
293
|
+
'- 정본을 직접 저장하지 않는다. 후보만 내고, 받을지 버릴지는 저작자가 화면에서 정한다.',
|
|
294
|
+
'- **고치라는 요청이면 먼저 `getFigureSource` 를 부른다.** 읽지 않고 고치면 짐작을 상대로 후보를 내게 되고, 부품 이름이 갈려 이미 배치된 보드의 바인딩이 끊긴다.',
|
|
295
|
+
'- 타입 이름을 지어내지 않는다 — `listFigures` 로 확인한다. **타입 이름은 저장되는 식별자**이고 보드가 그 이름으로 도형을 찾는다.',
|
|
296
|
+
'- 발행이 안 되는 이유를 물으면 `inspectFigure` 를 부른다. 판정 없이 "발행할 수 있습니다"라고 말하지 않는다.',
|
|
297
|
+
' 판정의 각 항목은 **왜 문제인지와 무엇을 바꾸면 되는지**를 함께 담고 있다. 그대로 전한다 — 요약하면 저작자가 어느 부품의 어느 축을 고칠지 다시 찾아야 한다.',
|
|
298
|
+
'- 무게·삼각형 수를 물으면 `getFigureSource` 의 `cost` 를 쓴다. 눈대중으로 세지 않는다.'
|
|
299
|
+
].join('\n'),
|
|
300
|
+
specs: figureToolSpecs()
|
|
301
|
+
};
|
|
302
|
+
(0, ai_client_base_1.registerToolCategory)(authoring);
|
|
303
|
+
}
|
|
304
|
+
//# sourceMappingURL=figure-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figure-tools.js","sourceRoot":"","sources":["../../../server/service/figure/figure-tools.ts"],"names":[],"mappings":";;AAgEA,gEAEC;AA0OD,oEAmBC;AA/TD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;YACN,aAAa,EAAE,KAAK,CAAC,aAAa;YAClC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,MAAM,EAAE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,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 }\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 * 무엇을 고치라는 것인지 대화면 문맥에서 해소한다.\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 if (!row.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 source = JSON.parse(row.source)\n const blueprint = compile(source)\n\n return {\n id: row.id,\n type: row.type,\n name: row.name,\n state: row.state,\n source,\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 { inspectSource } = getDeps()\n return inspectSource(row.source)\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 if (row.source) base = JSON.parse(row.source)\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 result = await proposeFigure({\n prompt,\n palette,\n base,\n type: typeof args?.type === 'string' ? args.type : undefined\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 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"]}
|
|
@@ -27,7 +27,6 @@ export declare class FigurePatch {
|
|
|
27
27
|
category?: string;
|
|
28
28
|
source?: string;
|
|
29
29
|
properties?: string;
|
|
30
|
-
state?: 'draft' | 'released';
|
|
31
30
|
thumbnail?: string;
|
|
32
31
|
}
|
|
33
32
|
export declare class FigureList {
|
|
@@ -55,3 +54,28 @@ export declare class FigureSaveResult {
|
|
|
55
54
|
figure: Figure;
|
|
56
55
|
violations: FigureFinding[];
|
|
57
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* 발행 판정 한 줄.
|
|
59
|
+
*
|
|
60
|
+
* `FigureFinding` 과 칸이 겹치지만 **`blocking` 이 하나 더 있다.** 저장 쪽 발견은 정의상 막지 않는
|
|
61
|
+
* 것들이라 그 칸이 필요 없었다. 발행 판정은 막는 것과 알리는 것을 함께 내므로, 어느 쪽인지를 값이
|
|
62
|
+
* 스스로 말해야 한다 — 코드를 보고 화면이 다시 분류하면 규칙이 두 벌이 된다.
|
|
63
|
+
*/
|
|
64
|
+
export declare class FigureGateFinding {
|
|
65
|
+
code: string;
|
|
66
|
+
message: string;
|
|
67
|
+
why?: string;
|
|
68
|
+
how?: string;
|
|
69
|
+
at?: string;
|
|
70
|
+
blocking: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 발행 판정.
|
|
74
|
+
*
|
|
75
|
+
* 화면이 **발행을 누르기 전에** 물어보는 자리다. 눌러 보고 거절당하는 것으로 알게 되면, 무엇을
|
|
76
|
+
* 고쳐야 하는지 모른 채 단추만 두드리게 된다.
|
|
77
|
+
*/
|
|
78
|
+
export declare class FigureInspection {
|
|
79
|
+
blocked: boolean;
|
|
80
|
+
findings: FigureGateFinding[];
|
|
81
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FigureSaveResult = exports.FigureFinding = exports.FigureList = exports.FigurePatch = exports.NewFigure = void 0;
|
|
3
|
+
exports.FigureInspection = exports.FigureGateFinding = exports.FigureSaveResult = exports.FigureFinding = exports.FigureList = exports.FigurePatch = exports.NewFigure = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const type_graphql_1 = require("type-graphql");
|
|
6
6
|
const figure_js_1 = require("./figure.js");
|
|
@@ -77,10 +77,6 @@ tslib_1.__decorate([
|
|
|
77
77
|
(0, type_graphql_1.Field)({ nullable: true, description: 'The new master-data field definition.' }),
|
|
78
78
|
tslib_1.__metadata("design:type", String)
|
|
79
79
|
], FigurePatch.prototype, "properties", void 0);
|
|
80
|
-
tslib_1.__decorate([
|
|
81
|
-
(0, type_graphql_1.Field)({ nullable: true, description: 'The new lifecycle state.' }),
|
|
82
|
-
tslib_1.__metadata("design:type", String)
|
|
83
|
-
], FigurePatch.prototype, "state", void 0);
|
|
84
80
|
tslib_1.__decorate([
|
|
85
81
|
(0, type_graphql_1.Field)({ nullable: true, description: 'A base64 encoded thumbnail image.' }),
|
|
86
82
|
tslib_1.__metadata("design:type", String)
|
|
@@ -146,4 +142,61 @@ tslib_1.__decorate([
|
|
|
146
142
|
exports.FigureSaveResult = FigureSaveResult = tslib_1.__decorate([
|
|
147
143
|
(0, type_graphql_1.ObjectType)({ description: 'Result of saving a figure, carrying non-blocking violations.' })
|
|
148
144
|
], FigureSaveResult);
|
|
145
|
+
/**
|
|
146
|
+
* 발행 판정 한 줄.
|
|
147
|
+
*
|
|
148
|
+
* `FigureFinding` 과 칸이 겹치지만 **`blocking` 이 하나 더 있다.** 저장 쪽 발견은 정의상 막지 않는
|
|
149
|
+
* 것들이라 그 칸이 필요 없었다. 발행 판정은 막는 것과 알리는 것을 함께 내므로, 어느 쪽인지를 값이
|
|
150
|
+
* 스스로 말해야 한다 — 코드를 보고 화면이 다시 분류하면 규칙이 두 벌이 된다.
|
|
151
|
+
*/
|
|
152
|
+
let FigureGateFinding = class FigureGateFinding {
|
|
153
|
+
};
|
|
154
|
+
exports.FigureGateFinding = FigureGateFinding;
|
|
155
|
+
tslib_1.__decorate([
|
|
156
|
+
(0, type_graphql_1.Field)({ description: 'Stable code — figure-model validation codes, or sizing-splits / sizing-loose.' }),
|
|
157
|
+
tslib_1.__metadata("design:type", String)
|
|
158
|
+
], FigureGateFinding.prototype, "code", void 0);
|
|
159
|
+
tslib_1.__decorate([
|
|
160
|
+
(0, type_graphql_1.Field)({ description: 'Human-readable message.' }),
|
|
161
|
+
tslib_1.__metadata("design:type", String)
|
|
162
|
+
], FigureGateFinding.prototype, "message", void 0);
|
|
163
|
+
tslib_1.__decorate([
|
|
164
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Why this is a problem — what a person sees when it happens.' }),
|
|
165
|
+
tslib_1.__metadata("design:type", String)
|
|
166
|
+
], FigureGateFinding.prototype, "why", void 0);
|
|
167
|
+
tslib_1.__decorate([
|
|
168
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'What to change, naming the part and the value.' }),
|
|
169
|
+
tslib_1.__metadata("design:type", String)
|
|
170
|
+
], FigureGateFinding.prototype, "how", void 0);
|
|
171
|
+
tslib_1.__decorate([
|
|
172
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Where it points: part names that came apart, or a path in the source.' }),
|
|
173
|
+
tslib_1.__metadata("design:type", String)
|
|
174
|
+
], FigureGateFinding.prototype, "at", void 0);
|
|
175
|
+
tslib_1.__decorate([
|
|
176
|
+
(0, type_graphql_1.Field)({ description: 'True when this finding blocks the release.' }),
|
|
177
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
178
|
+
], FigureGateFinding.prototype, "blocking", void 0);
|
|
179
|
+
exports.FigureGateFinding = FigureGateFinding = tslib_1.__decorate([
|
|
180
|
+
(0, type_graphql_1.ObjectType)({ description: 'One finding from the release gate.' })
|
|
181
|
+
], FigureGateFinding);
|
|
182
|
+
/**
|
|
183
|
+
* 발행 판정.
|
|
184
|
+
*
|
|
185
|
+
* 화면이 **발행을 누르기 전에** 물어보는 자리다. 눌러 보고 거절당하는 것으로 알게 되면, 무엇을
|
|
186
|
+
* 고쳐야 하는지 모른 채 단추만 두드리게 된다.
|
|
187
|
+
*/
|
|
188
|
+
let FigureInspection = class FigureInspection {
|
|
189
|
+
};
|
|
190
|
+
exports.FigureInspection = FigureInspection;
|
|
191
|
+
tslib_1.__decorate([
|
|
192
|
+
(0, type_graphql_1.Field)({ description: 'True when at least one finding blocks the release.' }),
|
|
193
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
194
|
+
], FigureInspection.prototype, "blocked", void 0);
|
|
195
|
+
tslib_1.__decorate([
|
|
196
|
+
(0, type_graphql_1.Field)(type => [FigureGateFinding], { description: 'Findings, blocking and advisory together.' }),
|
|
197
|
+
tslib_1.__metadata("design:type", Array)
|
|
198
|
+
], FigureInspection.prototype, "findings", void 0);
|
|
199
|
+
exports.FigureInspection = FigureInspection = tslib_1.__decorate([
|
|
200
|
+
(0, type_graphql_1.ObjectType)({ description: 'Whether a figure may be released, and why not.' })
|
|
201
|
+
], FigureInspection);
|
|
149
202
|
//# sourceMappingURL=figure-type.js.map
|