|
| 1 | +// @ts-nocheck |
| 2 | +import { createStore } from "solid-js/store" |
| 3 | +import { createPromptState } from "@/context/prompt" |
| 4 | +import { createPromptInputHistory, PromptInput } from "./prompt-input" |
| 5 | + |
| 6 | +function PromptInputExample() { |
| 7 | + const state = createPromptState() |
| 8 | + const history = createPromptInputHistory() |
| 9 | + const [controls, setControls] = createStore({ |
| 10 | + agent: "build", |
| 11 | + variant: undefined as string | undefined, |
| 12 | + comments: 0, |
| 13 | + tabs: [] as string[], |
| 14 | + activeTab: undefined as string | undefined, |
| 15 | + reviewOpen: false, |
| 16 | + }) |
| 17 | + const model = { |
| 18 | + current: () => ({ id: "claude-3-7-sonnet", name: "Claude 3.7 Sonnet", provider: { id: "anthropic" } }), |
| 19 | + variant: { |
| 20 | + list: () => ["fast", "thinking"], |
| 21 | + current: () => controls.variant, |
| 22 | + set: (variant?: string) => setControls("variant", variant), |
| 23 | + }, |
| 24 | + } |
| 25 | + const submission = { |
| 26 | + abort() {}, |
| 27 | + handleSubmit(event: Event) { |
| 28 | + event.preventDefault() |
| 29 | + state.reset() |
| 30 | + }, |
| 31 | + } |
| 32 | + const inputControls = { |
| 33 | + agents: { |
| 34 | + available: [{ name: "review", hidden: false, mode: "subagent" }], |
| 35 | + options: ["build", "review", "plan"], |
| 36 | + get current() { |
| 37 | + return controls.agent |
| 38 | + }, |
| 39 | + loading: false, |
| 40 | + visible: true, |
| 41 | + select: (agent?: string) => setControls("agent", agent ?? "build"), |
| 42 | + }, |
| 43 | + model: { |
| 44 | + selection: model, |
| 45 | + paid: true, |
| 46 | + loading: false, |
| 47 | + }, |
| 48 | + projects: { |
| 49 | + available: [{ name: "Story project", worktree: "/tmp/story", sandboxes: [] }], |
| 50 | + directory: "/tmp/story", |
| 51 | + select() {}, |
| 52 | + add() {}, |
| 53 | + }, |
| 54 | + session: { |
| 55 | + id: "story-session", |
| 56 | + tabs: { |
| 57 | + active: () => controls.activeTab, |
| 58 | + all: () => controls.tabs, |
| 59 | + open: (tab: string) => setControls("tabs", (tabs) => (tabs.includes(tab) ? tabs : [...tabs, tab])), |
| 60 | + setActive: (tab: string) => setControls("activeTab", tab), |
| 61 | + }, |
| 62 | + reviewPanel: { |
| 63 | + opened: () => controls.reviewOpen, |
| 64 | + open: () => setControls("reviewOpen", true), |
| 65 | + }, |
| 66 | + }, |
| 67 | + newLayoutDesigns: true, |
| 68 | + } |
| 69 | + const addReviewComment = () => { |
| 70 | + const comment = controls.comments + 1 |
| 71 | + setControls("comments", comment) |
| 72 | + state.context.add({ |
| 73 | + type: "file", |
| 74 | + path: "src/components/prompt-input.tsx", |
| 75 | + selection: { |
| 76 | + startLine: 84 + comment, |
| 77 | + startChar: 0, |
| 78 | + endLine: 84 + comment, |
| 79 | + endChar: 0, |
| 80 | + }, |
| 81 | + comment: `Review comment ${comment}`, |
| 82 | + commentID: `review-comment-${comment}`, |
| 83 | + commentOrigin: "review", |
| 84 | + preview: "export const PromptInput = ...", |
| 85 | + }) |
| 86 | + } |
| 87 | + |
| 88 | + return ( |
| 89 | + <div class="flex flex-col gap-3"> |
| 90 | + <PromptInput controls={inputControls} state={state} history={history} submission={submission} /> |
| 91 | + <div> |
| 92 | + <button |
| 93 | + type="button" |
| 94 | + class="rounded-md border border-border-weak-base bg-background-base px-2.5 py-1.5 text-12-medium text-text-base hover:bg-background-stronger" |
| 95 | + onClick={addReviewComment} |
| 96 | + > |
| 97 | + Add review comment |
| 98 | + </button> |
| 99 | + </div> |
| 100 | + </div> |
| 101 | + ) |
| 102 | +} |
| 103 | + |
| 104 | +export default { |
| 105 | + title: "App/PromptInput", |
| 106 | + id: "app-prompt-input", |
| 107 | + component: PromptInput, |
| 108 | +} |
| 109 | + |
| 110 | +export const Basic = { |
| 111 | + render: () => ( |
| 112 | + <div class="pt-10"> |
| 113 | + <h1 class="mb-4">Prompt Input</h1> |
| 114 | + <PromptInputExample /> |
| 115 | + </div> |
| 116 | + ), |
| 117 | +} |