@@ -2,6 +2,7 @@ import { assert, describe, it } from "@effect/vitest";
22import * as NodeServices from "@effect/platform-node/NodeServices" ;
33import {
44 CheckpointId ,
5+ ChatAttachmentId ,
56 EnvironmentId ,
67 NodeId ,
78 ProviderInstanceId ,
@@ -22,6 +23,7 @@ import * as DateTime from "effect/DateTime";
2223import * as Duration from "effect/Duration" ;
2324import * as Effect from "effect/Effect" ;
2425import * as Fiber from "effect/Fiber" ;
26+ import * as FileSystem from "effect/FileSystem" ;
2527import * as Layer from "effect/Layer" ;
2628import * as PlatformError from "effect/PlatformError" ;
2729import * as Queue from "effect/Queue" ;
@@ -37,6 +39,7 @@ import * as ProviderContinuationRequests from "@t3tools/provider-core/server/Pro
3739import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions" ;
3840import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator" ;
3941import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter" ;
42+ import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost" ;
4043import { handoffBudget } from "@t3tools/provider-core/server/handoffBudget" ;
4144import * as HostProcess from "@t3tools/shared/HostProcess" ;
4245import { toolOutputImages , compactDynamicToolOutput } from "@t3tools/shared/toolOutput" ;
@@ -490,6 +493,92 @@ const expectModelFailure = (errorMessage: string) =>
490493 } ) . pipe ( Effect . scoped , Effect . provide ( layerTest ) ) ;
491494
492495describe ( "PiAdapterV2" , ( ) => {
496+ it . effect ( "keeps native image bytes and the saved path in the prompt" , ( ) =>
497+ Effect . gen ( function * ( ) {
498+ const host = yield * ProviderHost . ProviderHost ;
499+ const fileSystem = yield * FileSystem . FileSystem ;
500+ const attachment : ChatAttachment = {
501+ id : ChatAttachmentId . make ( "image" ) ,
502+ type : "image" ,
503+ name : "image.png" ,
504+ mimeType : "image/png" ,
505+ sizeBytes : 3 ,
506+ } ;
507+ const path = host . resolveAttachmentPath ( attachment ) ! ;
508+ yield * fileSystem . writeFile ( path , new Uint8Array ( [ 1 , 2 , 3 ] ) ) ;
509+ const fake = yield * makeFakePi ;
510+ const { runtime } = yield * openRuntime ( fake ) ;
511+ const providerThread = yield * runtime . ensureThread ( {
512+ threadId : THREAD_ID ,
513+ modelSelection : modelSelection ( "default" ) ,
514+ runtimePolicy,
515+ } ) ;
516+ yield * startTurn ( runtime , providerThread , "default" , [ attachment ] ) ;
517+ const prompt = yield * fake . takeRequest ( "prompt" ) ;
518+ assert . include ( String ( prompt [ "message" ] ) , path ) ;
519+ assert . deepEqual ( prompt [ "images" ] , [ { type : "image" , data : "AQID" , mimeType : "image/png" } ] ) ;
520+ } ) . pipe ( Effect . scoped , Effect . provide ( layerTest ) ) ,
521+ ) ;
522+
523+ it . effect ( "lists unavailable attachments alongside resolvable files in the native prompt" , ( ) =>
524+ Effect . gen ( function * ( ) {
525+ const host = yield * ProviderHost . ProviderHost ;
526+ const fake = yield * makeFakePi ;
527+ const { runtime } = yield * openRuntime ( fake ) . pipe (
528+ Effect . provideService ( ProviderHost . ProviderHost , {
529+ ...host ,
530+ resolveAttachmentPath : ( attachment ) =>
531+ attachment . id === "available" ? host . resolveAttachmentPath ( attachment ) : null ,
532+ } ) ,
533+ ) ;
534+ const providerThread = yield * runtime . ensureThread ( {
535+ threadId : THREAD_ID ,
536+ modelSelection : modelSelection ( "default" ) ,
537+ runtimePolicy,
538+ } ) ;
539+ const attachments : ReadonlyArray < ChatAttachment > = [
540+ {
541+ id : ChatAttachmentId . make ( "available" ) ,
542+ type : "file" ,
543+ name : "notes.txt" ,
544+ mimeType : "text/plain" ,
545+ sizeBytes : 1 ,
546+ } ,
547+ {
548+ id : ChatAttachmentId . make ( "missing-file" ) ,
549+ type : "file" ,
550+ name : "missing.txt" ,
551+ mimeType : "text/plain" ,
552+ sizeBytes : 1 ,
553+ } ,
554+ {
555+ id : ChatAttachmentId . make ( "missing-image" ) ,
556+ type : "image" ,
557+ name : "missing.png" ,
558+ mimeType : "image/png" ,
559+ sizeBytes : 1 ,
560+ } ,
561+ {
562+ id : ChatAttachmentId . make ( "missing-future" ) ,
563+ type : "future" ,
564+ name : "future.bin" ,
565+ mimeType : "application/octet-stream" ,
566+ sizeBytes : 1 ,
567+ } ,
568+ ] ;
569+ yield * startTurn ( runtime , providerThread , "default" , attachments ) ;
570+ const prompt = yield * fake . takeRequest ( "prompt" ) ;
571+ assert . isString ( prompt [ "message" ] ) ;
572+ const message = String ( prompt [ "message" ] ) ;
573+ assert . include ( message , host . resolveAttachmentPath ( attachments [ 0 ] ! ) ! ) ;
574+ for ( const attachment of attachments . slice ( 1 ) ) {
575+ assert . include ( message , attachment . name ) ;
576+ assert . include ( message , attachment . id ) ;
577+ }
578+ assert . equal ( ( message . match ( / u n a v a i l a b l e / g) ?? [ ] ) . length , 3 ) ;
579+ } ) . pipe ( Effect . scoped , Effect . provide ( layerTest ) ) ,
580+ ) ;
581+
493582 it . effect . each ( [ false , true ] ) (
494583 "completes a resumed user turn before native wake events arrive, Pi streaming=%s" ,
495584 ( streaming ) =>
0 commit comments