-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: AI prompt management dashboard and enhanced span inspectors #3244
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
ericallam
wants to merge
11
commits into
main
Choose a base branch
from
feature/tri-7888-ai-prompts
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.
+7,525
−319
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d7efcb8
feat: prompt management with service layer, dashboard UI, and AI span…
ericallam 3c696b7
feat: operations/providers filters, prompt version model display, ove…
ericallam 86beeb9
feat: generations/metrics across all versions by default, add version…
ericallam db26f63
feat: prompts list redesign with separate columns, bar sparklines, ve…
ericallam 8d5b28f
feat: full-width override banner, cleaner header for prompt detail page
ericallam 1a81db4
feat: add timestamp and duration to AI span inspector header
ericallam 37e3367
feat: custom span inspectors for top-level AI SDK spans (generateText…
ericallam 3935f7e
fix: a11y label on expand button, try-catch request.json, add missing…
ericallam 7a681c2
fix: TypeScript strict mode errors across AI prompts feature
ericallam 2228c9e
coderabbit fixes
ericallam 96e1426
fix: transaction safety, parsePeriodToMs consistency, SQL injection p…
ericallam 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import type { ViewUpdate } from "@codemirror/view"; | ||
| import { EditorView, lineNumbers } from "@codemirror/view"; | ||
| import { CheckIcon, ClipboardIcon } from "@heroicons/react/20/solid"; | ||
| import type { ReactCodeMirrorProps, UseCodeMirror } from "@uiw/react-codemirror"; | ||
| import { useCodeMirror } from "@uiw/react-codemirror"; | ||
| import { useCallback, useEffect, useRef, useState } from "react"; | ||
| import { cn } from "~/utils/cn"; | ||
| import { Button } from "../primitives/Buttons"; | ||
| import { getEditorSetup } from "./codeMirrorSetup"; | ||
| import { darkTheme } from "./codeMirrorTheme"; | ||
|
|
||
| export interface TextEditorProps extends Omit<ReactCodeMirrorProps, "onBlur"> { | ||
| defaultValue?: string; | ||
| readOnly?: boolean; | ||
| onChange?: (value: string) => void; | ||
| onUpdate?: (update: ViewUpdate) => void; | ||
| showCopyButton?: boolean; | ||
| additionalActions?: React.ReactNode; | ||
| } | ||
|
|
||
| export function TextEditor(opts: TextEditorProps) { | ||
| const { | ||
| defaultValue = "", | ||
| readOnly = false, | ||
| onChange, | ||
| onUpdate, | ||
| autoFocus, | ||
| showCopyButton = true, | ||
| additionalActions, | ||
| } = opts; | ||
|
|
||
| // Don't use default line numbers from setup — add our own with proper sizing | ||
| const extensions = getEditorSetup(false); | ||
| extensions.push(EditorView.lineWrapping); | ||
| extensions.push( | ||
| lineNumbers({ | ||
| formatNumber: (n) => String(n), | ||
| }) | ||
| ); | ||
| extensions.push( | ||
| EditorView.theme({ | ||
| ".cm-lineNumbers": { | ||
| minWidth: "40px", | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| const editor = useRef<HTMLDivElement>(null); | ||
| const settings: Omit<UseCodeMirror, "onBlur"> = { | ||
| ...opts, | ||
| container: editor.current, | ||
| extensions, | ||
| editable: !readOnly, | ||
| contentEditable: !readOnly, | ||
| value: defaultValue, | ||
| autoFocus, | ||
| theme: darkTheme(), | ||
| indentWithTab: false, | ||
| basicSetup: false, | ||
| onChange, | ||
| onUpdate, | ||
| }; | ||
| const { setContainer, view } = useCodeMirror(settings); | ||
| const [copied, setCopied] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| if (editor.current) { | ||
| setContainer(editor.current); | ||
| } | ||
| }, [setContainer]); | ||
|
|
||
| useEffect(() => { | ||
| if (view !== undefined) { | ||
| if (view.state.doc.toString() === defaultValue) return; | ||
| view.dispatch({ | ||
| changes: { from: 0, to: view.state.doc.length, insert: defaultValue }, | ||
| }); | ||
| } | ||
| }, [defaultValue, view]); | ||
|
|
||
| const copy = useCallback(() => { | ||
| if (view === undefined) return; | ||
| navigator.clipboard.writeText(view.state.doc.toString()); | ||
| setCopied(true); | ||
| setTimeout(() => setCopied(false), 1500); | ||
| }, [view]); | ||
|
|
||
| const showToolbar = showCopyButton || additionalActions; | ||
|
|
||
| return ( | ||
| <div | ||
| className={cn( | ||
| "grid", | ||
| showToolbar ? "grid-rows-[2.5rem_1fr]" : "grid-rows-[1fr]", | ||
| opts.className | ||
| )} | ||
| > | ||
| {showToolbar && ( | ||
| <div className="mx-3 flex items-center justify-between gap-2 border-b border-grid-dimmed"> | ||
| <div className="flex items-center">{additionalActions}</div> | ||
| <div className="flex items-center gap-2"> | ||
| {showCopyButton && ( | ||
| <Button | ||
| type="button" | ||
| variant="minimal/small" | ||
| TrailingIcon={copied ? CheckIcon : ClipboardIcon} | ||
| trailingIconClassName={ | ||
| copied ? "text-green-500 group-hover:text-green-500" : undefined | ||
| } | ||
| onClick={(event) => { | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| copy(); | ||
| }} | ||
| > | ||
| Copy | ||
| </Button> | ||
| )} | ||
| </div> | ||
| </div> | ||
| )} | ||
| <div className="min-h-0 min-w-0 overflow-auto" ref={editor} /> | ||
| </div> | ||
| ); | ||
| } | ||
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.