UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 2.51 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-DuCQi-Qb.mjs";import{i as MODEL_CATALOG_THINKING_LEVELS}from"./model-catalog-types-C-uYZJxd.mjs";import{f as isLoopbackIpAddress}from"./ip-DwojXwyb.mjs"; //!src/worker/native-runtime-transport.ts 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}}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`})}} //!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`);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()});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)});export{buildNativeRuntimeFetch as i,NativeRuntimeIdentifier as n,NativeRuntimeModelSchema as r,NativeRuntimeConfigSchema as t};