@buoy-gg/agent-core 7.0.54 → 7.0.56
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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.HOSTED_PROTOCOL_VERSION=exports.HOSTED_HEADERS=exports.HOSTED_ERRORS=void 0;exports.isHostedErrorCode=isHostedErrorCode;const HOSTED_PROTOCOL_VERSION=exports.HOSTED_PROTOCOL_VERSION=1;const HOSTED_HEADERS=exports.HOSTED_HEADERS={session:"X-Buoy-Session",ask:"X-Buoy-Ask",round:"X-Buoy-Round",attempt:"X-Buoy-Attempt",protocol:"X-Buoy-Protocol",client:"X-Buoy-Client",requestId:"X-Buoy-Request-Id"};const HOSTED_ERRORS=exports.HOSTED_ERRORS={session_missing:{status:401,action:"sign_in",message:"Sign in to use hosted Ask Buoy.",buttons:["sign_in"]},session_expired:{status:401,action:"refresh_retry",message:"Your sign-in ran out. Sign in again.",buttons:["sign_in"]},session_revoked:{status:401,action:"sign_in",message:"You were signed out. Sign in again.",buttons:["sign_in"]},token_not_allowed:{status:401,action:"sign_in",message:"This sign-in can't use hosted AI. Sign in as a person.",buttons:["sign_in"]},client_too_old:{status:426,action:"none",message:"Update Buoy to keep using hosted Ask Buoy.",buttons:[]},plan_not_eligible:{status:403,action:"none",message:"Hosted Ask Buoy comes with Pro and Business.",buttons:["see_plans"]},not_in_pilot:{status:403,action:"none",message:"Hosted Ask Buoy is in a small test right now.",buttons:[]},team_hosted_off:{status:403,action:"none",message:"Your team admin turned off hosted AI.",buttons:[]},account_frozen:{status:403,action:"none",message:"Your account has a billing problem.",buttons:["billing"]},credits_out:{status:402,action:"none",message:"You used this
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.HOSTED_PROTOCOL_VERSION=exports.HOSTED_HEADERS=exports.HOSTED_ERRORS=void 0;exports.isHostedErrorCode=isHostedErrorCode;const HOSTED_PROTOCOL_VERSION=exports.HOSTED_PROTOCOL_VERSION=1;const HOSTED_HEADERS=exports.HOSTED_HEADERS={session:"X-Buoy-Session",ask:"X-Buoy-Ask",round:"X-Buoy-Round",attempt:"X-Buoy-Attempt",protocol:"X-Buoy-Protocol",client:"X-Buoy-Client",requestId:"X-Buoy-Request-Id"};const HOSTED_ERRORS=exports.HOSTED_ERRORS={session_missing:{status:401,action:"sign_in",message:"Sign in to use hosted Ask Buoy.",buttons:["sign_in"]},session_expired:{status:401,action:"refresh_retry",message:"Your sign-in ran out. Sign in again.",buttons:["sign_in"]},session_revoked:{status:401,action:"sign_in",message:"You were signed out. Sign in again.",buttons:["sign_in"]},token_not_allowed:{status:401,action:"sign_in",message:"This sign-in can't use hosted AI. Sign in as a person.",buttons:["sign_in"]},client_too_old:{status:426,action:"none",message:"Update Buoy to keep using hosted Ask Buoy.",buttons:[]},plan_not_eligible:{status:403,action:"none",message:"Hosted Ask Buoy comes with Pro and Business.",buttons:["see_plans"]},not_in_pilot:{status:403,action:"none",message:"Hosted Ask Buoy is in a small test right now.",buttons:[]},team_hosted_off:{status:403,action:"none",message:"Your team admin turned off hosted AI.",buttons:[]},account_frozen:{status:403,action:"none",message:"Your account has a billing problem.",buttons:["billing"]},credits_out:{status:402,action:"none",message:"You used this week's credits. They come back on {date}.",buttons:["own_endpoint"]},member_cap:{status:402,action:"none",message:"You hit your team's limit for you. Ask your admin.",buttons:[]},ask_too_costly:{status:402,action:"none",message:"This ask got too big. Try a smaller ask.",buttons:[]},ask_busy:{status:409,action:"retry_after",message:"Another ask is still running.",buttons:[]},duplicate_request:{status:409,action:"none",message:"That was already sent.",buttons:[]},request_too_large:{status:413,action:"trim_retry",message:"This chat got too long. Start a new chat.",buttons:["new_chat"]},media_not_allowed:{status:400,action:"none",message:"Hosted Ask Buoy can't read images yet.",buttons:[]},bad_request:{status:400,action:"none",message:"Something in the request was wrong.",buttons:["report"]},rate_limited:{status:429,action:"retry_after",message:"Too many asks at once. Trying again.",buttons:[]},hosted_paused:{status:503,action:"none",message:"Hosted AI is paused right now.",buttons:["own_endpoint"]},upstream_busy:{status:503,action:"retry_after",message:"The AI is busy. Trying again.",buttons:[]},upstream_error:{status:502,action:"retry_after",message:"The AI had a problem.",buttons:["try_again","report"]},upstream_refused:{status:403,action:"none",message:"The AI would not answer that.",buttons:["report"]},internal:{status:500,action:"none",message:"Something broke on our side.",buttons:["try_again","report"]}};function isHostedErrorCode(t){return typeof t==="string"&&Object.prototype.hasOwnProperty.call(HOSTED_ERRORS,t)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";export const HOSTED_PROTOCOL_VERSION=1;export const HOSTED_HEADERS={session:"X-Buoy-Session",ask:"X-Buoy-Ask",round:"X-Buoy-Round",attempt:"X-Buoy-Attempt",protocol:"X-Buoy-Protocol",client:"X-Buoy-Client",requestId:"X-Buoy-Request-Id"};export const HOSTED_ERRORS={session_missing:{status:401,action:"sign_in",message:"Sign in to use hosted Ask Buoy.",buttons:["sign_in"]},session_expired:{status:401,action:"refresh_retry",message:"Your sign-in ran out. Sign in again.",buttons:["sign_in"]},session_revoked:{status:401,action:"sign_in",message:"You were signed out. Sign in again.",buttons:["sign_in"]},token_not_allowed:{status:401,action:"sign_in",message:"This sign-in can't use hosted AI. Sign in as a person.",buttons:["sign_in"]},client_too_old:{status:426,action:"none",message:"Update Buoy to keep using hosted Ask Buoy.",buttons:[]},plan_not_eligible:{status:403,action:"none",message:"Hosted Ask Buoy comes with Pro and Business.",buttons:["see_plans"]},not_in_pilot:{status:403,action:"none",message:"Hosted Ask Buoy is in a small test right now.",buttons:[]},team_hosted_off:{status:403,action:"none",message:"Your team admin turned off hosted AI.",buttons:[]},account_frozen:{status:403,action:"none",message:"Your account has a billing problem.",buttons:["billing"]},credits_out:{status:402,action:"none",message:"You used this
|
|
1
|
+
"use strict";export const HOSTED_PROTOCOL_VERSION=1;export const HOSTED_HEADERS={session:"X-Buoy-Session",ask:"X-Buoy-Ask",round:"X-Buoy-Round",attempt:"X-Buoy-Attempt",protocol:"X-Buoy-Protocol",client:"X-Buoy-Client",requestId:"X-Buoy-Request-Id"};export const HOSTED_ERRORS={session_missing:{status:401,action:"sign_in",message:"Sign in to use hosted Ask Buoy.",buttons:["sign_in"]},session_expired:{status:401,action:"refresh_retry",message:"Your sign-in ran out. Sign in again.",buttons:["sign_in"]},session_revoked:{status:401,action:"sign_in",message:"You were signed out. Sign in again.",buttons:["sign_in"]},token_not_allowed:{status:401,action:"sign_in",message:"This sign-in can't use hosted AI. Sign in as a person.",buttons:["sign_in"]},client_too_old:{status:426,action:"none",message:"Update Buoy to keep using hosted Ask Buoy.",buttons:[]},plan_not_eligible:{status:403,action:"none",message:"Hosted Ask Buoy comes with Pro and Business.",buttons:["see_plans"]},not_in_pilot:{status:403,action:"none",message:"Hosted Ask Buoy is in a small test right now.",buttons:[]},team_hosted_off:{status:403,action:"none",message:"Your team admin turned off hosted AI.",buttons:[]},account_frozen:{status:403,action:"none",message:"Your account has a billing problem.",buttons:["billing"]},credits_out:{status:402,action:"none",message:"You used this week's credits. They come back on {date}.",buttons:["own_endpoint"]},member_cap:{status:402,action:"none",message:"You hit your team's limit for you. Ask your admin.",buttons:[]},ask_too_costly:{status:402,action:"none",message:"This ask got too big. Try a smaller ask.",buttons:[]},ask_busy:{status:409,action:"retry_after",message:"Another ask is still running.",buttons:[]},duplicate_request:{status:409,action:"none",message:"That was already sent.",buttons:[]},request_too_large:{status:413,action:"trim_retry",message:"This chat got too long. Start a new chat.",buttons:["new_chat"]},media_not_allowed:{status:400,action:"none",message:"Hosted Ask Buoy can't read images yet.",buttons:[]},bad_request:{status:400,action:"none",message:"Something in the request was wrong.",buttons:["report"]},rate_limited:{status:429,action:"retry_after",message:"Too many asks at once. Trying again.",buttons:[]},hosted_paused:{status:503,action:"none",message:"Hosted AI is paused right now.",buttons:["own_endpoint"]},upstream_busy:{status:503,action:"retry_after",message:"The AI is busy. Trying again.",buttons:[]},upstream_error:{status:502,action:"retry_after",message:"The AI had a problem.",buttons:["try_again","report"]},upstream_refused:{status:403,action:"none",message:"The AI would not answer that.",buttons:["report"]},internal:{status:500,action:"none",message:"Something broke on our side.",buttons:["try_again","report"]}};export function isHostedErrorCode(t){return typeof t==="string"&&Object.prototype.hasOwnProperty.call(HOSTED_ERRORS,t)}
|
|
@@ -107,7 +107,7 @@ export declare const HOSTED_ERRORS: {
|
|
|
107
107
|
readonly credits_out: {
|
|
108
108
|
readonly status: 402;
|
|
109
109
|
readonly action: "none";
|
|
110
|
-
readonly message: "You used this
|
|
110
|
+
readonly message: "You used this week's credits. They come back on {date}.";
|
|
111
111
|
readonly buttons: readonly ["own_endpoint"];
|
|
112
112
|
};
|
|
113
113
|
readonly member_cap: {
|
package/lib/web/index.mjs
CHANGED
|
@@ -21,7 +21,7 @@ Use it to get a clean baseline right before reproducing a bug (clearEvents -> re
|
|
|
21
21
|
`),v=d.flatMap(m=>m.inputExamples??[]);l.push({name:Fe(i.toolId),...v.length?{inputExamples:v}:{},description:g,summaryDescription:u,actionsBlock:h,inputSchema:{type:"object",properties:{action:{type:"string",enum:d.map(m=>m.action),description:"Which action to run. See the list in this tool's description."},params:{type:"object",description:"Arguments for the action. Each action's `params:` line in this tool's description lists its exact fields \u2014 `*` marks a required one. Send EXACTLY those names; a field that is not listed is rejected."}},required:["action"],additionalProperties:false}})}return l}function Ve(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Qa(e,t){switch(t){case"integer":return typeof e=="number"&&Number.isInteger(e);case"number":return typeof e=="number"&&Number.isFinite(e);case"null":return e===null;case"array":return Array.isArray(e);case"object":return Ve(e)==="object";default:return typeof e===t}}function nt(e,t,r,a){if(t.anyOf?.length){if(!t.anyOf.some(o=>{let s=[];return nt(e,o,r,s),s.length===0})){let o=t.anyOf.map(s=>s.type??"?").join(" | ");a.push(`${r}: expected ${o}, got ${Ve(e)}`)}return}if(t.type&&!Qa(e,t.type)){a.push(`${r}: expected ${t.type}, got ${Ve(e)}`);return}if(t.enum&&!t.enum.includes(e)){a.push(`${r}: expected one of ${t.enum.map(o=>JSON.stringify(o)).join(", ")}, got ${JSON.stringify(e)}`);return}if(t.type==="array"&&Array.isArray(e)){t.minItems!==void 0&&e.length<t.minItems&&a.push(`${r}: expected at least ${t.minItems} item(s), got ${e.length}`),t.maxItems!==void 0&&e.length>t.maxItems&&a.push(`${r}: expected at most ${t.maxItems} item(s), got ${e.length}`),t.items&&e.forEach((o,s)=>nt(o,t.items,`${r}[${s}]`,a));return}if(t.type==="object"&&Ve(e)==="object"){let o=e;for(let s of t.required??[])o[s]===void 0&&a.push(`${r}.${s}: required`);if(t.properties){for(let[s,l]of Object.entries(t.properties))o[s]!==void 0&&nt(o[s],l,`${r}.${s}`,a);if(t.additionalProperties===false){let s=new Set(Object.keys(t.properties));for(let l of Object.keys(o))s.has(l)||a.push(`${r}.${l}: unexpected property`)}}}}function xe(e,t){let r=[];return nt(e??{},t,"params",r),{ok:r.length===0,errors:r}}function We(e,t){let r=Ve(e)==="object"?{...e}:{};for(let[a,o]of Object.entries(t.properties??{}))r[a]===void 0&&o.default!==void 0&&(r[a]=o.default);return r}var Xa=["authorization","cookie","setcookie","apikey","proxyauthorization","authtoken","accesstoken","refreshtoken","idtoken","sessiontoken","bearertoken","licensekey","licencekey","buoykey","privatekey","secret","password","passwd","credential"],Za="[redacted by Buoy]",es=[{re:/\bBearer\s+[A-Za-z0-9._~+/-]{12,}=*/gi,label:"[bearer token removed]"},{re:/\beyJ[A-Za-z0-9._-]{20,}/g,label:"[jwt removed]"},{re:/\bsk-[A-Za-z0-9_-]{16,}/g,label:"[api key removed]"},{re:/\bBUOY-[A-Z0-9-]{8,}/g,label:"[license key removed]"},{re:/\b[A-F0-9]{6}(?:-[A-F0-9]{6}){4}-V\d\b/g,label:"[license key removed]"},{re:/("|')?[A-Za-z0-9_-]*(authorization|api[_-]?key|password|passwd|secret|access[_-]?token|refresh[_-]?token|auth[_-]?token|session[_-]?token|license[_-]?key|licence[_-]?key|buoy[_-]?key|private[_-]?key)\1?\s*[:=]\s*("|')?(?!(?:authorization|bearer|cookie|header)\b)[^\s"',}]{6,}/gi,label:"[credential removed]"}];function ts(e){let t=e;for(let{re:r,label:a}of es)t=t.replace(r,a);return t}function rs(e){let t=e.toLowerCase().replace(/[-_.\s]/g,"");return Xa.some(r=>t.includes(r))}function lt(e,t=0){if(typeof e=="string")return ts(e);if(t>12||e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(a=>lt(a,t+1));let r={};for(let[a,o]of Object.entries(e))r[a]=rs(a)?Za:lt(o,t+1);return r}var yr=new Set,gr="__BUOY_INTERNAL_HOSTS__";function fr(e){try{let t=/^[a-z]+:\/\/([^/?#]+)/i.exec(e);if(!t?.[1])return;let r=t[1].toLowerCase();yr.add(r);let a=globalThis,o=a[gr],s=o instanceof Set?o:new Set;s.add(r),a[gr]=s}catch{}}function Pt(e){if(typeof e!="string")return false;let t=e.toLowerCase();for(let r of yr)if(t.includes(r))return true;return false}function as(e){if(!e||typeof e!="object")return false;let t=e;return Pt(t.url??t.uri??t.href)}function dt(e,t=0){if(t>6||e===null||typeof e!="object")return e;if(Array.isArray(e))return e.filter(a=>!as(a)).map(a=>dt(a,t+1));let r={};for(let[a,o]of Object.entries(e))r[a]=dt(o,t+1);return r}var le="getSnapshot",vr={verbose:0,debug:0,trace:0,log:1,info:1,warn:2,warning:2,error:3};function ee(e){return Array.isArray(e)?e:[]}function j(e){return e&&typeof e=="object"?e:{}}function ve(e,t){return typeof e=="number"&&e>0?e:t}function ze(e,t){return e.length<=t?e:e.slice(0,t)}function ss(e,t){let r=ee(j(e).entries),a=typeof t.level=="string"?vr[t.level]??0:0,o=typeof t.pattern=="string"?t.pattern.toLowerCase():void 0,s=r.filter(i=>{let n=j(i),d=String(n.level??"log");return(vr[d]??1)<a?false:o?String(n.message??"").toLowerCase().includes(o):true}),l=ze(s,ve(t.limit,40));return{totalCaptured:r.length,shown:l.length,entries:l.map(i=>{let n=j(i);return{at:n.timestamp,level:n.level,message:n.message}})}}function os(e,t){let r=j(e),a=ee(r.events).filter(n=>!Pt(j(n).url)),o=t.failedOnly===true,s=typeof t.pattern=="string"?t.pattern.toLowerCase():void 0,l=a.filter(n=>{let d=j(n),u=typeof d.status=="number"?d.status:void 0;return o&&!(d.error||u!==void 0&&u>=400)?false:s?String(d.url??"").toLowerCase().includes(s):true}),i=ze(l,ve(t.limit,25));return{totalCaptured:a.length,shown:i.length,requests:i.map(n=>{let d=j(n);return{id:d.id,method:d.method,url:d.url,status:d.status,durationMs:d.duration,error:d.error,overridden:d.override?true:void 0}}),hint:"Read one response with network.getEventBody({ id })."}}function wr(e,t=[],r=80){for(let a of ee(e)){if(t.length>=r)break;let o=j(a);o.isInternal!==true&&typeof o.path=="string"&&t.push(o.path),wr(o.children,t,r)}return t}function is(e,t){let r=l=>typeof l=="string"&&l.length>300?`${l.slice(0,300)}\u2026`:l,a=typeof t.key=="string"?t.key.toLowerCase():void 0,o=ee(e).map(j).map(l=>{let i=j(l.data);return{id:l.id,at:l.timestamp,action:l.action,storage:l.storageType,key:i.key??i.keys,value:r(i.value),prevValue:r(i.prevValue)}}).filter(l=>!a||JSON.stringify(l.key??"").toLowerCase().includes(a)).sort((l,i)=>String(i.at).localeCompare(String(l.at))),s=ve(t.limit,20);return{events:o.slice(0,s),total:o.length,returned:Math.min(s,o.length)}}function ns(e,t){let r=l=>{if(l===void 0)return;let i=typeof l=="string"?l:JSON.stringify(l);return i&&i.length>400?`${i.slice(0,400)}\u2026`:l},a=typeof t.type=="string"?t.type.toLowerCase():void 0,o=ee(e).map(j).filter(l=>l.category!=="internal").map(l=>({id:l.id,at:l.timestamp,type:l.type,payload:r(l.payload),meta:r(l.meta),error:r(l.error),changed:l.diffSummary||void 0})).filter(l=>!a||String(l.type).toLowerCase().includes(a)).sort((l,i)=>Number(i.at)-Number(l.at)),s=ve(t.limit,20);return{actions:o.slice(0,s),total:o.length,returned:Math.min(s,o.length)}}function br(e,t,r,a){let o=n=>{if(n===void 0)return;let d=typeof n=="string"?n:JSON.stringify(n);return d&&d.length>400?`${d.slice(0,400)}\u2026`:n},s=typeof t[a]=="string"?String(t[a]).toLowerCase():void 0,l=ee(j(e).changes).map(j).map(n=>({id:n.id,at:n.timestamp,[a]:n[r],changed:n.changedKeys,summary:n.diffSummary||void 0,...r==="storeName"?{partial:o(n.partial)}:{value:o(n.valuePreview)}})).filter(n=>!s||String(n[a]??"").toLowerCase().includes(s)).sort((n,d)=>Number(d.at)-Number(n.at)),i=ve(t.limit,20);return{changes:l.slice(0,i),total:l.length,returned:Math.min(i,l.length)}}function ls(e,t){let r=j(e),a=j(r.sitemap),o=ee(r.stack).map(j),s=ee(r.events).map(j),l=o.map(d=>({name:d.name,path:d.pathname,focused:d.isFocused===true?true:void 0})),i=s.slice(0,ve(t.limit,15)).map(d=>({at:d.timestamp,from:d.previousPathname,to:d.pathname})),n=o.find(d=>d.isFocused===true)??o[o.length-1];return{currentRoute:s.length?{path:s[0].pathname,source:"event"}:typeof n?.pathname=="string"?{path:n.pathname,source:"stack"}:void 0,stack:l,routes:wr(a.routes),sitemapSource:a.source,recentNavigations:i}}function ds(e){let t=j(e);return{env:t.env??t.variables,requiredEnvVars:t.requiredEnvVars,...Array.isArray(t.checks)?{checks:t.checks}:{}}}function us(e,t){let r=j(e),a=ee(r.envelopes).map(j),o=typeof t.type=="string"?t.type:void 0,s=typeof t.pattern=="string"?t.pattern.toLowerCase():void 0,l=a.filter(n=>{let d=ee(n.items).map(j);return o&&!d.some(u=>u.type===o)?false:s?d.some(u=>String(u.summary??"").toLowerCase().includes(s)):true}),i=ze(l,ve(t.limit,10));return{status:r.status,totalCaptured:a.length,shown:i.length,envelopes:i.map(n=>({id:n.id,at:n.timestamp,origin:n.origin,eventId:n.eventId,totalBytes:n.totalBytes,items:ee(n.items).map(d=>{let u=j(d);return{type:u.type,summary:u.summary,spanCount:u.spanCount,bytes:u.bytes}})})),drops:(()=>{let n=j(r.drops),d=ee(n.recent).map(j),u=g=>g.category==="span"||g.category==="transaction",h=[...ze(d.filter(g=>!u(g)),8),...ze(d.filter(u),3)].map(g=>({at:g.timestamp,reason:g.reason,category:g.category,quantity:g.quantity,detail:typeof g.detail=="string"?g.detail.slice(0,200):g.detail}));return h.length||n.summary?{summary:n.summary,recent:h}:void 0})(),hint:"For crash stack traces, console's [FATAL] entries carry the component stacks. `drops` lists events the SDK discarded before sending, with the reason."}}function Nt(e,t,r={}){switch(e){case"console":return ss(t,r);case"network":return os(t,r);case"route-events":return ls(t,r);case"storage":return is(t,r);case"redux":return ns(t,r);case"zustand":return br(t,r,"storeName","store");case"jotai":return br(t,r,"atomLabel","atom");case"env":return ds(t);case"sentry":return us(t,r);default:return t}}var Ke=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Dt(e){return JSON.stringify(e,(t,r)=>Ke(r)?Object.keys(r).sort().reduce((a,o)=>(a[o]=r[o],a),{}):r)}function W(e,t,r,a){return e[r]!==void 0||e[t]===void 0?false:(e[r]=e[t],delete e[t],a.push(`Accepted \`${t}\` as \`${r}\` \u2014 the parameter is named \`${r}\`.`),true)}var cs=new Set(["getQueryData","refetch","invalidate","reset","remove","triggerError","restoreError","triggerLoading","restoreLoading"]),hs=["id","urlPattern","enabled","name","methods","kind","status","statusText","headers","body","bodyPatch","bodyPath","bodyValue","failKind","delayMs","times","alternate","force","bodyOmitted"];function ps(e,t,r){if(cs.has(e)&&t.queryHash===void 0){let a=Ke(t.filters)?t.filters:void 0,o=t.queryKey??t.key??t.hash??a?.queryKey??a?.queryHash;Array.isArray(o)?(t.queryHash=Dt(o),r.push(`Accepted the queryKey array as the query's hash (${t.queryHash}) \u2014 the parameter is \`queryHash\`, the string from listQueries.`)):typeof o=="string"&&(t.queryHash=o,r.push("Accepted it as `queryHash` \u2014 that is the parameter name.")),delete t.queryKey,delete t.key,delete t.hash,delete t.filters}if(e==="setQueryData"){if(Ke(t.data))for(let a of["merge","force"])typeof t.data[a]=="boolean"&&t[a]===void 0&&(t[a]=t.data[a],delete t.data[a],r.push(`Moved \`${a}\` out of \`data\` to the top level \u2014 it is a write flag, not part of the value.`));if(W(t,"newData","data",r)||t.path===void 0&&W(t,"value","data",r)||W(t,"patch","data",r),t.queryKey===void 0&&typeof t.queryHash=="string")try{let a=JSON.parse(t.queryHash);Array.isArray(a)&&(t.queryKey=a,r.push("Accepted the queryHash as the key \u2014 setQueryData takes `queryKey`, the array."))}catch{}(t.patch!==void 0||t.merge===void 0)&&r.some(a=>a.includes("`patch`"))&&(t.merge=true)}}function ms(e,t,r){if((e==="getEventBody"||e==="setPinned"||e==="setSaved")&&(W(t,"requestId","id",r)||W(t,"eventId","id",r)),(e==="deleteOverrideRule"||e==="setOverrideRuleEnabled"||e==="getOverrideRuleBody")&&W(t,"ruleId","id",r),e==="upsertOverrideRule"){let a=Ke(t.rule)?{...t.rule}:{};t.fromRequestId===void 0&&typeof a.fromRequestId=="string"&&(t.fromRequestId=a.fromRequestId,r.push("Accepted `rule.fromRequestId` \u2014 it is a top-level parameter, beside `rule`.")),delete a.fromRequestId,ys(a,r),gs(t,a,r);let o=[];for(let s of hs)t[s]!==void 0&&a[s]===void 0&&(a[s]=t[s],o.push(s)),delete t[s];o.length&&r.push(`Accepted ${o.map(s=>`\`${s}\``).join(", ")} at the top level \u2014 rule fields belong inside \`rule\`.`),typeof a.times=="number"&&a.times<=0&&(delete a.times,r.push("Read `times: 0` as no limit \u2014 leave `times` out for a rule that keeps firing; `times: 1` fires once.")),Object.keys(a).length&&(t.rule=a)}}function ys(e,t){for(let[r,a]of[["match",["urlPattern","methods","method","url","pattern","urlContains","contains"]],["response",["status","statusText","body","headers","bodyPatch"]]]){let o=e[r];if(!Ke(o))continue;let s=[];for(let l of a){if(o[l]===void 0)continue;let i=l==="method"?"methods":l==="url"||l==="pattern"||l==="urlContains"||l==="contains"?"urlPattern":l;e[i]===void 0&&(e[i]=i==="methods"&&!Array.isArray(o[l])?[o[l]]:o[l],delete o[l],s.push(l))}s.length&&(Object.keys(o).length||delete e[r],t.push(`Read \`rule.${r}.{${s.join(", ")}}\` as top-level rule fields \u2014 this rule is flat, unlike msw/nock-style mocks.`))}}function gs(e,t,r){t.bodyPath===void 0&&typeof t.path=="string"&&(t.bodyPath=t.path,t.bodyValue===void 0&&t.value!==void 0&&(t.bodyValue=t.value),delete t.path,delete t.value,r.push("Read `path`/`value` as `bodyPath`/`bodyValue` \u2014 on a rule they address the response body."));let a=l=>t[l]!==void 0?t[l]:e[l],o=l=>{delete t[l],delete e[l]},s=a("mode");typeof s=="string"&&["respond","fail","delay"].includes(s)&&t.kind===void 0&&(t.kind=s,r.push(`Read \`mode: "${s}"\` as \`kind: "${s}"\`.`)),o("mode"),a("fail")===true&&t.kind===void 0&&(t.kind="fail",r.push('Read `fail: true` as `kind: "fail"` \u2014 a transport failure, as if offline.')),o("fail"),a("failOnce")===true&&(t.kind===void 0&&(t.kind="fail"),t.times===void 0&&(t.times=1),r.push('Read `failOnce: true` as `kind: "fail"` with `times: 1` \u2014 it fires once, then the rule disables itself.')),o("failOnce"),a("once")===true&&t.times===void 0&&(t.times=1,r.push("Read `once: true` as `times: 1` \u2014 the rule auto-disables after one match.")),o("once");for(let l of["maxHits","hits","count","maxTimes","applyTimes"]){let i=a(l);typeof i=="number"&&Number.isFinite(i)&&i>0&&t.times===void 0&&(t.times=i,r.push(`Read \`${l}: ${i}\` as \`times: ${i}\` \u2014 the rule auto-disables after ${i} match(es).`)),o(l)}}function fs(e,t,r){W(t,"name","storeName",r)||W(t,"store","storeName",r),e==="setState"&&(W(t,"statePatch","state",r)||W(t,"partial","state",r)||W(t,"patch","state",r)||W(t,"newState","state",r)||W(t,"nextState","state",r)||t.path===void 0&&W(t,"value","state",r),t.replace===void 0&&(t.replace=false,r.push("Applied replace:false (merge) \u2014 a store keeps action functions that can't be re-sent, and replacing would wipe them (the buttons that call them would then crash). Send replace:true only to deliberately reset the whole store.")))}function vs(e,t,r){e==="navigate"&&(W(t,"route","path",r)||W(t,"to","path",r)||W(t,"url","path",r)||W(t,"pathname","path",r))}function Je(e,t,r){let a={...r},o=[];switch(e){case"query":ps(t,a,o);break;case"network":ms(t,a,o);break;case"zustand":fs(t,a,o);break;case"route-events":vs(t,a,o);break;default:break}return{params:a,notes:o}}function kr(e){return e.length?`
|
|
22
22
|
|
|
23
23
|
[Buoy] ${e.join(" ")}`:""}function*ws(e,t){let r=e,a;for(;(a=r.search(/\r?\n\r?\n/))!==-1;){let o=r.slice(0,a);r=r.slice(a+(r[a]==="\r"?4:2)),t?.();let s,l=[];for(let i of o.split(/\r?\n/))i.startsWith(":")||(i.startsWith("event:")?s=i.slice(6).trim():i.startsWith("data:")&&l.push(i.slice(5).replace(/^ /,"")));l.length&&(yield{event:s,data:l.join(`
|
|
24
|
-
`)})}return r}function*ut(e,t,r){let a=ws(e,r),o=a.next();for(;!o.done;)yield o.value,o=a.next();t.rest=o.value}async function*bs(e,t={}){let{status:r,onFrame:a}=t,o={rest:""},s="";for await(let l of e)s+=l,yield*ut(s,o,a),s=o.rest;r&&o.rest.trim()&&(r.truncated=true)}async function*ks(e,t={}){let{status:r,onFrame:a,signal:o}=t,s=e.body,l={rest:""};if(!s||typeof s.getReader!="function"){let g=await e.text();yield*ut(g,l,a),r&&l.rest.trim()&&(r.truncated=true);return}let i=s.getReader(),n=new TextDecoder,d="",u=false,h=o?new Promise((g,v)=>{let m=()=>{let w=new Error("Aborted");w.name="AbortError",v(w)};o.aborted?m():o.addEventListener?.("abort",m,{once:true})}):void 0;h?.catch(()=>{});try{for(;;){let g=i.read(),{done:v,value:m}=h?await Promise.race([g,h]):await g;if(v)break;d+=n.decode(m,{stream:true}),yield*ut(d,l,a),d=l.rest}d+=n.decode(),yield*ut(d,l,a),r&&l.rest.trim()&&(r.truncated=true),u=true}finally{if(!u)try{Promise.resolve(i.cancel()).catch(()=>{})}catch{}try{i.releaseLock()}catch{}}}async function Ss(e){let t=e.headers?.get?.("content-type")??"";if(!t)return;let r=t.toLowerCase();if(r.includes("event-stream"))return;let a=(await e.text().catch(()=>"")).slice(0,600);return r.includes("json")?`The endpoint answered with JSON instead of a stream \u2014 it may not support "stream": true.${a?` \u2014 ${a}`:""}`:`The endpoint answered with ${t} instead of an event stream.${a?` \u2014 ${a}`:""}`}async function Ts(e){try{return(await e.text()).slice(0,600)}catch{return""}}function Sr(e){return e?"The connection dropped before the answer finished.":"The endpoint closed the stream without saying the answer was finished."}function jt(e,t,r){let a=r==="length",o=t.length>160?`\u2026${t.slice(-160)}`:t;return`Model sent unparseable arguments for ${e}`+(a?" (cut off at max_tokens \u2014 raise it or reduce thinking budget)":"")+` [stop: ${r??"none"}, ${t.length} chars] ${o}`}function U(){let e=globalThis.__buoyRealNow;return typeof e=="function"?e():Date.now()}function Tr(){return globalThis.__buoyRealTimers??globalThis}function ct(e,t){return Tr().setTimeout(e,t)}function Ct(e){Tr().clearTimeout(e)}var Rs=3e4,As=9e4;function Rr(e,t={}){let r=t.connectTimeoutMs??Rs,a=t.idleTimeoutMs??As,o=typeof AbortController=="function"?AbortController:void 0;if(!o)return{signal:e,connected(){},activity(){},expired:void 0,message:()=>{},dispose(){}};let s=new o,l,i,n=false,d=()=>{i!==void 0&&(Ct(i),i=void 0)},u=(g,v)=>{d(),!(n||!Number.isFinite(g)||g<=0)&&(i=ct(()=>{i=void 0,l=v;try{s.abort()}catch{}},g))},h=()=>{d();try{s.abort()}catch{}};return e&&(e.aborted?h():e.addEventListener?.("abort",h)),u(r,"connect"),{signal:s.signal,connected(){u(a,"idle")},activity(){n||u(a,"idle")},get expired(){return l},message(){if(l==="connect")return`The model endpoint did not respond within ${Math.round(r/1e3)}s. Nothing was generated, and nothing was re-sent.`;if(l==="idle")return`The model endpoint stopped sending after ${Math.round(a/1e3)}s of silence. Whatever arrived is above; nothing was re-sent.`},dispose(){n=true,d(),e?.removeEventListener?.("abort",h)}}}var qs=8e6;function _t(){return typeof XMLHttpRequest=="function"}function xs(e){return new Promise((t,r)=>{let a=new XMLHttpRequest,o=[],s=[],l=0,i=false,n,d=false,u=false,h=()=>{for(;s.length;)s.shift()()},g=()=>{let y;try{y=a.responseText??""}catch{return}if(!(y.length<=l)){if(y.length>qs){u=true,n=new Error("The endpoint sent more than this tool will read."),i=true;try{a.abort()}catch{}h();return}o.push(y.slice(l)),l=y.length,h()}},v=()=>{if(d)return;d=true;let y="",E=null;try{y=a.getResponseHeader("content-type")??"",E=a.getResponseHeader("retry-after")}catch{y=""}t({status:a.status,ok:a.status>=200&&a.status<300,contentType:y,retryAfter:E,async text(){await new Promise(M=>{if(i)return M();s.push(()=>M())});try{return a.responseText??""}catch{return""}},frames(M){return bs(m(),M)}})};async function*m(){try{for(;;){for(;o.length;)yield o.shift();if(i)break;await new Promise(y=>s.push(y))}for(;o.length;)yield o.shift();if(n)throw n}finally{if(!i)try{a.abort()}catch{}}}let w=()=>{try{a.abort()}catch{}};a.onreadystatechange=()=>{a.readyState===2&&v()},a.onprogress=()=>{v(),g()},a.onload=()=>{v(),u||g(),i=true,h()},a.onerror=()=>{n=new Error("The request failed before it finished."),i=true,d||(d=true,r(n)),h()},a.onabort=()=>{let y=new Error("Aborted");y.name="AbortError",n=y,i=true,d||(d=true,r(y)),h()},a.ontimeout=()=>{n=new Error("The request timed out."),i=true,d||(d=true,r(n)),h()};try{a.open("POST",e.url,true),a.responseType="text";for(let[y,E]of Object.entries(e.headers))try{a.setRequestHeader(y,E)}catch{}e.signal&&(e.signal.aborted?w():e.signal.addEventListener?.("abort",w)),a.send(e.body)}catch(y){d=true,r(y instanceof Error?y:new Error(String(y)))}})}var Es=1,Is={session:"X-Buoy-Session",ask:"X-Buoy-Ask",round:"X-Buoy-Round",attempt:"X-Buoy-Attempt",protocol:"X-Buoy-Protocol",client:"X-Buoy-Client",requestId:"X-Buoy-Request-Id"},Mt={session_missing:{status:401,action:"sign_in",message:"Sign in to use hosted Ask Buoy.",buttons:["sign_in"]},session_expired:{status:401,action:"refresh_retry",message:"Your sign-in ran out. Sign in again.",buttons:["sign_in"]},session_revoked:{status:401,action:"sign_in",message:"You were signed out. Sign in again.",buttons:["sign_in"]},token_not_allowed:{status:401,action:"sign_in",message:"This sign-in can't use hosted AI. Sign in as a person.",buttons:["sign_in"]},client_too_old:{status:426,action:"none",message:"Update Buoy to keep using hosted Ask Buoy.",buttons:[]},plan_not_eligible:{status:403,action:"none",message:"Hosted Ask Buoy comes with Pro and Business.",buttons:["see_plans"]},not_in_pilot:{status:403,action:"none",message:"Hosted Ask Buoy is in a small test right now.",buttons:[]},team_hosted_off:{status:403,action:"none",message:"Your team admin turned off hosted AI.",buttons:[]},account_frozen:{status:403,action:"none",message:"Your account has a billing problem.",buttons:["billing"]},credits_out:{status:402,action:"none",message:"You used this month's credits. They come back on {date}.",buttons:["own_endpoint"]},member_cap:{status:402,action:"none",message:"You hit your team's limit for you. Ask your admin.",buttons:[]},ask_too_costly:{status:402,action:"none",message:"This ask got too big. Try a smaller ask.",buttons:[]},ask_busy:{status:409,action:"retry_after",message:"Another ask is still running.",buttons:[]},duplicate_request:{status:409,action:"none",message:"That was already sent.",buttons:[]},request_too_large:{status:413,action:"trim_retry",message:"This chat got too long. Start a new chat.",buttons:["new_chat"]},media_not_allowed:{status:400,action:"none",message:"Hosted Ask Buoy can't read images yet.",buttons:[]},bad_request:{status:400,action:"none",message:"Something in the request was wrong.",buttons:["report"]},rate_limited:{status:429,action:"retry_after",message:"Too many asks at once. Trying again.",buttons:[]},hosted_paused:{status:503,action:"none",message:"Hosted AI is paused right now.",buttons:["own_endpoint"]},upstream_busy:{status:503,action:"retry_after",message:"The AI is busy. Trying again.",buttons:[]},upstream_error:{status:502,action:"retry_after",message:"The AI had a problem.",buttons:["try_again","report"]},upstream_refused:{status:403,action:"none",message:"The AI would not answer that.",buttons:["report"]},internal:{status:500,action:"none",message:"Something broke on our side.",buttons:["try_again","report"]}};function Ar(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(Mt,e)}var Os=new Set([429,503,529]),Ps=new Set([401,403]),Ns=new Set(["overloaded_error","rate_limit_error","rate_limit_exceeded","insufficient_quota","server_overloaded"]),Ds=new Set(["authentication_error","permission_error","invalid_api_key"]),js=new Set(["request_too_large","context_length_exceeded"]),Cs=["rate_limit_exceeded","rate limit","too many requests","overloaded","capacity","try again later"],_s=["prompt is too long","input too long","input is too long","input length exceeds context window","input and output tokens exceed your context limit","maximum context length","context_length_exceeded","too many tokens","context length","input is too long for requested model","input length and `max_tokens` exceed context limit","too many total text bytes","exceed customer model maximum"];function ht(e){let t=e.message.toLowerCase(),r=e.type?.toLowerCase(),a=Ms(e.retryAfter),o=s=>({kind:s,...e.status!==void 0?{status:e.status}:{},...a!==void 0?{retryAfterMs:a}:{}});if(e.hosted){let s=e.hosted,l=s.action==="retry_after"||s.action==="refresh_retry"?"throttled":s.action==="trim_retry"?"overflow":"blocked",i=s.action==="refresh_retry"?0:typeof s.retry_after_ms=="number"&&s.retry_after_ms>0?s.retry_after_ms:a;return{kind:l,...e.status!==void 0?{status:e.status}:{},...i!==void 0?{retryAfterMs:i}:{},hosted:s}}return e.status!==void 0&&Ps.has(e.status)||r&&Ds.has(r)?o("auth"):e.status!==void 0&&Os.has(e.status)||r&&Ns.has(r)?o("throttled"):r&&js.has(r)||_s.some(s=>t.includes(s))?o("overflow"):Cs.some(s=>t.includes(s))?o("throttled"):o("other")}function Ms(e){if(!e)return;let t=e.trim();if(/^\d+$/.test(t))return Number(t)*1e3;let r=Date.parse(t);if(Number.isNaN(r))return;let a=r-U();return a>0?a:void 0}function qr(e){try{let t=JSON.parse(e),r=typeof t.error=="object"&&t.error?t.error:void 0,a=r?.type??r?.code??t.type;return typeof a=="string"?a:void 0}catch{return}}function pt(e){let t=e;if(typeof e=="string")try{t=JSON.parse(e).error}catch{return}if(!t||typeof t!="object")return;let r=t;if(!Ar(r.code))return;let a=Mt[r.code],o=s=>typeof s=="string"?s:null;return{code:r.code,message:o(r.message)??a.message,request_id:o(r.request_id),action:a.action,retry_after_ms:typeof r.retry_after_ms=="number"?r.retry_after_ms:null,reset_at:o(r.reset_at),help_url:o(r.help_url)}}var mt=async function*(){};function xr(e){let t=e.transport??"auto",r=false,a=()=>e.fetch?t==="xhr"&&_t():t==="xhr"?_t():t==="fetch"?false:r&&_t();return{async open(o){if(a()){let n=await xs({url:e.endpoint,headers:o.headers,body:o.body,signal:o.signal});if(!n.ok){let u=(await n.text()).slice(0,600),h=e.hosted?pt(u):void 0;return{problem:h?h.message:`HTTP ${n.status}${u?` \u2014 ${u}`:""}`,problemInfo:ht({status:n.status,type:qr(u),message:u,retryAfter:n.retryAfter,...h?{hosted:h}:{}}),frames:mt}}let d=n.contentType.toLowerCase();if(d&&!d.includes("event-stream")){let u=(await n.text()).slice(0,600);return{problem:d.includes("json")?`The endpoint answered with JSON instead of a stream \u2014 it may not support "stream": true.${u?` \u2014 ${u}`:""}`:`The endpoint answered with ${n.contentType} instead of an event stream.${u?` \u2014 ${u}`:""}`,frames:mt}}return{frames:u=>n.frames(u)}}let s=await(e.fetch??fetch)(e.endpoint,{method:"POST",headers:o.headers,signal:o.signal,body:o.body});if(!s.ok){let n=await Ts(s),d=e.hosted?pt(n):void 0;return{problem:d?d.message:`HTTP ${s.status}${n?` \u2014 ${n}`:""}`,problemInfo:ht({status:s.status,type:qr(n),message:n,retryAfter:s.headers?.get?.("retry-after")??null,...d?{hosted:d}:{}}),frames:mt}}let l=await Ss(s);if(l)return{problem:l,frames:mt};let i=s.body;return(!i||typeof i.getReader!="function")&&!e.fetch&&(r=true),{frames:n=>ks(s,n)}}}}var Ls="2023-06-01";function Bs(e){let t=e[e.length-1],r=t?.content[t.content.length-1];return r&&(r.cache_control={type:"ephemeral"}),e}function Er(e){let t=[];for(let r of e)if(r.role==="user")t.push({role:"user",content:[{type:"text",text:r.text}]});else if(r.role==="assistant"){let a=[];for(let o of r.thinking??[])a.push(o);r.text&&a.push({type:"text",text:r.text});for(let o of r.toolCalls??[])a.push({type:"tool_use",id:o.id,name:o.name,input:o.input});a.length&&t.push({role:"assistant",content:a})}else t.push({role:"user",content:r.results.map(a=>({type:"tool_result",tool_use_id:a.toolCallId,content:a.content,...a.isError?{is_error:true}:{}}))});return t}function Ir(e){let t=xr(e);return{protocol:"anthropic",async*send(r){let a=Rr(r.signal,e),o={truncated:false};try{let s={"content-type":"application/json","anthropic-version":e.anthropicVersion??Ls,...await(e.headers?.(r.meta)??{})};e.apiKey&&!s["x-api-key"]&&!s.Authorization&&(s["x-api-key"]=e.apiKey,s["anthropic-dangerous-direct-browser-access"]="true");let l=await t.open({headers:s,signal:a.signal,body:JSON.stringify({model:r.model,max_tokens:r.maxTokens,stream:true,system:e.cache===false?r.systemVolatile?`${r.system}
|
|
24
|
+
`)})}return r}function*ut(e,t,r){let a=ws(e,r),o=a.next();for(;!o.done;)yield o.value,o=a.next();t.rest=o.value}async function*bs(e,t={}){let{status:r,onFrame:a}=t,o={rest:""},s="";for await(let l of e)s+=l,yield*ut(s,o,a),s=o.rest;r&&o.rest.trim()&&(r.truncated=true)}async function*ks(e,t={}){let{status:r,onFrame:a,signal:o}=t,s=e.body,l={rest:""};if(!s||typeof s.getReader!="function"){let g=await e.text();yield*ut(g,l,a),r&&l.rest.trim()&&(r.truncated=true);return}let i=s.getReader(),n=new TextDecoder,d="",u=false,h=o?new Promise((g,v)=>{let m=()=>{let w=new Error("Aborted");w.name="AbortError",v(w)};o.aborted?m():o.addEventListener?.("abort",m,{once:true})}):void 0;h?.catch(()=>{});try{for(;;){let g=i.read(),{done:v,value:m}=h?await Promise.race([g,h]):await g;if(v)break;d+=n.decode(m,{stream:true}),yield*ut(d,l,a),d=l.rest}d+=n.decode(),yield*ut(d,l,a),r&&l.rest.trim()&&(r.truncated=true),u=true}finally{if(!u)try{Promise.resolve(i.cancel()).catch(()=>{})}catch{}try{i.releaseLock()}catch{}}}async function Ss(e){let t=e.headers?.get?.("content-type")??"";if(!t)return;let r=t.toLowerCase();if(r.includes("event-stream"))return;let a=(await e.text().catch(()=>"")).slice(0,600);return r.includes("json")?`The endpoint answered with JSON instead of a stream \u2014 it may not support "stream": true.${a?` \u2014 ${a}`:""}`:`The endpoint answered with ${t} instead of an event stream.${a?` \u2014 ${a}`:""}`}async function Ts(e){try{return(await e.text()).slice(0,600)}catch{return""}}function Sr(e){return e?"The connection dropped before the answer finished.":"The endpoint closed the stream without saying the answer was finished."}function jt(e,t,r){let a=r==="length",o=t.length>160?`\u2026${t.slice(-160)}`:t;return`Model sent unparseable arguments for ${e}`+(a?" (cut off at max_tokens \u2014 raise it or reduce thinking budget)":"")+` [stop: ${r??"none"}, ${t.length} chars] ${o}`}function U(){let e=globalThis.__buoyRealNow;return typeof e=="function"?e():Date.now()}function Tr(){return globalThis.__buoyRealTimers??globalThis}function ct(e,t){return Tr().setTimeout(e,t)}function Ct(e){Tr().clearTimeout(e)}var Rs=3e4,As=9e4;function Rr(e,t={}){let r=t.connectTimeoutMs??Rs,a=t.idleTimeoutMs??As,o=typeof AbortController=="function"?AbortController:void 0;if(!o)return{signal:e,connected(){},activity(){},expired:void 0,message:()=>{},dispose(){}};let s=new o,l,i,n=false,d=()=>{i!==void 0&&(Ct(i),i=void 0)},u=(g,v)=>{d(),!(n||!Number.isFinite(g)||g<=0)&&(i=ct(()=>{i=void 0,l=v;try{s.abort()}catch{}},g))},h=()=>{d();try{s.abort()}catch{}};return e&&(e.aborted?h():e.addEventListener?.("abort",h)),u(r,"connect"),{signal:s.signal,connected(){u(a,"idle")},activity(){n||u(a,"idle")},get expired(){return l},message(){if(l==="connect")return`The model endpoint did not respond within ${Math.round(r/1e3)}s. Nothing was generated, and nothing was re-sent.`;if(l==="idle")return`The model endpoint stopped sending after ${Math.round(a/1e3)}s of silence. Whatever arrived is above; nothing was re-sent.`},dispose(){n=true,d(),e?.removeEventListener?.("abort",h)}}}var qs=8e6;function _t(){return typeof XMLHttpRequest=="function"}function xs(e){return new Promise((t,r)=>{let a=new XMLHttpRequest,o=[],s=[],l=0,i=false,n,d=false,u=false,h=()=>{for(;s.length;)s.shift()()},g=()=>{let y;try{y=a.responseText??""}catch{return}if(!(y.length<=l)){if(y.length>qs){u=true,n=new Error("The endpoint sent more than this tool will read."),i=true;try{a.abort()}catch{}h();return}o.push(y.slice(l)),l=y.length,h()}},v=()=>{if(d)return;d=true;let y="",E=null;try{y=a.getResponseHeader("content-type")??"",E=a.getResponseHeader("retry-after")}catch{y=""}t({status:a.status,ok:a.status>=200&&a.status<300,contentType:y,retryAfter:E,async text(){await new Promise(M=>{if(i)return M();s.push(()=>M())});try{return a.responseText??""}catch{return""}},frames(M){return bs(m(),M)}})};async function*m(){try{for(;;){for(;o.length;)yield o.shift();if(i)break;await new Promise(y=>s.push(y))}for(;o.length;)yield o.shift();if(n)throw n}finally{if(!i)try{a.abort()}catch{}}}let w=()=>{try{a.abort()}catch{}};a.onreadystatechange=()=>{a.readyState===2&&v()},a.onprogress=()=>{v(),g()},a.onload=()=>{v(),u||g(),i=true,h()},a.onerror=()=>{n=new Error("The request failed before it finished."),i=true,d||(d=true,r(n)),h()},a.onabort=()=>{let y=new Error("Aborted");y.name="AbortError",n=y,i=true,d||(d=true,r(y)),h()},a.ontimeout=()=>{n=new Error("The request timed out."),i=true,d||(d=true,r(n)),h()};try{a.open("POST",e.url,true),a.responseType="text";for(let[y,E]of Object.entries(e.headers))try{a.setRequestHeader(y,E)}catch{}e.signal&&(e.signal.aborted?w():e.signal.addEventListener?.("abort",w)),a.send(e.body)}catch(y){d=true,r(y instanceof Error?y:new Error(String(y)))}})}var Es=1,Is={session:"X-Buoy-Session",ask:"X-Buoy-Ask",round:"X-Buoy-Round",attempt:"X-Buoy-Attempt",protocol:"X-Buoy-Protocol",client:"X-Buoy-Client",requestId:"X-Buoy-Request-Id"},Mt={session_missing:{status:401,action:"sign_in",message:"Sign in to use hosted Ask Buoy.",buttons:["sign_in"]},session_expired:{status:401,action:"refresh_retry",message:"Your sign-in ran out. Sign in again.",buttons:["sign_in"]},session_revoked:{status:401,action:"sign_in",message:"You were signed out. Sign in again.",buttons:["sign_in"]},token_not_allowed:{status:401,action:"sign_in",message:"This sign-in can't use hosted AI. Sign in as a person.",buttons:["sign_in"]},client_too_old:{status:426,action:"none",message:"Update Buoy to keep using hosted Ask Buoy.",buttons:[]},plan_not_eligible:{status:403,action:"none",message:"Hosted Ask Buoy comes with Pro and Business.",buttons:["see_plans"]},not_in_pilot:{status:403,action:"none",message:"Hosted Ask Buoy is in a small test right now.",buttons:[]},team_hosted_off:{status:403,action:"none",message:"Your team admin turned off hosted AI.",buttons:[]},account_frozen:{status:403,action:"none",message:"Your account has a billing problem.",buttons:["billing"]},credits_out:{status:402,action:"none",message:"You used this week's credits. They come back on {date}.",buttons:["own_endpoint"]},member_cap:{status:402,action:"none",message:"You hit your team's limit for you. Ask your admin.",buttons:[]},ask_too_costly:{status:402,action:"none",message:"This ask got too big. Try a smaller ask.",buttons:[]},ask_busy:{status:409,action:"retry_after",message:"Another ask is still running.",buttons:[]},duplicate_request:{status:409,action:"none",message:"That was already sent.",buttons:[]},request_too_large:{status:413,action:"trim_retry",message:"This chat got too long. Start a new chat.",buttons:["new_chat"]},media_not_allowed:{status:400,action:"none",message:"Hosted Ask Buoy can't read images yet.",buttons:[]},bad_request:{status:400,action:"none",message:"Something in the request was wrong.",buttons:["report"]},rate_limited:{status:429,action:"retry_after",message:"Too many asks at once. Trying again.",buttons:[]},hosted_paused:{status:503,action:"none",message:"Hosted AI is paused right now.",buttons:["own_endpoint"]},upstream_busy:{status:503,action:"retry_after",message:"The AI is busy. Trying again.",buttons:[]},upstream_error:{status:502,action:"retry_after",message:"The AI had a problem.",buttons:["try_again","report"]},upstream_refused:{status:403,action:"none",message:"The AI would not answer that.",buttons:["report"]},internal:{status:500,action:"none",message:"Something broke on our side.",buttons:["try_again","report"]}};function Ar(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(Mt,e)}var Os=new Set([429,503,529]),Ps=new Set([401,403]),Ns=new Set(["overloaded_error","rate_limit_error","rate_limit_exceeded","insufficient_quota","server_overloaded"]),Ds=new Set(["authentication_error","permission_error","invalid_api_key"]),js=new Set(["request_too_large","context_length_exceeded"]),Cs=["rate_limit_exceeded","rate limit","too many requests","overloaded","capacity","try again later"],_s=["prompt is too long","input too long","input is too long","input length exceeds context window","input and output tokens exceed your context limit","maximum context length","context_length_exceeded","too many tokens","context length","input is too long for requested model","input length and `max_tokens` exceed context limit","too many total text bytes","exceed customer model maximum"];function ht(e){let t=e.message.toLowerCase(),r=e.type?.toLowerCase(),a=Ms(e.retryAfter),o=s=>({kind:s,...e.status!==void 0?{status:e.status}:{},...a!==void 0?{retryAfterMs:a}:{}});if(e.hosted){let s=e.hosted,l=s.action==="retry_after"||s.action==="refresh_retry"?"throttled":s.action==="trim_retry"?"overflow":"blocked",i=s.action==="refresh_retry"?0:typeof s.retry_after_ms=="number"&&s.retry_after_ms>0?s.retry_after_ms:a;return{kind:l,...e.status!==void 0?{status:e.status}:{},...i!==void 0?{retryAfterMs:i}:{},hosted:s}}return e.status!==void 0&&Ps.has(e.status)||r&&Ds.has(r)?o("auth"):e.status!==void 0&&Os.has(e.status)||r&&Ns.has(r)?o("throttled"):r&&js.has(r)||_s.some(s=>t.includes(s))?o("overflow"):Cs.some(s=>t.includes(s))?o("throttled"):o("other")}function Ms(e){if(!e)return;let t=e.trim();if(/^\d+$/.test(t))return Number(t)*1e3;let r=Date.parse(t);if(Number.isNaN(r))return;let a=r-U();return a>0?a:void 0}function qr(e){try{let t=JSON.parse(e),r=typeof t.error=="object"&&t.error?t.error:void 0,a=r?.type??r?.code??t.type;return typeof a=="string"?a:void 0}catch{return}}function pt(e){let t=e;if(typeof e=="string")try{t=JSON.parse(e).error}catch{return}if(!t||typeof t!="object")return;let r=t;if(!Ar(r.code))return;let a=Mt[r.code],o=s=>typeof s=="string"?s:null;return{code:r.code,message:o(r.message)??a.message,request_id:o(r.request_id),action:a.action,retry_after_ms:typeof r.retry_after_ms=="number"?r.retry_after_ms:null,reset_at:o(r.reset_at),help_url:o(r.help_url)}}var mt=async function*(){};function xr(e){let t=e.transport??"auto",r=false,a=()=>e.fetch?t==="xhr"&&_t():t==="xhr"?_t():t==="fetch"?false:r&&_t();return{async open(o){if(a()){let n=await xs({url:e.endpoint,headers:o.headers,body:o.body,signal:o.signal});if(!n.ok){let u=(await n.text()).slice(0,600),h=e.hosted?pt(u):void 0;return{problem:h?h.message:`HTTP ${n.status}${u?` \u2014 ${u}`:""}`,problemInfo:ht({status:n.status,type:qr(u),message:u,retryAfter:n.retryAfter,...h?{hosted:h}:{}}),frames:mt}}let d=n.contentType.toLowerCase();if(d&&!d.includes("event-stream")){let u=(await n.text()).slice(0,600);return{problem:d.includes("json")?`The endpoint answered with JSON instead of a stream \u2014 it may not support "stream": true.${u?` \u2014 ${u}`:""}`:`The endpoint answered with ${n.contentType} instead of an event stream.${u?` \u2014 ${u}`:""}`,frames:mt}}return{frames:u=>n.frames(u)}}let s=await(e.fetch??fetch)(e.endpoint,{method:"POST",headers:o.headers,signal:o.signal,body:o.body});if(!s.ok){let n=await Ts(s),d=e.hosted?pt(n):void 0;return{problem:d?d.message:`HTTP ${s.status}${n?` \u2014 ${n}`:""}`,problemInfo:ht({status:s.status,type:qr(n),message:n,retryAfter:s.headers?.get?.("retry-after")??null,...d?{hosted:d}:{}}),frames:mt}}let l=await Ss(s);if(l)return{problem:l,frames:mt};let i=s.body;return(!i||typeof i.getReader!="function")&&!e.fetch&&(r=true),{frames:n=>ks(s,n)}}}}var Ls="2023-06-01";function Bs(e){let t=e[e.length-1],r=t?.content[t.content.length-1];return r&&(r.cache_control={type:"ephemeral"}),e}function Er(e){let t=[];for(let r of e)if(r.role==="user")t.push({role:"user",content:[{type:"text",text:r.text}]});else if(r.role==="assistant"){let a=[];for(let o of r.thinking??[])a.push(o);r.text&&a.push({type:"text",text:r.text});for(let o of r.toolCalls??[])a.push({type:"tool_use",id:o.id,name:o.name,input:o.input});a.length&&t.push({role:"assistant",content:a})}else t.push({role:"user",content:r.results.map(a=>({type:"tool_result",tool_use_id:a.toolCallId,content:a.content,...a.isError?{is_error:true}:{}}))});return t}function Ir(e){let t=xr(e);return{protocol:"anthropic",async*send(r){let a=Rr(r.signal,e),o={truncated:false};try{let s={"content-type":"application/json","anthropic-version":e.anthropicVersion??Ls,...await(e.headers?.(r.meta)??{})};e.apiKey&&!s["x-api-key"]&&!s.Authorization&&(s["x-api-key"]=e.apiKey,s["anthropic-dangerous-direct-browser-access"]="true");let l=await t.open({headers:s,signal:a.signal,body:JSON.stringify({model:r.model,max_tokens:r.maxTokens,stream:true,system:e.cache===false?r.systemVolatile?`${r.system}
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buoy-gg/agent-core",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.56",
|
|
4
4
|
"description": "Headless agent core for Ask Buoy - the tool catalog, BYO-model providers, turn loop and effect ledger that let an LLM drive Buoy devtools",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|