-
Notifications
You must be signed in to change notification settings - Fork 128
Feature/suggestion pills #53
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
zachdive
wants to merge
7
commits into
master
Choose a base branch
from
feature/suggestion-pills
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9ddfda9
feat: add suggestion pills for follow-up prompts
zachdive 8b94070
fix: improve suggestion prompt and reduce to 2 suggestions
zachdive 170504f
fix: get suggestions from last assistant message, not last message
zachdive 6c4274f
feat: generate suggestions on frontend from last user message
zachdive 9f5b62a
feat: send generated code to suggestion-generator for better context
zachdive 21eb29f
fix: suggestions focus on new features, not parameter adjustments
zachdive e121be3
fix: address security and code review issues
zachdive 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { Button } from '@/components/ui/button'; | ||
| import { cn } from '@/lib/utils'; | ||
|
|
||
| interface SuggestionPillsProps { | ||
| suggestions: string[]; | ||
| onSelect: (suggestion: string) => void; | ||
| disabled?: boolean; | ||
| } | ||
|
|
||
| export function SuggestionPills({ | ||
| disabled, | ||
| suggestions, | ||
| onSelect, | ||
| }: SuggestionPillsProps) { | ||
| if (!suggestions.length) return null; | ||
|
|
||
| return ( | ||
| <div className="scrollbar-hide flex gap-2 overflow-x-auto pb-2 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"> | ||
| {suggestions.map((suggestion) => ( | ||
| <Button | ||
| key={suggestion} | ||
| variant="outline" | ||
| size="sm" | ||
| className={cn( | ||
| 'shrink-0 rounded-full border border-adam-neutral-700 bg-adam-neutral-800 text-xs text-white hover:text-white hover:opacity-80', | ||
| disabled ? 'opacity-50' : '', | ||
| )} | ||
| onClick={() => onSelect(suggestion)} | ||
| disabled={disabled} | ||
| > | ||
| {suggestion} | ||
| </Button> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "imports": { | ||
| "@shared/": "../../../shared/" | ||
| }, | ||
| "lint": { | ||
| "rules": { | ||
| "exclude": ["no-import-prefix", "no-unversioned-import"] | ||
| } | ||
| } | ||
| } |
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,149 @@ | ||
| import 'jsr:@supabase/functions-js/edge-runtime.d.ts'; | ||
| import { corsHeaders } from '../_shared/cors.ts'; | ||
| import { getAnonSupabaseClient } from '../_shared/supabaseClient.ts'; | ||
|
|
||
| const OPENROUTER_API_URL = 'https://openrouter.ai/api/v1/chat/completions'; | ||
| const OPENROUTER_API_KEY = Deno.env.get('OPENROUTER_API_KEY') ?? ''; | ||
|
|
||
| Deno.serve(async (req) => { | ||
| if (req.method === 'OPTIONS') { | ||
| return new Response('ok', { headers: corsHeaders }); | ||
| } | ||
|
|
||
| if (req.method !== 'POST') { | ||
| return new Response('Method not allowed', { status: 405 }); | ||
| } | ||
|
Comment on lines
+8
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: add function registration to Prompt To Fix With AIThis is a comment left during a code review.
Path: supabase/functions/suggestion-generator/index.ts
Line: 7:14
Comment:
**style:** add function registration to `config.toml` with `verify_jwt = true` per backend architecture guidelines
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| // Authenticate user | ||
| const supabaseClient = getAnonSupabaseClient({ | ||
| global: { | ||
| headers: { Authorization: req.headers.get('Authorization') ?? '' }, | ||
| }, | ||
| }); | ||
|
|
||
| const { data: userData, error: userError } = | ||
| await supabaseClient.auth.getUser(); | ||
|
|
||
| if (!userData.user) { | ||
| return new Response( | ||
| JSON.stringify({ error: { message: 'Unauthorized' } }), | ||
| { | ||
| status: 401, | ||
| headers: { ...corsHeaders, 'Content-Type': 'application/json' }, | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| if (userError) { | ||
| return new Response( | ||
| JSON.stringify({ error: { message: userError.message } }), | ||
| { | ||
| status: 401, | ||
| headers: { ...corsHeaders, 'Content-Type': 'application/json' }, | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const { userPrompt, generatedCode } = await req.json(); | ||
|
|
||
| if (!userPrompt) { | ||
| return new Response(JSON.stringify({ suggestions: [] }), { | ||
| headers: { ...corsHeaders, 'Content-Type': 'application/json' }, | ||
| }); | ||
| } | ||
|
|
||
| const suggestionPrompt = `You are helping a user iterate on a 3D CAD model. | ||
|
|
||
| USER REQUEST: "${userPrompt}" | ||
|
|
||
| GENERATED CODE: | ||
| \`\`\`openscad | ||
| ${generatedCode?.slice(0, 1500) || 'No code available'} | ||
| \`\`\` | ||
|
|
||
| Suggest exactly 2 NEW FEATURES to add to this model. Focus on structural additions, not parameter tweaks. | ||
|
|
||
| Good suggestions ADD something new: | ||
| - "Add handle" - adds a new part | ||
| - "Add mounting holes" - adds functional feature | ||
| - "Add lid" - adds new component | ||
| - "Hollow it out" - structural change | ||
| - "Add feet" - adds new elements | ||
| - "Round the edges" - adds fillets/chamfers | ||
|
|
||
| DO NOT suggest: | ||
| - Parameter adjustments (taller, wider, thicker, bigger, smaller) | ||
| - Generic improvements ("Add detail", "Improve design") | ||
| - Exporting, rendering, or colors | ||
| - Things already visible in the code | ||
|
|
||
| Return exactly 2 suggestions (2-4 words each): | ||
| <suggestion>First new feature</suggestion> | ||
| <suggestion>Second new feature</suggestion>`; | ||
|
|
||
| const response = await fetch(OPENROUTER_API_URL, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| Authorization: `Bearer ${OPENROUTER_API_KEY}`, | ||
| 'HTTP-Referer': 'https://adam-cad.com', | ||
| 'X-Title': 'Adam CAD', | ||
| }, | ||
| body: JSON.stringify({ | ||
| model: 'anthropic/claude-3.5-haiku', | ||
| max_tokens: 100, | ||
| messages: [ | ||
| { | ||
| role: 'user', | ||
| content: suggestionPrompt, | ||
| }, | ||
| ], | ||
| }), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`OpenRouter API error: ${response.statusText}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| let suggestions: string[] = []; | ||
|
|
||
| if (data.choices && data.choices[0]?.message?.content) { | ||
| const responseText = data.choices[0].message.content; | ||
| const suggestionRegex = /<suggestion>(.*?)<\/suggestion>/gi; | ||
| const matches = responseText.matchAll(suggestionRegex); | ||
|
|
||
| suggestions = Array.from( | ||
| new Set( | ||
| Array.from(matches) | ||
| .map(([, text]) => { | ||
| if (!text) return null; | ||
| const cleaned = text | ||
| .trim() | ||
| .replace(/[""'']/g, '') | ||
| .replace(/^["']|["']$/g, '') | ||
| .trim(); | ||
| const words = cleaned.split(/\s+/); | ||
| if (words.length > 5) return null; | ||
| return words | ||
| .map( | ||
| (w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase(), | ||
| ) | ||
| .join(' '); | ||
| }) | ||
| .filter((s): s is string => s !== null && s.length > 0), | ||
| ), | ||
| ).slice(0, 2); | ||
| } | ||
|
|
||
| return new Response(JSON.stringify({ suggestions }), { | ||
| headers: { ...corsHeaders, 'Content-Type': 'application/json' }, | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error generating suggestions:', error); | ||
| return new Response(JSON.stringify({ suggestions: [] }), { | ||
| headers: { ...corsHeaders, 'Content-Type': 'application/json' }, | ||
| }); | ||
| } | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: using array index as
keycan cause rendering issues if suggestions change. use the suggestion text itself as the key since suggestions are uniquePrompt To Fix With AI