@runappsai/agent 0.1.4 → 0.1.5
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/dist/agent-core.umd.js +1 -1
- package/dist/agent.umd.js +87 -87
- package/dist/chat.js +11 -5
- package/dist/ui.cjs +11 -4
- package/docs/chat-ui.md +1 -1
- package/package.json +1 -1
package/dist/agent-core.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @runappsai/agent 0.1.
|
|
1
|
+
/* @runappsai/agent 0.1.5 (core) */
|
|
2
2
|
"use strict";var RunAppsAgent=(()=>{var $e=Object.defineProperty;var mn=Object.getOwnPropertyDescriptor;var gn=Object.getOwnPropertyNames;var yn=Object.prototype.hasOwnProperty;var wn=(r,e,t)=>e in r?$e(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var bn=(r,e)=>{for(var t in e)$e(r,t,{get:e[t],enumerable:!0})},kn=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of gn(e))!yn.call(r,s)&&s!==t&&$e(r,s,{get:()=>e[s],enumerable:!(n=mn(e,s))||n.enumerable});return r};var xn=r=>kn($e({},"__esModule",{value:!0}),r);var y=(r,e,t)=>wn(r,typeof e!="symbol"?e+"":e,t);var Sr={};bn(Sr,{Agent:()=>fe,ContextOverflowError:()=>J,DEFAULT_SKILLS_DIR:()=>wt,DEFAULT_USER_SKILLS_DIR:()=>bt,MCPError:()=>_,PartialReadError:()=>Q,ProviderError:()=>B,UNTITLED:()=>ae,Workspace:()=>oe,applyEdits:()=>ze,askUserTool:()=>rt,buildSystemPrompt:()=>Re,buildZip:()=>Ft,collectCompletion:()=>we,configurePdf:()=>qt,connectMCP:()=>pn,createAgent:()=>xr,decodeText:()=>X,defineTool:()=>D,domUI:()=>nt,estimateTokens:()=>C,expandSlash:()=>Le,extractPdfText:()=>Be,fileGuard:()=>le,fileTools:()=>Qe,fitBudget:()=>he,formatPdfText:()=>qe,groupTurns:()=>ot,guessType:()=>Y,isContextOverflow:()=>Ee,isPdf:()=>We,listTemplates:()=>Ut,listZip:()=>Fe,memoryFS:()=>Vt,modelAccepts:()=>Me,normalizeForFuzzyMatch:()=>ht,normalizePath:()=>w,normalizeResult:()=>be,nullUI:()=>Tt,openAIProvider:()=>Mt,openWorkspace:()=>vr,parseCommandArgs:()=>dt,parseFrontmatter:()=>pt,parseSkill:()=>ke,planCut:()=>Ue,readZipEntry:()=>ne,runInSandbox:()=>xt,runappsProvider:()=>it,sandboxTool:()=>tt,serializeConversation:()=>ye,skillFoldersOf:()=>xe,skillZipFS:()=>se,splitForSummary:()=>Oe,sseData:()=>pe,subFS:()=>ve,substituteArgs:()=>ft,summaryMessage:()=>me,summaryOf:()=>K,titleOf:()=>Pe,toProvider:()=>Z,validateSchema:()=>et});function Me(r,e){if(r){if(Array.isArray(r.input_modalities))return r.input_modalities.includes(e);if(e==="image"&&r.capability==="vision")return!0}}var B=class extends Error{constructor(t,n,s={}){super(n);y(this,"status");y(this,"code");y(this,"retryAfter");this.name="ProviderError",this.status=t,this.code=s.code,this.retryAfter=s.retryAfter}get statusCode(){return this.status}},vn={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"},J=class extends B{constructor(t,n,s=400){super(s,vn[t.cause],{code:"context_overflow"});y(this,"overflow");y(this,"detail");this.name="ContextOverflowError",this.overflow=t,this.detail=n}},Sn=/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(r){if(r instanceof J)return!0;let e=_e(r);if(e===401||e===402||e===403||e===404||e===429)return!1;if(e===413)return!0;let t=r?.code;return t==="context_length_exceeded"||t==="context_overflow"?!0:r instanceof Error&&Sn.test(r.message)}function $t(r){let e=r instanceof Error?r.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),s=n?Number(n.replace(/,/g,"")):NaN;return s>=1e3?s:void 0}function _e(r){if(!r||typeof r!="object")return;let e=r;return typeof e.statusCode=="number"?e.statusCode:typeof e.status=="number"?e.status:void 0}function it(r){let e=r.files;return{name:r.projectName,stream:(t,n)=>r.chat.stream(t,n),complete:r.chat.create?(t,n)=>r.chat.create(t,n):void 0,models:r.models?.list?async t=>await r.models.list(t):void 0,readFile:e?async(t,n)=>{let s=await e.stat(t);return n?.etag&&s.etag&&n.etag===s.etag?null:{bytes:new Uint8Array(await(await e.get(t)).arrayBuffer()),etag:s.etag}}:void 0}}function Z(r){if(typeof r.stream=="function")return r;if(typeof r.chat?.stream=="function")return it(r);throw new Error("pass a ModelProvider (with stream()) or a RunApps client")}function Mt(r){let e=r.baseURL.replace(/\/+$/,""),t=r.fetch??((...i)=>fetch(...i)),n=()=>({"Content-Type":"application/json",...r.apiKey?{Authorization:`Bearer ${r.apiKey}`}:{},...r.headers??{}}),s=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 B(0,`network error: ${l.message}`)}if(!a.ok)throw await Ct(a);return a};return{name:r.name,async*stream(i,o){let a={...i,stream:!0,...r.streamUsage===!1?{}:{stream_options:{include_usage:!0}}},l=await s(a,o?.signal);if(!l.body)throw new B(0,"the response has no body to stream");for await(let c of pe(l.body,o?.signal)){if(c==="[DONE]")return;let u;try{u=JSON.parse(c)}catch{continue}if(u.error)throw new B(500,u.error.message??"stream error",{code:u.error.code});yield u}},async complete(i,o){return await(await s({...i,stream:!1},o?.signal)).json()},models:r.models===void 0?void 0:async()=>{if(Array.isArray(r.models))return r.models;let i=await t(`${e}/models`,{headers:n()});if(!i.ok)throw await Ct(i);return((await i.json()).data??[]).map(({id:a,is_default:l,capability:c,max_input_tokens:u,max_tokens:d,options:p})=>({id:a,is_default:l,capability:c??"text",max_input_tokens:u,max_tokens:d,options:p}))}}}async function Ct(r){let e=`HTTP ${r.status}`,t;try{let s=await r.json();typeof s.error=="string"?e=s.error:s.error?.message?(e=s.error.message,t=s.error.code??s.error.type):s.message&&(e=s.message)}catch{}let n=Number(r.headers.get("Retry-After"));return new B(r.status,e,{code:t,retryAfter:Number.isFinite(n)&&n>0?n:void 0})}async function*pe(r,e){let t=r.getReader(),n=new TextDecoder,s="",i=()=>{t.cancel().catch(()=>{})};e?.addEventListener("abort",i,{once:!0});try{for(;;){let{done:a,value:l}=await t.read();if(a)break;s+=n.decode(l,{stream:!0});let c;for(;(c=s.search(/\r?\n\r?\n/))>=0;){let u=s.slice(0,c);s=s.slice(c).replace(/^\r?\n\r?\n/,"");let d=u.split(/\r?\n/).filter(p=>p.startsWith("data:")).map(p=>p.slice(5).replace(/^ /,"")).join(`
|
|
3
3
|
`);d&&(yield d)}}let o=s.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 Re(r){let e=(r.now??new Date).toISOString().slice(0,10),t=[];t.push(`You are ${r.appName?`the assistant built into ${r.appName}`:"an assistant"}. Today is ${e}.`),r.instructions?.trim()&&t.push(r.instructions.trim()),r.agentsMd?.trim()&&t.push(`Project-specific instructions and guidelines:
|