@runappsai/agent 0.1.7 → 0.1.8

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.
@@ -1,4 +1,4 @@
1
- /* @runappsai/agent 0.1.7 (core) */
1
+ /* @runappsai/agent 0.1.8 (core) */
2
2
  "use strict";var RunAppsAgent=(()=>{var Me=Object.defineProperty;var gn=Object.getOwnPropertyDescriptor;var yn=Object.getOwnPropertyNames;var wn=Object.prototype.hasOwnProperty;var bn=(s,e,t)=>e in s?Me(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var kn=(s,e)=>{for(var t in e)Me(s,t,{get:e[t],enumerable:!0})},xn=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of yn(e))!wn.call(s,r)&&r!==t&&Me(s,r,{get:()=>e[r],enumerable:!(n=gn(e,r))||n.enumerable});return s};var vn=s=>xn(Me({},"__esModule",{value:!0}),s);var w=(s,e,t)=>bn(s,typeof e!="symbol"?e+"":e,t);var Pr={};kn(Pr,{Agent:()=>fe,ContextOverflowError:()=>G,DEFAULT_SKILLS_DIR:()=>wt,DEFAULT_USER_SKILLS_DIR:()=>bt,MCPError:()=>O,PartialReadError:()=>Q,ProviderError:()=>q,UNTITLED:()=>ae,Workspace:()=>oe,applyEdits:()=>Ne,askUserTool:()=>rt,buildSystemPrompt:()=>Ue,buildZip:()=>Ft,collectCompletion:()=>we,configurePdf:()=>qt,connectMCP:()=>pn,createAgent:()=>Tr,decodeText:()=>X,defineTool:()=>j,domUI:()=>nt,estimateTokens:()=>_,expandSlash:()=>De,extractPdfText:()=>qe,fileGuard:()=>le,fileTools:()=>Qe,fitBudget:()=>pe,formatPdfText:()=>Ke,groupTurns:()=>ot,guessType:()=>Y,isContextOverflow:()=>Ee,isPdf:()=>Be,listTemplates:()=>Ot,listZip:()=>ze,memoryFS:()=>Vt,modelAccepts:()=>_e,normalizeForFuzzyMatch:()=>pt,normalizePath:()=>x,normalizeResult:()=>be,nullUI:()=>At,openAIProvider:()=>_t,openWorkspace:()=>Ar,parseCommandArgs:()=>dt,parseFrontmatter:()=>ht,parseSkill:()=>xe,planCut:()=>Oe,readZipEntry:()=>ne,runInSandbox:()=>vt,runappsProvider:()=>it,sandboxTool:()=>tt,serializeConversation:()=>ye,skillFoldersOf:()=>ve,skillZipFS:()=>se,splitForSummary:()=>Le,sseData:()=>he,subFS:()=>Se,substituteArgs:()=>ft,summaryMessage:()=>me,summaryOf:()=>K,titleOf:()=>Ce,toProvider:()=>Z,validateSchema:()=>et});function _e(s,e){if(s){if(Array.isArray(s.input_modalities))return s.input_modalities.includes(e);if(e==="image"&&s.capability==="vision")return!0}}var q=class extends Error{constructor(t,n,r={}){super(n);w(this,"status");w(this,"code");w(this,"retryAfter");this.name="ProviderError",this.status=t,this.code=r.code,this.retryAfter=r.retryAfter}get statusCode(){return this.status}},Sn={attachments:"The attachments on this message are too large for the model's context",message:"This message is too long for the model's context",tools:"The connected tools take up too much of the model's context",history:"This conversation is too long for the model's context",model:"This request does not fit the model's context"},G=class extends q{constructor(t,n,r=400){super(r,Sn[t.cause],{code:"context_overflow"});w(this,"overflow");w(this,"detail");this.name="ContextOverflowError",this.overflow=t,this.detail=n}},Tn=/context[_ ]length|context[_ ]window|maximum context|(?:prompt|input|request|message)s? (?:is |are )?too (?:long|large)|too many (?:input |prompt )?tokens|prompt tokens too many|exceed\w* .{0,30}(?:context|token limit|input token)|input token count|max_input_tokens|range of input length|payload too large|entity too large/i;function Ee(s){if(s instanceof G)return!0;let e=Re(s);if(e===401||e===402||e===403||e===404||e===429)return!1;if(e===413)return!0;let t=s?.code;return t==="context_length_exceeded"||t==="context_overflow"?!0:s instanceof Error&&Tn.test(s.message)}function Mt(s){let e=s instanceof Error?s.message:"",n=/its ([\d,]+) max_input_tokens|maximum context length is ([\d,]+)|> ?([\d,]+) maximum|context (?:window|length) of ([\d,]+)|token limit\D{0,5}([\d,]+)|\[1, ?([\d,]+)\]/i.exec(e)?.slice(1).find(Boolean),r=n?Number(n.replace(/,/g,"")):NaN;return r>=1e3?r:void 0}function Re(s){if(!s||typeof s!="object")return;let e=s;return typeof e.statusCode=="number"?e.statusCode:typeof e.status=="number"?e.status:void 0}function it(s){let e=s.files;return{name:s.projectName,stream:(t,n)=>s.chat.stream(t,n),complete:s.chat.create?(t,n)=>s.chat.create(t,n):void 0,models:s.models?.list?async t=>await s.models.list(t):void 0,readFile:e?async(t,n)=>{let r=await e.stat(t);return n?.etag&&r.etag&&n.etag===r.etag?null:{bytes:new Uint8Array(await(await e.get(t)).arrayBuffer()),etag:r.etag}}:void 0}}function Z(s){if(typeof s.stream=="function")return s;if(typeof s.chat?.stream=="function")return it(s);throw new Error("pass a ModelProvider (with stream()) or a RunApps client")}function _t(s){let e=s.baseURL.replace(/\/+$/,""),t=s.fetch??((...i)=>fetch(...i)),n=()=>({"Content-Type":"application/json",...s.apiKey?{Authorization:`Bearer ${s.apiKey}`}:{},...s.headers??{}}),r=async(i,o)=>{let a;try{a=await t(`${e}/chat/completions`,{method:"POST",headers:n(),body:JSON.stringify(i),signal:o})}catch(l){throw o?.aborted?l:new q(0,`network error: ${l.message}`)}if(!a.ok)throw await $t(a);return a};return{name:s.name,async*stream(i,o){let a={...i,stream:!0,...s.streamUsage===!1?{}:{stream_options:{include_usage:!0}}},l=await r(a,o?.signal);if(!l.body)throw new q(0,"the response has no body to stream");for await(let c of he(l.body,o?.signal)){if(c==="[DONE]")return;let u;try{u=JSON.parse(c)}catch{continue}if(u.error)throw new q(500,u.error.message??"stream error",{code:u.error.code});yield u}},async complete(i,o){return await(await r({...i,stream:!1},o?.signal)).json()},models:s.models===void 0?void 0:async()=>{if(Array.isArray(s.models))return s.models;let i=await t(`${e}/models`,{headers:n()});if(!i.ok)throw await $t(i);return((await i.json()).data??[]).map(({id:a,is_default:l,capability:c,max_input_tokens:u,max_tokens:d,options:h})=>({id:a,is_default:l,capability:c??"text",max_input_tokens:u,max_tokens:d,options:h}))}}}async function $t(s){let e=`HTTP ${s.status}`,t;try{let r=await s.json();typeof r.error=="string"?e=r.error:r.error?.message?(e=r.error.message,t=r.error.code??r.error.type):r.message&&(e=r.message)}catch{}let n=Number(s.headers.get("Retry-After"));return new q(s.status,e,{code:t,retryAfter:Number.isFinite(n)&&n>0?n:void 0})}async function*he(s,e){let t=s.getReader(),n=new TextDecoder,r="",i=()=>{t.cancel().catch(()=>{})};e?.addEventListener("abort",i,{once:!0});try{for(;;){let{done:a,value:l}=await t.read();if(a)break;r+=n.decode(l,{stream:!0});let c;for(;(c=r.search(/\r?\n\r?\n/))>=0;){let u=r.slice(0,c);r=r.slice(c).replace(/^\r?\n\r?\n/,"");let d=u.split(/\r?\n/).filter(h=>h.startsWith("data:")).map(h=>h.slice(5).replace(/^ /,"")).join(`
3
3
  `);d&&(yield d)}}let o=r.split(/\r?\n/).filter(a=>a.startsWith("data:")).map(a=>a.slice(5).replace(/^ /,"")).join(`
4
4
  `);o&&(yield o)}finally{e?.removeEventListener("abort",i),t.releaseLock()}e?.throwIfAborted()}function Ue(s){let e=(s.now??new Date).toISOString().slice(0,10),t=[];t.push(`You are ${s.appName?`the assistant built into ${s.appName}`:"an assistant"}. Today is ${e}.`),s.instructions?.trim()&&t.push(s.instructions.trim()),s.agentsMd?.trim()&&t.push(`Project-specific instructions and guidelines: