refactor(qa): share provider json writer · openclaw/openclaw@9f6d5e4
vincentkoc
·
2026-06-20
·
via Recent Commits to openclaw:main
File tree
extensions/qa-lab/src/providers
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import {
|
6 | 6 | type JournalEntry, |
7 | 7 | type Mountable, |
8 | 8 | } from "@copilotkit/aimock"; |
| 9 | +import { writeJson } from "../shared/http-json.js"; |
9 | 10 | |
10 | 11 | type AimockRequestSnapshot = { |
11 | 12 | raw: string; |
@@ -22,16 +23,6 @@ type AimockRequestSnapshot = {
|
22 | 23 | toolOutputStructuredError?: true; |
23 | 24 | }; |
24 | 25 | |
25 | | -function writeJson(res: ServerResponse, status: number, body: unknown) { |
26 | | -const text = JSON.stringify(body); |
27 | | -res.writeHead(status, { |
28 | | -"content-type": "application/json; charset=utf-8", |
29 | | -"content-length": Buffer.byteLength(text), |
30 | | -"cache-control": "no-store", |
31 | | -}); |
32 | | -res.end(text); |
33 | | -} |
34 | | - |
35 | 26 | function stringifyContent(content: unknown): string { |
36 | 27 | if (typeof content === "string") { |
37 | 28 | return content; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ import { setTimeout as sleep } from "node:timers/promises";
|
5 | 5 | import { escapeRegExp } from "openclaw/plugin-sdk/text-utility-runtime"; |
6 | 6 | import { readRequestBodyWithLimit } from "openclaw/plugin-sdk/webhook-ingress"; |
7 | 7 | import { closeQaHttpServer } from "../../bus-server.js"; |
| 8 | +import { writeJson } from "../shared/http-json.js"; |
8 | 9 | |
9 | 10 | type ResponsesInputItem = Record<string, unknown>; |
10 | 11 | |
@@ -234,16 +235,6 @@ function transcriptionTextForAudioRequest(rawBody: string) {
|
234 | 235 | return QA_AUDIO_TRANSCRIPTION_TEXT; |
235 | 236 | } |
236 | 237 | |
237 | | -function writeJson(res: ServerResponse, status: number, body: unknown) { |
238 | | -const text = JSON.stringify(body); |
239 | | -res.writeHead(status, { |
240 | | -"content-type": "application/json; charset=utf-8", |
241 | | -"content-length": Buffer.byteLength(text), |
242 | | -"cache-control": "no-store", |
243 | | -}); |
244 | | -res.end(text); |
245 | | -} |
246 | | - |
247 | 238 | function writeSse(res: ServerResponse, events: StreamEvent[]) { |
248 | 239 | const body = `${events.map((event) => `data: ${JSON.stringify(event)}\n\n`).join("")}data: [DONE]\n\n`; |
249 | 240 | res.writeHead(200, { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import type { ServerResponse } from "node:http"; |
| 2 | + |
| 3 | +export function writeJson(res: ServerResponse, status: number, body: unknown) { |
| 4 | +const text = JSON.stringify(body); |
| 5 | +res.writeHead(status, { |
| 6 | +"content-type": "application/json; charset=utf-8", |
| 7 | +"content-length": Buffer.byteLength(text), |
| 8 | +"cache-control": "no-store", |
| 9 | +}); |
| 10 | +res.end(text); |
| 11 | +} |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。