mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 17:48:26 +00:00
refactor(shared): dedupe protocol schema typing and session/media helpers
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { normalizeGoogleModelId } from "../../../agents/models-config.providers.js";
|
||||
import { parseGeminiAuth } from "../../../infra/gemini-auth.js";
|
||||
import { assertOkOrThrowHttpError, fetchWithTimeoutGuarded, normalizeBaseUrl } from "../shared.js";
|
||||
import { assertOkOrThrowHttpError, normalizeBaseUrl, postJsonRequest } from "../shared.js";
|
||||
|
||||
export async function generateGeminiInlineDataText(params: {
|
||||
buffer: Buffer;
|
||||
@@ -61,17 +61,14 @@ export async function generateGeminiInlineDataText(params: {
|
||||
],
|
||||
};
|
||||
|
||||
const { response: res, release } = await fetchWithTimeoutGuarded(
|
||||
const { response: res, release } = await postJsonRequest({
|
||||
url,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(body),
|
||||
},
|
||||
params.timeoutMs,
|
||||
headers,
|
||||
body,
|
||||
timeoutMs: params.timeoutMs,
|
||||
fetchFn,
|
||||
allowPrivate ? { ssrfPolicy: { allowPrivateNetwork: true } } : undefined,
|
||||
);
|
||||
allowPrivateNetwork: allowPrivate,
|
||||
});
|
||||
|
||||
try {
|
||||
await assertOkOrThrowHttpError(res, params.httpErrorLabel);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { VideoDescriptionRequest, VideoDescriptionResult } from "../../types.js";
|
||||
import { assertOkOrThrowHttpError, fetchWithTimeoutGuarded, normalizeBaseUrl } from "../shared.js";
|
||||
import { assertOkOrThrowHttpError, normalizeBaseUrl, postJsonRequest } from "../shared.js";
|
||||
|
||||
export const DEFAULT_MOONSHOT_VIDEO_BASE_URL = "https://api.moonshot.ai/v1";
|
||||
const DEFAULT_MOONSHOT_VIDEO_MODEL = "kimi-k2.5";
|
||||
@@ -84,16 +84,13 @@ export async function describeMoonshotVideo(
|
||||
],
|
||||
};
|
||||
|
||||
const { response: res, release } = await fetchWithTimeoutGuarded(
|
||||
const { response: res, release } = await postJsonRequest({
|
||||
url,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(body),
|
||||
},
|
||||
params.timeoutMs,
|
||||
headers,
|
||||
body,
|
||||
timeoutMs: params.timeoutMs,
|
||||
fetchFn,
|
||||
);
|
||||
});
|
||||
|
||||
try {
|
||||
await assertOkOrThrowHttpError(res, "Moonshot video description failed");
|
||||
|
||||
@@ -53,6 +53,27 @@ export async function postTranscriptionRequest(params: {
|
||||
);
|
||||
}
|
||||
|
||||
export async function postJsonRequest(params: {
|
||||
url: string;
|
||||
headers: Headers;
|
||||
body: unknown;
|
||||
timeoutMs: number;
|
||||
fetchFn: typeof fetch;
|
||||
allowPrivateNetwork?: boolean;
|
||||
}) {
|
||||
return fetchWithTimeoutGuarded(
|
||||
params.url,
|
||||
{
|
||||
method: "POST",
|
||||
headers: params.headers,
|
||||
body: JSON.stringify(params.body),
|
||||
},
|
||||
params.timeoutMs,
|
||||
params.fetchFn,
|
||||
params.allowPrivateNetwork ? { ssrfPolicy: { allowPrivateNetwork: true } } : undefined,
|
||||
);
|
||||
}
|
||||
|
||||
export async function readErrorResponse(res: Response): Promise<string | undefined> {
|
||||
try {
|
||||
const text = await res.text();
|
||||
|
||||
Reference in New Issue
Block a user