cwtools-shared 0.2.8 → 0.3.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/dist/generated/mcpTools.d.ts +2140 -0
- package/dist/generated/mcpTools.js +2875 -37
- package/dist/generated/workshopDetection.d.ts +22 -0
- package/dist/generated/workshopDetection.js +50 -0
- package/dist/generated/workspaceDetectionProfiles.d.ts +2 -0
- package/dist/generated/workspaceDetectionProfiles.js +84 -0
- package/dist/generated/workspaceGameDetection.d.ts +39 -0
- package/dist/generated/workspaceGameDetection.js +424 -0
- package/dist/host/capabilities.d.ts +39 -0
- package/dist/host/capabilities.js +124 -0
- package/dist/host/diagnostics.d.ts +5 -1
- package/dist/host/hostServices.d.ts +5 -0
- package/dist/host/lsp.d.ts +9 -0
- package/dist/host/lsp.js +27 -0
- package/dist/host/vanillaCache.js +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/tools/callHandler.d.ts +10 -0
- package/dist/tools/callHandler.js +72 -0
- package/dist/tools/mcpSchema.d.ts +23 -1
- package/dist/tools/mcpSchema.js +34 -2
- package/dist/tools/names.d.ts +8 -5
- package/dist/tools/names.js +23 -8
- package/dist/tools/registry.d.ts +1 -0
- package/dist/tools/targetingWeights.d.ts +206 -0
- package/dist/tools/targetingWeights.js +350 -0
- package/dist/tools/toolHandlers.d.ts +5 -1
- package/dist/tools/toolHandlers.js +57 -25
- package/package.json +1 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Backend capability handshake.
|
|
3
|
+
//
|
|
4
|
+
// `cwtools.ai.getHostCapabilities` is an internal command: it is answered before
|
|
5
|
+
// the game model loads, it is not part of any model-facing tool schema, and it
|
|
6
|
+
// exists so a host can prove it is talking to a compatible build before it
|
|
7
|
+
// spends seconds (or gigabytes) loading a project.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.REQUIRED_BACKEND_COMMANDS = exports.BACKEND_INCOMPATIBLE_CODE = exports.HOST_CAPABILITIES_PROTOCOL_VERSION = void 0;
|
|
10
|
+
exports.parseHostCapabilities = parseHostCapabilities;
|
|
11
|
+
exports.checkRequiredCommands = checkRequiredCommands;
|
|
12
|
+
/** Protocol version this client speaks. Bump when the response shape changes. */
|
|
13
|
+
exports.HOST_CAPABILITIES_PROTOCOL_VERSION = 1;
|
|
14
|
+
exports.BACKEND_INCOMPATIBLE_CODE = 'backend_incompatible';
|
|
15
|
+
function isRecord(value) {
|
|
16
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validate an untrusted handshake payload. Anything that is not a complete,
|
|
20
|
+
* well-formed, protocol-matching record is a rejection with a precise reason so
|
|
21
|
+
* the caller can report `backend_incompatible` and release the backend rather
|
|
22
|
+
* than running against a server whose command table it cannot trust.
|
|
23
|
+
*/
|
|
24
|
+
function parseHostCapabilities(raw) {
|
|
25
|
+
if (!isRecord(raw)) {
|
|
26
|
+
return { ok: false, reason: 'legacy', message: 'Backend did not answer cwtools.ai.getHostCapabilities.' };
|
|
27
|
+
}
|
|
28
|
+
if (raw.status === 'unavailable' || isRecord(raw.error)) {
|
|
29
|
+
return {
|
|
30
|
+
ok: false,
|
|
31
|
+
reason: 'legacy',
|
|
32
|
+
message: `Backend rejected the capability handshake: ${String((isRecord(raw.error) ? raw.error.message : undefined) ?? 'unavailable')}.`,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const protocolVersion = raw.protocolVersion;
|
|
36
|
+
const serverVersion = raw.serverVersion;
|
|
37
|
+
const commands = raw.commands;
|
|
38
|
+
if (typeof protocolVersion !== 'number' || !Number.isInteger(protocolVersion)) {
|
|
39
|
+
return { ok: false, reason: 'malformed', message: 'Backend handshake is missing an integer protocolVersion.' };
|
|
40
|
+
}
|
|
41
|
+
if (typeof serverVersion !== 'string' || serverVersion.trim().length === 0) {
|
|
42
|
+
return { ok: false, reason: 'malformed', message: 'Backend handshake is missing a serverVersion string.' };
|
|
43
|
+
}
|
|
44
|
+
if (!Array.isArray(commands) || commands.some(command => typeof command !== 'string')) {
|
|
45
|
+
return { ok: false, reason: 'malformed', message: 'Backend handshake is missing a string[] commands table.' };
|
|
46
|
+
}
|
|
47
|
+
if (protocolVersion !== exports.HOST_CAPABILITIES_PROTOCOL_VERSION) {
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
reason: 'protocol',
|
|
51
|
+
message: `Backend speaks capability protocol ${protocolVersion}; this client requires ${exports.HOST_CAPABILITIES_PROTOCOL_VERSION}.`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (commands.length === 0) {
|
|
55
|
+
return { ok: false, reason: 'incomplete', message: 'Backend handshake reported an empty command table.' };
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
ok: true,
|
|
59
|
+
capabilities: { protocolVersion, serverVersion: serverVersion.trim(), commands: [...commands] },
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Every LSP command this client's tool surface actually calls. Derived from the
|
|
64
|
+
* cwtools-shared dispatcher call sites plus the Node diagnostics/revalidation
|
|
65
|
+
* hosts, so a backend missing any one of them is rejected up front instead of
|
|
66
|
+
* degrading a single tool into an empty answer at call time.
|
|
67
|
+
*
|
|
68
|
+
* `cwtools.ai.getHostCapabilities` is deliberately absent: it is the handshake
|
|
69
|
+
* itself and never a model-facing tool.
|
|
70
|
+
*/
|
|
71
|
+
exports.REQUIRED_BACKEND_COMMANDS = [
|
|
72
|
+
// Readiness, diagnostics and manual revalidation.
|
|
73
|
+
'cwtools.ai.getValidationStatus',
|
|
74
|
+
'cwtools.ai.getDiagnosticsFresh',
|
|
75
|
+
'cwtools.ai.getAllDiagnostics',
|
|
76
|
+
'cwtools.ai.revalidateFiles',
|
|
77
|
+
// Completion, symbols and navigation.
|
|
78
|
+
'cwtools.ai.getCompletionContext',
|
|
79
|
+
'cwtools.ai.getScopeAtPosition',
|
|
80
|
+
'cwtools.ai.queryDefinition',
|
|
81
|
+
'cwtools.ai.queryDefinitionByName',
|
|
82
|
+
'cwtools.ai.getEntityInfo',
|
|
83
|
+
// Semantic model and project graph.
|
|
84
|
+
'cwtools.ai.queryTypes',
|
|
85
|
+
'cwtools.ai.exploreProject',
|
|
86
|
+
'cwtools.ai.exploreInlineGraph',
|
|
87
|
+
'cwtools.ai.analyzePdxFlow',
|
|
88
|
+
'cwtools.ai.compareDefinitionWithVanilla',
|
|
89
|
+
'cwtools.ai.parseFragment',
|
|
90
|
+
'cwtools.ai.queryProjectKnowledgeDb',
|
|
91
|
+
// Localisation.
|
|
92
|
+
'cwtools.ai.queryLocalisationAudit',
|
|
93
|
+
// Scripted types and enums.
|
|
94
|
+
'cwtools.ai.queryScriptedEffects',
|
|
95
|
+
'cwtools.ai.queryScriptedTriggers',
|
|
96
|
+
'cwtools.ai.queryEnums',
|
|
97
|
+
'cwtools.ai.queryStaticModifiers',
|
|
98
|
+
'cwtools.ai.queryVariables',
|
|
99
|
+
// Shader surface: all seven commands are individually exposed as tools.
|
|
100
|
+
'cwtools.ai.shader.symbols',
|
|
101
|
+
'cwtools.ai.shader.compileUnit',
|
|
102
|
+
'cwtools.ai.shader.variants',
|
|
103
|
+
'cwtools.ai.shader.callers',
|
|
104
|
+
'cwtools.ai.shader.reachability',
|
|
105
|
+
'cwtools.ai.shader.validate',
|
|
106
|
+
'cwtools.ai.shader.compareVanilla',
|
|
107
|
+
];
|
|
108
|
+
/**
|
|
109
|
+
* Check a validated capability set against the commands this client requires.
|
|
110
|
+
* A backend that is merely old is still rejected: the client cannot silently
|
|
111
|
+
* degrade a semantic tool into an empty answer.
|
|
112
|
+
*/
|
|
113
|
+
function checkRequiredCommands(capabilities, required = exports.REQUIRED_BACKEND_COMMANDS) {
|
|
114
|
+
const present = new Set(capabilities.commands);
|
|
115
|
+
const missing = required.filter(command => !present.has(command));
|
|
116
|
+
if (missing.length > 0) {
|
|
117
|
+
return {
|
|
118
|
+
ok: false,
|
|
119
|
+
reason: 'incomplete',
|
|
120
|
+
message: `Backend is missing required commands: ${missing.join(', ')}.`,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return { ok: true, capabilities };
|
|
124
|
+
}
|
|
@@ -35,7 +35,11 @@ export interface DiagnosticsQueryResult {
|
|
|
35
35
|
message: string;
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
+
/** Per-call context for a diagnostics query. `signal` cancels the backend work. */
|
|
39
|
+
export interface DiagnosticsQueryContext {
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}
|
|
38
42
|
export interface DiagnosticsHost {
|
|
39
|
-
getDiagnostics(filter?: DiagnosticsFilter): Promise<DiagnosticsQueryResult>;
|
|
43
|
+
getDiagnostics(filter?: DiagnosticsFilter, context?: DiagnosticsQueryContext): Promise<DiagnosticsQueryResult>;
|
|
40
44
|
}
|
|
41
45
|
export declare function createUnavailableDiagnosticsHost(message?: string): DiagnosticsHost;
|
|
@@ -3,6 +3,7 @@ import type { FilesystemHost } from './filesystem';
|
|
|
3
3
|
import type { IndexHost } from './indexing';
|
|
4
4
|
import type { LspHost } from './lsp';
|
|
5
5
|
import type { VanillaCacheStatus } from './vanillaCache';
|
|
6
|
+
import type { WorkspaceProjectKind } from '../generated/workspaceGameDetection';
|
|
6
7
|
export type HostLogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
7
8
|
export interface ProjectProfileHost {
|
|
8
9
|
readProfile(): Promise<unknown | null>;
|
|
@@ -43,6 +44,10 @@ export interface HostServices {
|
|
|
43
44
|
vanillaCache?: VanillaCacheStatus;
|
|
44
45
|
projectSupported?: boolean;
|
|
45
46
|
projectSupportReason?: string;
|
|
47
|
+
projectKind?: WorkspaceProjectKind;
|
|
48
|
+
projectGameId?: string;
|
|
49
|
+
projectEvidence?: string[];
|
|
50
|
+
projectCandidates?: string[];
|
|
46
51
|
now(): number;
|
|
47
52
|
log(level: HostLogLevel, message: string, data?: unknown): void;
|
|
48
53
|
dispose?(): void;
|
package/dist/host/lsp.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
export interface LspCommandOptions {
|
|
2
2
|
timeoutMs?: number;
|
|
3
|
+
signal?: AbortSignal;
|
|
3
4
|
}
|
|
4
5
|
export interface LspHost {
|
|
5
6
|
executeCommand<T = unknown>(command: string, args?: unknown[], options?: LspCommandOptions): Promise<T>;
|
|
6
7
|
request?<T = unknown>(method: string, params?: unknown, options?: LspCommandOptions): Promise<T>;
|
|
7
8
|
}
|
|
9
|
+
/** True for a DOMException/Error raised because an AbortSignal fired. */
|
|
10
|
+
export declare function isAbortError(error: unknown): boolean;
|
|
11
|
+
/** Build the error a host rejects with when it stops work for an aborted signal. */
|
|
12
|
+
export declare function createAbortError(message?: string): Error;
|
|
13
|
+
/** Rethrow an abort error, ignoring anything else. Used to keep aborts out of `unavailable` paths. */
|
|
14
|
+
export declare function rethrowIfAborted(error: unknown): void;
|
|
15
|
+
/** Throwing guard: clears the way for hosts that poll before each step. */
|
|
16
|
+
export declare function throwIfAborted(signal?: AbortSignal): void;
|
|
8
17
|
export declare function createUnavailableLspHost(message?: string): LspHost;
|
package/dist/host/lsp.js
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAbortError = isAbortError;
|
|
4
|
+
exports.createAbortError = createAbortError;
|
|
5
|
+
exports.rethrowIfAborted = rethrowIfAborted;
|
|
6
|
+
exports.throwIfAborted = throwIfAborted;
|
|
3
7
|
exports.createUnavailableLspHost = createUnavailableLspHost;
|
|
8
|
+
/** True for a DOMException/Error raised because an AbortSignal fired. */
|
|
9
|
+
function isAbortError(error) {
|
|
10
|
+
if (!error || typeof error !== 'object')
|
|
11
|
+
return false;
|
|
12
|
+
const record = error;
|
|
13
|
+
return record.name === 'AbortError' || record.code === 'ABORT_ERR';
|
|
14
|
+
}
|
|
15
|
+
/** Build the error a host rejects with when it stops work for an aborted signal. */
|
|
16
|
+
function createAbortError(message = 'Operation was aborted.') {
|
|
17
|
+
const error = new Error(message);
|
|
18
|
+
error.name = 'AbortError';
|
|
19
|
+
return error;
|
|
20
|
+
}
|
|
21
|
+
/** Rethrow an abort error, ignoring anything else. Used to keep aborts out of `unavailable` paths. */
|
|
22
|
+
function rethrowIfAborted(error) {
|
|
23
|
+
if (isAbortError(error))
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
/** Throwing guard: clears the way for hosts that poll before each step. */
|
|
27
|
+
function throwIfAborted(signal) {
|
|
28
|
+
if (signal?.aborted)
|
|
29
|
+
throw createAbortError(signal.reason instanceof Error ? signal.reason.message : undefined);
|
|
30
|
+
}
|
|
4
31
|
function createUnavailableLspHost(message = 'CWTools LSP is not connected.') {
|
|
5
32
|
return {
|
|
6
33
|
async executeCommand() {
|
|
@@ -17,7 +17,7 @@ const GAME_CACHE_PREFIX = {
|
|
|
17
17
|
vic3: 'vic3',
|
|
18
18
|
};
|
|
19
19
|
function vanillaCacheFileName(game) {
|
|
20
|
-
const prefix = GAME_CACHE_PREFIX[
|
|
20
|
+
const prefix = game ? GAME_CACHE_PREFIX[game.toLowerCase()] : undefined;
|
|
21
21
|
return prefix ? `${prefix}.cwb` : undefined;
|
|
22
22
|
}
|
|
23
23
|
// Read-only tools whose results are only complete when vanilla data is loaded.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './generated/mcpTools';
|
|
2
|
+
export * from './generated/workspaceGameDetection';
|
|
3
|
+
export * from './host/capabilities';
|
|
2
4
|
export * from './host/diagnostics';
|
|
3
5
|
export * from './host/filesystem';
|
|
4
6
|
export * from './host/hostServices';
|
|
@@ -16,10 +18,12 @@ export * from './project/knowledge';
|
|
|
16
18
|
export * from './safety/localisation';
|
|
17
19
|
export * from './safety/paths';
|
|
18
20
|
export * from './safety/writes';
|
|
21
|
+
export * from './tools/callHandler';
|
|
19
22
|
export * from './tools/mcpSchema';
|
|
20
23
|
export * from './tools/names';
|
|
21
24
|
export * from './tools/pdxBlock';
|
|
22
25
|
export * from './tools/registry';
|
|
23
26
|
export * from './tools/schema';
|
|
24
27
|
export * from './tools/symbols';
|
|
28
|
+
export * from './tools/targetingWeights';
|
|
25
29
|
export * from './tools/toolHandlers';
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./generated/mcpTools"), exports);
|
|
18
|
+
__exportStar(require("./generated/workspaceGameDetection"), exports);
|
|
19
|
+
__exportStar(require("./host/capabilities"), exports);
|
|
18
20
|
__exportStar(require("./host/diagnostics"), exports);
|
|
19
21
|
__exportStar(require("./host/filesystem"), exports);
|
|
20
22
|
__exportStar(require("./host/hostServices"), exports);
|
|
@@ -32,10 +34,12 @@ __exportStar(require("./project/knowledge"), exports);
|
|
|
32
34
|
__exportStar(require("./safety/localisation"), exports);
|
|
33
35
|
__exportStar(require("./safety/paths"), exports);
|
|
34
36
|
__exportStar(require("./safety/writes"), exports);
|
|
37
|
+
__exportStar(require("./tools/callHandler"), exports);
|
|
35
38
|
__exportStar(require("./tools/mcpSchema"), exports);
|
|
36
39
|
__exportStar(require("./tools/names"), exports);
|
|
37
40
|
__exportStar(require("./tools/pdxBlock"), exports);
|
|
38
41
|
__exportStar(require("./tools/registry"), exports);
|
|
39
42
|
__exportStar(require("./tools/schema"), exports);
|
|
40
43
|
__exportStar(require("./tools/symbols"), exports);
|
|
44
|
+
__exportStar(require("./tools/targetingWeights"), exports);
|
|
41
45
|
__exportStar(require("./tools/toolHandlers"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HostServices } from '../host/hostServices';
|
|
2
|
+
import { type SharedToolContext, type SharedToolDispatcher } from './toolHandlers';
|
|
3
|
+
import type { SharedToolResult } from './schema';
|
|
4
|
+
/** Per-call context. `signal` cancels the underlying backend work. */
|
|
5
|
+
export type ToolCallContext = SharedToolContext;
|
|
6
|
+
export type SharedToolHandler = (name: string, args?: Record<string, unknown>, context?: ToolCallContext) => Promise<SharedToolResult>;
|
|
7
|
+
export declare const GENERIC_PARADOX_WARNING = "Generic Paradox mode: the exact game is unknown; no game-specific rules or vanilla data are assumed. Pass --game to select a game.";
|
|
8
|
+
export declare function createToolCallHandler(host: HostServices, dispatcher?: SharedToolDispatcher): SharedToolHandler;
|
|
9
|
+
/** Convenience wrapper for hosts that keep one handler per host instance. */
|
|
10
|
+
export declare function bindToolCallHandler(host: HostServices, dispatcher?: SharedToolDispatcher): SharedToolHandler;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GENERIC_PARADOX_WARNING = void 0;
|
|
4
|
+
exports.createToolCallHandler = createToolCallHandler;
|
|
5
|
+
exports.bindToolCallHandler = bindToolCallHandler;
|
|
6
|
+
const lsp_1 = require("../host/lsp");
|
|
7
|
+
const readiness_1 = require("../host/readiness");
|
|
8
|
+
const vanillaCache_1 = require("../host/vanillaCache");
|
|
9
|
+
const mcpSchema_1 = require("./mcpSchema");
|
|
10
|
+
const toolHandlers_1 = require("./toolHandlers");
|
|
11
|
+
exports.GENERIC_PARADOX_WARNING = 'Generic Paradox mode: the exact game is unknown; no game-specific rules or vanilla data are assumed. Pass --game to select a game.';
|
|
12
|
+
function createToolCallHandler(host, dispatcher = toolHandlers_1.defaultSharedToolDispatcher) {
|
|
13
|
+
// The game stays loaded once ready, so probe readiness only until it flips true.
|
|
14
|
+
let ready = false;
|
|
15
|
+
const probeReadiness = async (context) => {
|
|
16
|
+
if (ready)
|
|
17
|
+
return { ready: true };
|
|
18
|
+
try {
|
|
19
|
+
const status = await host.lsp.executeCommand('cwtools.ai.getValidationStatus', [], {
|
|
20
|
+
timeoutMs: 8000,
|
|
21
|
+
...(context?.signal ? { signal: context.signal } : {}),
|
|
22
|
+
});
|
|
23
|
+
const verdict = (0, readiness_1.parseReadiness)(status);
|
|
24
|
+
if (verdict.ready)
|
|
25
|
+
ready = true;
|
|
26
|
+
return verdict;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
// A cancelled probe is not an absent backend: surface the abort instead of
|
|
30
|
+
// reporting `lsp_unavailable`.
|
|
31
|
+
(0, lsp_1.throwIfAborted)(context?.signal);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return async (name, args = {}, context) => {
|
|
36
|
+
(0, lsp_1.throwIfAborted)(context?.signal);
|
|
37
|
+
const writesEnabled = host.writesEnabled === true && host.readonlyMode === false;
|
|
38
|
+
const cwtOnly = host.projectKind === 'cwt-only';
|
|
39
|
+
if (!(0, mcpSchema_1.isMcpToolAvailable)(name, { includeWrites: writesEnabled, cwtOnly })) {
|
|
40
|
+
return {
|
|
41
|
+
ok: false,
|
|
42
|
+
status: 'denied',
|
|
43
|
+
source: 'cwtools-shared',
|
|
44
|
+
error: {
|
|
45
|
+
code: cwtOnly ? 'tool_not_available_in_cwt_only' : 'tool_not_available',
|
|
46
|
+
message: cwtOnly
|
|
47
|
+
? `Tool '${name}' requires a full Paradox game model and is not available in a CWT-only workspace.`
|
|
48
|
+
: `Tool '${name}' is not available under the current host write policy.`,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const result = await dispatcher(host, name, args, context);
|
|
53
|
+
const withGenericWarning = host.projectGameId === 'paradox'
|
|
54
|
+
? {
|
|
55
|
+
...result,
|
|
56
|
+
warnings: [...(result.warnings ?? []), exports.GENERIC_PARADOX_WARNING],
|
|
57
|
+
}
|
|
58
|
+
: result;
|
|
59
|
+
// Tag vanilla-dependent results with cache provenance so clients never read a
|
|
60
|
+
// mod-only answer as complete.
|
|
61
|
+
const withVanilla = (0, vanillaCache_1.annotateVanillaCache)(name, withGenericWarning, host.vanillaCache);
|
|
62
|
+
// For load-dependent tools, mark results produced before the game is ready as
|
|
63
|
+
// `loading` so clients retry instead of trusting an empty answer.
|
|
64
|
+
if (!readiness_1.LOAD_DEPENDENT_TOOLS.has(name))
|
|
65
|
+
return withVanilla;
|
|
66
|
+
return (0, readiness_1.annotateReadiness)(name, withVanilla, await probeReadiness(context));
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Convenience wrapper for hosts that keep one handler per host instance. */
|
|
70
|
+
function bindToolCallHandler(host, dispatcher = toolHandlers_1.defaultSharedToolDispatcher) {
|
|
71
|
+
return createToolCallHandler(host, dispatcher);
|
|
72
|
+
}
|
|
@@ -1,5 +1,27 @@
|
|
|
1
|
+
import { type McpToolName } from './names';
|
|
1
2
|
import type { GeneratedMcpTool, McpToolSchema } from './schema';
|
|
2
3
|
export declare function getGeneratedMcpTools(): readonly GeneratedMcpTool[];
|
|
3
|
-
export declare function listMcpToolSchemas(
|
|
4
|
+
export declare function listMcpToolSchemas(options?: {
|
|
5
|
+
includeWrites?: boolean;
|
|
6
|
+
cwtOnly?: boolean;
|
|
7
|
+
}): McpToolSchema[];
|
|
8
|
+
export declare function isMcpToolAvailable(value: string, options?: {
|
|
9
|
+
includeWrites?: boolean;
|
|
10
|
+
cwtOnly?: boolean;
|
|
11
|
+
}): value is McpToolName;
|
|
12
|
+
/**
|
|
13
|
+
* Transport-neutral aliases.
|
|
14
|
+
*
|
|
15
|
+
* The schema surface is consumed by hosts that have nothing to do with MCP (the
|
|
16
|
+
* Node host, an editor integration, an external agent runtime). Those callers ask
|
|
17
|
+
* for "CWTools tools", not "MCP tools", so the neutral names are the preferred
|
|
18
|
+
* spelling and the MCP-prefixed functions above remain for compatibility.
|
|
19
|
+
*/
|
|
20
|
+
export declare const listCwtoolsToolSchemas: typeof listMcpToolSchemas;
|
|
21
|
+
export declare function isCwtoolsToolAvailable(value: string, options?: {
|
|
22
|
+
includeWrites?: boolean;
|
|
23
|
+
cwtOnly?: boolean;
|
|
24
|
+
}): value is McpToolName;
|
|
25
|
+
export declare function getCwtoolsToolSchema(name: string): McpToolSchema | undefined;
|
|
4
26
|
export declare function getMcpToolSchema(name: string): McpToolSchema | undefined;
|
|
5
27
|
export declare function getMcpToolRegistryMetadata(name: string): GeneratedMcpTool['registry'] | undefined;
|
package/dist/tools/mcpSchema.js
CHANGED
|
@@ -1,15 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listCwtoolsToolSchemas = void 0;
|
|
3
4
|
exports.getGeneratedMcpTools = getGeneratedMcpTools;
|
|
4
5
|
exports.listMcpToolSchemas = listMcpToolSchemas;
|
|
6
|
+
exports.isMcpToolAvailable = isMcpToolAvailable;
|
|
7
|
+
exports.isCwtoolsToolAvailable = isCwtoolsToolAvailable;
|
|
8
|
+
exports.getCwtoolsToolSchema = getCwtoolsToolSchema;
|
|
5
9
|
exports.getMcpToolSchema = getMcpToolSchema;
|
|
6
10
|
exports.getMcpToolRegistryMetadata = getMcpToolRegistryMetadata;
|
|
7
11
|
const mcpTools_1 = require("../generated/mcpTools");
|
|
12
|
+
const names_1 = require("./names");
|
|
8
13
|
function getGeneratedMcpTools() {
|
|
9
14
|
return mcpTools_1.GENERATED_MCP_TOOLS;
|
|
10
15
|
}
|
|
11
|
-
function listMcpToolSchemas() {
|
|
12
|
-
|
|
16
|
+
function listMcpToolSchemas(options) {
|
|
17
|
+
const includeWrites = options?.includeWrites !== false;
|
|
18
|
+
const cwtOnly = options?.cwtOnly === true;
|
|
19
|
+
return mcpTools_1.GENERATED_MCP_TOOLS
|
|
20
|
+
.filter(entry => (includeWrites || !(0, names_1.isMcpWriteToolName)(entry.tool.name))
|
|
21
|
+
&& (!cwtOnly || entry.registry.mcpSupportsCwtOnly))
|
|
22
|
+
.map(entry => ({ ...entry.tool }));
|
|
23
|
+
}
|
|
24
|
+
function isMcpToolAvailable(value, options) {
|
|
25
|
+
if (!(0, names_1.isMcpToolName)(value, options))
|
|
26
|
+
return false;
|
|
27
|
+
if (!options?.cwtOnly)
|
|
28
|
+
return true;
|
|
29
|
+
return mcpTools_1.GENERATED_MCP_TOOLS.find(entry => entry.tool.name === value)?.registry.mcpSupportsCwtOnly === true;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Transport-neutral aliases.
|
|
33
|
+
*
|
|
34
|
+
* The schema surface is consumed by hosts that have nothing to do with MCP (the
|
|
35
|
+
* Node host, an editor integration, an external agent runtime). Those callers ask
|
|
36
|
+
* for "CWTools tools", not "MCP tools", so the neutral names are the preferred
|
|
37
|
+
* spelling and the MCP-prefixed functions above remain for compatibility.
|
|
38
|
+
*/
|
|
39
|
+
exports.listCwtoolsToolSchemas = listMcpToolSchemas;
|
|
40
|
+
function isCwtoolsToolAvailable(value, options) {
|
|
41
|
+
return isMcpToolAvailable(value, options);
|
|
42
|
+
}
|
|
43
|
+
function getCwtoolsToolSchema(name) {
|
|
44
|
+
return getMcpToolSchema(name);
|
|
13
45
|
}
|
|
14
46
|
function getMcpToolSchema(name) {
|
|
15
47
|
return mcpTools_1.GENERATED_MCP_TOOLS.find(entry => entry.tool.name === name)?.tool;
|
package/dist/tools/names.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export
|
|
1
|
+
export declare const MCP_READONLY_TOOL_NAMES: readonly ["query_types", "query_rules", "query_cwt_schema", "search_rule_capabilities", "explain_scope", "parse_pdx_fragment", "query_scope", "get_diagnostics", "analyze_diagnostic_error", "query_project_profile", "query_project_knowledge", "query_workspace_index", "explore_pdx_project", "query_inline_instantiation", "analyze_pdx_flow", "compare_definition_with_vanilla", "query_targeting_weight", "query_localisation_index", "get_pdx_block", "get_completion_at", "document_symbols", "workspace_symbols", "go_to_definition", "find_references", "query_scripted_effects", "query_scripted_triggers", "query_enums", "query_static_modifiers", "query_variables", "get_entity_info", "query_shader_symbol", "query_shader_compile_unit", "query_shader_platform_variants", "query_shader_callers", "explain_shader_reachability", "validate_shader", "compare_shader_with_vanilla", "get_ide_context", "open_in_visual_editor"];
|
|
2
|
+
export declare const MCP_WRITE_TOOL_NAMES: readonly ["write_localisation", "typed_pdx_write", "candidate_transaction", "convert_image_to_dds", "convert_audio", "deploy_mod_asset"];
|
|
3
|
+
export declare const MCP_TOOL_NAMES: readonly ["query_types", "query_rules", "query_cwt_schema", "search_rule_capabilities", "explain_scope", "parse_pdx_fragment", "query_scope", "get_diagnostics", "analyze_diagnostic_error", "query_project_profile", "query_project_knowledge", "query_workspace_index", "explore_pdx_project", "query_inline_instantiation", "analyze_pdx_flow", "compare_definition_with_vanilla", "query_targeting_weight", "query_localisation_index", "get_pdx_block", "get_completion_at", "document_symbols", "workspace_symbols", "go_to_definition", "find_references", "query_scripted_effects", "query_scripted_triggers", "query_enums", "query_static_modifiers", "query_variables", "get_entity_info", "query_shader_symbol", "query_shader_compile_unit", "query_shader_platform_variants", "query_shader_callers", "explain_shader_reachability", "validate_shader", "compare_shader_with_vanilla", "get_ide_context", "open_in_visual_editor"];
|
|
4
|
+
export declare const MCP_ALL_TOOL_NAMES: readonly ["query_types", "query_rules", "query_cwt_schema", "search_rule_capabilities", "explain_scope", "parse_pdx_fragment", "query_scope", "get_diagnostics", "analyze_diagnostic_error", "query_project_profile", "query_project_knowledge", "query_workspace_index", "explore_pdx_project", "query_inline_instantiation", "analyze_pdx_flow", "compare_definition_with_vanilla", "query_targeting_weight", "query_localisation_index", "get_pdx_block", "get_completion_at", "document_symbols", "workspace_symbols", "go_to_definition", "find_references", "query_scripted_effects", "query_scripted_triggers", "query_enums", "query_static_modifiers", "query_variables", "get_entity_info", "query_shader_symbol", "query_shader_compile_unit", "query_shader_platform_variants", "query_shader_callers", "explain_shader_reachability", "validate_shader", "compare_shader_with_vanilla", "get_ide_context", "open_in_visual_editor", "write_localisation", "typed_pdx_write", "candidate_transaction", "convert_image_to_dds", "convert_audio", "deploy_mod_asset"];
|
|
5
|
+
export type McpToolName = typeof MCP_ALL_TOOL_NAMES[number];
|
|
6
|
+
export declare function isMcpToolName(value: string, options?: {
|
|
7
|
+
includeWrites?: boolean;
|
|
8
|
+
}): value is McpToolName;
|
|
6
9
|
export declare function isMcpWriteToolName(value: string): value is typeof MCP_WRITE_TOOL_NAMES[number];
|
package/dist/tools/names.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MCP_ALL_TOOL_NAMES = exports.MCP_TOOL_NAMES = exports.MCP_WRITE_TOOL_NAMES = exports.MCP_READONLY_TOOL_NAMES = void 0;
|
|
4
4
|
exports.isMcpToolName = isMcpToolName;
|
|
5
5
|
exports.isMcpWriteToolName = isMcpWriteToolName;
|
|
6
|
-
exports.
|
|
6
|
+
exports.MCP_READONLY_TOOL_NAMES = [
|
|
7
7
|
'query_types',
|
|
8
8
|
'query_rules',
|
|
9
9
|
'query_cwt_schema',
|
|
@@ -41,13 +41,28 @@ exports.MCP_TOOL_NAMES = [
|
|
|
41
41
|
'explain_shader_reachability',
|
|
42
42
|
'validate_shader',
|
|
43
43
|
'compare_shader_with_vanilla',
|
|
44
|
+
'get_ide_context',
|
|
45
|
+
'open_in_visual_editor',
|
|
44
46
|
];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
exports.MCP_WRITE_TOOL_NAMES = [
|
|
48
|
+
'write_localisation',
|
|
49
|
+
'typed_pdx_write',
|
|
50
|
+
'candidate_transaction',
|
|
51
|
+
'convert_image_to_dds',
|
|
52
|
+
'convert_audio',
|
|
53
|
+
'deploy_mod_asset',
|
|
54
|
+
];
|
|
55
|
+
exports.MCP_TOOL_NAMES = exports.MCP_READONLY_TOOL_NAMES;
|
|
56
|
+
exports.MCP_ALL_TOOL_NAMES = [
|
|
57
|
+
...exports.MCP_READONLY_TOOL_NAMES,
|
|
58
|
+
...exports.MCP_WRITE_TOOL_NAMES,
|
|
59
|
+
];
|
|
60
|
+
function isMcpToolName(value, options) {
|
|
61
|
+
if (exports.MCP_READONLY_TOOL_NAMES.includes(value))
|
|
62
|
+
return true;
|
|
63
|
+
if (options?.includeWrites !== false && exports.MCP_WRITE_TOOL_NAMES.includes(value))
|
|
64
|
+
return true;
|
|
65
|
+
return false;
|
|
51
66
|
}
|
|
52
67
|
function isMcpWriteToolName(value) {
|
|
53
68
|
return exports.MCP_WRITE_TOOL_NAMES.includes(value);
|