feat(core): Implement partial execution for all tool nodes (#15168)

This commit is contained in:
Benjamin Schroth
2025-05-12 12:31:17 +02:00
committed by GitHub
parent d12c7ee87f
commit 8b467e3f56
39 changed files with 1129 additions and 279 deletions

View File

@@ -0,0 +1,39 @@
import { z } from 'zod';
export const convertValueBySchema = (value: unknown, schema: any): unknown => {
if (!schema || !value) return value;
if (typeof value === 'string') {
if (schema instanceof z.ZodNumber) {
return Number(value);
} else if (schema instanceof z.ZodBoolean) {
return value.toLowerCase() === 'true';
} else if (schema instanceof z.ZodObject) {
try {
const parsed = JSON.parse(value);
return convertValueBySchema(parsed, schema);
} catch {
return value;
}
}
}
if (schema instanceof z.ZodObject && typeof value === 'object' && value !== null) {
const result: any = {};
for (const [key, val] of Object.entries(value)) {
const fieldSchema = schema.shape[key];
if (fieldSchema) {
result[key] = convertValueBySchema(val, fieldSchema);
} else {
result[key] = val;
}
}
return result;
}
return value;
};
export const convertObjectBySchema = (obj: any, schema: any): any => {
return convertValueBySchema(obj, schema);
};