@augmentcode/auggie 1.2.0-prerelease.202610150920 → 1.2.0-prerelease.202610151518
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/auggie-v2.mjs +1593 -1583
- package/auggie-v2.mjs.d/extensions/mcp/index.js +1 -1
- package/indexing-worker.mjs +44 -44
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ Available tools on MCP server "{{server_name}}":
|
|
|
14
14
|
{{tool_list}}
|
|
15
15
|
|
|
16
16
|
Respond with ONLY the tool name (no markdown, no explanation).`,SM=/[\n\r]/g,wM=/</g,bM=/>/g;function fn(t){return t.replace(SM," ").replace(wM,"\u2039").replace(bM,"\u203A").trim()}function RM(){let t=process.env[vM];return t?.trim()?t:_M}var CM=/\{\{(query|server_name|tool_list)\}\}/g;function Tg(t,e,r){let n={"{{query}}":fn(t),"{{server_name}}":fn(e),"{{tool_list}}":r};return RM().replace(CM,o=>n[o]??o)}function Pe(t){return{content:[{type:"text",text:t}],details:void 0}}function Ag(t){return[...t].sort((e,r)=>e.name.localeCompare(r.name))}function md(t){return{tool_name:t.name,description:t.description??"",input_schema:t.inputSchema??{}}}function _a(t,e,r){let n={mcp_server:t,tools:Ag(e).map(md),note:r};return Pe(JSON.stringify(n,null,2))}function Mg(t){return Ag(t).map(e=>{let r=fn(e.name),n=fn(e.description??"");return`- ${r}: ${n}`}).join(`
|
|
17
|
-
`)}function $g(t){let e=t.trim();try{let r=JSON.parse(e);if(typeof r.tool_name=="string")return r.tool_name}catch{}return e}import{complete as PM}from"@earendil-works/pi-ai";var xM="augment:tool-search-usage";function kM(t){let e="";for(let r of t.content)r.type==="text"&&(e+=r.text);return e.trim()}async function Ig(t,e,r){let n=e.model;if(!n)return;let o=await e.modelRegistry.getApiKeyAndHeaders(n);if(!(o.ok&&o.apiKey))return;let i={role:"user",content:[{type:"text",text:r}],timestamp:Date.now()},s=await PM(n,{messages:[i]},{apiKey:o.apiKey,headers:o.headers,signal:e.signal}),a={model:s.model,usage:s.usage};return t.events.emit(xM,a),kM(s)}var Dg=EM.child({prefix:"pi-mcp"}),oo="find-tool",zr="execute-tool",TM=10,Ng=15,AM=20,MM={type:"object",properties:{query:{type:"string",description:"Detailed description of the task you need a tool for: the action (create, read, search, delete, \u2026), the target resource, and relevant context (field names, filters). More specific queries match better."},mcp_server:{type:"string",description:"Name of the MCP server to search."}},required:["query","mcp_server"]},$M={type:"object",properties:{mcp_server:{type:"string",description:"Name of the MCP server hosting the tool."},tool_name:{type:"string",description:"Original MCP tool name returned by find-tool."},arguments:{type:"object",description:"Arguments object to pass to the tool."}},required:["mcp_server","tool_name","arguments"]};function gd(t){return t.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{M}\p{N}]+/gu," ").trim().replace(/\s+/g," ")}function IM(t){let e=[...te().servers.values()].filter(c=>c.status==="success"),r=e.find(c=>c.name===t);if(r)return{server:r,name:r.name};let n=gd(t),o=e.filter(c=>n.length>0&&gd(c.name)===n);if(o.length===1){let[c]=o;return{server:c,name:c.name}}let i=n.split(" ").filter(Boolean),s=e.filter(c=>{let u=new Set(gd(c.name).split(" "));return n.length>0&&i.every(d=>u.has(d))});if(s.length===1){let[c]=s;return{server:c,name:c.name}}let a=[...o,...s].map(c=>c.name).filter((c,u,d)=>d.indexOf(c)===u).sort();if(a.length>1){let c=e.map(u=>u.name).sort();throw new Error(`MCP server name "${t}" is ambiguous. Matching servers: ${a.join(", ")}. Use an exact server name. Available servers: ${c.join(", ")}.`)}}function Lg(t,e){let r=te(),n=t.getAllTools().map(u=>u.name);if(!n.includes(e)){let u=e.trim().toLowerCase(),d=ln(r).find(l=>l.id===e.trim()||l.name.toLowerCase()===u);if(d)throw new Error(`MCP server "${d.name}" is available but not attached. Call attach-mcp-server now with config_id "${d.id}"; it attaches directly without requiring user approval.`)}let o=n.includes(e)?void 0:IM(e);if(o)return o;let i=t.getActiveTools(),s=r.servers.get(e),a=[...r.servers.values()].filter(u=>u.status==="success").map(u=>u.name).sort(),c=ha(e,s?.status,n,i);throw new Error(`${c} Available servers: ${a.join(", ")||"none"}.`)}function OM(t){if(t==null)throw new Error(`${zr} requires an "arguments" object with the tool's parameters.`);if(typeof t!="object"||Array.isArray(t)){let e=Array.isArray(t)?"an array":typeof t;throw new Error(`${zr} "arguments" must be an object, not ${e}.`)}return t}async function zM(t,e,r,n,o){let i=Tg(r,n,Mg(o)),s=await Ig(t,e,i);if(!s)return;let a=$g(s);return o.find(c=>c.name===a)}async function NM(t,e,r){let{query:n,mcp_server:o}=r??{};if(typeof n!="string"||typeof o!="string")throw new Error(`${oo} requires string "query" and "mcp_server" parameters.`);let i=Lg(t,o),s=i.server.listTools();if(s.length===0)throw new Error(`No tools available on MCP server "${i.name}".`);if(s.length<=TM)return _a(i.name,s,"All tools on this server.");try{let a=await zM(t,e,n,i.name,s);return a?Pe(JSON.stringify(md(a),null,2)):_a(i.name,s,"No single best match; all tools listed.")}catch(a){return Dg.warn(`${oo} LLM match failed: ${a instanceof Error?a.message:String(a)}`),_a(i.name,s,"Search failed; all tools listed.")}}async function DM(t,e,r,n){let{mcp_server:o,tool_name:i,arguments:s}=e??{};if(typeof o!="string"||typeof i!="string")throw new Error(`${zr} requires string "mcp_server" and "tool_name" parameters.`);let a=OM(s),c=Lg(t,o),u=await c.server.callTool(i,a,r,n);return ud(u,c.name,i)}function LM(){let t=te(),e=[...t.servers.values()].filter(i=>i.status==="success"),r=`Search for the right MCP tool. Call with a natural-language query and the target MCP server name to get the best-matching tool, then run it with ${zr}. When this gateway is present, MCP tools may intentionally be absent as top-level tools. Before reporting an expected MCP capability unavailable, search its attached server with ${oo}, then invoke it with ${zr}.`,n=[];if(e.length===0)n.push(`${r} No MCP servers are currently connected.`);else{let i=e.map(s=>{let a=s.listTools().map(d=>d.name),c=a.slice(0,Ng).join(", "),u=a.length>Ng?", \u2026":"";return`- ${s.name} (${a.length} tool(s): ${c}${u})`});n.push(`${r} Available MCP servers:
|
|
17
|
+
`)}function $g(t){let e=t.trim();try{let r=JSON.parse(e);if(typeof r.tool_name=="string")return r.tool_name}catch{}return e}import{complete as PM}from"@earendil-works/pi-ai";var xM="augment:tool-search-usage";function kM(t){let e="";for(let r of t.content)r.type==="text"&&(e+=r.text);return e.trim()}async function Ig(t,e,r){let n=e.model;if(!n)return;let o=await e.modelRegistry.getApiKeyAndHeaders(n);if(!(o.ok&&o.apiKey))return;let i={role:"user",content:[{type:"text",text:r}],timestamp:Date.now()},s=await PM(o.baseUrl?{...n,baseUrl:o.baseUrl}:n,{messages:[i]},{apiKey:o.apiKey,headers:o.headers,signal:e.signal}),a={model:s.model,usage:s.usage};return t.events.emit(xM,a),kM(s)}var Dg=EM.child({prefix:"pi-mcp"}),oo="find-tool",zr="execute-tool",TM=10,Ng=15,AM=20,MM={type:"object",properties:{query:{type:"string",description:"Detailed description of the task you need a tool for: the action (create, read, search, delete, \u2026), the target resource, and relevant context (field names, filters). More specific queries match better."},mcp_server:{type:"string",description:"Name of the MCP server to search."}},required:["query","mcp_server"]},$M={type:"object",properties:{mcp_server:{type:"string",description:"Name of the MCP server hosting the tool."},tool_name:{type:"string",description:"Original MCP tool name returned by find-tool."},arguments:{type:"object",description:"Arguments object to pass to the tool."}},required:["mcp_server","tool_name","arguments"]};function gd(t){return t.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{M}\p{N}]+/gu," ").trim().replace(/\s+/g," ")}function IM(t){let e=[...te().servers.values()].filter(c=>c.status==="success"),r=e.find(c=>c.name===t);if(r)return{server:r,name:r.name};let n=gd(t),o=e.filter(c=>n.length>0&&gd(c.name)===n);if(o.length===1){let[c]=o;return{server:c,name:c.name}}let i=n.split(" ").filter(Boolean),s=e.filter(c=>{let u=new Set(gd(c.name).split(" "));return n.length>0&&i.every(d=>u.has(d))});if(s.length===1){let[c]=s;return{server:c,name:c.name}}let a=[...o,...s].map(c=>c.name).filter((c,u,d)=>d.indexOf(c)===u).sort();if(a.length>1){let c=e.map(u=>u.name).sort();throw new Error(`MCP server name "${t}" is ambiguous. Matching servers: ${a.join(", ")}. Use an exact server name. Available servers: ${c.join(", ")}.`)}}function Lg(t,e){let r=te(),n=t.getAllTools().map(u=>u.name);if(!n.includes(e)){let u=e.trim().toLowerCase(),d=ln(r).find(l=>l.id===e.trim()||l.name.toLowerCase()===u);if(d)throw new Error(`MCP server "${d.name}" is available but not attached. Call attach-mcp-server now with config_id "${d.id}"; it attaches directly without requiring user approval.`)}let o=n.includes(e)?void 0:IM(e);if(o)return o;let i=t.getActiveTools(),s=r.servers.get(e),a=[...r.servers.values()].filter(u=>u.status==="success").map(u=>u.name).sort(),c=ha(e,s?.status,n,i);throw new Error(`${c} Available servers: ${a.join(", ")||"none"}.`)}function OM(t){if(t==null)throw new Error(`${zr} requires an "arguments" object with the tool's parameters.`);if(typeof t!="object"||Array.isArray(t)){let e=Array.isArray(t)?"an array":typeof t;throw new Error(`${zr} "arguments" must be an object, not ${e}.`)}return t}async function zM(t,e,r,n,o){let i=Tg(r,n,Mg(o)),s=await Ig(t,e,i);if(!s)return;let a=$g(s);return o.find(c=>c.name===a)}async function NM(t,e,r){let{query:n,mcp_server:o}=r??{};if(typeof n!="string"||typeof o!="string")throw new Error(`${oo} requires string "query" and "mcp_server" parameters.`);let i=Lg(t,o),s=i.server.listTools();if(s.length===0)throw new Error(`No tools available on MCP server "${i.name}".`);if(s.length<=TM)return _a(i.name,s,"All tools on this server.");try{let a=await zM(t,e,n,i.name,s);return a?Pe(JSON.stringify(md(a),null,2)):_a(i.name,s,"No single best match; all tools listed.")}catch(a){return Dg.warn(`${oo} LLM match failed: ${a instanceof Error?a.message:String(a)}`),_a(i.name,s,"Search failed; all tools listed.")}}async function DM(t,e,r,n){let{mcp_server:o,tool_name:i,arguments:s}=e??{};if(typeof o!="string"||typeof i!="string")throw new Error(`${zr} requires string "mcp_server" and "tool_name" parameters.`);let a=OM(s),c=Lg(t,o),u=await c.server.callTool(i,a,r,n);return ud(u,c.name,i)}function LM(){let t=te(),e=[...t.servers.values()].filter(i=>i.status==="success"),r=`Search for the right MCP tool. Call with a natural-language query and the target MCP server name to get the best-matching tool, then run it with ${zr}. When this gateway is present, MCP tools may intentionally be absent as top-level tools. Before reporting an expected MCP capability unavailable, search its attached server with ${oo}, then invoke it with ${zr}.`,n=[];if(e.length===0)n.push(`${r} No MCP servers are currently connected.`);else{let i=e.map(s=>{let a=s.listTools().map(d=>d.name),c=a.slice(0,Ng).join(", "),u=a.length>Ng?", \u2026":"";return`- ${s.name} (${a.length} tool(s): ${c}${u})`});n.push(`${r} Available MCP servers:
|
|
18
18
|
${i.join(`
|
|
19
19
|
`)}`)}let o=ln(t).slice(0,AM);if(o.length>0){let i=o.map(s=>{let a=fn(s.description),c=s.requiresAuth?" [requires auth]":"";return`- ${s.name}${a?` \u2014 ${a}`:""}${c}`});n.push(`Available but not attached (use attach-mcp-server to enable):
|
|
20
20
|
${i.join(`
|