Download packages/app/src/components/prompt-input/submission-state.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 939 Bytes
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/components/prompt-input/submission-state.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/app/src/components/prompt-input/submission-state.ts
-
curl -L -o submission-state.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/components/prompt-input/submission-state.ts
939 Bytes
| import { type ContextItem, type Prompt, type usePrompt } from "@/context/prompt" | |
| type PromptTarget = ReturnType<ReturnType<typeof usePrompt>["capture"]> | |
| export function createPromptSubmissionState(input: { | |
| target: PromptTarget | |
| prompt: Prompt | |
| context: (ContextItem & { key: string })[] | |
| }) { | |
| const initial = input.target | |
| let target = input.target | |
| let cleared: Prompt | undefined | |
| return { | |
| prompt: input.prompt, | |
| context: input.context, | |
| target: () => target, | |
| clear() { | |
| if (initial !== target) initial.reset() | |
| target.reset() | |
| cleared = target.current() | |
| }, | |
| retarget(next: PromptTarget) { | |
| input.context.forEach(next.context.add) | |
| target = next | |
| }, | |
| current: (value: PromptTarget) => target === value, | |
| restore() { | |
| if (cleared !== undefined && target.current() !== cleared) return | |
| return { target, prompt: input.prompt, context: input.context } | |
| }, | |
| } | |
| } | |