rhachet-brains-openai 0.3.0 → 0.3.1

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.js CHANGED
@@ -819,8 +819,41 @@ var castIntoOpenaiFunctionCallOutput = (input) => ({
819
819
 
820
820
  // src/infra/schema/asJsonSchema.ts
821
821
  var import_zod = require("zod");
822
+ var asOpenaiStrictSchema = (schema) => {
823
+ if (!schema.properties) return schema;
824
+ const requiredSet = new Set(schema.required ?? []);
825
+ const allPropertyNames = Object.keys(schema.properties);
826
+ const propertiesTransformed = {};
827
+ for (const [name, prop] of Object.entries(schema.properties)) {
828
+ const isOptional = !requiredSet.has(name);
829
+ let propTransformed = { ...prop };
830
+ if (prop.type === "object" && prop.properties) {
831
+ propTransformed = asOpenaiStrictSchema(prop);
832
+ }
833
+ if (isOptional && propTransformed.type) {
834
+ const currentType = propTransformed.type;
835
+ if (Array.isArray(currentType)) {
836
+ if (!currentType.includes("null")) {
837
+ propTransformed = {
838
+ ...propTransformed,
839
+ type: [...currentType, "null"]
840
+ };
841
+ }
842
+ } else {
843
+ propTransformed = { ...propTransformed, type: [currentType, "null"] };
844
+ }
845
+ }
846
+ propertiesTransformed[name] = propTransformed;
847
+ }
848
+ return {
849
+ ...schema,
850
+ properties: propertiesTransformed,
851
+ required: allPropertyNames
852
+ };
853
+ };
822
854
  var asJsonSchema = (input) => {
823
- return import_zod.z.toJSONSchema(input.schema, { target: "openAi" });
855
+ const schema = import_zod.z.toJSONSchema(input.schema, { target: "openAi" });
856
+ return asOpenaiStrictSchema(schema);
824
857
  };
825
858
 
826
859
  // src/infra/cast/castIntoOpenaiFunctionTool.ts
@@ -1,12 +1,15 @@
1
1
  import { z } from 'zod';
2
2
  /**
3
3
  * .what = convert a zod schema to JSON schema for native SDK enforcement
4
- * .why = enables native structured output support in SDKs, reducing
4
+ * .why = enables native structured output support in SDKs to reduce
5
5
  * token waste on validation retries
6
6
  *
7
7
  * .note = different SDKs require different conversion options:
8
8
  * - claude-agent-sdk: { $refStrategy: 'root' }
9
9
  * - codex-sdk: { target: 'openAi' }
10
+ *
11
+ * .note = openai strict mode requires all properties in required array
12
+ * with optional properties marked as nullable types
10
13
  */
11
14
  export declare const asJsonSchema: (input: {
12
15
  schema: z.ZodSchema;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "rhachet-brains-openai",
3
3
  "author": "ehmpathy",
4
4
  "description": "rhachet brain.atom and brain.repl adapter for openai",
5
- "version": "0.3.0",
5
+ "version": "0.3.1",
6
6
  "repository": "ehmpathy/rhachet-brains-openai",
7
7
  "homepage": "https://github.com/ehmpathy/rhachet-brains-openai",
8
8
  "keywords": [
@@ -90,11 +90,11 @@
90
90
  "husky": "8.0.3",
91
91
  "iso-time": "1.11.1",
92
92
  "jest": "30.2.0",
93
- "rhachet": "1.37.17",
94
- "rhachet-brains-anthropic": "0.3.3",
95
- "rhachet-roles-bhrain": "0.20.0",
96
- "rhachet-roles-bhuild": "0.14.2",
97
- "rhachet-roles-ehmpathy": "1.29.0",
93
+ "rhachet": "1.37.18",
94
+ "rhachet-brains-anthropic": "0.4.0",
95
+ "rhachet-roles-bhrain": "0.20.2",
96
+ "rhachet-roles-bhuild": "0.14.4",
97
+ "rhachet-roles-ehmpathy": "1.29.2",
98
98
  "test-fns": "1.10.0",
99
99
  "tsc-alias": "1.8.10",
100
100
  "tsx": "4.20.6",