11import { z } from "zod" ;
22import { logWarn } from "@/chat/logging" ;
33import type { completeObject } from "@/chat/pi/client" ;
4+ import { evaluateQuestions } from "@/chat/pi/evaluate" ;
45import { GUARDIAN_ACTION_POLICY } from "@/chat/services/guardian-action-policy" ;
56import { ProviderError } from "@/chat/services/provider-error" ;
67import type {
@@ -20,6 +21,7 @@ const guardianDecisionSchema = z
2021type CompleteObject = typeof completeObject ;
2122const GUARDIAN_REVIEW_TIMEOUT_MS = 60_000 ;
2223const GUARDIAN_REVIEW_MAX_TOKENS = 2_000 ;
24+ const JEV_MODEL_ID = "typesafe-ai/jev" ;
2325const MAX_PROPOSAL_CHARS = 192_000 ;
2426
2527/** Serialize one bounded proposal while keeping its contents untrusted. */
@@ -51,6 +53,54 @@ export function createGuardianActionReviewer(options: {
5153 const signal = reviewOptions ?. signal
5254 ? AbortSignal . any ( [ reviewOptions . signal , timeoutSignal ] )
5355 : timeoutSignal ;
56+ if ( options . modelId === JEV_MODEL_ID ) {
57+ const result = await evaluateQuestions ( {
58+ modelId : options . modelId ,
59+ state : [ GUARDIAN_ACTION_POLICY , guardianPrompt ( proposal ) ] . join (
60+ "\n\n" ,
61+ ) ,
62+ questions : {
63+ decision : {
64+ type : "choice" ,
65+ instructions : "Choose the required Guardian decision." ,
66+ criteria : {
67+ allow : "The policy allows the action without confirmation." ,
68+ ask : "The policy requires explicit user confirmation." ,
69+ deny : "The policy prohibits the action." ,
70+ } ,
71+ } ,
72+ riskLevel : {
73+ type : "choice" ,
74+ instructions : "Choose the risk level of the planned action." ,
75+ criteria : {
76+ low : "Low impact and easy to reverse." ,
77+ medium : "Meaningful but limited impact." ,
78+ high : "Substantial impact or hard to reverse." ,
79+ critical : "Severe, broad, or irreversible impact." ,
80+ } ,
81+ } ,
82+ userAuthorization : {
83+ type : "choice" ,
84+ instructions :
85+ "Choose how clearly the user authorized the planned action." ,
86+ criteria : {
87+ high : "The user explicitly authorized this exact action." ,
88+ medium : "The user intent supports the action but is not exact." ,
89+ low : "The action is only weakly implied." ,
90+ unknown : "The proposal shows no user authorization." ,
91+ } ,
92+ } ,
93+ } ,
94+ signal,
95+ } ) ;
96+ return guardianDecisionSchema . parse ( {
97+ decision : result . answers . decision . choice ,
98+ reason : "jev_evaluation" ,
99+ riskLevel : result . answers . riskLevel . choice ,
100+ userAuthorization : result . answers . userAuthorization . choice ,
101+ } ) ;
102+ }
103+
54104 const completeReview = ( ) =>
55105 options . completeObject ( {
56106 modelId : options . modelId ,
@@ -87,7 +137,9 @@ export function createGuardianActionReviewer(options: {
87137 }
88138 return {
89139 ...guardianDecisionSchema . parse ( result . object ) ,
90- ...( result . costUsd !== undefined ? { costUsd : result . costUsd } : undefined ) ,
140+ ...( result . costUsd !== undefined
141+ ? { costUsd : result . costUsd }
142+ : undefined ) ,
91143 } ;
92144 } ,
93145 } ;
0 commit comments