mirror of
https://github.com/fbarrca/obsidian-inlineAI.git
synced 2026-07-22 11:50:24 +00:00
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:
parent
b389c5991d
commit
1024c37991
2 changed files with 15 additions and 22 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue