Skip to content
Merged
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
27 changes: 13 additions & 14 deletions pr-review/package-lock.json

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

3 changes: 1 addition & 2 deletions pr-review/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"mollitia": "0.2.0",
"octokit": "5.0.3",
"parse-diff": "0.11.1",
"zod": "3.25.76",
"zod-to-json-schema": "3.24.6"
"zod": "4.0.5"
},
"devDependencies": {
"@eslint/js": "9.31.0",
Expand Down
7 changes: 3 additions & 4 deletions pr-review/src/ai-core-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ChatMessage, OrchestrationClient, TokenUsage } from "@sap-ai-sdk/orches
import axios from "axios"
import { inspect } from "node:util"
import { z } from "zod"
import { zodToJsonSchema } from "zod-to-json-schema"
import { config } from "./config.js"

let modelName = config.model
Expand Down Expand Up @@ -63,7 +62,7 @@ export async function chatCompletion(messages: ChatMessage[]): Promise<string> {
*/
export async function chatCompletionWithJsonSchema<T extends z.ZodTypeAny>(zodSchema: T, messages: ChatMessage[]): Promise<z.infer<T>> {
process.env.AICORE_SERVICE_KEY = JSON.stringify(config.aicoreServiceKey)
const jsonSchema = zodToJsonSchema(zodSchema)
const jsonSchema = z.toJSONSchema(zodSchema)

let responseJson
try {
Expand Down Expand Up @@ -102,11 +101,11 @@ export async function chatCompletionWithJsonSchema<T extends z.ZodTypeAny>(zodSc
core.info(responseJson)
responseJson = responseJson.slice(responseJson.indexOf("{"), responseJson.lastIndexOf("}") + 1)
try {
return zodSchema.parse(JSON.parse(responseJson)) // eslint-disable-line @typescript-eslint/no-unsafe-return
return zodSchema.parse(JSON.parse(responseJson))
} catch (error) {
if (error instanceof Error) core.warning(`Failed to parse JSON. Trying to replace newlines. Error was: ${error.message}`)
const json = responseJson.replaceAll(/"(?:[^"\\]|\\.)*"/g, matched => matched.replaceAll("\n", String.raw`\n`))
return zodSchema.parse(JSON.parse(json)) // eslint-disable-line @typescript-eslint/no-unsafe-return
return zodSchema.parse(JSON.parse(json))
}
}

Expand Down
6 changes: 3 additions & 3 deletions pr-review/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (process.env.NODE_ENV === "development") {
function parseInput<T extends z.ZodTypeAny>(zodSchema: T, name: string): z.infer<T> {
const value: string = core.getInput(name)
try {
return zodSchema.parse(value) // eslint-disable-line @typescript-eslint/no-unsafe-return
return zodSchema.parse(value)
} catch (error) {
if (error instanceof Error) {
core.error(`Failed to parse input "${name}": \`${value}\``)
Expand All @@ -40,7 +40,7 @@ function parseInput<T extends z.ZodTypeAny>(zodSchema: T, name: string): z.infer
function parseInputAsJson<T extends z.ZodTypeAny>(zodSchema: T, name: string): z.infer<T> {
const json: string = core.getInput(name)
try {
return zodSchema.parse(JSON.parse(json)) // eslint-disable-line @typescript-eslint/no-unsafe-return
return zodSchema.parse(JSON.parse(json))
} catch (error) {
if (error instanceof Error) {
core.error(`Failed to parse input "${name}": \`${json}\``)
Expand All @@ -56,7 +56,7 @@ function parseInputAsArray<T extends z.ZodTypeAny>(zodSchema: T, name: string):
.split(/[\n,]/)
.map(v => v.trim())
.filter(Boolean)
.map(v => zodSchema.parse(v) as z.infer<T>) // eslint-disable-line @typescript-eslint/no-unsafe-return
.map(v => zodSchema.parse(v) as z.infer<T>)
}

function setSecret<T>(value: T): T {
Expand Down
4 changes: 2 additions & 2 deletions pr-review/src/zod-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export const ModelName: ZodType<ChatModel> = z.string()
export type ModelName = z.infer<typeof ModelName>

// DeploymentConfig
export const DeploymentConfig: ZodType<ResourceGroupConfig> = z.record(z.any())
export const DeploymentConfig: ZodType<ResourceGroupConfig> = z.record(z.any(), z.any())
export type DeploymentConfig = z.infer<typeof DeploymentConfig>

// ModelParameters
export const ModelParameters: ZodType<LlmModelParams> = z.record(z.any())
export const ModelParameters: ZodType<LlmModelParams> = z.record(z.any(), z.any())
export type ModelParameters = z.infer<typeof ModelParameters>
17 changes: 13 additions & 4 deletions pr-summary/package-lock.json

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

2 changes: 1 addition & 1 deletion pr-summary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"mollitia": "0.2.0",
"octokit": "5.0.3",
"parse-diff": "0.11.1",
"zod": "3.25.76"
"zod": "4.0.5"
},
"devDependencies": {
"@eslint/js": "9.31.0",
Expand Down
6 changes: 3 additions & 3 deletions pr-summary/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (process.env.NODE_ENV === "development") {
function parseInput<T extends z.ZodTypeAny>(zodSchema: T, name: string): z.infer<T> {
const value: string = core.getInput(name)
try {
return zodSchema.parse(value) // eslint-disable-line @typescript-eslint/no-unsafe-return
return zodSchema.parse(value)
} catch (error) {
if (error instanceof Error) {
core.error(`Failed to parse input "${name}": \`${value}\``)
Expand All @@ -40,7 +40,7 @@ function parseInput<T extends z.ZodTypeAny>(zodSchema: T, name: string): z.infer
function parseInputAsJson<T extends z.ZodTypeAny>(zodSchema: T, name: string): z.infer<T> {
const json: string = core.getInput(name)
try {
return zodSchema.parse(JSON.parse(json)) // eslint-disable-line @typescript-eslint/no-unsafe-return
return zodSchema.parse(JSON.parse(json))
} catch (error) {
if (error instanceof Error) {
core.error(`Failed to parse input "${name}": \`${json}\``)
Expand All @@ -56,7 +56,7 @@ function parseInputAsArray<T extends z.ZodTypeAny>(zodSchema: T, name: string):
.split(/[\n,]/)
.map(v => v.trim())
.filter(Boolean)
.map(v => zodSchema.parse(v) as z.infer<T>) // eslint-disable-line @typescript-eslint/no-unsafe-return
.map(v => zodSchema.parse(v) as z.infer<T>)
}

function setSecret<T>(value: T): T {
Expand Down
4 changes: 2 additions & 2 deletions pr-summary/src/zod-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export const ModelName: ZodType<ChatModel> = z.string()
export type ModelName = z.infer<typeof ModelName>

// DeploymentConfig
export const DeploymentConfig: ZodType<ResourceGroupConfig> = z.record(z.any())
export const DeploymentConfig: ZodType<ResourceGroupConfig> = z.record(z.any(), z.any())
export type DeploymentConfig = z.infer<typeof DeploymentConfig>

// ModelParameters
export const ModelParameters: ZodType<LlmModelParams> = z.record(z.any())
export const ModelParameters: ZodType<LlmModelParams> = z.record(z.any(), z.any())
export type ModelParameters = z.infer<typeof ModelParameters>
Loading