eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.72 kB
JavaScript
import{DEFAULT_AGENT_MODEL_ID}from"#shared/default-agent-model.js";import{AI_GATEWAY_MODELS_URL}from"#internal/gateway.js";import{defineTool}from"eve/tools";import{parseGatewayModelCatalog}from"#shared/gateway-model-catalog.js";const inputSchema={type:`object`,additionalProperties:!1,properties:{query:{type:`string`,minLength:1,maxLength:100,description:`A full model ID, model name, or short name such as 'luna'.`}},required:[`query`]},outputSchema={type:`object`,additionalProperties:!1,properties:{models:{type:`array`,items:{type:`object`,additionalProperties:!1,properties:{id:{type:`string`},name:{type:`string`},provider:{type:`string`}},required:[`id`,`name`,`provider`]}}},required:[`models`]};function searchGatewayModels(e,t){let n=t.trim().toLowerCase();return e.filter(e=>e.type===`language`&&(e.id===DEFAULT_AGENT_MODEL_ID||e.tags?.includes(`web-search`))&&(e.id.toLowerCase().includes(n)||e.name.toLowerCase().includes(n))).slice(0,20).map(e=>({id:e.id,name:e.name,provider:e.id.split(`/`)[0]??``}))}var search_models_default=defineTool({description:`Search the Vercel AI Gateway model catalog. Call this to list available AI Gateway models or resolve a model to its exact ID.`,inputSchema,outputSchema,async execute(e,t){if(typeof e.query!=`string`)throw Error(`Expected a model search query.`);let n=new AbortController,r=setTimeout(()=>n.abort(),5e3);try{let r=AbortSignal.any([t.abortSignal,n.signal]),i=await fetch(AI_GATEWAY_MODELS_URL,{signal:r});if(!i.ok)throw Error(`AI Gateway model catalog request failed (${i.status}).`);return{models:searchGatewayModels(parseGatewayModelCatalog(await i.json()),e.query)}}finally{clearTimeout(r)}}});export{search_models_default as default,searchGatewayModels};