diff --git a/common/src/types/__tests__/json-provider-compatibility.test.ts b/common/src/types/__tests__/json-provider-compatibility.test.ts new file mode 100644 index 0000000000..7a199158ea --- /dev/null +++ b/common/src/types/__tests__/json-provider-compatibility.test.ts @@ -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, +): ProviderMetadata { + return options +} + +describe('AI SDK provider metadata compatibility', () => { + test('accepts provider options containing nested JSON arrays and objects', () => { + const providerOptions: NonNullable = { + example: { + enabled: true, + nested: [1, { label: 'readonly JSON value' }], + }, + } + + expect(toLocalProviderMetadata(providerOptions)).toEqual(providerOptions) + }) +}) diff --git a/common/src/types/json.ts b/common/src/types/json.ts index 244e9a31d8..32433b3d4d 100644 --- a/common/src/types/json.ts +++ b/common/src/types/json.ts @@ -5,8 +5,8 @@ export type JSONValue = | string | number | boolean - | JSONObject - | JSONArray + | Readonly + | readonly JSONValue[] export const jsonValueSchema: z.ZodType = z.lazy(() => z.union([ z.null(), @@ -26,4 +26,4 @@ export type JSONObject = { [key in string]: JSONValue | undefined } export const jsonArraySchema: z.ZodType = z.lazy(() => z.array(jsonValueSchema), ) -export type JSONArray = JSONValue[] +export type JSONArray = readonly JSONValue[]