@midscene/shared 1.7.5 → 1.7.6-beta-20260423130231.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.
|
@@ -68,10 +68,13 @@ function transformSchemaField(key, value) {
|
|
|
68
68
|
value
|
|
69
69
|
];
|
|
70
70
|
}
|
|
71
|
-
function extractActionSchema(paramSchema) {
|
|
71
|
+
function extractActionSchema(paramSchema, actionName) {
|
|
72
72
|
if (!paramSchema) return {};
|
|
73
73
|
const shape = getZodObjectShape(paramSchema);
|
|
74
|
-
if (!shape)
|
|
74
|
+
if (!shape) {
|
|
75
|
+
const typeName = paramSchema?._def?.typeName ?? 'unknown';
|
|
76
|
+
throw new Error(`Action "${actionName}" declared a non-object paramSchema (${typeName}). CLI and MCP tool schemas must be a ZodObject (e.g. z.object({ uri: z.string() })) or undefined. Wrap primitive fields in an object schema.`);
|
|
77
|
+
}
|
|
75
78
|
return Object.fromEntries(Object.entries(shape).map(([key, value])=>transformSchemaField(key, value)));
|
|
76
79
|
}
|
|
77
80
|
function getPromptText(prompt) {
|
|
@@ -289,7 +292,7 @@ function mergeToolCliMetadata(base, extra) {
|
|
|
289
292
|
function generateToolsFromActionSpace(actionSpace, getAgent, sanitizeArgs = (args)=>args, initArgSchema = {}, initArgCliMetadata) {
|
|
290
293
|
return actionSpace.map((action)=>{
|
|
291
294
|
const schema = {
|
|
292
|
-
...extractActionSchema(action.paramSchema),
|
|
295
|
+
...extractActionSchema(action.paramSchema, action.name),
|
|
293
296
|
...initArgSchema
|
|
294
297
|
};
|
|
295
298
|
return {
|
|
@@ -97,10 +97,13 @@ function transformSchemaField(key, value) {
|
|
|
97
97
|
value
|
|
98
98
|
];
|
|
99
99
|
}
|
|
100
|
-
function extractActionSchema(paramSchema) {
|
|
100
|
+
function extractActionSchema(paramSchema, actionName) {
|
|
101
101
|
if (!paramSchema) return {};
|
|
102
102
|
const shape = getZodObjectShape(paramSchema);
|
|
103
|
-
if (!shape)
|
|
103
|
+
if (!shape) {
|
|
104
|
+
const typeName = paramSchema?._def?.typeName ?? 'unknown';
|
|
105
|
+
throw new Error(`Action "${actionName}" declared a non-object paramSchema (${typeName}). CLI and MCP tool schemas must be a ZodObject (e.g. z.object({ uri: z.string() })) or undefined. Wrap primitive fields in an object schema.`);
|
|
106
|
+
}
|
|
104
107
|
return Object.fromEntries(Object.entries(shape).map(([key, value])=>transformSchemaField(key, value)));
|
|
105
108
|
}
|
|
106
109
|
function getPromptText(prompt) {
|
|
@@ -318,7 +321,7 @@ function mergeToolCliMetadata(base, extra) {
|
|
|
318
321
|
function generateToolsFromActionSpace(actionSpace, getAgent, sanitizeArgs = (args)=>args, initArgSchema = {}, initArgCliMetadata) {
|
|
319
322
|
return actionSpace.map((action)=>{
|
|
320
323
|
const schema = {
|
|
321
|
-
...extractActionSchema(action.paramSchema),
|
|
324
|
+
...extractActionSchema(action.paramSchema, action.name),
|
|
322
325
|
...initArgSchema
|
|
323
326
|
};
|
|
324
327
|
return {
|
package/package.json
CHANGED
|
@@ -153,10 +153,19 @@ function transformSchemaField(
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
|
-
* Extract and transform schema from action's paramSchema
|
|
156
|
+
* Extract and transform schema from action's paramSchema.
|
|
157
|
+
*
|
|
158
|
+
* CLI and MCP both expose parameters as named fields, so the only schema
|
|
159
|
+
* shapes we can surface are ZodObject (any number of fields) or undefined
|
|
160
|
+
* (the action takes no parameters). A primitive schema like `z.string()`
|
|
161
|
+
* silently degraded to leaking the ZodString instance's prototype methods
|
|
162
|
+
* as CLI flags — see https://github.com/web-infra-dev/midscene/issues/2313.
|
|
163
|
+
* Reject such schemas up front so the next author gets a loud error
|
|
164
|
+
* instead of a silent misconfiguration at runtime.
|
|
157
165
|
*/
|
|
158
166
|
function extractActionSchema(
|
|
159
167
|
paramSchema: z.ZodTypeAny | undefined,
|
|
168
|
+
actionName: string,
|
|
160
169
|
): Record<string, z.ZodTypeAny> {
|
|
161
170
|
if (!paramSchema) {
|
|
162
171
|
return {};
|
|
@@ -164,7 +173,12 @@ function extractActionSchema(
|
|
|
164
173
|
|
|
165
174
|
const shape = getZodObjectShape(paramSchema);
|
|
166
175
|
if (!shape) {
|
|
167
|
-
|
|
176
|
+
const typeName =
|
|
177
|
+
(paramSchema as unknown as { _def?: { typeName?: string } })?._def
|
|
178
|
+
?.typeName ?? 'unknown';
|
|
179
|
+
throw new Error(
|
|
180
|
+
`Action "${actionName}" declared a non-object paramSchema (${typeName}). CLI and MCP tool schemas must be a ZodObject (e.g. z.object({ uri: z.string() })) or undefined. Wrap primitive fields in an object schema.`,
|
|
181
|
+
);
|
|
168
182
|
}
|
|
169
183
|
|
|
170
184
|
return Object.fromEntries(
|
|
@@ -476,7 +490,7 @@ export function generateToolsFromActionSpace(
|
|
|
476
490
|
): ToolDefinition[] {
|
|
477
491
|
return actionSpace.map((action) => {
|
|
478
492
|
const schema = {
|
|
479
|
-
...extractActionSchema(action.paramSchema as z.ZodTypeAny),
|
|
493
|
+
...extractActionSchema(action.paramSchema as z.ZodTypeAny, action.name),
|
|
480
494
|
...initArgSchema,
|
|
481
495
|
};
|
|
482
496
|
|