mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-23 18:54:21 +01:00
wip: desktop work
This commit is contained in:
@@ -15,11 +15,13 @@ import type { BashTool } from "opencode/tool/bash"
|
|||||||
import type { EditTool } from "opencode/tool/edit"
|
import type { EditTool } from "opencode/tool/edit"
|
||||||
import type { WriteTool } from "opencode/tool/write"
|
import type { WriteTool } from "opencode/tool/write"
|
||||||
import { DiffChanges } from "./diff-changes"
|
import { DiffChanges } from "./diff-changes"
|
||||||
|
import { TodoWriteTool } from "opencode/tool/todo"
|
||||||
|
|
||||||
export function AssistantMessage(props: { message: AssistantMessage; parts: Part[] }) {
|
export function AssistantMessage(props: { message: AssistantMessage; parts: Part[] }) {
|
||||||
|
const filteredParts = createMemo(() => props.parts.filter((x) => x.type !== "tool" || x.tool !== "todoread"))
|
||||||
return (
|
return (
|
||||||
<div class="w-full flex flex-col items-start gap-4">
|
<div class="w-full flex flex-col items-start gap-4">
|
||||||
<For each={props.parts}>
|
<For each={filteredParts()}>
|
||||||
{(part) => {
|
{(part) => {
|
||||||
const component = createMemo(() => PART_MAPPING[part.type as keyof typeof PART_MAPPING])
|
const component = createMemo(() => PART_MAPPING[part.type as keyof typeof PART_MAPPING])
|
||||||
return (
|
return (
|
||||||
@@ -88,8 +90,11 @@ function ToolPart(props: { part: ToolPart; message: AssistantMessage }) {
|
|||||||
|
|
||||||
type TriggerTitle = {
|
type TriggerTitle = {
|
||||||
title: string
|
title: string
|
||||||
|
titleClass?: string
|
||||||
subtitle?: string
|
subtitle?: string
|
||||||
|
subtitleClass?: string
|
||||||
args?: string[]
|
args?: string[]
|
||||||
|
argsClass?: string
|
||||||
action?: JSX.Element
|
action?: JSX.Element
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,35 +104,59 @@ const isTriggerTitle = (val: any): val is TriggerTitle => {
|
|||||||
|
|
||||||
function BasicTool(props: { icon: IconProps["name"]; trigger: TriggerTitle | JSX.Element; children?: JSX.Element }) {
|
function BasicTool(props: { icon: IconProps["name"]; trigger: TriggerTitle | JSX.Element; children?: JSX.Element }) {
|
||||||
const resolved = children(() => props.children)
|
const resolved = children(() => props.children)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Collapsible>
|
<Collapsible>
|
||||||
<Collapsible.Trigger>
|
<Collapsible.Trigger>
|
||||||
<div class="w-full flex items-center self-stretch gap-5 justify-between">
|
<div class="w-full flex items-center self-stretch gap-5 justify-between">
|
||||||
<div class="w-full flex items-center self-stretch gap-5">
|
<div class="w-full flex items-center self-stretch gap-5">
|
||||||
<Icon name={props.icon} size="small" />
|
<Icon name={props.icon} size="small" class="shrink-0" />
|
||||||
|
<div class="grow min-w-0">
|
||||||
<Switch>
|
<Switch>
|
||||||
<Match when={isTriggerTitle(props.trigger)}>
|
<Match when={isTriggerTitle(props.trigger) && props.trigger}>
|
||||||
|
{(trigger) => (
|
||||||
<div class="w-full flex items-center gap-2 justify-between">
|
<div class="w-full flex items-center gap-2 justify-between">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2 whitespace-nowrap truncate">
|
||||||
<span class="text-12-medium text-text-base capitalize">
|
<span
|
||||||
{(props.trigger as TriggerTitle).title}
|
classList={{
|
||||||
|
"text-12-medium text-text-base": true,
|
||||||
|
[trigger().titleClass ?? ""]: !!trigger().titleClass,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{trigger().title}
|
||||||
|
</span>
|
||||||
|
<Show when={trigger().subtitle}>
|
||||||
|
<span
|
||||||
|
classList={{
|
||||||
|
"text-12-medium text-text-weak": true,
|
||||||
|
[trigger().subtitleClass ?? ""]: !!trigger().subtitleClass,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{trigger().subtitle}
|
||||||
</span>
|
</span>
|
||||||
<Show when={(props.trigger as TriggerTitle).subtitle}>
|
|
||||||
<span class="text-12-medium text-text-weak">{(props.trigger as TriggerTitle).subtitle}</span>
|
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={(props.trigger as TriggerTitle).args?.length}>
|
<Show when={trigger().args?.length}>
|
||||||
<For each={(props.trigger as TriggerTitle).args}>
|
<For each={trigger().args}>
|
||||||
{(arg) => <span class="text-12-regular text-text-weaker">{arg}</span>}
|
{(arg) => (
|
||||||
|
<span
|
||||||
|
classList={{
|
||||||
|
"text-12-regular text-text-weak": true,
|
||||||
|
[trigger().argsClass ?? ""]: !!trigger().argsClass,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{arg}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</For>
|
</For>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
<Show when={(props.trigger as TriggerTitle).action}>{(props.trigger as TriggerTitle).action}</Show>
|
<Show when={trigger().action}>{trigger().action}</Show>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={true}>{props.trigger as JSX.Element}</Match>
|
<Match when={true}>{props.trigger as JSX.Element}</Match>
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<Show when={resolved()}>
|
<Show when={resolved()}>
|
||||||
<Collapsible.Arrow />
|
<Collapsible.Arrow />
|
||||||
</Show>
|
</Show>
|
||||||
@@ -178,7 +207,7 @@ ToolRegistry.register<typeof ReadTool>({
|
|||||||
return (
|
return (
|
||||||
<BasicTool
|
<BasicTool
|
||||||
icon="glasses"
|
icon="glasses"
|
||||||
trigger={{ title: props.tool, subtitle: props.input.filePath ? getFilename(props.input.filePath) : "" }}
|
trigger={{ title: "Read", subtitle: props.input.filePath ? getFilename(props.input.filePath) : "" }}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -188,7 +217,7 @@ ToolRegistry.register<typeof ListTool>({
|
|||||||
name: "list",
|
name: "list",
|
||||||
render(props) {
|
render(props) {
|
||||||
return (
|
return (
|
||||||
<BasicTool icon="bullet-list" trigger={{ title: props.tool, subtitle: getDirectory(props.input.path || "/") }}>
|
<BasicTool icon="bullet-list" trigger={{ title: "List", subtitle: getDirectory(props.input.path || "/") }}>
|
||||||
<Show when={false && props.output}>
|
<Show when={false && props.output}>
|
||||||
<div class="whitespace-pre">{props.output}</div>
|
<div class="whitespace-pre">{props.output}</div>
|
||||||
</Show>
|
</Show>
|
||||||
@@ -204,7 +233,7 @@ ToolRegistry.register<typeof GlobTool>({
|
|||||||
<BasicTool
|
<BasicTool
|
||||||
icon="magnifying-glass-menu"
|
icon="magnifying-glass-menu"
|
||||||
trigger={{
|
trigger={{
|
||||||
title: props.tool,
|
title: "Glob",
|
||||||
subtitle: getDirectory(props.input.path || "/"),
|
subtitle: getDirectory(props.input.path || "/"),
|
||||||
args: props.input.pattern ? ["pattern=" + props.input.pattern] : [],
|
args: props.input.pattern ? ["pattern=" + props.input.pattern] : [],
|
||||||
}}
|
}}
|
||||||
@@ -227,7 +256,7 @@ ToolRegistry.register<typeof GrepTool>({
|
|||||||
<BasicTool
|
<BasicTool
|
||||||
icon="magnifying-glass-menu"
|
icon="magnifying-glass-menu"
|
||||||
trigger={{
|
trigger={{
|
||||||
title: props.tool,
|
title: "Grep",
|
||||||
subtitle: getDirectory(props.input.path || "/"),
|
subtitle: getDirectory(props.input.path || "/"),
|
||||||
args,
|
args,
|
||||||
}}
|
}}
|
||||||
@@ -247,7 +276,7 @@ ToolRegistry.register<typeof WebFetchTool>({
|
|||||||
<BasicTool
|
<BasicTool
|
||||||
icon="window-cursor"
|
icon="window-cursor"
|
||||||
trigger={{
|
trigger={{
|
||||||
title: props.tool,
|
title: "Webfetch",
|
||||||
subtitle: props.input.url || "",
|
subtitle: props.input.url || "",
|
||||||
args: props.input.format ? ["format=" + props.input.format] : [],
|
args: props.input.format ? ["format=" + props.input.format] : [],
|
||||||
action: (
|
action: (
|
||||||
@@ -273,6 +302,7 @@ ToolRegistry.register<typeof TaskTool>({
|
|||||||
icon="task"
|
icon="task"
|
||||||
trigger={{
|
trigger={{
|
||||||
title: `${props.input.subagent_type || props.tool} Agent`,
|
title: `${props.input.subagent_type || props.tool} Agent`,
|
||||||
|
titleClass: "capitalize",
|
||||||
subtitle: props.input.description,
|
subtitle: props.input.description,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -311,7 +341,7 @@ ToolRegistry.register<typeof EditTool>({
|
|||||||
icon="code-lines"
|
icon="code-lines"
|
||||||
trigger={
|
trigger={
|
||||||
<div class="flex items-center justify-between w-full">
|
<div class="flex items-center justify-between w-full">
|
||||||
<div class="flex items-center gap-5">
|
<div class="flex items-center gap-2">
|
||||||
<div class="text-12-medium text-text-base capitalize">Edit</div>
|
<div class="text-12-medium text-text-base capitalize">Edit</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<Show when={props.input.filePath?.includes("/")}>
|
<Show when={props.input.filePath?.includes("/")}>
|
||||||
@@ -340,7 +370,7 @@ ToolRegistry.register<typeof WriteTool>({
|
|||||||
icon="code-lines"
|
icon="code-lines"
|
||||||
trigger={
|
trigger={
|
||||||
<div class="flex items-center justify-between w-full">
|
<div class="flex items-center justify-between w-full">
|
||||||
<div class="flex items-center gap-5">
|
<div class="flex items-center gap-2">
|
||||||
<div class="text-12-medium text-text-base capitalize">Write</div>
|
<div class="text-12-medium text-text-base capitalize">Write</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<Show when={props.input.filePath?.includes("/")}>
|
<Show when={props.input.filePath?.includes("/")}>
|
||||||
@@ -360,3 +390,22 @@ ToolRegistry.register<typeof WriteTool>({
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ToolRegistry.register<typeof TodoWriteTool>({
|
||||||
|
name: "todowrite",
|
||||||
|
render(props) {
|
||||||
|
return (
|
||||||
|
<BasicTool
|
||||||
|
icon="checklist"
|
||||||
|
trigger={{
|
||||||
|
title: "To-dos",
|
||||||
|
subtitle: `${props.input.todos?.filter((t) => t.status === "completed").length}/${props.input.todos?.length}`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Show when={false && props.output}>
|
||||||
|
<div class="whitespace-pre">{props.output}</div>
|
||||||
|
</Show>
|
||||||
|
</BasicTool>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|||||||
@@ -696,24 +696,24 @@ export default function Page() {
|
|||||||
<Accordion.Item value={diff.file}>
|
<Accordion.Item value={diff.file}>
|
||||||
<Accordion.Header>
|
<Accordion.Header>
|
||||||
<Accordion.Trigger onClick={handleDiffTriggerClick}>
|
<Accordion.Trigger onClick={handleDiffTriggerClick}>
|
||||||
<div class="flex items-center justify-between w-full">
|
<div class="flex items-center justify-between w-full gap-5">
|
||||||
<div class="flex items-center gap-5">
|
<div class="grow flex items-center gap-5 min-w-0">
|
||||||
<FileIcon
|
<FileIcon
|
||||||
node={{ path: diff.file, type: "file" }}
|
node={{ path: diff.file, type: "file" }}
|
||||||
class="shrink-0 size-4"
|
class="shrink-0 size-4"
|
||||||
/>
|
/>
|
||||||
<div class="flex">
|
<div class="flex grow min-w-0">
|
||||||
<Show when={diff.file.includes("/")}>
|
<Show when={diff.file.includes("/")}>
|
||||||
<span class="text-text-base">
|
<span class="text-text-base truncate-start">
|
||||||
{getDirectory(diff.file)}
|
{getDirectory(diff.file)}‎
|
||||||
</span>
|
</span>
|
||||||
</Show>
|
</Show>
|
||||||
<span class="text-text-strong">
|
<span class="text-text-strong shrink-0">
|
||||||
{getFilename(diff.file)}
|
{getFilename(diff.file)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex gap-4 items-center justify-end">
|
<div class="shrink-0 flex gap-4 items-center justify-end">
|
||||||
<DiffChanges diff={diff} />
|
<DiffChanges diff={diff} />
|
||||||
<Icon name="chevron-grabber-vertical" size="small" />
|
<Icon name="chevron-grabber-vertical" size="small" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,3 +7,11 @@
|
|||||||
scrollbar-width: none; /* Firefox */
|
scrollbar-width: none; /* Firefox */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@utility truncate-start {
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
direction: rtl;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,6 +48,14 @@
|
|||||||
border-width: 0;
|
border-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.truncate-start {
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
direction: rtl;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
.text-12-regular {
|
.text-12-regular {
|
||||||
font-family: var(--font-family-sans);
|
font-family: var(--font-family-sans);
|
||||||
font-size: var(--font-size-small);
|
font-size: var(--font-size-small);
|
||||||
|
|||||||
Reference in New Issue
Block a user