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
8 changes: 8 additions & 0 deletions packages/app/src/components/prompt-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,13 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
agent,
model: `${model.providerID}/${model.modelID}`,
variant,
parts: images.map((attachment) => ({
id: Identifier.ascending("part"),
type: "file" as const,
mime: attachment.mime,
url: attachment.dataUrl,
filename: attachment.filename,
})),
})
.catch((err) => {
showToast({
Expand Down Expand Up @@ -1188,6 +1195,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
filename: attachment.filename,
}))


const messageID = Identifier.ascending("message")
const textPart = {
id: Identifier.ascending("part"),
Expand Down
6 changes: 6 additions & 0 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ export function Prompt(props: PromptProps) {
model: `${selectedModel.providerID}/${selectedModel.modelID}`,
messageID,
variant,
parts: nonTextParts
.filter((x) => x.type === "file")
.map((x) => ({
id: Identifier.ascending("part"),
...x,
})),
})
} else {
sdk.client.session.prompt({
Expand Down
20 changes: 17 additions & 3 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1422,10 +1422,23 @@ export namespace SessionPrompt {
arguments: z.string(),
command: z.string(),
variant: z.string().optional(),
parts: z
.array(
z.discriminatedUnion("type", [
MessageV2.FilePart.omit({
messageID: true,
sessionID: true,
}).partial({
id: true,
}),
]),
)
.optional(),
})
export type CommandInput = z.infer<typeof CommandInput>
const bashRegex = /!`([^`]+)`/g
const argsRegex = /(?:[^\s"']+|"[^"]*"|'[^']*')+/g
// Match [Image N] as single token, quoted strings, or non-space sequences
const argsRegex = /(?:\[Image\s+\d+\]|"[^"]*"|'[^']*'|[^\s"']+)/gi
const placeholderRegex = /\$(\d+)/g
const quoteTrimRegex = /^["']|["']$/g
/**
Expand Down Expand Up @@ -1516,6 +1529,7 @@ export namespace SessionPrompt {
throw error
}

const templateParts = await resolvePromptParts(template)
const parts =
(agent.mode === "subagent" && command.subtask !== false) || command.subtask === true
? [
Expand All @@ -1525,10 +1539,10 @@ export namespace SessionPrompt {
description: command.description ?? "",
command: input.command,
// TODO: how can we make task tool accept a more complex input?
prompt: await resolvePromptParts(template).then((x) => x.find((y) => y.type === "text")?.text ?? ""),
prompt: templateParts.find((y) => y.type === "text")?.text ?? "",
},
]
: await resolvePromptParts(template)
: [...templateParts, ...(input.parts ?? [])]

const result = (await prompt({
sessionID: input.sessionID,
Expand Down
10 changes: 10 additions & 0 deletions packages/sdk/js/src/v2/gen/sdk.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
ExperimentalResourceListResponses,
FileListResponses,
FilePartInput,
FilePartSource,
FileReadResponses,
FileStatusResponses,
FindFilesResponses,
Expand Down Expand Up @@ -1451,6 +1452,14 @@ export class Session extends HeyApiClient {
arguments?: string
command?: string
variant?: string
parts?: Array<{
id?: string
type: "file"
mime: string
filename?: string
url: string
source?: FilePartSource
}>
},
options?: Options<never, ThrowOnError>,
) {
Expand All @@ -1467,6 +1476,7 @@ export class Session extends HeyApiClient {
{ in: "body", key: "arguments" },
{ in: "body", key: "command" },
{ in: "body", key: "variant" },
{ in: "body", key: "parts" },
],
},
],
Expand Down
8 changes: 8 additions & 0 deletions packages/sdk/js/src/v2/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3292,6 +3292,14 @@ export type SessionCommandData = {
arguments: string
command: string
variant?: string
parts?: Array<{
id?: string
type: "file"
mime: string
filename?: string
url: string
source?: FilePartSource
}>
}
path: {
/**
Expand Down
32 changes: 32 additions & 0 deletions packages/sdk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,38 @@
},
"variant": {
"type": "string"
},
"parts": {
"type": "array",
"items": {
"anyOf": [
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string",
"const": "file"
},
"mime": {
"type": "string"
},
"filename": {
"type": "string"
},
"url": {
"type": "string"
},
"source": {
"$ref": "#/components/schemas/FilePartSource"
}
},
"required": ["type", "mime", "url"]
}
]
}
}
},
"required": ["arguments", "command"]
Expand Down