@llmindset/hf-mcp 0.2.41 → 0.2.43
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/space/commands/invoke.d.ts +6 -0
- package/dist/space/commands/invoke.d.ts.map +1 -0
- package/dist/space/commands/invoke.js +236 -0
- package/dist/space/commands/invoke.js.map +1 -0
- package/dist/space/commands/view-parameters.d.ts +3 -0
- package/dist/space/commands/view-parameters.d.ts.map +1 -0
- package/dist/space/commands/view-parameters.js +144 -0
- package/dist/space/commands/view-parameters.js.map +1 -0
- package/dist/space/space-tool.d.ts +35 -0
- package/dist/space/space-tool.d.ts.map +1 -0
- package/dist/space/space-tool.js +198 -0
- package/dist/space/space-tool.js.map +1 -0
- package/dist/space/types.d.ts +74 -0
- package/dist/space/types.d.ts.map +1 -0
- package/dist/space/types.js +24 -0
- package/dist/space/types.js.map +1 -0
- package/dist/space/utils/parameter-formatter.d.ts +5 -0
- package/dist/space/utils/parameter-formatter.d.ts.map +1 -0
- package/dist/space/utils/parameter-formatter.js +132 -0
- package/dist/space/utils/parameter-formatter.js.map +1 -0
- package/dist/space/utils/result-formatter.d.ts +4 -0
- package/dist/space/utils/result-formatter.d.ts.map +1 -0
- package/dist/space/utils/result-formatter.js +146 -0
- package/dist/space/utils/result-formatter.js.map +1 -0
- package/dist/space/utils/schema-validator.d.ts +9 -0
- package/dist/space/utils/schema-validator.d.ts.map +1 -0
- package/dist/space/utils/schema-validator.js +145 -0
- package/dist/space/utils/schema-validator.js.map +1 -0
- package/dist/space-search.d.ts.map +1 -1
- package/dist/space-search.js +5 -4
- package/dist/space-search.js.map +1 -1
- package/dist/tool-ids.d.ts +4 -2
- package/dist/tool-ids.d.ts.map +1 -1
- package/dist/tool-ids.js +4 -1
- package/dist/tool-ids.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +1 -0
- package/src/space/commands/invoke.ts +335 -0
- package/src/space/commands/view-parameters.ts +204 -0
- package/src/space/space-tool.ts +252 -0
- package/src/space/types.ts +127 -0
- package/src/space/utils/parameter-formatter.ts +200 -0
- package/src/space/utils/result-formatter.ts +226 -0
- package/src/space/utils/schema-validator.ts +232 -0
- package/src/space-search.ts +5 -4
- package/src/tool-ids.ts +4 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { spaceArgsSchema, OPERATION_NAMES } from './types.js';
|
|
2
|
+
import { viewParameters } from './commands/view-parameters.js';
|
|
3
|
+
import { invokeSpace } from './commands/invoke.js';
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
const USAGE_INSTRUCTIONS = `# Gradio Space Interaction
|
|
6
|
+
|
|
7
|
+
Dynamically interact with any Gradio MCP Space. View parameter schemas or invoke spaces with custom parameters.
|
|
8
|
+
|
|
9
|
+
## Supported Schema Types
|
|
10
|
+
|
|
11
|
+
✅ **Simple types** (supported):
|
|
12
|
+
- Strings, numbers, booleans
|
|
13
|
+
- Enums (predefined value sets)
|
|
14
|
+
- Arrays of primitives
|
|
15
|
+
- Shallow objects (one level deep)
|
|
16
|
+
- FileData (as URL strings)
|
|
17
|
+
|
|
18
|
+
❌ **Complex types** (not supported):
|
|
19
|
+
- Deeply nested objects (2+ levels)
|
|
20
|
+
- Arrays of objects
|
|
21
|
+
- Union types
|
|
22
|
+
- Recursive schemas
|
|
23
|
+
|
|
24
|
+
For spaces with complex schemas, direct the user to huggingface.co/settings/mcp to manage their settings.
|
|
25
|
+
|
|
26
|
+
## Available Operations
|
|
27
|
+
|
|
28
|
+
### view_parameters
|
|
29
|
+
Display the parameter schema for a space's first tool.
|
|
30
|
+
|
|
31
|
+
**Example:**
|
|
32
|
+
\`\`\`json
|
|
33
|
+
{
|
|
34
|
+
"operation": "view_parameters",
|
|
35
|
+
"space_name": "evalstate/FLUX1_schnell"
|
|
36
|
+
}
|
|
37
|
+
\`\`\`
|
|
38
|
+
|
|
39
|
+
### invoke
|
|
40
|
+
Execute a space's first tool with provided parameters.
|
|
41
|
+
|
|
42
|
+
**Example:**
|
|
43
|
+
\`\`\`json
|
|
44
|
+
{
|
|
45
|
+
"operation": "invoke",
|
|
46
|
+
"space_name": "evalstate/FLUX1_schnell",
|
|
47
|
+
"parameters": "{\\"prompt\\": \\"a cute cat\\", \\"num_steps\\": 4}"
|
|
48
|
+
}
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
## Workflow
|
|
52
|
+
|
|
53
|
+
1. **Discover parameters** - Use \`view_parameters\` to see what a space accepts
|
|
54
|
+
2. **Invoke the space** - Use \`invoke\` with the required parameters
|
|
55
|
+
3. **Review results** - Get formatted output (text, images, resources)
|
|
56
|
+
|
|
57
|
+
## File Handling
|
|
58
|
+
|
|
59
|
+
For parameters that accept files (FileData types):
|
|
60
|
+
- Provide a publicly accessible URL (http:// or https://)
|
|
61
|
+
- Example: \`{"image": "https://example.com/photo.jpg"}\`
|
|
62
|
+
- To upload local files, use the dedicated gr_* prefixed tool for that space
|
|
63
|
+
|
|
64
|
+
## Tips
|
|
65
|
+
|
|
66
|
+
- The tool automatically applies default values for optional parameters
|
|
67
|
+
- Unknown parameters generate warnings but are still passed through (permissive inputs)
|
|
68
|
+
- Enum parameters show all allowed values in view_parameters
|
|
69
|
+
- Required parameters are clearly marked and validated
|
|
70
|
+
`;
|
|
71
|
+
export const DYNAMIC_SPACE_TOOL_CONFIG = {
|
|
72
|
+
name: 'dynamic_space',
|
|
73
|
+
description: 'Dynamically interact with Gradio MCP Spaces . View parameter schemas or invoke spaces with custom parameters. ' +
|
|
74
|
+
'Supports simple parameter types (strings, numbers, booleans, arrays, enums, shallow objects). ' +
|
|
75
|
+
'Call with no operation for full usage instructions.',
|
|
76
|
+
schema: spaceArgsSchema,
|
|
77
|
+
annotations: {
|
|
78
|
+
title: 'Gradio Space Interaction',
|
|
79
|
+
readOnlyHint: false,
|
|
80
|
+
openWorldHint: true,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
export class SpaceTool {
|
|
84
|
+
hfToken;
|
|
85
|
+
constructor(hfToken) {
|
|
86
|
+
this.hfToken = hfToken;
|
|
87
|
+
}
|
|
88
|
+
async execute(params, extra) {
|
|
89
|
+
const requestedOperation = params.operation;
|
|
90
|
+
if (!requestedOperation) {
|
|
91
|
+
return {
|
|
92
|
+
formatted: USAGE_INSTRUCTIONS,
|
|
93
|
+
totalResults: 1,
|
|
94
|
+
resultsShared: 1,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const normalizedOperation = requestedOperation.toLowerCase();
|
|
98
|
+
if (!isOperationName(normalizedOperation)) {
|
|
99
|
+
return {
|
|
100
|
+
formatted: `Unknown operation: "${requestedOperation}"
|
|
101
|
+
Available operations: ${OPERATION_NAMES.join(', ')}
|
|
102
|
+
|
|
103
|
+
Call this tool with no operation for full usage instructions.`,
|
|
104
|
+
totalResults: 0,
|
|
105
|
+
resultsShared: 0,
|
|
106
|
+
isError: true,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
switch (normalizedOperation) {
|
|
111
|
+
case 'view_parameters':
|
|
112
|
+
return await this.handleViewParameters(params);
|
|
113
|
+
case 'invoke':
|
|
114
|
+
return await this.handleInvoke(params, extra);
|
|
115
|
+
default:
|
|
116
|
+
return {
|
|
117
|
+
formatted: `Unknown operation: "${requestedOperation}"`,
|
|
118
|
+
totalResults: 0,
|
|
119
|
+
resultsShared: 0,
|
|
120
|
+
isError: true,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
126
|
+
return {
|
|
127
|
+
formatted: `Error executing ${requestedOperation}: ${errorMessage}`,
|
|
128
|
+
totalResults: 0,
|
|
129
|
+
resultsShared: 0,
|
|
130
|
+
isError: true,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async handleViewParameters(params) {
|
|
135
|
+
if (!params.space_name) {
|
|
136
|
+
return {
|
|
137
|
+
formatted: `Error: Missing required parameter: "space_name"
|
|
138
|
+
|
|
139
|
+
Example:
|
|
140
|
+
\`\`\`json
|
|
141
|
+
{
|
|
142
|
+
"operation": "view_parameters",
|
|
143
|
+
"space_name": "username/space-name"
|
|
144
|
+
}
|
|
145
|
+
\`\`\``,
|
|
146
|
+
totalResults: 0,
|
|
147
|
+
resultsShared: 0,
|
|
148
|
+
isError: true,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
return await viewParameters(params.space_name, this.hfToken);
|
|
152
|
+
}
|
|
153
|
+
async handleInvoke(params, extra) {
|
|
154
|
+
if (!params.space_name) {
|
|
155
|
+
return {
|
|
156
|
+
formatted: `Error: Missing required parameter: "space_name"
|
|
157
|
+
|
|
158
|
+
Example:
|
|
159
|
+
\`\`\`json
|
|
160
|
+
{
|
|
161
|
+
"operation": "invoke",
|
|
162
|
+
"space_name": "username/space-name",
|
|
163
|
+
"parameters": "{\\"param1\\": \\"value1\\"}"
|
|
164
|
+
}
|
|
165
|
+
\`\`\``,
|
|
166
|
+
totalResults: 0,
|
|
167
|
+
resultsShared: 0,
|
|
168
|
+
isError: true,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (!params.parameters) {
|
|
172
|
+
return {
|
|
173
|
+
formatted: `Error: Missing required parameter: "parameters"
|
|
174
|
+
|
|
175
|
+
The "parameters" field must be a JSON object string containing the space parameters.
|
|
176
|
+
|
|
177
|
+
Example:
|
|
178
|
+
\`\`\`json
|
|
179
|
+
{
|
|
180
|
+
"operation": "invoke",
|
|
181
|
+
"space_name": "${params.space_name}",
|
|
182
|
+
"parameters": "{\\"param1\\": \\"value1\\", \\"param2\\": 42}"
|
|
183
|
+
}
|
|
184
|
+
\`\`\`
|
|
185
|
+
|
|
186
|
+
Use "view_parameters" to see what parameters this space accepts.`,
|
|
187
|
+
totalResults: 0,
|
|
188
|
+
resultsShared: 0,
|
|
189
|
+
isError: true,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return await invokeSpace(params.space_name, params.parameters, this.hfToken, extra);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function isOperationName(value) {
|
|
196
|
+
return OPERATION_NAMES.includes(value);
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=space-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space-tool.js","sourceRoot":"","sources":["../../src/space/space-tool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAyD,MAAM,YAAY,CAAC;AACrH,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,cAAc,YAAY,CAAC;AAK3B,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiE1B,CAAC;AAKF,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACxC,IAAI,EAAE,eAAe;IACrB,WAAW,EACV,gHAAgH;QAChH,gGAAgG;QAChG,qDAAqD;IACtD,MAAM,EAAE,eAAe;IACvB,WAAW,EAAE;QACZ,KAAK,EAAE,0BAA0B;QACjC,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,IAAI;KACnB;CACQ,CAAC;AAKX,MAAM,OAAO,SAAS;IACb,OAAO,CAAU;IAEzB,YAAY,OAAgB;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAOD,KAAK,CAAC,OAAO,CACZ,MAAiB,EACjB,KAA8D;QAE9D,MAAM,kBAAkB,GAAG,MAAM,CAAC,SAAS,CAAC;QAG5C,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACzB,OAAO;gBACN,SAAS,EAAE,kBAAkB;gBAC7B,YAAY,E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OAQR;gBACH,YAAY,EAAE,CAAC;gBACf,aAAa,EAAE,CAAC;gBAChB,OAAO,EAAE,IAAI;aACb,CAAC;QACH,CAAC;QAED,OAAO,MAAM,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9D,CAAC;IAMO,KAAK,CAAC,YAAY,CACzB,MAAiB,EACjB,KAA8D;QAG9D,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACxB,OAAO;gBACN,SAAS,EAAE;;;;;;;;;OASR;gBACH,YAAY,EAAE,CAAC;gBACf,aAAa,EAAE,CAAC;gBAChB,OAAO,EAAE,IAAI;aACb,CAAC;QACH,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACxB,OAAO;gBACN,SAAS,EAAE;;;;;;;;mBAQI,MAAM,CAAC,UAAU;;;;;iEAK6B;gBAC7D,YAAY,EAAE,CAAC;gBACf,aAAa,EAAE,CAAC;gBAChB,OAAO,EAAE,IAAI;aACb,CAAC;QACH,CAAC;QAED,OAAO,MAAM,WAAW,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACrF,CAAC;CACD;AAKD,SAAS,eAAe,CAAC,KAAa;IACrC,OAAQ,eAAqC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const OPERATION_NAMES: readonly ["view_parameters", "invoke"];
|
|
3
|
+
export type OperationName = (typeof OPERATION_NAMES)[number];
|
|
4
|
+
export declare const spaceArgsSchema: z.ZodObject<{
|
|
5
|
+
operation: z.ZodOptional<z.ZodEnum<["view_parameters", "invoke"]>>;
|
|
6
|
+
space_name: z.ZodOptional<z.ZodString>;
|
|
7
|
+
parameters: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
parameters?: string | undefined;
|
|
10
|
+
operation?: "view_parameters" | "invoke" | undefined;
|
|
11
|
+
space_name?: string | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
parameters?: string | undefined;
|
|
14
|
+
operation?: "view_parameters" | "invoke" | undefined;
|
|
15
|
+
space_name?: string | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
export type SpaceArgs = z.infer<typeof spaceArgsSchema>;
|
|
18
|
+
export interface ParameterInfo {
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
required: boolean;
|
|
23
|
+
default?: unknown;
|
|
24
|
+
enum?: unknown[];
|
|
25
|
+
isFileData?: boolean;
|
|
26
|
+
complexType?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface SchemaComplexityResult {
|
|
29
|
+
isSimple: boolean;
|
|
30
|
+
reason?: string;
|
|
31
|
+
parameters: ParameterInfo[];
|
|
32
|
+
toolName: string;
|
|
33
|
+
toolDescription?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ProcessParametersResult {
|
|
36
|
+
valid: boolean;
|
|
37
|
+
parameters?: Record<string, unknown>;
|
|
38
|
+
error?: string;
|
|
39
|
+
warnings?: string[];
|
|
40
|
+
}
|
|
41
|
+
export interface JsonSchemaProperty {
|
|
42
|
+
type?: string;
|
|
43
|
+
title?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
default?: unknown;
|
|
46
|
+
enum?: unknown[];
|
|
47
|
+
format?: string;
|
|
48
|
+
properties?: Record<string, JsonSchemaProperty>;
|
|
49
|
+
items?: JsonSchemaProperty;
|
|
50
|
+
required?: string[];
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
export interface JsonSchema {
|
|
54
|
+
type?: string;
|
|
55
|
+
properties?: Record<string, JsonSchemaProperty>;
|
|
56
|
+
required?: string[];
|
|
57
|
+
description?: string;
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
export declare const FILE_INPUT_HELP_MESSAGE: string;
|
|
61
|
+
export declare function isFileDataProperty(prop: JsonSchemaProperty): boolean;
|
|
62
|
+
export declare function hasFileData(schema: JsonSchema): boolean;
|
|
63
|
+
export interface InvokeResult {
|
|
64
|
+
result: {
|
|
65
|
+
content: unknown[];
|
|
66
|
+
isError?: boolean;
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
};
|
|
69
|
+
warnings: string[];
|
|
70
|
+
totalResults: number;
|
|
71
|
+
resultsShared: number;
|
|
72
|
+
isError?: boolean;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/space/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,eAAe,wCAAyC,CAAC;AACtE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAK7D,eAAO,MAAM,eAAe;;;;;;;;;;;;EAO1B,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAKxD,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAKD,MAAM,WAAW,sBAAsB;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,a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,OAAO,EAAE,OAAO,EAAE,CAAC;QACnB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB,CAAC;IACF,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const OPERATION_NAMES = ['view_parameters', 'invoke'];
|
|
3
|
+
export const spaceArgsSchema = z.object({
|
|
4
|
+
operation: z
|
|
5
|
+
.enum(OPERATION_NAMES)
|
|
6
|
+
.optional()
|
|
7
|
+
.describe('Operation to execute. Valid values: "view_parameters", "invoke"'),
|
|
8
|
+
space_name: z.string().optional().describe('The Hugging Face space ID (format: "username/space-name")'),
|
|
9
|
+
parameters: z.string().optional().describe('For invoke operation: JSON object string of parameters'),
|
|
10
|
+
});
|
|
11
|
+
export const FILE_INPUT_HELP_MESSAGE = 'Provide a publicly accessible URL (http:// or https://) pointing to the file. ' +
|
|
12
|
+
'To upload local files, use the dedicated gr_* prefixed tool for this space, which supports file upload.';
|
|
13
|
+
export function isFileDataProperty(prop) {
|
|
14
|
+
return (prop.title === 'ImageData' ||
|
|
15
|
+
prop.title === 'FileData' ||
|
|
16
|
+
(prop.format?.includes('http') && prop.format?.includes('file')) ||
|
|
17
|
+
false);
|
|
18
|
+
}
|
|
19
|
+
export function hasFileData(schema) {
|
|
20
|
+
if (!schema.properties)
|
|
21
|
+
return false;
|
|
22
|
+
return Object.values(schema.properties).some((prop) => isFileDataProperty(prop));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/space/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAU,CAAC;AAMtE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,SAAS,EAAE,CAAC;SACV,IAAI,CAAC,eAAe,CAAC;SACrB,QAAQ,EAAE;SACV,QAAQ,CAAC,iEAAiE,CAAC;IAC7E,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,2DAA2D,CAAC;IACvG,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wDAAwD,CAAC;CACpG,CAAC,CAAC;AAqEH,MAAM,CAAC,MAAM,uBAAuB,GACnC,gFAAgF;IAChF,yGAAyG,CAAC;AAK3G,MAAM,UAAU,kBAAkB,CAAC,IAAwB;IAC1D,OAAO,CACN,IAAI,CAAC,KAAK,KAAK,WAAW;QAC1B,IAAI,CAAC,KAAK,KAAK,UAAU;QACzB,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAChE,KAAK,CACL,CAAC;AACH,CAAC;AAKD,MAAM,UAAU,WAAW,CAAC,MAAkB;IAC7C,IAAI,CAAC,MAAM,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAErC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SchemaComplexityResult } from '../types.js';
|
|
2
|
+
export declare function formatParameters(schemaResult: SchemaComplexityResult, spaceName: string): string;
|
|
3
|
+
export declare function formatComplexSchemaError(spaceName: string, reason: string): string;
|
|
4
|
+
export declare function formatValidationError(errors: string[], spaceName: string): string;
|
|
5
|
+
//# sourceMappingURL=parameter-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter-formatter.d.ts","sourceRoot":"","sources":["../../../src/space/utils/parameter-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAiB,MAAM,aAAa,CAAC;AAYzE,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CA4BhG;AAwID,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQlF;AAKD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAUjF"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { FILE_INPUT_HELP_MESSAGE } from '../types.js';
|
|
2
|
+
export function formatParameters(schemaResult, spaceName) {
|
|
3
|
+
const { toolName, toolDescription, parameters } = schemaResult;
|
|
4
|
+
let output = `# Parameters for: ${toolName}\n\n`;
|
|
5
|
+
if (toolDescription) {
|
|
6
|
+
output += `**Description:** ${toolDescription}\n\n`;
|
|
7
|
+
}
|
|
8
|
+
const sortedParams = [...parameters].sort((a, b) => {
|
|
9
|
+
if (a.required !== b.required) {
|
|
10
|
+
return a.required ? -1 : 1;
|
|
11
|
+
}
|
|
12
|
+
return a.name.localeCompare(b.name);
|
|
13
|
+
});
|
|
14
|
+
output += `## Parameters:\n\n`;
|
|
15
|
+
for (const param of sortedParams) {
|
|
16
|
+
output += formatParameter(param);
|
|
17
|
+
}
|
|
18
|
+
output += '\n## Usage Example:\n\n';
|
|
19
|
+
output += formatUsageExample(spaceName, parameters);
|
|
20
|
+
return output;
|
|
21
|
+
}
|
|
22
|
+
function formatParameter(param) {
|
|
23
|
+
const badge = param.required ? '[REQUIRED]' : '[OPTIONAL]';
|
|
24
|
+
let output = `### ${param.name} ${badge}\n`;
|
|
25
|
+
output += `- **Type:** ${param.type}\n`;
|
|
26
|
+
if (param.description) {
|
|
27
|
+
output += `- **Description:** ${param.description}\n`;
|
|
28
|
+
}
|
|
29
|
+
if (param.default !== undefined) {
|
|
30
|
+
const defaultStr = formatValue(param.default);
|
|
31
|
+
output += `- **Default:** ${defaultStr}\n`;
|
|
32
|
+
}
|
|
33
|
+
if (param.enum && param.enum.length > 0) {
|
|
34
|
+
const enumStr = param.enum.map((v) => formatValue(v)).join(', ');
|
|
35
|
+
output += `- **Allowed values:** ${enumStr}\n`;
|
|
36
|
+
}
|
|
37
|
+
if (param.isFileData) {
|
|
38
|
+
output += `- **Note:** ${FILE_INPUT_HELP_MESSAGE}\n`;
|
|
39
|
+
}
|
|
40
|
+
output += '\n';
|
|
41
|
+
return output;
|
|
42
|
+
}
|
|
43
|
+
function formatValue(value) {
|
|
44
|
+
if (value === null)
|
|
45
|
+
return 'null';
|
|
46
|
+
if (value === undefined)
|
|
47
|
+
return 'undefined';
|
|
48
|
+
if (typeof value === 'string')
|
|
49
|
+
return `"${value}"`;
|
|
50
|
+
if (typeof value === 'object') {
|
|
51
|
+
try {
|
|
52
|
+
return JSON.stringify(value);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return '[object]';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
59
|
+
return String(value);
|
|
60
|
+
}
|
|
61
|
+
return JSON.stringify(value);
|
|
62
|
+
}
|
|
63
|
+
function formatUsageExample(spaceName, parameters) {
|
|
64
|
+
const exampleParams = {};
|
|
65
|
+
for (const param of parameters.filter((p) => p.required)) {
|
|
66
|
+
exampleParams[param.name] = getExampleValue(param);
|
|
67
|
+
}
|
|
68
|
+
const optionalParams = parameters.filter((p) => !p.required);
|
|
69
|
+
for (let i = 0; i < Math.min(2, optionalParams.length); i++) {
|
|
70
|
+
const param = optionalParams[i];
|
|
71
|
+
if (param) {
|
|
72
|
+
exampleParams[param.name] = getExampleValue(param);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const paramsJson = JSON.stringify(exampleParams, null, 2)
|
|
76
|
+
.split('\n')
|
|
77
|
+
.map((line) => ` ${line}`)
|
|
78
|
+
.join('\n')
|
|
79
|
+
.trim();
|
|
80
|
+
return `\`\`\`json
|
|
81
|
+
{
|
|
82
|
+
"operation": "invoke",
|
|
83
|
+
"space_name": "${spaceName}",
|
|
84
|
+
"parameters": "${paramsJson.replace(/"/g, '\\"')}"
|
|
85
|
+
}
|
|
86
|
+
\`\`\``;
|
|
87
|
+
}
|
|
88
|
+
function getExampleValue(param) {
|
|
89
|
+
if (param.default !== undefined) {
|
|
90
|
+
return formatValue(param.default);
|
|
91
|
+
}
|
|
92
|
+
if (param.enum && param.enum.length > 0) {
|
|
93
|
+
return formatValue(param.enum[0]);
|
|
94
|
+
}
|
|
95
|
+
if (param.isFileData) {
|
|
96
|
+
return '"https://example.com/file.jpg"';
|
|
97
|
+
}
|
|
98
|
+
const baseType = param.type.split(' ')[0]?.split('<')[0];
|
|
99
|
+
switch (baseType) {
|
|
100
|
+
case 'string':
|
|
101
|
+
return '"example value"';
|
|
102
|
+
case 'number':
|
|
103
|
+
case 'integer':
|
|
104
|
+
return '42';
|
|
105
|
+
case 'boolean':
|
|
106
|
+
return 'true';
|
|
107
|
+
case 'array':
|
|
108
|
+
return '["item1", "item2"]';
|
|
109
|
+
case 'object':
|
|
110
|
+
return '{"key": "value"}';
|
|
111
|
+
default:
|
|
112
|
+
return '"value"';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function formatComplexSchemaError(spaceName, reason) {
|
|
116
|
+
return `Error: Schema too complex for space '${spaceName}'.
|
|
117
|
+
|
|
118
|
+
${reason}
|
|
119
|
+
|
|
120
|
+
Supported types: strings, numbers, booleans, arrays of primitives, enums, shallow objects, and file URLs.
|
|
121
|
+
|
|
122
|
+
For this space, use the dedicated gr_* prefixed tools instead.`;
|
|
123
|
+
}
|
|
124
|
+
export function formatValidationError(errors, spaceName) {
|
|
125
|
+
let output = `Error: Invalid parameters for space '${spaceName}'.\n\n`;
|
|
126
|
+
for (const error of errors) {
|
|
127
|
+
output += `- ${error}\n`;
|
|
128
|
+
}
|
|
129
|
+
output += `\nUse the view_parameters operation to see all required parameters and their types.`;
|
|
130
|
+
return output;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=parameter-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter-formatter.js","sourceRoot":"","sources":["../../../src/space/utils/parameter-formatter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAWtD,MAAM,UAAU,gBAAgB,CAAC,YAAoC,EAAE,SAAiB;IACvF,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,YAAY,CAAC;IAE/D,IAAI,MAAM,GAAG,qBAAqB,QAAQ,MAAM,CAAC;IAEjD,IAAI,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,oBAAoB,eAAe,MAAM,CAAC;IACrD,CAAC;IAGD,MAAM,YAAY,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAClD,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC/B,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,MAAM,IAAI,oBAAoB,CAAC;IAE/B,KAAK,MAAM,KAAK,IAAI,YAAY,EA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C;QAC7B,KAAK,QAAQ;YACZ,OAAO,kBAAkB,CAAC;QAC3B;YACC,OAAO,SAAS,CAAC;IACnB,CAAC;AACF,CAAC;AAKD,MAAM,UAAU,wBAAwB,CAAC,SAAiB,EAAE,MAAc;IACzE,OAAO,wCAAwC,SAAS;;EAEvD,MAAM;;;;+DAIuD,CAAC;AAChE,CAAC;AAKD,MAAM,UAAU,qBAAqB,CAAC,MAAgB,EAAE,SAAiB;IACxE,IAAI,MAAM,GAAG,wCAAwC,SAAS,QAAQ,CAAC;IAEvE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,KAAK,IAAI,CAAC;IAC1B,CAAC;IAED,MAAM,IAAI,qFAAqF,CAAC;IAEhG,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
export declare function formatToolResult(result: typeof CallToolResultSchema._type): string;
|
|
3
|
+
export declare function formatWarnings(warnings: string[]): string;
|
|
4
|
+
//# sourceMappingURL=result-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-formatter.d.ts","sourceRoot":"","sources":["../../../src/space/utils/result-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAU/E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,oBAAoB,CAAC,KAAK,GAAG,MAAM,CAalF;AAmMD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAOzD"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
export function formatToolResult(result) {
|
|
2
|
+
if (result.isError) {
|
|
3
|
+
return formatErrorResult(result);
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(result.content) && result.content.length > 0) {
|
|
6
|
+
return formatContentArray(result.content);
|
|
7
|
+
}
|
|
8
|
+
return 'Tool executed successfully (no content returned).';
|
|
9
|
+
}
|
|
10
|
+
function formatErrorResult(result) {
|
|
11
|
+
if (!Array.isArray(result.content) || result.content.length === 0) {
|
|
12
|
+
return 'Error: Tool execution failed (no error details provided).';
|
|
13
|
+
}
|
|
14
|
+
const errorMessages = [];
|
|
15
|
+
for (const item of result.content) {
|
|
16
|
+
if (typeof item === 'string') {
|
|
17
|
+
errorMessages.push(item);
|
|
18
|
+
}
|
|
19
|
+
else if (item && typeof item === 'object') {
|
|
20
|
+
const obj = item;
|
|
21
|
+
if (typeof obj.text === 'string') {
|
|
22
|
+
errorMessages.push(obj.text);
|
|
23
|
+
}
|
|
24
|
+
else if (typeof obj.message === 'string') {
|
|
25
|
+
errorMessages.push(obj.message);
|
|
26
|
+
}
|
|
27
|
+
else if (typeof obj.error === 'string') {
|
|
28
|
+
errorMessages.push(obj.error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (errorMessages.length > 0) {
|
|
33
|
+
return `Error: ${errorMessages.join('\n')}`;
|
|
34
|
+
}
|
|
35
|
+
return 'Error: Tool execution failed.';
|
|
36
|
+
}
|
|
37
|
+
function formatContentArray(content) {
|
|
38
|
+
const formattedItems = [];
|
|
39
|
+
for (const item of content) {
|
|
40
|
+
const formatted = formatContentItem(item);
|
|
41
|
+
if (formatted) {
|
|
42
|
+
formattedItems.push(formatted);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (formattedItems.length === 0) {
|
|
46
|
+
return 'Tool executed successfully (no displayable content).';
|
|
47
|
+
}
|
|
48
|
+
return formattedItems.join('\n\n');
|
|
49
|
+
}
|
|
50
|
+
function formatContentItem(item) {
|
|
51
|
+
if (!item) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (typeof item === 'string') {
|
|
55
|
+
return item;
|
|
56
|
+
}
|
|
57
|
+
if (typeof item !== 'object') {
|
|
58
|
+
if (typeof item === 'number' || typeof item === 'boolean') {
|
|
59
|
+
return String(item);
|
|
60
|
+
}
|
|
61
|
+
return JSON.stringify(item);
|
|
62
|
+
}
|
|
63
|
+
const obj = item;
|
|
64
|
+
const type = typeof obj.type === 'string' ? obj.type.toLowerCase() : undefined;
|
|
65
|
+
switch (type) {
|
|
66
|
+
case 'text':
|
|
67
|
+
return formatTextContent(obj);
|
|
68
|
+
case 'image':
|
|
69
|
+
return formatImageContent(obj);
|
|
70
|
+
case 'resource':
|
|
71
|
+
return formatResourceContent(obj);
|
|
72
|
+
case 'embedded_resource':
|
|
73
|
+
return formatEmbeddedResourceContent(obj);
|
|
74
|
+
default:
|
|
75
|
+
if (typeof obj.text === 'string') {
|
|
76
|
+
return obj.text;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
return JSON.stringify(item, null, 2);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return '[complex object]';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function formatTextContent(obj) {
|
|
87
|
+
if (typeof obj.text === 'string') {
|
|
88
|
+
return obj.text;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
function formatImageContent(obj) {
|
|
93
|
+
const parts = ['[Image Content]'];
|
|
94
|
+
if (typeof obj.mimeType === 'string') {
|
|
95
|
+
parts.push(`Type: ${obj.mimeType}`);
|
|
96
|
+
}
|
|
97
|
+
if (typeof obj.url === 'string') {
|
|
98
|
+
parts.push(`URL: ${obj.url}`);
|
|
99
|
+
}
|
|
100
|
+
if (typeof obj.data === 'string') {
|
|
101
|
+
const dataLength = obj.data.length;
|
|
102
|
+
parts.push(`Data: ${dataLength} characters (base64)`);
|
|
103
|
+
}
|
|
104
|
+
return parts.join('\n');
|
|
105
|
+
}
|
|
106
|
+
function formatResourceContent(obj) {
|
|
107
|
+
const parts = ['[Resource]'];
|
|
108
|
+
const resource = obj.resource;
|
|
109
|
+
if (resource) {
|
|
110
|
+
if (typeof resource.uri === 'string') {
|
|
111
|
+
parts.push(`URI: ${resource.uri}`);
|
|
112
|
+
}
|
|
113
|
+
if (typeof resource.name === 'string') {
|
|
114
|
+
parts.push(`Name: ${resource.name}`);
|
|
115
|
+
}
|
|
116
|
+
if (typeof resource.mimeType === 'string') {
|
|
117
|
+
parts.push(`Type: ${resource.mimeType}`);
|
|
118
|
+
}
|
|
119
|
+
if (typeof resource.description === 'string') {
|
|
120
|
+
parts.push(`Description: ${resource.description}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return parts.join('\n');
|
|
124
|
+
}
|
|
125
|
+
function formatEmbeddedResourceContent(obj) {
|
|
126
|
+
const parts = ['[Embedded Resource]'];
|
|
127
|
+
if (typeof obj.uri === 'string') {
|
|
128
|
+
parts.push(`URI: ${obj.uri}`);
|
|
129
|
+
}
|
|
130
|
+
if (typeof obj.mimeType === 'string') {
|
|
131
|
+
parts.push(`Type: ${obj.mimeType}`);
|
|
132
|
+
}
|
|
133
|
+
if (typeof obj.blob === 'string') {
|
|
134
|
+
const blobLength = obj.blob.length;
|
|
135
|
+
parts.push(`Data: ${blobLength} characters`);
|
|
136
|
+
}
|
|
137
|
+
return parts.join('\n');
|
|
138
|
+
}
|
|
139
|
+
export function formatWarnings(warnings) {
|
|
140
|
+
if (warnings.length === 0) {
|
|
141
|
+
return '';
|
|
142
|
+
}
|
|
143
|
+
const header = warnings.length === 1 ? 'Warning:' : 'Warnings:';
|
|
144
|
+
return `${header}\n${warnings.map((w) => `- ${w}`).join('\n')}\n\n`;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=result-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-formatter.js","sourceRoot":"","sources":["../../../src/space/utils/result-formatter.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,gBAAgB,CAAC,MAAyC;IAEzE,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAA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IAED,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACtC,KAAK,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IACrC,CAAC;IAGD,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,SAAS,UAAU,aAAa,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAKD,MAAM,UAAU,cAAc,CAAC,QAAkB;IAChD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;IAChE,OAAO,GAAG,MAAM,KAAK,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import type { SchemaComplexityResult } from '../types.js';
|
|
3
|
+
export declare function analyzeSchemaComplexity(tool: Tool): SchemaComplexityResult;
|
|
4
|
+
export declare function validateParameters(parameters: Record<string, unknown>, schemaResult: SchemaComplexityResult): {
|
|
5
|
+
valid: boolean;
|
|
6
|
+
errors: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare function applyDefaults(parameters: Record<string, unknown>, schemaResult: SchemaComplexityResult): Record<string, unknown>;
|
|
9
|
+
//# sourceMappingURL=schema-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-validator.d.ts","sourceRoot":"","sources":["../../../src/space/utils/schema-validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAAK,EAGX,sBAAsB,EAEtB,MAAM,aAAa,CAAC;AAmBrB,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,GAAG,sBAAsB,CA8B1E;AAkFD,wBAAgB,kBAAkB,CACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,YAAY,EAAE,sBAAsB,GAClC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAkCtC;AA2CD,wBAAgB,aAAa,CAC5B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,YAAY,EAAE,sBAAsB,GAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAWzB"}
|