Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions packages/app/src/context/global-sync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type LspStatus,
type VcsInfo,
type PermissionRequest,
type QuestionRequest,
createOpencodeClient,
} from "@opencode-ai/sdk/v2/client"
import { createStore, produce, reconcile } from "solid-js/store"
Expand Down Expand Up @@ -49,6 +50,9 @@ type State = {
permission: {
[sessionID: string]: PermissionRequest[]
}
question: {
[sessionID: string]: QuestionRequest[]
}
mcp: {
[name: string]: McpStatus
}
Expand Down Expand Up @@ -98,6 +102,7 @@ function createGlobalSync() {
session_diff: {},
todo: {},
permission: {},
question: {},
mcp: {},
lsp: [],
vcs: undefined,
Expand Down Expand Up @@ -208,6 +213,38 @@ function createGlobalSync() {
}
})
}),
sdk.question.list().then((x) => {
const grouped: Record<string, QuestionRequest[]> = {}
for (const question of x.data ?? []) {
if (!question?.id || !question.sessionID) continue
const existing = grouped[question.sessionID]
if (existing) {
existing.push(question)
continue
}
grouped[question.sessionID] = [question]
}

batch(() => {
for (const sessionID of Object.keys(store.question)) {
if (grouped[sessionID]) continue
setStore("question", sessionID, [])
}
for (const [sessionID, questions] of Object.entries(grouped)) {
setStore(
"question",
sessionID,
reconcile(
questions
.filter((q) => !!q?.id)
.slice()
.sort((a, b) => a.id.localeCompare(b.id)),
{ key: "id" },
),
)
}
})
}),
]).then(() => {
setStore("status", "complete")
})
Expand Down Expand Up @@ -396,6 +433,44 @@ function createGlobalSync() {
)
break
}
case "question.asked": {
const sessionID = event.properties.sessionID
const questions = store.question[sessionID]
if (!questions) {
setStore("question", sessionID, [event.properties])
break
}

const result = Binary.search(questions, event.properties.id, (q) => q.id)
if (result.found) {
setStore("question", sessionID, result.index, reconcile(event.properties))
break
}

setStore(
"question",
sessionID,
produce((draft) => {
draft.splice(result.index, 0, event.properties)
}),
)
break
}
case "question.replied":
case "question.rejected": {
const questions = store.question[event.properties.sessionID]
if (!questions) break
const result = Binary.search(questions, event.properties.requestID, (q) => q.id)
if (!result.found) break
setStore(
"question",
event.properties.sessionID,
produce((draft) => {
draft.splice(result.index, 1)
}),
)
break
}
case "lsp.updated": {
const sdk = createOpencodeClient({
baseUrl: globalSDK.url,
Expand Down
8 changes: 8 additions & 0 deletions packages/app/src/pages/directory-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LocalProvider } from "@/context/local"
import { base64Decode } from "@opencode-ai/util/encode"
import { DataProvider } from "@opencode-ai/ui/context"
import { iife } from "@opencode-ai/util/iife"
import type { QuestionAnswer } from "@opencode-ai/sdk/v2"

export default function Layout(props: ParentProps) {
const params = useParams()
Expand All @@ -27,6 +28,11 @@ export default function Layout(props: ParentProps) {
response: "once" | "always" | "reject"
}) => sdk.client.permission.respond(input)

const replyToQuestion = (input: { requestID: string; answers: QuestionAnswer[] }) =>
sdk.client.question.reply(input)

const rejectQuestion = (input: { requestID: string }) => sdk.client.question.reject(input)

const navigateToSession = (sessionID: string) => {
navigate(`/${params.dir}/session/${sessionID}`)
}
Expand All @@ -36,6 +42,8 @@ export default function Layout(props: ParentProps) {
data={sync.data}
directory={directory()}
onPermissionRespond={respond}
onQuestionReply={replyToQuestion}
onQuestionReject={rejectQuestion}
onNavigateToSession={navigateToSession}
>
<LocalProvider>{props.children}</LocalProvider>
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/tool/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export namespace ToolRegistry {

return [
InvalidTool,
...(Flag.OPENCODE_CLIENT === "cli" ? [QuestionTool] : []),
...(["app", "cli", "desktop"].includes(Flag.OPENCODE_CLIENT) ? [QuestionTool] : []),
BashTool,
ReadTool,
GlobTool,
Expand Down
10 changes: 8 additions & 2 deletions packages/ui/src/components/basic-tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface BasicToolProps {
hideDetails?: boolean
defaultOpen?: boolean
forceOpen?: boolean
locked?: boolean
onSubtitleClick?: () => void
}

Expand All @@ -35,8 +36,13 @@ export function BasicTool(props: BasicToolProps) {
if (props.forceOpen) setOpen(true)
})

const handleOpenChange = (value: boolean) => {
if (props.locked && !value) return
setOpen(value)
}

return (
<Collapsible open={open()} onOpenChange={setOpen}>
<Collapsible open={open()} onOpenChange={handleOpenChange}>
<Collapsible.Trigger>
<div data-component="tool-trigger">
<div data-slot="basic-tool-tool-trigger-content">
Expand Down Expand Up @@ -95,7 +101,7 @@ export function BasicTool(props: BasicToolProps) {
</Switch>
</div>
</div>
<Show when={props.children && !props.hideDetails}>
<Show when={props.children && !props.hideDetails && !props.locked}>
<Collapsible.Arrow />
</Show>
</div>
Expand Down
193 changes: 192 additions & 1 deletion packages/ui/src/components/message-part.css
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@
[data-component="tool-part-wrapper"] {
width: 100%;

&[data-permission="true"] {
&[data-permission="true"],
&[data-question="true"] {
position: sticky;
top: calc(2px + var(--sticky-header-height, 40px));
bottom: 0px;
Expand Down Expand Up @@ -490,3 +491,193 @@
justify-content: flex-end;
}
}

[data-component="question-prompt"] {
display: flex;
flex-direction: column;
padding: 12px;
background-color: var(--surface-inset-base);
border-radius: 0 0 6px 6px;
gap: 12px;

[data-slot="question-tabs"] {
display: flex;
gap: 4px;
flex-wrap: wrap;

[data-slot="question-tab"] {
padding: 4px 12px;
font-size: 13px;
border-radius: 4px;
background-color: var(--surface-base);
color: var(--text-base);
border: none;
cursor: pointer;
transition:
color 0.15s,
background-color 0.15s;

&:hover {
background-color: var(--surface-base-hover);
}

&[data-active="true"] {
background-color: var(--surface-raised-base);
}

&[data-answered="true"] {
color: var(--text-strong);
}
}
}

[data-slot="question-content"] {
display: flex;
flex-direction: column;
gap: 8px;

[data-slot="question-text"] {
font-size: 14px;
color: var(--text-base);
line-height: 1.5;
}
}

[data-slot="question-options"] {
display: flex;
flex-direction: column;
gap: 4px;

[data-slot="question-option"] {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 2px;
padding: 8px 12px;
background-color: var(--surface-base);
border: 1px solid var(--border-weaker-base);
border-radius: 6px;
cursor: pointer;
text-align: left;
width: 100%;
transition:
background-color 0.15s,
border-color 0.15s;
position: relative;

&:hover {
background-color: var(--surface-base-hover);
border-color: var(--border-default);
}

&[data-picked="true"] {
[data-component="icon"] {
position: absolute;
right: 12px;
top: 50%;
transform: translateY(-50%);
color: var(--text-strong);
}
}

[data-slot="option-label"] {
font-size: 14px;
color: var(--text-base);
font-weight: 500;
}

[data-slot="option-description"] {
font-size: 12px;
color: var(--text-weak);
}
}

[data-slot="custom-input-form"] {
display: flex;
gap: 8px;
padding: 8px 0;
align-items: stretch;

[data-slot="custom-input"] {
flex: 1;
padding: 8px 12px;
font-size: 14px;
border: 1px solid var(--border-default);
border-radius: 6px;
background-color: var(--surface-base);
color: var(--text-base);
outline: none;

&:focus {
border-color: var(--border-focus);
}

&::placeholder {
color: var(--text-weak);
}
}

[data-component="button"] {
height: auto;
}
}
}

[data-slot="question-review"] {
display: flex;
flex-direction: column;
gap: 12px;

[data-slot="review-title"] {
display: none;
}

[data-slot="review-item"] {
display: flex;
flex-direction: column;
gap: 2px;
font-size: 13px;

[data-slot="review-label"] {
color: var(--text-weak);
}

[data-slot="review-value"] {
color: var(--text-strong);

&[data-answered="false"] {
color: var(--text-weak);
}
}
}
}

[data-slot="question-actions"] {
display: flex;
align-items: center;
gap: 8px;
justify-content: flex-end;
}
}

[data-component="question-answers"] {
display: flex;
flex-direction: column;
gap: 12px;
padding: 8px 12px;

[data-slot="question-answer-item"] {
display: flex;
flex-direction: column;
gap: 2px;
font-size: 13px;

[data-slot="question-text"] {
color: var(--text-weak);
}

[data-slot="answer-text"] {
color: var(--text-strong);
}
}
}
Loading