mirror of
https://github.com/stablyai/orca.git
synced 2026-10-19 16:03:26 +00:00
* fix(mobile-chat): a returned message is appended to the draft, and an expired resend id is spent * test(mobile-chat): leave the idempotent append to the shared rule's own test * docs(native-chat): say a whitespace-only draft counts as empty * docs(mobile-chat): don't overclaim where returned text survives
20 lines
645 B
TypeScript
20 lines
645 B
TypeScript
/**
|
|
* Puts text a chat handed back after what the composer already holds, a blank line apart. It never
|
|
* replaces typed text (a whitespace-only draft counts as empty), and adds nothing when the draft
|
|
* already ends with that text, so handing the same text back twice leaves one copy.
|
|
*/
|
|
export function appendReturnedDraftText(draft: string, text: string): string {
|
|
const returned = text.trimEnd()
|
|
if (returned.trim() === '') {
|
|
return draft
|
|
}
|
|
const kept = draft.trimEnd()
|
|
if (kept === '') {
|
|
return text
|
|
}
|
|
if (kept === returned || kept.endsWith(`\n\n${returned}`)) {
|
|
return draft
|
|
}
|
|
return `${kept}\n\n${text}`
|
|
}
|