-
Notifications
You must be signed in to change notification settings - Fork 14
(MOT-4173) console: prompts page for the prompt store #565
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
rohitg00
wants to merge
3
commits into
main
Choose a base branch
from
console-prompts-view
base: main
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
3 commits
Select commit
Hold shift + click to select a range
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
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,99 @@ | ||
| import { useEffect, useRef, useState } from 'react' | ||
| import { Select } from '@/components/ui/Select' | ||
| import { getPrompt, listPrompts, type PromptRow } from '@/lib/prompts' | ||
|
|
||
| /** | ||
| * In-chat system prompt picker — "which system prompt is this chat | ||
| * running". `default` defers to the harness identity chain (router | ||
| * override, provider-declared, embedded fallback). Picking a `kind: | ||
| * system` entry from the prompt store overrides the system prompt for | ||
| * every following send in THIS conversation, so a five-line special- | ||
| * purpose prompt (blog writing, scraping) fully replaces the general | ||
| * agent prompt. Lives next to the composer as one compact dropdown; | ||
| * mid-conversation switches apply from the next turn. | ||
| */ | ||
|
|
||
| export interface SessionPrompt { | ||
| name: string | ||
| body: string | ||
| } | ||
|
|
||
| interface PromptPickerProps { | ||
| /** Prompt for THIS conversation; null = the harness default chain. */ | ||
| value: SessionPrompt | null | ||
| onChange: (next: SessionPrompt | null) => void | ||
| disabled?: boolean | ||
| } | ||
|
|
||
| const DEFAULT = '(default)' | ||
|
|
||
| export function PromptPicker({ value, onChange, disabled }: PromptPickerProps) { | ||
| const [prompts, setPrompts] = useState<PromptRow[]>([]) | ||
| // Monotonic token so a slow getPrompt from an earlier selection can't | ||
| // land after a newer one and apply a stale prompt. | ||
| const selectionRef = useRef(0) | ||
|
|
||
| useEffect(() => { | ||
| let cancelled = false | ||
| void listPrompts() | ||
| .then((next) => { | ||
| if (!cancelled) { | ||
| setPrompts(next.filter((p) => p.kind === 'system')) | ||
| } | ||
| }) | ||
| .catch(() => {}) | ||
| return () => { | ||
| cancelled = true | ||
| } | ||
| }, []) | ||
|
|
||
| const known = prompts.some((p) => p.name === value?.name) | ||
| const options = [ | ||
| { | ||
| value: DEFAULT, | ||
| label: 'prompt: default', | ||
| title: | ||
| 'the harness identity chain (router override, provider prompt, fallback)', | ||
| }, | ||
| ...prompts.map((p) => ({ | ||
| value: p.name, | ||
| label: `prompt: ${p.name}`, | ||
| title: p.description, | ||
| })), | ||
| ...(value && !known | ||
| ? [ | ||
| { | ||
| value: value.name, | ||
| label: `prompt: ${value.name}`, | ||
| title: 'no longer in the prompt store; still applied to this chat', | ||
| }, | ||
| ] | ||
| : []), | ||
| ] | ||
|
|
||
| return ( | ||
| <Select<string> | ||
| value={value?.name ?? DEFAULT} | ||
| onChange={(next) => { | ||
| // Every selection (including DEFAULT) supersedes any in-flight read. | ||
| const token = ++selectionRef.current | ||
| if (next === DEFAULT) { | ||
| onChange(null) | ||
| return | ||
| } | ||
| void getPrompt(next) | ||
| .then((detail) => { | ||
| if (token !== selectionRef.current) return | ||
| if (detail) onChange({ name: detail.name, body: detail.body }) | ||
| }) | ||
| .catch(() => { | ||
| // Failed read: leave the current selection untouched. | ||
| }) | ||
| }} | ||
| disabled={disabled} | ||
| aria-label="system prompt" | ||
| className="min-w-[104px] max-w-[180px]" | ||
| options={options} | ||
| /> | ||
| ) | ||
| } |
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
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.
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Scope the selected prompt by
conversation.id.This state can leak the previous chat’s override into the next selected conversation; if
ChatViewremounts instead, it loses the prior conversation’s selection. Store prompt selection keyed by conversation id (preferably in conversation state) and derive the current override from that mapping before both send paths.🤖 Prompt for AI Agents