@mcp-web/core 0.1.0 → 0.1.2
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/web.d.ts +1 -1
- package/dist/web.js +1 -1
- package/package.json +9 -4
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.d.ts +0 -8
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.d.ts.map +0 -1
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.js +0 -53
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.test.d.ts +0 -2
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/generate-fixed-shape-tools.test.js +0 -331
- package/dist/expanded-schema-tools/index.d.ts +0 -4
- package/dist/expanded-schema-tools/index.d.ts.map +0 -1
- package/dist/expanded-schema-tools/index.js +0 -2
- package/dist/expanded-schema-tools/integration.test.d.ts +0 -2
- package/dist/expanded-schema-tools/integration.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/integration.test.js +0 -599
- package/dist/expanded-schema-tools/schema-analysis.d.ts +0 -18
- package/dist/expanded-schema-tools/schema-analysis.d.ts.map +0 -1
- package/dist/expanded-schema-tools/schema-analysis.js +0 -142
- package/dist/expanded-schema-tools/schema-analysis.test.d.ts +0 -2
- package/dist/expanded-schema-tools/schema-analysis.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/schema-analysis.test.js +0 -314
- package/dist/expanded-schema-tools/schema-helpers.d.ts +0 -69
- package/dist/expanded-schema-tools/schema-helpers.d.ts.map +0 -1
- package/dist/expanded-schema-tools/schema-helpers.js +0 -139
- package/dist/expanded-schema-tools/schema-helpers.test.d.ts +0 -2
- package/dist/expanded-schema-tools/schema-helpers.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/schema-helpers.test.js +0 -223
- package/dist/expanded-schema-tools/tool-generator.d.ts +0 -10
- package/dist/expanded-schema-tools/tool-generator.d.ts.map +0 -1
- package/dist/expanded-schema-tools/tool-generator.js +0 -430
- package/dist/expanded-schema-tools/tool-generator.test.d.ts +0 -2
- package/dist/expanded-schema-tools/tool-generator.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/tool-generator.test.js +0 -689
- package/dist/expanded-schema-tools/types.d.ts +0 -26
- package/dist/expanded-schema-tools/types.d.ts.map +0 -1
- package/dist/expanded-schema-tools/types.js +0 -1
- package/dist/expanded-schema-tools/utils.d.ts +0 -16
- package/dist/expanded-schema-tools/utils.d.ts.map +0 -1
- package/dist/expanded-schema-tools/utils.js +0 -35
- package/dist/expanded-schema-tools/utils.test.d.ts +0 -2
- package/dist/expanded-schema-tools/utils.test.d.ts.map +0 -1
- package/dist/expanded-schema-tools/utils.test.js +0 -169
- package/dist/schema-helpers.d.ts +0 -69
- package/dist/schema-helpers.d.ts.map +0 -1
- package/dist/schema-helpers.js +0 -139
- package/dist/zod-to-tools.d.ts +0 -49
- package/dist/zod-to-tools.d.ts.map +0 -1
- package/dist/zod-to-tools.js +0 -623
package/dist/web.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ import type { QueryRequest } from './types.js';
|
|
|
40
40
|
* name: 'Checkers Game',
|
|
41
41
|
* description: 'Interactive checkers game controllable by AI agents',
|
|
42
42
|
* bridgeUrl: 'localhost:3001',
|
|
43
|
-
* icon: 'https://example.com/icon.
|
|
43
|
+
* icon: 'https://example.com/icon.svg',
|
|
44
44
|
* agentUrl: 'localhost:3003',
|
|
45
45
|
* autoConnect: true,
|
|
46
46
|
* });
|
package/dist/web.js
CHANGED
|
@@ -42,7 +42,7 @@ import { toJSONSchema, toToolMetadataJson } from './utils.js';
|
|
|
42
42
|
* name: 'Checkers Game',
|
|
43
43
|
* description: 'Interactive checkers game controllable by AI agents',
|
|
44
44
|
* bridgeUrl: 'localhost:3001',
|
|
45
|
-
* icon: 'https://example.com/icon.
|
|
45
|
+
* icon: 'https://example.com/icon.svg',
|
|
46
46
|
* agentUrl: 'localhost:3003',
|
|
47
47
|
* autoConnect: true,
|
|
48
48
|
* });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-web/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"ajv": "^8.17.1",
|
|
39
39
|
"zod": "~4.1.12",
|
|
40
|
-
"@mcp-web/bridge": "0.1.
|
|
41
|
-
"@mcp-web/
|
|
42
|
-
"@mcp-web/
|
|
40
|
+
"@mcp-web/bridge": "0.1.2",
|
|
41
|
+
"@mcp-web/types": "0.1.2",
|
|
42
|
+
"@mcp-web/decompose-zod-schema": "0.1.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/json-schema": "^7.0.15",
|
|
@@ -49,6 +49,11 @@
|
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": ">=16.8.0"
|
|
51
51
|
},
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "https://github.com/flekschas/mcp-web",
|
|
55
|
+
"directory": "packages/core"
|
|
56
|
+
},
|
|
52
57
|
"scripts": {
|
|
53
58
|
"dev": "tsc --watch",
|
|
54
59
|
"build": "tsc",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from '@mcp-web/types';
|
|
2
|
-
import type { SchemaShape, ToolGenerationOptions } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Generates getter and setter tools for fixed-shape schemas.
|
|
5
|
-
* Fixed-shape includes: primitives, tuples, and objects with only fixed props.
|
|
6
|
-
*/
|
|
7
|
-
export declare function generateFixedShapeTools(options: ToolGenerationOptions, shape: SchemaShape): ToolDefinition[];
|
|
8
|
-
//# sourceMappingURL=generate-fixed-shape-tools.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-fixed-shape-tools.d.ts","sourceRoot":"","sources":["../../src/expanded-schema-tools/generate-fixed-shape-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGrE;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,KAAK,EAAE,WAAW,GACjB,cAAc,EAAE,CAgDlB"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { deriveSetInputSchema, unwrapSchema } from './schema-helpers.js';
|
|
3
|
-
import { deepMerge } from './utils.js';
|
|
4
|
-
/**
|
|
5
|
-
* Generates getter and setter tools for fixed-shape schemas.
|
|
6
|
-
* Fixed-shape includes: primitives, tuples, and objects with only fixed props.
|
|
7
|
-
*/
|
|
8
|
-
export function generateFixedShapeTools(options, shape) {
|
|
9
|
-
const { name, description, get, set, schema } = options;
|
|
10
|
-
const tools = [];
|
|
11
|
-
const unwrapped = unwrapSchema(schema);
|
|
12
|
-
// Getter tool
|
|
13
|
-
tools.push({
|
|
14
|
-
name: `get_${name}`,
|
|
15
|
-
description: `Get the current ${description}`,
|
|
16
|
-
inputSchema: z.object({}),
|
|
17
|
-
handler: async () => {
|
|
18
|
-
return get();
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
// Setter tool - behavior depends on subtype
|
|
22
|
-
if (shape.subtype === 'primitive' || shape.subtype === 'tuple') {
|
|
23
|
-
// Full replacement for primitives and tuples
|
|
24
|
-
tools.push({
|
|
25
|
-
name: `set_${name}`,
|
|
26
|
-
description: `Set the ${description}`,
|
|
27
|
-
inputSchema: z.object({ value: schema }),
|
|
28
|
-
handler: async (input) => {
|
|
29
|
-
const validated = schema.parse(input.value);
|
|
30
|
-
set(validated);
|
|
31
|
-
return { success: true, value: validated };
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
else if (shape.subtype === 'object') {
|
|
36
|
-
// Partial update with deep merge for objects
|
|
37
|
-
const objectSchema = unwrapped;
|
|
38
|
-
const setInputSchema = deriveSetInputSchema(objectSchema);
|
|
39
|
-
tools.push({
|
|
40
|
-
name: `set_${name}`,
|
|
41
|
-
description: `Update the ${description} (partial update with deep merge)`,
|
|
42
|
-
inputSchema: setInputSchema,
|
|
43
|
-
handler: async (input) => {
|
|
44
|
-
const current = get();
|
|
45
|
-
const merged = deepMerge(current, input);
|
|
46
|
-
const validated = schema.parse(merged);
|
|
47
|
-
set(validated);
|
|
48
|
-
return { success: true, value: validated };
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return tools;
|
|
53
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-fixed-shape-tools.test.d.ts","sourceRoot":"","sources":["../../src/expanded-schema-tools/generate-fixed-shape-tools.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'bun:test';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { generateFixedShapeTools } from './generate-fixed-shape-tools.js';
|
|
4
|
-
import { analyzeSchemaShape } from './schema-analysis.js';
|
|
5
|
-
import { system } from './schema-helpers.js';
|
|
6
|
-
// ============================================================================
|
|
7
|
-
// Primitive Tools
|
|
8
|
-
// ============================================================================
|
|
9
|
-
test('generateFixedShapeTools() - generates get + set for string', () => {
|
|
10
|
-
let state = 'initial';
|
|
11
|
-
const schema = z.string();
|
|
12
|
-
const shape = analyzeSchemaShape(schema);
|
|
13
|
-
const tools = generateFixedShapeTools({
|
|
14
|
-
name: 'text',
|
|
15
|
-
description: 'text value',
|
|
16
|
-
get: () => state,
|
|
17
|
-
set: (value) => {
|
|
18
|
-
state = value;
|
|
19
|
-
},
|
|
20
|
-
schema,
|
|
21
|
-
}, shape);
|
|
22
|
-
expect(tools).toHaveLength(2);
|
|
23
|
-
expect(tools[0].name).toBe('get_text');
|
|
24
|
-
expect(tools[1].name).toBe('set_text');
|
|
25
|
-
});
|
|
26
|
-
test('generateFixedShapeTools() - get returns current value', async () => {
|
|
27
|
-
let state = 'hello';
|
|
28
|
-
const schema = z.string();
|
|
29
|
-
const shape = analyzeSchemaShape(schema);
|
|
30
|
-
const tools = generateFixedShapeTools({
|
|
31
|
-
name: 'text',
|
|
32
|
-
description: 'text value',
|
|
33
|
-
get: () => state,
|
|
34
|
-
set: (value) => {
|
|
35
|
-
state = value;
|
|
36
|
-
},
|
|
37
|
-
schema,
|
|
38
|
-
}, shape);
|
|
39
|
-
const getter = tools[0];
|
|
40
|
-
const result = await getter.handler({});
|
|
41
|
-
expect(result).toBe('hello');
|
|
42
|
-
});
|
|
43
|
-
test('generateFixedShapeTools() - set uses full replacement for primitives', async () => {
|
|
44
|
-
let state = 'initial';
|
|
45
|
-
const schema = z.string();
|
|
46
|
-
const shape = analyzeSchemaShape(schema);
|
|
47
|
-
const tools = generateFixedShapeTools({
|
|
48
|
-
name: 'text',
|
|
49
|
-
description: 'text value',
|
|
50
|
-
get: () => state,
|
|
51
|
-
set: (value) => {
|
|
52
|
-
state = value;
|
|
53
|
-
},
|
|
54
|
-
schema,
|
|
55
|
-
}, shape);
|
|
56
|
-
const setter = tools[1];
|
|
57
|
-
const result = await setter.handler({ value: 'updated' });
|
|
58
|
-
expect(result).toEqual({ success: true, value: 'updated' });
|
|
59
|
-
expect(state).toBe('updated');
|
|
60
|
-
});
|
|
61
|
-
test('generateFixedShapeTools() - set validates with schema', async () => {
|
|
62
|
-
let state = 5;
|
|
63
|
-
const schema = z.number().min(0).max(10);
|
|
64
|
-
const shape = analyzeSchemaShape(schema);
|
|
65
|
-
const tools = generateFixedShapeTools({
|
|
66
|
-
name: 'count',
|
|
67
|
-
description: 'count value',
|
|
68
|
-
get: () => state,
|
|
69
|
-
set: (value) => {
|
|
70
|
-
state = value;
|
|
71
|
-
},
|
|
72
|
-
schema,
|
|
73
|
-
}, shape);
|
|
74
|
-
const setter = tools[1];
|
|
75
|
-
// Valid value
|
|
76
|
-
await setter.handler({ value: 7 });
|
|
77
|
-
expect(state).toBe(7);
|
|
78
|
-
// Invalid value (out of range) should throw
|
|
79
|
-
try {
|
|
80
|
-
await setter.handler({ value: 15 });
|
|
81
|
-
expect(true).toBe(false); // Should not reach here
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
expect(error).toBeDefined();
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
test('generateFixedShapeTools() - generates get + set for number', () => {
|
|
88
|
-
let state = 42;
|
|
89
|
-
const schema = z.number();
|
|
90
|
-
const shape = analyzeSchemaShape(schema);
|
|
91
|
-
const tools = generateFixedShapeTools({
|
|
92
|
-
name: 'count',
|
|
93
|
-
description: 'count value',
|
|
94
|
-
get: () => state,
|
|
95
|
-
set: (value) => {
|
|
96
|
-
state = value;
|
|
97
|
-
},
|
|
98
|
-
schema,
|
|
99
|
-
}, shape);
|
|
100
|
-
expect(tools).toHaveLength(2);
|
|
101
|
-
expect(tools[0].name).toBe('get_count');
|
|
102
|
-
expect(tools[1].name).toBe('set_count');
|
|
103
|
-
});
|
|
104
|
-
test('generateFixedShapeTools() - generates get + set for boolean', () => {
|
|
105
|
-
let state = true;
|
|
106
|
-
const schema = z.boolean();
|
|
107
|
-
const shape = analyzeSchemaShape(schema);
|
|
108
|
-
const tools = generateFixedShapeTools({
|
|
109
|
-
name: 'active',
|
|
110
|
-
description: 'active flag',
|
|
111
|
-
get: () => state,
|
|
112
|
-
set: (value) => {
|
|
113
|
-
state = value;
|
|
114
|
-
},
|
|
115
|
-
schema,
|
|
116
|
-
}, shape);
|
|
117
|
-
expect(tools).toHaveLength(2);
|
|
118
|
-
expect(tools[0].name).toBe('get_active');
|
|
119
|
-
expect(tools[1].name).toBe('set_active');
|
|
120
|
-
});
|
|
121
|
-
// ============================================================================
|
|
122
|
-
// Tuple Tools
|
|
123
|
-
// ============================================================================
|
|
124
|
-
test('generateFixedShapeTools() - generates get + set for tuple', () => {
|
|
125
|
-
let state = ['hello', 42, true];
|
|
126
|
-
const schema = z.tuple([z.string(), z.number(), z.boolean()]);
|
|
127
|
-
const shape = analyzeSchemaShape(schema);
|
|
128
|
-
const tools = generateFixedShapeTools({
|
|
129
|
-
name: 'coords',
|
|
130
|
-
description: 'coordinates',
|
|
131
|
-
get: () => state,
|
|
132
|
-
set: (value) => {
|
|
133
|
-
state = value;
|
|
134
|
-
},
|
|
135
|
-
schema,
|
|
136
|
-
}, shape);
|
|
137
|
-
expect(tools).toHaveLength(2);
|
|
138
|
-
expect(tools[0].name).toBe('get_coords');
|
|
139
|
-
expect(tools[1].name).toBe('set_coords');
|
|
140
|
-
});
|
|
141
|
-
test('generateFixedShapeTools() - set uses full replacement for tuples', async () => {
|
|
142
|
-
let state = [10, 20];
|
|
143
|
-
const schema = z.tuple([z.number(), z.number()]);
|
|
144
|
-
const shape = analyzeSchemaShape(schema);
|
|
145
|
-
const tools = generateFixedShapeTools({
|
|
146
|
-
name: 'coords',
|
|
147
|
-
description: 'coordinates',
|
|
148
|
-
get: () => state,
|
|
149
|
-
set: (value) => {
|
|
150
|
-
state = value;
|
|
151
|
-
},
|
|
152
|
-
schema,
|
|
153
|
-
}, shape);
|
|
154
|
-
const setter = tools[1];
|
|
155
|
-
const result = await setter.handler({ value: [30, 40] });
|
|
156
|
-
expect(result).toEqual({ success: true, value: [30, 40] });
|
|
157
|
-
expect(state).toEqual([30, 40]);
|
|
158
|
-
});
|
|
159
|
-
// ============================================================================
|
|
160
|
-
// Fixed Object Tools
|
|
161
|
-
// ============================================================================
|
|
162
|
-
test('generateFixedShapeTools() - generates get + set for fixed-shape object', () => {
|
|
163
|
-
let state = { name: 'Alice', age: 30 };
|
|
164
|
-
const schema = z.object({
|
|
165
|
-
name: z.string(),
|
|
166
|
-
age: z.number(),
|
|
167
|
-
});
|
|
168
|
-
const shape = analyzeSchemaShape(schema);
|
|
169
|
-
const tools = generateFixedShapeTools({
|
|
170
|
-
name: 'user',
|
|
171
|
-
description: 'user data',
|
|
172
|
-
get: () => state,
|
|
173
|
-
set: (value) => {
|
|
174
|
-
state = value;
|
|
175
|
-
},
|
|
176
|
-
schema,
|
|
177
|
-
}, shape);
|
|
178
|
-
expect(tools).toHaveLength(2);
|
|
179
|
-
expect(tools[0].name).toBe('get_user');
|
|
180
|
-
expect(tools[1].name).toBe('set_user');
|
|
181
|
-
});
|
|
182
|
-
test('generateFixedShapeTools() - set uses partial update with deep merge', async () => {
|
|
183
|
-
let state = {
|
|
184
|
-
name: 'Alice',
|
|
185
|
-
age: 30,
|
|
186
|
-
settings: { theme: 'dark', notifications: true },
|
|
187
|
-
};
|
|
188
|
-
const schema = z.object({
|
|
189
|
-
name: z.string(),
|
|
190
|
-
age: z.number(),
|
|
191
|
-
settings: z.object({
|
|
192
|
-
theme: z.string(),
|
|
193
|
-
notifications: z.boolean(),
|
|
194
|
-
}),
|
|
195
|
-
});
|
|
196
|
-
const shape = analyzeSchemaShape(schema);
|
|
197
|
-
const tools = generateFixedShapeTools({
|
|
198
|
-
name: 'user',
|
|
199
|
-
description: 'user data',
|
|
200
|
-
get: () => state,
|
|
201
|
-
set: (value) => {
|
|
202
|
-
state = value;
|
|
203
|
-
},
|
|
204
|
-
schema,
|
|
205
|
-
}, shape);
|
|
206
|
-
const setter = tools[1];
|
|
207
|
-
// Partial update - only change age
|
|
208
|
-
await setter.handler({ age: 31 });
|
|
209
|
-
expect(state.age).toBe(31);
|
|
210
|
-
expect(state.name).toBe('Alice'); // Unchanged
|
|
211
|
-
expect(state.settings).toEqual({ theme: 'dark', notifications: true }); // Unchanged
|
|
212
|
-
// Partial update - nested object
|
|
213
|
-
await setter.handler({ settings: { theme: 'light' } });
|
|
214
|
-
expect(state.settings.theme).toBe('light');
|
|
215
|
-
expect(state.settings.notifications).toBe(true); // Preserved via deep merge
|
|
216
|
-
});
|
|
217
|
-
test('generateFixedShapeTools() - set excludes system fields from input schema', () => {
|
|
218
|
-
let state = { id: 'abc', name: 'Alice', created_at: 123456 };
|
|
219
|
-
const schema = z.object({
|
|
220
|
-
id: system(z.string().default(() => crypto.randomUUID())),
|
|
221
|
-
name: z.string(),
|
|
222
|
-
created_at: system(z.number().default(() => Date.now())),
|
|
223
|
-
});
|
|
224
|
-
const shape = analyzeSchemaShape(schema);
|
|
225
|
-
const tools = generateFixedShapeTools({
|
|
226
|
-
name: 'user',
|
|
227
|
-
description: 'user data',
|
|
228
|
-
get: () => state,
|
|
229
|
-
set: (value) => {
|
|
230
|
-
state = value;
|
|
231
|
-
},
|
|
232
|
-
schema,
|
|
233
|
-
}, shape);
|
|
234
|
-
const setter = tools[1];
|
|
235
|
-
const inputSchema = setter.inputSchema;
|
|
236
|
-
// System fields should not be in input schema
|
|
237
|
-
expect('id' in inputSchema.shape).toBe(false);
|
|
238
|
-
expect('created_at' in inputSchema.shape).toBe(false);
|
|
239
|
-
expect('name' in inputSchema.shape).toBe(true);
|
|
240
|
-
});
|
|
241
|
-
test('generateFixedShapeTools() - set makes all fields optional', () => {
|
|
242
|
-
let state = { name: 'Alice', age: 30, email: 'alice@example.com' };
|
|
243
|
-
const schema = z.object({
|
|
244
|
-
name: z.string(),
|
|
245
|
-
age: z.number(),
|
|
246
|
-
email: z.string(),
|
|
247
|
-
});
|
|
248
|
-
const shape = analyzeSchemaShape(schema);
|
|
249
|
-
const tools = generateFixedShapeTools({
|
|
250
|
-
name: 'user',
|
|
251
|
-
description: 'user data',
|
|
252
|
-
get: () => state,
|
|
253
|
-
set: (value) => {
|
|
254
|
-
state = value;
|
|
255
|
-
},
|
|
256
|
-
schema,
|
|
257
|
-
}, shape);
|
|
258
|
-
const setter = tools[1];
|
|
259
|
-
const inputSchema = setter.inputSchema;
|
|
260
|
-
// All fields should be optional
|
|
261
|
-
const emptyResult = inputSchema.safeParse({});
|
|
262
|
-
expect(emptyResult.success).toBe(true);
|
|
263
|
-
const partialResult = inputSchema.safeParse({ name: 'Bob' });
|
|
264
|
-
expect(partialResult.success).toBe(true);
|
|
265
|
-
});
|
|
266
|
-
test('generateFixedShapeTools() - deep merge preserves unspecified fields', async () => {
|
|
267
|
-
let state = {
|
|
268
|
-
user: {
|
|
269
|
-
name: 'Alice',
|
|
270
|
-
email: 'alice@example.com',
|
|
271
|
-
profile: {
|
|
272
|
-
bio: 'Hello',
|
|
273
|
-
avatar: 'avatar.png',
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
};
|
|
277
|
-
const schema = z.object({
|
|
278
|
-
user: z.object({
|
|
279
|
-
name: z.string(),
|
|
280
|
-
email: z.string(),
|
|
281
|
-
profile: z.object({
|
|
282
|
-
bio: z.string(),
|
|
283
|
-
avatar: z.string(),
|
|
284
|
-
}),
|
|
285
|
-
}),
|
|
286
|
-
});
|
|
287
|
-
const shape = analyzeSchemaShape(schema);
|
|
288
|
-
const tools = generateFixedShapeTools({
|
|
289
|
-
name: 'data',
|
|
290
|
-
description: 'data',
|
|
291
|
-
get: () => state,
|
|
292
|
-
set: (value) => {
|
|
293
|
-
state = value;
|
|
294
|
-
},
|
|
295
|
-
schema,
|
|
296
|
-
}, shape);
|
|
297
|
-
const setter = tools[1];
|
|
298
|
-
// Update only deeply nested field
|
|
299
|
-
await setter.handler({
|
|
300
|
-
user: { profile: { bio: 'Updated bio' } },
|
|
301
|
-
});
|
|
302
|
-
expect(state.user.name).toBe('Alice'); // Preserved
|
|
303
|
-
expect(state.user.email).toBe('alice@example.com'); // Preserved
|
|
304
|
-
expect(state.user.profile.bio).toBe('Updated bio'); // Updated
|
|
305
|
-
expect(state.user.profile.avatar).toBe('avatar.png'); // Preserved
|
|
306
|
-
});
|
|
307
|
-
test('generateFixedShapeTools() - set returns success response with value', async () => {
|
|
308
|
-
let state = { name: 'Alice', age: 30 };
|
|
309
|
-
const schema = z.object({
|
|
310
|
-
name: z.string(),
|
|
311
|
-
age: z.number(),
|
|
312
|
-
});
|
|
313
|
-
const shape = analyzeSchemaShape(schema);
|
|
314
|
-
const tools = generateFixedShapeTools({
|
|
315
|
-
name: 'user',
|
|
316
|
-
description: 'user data',
|
|
317
|
-
get: () => state,
|
|
318
|
-
set: (value) => {
|
|
319
|
-
state = value;
|
|
320
|
-
},
|
|
321
|
-
schema,
|
|
322
|
-
}, shape);
|
|
323
|
-
const setter = tools[1];
|
|
324
|
-
const result = await setter.handler({ age: 31 });
|
|
325
|
-
expect(result).toHaveProperty('success', true);
|
|
326
|
-
expect(result).toHaveProperty('value');
|
|
327
|
-
expect(result.value).toEqual({
|
|
328
|
-
name: 'Alice',
|
|
329
|
-
age: 31,
|
|
330
|
-
});
|
|
331
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/expanded-schema-tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"integration.test.d.ts","sourceRoot":"","sources":["../../src/expanded-schema-tools/integration.test.ts"],"names":[],"mappings":""}
|