@@ -2,7 +2,7 @@ import { execSync } from "child_process";
22import { mkdir , writeFile } from "fs/promises" ;
33import { join , dirname , relative } from "path" ;
44import { stringify } from "yaml" ;
5- import { VAPI_ENV , VAPI_BASE_URL , VAPI_TOKEN , RESOURCES_DIR , BASE_DIR } from "./config.ts" ;
5+ import { VAPI_ENV , VAPI_BASE_URL , VAPI_TOKEN , RESOURCES_DIR , BASE_DIR , APPLY_FILTER } from "./config.ts" ;
66import { loadState , saveState } from "./state.ts" ;
77import type { StateFile , ResourceType } from "./types.ts" ;
88
@@ -461,9 +461,14 @@ export async function pullResourceType(
461461async function main ( ) : Promise < void > {
462462 const force = process . argv . includes ( "--force" ) ;
463463
464+ const typeFilter = APPLY_FILTER . resourceTypes ;
465+
464466 console . log ( "═══════════════════════════════════════════════════════════════" ) ;
465467 console . log ( `🔄 Vapi GitOps Pull - Environment: ${ VAPI_ENV } ${ force ? " (force)" : "" } ` ) ;
466468 console . log ( ` API: ${ VAPI_BASE_URL } ` ) ;
469+ if ( typeFilter ?. length ) {
470+ console . log ( ` Filter: ${ typeFilter . join ( ", " ) } ` ) ;
471+ }
467472 console . log ( "═══════════════════════════════════════════════════════════════" ) ;
468473
469474 // Default mode: skip locally changed files (local is source of truth)
@@ -499,15 +504,19 @@ async function main(): Promise<void> {
499504 simulationSuites : { ...zero } ,
500505 } ;
501506
502- // Pull in dependency order
503- stats . tools = await pullResourceType ( "tools" , state , changedFiles ) ;
504- stats . structuredOutputs = await pullResourceType ( "structuredOutputs" , state , changedFiles ) ;
505- stats . assistants = await pullResourceType ( "assistants" , state , changedFiles ) ;
506- stats . squads = await pullResourceType ( "squads" , state , changedFiles ) ;
507- stats . personalities = await pullResourceType ( "personalities" , state , changedFiles ) ;
508- stats . scenarios = await pullResourceType ( "scenarios" , state , changedFiles ) ;
509- stats . simulations = await pullResourceType ( "simulations" , state , changedFiles ) ;
510- stats . simulationSuites = await pullResourceType ( "simulationSuites" , state , changedFiles ) ;
507+ // Pull in reverse-resolution order: pull resources that are referenced by others first,
508+ // so their state is populated when resolving references (UUID → resourceId) in dependent types.
509+ // e.g. structuredOutputs reference assistants, so assistants must be pulled first.
510+ const shouldPull = ( type : ResourceType ) => ! typeFilter ?. length || typeFilter . includes ( type ) ;
511+
512+ if ( shouldPull ( "tools" ) ) stats . tools = await pullResourceType ( "tools" , state , changedFiles ) ;
513+ if ( shouldPull ( "assistants" ) ) stats . assistants = await pullResourceType ( "assistants" , state , changedFiles ) ;
514+ if ( shouldPull ( "structuredOutputs" ) ) stats . structuredOutputs = await pullResourceType ( "structuredOutputs" , state , changedFiles ) ;
515+ if ( shouldPull ( "squads" ) ) stats . squads = await pullResourceType ( "squads" , state , changedFiles ) ;
516+ if ( shouldPull ( "personalities" ) ) stats . personalities = await pullResourceType ( "personalities" , state , changedFiles ) ;
517+ if ( shouldPull ( "scenarios" ) ) stats . scenarios = await pullResourceType ( "scenarios" , state , changedFiles ) ;
518+ if ( shouldPull ( "simulations" ) ) stats . simulations = await pullResourceType ( "simulations" , state , changedFiles ) ;
519+ if ( shouldPull ( "simulationSuites" ) ) stats . simulationSuites = await pullResourceType ( "simulationSuites" , state , changedFiles ) ;
511520
512521 await saveState ( state ) ;
513522
0 commit comments