@zyro-sec/session-ui 0.0.0-stage → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +25 -0
- package/bunfig.toml +2 -0
- package/component-tests/basic-tool.fixture.tsx +46 -0
- package/component-tests/basic-tool.spec.ts +63 -0
- package/component-tests/file-media.fixture.tsx +39 -0
- package/component-tests/file-media.spec.ts +13 -0
- package/component-tests/file-tool.spec.ts +62 -0
- package/component-tests/file-viewer.fixture.tsx +109 -0
- package/component-tests/file-viewer.spec.ts +134 -0
- package/component-tests/file.spec.ts +33 -0
- package/component-tests/line-comment-v2.spec.ts +15 -0
- package/component-tests/markdown-code-wrap.spec.ts +94 -0
- package/component-tests/markdown-readiness.spec.ts +95 -0
- package/component-tests/markdown.fixture.tsx +104 -0
- package/component-tests/markdown.spec.ts +1564 -0
- package/component-tests/mermaid-preview.spec.ts +43 -0
- package/component-tests/patch-group.spec.ts +79 -0
- package/component-tests/read-group.spec.ts +72 -0
- package/component-tests/read-image.fixture.tsx +66 -0
- package/component-tests/read-image.spec.ts +154 -0
- package/component-tests/session-compaction.spec.ts +254 -0
- package/component-tests/session-lifecycle.spec.ts +190 -0
- package/component-tests/session-message-projection.spec.ts +639 -0
- package/component-tests/session-notice-projection.spec.ts +20 -0
- package/component-tests/session-review-comments.spec.ts +179 -0
- package/component-tests/session-shell.spec.ts +93 -0
- package/component-tests/session-timeline-mobile.spec.ts +201 -0
- package/component-tests/session-timeline-notices.spec.ts +38 -0
- package/component-tests/session-timeline-reasoning.spec.ts +107 -0
- package/component-tests/session-timeline.spec.ts +157 -0
- package/component-tests/session-tool-projection.spec.ts +323 -0
- package/component-tests/text-lifecycle.fixture.tsx +26 -0
- package/component-tests/text-lifecycle.spec.ts +42 -0
- package/component-tests/timeline-subagent-rows.spec.ts +33 -0
- package/component-tests/tool-disclosure.spec.ts +48 -0
- package/component-tests/tool-group-sticky.spec.ts +37 -0
- package/component-tests/tool-group.spec.ts +290 -0
- package/component-tests/tool-status-title.fixture.tsx +22 -0
- package/component-tests/tool-status-title.spec.ts +30 -0
- package/component-tests/user-message-quotes.spec.ts +111 -0
- package/package.json +91 -4
- package/playwright.components.config.ts +4 -0
- package/playwright.local.config.ts +2 -0
- package/src/actions.ts +54 -0
- package/src/components/apply-patch-file.ts +122 -0
- package/src/components/basic-tool.css +487 -0
- package/src/components/basic-tool.tsx +258 -0
- package/src/components/copy-machine.ts +78 -0
- package/src/components/copy.ts +85 -0
- package/src/components/diagram-preview.tsx +28 -0
- package/src/components/disclosure-machine.ts +188 -0
- package/src/components/disclosure.ts +129 -0
- package/src/components/dock-prompt.stories.tsx +73 -0
- package/src/components/dock-prompt.tsx +29 -0
- package/src/components/file-comment-selection.tsx +146 -0
- package/src/components/file-media-machine.ts +165 -0
- package/src/components/file-media.stories.tsx +112 -0
- package/src/components/file-media.tsx +323 -0
- package/src/components/file-search.tsx +73 -0
- package/src/components/file.css +59 -0
- package/src/components/file.tsx +1300 -0
- package/src/components/image-preview.tsx +35 -0
- package/src/components/line-comment-annotations.tsx +580 -0
- package/src/components/line-comment-machine.ts +262 -0
- package/src/components/line-comment-styles.ts +293 -0
- package/src/components/line-comment.stories.tsx +152 -0
- package/src/components/line-comment.tsx +448 -0
- package/src/components/link-segments.ts +20 -0
- package/src/components/linked-text.tsx +21 -0
- package/src/components/markdown-cache-machine.ts +257 -0
- package/src/components/markdown-cache.tsx +556 -0
- package/src/components/markdown-clipboard.ts +101 -0
- package/src/components/markdown-code-machine.ts +200 -0
- package/src/components/markdown-code-state.ts +22 -0
- package/src/components/markdown-fragment-links.ts +74 -0
- package/src/components/markdown-github.svg +3 -0
- package/src/components/markdown-globe.svg +5 -0
- package/src/components/markdown-image-machine.ts +170 -0
- package/src/components/markdown-image.ts +156 -0
- package/src/components/markdown-inline-code-kind.ts +39 -0
- package/src/components/markdown-mermaid.ts +18 -0
- package/src/components/markdown-phase-machine.ts +102 -0
- package/src/components/markdown-projection.ts +13 -0
- package/src/components/markdown-session-links.ts +183 -0
- package/src/components/markdown-solid.test.tsx +92 -0
- package/src/components/markdown-solid.tsx +113 -0
- package/src/components/markdown-stream.ts +95 -0
- package/src/components/markdown-worker-machine.ts +516 -0
- package/src/components/markdown-worker-protocol.ts +73 -0
- package/src/components/markdown-worker.ts +250 -0
- package/src/components/markdown.css +672 -0
- package/src/components/markdown.stories.tsx +199 -0
- package/src/components/markdown.tsx +1612 -0
- package/src/components/markdown.worker.ts +188 -0
- package/src/components/message-file.ts +102 -0
- package/src/components/message-nav.css +134 -0
- package/src/components/message-nav.tsx +159 -0
- package/src/components/message-part.css +2109 -0
- package/src/components/message-part.tsx +3 -0
- package/src/components/question-prompt-experimental.css +576 -0
- package/src/components/question-prompt.css +527 -0
- package/src/components/quote-highlight.css +59 -0
- package/src/components/review-focus-driver.ts +142 -0
- package/src/components/review-focus-machine.ts +95 -0
- package/src/components/session-compaction.css +270 -0
- package/src/components/session-diff.ts +358 -0
- package/src/components/session-error.tsx +41 -0
- package/src/components/session-retry.tsx +92 -0
- package/src/components/session-review-machine.ts +241 -0
- package/src/components/session-review.css +264 -0
- package/src/components/session-review.stories.tsx +232 -0
- package/src/components/session-review.tsx +733 -0
- package/src/components/session-turn.css +282 -0
- package/src/components/shell-submessage.css +24 -0
- package/src/components/timeline-separator.tsx +69 -0
- package/src/components/tool-count-label.css +57 -0
- package/src/components/tool-count-label.tsx +76 -0
- package/src/components/tool-count-summary.css +102 -0
- package/src/components/tool-count-summary.stories.tsx +99 -0
- package/src/components/tool-count-summary.tsx +44 -0
- package/src/components/tool-error-card.css +178 -0
- package/src/components/tool-error-card.stories.tsx +113 -0
- package/src/components/tool-error-card.tsx +202 -0
- package/src/components/tool-status-title-machine.ts +128 -0
- package/src/components/tool-status-title.css +89 -0
- package/src/components/tool-status-title.tsx +163 -0
- package/src/context/data.tsx +107 -0
- package/src/context/index.ts +1 -0
- package/src/context/markdown.tsx +129 -0
- package/src/context/sources.tsx +34 -0
- package/src/document.ts +8 -0
- package/src/file-presentation.ts +34 -0
- package/src/message/action-machine.ts +72 -0
- package/src/message/agent-label.ts +3 -0
- package/src/message/attachment-card.css +119 -0
- package/src/message/attachment-card.tsx +40 -0
- package/src/message/attachment-media-machine.ts +213 -0
- package/src/message/comment-card.tsx +155 -0
- package/src/message/compaction-entrance-machine.ts +93 -0
- package/src/message/current-message.tsx +157 -0
- package/src/message/current-tool-state.ts +161 -0
- package/src/message/message-content.tsx +1391 -0
- package/src/message/paced-text-machine.ts +73 -0
- package/src/message/prompt-message.stories.tsx +149 -0
- package/src/message/relative-time.ts +45 -0
- package/src/message/user-message-quote-parts.ts +16 -0
- package/src/message/user-message-quotes.stories.tsx +797 -0
- package/src/message/user-message-quotes.tsx +135 -0
- package/src/pierre/comment-hover-machine.ts +53 -0
- package/src/pierre/comment-hover.ts +131 -0
- package/src/pierre/comment-selection-machine.ts +257 -0
- package/src/pierre/commented-lines.ts +106 -0
- package/src/pierre/diff-selection.ts +91 -0
- package/src/pierre/file-find-machine.ts +323 -0
- package/src/pierre/file-find.ts +537 -0
- package/src/pierre/file-runtime.ts +42 -0
- package/src/pierre/file-selection.ts +140 -0
- package/src/pierre/index.ts +344 -0
- package/src/pierre/media.ts +140 -0
- package/src/pierre/render-machine.ts +381 -0
- package/src/pierre/selection-bridge.ts +82 -0
- package/src/pierre/selection-machine.ts +198 -0
- package/src/pierre/virtualizer.ts +114 -0
- package/src/pierre/worker.ts +46 -0
- package/src/sources/experiment.ts +59 -0
- package/src/sources/site-icon.tsx +53 -0
- package/src/sources/sources-chip.tsx +57 -0
- package/src/sources/sources-expand-machine.ts +101 -0
- package/src/sources/sources-panel.tsx +249 -0
- package/src/sources/sources-title.tsx +21 -0
- package/src/sources/sources.css +266 -0
- package/src/sources/sources.ts +141 -0
- package/src/storybook/current-session-fixtures.ts +1492 -0
- package/src/storybook/current-session-scenarios.ts +76 -0
- package/src/storybook/current-session-story.tsx +154 -0
- package/src/storybook/index.ts +43 -0
- package/src/styles/index.css +19 -0
- package/src/timeline/__snapshots__/group-labels.test.ts.snap +110 -0
- package/src/timeline/__snapshots__/placement.test.ts.snap +1041 -0
- package/src/timeline/code-blocks.stories.tsx +105 -0
- package/src/timeline/commentary.stories.tsx +70 -0
- package/src/timeline/commentary.ts +38 -0
- package/src/timeline/detail.ts +111 -0
- package/src/timeline/error-card.stories.tsx +134 -0
- package/src/timeline/error-spacing.stories.tsx +71 -0
- package/src/timeline/facts.ts +493 -0
- package/src/timeline/file-changes.stories.tsx +436 -0
- package/src/timeline/group-label-fixtures.ts +97 -0
- package/src/timeline/mermaid.stories.tsx +131 -0
- package/src/timeline/place.ts +280 -0
- package/src/timeline/placement-fixtures.ts +365 -0
- package/src/timeline/placement-reactivity.ts +133 -0
- package/src/timeline/projection.ts +1261 -0
- package/src/timeline/research-and-agents.stories.tsx +461 -0
- package/src/timeline/session-timeline-row.tsx +1675 -0
- package/src/timeline/session-timeline.tsx +68 -0
- package/src/timeline/steer-arrival-machine.ts +134 -0
- package/src/timeline/terminal-work.stories.tsx +464 -0
- package/src/timeline/timeline-row.stories.tsx +1069 -0
- package/src/timeline/timeline-row.ts +238 -0
- package/src/timeline/turn-phase-machine.ts +112 -0
- package/src/timeline/user-message-fold.stories.tsx +194 -0
- package/src/timeline/user-runs.ts +87 -0
- package/src/timeline-next/__snapshots__/placement.test.ts.snap +990 -0
- package/src/timeline-next/compaction.tsx +236 -0
- package/src/timeline-next/errors.ts +101 -0
- package/src/timeline-next/event-row.tsx +168 -0
- package/src/timeline-next/events.ts +103 -0
- package/src/timeline-next/index.ts +10 -0
- package/src/timeline-next/nested-rail.ts +125 -0
- package/src/timeline-next/projection.ts +1028 -0
- package/src/timeline-next/row.tsx +1728 -0
- package/src/timeline-next/rules.ts +89 -0
- package/src/timeline-next/separator.tsx +73 -0
- package/src/timeline-next/spacing.ts +127 -0
- package/src/timeline-next/status-line.tsx +41 -0
- package/src/timeline-next/status.ts +33 -0
- package/src/timeline-next/stories/compare-renderer.stories.tsx +190 -0
- package/src/timeline-next/stories/compare-sessions/.gitignore +3 -0
- package/src/timeline-next/stories/compare.stories.tsx +486 -0
- package/src/timeline-next/stories/playground.stories.tsx +297 -0
- package/src/timeline-next/stories/session-replay.ts +1156 -0
- package/src/timeline-next/stories/session-timeline.tsx +50 -0
- package/src/timeline-next/stories/subagent-status.stories.tsx +132 -0
- package/src/timeline-next/timeline-next.css +649 -0
- package/src/timeline-next/tools/__snapshots__/activity-label.test.ts.snap +39 -0
- package/src/timeline-next/tools/activity-label.ts +166 -0
- package/src/timeline-next/tools/assistant-content.tsx +84 -0
- package/src/timeline-next/tools/context-group.tsx +619 -0
- package/src/timeline-next/tools/error-card.tsx +147 -0
- package/src/timeline-next/tools/explore.tsx +119 -0
- package/src/timeline-next/tools/file-group.tsx +128 -0
- package/src/timeline-next/tools/patch.tsx +174 -0
- package/src/timeline-next/tools/shell.tsx +186 -0
- package/src/timeline-next/tools/thought.tsx +87 -0
- package/src/timeline-next/tools/tool-display.tsx +119 -0
- package/src/tools/ansi.ts +8 -0
- package/src/tools/context-group-label.ts +123 -0
- package/src/tools/file-runs.ts +35 -0
- package/src/tools/project-path.ts +18 -0
- package/src/tools/read-group.stories.tsx +159 -0
- package/src/tools/run-machine.ts +185 -0
- package/src/tools/shell-output-machine.ts +233 -0
- package/src/tools/shell-output.ts +91 -0
- package/src/tools/subagent-row-variants.stories.tsx +129 -0
- package/src/tools/tool-group.stories.tsx +345 -0
- package/src/tools/tool-renderer.tsx +2876 -0
- package/src/v2/components/line-comment-annotations-v2.tsx +215 -0
- package/src/v2/components/session-file-panel-v2.tsx +149 -0
- package/src/v2/components/session-progress-indicator-v2.css +5 -0
- package/src/v2/components/session-progress-indicator-v2.stories.tsx +86 -0
- package/src/v2/components/session-progress-indicator-v2.tsx +16 -0
- package/src/v2/components/session-review-empty-changes-v2.tsx +17 -0
- package/src/v2/components/session-review-empty-no-git-v2.tsx +28 -0
- package/src/v2/components/session-review-file-preview-v2-virtualize.ts +5 -0
- package/src/v2/components/session-review-file-preview-v2.tsx +266 -0
- package/src/v2/components/session-review-v2.css +653 -0
- package/src/v2/components/session-review-v2.tsx +422 -0
- package/src/v2/components/sidebar-presence-machine.ts +69 -0
- package/tsconfig.json +20 -0
- package/README.md +0 -3
|
@@ -0,0 +1,2876 @@
|
|
|
1
|
+
// Current Session tool presentation grouped by visual family.
|
|
2
|
+
import {
|
|
3
|
+
type Accessor,
|
|
4
|
+
Component,
|
|
5
|
+
batch,
|
|
6
|
+
createComputed,
|
|
7
|
+
createEffect,
|
|
8
|
+
createMemo,
|
|
9
|
+
createSignal,
|
|
10
|
+
createUniqueId,
|
|
11
|
+
For,
|
|
12
|
+
Match,
|
|
13
|
+
onCleanup,
|
|
14
|
+
onMount,
|
|
15
|
+
Show,
|
|
16
|
+
Switch,
|
|
17
|
+
Index,
|
|
18
|
+
on,
|
|
19
|
+
untrack,
|
|
20
|
+
type JSX,
|
|
21
|
+
} from "solid-js"
|
|
22
|
+
import { createStore } from "solid-js/store"
|
|
23
|
+
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
|
24
|
+
import { Effect, Option, Schema } from "effect"
|
|
25
|
+
import { createTwoFilesPatch, diffLines } from "diff"
|
|
26
|
+
import { Dynamic } from "solid-js/web"
|
|
27
|
+
import { type SessionSummary, useData } from "../context"
|
|
28
|
+
import { useFileComponent } from "@zyro-sec/ui/context/file"
|
|
29
|
+
import { type UiI18n, useI18n } from "@zyro-sec/ui/context/i18n"
|
|
30
|
+
import { BasicTool, GenericTool } from "../components/basic-tool"
|
|
31
|
+
import { createDisclosure } from "../components/disclosure"
|
|
32
|
+
import { FileIcon } from "@zyro-sec/ui/file-icon"
|
|
33
|
+
import { Icon } from "@zyro-sec/ui/icon"
|
|
34
|
+
import { ToolErrorCard } from "../components/tool-error-card"
|
|
35
|
+
import { DiffChanges } from "@zyro-sec/ui/diff-changes"
|
|
36
|
+
import { Markdown } from "../components/markdown"
|
|
37
|
+
import { createMarkdownImages } from "../components/markdown-image"
|
|
38
|
+
import { createImagePreview } from "../components/image-preview"
|
|
39
|
+
import { useMarkdown } from "../context/markdown"
|
|
40
|
+
import { getDirectory, getFilename } from "@zyro-sec/util/path"
|
|
41
|
+
import { checksum } from "@zyro-sec/util/encode"
|
|
42
|
+
import { formatExecuteOutput } from "@zyro-sec/util/execute-output"
|
|
43
|
+
import { Badge } from "@zyro-sec/ui/badge"
|
|
44
|
+
import { Tooltip } from "@zyro-sec/ui/tooltip"
|
|
45
|
+
import { useDialog } from "@zyro-sec/ui/context/dialog"
|
|
46
|
+
import { Dialog, DialogBody, DialogHeader, DialogTitle } from "@zyro-sec/ui/dialog"
|
|
47
|
+
import { IconButton } from "@zyro-sec/ui/icon-button"
|
|
48
|
+
import { TextShimmer } from "@zyro-sec/ui/text-shimmer"
|
|
49
|
+
import { AnimatedNumber } from "@zyro-sec/ui/animated-number"
|
|
50
|
+
import { changedFileDiff, patchFileGroups } from "../components/apply-patch-file"
|
|
51
|
+
import { animate } from "@kitlangton/solid-motion"
|
|
52
|
+
import { SessionProgressIndicatorV2 } from "../v2/components/session-progress-indicator-v2"
|
|
53
|
+
import type {
|
|
54
|
+
FileDiffInfo,
|
|
55
|
+
SessionMessageAssistantReasoning,
|
|
56
|
+
SessionMessageAssistantTool,
|
|
57
|
+
SessionMessageShell,
|
|
58
|
+
} from "@zyro-sec/client/promise"
|
|
59
|
+
import {
|
|
60
|
+
currentToolError,
|
|
61
|
+
currentToolGroupedRead,
|
|
62
|
+
currentToolInput,
|
|
63
|
+
currentToolMetadata,
|
|
64
|
+
currentToolOutput,
|
|
65
|
+
executeToolCallArgs,
|
|
66
|
+
executeToolCallCount,
|
|
67
|
+
executeToolCalls,
|
|
68
|
+
executeToolErrorIndex,
|
|
69
|
+
executeToolSubtitle,
|
|
70
|
+
readImagePath,
|
|
71
|
+
type ExecuteToolCall,
|
|
72
|
+
} from "../message/current-tool-state"
|
|
73
|
+
import { AssistantReasoningContent } from "../message/message-content"
|
|
74
|
+
import { createCopyFeedback } from "../components/copy"
|
|
75
|
+
import { stripAnsi } from "./ansi"
|
|
76
|
+
import { relativizeProjectPath } from "./project-path"
|
|
77
|
+
import { createShellFollower } from "./shell-output"
|
|
78
|
+
import {
|
|
79
|
+
createShellRunState,
|
|
80
|
+
shellRunProps,
|
|
81
|
+
subagentRunProps,
|
|
82
|
+
transitionShellRun,
|
|
83
|
+
transitionSubagentRun,
|
|
84
|
+
viewShellRun,
|
|
85
|
+
viewSubagentRun,
|
|
86
|
+
INITIAL_SUBAGENT_RUN_STATE,
|
|
87
|
+
stoppedShell,
|
|
88
|
+
type ShellRunEvent,
|
|
89
|
+
type SubagentRunState,
|
|
90
|
+
} from "./run-machine"
|
|
91
|
+
import { LinkedText } from "../components/linked-text"
|
|
92
|
+
|
|
93
|
+
export function ShellSubmessage(props: { text: string; animate?: boolean }) {
|
|
94
|
+
let widthRef: HTMLSpanElement | undefined
|
|
95
|
+
let valueRef: HTMLSpanElement | undefined
|
|
96
|
+
|
|
97
|
+
onMount(() => {
|
|
98
|
+
if (!props.animate) return
|
|
99
|
+
requestAnimationFrame(() => {
|
|
100
|
+
if (widthRef) {
|
|
101
|
+
animate(widthRef, { width: "auto" }, { type: "spring", visualDuration: 0.25, bounce: 0 })
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (valueRef) {
|
|
105
|
+
valueRef.animate?.(
|
|
106
|
+
{ opacity: [0, 1], filter: ["blur(2px)", "blur(0px)"] },
|
|
107
|
+
{ duration: 320, easing: "cubic-bezier(0.16, 1, 0.3, 1)" },
|
|
108
|
+
)
|
|
109
|
+
valueRef.style.opacity = "1"
|
|
110
|
+
valueRef.style.filter = "blur(0px)"
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<span data-component="shell-submessage" dir="ltr">
|
|
117
|
+
<span ref={widthRef} data-slot="shell-submessage-width" style={{ width: props.animate ? "0px" : undefined }}>
|
|
118
|
+
<span data-slot="basic-tool-tool-subtitle">
|
|
119
|
+
<span
|
|
120
|
+
ref={valueRef}
|
|
121
|
+
data-slot="shell-submessage-value"
|
|
122
|
+
style={props.animate ? { opacity: 0, filter: "blur(2px)" } : undefined}
|
|
123
|
+
>
|
|
124
|
+
{props.text}
|
|
125
|
+
</span>
|
|
126
|
+
</span>
|
|
127
|
+
</span>
|
|
128
|
+
</span>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Tool input and metadata are open records shared by every tool. Each field decodes on its own,
|
|
133
|
+
// so a malformed value drops only that field. Plugin tools are untyped at runtime, so a record that
|
|
134
|
+
// is not an object reads as empty instead of failing the render.
|
|
135
|
+
function optional<S extends Schema.ConstraintCodec<unknown, unknown>>(schema: S) {
|
|
136
|
+
const field = Schema.optional(schema)
|
|
137
|
+
|
|
138
|
+
return Schema.catchDecoding<typeof field>(() => Effect.succeed(Option.none()))(field)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const toolInput = Schema.decodeUnknownSync(
|
|
142
|
+
Schema.Struct({
|
|
143
|
+
path: optional(Schema.String),
|
|
144
|
+
pattern: optional(Schema.String),
|
|
145
|
+
include: optional(Schema.String),
|
|
146
|
+
offset: optional(Schema.Number),
|
|
147
|
+
limit: optional(Schema.Number),
|
|
148
|
+
url: optional(Schema.String),
|
|
149
|
+
query: optional(Schema.String),
|
|
150
|
+
agent: optional(Schema.String),
|
|
151
|
+
description: optional(Schema.String),
|
|
152
|
+
command: optional(Schema.String),
|
|
153
|
+
code: optional(Schema.String),
|
|
154
|
+
oldString: optional(Schema.String),
|
|
155
|
+
newString: optional(Schema.String),
|
|
156
|
+
content: optional(Schema.String),
|
|
157
|
+
id: optional(Schema.String),
|
|
158
|
+
name: optional(Schema.String),
|
|
159
|
+
questions: optional(Schema.Array(Schema.Unknown)),
|
|
160
|
+
}).pipe(Schema.catchDecoding(() => Effect.succeed(Option.some({})))),
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
export const toolMetadata = Schema.decodeUnknownSync(
|
|
164
|
+
Schema.Struct({
|
|
165
|
+
name: optional(Schema.String),
|
|
166
|
+
provider: optional(Schema.String),
|
|
167
|
+
sessionID: optional(Schema.String),
|
|
168
|
+
command: optional(Schema.String),
|
|
169
|
+
shellID: optional(Schema.String),
|
|
170
|
+
status: optional(Schema.String),
|
|
171
|
+
interrupted: optional(Schema.Boolean),
|
|
172
|
+
notice: optional(Schema.String),
|
|
173
|
+
count: optional(Schema.Finite),
|
|
174
|
+
matches: optional(Schema.Finite),
|
|
175
|
+
files: optional(Schema.Array(Schema.Unknown)),
|
|
176
|
+
loaded: optional(Schema.Array(Schema.Unknown)),
|
|
177
|
+
answers: optional(Schema.Array(Schema.Unknown)),
|
|
178
|
+
diagnostics: optional(Schema.Record(Schema.String, Schema.Array(Schema.Unknown))),
|
|
179
|
+
}).pipe(Schema.catchDecoding(() => Effect.succeed(Option.some({})))),
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
type ToolInput = ReturnType<typeof toolInput>
|
|
183
|
+
|
|
184
|
+
type ToolMetadata = ReturnType<typeof toolMetadata>
|
|
185
|
+
|
|
186
|
+
const decodeString = Schema.decodeUnknownOption(Schema.String)
|
|
187
|
+
|
|
188
|
+
const decodeQuestion = Schema.decodeUnknownOption(Schema.Struct({ question: Schema.String }))
|
|
189
|
+
|
|
190
|
+
const decodeAnswer = Schema.decodeUnknownOption(Schema.Array(Schema.String))
|
|
191
|
+
|
|
192
|
+
const decodeDiagnostic = Schema.decodeUnknownOption(
|
|
193
|
+
Schema.Struct({
|
|
194
|
+
range: Schema.Struct({ start: Schema.Struct({ line: Schema.Number, character: Schema.Number }) }),
|
|
195
|
+
message: Schema.String,
|
|
196
|
+
severity: Schema.optional(Schema.Number),
|
|
197
|
+
}),
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
type Diagnostic = Option.Option.Value<ReturnType<typeof decodeDiagnostic>>
|
|
201
|
+
|
|
202
|
+
function questions(input: ToolInput) {
|
|
203
|
+
return (input.questions ?? []).flatMap((question) => Option.toArray(decodeQuestion(question)))
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function getDiagnostics(diagnosticsByFile: ToolMetadata["diagnostics"], filePath: string | undefined) {
|
|
207
|
+
if (!filePath) return []
|
|
208
|
+
|
|
209
|
+
return (diagnosticsByFile?.[filePath] ?? [])
|
|
210
|
+
.flatMap((value) => Option.toArray(decodeDiagnostic(value)).filter((diagnostic) => diagnostic.severity === 1))
|
|
211
|
+
.slice(0, 3)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function DiagnosticsDisplay(props: { diagnostics: readonly Diagnostic[] }): JSX.Element {
|
|
215
|
+
const i18n = useI18n()
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<Show when={props.diagnostics.length > 0}>
|
|
219
|
+
<div data-component="diagnostics">
|
|
220
|
+
<For each={props.diagnostics}>
|
|
221
|
+
{(diagnostic) => (
|
|
222
|
+
<div data-slot="diagnostic">
|
|
223
|
+
<span data-slot="diagnostic-label">{i18n.t("ui.messagePart.diagnostic.error")}</span>
|
|
224
|
+
<span data-slot="diagnostic-location">
|
|
225
|
+
[{diagnostic.range.start.line + 1}:{diagnostic.range.start.character + 1}]
|
|
226
|
+
</span>
|
|
227
|
+
<span data-slot="diagnostic-message">{diagnostic.message}</span>
|
|
228
|
+
</div>
|
|
229
|
+
)}
|
|
230
|
+
</For>
|
|
231
|
+
</div>
|
|
232
|
+
</Show>
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function displayDirectory(path: string | undefined) {
|
|
237
|
+
const data = useData()
|
|
238
|
+
|
|
239
|
+
return relativizeProjectPath(getDirectory(path), data.directory)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** A folder a tool searched or listed, relative to the project; `/` for the project itself. */
|
|
243
|
+
export function displayFolder(path: string | undefined) {
|
|
244
|
+
const data = useData()
|
|
245
|
+
|
|
246
|
+
return relativizeProjectPath(path ?? "/", data.directory) || "/"
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
import { resolveFileDiff } from "../components/session-diff"
|
|
250
|
+
import { factsOf, sameFileFact, summarize, type FileFact } from "../timeline/facts"
|
|
251
|
+
import { contextGroupLabel, webSearchProviderLabel } from "./context-group-label"
|
|
252
|
+
import type { FileRun } from "./file-runs"
|
|
253
|
+
|
|
254
|
+
export function taskAgentName(raw: string | undefined, list?: readonly { name: string }[]) {
|
|
255
|
+
if (!raw) return undefined
|
|
256
|
+
const key = raw.toLowerCase()
|
|
257
|
+
|
|
258
|
+
return (
|
|
259
|
+
list?.find((entry) => entry.name === raw || entry.name.toLowerCase() === key)?.name ??
|
|
260
|
+
`${raw[0].toUpperCase()}${raw.slice(1)}`
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function readArgs(input: ToolInput) {
|
|
265
|
+
return [
|
|
266
|
+
...(input.offset === undefined ? [] : [`offset=${input.offset}`]),
|
|
267
|
+
...(input.limit === undefined ? [] : [`limit=${input.limit}`]),
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function skillToolName(input: ToolInput, metadata: ToolMetadata) {
|
|
272
|
+
return metadata.name ?? input.id ?? input.name
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function currentSkillName(tool: SessionMessageAssistantTool) {
|
|
276
|
+
return skillToolName(toolInput(currentToolInput(tool)), toolMetadata(currentToolMetadata(tool)))
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function urls(text: string | undefined) {
|
|
280
|
+
if (!text) return []
|
|
281
|
+
|
|
282
|
+
return [
|
|
283
|
+
...new Set(Array.from(text.matchAll(/https?:\/\/[^\s<>"'`)\]]+/g), (item) => item[0].replace(/[),.;:!?]+$/g, ""))),
|
|
284
|
+
]
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export function sessionLink(id: string | undefined, href?: (id: string) => string | undefined) {
|
|
288
|
+
if (!id) return undefined
|
|
289
|
+
|
|
290
|
+
return href?.(id)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function taskSession(
|
|
294
|
+
description: string | undefined,
|
|
295
|
+
parentID: string | undefined,
|
|
296
|
+
sessions: SessionSummary[] | undefined,
|
|
297
|
+
) {
|
|
298
|
+
if (!parentID) return undefined
|
|
299
|
+
|
|
300
|
+
return (sessions ?? [])
|
|
301
|
+
.filter((session) => session.parentID === parentID && !session.time?.archived)
|
|
302
|
+
.filter((session) => (description ? session.title?.startsWith(description) : true))
|
|
303
|
+
.sort((a, b) => (b.time.created ?? 0) - (a.time.created ?? 0))[0]?.id
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function ExaOutput(props: { output?: string }) {
|
|
307
|
+
const i18n = useI18n()
|
|
308
|
+
const [showAll, setShowAll] = createSignal(false)
|
|
309
|
+
let firstRevealedRef: HTMLAnchorElement | undefined
|
|
310
|
+
const links = createMemo(() => urls(props.output))
|
|
311
|
+
|
|
312
|
+
const visibleLinks = createMemo(() => {
|
|
313
|
+
const all = links()
|
|
314
|
+
|
|
315
|
+
if (showAll() || all.length <= 10) return all
|
|
316
|
+
|
|
317
|
+
return all.slice(0, 10)
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
const remaining = createMemo(() => Math.max(0, links().length - 10))
|
|
321
|
+
|
|
322
|
+
const expand = (event: MouseEvent) => {
|
|
323
|
+
event.stopPropagation()
|
|
324
|
+
setShowAll(true)
|
|
325
|
+
requestAnimationFrame(() => {
|
|
326
|
+
firstRevealedRef?.focus()
|
|
327
|
+
})
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return (
|
|
331
|
+
<Show when={links().length > 0}>
|
|
332
|
+
<div data-component="exa-tool-output">
|
|
333
|
+
<div data-slot="exa-tool-links">
|
|
334
|
+
<For each={visibleLinks()}>
|
|
335
|
+
{(url, index) => (
|
|
336
|
+
<a
|
|
337
|
+
ref={(el) => {
|
|
338
|
+
if (index() === 10) firstRevealedRef = el
|
|
339
|
+
}}
|
|
340
|
+
data-slot="exa-tool-link"
|
|
341
|
+
class="webfetch-link"
|
|
342
|
+
href={url}
|
|
343
|
+
target="_blank"
|
|
344
|
+
rel="noopener noreferrer"
|
|
345
|
+
onClick={(event) => event.stopPropagation()}
|
|
346
|
+
>
|
|
347
|
+
<span data-slot="webfetch-link-text">{url}</span>
|
|
348
|
+
<Icon name="outline-square-arrow" class="webfetch-link-icon" />
|
|
349
|
+
</a>
|
|
350
|
+
)}
|
|
351
|
+
</For>
|
|
352
|
+
<Show when={!showAll() && remaining() > 0}>
|
|
353
|
+
<button type="button" data-slot="exa-tool-more" onClick={expand}>
|
|
354
|
+
{i18n.plural("ui.common.moreCount", remaining())}
|
|
355
|
+
</button>
|
|
356
|
+
</Show>
|
|
357
|
+
</div>
|
|
358
|
+
</div>
|
|
359
|
+
</Show>
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export type ContextGroupPart =
|
|
364
|
+
| SessionMessageAssistantTool
|
|
365
|
+
| (SessionMessageAssistantReasoning & { id: string; streaming?: boolean })
|
|
366
|
+
| { type: "notice" | "shell" | "text"; id: string; render: () => JSX.Element }
|
|
367
|
+
| { type: "file"; id: string; file: FileFact; render: () => JSX.Element }
|
|
368
|
+
|
|
369
|
+
export function CurrentContextToolGroup(props: {
|
|
370
|
+
parts: ContextGroupPart[]
|
|
371
|
+
busy: boolean
|
|
372
|
+
open: boolean
|
|
373
|
+
onOpenChange: (open: boolean) => void
|
|
374
|
+
onSizeChange?: () => void
|
|
375
|
+
reasoningDefaultOpen?: boolean
|
|
376
|
+
reasoningOpen?: (id: string) => boolean | undefined
|
|
377
|
+
onReasoningOpenChange?: (id: string, open: boolean) => void
|
|
378
|
+
toolDefaultOpen?: (tool: SessionMessageAssistantTool) => boolean | undefined
|
|
379
|
+
toolOpen?: (id: string) => boolean | undefined
|
|
380
|
+
onToolOpenChange?: (id: string, open: boolean) => void
|
|
381
|
+
fileOpen?: (path: string) => boolean | undefined
|
|
382
|
+
onFileOpenChange?: (path: string, open: boolean) => void
|
|
383
|
+
patchGroupKey?: (tools: SessionMessageAssistantTool[]) => string
|
|
384
|
+
}) {
|
|
385
|
+
const i18n = useI18n()
|
|
386
|
+
const tools = createMemo(() => props.parts.filter((part) => part.type === "tool"))
|
|
387
|
+
|
|
388
|
+
const pending = createMemo(
|
|
389
|
+
() => props.busy || tools().some((tool) => tool.state.status === "streaming" || tool.state.status === "running"),
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
const reasoning = createMemo(() => props.parts.flatMap((part) => (part.type === "reasoning" ? [part] : [])))
|
|
393
|
+
// Thoughts alone are not finished work yet, so the live group reads as Thinking, in place of Working, rather than
|
|
394
|
+
// "Used 1 Thought".
|
|
395
|
+
const thinking = createMemo(() => props.busy && reasoning().length > 0 && reasoning().length === props.parts.length)
|
|
396
|
+
const [now, setNow] = createSignal(Date.now())
|
|
397
|
+
|
|
398
|
+
createEffect(() => {
|
|
399
|
+
if (!thinking()) return
|
|
400
|
+
setNow(Date.now())
|
|
401
|
+
const timer = setInterval(() => setNow(Date.now()), 1000)
|
|
402
|
+
onCleanup(() => clearInterval(timer))
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
const elapsed = createMemo(() => {
|
|
406
|
+
const started = reasoning()[0]?.time?.created
|
|
407
|
+
|
|
408
|
+
if (!thinking() || started === undefined) return ""
|
|
409
|
+
const total = Math.max(0, Math.floor((now() - started) / 1000))
|
|
410
|
+
const numfmt = new Intl.NumberFormat(i18n.locale())
|
|
411
|
+
|
|
412
|
+
if (total < 60) return i18n.t("ui.message.duration.seconds", { count: numfmt.format(total) })
|
|
413
|
+
|
|
414
|
+
if (total < 3600)
|
|
415
|
+
return i18n.t("ui.message.duration.minutesSeconds", {
|
|
416
|
+
minutes: numfmt.format(Math.floor(total / 60)),
|
|
417
|
+
seconds: numfmt.format(total % 60),
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
return i18n.t("ui.message.duration.hoursMinutes", {
|
|
421
|
+
hours: numfmt.format(Math.floor(total / 3600)),
|
|
422
|
+
minutes: numfmt.format(Math.floor(total / 60) % 60),
|
|
423
|
+
})
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
const label = createMemo(() => {
|
|
427
|
+
if (thinking()) {
|
|
428
|
+
const text = i18n.t("ui.sessionTurn.status.thinking")
|
|
429
|
+
|
|
430
|
+
return { text, title: text, before: "", count: undefined, between: "", after: "" }
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return contextGroupLabel(props.parts, i18n)
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
const items = createMemo(() =>
|
|
437
|
+
(props.open ? props.parts : []).reduce<
|
|
438
|
+
(SessionMessageAssistantTool[] | Exclude<ContextGroupPart, SessionMessageAssistantTool>)[]
|
|
439
|
+
>((groups, tool) => {
|
|
440
|
+
if (tool.type !== "tool") {
|
|
441
|
+
groups.push(tool)
|
|
442
|
+
|
|
443
|
+
return groups
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const previous = groups.at(-1)
|
|
447
|
+
|
|
448
|
+
if (isFileChangeTool(tool) && Array.isArray(previous) && previous[0] && isFileChangeTool(previous[0])) {
|
|
449
|
+
previous.push(tool)
|
|
450
|
+
|
|
451
|
+
return groups
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (
|
|
455
|
+
currentToolGroupedRead(tool) &&
|
|
456
|
+
Array.isArray(previous) &&
|
|
457
|
+
previous[0] &&
|
|
458
|
+
currentToolGroupedRead(previous[0])
|
|
459
|
+
) {
|
|
460
|
+
previous.push(tool)
|
|
461
|
+
|
|
462
|
+
return groups
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (
|
|
466
|
+
tool.name === "skill" &&
|
|
467
|
+
tool.state.status !== "error" &&
|
|
468
|
+
currentSkillName(tool) &&
|
|
469
|
+
Array.isArray(previous) &&
|
|
470
|
+
previous?.[0]?.name === "skill" &&
|
|
471
|
+
previous[0].state.status !== "error" &&
|
|
472
|
+
currentSkillName(previous[0])
|
|
473
|
+
) {
|
|
474
|
+
previous.push(tool)
|
|
475
|
+
|
|
476
|
+
return groups
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
groups.push([tool])
|
|
480
|
+
|
|
481
|
+
return groups
|
|
482
|
+
}, []),
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
const patchKeys = createMemo(() => {
|
|
486
|
+
const keys = new Map<SessionMessageAssistantTool, string>()
|
|
487
|
+
items().forEach((item) => {
|
|
488
|
+
if (!Array.isArray(item) || !item[0] || !isFileChangeTool(item[0])) return
|
|
489
|
+
const key = props.patchGroupKey?.(item) ?? item[0].id
|
|
490
|
+
item.forEach((tool) => keys.set(tool, key))
|
|
491
|
+
})
|
|
492
|
+
|
|
493
|
+
return keys
|
|
494
|
+
})
|
|
495
|
+
|
|
496
|
+
let root: HTMLDivElement | undefined
|
|
497
|
+
|
|
498
|
+
const change = (open: boolean) => {
|
|
499
|
+
// Collapsing from the stuck header would leave the viewport far below the group, so keep the header in place.
|
|
500
|
+
// Scroll before collapsing because the shorter content would clamp the scroll position first.
|
|
501
|
+
const trigger = root?.querySelector(':scope > [data-component="collapsible"] > [data-slot="collapsible-trigger"]')
|
|
502
|
+
const stuck = !open && root && trigger ? trigger.getBoundingClientRect().top - root.getBoundingClientRect().top : 0
|
|
503
|
+
|
|
504
|
+
if (stuck > 0 && root) scrollParent(root)?.scrollBy({ top: -stuck, behavior: "instant" })
|
|
505
|
+
props.onOpenChange(open)
|
|
506
|
+
props.onSizeChange?.()
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return (
|
|
510
|
+
<div
|
|
511
|
+
ref={root}
|
|
512
|
+
data-component="collapsed-tool-group"
|
|
513
|
+
data-timeline-part-ids={props.parts.map((part) => part.id).join(",")}
|
|
514
|
+
>
|
|
515
|
+
<BasicTool
|
|
516
|
+
icon="glasses"
|
|
517
|
+
status={pending() ? "running" : "completed"}
|
|
518
|
+
compact
|
|
519
|
+
hasContent
|
|
520
|
+
allowOpenWhilePending
|
|
521
|
+
open={props.open}
|
|
522
|
+
onOpenChange={change}
|
|
523
|
+
trigger={
|
|
524
|
+
<div data-component="context-tool-group-trigger" aria-label={label().text}>
|
|
525
|
+
<span data-slot="context-tool-group-title">
|
|
526
|
+
<Show when={label().before || label().count || label().between}>
|
|
527
|
+
<span data-slot="context-tool-group-usage">
|
|
528
|
+
<Show when={label().before}>
|
|
529
|
+
{(before) => <span data-slot="context-tool-group-prefix">{before()}</span>}
|
|
530
|
+
</Show>
|
|
531
|
+
<Show when={label().count}>
|
|
532
|
+
{(count) => (
|
|
533
|
+
<span data-slot="context-tool-group-count">
|
|
534
|
+
<AnimatedNumber value={count()} />
|
|
535
|
+
</span>
|
|
536
|
+
)}
|
|
537
|
+
</Show>
|
|
538
|
+
<Show when={label().between}>
|
|
539
|
+
{(between) => <span data-slot="context-tool-group-prefix">{between()}</span>}
|
|
540
|
+
</Show>
|
|
541
|
+
</span>
|
|
542
|
+
</Show>
|
|
543
|
+
<Show when={label().title}>
|
|
544
|
+
{(title) => (
|
|
545
|
+
<span data-slot="basic-tool-tool-title">
|
|
546
|
+
<Show when={thinking()} fallback={title()}>
|
|
547
|
+
<TextShimmer text={title()} active />
|
|
548
|
+
</Show>
|
|
549
|
+
</span>
|
|
550
|
+
)}
|
|
551
|
+
</Show>
|
|
552
|
+
<Show when={elapsed()}>{(value) => <span data-slot="basic-tool-tool-subtitle">{value()}</span>}</Show>
|
|
553
|
+
<Show when={label().after}>
|
|
554
|
+
{(after) => <span data-slot="context-tool-group-prefix">{after()}</span>}
|
|
555
|
+
</Show>
|
|
556
|
+
</span>
|
|
557
|
+
</div>
|
|
558
|
+
}
|
|
559
|
+
>
|
|
560
|
+
<div data-component="context-tool-group-list">
|
|
561
|
+
<Index each={items()}>
|
|
562
|
+
{(item) => {
|
|
563
|
+
const group = createMemo(() => {
|
|
564
|
+
const value = item()
|
|
565
|
+
|
|
566
|
+
return Array.isArray(value) ? value : undefined
|
|
567
|
+
})
|
|
568
|
+
|
|
569
|
+
const reasoning = createMemo(() => {
|
|
570
|
+
const value = item()
|
|
571
|
+
|
|
572
|
+
return !Array.isArray(value) && value.type === "reasoning" ? value : undefined
|
|
573
|
+
})
|
|
574
|
+
|
|
575
|
+
// A change keeps its card while progress reports rebuild the list around it.
|
|
576
|
+
const file = createMemo(
|
|
577
|
+
() => {
|
|
578
|
+
const value = item()
|
|
579
|
+
|
|
580
|
+
return !Array.isArray(value) && value.type === "file" ? value : undefined
|
|
581
|
+
},
|
|
582
|
+
undefined,
|
|
583
|
+
{
|
|
584
|
+
equals: (previous, next) =>
|
|
585
|
+
previous === next || (!!previous && !!next && sameFileFact(previous.file, next.file)),
|
|
586
|
+
},
|
|
587
|
+
)
|
|
588
|
+
|
|
589
|
+
const callback = createMemo(() => {
|
|
590
|
+
const value = item()
|
|
591
|
+
|
|
592
|
+
return !Array.isArray(value) &&
|
|
593
|
+
(value.type === "notice" || value.type === "shell" || value.type === "text")
|
|
594
|
+
? value
|
|
595
|
+
: undefined
|
|
596
|
+
})
|
|
597
|
+
|
|
598
|
+
return (
|
|
599
|
+
<Show
|
|
600
|
+
when={group()}
|
|
601
|
+
fallback={
|
|
602
|
+
<Show
|
|
603
|
+
when={reasoning()}
|
|
604
|
+
fallback={
|
|
605
|
+
<Show
|
|
606
|
+
when={file()}
|
|
607
|
+
keyed
|
|
608
|
+
fallback={
|
|
609
|
+
<Show when={callback()}>
|
|
610
|
+
{(part) => <div data-slot="context-tool-group-item">{part().render()}</div>}
|
|
611
|
+
</Show>
|
|
612
|
+
}
|
|
613
|
+
>
|
|
614
|
+
{(part) => <div data-slot="context-tool-group-item">{part.render()}</div>}
|
|
615
|
+
</Show>
|
|
616
|
+
}
|
|
617
|
+
>
|
|
618
|
+
{(part) => (
|
|
619
|
+
<div data-slot="context-tool-group-item">
|
|
620
|
+
<AssistantReasoningContent
|
|
621
|
+
id={part().id}
|
|
622
|
+
content={part()}
|
|
623
|
+
streaming={part().streaming ?? false}
|
|
624
|
+
// The group already reads as Thinking, so opening it shows the thoughts themselves.
|
|
625
|
+
defaultOpen={thinking() || props.reasoningDefaultOpen}
|
|
626
|
+
open={props.reasoningOpen?.(part().id)}
|
|
627
|
+
onOpenChange={(open) => props.onReasoningOpenChange?.(part().id, open)}
|
|
628
|
+
onContentRendered={props.onSizeChange}
|
|
629
|
+
/>
|
|
630
|
+
</div>
|
|
631
|
+
)}
|
|
632
|
+
</Show>
|
|
633
|
+
}
|
|
634
|
+
>
|
|
635
|
+
{(group) => {
|
|
636
|
+
const tool = createMemo(() => group()[0]!)
|
|
637
|
+
const trigger = createMemo(() => currentContextToolTrigger(tool(), i18n))
|
|
638
|
+
|
|
639
|
+
const skills = createMemo(() =>
|
|
640
|
+
group().flatMap((item) => {
|
|
641
|
+
const name = currentSkillName(item)
|
|
642
|
+
|
|
643
|
+
return name ? [name] : []
|
|
644
|
+
}),
|
|
645
|
+
)
|
|
646
|
+
|
|
647
|
+
const marker = "__OPENCODE_LOADED_SKILL__"
|
|
648
|
+
|
|
649
|
+
const loaded = createMemo(() =>
|
|
650
|
+
i18n.plural("ui.tool.loadedSkills", skills().length, { name: marker }),
|
|
651
|
+
)
|
|
652
|
+
|
|
653
|
+
return (
|
|
654
|
+
<div data-slot="context-tool-group-item">
|
|
655
|
+
<Show
|
|
656
|
+
when={!currentToolGroupedRead(tool())}
|
|
657
|
+
fallback={
|
|
658
|
+
<CurrentReadToolGroup
|
|
659
|
+
tools={group()}
|
|
660
|
+
open={props.toolOpen?.(tool().id)}
|
|
661
|
+
onOpenChange={(open) => props.onToolOpenChange?.(tool().id, open)}
|
|
662
|
+
onSizeChange={props.onSizeChange}
|
|
663
|
+
/>
|
|
664
|
+
}
|
|
665
|
+
>
|
|
666
|
+
<Show
|
|
667
|
+
when={tool().state.status !== "error" && ["glob", "grep", "list"].includes(tool().name)}
|
|
668
|
+
fallback={
|
|
669
|
+
<Show
|
|
670
|
+
when={
|
|
671
|
+
tool().name === "skill" && group().length > 1 && skills().length === group().length
|
|
672
|
+
}
|
|
673
|
+
fallback={
|
|
674
|
+
<Show
|
|
675
|
+
when={isFileChangeTool(tool())}
|
|
676
|
+
fallback={
|
|
677
|
+
<ToolDisplay
|
|
678
|
+
id={tool().id}
|
|
679
|
+
tool={tool().name}
|
|
680
|
+
input={currentToolInput(tool())}
|
|
681
|
+
metadata={currentToolMetadata(tool())}
|
|
682
|
+
output={currentToolOutput(tool())}
|
|
683
|
+
error={currentToolError(tool())}
|
|
684
|
+
status={tool().state.status}
|
|
685
|
+
defaultOpen={props.toolDefaultOpen?.(tool()) ?? false}
|
|
686
|
+
open={props.toolOpen?.(tool().id) ?? props.toolDefaultOpen?.(tool())}
|
|
687
|
+
onOpenChange={(open) => props.onToolOpenChange?.(tool().id, open)}
|
|
688
|
+
deferContent
|
|
689
|
+
virtualizeDiff={false}
|
|
690
|
+
onContentRendered={props.onSizeChange}
|
|
691
|
+
/>
|
|
692
|
+
}
|
|
693
|
+
>
|
|
694
|
+
<CurrentFileToolGroup
|
|
695
|
+
tools={group()}
|
|
696
|
+
fileOpen={
|
|
697
|
+
props.fileOpen &&
|
|
698
|
+
((path) => props.fileOpen?.(`${patchKeys().get(tool())}:${path}`))
|
|
699
|
+
}
|
|
700
|
+
onFileOpenChange={
|
|
701
|
+
props.onFileOpenChange &&
|
|
702
|
+
((path, open) =>
|
|
703
|
+
props.onFileOpenChange?.(`${patchKeys().get(tool())}:${path}`, open))
|
|
704
|
+
}
|
|
705
|
+
onSizeChange={props.onSizeChange}
|
|
706
|
+
/>
|
|
707
|
+
</Show>
|
|
708
|
+
}
|
|
709
|
+
>
|
|
710
|
+
<div
|
|
711
|
+
data-component="tool-loaded-item"
|
|
712
|
+
data-timeline-part-ids={group()
|
|
713
|
+
.map((item) => item.id)
|
|
714
|
+
.join(",")}
|
|
715
|
+
aria-label={i18n.plural("ui.tool.loadedSkills", skills().length, {
|
|
716
|
+
name: skills().join(", "),
|
|
717
|
+
})}
|
|
718
|
+
>
|
|
719
|
+
<span data-slot="tool-loaded-label" aria-hidden="true">
|
|
720
|
+
{loaded().split(marker)[0]?.trim()}
|
|
721
|
+
</span>
|
|
722
|
+
<span data-slot="tool-loaded-value" aria-hidden="true">
|
|
723
|
+
<For each={skills()}>
|
|
724
|
+
{(name, index) => (
|
|
725
|
+
<>
|
|
726
|
+
<Show when={index() > 0}>, </Show>
|
|
727
|
+
<TextShimmer
|
|
728
|
+
as="span"
|
|
729
|
+
text={name}
|
|
730
|
+
active={["streaming", "running"].includes(group()[index()]!.state.status)}
|
|
731
|
+
/>
|
|
732
|
+
</>
|
|
733
|
+
)}
|
|
734
|
+
</For>
|
|
735
|
+
</span>
|
|
736
|
+
<Show when={loaded().split(marker)[1]?.trim()}>
|
|
737
|
+
{(suffix) => (
|
|
738
|
+
<span data-slot="tool-loaded-kind" aria-hidden="true">
|
|
739
|
+
{suffix()}
|
|
740
|
+
</span>
|
|
741
|
+
)}
|
|
742
|
+
</Show>
|
|
743
|
+
</div>
|
|
744
|
+
</Show>
|
|
745
|
+
}
|
|
746
|
+
>
|
|
747
|
+
<div data-component="tool-trigger">
|
|
748
|
+
<div data-slot="basic-tool-tool-trigger-content">
|
|
749
|
+
<div data-slot="basic-tool-tool-info">
|
|
750
|
+
<div data-slot="basic-tool-tool-info-structured">
|
|
751
|
+
<div data-slot="basic-tool-tool-info-main">
|
|
752
|
+
<span data-slot="basic-tool-tool-title">
|
|
753
|
+
<TextShimmer
|
|
754
|
+
text={trigger().title}
|
|
755
|
+
active={
|
|
756
|
+
tool().state.status === "streaming" || tool().state.status === "running"
|
|
757
|
+
}
|
|
758
|
+
/>
|
|
759
|
+
</span>
|
|
760
|
+
<Show when={trigger().subtitle}>
|
|
761
|
+
{(subtitle) => <span data-slot="basic-tool-tool-subtitle">{subtitle()}</span>}
|
|
762
|
+
</Show>
|
|
763
|
+
<For each={trigger().args}>
|
|
764
|
+
{(arg) => <span data-slot="basic-tool-tool-arg">{arg}</span>}
|
|
765
|
+
</For>
|
|
766
|
+
</div>
|
|
767
|
+
<Show when={trigger().matches}>
|
|
768
|
+
{(matches) => (
|
|
769
|
+
<>
|
|
770
|
+
<span data-slot="context-tool-group-dot" />
|
|
771
|
+
<span data-slot="context-tool-group-matches">{matches()}</span>
|
|
772
|
+
</>
|
|
773
|
+
)}
|
|
774
|
+
</Show>
|
|
775
|
+
</div>
|
|
776
|
+
</div>
|
|
777
|
+
</div>
|
|
778
|
+
</div>
|
|
779
|
+
</Show>
|
|
780
|
+
</Show>
|
|
781
|
+
</div>
|
|
782
|
+
)
|
|
783
|
+
}}
|
|
784
|
+
</Show>
|
|
785
|
+
)
|
|
786
|
+
}}
|
|
787
|
+
</Index>
|
|
788
|
+
</div>
|
|
789
|
+
</BasicTool>
|
|
790
|
+
</div>
|
|
791
|
+
)
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
export function CurrentReadToolGroup(props: {
|
|
795
|
+
tools: SessionMessageAssistantTool[]
|
|
796
|
+
open?: boolean
|
|
797
|
+
onOpenChange?: (open: boolean) => void
|
|
798
|
+
onSizeChange?: () => void
|
|
799
|
+
/** Names each file once, and up to this many while closed; past that the closed row says how many files. */
|
|
800
|
+
names?: number
|
|
801
|
+
}) {
|
|
802
|
+
const i18n = useI18n()
|
|
803
|
+
const [state, setState] = createStore({ truncated: false })
|
|
804
|
+
const disclosure = createDisclosure({ open: () => props.open, onOpenChange: (open) => props.onOpenChange?.(open) })
|
|
805
|
+
const open = disclosure.open
|
|
806
|
+
|
|
807
|
+
const pending = createMemo(() =>
|
|
808
|
+
props.tools.some((tool) => tool.state.status === "streaming" || tool.state.status === "running"),
|
|
809
|
+
)
|
|
810
|
+
|
|
811
|
+
const files = createMemo(() => {
|
|
812
|
+
const reads = props.tools.flatMap((tool) => {
|
|
813
|
+
const input = toolInput(currentToolInput(tool))
|
|
814
|
+
const name = getFilename(input.path ?? "")
|
|
815
|
+
|
|
816
|
+
return name ? [{ id: tool.id, path: input.path ?? "", name, args: readArgs(input) }] : []
|
|
817
|
+
})
|
|
818
|
+
|
|
819
|
+
if (props.names === undefined) return reads
|
|
820
|
+
|
|
821
|
+
// A file read in several ranges is named once, without one range standing for the rest.
|
|
822
|
+
return [
|
|
823
|
+
...reads
|
|
824
|
+
.reduce((unique, file) => {
|
|
825
|
+
const seen = unique.get(file.path)
|
|
826
|
+
|
|
827
|
+
return unique.set(file.path, seen ? { ...seen, args: [] } : file)
|
|
828
|
+
}, new Map<string, (typeof reads)[number]>())
|
|
829
|
+
.values(),
|
|
830
|
+
]
|
|
831
|
+
})
|
|
832
|
+
|
|
833
|
+
const summary = createMemo(() => {
|
|
834
|
+
const count = summarize(factsOf(props.tools)).readFiles.length
|
|
835
|
+
|
|
836
|
+
return props.names !== undefined && !open() && count > props.names
|
|
837
|
+
? i18n.plural("ui.timeline.activity.files", count)
|
|
838
|
+
: undefined
|
|
839
|
+
})
|
|
840
|
+
|
|
841
|
+
const expandable = () => open() || state.truncated || !!summary()
|
|
842
|
+
|
|
843
|
+
let list: HTMLSpanElement | undefined
|
|
844
|
+
|
|
845
|
+
const measure = () => {
|
|
846
|
+
if (!list || open()) return
|
|
847
|
+
setState("truncated", list.scrollWidth > list.clientWidth)
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
createResizeObserver(() => list, measure)
|
|
851
|
+
createEffect(on(files, measure))
|
|
852
|
+
|
|
853
|
+
const toggle = () => {
|
|
854
|
+
if (!expandable()) return
|
|
855
|
+
disclosure.toggle()
|
|
856
|
+
props.onSizeChange?.()
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
return (
|
|
860
|
+
<div
|
|
861
|
+
data-component="read-tool-group"
|
|
862
|
+
data-timeline-part-ids={props.tools.map((tool) => tool.id).join(",")}
|
|
863
|
+
data-expanded={open() ? "true" : undefined}
|
|
864
|
+
role={expandable() ? "button" : undefined}
|
|
865
|
+
tabIndex={expandable() ? 0 : undefined}
|
|
866
|
+
aria-expanded={expandable() ? open() : undefined}
|
|
867
|
+
onClick={toggle}
|
|
868
|
+
onKeyDown={(event) => {
|
|
869
|
+
if (event.key !== "Enter" && event.key !== " ") return
|
|
870
|
+
event.preventDefault()
|
|
871
|
+
toggle()
|
|
872
|
+
}}
|
|
873
|
+
>
|
|
874
|
+
<div data-component="tool-trigger">
|
|
875
|
+
<div data-slot="basic-tool-tool-trigger-content">
|
|
876
|
+
<div data-slot="basic-tool-tool-info">
|
|
877
|
+
<div data-slot="basic-tool-tool-info-structured">
|
|
878
|
+
<div data-slot="basic-tool-tool-info-main">
|
|
879
|
+
<span data-slot="basic-tool-tool-title">
|
|
880
|
+
<TextShimmer text={i18n.t("ui.tool.read")} active={pending()} />
|
|
881
|
+
</span>
|
|
882
|
+
<span ref={list} data-slot="basic-tool-tool-subtitle">
|
|
883
|
+
<Show
|
|
884
|
+
when={summary()}
|
|
885
|
+
fallback={
|
|
886
|
+
<Index each={files()}>
|
|
887
|
+
{(file, index) => (
|
|
888
|
+
<>
|
|
889
|
+
<Show when={index > 0}> </Show>
|
|
890
|
+
<span data-slot="read-tool-group-file" data-timeline-part-id={file().id}>
|
|
891
|
+
{file().name}
|
|
892
|
+
<For each={file().args}>
|
|
893
|
+
{(arg) => <span data-slot="basic-tool-tool-arg">{` ${arg}`}</span>}
|
|
894
|
+
</For>
|
|
895
|
+
<Show when={index < files().length - 1}>,</Show>
|
|
896
|
+
</span>
|
|
897
|
+
</>
|
|
898
|
+
)}
|
|
899
|
+
</Index>
|
|
900
|
+
}
|
|
901
|
+
>
|
|
902
|
+
{(text) => text()}
|
|
903
|
+
</Show>
|
|
904
|
+
</span>
|
|
905
|
+
</div>
|
|
906
|
+
</div>
|
|
907
|
+
</div>
|
|
908
|
+
</div>
|
|
909
|
+
<Show when={expandable()}>
|
|
910
|
+
<span data-slot="read-tool-group-arrow" aria-hidden="true">
|
|
911
|
+
<Icon name="fill-triangle-down" />
|
|
912
|
+
</span>
|
|
913
|
+
</Show>
|
|
914
|
+
</div>
|
|
915
|
+
</div>
|
|
916
|
+
)
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
export function CurrentFileToolGroup(props: {
|
|
920
|
+
tools: SessionMessageAssistantTool[]
|
|
921
|
+
fileOpen?: (path: string) => boolean | undefined
|
|
922
|
+
onFileOpenChange?: (path: string, open: boolean) => void
|
|
923
|
+
onSizeChange?: () => void
|
|
924
|
+
}) {
|
|
925
|
+
const files = createMemo((previous: { key: string; toolID: string; value: FileDiffInfo }[]) => {
|
|
926
|
+
const next = props.tools.flatMap((tool) => {
|
|
927
|
+
const files = toolMetadata(currentToolMetadata(tool)).files ?? []
|
|
928
|
+
|
|
929
|
+
// Invalid entries render nothing, but metadata files still replace the input-derived preview.
|
|
930
|
+
if (files.length > 0)
|
|
931
|
+
return files.flatMap((value, index) =>
|
|
932
|
+
changedFileDiff(value) ? [{ key: `${tool.id}:${index}`, toolID: tool.id, value }] : [],
|
|
933
|
+
)
|
|
934
|
+
const input = toolInput(currentToolInput(tool))
|
|
935
|
+
|
|
936
|
+
if (input.path === undefined) return []
|
|
937
|
+
|
|
938
|
+
if (tool.name === "edit" && input.oldString !== undefined && input.newString !== undefined) {
|
|
939
|
+
const changes = diffLines(input.oldString, input.newString)
|
|
940
|
+
|
|
941
|
+
const additions = changes
|
|
942
|
+
.filter((change) => change.added)
|
|
943
|
+
.reduce((total, change) => total + (change.count ?? 0), 0)
|
|
944
|
+
|
|
945
|
+
const deletions = changes
|
|
946
|
+
.filter((change) => change.removed)
|
|
947
|
+
.reduce((total, change) => total + (change.count ?? 0), 0)
|
|
948
|
+
|
|
949
|
+
if (additions === 0 && deletions === 0) return []
|
|
950
|
+
|
|
951
|
+
return [
|
|
952
|
+
{
|
|
953
|
+
key: `${tool.id}:0`,
|
|
954
|
+
toolID: tool.id,
|
|
955
|
+
value: {
|
|
956
|
+
file: input.path,
|
|
957
|
+
patch: createTwoFilesPatch(input.path, input.path, input.oldString, input.newString),
|
|
958
|
+
additions,
|
|
959
|
+
deletions,
|
|
960
|
+
status: "modified" as const,
|
|
961
|
+
},
|
|
962
|
+
},
|
|
963
|
+
]
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
if (tool.name !== "write" || !input.content) return []
|
|
967
|
+
|
|
968
|
+
return [
|
|
969
|
+
{
|
|
970
|
+
key: `${tool.id}:0`,
|
|
971
|
+
toolID: tool.id,
|
|
972
|
+
value: {
|
|
973
|
+
file: input.path,
|
|
974
|
+
patch: createTwoFilesPatch(input.path, input.path, "", input.content),
|
|
975
|
+
additions: input.content.split("\n").length - Number(input.content.endsWith("\n")),
|
|
976
|
+
deletions: 0,
|
|
977
|
+
status: "modified" as const,
|
|
978
|
+
},
|
|
979
|
+
},
|
|
980
|
+
]
|
|
981
|
+
})
|
|
982
|
+
|
|
983
|
+
const updates = new Map(next.map((entry) => [entry.key, entry.value]))
|
|
984
|
+
const existing = new Set(previous.map((entry) => entry.key))
|
|
985
|
+
const owners = new Set(props.tools.map((tool) => tool.id))
|
|
986
|
+
|
|
987
|
+
const result = [
|
|
988
|
+
...previous.flatMap((entry) => {
|
|
989
|
+
if (!owners.has(entry.toolID)) return []
|
|
990
|
+
const value = updates.get(entry.key)
|
|
991
|
+
|
|
992
|
+
if (!value || samePatchFile(value, entry.value)) return [entry]
|
|
993
|
+
|
|
994
|
+
return [{ ...entry, value }]
|
|
995
|
+
}),
|
|
996
|
+
...next.filter((entry) => !existing.has(entry.key)),
|
|
997
|
+
]
|
|
998
|
+
|
|
999
|
+
return result.length === previous.length && result.every((entry, index) => entry === previous[index])
|
|
1000
|
+
? previous
|
|
1001
|
+
: result
|
|
1002
|
+
}, [])
|
|
1003
|
+
|
|
1004
|
+
const metadata = createMemo(() => ({
|
|
1005
|
+
files: files().map((entry) => entry.value),
|
|
1006
|
+
}))
|
|
1007
|
+
|
|
1008
|
+
const pending = createMemo(() =>
|
|
1009
|
+
props.tools.some((tool) => tool.state.status === "streaming" || tool.state.status === "running"),
|
|
1010
|
+
)
|
|
1011
|
+
|
|
1012
|
+
const render = ToolRegistry.render("patch") ?? GenericTool
|
|
1013
|
+
|
|
1014
|
+
const tool = createMemo(() => {
|
|
1015
|
+
const name = props.tools[0]?.name
|
|
1016
|
+
|
|
1017
|
+
return name === "edit" || name === "write" ? name : "patch"
|
|
1018
|
+
})
|
|
1019
|
+
|
|
1020
|
+
return (
|
|
1021
|
+
<div
|
|
1022
|
+
data-component="tool-part-wrapper"
|
|
1023
|
+
data-timeline-part-id={props.tools.length === 1 ? props.tools[0]?.id : undefined}
|
|
1024
|
+
data-timeline-part-ids={props.tools.length > 1 ? props.tools.map((tool) => tool.id).join(",") : undefined}
|
|
1025
|
+
>
|
|
1026
|
+
<Dynamic
|
|
1027
|
+
component={render}
|
|
1028
|
+
tool={tool()}
|
|
1029
|
+
input={{}}
|
|
1030
|
+
metadata={metadata()}
|
|
1031
|
+
status={pending() ? "running" : "completed"}
|
|
1032
|
+
fileOpen={props.fileOpen}
|
|
1033
|
+
onFileOpenChange={props.onFileOpenChange}
|
|
1034
|
+
deferContent
|
|
1035
|
+
virtualizeDiff={false}
|
|
1036
|
+
onContentRendered={props.onSizeChange}
|
|
1037
|
+
/>
|
|
1038
|
+
</div>
|
|
1039
|
+
)
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/** A file group holding a script's changes: each run in order, direct calls drawn as their own group. */
|
|
1043
|
+
export function FileChangeRuns(props: {
|
|
1044
|
+
runs: readonly FileRun[]
|
|
1045
|
+
tools: (tools: Accessor<SessionMessageAssistantTool[]>) => JSX.Element
|
|
1046
|
+
render: Component<ToolProps>
|
|
1047
|
+
fileOpen?: (key: string) => boolean | undefined
|
|
1048
|
+
onFileOpenChange?: (key: string, open: boolean) => void
|
|
1049
|
+
onSizeChange?: () => void
|
|
1050
|
+
}) {
|
|
1051
|
+
return (
|
|
1052
|
+
<Index each={props.runs}>
|
|
1053
|
+
{(run) => {
|
|
1054
|
+
const tools = createMemo(() => {
|
|
1055
|
+
const value = run()
|
|
1056
|
+
|
|
1057
|
+
return value.type === "tools" ? value.tools : undefined
|
|
1058
|
+
})
|
|
1059
|
+
|
|
1060
|
+
const files = createMemo(() => {
|
|
1061
|
+
const value = run()
|
|
1062
|
+
|
|
1063
|
+
return value.type === "script" ? value.files : undefined
|
|
1064
|
+
})
|
|
1065
|
+
|
|
1066
|
+
return (
|
|
1067
|
+
<Show
|
|
1068
|
+
when={tools()}
|
|
1069
|
+
fallback={
|
|
1070
|
+
<Show when={files()}>
|
|
1071
|
+
{(list) => (
|
|
1072
|
+
<ScriptChanges
|
|
1073
|
+
files={list()}
|
|
1074
|
+
render={props.render}
|
|
1075
|
+
fileOpen={props.fileOpen}
|
|
1076
|
+
onFileOpenChange={props.onFileOpenChange}
|
|
1077
|
+
onSizeChange={props.onSizeChange}
|
|
1078
|
+
/>
|
|
1079
|
+
)}
|
|
1080
|
+
</Show>
|
|
1081
|
+
}
|
|
1082
|
+
>
|
|
1083
|
+
{(list) => props.tools(list)}
|
|
1084
|
+
</Show>
|
|
1085
|
+
)
|
|
1086
|
+
}}
|
|
1087
|
+
</Index>
|
|
1088
|
+
)
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// A change's part id: the fact id less its message.
|
|
1092
|
+
function scriptChangePartID(file: FileFact) {
|
|
1093
|
+
return file.id.slice(file.id.indexOf(":") + 1)
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
/**
|
|
1097
|
+
* The changes a script made, in order, one card each: the same file changed twice is two cards. A change without a
|
|
1098
|
+
* diff, past the size cap, to a binary file, a copy or a delete, shows what it did as a patch's file header does. Each
|
|
1099
|
+
* card opens by the change's own id.
|
|
1100
|
+
*/
|
|
1101
|
+
export function ScriptChanges(props: {
|
|
1102
|
+
files: readonly FileFact[]
|
|
1103
|
+
render: Component<ToolProps>
|
|
1104
|
+
fileOpen?: (key: string) => boolean | undefined
|
|
1105
|
+
onFileOpenChange?: (key: string, open: boolean) => void
|
|
1106
|
+
onSizeChange?: () => void
|
|
1107
|
+
}) {
|
|
1108
|
+
const i18n = useI18n()
|
|
1109
|
+
|
|
1110
|
+
// One wrapper, as a direct patch's files share one, so the turn's gap falls around the list and not between changes.
|
|
1111
|
+
return (
|
|
1112
|
+
<div data-component="tool-part-wrapper" data-script-changes="">
|
|
1113
|
+
<Index each={props.files}>
|
|
1114
|
+
{(file) => {
|
|
1115
|
+
const diff = createMemo(
|
|
1116
|
+
() => {
|
|
1117
|
+
const value = {
|
|
1118
|
+
file: file().path,
|
|
1119
|
+
patch: file().patch,
|
|
1120
|
+
additions: file().additions ?? 0,
|
|
1121
|
+
deletions: file().deletions ?? 0,
|
|
1122
|
+
status: file().change ?? "modified",
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
return changedFileDiff(value) ? value : undefined
|
|
1126
|
+
},
|
|
1127
|
+
undefined,
|
|
1128
|
+
// A progress report reads each change again; the same diff keeps its parsed view.
|
|
1129
|
+
{
|
|
1130
|
+
equals: (previous, next) =>
|
|
1131
|
+
previous === next ||
|
|
1132
|
+
(!!previous &&
|
|
1133
|
+
!!next &&
|
|
1134
|
+
previous.file === next.file &&
|
|
1135
|
+
previous.patch === next.patch &&
|
|
1136
|
+
previous.additions === next.additions &&
|
|
1137
|
+
previous.deletions === next.deletions &&
|
|
1138
|
+
previous.status === next.status),
|
|
1139
|
+
},
|
|
1140
|
+
)
|
|
1141
|
+
|
|
1142
|
+
return (
|
|
1143
|
+
<Show
|
|
1144
|
+
when={diff()}
|
|
1145
|
+
fallback={
|
|
1146
|
+
<div
|
|
1147
|
+
data-component="file-counts"
|
|
1148
|
+
data-type={file().change}
|
|
1149
|
+
data-timeline-part-id={scriptChangePartID(file())}
|
|
1150
|
+
>
|
|
1151
|
+
<FileIcon node={{ path: file().path, type: "file" }} />
|
|
1152
|
+
<span data-slot="file-counts-name">
|
|
1153
|
+
<Show when={file().path.includes("/")}>
|
|
1154
|
+
<span data-slot="file-counts-directory">{`\u202A${displayDirectory(file().path)}\u202C`}</span>
|
|
1155
|
+
</Show>
|
|
1156
|
+
<span data-slot="file-counts-filename">{getFilename(file().path)}</span>
|
|
1157
|
+
</span>
|
|
1158
|
+
<Switch>
|
|
1159
|
+
<Match when={file().change === "added"}>
|
|
1160
|
+
<span data-component="diff-changes" data-appearance="standard">
|
|
1161
|
+
<span data-slot="diff-changes-additions">{i18n.t("ui.patch.action.created")}</span>
|
|
1162
|
+
</span>
|
|
1163
|
+
</Match>
|
|
1164
|
+
<Match when={file().change === "deleted"}>
|
|
1165
|
+
<span data-component="diff-changes" data-appearance="standard">
|
|
1166
|
+
<span data-slot="diff-changes-deletions">{i18n.t("ui.patch.action.deleted")}</span>
|
|
1167
|
+
</span>
|
|
1168
|
+
</Match>
|
|
1169
|
+
<Match when={(file().additions ?? 0) + (file().deletions ?? 0) > 0}>
|
|
1170
|
+
<DiffChanges
|
|
1171
|
+
appearance="standard"
|
|
1172
|
+
markEmpty
|
|
1173
|
+
changes={{ additions: file().additions ?? 0, deletions: file().deletions ?? 0 }}
|
|
1174
|
+
/>
|
|
1175
|
+
</Match>
|
|
1176
|
+
</Switch>
|
|
1177
|
+
</div>
|
|
1178
|
+
}
|
|
1179
|
+
>
|
|
1180
|
+
{(value) => (
|
|
1181
|
+
<div data-script-change="patch" data-timeline-part-id={scriptChangePartID(file())}>
|
|
1182
|
+
<Dynamic
|
|
1183
|
+
component={props.render}
|
|
1184
|
+
tool="patch"
|
|
1185
|
+
input={{}}
|
|
1186
|
+
metadata={{ files: [value()] }}
|
|
1187
|
+
status="completed"
|
|
1188
|
+
fileOpen={props.fileOpen && (() => props.fileOpen?.(file().id))}
|
|
1189
|
+
onFileOpenChange={
|
|
1190
|
+
props.onFileOpenChange &&
|
|
1191
|
+
((_: string, open: boolean) => props.onFileOpenChange?.(file().id, open))
|
|
1192
|
+
}
|
|
1193
|
+
deferContent
|
|
1194
|
+
virtualizeDiff={false}
|
|
1195
|
+
onContentRendered={props.onSizeChange}
|
|
1196
|
+
/>
|
|
1197
|
+
</div>
|
|
1198
|
+
)}
|
|
1199
|
+
</Show>
|
|
1200
|
+
)
|
|
1201
|
+
}}
|
|
1202
|
+
</Index>
|
|
1203
|
+
</div>
|
|
1204
|
+
)
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
export { fileRuns, runDisclosureKey, type FileRun } from "./file-runs"
|
|
1208
|
+
|
|
1209
|
+
export function scrollParent(element: HTMLElement): HTMLElement | undefined {
|
|
1210
|
+
const parent = element.parentElement
|
|
1211
|
+
|
|
1212
|
+
if (!parent) return
|
|
1213
|
+
|
|
1214
|
+
if (/auto|scroll/.test(getComputedStyle(parent).overflowY)) return parent
|
|
1215
|
+
|
|
1216
|
+
return scrollParent(parent)
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
function isFileChangeTool(tool: SessionMessageAssistantTool) {
|
|
1220
|
+
return tool.state.status !== "error" && (tool.name === "edit" || tool.name === "write" || tool.name === "patch")
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
export function samePatchFile(a: FileDiffInfo, b: FileDiffInfo) {
|
|
1224
|
+
return (
|
|
1225
|
+
a === b ||
|
|
1226
|
+
(a.file === b.file &&
|
|
1227
|
+
a.patch === b.patch &&
|
|
1228
|
+
a.additions === b.additions &&
|
|
1229
|
+
a.deletions === b.deletions &&
|
|
1230
|
+
a.status === b.status)
|
|
1231
|
+
)
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
function currentContextToolTrigger(tool: SessionMessageAssistantTool, i18n: ReturnType<typeof useI18n>) {
|
|
1235
|
+
const input = toolInput(currentToolInput(tool))
|
|
1236
|
+
const metadata = toolMetadata(currentToolMetadata(tool))
|
|
1237
|
+
const subtitle = displayFolder(input.path)
|
|
1238
|
+
|
|
1239
|
+
const matches = (count: number | undefined) =>
|
|
1240
|
+
count ? i18n.plural("ui.messagePart.context.match", count) : undefined
|
|
1241
|
+
|
|
1242
|
+
if (tool.name === "list") return { title: i18n.t("ui.tool.list"), subtitle, args: [], matches: undefined }
|
|
1243
|
+
|
|
1244
|
+
if (tool.name === "glob")
|
|
1245
|
+
return {
|
|
1246
|
+
title: i18n.t("ui.tool.glob"),
|
|
1247
|
+
subtitle,
|
|
1248
|
+
args: input.pattern ? [`pattern=${input.pattern}`] : [],
|
|
1249
|
+
matches: matches(metadata.count),
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
return {
|
|
1253
|
+
title: i18n.t("ui.tool.grep"),
|
|
1254
|
+
subtitle,
|
|
1255
|
+
args: [
|
|
1256
|
+
...(input.pattern ? [`pattern=${input.pattern}`] : []),
|
|
1257
|
+
...(input.include ? [`include=${input.include}`] : []),
|
|
1258
|
+
],
|
|
1259
|
+
matches: matches(metadata.matches),
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
// SAFETY: tool input and metadata are open per-tool records. GenericTool shows arbitrary input keys, and
|
|
1264
|
+
// renderers decode the fields they read with `toolInput` and `toolMetadata`.
|
|
1265
|
+
export interface ToolProps {
|
|
1266
|
+
// oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- see SAFETY above
|
|
1267
|
+
input: Record<string, unknown>
|
|
1268
|
+
error?: string
|
|
1269
|
+
// oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- see SAFETY above
|
|
1270
|
+
metadata: Record<string, unknown>
|
|
1271
|
+
tool: string
|
|
1272
|
+
sessionID?: string
|
|
1273
|
+
output?: string
|
|
1274
|
+
status?: string
|
|
1275
|
+
hideDetails?: boolean
|
|
1276
|
+
defaultOpen?: boolean
|
|
1277
|
+
open?: boolean
|
|
1278
|
+
onOpenChange?: (open: boolean) => void
|
|
1279
|
+
fileOpen?: (path: string) => boolean | undefined
|
|
1280
|
+
onFileOpenChange?: (path: string, open: boolean) => void
|
|
1281
|
+
deferContent?: boolean
|
|
1282
|
+
virtualizeDiff?: boolean
|
|
1283
|
+
onContentRendered?: () => void
|
|
1284
|
+
/** Paths the patch view lists, without change counts or diffs, instead of `metadata.files`. */
|
|
1285
|
+
pendingFiles?: readonly string[]
|
|
1286
|
+
forceOpen?: boolean
|
|
1287
|
+
locked?: boolean
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
type ToolComponent = Component<ToolProps>
|
|
1291
|
+
|
|
1292
|
+
const state: Record<
|
|
1293
|
+
string,
|
|
1294
|
+
{
|
|
1295
|
+
name: string
|
|
1296
|
+
render?: ToolComponent
|
|
1297
|
+
}
|
|
1298
|
+
> = {}
|
|
1299
|
+
|
|
1300
|
+
function registerTool(input: { name: string; render?: ToolComponent }) {
|
|
1301
|
+
state[input.name] = input
|
|
1302
|
+
|
|
1303
|
+
return input
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
function getTool(name: string) {
|
|
1307
|
+
return state[name]?.render
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
export const ToolRegistry = {
|
|
1311
|
+
register: registerTool,
|
|
1312
|
+
render: getTool,
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
export function FileTool(props: ToolProps & { title: string; count: number; children?: JSX.Element }) {
|
|
1316
|
+
const i18n = useI18n()
|
|
1317
|
+
|
|
1318
|
+
return (
|
|
1319
|
+
<BasicTool
|
|
1320
|
+
{...props}
|
|
1321
|
+
open
|
|
1322
|
+
onOpenChange={undefined}
|
|
1323
|
+
locked
|
|
1324
|
+
icon="code-lines"
|
|
1325
|
+
hasContent
|
|
1326
|
+
defer={false}
|
|
1327
|
+
rail={false}
|
|
1328
|
+
trigger={{
|
|
1329
|
+
title: props.title,
|
|
1330
|
+
subtitle: props.count > 0 ? `${props.count} ${i18n.plural("ui.common.file", props.count)}` : "",
|
|
1331
|
+
}}
|
|
1332
|
+
>
|
|
1333
|
+
{props.children}
|
|
1334
|
+
</BasicTool>
|
|
1335
|
+
)
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
export function FileAccordionGroup(props: { children: JSX.Element }) {
|
|
1339
|
+
return (
|
|
1340
|
+
<div
|
|
1341
|
+
data-component="accordion"
|
|
1342
|
+
data-scope="apply-patch"
|
|
1343
|
+
onKeyDown={(event) => {
|
|
1344
|
+
if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
|
1345
|
+
|
|
1346
|
+
if (!["ArrowUp", "ArrowDown", "Home", "End"].includes(event.key)) return
|
|
1347
|
+
|
|
1348
|
+
if (!(event.target instanceof HTMLButtonElement) || event.target.dataset.slot !== "accordion-trigger") return
|
|
1349
|
+
|
|
1350
|
+
if (event.target.closest('[data-component="accordion"]') !== event.currentTarget) return
|
|
1351
|
+
|
|
1352
|
+
const triggers = [
|
|
1353
|
+
...event.currentTarget.querySelectorAll<HTMLButtonElement>(
|
|
1354
|
+
':scope > [data-slot="accordion-item"] > [data-slot="accordion-header"] > [data-slot="accordion-trigger"]',
|
|
1355
|
+
),
|
|
1356
|
+
]
|
|
1357
|
+
|
|
1358
|
+
const index = triggers.indexOf(event.target)
|
|
1359
|
+
|
|
1360
|
+
if (index < 0) return
|
|
1361
|
+
event.preventDefault()
|
|
1362
|
+
|
|
1363
|
+
if (event.key === "Home") return triggers[0]?.focus()
|
|
1364
|
+
|
|
1365
|
+
if (event.key === "End") return triggers.at(-1)?.focus()
|
|
1366
|
+
triggers[(index + (event.key === "ArrowDown" ? 1 : -1) + triggers.length) % triggers.length]?.focus()
|
|
1367
|
+
}}
|
|
1368
|
+
>
|
|
1369
|
+
{props.children}
|
|
1370
|
+
</div>
|
|
1371
|
+
)
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
function FileAccordionItem(props: {
|
|
1375
|
+
open: boolean
|
|
1376
|
+
onOpenChange: (open: boolean) => void
|
|
1377
|
+
type?: string
|
|
1378
|
+
header: JSX.Element
|
|
1379
|
+
children: JSX.Element
|
|
1380
|
+
}) {
|
|
1381
|
+
const id = createUniqueId()
|
|
1382
|
+
|
|
1383
|
+
return (
|
|
1384
|
+
<div
|
|
1385
|
+
data-slot="accordion-item"
|
|
1386
|
+
data-type={props.type}
|
|
1387
|
+
data-expanded={props.open ? "" : undefined}
|
|
1388
|
+
data-closed={!props.open ? "" : undefined}
|
|
1389
|
+
>
|
|
1390
|
+
<h3
|
|
1391
|
+
data-slot="accordion-header"
|
|
1392
|
+
data-component="sticky-accordion-header"
|
|
1393
|
+
data-expanded={props.open ? "" : undefined}
|
|
1394
|
+
data-closed={!props.open ? "" : undefined}
|
|
1395
|
+
>
|
|
1396
|
+
<button
|
|
1397
|
+
type="button"
|
|
1398
|
+
id={`${id}-trigger`}
|
|
1399
|
+
data-slot="accordion-trigger"
|
|
1400
|
+
data-expanded={props.open ? "" : undefined}
|
|
1401
|
+
data-closed={!props.open ? "" : undefined}
|
|
1402
|
+
aria-expanded={props.open}
|
|
1403
|
+
aria-controls={props.open ? `${id}-content` : undefined}
|
|
1404
|
+
onClick={() => batch(() => props.onOpenChange(!props.open))}
|
|
1405
|
+
>
|
|
1406
|
+
{props.header}
|
|
1407
|
+
</button>
|
|
1408
|
+
</h3>
|
|
1409
|
+
<Show when={props.open}>
|
|
1410
|
+
<div
|
|
1411
|
+
id={`${id}-content`}
|
|
1412
|
+
role="region"
|
|
1413
|
+
aria-labelledby={`${id}-trigger`}
|
|
1414
|
+
data-slot="accordion-content"
|
|
1415
|
+
data-expanded=""
|
|
1416
|
+
>
|
|
1417
|
+
{props.children}
|
|
1418
|
+
</div>
|
|
1419
|
+
</Show>
|
|
1420
|
+
</div>
|
|
1421
|
+
)
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
function ToolFileAccordion(props: {
|
|
1425
|
+
path: string
|
|
1426
|
+
actions?: JSX.Element
|
|
1427
|
+
children: JSX.Element
|
|
1428
|
+
defaultOpen?: boolean
|
|
1429
|
+
open?: boolean
|
|
1430
|
+
onOpenChange?: (open: boolean) => void
|
|
1431
|
+
forceOpen?: boolean
|
|
1432
|
+
defer?: boolean
|
|
1433
|
+
}) {
|
|
1434
|
+
const disclosure = createDisclosure({
|
|
1435
|
+
open: () => props.open,
|
|
1436
|
+
defaultOpen: () => props.defaultOpen ?? false,
|
|
1437
|
+
forceOpen: () => props.forceOpen ?? false,
|
|
1438
|
+
defer: () => props.defer ?? false,
|
|
1439
|
+
onOpenChange: (open) => props.onOpenChange?.(open),
|
|
1440
|
+
})
|
|
1441
|
+
|
|
1442
|
+
return (
|
|
1443
|
+
<FileAccordionGroup>
|
|
1444
|
+
<FileAccordionItem
|
|
1445
|
+
open={disclosure.open()}
|
|
1446
|
+
onOpenChange={disclosure.setOpen}
|
|
1447
|
+
header={
|
|
1448
|
+
<div data-slot="apply-patch-trigger-content">
|
|
1449
|
+
<div data-slot="apply-patch-file-info">
|
|
1450
|
+
<FileIcon node={{ path: props.path, type: "file" }} />
|
|
1451
|
+
<div data-slot="apply-patch-file-name-container">
|
|
1452
|
+
<Show when={props.path.includes("/")}>
|
|
1453
|
+
<span data-slot="apply-patch-directory">{`\u202A${displayDirectory(props.path)}\u202C`}</span>
|
|
1454
|
+
</Show>
|
|
1455
|
+
<span data-slot="apply-patch-filename">{getFilename(props.path)}</span>
|
|
1456
|
+
</div>
|
|
1457
|
+
</div>
|
|
1458
|
+
<div data-slot="apply-patch-trigger-actions">
|
|
1459
|
+
{props.actions}
|
|
1460
|
+
<Icon name="chevron-grabber-vertical" />
|
|
1461
|
+
</div>
|
|
1462
|
+
</div>
|
|
1463
|
+
}
|
|
1464
|
+
>
|
|
1465
|
+
<Show when={!props.defer || disclosure.mounted()}>{props.children}</Show>
|
|
1466
|
+
</FileAccordionItem>
|
|
1467
|
+
</FileAccordionGroup>
|
|
1468
|
+
)
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
export function ToolDisplay(
|
|
1472
|
+
props: ToolProps & {
|
|
1473
|
+
id: string
|
|
1474
|
+
error?: string
|
|
1475
|
+
},
|
|
1476
|
+
) {
|
|
1477
|
+
const data = useData()
|
|
1478
|
+
const i18n = useI18n()
|
|
1479
|
+
|
|
1480
|
+
if (props.tool === "todowrite") return null
|
|
1481
|
+
const hideQuestion = () => props.tool === "question" && (props.status === "streaming" || props.status === "running")
|
|
1482
|
+
|
|
1483
|
+
const taskId = createMemo(() => {
|
|
1484
|
+
if (props.tool !== "subagent") return undefined
|
|
1485
|
+
|
|
1486
|
+
return toolMetadata(props.metadata).sessionID || undefined
|
|
1487
|
+
})
|
|
1488
|
+
|
|
1489
|
+
const taskHref = createMemo(() => sessionLink(taskId(), data.sessionHref))
|
|
1490
|
+
|
|
1491
|
+
const taskSubtitle = createMemo(() => {
|
|
1492
|
+
if (props.tool !== "subagent") return undefined
|
|
1493
|
+
|
|
1494
|
+
return toolInput(props.input).description || taskId()
|
|
1495
|
+
})
|
|
1496
|
+
|
|
1497
|
+
const errorSubtitle = createMemo(() => toolErrorSubtitle(props, i18n))
|
|
1498
|
+
const error = createMemo(() => toolDisplayError(props))
|
|
1499
|
+
const stopped = createMemo(() => stoppedShell({ ...props, metadata: toolMetadata(props.metadata) }))
|
|
1500
|
+
const render = createMemo(() => ToolRegistry.render(props.tool) ?? GenericTool)
|
|
1501
|
+
|
|
1502
|
+
return (
|
|
1503
|
+
<Show when={!hideQuestion()}>
|
|
1504
|
+
<div data-component="tool-part-wrapper" data-timeline-part-id={props.id}>
|
|
1505
|
+
<Switch>
|
|
1506
|
+
<Match when={stopped()}>
|
|
1507
|
+
{(stopped) => (
|
|
1508
|
+
<>
|
|
1509
|
+
<Dynamic component={render()} {...props} output={stopped().output} />
|
|
1510
|
+
<ToolErrorCard tool={props.tool} error={stopped().notice} subtitle={errorSubtitle()} />
|
|
1511
|
+
</>
|
|
1512
|
+
)}
|
|
1513
|
+
</Match>
|
|
1514
|
+
<Match when={error()}>
|
|
1515
|
+
{(error) => {
|
|
1516
|
+
const cleaned = error().replace("Error: ", "")
|
|
1517
|
+
|
|
1518
|
+
if (props.tool === "question" && cleaned.includes("dismissed this question")) {
|
|
1519
|
+
return (
|
|
1520
|
+
<div style="width: 100%; display: flex; justify-content: flex-end;">
|
|
1521
|
+
<span class="text-13-regular text-v2-text-text-faint cursor-default">
|
|
1522
|
+
{i18n.t("ui.messagePart.questions.dismissed")}
|
|
1523
|
+
</span>
|
|
1524
|
+
</div>
|
|
1525
|
+
)
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
return (
|
|
1529
|
+
<ToolErrorCard
|
|
1530
|
+
tool={props.tool}
|
|
1531
|
+
error={error()}
|
|
1532
|
+
title={
|
|
1533
|
+
props.tool === "websearch"
|
|
1534
|
+
? webSearchProviderLabel(toolMetadata(props.metadata).provider, i18n)
|
|
1535
|
+
: undefined
|
|
1536
|
+
}
|
|
1537
|
+
defaultOpen={props.defaultOpen}
|
|
1538
|
+
open={props.open}
|
|
1539
|
+
onOpenChange={props.onOpenChange}
|
|
1540
|
+
subtitle={taskSubtitle() ?? errorSubtitle()}
|
|
1541
|
+
href={taskHref()}
|
|
1542
|
+
onSubtitleClick={(event) => {
|
|
1543
|
+
if (!data.navigateToSession) return
|
|
1544
|
+
|
|
1545
|
+
if (event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
|
1546
|
+
const id = taskId()
|
|
1547
|
+
|
|
1548
|
+
if (!id) return
|
|
1549
|
+
event.preventDefault()
|
|
1550
|
+
data.navigateToSession(id)
|
|
1551
|
+
}}
|
|
1552
|
+
/>
|
|
1553
|
+
)
|
|
1554
|
+
}}
|
|
1555
|
+
</Match>
|
|
1556
|
+
<Match when={true}>
|
|
1557
|
+
<Dynamic component={render()} {...props} />
|
|
1558
|
+
</Match>
|
|
1559
|
+
</Switch>
|
|
1560
|
+
</div>
|
|
1561
|
+
</Show>
|
|
1562
|
+
)
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
// Each branch must stay in sync with its tool trigger's subtitle expression so
|
|
1566
|
+
// failed rows read like their non-error counterparts ("Shell sleep 30").
|
|
1567
|
+
export function toolErrorSubtitle(props: ToolProps, i18n: UiI18n) {
|
|
1568
|
+
const input = toolInput(props.input)
|
|
1569
|
+
const metadata = toolMetadata(props.metadata)
|
|
1570
|
+
|
|
1571
|
+
if (props.tool === "shell") return input.command || metadata.command || undefined
|
|
1572
|
+
|
|
1573
|
+
if (props.tool === "read" || props.tool === "edit" || props.tool === "write") return getFilename(input.path ?? "")
|
|
1574
|
+
|
|
1575
|
+
if (props.tool === "list" || props.tool === "glob" || props.tool === "grep") return displayFolder(input.path)
|
|
1576
|
+
|
|
1577
|
+
if (props.tool === "webfetch") return input.url || undefined
|
|
1578
|
+
|
|
1579
|
+
if (props.tool === "websearch") return input.query || undefined
|
|
1580
|
+
|
|
1581
|
+
if (props.tool === "skill") return skillToolName(input, metadata)
|
|
1582
|
+
|
|
1583
|
+
if (props.tool === "patch") {
|
|
1584
|
+
const count = new Set((metadata.files ?? []).flatMap((file) => (changedFileDiff(file) ? [file.file] : []))).size
|
|
1585
|
+
|
|
1586
|
+
if (count === 0) return undefined
|
|
1587
|
+
|
|
1588
|
+
return `${count} ${i18n.plural("ui.common.file", count)}`
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
if (props.tool === "question") {
|
|
1592
|
+
const count = questions(input).length
|
|
1593
|
+
|
|
1594
|
+
if (count === 0) return undefined
|
|
1595
|
+
|
|
1596
|
+
return `${count} ${i18n.plural("ui.common.question", count)}`
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
return undefined
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
export function toolDisplayError(props: ToolProps & { error?: string }) {
|
|
1603
|
+
// Code Mode failures render inline in the execution's call list.
|
|
1604
|
+
if (props.tool === "execute") return undefined
|
|
1605
|
+
|
|
1606
|
+
if (props.status === "error") return props.error
|
|
1607
|
+
|
|
1608
|
+
return undefined
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
ToolRegistry.register({
|
|
1612
|
+
name: "read",
|
|
1613
|
+
render(props) {
|
|
1614
|
+
const data = useData()
|
|
1615
|
+
const i18n = useI18n()
|
|
1616
|
+
const image = createMemo(() => (props.status === "completed" ? readImagePath(props.input) : undefined))
|
|
1617
|
+
|
|
1618
|
+
const loaded = createMemo(() => {
|
|
1619
|
+
if (props.status !== "completed") return []
|
|
1620
|
+
|
|
1621
|
+
return (toolMetadata(props.metadata).loaded ?? []).flatMap((path) => Option.toArray(decodeString(path)))
|
|
1622
|
+
})
|
|
1623
|
+
|
|
1624
|
+
const paths = createMemo(() =>
|
|
1625
|
+
loaded().map((filepath) => {
|
|
1626
|
+
const relative = relativizeProjectPath(filepath, data.directory)
|
|
1627
|
+
|
|
1628
|
+
return relative === filepath ? relative : relative.replace(/^[/\\]/, "")
|
|
1629
|
+
}),
|
|
1630
|
+
)
|
|
1631
|
+
|
|
1632
|
+
const marker = "__OPENCODE_LOADED_PATH__"
|
|
1633
|
+
const parts = createMemo(() => i18n.t("ui.tool.loadedFile", { path: marker }).split(marker))
|
|
1634
|
+
|
|
1635
|
+
return (
|
|
1636
|
+
<>
|
|
1637
|
+
<BasicTool
|
|
1638
|
+
{...props}
|
|
1639
|
+
icon="glasses"
|
|
1640
|
+
hasContent={!!image()}
|
|
1641
|
+
defer
|
|
1642
|
+
onOpenChange={(open) => {
|
|
1643
|
+
props.onOpenChange?.(open)
|
|
1644
|
+
props.onContentRendered?.()
|
|
1645
|
+
}}
|
|
1646
|
+
trigger={{
|
|
1647
|
+
title: i18n.t("ui.tool.read"),
|
|
1648
|
+
subtitle: getFilename(toolInput(props.input).path ?? ""),
|
|
1649
|
+
args: readArgs(toolInput(props.input)),
|
|
1650
|
+
}}
|
|
1651
|
+
>
|
|
1652
|
+
<Show when={image()} keyed>
|
|
1653
|
+
{(path) => <ReadImage path={path} onContentRendered={props.onContentRendered} />}
|
|
1654
|
+
</Show>
|
|
1655
|
+
</BasicTool>
|
|
1656
|
+
<Show when={paths().length > 0}>
|
|
1657
|
+
<div
|
|
1658
|
+
data-component="tool-loaded-item"
|
|
1659
|
+
aria-label={i18n.t("ui.tool.loadedFile", { path: paths().join(", ") })}
|
|
1660
|
+
>
|
|
1661
|
+
<span data-slot="tool-loaded-label" aria-hidden="true">
|
|
1662
|
+
{parts()[0]?.trim()}
|
|
1663
|
+
</span>
|
|
1664
|
+
<span data-slot="tool-loaded-value" aria-hidden="true">
|
|
1665
|
+
{paths().join(", ")}
|
|
1666
|
+
</span>
|
|
1667
|
+
<Show when={parts()[1]?.trim()}>
|
|
1668
|
+
{(suffix) => (
|
|
1669
|
+
<span data-slot="tool-loaded-kind" aria-hidden="true">
|
|
1670
|
+
{suffix()}
|
|
1671
|
+
</span>
|
|
1672
|
+
)}
|
|
1673
|
+
</Show>
|
|
1674
|
+
</div>
|
|
1675
|
+
</Show>
|
|
1676
|
+
</>
|
|
1677
|
+
)
|
|
1678
|
+
},
|
|
1679
|
+
})
|
|
1680
|
+
|
|
1681
|
+
function ReadImage(props: { path: string; onContentRendered?: () => void }) {
|
|
1682
|
+
const markdown = useMarkdown()
|
|
1683
|
+
const previewImages = createImagePreview()
|
|
1684
|
+
let root!: HTMLDivElement
|
|
1685
|
+
createEffect(() => {
|
|
1686
|
+
previewImages(root)
|
|
1687
|
+
|
|
1688
|
+
if (!markdown?.readImage) return
|
|
1689
|
+
const images = createMarkdownImages(markdown.readImage)
|
|
1690
|
+
images.update(root)
|
|
1691
|
+
onCleanup(() => images.dispose())
|
|
1692
|
+
})
|
|
1693
|
+
onMount(() => props.onContentRendered?.())
|
|
1694
|
+
|
|
1695
|
+
return (
|
|
1696
|
+
<div ref={root} data-component="read-image">
|
|
1697
|
+
<img
|
|
1698
|
+
data-local-image={props.path}
|
|
1699
|
+
alt={getFilename(props.path)}
|
|
1700
|
+
onLoad={() => props.onContentRendered?.()}
|
|
1701
|
+
onError={() => props.onContentRendered?.()}
|
|
1702
|
+
/>
|
|
1703
|
+
</div>
|
|
1704
|
+
)
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
ToolRegistry.register({
|
|
1708
|
+
name: "list",
|
|
1709
|
+
render(props) {
|
|
1710
|
+
const i18n = useI18n()
|
|
1711
|
+
|
|
1712
|
+
return (
|
|
1713
|
+
<BasicTool
|
|
1714
|
+
{...props}
|
|
1715
|
+
icon="bullet-list"
|
|
1716
|
+
hasContent={!!props.output}
|
|
1717
|
+
trigger={{
|
|
1718
|
+
title: i18n.t("ui.tool.list"),
|
|
1719
|
+
subtitle: displayFolder(toolInput(props.input).path),
|
|
1720
|
+
}}
|
|
1721
|
+
>
|
|
1722
|
+
<Show when={props.output}>
|
|
1723
|
+
<div
|
|
1724
|
+
data-component="tool-output"
|
|
1725
|
+
data-scrollable
|
|
1726
|
+
tabIndex={-1}
|
|
1727
|
+
role="region"
|
|
1728
|
+
aria-label={i18n.t("ui.scrollView.ariaLabel")}
|
|
1729
|
+
>
|
|
1730
|
+
<Markdown text={props.output!} />
|
|
1731
|
+
</div>
|
|
1732
|
+
</Show>
|
|
1733
|
+
</BasicTool>
|
|
1734
|
+
)
|
|
1735
|
+
},
|
|
1736
|
+
})
|
|
1737
|
+
|
|
1738
|
+
ToolRegistry.register({
|
|
1739
|
+
name: "glob",
|
|
1740
|
+
render(props) {
|
|
1741
|
+
const i18n = useI18n()
|
|
1742
|
+
const input = createMemo(() => toolInput(props.input))
|
|
1743
|
+
|
|
1744
|
+
return (
|
|
1745
|
+
<BasicTool
|
|
1746
|
+
{...props}
|
|
1747
|
+
icon="magnifying-glass-menu"
|
|
1748
|
+
hasContent={!!props.output}
|
|
1749
|
+
trigger={{
|
|
1750
|
+
title: i18n.t("ui.tool.glob"),
|
|
1751
|
+
subtitle: displayFolder(input().path),
|
|
1752
|
+
args: input().pattern === undefined ? [] : ["pattern=" + input().pattern],
|
|
1753
|
+
}}
|
|
1754
|
+
>
|
|
1755
|
+
<Show when={props.output}>
|
|
1756
|
+
<div
|
|
1757
|
+
data-component="tool-output"
|
|
1758
|
+
data-scrollable
|
|
1759
|
+
tabIndex={-1}
|
|
1760
|
+
role="region"
|
|
1761
|
+
aria-label={i18n.t("ui.scrollView.ariaLabel")}
|
|
1762
|
+
>
|
|
1763
|
+
<Markdown text={props.output!} />
|
|
1764
|
+
</div>
|
|
1765
|
+
</Show>
|
|
1766
|
+
</BasicTool>
|
|
1767
|
+
)
|
|
1768
|
+
},
|
|
1769
|
+
})
|
|
1770
|
+
|
|
1771
|
+
ToolRegistry.register({
|
|
1772
|
+
name: "grep",
|
|
1773
|
+
render(props) {
|
|
1774
|
+
const i18n = useI18n()
|
|
1775
|
+
const input = createMemo(() => toolInput(props.input))
|
|
1776
|
+
|
|
1777
|
+
const args = () => [
|
|
1778
|
+
...(input().pattern === undefined ? [] : ["pattern=" + input().pattern]),
|
|
1779
|
+
...(input().include === undefined ? [] : ["include=" + input().include]),
|
|
1780
|
+
]
|
|
1781
|
+
|
|
1782
|
+
return (
|
|
1783
|
+
<BasicTool
|
|
1784
|
+
{...props}
|
|
1785
|
+
icon="magnifying-glass-menu"
|
|
1786
|
+
hasContent={!!props.output}
|
|
1787
|
+
trigger={{
|
|
1788
|
+
title: i18n.t("ui.tool.grep"),
|
|
1789
|
+
subtitle: displayFolder(input().path),
|
|
1790
|
+
args: args(),
|
|
1791
|
+
}}
|
|
1792
|
+
>
|
|
1793
|
+
<Show when={props.output}>
|
|
1794
|
+
<div
|
|
1795
|
+
data-component="tool-output"
|
|
1796
|
+
data-scrollable
|
|
1797
|
+
tabIndex={-1}
|
|
1798
|
+
role="region"
|
|
1799
|
+
aria-label={i18n.t("ui.scrollView.ariaLabel")}
|
|
1800
|
+
>
|
|
1801
|
+
<Markdown text={props.output!} />
|
|
1802
|
+
</div>
|
|
1803
|
+
</Show>
|
|
1804
|
+
</BasicTool>
|
|
1805
|
+
)
|
|
1806
|
+
},
|
|
1807
|
+
})
|
|
1808
|
+
|
|
1809
|
+
ToolRegistry.register({
|
|
1810
|
+
name: "webfetch",
|
|
1811
|
+
render(props) {
|
|
1812
|
+
const i18n = useI18n()
|
|
1813
|
+
const pending = createMemo(() => props.status === "streaming" || props.status === "running")
|
|
1814
|
+
|
|
1815
|
+
const url = createMemo(() => toolInput(props.input).url ?? "")
|
|
1816
|
+
|
|
1817
|
+
return (
|
|
1818
|
+
<BasicTool
|
|
1819
|
+
{...props}
|
|
1820
|
+
hideDetails
|
|
1821
|
+
icon="select-element"
|
|
1822
|
+
trigger={
|
|
1823
|
+
<div data-slot="basic-tool-tool-info-structured">
|
|
1824
|
+
<div data-slot="basic-tool-tool-info-main">
|
|
1825
|
+
<span data-slot="basic-tool-tool-title">
|
|
1826
|
+
<TextShimmer text={i18n.t("ui.tool.webfetch")} active={pending()} />
|
|
1827
|
+
</span>
|
|
1828
|
+
<Show when={props.status !== "streaming" && url()}>
|
|
1829
|
+
<a
|
|
1830
|
+
data-slot="basic-tool-tool-subtitle"
|
|
1831
|
+
class="webfetch-link"
|
|
1832
|
+
href={url()}
|
|
1833
|
+
target="_blank"
|
|
1834
|
+
rel="noopener noreferrer"
|
|
1835
|
+
onClick={(event) => event.stopPropagation()}
|
|
1836
|
+
>
|
|
1837
|
+
<span data-slot="webfetch-link-text">{url()}</span>
|
|
1838
|
+
<Icon name="outline-square-arrow" class="webfetch-link-icon" />
|
|
1839
|
+
</a>
|
|
1840
|
+
</Show>
|
|
1841
|
+
</div>
|
|
1842
|
+
</div>
|
|
1843
|
+
}
|
|
1844
|
+
/>
|
|
1845
|
+
)
|
|
1846
|
+
},
|
|
1847
|
+
})
|
|
1848
|
+
|
|
1849
|
+
ToolRegistry.register({
|
|
1850
|
+
name: "websearch",
|
|
1851
|
+
render(props) {
|
|
1852
|
+
const i18n = useI18n()
|
|
1853
|
+
|
|
1854
|
+
const query = createMemo(() => toolInput(props.input).query ?? "")
|
|
1855
|
+
|
|
1856
|
+
const title = createMemo(() => webSearchProviderLabel(toolMetadata(props.metadata).provider, i18n))
|
|
1857
|
+
|
|
1858
|
+
return (
|
|
1859
|
+
<BasicTool
|
|
1860
|
+
{...props}
|
|
1861
|
+
icon="select-element"
|
|
1862
|
+
trigger={{
|
|
1863
|
+
title: title(),
|
|
1864
|
+
subtitle: query(),
|
|
1865
|
+
subtitleClass: "exa-tool-query",
|
|
1866
|
+
}}
|
|
1867
|
+
>
|
|
1868
|
+
<ExaOutput output={props.output} />
|
|
1869
|
+
</BasicTool>
|
|
1870
|
+
)
|
|
1871
|
+
},
|
|
1872
|
+
})
|
|
1873
|
+
|
|
1874
|
+
ToolRegistry.register({
|
|
1875
|
+
name: "subagent",
|
|
1876
|
+
render(props) {
|
|
1877
|
+
const data = useData()
|
|
1878
|
+
const i18n = useI18n()
|
|
1879
|
+
|
|
1880
|
+
const input = createMemo(() => toolInput(props.input))
|
|
1881
|
+
const metadata = createMemo(() => toolMetadata(props.metadata))
|
|
1882
|
+
|
|
1883
|
+
const childSessionId = createMemo(
|
|
1884
|
+
() => metadata().sessionID || taskSession(input().description, data.sessionID, data.store.session),
|
|
1885
|
+
)
|
|
1886
|
+
|
|
1887
|
+
const title = createMemo(() => taskAgentName(input().agent, data.store.agent) ?? i18n.t("ui.tool.agent.default"))
|
|
1888
|
+
|
|
1889
|
+
const run = createMemo((state: SubagentRunState) => {
|
|
1890
|
+
const id = childSessionId()
|
|
1891
|
+
const childBusy = !!id && (data.store.session_status[id]?.type ?? "idle") !== "idle"
|
|
1892
|
+
|
|
1893
|
+
return transitionSubagentRun(state, {
|
|
1894
|
+
type: "sync",
|
|
1895
|
+
props: subagentRunProps({ status: props.status, metadata: metadata() }, childBusy),
|
|
1896
|
+
})
|
|
1897
|
+
}, INITIAL_SUBAGENT_RUN_STATE)
|
|
1898
|
+
|
|
1899
|
+
const view = createMemo(() => viewSubagentRun(run()))
|
|
1900
|
+
|
|
1901
|
+
const subtitle = createMemo(() => input().description || childSessionId())
|
|
1902
|
+
|
|
1903
|
+
const href = createMemo(() => sessionLink(childSessionId(), data.sessionHref))
|
|
1904
|
+
const clickable = createMemo(() => !!(childSessionId() && (data.navigateToSession || href())))
|
|
1905
|
+
|
|
1906
|
+
const open = () => {
|
|
1907
|
+
const id = childSessionId()
|
|
1908
|
+
|
|
1909
|
+
if (!id) return
|
|
1910
|
+
data.navigateToSession?.(id)
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
const navigate = (event: MouseEvent) => {
|
|
1914
|
+
if (!data.navigateToSession) return
|
|
1915
|
+
|
|
1916
|
+
if (event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
|
1917
|
+
event.preventDefault()
|
|
1918
|
+
open()
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
const navigateKey = (event: KeyboardEvent) => {
|
|
1922
|
+
if (!clickable() || href()) return
|
|
1923
|
+
|
|
1924
|
+
if (event.key !== "Enter" && event.key !== " ") return
|
|
1925
|
+
event.preventDefault()
|
|
1926
|
+
open()
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
const trigger = () => (
|
|
1930
|
+
<div data-component="task-tool-card">
|
|
1931
|
+
<div data-component="task-tool-surface">
|
|
1932
|
+
<div data-slot="basic-tool-tool-info-structured">
|
|
1933
|
+
<div data-slot="basic-tool-tool-info-main">
|
|
1934
|
+
<Show when={view().running}>
|
|
1935
|
+
<SessionProgressIndicatorV2 />
|
|
1936
|
+
</Show>
|
|
1937
|
+
<span data-component="task-tool-title">{title()}</span>
|
|
1938
|
+
<Show when={subtitle()}>
|
|
1939
|
+
<span data-slot="basic-tool-tool-subtitle">{subtitle()}</span>
|
|
1940
|
+
</Show>
|
|
1941
|
+
</div>
|
|
1942
|
+
<Show when={clickable()}>
|
|
1943
|
+
<div data-component="task-tool-action">
|
|
1944
|
+
<Icon name="chevron-right" size="normal" />
|
|
1945
|
+
</div>
|
|
1946
|
+
</Show>
|
|
1947
|
+
</div>
|
|
1948
|
+
</div>
|
|
1949
|
+
</div>
|
|
1950
|
+
)
|
|
1951
|
+
|
|
1952
|
+
return (
|
|
1953
|
+
<Show
|
|
1954
|
+
when={view().delegating}
|
|
1955
|
+
fallback={
|
|
1956
|
+
<BasicTool
|
|
1957
|
+
icon="task"
|
|
1958
|
+
status={view().basicStatus}
|
|
1959
|
+
trigger={trigger()}
|
|
1960
|
+
hideDetails
|
|
1961
|
+
triggerAsLink
|
|
1962
|
+
triggerHref={href()}
|
|
1963
|
+
clickable={clickable()}
|
|
1964
|
+
onTriggerClick={navigate}
|
|
1965
|
+
onTriggerKeyDown={navigateKey}
|
|
1966
|
+
/>
|
|
1967
|
+
}
|
|
1968
|
+
>
|
|
1969
|
+
<div
|
|
1970
|
+
data-component="task-tool-delegating"
|
|
1971
|
+
class="flex h-9 w-fit max-w-full items-center gap-2 rounded-[8px] bg-v2-background-bg-layer-02 px-3 text-[13px] font-[530] leading-text-compact tracking-[-0.04px] text-v2-text-text-base"
|
|
1972
|
+
>
|
|
1973
|
+
<SessionProgressIndicatorV2 />
|
|
1974
|
+
<span class="min-w-0 truncate">{i18n.t("ui.tool.agent.delegating")}</span>
|
|
1975
|
+
</div>
|
|
1976
|
+
</Show>
|
|
1977
|
+
)
|
|
1978
|
+
},
|
|
1979
|
+
})
|
|
1980
|
+
|
|
1981
|
+
export function ConsoleOutput(props: { command?: string; output: string }) {
|
|
1982
|
+
const i18n = useI18n()
|
|
1983
|
+
|
|
1984
|
+
return (
|
|
1985
|
+
<div data-component="bash-output" data-variant="shell" dir="ltr">
|
|
1986
|
+
<div
|
|
1987
|
+
data-slot="bash-scroll"
|
|
1988
|
+
data-scrollable
|
|
1989
|
+
tabIndex={-1}
|
|
1990
|
+
role="region"
|
|
1991
|
+
aria-label={i18n.t("ui.scrollView.ariaLabel")}
|
|
1992
|
+
>
|
|
1993
|
+
<Show when={props.command}>
|
|
1994
|
+
{(command) => (
|
|
1995
|
+
<div data-slot="bash-command">
|
|
1996
|
+
<ConsoleCopy text={command()} label={i18n.t("ui.message.copy")} />
|
|
1997
|
+
<pre data-slot="bash-pre">
|
|
1998
|
+
<code>{command()}</code>
|
|
1999
|
+
</pre>
|
|
2000
|
+
</div>
|
|
2001
|
+
)}
|
|
2002
|
+
</Show>
|
|
2003
|
+
<Show when={props.output}>
|
|
2004
|
+
{(output) => (
|
|
2005
|
+
<div data-slot="bash-result">
|
|
2006
|
+
<ConsoleCopy text={output()} label={i18n.t("ui.message.copyOutput")} />
|
|
2007
|
+
<pre data-slot="bash-pre">
|
|
2008
|
+
<code>
|
|
2009
|
+
<LinkedText text={output()} />
|
|
2010
|
+
</code>
|
|
2011
|
+
</pre>
|
|
2012
|
+
</div>
|
|
2013
|
+
)}
|
|
2014
|
+
</Show>
|
|
2015
|
+
</div>
|
|
2016
|
+
</div>
|
|
2017
|
+
)
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
// The button sits beside its section's <pre>, not inside it, so selecting and copying text never picks it up.
|
|
2021
|
+
export function ConsoleCopy(props: { text: string; label: string }) {
|
|
2022
|
+
const i18n = useI18n()
|
|
2023
|
+
const copy = createCopyFeedback()
|
|
2024
|
+
const label = () => (copy.copied() ? i18n.t("ui.message.copied") : props.label)
|
|
2025
|
+
|
|
2026
|
+
return (
|
|
2027
|
+
<div data-slot="bash-copy">
|
|
2028
|
+
<Tooltip value={label()} placement="top" forceOpen={copy.copied() || undefined}>
|
|
2029
|
+
<IconButton
|
|
2030
|
+
icon={<Icon name={copy.copied() ? "check" : "copy"} />}
|
|
2031
|
+
size="normal"
|
|
2032
|
+
variant="ghost-muted"
|
|
2033
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
2034
|
+
onClick={() => copy.copy(props.text)}
|
|
2035
|
+
aria-label={label()}
|
|
2036
|
+
/>
|
|
2037
|
+
</Tooltip>
|
|
2038
|
+
</div>
|
|
2039
|
+
)
|
|
2040
|
+
}
|
|
2041
|
+
|
|
2042
|
+
ToolRegistry.register({
|
|
2043
|
+
name: "execute",
|
|
2044
|
+
render(props) {
|
|
2045
|
+
const i18n = useI18n()
|
|
2046
|
+
const dialog = useDialog()
|
|
2047
|
+
const pending = () => props.status === "streaming" || props.status === "running"
|
|
2048
|
+
const count = createMemo(() => executeToolCallCount(props.metadata))
|
|
2049
|
+
const subtitle = createMemo(() => executeToolSubtitle(props.metadata))
|
|
2050
|
+
const code = createMemo(() => (toolInput(props.input).code ?? "").trimEnd())
|
|
2051
|
+
|
|
2052
|
+
// A runtime failure shows its output on the failing row; a successful script shows its result below the calls.
|
|
2053
|
+
const error = createMemo(() => {
|
|
2054
|
+
if (props.status !== "error" && props.metadata.error !== true) return undefined
|
|
2055
|
+
const fallback = i18n.t("ui.toolErrorCard.failed")
|
|
2056
|
+
const text = stripAnsi((props.status === "error" ? props.error : undefined) || props.output || fallback)
|
|
2057
|
+
|
|
2058
|
+
return text.replace(/^Error:\s*/, "").trim() || fallback
|
|
2059
|
+
})
|
|
2060
|
+
|
|
2061
|
+
const output = createMemo(() =>
|
|
2062
|
+
error()
|
|
2063
|
+
? ""
|
|
2064
|
+
: stripAnsi(props.output ?? "")
|
|
2065
|
+
.replace(/\r\n?/g, "\n")
|
|
2066
|
+
.trim(),
|
|
2067
|
+
)
|
|
2068
|
+
|
|
2069
|
+
// A runtime failure belongs to the call that raised it; scripts can also fail outside any call.
|
|
2070
|
+
const owner = createMemo(() => executeToolErrorIndex(props.metadata))
|
|
2071
|
+
|
|
2072
|
+
// A script can make thousands of calls, and a row costs as much to style as a line of a diff, so the list shows the
|
|
2073
|
+
// latest and reveals earlier ones on request.
|
|
2074
|
+
const [shown, setShown] = createSignal(executeCallsShown)
|
|
2075
|
+
const hidden = createMemo(() => Math.max(0, count() - shown()))
|
|
2076
|
+
const visible = createMemo(() => executeToolCalls(props.metadata, hidden()))
|
|
2077
|
+
|
|
2078
|
+
const reveal = (event: { currentTarget: HTMLElement }) => {
|
|
2079
|
+
const list = event.currentTarget.parentElement
|
|
2080
|
+
setShown((count) => count + executeCallsRevealed)
|
|
2081
|
+
|
|
2082
|
+
// The button leaves with the last hidden call, so focus moves on to the first call rather than the page.
|
|
2083
|
+
if (hidden() === 0) list?.querySelector<HTMLElement>('[data-slot="execute-tool-call"][tabindex]')?.focus()
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
const sawPending = pending()
|
|
2087
|
+
// A shimmer is six elements; a group opens dozens of finished scripts, so only one that ran while shown gets it.
|
|
2088
|
+
const shimmered = createMemo((was: boolean) => was || pending(), false)
|
|
2089
|
+
|
|
2090
|
+
// The script is complete once the call leaves streaming, so the dialog can show it while it runs.
|
|
2091
|
+
const viewable = () => props.status !== "streaming" && !!code()
|
|
2092
|
+
|
|
2093
|
+
const openDetails = () =>
|
|
2094
|
+
dialog.show(() => <ExecuteDetails code={code()} output={output()} error={error()} status={props.status} />)
|
|
2095
|
+
|
|
2096
|
+
return (
|
|
2097
|
+
<BasicTool
|
|
2098
|
+
{...props}
|
|
2099
|
+
icon="terminal"
|
|
2100
|
+
rail={false}
|
|
2101
|
+
hasContent={count() > 0 || !!error() || !!output()}
|
|
2102
|
+
compact
|
|
2103
|
+
allowOpenWhilePending
|
|
2104
|
+
trigger={(open) => (
|
|
2105
|
+
<div data-slot="basic-tool-tool-info-structured">
|
|
2106
|
+
<div data-slot="basic-tool-tool-info-main">
|
|
2107
|
+
<span data-slot="basic-tool-tool-title">
|
|
2108
|
+
<Show when={shimmered()} fallback={i18n.t("ui.tool.execute")}>
|
|
2109
|
+
<TextShimmer text={i18n.t("ui.tool.execute")} active={pending()} />
|
|
2110
|
+
</Show>
|
|
2111
|
+
</span>
|
|
2112
|
+
<Show when={!open() && subtitle()}>
|
|
2113
|
+
{(text) => <ShellSubmessage text={text()} animate={sawPending} />}
|
|
2114
|
+
</Show>
|
|
2115
|
+
</div>
|
|
2116
|
+
</div>
|
|
2117
|
+
)}
|
|
2118
|
+
action={
|
|
2119
|
+
viewable() ? (
|
|
2120
|
+
<Tooltip value={i18n.t("ui.tool.execute.viewCode")} placement="top">
|
|
2121
|
+
<IconButton
|
|
2122
|
+
icon={<Icon name="code" />}
|
|
2123
|
+
size="normal"
|
|
2124
|
+
variant="ghost"
|
|
2125
|
+
aria-label={i18n.t("ui.tool.execute.viewCode")}
|
|
2126
|
+
aria-haspopup="dialog"
|
|
2127
|
+
onClick={openDetails}
|
|
2128
|
+
/>
|
|
2129
|
+
</Tooltip>
|
|
2130
|
+
) : undefined
|
|
2131
|
+
}
|
|
2132
|
+
>
|
|
2133
|
+
<div data-component="execute-tool-calls">
|
|
2134
|
+
<Show when={hidden()}>
|
|
2135
|
+
{(count) => (
|
|
2136
|
+
<button type="button" data-slot="execute-tool-call-more" onClick={reveal}>
|
|
2137
|
+
{i18n.plural("ui.common.moreCount", count())}
|
|
2138
|
+
</button>
|
|
2139
|
+
)}
|
|
2140
|
+
</Show>
|
|
2141
|
+
<Index each={visible()}>
|
|
2142
|
+
{(item) => <ExecuteCallRow call={item().call} error={item().index === owner() ? error() : undefined} />}
|
|
2143
|
+
</Index>
|
|
2144
|
+
{/* A failure with no call, or one that belongs to a call still hidden above, shows on its own. */}
|
|
2145
|
+
<Show when={owner() < hidden() && error()}>{(text) => <ExecuteCallRow error={text()} />}</Show>
|
|
2146
|
+
<Show when={output()}>{(value) => <ExecuteOutputRow output={value()} />}</Show>
|
|
2147
|
+
</div>
|
|
2148
|
+
</BasicTool>
|
|
2149
|
+
)
|
|
2150
|
+
},
|
|
2151
|
+
})
|
|
2152
|
+
|
|
2153
|
+
const executeCallsShown = 10
|
|
2154
|
+
|
|
2155
|
+
const executeCallsRevealed = 50
|
|
2156
|
+
|
|
2157
|
+
function ExecuteDetails(props: { code: string; output: string; error?: string; status?: string }) {
|
|
2158
|
+
const i18n = useI18n()
|
|
2159
|
+
const fileComponent = useFileComponent()
|
|
2160
|
+
const lineCount = (text: string) => text.split("\n").length
|
|
2161
|
+
|
|
2162
|
+
// Code Mode returns structured results as compact JSON; show those indented, and highlight a bare JSON result.
|
|
2163
|
+
const output = createMemo(() => formatExecuteOutput(props.output))
|
|
2164
|
+
|
|
2165
|
+
// Code and output/error share one number gutter, sized to the longer block, so their content starts on the same column.
|
|
2166
|
+
const numberDigits = () =>
|
|
2167
|
+
String(
|
|
2168
|
+
Math.max(
|
|
2169
|
+
lineCount(props.code),
|
|
2170
|
+
props.error ? lineCount(props.error) : props.output ? lineCount(output().text) : 0,
|
|
2171
|
+
),
|
|
2172
|
+
).length
|
|
2173
|
+
|
|
2174
|
+
const statusLabel = () =>
|
|
2175
|
+
props.error
|
|
2176
|
+
? i18n.t("ui.toolErrorCard.failed")
|
|
2177
|
+
: props.status === "running"
|
|
2178
|
+
? i18n.t("ui.tool.execute.running")
|
|
2179
|
+
: i18n.t("ui.tool.execute.completed")
|
|
2180
|
+
|
|
2181
|
+
return (
|
|
2182
|
+
<Dialog size="large" fit>
|
|
2183
|
+
<DialogHeader>
|
|
2184
|
+
<div data-slot="execute-details-title">
|
|
2185
|
+
<DialogTitle>{i18n.t("ui.tool.execute")}</DialogTitle>
|
|
2186
|
+
<Badge variant={props.error ? "danger" : "neutral"}>{statusLabel()}</Badge>
|
|
2187
|
+
</div>
|
|
2188
|
+
</DialogHeader>
|
|
2189
|
+
<DialogBody class="min-h-0">
|
|
2190
|
+
<div data-component="execute-details" style={{ "--execute-details-number-width": `${numberDigits()}ch` }}>
|
|
2191
|
+
<ExecuteDetailsSection
|
|
2192
|
+
label={i18n.t("ui.tool.execute.code")}
|
|
2193
|
+
copy={props.code}
|
|
2194
|
+
copyLabel={i18n.t("ui.tool.execute.copyCode")}
|
|
2195
|
+
>
|
|
2196
|
+
<Dynamic
|
|
2197
|
+
component={fileComponent}
|
|
2198
|
+
mode="text"
|
|
2199
|
+
file={{ name: "execute.js", contents: props.code, cacheKey: checksum(props.code) }}
|
|
2200
|
+
overflow="wrap"
|
|
2201
|
+
lineHoverHighlight="disabled"
|
|
2202
|
+
/>
|
|
2203
|
+
</ExecuteDetailsSection>
|
|
2204
|
+
<Show
|
|
2205
|
+
when={props.error}
|
|
2206
|
+
fallback={
|
|
2207
|
+
<Show when={props.output}>
|
|
2208
|
+
<ExecuteDetailsSection
|
|
2209
|
+
label={i18n.t("ui.tool.execute.output")}
|
|
2210
|
+
copy={output().text}
|
|
2211
|
+
copyLabel={i18n.t("ui.tool.execute.copyOutput")}
|
|
2212
|
+
>
|
|
2213
|
+
<Dynamic
|
|
2214
|
+
component={fileComponent}
|
|
2215
|
+
mode="text"
|
|
2216
|
+
file={{
|
|
2217
|
+
name: output().json !== undefined && output().rest === undefined ? "output.json" : "output.txt",
|
|
2218
|
+
contents: output().text,
|
|
2219
|
+
cacheKey: checksum(output().text),
|
|
2220
|
+
}}
|
|
2221
|
+
overflow="wrap"
|
|
2222
|
+
lineHoverHighlight="disabled"
|
|
2223
|
+
/>
|
|
2224
|
+
</ExecuteDetailsSection>
|
|
2225
|
+
</Show>
|
|
2226
|
+
}
|
|
2227
|
+
>
|
|
2228
|
+
{(error) => (
|
|
2229
|
+
<ExecuteDetailsSection
|
|
2230
|
+
label={i18n.t("ui.tool.execute.error")}
|
|
2231
|
+
copy={error()}
|
|
2232
|
+
copyLabel={i18n.t("ui.toolErrorCard.copyError")}
|
|
2233
|
+
>
|
|
2234
|
+
<div data-tone="danger">
|
|
2235
|
+
<Dynamic
|
|
2236
|
+
component={fileComponent}
|
|
2237
|
+
mode="text"
|
|
2238
|
+
file={{ name: "error.txt", contents: error(), cacheKey: checksum(error()) }}
|
|
2239
|
+
overflow="wrap"
|
|
2240
|
+
lineHoverHighlight="disabled"
|
|
2241
|
+
/>
|
|
2242
|
+
</div>
|
|
2243
|
+
</ExecuteDetailsSection>
|
|
2244
|
+
)}
|
|
2245
|
+
</Show>
|
|
2246
|
+
</div>
|
|
2247
|
+
</DialogBody>
|
|
2248
|
+
</Dialog>
|
|
2249
|
+
)
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
function ExecuteDetailsSection(props: {
|
|
2253
|
+
label: string
|
|
2254
|
+
copy: string
|
|
2255
|
+
copyLabel: string
|
|
2256
|
+
children: JSX.Element
|
|
2257
|
+
}) {
|
|
2258
|
+
const i18n = useI18n()
|
|
2259
|
+
const copy = createCopyFeedback()
|
|
2260
|
+
|
|
2261
|
+
return (
|
|
2262
|
+
<section data-slot="execute-details-section">
|
|
2263
|
+
<header data-slot="execute-details-section-header">
|
|
2264
|
+
<span data-slot="execute-details-section-label">{props.label}</span>
|
|
2265
|
+
<Tooltip
|
|
2266
|
+
value={copy.copied() ? i18n.t("ui.message.copied") : props.copyLabel}
|
|
2267
|
+
placement="top"
|
|
2268
|
+
forceOpen={copy.copied() || undefined}
|
|
2269
|
+
>
|
|
2270
|
+
<IconButton
|
|
2271
|
+
icon={<Icon name={copy.copied() ? "check" : "copy"} />}
|
|
2272
|
+
size="normal"
|
|
2273
|
+
variant="ghost-muted"
|
|
2274
|
+
aria-label={copy.copied() ? i18n.t("ui.message.copied") : props.copyLabel}
|
|
2275
|
+
onClick={() => copy.copy(props.copy)}
|
|
2276
|
+
/>
|
|
2277
|
+
</Tooltip>
|
|
2278
|
+
</header>
|
|
2279
|
+
<div data-slot="execute-details-source">{props.children}</div>
|
|
2280
|
+
</section>
|
|
2281
|
+
)
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
// Whether the press that ends on `row` selected text in it, which the row keeps rather than toggling. A selection that
|
|
2285
|
+
// neither starts nor ends in the row is not that press's: a text field keeps its selection after focus leaves it, and a
|
|
2286
|
+
// press on a row the host made non-selectable clears nothing.
|
|
2287
|
+
function selectsRowText(row: HTMLElement) {
|
|
2288
|
+
const selection = window.getSelection()
|
|
2289
|
+
|
|
2290
|
+
if (!selection || selection.isCollapsed) return false
|
|
2291
|
+
|
|
2292
|
+
return row.contains(selection.anchorNode) || row.contains(selection.focusNode)
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
function ExecuteOutputRow(props: { output: string }) {
|
|
2296
|
+
const i18n = useI18n()
|
|
2297
|
+
const [open, setOpen] = createSignal(false)
|
|
2298
|
+
const text = createMemo(() => formatExecuteOutput(props.output).text)
|
|
2299
|
+
|
|
2300
|
+
const toggle = (event: { currentTarget: HTMLElement }) => {
|
|
2301
|
+
if (selectsRowText(event.currentTarget)) return
|
|
2302
|
+
setOpen((value) => !value)
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
return (
|
|
2306
|
+
<div data-slot="execute-tool-call-item">
|
|
2307
|
+
<div
|
|
2308
|
+
data-slot="execute-tool-call"
|
|
2309
|
+
data-kind="output"
|
|
2310
|
+
role="button"
|
|
2311
|
+
tabIndex={0}
|
|
2312
|
+
aria-expanded={open()}
|
|
2313
|
+
onClick={toggle}
|
|
2314
|
+
onKeyDown={(event) => {
|
|
2315
|
+
if (event.key !== "Enter" && event.key !== " ") return
|
|
2316
|
+
event.preventDefault()
|
|
2317
|
+
toggle(event)
|
|
2318
|
+
}}
|
|
2319
|
+
>
|
|
2320
|
+
<span data-slot="execute-tool-call-marker">
|
|
2321
|
+
<span data-slot="execute-tool-call-arrow">›</span>
|
|
2322
|
+
</span>
|
|
2323
|
+
<span data-slot="execute-tool-call-name">{i18n.t("ui.tool.execute.output")}</span>
|
|
2324
|
+
<span data-slot="execute-tool-call-args">
|
|
2325
|
+
{i18n.plural("ui.tool.execute.lines", text().split("\n").length)}
|
|
2326
|
+
</span>
|
|
2327
|
+
</div>
|
|
2328
|
+
<Show when={open()}>
|
|
2329
|
+
<div data-slot="execute-tool-output">
|
|
2330
|
+
<ConsoleOutput output={text()} />
|
|
2331
|
+
</div>
|
|
2332
|
+
</Show>
|
|
2333
|
+
</div>
|
|
2334
|
+
)
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2337
|
+
function ExecuteCallRow(props: { call?: ExecuteToolCall; error?: string }) {
|
|
2338
|
+
const [open, setOpen] = createSignal(false)
|
|
2339
|
+
const args = createMemo(() => (props.call ? executeToolCallArgs(props.call) : []))
|
|
2340
|
+
const input = createMemo(() => Object.entries(props.call?.input ?? {}))
|
|
2341
|
+
const failed = () => !props.call || props.call.status === "error"
|
|
2342
|
+
const expandable = () => input().length > 0 || !!props.error
|
|
2343
|
+
const summary = () => (props.call ? args().join(", ") : props.error?.split("\n", 1)[0])
|
|
2344
|
+
// Only a call that ran while shown gets a shimmer, kept so it fades out when the call finishes.
|
|
2345
|
+
const shimmered = createMemo((was: boolean) => was || props.call?.status === "running", false)
|
|
2346
|
+
|
|
2347
|
+
const toggle = (event: { currentTarget: HTMLElement }) => {
|
|
2348
|
+
if (!expandable() || selectsRowText(event.currentTarget)) return
|
|
2349
|
+
setOpen((value) => !value)
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
return (
|
|
2353
|
+
<div data-slot="execute-tool-call-item">
|
|
2354
|
+
<div
|
|
2355
|
+
data-slot="execute-tool-call"
|
|
2356
|
+
data-status={failed() ? "error" : props.call?.status}
|
|
2357
|
+
data-expanded={open() ? "true" : undefined}
|
|
2358
|
+
dir="ltr"
|
|
2359
|
+
role={expandable() ? "button" : undefined}
|
|
2360
|
+
tabIndex={expandable() ? 0 : undefined}
|
|
2361
|
+
aria-expanded={expandable() ? open() : undefined}
|
|
2362
|
+
onClick={toggle}
|
|
2363
|
+
onKeyDown={(event) => {
|
|
2364
|
+
if (event.key !== "Enter" && event.key !== " ") return
|
|
2365
|
+
event.preventDefault()
|
|
2366
|
+
toggle(event)
|
|
2367
|
+
}}
|
|
2368
|
+
>
|
|
2369
|
+
<Show when={failed()} fallback={<span data-slot="execute-tool-call-marker">›</span>}>
|
|
2370
|
+
<span data-slot="execute-tool-call-marker">
|
|
2371
|
+
<Icon name="outline-hexagonal-warning" size="small" />
|
|
2372
|
+
</span>
|
|
2373
|
+
</Show>
|
|
2374
|
+
<Show when={props.call}>
|
|
2375
|
+
{(call) => (
|
|
2376
|
+
<span data-slot="execute-tool-call-name">
|
|
2377
|
+
<Show when={shimmered()} fallback={call().tool}>
|
|
2378
|
+
<TextShimmer text={call().tool} active={call().status === "running"} />
|
|
2379
|
+
</Show>
|
|
2380
|
+
</span>
|
|
2381
|
+
)}
|
|
2382
|
+
</Show>
|
|
2383
|
+
<Show when={!open() && summary()}>
|
|
2384
|
+
{(text) => (
|
|
2385
|
+
<span data-slot="execute-tool-call-args" title={text()}>
|
|
2386
|
+
{props.call ? `[${text()}]` : text()}
|
|
2387
|
+
</span>
|
|
2388
|
+
)}
|
|
2389
|
+
</Show>
|
|
2390
|
+
<Show when={props.error}>
|
|
2391
|
+
<span data-slot="execute-tool-call-arrow">›</span>
|
|
2392
|
+
</Show>
|
|
2393
|
+
</div>
|
|
2394
|
+
<Show when={open()}>
|
|
2395
|
+
<Show when={input().length > 0}>
|
|
2396
|
+
<dl data-slot="execute-tool-call-input" dir="ltr">
|
|
2397
|
+
<For each={input()}>
|
|
2398
|
+
{([key, value]) => (
|
|
2399
|
+
<div data-slot="execute-tool-call-input-entry">
|
|
2400
|
+
<dt>{key}:</dt>
|
|
2401
|
+
<dd>{Option.getOrElse(decodeString(value), () => JSON.stringify(value, null, 2))}</dd>
|
|
2402
|
+
</div>
|
|
2403
|
+
)}
|
|
2404
|
+
</For>
|
|
2405
|
+
</dl>
|
|
2406
|
+
</Show>
|
|
2407
|
+
<Show when={props.error}>
|
|
2408
|
+
{(error) => (
|
|
2409
|
+
<div data-slot="execute-tool-error" dir="ltr">
|
|
2410
|
+
<LinkedText text={error()} />
|
|
2411
|
+
</div>
|
|
2412
|
+
)}
|
|
2413
|
+
</Show>
|
|
2414
|
+
</Show>
|
|
2415
|
+
</div>
|
|
2416
|
+
)
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
ToolRegistry.register({
|
|
2420
|
+
name: "shell",
|
|
2421
|
+
render(props) {
|
|
2422
|
+
const i18n = useI18n()
|
|
2423
|
+
const data = useData()
|
|
2424
|
+
|
|
2425
|
+
const runProps = () =>
|
|
2426
|
+
shellRunProps(
|
|
2427
|
+
{
|
|
2428
|
+
status: props.status,
|
|
2429
|
+
input: toolInput(props.input),
|
|
2430
|
+
metadata: toolMetadata(props.metadata),
|
|
2431
|
+
output: props.output,
|
|
2432
|
+
},
|
|
2433
|
+
(id) => data.shellRunning?.(id) === true,
|
|
2434
|
+
)
|
|
2435
|
+
|
|
2436
|
+
const [run, setRun] = createSignal(createShellRunState(untrack(runProps)))
|
|
2437
|
+
|
|
2438
|
+
const dispatch = (event: ShellRunEvent) => {
|
|
2439
|
+
const next = transitionShellRun(untrack(run), event)
|
|
2440
|
+
|
|
2441
|
+
if (next !== untrack(run)) setRun(next)
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
// Synchronous, so the row never renders a pass with the previous phase.
|
|
2445
|
+
createComputed(on(runProps, (value) => dispatch({ type: "sync", props: value }), { defer: true }))
|
|
2446
|
+
const view = createMemo(() => viewShellRun(run()))
|
|
2447
|
+
// The trigger animates the command in only when the row mounted while the model was still writing it.
|
|
2448
|
+
const animateCommand = untrack(run).status === "writing"
|
|
2449
|
+
|
|
2450
|
+
function Output() {
|
|
2451
|
+
const followID = createMemo(() => view().follow?.id)
|
|
2452
|
+
const followRunning = createMemo(() => view().follow?.running === true)
|
|
2453
|
+
|
|
2454
|
+
createEffect(() => {
|
|
2455
|
+
const id = followID()
|
|
2456
|
+
const load = data.shellOutput
|
|
2457
|
+
|
|
2458
|
+
if (id === undefined || !load) return
|
|
2459
|
+
|
|
2460
|
+
const follower = createShellFollower({
|
|
2461
|
+
id,
|
|
2462
|
+
directory: data.directory,
|
|
2463
|
+
running: untrack(followRunning),
|
|
2464
|
+
load,
|
|
2465
|
+
onOutput: (output) => dispatch({ type: "output.received", shellID: id, output }),
|
|
2466
|
+
})
|
|
2467
|
+
|
|
2468
|
+
createEffect(on(followRunning, (running) => follower.setRunning(running), { defer: true }))
|
|
2469
|
+
onCleanup(follower.dispose)
|
|
2470
|
+
})
|
|
2471
|
+
|
|
2472
|
+
return <ConsoleOutput command={view().command} output={view().output} />
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
return (
|
|
2476
|
+
<BasicTool
|
|
2477
|
+
{...props}
|
|
2478
|
+
status={view().basicStatus}
|
|
2479
|
+
icon="terminal"
|
|
2480
|
+
rail={false}
|
|
2481
|
+
hasContent
|
|
2482
|
+
compact
|
|
2483
|
+
allowOpenWhilePending
|
|
2484
|
+
trigger={(open) => (
|
|
2485
|
+
<div data-slot="basic-tool-tool-info-structured">
|
|
2486
|
+
<div data-slot="basic-tool-tool-info-main">
|
|
2487
|
+
<span data-slot="basic-tool-tool-title">
|
|
2488
|
+
<TextShimmer text={i18n.t("ui.tool.shell")} active={view().pending} />
|
|
2489
|
+
</span>
|
|
2490
|
+
<Show when={!open()}>
|
|
2491
|
+
<Show
|
|
2492
|
+
when={view().command}
|
|
2493
|
+
fallback={
|
|
2494
|
+
<Show when={view().writingPlaceholder}>
|
|
2495
|
+
<span data-slot="basic-tool-tool-subtitle">{i18n.t("ui.tool.shell.writingCommand")}</span>
|
|
2496
|
+
</Show>
|
|
2497
|
+
}
|
|
2498
|
+
>
|
|
2499
|
+
{(command) => <ShellSubmessage text={command()} animate={animateCommand} />}
|
|
2500
|
+
</Show>
|
|
2501
|
+
</Show>
|
|
2502
|
+
</div>
|
|
2503
|
+
</div>
|
|
2504
|
+
)}
|
|
2505
|
+
>
|
|
2506
|
+
<Output />
|
|
2507
|
+
</BasicTool>
|
|
2508
|
+
)
|
|
2509
|
+
},
|
|
2510
|
+
})
|
|
2511
|
+
|
|
2512
|
+
export function SessionShellMessage(props: {
|
|
2513
|
+
message: SessionMessageShell
|
|
2514
|
+
defaultOpen?: boolean
|
|
2515
|
+
open?: boolean
|
|
2516
|
+
onOpenChange?: (open: boolean) => void
|
|
2517
|
+
}) {
|
|
2518
|
+
const i18n = useI18n()
|
|
2519
|
+
const render = ToolRegistry.render("shell") ?? GenericTool
|
|
2520
|
+
|
|
2521
|
+
const error = createMemo(() => {
|
|
2522
|
+
const message = props.message
|
|
2523
|
+
|
|
2524
|
+
if (message.status === "timeout") return i18n.t("ui.tool.shell.timeout")
|
|
2525
|
+
|
|
2526
|
+
if (message.status === "killed") return i18n.t("ui.tool.shell.cancelled")
|
|
2527
|
+
|
|
2528
|
+
if (message.status !== "exited" || message.exit === undefined || message.exit === 0) return
|
|
2529
|
+
|
|
2530
|
+
return i18n.t("ui.tool.shell.exit", { code: message.exit })
|
|
2531
|
+
})
|
|
2532
|
+
|
|
2533
|
+
return (
|
|
2534
|
+
<div data-component="session-shell-message" data-timeline-part-id={props.message.id}>
|
|
2535
|
+
<Dynamic
|
|
2536
|
+
component={render}
|
|
2537
|
+
tool="shell"
|
|
2538
|
+
input={{ command: props.message.command }}
|
|
2539
|
+
metadata={{
|
|
2540
|
+
shellID: props.message.shellID,
|
|
2541
|
+
status: props.message.status,
|
|
2542
|
+
exit: props.message.exit,
|
|
2543
|
+
truncated: props.message.output?.truncated,
|
|
2544
|
+
}}
|
|
2545
|
+
output={props.message.output?.output}
|
|
2546
|
+
status={props.message.status === "running" ? "running" : "completed"}
|
|
2547
|
+
defaultOpen={props.defaultOpen}
|
|
2548
|
+
open={props.open}
|
|
2549
|
+
onOpenChange={props.onOpenChange}
|
|
2550
|
+
/>
|
|
2551
|
+
<Show when={error()}>
|
|
2552
|
+
{(error) => <ToolErrorCard tool="shell" error={error()} subtitle={props.message.command} />}
|
|
2553
|
+
</Show>
|
|
2554
|
+
</div>
|
|
2555
|
+
)
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
ToolRegistry.register({
|
|
2559
|
+
name: "edit",
|
|
2560
|
+
render(props) {
|
|
2561
|
+
const i18n = useI18n()
|
|
2562
|
+
const fileComponent = useFileComponent()
|
|
2563
|
+
const input = createMemo(() => toolInput(props.input))
|
|
2564
|
+
const metadata = createMemo(() => toolMetadata(props.metadata))
|
|
2565
|
+
const inputPath = () => input().path ?? ""
|
|
2566
|
+
const diff = createMemo(() => metadata().files?.find(changedFileDiff))
|
|
2567
|
+
const diagnostics = createMemo(() => getDiagnostics(metadata().diagnostics, inputPath()))
|
|
2568
|
+
const path = createMemo(() => diff()?.file ?? inputPath())
|
|
2569
|
+
|
|
2570
|
+
const pending = () => props.status === "streaming" || props.status === "running"
|
|
2571
|
+
|
|
2572
|
+
const diffSource = createMemo(
|
|
2573
|
+
() => {
|
|
2574
|
+
const source = diff()
|
|
2575
|
+
|
|
2576
|
+
if (!source) return undefined
|
|
2577
|
+
|
|
2578
|
+
return { file: source.file, patch: source.patch }
|
|
2579
|
+
},
|
|
2580
|
+
undefined,
|
|
2581
|
+
{
|
|
2582
|
+
equals: (a, b) => a?.file === b?.file && a?.patch === b?.patch,
|
|
2583
|
+
},
|
|
2584
|
+
)
|
|
2585
|
+
|
|
2586
|
+
const fileCompProps = createMemo(() => {
|
|
2587
|
+
try {
|
|
2588
|
+
const source = diffSource()
|
|
2589
|
+
|
|
2590
|
+
if (source) {
|
|
2591
|
+
const fileDiff = resolveFileDiff(source)
|
|
2592
|
+
|
|
2593
|
+
if (fileDiff) return { fileDiff, hunkSeparators: fileDiff.isPartial ? "simple" : "line-info-basic" }
|
|
2594
|
+
}
|
|
2595
|
+
} catch {}
|
|
2596
|
+
|
|
2597
|
+
return {
|
|
2598
|
+
before: {
|
|
2599
|
+
name: path(),
|
|
2600
|
+
contents: input().oldString ?? "",
|
|
2601
|
+
},
|
|
2602
|
+
after: {
|
|
2603
|
+
name: path(),
|
|
2604
|
+
contents: input().newString ?? "",
|
|
2605
|
+
},
|
|
2606
|
+
}
|
|
2607
|
+
})
|
|
2608
|
+
|
|
2609
|
+
return (
|
|
2610
|
+
<div data-component="edit-tool">
|
|
2611
|
+
<FileTool {...props} title={i18n.t("ui.messagePart.title.edit")} count={path() ? 1 : 0}>
|
|
2612
|
+
<Show when={path()}>
|
|
2613
|
+
<ToolFileAccordion
|
|
2614
|
+
path={path()}
|
|
2615
|
+
defaultOpen={props.defaultOpen}
|
|
2616
|
+
open={props.open}
|
|
2617
|
+
onOpenChange={props.onOpenChange}
|
|
2618
|
+
forceOpen={props.forceOpen}
|
|
2619
|
+
defer={props.deferContent !== false}
|
|
2620
|
+
actions={
|
|
2621
|
+
<Show when={!pending() ? diff() : undefined}>
|
|
2622
|
+
{(diff) => <DiffChanges appearance="standard" changes={diff()} />}
|
|
2623
|
+
</Show>
|
|
2624
|
+
}
|
|
2625
|
+
>
|
|
2626
|
+
<div data-component="edit-content">
|
|
2627
|
+
<Dynamic
|
|
2628
|
+
component={fileComponent}
|
|
2629
|
+
mode="diff"
|
|
2630
|
+
virtualize={props.virtualizeDiff}
|
|
2631
|
+
onRendered={props.onContentRendered}
|
|
2632
|
+
{...fileCompProps()}
|
|
2633
|
+
/>
|
|
2634
|
+
</div>
|
|
2635
|
+
</ToolFileAccordion>
|
|
2636
|
+
</Show>
|
|
2637
|
+
<DiagnosticsDisplay diagnostics={diagnostics()} />
|
|
2638
|
+
</FileTool>
|
|
2639
|
+
</div>
|
|
2640
|
+
)
|
|
2641
|
+
},
|
|
2642
|
+
})
|
|
2643
|
+
|
|
2644
|
+
ToolRegistry.register({
|
|
2645
|
+
name: "write",
|
|
2646
|
+
render(props) {
|
|
2647
|
+
const fileComponent = useFileComponent()
|
|
2648
|
+
const path = createMemo(() => toolInput(props.input).path ?? "")
|
|
2649
|
+
const content = createMemo(() => toolInput(props.input).content ?? "")
|
|
2650
|
+
const diagnostics = createMemo(() => getDiagnostics(toolMetadata(props.metadata).diagnostics, path()))
|
|
2651
|
+
|
|
2652
|
+
return (
|
|
2653
|
+
<div data-component="write-tool">
|
|
2654
|
+
<Show when={content() && path()}>
|
|
2655
|
+
<ToolFileAccordion
|
|
2656
|
+
path={path()}
|
|
2657
|
+
defaultOpen={props.defaultOpen}
|
|
2658
|
+
open={props.open}
|
|
2659
|
+
onOpenChange={props.onOpenChange}
|
|
2660
|
+
forceOpen={props.forceOpen}
|
|
2661
|
+
defer={props.deferContent !== false}
|
|
2662
|
+
>
|
|
2663
|
+
<div data-component="write-content">
|
|
2664
|
+
<Dynamic
|
|
2665
|
+
component={fileComponent}
|
|
2666
|
+
mode="text"
|
|
2667
|
+
file={{
|
|
2668
|
+
name: path(),
|
|
2669
|
+
contents: content(),
|
|
2670
|
+
cacheKey: checksum(content()),
|
|
2671
|
+
}}
|
|
2672
|
+
overflow="scroll"
|
|
2673
|
+
onRendered={props.onContentRendered}
|
|
2674
|
+
/>
|
|
2675
|
+
</div>
|
|
2676
|
+
</ToolFileAccordion>
|
|
2677
|
+
</Show>
|
|
2678
|
+
<DiagnosticsDisplay diagnostics={diagnostics()} />
|
|
2679
|
+
</div>
|
|
2680
|
+
)
|
|
2681
|
+
},
|
|
2682
|
+
})
|
|
2683
|
+
|
|
2684
|
+
ToolRegistry.register({
|
|
2685
|
+
name: "patch",
|
|
2686
|
+
render(props) {
|
|
2687
|
+
const i18n = useI18n()
|
|
2688
|
+
const fileComponent = useFileComponent()
|
|
2689
|
+
|
|
2690
|
+
const files = createMemo(
|
|
2691
|
+
() =>
|
|
2692
|
+
props.pendingFiles?.map((path) => ({
|
|
2693
|
+
path,
|
|
2694
|
+
type: "update" as const,
|
|
2695
|
+
additions: 0,
|
|
2696
|
+
deletions: 0,
|
|
2697
|
+
views: [],
|
|
2698
|
+
})) ?? patchFileGroups(props.metadata.files),
|
|
2699
|
+
)
|
|
2700
|
+
|
|
2701
|
+
const title = createMemo(() => {
|
|
2702
|
+
if (props.tool === "edit") return i18n.t("ui.messagePart.title.edit")
|
|
2703
|
+
|
|
2704
|
+
if (props.tool === "write") return i18n.t("ui.messagePart.title.write")
|
|
2705
|
+
|
|
2706
|
+
return i18n.t("ui.tool.patch")
|
|
2707
|
+
})
|
|
2708
|
+
|
|
2709
|
+
return (
|
|
2710
|
+
<div data-component="apply-patch-tool">
|
|
2711
|
+
<Show when={files().length > 0} fallback={<FileTool {...props} title={title()} count={0} />}>
|
|
2712
|
+
<FileAccordionGroup>
|
|
2713
|
+
<Index each={files()}>
|
|
2714
|
+
{(file) => {
|
|
2715
|
+
// Each file opens on its own: the owner's `fileOpen` controls it, otherwise it keeps its own state.
|
|
2716
|
+
const disclosure = createDisclosure({
|
|
2717
|
+
open: () => (props.fileOpen ? props.fileOpen(file().path) === true : undefined),
|
|
2718
|
+
defer: () => props.deferContent !== false,
|
|
2719
|
+
onOpenChange: (open) => props.onFileOpenChange?.(file().path, open),
|
|
2720
|
+
})
|
|
2721
|
+
|
|
2722
|
+
return (
|
|
2723
|
+
<FileAccordionItem
|
|
2724
|
+
open={disclosure.open()}
|
|
2725
|
+
onOpenChange={disclosure.setOpen}
|
|
2726
|
+
type={file().type}
|
|
2727
|
+
header={
|
|
2728
|
+
<div data-slot="apply-patch-trigger-content">
|
|
2729
|
+
<div data-slot="apply-patch-file-info">
|
|
2730
|
+
<FileIcon node={{ path: file().path, type: "file" }} />
|
|
2731
|
+
<div data-slot="apply-patch-file-name-container">
|
|
2732
|
+
<Show when={file().path.includes("/")}>
|
|
2733
|
+
<span data-slot="apply-patch-directory">{`\u202A${displayDirectory(file().path)}\u202C`}</span>
|
|
2734
|
+
</Show>
|
|
2735
|
+
<span data-slot="apply-patch-filename">{getFilename(file().path)}</span>
|
|
2736
|
+
</div>
|
|
2737
|
+
</div>
|
|
2738
|
+
<div data-slot="apply-patch-trigger-actions">
|
|
2739
|
+
<Switch>
|
|
2740
|
+
<Match when={file().type === "add"}>
|
|
2741
|
+
<span data-slot="apply-patch-change" data-type="added">
|
|
2742
|
+
{i18n.t("ui.patch.action.created")}
|
|
2743
|
+
</span>
|
|
2744
|
+
</Match>
|
|
2745
|
+
<Match when={file().type === "delete"}>
|
|
2746
|
+
<span data-slot="apply-patch-change" data-type="removed">
|
|
2747
|
+
{i18n.t("ui.patch.action.deleted")}
|
|
2748
|
+
</span>
|
|
2749
|
+
</Match>
|
|
2750
|
+
<Match when={true}>
|
|
2751
|
+
<DiffChanges
|
|
2752
|
+
appearance="standard"
|
|
2753
|
+
changes={{ additions: file().additions, deletions: file().deletions }}
|
|
2754
|
+
/>
|
|
2755
|
+
</Match>
|
|
2756
|
+
</Switch>
|
|
2757
|
+
<Icon name="chevron-grabber-vertical" />
|
|
2758
|
+
</div>
|
|
2759
|
+
</div>
|
|
2760
|
+
}
|
|
2761
|
+
>
|
|
2762
|
+
<Show when={disclosure.mounted()}>
|
|
2763
|
+
<For each={file().views}>
|
|
2764
|
+
{(view) => (
|
|
2765
|
+
<div data-component="apply-patch-file-diff">
|
|
2766
|
+
<Dynamic
|
|
2767
|
+
component={fileComponent}
|
|
2768
|
+
mode="diff"
|
|
2769
|
+
virtualize={props.virtualizeDiff}
|
|
2770
|
+
fileDiff={view.fileDiff}
|
|
2771
|
+
hunkSeparators={view.fileDiff.isPartial ? "simple" : "line-info-basic"}
|
|
2772
|
+
onRendered={props.onContentRendered}
|
|
2773
|
+
/>
|
|
2774
|
+
</div>
|
|
2775
|
+
)}
|
|
2776
|
+
</For>
|
|
2777
|
+
</Show>
|
|
2778
|
+
</FileAccordionItem>
|
|
2779
|
+
)
|
|
2780
|
+
}}
|
|
2781
|
+
</Index>
|
|
2782
|
+
</FileAccordionGroup>
|
|
2783
|
+
</Show>
|
|
2784
|
+
</div>
|
|
2785
|
+
)
|
|
2786
|
+
},
|
|
2787
|
+
})
|
|
2788
|
+
|
|
2789
|
+
ToolRegistry.register({
|
|
2790
|
+
name: "question",
|
|
2791
|
+
render(props) {
|
|
2792
|
+
const i18n = useI18n()
|
|
2793
|
+
|
|
2794
|
+
const items = createMemo(() => questions(toolInput(props.input)))
|
|
2795
|
+
|
|
2796
|
+
const answers = createMemo(() =>
|
|
2797
|
+
(toolMetadata(props.metadata).answers ?? []).flatMap((answer) => Option.toArray(decodeAnswer(answer))),
|
|
2798
|
+
)
|
|
2799
|
+
|
|
2800
|
+
const completed = createMemo(() => answers().length > 0)
|
|
2801
|
+
|
|
2802
|
+
const subtitle = createMemo(() => {
|
|
2803
|
+
const count = items().length
|
|
2804
|
+
|
|
2805
|
+
if (count === 0) return ""
|
|
2806
|
+
|
|
2807
|
+
if (completed()) return i18n.t("ui.question.subtitle.answered", { count })
|
|
2808
|
+
|
|
2809
|
+
return `${count} ${i18n.plural("ui.common.question", count)}`
|
|
2810
|
+
})
|
|
2811
|
+
|
|
2812
|
+
return (
|
|
2813
|
+
<BasicTool
|
|
2814
|
+
{...props}
|
|
2815
|
+
defaultOpen={completed()}
|
|
2816
|
+
icon="comment"
|
|
2817
|
+
trigger={{
|
|
2818
|
+
title: i18n.t("ui.tool.questions"),
|
|
2819
|
+
subtitle: subtitle(),
|
|
2820
|
+
}}
|
|
2821
|
+
>
|
|
2822
|
+
<Show when={completed()}>
|
|
2823
|
+
<div data-component="question-answers">
|
|
2824
|
+
<For each={items()}>
|
|
2825
|
+
{(q, i) => {
|
|
2826
|
+
const answer = () => answers()[i()] ?? []
|
|
2827
|
+
|
|
2828
|
+
return (
|
|
2829
|
+
<div data-slot="question-answer-item">
|
|
2830
|
+
<div data-slot="question-text">
|
|
2831
|
+
<LinkedText text={q.question} />
|
|
2832
|
+
</div>
|
|
2833
|
+
<div data-slot="answer-text">{answer().join(", ") || i18n.t("ui.question.answer.none")}</div>
|
|
2834
|
+
</div>
|
|
2835
|
+
)
|
|
2836
|
+
}}
|
|
2837
|
+
</For>
|
|
2838
|
+
</div>
|
|
2839
|
+
</Show>
|
|
2840
|
+
</BasicTool>
|
|
2841
|
+
)
|
|
2842
|
+
},
|
|
2843
|
+
})
|
|
2844
|
+
|
|
2845
|
+
ToolRegistry.register({
|
|
2846
|
+
name: "skill",
|
|
2847
|
+
render(props) {
|
|
2848
|
+
const i18n = useI18n()
|
|
2849
|
+
const name = createMemo(() => skillToolName(toolInput(props.input), toolMetadata(props.metadata)))
|
|
2850
|
+
const running = createMemo(() => props.status === "streaming" || props.status === "running")
|
|
2851
|
+
const marker = "__OPENCODE_LOADED_SKILL__"
|
|
2852
|
+
const parts = createMemo(() => i18n.t("ui.tool.loadedSkill", { name: marker }).split(marker))
|
|
2853
|
+
|
|
2854
|
+
return (
|
|
2855
|
+
<Show when={name()} fallback={<TextShimmer text={i18n.t("ui.tool.skill")} active={running()} />}>
|
|
2856
|
+
{(name) => (
|
|
2857
|
+
<div data-component="tool-loaded-item" aria-label={i18n.t("ui.tool.loadedSkill", { name: name() })}>
|
|
2858
|
+
<span data-slot="tool-loaded-label" aria-hidden="true">
|
|
2859
|
+
{parts()[0].trim()}
|
|
2860
|
+
</span>
|
|
2861
|
+
<span data-slot="tool-loaded-value" aria-hidden="true">
|
|
2862
|
+
<TextShimmer as="span" text={name()} active={running()} />
|
|
2863
|
+
</span>
|
|
2864
|
+
<Show when={parts()[1]?.trim()}>
|
|
2865
|
+
{(suffix) => (
|
|
2866
|
+
<span data-slot="tool-loaded-kind" aria-hidden="true">
|
|
2867
|
+
{suffix()}
|
|
2868
|
+
</span>
|
|
2869
|
+
)}
|
|
2870
|
+
</Show>
|
|
2871
|
+
</div>
|
|
2872
|
+
)}
|
|
2873
|
+
</Show>
|
|
2874
|
+
)
|
|
2875
|
+
},
|
|
2876
|
+
})
|