Skip to content

Commit 8a4198c

Browse files
nicohrubecclaude
andauthored
ref(server-utils): Remove array JSON-stringify fallback in Vercel AI integration (#23102)
We now support arrays so we don't need this fallback stringification for any arrays in vercel. Conventions still require the attributes that we send to be strings so keeping the explicit attribute stringifications and adding one for the `finish_reason` so we preserve the format. Fixes #20863 Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 64bf6e2 commit 8a4198c

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

  • packages/server-utils/src/ai/vercel-ai

packages/server-utils/src/ai/vercel-ai/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
GEN_AI_OUTPUT_MESSAGES,
1818
GEN_AI_PROVIDER_NAME,
1919
GEN_AI_REQUEST_MODEL,
20+
GEN_AI_RESPONSE_FINISH_REASONS,
2021
GEN_AI_RESPONSE_MODEL,
2122
GEN_AI_TOOL_CALL_ARGUMENTS,
2223
GEN_AI_TOOL_CALL_RESULT,
@@ -334,14 +335,13 @@ export function processVercelAiSpanAttributes(attributes: Record<string, unknown
334335
attributes[GEN_AI_EMBEDDINGS_INPUT] = parsed.length === 1 ? parsed[0] : JSON.stringify(parsed);
335336
}
336337

338+
if (Array.isArray(attributes[GEN_AI_RESPONSE_FINISH_REASONS])) {
339+
attributes[GEN_AI_RESPONSE_FINISH_REASONS] = JSON.stringify(attributes[GEN_AI_RESPONSE_FINISH_REASONS]);
340+
}
341+
337342
addProviderMetadataToAttributes(attributes);
338343

339344
for (const key of Object.keys(attributes)) {
340-
// JSON-stringify any array-valued attributes so they survive v2 span serialization.
341-
// Can be removed once span streaming supports arrays natively.
342-
if (Array.isArray(attributes[key])) {
343-
attributes[key] = JSON.stringify(attributes[key]);
344-
}
345345
// Change attributes namespaced with `ai.X` to `vercel.ai.X`
346346
if (key.startsWith('ai.')) {
347347
renameAttributeKey(attributes, key, `vercel.${key}`);

0 commit comments

Comments
 (0)