-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improving the checkpoint output for tools and structured outputs
- Loading branch information
1 parent
faea029
commit 530f723
Showing
8 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Zod Schema Extensions | ||
* | ||
* This module provides extensions to Zod schemas that improve their | ||
* serialization capabilities when used with GenSX's checkpoint system. | ||
*/ | ||
|
||
import { z } from "zod"; | ||
import { zodToJsonSchema } from "zod-to-json-schema"; | ||
|
||
export function extendZodWithToJSON(): void { | ||
// Use type assertion to check for toJSON method | ||
const prototype = z.ZodSchema.prototype as unknown as { | ||
toJSON?: () => Record<string, unknown>; | ||
}; | ||
|
||
// Only add the method once to avoid overriding | ||
if (!prototype.toJSON) { | ||
Object.defineProperty(z.ZodSchema.prototype, "toJSON", { | ||
value: function (this: z.ZodType) { | ||
return zodToJsonSchema(this); | ||
}, | ||
configurable: true, | ||
writable: true, | ||
}); | ||
} | ||
} | ||
|
||
// Execute the extension immediately when this module is imported | ||
extendZodWithToJSON(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Zod Schema Extensions | ||
* | ||
* This module provides extensions to Zod schemas that improve their | ||
* serialization capabilities when used with GenSX's checkpoint system. | ||
*/ | ||
|
||
import { z } from "zod"; | ||
import { zodToJsonSchema } from "zod-to-json-schema"; | ||
|
||
export function extendZodWithToJSON(): void { | ||
// Use type assertion to check for toJSON method | ||
const prototype = z.ZodSchema.prototype as unknown as { | ||
toJSON?: () => Record<string, unknown>; | ||
}; | ||
|
||
// Only add the method once to avoid overriding | ||
if (!prototype.toJSON) { | ||
Object.defineProperty(z.ZodSchema.prototype, "toJSON", { | ||
value: function (this: z.ZodType) { | ||
return zodToJsonSchema(this); | ||
}, | ||
configurable: true, | ||
writable: true, | ||
}); | ||
} | ||
} | ||
|
||
// Execute the extension immediately when this module is imported | ||
extendZodWithToJSON(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters