Skip to content
Source
Sign inSign up
TanStack/ai

fix: openAi model names and structure parsing #188

MergedAlemTuzlakmerged 12 commits intomain fromrefs/pull/188/headmerged by AlemTuzlak View on GitHub

AlemTuzlakcommented

🎯 Changes

Fixes #173 Fixes #178 Fixes #186 Fixes #187 Fixes #170

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features

    • OpenAI structured-output conversion now supports anyOf unions (oneOf yields a clear error).
    • Exposed updated list of OpenAI chat models.
  • Bug Fixes

    • Normalized public OpenAI model names to their latest identifiers.
  • Tests

    • Added unit tests for schema conversion, null handling, unions, and arrays/objects.
  • Documentation

    • Removed "Bonus: TanStack Start Integration" sections from multiple READMEs.
  • Chores

    • Added changesets and relaxed JSONSchema index typing for compatibility.
✏️ Tip: You can customize this high-level summary in your review settings.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      📝 Walkthrough

      Walkthrough

      This PR renames OpenAI chat model public names, exports OPENAI_CHAT_MODELS, extends OpenAI structured-output schema conversion to handle unions (anyOf) with explicit errors for unsupported oneOf, adds unit tests for the converter, relaxes the JSONSchema index signature for assignability, removes "TanStack Start Integration" sections from multiple READMEs, and adds changeset files for patch bumps.

      Changes

      Cohort / File(s)Summary
      Model name corrections & export
      packages/typescript/ai-openai/src/model-meta.ts, packages/typescript/ai-openai/src/index.ts
      Updated chat model .name fields to match OpenAI identifiers (added -latest suffixes and chatgpt-4.0 → chatgpt-4o-latest) and re-exported OPENAI_CHAT_MODELS.
      Schema conversion: union support
      packages/typescript/ai-openai/src/utils/schema-converter.ts
      Extended makeOpenAIStructuredOutputCompatible to handle anyOf recursively at property and root levels (apply per-variant required / additionalProperties: false); throws on unsupported oneOf.
      Schema converter tests
      packages/typescript/ai-openai/tests/schema-converter.test.ts
      Added tests for transformNullsToUndefined and makeOpenAIStructuredOutputCompatible, covering null→undefined, nested objects/arrays, and union (anyOf/oneOf) cases.
      Type signature update
      packages/typescript/ai/src/types.ts
      Changed JSONSchema index signature from [key: string]: unknown to [key: string]: any to improve assignability with custom schema shapes.
      README removals (TanStack Start Integration)
      README.md, packages/typescript/ai-client/README.md, packages/typescript/ai-devtools/README.md, packages/typescript/ai-gemini/README.md, packages/typescript/ai-ollama/README.md, packages/typescript/ai-openai/README.md, packages/typescript/ai-react-ui/README.md, packages/typescript/ai-react/README.md, packages/typescript/ai/README.md, packages/typescript/react-ai-devtools/README.md, packages/typescript/solid-ai-devtools/README.md
      Removed the entire "Bonus: TanStack Start Integration" section (headers, explanatory text, and code examples) from multiple package READMEs — documentation-only deletions.
      Changeset / release metadata
      .changeset/full-stars-drop.md, .changeset/mighty-gifts-enter.md
      Added/updated changeset files marking patch bumps for multiple @tanstack packages with short notes (includes @tanstack/ai-openai, @tanstack/ai, @tanstack/ai-solid, devtools and UI packages).

      Sequence Diagram(s)

      (omitted)

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~25 minutes

      • TanStack/ai#166: Overlaps packages/typescript/ai-openai/src/model-meta.ts — related model name identifier and export changes.

      Suggested reviewers

      • jherr

      Poem

      🐰 I hopped through names and schema trees,

      I nudged unions gently with my paws, Tests now hum like carrot breeze, Readmes trimmed, neat as springtime laws, A tiny hop — then nap because.

      Pre-merge checks and finishing touches

      ❌ Failed checks (1 inconclusive)
      Check nameStatusExplanationResolution
      Description check❓ InconclusiveThe PR description references five linked issues (#173, #178, #186, #187, #170) that address various bugs, but lacks implementation details explaining what code changes fix each issue. The checklist items are unchecked, which appears incomplete for a submission.Add a detailed 'Changes' section explaining how each linked issue is addressed in the code (e.g., model name updates, schema converter changes, export additions, README removals).
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title concisely describes the main change: fixing GPT-5 chat model names (e.g., changing 'gpt-5.2-chat' to 'gpt-5.2-chat-latest') which is the primary focus across the changeset.
      Linked Issues check✅ PassedCode changes address all five linked issues: model names updated (#173), JSONSchema index signature changed to 'any' (#178), schema-converter expanded for unions (#186), README sections removed (#170), and changes appear comprehensive for addressing all issues.
      Out of Scope Changes check✅ PassedChanges include model name fixes, schema converter updates, type definition changes, export additions, test additions, and README cleanup—all directly supporting the five linked issues with no detectable out-of-scope modifications.
      Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
      ✨ Finishing touches
      • 📝 Generate docstrings

      📜 Recent review details

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between 9ea46740346c28934862f379bf21d17381ff6b49 and cda48469cb6a25e454ebaa63fbf0ef094603ed8e.

      📒 Files selected for processing (1)
      • packages/typescript/ai-openai/src/index.ts
      🧰 Additional context used
      📓 Path-based instructions (3)
      **/*.{ts,tsx}

      📄 CodeRabbit inference engine (CLAUDE.md)

      **/*.{ts,tsx}: Use tree-shakeable adapter architecture for provider implementations - export specialized adapters (text, embedding, summarize, image) as separate imports from /adapters subpath rather than monolithic adapters Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with toolDefinition() and Zod schema inference Implement isomorphic tool system using toolDefinition() with .server() and .client() implementations for dual-environment execution Use type-safe per-model configuration with provider options typed based on selected model to ensure compile-time safety Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses

      Files:

      • packages/typescript/ai-openai/src/index.ts
      packages/typescript/*/src/index.ts

      📄 CodeRabbit inference engine (CLAUDE.md)

      Export tree-shakeable adapters with clear subpath exports in package.json (e.g., @tanstack/ai/adapters, @tanstack/ai-openai/adapters) to minimize bundle size

      Files:

      • packages/typescript/ai-openai/src/index.ts
      **/*.{ts,tsx,js,jsx}

      📄 CodeRabbit inference engine (CLAUDE.md)

      Use camelCase for function and variable names throughout the codebase

      Files:

      • packages/typescript/ai-openai/src/index.ts
      🧠 Learnings (4)
      📚 Learning: 2025-12-27T20:22:51.232Z
      Learnt from: harry-whorlow
      Repo: TanStack/ai PR: 117
      File: packages/typescript/ai-ollama/src/meta/model-meta-gpt-oss.ts:92-97
      Timestamp: 2025-12-27T20:22:51.232Z
      Learning: In the ai-ollama package's model-meta files (packages/typescript/ai-ollama/src/meta/model-meta-*.ts), capability-related comments follow a standard template format across all files for consistency, even if the comment text doesn't precisely match individual model capabilities. This is an intentional design choice to maintain uniformity across the codebase.

      Applied to files:

      • packages/typescript/ai-openai/src/index.ts
      📚 Learning: 2025-12-13T17:09:09.794Z
      Learnt from: CR
      Repo: TanStack/ai PR: 0
      File: CLAUDE.md:0-0
      Timestamp: 2025-12-13T17:09:09.794Z
      Learning: Applies to packages/typescript/*/src/model-meta.ts : Maintain model metadata files that define provider options and capabilities per model for per-model type safety

      Applied to files:

      • packages/typescript/ai-openai/src/index.ts
      📚 Learning: 2025-12-13T17:09:09.794Z
      Learnt from: CR
      Repo: TanStack/ai PR: 0
      File: CLAUDE.md:0-0
      Timestamp: 2025-12-13T17:09:09.794Z
      Learning: Applies to packages/typescript/*/src/index.ts : Export tree-shakeable adapters with clear subpath exports in package.json (e.g., `tanstack/ai/adapters`, `tanstack/ai-openai/adapters`) to minimize bundle size

      Applied to files:

      • packages/typescript/ai-openai/src/index.ts
      📚 Learning: 2025-12-27T21:39:29.563Z
      Learnt from: harry-whorlow
      Repo: TanStack/ai PR: 117
      File: packages/typescript/ai-ollama/src/meta/model-meta-llama-guard3.ts:70-75
      Timestamp: 2025-12-27T21:39:29.563Z
      Learning: The standard template comments in ai-ollama model-meta files (like "Models with text, image, audio, video (no document)") should not be modified to match individual model capabilities, as they are intentionally kept uniform across all model-meta-*.ts files for consistency, regardless of what each specific model actually supports.

      Applied to files:

      • packages/typescript/ai-openai/src/index.ts
      🔇 Additional comments (1)
      packages/typescript/ai-openai/src/index.ts (1)

      87-87: LGTM! Export addresses user request.

      The addition of OPENAI_CHAT_MODELS export is consistent with existing model constant exports and directly addresses stephansama's request to make chat models publicly accessible. The change maintains the established pattern and supports tree-shaking.


      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit f9239fb12afc81b117c10ed2631c7a26e3bcce81

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded2m 40sView ↗
      nx run-many --targets=build --exclude=examples/**✅ Succeeded1m 5sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-01-05 16:13:41 UTC

    3. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented

      Open in StackBlitz

      @tanstack/ai

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@188

      @tanstack/ai-anthropic

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@188

      @tanstack/ai-client

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@188

      @tanstack/ai-devtools-core

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@188

      @tanstack/ai-gemini

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@188

      @tanstack/ai-ollama

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@188

      @tanstack/ai-openai

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@188

      @tanstack/ai-preact

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@188

      @tanstack/ai-react

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@188

      @tanstack/ai-react-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@188

      @tanstack/ai-solid

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@188

      @tanstack/ai-solid-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@188

      @tanstack/ai-svelte

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@188

      @tanstack/ai-vue

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@188

      @tanstack/ai-vue-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@188

      @tanstack/react-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@188

      @tanstack/solid-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@188

      commit: f9239fb

    4. @@ -75,3 +75,4 @@
      7575 prop.items.required || [],
      7676 ),
      7777 }
      78+ } else if (prop.anyOf || prop.oneOf) {
      AlemTuzlakcommented

      ah you're right, thank you! Wanted to cover both while I was at it 😓

    5. Actionable comments posted: 1

      📜 Review details

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between a8667216fd081be1629f47a531ff3a39052b1156 and 433e57ac3c4858a1c9692bb928bd4730ed65156b.

      📒 Files selected for processing (5)
      • .changeset/full-stars-drop.md
      • packages/typescript/ai-openai/src/model-meta.ts
      • packages/typescript/ai-openai/src/utils/schema-converter.ts
      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      • packages/typescript/ai/src/types.ts
      🧰 Additional context used
      📓 Path-based instructions (4)
      **/*.{ts,tsx}

      📄 CodeRabbit inference engine (CLAUDE.md)

      **/*.{ts,tsx}: Use tree-shakeable adapter architecture for provider implementations - export specialized adapters (text, embedding, summarize, image) as separate imports from /adapters subpath rather than monolithic adapters Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with toolDefinition() and Zod schema inference Implement isomorphic tool system using toolDefinition() with .server() and .client() implementations for dual-environment execution Use type-safe per-model configuration with provider options typed based on selected model to ensure compile-time safety Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses

      Files:

      • packages/typescript/ai/src/types.ts
      • packages/typescript/ai-openai/src/model-meta.ts
      • packages/typescript/ai-openai/src/utils/schema-converter.ts
      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      **/*.{ts,tsx,js,jsx}

      📄 CodeRabbit inference engine (CLAUDE.md)

      Use camelCase for function and variable names throughout the codebase

      Files:

      • packages/typescript/ai/src/types.ts
      • packages/typescript/ai-openai/src/model-meta.ts
      • packages/typescript/ai-openai/src/utils/schema-converter.ts
      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      packages/typescript/*/src/model-meta.ts

      📄 CodeRabbit inference engine (CLAUDE.md)

      Maintain model metadata files that define provider options and capabilities per model for per-model type safety

      Files:

      • packages/typescript/ai-openai/src/model-meta.ts
      **/*.test.ts

      📄 CodeRabbit inference engine (CLAUDE.md)

      Write unit tests using Vitest alongside source files with .test.ts naming convention

      Files:

      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      🧠 Learnings (3)
      📚 Learning: 2025-12-13T17:09:09.794Z
      Learnt from: CR
      Repo: TanStack/ai PR: 0
      File: CLAUDE.md:0-0
      Timestamp: 2025-12-13T17:09:09.794Z
      Learning: Applies to packages/typescript/*/src/index.ts : Export tree-shakeable adapters with clear subpath exports in package.json (e.g., `tanstack/ai/adapters`, `tanstack/ai-openai/adapters`) to minimize bundle size

      Applied to files:

      • packages/typescript/ai/src/types.ts
      📚 Learning: 2025-12-13T17:09:09.794Z
      Learnt from: CR
      Repo: TanStack/ai PR: 0
      File: CLAUDE.md:0-0
      Timestamp: 2025-12-13T17:09:09.794Z
      Learning: Applies to **/*.{ts,tsx} : Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with `toolDefinition()` and Zod schema inference

      Applied to files:

      • packages/typescript/ai/src/types.ts
      • packages/typescript/ai-openai/src/utils/schema-converter.ts
      📚 Learning: 2025-12-13T17:09:09.794Z
      Learnt from: CR
      Repo: TanStack/ai PR: 0
      File: CLAUDE.md:0-0
      Timestamp: 2025-12-13T17:09:09.794Z
      Learning: Applies to packages/typescript/*/src/model-meta.ts : Maintain model metadata files that define provider options and capabilities per model for per-model type safety

      Applied to files:

      • packages/typescript/ai/src/types.ts
      • packages/typescript/ai-openai/src/model-meta.ts
      ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
      • GitHub Check: Test
      • GitHub Check: Preview
      🔇 Additional comments (7)
      packages/typescript/ai/src/types.ts (1)

      63-63: LGTM: Index signature change improves type compatibility.

      Changing from unknown to any resolves type assignment issues when using custom JSON Schema definitions with toolDefinition(), as noted in issue #178. While this reduces type safety, it's appropriate for JSON Schema's dynamic nature and aligns with the extensibility goal noted in the comment.

      packages/typescript/ai-openai/src/utils/schema-converter.ts (3)

      64-83: LGTM: Property-level union handling correctly added.

      The new logic recursively transforms anyOf and oneOf properties, ensuring each union variant receives proper OpenAI structured output compatibility (including additionalProperties: false). This addresses issue #186.


      115-120: LGTM: Schema-level anyOf handling implemented correctly.

      Each variant in anyOf unions is recursively transformed with its own required array, ensuring OpenAI compatibility for union schemas.


      122-127: LGTM: Schema-level oneOf handling mirrors anyOf approach.

      The oneOf handling correctly applies the same recursive transformation pattern as anyOf, ensuring discriminated union schemas are compatible with OpenAI's requirements.

      packages/typescript/ai-openai/tests/schema-converter.test.ts (2)

      7-29: LGTM: Comprehensive tests for transformNullsToUndefined.

      The test suite covers null-to-undefined conversion, nested object pruning, array handling, and value preservation. All test cases are well-structured and validate the expected behavior.


      31-183: LGTM: Thorough test coverage for OpenAI schema transformation.

      The test suite validates all key behaviors:

      • additionalProperties: false enforcement
      • Required property augmentation
      • Nullable optional fields
      • Union type handling (anyOf/oneOf) with recursive transformation
      • Nested structures within unions
      • Array item schemas

      All tests are well-structured and align with the implementation changes for structured output union support.

      packages/typescript/ai-openai/src/model-meta.ts (1)

      136-136: Verify updated model names match OpenAI's API.

      The model name updates to gpt-5.2-chat-latest, gpt-5.1-chat-latest, and chatgpt-4o-latest align with valid OpenAI API identifiers as of December 2025. However, verify that any hardcoded references to the old model names in examples, tests, or documentation are also updated.

      .changeset/full-stars-drop.md line 7OutdatedResolvedby AlemTuzlak
    6. Actionable comments posted: 1

      🧹 Nitpick comments (2)
      packages/typescript/ai-openai/tests/schema-converter.test.ts (2)

      7-29: Consider adding edge case tests for deeply nested structures.

      The current test coverage is solid for the core functionality. However, consider adding tests for:

      • Deeply nested structures (3+ levels of nesting)
      • Empty objects and arrays
      • Mixed arrays containing objects, arrays, and primitives

      These additions would strengthen confidence in the recursive transformation logic.

      💡 Example additional test cases
      +  it('should handle deeply nested structures', () => {
      +    const input = {
      +      level1: {
      +        level2: {
      +          level3: { value: null, keep: 'this' }
      +        }
      +      }
      +    }
      +    const result = transformNullsToUndefined(input)
      +    expect(result).toEqual({ level1: { level2: { level3: { keep: 'this' } } } })
      +  })
      +
      +  it('should handle empty objects and arrays', () => {
      +    expect(transformNullsToUndefined({})).toEqual({})
      +    expect(transformNullsToUndefined([])).toEqual([])
      +  })

      31-154: Add test coverage for root-level anyOf and additional type scenarios.

      The implementation (per relevant code snippets) handles root-level anyOf schemas where the schema itself contains an anyOf array, not just anyOf in properties. This important case is not tested.

      Additionally, the optional-fields-nullable test (lines 59-72) only covers string types. Other primitive types and edge cases should be verified.

      🔎 Suggested additional test cases
      it('should handle root-level anyOf schemas', () => {
        const schema = {
          anyOf: [
            {
              type: 'object',
              properties: { a: { type: 'string' } },
              required: ['a'],
            },
            {
              type: 'object',
              properties: { b: { type: 'number' } },
              required: ['b'],
            },
          ],
        }
      
        const result = makeOpenAIStructuredOutputCompatible(schema)
        
        // Each root-level anyOf variant should have additionalProperties: false
        expect(result.anyOf[0].additionalProperties).toBe(false)
        expect(result.anyOf[1].additionalProperties).toBe(false)
        expect(result.anyOf).toHaveLength(2)
      })
      
      it('should handle nullable optional fields of different types', () => {
        const schema = {
          type: 'object',
          properties: {
            optString: { type: 'string' },
            optNumber: { type: 'number' },
            optBoolean: { type: 'boolean' },
            optArray: { type: 'array', items: { type: 'string' } },
          },
          required: [],
        }
      
        const result = makeOpenAIStructuredOutputCompatible(schema, [])
        
        expect(result.properties.optString.type).toEqual(['string', 'null'])
        expect(result.properties.optNumber.type).toEqual(['number', 'null'])
        expect(result.properties.optBoolean.type).toEqual(['boolean', 'null'])
        expect(result.properties.optArray.type).toEqual(['array', 'null'])
      })

      Based on relevant code snippets showing that makeOpenAIStructuredOutputCompatible handles root-level anyOf schemas.

      📜 Review details

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between 433e57ac3c4858a1c9692bb928bd4730ed65156b and 99203e11ab5ae15b6ddfba11636eb5e15b41ce67.

      📒 Files selected for processing (14)
      • .changeset/mighty-gifts-enter.md
      • README.md
      • packages/typescript/ai-client/README.md
      • packages/typescript/ai-devtools/README.md
      • packages/typescript/ai-gemini/README.md
      • packages/typescript/ai-ollama/README.md
      • packages/typescript/ai-openai/README.md
      • packages/typescript/ai-openai/src/utils/schema-converter.ts
      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      • packages/typescript/ai-react-ui/README.md
      • packages/typescript/ai-react/README.md
      • packages/typescript/ai/README.md
      • packages/typescript/react-ai-devtools/README.md
      • packages/typescript/solid-ai-devtools/README.md
      💤 Files with no reviewable changes (11)
      • packages/typescript/ai-client/README.md
      • README.md
      • packages/typescript/solid-ai-devtools/README.md
      • packages/typescript/ai-openai/README.md
      • packages/typescript/ai-react/README.md
      • packages/typescript/ai-gemini/README.md
      • packages/typescript/ai-react-ui/README.md
      • packages/typescript/react-ai-devtools/README.md
      • packages/typescript/ai-ollama/README.md
      • packages/typescript/ai-devtools/README.md
      • packages/typescript/ai/README.md
      ✅ Files skipped from review due to trivial changes (1)
      • .changeset/mighty-gifts-enter.md
      🚧 Files skipped from review as they are similar to previous changes (1)
      • packages/typescript/ai-openai/src/utils/schema-converter.ts
      🧰 Additional context used
      📓 Path-based instructions (3)
      **/*.{ts,tsx}

      📄 CodeRabbit inference engine (CLAUDE.md)

      **/*.{ts,tsx}: Use tree-shakeable adapter architecture for provider implementations - export specialized adapters (text, embedding, summarize, image) as separate imports from /adapters subpath rather than monolithic adapters Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with toolDefinition() and Zod schema inference Implement isomorphic tool system using toolDefinition() with .server() and .client() implementations for dual-environment execution Use type-safe per-model configuration with provider options typed based on selected model to ensure compile-time safety Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses

      Files:

      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      **/*.test.ts

      📄 CodeRabbit inference engine (CLAUDE.md)

      Write unit tests using Vitest alongside source files with .test.ts naming convention

      Files:

      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      **/*.{ts,tsx,js,jsx}

      📄 CodeRabbit inference engine (CLAUDE.md)

      Use camelCase for function and variable names throughout the codebase

      Files:

      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      🧠 Learnings (1)
      📚 Learning: 2025-12-13T17:09:09.794Z
      Learnt from: CR
      Repo: TanStack/ai PR: 0
      File: CLAUDE.md:0-0
      Timestamp: 2025-12-13T17:09:09.794Z
      Learning: Applies to **/*.{ts,tsx} : Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with `toolDefinition()` and Zod schema inference

      Applied to files:

      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      🧬 Code graph analysis (1)
      packages/typescript/ai-openai/tests/schema-converter.test.ts (1)
      packages/typescript/ai-openai/src/utils/schema-converter.ts (2)
      • transformNullsToUndefined (12-35)
      • makeOpenAIStructuredOutputCompatible (48-123)
      ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
      • GitHub Check: Test
      • GitHub Check: Preview
      🔇 Additional comments (2)
      packages/typescript/ai-openai/tests/schema-converter.test.ts (2)

      1-5: LGTM! Clean imports and proper test setup.

      The imports follow the coding guidelines (Vitest for unit tests with .test.ts naming) and correctly reference the source functions.


      103-133: Good coverage of nested object transformation.

      This test effectively verifies the recursive transformation of nested objects within anyOf variants. The assertions check both the variant level and the nested object level, which is excellent.

    7. Actionable comments posted: 1

      🧹 Nitpick comments (2)
      packages/typescript/ai-openai/tests/schema-converter.test.ts (2)

      74-140: LGTM! anyOf handling is thoroughly tested.

      The anyOf tests comprehensively verify:

      • Recursive transformation of union variants
      • additionalProperties: false on each variant
      • Preservation of required fields through transformation
      • Deep nesting within union types

      Consider adding an assertion for the nested object's required array in the second test for complete verification:

      Optional enhancement
         const result = makeOpenAIStructuredOutputCompatible(schema, ['data'])
      
         // The nested object inside anyOf variant should also have additionalProperties: false
         expect(result.properties.data.anyOf[0].additionalProperties).toBe(false)
         expect(
           result.properties.data.anyOf[0].properties.nested.additionalProperties,
         ).toBe(false)
      +  expect(
      +    result.properties.data.anyOf[0].properties.nested.required,
      +  ).toEqual(['x'])

      31-187: Consider adding tests for additional edge cases.

      The current test suite covers the main functionality well. For more comprehensive coverage, consider adding tests for:

      1. Root-level unions: anyOf/oneOf at the schema root rather than within properties
      2. Type arrays: Fields with type: ['string', 'number'] or types that already include 'null'
      3. Optional fields within anyOf variants: Verify nullable transformation applies recursively
      Example tests for edge cases
      it('should handle anyOf at root level', () => {
        const schema = {
          anyOf: [
            {
              type: 'object',
              properties: { a: { type: 'string' } },
              required: ['a'],
            },
            {
              type: 'object',
              properties: { b: { type: 'number' } },
              required: ['b'],
            },
          ],
        }
      
        const result = makeOpenAIStructuredOutputCompatible(schema, [])
        expect(result.anyOf[0].additionalProperties).toBe(false)
        expect(result.anyOf[1].additionalProperties).toBe(false)
      })
      
      it('should handle fields with existing type arrays', () => {
        const schema = {
          type: 'object',
          properties: {
            multiType: { type: ['string', 'number'] },
            alreadyNullable: { type: ['string', 'null'] },
          },
          required: [],
        }
      
        const result = makeOpenAIStructuredOutputCompatible(schema, [])
        expect(result.properties.multiType.type).toEqual(['string', 'number', 'null'])
        expect(result.properties.alreadyNullable.type).toEqual(['string', 'null'])
      })
      📜 Review details

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between ef311605e06280e4b34442cf2c673422a89a4557 and 9ea46740346c28934862f379bf21d17381ff6b49.

      📒 Files selected for processing (2)
      • packages/typescript/ai-openai/src/utils/schema-converter.ts
      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      🚧 Files skipped from review as they are similar to previous changes (1)
      • packages/typescript/ai-openai/src/utils/schema-converter.ts
      🧰 Additional context used
      📓 Path-based instructions (3)
      **/*.{ts,tsx}

      📄 CodeRabbit inference engine (CLAUDE.md)

      **/*.{ts,tsx}: Use tree-shakeable adapter architecture for provider implementations - export specialized adapters (text, embedding, summarize, image) as separate imports from /adapters subpath rather than monolithic adapters Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with toolDefinition() and Zod schema inference Implement isomorphic tool system using toolDefinition() with .server() and .client() implementations for dual-environment execution Use type-safe per-model configuration with provider options typed based on selected model to ensure compile-time safety Implement stream processing with StreamProcessor for handling chunked responses and support partial JSON parsing for streaming AI responses

      Files:

      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      **/*.test.ts

      📄 CodeRabbit inference engine (CLAUDE.md)

      Write unit tests using Vitest alongside source files with .test.ts naming convention

      Files:

      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      **/*.{ts,tsx,js,jsx}

      📄 CodeRabbit inference engine (CLAUDE.md)

      Use camelCase for function and variable names throughout the codebase

      Files:

      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      🧠 Learnings (1)
      📚 Learning: 2025-12-13T17:09:09.794Z
      Learnt from: CR
      Repo: TanStack/ai PR: 0
      File: CLAUDE.md:0-0
      Timestamp: 2025-12-13T17:09:09.794Z
      Learning: Applies to **/*.{ts,tsx} : Use Zod for runtime schema validation and type inference, particularly for tool input/output definitions with `toolDefinition()` and Zod schema inference

      Applied to files:

      • packages/typescript/ai-openai/tests/schema-converter.test.ts
      🧬 Code graph analysis (1)
      packages/typescript/ai-openai/tests/schema-converter.test.ts (1)
      packages/typescript/ai-openai/src/utils/schema-converter.ts (2)
      • transformNullsToUndefined (12-35)
      • makeOpenAIStructuredOutputCompatible (48-134)
      ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
      • GitHub Check: Preview
      • GitHub Check: Test
      🔇 Additional comments (3)
      packages/typescript/ai-openai/tests/schema-converter.test.ts (3)

      7-29: LGTM! Comprehensive coverage of null transformation.

      The test suite thoroughly covers the key behaviors of transformNullsToUndefined:

      • Primitive null conversion to undefined
      • Field pruning for null values in objects (absent rather than undefined)
      • Array element handling (null becomes undefined in place)
      • Preservation of non-null values

      31-72: LGTM! Core transformation behaviors are well tested.

      These tests effectively verify the fundamental OpenAI schema compatibility transformations:

      • Enforcement of additionalProperties: false
      • All properties made required (previously optional fields added to required array)
      • Optional fields made nullable via union types

      142-187: LGTM! Array and oneOf restriction tests are correct.

      These tests properly verify:

      • Recursive transformation of array item schemas
      • Explicit error on oneOf usage (unsupported by OpenAI)

      The error message assertion is sufficient to identify the correct error case.

    8. would it be possible to tack on exporting the chat model names in the main index file? image all of the other models are exported except for the chat models

    9. @stephansama mind opening up an issue? Im off this week and I'll forget this by the time I'm back 😅

    10. @stephansama mind opening up an issue? Im off this week and I'll forget this by the time I'm back 😅

    11. @stephansama mind opening up an issue? Im off this week and I'll forget this by the time I'm back 😅

      Of course! I can also make the changes if that is permissible or just create the issue either or both

    12. @stephansama added the export

    13. harry-whorlow(GitHub profile, opens in a new tab) approved these changes

    14. AlemTuzlak merged this181e0ac

    15. AlemTuzlak closed this

Sign in to join this conversation.