11import type { IndexedKeyType , MemoryStrategyType } from '../../../../schema' ;
22import { AgentNameSchema , StreamContentLevelSchema } from '../../../../schema' ;
33import { ARN_VALIDATION_MESSAGE , isValidArn } from '../../../commands/shared/arn-utils' ;
4+ import { validateIndexedKeyName } from '../../../commands/shared/indexed-key-parser' ;
45import {
56 ConfirmReview ,
67 Panel ,
@@ -24,7 +25,7 @@ import {
2425} from './types' ;
2526import { useAddMemoryWizard } from './useAddMemoryWizard' ;
2627import { Box , Text } from 'ink' ;
27- import React , { useCallback , useMemo , useState } from 'react' ;
28+ import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
2829
2930interface AddMemoryScreenProps {
3031 onComplete : ( config : AddMemoryConfig ) => void ;
@@ -72,16 +73,20 @@ export function AddMemoryScreen({ onComplete, onExit, existingMemoryNames }: Add
7273 const isStrategiesStep = wizard . step === 'strategies' ;
7374 const isIndexedKeysStep = wizard . step === 'indexedKeys' ;
7475
75- if (
76- isIndexedKeysStep &&
77- indexedKeysSubStep === 'prompt' &&
78- collectedKeys . length === 0 &&
79- wizard . config . indexedKeys &&
80- wizard . config . indexedKeys . length > 0
81- ) {
82- setCollectedKeys ( wizard . config . indexedKeys ) ;
83- setIndexedKeysSubStep ( 'addAnother' ) ;
84- }
76+ /* eslint-disable react-hooks/set-state-in-effect */
77+ useEffect ( ( ) => {
78+ if (
79+ isIndexedKeysStep &&
80+ indexedKeysSubStep === 'prompt' &&
81+ collectedKeys . length === 0 &&
82+ wizard . config . indexedKeys &&
83+ wizard . config . indexedKeys . length > 0
84+ ) {
85+ setCollectedKeys ( wizard . config . indexedKeys ) ;
86+ setIndexedKeysSubStep ( 'addAnother' ) ;
87+ }
88+ } , [ isIndexedKeysStep , indexedKeysSubStep , collectedKeys . length , wizard . config . indexedKeys ] ) ;
89+ /* eslint-enable react-hooks/set-state-in-effect */
8590
8691 const isStreamingStep = wizard . step === 'streaming' ;
8792 const isStreamArnStep = wizard . step === 'streamArn' ;
@@ -305,31 +310,18 @@ export function AddMemoryScreen({ onComplete, onExit, existingMemoryNames }: Add
305310 < TextInput
306311 key = { `keyName-${ collectedKeys . length } ` }
307312 prompt = "Metadata key name"
308- initialValue = ""
313+ initialValue = { pendingKeyName }
309314 onSubmit = { handleKeyNameSubmit }
310315 onCancel = { ( ) => {
316+ setPendingKeyName ( '' ) ;
311317 if ( collectedKeys . length > 0 ) {
312318 setIndexedKeysSubStep ( 'addAnother' ) ;
313319 } else {
314320 wizard . clearIndexedKeys ( ) ;
315321 setIndexedKeysSubStep ( 'prompt' ) ;
316322 }
317323 } }
318- customValidation = { value => {
319- if ( ! / ^ [ a - z A - Z 0 - 9 \s . _ : / = + @ - ] + $ / . test ( value ) ) {
320- return 'Must contain only alphanumeric characters, whitespace, or the symbols . _ : / = + @ -' ;
321- }
322- if ( value . trim ( ) . length === 0 ) {
323- return 'Key cannot be only whitespace' ;
324- }
325- if ( value . length > 128 ) {
326- return 'Maximum 128 characters' ;
327- }
328- if ( existingKeyNames . includes ( value ) ) {
329- return 'Key already defined' ;
330- }
331- return true ;
332- } }
324+ customValidation = { value => validateIndexedKeyName ( value , existingKeyNames ) }
333325 />
334326 </ Box >
335327 ) }
0 commit comments