Skip to content
Open
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
7 changes: 7 additions & 0 deletions packages/opencode/src/tool/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import path from "path"
import { type ToolContext as PluginToolContext, type ToolDefinition } from "@opencode-ai/plugin"
import z from "zod"
import { Plugin } from "../plugin"
import { Question } from "../question"
import { WebSearchTool } from "./websearch"
import { CodeSearchTool } from "./codesearch"
import { Flag } from "@/flag/flag"
Expand Down Expand Up @@ -68,6 +69,12 @@ export namespace ToolRegistry {
...ctx,
directory: Instance.directory,
worktree: Instance.worktree,
askQuestion: (input: { questions: Question.Info[] }) =>
Question.ask({
sessionID: ctx.sessionID,
questions: input.questions,
tool: ctx.callID ? { messageID: ctx.messageID, callID: ctx.callID } : undefined,
}),
} as unknown as PluginToolContext
const result = await def.execute(args as any, pluginCtx)
const out = await Truncate.output(result, {}, initCtx?.agent)
Expand Down
17 changes: 17 additions & 0 deletions packages/plugin/src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type ToolContext = {
abort: AbortSignal
metadata(input: { title?: string; metadata?: { [key: string]: any } }): void
ask(input: AskInput): Promise<void>
askQuestion(input: { questions: QuestionInput[] }): Promise<QuestionAnswer[]>
}

type AskInput = {
Expand All @@ -26,6 +27,22 @@ type AskInput = {
metadata: { [key: string]: any }
}

export type QuestionOption = {
label: string
description: string
}

export type QuestionInput = {
question: string
header: string
options: QuestionOption[]
multiple?: boolean
custom?: boolean
}

/** Each answer is an array of selected labels */
export type QuestionAnswer = string[]

export function tool<Args extends z.ZodRawShape>(input: {
description: string
args: Args
Expand Down
Loading