Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions common/src/types/__tests__/json-provider-compatibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, test } from 'bun:test'
import type { ToolModelMessage } from 'ai'

import type { ProviderMetadata } from '../messages/provider-metadata'

function toLocalProviderMetadata(
options: NonNullable<ToolModelMessage['providerOptions']>,
): ProviderMetadata {
return options
}

describe('AI SDK provider metadata compatibility', () => {
test('accepts provider options containing nested JSON arrays and objects', () => {
const providerOptions: NonNullable<ToolModelMessage['providerOptions']> = {
example: {
enabled: true,
nested: [1, { label: 'readonly JSON value' }],
},
}

expect(toLocalProviderMetadata(providerOptions)).toEqual(providerOptions)
})
})
6 changes: 3 additions & 3 deletions common/src/types/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export type JSONValue =
| string
| number
| boolean
| JSONObject
| JSONArray
| Readonly<JSONObject>
| readonly JSONValue[]
export const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
z.union([
z.null(),
Expand All @@ -26,4 +26,4 @@ export type JSONObject = { [key in string]: JSONValue | undefined }
export const jsonArraySchema: z.ZodType<JSONArray> = z.lazy(() =>
z.array(jsonValueSchema),
)
export type JSONArray = JSONValue[]
export type JSONArray = readonly JSONValue[]
Loading