@@ -21,8 +21,7 @@ import {
2121} from "../../../lib/chat/tool-display.ts" ;
2222import type { SidebarContent } from "./chat-sidebar.ts" ;
2323
24- const TOOL_PREVIEW_MAX_LINES = 2 ;
25- const TOOL_PREVIEW_MAX_CHARS = 100 ;
24+ type FullMessageRequest = NonNullable < SidebarContent [ "fullMessageRequest" ] > ;
2625
2726function formatToolOutputForSidebar ( text : string ) : string {
2827 if ( isMarkdownBlockArtText ( text ) ) {
@@ -40,18 +39,6 @@ function formatToolOutputForSidebar(text: string): string {
4039 return text ;
4140}
4241
43- function getTruncatedPreview ( text : string ) : string {
44- const allLines = text . split ( "\n" ) ;
45- const lines = allLines . slice ( 0 , TOOL_PREVIEW_MAX_LINES ) ;
46- const preview = lines . join ( "\n" ) ;
47- if ( preview . length > TOOL_PREVIEW_MAX_CHARS ) {
48- return `${ preview . slice ( 0 , TOOL_PREVIEW_MAX_CHARS ) } …` ;
49- }
50- return lines . length < allLines . length ? `${ preview } …` : preview ;
51- }
52-
53- type FullMessageRequest = NonNullable < SidebarContent [ "fullMessageRequest" ] > ;
54-
5542function renderToolIcon ( name : string ) {
5643 return icons [ name as IconName ] ?? icons . puzzle ;
5744}
@@ -243,39 +230,22 @@ export function renderRawOutputToggle(text: string) {
243230 < span class ="chat-tool-card__raw-toggle-icon "> ${ icons . chevronDown } </ span >
244231 </ button >
245232 < div class ="chat-tool-card__raw-body " hidden >
246- ${ renderToolDataBlock ( {
247- label : "Tool output" ,
248- text,
249- expanded : true ,
250- } ) }
233+ ${ renderToolDataBlock ( { label : "Tool output" , text } ) }
251234 </ div >
252235 </ div >
253236 ` ;
254237}
255238
256- function renderToolDataBlock ( params : {
257- label : string ;
258- text : string ;
259- expanded : boolean ;
260- empty ?: boolean ;
261- } ) {
262- const { label, text, expanded, empty } = params ;
239+ function renderToolDataBlock ( params : { label : string ; text : string } ) {
240+ const { label, text } = params ;
263241 const codeClass = isMarkdownBlockArtText ( text ) ? "markdown-block-art" : "" ;
264242 return html `
265- < div class ="chat-tool-card__block ${ expanded ? "chat-tool-card__block--expanded" : "" } ">
243+ < div class ="chat-tool-card__block ">
266244 < div class ="chat-tool-card__block-header ">
267245 < span class ="chat-tool-card__block-icon "> ${ icons . zap } </ span >
268246 < span class ="chat-tool-card__block-label "> ${ label } </ span >
269247 </ div >
270- ${ empty
271- ? html `< div class ="chat-tool-card__block-empty muted "> ${ text } </ div > `
272- : expanded
273- ? html `< pre
274- class ="chat-tool-card__block-content "
275- > < code class =${ codeClass } > ${ text } </ code > </ pre > `
276- : html `< div class ="chat-tool-card__block-preview mono ">
277- ${ getTruncatedPreview ( text ) }
278- </ div > ` }
248+ < pre class ="chat-tool-card__block-content "> < code class =${ codeClass } > ${ text } </ code > </ pre >
279249 </ div >
280250 ` ;
281251}
@@ -437,7 +407,7 @@ export function renderExpandedToolCardContent(
437407 : nothing ;
438408
439409 return html `
440- < div class ="chat-tool-card chat-tool-card--expanded ${ isError ? "chat-tool-card--error" : "" } ">
410+ < div class ="chat-tool-card ${ isError ? "chat-tool-card--error" : "" } ">
441411 < div class ="chat-tool-card__header ">
442412 < div class ="chat-tool-card__title ">
443413 < span class ="chat-tool-card__icon "> ${ renderToolIcon ( display . icon ) } </ span >
@@ -470,7 +440,6 @@ export function renderExpandedToolCardContent(
470440 ? renderToolDataBlock ( {
471441 label : "Tool input" ,
472442 text : card . inputText ! ,
473- expanded : true ,
474443 } )
475444 : nothing }
476445 ${ hasOutput
@@ -479,110 +448,8 @@ export function renderExpandedToolCardContent(
479448 : renderToolDataBlock ( {
480449 label : isError ? "Tool error" : "Tool output" ,
481450 text : card . outputText ! ,
482- expanded : true ,
483451 } )
484452 : nothing }
485453 </ div >
486454 ` ;
487455}
488-
489- export function renderToolCardSidebar (
490- card : ToolCard ,
491- onOpenSidebar ?: ( content : SidebarContent ) => void ,
492- canvasPluginSurfaceUrl ?: string | null ,
493- embedSandboxMode : EmbedSandboxMode = "scripts" ,
494- options ?: { sessionKey ?: string ; agentId ?: string } ,
495- ) {
496- const display = resolveToolDisplay ( { name : card . name , args : card . args } ) ;
497- const detail = formatToolDetail ( display ) ;
498- const preview = card . preview ;
499- const hasText = Boolean ( card . outputText ?. trim ( ) ) ;
500- const hasPreview = Boolean ( preview ) ;
501- const isError = isToolCardError ( card ) ;
502- const fullMessageRequest = buildToolSidebarFullMessageRequest ( card , options ?. sessionKey ) ;
503- const sidebarContent =
504- preview ?. kind === "canvas"
505- ? buildPreviewSidebarContent ( preview , card . outputText , { fullMessageRequest } )
506- : buildSidebarContent ( buildToolCardSidebarContent ( card ) , {
507- fullMessageRequest,
508- rawText : card . outputText ?? null ,
509- } ) ;
510- const actionContent =
511- sidebarContent ??
512- buildSidebarContent ( buildToolCardSidebarContent ( card ) , {
513- fullMessageRequest,
514- rawText : card . outputText ?? null ,
515- } ) ;
516- const canClick = Boolean ( onOpenSidebar ) ;
517- const handleClick = canClick ? ( ) => onOpenSidebar ?.( actionContent ) : undefined ;
518- const isShort = hasText && ! hasPreview && ( card . outputText ?. length ?? 0 ) <= 240 ;
519- const showCollapsed = hasText && ! hasPreview && ! isShort ;
520- const showInline = hasText && ! hasPreview && isShort ;
521- const isEmpty = ! hasText && ! hasPreview ;
522- const statusIcon = isError ? icons . x : icons . check ;
523-
524- return html `
525- < div
526- class ="chat-tool-card ${ canClick ? "chat-tool-card--clickable" : "" } ${ isError
527- ? "chat-tool-card--error"
528- : "" } "
529- @click =${ handleClick }
530- role =${ canClick ? "button" : nothing }
531- tabindex=${ canClick ? "0" : nothing }
532- @keydown=${ canClick
533- ? ( e : KeyboardEvent ) => {
534- if ( e . key !== "Enter" && e . key !== " " ) {
535- return ;
536- }
537- e . preventDefault ( ) ;
538- handleClick ?.( ) ;
539- }
540- : nothing }
541- >
542- < div class ="chat-tool-card__header ">
543- < div class ="chat-tool-card__title ">
544- < span class ="chat-tool-card__icon "> ${ renderToolIcon ( display . icon ) } </ span >
545- < span > ${ display . label } </ span >
546- </ div >
547- ${ canClick
548- ? html `< span
549- class ="chat-tool-card__action ${ isError ? "chat-tool-card__action--error" : "" } "
550- > ${ isError ? "View error" : hasText || hasPreview ? "View" : "" } ${ statusIcon } </ span
551- > `
552- : nothing }
553- ${ isEmpty && ! canClick
554- ? html `< span
555- class ="chat-tool-card__status ${ isError ? "chat-tool-card__status--error" : "" } "
556- > ${ statusIcon } </ span
557- > `
558- : nothing }
559- </ div >
560- ${ detail ? html `< div class ="chat-tool-card__detail "> ${ detail } </ div > ` : nothing }
561- ${ isEmpty
562- ? html `< div
563- class ="chat-tool-card__status-text ${ isError
564- ? "chat-tool-card__status-text--error"
565- : "muted" } "
566- >
567- ${ isError ? "Failed" : "Completed" }
568- </ div > `
569- : nothing }
570- ${ preview
571- ? html `${ renderToolPreview ( preview , "chat_tool" , {
572- onOpenSidebar,
573- rawText : card . outputText ,
574- canvasPluginSurfaceUrl,
575- embedSandboxMode,
576- } ) } `
577- : nothing }
578- ${ showCollapsed
579- ? html `< div class ="chat-tool-card__preview mono ">
580- ${ getTruncatedPreview ( card . outputText ! ) }
581- </ div > `
582- : nothing }
583- ${ showInline
584- ? html `< div class ="chat-tool-card__inline mono "> ${ card . outputText } </ div > `
585- : nothing }
586- </ div >
587- ` ;
588- }
0 commit comments