Commit 1211eaa
authored
fix: avoid unsafe array index access in AnthropicVertex completePrompt (#789)
The completePrompt method accessed response.content[0] directly, which
could throw a TypeError when the content array is empty, and would
return an empty string when the first block is a non-text block (e.g.
thinking or tool_use) even when a text block is present later in the
array.
Use Array.prototype.find() to locate the first text block, matching
the pattern already used in anthropic.ts. This safely returns undefined
for empty arrays and surfaces the actual text response regardless of
its position among content blocks.
Add regression tests covering an empty content array and a mixed
content array where a thinking block precedes the text block.
Signed-off-by: daewoongoh <dw.oh@samsung.com>1 parent 4e5f601 commit 1211eaa
2 files changed
Lines changed: 40 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
895 | 895 | | |
896 | 896 | | |
897 | 897 | | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
898 | 933 | | |
899 | 934 | | |
900 | 935 | | |
| |||
1342 | 1377 | | |
1343 | 1378 | | |
1344 | 1379 | | |
1345 | | - | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
1346 | 1383 | | |
1347 | 1384 | | |
1348 | 1385 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | | - | |
| 300 | + | |
301 | 301 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
| 302 | + | |
307 | 303 | | |
308 | 304 | | |
309 | 305 | | |
| |||
0 commit comments