Spaces:
Running
Running
File size: 9,550 Bytes
bc7e9cd db9635c bc7e9cd db9635c bc7e9cd db9635c bc7e9cd db9635c bc7e9cd db9635c bc7e9cd db9635c bc7e9cd db9635c bc7e9cd db9635c bc7e9cd db9635c bc7e9cd db9635c bc7e9cd db9635c bc7e9cd db9635c bc7e9cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
<script lang="ts">
import { slide } from "svelte/transition";
import { onMount } from "svelte";
import gsap from "gsap";
import type { MessageSegment } from "../../../models/chat-data";
export let invocation: MessageSegment | null = null;
export let result: MessageSegment | null = null;
let isExpanded = false;
let blockRef: HTMLDivElement;
let progressRef: HTMLDivElement;
let iconRef: HTMLSpanElement;
$: segment = result || invocation;
$: isRunning = segment?.streaming || segment?.toolStatus === "running";
$: isError = segment?.toolError || segment?.toolStatus === "error";
$: hasOutput = result?.toolOutput || result?.content;
$: isSuccess = !isRunning && !isError && hasOutput;
$: if (isError && !isExpanded) {
isExpanded = true;
}
$: if (isSuccess && iconRef) {
gsap.fromTo(iconRef,
{ scale: 1, rotation: 0 },
{
scale: 1.2,
rotation: 360,
duration: 0.6,
ease: "elastic.out(1, 0.5)",
onComplete: () => {
gsap.to(iconRef, { scale: 1, duration: 0.2 });
}
}
);
}
onMount(() => {
if (blockRef) {
gsap.fromTo(blockRef,
{ opacity: 0, x: -10 },
{ opacity: 1, x: 0, duration: 0.3, ease: "power2.out" }
);
}
if (isRunning && progressRef) {
gsap.fromTo(progressRef,
{ scaleX: 0 },
{ scaleX: 1, duration: 3, ease: "power1.inOut" }
);
}
});
function toggleExpanded() {
isExpanded = !isExpanded;
if (blockRef) {
gsap.to(blockRef, {
backgroundColor: isExpanded ? "rgba(255, 255, 255, 0.02)" : "rgba(255, 255, 255, 0.01)",
duration: 0.2
});
}
}
function getToolIcon(): string {
const name = invocation?.toolName || result?.toolName || "";
const lowerName = name.toLowerCase();
// Editor tools
if (lowerName === "read_editor" || lowerName === "read_editor_lines") return "π";
if (lowerName === "write_editor") return "πΎ";
if (lowerName === "edit_editor") return "βοΈ";
if (lowerName === "search_editor") return "π";
// Task management
if (lowerName === "plan_tasks") return "π";
if (lowerName === "update_task") return "β
";
if (lowerName === "view_tasks") return "ποΈ";
// Documentation/library tools
if (lowerName === "resolve_library_id") return "π";
if (lowerName === "get_library_docs") return "π";
// Console observation
if (lowerName === "observe_console") return "π₯οΈ";
// Generic fallbacks
if (lowerName.includes("read")) return "π";
if (lowerName.includes("write") || lowerName.includes("edit")) return "βοΈ";
if (lowerName.includes("search")) return "π";
if (lowerName.includes("task")) return "β
";
return "π§";
}
function getToolColor(): string {
const name = invocation?.toolName || result?.toolName || "";
const lowerName = name.toLowerCase();
// Editor tools
if (lowerName === "read_editor" || lowerName === "read_editor_lines") return "rgba(100, 149, 237, 0.08)"; // Cornflower blue
if (lowerName === "write_editor") return "rgba(255, 165, 0, 0.08)"; // Orange
if (lowerName === "edit_editor") return "rgba(255, 215, 0, 0.08)"; // Gold
if (lowerName === "search_editor") return "rgba(147, 112, 219, 0.08)"; // Medium purple
// Task management
if (lowerName.includes("task")) return "rgba(76, 175, 80, 0.08)"; // Green
// Documentation
if (lowerName.includes("library") || lowerName.includes("docs")) return "rgba(70, 130, 180, 0.08)"; // Steel blue
// Console
if (lowerName === "observe_console") return "rgba(96, 125, 139, 0.08)"; // Blue grey
return "rgba(255, 255, 255, 0.03)";
}
function getToolName(): string {
const name = invocation?.toolName || result?.toolName || "Tool";
return name.replace(/_/g, " ");
}
function getStatusText(): string {
if (isRunning) return "Running...";
if (isError) return "Error";
if (result?.endTime && result?.startTime) {
const duration = result.endTime - result.startTime;
if (duration < 1000) return `${duration}ms`;
return `${(duration / 1000).toFixed(1)}s`;
}
return "";
}
function formatArgs(args: any): string {
if (!args) return "";
return JSON.stringify(args, null, 2);
}
</script>
<div class="tool-block" class:error={isError} class:success={isSuccess} bind:this={blockRef} style="background: {getToolColor()}">
{#if isRunning}
<div class="progress-bar" bind:this={progressRef}></div>
{/if}
<button
class="tool-header"
on:click={toggleExpanded}
class:expanded={isExpanded}
>
<span class="tool-icon" bind:this={iconRef}>{getToolIcon()}</span>
<span class="tool-name">{getToolName()}</span>
{#if isRunning}
<span class="status running">
<span class="pulse-dot">β</span>
{getStatusText()}
</span>
{:else if isError}
<span class="status error">β {getStatusText()}</span>
{:else if hasOutput}
<span class="status completed">β {getStatusText()}</span>
{/if}
<span class="expand-icon" class:expanded={isExpanded}>βΆ</span>
</button>
{#if isExpanded}
<div class="tool-content" transition:slide={{ duration: 200 }}>
{#if invocation?.toolArgs}
<div class="section args">
<div class="label">Arguments</div>
<pre>{formatArgs(invocation.toolArgs)}</pre>
</div>
{/if}
{#if isRunning && result?.content}
<div class="section output streaming">
<div class="label">Output</div>
<pre>{result.content}<span class="cursor">β</span></pre>
</div>
{:else if result?.toolError}
<div class="section error">
<div class="label">Error</div>
<pre>{result.toolError}</pre>
</div>
{:else if result?.toolOutput || result?.content}
<div class="section output">
<div class="label">Output</div>
<pre>{result.toolOutput || result.content}</pre>
</div>
{/if}
</div>
{/if}
</div>
<style>
.tool-block {
margin: 0.125rem 0;
border: 1px solid rgba(255, 255, 255, 0.05);
border-radius: 4px;
background: rgba(255, 255, 255, 0.01);
overflow: hidden;
position: relative;
transition: all 0.3s ease;
}
.tool-block.error {
border-color: rgba(244, 67, 54, 0.2);
animation: errorShake 0.3s ease-in-out;
}
.tool-block.success {
border-color: rgba(76, 175, 80, 0.15);
}
@keyframes errorShake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-2px); }
75% { transform: translateX(2px); }
}
.progress-bar {
position: absolute;
top: 0;
left: 0;
height: 2px;
width: 100%;
background: linear-gradient(90deg,
rgba(33, 150, 243, 0.8),
rgba(100, 181, 246, 1),
rgba(33, 150, 243, 0.8));
transform-origin: left;
animation: shimmer 2s ease-in-out infinite;
}
@keyframes shimmer {
0%, 100% { opacity: 0.6; }
50% { opacity: 1; }
}
.tool-header {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.375rem 0.5rem;
width: 100%;
background: transparent;
border: none;
color: inherit;
font: inherit;
text-align: left;
cursor: pointer;
transition: background 0.15s ease;
}
.tool-header:hover {
background: rgba(255, 255, 255, 0.02);
}
.tool-icon {
font-size: 1rem;
margin-right: 0.25rem;
display: inline-block;
}
.tool-name {
flex: 1;
font-size: 0.8rem;
color: rgba(255, 255, 255, 0.7);
text-transform: capitalize;
}
.status {
font-size: 0.75rem;
padding: 0.125rem 0.375rem;
border-radius: 3px;
background: rgba(255, 255, 255, 0.05);
color: rgba(255, 255, 255, 0.6);
}
.status.running {
background: rgba(33, 150, 243, 0.1);
color: rgba(33, 150, 243, 0.9);
}
.status.error {
background: rgba(244, 67, 54, 0.1);
color: rgba(244, 67, 54, 0.9);
}
.status.completed {
background: rgba(76, 175, 80, 0.1);
color: rgba(76, 175, 80, 0.9);
}
.pulse-dot {
display: inline-block;
animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% {
opacity: 0.3;
}
50% {
opacity: 1;
}
}
.expand-icon {
font-size: 0.6rem;
color: rgba(255, 255, 255, 0.3);
transition: transform 0.15s ease;
}
.expand-icon.expanded {
transform: rotate(90deg);
}
.tool-content {
border-top: 1px solid rgba(255, 255, 255, 0.05);
background: rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.section {
padding: 0.5rem;
}
.section + .section {
border-top: 1px solid rgba(255, 255, 255, 0.03);
}
.label {
font-size: 0.7rem;
color: rgba(255, 255, 255, 0.4);
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 0.25rem;
}
pre {
margin: 0;
font-family: "Monaco", "Menlo", "Consolas", monospace;
font-size: 0.75rem;
line-height: 1.4;
color: rgba(255, 255, 255, 0.8);
white-space: pre-wrap;
word-wrap: break-word;
}
.section.args pre {
color: rgba(255, 255, 255, 0.6);
}
.section.error pre {
color: rgba(244, 67, 54, 0.9);
}
.cursor {
display: inline-block;
color: rgba(65, 105, 225, 0.6);
animation: blink 1s infinite;
}
@keyframes blink {
0%, 50% {
opacity: 1;
}
51%, 100% {
opacity: 0;
}
}
</style> |