@@ -11,6 +11,7 @@ import {
1111 ThreadId ,
1212} from "@t3tools/contracts" ;
1313import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime" ;
14+ import { htmlRenderFromToolItem } from "@t3tools/shared/toolOutput" ;
1415import * as Crypto from "effect/Crypto" ;
1516import * as DateTime from "effect/DateTime" ;
1617import * as Effect from "effect/Effect" ;
@@ -518,3 +519,202 @@ describe("AntigravityAdapterV2 client file system under restrictive policies", (
518519 } ) . pipe ( Effect . provide ( layerSession ) , Effect . scoped ) ,
519520 ) ;
520521} ) ;
522+
523+ describe ( "AntigravityAdapterV2 html_render pages" , ( ) => {
524+ it . effect ( "shows the page html_render published when the agent reports only a summary" , ( ) =>
525+ Effect . gen ( function * ( ) {
526+ const childProcessSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
527+ const path = yield * Path . Path ;
528+ const crypto = yield * Crypto . Crypto ;
529+ const mcpSessions = yield * McpProviderSessions . McpProviderSessions ;
530+ const mockAgentPath = yield * path . fromFileUrl (
531+ new URL ( "../../../scripts/acp-mock-agent.ts" , import . meta. url ) ,
532+ ) ;
533+ type RuntimeService = AcpSessionRuntime . AcpSessionRuntime [ "Service" ] ;
534+ let sessionUpdate : Parameters < RuntimeService [ "handleSessionUpdate" ] > [ 0 ] | undefined ;
535+ const instanceId = ProviderInstanceId . make ( "antigravity-html-render-test" ) ;
536+ const threadId = ThreadId . make ( "thread-antigravity-html-render" ) ;
537+ const page = ( name : string ) => ( {
538+ attachmentId : `${ threadId } -${ name } -html` ,
539+ title : "Revenue" ,
540+ height : 240 ,
541+ } ) ;
542+ const revenue = { html : "<p>Revenue</p>" , title : "Revenue" , height : 240 } ;
543+ const adapter = yield * makeAntigravityAdapterV2 ( {
544+ instanceId,
545+ selfInvocation : yield * resolveSelfInvocation ( ) ,
546+ makeRuntime : ( input ) =>
547+ makeAntigravityAcpRuntime ( {
548+ ...input ,
549+ childProcessSpawner,
550+ spawn : {
551+ command : process . execPath ,
552+ args : [ mockAgentPath ] ,
553+ cwd : input . cwd ,
554+ env : { T3_ACP_ANTIGRAVITY : "1" } ,
555+ } ,
556+ } ) . pipe (
557+ Effect . provideService ( Crypto . Crypto , crypto ) ,
558+ Effect . map ( ( runtime ) : RuntimeService => ( {
559+ ...runtime ,
560+ handleSessionUpdate : ( handler ) =>
561+ Effect . sync ( ( ) => {
562+ sessionUpdate = handler ;
563+ } ) . pipe ( Effect . andThen ( runtime . handleSessionUpdate ( handler ) ) ) ,
564+ prompt : ( ) =>
565+ Effect . gen ( function * ( ) {
566+ const send = ( update : EffectAcpSchema . SessionUpdate ) =>
567+ sessionUpdate === undefined
568+ ? Effect . die ( "the adapter must handle session updates" )
569+ : sessionUpdate ( { sessionId : "mock-session-1" , update } ) ;
570+ // agy_acp_server 1.3.0 and 1.4.0 without a permission prompt:
571+ // the title is "Running <tool>", rawInput holds only the
572+ // tool's arguments, and the completion reports the step's
573+ // own summary as rawOutput instead of the MCP result.
574+ const start = ( toolCallId : string , rawInput : typeof revenue ) =>
575+ send ( {
576+ sessionUpdate : "tool_call" ,
577+ toolCallId,
578+ title : "Running html_render" ,
579+ kind : "other" ,
580+ status : "in_progress" ,
581+ rawInput,
582+ } ) ;
583+ yield * start ( "trajectory:1" , revenue ) ;
584+ yield * start ( "trajectory:2" , { ...revenue , title : "Costs" } ) ;
585+ yield * start ( "trajectory:3" , revenue ) ;
586+ // T3's MCP server publishes while each call runs.
587+ yield * mcpSessions . recordHtmlRender ( threadId , revenue , page ( "first" ) ) ;
588+ yield * mcpSessions . recordHtmlRender ( threadId , revenue , page ( "second" ) ) ;
589+ yield * send ( {
590+ sessionUpdate : "tool_call_update" ,
591+ toolCallId : "trajectory:1" ,
592+ status : "completed" ,
593+ rawOutput : "Render revenue chart" ,
594+ } ) ;
595+ // A call with no page published for its arguments stays as reported.
596+ yield * send ( {
597+ sessionUpdate : "tool_call_update" ,
598+ toolCallId : "trajectory:2" ,
599+ status : "completed" ,
600+ rawOutput : "Render costs chart" ,
601+ } ) ;
602+ // A failed call does not claim a page.
603+ yield * send ( {
604+ sessionUpdate : "tool_call_update" ,
605+ toolCallId : "trajectory:3" ,
606+ status : "failed" ,
607+ rawOutput : "MCP call timed out" ,
608+ } ) ;
609+ return { stopReason : "end_turn" as const } ;
610+ } ) ,
611+ } ) ) ,
612+ ) ,
613+ withProcess : ( _stop , task ) => task ,
614+ defaultModel : Effect . succeed ( undefined ) ,
615+ } ) ;
616+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
617+ runtimeMode : "full-access" ,
618+ interactionMode : "default" ,
619+ cwd : process . cwd ( ) ,
620+ } ) ;
621+ const modelSelection = { instanceId, model : "gemini-test-low" } as const ;
622+ const session = yield * adapter . openSession ( {
623+ threadId,
624+ providerSessionId : ProviderSessionId . make ( "provider-session-antigravity-html-render" ) ,
625+ modelSelection,
626+ runtimePolicy,
627+ } ) ;
628+ const providerThread = yield * session . ensureThread ( {
629+ threadId,
630+ modelSelection,
631+ runtimePolicy,
632+ } ) ;
633+ const now = yield * DateTime . now ;
634+ yield * session . startTurn ( {
635+ appThread : {
636+ createdBy : "user" ,
637+ creationSource : "web" ,
638+ id : threadId ,
639+ projectId : ProjectId . make ( "project-antigravity-html-render" ) ,
640+ title : "Antigravity html_render" ,
641+ providerInstanceId : instanceId ,
642+ modelSelection,
643+ runtimeMode : "full-access" ,
644+ interactionMode : "default" ,
645+ branch : null ,
646+ worktreePath : process . cwd ( ) ,
647+ activeProviderThreadId : providerThread . id ,
648+ lineage : { parentThreadId : null , relationshipToParent : null , rootThreadId : threadId } ,
649+ forkedFrom : null ,
650+ createdAt : now ,
651+ updatedAt : now ,
652+ archivedAt : null ,
653+ settledOverride : null ,
654+ settledAt : null ,
655+ lastVisitedAt : null ,
656+ deletedAt : null ,
657+ } ,
658+ threadId,
659+ runId : RunId . make ( "run-antigravity-html-render" ) ,
660+ runOrdinal : 1 ,
661+ providerTurnOrdinal : 1 ,
662+ attemptId : RunAttemptId . make ( "attempt-antigravity-html-render" ) ,
663+ rootNodeId : NodeId . make ( "node-antigravity-html-render" ) ,
664+ providerThread,
665+ message : {
666+ createdBy : "user" ,
667+ creationSource : "web" ,
668+ messageId : MessageId . make ( "message-antigravity-html-render" ) ,
669+ text : "chart the revenue" ,
670+ attachments : [ ] ,
671+ } ,
672+ modelSelection,
673+ runtimePolicy,
674+ } ) ;
675+ const events = yield * session . events . pipe (
676+ Stream . takeUntil ( ( event ) => event . type === "turn.terminal" ) ,
677+ Stream . runCollect ,
678+ ) ;
679+ const finalItem = ( nativeId : string ) =>
680+ Array . from ( events ) . findLast (
681+ ( event ) =>
682+ event . type === "turn_item.updated" &&
683+ event . turnItem . nativeItemRef ?. nativeId === nativeId ,
684+ ) ;
685+ const tool = ( nativeId : string ) => {
686+ const event = finalItem ( nativeId ) ;
687+ const item = event ?. type === "turn_item.updated" ? event . turnItem : undefined ;
688+ return item ?. type === "dynamic_tool"
689+ ? {
690+ status : item . status ,
691+ toolName : item . toolName ,
692+ page : htmlRenderFromToolItem ( item ) ,
693+ output : item . output ,
694+ }
695+ : undefined ;
696+ } ;
697+
698+ assert . deepEqual ( tool ( "trajectory:1" ) , {
699+ status : "completed" ,
700+ toolName : "t3-code.html_render" ,
701+ page : page ( "first" ) ,
702+ output : { htmlRender : page ( "first" ) } ,
703+ } ) ;
704+ assert . deepEqual ( tool ( "trajectory:2" ) , {
705+ status : "completed" ,
706+ toolName : "t3-code.html_render" ,
707+ page : undefined ,
708+ output : "Render costs chart" ,
709+ } ) ;
710+ assert . deepEqual ( tool ( "trajectory:3" ) , {
711+ status : "failed" ,
712+ toolName : "t3-code.html_render" ,
713+ page : undefined ,
714+ output : "MCP call timed out" ,
715+ } ) ;
716+ // Each page goes to one call; the unclaimed one stays for a later call.
717+ assert . deepEqual ( yield * mcpSessions . takeHtmlRender ( threadId , revenue ) , page ( "second" ) ) ;
718+ } ) . pipe ( Effect . provide ( layerSession ) , Effect . scoped ) ,
719+ ) ;
720+ } ) ;
0 commit comments