@@ -26,13 +26,7 @@ interface MockLanguageModelToolCallPart {
2626interface MockLanguageModelToolResultPart {
2727 type : "tool_result"
2828 callId : string
29- content : ( MockLanguageModelTextPart | MockLanguageModelDataPart ) [ ]
30- }
31-
32- interface MockLanguageModelDataPart {
33- type : "data"
34- data : Uint8Array
35- mimeType : string
29+ content : MockLanguageModelTextPart [ ]
3630}
3731
3832// Mock vscode namespace
@@ -60,32 +54,10 @@ vitest.mock("vscode", () => {
6054 type = "tool_result"
6155 constructor (
6256 public callId : string ,
63- public content : ( MockLanguageModelTextPart | MockLanguageModelDataPart ) [ ] ,
57+ public content : MockLanguageModelTextPart [ ] ,
6458 ) { }
6559 }
6660
67- class MockLanguageModelDataPart {
68- type = "data"
69- constructor (
70- public data : Uint8Array ,
71- public mimeType : string ,
72- ) { }
73-
74- static image ( data : Uint8Array , mime : string ) {
75- return new MockLanguageModelDataPart ( data , mime )
76- }
77-
78- static json ( value : any , mime ?: string ) {
79- const bytes = new TextEncoder ( ) . encode ( JSON . stringify ( value ) )
80- return new MockLanguageModelDataPart ( bytes , mime || "application/json" )
81- }
82-
83- static text ( value : string , mime ?: string ) {
84- const bytes = new TextEncoder ( ) . encode ( value )
85- return new MockLanguageModelDataPart ( bytes , mime || "text/plain" )
86- }
87- }
88-
8961 return {
9062 LanguageModelChatMessage : {
9163 Assistant : vitest . fn ( ( content ) => ( {
@@ -103,7 +75,6 @@ vitest.mock("vscode", () => {
10375 LanguageModelTextPart : MockLanguageModelTextPart ,
10476 LanguageModelToolCallPart : MockLanguageModelToolCallPart ,
10577 LanguageModelToolResultPart : MockLanguageModelToolResultPart ,
106- LanguageModelDataPart : MockLanguageModelDataPart ,
10778 }
10879} )
10980
@@ -179,7 +150,7 @@ describe("convertToVsCodeLmMessages", () => {
179150 expect ( toolCall . type ) . toBe ( "tool_call" )
180151 } )
181152
182- it ( "should convert image blocks to LanguageModelDataPart " , ( ) => {
153+ it ( "should handle image blocks with appropriate placeholders " , ( ) => {
183154 const messages : Anthropic . Messages . MessageParam [ ] = [
184155 {
185156 role : "user" ,
@@ -190,7 +161,7 @@ describe("convertToVsCodeLmMessages", () => {
190161 source : {
191162 type : "base64" ,
192163 media_type : "image/png" ,
193- data : "dGVzdA==" , // "test" in base64
164+ data : "base64data" ,
194165 } ,
195166 } ,
196167 ] ,
@@ -200,123 +171,8 @@ describe("convertToVsCodeLmMessages", () => {
200171 const result = convertToVsCodeLmMessages ( messages )
201172
202173 expect ( result ) . toHaveLength ( 1 )
203- expect ( result [ 0 ] . content ) . toHaveLength ( 2 )
204-
205- // First part should be text
206- const textPart = result [ 0 ] . content [ 0 ] as MockLanguageModelTextPart
207- expect ( textPart . type ) . toBe ( "text" )
208- expect ( textPart . value ) . toBe ( "Look at this:" )
209-
210- // Second part should be a LanguageModelDataPart for the image
211- const imagePart = result [ 0 ] . content [ 1 ] as unknown as MockLanguageModelDataPart
212- expect ( imagePart . type ) . toBe ( "data" )
213- expect ( imagePart . mimeType ) . toBe ( "image/png" )
214- expect ( imagePart . data ) . toBeInstanceOf ( Uint8Array )
215- } )
216-
217- it ( "should handle images in tool results" , ( ) => {
218- const messages : Anthropic . Messages . MessageParam [ ] = [
219- {
220- role : "user" ,
221- content : [
222- {
223- type : "tool_result" ,
224- tool_use_id : "tool-1" ,
225- content : [
226- { type : "text" , text : "Screenshot result:" } ,
227- {
228- type : "image" ,
229- source : {
230- type : "base64" ,
231- media_type : "image/jpeg" ,
232- data : "dGVzdA==" ,
233- } ,
234- } ,
235- ] ,
236- } ,
237- ] ,
238- } ,
239- ]
240-
241- const result = convertToVsCodeLmMessages ( messages )
242-
243- expect ( result ) . toHaveLength ( 1 )
244- expect ( result [ 0 ] . content ) . toHaveLength ( 1 )
245-
246- const toolResult = result [ 0 ] . content [ 0 ] as MockLanguageModelToolResultPart
247- expect ( toolResult . type ) . toBe ( "tool_result" )
248- expect ( toolResult . content ) . toHaveLength ( 2 )
249-
250- // First item in tool result should be text
251- const textPart = toolResult . content [ 0 ] as MockLanguageModelTextPart
252- expect ( textPart . type ) . toBe ( "text" )
253-
254- // Second item should be image data
255- const imagePart = toolResult . content [ 1 ] as MockLanguageModelDataPart
256- expect ( imagePart . type ) . toBe ( "data" )
257- expect ( imagePart . mimeType ) . toBe ( "image/jpeg" )
258- } )
259-
260- it ( "should return text placeholder for URL-based images" , ( ) => {
261- const messages : Anthropic . Messages . MessageParam [ ] = [
262- {
263- role : "user" ,
264- content : [
265- { type : "text" , text : "Check this image:" } ,
266- {
267- type : "image" ,
268- source : {
269- type : "url" ,
270- url : "https://example.com/image.png" ,
271- } as any ,
272- } ,
273- ] ,
274- } ,
275- ]
276-
277- const result = convertToVsCodeLmMessages ( messages )
278-
279- expect ( result ) . toHaveLength ( 1 )
280- expect ( result [ 0 ] . content ) . toHaveLength ( 2 )
281-
282- // First part should be text
283- const textPart = result [ 0 ] . content [ 0 ] as MockLanguageModelTextPart
284- expect ( textPart . type ) . toBe ( "text" )
285- expect ( textPart . value ) . toBe ( "Check this image:" )
286-
287- // Second part should be a text placeholder (not an empty DataPart)
288174 const imagePlaceholder = result [ 0 ] . content [ 1 ] as MockLanguageModelTextPart
289- expect ( imagePlaceholder . type ) . toBe ( "text" )
290- expect ( imagePlaceholder . value ) . toContain ( "URL not supported" )
291- expect ( imagePlaceholder . value ) . toContain ( "https://example.com/image.png" )
292- } )
293-
294- it ( "should return text placeholder for unknown image source types" , ( ) => {
295- const messages : Anthropic . Messages . MessageParam [ ] = [
296- {
297- role : "user" ,
298- content : [
299- {
300- type : "image" ,
301- source : {
302- type : "unknown" ,
303- media_type : "image/png" ,
304- data : "" , // Required by type but ignored for unknown source types
305- } as any ,
306- } ,
307- ] ,
308- } ,
309- ]
310-
311- const result = convertToVsCodeLmMessages ( messages )
312-
313- expect ( result ) . toHaveLength ( 1 )
314- expect ( result [ 0 ] . content ) . toHaveLength ( 1 )
315-
316- // Should return a text placeholder for unknown source types
317- const placeholder = result [ 0 ] . content [ 0 ] as MockLanguageModelTextPart
318- expect ( placeholder . type ) . toBe ( "text" )
319- expect ( placeholder . value ) . toContain ( "unsupported source type" )
175+ expect ( imagePlaceholder . value ) . toContain ( "[Image (base64): image/png not supported by VSCode LM API]" )
320176 } )
321177} )
322178
0 commit comments