feat(open-sse): mark streaming requestDetail as error on stream-error pattern match
This commit is contained in:
@@ -6,6 +6,7 @@ import { PROVIDERS } from "../../config/providers.js";
|
|||||||
import { STREAM_STALL_TIMEOUT_MS } from "../../config/runtimeConfig.js";
|
import { STREAM_STALL_TIMEOUT_MS } from "../../config/runtimeConfig.js";
|
||||||
import { buildAbortedResponsesTerminalBytes } from "../../utils/responsesStreamHelpers.js";
|
import { buildAbortedResponsesTerminalBytes } from "../../utils/responsesStreamHelpers.js";
|
||||||
import { buildRequestDetail, extractRequestConfig, saveUsageStats, formatDoneLine } from "./requestDetail.js";
|
import { buildRequestDetail, extractRequestConfig, saveUsageStats, formatDoneLine } from "./requestDetail.js";
|
||||||
|
import { streamStatusForContent } from "../../utils/streamErrorPatterns.js";
|
||||||
import { saveRequestDetail } from "@/lib/usageDb.js";
|
import { saveRequestDetail } from "@/lib/usageDb.js";
|
||||||
import { SSE_HEADERS_CORS as SSE_HEADERS } from "../../utils/sseConstants.js";
|
import { SSE_HEADERS_CORS as SSE_HEADERS } from "../../utils/sseConstants.js";
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@ export async function handleStreamingResponse({ providerResponse, provider, mode
|
|||||||
/**
|
/**
|
||||||
* Build onStreamComplete callback for streaming usage tracking.
|
* Build onStreamComplete callback for streaming usage tracking.
|
||||||
*/
|
*/
|
||||||
export function buildOnStreamComplete({ provider, model, connectionId, apiKey, requestStartTime, body, stream, finalBody, translatedBody, clientRawRequest, pxpipe, reqTag, log }) {
|
export function buildOnStreamComplete({ provider, model, connectionId, apiKey, requestStartTime, body, stream, finalBody, translatedBody, clientRawRequest, pxpipe, reqTag, log, streamErrorPatterns }) {
|
||||||
const streamDetailId = `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
const streamDetailId = `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
||||||
|
|
||||||
const onStreamComplete = (contentObj, usage, ttftAt) => {
|
const onStreamComplete = (contentObj, usage, ttftAt) => {
|
||||||
@@ -130,7 +131,7 @@ export function buildOnStreamComplete({ provider, model, connectionId, apiKey, r
|
|||||||
providerResponse: safeContent,
|
providerResponse: safeContent,
|
||||||
response: { content: safeContent, thinking: safeThinking, type: "streaming" },
|
response: { content: safeContent, thinking: safeThinking, type: "streaming" },
|
||||||
pxpipe,
|
pxpipe,
|
||||||
status: "success"
|
status: streamStatusForContent(streamErrorPatterns?.[provider], safeContent)
|
||||||
}, { id: streamDetailId })).catch(err => {
|
}, { id: streamDetailId })).catch(err => {
|
||||||
console.error("[RequestDetail] Failed to update streaming content:", err.message);
|
console.error("[RequestDetail] Failed to update streaming content:", err.message);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user