dsh-unreal-python-api 0.0.0-stage → 1.0.0
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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +141 -2
- package/cordis.patch.yml +4 -0
- package/docs/DETAIL.md +78 -0
- package/icon.svg +9 -0
- package/index.js +482 -0
- package/lib/builder.js +603 -0
- package/lib/docs.js +196 -0
- package/lib/inventory.js +304 -0
- package/link-deps.ps1 +36 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +51 -4
- package/test/smoke.mjs +222 -0
package/index.js
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unreal Engine Python API context for agents.
|
|
3
|
+
*
|
|
4
|
+
* Publishes the documented Unreal Python 5.8 surface as four tools — list,
|
|
5
|
+
* search, syntax, and tool builder — backed by the symbol inventory Epic
|
|
6
|
+
* publishes beside the Python API documentation. Nothing here guesses at an
|
|
7
|
+
* API: a symbol that is not in the inventory is reported as unresolved.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-unreal-python-api
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import z from '@deepseek-ai/schemastery'
|
|
13
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_DOC_BASE_URL,
|
|
16
|
+
friendlyKind,
|
|
17
|
+
listChildren,
|
|
18
|
+
loadInventory,
|
|
19
|
+
pageUrl,
|
|
20
|
+
resolveCacheDir,
|
|
21
|
+
searchSymbols,
|
|
22
|
+
summarize,
|
|
23
|
+
} from './lib/inventory.js'
|
|
24
|
+
import { readSymbolDoc } from './lib/docs.js'
|
|
25
|
+
import { DEFAULT_REGISTRY_IMPORT, buildToolset } from './lib/builder.js'
|
|
26
|
+
|
|
27
|
+
export const name = 'unreal-python-api'
|
|
28
|
+
|
|
29
|
+
export const inject = ['tools', 'systemPrompt']
|
|
30
|
+
|
|
31
|
+
export const Config = z.object({
|
|
32
|
+
docBaseUrl: z.string().default(DEFAULT_DOC_BASE_URL),
|
|
33
|
+
cacheDir: z.string().default(''),
|
|
34
|
+
refreshHours: z.number().default(24),
|
|
35
|
+
maxResults: z.number().default(30),
|
|
36
|
+
fetchTimeoutMs: z.number().default(30_000),
|
|
37
|
+
promptSection: z.boolean().default(true),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
/** Largest row count any tool returns, whatever a caller asks for. */
|
|
41
|
+
const ROW_CEILING = 200
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resolve a requested row cap.
|
|
45
|
+
* @param {number | undefined} requested Caller value.
|
|
46
|
+
* @param {number} fallback Configured default.
|
|
47
|
+
* @returns {number} Effective row cap.
|
|
48
|
+
*/
|
|
49
|
+
function clampLimit(requested, fallback) {
|
|
50
|
+
if (requested === undefined || requested === null) return fallback
|
|
51
|
+
const value = Math.floor(Number(requested))
|
|
52
|
+
if (!Number.isFinite(value) || value < 1) throw new Error('limit must be a positive number')
|
|
53
|
+
return Math.min(value, ROW_CEILING)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Build a fresh symbol-row schema. @returns {object} Row schema. */
|
|
57
|
+
function rowSchema() {
|
|
58
|
+
return {
|
|
59
|
+
type: 'object',
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
properties: {
|
|
62
|
+
name: { type: 'string', required: true },
|
|
63
|
+
kind: { type: 'string', required: true },
|
|
64
|
+
url: { type: 'string', required: true },
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Build a fresh kind-count schema. @returns {object} Count schema. */
|
|
70
|
+
function countSchema() {
|
|
71
|
+
return {
|
|
72
|
+
type: 'object',
|
|
73
|
+
additionalProperties: false,
|
|
74
|
+
properties: {
|
|
75
|
+
kind: { type: 'string', required: true },
|
|
76
|
+
count: { type: 'number', required: true },
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Render symbol rows as compact lines.
|
|
83
|
+
* @param {string} header First line.
|
|
84
|
+
* @param {Array<{name: string, kind: string, url: string}>} rows Symbol rows.
|
|
85
|
+
* @param {string} [footer] Closing line.
|
|
86
|
+
* @returns {string} Rendered text.
|
|
87
|
+
*/
|
|
88
|
+
function renderRows(header, rows, footer) {
|
|
89
|
+
const lines = [header]
|
|
90
|
+
for (const row of rows) lines.push(` ${row.name} [${row.kind}] ${row.url}`)
|
|
91
|
+
if (footer) lines.push(footer)
|
|
92
|
+
return lines.join('\n')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Register the Unreal Python API tools.
|
|
97
|
+
* @param {object} ctx Plugin context.
|
|
98
|
+
* @param {object} config Resolved plugin configuration.
|
|
99
|
+
* @returns {void}
|
|
100
|
+
*/
|
|
101
|
+
export function apply(ctx, config) {
|
|
102
|
+
const docBaseUrl = String(config.docBaseUrl ?? DEFAULT_DOC_BASE_URL)
|
|
103
|
+
if (!/^https?:\/\//.test(docBaseUrl)) throw new Error('docBaseUrl must be an http(s) URL')
|
|
104
|
+
const cacheDir = resolveCacheDir(config.cacheDir)
|
|
105
|
+
const maxResults = config.maxResults
|
|
106
|
+
const fetchTimeoutMs = config.fetchTimeoutMs
|
|
107
|
+
const refreshHours = config.refreshHours
|
|
108
|
+
if (!Number.isFinite(maxResults) || maxResults < 1) throw new Error('maxResults must be a positive number')
|
|
109
|
+
if (!Number.isFinite(fetchTimeoutMs) || fetchTimeoutMs < 1_000) throw new Error('fetchTimeoutMs must be at least 1000')
|
|
110
|
+
if (!Number.isFinite(refreshHours) || refreshHours < 0) throw new Error('refreshHours must not be negative')
|
|
111
|
+
|
|
112
|
+
let loaded = null
|
|
113
|
+
/**
|
|
114
|
+
* Load the inventory once per process, re-reading it when a caller asks to refresh.
|
|
115
|
+
* @param {boolean} refresh Force a download.
|
|
116
|
+
* @returns {Promise<object>} Loaded inventory.
|
|
117
|
+
*/
|
|
118
|
+
function inventory(refresh) {
|
|
119
|
+
if (refresh === true) loaded = null
|
|
120
|
+
if (loaded === null) {
|
|
121
|
+
loaded = loadInventory({
|
|
122
|
+
docBaseUrl,
|
|
123
|
+
cacheDir,
|
|
124
|
+
refreshHours: refresh === true ? 0 : refreshHours,
|
|
125
|
+
timeoutMs: fetchTimeoutMs,
|
|
126
|
+
}).catch((error) => {
|
|
127
|
+
loaded = null
|
|
128
|
+
throw error
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
return loaded
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
ctx.tools.register(defineTool({
|
|
135
|
+
name: 'unreal_python_tools_list',
|
|
136
|
+
description: 'List Unreal Engine Python API symbols. Without a parent it reports how many symbols the published documentation holds and their kinds; with a parent such as unreal.Actor it lists that namespace or class direct members.',
|
|
137
|
+
parameters: {
|
|
138
|
+
parent: { type: 'string', description: 'Dotted symbol whose direct members to list, for example unreal.EditorAssetLibrary.' },
|
|
139
|
+
kind: { type: 'string', description: 'Restrict rows to class, method, property, attribute, function, doc, or label.' },
|
|
140
|
+
limit: { type: 'number', description: 'Row cap; defaults to the configured result limit.' },
|
|
141
|
+
refresh: { type: 'boolean', description: 'Download the symbol inventory again instead of using the cached copy.' },
|
|
142
|
+
},
|
|
143
|
+
output: {
|
|
144
|
+
schema: {
|
|
145
|
+
type: 'object',
|
|
146
|
+
additionalProperties: false,
|
|
147
|
+
properties: {
|
|
148
|
+
apiVersion: { type: 'string', required: true },
|
|
149
|
+
source: { type: 'string', required: true },
|
|
150
|
+
total: { type: 'number', required: true },
|
|
151
|
+
shown: { type: 'number', required: true },
|
|
152
|
+
truncated: { type: 'boolean', required: true },
|
|
153
|
+
counts: { type: 'array', required: true, items: countSchema() },
|
|
154
|
+
rows: { type: 'array', required: true, items: rowSchema() },
|
|
155
|
+
parent: { type: 'string' },
|
|
156
|
+
hint: { type: 'string' },
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
render: (_args, value) => {
|
|
160
|
+
const counts = value.counts.map((entry) => `${entry.kind} ${entry.count}`).join(', ')
|
|
161
|
+
const header = `Unreal Python ${value.apiVersion} API: ${value.total} symbols, inventory from ${value.source}\nkinds: ${counts}`
|
|
162
|
+
if (value.rows.length === 0) return [{ type: 'text', text: `${header}\n${value.hint ?? ''}`.trim() }]
|
|
163
|
+
const footer = `${value.shown} of ${value.total} direct members of ${value.parent}${value.truncated ? ' (truncated)' : ''}`
|
|
164
|
+
return [{ type: 'text', text: renderRows(header, value.rows, footer) }]
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
timeoutMs: fetchTimeoutMs + 5_000,
|
|
168
|
+
async execute(args) {
|
|
169
|
+
const limit = clampLimit(args.limit, maxResults)
|
|
170
|
+
const current = await inventory(args.refresh === true)
|
|
171
|
+
const counts = summarize(current.inventory)
|
|
172
|
+
const parent = args.parent === undefined ? '' : String(args.parent).trim()
|
|
173
|
+
if (parent === '') {
|
|
174
|
+
return {
|
|
175
|
+
apiVersion: current.version,
|
|
176
|
+
source: current.source,
|
|
177
|
+
total: current.inventory.names.length,
|
|
178
|
+
shown: 0,
|
|
179
|
+
truncated: false,
|
|
180
|
+
counts,
|
|
181
|
+
rows: [],
|
|
182
|
+
hint: "Pass parent (for example unreal.EditorAssetLibrary or unreal.Actor) to list direct members; use unreal_python_search to find symbols by name.",
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const listing = listChildren(current.inventory, { parent, kind: args.kind, limit })
|
|
186
|
+
return {
|
|
187
|
+
apiVersion: current.version,
|
|
188
|
+
source: current.source,
|
|
189
|
+
total: listing.total,
|
|
190
|
+
shown: listing.rows.length,
|
|
191
|
+
truncated: listing.truncated,
|
|
192
|
+
counts: listing.counts,
|
|
193
|
+
rows: listing.rows,
|
|
194
|
+
parent,
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
}))
|
|
198
|
+
|
|
199
|
+
ctx.tools.register(defineTool({
|
|
200
|
+
name: 'unreal_python_search',
|
|
201
|
+
description: 'Search Unreal Python API symbol names. Ranks an exact name first, then a member name that starts with the query, then any containing name, and returns each match with its documentation URL.',
|
|
202
|
+
parameters: {
|
|
203
|
+
query: { type: 'string', required: true, description: 'Symbol text to find, for example save_asset or unreal.Actor.' },
|
|
204
|
+
kind: { type: 'string', description: 'Restrict matches to class, method, property, attribute, function, doc, or label.' },
|
|
205
|
+
parent: { type: 'string', description: 'Restrict matches to members of this dotted symbol.' },
|
|
206
|
+
limit: { type: 'number', description: 'Match cap; defaults to the configured result limit.' },
|
|
207
|
+
},
|
|
208
|
+
output: {
|
|
209
|
+
schema: {
|
|
210
|
+
type: 'object',
|
|
211
|
+
additionalProperties: false,
|
|
212
|
+
properties: {
|
|
213
|
+
apiVersion: { type: 'string', required: true },
|
|
214
|
+
query: { type: 'string', required: true },
|
|
215
|
+
total: { type: 'number', required: true },
|
|
216
|
+
shown: { type: 'number', required: true },
|
|
217
|
+
truncated: { type: 'boolean', required: true },
|
|
218
|
+
rows: { type: 'array', required: true, items: rowSchema() },
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
render: (_args, value) => {
|
|
222
|
+
if (value.rows.length === 0) {
|
|
223
|
+
return [{ type: 'text', text: `No Unreal Python ${value.apiVersion} symbol matches "${value.query}". Try a shorter query, or unreal_python_tools_list for the documented namespaces.` }]
|
|
224
|
+
}
|
|
225
|
+
const header = `${value.total} symbols match "${value.query}" in the Unreal Python ${value.apiVersion} API; showing ${value.shown}${value.truncated ? ' (truncated)' : ''}`
|
|
226
|
+
return [{ type: 'text', text: renderRows(header, value.rows) }]
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
timeoutMs: fetchTimeoutMs + 5_000,
|
|
230
|
+
async execute(args) {
|
|
231
|
+
const limit = clampLimit(args.limit, maxResults)
|
|
232
|
+
const current = await inventory(false)
|
|
233
|
+
const result = searchSymbols(current.inventory, {
|
|
234
|
+
query: args.query,
|
|
235
|
+
kind: args.kind,
|
|
236
|
+
parent: args.parent,
|
|
237
|
+
limit,
|
|
238
|
+
})
|
|
239
|
+
return {
|
|
240
|
+
apiVersion: current.version,
|
|
241
|
+
query: String(args.query).trim(),
|
|
242
|
+
total: result.total,
|
|
243
|
+
shown: result.matches.length,
|
|
244
|
+
truncated: result.truncated,
|
|
245
|
+
rows: result.matches,
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
}))
|
|
249
|
+
|
|
250
|
+
ctx.tools.register(defineTool({
|
|
251
|
+
name: 'unreal_python_syntax',
|
|
252
|
+
description: 'Return the exact documented syntax of Unreal Python symbols: signature, description, parameters, and return value, read from the published documentation page that carries the symbol.',
|
|
253
|
+
parameters: {
|
|
254
|
+
symbols: {
|
|
255
|
+
type: 'array',
|
|
256
|
+
required: true,
|
|
257
|
+
items: { type: 'string' },
|
|
258
|
+
description: 'Dotted symbol names, for example unreal.Actor.set_actor_scale3d.',
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
output: {
|
|
262
|
+
schema: {
|
|
263
|
+
type: 'object',
|
|
264
|
+
additionalProperties: false,
|
|
265
|
+
properties: {
|
|
266
|
+
apiVersion: { type: 'string', required: true },
|
|
267
|
+
entries: {
|
|
268
|
+
type: 'array',
|
|
269
|
+
required: true,
|
|
270
|
+
items: {
|
|
271
|
+
type: 'object',
|
|
272
|
+
additionalProperties: false,
|
|
273
|
+
properties: {
|
|
274
|
+
symbol: { type: 'string', required: true },
|
|
275
|
+
kind: { type: 'string', required: true },
|
|
276
|
+
url: { type: 'string', required: true },
|
|
277
|
+
resolved: { type: 'boolean', required: true },
|
|
278
|
+
signature: { type: 'string', required: true },
|
|
279
|
+
description: { type: 'string', required: true },
|
|
280
|
+
parameters: {
|
|
281
|
+
type: 'array',
|
|
282
|
+
required: true,
|
|
283
|
+
items: {
|
|
284
|
+
type: 'object',
|
|
285
|
+
additionalProperties: false,
|
|
286
|
+
properties: {
|
|
287
|
+
name: { type: 'string', required: true },
|
|
288
|
+
text: { type: 'string', required: true },
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
returns: { type: 'string', required: true },
|
|
293
|
+
note: { type: 'string', required: true },
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
unresolved: {
|
|
298
|
+
type: 'array',
|
|
299
|
+
required: true,
|
|
300
|
+
items: {
|
|
301
|
+
type: 'object',
|
|
302
|
+
additionalProperties: false,
|
|
303
|
+
properties: {
|
|
304
|
+
symbol: { type: 'string', required: true },
|
|
305
|
+
reason: { type: 'string', required: true },
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
render: (_args, value) => {
|
|
312
|
+
const blocks = []
|
|
313
|
+
for (const entry of value.entries) {
|
|
314
|
+
const lines = [`${entry.symbol} [${entry.kind}]`]
|
|
315
|
+
lines.push(` signature: ${entry.signature === '' ? '(not on the page)' : entry.signature}`)
|
|
316
|
+
if (entry.description !== '') lines.push(` summary: ${entry.description}`)
|
|
317
|
+
for (const parameter of entry.parameters) {
|
|
318
|
+
lines.push(` param: ${parameter.name === '' ? parameter.text : `${parameter.name} - ${parameter.text}`}`)
|
|
319
|
+
}
|
|
320
|
+
if (entry.returns !== '') lines.push(` returns: ${entry.returns}`)
|
|
321
|
+
lines.push(` docs: ${entry.url}`)
|
|
322
|
+
if (entry.resolved === false) lines.push(` note: ${entry.note}`)
|
|
323
|
+
blocks.push(lines.join('\n'))
|
|
324
|
+
}
|
|
325
|
+
for (const missing of value.unresolved) {
|
|
326
|
+
blocks.push(`${missing.symbol}: unresolved - ${missing.reason}`)
|
|
327
|
+
}
|
|
328
|
+
return [{ type: 'text', text: `Unreal Python ${value.apiVersion} API\n\n${blocks.join('\n\n')}` }]
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
timeoutMs: fetchTimeoutMs + 10_000,
|
|
332
|
+
async execute(args) {
|
|
333
|
+
const current = await inventory(false)
|
|
334
|
+
const { inventory: api } = current
|
|
335
|
+
const requested = [...new Set((args.symbols ?? []).map((symbol) => String(symbol).trim()).filter((symbol) => symbol !== ''))]
|
|
336
|
+
if (requested.length === 0) throw new Error('symbols must contain at least one symbol name')
|
|
337
|
+
const entries = []
|
|
338
|
+
const unresolved = []
|
|
339
|
+
const reads = requested.map(async (symbol) => {
|
|
340
|
+
const position = api.index.get(symbol)
|
|
341
|
+
if (position === undefined) {
|
|
342
|
+
unresolved.push({ symbol, reason: `not in the Unreal Python ${current.version} inventory` })
|
|
343
|
+
return null
|
|
344
|
+
}
|
|
345
|
+
return readSymbolDoc({
|
|
346
|
+
docBaseUrl,
|
|
347
|
+
symbol,
|
|
348
|
+
uri: api.uris[position],
|
|
349
|
+
kind: friendlyKind(api.kinds[position]),
|
|
350
|
+
timeoutMs: fetchTimeoutMs,
|
|
351
|
+
})
|
|
352
|
+
})
|
|
353
|
+
for (const read of await Promise.all(reads)) if (read !== null) entries.push(read)
|
|
354
|
+
return { apiVersion: current.version, entries, unresolved }
|
|
355
|
+
},
|
|
356
|
+
}))
|
|
357
|
+
|
|
358
|
+
ctx.tools.register(defineTool({
|
|
359
|
+
name: 'unreal_python_tool_builder',
|
|
360
|
+
description: 'Scaffold an Unreal Python tool from a description plus verified API symbols. Styles: toolset (a ToolsetRegistry toolset class with its test module), editor_script (a plain editor script), mcp_tool (MCP tool descriptors in JSON plus the Python handler module that serves them), and dsh_tool (a DSH plugin tool module whose definitions register through defineTool, with a Node test module). Every Unreal API symbol the tool asks for is verified against the published inventory and recorded with its documentation URL; unverified symbols are reported instead of written into the code.',
|
|
361
|
+
parameters: {
|
|
362
|
+
toolset_name: { type: 'string', required: true, description: 'Class name for the toolset, for example TerritoryTools.' },
|
|
363
|
+
description: { type: 'string', required: true, description: 'What the toolset does; becomes its docstring.' },
|
|
364
|
+
tools: {
|
|
365
|
+
type: 'array',
|
|
366
|
+
required: true,
|
|
367
|
+
description: 'Tools to scaffold.',
|
|
368
|
+
items: {
|
|
369
|
+
type: 'object',
|
|
370
|
+
additionalProperties: false,
|
|
371
|
+
properties: {
|
|
372
|
+
name: { type: 'string', required: true, description: 'Tool function name, for example save_dirty_assets.' },
|
|
373
|
+
description: { type: 'string', required: true, description: 'What the tool does; becomes its docstring.' },
|
|
374
|
+
parameters: {
|
|
375
|
+
type: 'array',
|
|
376
|
+
description: 'Tool parameters.',
|
|
377
|
+
items: {
|
|
378
|
+
type: 'object',
|
|
379
|
+
additionalProperties: false,
|
|
380
|
+
properties: {
|
|
381
|
+
name: { type: 'string', required: true },
|
|
382
|
+
type: { type: 'string', required: true, description: 'str, int, float, bool, list[...], dict[...], or a dotted unreal type.' },
|
|
383
|
+
description: { type: 'string' },
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
returns: { type: 'string', description: 'Return annotation; defaults to None.' },
|
|
388
|
+
symbols: {
|
|
389
|
+
type: 'array',
|
|
390
|
+
items: { type: 'string' },
|
|
391
|
+
description: 'Unreal Python symbols the body will call, for example unreal.EditorAssetLibrary.save_asset.',
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
style: { type: 'string', description: 'toolset (default), editor_script, mcp_tool, or dsh_tool.' },
|
|
397
|
+
registry_import: { type: 'string', description: `Import line for the ToolsetRegistry decorator module; defaults to ${DEFAULT_REGISTRY_IMPORT}.` },
|
|
398
|
+
base_class: { type: 'string', description: 'Toolset base class; defaults to unreal.ToolsetDefinition.' },
|
|
399
|
+
test_module: { type: 'string', description: 'Module exporting the generated class, used by the generated test import; defaults to the snake_case toolset name.' },
|
|
400
|
+
},
|
|
401
|
+
output: {
|
|
402
|
+
schema: {
|
|
403
|
+
type: 'object',
|
|
404
|
+
additionalProperties: false,
|
|
405
|
+
properties: {
|
|
406
|
+
apiVersion: { type: 'string', required: true },
|
|
407
|
+
inventorySource: { type: 'string', required: true },
|
|
408
|
+
style: { type: 'string', required: true },
|
|
409
|
+
codeLabel: { type: 'string', required: true },
|
|
410
|
+
testLabel: { type: 'string', required: true },
|
|
411
|
+
code: { type: 'string', required: true },
|
|
412
|
+
testCode: { type: 'string', required: true },
|
|
413
|
+
verified: {
|
|
414
|
+
type: 'array',
|
|
415
|
+
required: true,
|
|
416
|
+
items: {
|
|
417
|
+
type: 'object',
|
|
418
|
+
additionalProperties: false,
|
|
419
|
+
properties: {
|
|
420
|
+
symbol: { type: 'string', required: true },
|
|
421
|
+
kind: { type: 'string', required: true },
|
|
422
|
+
url: { type: 'string', required: true },
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
unresolved: { type: 'array', required: true, items: { type: 'string' } },
|
|
427
|
+
notes: { type: 'array', required: true, items: { type: 'string' } },
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
render: (_args, value) => {
|
|
431
|
+
const fence = (label) => (label.includes('JSON') ? 'json' : label.includes('JavaScript') ? 'js' : 'python')
|
|
432
|
+
const lines = [`Scaffold built against the Unreal Python ${value.apiVersion} inventory (${value.inventorySource}).`]
|
|
433
|
+
for (const note of value.notes) lines.push(`- ${note}`)
|
|
434
|
+
if (value.verified.length > 0) {
|
|
435
|
+
lines.push(`Verified API calls (${value.verified.length}):`)
|
|
436
|
+
for (const entry of value.verified) lines.push(` ${entry.symbol} [${entry.kind}] ${entry.url}`)
|
|
437
|
+
}
|
|
438
|
+
if (value.unresolved.length > 0) {
|
|
439
|
+
lines.push(`Unresolved (${value.unresolved.length}):`)
|
|
440
|
+
for (const symbol of value.unresolved) lines.push(` ${symbol}`)
|
|
441
|
+
}
|
|
442
|
+
lines.push('', `${value.codeLabel}:`, '```' + fence(value.codeLabel), value.code, '```')
|
|
443
|
+
if (value.testCode !== '') lines.push(`${value.testLabel}:`, '```' + fence(value.testLabel), value.testCode, '```')
|
|
444
|
+
return [{ type: 'text', text: lines.join('\n') }]
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
timeoutMs: fetchTimeoutMs + 5_000,
|
|
448
|
+
async execute(args) {
|
|
449
|
+
const current = await inventory(false)
|
|
450
|
+
const { inventory: api } = current
|
|
451
|
+
const result = buildToolset(
|
|
452
|
+
{
|
|
453
|
+
toolsetName: args.toolset_name,
|
|
454
|
+
description: args.description,
|
|
455
|
+
style: args.style,
|
|
456
|
+
registryImport: args.registry_import,
|
|
457
|
+
baseClass: args.base_class,
|
|
458
|
+
testModule: args.test_module,
|
|
459
|
+
tools: args.tools,
|
|
460
|
+
},
|
|
461
|
+
(symbol) => {
|
|
462
|
+
const position = api.index.get(symbol)
|
|
463
|
+
if (position === undefined) return { found: false }
|
|
464
|
+
return {
|
|
465
|
+
found: true,
|
|
466
|
+
kind: friendlyKind(api.kinds[position]),
|
|
467
|
+
url: pageUrl(docBaseUrl, api.uris[position], symbol),
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
)
|
|
471
|
+
return { apiVersion: current.version, inventorySource: current.source, ...result }
|
|
472
|
+
},
|
|
473
|
+
}))
|
|
474
|
+
|
|
475
|
+
if (config.promptSection) {
|
|
476
|
+
ctx.systemPrompt.section({
|
|
477
|
+
name: 'plugin:unreal-python-api',
|
|
478
|
+
order: 350,
|
|
479
|
+
text: `Unreal Python API (published 5.8 documentation): unreal_python_tools_list and unreal_python_search find documented symbols, unreal_python_syntax returns their exact signatures and parameters, and unreal_python_tool_builder scaffolds a tool from verified symbols in one of four styles — a ToolsetRegistry toolset, an editor script, MCP tool descriptors with their Python handlers, or a DSH tool module built on defineTool. Documentation root: ${docBaseUrl}`,
|
|
480
|
+
})
|
|
481
|
+
}
|
|
482
|
+
}
|