fix: implement client-side caching for example diagrams (#150)

- Add client-side cache check in onFormSubmit to bypass API calls for example prompts
- Use findCachedResponse to match input against cached examples
- Directly set messages with cached tool response when example matches
- Hide regenerate button for cached example responses (toolCallId starts with 'cached-')
- Prevents unnecessary API calls when using example buttons

Co-authored-by: dayuan.jiang <jiangdy@amazon.co.jp>
This commit is contained in:
Dayuan Jiang
2025-12-07 19:36:09 +09:00
committed by GitHub
parent 0baf21fadb
commit 86420a42c6
3 changed files with 68 additions and 2 deletions

View File

@@ -676,9 +676,14 @@ export function ChatMessageDisplay({
<Copy className="h-3.5 w-3.5" />
)}
</button>
{/* Regenerate button - only on last assistant message */}
{/* Regenerate button - only on last assistant message, not for cached examples */}
{onRegenerate &&
isLastAssistantMessage && (
isLastAssistantMessage &&
!message.parts?.some((p: any) =>
p.toolCallId?.startsWith(
"cached-",
),
) && (
<button
type="button"
onClick={() =>