1- import type { AgentCoreProjectSpec , DeployedState , OnlineEvalConfig } from '../../../schema' ;
1+ import type { OnlineEvalConfig } from '../../../schema' ;
22import type { GetOnlineEvalConfigResult , OnlineEvalConfigSummary } from '../../aws/agentcore-control' ;
33import { getOnlineEvaluationConfig , listAllOnlineEvaluationConfigs } from '../../aws/agentcore-control' ;
44import { ANSI } from './constants' ;
@@ -7,8 +7,6 @@ import { executeResourceImport } from './resource-import';
77import type { ImportResourceOptions , ImportResourceResult , ResourceImportDescriptor } from './types' ;
88import type { Command } from '@commander-js/extra-typings' ;
99
10- const ARN_PREFIX = 'arn:' ;
11-
1210/**
1311 * Derive the agent name from the online eval config's service names.
1412 * Service names follow the pattern: "{agentName}.DEFAULT"
@@ -28,7 +26,7 @@ export function toOnlineEvalConfigSpec(
2826 detail : GetOnlineEvalConfigResult ,
2927 localName : string ,
3028 agentName : string ,
31- evaluatorNames : string [ ]
29+ evaluatorArns : string [ ]
3230) : OnlineEvalConfig {
3331 if ( ! detail . samplingPercentage ) {
3432 throw new Error ( `Online eval config "${ detail . configName } " has no sampling configuration. Cannot import.` ) ;
@@ -37,51 +35,28 @@ export function toOnlineEvalConfigSpec(
3735 return {
3836 name : localName ,
3937 agent : agentName ,
40- evaluators : evaluatorNames ,
38+ evaluators : evaluatorArns ,
4139 samplingRate : detail . samplingPercentage ,
4240 ...( detail . description && { description : detail . description } ) ,
4341 ...( detail . executionStatus === 'ENABLED' && { enableOnCreate : true } ) ,
4442 } ;
4543}
4644
4745/**
48- * Resolve evaluator IDs to local names or ARNs .
49- * If an evaluator ID matches a local evaluator ( by checking deployed state), use the local name.
50- * Otherwise, construct an ARN so the schema validation passes .
46+ * Build evaluator ARNs from evaluator IDs .
47+ * Online eval configs reference evaluators by ARN rather than importing them,
48+ * since evaluators locked by an online eval config cannot be CFN-imported .
5149 */
52- function resolveEvaluatorReferences (
53- evaluatorIds : string [ ] ,
54- projectSpec : AgentCoreProjectSpec ,
55- deployedEvaluators : Record < string , string > ,
56- region : string ,
57- account : string
58- ) : string [ ] {
59- const localEvaluators = projectSpec . evaluators ?? [ ] ;
60-
61- return evaluatorIds . map ( id => {
62- // First check deployed state for an exact physical ID → local name match
63- // This handles imported evaluators where the local name differs from the AWS name
64- if ( deployedEvaluators [ id ] ) {
65- return deployedEvaluators [ id ] ;
66- }
67- // Then check if the evaluator ID contains a local evaluator name
68- // This handles evaluators deployed by the same project (ID pattern: {projectName}_{evaluatorName}-{suffix})
69- for ( const localEval of localEvaluators ) {
70- if ( id . includes ( localEval . name ) ) {
71- return localEval . name ;
72- }
73- }
74- // Fall back to ARN format (bypasses schema cross-reference validation)
75- return `${ ARN_PREFIX } aws:bedrock-agentcore:${ region } :${ account } :evaluator/${ id } ` ;
76- } ) ;
50+ function buildEvaluatorArns ( evaluatorIds : string [ ] , region : string , account : string ) : string [ ] {
51+ return evaluatorIds . map ( id => `arn:aws:bedrock-agentcore:${ region } :${ account } :evaluator/${ id } ` ) ;
7752}
7853
7954/**
8055 * Create an online-eval descriptor with closed-over state for reference resolution.
8156 */
8257function createOnlineEvalDescriptor ( ) : ResourceImportDescriptor < GetOnlineEvalConfigResult , OnlineEvalConfigSummary > {
8358 let resolvedAgentName = '' ;
84- let resolvedEvaluatorNames : string [ ] = [ ] ;
59+ let resolvedEvaluatorArns : string [ ] = [ ] ;
8560
8661 return {
8762 resourceType : 'online-eval' ,
@@ -112,7 +87,7 @@ function createOnlineEvalDescriptor(): ResourceImportDescriptor<GetOnlineEvalCon
11287 getExistingNames : spec => ( spec . onlineEvalConfigs ?? [ ] ) . map ( c => c . name ) ,
11388 addToProjectSpec : ( detail , localName , spec ) => {
11489 ( spec . onlineEvalConfigs ??= [ ] ) . push (
115- toOnlineEvalConfigSpec ( detail , localName , resolvedAgentName , resolvedEvaluatorNames )
90+ toOnlineEvalConfigSpec ( detail , localName , resolvedAgentName , resolvedEvaluatorArns )
11691 ) ;
11792 } ,
11893
@@ -122,7 +97,8 @@ function createOnlineEvalDescriptor(): ResourceImportDescriptor<GetOnlineEvalCon
12297
12398 buildDeployedStateEntry : ( name , id , d ) => ( { type : 'online-eval' , name, id, arn : d . configArn } ) ,
12499
125- beforeConfigWrite : async ( { detail, localName, projectSpec, ctx, target, onProgress, logger } ) => {
100+ // eslint-disable-next-line @typescript-eslint/require-await -- interface requires Promise return type
101+ beforeConfigWrite : async ( { detail, localName, projectSpec, target, onProgress, logger } ) => {
126102 logger . startStep ( 'Resolve references' ) ;
127103
128104 // Extract agent name from service names
@@ -148,7 +124,7 @@ function createOnlineEvalDescriptor(): ResourceImportDescriptor<GetOnlineEvalCon
148124 ) ;
149125 }
150126
151- // Resolve evaluator IDs to local names or ARNs
127+ // Resolve evaluator IDs to ARNs
152128 const evaluatorIds = detail . evaluatorIds ?? [ ] ;
153129 if ( evaluatorIds . length === 0 ) {
154130 return failResult (
@@ -159,28 +135,9 @@ function createOnlineEvalDescriptor(): ResourceImportDescriptor<GetOnlineEvalCon
159135 ) ;
160136 }
161137
162- // Build reverse map from deployed state: evaluatorId → localName
163- const deployedEvaluators : Record < string , string > = { } ;
164- const deployedState : DeployedState = await ctx . configIO
165- . readDeployedState ( )
166- . catch ( ( ) : DeployedState => ( { targets : { } } ) ) ;
167- const targetName = target . name ?? 'default' ;
168- const evalEntries = deployedState . targets [ targetName ] ?. resources ?. evaluators ;
169- if ( evalEntries ) {
170- for ( const [ localEvalName , entry ] of Object . entries ( evalEntries ) ) {
171- deployedEvaluators [ entry . evaluatorId ] = localEvalName ;
172- }
173- }
174-
175- resolvedEvaluatorNames = resolveEvaluatorReferences (
176- evaluatorIds ,
177- projectSpec ,
178- deployedEvaluators ,
179- target . region ,
180- target . account
181- ) ;
138+ resolvedEvaluatorArns = buildEvaluatorArns ( evaluatorIds , target . region , target . account ) ;
182139 resolvedAgentName = agentName ;
183- onProgress ( `Agent: ${ agentName } , Evaluators: ${ resolvedEvaluatorNames . join ( ', ' ) } ` ) ;
140+ onProgress ( `Agent: ${ agentName } , Evaluators: ${ resolvedEvaluatorArns . join ( ', ' ) } ` ) ;
184141 logger . endStep ( 'success' ) ;
185142 } ,
186143 } ;
0 commit comments