@things-factory/figure-service 10.1.281 → 10.1.283
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/routers/figure-thumbnail-router.d.ts +3 -1
- package/dist-server/routers/figure-thumbnail-router.js +15 -2
- package/dist-server/service/figure/figure-mcp-agent.d.ts +63 -0
- package/dist-server/service/figure/figure-mcp-agent.js +221 -0
- package/dist-server/service/figure/figure-public.d.ts +5 -0
- package/dist-server/service/figure/figure-public.js +9 -0
- package/dist-server/service/figure/figure-query.d.ts +6 -0
- package/dist-server/service/figure/figure-query.js +18 -1
- package/dist-server/service/figure/figure-read.d.ts +13 -0
- package/dist-server/service/figure/figure-read.js +105 -0
- package/dist-server/service/figure/figure-release-catalog.d.ts +36 -0
- package/dist-server/service/figure/figure-release-catalog.js +149 -0
- package/dist-server/service/figure/figure-tools.js +72 -18
- package/dist-server/service/index.d.ts +3 -1
- package/dist-server/service/index.js +3 -1
- package/dist-server/service/install-key/figure-install-key.d.ts +37 -0
- package/dist-server/service/install-key/figure-install-key.js +164 -0
- package/mcp/figure-mcp-server.mjs +259 -0
- package/package.json +9 -8
- package/translations/en.json +15 -1
- package/translations/es.json +15 -1
- package/translations/ja.json +15 -1
- package/translations/ko.json +15 -1
- package/translations/ms.json +15 -1
- package/translations/zh.json +15 -1
|
@@ -30,4 +30,6 @@ export declare const figureThumbnailRouter: any;
|
|
|
30
30
|
export declare function sendFigureThumbnail(context: any, next: () => Promise<any>, id: string, domain: {
|
|
31
31
|
id: string;
|
|
32
32
|
parentId?: string;
|
|
33
|
-
}, files?: ThumbnailFiles
|
|
33
|
+
}, files?: ThumbnailFiles, { released }?: {
|
|
34
|
+
released?: boolean;
|
|
35
|
+
}): Promise<void>;
|
|
@@ -55,6 +55,19 @@ exports.figureThumbnailRouter.get('/figure-thumbnail/:id', async (context, next)
|
|
|
55
55
|
}
|
|
56
56
|
await sendFigureThumbnail(context, next, context.params.id, domain);
|
|
57
57
|
});
|
|
58
|
+
/**
|
|
59
|
+
* The picture of a figure's latest release, for a server choosing what to install (ADR-0114 decision 25): behind the
|
|
60
|
+
* same door as `/figure-package` and `figureReleaseCatalog` (`figure-published`), never the draft's picture.
|
|
61
|
+
*/
|
|
62
|
+
exports.figureThumbnailRouter.get('/figure-release-thumbnail/:id', async (context, next) => {
|
|
63
|
+
const { domain, user, unsafeIP, prohibitedPrivileges } = context.state;
|
|
64
|
+
const allowed = await (0, auth_base_1.checkPermission)({ category: 'figure-published', privilege: 'query', owner: true }, user, domain, unsafeIP, prohibitedPrivileges);
|
|
65
|
+
if (!allowed) {
|
|
66
|
+
context.status = 403;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
await sendFigureThumbnail(context, next, context.params.id, domain, undefined, { released: true });
|
|
70
|
+
});
|
|
58
71
|
/** A public figure's picture as its latest release keeps it, on the figure's domain. */
|
|
59
72
|
async function releasedPictureOf(row) {
|
|
60
73
|
const release = await (0, shell_1.getRepository)(figure_history_js_1.FigureHistory).findOne({
|
|
@@ -68,7 +81,7 @@ async function releasedPictureOf(row) {
|
|
|
68
81
|
* The picture of a figure the caller may read, by its hash (ADR-0104 decision 6). Exported for tests, which give
|
|
69
82
|
* their own `files`.
|
|
70
83
|
*/
|
|
71
|
-
async function sendFigureThumbnail(context, next, id, domain, files = (0, figure_thumbnail_store_js_1.thumbnailFiles)()) {
|
|
84
|
+
async function sendFigureThumbnail(context, next, id, domain, files = (0, figure_thumbnail_store_js_1.thumbnailFiles)(), { released = false } = {}) {
|
|
72
85
|
/*
|
|
73
86
|
읽기는 부모 도메인까지 본다 — `figure` 질의와 같은 범위다. 물려받은 형상을 목록에는 보여 주고
|
|
74
87
|
그림만 404 를 내면, 화면은 「그림이 아직 없다」고 거짓말하게 된다.
|
|
@@ -79,7 +92,7 @@ async function sendFigureThumbnail(context, next, id, domain, files = (0, figure
|
|
|
79
92
|
Another domain is shown the picture of the latest release, as its list is (2026-11-03 audit 1): the row's picture
|
|
80
93
|
may be of a draft not released.
|
|
81
94
|
*/
|
|
82
|
-
const found = row && (0, figure_public_js_1.foreignPublic)(domain, row) ? await releasedPictureOf(row) : row;
|
|
95
|
+
const found = row && (released || (0, figure_public_js_1.foreignPublic)(domain, row)) ? await releasedPictureOf(row) : row;
|
|
83
96
|
if (!found?.thumbnailHash) {
|
|
84
97
|
context.status = 404;
|
|
85
98
|
return;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { FigureAsset, FigureProposalFinding } from '@hatiolab/figure-model';
|
|
2
|
+
import { type ToolAccessCheck } from '@things-factory/ai-client-base';
|
|
3
|
+
import type { ProposeFigureResult } from './figure-propose-steps.js';
|
|
4
|
+
/**
|
|
5
|
+
* On by FIGURE_BUILD=mcp-agent, or figure/build in the server's config -- a development server's own choice -- and only
|
|
6
|
+
* where Claude Code may answer at all: NODE_ENV development with the CLI logged in (claudeCodeAvailable). A production
|
|
7
|
+
* server never runs it, whatever its config says.
|
|
8
|
+
*/
|
|
9
|
+
export declare const figureMcpAgentOn: () => boolean;
|
|
10
|
+
export declare function figureAgentEnv(from?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
11
|
+
/**
|
|
12
|
+
* The tools that reach the application, each with the GraphQL door it goes through (2026-11-14, the person: pass the
|
|
13
|
+
* user's token and give the agent the tools by the user's privileges). The kernel tools touch only the agent's folder;
|
|
14
|
+
* these read what the person's domain holds, as the person. Read only: the agent hands over a card, and the person
|
|
15
|
+
* saves it.
|
|
16
|
+
*/
|
|
17
|
+
export declare const FIGURE_APP_TOOL_DOORS: {
|
|
18
|
+
readonly find_figures: "Query.figures";
|
|
19
|
+
readonly open_figure: "Query.figure";
|
|
20
|
+
};
|
|
21
|
+
export type FigureAppTool = keyof typeof FIGURE_APP_TOOL_DOORS;
|
|
22
|
+
/** The figure tools by their short names, as the agent's events name them (mcp__figure__<name>). */
|
|
23
|
+
export type FigureMcpTool = 'get_guide' | 'apply_steps' | 'read_figure' | 'try_pose' | 'render' | 'start_over' | 'finish' | FigureAppTool;
|
|
24
|
+
/**
|
|
25
|
+
* The application tools this caller may be given: those whose door they pass. The check is the conversation's own tool
|
|
26
|
+
* gate (the tool's `access`), the one that chose this turn's tools -- never a copy of it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function figureAppToolsFor(passes: ToolAccessCheck): Promise<FigureAppTool[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Who asked, for the tools that reach the application: a token of that user's, short-lived, and the tools their
|
|
31
|
+
* privileges open. The MCP server calls the application's GraphQL with it, so every call is checked again at the door,
|
|
32
|
+
* as the person's own call would be: the list only keeps the agent from trying what it would be refused.
|
|
33
|
+
*/
|
|
34
|
+
export interface McpAgentCaller {
|
|
35
|
+
/** The application's GraphQL endpoint as this server reaches itself. */
|
|
36
|
+
url: string;
|
|
37
|
+
token: string;
|
|
38
|
+
/** The caller's domain (its subdomain), sent as x-things-factory-domain. */
|
|
39
|
+
domain: string;
|
|
40
|
+
tools: FigureAppTool[];
|
|
41
|
+
}
|
|
42
|
+
export interface McpAgentInput {
|
|
43
|
+
prompt: string;
|
|
44
|
+
/** The open figure the request changes; absent, a new figure. */
|
|
45
|
+
base?: FigureAsset;
|
|
46
|
+
name?: string;
|
|
47
|
+
/** A Claude Code model alias or name. */
|
|
48
|
+
model?: string;
|
|
49
|
+
/** Milliseconds after which the agent is stopped with what it has. */
|
|
50
|
+
budgetMs?: number;
|
|
51
|
+
/** Each tool call as the agent makes it, with how many of that tool so far. */
|
|
52
|
+
onTool?: (tool: FigureMcpTool, count: number) => void;
|
|
53
|
+
/** The person who asked; absent, the agent has the kernel tools only. */
|
|
54
|
+
caller?: McpAgentCaller;
|
|
55
|
+
}
|
|
56
|
+
export interface McpAgentResult extends ProposeFigureResult {
|
|
57
|
+
/** What is still off by measure, against the figure the request started from. */
|
|
58
|
+
findings?: FigureProposalFinding[];
|
|
59
|
+
finished: boolean;
|
|
60
|
+
summary?: string;
|
|
61
|
+
calls: number;
|
|
62
|
+
}
|
|
63
|
+
export declare function buildByMcpAgent(input: McpAgentInput): Promise<McpAgentResult>;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FIGURE_APP_TOOL_DOORS = exports.figureMcpAgentOn = void 0;
|
|
4
|
+
exports.figureAgentEnv = figureAgentEnv;
|
|
5
|
+
exports.figureAppToolsFor = figureAppToolsFor;
|
|
6
|
+
exports.buildByMcpAgent = buildByMcpAgent;
|
|
7
|
+
/**
|
|
8
|
+
* A figure built by an agent with the figure MCP tools (development, 2026-11-14, the person: put MCP on the dock).
|
|
9
|
+
*
|
|
10
|
+
* The way that made good figures when an outside agent was handed the kernel (2026-11-13: six of six, against three of
|
|
11
|
+
* six for the planned path): the whole figure written as commands, read back, measured, looked at, fixed until right.
|
|
12
|
+
* Here the agent is Claude Code run headless on this server (`claude -p`), with no tool but the figure MCP server
|
|
13
|
+
* (mcp/figure-mcp-server.mjs) -- no files, no shell, no source: what it knows of the modeller is the guide and what the
|
|
14
|
+
* tools answer. Development only, as the claude-code provider is: it needs the `claude` CLI logged in here.
|
|
15
|
+
*
|
|
16
|
+
* Behind FIGURE_BUILD=mcp-agent, and only where the claude-code provider is offered: a development server whose machine
|
|
17
|
+
* has the CLI logged in. Anywhere else the dock builds as before.
|
|
18
|
+
*/
|
|
19
|
+
const fs_1 = require("fs");
|
|
20
|
+
const os_1 = require("os");
|
|
21
|
+
const path_1 = require("path");
|
|
22
|
+
const readline_1 = require("readline");
|
|
23
|
+
const figure_model_1 = require("@hatiolab/figure-model");
|
|
24
|
+
const ai_client_base_1 = require("@things-factory/ai-client-base");
|
|
25
|
+
const env_1 = require("@things-factory/env");
|
|
26
|
+
/**
|
|
27
|
+
* On by FIGURE_BUILD=mcp-agent, or figure/build in the server's config -- a development server's own choice -- and only
|
|
28
|
+
* where Claude Code may answer at all: NODE_ENV development with the CLI logged in (claudeCodeAvailable). A production
|
|
29
|
+
* server never runs it, whatever its config says.
|
|
30
|
+
*/
|
|
31
|
+
const figureMcpAgentOn = () => (process.env.FIGURE_BUILD || env_1.config.get('figure/build', '')) === 'mcp-agent' && (0, ai_client_base_1.claudeCodeAvailable)();
|
|
32
|
+
exports.figureMcpAgentOn = figureMcpAgentOn;
|
|
33
|
+
/** How many turns and how many dollars (at API prices) one build may take: a request answered in 9-27 turns and $0.64-1.68 (2026-11-14). */
|
|
34
|
+
const MAX_TURNS = () => Number(process.env.FIGURE_MCP_MAX_TURNS) || 60;
|
|
35
|
+
const MAX_USD = () => Number(process.env.FIGURE_MCP_MAX_USD) || 5;
|
|
36
|
+
/**
|
|
37
|
+
* What the CLI and the figure MCP server it starts may read of this server's environment: what a logged-in CLI needs
|
|
38
|
+
* to run, and nothing of the application's -- no database password, no key. The application is reached only by the
|
|
39
|
+
* caller's token, handed to the MCP server in its own config.
|
|
40
|
+
*/
|
|
41
|
+
const PASSED_ENV = /^(PATH|HOME|USER|LOGNAME|SHELL|TMPDIR|TMP|TEMP|LANG|LC_[A-Z]+|TERM|XDG_[A-Z_]+|NODE_EXTRA_CA_CERTS|CLAUDE_CONFIG_DIR|AI_CLAUDE_CODE_BIN|HTTPS?_PROXY|NO_PROXY|https?_proxy|no_proxy|PLAYWRIGHT_BROWSERS_PATH)$/;
|
|
42
|
+
function figureAgentEnv(from = process.env) {
|
|
43
|
+
return Object.fromEntries(Object.entries(from).filter(([key]) => PASSED_ENV.test(key)));
|
|
44
|
+
}
|
|
45
|
+
/** A development checkout of figure-ui, for pictures. */
|
|
46
|
+
const figureUiDir = () => process.env.FIGURE_UI_DIR || env_1.config.get('figure/uiDir', '') || undefined;
|
|
47
|
+
/** What the agent is told: how to work. What the modeller is and how a thing is said in it comes from get_guide. */
|
|
48
|
+
const MCP_AGENT_SYSTEM = [
|
|
49
|
+
'You build 3D figures in the Operato Figure modeller with the figure tools. What the thing is, what it looks like and how it moves is your own knowledge; how it is said in this modeller is in get_guide.',
|
|
50
|
+
'',
|
|
51
|
+
'HOW TO WORK',
|
|
52
|
+
'- First call get_guide and read it.',
|
|
53
|
+
'- Decide the design: the parts, their sizes in mm, how they hang together and how they move.',
|
|
54
|
+
'- Write the figure as commands and apply_steps. Read what it answers: a refusal says which step and why; findings marked WRONG must be fixed.',
|
|
55
|
+
'- render the figure and look at it as the person who asked would, at rest and with each control moved. Check joints with try_pose.',
|
|
56
|
+
'- Fix what is off with more steps, or start_over when the design itself is wrong. Repeat until it is a convincing, recognisable version of the request with the motion asked for (controls, and a clip that shows the motion).',
|
|
57
|
+
'- When the request changes an existing figure, change only what it asks; the figure is there already (read_figure).',
|
|
58
|
+
'- Then call finish with one or two sentences for the person, in the language of the request. The work is handed over only by finish: end every build with it, never with words alone.',
|
|
59
|
+
'You have no other tools; do not ask the person anything.'
|
|
60
|
+
].join('\n');
|
|
61
|
+
/**
|
|
62
|
+
* The tools that reach the application, each with the GraphQL door it goes through (2026-11-14, the person: pass the
|
|
63
|
+
* user's token and give the agent the tools by the user's privileges). The kernel tools touch only the agent's folder;
|
|
64
|
+
* these read what the person's domain holds, as the person. Read only: the agent hands over a card, and the person
|
|
65
|
+
* saves it.
|
|
66
|
+
*/
|
|
67
|
+
exports.FIGURE_APP_TOOL_DOORS = {
|
|
68
|
+
find_figures: 'Query.figures',
|
|
69
|
+
open_figure: 'Query.figure'
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The application tools this caller may be given: those whose door they pass. The check is the conversation's own tool
|
|
73
|
+
* gate (the tool's `access`), the one that chose this turn's tools -- never a copy of it.
|
|
74
|
+
*/
|
|
75
|
+
async function figureAppToolsFor(passes) {
|
|
76
|
+
const tools = [];
|
|
77
|
+
for (const [tool, door] of Object.entries(exports.FIGURE_APP_TOOL_DOORS))
|
|
78
|
+
if (await passes(door))
|
|
79
|
+
tools.push(tool);
|
|
80
|
+
return tools;
|
|
81
|
+
}
|
|
82
|
+
const SERVER = (0, path_1.resolve)(__dirname, '..', '..', '..', 'mcp', 'figure-mcp-server.mjs');
|
|
83
|
+
async function buildByMcpAgent(input) {
|
|
84
|
+
const work = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'figure-mcp-'));
|
|
85
|
+
const started = Date.now();
|
|
86
|
+
try {
|
|
87
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(work, 'meta.json'), JSON.stringify({ name: input.name ?? '' }));
|
|
88
|
+
if (input.base)
|
|
89
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(work, 'base.json'), (0, figure_model_1.serializeFigureAsset)(input.base));
|
|
90
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(work, 'system.txt'), MCP_AGENT_SYSTEM);
|
|
91
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(work, 'mcp.json'), JSON.stringify({
|
|
92
|
+
mcpServers: {
|
|
93
|
+
figure: {
|
|
94
|
+
type: 'stdio',
|
|
95
|
+
command: process.execPath,
|
|
96
|
+
args: [process.env.FIGURE_MCP_SERVER || SERVER],
|
|
97
|
+
env: {
|
|
98
|
+
FIGURE_WORK_DIR: work,
|
|
99
|
+
...(figureUiDir() ? { FIGURE_UI_DIR: figureUiDir() } : {}),
|
|
100
|
+
...(input.caller?.tools.length
|
|
101
|
+
? {
|
|
102
|
+
FIGURE_API_URL: input.caller.url,
|
|
103
|
+
FIGURE_API_TOKEN: input.caller.token,
|
|
104
|
+
FIGURE_API_DOMAIN: input.caller.domain,
|
|
105
|
+
FIGURE_APP_TOOLS: input.caller.tools.join(',')
|
|
106
|
+
}
|
|
107
|
+
: {})
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
const args = [
|
|
113
|
+
'-p',
|
|
114
|
+
'--output-format',
|
|
115
|
+
'stream-json',
|
|
116
|
+
'--verbose',
|
|
117
|
+
'--tools',
|
|
118
|
+
'',
|
|
119
|
+
'--strict-mcp-config',
|
|
120
|
+
'--mcp-config',
|
|
121
|
+
(0, path_1.join)(work, 'mcp.json'),
|
|
122
|
+
'--allowedTools',
|
|
123
|
+
'mcp__figure',
|
|
124
|
+
'--setting-sources',
|
|
125
|
+
'',
|
|
126
|
+
'--no-session-persistence',
|
|
127
|
+
'--system-prompt-file',
|
|
128
|
+
(0, path_1.join)(work, 'system.txt'),
|
|
129
|
+
'--model',
|
|
130
|
+
input.model || process.env.FIGURE_MCP_MODEL || 'opus',
|
|
131
|
+
'--max-turns',
|
|
132
|
+
String(MAX_TURNS()),
|
|
133
|
+
'--max-budget-usd',
|
|
134
|
+
String(MAX_USD())
|
|
135
|
+
];
|
|
136
|
+
const counts = new Map();
|
|
137
|
+
const appCalls = new Map();
|
|
138
|
+
let calls = 0;
|
|
139
|
+
let summary;
|
|
140
|
+
/* What the CLI said went wrong: kept for when nothing was made, which is how a failed start shows. */
|
|
141
|
+
let err = '';
|
|
142
|
+
await new Promise((done, fail) => {
|
|
143
|
+
const child = (0, ai_client_base_1.startClaudeCode)(args, work, figureAgentEnv());
|
|
144
|
+
const timer = setTimeout(() => child.kill('SIGTERM'), input.budgetMs ?? 1_200_000);
|
|
145
|
+
child.stderr.on('data', d => (err += d));
|
|
146
|
+
(0, readline_1.createInterface)({ input: child.stdout }).on('line', line => {
|
|
147
|
+
let event;
|
|
148
|
+
try {
|
|
149
|
+
event = JSON.parse(line);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
/* What the application answered the agent, as the person: a refusal at the door shows here. */
|
|
155
|
+
if (event?.type === 'user')
|
|
156
|
+
for (const part of event.message?.content ?? []) {
|
|
157
|
+
const tool = part?.type === 'tool_result' ? appCalls.get(part.tool_use_id) : undefined;
|
|
158
|
+
if (!tool)
|
|
159
|
+
continue;
|
|
160
|
+
const text = (Array.isArray(part.content) ? part.content.map((c) => c?.text ?? '').join(' ') : String(part.content ?? '')).replace(/\s+/g, ' ');
|
|
161
|
+
env_1.logger.info(`figure mcp agent: ${tool}${part.is_error ? ' refused' : ''}: ${text.slice(0, 300)}`);
|
|
162
|
+
}
|
|
163
|
+
if (event?.type === 'assistant')
|
|
164
|
+
for (const part of event.message?.content ?? []) {
|
|
165
|
+
if (part?.type !== 'tool_use' || typeof part.name !== 'string' || !part.name.startsWith('mcp__figure__'))
|
|
166
|
+
continue;
|
|
167
|
+
const tool = part.name.slice('mcp__figure__'.length);
|
|
168
|
+
if (tool in exports.FIGURE_APP_TOOL_DOORS)
|
|
169
|
+
appCalls.set(part.id, tool);
|
|
170
|
+
const n = (counts.get(tool) ?? 0) + 1;
|
|
171
|
+
counts.set(tool, n);
|
|
172
|
+
calls++;
|
|
173
|
+
if (tool === 'finish' && typeof part.input?.summary === 'string')
|
|
174
|
+
summary = part.input.summary;
|
|
175
|
+
input.onTool?.(tool, n);
|
|
176
|
+
}
|
|
177
|
+
if (event?.type === 'result' && event.is_error)
|
|
178
|
+
err += `\n${String(event.result ?? '')}`;
|
|
179
|
+
});
|
|
180
|
+
child.on('error', fail);
|
|
181
|
+
child.on('close', code => {
|
|
182
|
+
clearTimeout(timer);
|
|
183
|
+
env_1.logger.info(`figure mcp agent: ${calls} calls (${[...counts].map(([k, v]) => `${k} ${v}`).join(', ')}) in ${Math.round((Date.now() - started) / 1000)} s, exit ${code}`);
|
|
184
|
+
if (code && !(0, fs_1.existsSync)((0, path_1.join)(work, 'current.json')))
|
|
185
|
+
fail(new Error(`The agent stopped: ${err.slice(-500)}`));
|
|
186
|
+
else
|
|
187
|
+
done();
|
|
188
|
+
});
|
|
189
|
+
child.stdin.end(input.prompt);
|
|
190
|
+
});
|
|
191
|
+
const read = (name) => ((0, fs_1.existsSync)((0, path_1.join)(work, name)) ? (0, fs_1.readFileSync)((0, path_1.join)(work, name), 'utf-8') : undefined);
|
|
192
|
+
const steps = JSON.parse(read('steps.json') ?? '[]');
|
|
193
|
+
const text = read('current.json');
|
|
194
|
+
const made = steps.some(s => s.kind !== 'set-detail-level');
|
|
195
|
+
if (!text || !made) {
|
|
196
|
+
if (err.trim())
|
|
197
|
+
env_1.logger.warn(`figure mcp agent: made nothing; the agent said: ${err.trim().slice(-500)}`);
|
|
198
|
+
throw Object.assign(new Error('The figure could not be made.'), { reasons: ['The agent made nothing.'] });
|
|
199
|
+
}
|
|
200
|
+
const source = (0, figure_model_1.parseFigureAsset)(text);
|
|
201
|
+
const finished = (0, fs_1.existsSync)((0, path_1.join)(work, 'finished.json'));
|
|
202
|
+
if (!summary && finished)
|
|
203
|
+
summary = JSON.parse(read('finished.json')).summary;
|
|
204
|
+
const findings = (0, figure_model_1.figureProposalFindings)(input.base, source);
|
|
205
|
+
return {
|
|
206
|
+
steps,
|
|
207
|
+
source,
|
|
208
|
+
score: (0, figure_model_1.figureScoreOf)(source),
|
|
209
|
+
cost: (0, figure_model_1.figureCostOf)(source),
|
|
210
|
+
attempts: counts.get('apply_steps') ?? 0,
|
|
211
|
+
...(findings.length ? { findings } : {}),
|
|
212
|
+
finished,
|
|
213
|
+
...(summary ? { summary } : {}),
|
|
214
|
+
calls
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
finally {
|
|
218
|
+
(0, fs_1.rmSync)(work, { recursive: true, force: true });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=figure-mcp-agent.js.map
|
|
@@ -3,6 +3,11 @@ type Reader = {
|
|
|
3
3
|
id: string;
|
|
4
4
|
parentId?: string | null;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* The join of a figure row to its releases: `{row}.id` (uuid) against `{originalId}` (text). Postgres compares the two
|
|
8
|
+
* only with a cast ("operator does not exist: uuid = character varying"); sqlite stores both as text and needs none.
|
|
9
|
+
*/
|
|
10
|
+
export declare function figureRowOfRelease(row: string, originalId: string): string;
|
|
6
11
|
/** The domains a reader reads as its own: itself and its parent. */
|
|
7
12
|
export declare const ownScope: (domain: Reader) => import("typeorm").FindOperator<any>;
|
|
8
13
|
/** A figure the reader may read the releases of: its own or its parent's, or any domain's public one. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ownScope = void 0;
|
|
4
|
+
exports.figureRowOfRelease = figureRowOfRelease;
|
|
4
5
|
exports.readableFigure = readableFigure;
|
|
5
6
|
exports.foreignPublic = foreignPublic;
|
|
6
7
|
exports.publicFigureOfName = publicFigureOfName;
|
|
@@ -9,6 +10,14 @@ const typeorm_1 = require("typeorm");
|
|
|
9
10
|
const shell_1 = require("@things-factory/shell");
|
|
10
11
|
const figure_js_1 = require("./figure.js");
|
|
11
12
|
const figure_history_js_1 = require("./figure-history.js");
|
|
13
|
+
/**
|
|
14
|
+
* The join of a figure row to its releases: `{row}.id` (uuid) against `{originalId}` (text). Postgres compares the two
|
|
15
|
+
* only with a cast ("operator does not exist: uuid = character varying"); sqlite stores both as text and needs none.
|
|
16
|
+
*/
|
|
17
|
+
function figureRowOfRelease(row, originalId) {
|
|
18
|
+
const type = (0, shell_1.getRepository)(figure_js_1.Figure).manager.connection.options.type;
|
|
19
|
+
return type === 'postgres' ? `CAST(${row}.id AS text) = ${originalId}` : `${row}.id = ${originalId}`;
|
|
20
|
+
}
|
|
12
21
|
/** The domains a reader reads as its own: itself and its parent. */
|
|
13
22
|
const ownScope = (domain) => (0, typeorm_1.In)([domain.id, domain.parentId].filter(Boolean));
|
|
14
23
|
exports.ownScope = ownScope;
|
|
@@ -3,6 +3,7 @@ import { Figure } from './figure.js';
|
|
|
3
3
|
import { FigureHistory } from './figure-history.js';
|
|
4
4
|
import { FigureInspection, FigureList, FigureProposalOutcome } from './figure-type.js';
|
|
5
5
|
import { FigureReplacedDraft } from './figure-replaced-draft.js';
|
|
6
|
+
import { FigureReleaseCatalog } from './figure-release-catalog.js';
|
|
6
7
|
export declare class FigureQuery {
|
|
7
8
|
figure(id: string, context: ResolverContext): Promise<Figure>;
|
|
8
9
|
figures(params: ListParam, context: ResolverContext): Promise<FigureList>;
|
|
@@ -18,6 +19,11 @@ export declare class FigureQuery {
|
|
|
18
19
|
* figure as a whole is shown: that it is public and whether it is retired. Tags are not recorded with a release, so a
|
|
19
20
|
* public figure shows none.
|
|
20
21
|
*/
|
|
22
|
+
/**
|
|
23
|
+
* The releases another server may install (ADR-0114 decision 24): each readable figure as its latest release. Behind
|
|
24
|
+
* the same door as `/figure-package` (`figure-published`), so a board server's token needs no right to read drafts.
|
|
25
|
+
*/
|
|
26
|
+
figureReleaseCatalog(params: ListParam, context: ResolverContext): Promise<FigureReleaseCatalog>;
|
|
21
27
|
publicFigures(params: ListParam, context: ResolverContext): Promise<FigureList>;
|
|
22
28
|
/**
|
|
23
29
|
* 등록된 타입 이름 목록.
|
|
@@ -17,6 +17,7 @@ const figure_proposal_js_1 = require("./figure-proposal.js");
|
|
|
17
17
|
const figure_mesh_store_js_1 = require("./figure-mesh-store.js");
|
|
18
18
|
const figure_public_js_1 = require("./figure-public.js");
|
|
19
19
|
const figure_categories_js_1 = require("./figure-categories.js");
|
|
20
|
+
const figure_release_catalog_js_1 = require("./figure-release-catalog.js");
|
|
20
21
|
/** What a figure list finds figures by - tags too, see `figures` - and its state counts alike. */
|
|
21
22
|
const FIGURE_SEARCHABLES = ['type', 'name', 'description', 'category', 'tags'];
|
|
22
23
|
/** A release records no tags (`FigureHistory`). */
|
|
@@ -70,6 +71,13 @@ let FigureQuery = class FigureQuery {
|
|
|
70
71
|
* figure as a whole is shown: that it is public and whether it is retired. Tags are not recorded with a release, so a
|
|
71
72
|
* public figure shows none.
|
|
72
73
|
*/
|
|
74
|
+
/**
|
|
75
|
+
* The releases another server may install (ADR-0114 decision 24): each readable figure as its latest release. Behind
|
|
76
|
+
* the same door as `/figure-package` (`figure-published`), so a board server's token needs no right to read drafts.
|
|
77
|
+
*/
|
|
78
|
+
async figureReleaseCatalog(params, context) {
|
|
79
|
+
return (0, figure_release_catalog_js_1.figureReleaseCatalogOf)(context.state.domain, params);
|
|
80
|
+
}
|
|
73
81
|
async publicFigures(params, context) {
|
|
74
82
|
const { domain } = context.state;
|
|
75
83
|
const mine = [domain.id, domain.parentId].filter(Boolean);
|
|
@@ -79,7 +87,7 @@ let FigureQuery = class FigureQuery {
|
|
|
79
87
|
alias: 'figure',
|
|
80
88
|
searchables: PUBLIC_FIGURE_SEARCHABLES
|
|
81
89
|
})
|
|
82
|
-
.innerJoinAndMapOne('figure.row', figure_js_1.Figure, 'row', 'row
|
|
90
|
+
.innerJoinAndMapOne('figure.row', figure_js_1.Figure, 'row', `${(0, figure_public_js_1.figureRowOfRelease)('row', 'figure.originalId')} AND row.public = :public AND row.deletedAt IS NULL`, { public: true })
|
|
83
91
|
.leftJoinAndSelect('figure.domain', 'owner')
|
|
84
92
|
.leftJoinAndSelect('figure.updater', 'releaser')
|
|
85
93
|
.andWhere('owner.id NOT IN (:...mine)', { mine })
|
|
@@ -377,6 +385,15 @@ tslib_1.__decorate([
|
|
|
377
385
|
tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
|
|
378
386
|
tslib_1.__metadata("design:returntype", Promise)
|
|
379
387
|
], FigureQuery.prototype, "figureStateCounts", null);
|
|
388
|
+
tslib_1.__decorate([
|
|
389
|
+
(0, type_graphql_1.Directive)('@privilege(category: "figure-published", privilege: "query", domainOwnerGranted: true)'),
|
|
390
|
+
(0, type_graphql_1.Query)(returns => figure_release_catalog_js_1.FigureReleaseCatalog, { description: 'The figures this domain may install elsewhere - its own, its parent\'s and public ones - each as its latest release.' }),
|
|
391
|
+
tslib_1.__param(0, (0, type_graphql_1.Args)()),
|
|
392
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
393
|
+
tslib_1.__metadata("design:type", Function),
|
|
394
|
+
tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
|
|
395
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
396
|
+
], FigureQuery.prototype, "figureReleaseCatalog", null);
|
|
380
397
|
tslib_1.__decorate([
|
|
381
398
|
(0, type_graphql_1.Directive)('@privilege(category: "figure", privilege: "query", domainOwnerGranted: true)'),
|
|
382
399
|
(0, type_graphql_1.Query)(returns => figure_type_js_1.FigureList, { description: "Other domains' public figures, each as its latest release. Read only: their releases, never their drafts." }),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FigureAsset, FigureProposalStep } from '@hatiolab/figure-model';
|
|
2
|
+
/**
|
|
3
|
+
* The figure a build starts from, and the steps that made it from nothing: the open figure as it is, or a new one made
|
|
4
|
+
* to show -- unlimited detail, as a planned one is (figure-plan.ts); left to itself the model set M or L and held
|
|
5
|
+
* itself to 8 or 20 parts (2026-11-13, held-out runs). Both agents start here.
|
|
6
|
+
*/
|
|
7
|
+
export declare function startingFigure(base: FigureAsset | undefined, name?: string): {
|
|
8
|
+
asset: FigureAsset;
|
|
9
|
+
steps: FigureProposalStep[];
|
|
10
|
+
};
|
|
11
|
+
/** The figure as it stands, in the words a modeller checks it by. */
|
|
12
|
+
export declare function readFigure(asset: FigureAsset, parts?: string[]): string;
|
|
13
|
+
export declare function tryPose(asset: FigureAsset, values: Record<string, number>): string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startingFigure = startingFigure;
|
|
4
|
+
exports.readFigure = readFigure;
|
|
5
|
+
exports.tryPose = tryPose;
|
|
6
|
+
/**
|
|
7
|
+
* The figure read back as a modeller checks it (2026-11-13, moved out of figure-agent-build 2026-11-14): where each part
|
|
8
|
+
* spans, which way it faces, what it hangs on, how it moves, what it touches -- at rest or with controls set -- and the
|
|
9
|
+
* figure a build starts from. Only figure-model, so a process outside the server (the figure MCP server) reads and
|
|
10
|
+
* starts a figure the same way.
|
|
11
|
+
*/
|
|
12
|
+
const figure_model_1 = require("@hatiolab/figure-model");
|
|
13
|
+
/**
|
|
14
|
+
* The figure a build starts from, and the steps that made it from nothing: the open figure as it is, or a new one made
|
|
15
|
+
* to show -- unlimited detail, as a planned one is (figure-plan.ts); left to itself the model set M or L and held
|
|
16
|
+
* itself to 8 or 20 parts (2026-11-13, held-out runs). Both agents start here.
|
|
17
|
+
*/
|
|
18
|
+
function startingFigure(base, name) {
|
|
19
|
+
if (base)
|
|
20
|
+
return { asset: base, steps: [] };
|
|
21
|
+
const unlimited = { kind: 'set-detail-level', level: 'UNLIMITED' };
|
|
22
|
+
return { asset: (0, figure_model_1.applyFigureProposal)((0, figure_model_1.createFigureAsset)(name || 'Figure'), [unlimited]), steps: [unlimited] };
|
|
23
|
+
}
|
|
24
|
+
const r = (v) => Math.round(v);
|
|
25
|
+
function wayOf(v) {
|
|
26
|
+
const names = [
|
|
27
|
+
[0, 'X'],
|
|
28
|
+
[1, 'Y'],
|
|
29
|
+
[2, 'Z']
|
|
30
|
+
];
|
|
31
|
+
const [k, axis] = names.reduce((best, cur) => (Math.abs(v[cur[0]]) > Math.abs(v[best[0]]) ? cur : best));
|
|
32
|
+
if (Math.abs(Math.abs(v[k]) - 1) > 0.02)
|
|
33
|
+
return `(${v.map(x => x.toFixed(2)).join(', ')})`;
|
|
34
|
+
const plus = { X: 'right', Y: 'up', Z: 'front' }[axis];
|
|
35
|
+
const minus = { X: 'left', Y: 'down', Z: 'back' }[axis];
|
|
36
|
+
return `${v[k] > 0 ? '+' : '-'}${axis} (${v[k] > 0 ? plus : minus})`;
|
|
37
|
+
}
|
|
38
|
+
function boxesOf(asset, state = {}) {
|
|
39
|
+
const geometry = (0, figure_model_1.compileFigureAsset)(asset).evaluate({ ...(asset.stateDefaults ?? {}), ...state }).geometry;
|
|
40
|
+
return { boxes: new Map((0, figure_model_1.figureOccupiedBoxesOf)(geometry, (0, figure_model_1.figureWritersOf)(asset)).map(b => [b.part, b])), geometry };
|
|
41
|
+
}
|
|
42
|
+
const span = (b) => ['x', 'y', 'z'].map(a => `${a} ${r(b.centre[a] - b.extent[a] / 2)}..${r(b.centre[a] + b.extent[a] / 2)}`).join(', ');
|
|
43
|
+
/** Which way a part faces: a round part by its round axis, any other by where its own up and front point, when turned. */
|
|
44
|
+
function facingOf(g) {
|
|
45
|
+
const R = g?.pose?.r;
|
|
46
|
+
if (!R)
|
|
47
|
+
return '';
|
|
48
|
+
const col = (k) => [R[0][k], R[1][k], R[2][k]];
|
|
49
|
+
const e = g.shape?.extrusion;
|
|
50
|
+
if (e && (e.section?.kind === 'circle' || e.section?.kind === 'ellipse')) {
|
|
51
|
+
const k = { x: 0, y: 1, z: 2 }[e.axis] ?? 1;
|
|
52
|
+
return `round about ${wayOf(col(k)).replace(/^[+-]/, '')}`;
|
|
53
|
+
}
|
|
54
|
+
const turned = R.some((row, i) => row.some((v, j) => Math.abs(v - (i === j ? 1 : 0)) > 1e-6));
|
|
55
|
+
return turned ? `turned: its own up points ${wayOf(col(1))}, its front ${wayOf(col(2))}` : '';
|
|
56
|
+
}
|
|
57
|
+
function dimsOf(asset, part) {
|
|
58
|
+
const d = Object.entries((asset.designInputs ?? {})).filter(([k]) => k.startsWith(`${part}.dimension.`));
|
|
59
|
+
return d.map(([k, v]) => `${k.slice(part.length + 11)} ${r(v)}`).join(', ');
|
|
60
|
+
}
|
|
61
|
+
/** The figure as it stands, in the words a modeller checks it by. */
|
|
62
|
+
function readFigure(asset, parts) {
|
|
63
|
+
const { boxes, geometry } = boxesOf(asset);
|
|
64
|
+
const all = [...boxes.values()];
|
|
65
|
+
if (!all.length)
|
|
66
|
+
return 'The figure has no parts yet.';
|
|
67
|
+
const lo = (a) => Math.min(...all.map(b => b.centre[a] - b.extent[a] / 2));
|
|
68
|
+
const hi = (a) => Math.max(...all.map(b => b.centre[a] + b.extent[a] / 2));
|
|
69
|
+
const inputs = asset.document.model.inputs.filter(i => i.role === 'state');
|
|
70
|
+
const rest = (asset.stateDefaults ?? {});
|
|
71
|
+
const joints = (asset.joints ?? []);
|
|
72
|
+
const lines = [
|
|
73
|
+
`Figure: ${all.length} parts; spans ${['x', 'y', 'z'].map(a => `${a} ${r(lo(a))}..${r(hi(a))}`).join(', ')}.`,
|
|
74
|
+
inputs.length ? `Controls: ${inputs.map(i => `${i.id} ${i.min}..${i.max} at ${rest[i.id] ?? 0}`).join('; ')}.` : 'Controls: none.'
|
|
75
|
+
];
|
|
76
|
+
const wanted = parts?.length ? new Set(parts) : undefined;
|
|
77
|
+
for (const b of all) {
|
|
78
|
+
if (wanted && !wanted.has(b.part))
|
|
79
|
+
continue;
|
|
80
|
+
const g = geometry.find(x => x.id === b.part);
|
|
81
|
+
const j = joints.find(x => x.body1?.part === b.part);
|
|
82
|
+
const on = j ? ('plane' in (j.body0 ?? {}) ? 'the mounting plane' : `${j.body0.part} ${j.body0.face ? `face ${j.body0.face}` : j.body0.surface ? `surface ${JSON.stringify(j.body0.surface)}` : ''}`.trim()) : 'nothing (not fastened)';
|
|
83
|
+
const how = j?.origin?.facing ? `, ${j.origin.facing}` : '';
|
|
84
|
+
const moves = (j?.motion ?? []).map((m) => `${m.type} about ${typeof m.axis === 'string' ? m.axis : JSON.stringify(m.axis)} ${m.lowerLimit ?? '-inf'}..${m.upperLimit ?? 'inf'} by ${m.state?.id ?? m.id ?? j.id}`).join('; ');
|
|
85
|
+
const touching = all
|
|
86
|
+
.filter(o => o !== b && o.part !== j?.body0?.part)
|
|
87
|
+
.filter(o => ['x', 'y', 'z'].every(a => Math.abs(o.centre[a] - b.centre[a]) <= (o.extent[a] + b.extent[a]) / 2 + 1))
|
|
88
|
+
.map(o => o.part);
|
|
89
|
+
const facing = facingOf(g);
|
|
90
|
+
lines.push(`- ${b.part}: ${dimsOf(asset, b.part)}; spans ${span(b)}${facing ? `; ${facing}` : ''}; on ${on}${how}${moves ? `; moves ${moves}` : ''}${touching.length ? `; touches ${touching.slice(0, 8).join(', ')}${touching.length > 8 ? ' ...' : ''}` : ''}`);
|
|
91
|
+
}
|
|
92
|
+
return lines.join('\n');
|
|
93
|
+
}
|
|
94
|
+
function tryPose(asset, values) {
|
|
95
|
+
const before = boxesOf(asset).boxes;
|
|
96
|
+
const { boxes, geometry } = boxesOf(asset, values);
|
|
97
|
+
const moved = [...boxes.values()].filter(b => {
|
|
98
|
+
const a = before.get(b.part);
|
|
99
|
+
return !a || ['x', 'y', 'z'].some(k => Math.abs(a.centre[k] - b.centre[k]) > 1 || Math.abs(a.extent[k] - b.extent[k]) > 1);
|
|
100
|
+
});
|
|
101
|
+
if (!moved.length)
|
|
102
|
+
return `With ${JSON.stringify(values)} nothing moved.`;
|
|
103
|
+
return [`With ${JSON.stringify(values)}:`, ...moved.map(b => `- ${b.part}: spans ${span(b)}${facingOf(geometry.find(x => x.id === b.part)) ? `; ${facingOf(geometry.find(x => x.id === b.part))}` : ''}`)].join('\n');
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=figure-read.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ListParam } from '@things-factory/shell';
|
|
2
|
+
/**
|
|
3
|
+
* One figure as another server installs it (ADR-0114 decision 24): its latest release, never its draft. A board server
|
|
4
|
+
* lists these to choose what to install, then asks `/figure-package` for the chosen refs.
|
|
5
|
+
*/
|
|
6
|
+
export declare class FigureReleaseCatalogItem {
|
|
7
|
+
figureId: string;
|
|
8
|
+
fullName: string;
|
|
9
|
+
ref: string;
|
|
10
|
+
namespace: string;
|
|
11
|
+
type: string;
|
|
12
|
+
version: number;
|
|
13
|
+
name?: string;
|
|
14
|
+
names?: Record<string, string>;
|
|
15
|
+
description?: string;
|
|
16
|
+
category?: string;
|
|
17
|
+
deprecated: boolean;
|
|
18
|
+
supersededBy?: string;
|
|
19
|
+
public: boolean;
|
|
20
|
+
assetFormat?: string;
|
|
21
|
+
kernelVersion?: string;
|
|
22
|
+
releasedAt?: Date;
|
|
23
|
+
thumbnailHash?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare class FigureReleaseCatalog {
|
|
26
|
+
items: FigureReleaseCatalogItem[];
|
|
27
|
+
total: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The figures a domain may read the releases of - its own, its parent's and any domain's public one, the scope of
|
|
31
|
+
* `figureBlueprint` and `/figure-package` - each as its latest release. Figures never released are not listed.
|
|
32
|
+
*/
|
|
33
|
+
export declare function figureReleaseCatalogOf(domain: {
|
|
34
|
+
id: string;
|
|
35
|
+
parentId?: string | null;
|
|
36
|
+
}, params: ListParam): Promise<FigureReleaseCatalog>;
|