Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
83d36de
feat: Migrate to Zod's native `toJSONSchema` for schema conversion an…
LukeSchlangen Jan 2, 2026
9a8f0c6
feat: Include raw model output in generation responses and refine Zod…
LukeSchlangen Jan 2, 2026
d4064bd
fix: Adjust type casting and schema conversion for nullable propertie…
LukeSchlangen Jan 2, 2026
726f99f
chore(next): migrate to zod 4
LukeSchlangen Jan 2, 2026
a945cf6
chore(basic-gemini): remove zod-to-json-schema and fix type errors
LukeSchlangen Jan 5, 2026
793a87f
chore(model-armor): migrate to zod 4
LukeSchlangen Jan 5, 2026
bb60944
chore(vertexai-modelgarden): migrate to zod 4
LukeSchlangen Jan 5, 2026
91c7551
chore(next-app): migrate to zod 4
LukeSchlangen Jan 5, 2026
a65d485
chore(next-app): remove duplicate lockfile
LukeSchlangen Jan 5, 2026
4b6838f
refactor: Upgrade TypeScript to 5.5 and Zod to v4, adapting code to n…
LukeSchlangen Jan 5, 2026
c4d4c9a
fix(express): update ContextProvider to use inferred input type
LukeSchlangen Jan 5, 2026
19b5326
fix(compat-oai): replace AnyZodObject with ZodObject<any>
LukeSchlangen Jan 5, 2026
1736256
fix(compat-oai): cast defineCompatOpenAIModel result to any
LukeSchlangen Jan 5, 2026
f780d75
fix(compat-oai): cast request.config to any to access properties
LukeSchlangen Jan 5, 2026
3fb8cb4
fix(compat-oai): cast resolver to any to avoid type mismatch
LukeSchlangen Jan 5, 2026
6de0ee0
fix(compat-oai): cast request.config to any in utils and grok
LukeSchlangen Jan 5, 2026
ec76d1d
fix(anthropic): cast init/resolve returns to any
LukeSchlangen Jan 5, 2026
175a793
fix(evaluators): update judgeConfig to use z.infer<CustomModelOptions>
LukeSchlangen Jan 5, 2026
4bbdd79
fix(mcp): update prompt stream response and render input types
LukeSchlangen Jan 5, 2026
0fe8c3a
fix(mcp): fix type errors within mcp plugins
LukeSchlangen Jan 5, 2026
22f8e2c
fix(firestore-retriever): update z.record to zod 4
LukeSchlangen Jan 5, 2026
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
3 changes: 1 addition & 2 deletions genkit-tools/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"uuid": "^9.0.1",
"winston": "^3.11.0",
"yaml": "^2.4.1",
"zod": "^3.22.4",
"zod-to-json-schema": "^3.22.4"
"zod": "^4.0.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand Down
29 changes: 8 additions & 21 deletions genkit-tools/common/src/types/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import type { JSONSchema7 } from 'json-schema';
import { z } from 'zod';
import zodToJsonSchema from 'zod-to-json-schema';
import type {
CreateDatasetRequest,
ListEvalKeysRequest,
Expand All @@ -37,34 +36,22 @@ export const ModelInferenceInputSchema = z.union([
GenerateRequestSchema,
]);
export type ModelInferenceInput = z.infer<typeof ModelInferenceInputSchema>;
export const ModelInferenceInputJSONSchema = zodToJsonSchema(
ModelInferenceInputSchema,
{
$refStrategy: 'none',
removeAdditionalStrategy: 'strict',
}
export const ModelInferenceInputJSONSchema = z.toJSONSchema(
ModelInferenceInputSchema
) as JSONSchema7;

/**
* GenerateRequest JSON schema to support eval-inference using models
*/
export const GenerateRequestJSONSchema = zodToJsonSchema(
GenerateRequestSchema,
{
$refStrategy: 'none',
removeAdditionalStrategy: 'strict',
}
export const GenerateRequestJSONSchema = z.toJSONSchema(
GenerateRequestSchema
) as JSONSchema7;

/**
* Combined GenerateInput JSON schema to support eval-inference using models
*/
export const GenerateInputJSONSchema = zodToJsonSchema(
z.union([GenerateRequestSchema, GenerateActionOptionsSchema]),
{
$refStrategy: 'none',
removeAdditionalStrategy: 'strict',
}
export const GenerateInputJSONSchema = z.toJSONSchema(
z.union([GenerateRequestSchema, GenerateActionOptionsSchema])
) as JSONSchema7;

/**
Expand Down Expand Up @@ -252,11 +239,11 @@ export interface EvalStore {

export const DatasetSchemaSchema = z.object({
inputSchema: z
.record(z.any())
.record(z.string(), z.any())
.describe('Valid JSON Schema for the `input` field of dataset entry.')
.optional(),
referenceSchema: z
.record(z.any())
.record(z.string(), z.any())
.describe('Valid JSON Schema for the `reference` field of dataset entry.')
.optional(),
});
Expand Down
10 changes: 5 additions & 5 deletions genkit-tools/common/src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export type Role = z.infer<typeof RoleSchema>;
export const MessageSchema = z.object({
role: RoleSchema,
content: z.array(PartSchema),
metadata: z.record(z.unknown()).optional(),
metadata: z.record(z.string(), z.unknown()).optional(),
});

/**
Expand All @@ -114,7 +114,7 @@ export const ModelInfoSchema = z.object({
/** Friendly label for this model (e.g. "Google AI - Gemini Pro") */
label: z.string().optional(),
/** Model Specific configuration. */
configSchema: z.record(z.any()).optional(),
configSchema: z.record(z.string(), z.any()).optional(),
/** Supported model capabilities. */
supports: z
.object({
Expand Down Expand Up @@ -205,7 +205,7 @@ export type GenerationCommonConfig = typeof GenerationCommonConfigSchema;
*/
export const OutputConfigSchema = z.object({
format: z.string().optional(),
schema: z.record(z.any()).optional(),
schema: z.record(z.string(), z.any()).optional(),
constrained: z.boolean().optional(),
contentType: z.string().optional(),
});
Expand Down Expand Up @@ -267,7 +267,7 @@ export const GenerationUsageSchema = z.object({
outputVideos: z.number().optional(),
inputAudioFiles: z.number().optional(),
outputAudioFiles: z.number().optional(),
custom: z.record(z.number()).optional(),
custom: z.record(z.string(), z.number()).optional(),
thoughtsTokens: z.number().optional(),
cachedContentTokens: z.number().optional(),
});
Expand Down Expand Up @@ -390,7 +390,7 @@ export const GenerateActionOptionsSchema = z.object({
.object({
respond: z.array(ToolResponsePartSchema).optional(),
restart: z.array(ToolRequestPartSchema).optional(),
metadata: z.record(z.any()).optional(),
metadata: z.record(z.string(), z.any()).optional(),
})
.optional(),
/** When true, return tool calls for manual processing instead of automatically resolving them. */
Expand Down
6 changes: 3 additions & 3 deletions genkit-tools/common/src/types/parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const EmptyPartSchema = z.object({
toolRequest: z.never().optional(),
toolResponse: z.never().optional(),
data: z.unknown().optional(),
metadata: z.record(z.unknown()).optional(),
custom: z.record(z.unknown()).optional(),
metadata: z.record(z.string(), z.unknown()).optional(),
custom: z.record(z.string(), z.unknown()).optional(),
reasoning: z.never().optional(),
resource: z.never().optional(),
});
Expand Down Expand Up @@ -152,7 +152,7 @@ export type DataPart = z.infer<typeof DataPartSchema>;
* Zod schema of a custom part.
*/
export const CustomPartSchema = EmptyPartSchema.extend({
custom: z.record(z.any()),
custom: z.record(z.string(), z.any()),
});

/**
Expand Down
2 changes: 1 addition & 1 deletion genkit-tools/common/src/types/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const PromptFrontmatterSchema = z.object({
schema: z.unknown().optional(),
})
.optional(),
metadata: z.record(z.unknown()).optional(),
metadata: z.record(z.string(), z.unknown()).optional(),
});

export type PromptFrontmatter = z.infer<typeof PromptFrontmatterSchema>;
3 changes: 1 addition & 2 deletions genkit-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"only-allow": "^1.2.1",
"rimraf": "^6.0.1",
"tsx": "^4.20.3",
"zod": "^3.25.67",
"zod-to-json-schema": "^3.24.5"
"zod": "^4.0.0"
},
"pnpm": {
"overrides": {
Expand Down
42 changes: 17 additions & 25 deletions genkit-tools/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions genkit-tools/scripts/schema-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import * as fs from 'fs';
import type { JSONSchema7 } from 'json-schema';
import * as path from 'path';
import * as z from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';

/** List of files that contain types to be exported. */
const EXPORTED_TYPE_MODULES = [
Expand Down Expand Up @@ -53,12 +52,11 @@ function generateJsonSchema(modulePaths: string[]): JSONSchema7 {
});
}
// Putting all of the schemas in an object and later extracting out the definitions is the most succinct way.
const { $defs } = zodToJsonSchema(z.object(schemas), {
definitions: schemas,
definitionPath: '$defs',
target: 'jsonSchema7',
}) as JSONSchema7;
return { $schema: 'http://json-schema.org/draft-07/schema#', $defs };
const jsonSchema = z.toJSONSchema(z.object(schemas)) as any;
return {
$schema: 'http://json-schema.org/draft-07/schema#',
$defs: jsonSchema.properties,
};
}

if (!process.argv[2]) {
Expand Down
4 changes: 2 additions & 2 deletions genkit-tools/telemetry-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"async-mutex": "^0.5.0",
"express": "^4.21.0",
"lockfile": "^1.0.4",
"zod": "^3.22.4"
"zod": "^4.0.0"
},
"devDependencies": {
"@types/express": "~4.17.21",
Expand All @@ -48,7 +48,7 @@
"rimraf": "^6.0.1",
"genversion": "^3.2.0",
"tsx": "^4.19.2",
"typescript": "^4.9.0"
"typescript": "^5.5.0"
},
"types": "./lib/types/index.d.ts",
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions js/ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"rimraf": "^6.0.1",
"tsup": "^8.3.5",
"tsx": "^4.19.2",
"typescript": "^4.9.0",
"typescript": "^5.5.0",
"yaml": "^2.7.0"
},
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -166,4 +166,4 @@
]
}
}
}
}
4 changes: 2 additions & 2 deletions js/ai/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ export class Chat {
return response;
}
)
);
) as Promise<GenerateResponse<z.infer<O>>>;
}

sendStream<
O extends z.ZodTypeAny = z.ZodTypeAny,
CustomOptions extends z.ZodTypeAny = typeof GenerationCommonConfigSchema,
>(
options: string | Part[] | GenerateStreamOptions<O, CustomOptions>
): GenerateStreamResponse<z.infer<O>> {
): GenerateStreamResponse<O> {
const channel = new Channel<GenerateResponseChunk>();
const resolvedOptions = resolveSendOptions(options);

Expand Down
2 changes: 1 addition & 1 deletion js/ai/src/check-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ export async function checkOperation<T = unknown>(
message: `Failed to resolve background action from original request: ${operation.action}`,
});
}
return await backgroundAction.check(operation);
return (await backgroundAction.check(operation)) as unknown as Operation<T>;
}
Loading