fix: correct SSE delta parsing + custom model input

response.output_text.delta has delta as plain string not object; fix
parseSseText to handle it. Also fix custom model dropdown — selecting
Custom now sets model to "" so isCustom triggers correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Felix Isaac Lim 2026-05-23 06:27:35 +08:00
parent b389c5991d
commit 1024c37991
2 changed files with 15 additions and 22 deletions

View file

@ -44,26 +44,21 @@ function parseSseText(sseBody: string): string {
try {
const json = JSON.parse(data) as any;
// Responses API emits output[].content[].text deltas
for (const output of json.output ?? []) {
for (const content of output.content ?? []) {
if (content.type === "output_text" && content.text) {
parts.push(content.text);
}
}
// response.output_text.delta — delta is a plain string
if (json.type === "response.output_text.delta" && typeof json.delta === "string") {
parts.push(json.delta);
}
// Delta format
const delta = json.delta;
if (delta?.type === "output_text" && delta.text) {
parts.push(delta.text);
}
// Snapshot format (non-streaming final)
// response.completed — full text in output[].content[]
if (json.type === "response.completed") {
const output = json.response?.output ?? [];
for (const item of output) {
for (const c of item.content ?? []) {
if (c.type === "output_text" && c.text) {
parts.push(c.text);
// only use completed if we got no deltas (requestUrl buffers whole response)
if (parts.length === 0) {
for (const item of json.response?.output ?? []) {
for (const c of item.content ?? []) {
if (c.type === "output_text" && typeof c.text === "string") {
parts.push(c.text);
}
}
}
}

View file

@ -150,10 +150,8 @@ export class InlineAISettingsTab extends PluginSettingTab {
.addDropdown((dd) => {
CODEX_MODELS.forEach((m) => dd.addOption(m.value, m.label));
dd.setValue(dropdownValue).onChange(async (value) => {
if (value !== "custom") {
this.plugin.settings.model = value;
await this.saveSettings();
}
this.plugin.settings.model = value === "custom" ? "" : value;
await this.saveSettings();
this.display();
});
});