Skip to content

Commit

Permalink
feat: ✨ handle array content in message append functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 19, 2024
1 parent 85c5a21 commit a012fca
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/core/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,10 @@ export function appendUserMessage(
if (ephemeral) last.cacheControl = "ephemeral"
messages.push(last)
}
if (last.content) last.content += "\n" + content
else last.content = content
if (last.content) {
if (typeof last.content === "string") last.content += "\n" + content
else last.content.push({ type: "text", text: content })
} else last.content = content
}

Check failure on line 1092 in packages/core/src/chat.ts

View workflow job for this annotation

GitHub Actions / build

Type coercion detected. Ensure type safety when appending content to `last.content`.

export function appendAssistantMessage(
Expand All @@ -1108,8 +1110,10 @@ export function appendAssistantMessage(
if (ephemeral) last.cacheControl = "ephemeral"
messages.push(last)
}
if (last.content) last.content += "\n" + content
else last.content = content
if (last.content) {
if (typeof last.content === "string") last.content += "\n" + content
else last.content.push({ type: "text", text: content })
} else last.content = content
}

Check failure on line 1117 in packages/core/src/chat.ts

View workflow job for this annotation

GitHub Actions / build

Type coercion detected. Ensure type safety when appending content to `last.content`.

export function appendSystemMessage(
Expand All @@ -1132,8 +1136,11 @@ export function appendSystemMessage(
if (ephemeral) last.cacheControl = "ephemeral"
messages.unshift(last)
}
if (last.content) last.content += SYSTEM_FENCE
last.content += content
if (last.content) {
if (typeof last.content === "string")
last.content += SYSTEM_FENCE + content
else last.content.push({ type: "text", text: content })

Check failure on line 1142 in packages/core/src/chat.ts

View workflow job for this annotation

GitHub Actions / build

Type coercion detected. Ensure type safety when appending content to `last.content`.
} else last.content = content
}

export function addToolDefinitionsMessage(
Expand Down

0 comments on commit a012fca

Please sign in to comment.