UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

72 lines (71 loc) • 3.21 kB
import { Et as _enum, Jn as string, Ln as partialRecord, Lt as boolean, Nt as array, Pn as number, Un as record, qn as strictObject } from "./schemas-Cy6abvsu.mjs"; import { i as MODEL_CATALOG_THINKING_LEVELS } from "./model-catalog-types-DFHCZ2Xr.mjs"; import { f as isLoopbackIpAddress } from "./ip-BUyyYvdK.mjs"; //#region src/worker/native-runtime-transport.ts /** Explicit loopback literals support same-host proxies and isolated wire proof without DNS. */ function isNativeRuntimeEndpoint(e) { try { const t = new URL(e); return (t.protocol === "https:" || t.protocol === "http:" && isLoopbackIpAddress(t.hostname)) && !t.username && !t.password && !t.search && !t.hash && !/[{}]/.test(e); } catch { return false; } } /** The operator selects one origin, not an authority to replay credentials through redirects. */ function buildNativeRuntimeFetch(e) { if (!isNativeRuntimeEndpoint(e.baseUrl)) throw new Error("Native inference requires HTTPS or a literal loopback HTTP endpoint"); const t = new URL(e.baseUrl).origin; const n = globalThis.fetch; return (e, r) => { const i = new URL(typeof e === "string" ? e : e instanceof URL ? e.href : e.url); if (i.origin !== t || i.username || i.password) throw new Error("Native inference request left its configured endpoint origin"); return n(e, { ...r, redirect: "error" }); }; } //#endregion //#region src/worker/native-runtime-config.ts const ThinkingSchema = _enum(MODEL_CATALOG_THINKING_LEVELS); const NativeRuntimeIdentifier = string().trim().min(1).max(256); const provider = NativeRuntimeIdentifier.refine((e) => !e.includes("/"), "Provider must not contain /"); const baseUrl = string().url().refine(isNativeRuntimeEndpoint, "Expected HTTPS (or literal loopback HTTP) without credentials, query, or placeholders"); /** Trusted local startup configuration, never a turn-wire configuration surface. */ const NativeRuntimeModelSchema = strictObject({ provider, id: NativeRuntimeIdentifier, api: NativeRuntimeIdentifier, baseUrl, name: NativeRuntimeIdentifier.optional(), contextWindow: number().int().positive(), maxTokens: number().int().positive(), reasoning: boolean().optional(), thinkingLevelMap: partialRecord(ThinkingSchema, string().nullable()).optional(), cost: strictObject({ input: number().finite().nonnegative(), output: number().finite().nonnegative(), cacheRead: number().finite().nonnegative(), cacheWrite: number().finite().nonnegative() }), input: array(_enum(["text", "image"])).min(1).optional(), headers: record(string(), string()).optional() }); /** Canonical node models and exact workspace projected into one trusted worker child. */ const NativeRuntimeConfigSchema = strictObject({ models: array(NativeRuntimeModelSchema).min(1).superRefine((e, t) => { const n = /* @__PURE__ */ new Set(); e.forEach((e, r) => { const i = `${e.provider}/${e.id}`; if (n.has(i)) t.addIssue({ code: "custom", path: [r], message: "Duplicate native runtime model" }); n.add(i); }); }), workspace: string().trim().min(1) }); //#endregion export { buildNativeRuntimeFetch as i, NativeRuntimeIdentifier as n, NativeRuntimeModelSchema as r, NativeRuntimeConfigSchema as t };