mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 16:20:20 +00:00
refactor: move memory host into sdk package
This commit is contained in:
38
packages/memory-host-sdk/src/host/batch-utils.ts
Normal file
38
packages/memory-host-sdk/src/host/batch-utils.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { SsrFPolicy } from "../../../../src/infra/net/ssrf.js";
|
||||
|
||||
export type BatchHttpClientConfig = {
|
||||
baseUrl?: string;
|
||||
headers?: Record<string, string>;
|
||||
ssrfPolicy?: SsrFPolicy;
|
||||
};
|
||||
|
||||
export function normalizeBatchBaseUrl(client: BatchHttpClientConfig): string {
|
||||
return client.baseUrl?.replace(/\/$/, "") ?? "";
|
||||
}
|
||||
|
||||
export function buildBatchHeaders(
|
||||
client: Pick<BatchHttpClientConfig, "headers">,
|
||||
params: { json: boolean },
|
||||
): Record<string, string> {
|
||||
const headers = client.headers ? { ...client.headers } : {};
|
||||
if (params.json) {
|
||||
if (!headers["Content-Type"] && !headers["content-type"]) {
|
||||
headers["Content-Type"] = "application/json";
|
||||
}
|
||||
} else {
|
||||
delete headers["Content-Type"];
|
||||
delete headers["content-type"];
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
export function splitBatchRequests<T>(requests: T[], maxRequests: number): T[][] {
|
||||
if (requests.length <= maxRequests) {
|
||||
return [requests];
|
||||
}
|
||||
const groups: T[][] = [];
|
||||
for (let i = 0; i < requests.length; i += maxRequests) {
|
||||
groups.push(requests.slice(i, i + maxRequests));
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
Reference in New Issue
Block a user