Skip to content

Commit d128322

Browse files
committed
fix
1 parent bf18b78 commit d128322

File tree

6 files changed

+111
-47
lines changed

6 files changed

+111
-47
lines changed

packages/web/src/components/ChatMessage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ const ChatMessage: React.FC<Props> = (props) => {
186186
<summary className="text-sm" onClick={toggleOpenTrace}>
187187
<div className="inline-flex gap-1">
188188
{t('common.trace')}
189-
{props.loading && !chatContent?.content && (
190-
<div className="border-aws-sky size-5 animate-spin rounded-full border-4 border-t-transparent"></div>
189+
{props.loading && (
190+
<div className="border-aws-sky size-4 animate-spin rounded-full border-2 border-t-transparent"></div>
191191
)}
192192
</div>
193193
</summary>

packages/web/src/components/agentBuilder/AgentChatUnified.tsx

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ const AgentChatUnified: React.FC<AgentChatProps> = ({
6969
const { t } = useTranslation();
7070

7171
// Generate session ID if not provided
72+
const { pathname } = useLocation();
7273
const [sessionId] = useState(() => providedSessionId || uuidv4());
73-
const chatId = `agent-chat-${agent.agentId}-${sessionId}`;
7474
const { scrollableContainer, setFollowing } = useFollow();
7575

7676
// AgentCore for chat functionality
@@ -84,7 +84,7 @@ const AgentChatUnified: React.FC<AgentChatProps> = ({
8484
updateSystemContext,
8585
getModelId,
8686
setModelId,
87-
} = useAgentCore(chatId);
87+
} = useAgentCore(pathname);
8888

8989
const [chatContent, setChatContent] = useState('');
9090
const [initialized, setInitialized] = useState(false);
@@ -94,36 +94,24 @@ const AgentChatUnified: React.FC<AgentChatProps> = ({
9494
const { modelIds: availableModels, modelDisplayName } = MODELS;
9595
const modelId = getModelId();
9696

97-
// File handling - use location pathname to match InputChatContent
98-
const location = useLocation();
99-
const {
100-
clear: clearFiles,
101-
uploadFiles,
102-
uploadedFiles,
103-
} = useFiles(location.pathname);
97+
// File handling
98+
const { clear: clearFiles, uploadFiles, uploadedFiles } = useFiles(pathname);
10499

105100
// Initialize model ID when agent is loaded
106101
useEffect(() => {
107102
if (agent && availableModels.length > 0) {
108103
const agentModelId = agent.modelId || availableModels[0];
109-
setModelId(agentModelId);
104+
const currentModelId = getModelId();
105+
if (currentModelId !== agentModelId) {
106+
setModelId(agentModelId);
107+
}
110108
}
111-
// eslint-disable-next-line react-hooks/exhaustive-deps
112-
}, [agent, availableModels]);
109+
}, [agent, availableModels, getModelId, setModelId]);
113110

114-
// Initialize chat when component mounts
111+
// Initialize system context when component mounts (only once per agent)
115112
useEffect(() => {
116113
if (!initialized && agent) {
117-
console.log(
118-
'Starting chat with agent:',
119-
agent.name,
120-
'Model ID:',
121-
agent.modelId
122-
);
123-
console.log(
124-
'Code execution enabled in agent:',
125-
agent.codeExecutionEnabled
126-
);
114+
console.log('Initializing agent chat:', agent.name);
127115

128116
// Set the system context to the agent's system prompt
129117
const systemPrompt = `${agent.systemPrompt || 'You are a helpful assistant.'}
@@ -137,7 +125,24 @@ Please respond as this agent with the specified behavior and personality.`;
137125
setInitialized(true);
138126
}
139127
// eslint-disable-next-line react-hooks/exhaustive-deps
140-
}, [agent, initialized]);
128+
}, [agent?.agentId, initialized]);
129+
130+
// Update system context when agent data changes (for real-time updates)
131+
useEffect(() => {
132+
if (initialized && agent) {
133+
console.log('Updating agent context:', agent.name);
134+
135+
const systemPrompt = `${agent.systemPrompt || 'You are a helpful assistant.'}
136+
137+
Agent Name: ${agent.name}
138+
Agent Description: ${agent.description || 'No description provided'}
139+
140+
Please respond as this agent with the specified behavior and personality.`;
141+
142+
updateSystemContext(systemPrompt);
143+
}
144+
// eslint-disable-next-line react-hooks/exhaustive-deps
145+
}, [agent?.name, agent?.description, agent?.systemPrompt, initialized]);
141146

142147
// Accept file types based on model
143148
const accept = useMemo(() => {

packages/web/src/components/agentBuilder/AgentForm.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface AgentFormProps {
2323
initialData?: Partial<AgentConfiguration>;
2424
onSave: (data: AgentFormData) => Promise<void>;
2525
onCancel: () => void;
26+
onFormDataChange?: (data: AgentFormData) => void;
2627
loading?: boolean;
2728
error?: string;
2829
isEditMode?: boolean;
@@ -32,6 +33,7 @@ const AgentForm: React.FC<AgentFormProps> = ({
3233
initialData,
3334
onSave,
3435
onCancel,
36+
onFormDataChange,
3537
loading = false,
3638
error,
3739
isEditMode = false,
@@ -81,6 +83,24 @@ const AgentForm: React.FC<AgentFormProps> = ({
8183
}
8284
}, [initialData, availableModels]);
8385

86+
// Notify parent component when form data changes
87+
useEffect(() => {
88+
if (onFormDataChange) {
89+
// Parse tags from input for real-time updates
90+
const tags = tagsInput
91+
.split(',')
92+
.map((tag) => tag.trim())
93+
.filter((tag) => tag.length > 0);
94+
95+
const currentFormData: AgentFormData = {
96+
...formData,
97+
tags,
98+
};
99+
100+
onFormDataChange(currentFormData);
101+
}
102+
}, [formData, tagsInput, onFormDataChange]);
103+
84104
const handleSave = useCallback(async () => {
85105
try {
86106
// Parse tags from input

packages/web/src/pages/AgentCorePage.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ const AgentCorePage: React.FC = () => {
7272
const { pathname } = useLocation();
7373
const { content, setContent } = useAgentCorePageState();
7474

75-
// Use agent ARN as ID if provided, otherwise use fixed ID
76-
const chatId = agentArn ? `/agent-core/${agentArn}` : '/agent-core';
7775
const {
7876
messages,
7977
isEmpty,
@@ -85,7 +83,7 @@ const AgentCorePage: React.FC = () => {
8583
getExternalRuntimes,
8684
getModelId,
8785
setModelId,
88-
} = useAgentCore(chatId);
86+
} = useAgentCore(pathname);
8987

9088
const { scrollableContainer, setFollowing } = useFollow();
9189

packages/web/src/pages/agentBuilder/AgentBuilderEditPage.tsx

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const AgentBuilderEditPage: React.FC = () => {
2323

2424
const isEditMode = Boolean(agentId);
2525
const [testMode, setTestMode] = useState(false);
26+
const [currentFormData, setCurrentFormData] = useState<AgentFormData | null>(
27+
null
28+
);
2629

2730
const handleSave = useCallback(
2831
async (formData: AgentFormData) => {
@@ -38,7 +41,8 @@ const AgentBuilderEditPage: React.FC = () => {
3841
tags: formData.tags,
3942
agentId,
4043
});
41-
navigate('/agent-builder');
44+
// Navigate back to agent chat page after editing
45+
navigate(`/agent-builder/${agentId}`);
4246
} else {
4347
console.log(
4448
'Creating agent with data:',
@@ -56,6 +60,7 @@ const AgentBuilderEditPage: React.FC = () => {
5660
});
5761
if (newAgent) {
5862
console.log('Created agent:', JSON.stringify(newAgent, null, 2));
63+
// Navigate to agent list after creating new agent
5964
navigate('/agent-builder');
6065
}
6166
}
@@ -64,8 +69,18 @@ const AgentBuilderEditPage: React.FC = () => {
6469
); // Remove function dependencies
6570

6671
const handleCancel = useCallback(() => {
67-
navigate('/agent-builder');
68-
}, [navigate]);
72+
if (agentId && isEditMode) {
73+
// Navigate back to agent chat page when canceling edit
74+
navigate(`/agent-builder/${agentId}`);
75+
} else {
76+
// Navigate to agent list when canceling create
77+
navigate('/agent-builder');
78+
}
79+
}, [navigate, agentId, isEditMode]);
80+
81+
const handleFormDataChange = useCallback((formData: AgentFormData) => {
82+
setCurrentFormData(formData);
83+
}, []);
6984

7085
const title = isEditMode
7186
? t('agent_builder.edit_agent')
@@ -117,12 +132,12 @@ const AgentBuilderEditPage: React.FC = () => {
117132
</div>
118133
</div>
119134
<div className="flex items-center gap-2">
120-
<Button
121-
outlined
122-
onClick={() => setTestMode(!testMode)}
123-
disabled={!agent && isEditMode}>
124-
{t('agent_builder.test')}
125-
</Button>
135+
{/* Show test button when we have form data or existing agent */}
136+
{(currentFormData || agent) && (
137+
<Button outlined onClick={() => setTestMode(!testMode)}>
138+
{t('agent_builder.test')}
139+
</Button>
140+
)}
126141
</div>
127142
</div>
128143

@@ -134,23 +149,45 @@ const AgentBuilderEditPage: React.FC = () => {
134149
initialData={agent || undefined}
135150
onSave={handleSave}
136151
onCancel={handleCancel}
152+
onFormDataChange={handleFormDataChange}
137153
loading={loading}
138154
error={error || undefined}
139155
isEditMode={isEditMode}
140156
/>
141157
</div>
142158

143159
{/* Agent Testing */}
144-
{testMode && agent && (
160+
{testMode && (currentFormData || agent) && (
145161
<div className="space-y-6">
146162
<AgentTester
147163
agent={{
148-
...agent,
149-
agentId: agentId || 'temp-id',
150-
isPublic: false,
151-
createdAt: new Date().toISOString(),
152-
updatedAt: new Date().toISOString(),
153-
createdBy: 'current-user',
164+
// Use current form data if available, otherwise use existing agent data
165+
...(currentFormData
166+
? {
167+
agentId: agentId || 'temp-id',
168+
name: currentFormData.name,
169+
description: currentFormData.description,
170+
systemPrompt: currentFormData.systemPrompt,
171+
modelId: currentFormData.modelId,
172+
mcpServers: currentFormData.mcpServers as string[],
173+
codeExecutionEnabled:
174+
currentFormData.codeExecutionEnabled,
175+
isPublic: currentFormData.isPublic,
176+
tags: currentFormData.tags,
177+
isMyAgent: true,
178+
createdAt: new Date().toISOString(),
179+
updatedAt: new Date().toISOString(),
180+
createdBy: 'current-user',
181+
starCount: 0,
182+
}
183+
: {
184+
...agent!,
185+
agentId: agentId || 'temp-id',
186+
isPublic: false,
187+
createdAt: new Date().toISOString(),
188+
updatedAt: new Date().toISOString(),
189+
createdBy: 'current-user',
190+
}),
154191
}}
155192
/>
156193
</div>

packages/web/src/pages/agentBuilder/AgentBuilderListPage.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,12 @@ const AgentBuilderListPage: React.FC = () => {
369369
<div className="line-clamp-1 text-sm font-bold">
370370
{agent.name}
371371
</div>
372-
{agent.isFavorite && (
373-
<StarFillIcon className="text-aws-smile h-4 w-4" />
372+
{/* Show star count (total favorites) */}
373+
{agent.starCount > 0 && (
374+
<div className="flex items-center gap-1 text-xs text-gray-500">
375+
<StarIcon className="h-3 w-3" />
376+
<span>{agent.starCount}</span>
377+
</div>
374378
)}
375379
</div>
376380
{agent.description && (

0 commit comments

Comments
 (0)