Skip to content

Commit eb2f4cc

Browse files
authored
Add: RunSetting schema validation (#14)
* Add: RunSetting schema validation * Chore: Add changeset for RunSetting schema
1 parent a857129 commit eb2f4cc

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@perstack/core": patch
3+
"@perstack/runtime": patch
4+
---
5+
6+
Add runSettingSchema for validating stored run settings

packages/core/src/schemas/runtime.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,34 @@ export type RunParamsInput = {
134134
checkpoint?: Checkpoint
135135
}
136136

137+
export const runSettingSchema = z.object({
138+
model: z.string(),
139+
providerConfig: providerConfigSchema,
140+
runId: z.string(),
141+
expertKey: z.string().min(1).regex(expertKeyRegex),
142+
input: z.object({
143+
text: z.string().optional(),
144+
interactiveToolCallResult: z
145+
.object({
146+
toolCallId: z.string(),
147+
toolName: z.string(),
148+
text: z.string(),
149+
})
150+
.optional(),
151+
}),
152+
experts: z.record(z.string(), expertSchema),
153+
temperature: z.number().min(0).max(1),
154+
maxSteps: z.number().min(1).optional(),
155+
maxRetries: z.number().min(0),
156+
timeout: z.number().min(0),
157+
startedAt: z.number(),
158+
updatedAt: z.number(),
159+
perstackApiBaseUrl: z.string().url(),
160+
perstackApiKey: z.string().optional(),
161+
perstackBaseSkillCommand: z.array(z.string()).optional(),
162+
env: z.record(z.string(), z.string()),
163+
})
164+
137165
export const runParamsSchema = z.object({
138166
setting: z.object({
139167
model: z.string(),

packages/runtime/src/run-setting-store.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from "node:path"
2-
import type { RunSetting } from "@perstack/core"
2+
import { type RunSetting, runSettingSchema } from "@perstack/core"
33

44
export type FileSystem = {
55
existsSync: (path: string) => boolean
@@ -36,7 +36,9 @@ export async function storeRunSetting(
3636
const runDir = getRunDir(setting.runId)
3737
if (fileSystem.existsSync(runDir)) {
3838
const runSettingPath = path.resolve(runDir, "run-setting.json")
39-
const runSetting = JSON.parse(await fileSystem.readFile(runSettingPath, "utf-8")) as RunSetting
39+
const runSetting = runSettingSchema.parse(
40+
JSON.parse(await fileSystem.readFile(runSettingPath, "utf-8")),
41+
)
4042
runSetting.updatedAt = Date.now()
4143
await fileSystem.writeFile(runSettingPath, JSON.stringify(runSetting), "utf-8")
4244
} else {

0 commit comments

Comments
 (0)