-
Notifications
You must be signed in to change notification settings - Fork 552
feat(agent studio): add prompt suggestions widget #7054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shaejaz
wants to merge
47
commits into
master
Choose a base branch
from
feat/chat-page-suggestions-widget
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
38a296a
init
shaejaz 8d1e0b4
fix types
shaejaz fd8f9dd
Merge branch 'master' into feat/chat-page-suggestions-widget
shaejaz 599683b
fix duplicate requests
shaejaz b867e28
rename current page suggestions
shaejaz aee97fd
add suggestions pills component
shaejaz 01349ec
standalone suggestions
shaejaz b33b848
fix ssr
shaejaz 6881fd8
remove ChatPageSummary widget (split to feat/chat-page-summary-widget)
shaejaz 5479d0f
Merge branch 'master' into feat/chat-page-suggestions-widget
shaejaz fe120b1
fix tests
shaejaz a9a6004
update api
shaejaz 2e0f439
Merge branch 'master' into feat/chat-page-suggestions-widget
shaejaz 3b48a55
update endpoint, remove standalone naming
shaejaz 71db731
add tests
shaejaz 2fd7918
Merge branch 'master' into feat/chat-page-suggestions-widget
shaejaz 922aa54
chore(examples): revert example changes for chat-page-suggestions
shaejaz 953baf4
add task name test
shaejaz aae135c
address comments
shaejaz 5970f2b
fix bundlesize
shaejaz 9f59a30
fix nextjs and loading states
shaejaz 738eacb
address comments and fix test
shaejaz 6bfbd52
add header
shaejaz 30271bd
add streaming support
shaejaz 82c47a1
rename widget
shaejaz ff9ce8a
move functionality to connector
shaejaz 42fdb5b
add comments
shaejaz 82241ca
add filters support
shaejaz 0f37cfa
address comments
shaejaz 1f6ab0f
update bundlesize
shaejaz b588873
Merge branch 'master' into feat/chat-page-suggestions-widget
shaejaz 1b0b390
Merge branch 'master' into feat/chat-page-suggestions-widget
shaejaz f360a6f
address comments
shaejaz bd11185
Merge branch 'master' into feat/chat-page-suggestions-widget
shaejaz bf118b4
chore(chat): drop sessionStorage SSR guard (split to separate PR)
shaejaz 88fdcc1
remove next and ssr changes
shaejaz 99ae0b5
rename to prompt suggestions
shaejaz 87c12b1
add back chat prompt suggestions
shaejaz 9ee79ae
move back chat transport
shaejaz c52f220
rename connector
shaejaz ff78870
update bundlesize
shaejaz 5781b1d
address comments
shaejaz 3244084
update refer name
shaejaz f624a9e
use queryid
shaejaz 8633901
address comments
shaejaz 0aa15eb
update default task name
shaejaz 8bd3025
update turn context
shaejaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
examples/react/next-app-router/app/api/chat-page-suggestions/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { NextResponse } from 'next/server'; | ||
|
|
||
| type RequestBody = { | ||
| messages?: Array<{ | ||
| parts?: Array<{ type?: string; text?: string }>; | ||
| }>; | ||
| }; | ||
|
|
||
| type AgentInput = { | ||
| query?: string; | ||
| hitsSample?: Array<{ name?: string; categories?: string[] }>; | ||
| context?: Record<string, unknown>; | ||
| maxSuggestions?: number; | ||
| }; | ||
|
|
||
| // Returns a mocked agent-studio response in the shape the | ||
| // `connectChatPageSuggestions` connector expects: | ||
| // { parts: [<anything>, { text: '["prompt one", "prompt two", ...]' }] } | ||
| // | ||
| // Suggestions are loosely derived from the search query and the first hit's | ||
| // category so the demo feels reactive to refinements. | ||
| export async function POST(request: Request) { | ||
| const url = new URL(request.url); | ||
| const delayParam = Number(url.searchParams.get('delay')); | ||
| // Tune via `?delay=N` (ms). Default 500ms — long enough to see the client | ||
| // skeleton on refinement changes; short enough that SSR (with a generous | ||
| // `ssrTimeoutMs`) still wins the race and bakes pills into server HTML. | ||
| const delayMs = Number.isFinite(delayParam) && delayParam >= 0 ? delayParam : 500; | ||
|
|
||
| const body = (await request.json().catch(() => ({}))) as RequestBody; | ||
| const rawText = body.messages?.[0]?.parts?.[0]?.text ?? '{}'; | ||
| const input: AgentInput = | ||
| typeof rawText === 'string' | ||
| ? safeParse<AgentInput>(rawText) ?? {} | ||
| : (rawText as AgentInput); | ||
|
|
||
|
shaejaz marked this conversation as resolved.
Outdated
|
||
| const query = (input.query || '').trim(); | ||
| const firstHit = input.hitsSample?.[0]; | ||
| const category = firstHit?.categories?.[0]; | ||
| const max = Math.max(1, Math.min(input.maxSuggestions ?? 4, 8)); | ||
|
|
||
| const pool: string[] = []; | ||
| if (query) { | ||
| pool.push( | ||
| `Compare the top ${query} options`, | ||
| `What should I look for in a ${query}?`, | ||
| `Recommend a ${query} under $500`, | ||
| `Show me bestsellers for "${query}"` | ||
| ); | ||
| } | ||
| if (category) { | ||
| pool.push( | ||
| `What's new in ${category}?`, | ||
| `Top-rated ${category} this month`, | ||
| `Help me choose a ${category}` | ||
| ); | ||
| } | ||
| pool.push( | ||
| 'Help me find what I need', | ||
| 'What are people buying right now?', | ||
| 'Suggest something for a gift' | ||
| ); | ||
|
|
||
| // Dedupe and trim to the requested length. | ||
| const suggestions = Array.from(new Set(pool)).slice(0, max); | ||
|
|
||
| await new Promise((resolve) => setTimeout(resolve, delayMs)); | ||
|
|
||
| return NextResponse.json({ | ||
| id: `dummy-${Date.now()}`, | ||
| role: 'assistant', | ||
| parts: [ | ||
| { type: 'reasoning', text: 'mocked' }, | ||
| { type: 'text', text: JSON.stringify(suggestions) }, | ||
| ], | ||
| }); | ||
| } | ||
|
|
||
| function safeParse<T>(text: string): T | null { | ||
| try { | ||
| return JSON.parse(text) as T; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.