1- import { Agent , type RunResult } from "@cursor/sdk" ;
1+ import { Agent , Cursor , type RunResult } from "@cursor/sdk" ;
22import { validateAgentResult } from "./schema.js" ;
33import type { AgentResult } from "./schema.js" ;
44import { log , logError } from "./log.js" ;
@@ -38,12 +38,26 @@ export async function runAgent(input: RunAgentInput): Promise<RunAgentOutput> {
3838 RUBRIC : input . rubric ,
3939 } ) ;
4040
41+ try {
42+ const me = await Cursor . me ( { apiKey } ) ;
43+ log ( `key validated: apiKeyName=${ me . apiKeyName } ` ) ;
44+ } catch ( err ) {
45+ const name = err instanceof Error ? err . name : "non-Error" ;
46+ const msg = err instanceof Error ? err . message || "(empty message)" : String ( err ) ;
47+ if ( err && typeof err === "object" ) {
48+ const e = err as Record < string , unknown > ;
49+ process . stderr . write (
50+ `[skill-eval] preflight key validation failed: status=${ e . status } code=${ e . code } endpoint=${ e . endpoint } requestId=${ e . requestId } \n`
51+ ) ;
52+ }
53+ return { ok : false , error : `API key validation failed — ${ name } : ${ msg } ` } ;
54+ }
55+
4156 let res : RunResult ;
4257 try {
4358 res = await Agent . prompt ( prompt , {
4459 apiKey,
4560 model : { id : "gemini-3-flash" } ,
46- local : { cwd : process . cwd ( ) }
4761 } ) ;
4862 } catch ( err ) {
4963 logError ( `agent SDK call failed for ${ input . skillPath } ` , err ) ;
@@ -52,6 +66,12 @@ export async function runAgent(input: RunAgentInput): Promise<RunAgentOutput> {
5266 err instanceof Error
5367 ? err . message || "(empty message)"
5468 : String ( err ) ;
69+ if ( err && typeof err === "object" ) {
70+ const e = err as Record < string , unknown > ;
71+ process . stderr . write (
72+ `[skill-eval] error details: status=${ e . status } code=${ e . code } endpoint=${ e . endpoint } requestId=${ e . requestId } \n`
73+ ) ;
74+ }
5575 return { ok : false , error : `SDK threw ${ name } : ${ msg } ` } ;
5676 }
5777
0 commit comments