ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / workbench / contrib / chat / test / common / chatImageExtraction.test.ts 516 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
import assert from 'assert' ;
import { VSBuffer } from '../../../../../base/common/buffer.js' ;
import { isMarkdownString } from '../../../../../base/common/htmlContent.js' ;
import { URI } from '../../../../../base/common/uri.js' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js' ;
import { IChatRequestVariableEntry, IImageVariableEntry } from '../../common/attachments/chatVariableEntries.js' ;
import { IChatProgressResponseContent } from '../../common/model/chatModel.js' ;
import { IChatRequestViewModel IChatResponseViewModel
IChatContentInlineReference IChatToolInvocationSerialized IToolResultOutputDetailsSerialized
IToolResultInputOutputDetails
extractImagesFromChatRequest extractImagesFromChatResponse extractImagesFromToolInvocationMessages
overrides Partial IChatToolInvocationSerialized IChatToolInvocationSerialized
kind
toolCallId
toolId
invocationMessage
originMessage
pastTenseMessage
isConfirmed
isComplete
source
presentation
resultDetails
overrides
uri name IChatContentInlineReference
kind
inlineReference uri
name
items ReadonlyArray IChatProgressResponseContent opts
sessionResource
requestId
id
requestMessageText
requestVariables IChatRequestVariableEntry
noMatchingRequest
IChatResponseViewModel
sessionResource opts sessionResource
requestId opts requestId
responseId opts id
requestMessageText opts requestMessageText
id responseId
requestId
sessionResource
response value items
session
opts noMatchingRequest
id requestId
messageText requestMessageText
message parts text requestMessageText
variables opts requestVariables
IChatResponseViewModel
uri VSBuffer
variables IChatRequestViewModel opts id messageText IChatRequestViewModel
id opts id
sessionResource
dataId
username
message text opts messageText parts
messageText opts messageText
attempt
variables
currentRenderedHeight
shouldBeRemovedOnSend
isComplete
isCompleteAddedRequest
slashCommand
agentOrSlashCommandDetected
shouldBeBlocked
timestamp
IChatRequestViewModel
overrides Partial IImageVariableEntry Pick IImageVariableEntry IImageVariableEntry
value rest overrides
id
kind
name
value
mimeType
rest
response
result response fakeReadFile
assert result
id response sessionResource response id
title
images
response noMatchingRequest
result response fakeReadFile
assert result title
image value VSBuffer buffer
response requestMessageText requestVariables image
result response fakeReadFile
assert result title
resultDetails IToolResultOutputDetailsSerialized
output type mimeType base64Data
toolInvocation
toolCallId
toolId
pastTenseMessage
resultDetails
response toolInvocation
result response fakeReadFile
assert result images length
assert result images id
assert result images mimeType
assert result images source
assert result images caption
resultDetails IToolResultInputOutputDetails
input
output
type mimeType value isText
type mimeType value isText
type mimeType value isText
toolInvocation
toolCallId
toolId
pastTenseMessage
resultDetails
response toolInvocation
result response fakeReadFile
assert result images length
assert result images id
assert result images mimeType
assert result images id
assert result images mimeType
resultDetails IToolResultOutputDetailsSerialized
output type mimeType base64Data
toolInvocation resultDetails
response toolInvocation
result response fakeReadFile
assert result images length
imageUri
inlineRef imageUri
response inlineRef
result response fakeReadFile
assert result images length
assert result images uri imageUri
assert result images name
assert result images mimeType
assert result images source
imageUri
inlineRef IChatContentInlineReference
kind
inlineReference uri imageUri range startLineNumber startColumn endLineNumber endColumn
response inlineRef
result response fakeReadFile
assert result images length
assert result images uri imageUri
codeUri
inlineRef codeUri
response inlineRef
result response fakeReadFile
assert result images length
imageUri
inlineRef imageUri
response inlineRef
result response fakeReadFile
assert result images length
assert result images name
toolInvocation
toolCallId
toolId
resultDetails
output type mimeType base64Data
satisfies IToolResultOutputDetailsSerialized
inlineRef
toolInvocation2
toolCallId
toolId
resultDetails
output type mimeType base64Data
satisfies IToolResultOutputDetailsSerialized
response toolInvocation inlineRef toolInvocation2
result response fakeReadFile
assert result images length
assert result images id
assert result images name
assert result images id
sessionResource
response sessionResource id
result response fakeReadFile
assert result id sessionResource
imageUri
inlineRef imageUri
_uri
response inlineRef
result response failingReadFile
assert result images length
imageUri
toolInvocation
toolCallId
toolId
pastTenseMessage value isTrusted uris imageUri
response toolInvocation
result response fakeReadFile
assert result images length
assert result images uri imageUri
assert result images name
assert result images mimeType
caption result images caption
assert caption
assert caption value
imageUri
resultDetails IToolResultOutputDetailsSerialized
output type mimeType base64Data
toolInvocation
toolCallId
toolId
pastTenseMessage value isTrusted uris imageUri
resultDetails
response toolInvocation
result response fakeReadFile
assert result images length
assert result images id
assert result images uri imageUri
toolInvocation
pastTenseMessage
invocationMessage
result toolInvocation fakeReadFile
assert result
toolInvocation
pastTenseMessage
result toolInvocation fakeReadFile
assert result
toolInvocation
pastTenseMessage value isTrusted
result toolInvocation fakeReadFile
assert result
toolInvocation
pastTenseMessage value isTrusted uris
result toolInvocation fakeReadFile
assert result
toolInvocation
pastTenseMessage value isTrusted uris
result toolInvocation fakeReadFile
assert result
imageUri
toolInvocation
toolCallId
toolId
pastTenseMessage value isTrusted uris imageUri
result toolInvocation fakeReadFile
assert result length
assert result uri imageUri
assert result name
assert result mimeType
caption result caption
assert caption
assert caption value
assert result source
uri1
uri2
toolInvocation
pastTenseMessage
value
isTrusted
uris uri1 uri2
result toolInvocation fakeReadFile
assert result length
assert result mimeType
assert result mimeType
goodUri
badUri
uri
uri path
VSBuffer
toolInvocation
pastTenseMessage
value
isTrusted
uris badUri goodUri
result toolInvocation failingReadFile
assert result length
assert result uri goodUri
imageUri
toolInvocation
pastTenseMessage
invocationMessage value isTrusted uris imageUri
result toolInvocation fakeReadFile
assert result length
caption result caption
assert caption
assert caption value
request
value
result request
assert result length
assert result name
assert result mimeType
assert result data buffer
request
value buffer
result request
assert result length
assert result data buffer
request
value
result request
assert result length
assert result data buffer
request
value
result request
assert result length
assert result data buffer
uri
request
value uri references kind reference uri
assert request
uri
request
value references kind reference uri
result request
assert result length
assert result uri uri
,
}
from
'../../common/model/chatViewModel.js'
;
import
{
,
,
}
from
'../../common/chatService/chatService.js'
;
import
{
}
from
'../../common/tools/languageModelToolsService.js'
;
import
{
,
,
}
from
'../../common/chatImageExtraction.js'
;
function
makeToolInvocation
(
:
<
>
=
{
}
)
:
{
return
{
:
'toolInvocationSerialized'
,
:
'call_1'
,
:
'test-tool'
,
:
'Running tool'
,
:
undefined
,
:
'Ran tool'
,
:
true
,
:
true
,
:
undefined
,
:
undefined
,
:
undefined
,
...
,
}
;
}
function
makeInlineReference
(
:
URI
,
?
:
string
)
:
{
return
{
:
'inlineReference'
,
:
,
,
}
;
}
function
makeResponse
(
:
<
>
,
:
{
?
:
URI
;
?
:
string
;
?
:
string
;
?
:
string
;
?
:
readonly
[
]
;
?
:
boolean
;
}
=
{
}
)
:
{
const
=
.
??
URI
.
parse
(
'chat-session://test/session'
)
;
const
=
.
??
'req-1'
;
const
=
.
??
'resp-1'
;
const
=
.
??
'Show me images'
;
return
{
:
,
,
,
:
{
:
}
,
:
{
getItems
:
(
)
=>
.
?
[
]
:
[
{
:
,
:
,
:
{
:
[
]
,
:
}
,
:
.
??
[
]
,
}
]
,
}
,
}
as
unknown
as
;
}
const
fakeReadFile
=
(
:
URI
)
=>
Promise
.
resolve
(
.
fromString
(
` data-for- ${ uri. path} `
)
)
;
function
makeRequest
(
:
[
'variables'
]
,
:
{
?
:
string
;
?
:
string
}
=
{
}
)
:
{
return
{
:
.
??
'req-1'
,
:
URI
.
parse
(
'chat-session://test/session'
)
,
:
'data-1'
,
:
'test-user'
,
:
{
:
.
??
'Show me images'
,
:
[
]
}
,
:
.
??
'Show me images'
,
:
0
,
,
:
undefined
,
:
undefined
,
:
true
,
:
true
,
:
undefined
,
:
false
,
:
undefined
!
,
:
0
,
}
as
unknown
as
;
}
function
makeImageVariableEntry
(
:
<
>
&
<
,
'value'
>
)
:
{
const
{
,
...
}
=
;
return
{
:
'img-1'
,
:
'image'
,
:
'cat.png'
,
,
:
'image/png'
,
...
,
}
;
}
suite
(
'extractImagesFromChatResponse'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'returns empty images when response has no items'
,
async
(
)
=>
{
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
deepStrictEqual
(
,
{
:
.
.
toString
(
)
+
'_'
+
.
,
:
'Show me images'
,
:
[
]
,
}
)
;
}
)
;
test
(
'uses default title when no matching request is found'
,
async
(
)
=>
{
const
=
makeResponse
(
[
]
,
{
:
true
}
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
,
'Images'
)
;
}
)
;
test
(
'uses attachment summary title when matching request has no message text'
,
async
(
)
=>
{
const
=
makeImageVariableEntry
(
{
:
.
fromString
(
'image'
)
.
}
)
;
const
=
makeResponse
(
[
]
,
{
:
''
,
:
[
]
}
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
,
'Attached 1 image'
)
;
}
)
;
test
(
'extracts image from tool invocation with IToolResultOutputDetails'
,
async
(
)
=>
{
const
:
=
{
:
{
:
'data'
,
:
'image/png'
,
:
'AQID'
}
,
}
;
const
=
makeToolInvocation
(
{
:
'call_img'
,
:
'screenshot-tool'
,
:
'Took a screenshot'
,
,
}
)
;
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
1
)
;
.
strictEqual
(
.
[
0
]
.
,
'call_img_0'
)
;
.
strictEqual
(
.
[
0
]
.
,
'image/png'
)
;
.
ok
(
.
[
0
]
.
.
includes
(
'screenshot-tool'
)
)
;
.
strictEqual
(
.
[
0
]
.
,
'Took a screenshot'
)
;
}
)
;
test
(
'extracts multiple images from tool invocation with IToolResultInputOutputDetails'
,
async
(
)
=>
{
const
:
=
{
:
''
,
:
[
{
:
'embed'
,
:
'image/png'
,
:
'AQID'
,
:
false
}
,
{
:
'embed'
,
:
'text/plain'
,
:
'text'
,
:
true
}
,
{
:
'embed'
,
:
'image/jpeg'
,
:
'BAUG'
,
:
false
}
,
]
,
}
;
const
=
makeToolInvocation
(
{
:
'call_multi'
,
:
'multi-tool'
,
:
'Generated images'
,
,
}
)
;
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
2
)
;
.
strictEqual
(
.
[
0
]
.
,
'call_multi_0'
)
;
.
strictEqual
(
.
[
0
]
.
,
'image/png'
)
;
.
strictEqual
(
.
[
1
]
.
,
'call_multi_2'
)
;
.
strictEqual
(
.
[
1
]
.
,
'image/jpeg'
)
;
}
)
;
test
(
'skips tool invocations without image results'
,
async
(
)
=>
{
const
:
=
{
:
{
:
'data'
,
:
'text/plain'
,
:
'aGVsbG8='
}
,
}
;
const
=
makeToolInvocation
(
{
}
)
;
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
0
)
;
}
)
;
test
(
'extracts image from inline reference URI when readFile is provided'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/photos/cat.png'
)
;
const
=
makeInlineReference
(
,
'cat.png'
)
;
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
1
)
;
.
strictEqual
(
.
[
0
]
.
.
toString
(
)
,
.
toString
(
)
)
;
.
strictEqual
(
.
[
0
]
.
,
'cat.png'
)
;
.
strictEqual
(
.
[
0
]
.
,
'image/png'
)
;
.
strictEqual
(
.
[
0
]
.
,
'File'
)
;
}
)
;
test
(
'extracts image from inline reference Location'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/photos/dog.jpg'
)
;
const
:
=
{
:
'inlineReference'
,
:
{
:
,
:
{
:
1
,
:
1
,
:
1
,
:
1
}
}
,
}
;
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
1
)
;
.
strictEqual
(
.
[
0
]
.
.
toString
(
)
,
.
toString
(
)
)
;
}
)
;
test
(
'skips non-image inline references'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/src/main.ts'
)
;
const
=
makeInlineReference
(
)
;
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
0
)
;
}
)
;
test
(
'uses filename from URI path when name is not provided'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/assets/banner.gif'
)
;
const
=
makeInlineReference
(
)
;
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
1
)
;
.
strictEqual
(
.
[
0
]
.
,
'banner.gif'
)
;
}
)
;
test
(
'preserves interleaved order of tool and inline reference images'
,
async
(
)
=>
{
const
=
makeToolInvocation
(
{
:
'call_first'
,
:
'tool-1'
,
:
{
:
{
:
'data'
,
:
'image/png'
,
:
'AQID'
}
,
}
,
}
)
;
const
=
makeInlineReference
(
URI
.
file
(
'/middle.png'
)
,
'middle.png'
)
;
const
=
makeToolInvocation
(
{
:
'call_last'
,
:
'tool-2'
,
:
{
:
{
:
'data'
,
:
'image/jpeg'
,
:
'BAUG'
}
,
}
,
}
)
;
const
=
makeResponse
(
[
,
,
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
3
)
;
.
strictEqual
(
.
[
0
]
.
,
'call_first_0'
)
;
.
strictEqual
(
.
[
1
]
.
,
'middle.png'
)
;
.
strictEqual
(
.
[
2
]
.
,
'call_last_0'
)
;
}
)
;
test
(
'collection id combines sessionResource and response id'
,
async
(
)
=>
{
const
=
URI
.
parse
(
'chat-session://test/my-session'
)
;
const
=
makeResponse
(
[
]
,
{
,
:
'response-42'
}
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
,
.
toString
(
)
+
'_response-42'
)
;
}
)
;
test
(
'skips inline reference when readFile fails'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/photos/missing.png'
)
;
const
=
makeInlineReference
(
,
'missing.png'
)
;
const
failingReadFile
=
(
:
URI
)
=>
Promise
.
reject
(
new
Error
(
'File not found'
)
)
;
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
0
)
;
}
)
;
test
(
'extracts images from tool invocation message URIs'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/screenshots/result.png'
)
;
const
=
makeToolInvocation
(
{
:
'call_msg'
,
:
'screenshot-tool'
,
:
{
:
'Took a screenshot'
,
:
false
,
:
{
'0'
:
.
toJSON
(
)
}
}
,
}
)
;
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
1
)
;
.
strictEqual
(
.
[
0
]
.
.
toString
(
)
,
.
toString
(
)
)
;
.
strictEqual
(
.
[
0
]
.
,
'result.png'
)
;
.
strictEqual
(
.
[
0
]
.
,
'image/png'
)
;
const
=
.
[
0
]
.
;
.
ok
(
isMarkdownString
(
)
,
'caption should be an IMarkdownString'
)
;
.
strictEqual
(
.
,
'Took a screenshot'
)
;
}
)
;
test
(
'combines output details images and message URI images'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/screenshots/msg-image.jpg'
)
;
const
:
=
{
:
{
:
'data'
,
:
'image/png'
,
:
'AQID'
}
,
}
;
const
=
makeToolInvocation
(
{
:
'call_both'
,
:
'combo-tool'
,
:
{
:
'Ran combo tool'
,
:
false
,
:
{
'0'
:
.
toJSON
(
)
}
}
,
,
}
)
;
const
=
makeResponse
(
[
]
)
;
const
=
await
extractImagesFromChatResponse
(
,
)
;
.
strictEqual
(
.
.
,
2
)
;
.
strictEqual
(
.
[
0
]
.
,
'call_both_0'
)
;
.
strictEqual
(
.
[
1
]
.
.
toString
(
)
,
.
toString
(
)
)
;
}
)
;
}
)
;
suite
(
'extractImagesFromToolInvocationMessages'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'returns empty when message is undefined'
,
async
(
)
=>
{
const
=
makeToolInvocation
(
{
:
undefined
,
:
undefined
,
}
)
;
const
=
await
extractImagesFromToolInvocationMessages
(
,
)
;
.
deepStrictEqual
(
,
[
]
)
;
}
)
;
test
(
'returns empty when message is a string'
,
async
(
)
=>
{
const
=
makeToolInvocation
(
{
:
'some string message'
,
}
)
;
const
=
await
extractImagesFromToolInvocationMessages
(
,
)
;
.
deepStrictEqual
(
,
[
]
)
;
}
)
;
test
(
'returns empty when message has no uris'
,
async
(
)
=>
{
const
=
makeToolInvocation
(
{
:
{
:
'No URIs here'
,
:
false
}
,
}
)
;
const
=
await
extractImagesFromToolInvocationMessages
(
,
)
;
.
deepStrictEqual
(
,
[
]
)
;
}
)
;
test
(
'returns empty when message uris are empty'
,
async
(
)
=>
{
const
=
makeToolInvocation
(
{
:
{
:
'Empty URIs'
,
:
false
,
:
{
}
}
,
}
)
;
const
=
await
extractImagesFromToolInvocationMessages
(
,
)
;
.
deepStrictEqual
(
,
[
]
)
;
}
)
;
test
(
'skips non-image URIs'
,
async
(
)
=>
{
const
=
makeToolInvocation
(
{
:
{
:
'Code file'
,
:
false
,
:
{
'0'
:
URI
.
file
(
'/src/main.ts'
)
.
toJSON
(
)
}
}
,
}
)
;
const
=
await
extractImagesFromToolInvocationMessages
(
,
)
;
.
deepStrictEqual
(
,
[
]
)
;
}
)
;
test
(
'extracts image from message URI'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/screenshots/capture.png'
)
;
const
=
makeToolInvocation
(
{
:
'call_uri'
,
:
'screenshot-tool'
,
:
{
:
'Captured screenshot'
,
:
false
,
:
{
'0'
:
.
toJSON
(
)
}
}
,
}
)
;
const
=
await
extractImagesFromToolInvocationMessages
(
,
)
;
.
strictEqual
(
.
,
1
)
;
.
strictEqual
(
[
0
]
.
.
toString
(
)
,
.
toString
(
)
)
;
.
strictEqual
(
[
0
]
.
,
'capture.png'
)
;
.
strictEqual
(
[
0
]
.
,
'image/png'
)
;
const
=
[
0
]
.
;
.
ok
(
isMarkdownString
(
)
,
'caption should be an IMarkdownString'
)
;
.
strictEqual
(
.
,
'Captured screenshot'
)
;
.
ok
(
[
0
]
.
.
includes
(
'screenshot-tool'
)
)
;
}
)
;
test
(
'extracts multiple images from message URIs'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/img/a.png'
)
;
const
=
URI
.
file
(
'/img/b.jpg'
)
;
const
=
makeToolInvocation
(
{
:
{
:
'Generated images'
,
:
false
,
:
{
'0'
:
.
toJSON
(
)
,
'1'
:
.
toJSON
(
)
}
,
}
,
}
)
;
const
=
await
extractImagesFromToolInvocationMessages
(
,
)
;
.
strictEqual
(
.
,
2
)
;
.
strictEqual
(
[
0
]
.
,
'image/png'
)
;
.
strictEqual
(
[
1
]
.
,
'image/jpg'
)
;
}
)
;
test
(
'continues when readFile fails for one URI'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/img/good.png'
)
;
const
=
URI
.
file
(
'/img/bad.png'
)
;
const
failingReadFile
=
(
:
URI
)
=>
{
if
(
.
.
includes
(
'bad'
)
)
{
return
Promise
.
reject
(
new
Error
(
'File not found'
)
)
;
}
return
Promise
.
resolve
(
.
fromString
(
'image-data'
)
)
;
}
;
const
=
makeToolInvocation
(
{
:
{
:
'Mixed results'
,
:
false
,
:
{
'0'
:
.
toJSON
(
)
,
'1'
:
.
toJSON
(
)
}
,
}
,
}
)
;
const
=
await
extractImagesFromToolInvocationMessages
(
,
)
;
.
strictEqual
(
.
,
1
)
;
.
strictEqual
(
[
0
]
.
.
toString
(
)
,
.
toString
(
)
)
;
}
)
;
test
(
'falls back to invocationMessage when pastTenseMessage is undefined'
,
async
(
)
=>
{
const
=
URI
.
file
(
'/img/fallback.png'
)
;
const
=
makeToolInvocation
(
{
:
undefined
,
:
{
:
'Running tool'
,
:
false
,
:
{
'0'
:
.
toJSON
(
)
}
}
,
}
)
;
const
=
await
extractImagesFromToolInvocationMessages
(
,
)
;
.
strictEqual
(
.
,
1
)
;
const
=
[
0
]
.
;
.
ok
(
isMarkdownString
(
)
,
'caption should be an IMarkdownString'
)
;
.
strictEqual
(
.
,
'Running tool'
)
;
}
)
;
}
)
;
suite
(
'extractImagesFromChatRequest'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'extracts image attachment from Uint8Array'
,
(
)
=>
{
const
=
makeRequest
(
[
makeImageVariableEntry
(
{
:
new
Uint8Array
(
[
1
,
2
,
3
]
)
}
)
,
]
)
;
const
=
extractImagesFromChatRequest
(
)
;
.
strictEqual
(
.
,
1
)
;
.
strictEqual
(
[
0
]
.
,
'cat.png'
)
;
.
strictEqual
(
[
0
]
.
,
'image/png'
)
;
.
deepStrictEqual
(
[
...
[
0
]
.
.
]
,
[
1
,
2
,
3
]
)
;
}
)
;
test
(
'extracts image attachment from ArrayBuffer'
,
(
)
=>
{
const
=
makeRequest
(
[
makeImageVariableEntry
(
{
:
new
Uint8Array
(
[
4
,
5
,
6
]
)
.
}
)
,
]
)
;
const
=
extractImagesFromChatRequest
(
)
;
.
strictEqual
(
.
,
1
)
;
.
deepStrictEqual
(
[
...
[
0
]
.
.
]
,
[
4
,
5
,
6
]
)
;
}
)
;
test
(
'extracts restored image attachment from plain object bytes'
,
(
)
=>
{
const
=
makeRequest
(
[
makeImageVariableEntry
(
{
:
{
0
:
7
,
1
:
8
,
2
:
9
}
}
)
,
]
)
;
const
=
extractImagesFromChatRequest
(
)
;
.
strictEqual
(
.
,
1
)
;
.
deepStrictEqual
(
[
...
[
0
]
.
.
]
,
[
7
,
8
,
9
]
)
;
}
)
;
test
(
'extracts restored image attachment from reordered plain object bytes'
,
(
)
=>
{
const
=
makeRequest
(
[
makeImageVariableEntry
(
{
:
{
2
:
9
,
0
:
7
,
1
:
8
}
}
)
,
]
)
;
const
=
extractImagesFromChatRequest
(
)
;
.
strictEqual
(
.
,
1
)
;
.
deepStrictEqual
(
[
...
[
0
]
.
.
]
,
[
7
,
8
,
9
]
)
;
}
)
;
test
(
'does not treat a URI-backed image attachment as inline image bytes'
,
(
)
=>
{
const
=
URI
.
file
(
'/tmp/cat.png'
)
;
const
=
makeRequest
(
[
makeImageVariableEntry
(
{
:
,
:
[
{
:
'reference'
,
:
}
]
}
)
,
]
)
;
.
deepStrictEqual
(
extractImagesFromChatRequest
(
)
,
[
]
)
;
}
)
;
test
(
'uses attachment resource URI when available'
,
(
)
=>
{
const
=
URI
.
file
(
'/tmp/cat.png'
)
;
const
=
makeRequest
(
[
makeImageVariableEntry
(
{
:
new
Uint8Array
(
[
1
]
)
,
:
[
{
:
'reference'
,
:
}
]
}
)
,
]
)
;
const
=
extractImagesFromChatRequest
(
)
;
.
strictEqual
(
.
,
1
)
;
.
strictEqual
(
[
0
]
.
.
toString
(
)
,
.
toString
(
)
)
;
}
)
;
}
)
;