import { createEffect, createMemo, For, Show } from "solid-js" import { createStore } from "solid-js/store" import type { SessionMessageUser } from "@opencode/client/promise" import type { SessionUserActions } from "../actions" import { CurrentUserMessageDisplay } from "./message-content" import { CurrentSessionProviders } from "../storybook/current-session-story" import { CURRENT_SESSION_ID, STORY_MODEL, STORY_TIME } from "../storybook/current-session-fixtures" const statuses = ["delivered", "starting", "steering", "stranded", "queued", "sending"] as const type Args = { status: (typeof statuses)[number]; voice: boolean; text: boolean; grouped: boolean; fails: boolean } export default { title: "OpenCode/Conversation/Prompt message", id: "current-prompt-message", parameters: { layout: "fullscreen" }, args: { status: "steering", voice: false, text: true, grouped: false, fails: false } satisfies Args, argTypes: { status: { options: statuses } }, } export const Pending = { render: (args: Args) => { const [state, setState] = createStore({ ...args, failures: 0 }) // Frame controls and host callbacks can still change the fixture after a panel edit. for (const key of ["status", "voice", "text", "grouped", "fails"] as const) { createEffect(() => setState({ [key]: args[key] })) } // A failing host rejects, like a server error, and leaves the message as it was. const attempt = async (apply: () => void) => { if (!state.fails) return apply() setState("failures", (count) => count + 1) throw new Error("Request failed") } const message = createMemo(() => ({ id: "msg_pending_prompt_story", type: "user", text: state.text ? "Keep the prompt styling consistent with the rest of the timeline." : "", time: { created: STORY_TIME }, files: state.text ? [] : [{ name: "notes.json", mime: "application/json", data: "e30=", source: { type: "inline" } }], })) const document = createMemo(() => ({ sessionID: CURRENT_SESSION_ID, messages: [message()], status: { type: "idle" as const }, diffs: [], })) const actions = { revert: () => attempt(() => {}), fork: () => attempt(() => {}), pending: { status: () => (state.status === "delivered" ? undefined : state.status), queue: () => attempt(() => setState("status", "queued")), remove: () => attempt(() => setState("status", "delivered")), }, } satisfies SessionUserActions return (
{state.failures}
) }, } export const SendingAttachment = { ...Pending, args: { status: "sending", text: false } } export const DeliveredVoice = { ...Pending, args: { status: "delivered", voice: true } } export const StrandedSteer = { ...Pending, args: { status: "stranded", grouped: true } }