Skip to content

Commit a9a40a3

Browse files
committed
fix typecheck
1 parent 22f935b commit a9a40a3

7 files changed

+66
-4064
lines changed

packages/internal/src/openai-compatible/chat/convert-to-openai-compatible-chat-messages.test.ts

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { convertToOpenAICompatibleChatMessages } from './convert-to-openai-compatible-chat-messages';
2-
import { describe, it, expect } from 'vitest';
1+
import { describe, it, expect } from 'bun:test'
2+
3+
import { convertToOpenAICompatibleChatMessages } from './convert-to-openai-compatible-chat-messages'
34

45
describe('user messages', () => {
56
it('should convert messages with only a text part to a string content', async () => {
@@ -8,10 +9,10 @@ describe('user messages', () => {
89
role: 'user',
910
content: [{ type: 'text', text: 'Hello' }],
1011
},
11-
]);
12+
])
1213

13-
expect(result).toEqual([{ role: 'user', content: 'Hello' }]);
14-
});
14+
expect(result).toEqual([{ role: 'user', content: 'Hello' }])
15+
})
1516

1617
it('should convert messages with image parts', async () => {
1718
const result = convertToOpenAICompatibleChatMessages([
@@ -26,7 +27,7 @@ describe('user messages', () => {
2627
},
2728
],
2829
},
29-
]);
30+
])
3031

3132
expect(result).toEqual([
3233
{
@@ -39,8 +40,8 @@ describe('user messages', () => {
3940
},
4041
],
4142
},
42-
]);
43-
});
43+
])
44+
})
4445

4546
it('should convert messages with image parts from Uint8Array', async () => {
4647
const result = convertToOpenAICompatibleChatMessages([
@@ -55,7 +56,7 @@ describe('user messages', () => {
5556
},
5657
],
5758
},
58-
]);
59+
])
5960

6061
expect(result).toEqual([
6162
{
@@ -68,8 +69,8 @@ describe('user messages', () => {
6869
},
6970
],
7071
},
71-
]);
72-
});
72+
])
73+
})
7374

7475
it('should handle URL-based images', async () => {
7576
const result = convertToOpenAICompatibleChatMessages([
@@ -83,7 +84,7 @@ describe('user messages', () => {
8384
},
8485
],
8586
},
86-
]);
87+
])
8788

8889
expect(result).toEqual([
8990
{
@@ -95,9 +96,9 @@ describe('user messages', () => {
9596
},
9697
],
9798
},
98-
]);
99-
});
100-
});
99+
])
100+
})
101+
})
101102

102103
describe('tool calls', () => {
103104
it('should stringify arguments to tool calls', () => {
@@ -124,7 +125,7 @@ describe('tool calls', () => {
124125
},
125126
],
126127
},
127-
]);
128+
])
128129

129130
expect(result).toEqual([
130131
{
@@ -146,8 +147,8 @@ describe('tool calls', () => {
146147
content: JSON.stringify({ oof: '321rab' }),
147148
tool_call_id: 'quux',
148149
},
149-
]);
150-
});
150+
])
151+
})
151152

152153
it('should handle text output type in tool results', () => {
153154
const result = convertToOpenAICompatibleChatMessages([
@@ -173,7 +174,7 @@ describe('tool calls', () => {
173174
},
174175
],
175176
},
176-
]);
177+
])
177178

178179
expect(result).toEqual([
179180
{
@@ -195,9 +196,9 @@ describe('tool calls', () => {
195196
content: 'It is sunny today',
196197
tool_call_id: 'call-1',
197198
},
198-
]);
199-
});
200-
});
199+
])
200+
})
201+
})
201202

202203
describe('provider-specific metadata merging', () => {
203204
it('should merge system message metadata', async () => {
@@ -211,16 +212,16 @@ describe('provider-specific metadata merging', () => {
211212
},
212213
},
213214
},
214-
]);
215+
])
215216

216217
expect(result).toEqual([
217218
{
218219
role: 'system',
219220
content: 'You are a helpful assistant.',
220221
cacheControl: { type: 'ephemeral' },
221222
},
222-
]);
223-
});
223+
])
224+
})
224225

225226
it('should merge user message content metadata', async () => {
226227
const result = convertToOpenAICompatibleChatMessages([
@@ -238,16 +239,16 @@ describe('provider-specific metadata merging', () => {
238239
},
239240
],
240241
},
241-
]);
242+
])
242243

243244
expect(result).toEqual([
244245
{
245246
role: 'user',
246247
content: 'Hello',
247248
cacheControl: { type: 'ephemeral' },
248249
},
249-
]);
250-
});
250+
])
251+
})
251252

252253
it('should prioritize content-level metadata when merging', async () => {
253254
const result = convertToOpenAICompatibleChatMessages([
@@ -270,16 +271,16 @@ describe('provider-specific metadata merging', () => {
270271
},
271272
],
272273
},
273-
]);
274+
])
274275

275276
expect(result).toEqual([
276277
{
277278
role: 'user',
278279
content: 'Hello',
279280
contentLevel: true,
280281
},
281-
]);
282-
});
282+
])
283+
})
283284

284285
it('should handle tool calls with metadata', async () => {
285286
const result = convertToOpenAICompatibleChatMessages([
@@ -299,7 +300,7 @@ describe('provider-specific metadata merging', () => {
299300
},
300301
],
301302
},
302-
]);
303+
])
303304

304305
expect(result).toEqual([
305306
{
@@ -317,11 +318,11 @@ describe('provider-specific metadata merging', () => {
317318
},
318319
],
319320
},
320-
]);
321-
});
321+
])
322+
})
322323

323324
it('should handle image content with metadata', async () => {
324-
const imageUrl = new URL('https://example.com/image.jpg');
325+
const imageUrl = new URL('https://example.com/image.jpg')
325326
const result = convertToOpenAICompatibleChatMessages([
326327
{
327328
role: 'user',
@@ -338,7 +339,7 @@ describe('provider-specific metadata merging', () => {
338339
},
339340
],
340341
},
341-
]);
342+
])
342343

343344
expect(result).toEqual([
344345
{
@@ -351,8 +352,8 @@ describe('provider-specific metadata merging', () => {
351352
},
352353
],
353354
},
354-
]);
355-
});
355+
])
356+
})
356357

357358
it('should omit non-openaiCompatible metadata', async () => {
358359
const result = convertToOpenAICompatibleChatMessages([
@@ -365,15 +366,15 @@ describe('provider-specific metadata merging', () => {
365366
},
366367
},
367368
},
368-
]);
369+
])
369370

370371
expect(result).toEqual([
371372
{
372373
role: 'system',
373374
content: 'Hello',
374375
},
375-
]);
376-
});
376+
])
377+
})
377378

378379
it('should handle a user message with multiple content parts (text + image)', () => {
379380
const result = convertToOpenAICompatibleChatMessages([
@@ -401,7 +402,7 @@ describe('provider-specific metadata merging', () => {
401402
openaiCompatible: { priority: 'high' },
402403
},
403404
},
404-
]);
405+
])
405406

406407
expect(result).toEqual([
407408
{
@@ -422,8 +423,8 @@ describe('provider-specific metadata merging', () => {
422423
},
423424
],
424425
},
425-
]);
426-
});
426+
])
427+
})
427428

428429
it('should handle a user message with multiple text parts (flattening disabled)', () => {
429430
const result = convertToOpenAICompatibleChatMessages([
@@ -434,7 +435,7 @@ describe('provider-specific metadata merging', () => {
434435
{ type: 'text', text: 'Part 2' },
435436
],
436437
},
437-
]);
438+
])
438439

439440
// Because there are multiple text parts, the converter won't flatten them
440441
expect(result).toEqual([
@@ -445,8 +446,8 @@ describe('provider-specific metadata merging', () => {
445446
{ type: 'text', text: 'Part 2' },
446447
],
447448
},
448-
]);
449-
});
449+
])
450+
})
450451

451452
it('should handle an assistant message with text plus multiple tool calls', () => {
452453
const result = convertToOpenAICompatibleChatMessages([
@@ -472,7 +473,7 @@ describe('provider-specific metadata merging', () => {
472473
},
473474
],
474475
},
475-
]);
476+
])
476477

477478
expect(result).toEqual([
478479
{
@@ -498,8 +499,8 @@ describe('provider-specific metadata merging', () => {
498499
},
499500
],
500501
},
501-
]);
502-
});
502+
])
503+
})
503504

504505
it('should handle a single tool role message with multiple tool-result parts', () => {
505506
const result = convertToOpenAICompatibleChatMessages([
@@ -527,7 +528,7 @@ describe('provider-specific metadata merging', () => {
527528
},
528529
],
529530
},
530-
]);
531+
])
531532

532533
expect(result).toEqual([
533534
{
@@ -541,8 +542,8 @@ describe('provider-specific metadata merging', () => {
541542
content: JSON.stringify({ stepTwo: 'data chunk 2' }),
542543
partial: true,
543544
},
544-
]);
545-
});
545+
])
546+
})
546547

547548
it('should handle multiple content parts with multiple metadata layers', () => {
548549
const result = convertToOpenAICompatibleChatMessages([
@@ -571,7 +572,7 @@ describe('provider-specific metadata merging', () => {
571572
},
572573
],
573574
},
574-
]);
575+
])
575576

576577
expect(result).toEqual([
577578
{
@@ -592,8 +593,8 @@ describe('provider-specific metadata merging', () => {
592593
},
593594
],
594595
},
595-
]);
596-
});
596+
])
597+
})
597598

598599
it('should handle different tool metadata vs. message-level metadata', () => {
599600
const result = convertToOpenAICompatibleChatMessages([
@@ -617,7 +618,7 @@ describe('provider-specific metadata merging', () => {
617618
},
618619
],
619620
},
620-
]);
621+
])
621622

622623
expect(result).toEqual([
623624
{
@@ -636,8 +637,8 @@ describe('provider-specific metadata merging', () => {
636637
},
637638
],
638639
},
639-
]);
640-
});
640+
])
641+
})
641642

642643
it('should handle metadata collisions and overwrites in tool calls', () => {
643644
const result = convertToOpenAICompatibleChatMessages([
@@ -664,7 +665,7 @@ describe('provider-specific metadata merging', () => {
664665
},
665666
],
666667
},
667-
]);
668+
])
668669

669670
expect(result).toEqual([
670671
{
@@ -685,6 +686,6 @@ describe('provider-specific metadata merging', () => {
685686
},
686687
],
687688
},
688-
]);
689-
});
690-
});
689+
])
690+
})
691+
})

0 commit comments

Comments
 (0)