@@ -18,6 +18,7 @@ import {
1818} from "@t3tools/contracts" ;
1919import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime" ;
2020import { htmlRenderFromToolItem } from "@t3tools/shared/toolOutput" ;
21+ import * as Cause from "effect/Cause" ;
2122import * as DateTime from "effect/DateTime" ;
2223import * as Deferred from "effect/Deferred" ;
2324import * as Effect from "effect/Effect" ;
@@ -38,8 +39,11 @@ import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSession
3839import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator" ;
3940import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions" ;
4041import {
42+ ProviderAdapterTurnStartError ,
4143 type ProviderAdapterV2Error ,
4244 type ProviderAdapterV2Event ,
45+ type ProviderAdapterV2TurnInput ,
46+ ProviderCompactionUnsupportedError ,
4347 ProviderAdapterV2RuntimePolicy ,
4448} from "@t3tools/provider-core/server/ProviderAdapter" ;
4549import {
@@ -316,6 +320,8 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: {
316320 model : string ,
317321 options ?: ModelSelection [ "options" ] ,
318322 ) => Effect . Effect < void , ProviderAdapterV2Error > ;
323+ /** Runs T3's compact action as turn `ordinal`. */
324+ readonly compact : ( ordinal : number ) => Effect . Effect < void , ProviderAdapterV2Error > ;
319325 readonly interrupt : (
320326 providerTurnId : ProviderTurnId ,
321327 ) => Effect . Effect < void , ProviderAdapterV2Error > ;
@@ -390,10 +396,15 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: {
390396 } ) ;
391397 const providerThread = yield * session . ensureThread ( { threadId, modelSelection, runtimePolicy } ) ;
392398 const now = yield * DateTime . now ;
393- const startTurnOn = ( ordinal : number , model : string , options ?: ModelSelection [ "options" ] ) => {
399+ const turnInput = (
400+ ordinal : number ,
401+ model : string ,
402+ options ?: ModelSelection [ "options" ] ,
403+ text = "Say hello" ,
404+ ) : ProviderAdapterV2TurnInput => {
394405 const suffix = `${ threadId } :${ ordinal } ` ;
395406 const turnSelection = { instanceId, model, ...( options === undefined ? { } : { options } ) } ;
396- return session . startTurn ( {
407+ return {
397408 appThread : {
398409 createdBy : "user" ,
399410 creationSource : "web" ,
@@ -428,17 +439,26 @@ const runKiroScript = Effect.fn("runKiroScript")(function* (input: {
428439 createdBy : "user" ,
429440 creationSource : "web" ,
430441 messageId : MessageId . make ( `message:${ suffix } ` ) ,
431- text : "Say hello" ,
442+ text,
432443 attachments : [ ] ,
433444 } ,
434445 modelSelection : turnSelection ,
435446 runtimePolicy,
436- } ) ;
447+ } ;
437448 } ;
449+ const startTurnOn = ( ordinal : number , model : string , options ?: ModelSelection [ "options" ] ) =>
450+ session . startTurn ( turnInput ( ordinal , model , options ) ) ;
451+ const compact = ( ordinal : number ) =>
452+ session . compactThread === undefined
453+ ? Effect . die ( "Kiro adapter does not offer compactThread" )
454+ : session . compactThread (
455+ turnInput ( ordinal , modelSelection . model , input . options , "/compact" ) ,
456+ ) ;
438457 yield * input . drive ( {
439458 events : session . events ,
440459 startTurn : startTurnOn ( 1 , modelSelection . model , input . options ) ,
441460 startTurnOn,
461+ compact,
442462 interrupt : ( providerTurnId ) => session . interruptTurn ( { providerThread, providerTurnId } ) ,
443463 respond : ( requestId , decision ) => session . respondToRuntimeRequest ( { requestId, decision } ) ,
444464 } ) ;
@@ -460,7 +480,7 @@ const terminalStatus = (events: ReadonlyArray<ProviderAdapterV2Event>) => {
460480} ;
461481
462482describe ( "KiroAdapterV2" , ( ) => {
463- it . effect ( "opens a session on a deployment that advertises no Kiro extensions" , ( ) =>
483+ it . effect ( "opens a session and refuses compaction on a deployment with no Kiro extensions" , ( ) =>
464484 runKiroScript ( {
465485 scenario : "no-extensions" ,
466486 frames : [
@@ -476,10 +496,18 @@ describe("KiroAdapterV2", () => {
476496 } ) ,
477497 answer ( "session/prompt" , { stopReason : "end_turn" } ) ,
478498 ] ,
479- drive : ( { events, startTurn } ) =>
499+ drive : ( { events, startTurn, compact } ) =>
480500 Effect . gen ( function * ( ) {
481501 yield * startTurn ;
482502 assert . equal ( terminalStatus ( yield * collectTurn ( events ) ) , "completed" ) ;
503+ // `_kiro/session/compact` is not advertised, so T3 must not send it.
504+ const compacted = yield * Effect . exit ( compact ( 2 ) ) ;
505+ const error = Exit . isFailure ( compacted ) ? Cause . squash ( compacted . cause ) : undefined ;
506+ assert . instanceOf ( error , ProviderAdapterTurnStartError ) ;
507+ assert . instanceOf (
508+ ( error as ProviderAdapterTurnStartError ) . cause ,
509+ ProviderCompactionUnsupportedError ,
510+ ) ;
483511 } ) ,
484512 } ) . pipe ( Effect . provide ( testLayer ) , Effect . scoped ) ,
485513 ) ;
0 commit comments