@swifty.js/swifty 0.0.3-alpha → 0.0.4
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-5YZWK2BD.js → agent-MPIDW5VX.js} +1 -1
- package/dist/{anthropic-PWUGDLNY.js → anthropic-4E5EEQM6.js} +1 -1
- package/dist/{chunk-UAHM3AAK.js → chunk-DCI5RJC7.js} +12 -11
- package/dist/{chunk-35WOW2VS.js → chunk-IZ23BHLA.js} +16 -15
- package/dist/{chunk-XOFTPYYD.js → chunk-KYXKZJ3Z.js} +1 -1
- package/dist/{chunk-IE47RFDE.js → chunk-WGVF7CNO.js} +6 -6
- package/dist/glob_addon.node +0 -0
- package/dist/main.js +228 -232
- package/dist/{openai-S5NEHZTE.js → openai-UNFIBQUL.js} +1 -1
- package/dist/{server-BK5ZG2JS.js → server-NEYKYZKV.js} +3 -3
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __swiftyCreateRequire } from "node:module";
|
|
3
3
|
const require = __swiftyCreateRequire(import.meta.url);
|
|
4
|
-
import{h as Ks,i as Us}from"./chunk-XOFTPYYD.js";import{b as Fs,c as En,d as ss,e as On,f as vn,g as Tn}from"./chunk-FZPTNGTU.js";import"./chunk-7MHXMDYC.js";import{J as vr,K as Ls,L as rs,M as Ms,R as $n,e as kn}from"./chunk-4KVSJNS6.js";import"./chunk-MQ5XOYLD.js";import"./chunk-X3UA5OZL.js";function x(s,e,t,r,n){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?s!==e||!n:!e.has(s))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?n.call(s,t):n?n.value=t:e.set(s,t),t}function c(s,e,t,r){if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?s!==e||!r:!e.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?r:t==="a"?r.call(s):r?r.value:e.get(s)}var Ue=function(){let{crypto:s}=globalThis;if(s?.randomUUID)return Ue=s.randomUUID.bind(s),s.randomUUID();let e=new Uint8Array(1),t=s?()=>s.getRandomValues(e)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,r=>(+r^t()&15>>+r/4).toString(16))};function Tr(s){return typeof s=="object"&&s!==null&&("name"in s&&s.name==="AbortError"||"message"in s&&String(s.message).includes("FetchRequestCanceledException"))}var Nr=s=>{if(s instanceof Error)return s;if(typeof s=="object"&&s!==null){try{if(Object.prototype.toString.call(s)==="[object Error]"){let e=new Error(s.message,s.cause?{cause:s.cause}:{});return s.stack&&(e.stack=s.stack),s.cause&&!e.cause&&(e.cause=s.cause),s.name&&(e.name=s.name),e}}catch{}try{return new Error(JSON.stringify(s))}catch{}}return new Error(s)};var g=class extends Error{},T=class s extends g{constructor(e,t,r,n){super(`${s.makeMessage(e,t,r)}`),this.status=e,this.headers=n,this.requestID=n?.get("x-request-id"),this.error=t;let o=t;this.code=o?.code,this.param=o?.param,this.type=o?.type}static makeMessage(e,t,r){let n=t?.message?typeof t.message=="string"?t.message:JSON.stringify(t.message):t?JSON.stringify(t):r;return e&&n?`${e} ${n}`:e?`${e} status code (no body)`:n||"(no status code or body)"}static generate(e,t,r,n){if(!e||!n)return new we({message:r,cause:Nr(t)});let o=t?.error;return e===400?new _t(e,o,r,n):e===401?new gt(e,o,r,n):e===403?new yt(e,o,r,n):e===404?new At(e,o,r,n):e===409?new bt(e,o,r,n):e===422?new It(e,o,r,n):e===429?new wt(e,o,r,n):e>=500?new Pt(e,o,r,n):new s(e,o,r,n)}},F=class extends T{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}},we=class extends T{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}},Pe=class extends we{constructor({message:e}={}){super({message:e??"Request timed out."})}},_t=class extends T{},gt=class extends T{},yt=class extends T{},At=class extends T{},bt=class extends T{},It=class extends T{},wt=class extends T{},Pt=class extends T{},xt=class extends g{constructor(){super("Could not parse response content as the length limit was reached")}},Rt=class extends g{constructor(){super("Could not parse response content as the request was rejected by the content filter")}},ae=class extends Error{constructor(e){super(e)}},Be=class extends T{constructor(e,t,r){let n="OAuth2 authentication error",o;if(t&&typeof t=="object"){let u=t;o=u.error;let l=u.error_description;l&&typeof l=="string"?n=l:o&&(n=o)}super(e,t,n,r),this.error_code=o}},jr=class extends g{constructor(e,t,r){super(e),this.provider=t,this.cause=r}};var Zo=/^[a-z][a-z0-9+.-]*:/i,Nn=s=>Zo.test(s),X=s=>(X=Array.isArray,X(s)),Bs=X;function ns(s){return typeof s!="object"?{}:s??{}}function Ds(s){if(!s)return!0;for(let e in s)return!1;return!0}function jn(s,e){return Object.prototype.hasOwnProperty.call(s,e)}function Lr(s){return s!=null&&typeof s=="object"&&!Array.isArray(s)}var Ln=(s,e)=>{if(typeof e!="number"||!Number.isInteger(e))throw new g(`${s} must be an integer`);if(e<0)throw new g(`${s} must be a positive integer`);return e};var Mn=s=>{try{return JSON.parse(s)}catch{return}};var ue=s=>new Promise(e=>setTimeout(e,s));var xe="6.46.0";var Bn=()=>typeof window<"u"&&typeof window.document<"u"&&typeof navigator<"u";function ei(){return typeof Deno<"u"&&Deno.build!=null?"deno":typeof EdgeRuntime<"u"?"edge":Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]"?"node":"unknown"}var ti=()=>{let s=ei();if(s==="deno")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":xe,"X-Stainless-OS":Kn(Deno.build.os),"X-Stainless-Arch":Fn(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":typeof Deno.version=="string"?Deno.version:Deno.version?.deno??"unknown"};if(typeof EdgeRuntime<"u")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":xe,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if(s==="node")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":xe,"X-Stainless-OS":Kn(globalThis.process.platform??"unknown"),"X-Stainless-Arch":Fn(globalThis.process.arch??"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":globalThis.process.version??"unknown"};let e=ri();return e?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":xe,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${e.browser}`,"X-Stainless-Runtime-Version":e.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":xe,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function ri(){if(typeof navigator>"u"||!navigator)return null;let s=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(let{key:e,pattern:t}of s){let r=t.exec(navigator.userAgent);if(r){let n=r[1]||0,o=r[2]||0,u=r[3]||0;return{browser:e,version:`${n}.${o}.${u}`}}}return null}var Fn=s=>s==="x32"?"x32":s==="x86_64"||s==="x64"?"x64":s==="arm"?"arm":s==="aarch64"||s==="arm64"?"arm64":s?`other:${s}`:"unknown",Kn=s=>(s=s.toLowerCase(),s.includes("ios")?"iOS":s==="android"?"Android":s==="darwin"?"MacOS":s==="win32"?"Windows":s==="freebsd"?"FreeBSD":s==="openbsd"?"OpenBSD":s==="linux"?"Linux":s?`Other:${s}`:"Unknown"),Un,Dn=()=>Un??(Un=ti());function os(){if(typeof fetch<"u")return fetch;throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new OpenAI({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function zs(...s){let e=globalThis.ReadableStream;if(typeof e>"u")throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new e(...s)}function is(s){let e=Symbol.asyncIterator in s?s[Symbol.asyncIterator]():s[Symbol.iterator]();return zs({start(){},async pull(t){let{done:r,value:n}=await e.next();r?t.close():t.enqueue(n)},async cancel(){await e.return?.()}})}function qs(s){if(s[Symbol.asyncIterator])return s;let e=s.getReader();return{async next(){try{let t=await e.read();return t?.done&&e.releaseLock(),t}catch(t){throw e.releaseLock(),t}},async return(){let t=e.cancel();return e.releaseLock(),await t,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Ws(s){if(s===null||typeof s!="object")return;if(s[Symbol.asyncIterator]){await s[Symbol.asyncIterator]().return?.();return}let e=s.getReader(),t=e.cancel();e.releaseLock(),await t}var qn=({headers:s,body:e})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(e)});var Hs="RFC3986",Js=s=>String(s),Xs={RFC1738:s=>String(s).replace(/%20/g,"+"),RFC3986:Js},Wn="RFC1738";var as=(s,e)=>(as=Object.hasOwn??Function.prototype.call.bind(Object.prototype.hasOwnProperty),as(s,e)),ce=(()=>{let s=[];for(let e=0;e<256;++e)s.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return s})();var Gs=1024,Hn=(s,e,t,r,n)=>{if(s.length===0)return s;let o=s;if(typeof s=="symbol"?o=Symbol.prototype.toString.call(s):typeof s!="string"&&(o=String(s)),t==="iso-8859-1")return escape(o).replace(/%u[0-9a-f]{4}/gi,function(l){return"%26%23"+parseInt(l.slice(2),16)+"%3B"});let u="";for(let l=0;l<o.length;l+=Gs){let m=o.length>=Gs?o.slice(l,l+Gs):o,p=[];for(let I=0;I<m.length;++I){let h=m.charCodeAt(I);if(h===45||h===46||h===95||h===126||h>=48&&h<=57||h>=65&&h<=90||h>=97&&h<=122||n===Wn&&(h===40||h===41)){p[p.length]=m.charAt(I);continue}if(h<128){p[p.length]=ce[h];continue}if(h<2048){p[p.length]=ce[192|h>>6]+ce[128|h&63];continue}if(h<55296||h>=57344){p[p.length]=ce[224|h>>12]+ce[128|h>>6&63]+ce[128|h&63];continue}I+=1,h=65536+((h&1023)<<10|m.charCodeAt(I)&1023),p[p.length]=ce[240|h>>18]+ce[128|h>>12&63]+ce[128|h>>6&63]+ce[128|h&63]}u+=p.join("")}return u};function Jn(s){return!s||typeof s!="object"?!1:!!(s.constructor&&s.constructor.isBuffer&&s.constructor.isBuffer(s))}function Vs(s,e){if(X(s)){let t=[];for(let r=0;r<s.length;r+=1)t.push(e(s[r]));return t}return e(s)}var Gn={brackets(s){return String(s)+"[]"},comma:"comma",indices(s,e){return String(s)+"["+e+"]"},repeat(s){return String(s)}},Vn=function(s,e){Array.prototype.push.apply(s,X(e)?e:[e])},Xn,B={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:Hn,encodeValuesOnly:!1,format:Hs,formatter:Js,indices:!1,serializeDate(s){return(Xn??(Xn=Function.prototype.call.bind(Date.prototype.toISOString)))(s)},skipNulls:!1,strictNullHandling:!1};function ni(s){return typeof s=="string"||typeof s=="number"||typeof s=="boolean"||typeof s=="symbol"||typeof s=="bigint"}var Ys={};function Yn(s,e,t,r,n,o,u,l,m,p,I,h,f,b,y,A,w,k){let _=s,P=k,R=0,v=!1;for(;(P=P.get(Ys))!==void 0&&!v;){let M=P.get(s);if(R+=1,typeof M<"u"){if(M===R)throw new RangeError("Cyclic object value");v=!0}typeof P.get(Ys)>"u"&&(R=0)}if(typeof p=="function"?_=p(e,_):_ instanceof Date?_=f?.(_):t==="comma"&&X(_)&&(_=Vs(_,function(M){return M instanceof Date?f?.(M):M})),_===null){if(o)return m&&!A?m(e,B.encoder,w,"key",b):e;_=""}if(ni(_)||Jn(_)){if(m){let M=A?e:m(e,B.encoder,w,"key",b);return[y?.(M)+"="+y?.(m(_,B.encoder,w,"value",b))]}return[y?.(e)+"="+y?.(String(_))]}let O=[];if(typeof _>"u")return O;let N;if(t==="comma"&&X(_))A&&m&&(_=Vs(_,m)),N=[{value:_.length>0?_.join(",")||null:void 0}];else if(X(p))N=p;else{let M=Object.keys(_);N=I?M.sort(I):M}let j=l?String(e).replace(/\./g,"%2E"):String(e),J=r&&X(_)&&_.length===1?j+"[]":j;if(n&&X(_)&&_.length===0)return J+"[]";for(let M=0;M<N.length;++M){let U=N[M],Cn=typeof U=="object"&&typeof U.value<"u"?U.value:_[U];if(u&&Cn===null)continue;let js=h&&l?U.replace(/\./g,"%2E"):U,Yo=X(_)?typeof t=="function"?t(J,js):J:J+(h?"."+js:"["+js+"]");k.set(s,R);let Sn=new WeakMap;Sn.set(Ys,k),Vn(O,Yn(Cn,Yo,t,r,n,o,u,l,t==="comma"&&A&&X(_)?null:m,p,I,h,f,b,y,A,w,Sn))}return O}function oi(s=B){if(typeof s.allowEmptyArrays<"u"&&typeof s.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof s.encodeDotInKeys<"u"&&typeof s.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(s.encoder!==null&&typeof s.encoder<"u"&&typeof s.encoder!="function")throw new TypeError("Encoder has to be a function.");let e=s.charset||B.charset;if(typeof s.charset<"u"&&s.charset!=="utf-8"&&s.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let t=Hs;if(typeof s.format<"u"){if(!as(Xs,s.format))throw new TypeError("Unknown format option provided.");t=s.format}let r=Xs[t],n=B.filter;(typeof s.filter=="function"||X(s.filter))&&(n=s.filter);let o;if(s.arrayFormat&&s.arrayFormat in Gn?o=s.arrayFormat:"indices"in s?o=s.indices?"indices":"repeat":o=B.arrayFormat,"commaRoundTrip"in s&&typeof s.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");let u=typeof s.allowDots>"u"?s.encodeDotInKeys?!0:B.allowDots:!!s.allowDots;return{addQueryPrefix:typeof s.addQueryPrefix=="boolean"?s.addQueryPrefix:B.addQueryPrefix,allowDots:u,allowEmptyArrays:typeof s.allowEmptyArrays=="boolean"?!!s.allowEmptyArrays:B.allowEmptyArrays,arrayFormat:o,charset:e,charsetSentinel:typeof s.charsetSentinel=="boolean"?s.charsetSentinel:B.charsetSentinel,commaRoundTrip:!!s.commaRoundTrip,delimiter:typeof s.delimiter>"u"?B.delimiter:s.delimiter,encode:typeof s.encode=="boolean"?s.encode:B.encode,encodeDotInKeys:typeof s.encodeDotInKeys=="boolean"?s.encodeDotInKeys:B.encodeDotInKeys,encoder:typeof s.encoder=="function"?s.encoder:B.encoder,encodeValuesOnly:typeof s.encodeValuesOnly=="boolean"?s.encodeValuesOnly:B.encodeValuesOnly,filter:n,format:t,formatter:r,serializeDate:typeof s.serializeDate=="function"?s.serializeDate:B.serializeDate,skipNulls:typeof s.skipNulls=="boolean"?s.skipNulls:B.skipNulls,sort:typeof s.sort=="function"?s.sort:null,strictNullHandling:typeof s.strictNullHandling=="boolean"?s.strictNullHandling:B.strictNullHandling}}function Qn(s,e={}){let t=s,r=oi(e),n,o;typeof r.filter=="function"?(o=r.filter,t=o("",t)):X(r.filter)&&(o=r.filter,n=o);let u=[];if(typeof t!="object"||t===null)return"";let l=Gn[r.arrayFormat],m=l==="comma"&&r.commaRoundTrip;n||(n=Object.keys(t)),r.sort&&n.sort(r.sort);let p=new WeakMap;for(let f=0;f<n.length;++f){let b=n[f];r.skipNulls&&t[b]===null||Vn(u,Yn(t[b],b,l,m,r.allowEmptyArrays,r.strictNullHandling,r.skipNulls,r.encodeDotInKeys,r.encode?r.encoder:null,r.filter,r.sort,r.allowDots,r.serializeDate,r.format,r.formatter,r.encodeValuesOnly,r.charset,p))}let I=u.join(r.delimiter),h=r.addQueryPrefix===!0?"?":"";return r.charsetSentinel&&(r.charset==="iso-8859-1"?h+="utf8=%26%2310003%3B&":h+="utf8=%E2%9C%93&"),I.length>0?h+I:""}function Zn(s){return Qn(s,{arrayFormat:"brackets"})}function ro(s){let e=0;for(let n of s)e+=n.length;let t=new Uint8Array(e),r=0;for(let n of s)t.set(n,r),r+=n.length;return t}var eo;function Ct(s){let e;return(eo??(e=new globalThis.TextEncoder,eo=e.encode.bind(e)))(s)}var to;function Qs(s){let e;return(to??(e=new globalThis.TextDecoder,to=e.decode.bind(e)))(s)}var Q,Z,De=class{constructor(){Q.set(this,void 0),Z.set(this,void 0),x(this,Q,new Uint8Array,"f"),x(this,Z,null,"f")}decode(e){if(e==null)return[];let t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?Ct(e):e;x(this,Q,ro([c(this,Q,"f"),t]),"f");let r=[],n;for(;(n=ai(c(this,Q,"f"),c(this,Z,"f")))!=null;){if(n.carriage&&c(this,Z,"f")==null){x(this,Z,n.index,"f");continue}if(c(this,Z,"f")!=null&&(n.index!==c(this,Z,"f")+1||n.carriage)){r.push(Qs(c(this,Q,"f").subarray(0,c(this,Z,"f")-1))),x(this,Q,c(this,Q,"f").subarray(c(this,Z,"f")),"f"),x(this,Z,null,"f");continue}let o=c(this,Z,"f")!==null?n.preceding-1:n.preceding,u=Qs(c(this,Q,"f").subarray(0,o));r.push(u),x(this,Q,c(this,Q,"f").subarray(n.index),"f"),x(this,Z,null,"f")}return r}flush(){return c(this,Q,"f").length?this.decode(`
|
|
4
|
+
import{h as Ks,i as Us}from"./chunk-KYXKZJ3Z.js";import{b as Fs,c as En,d as ss,e as On,f as vn,g as Tn}from"./chunk-FZPTNGTU.js";import"./chunk-7MHXMDYC.js";import{J as vr,K as Ls,L as rs,M as Ms,R as $n,e as kn}from"./chunk-4KVSJNS6.js";import"./chunk-MQ5XOYLD.js";import"./chunk-X3UA5OZL.js";function x(s,e,t,r,n){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?s!==e||!n:!e.has(s))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?n.call(s,t):n?n.value=t:e.set(s,t),t}function c(s,e,t,r){if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?s!==e||!r:!e.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?r:t==="a"?r.call(s):r?r.value:e.get(s)}var Ue=function(){let{crypto:s}=globalThis;if(s?.randomUUID)return Ue=s.randomUUID.bind(s),s.randomUUID();let e=new Uint8Array(1),t=s?()=>s.getRandomValues(e)[0]:()=>Math.random()*255&255;return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,r=>(+r^t()&15>>+r/4).toString(16))};function Tr(s){return typeof s=="object"&&s!==null&&("name"in s&&s.name==="AbortError"||"message"in s&&String(s.message).includes("FetchRequestCanceledException"))}var Nr=s=>{if(s instanceof Error)return s;if(typeof s=="object"&&s!==null){try{if(Object.prototype.toString.call(s)==="[object Error]"){let e=new Error(s.message,s.cause?{cause:s.cause}:{});return s.stack&&(e.stack=s.stack),s.cause&&!e.cause&&(e.cause=s.cause),s.name&&(e.name=s.name),e}}catch{}try{return new Error(JSON.stringify(s))}catch{}}return new Error(s)};var g=class extends Error{},T=class s extends g{constructor(e,t,r,n){super(`${s.makeMessage(e,t,r)}`),this.status=e,this.headers=n,this.requestID=n?.get("x-request-id"),this.error=t;let o=t;this.code=o?.code,this.param=o?.param,this.type=o?.type}static makeMessage(e,t,r){let n=t?.message?typeof t.message=="string"?t.message:JSON.stringify(t.message):t?JSON.stringify(t):r;return e&&n?`${e} ${n}`:e?`${e} status code (no body)`:n||"(no status code or body)"}static generate(e,t,r,n){if(!e||!n)return new we({message:r,cause:Nr(t)});let o=t?.error;return e===400?new _t(e,o,r,n):e===401?new gt(e,o,r,n):e===403?new yt(e,o,r,n):e===404?new At(e,o,r,n):e===409?new bt(e,o,r,n):e===422?new It(e,o,r,n):e===429?new wt(e,o,r,n):e>=500?new Pt(e,o,r,n):new s(e,o,r,n)}},F=class extends T{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}},we=class extends T{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}},Pe=class extends we{constructor({message:e}={}){super({message:e??"Request timed out."})}},_t=class extends T{},gt=class extends T{},yt=class extends T{},At=class extends T{},bt=class extends T{},It=class extends T{},wt=class extends T{},Pt=class extends T{},xt=class extends g{constructor(){super("Could not parse response content as the length limit was reached")}},Rt=class extends g{constructor(){super("Could not parse response content as the request was rejected by the content filter")}},ae=class extends Error{constructor(e){super(e)}},Be=class extends T{constructor(e,t,r){let n="OAuth2 authentication error",o;if(t&&typeof t=="object"){let u=t;o=u.error;let l=u.error_description;l&&typeof l=="string"?n=l:o&&(n=o)}super(e,t,n,r),this.error_code=o}},jr=class extends g{constructor(e,t,r){super(e),this.provider=t,this.cause=r}};var Zo=/^[a-z][a-z0-9+.-]*:/i,Nn=s=>Zo.test(s),X=s=>(X=Array.isArray,X(s)),Bs=X;function ns(s){return typeof s!="object"?{}:s??{}}function Ds(s){if(!s)return!0;for(let e in s)return!1;return!0}function jn(s,e){return Object.prototype.hasOwnProperty.call(s,e)}function Lr(s){return s!=null&&typeof s=="object"&&!Array.isArray(s)}var Ln=(s,e)=>{if(typeof e!="number"||!Number.isInteger(e))throw new g(`${s} must be an integer`);if(e<0)throw new g(`${s} must be a positive integer`);return e};var Mn=s=>{try{return JSON.parse(s)}catch{return}};var ue=s=>new Promise(e=>setTimeout(e,s));var xe="6.46.0";var Bn=()=>typeof window<"u"&&typeof window.document<"u"&&typeof navigator<"u";function ei(){return typeof Deno<"u"&&Deno.build!=null?"deno":typeof EdgeRuntime<"u"?"edge":Object.prototype.toString.call(typeof globalThis.process<"u"?globalThis.process:0)==="[object process]"?"node":"unknown"}var ti=()=>{let s=ei();if(s==="deno")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":xe,"X-Stainless-OS":Kn(Deno.build.os),"X-Stainless-Arch":Fn(Deno.build.arch),"X-Stainless-Runtime":"deno","X-Stainless-Runtime-Version":typeof Deno.version=="string"?Deno.version:Deno.version?.deno??"unknown"};if(typeof EdgeRuntime<"u")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":xe,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":globalThis.process.version};if(s==="node")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":xe,"X-Stainless-OS":Kn(globalThis.process.platform??"unknown"),"X-Stainless-Arch":Fn(globalThis.process.arch??"unknown"),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":globalThis.process.version??"unknown"};let e=ri();return e?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":xe,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${e.browser}`,"X-Stainless-Runtime-Version":e.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":xe,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function ri(){if(typeof navigator>"u"||!navigator)return null;let s=[{key:"edge",pattern:/Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"ie",pattern:/Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"chrome",pattern:/Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"firefox",pattern:/Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/},{key:"safari",pattern:/(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/}];for(let{key:e,pattern:t}of s){let r=t.exec(navigator.userAgent);if(r){let n=r[1]||0,o=r[2]||0,u=r[3]||0;return{browser:e,version:`${n}.${o}.${u}`}}}return null}var Fn=s=>s==="x32"?"x32":s==="x86_64"||s==="x64"?"x64":s==="arm"?"arm":s==="aarch64"||s==="arm64"?"arm64":s?`other:${s}`:"unknown",Kn=s=>(s=s.toLowerCase(),s.includes("ios")?"iOS":s==="android"?"Android":s==="darwin"?"MacOS":s==="win32"?"Windows":s==="freebsd"?"FreeBSD":s==="openbsd"?"OpenBSD":s==="linux"?"Linux":s?`Other:${s}`:"Unknown"),Un,Dn=()=>Un??(Un=ti());function os(){if(typeof fetch<"u")return fetch;throw new Error("`fetch` is not defined as a global; Either pass `fetch` to the client, `new OpenAI({ fetch })` or polyfill the global, `globalThis.fetch = fetch`")}function zs(...s){let e=globalThis.ReadableStream;if(typeof e>"u")throw new Error("`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`");return new e(...s)}function is(s){let e=Symbol.asyncIterator in s?s[Symbol.asyncIterator]():s[Symbol.iterator]();return zs({start(){},async pull(t){let{done:r,value:n}=await e.next();r?t.close():t.enqueue(n)},async cancel(){await e.return?.()}})}function qs(s){if(s[Symbol.asyncIterator])return s;let e=s.getReader();return{async next(){try{let t=await e.read();return t?.done&&e.releaseLock(),t}catch(t){throw e.releaseLock(),t}},async return(){let t=e.cancel();return e.releaseLock(),await t,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}async function Ws(s){if(s===null||typeof s!="object")return;if(s[Symbol.asyncIterator]){await s[Symbol.asyncIterator]().return?.();return}let e=s.getReader(),t=e.cancel();e.releaseLock(),await t}var qn=({headers:s,body:e})=>({bodyHeaders:{"content-type":"application/json"},body:JSON.stringify(e)});var Hs="RFC3986",Js=s=>String(s),Xs={RFC1738:s=>String(s).replace(/%20/g,"+"),RFC3986:Js},Wn="RFC1738";var as=(s,e)=>(as=Object.hasOwn??Function.prototype.call.bind(Object.prototype.hasOwnProperty),as(s,e)),ce=(()=>{let s=[];for(let e=0;e<256;++e)s.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return s})();var Gs=1024,Hn=(s,e,t,r,n)=>{if(s.length===0)return s;let o=s;if(typeof s=="symbol"?o=Symbol.prototype.toString.call(s):typeof s!="string"&&(o=String(s)),t==="iso-8859-1")return escape(o).replace(/%u[0-9a-f]{4}/gi,function(l){return"%26%23"+parseInt(l.slice(2),16)+"%3B"});let u="";for(let l=0;l<o.length;l+=Gs){let m=o.length>=Gs?o.slice(l,l+Gs):o,p=[];for(let I=0;I<m.length;++I){let h=m.charCodeAt(I);if(h===45||h===46||h===95||h===126||h>=48&&h<=57||h>=65&&h<=90||h>=97&&h<=122||n===Wn&&(h===40||h===41)){p[p.length]=m.charAt(I);continue}if(h<128){p[p.length]=ce[h];continue}if(h<2048){p[p.length]=ce[192|h>>6]+ce[128|h&63];continue}if(h<55296||h>=57344){p[p.length]=ce[224|h>>12]+ce[128|h>>6&63]+ce[128|h&63];continue}I+=1,h=65536+((h&1023)<<10|m.charCodeAt(I)&1023),p[p.length]=ce[240|h>>18]+ce[128|h>>12&63]+ce[128|h>>6&63]+ce[128|h&63]}u+=p.join("")}return u};function Jn(s){return!s||typeof s!="object"?!1:!!(s.constructor&&s.constructor.isBuffer&&s.constructor.isBuffer(s))}function Vs(s,e){if(X(s)){let t=[];for(let r=0;r<s.length;r+=1)t.push(e(s[r]));return t}return e(s)}var Gn={brackets(s){return String(s)+"[]"},comma:"comma",indices(s,e){return String(s)+"["+e+"]"},repeat(s){return String(s)}},Vn=function(s,e){Array.prototype.push.apply(s,X(e)?e:[e])},Xn,B={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:Hn,encodeValuesOnly:!1,format:Hs,formatter:Js,indices:!1,serializeDate(s){return(Xn??(Xn=Function.prototype.call.bind(Date.prototype.toISOString)))(s)},skipNulls:!1,strictNullHandling:!1};function ni(s){return typeof s=="string"||typeof s=="number"||typeof s=="boolean"||typeof s=="symbol"||typeof s=="bigint"}var Ys={};function Yn(s,e,t,r,n,o,u,l,m,p,I,h,f,b,y,A,w,k){let _=s,P=k,R=0,v=!1;for(;(P=P.get(Ys))!==void 0&&!v;){let M=P.get(s);if(R+=1,typeof M<"u"){if(M===R)throw new RangeError("Cyclic object value");v=!0}typeof P.get(Ys)>"u"&&(R=0)}if(typeof p=="function"?_=p(e,_):_ instanceof Date?_=f?.(_):t==="comma"&&X(_)&&(_=Vs(_,function(M){return M instanceof Date?f?.(M):M})),_===null){if(o)return m&&!A?m(e,B.encoder,w,"key",b):e;_=""}if(ni(_)||Jn(_)){if(m){let M=A?e:m(e,B.encoder,w,"key",b);return[y?.(M)+"="+y?.(m(_,B.encoder,w,"value",b))]}return[y?.(e)+"="+y?.(String(_))]}let O=[];if(typeof _>"u")return O;let N;if(t==="comma"&&X(_))A&&m&&(_=Vs(_,m)),N=[{value:_.length>0?_.join(",")||null:void 0}];else if(X(p))N=p;else{let M=Object.keys(_);N=I?M.sort(I):M}let j=l?String(e).replace(/\./g,"%2E"):String(e),J=r&&X(_)&&_.length===1?j+"[]":j;if(n&&X(_)&&_.length===0)return J+"[]";for(let M=0;M<N.length;++M){let U=N[M],Cn=typeof U=="object"&&typeof U.value<"u"?U.value:_[U];if(u&&Cn===null)continue;let js=h&&l?U.replace(/\./g,"%2E"):U,Yo=X(_)?typeof t=="function"?t(J,js):J:J+(h?"."+js:"["+js+"]");k.set(s,R);let Sn=new WeakMap;Sn.set(Ys,k),Vn(O,Yn(Cn,Yo,t,r,n,o,u,l,t==="comma"&&A&&X(_)?null:m,p,I,h,f,b,y,A,w,Sn))}return O}function oi(s=B){if(typeof s.allowEmptyArrays<"u"&&typeof s.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof s.encodeDotInKeys<"u"&&typeof s.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(s.encoder!==null&&typeof s.encoder<"u"&&typeof s.encoder!="function")throw new TypeError("Encoder has to be a function.");let e=s.charset||B.charset;if(typeof s.charset<"u"&&s.charset!=="utf-8"&&s.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let t=Hs;if(typeof s.format<"u"){if(!as(Xs,s.format))throw new TypeError("Unknown format option provided.");t=s.format}let r=Xs[t],n=B.filter;(typeof s.filter=="function"||X(s.filter))&&(n=s.filter);let o;if(s.arrayFormat&&s.arrayFormat in Gn?o=s.arrayFormat:"indices"in s?o=s.indices?"indices":"repeat":o=B.arrayFormat,"commaRoundTrip"in s&&typeof s.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");let u=typeof s.allowDots>"u"?s.encodeDotInKeys?!0:B.allowDots:!!s.allowDots;return{addQueryPrefix:typeof s.addQueryPrefix=="boolean"?s.addQueryPrefix:B.addQueryPrefix,allowDots:u,allowEmptyArrays:typeof s.allowEmptyArrays=="boolean"?!!s.allowEmptyArrays:B.allowEmptyArrays,arrayFormat:o,charset:e,charsetSentinel:typeof s.charsetSentinel=="boolean"?s.charsetSentinel:B.charsetSentinel,commaRoundTrip:!!s.commaRoundTrip,delimiter:typeof s.delimiter>"u"?B.delimiter:s.delimiter,encode:typeof s.encode=="boolean"?s.encode:B.encode,encodeDotInKeys:typeof s.encodeDotInKeys=="boolean"?s.encodeDotInKeys:B.encodeDotInKeys,encoder:typeof s.encoder=="function"?s.encoder:B.encoder,encodeValuesOnly:typeof s.encodeValuesOnly=="boolean"?s.encodeValuesOnly:B.encodeValuesOnly,filter:n,format:t,formatter:r,serializeDate:typeof s.serializeDate=="function"?s.serializeDate:B.serializeDate,skipNulls:typeof s.skipNulls=="boolean"?s.skipNulls:B.skipNulls,sort:typeof s.sort=="function"?s.sort:null,strictNullHandling:typeof s.strictNullHandling=="boolean"?s.strictNullHandling:B.strictNullHandling}}function Qn(s,e={}){let t=s,r=oi(e),n,o;typeof r.filter=="function"?(o=r.filter,t=o("",t)):X(r.filter)&&(o=r.filter,n=o);let u=[];if(typeof t!="object"||t===null)return"";let l=Gn[r.arrayFormat],m=l==="comma"&&r.commaRoundTrip;n||(n=Object.keys(t)),r.sort&&n.sort(r.sort);let p=new WeakMap;for(let f=0;f<n.length;++f){let b=n[f];r.skipNulls&&t[b]===null||Vn(u,Yn(t[b],b,l,m,r.allowEmptyArrays,r.strictNullHandling,r.skipNulls,r.encodeDotInKeys,r.encode?r.encoder:null,r.filter,r.sort,r.allowDots,r.serializeDate,r.format,r.formatter,r.encodeValuesOnly,r.charset,p))}let I=u.join(r.delimiter),h=r.addQueryPrefix===!0?"?":"";return r.charsetSentinel&&(r.charset==="iso-8859-1"?h+="utf8=%26%2310003%3B&":h+="utf8=%E2%9C%93&"),I.length>0?h+I:""}function Zn(s){return Qn(s,{arrayFormat:"brackets"})}function ro(s){let e=0;for(let n of s)e+=n.length;let t=new Uint8Array(e),r=0;for(let n of s)t.set(n,r),r+=n.length;return t}var eo;function Ct(s){let e;return(eo??(e=new globalThis.TextEncoder,eo=e.encode.bind(e)))(s)}var to;function Qs(s){let e;return(to??(e=new globalThis.TextDecoder,to=e.decode.bind(e)))(s)}var Q,Z,De=class{constructor(){Q.set(this,void 0),Z.set(this,void 0),x(this,Q,new Uint8Array,"f"),x(this,Z,null,"f")}decode(e){if(e==null)return[];let t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?Ct(e):e;x(this,Q,ro([c(this,Q,"f"),t]),"f");let r=[],n;for(;(n=ai(c(this,Q,"f"),c(this,Z,"f")))!=null;){if(n.carriage&&c(this,Z,"f")==null){x(this,Z,n.index,"f");continue}if(c(this,Z,"f")!=null&&(n.index!==c(this,Z,"f")+1||n.carriage)){r.push(Qs(c(this,Q,"f").subarray(0,c(this,Z,"f")-1))),x(this,Q,c(this,Q,"f").subarray(c(this,Z,"f")),"f"),x(this,Z,null,"f");continue}let o=c(this,Z,"f")!==null?n.preceding-1:n.preceding,u=Qs(c(this,Q,"f").subarray(0,o));r.push(u),x(this,Q,c(this,Q,"f").subarray(n.index),"f"),x(this,Z,null,"f")}return r}flush(){return c(this,Q,"f").length?this.decode(`
|
|
5
5
|
`):[]}};Q=new WeakMap,Z=new WeakMap;De.NEWLINE_CHARS=new Set([`
|
|
6
6
|
`,"\r"]);De.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function ai(s,e){for(let n=e??0;n<s.length;n++){if(s[n]===10)return{preceding:n,index:n+1,carriage:!1};if(s[n]===13)return{preceding:n,index:n+1,carriage:!0}}return null}function so(s){for(let r=0;r<s.length-1;r++){if(s[r]===10&&s[r+1]===10||s[r]===13&&s[r+1]===13)return r+2;if(s[r]===13&&s[r+1]===10&&r+3<s.length&&s[r+2]===13&&s[r+3]===10)return r+4}return-1}var cs={off:0,error:200,warn:300,info:400,debug:500},Zs=(s,e,t)=>{if(s){if(jn(cs,s))return s;L(t).warn(`${e} was set to ${JSON.stringify(s)}, expected one of ${JSON.stringify(Object.keys(cs))}`)}};function Mr(){}function us(s,e,t){return!e||cs[s]>cs[t]?Mr:e[s].bind(e)}var ui={error:Mr,warn:Mr,info:Mr,debug:Mr},no=new WeakMap;function L(s){let e=s.logger,t=s.logLevel??"off";if(!e)return ui;let r=no.get(e);if(r&&r[0]===t)return r[1];let n={error:us("error",e,t),warn:us("warn",e,t),info:us("info",e,t),debug:us("debug",e,t)};return no.set(e,[t,n]),n}var me=s=>(s.options&&(s.options={...s.options},delete s.options.headers),s.headers&&(s.headers=Object.fromEntries((s.headers instanceof Headers?[...s.headers]:Object.entries(s.headers)).map(([e,t])=>[e,e.toLowerCase()==="authorization"||e.toLowerCase()==="api-key"||e.toLowerCase()==="x-api-key"||e.toLowerCase()==="x-amz-security-token"||e.toLowerCase()==="cookie"||e.toLowerCase()==="set-cookie"?"***":t]))),"retryOfRequestLogID"in s&&(s.retryOfRequestLogID&&(s.retryOf=s.retryOfRequestLogID),delete s.retryOfRequestLogID),s);var Fr,le=class s{constructor(e,t,r){this.iterator=e,Fr.set(this,void 0),this.controller=t,x(this,Fr,r,"f")}static fromSSEResponse(e,t,r,n){let o=!1,u=r?L(r):console;async function*l(){if(o)throw new g("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");o=!0;let m=!1;try{for await(let p of ci(e,t))if(!m){if(p.data.startsWith("[DONE]")){m=!0;continue}if(p.event===null||!p.event.startsWith("thread.")){let I;try{I=JSON.parse(p.data)}catch(h){throw u.error("Could not parse message into JSON:",p.data),u.error("From chunk:",p.raw),h}if(I&&I.error)throw new T(void 0,I.error,void 0,e.headers);yield n?{event:p.event,data:I}:I}else{let I;try{I=JSON.parse(p.data)}catch(h){throw console.error("Could not parse message into JSON:",p.data),console.error("From chunk:",p.raw),h}if(p.event=="error")throw new T(void 0,I.error,I.message,void 0);yield{event:p.event,data:I}}}m=!0}catch(p){if(Tr(p))return;throw p}finally{m||t.abort()}}return new s(l,t,r)}static fromReadableStream(e,t,r){let n=!1;async function*o(){let l=new De,m=qs(e);for await(let p of m)for(let I of l.decode(p))yield I;for(let p of l.flush())yield p}async function*u(){if(n)throw new g("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let l=!1;try{for await(let m of o())l||m&&(yield JSON.parse(m));l=!0}catch(m){if(Tr(m))return;throw m}finally{l||t.abort()}}return new s(u,t,r)}[(Fr=new WeakMap,Symbol.asyncIterator)](){return this.iterator()}tee(){let e=[],t=[],r=this.iterator(),n=o=>({next:()=>{if(o.length===0){let u=r.next();e.push(u),t.push(u)}return o.shift()}});return[new s(()=>n(e),this.controller,c(this,Fr,"f")),new s(()=>n(t),this.controller,c(this,Fr,"f"))]}toReadableStream(){let e=this,t;return zs({async start(){t=e[Symbol.asyncIterator]()},async pull(r){try{let{value:n,done:o}=await t.next();if(o)return r.close();let u=Ct(JSON.stringify(n)+`
|
|
7
7
|
`);r.enqueue(u)}catch(n){r.error(n)}},async cancel(){await t.return?.()}})}};async function*ci(s,e){if(!s.body)throw e.abort(),typeof globalThis.navigator<"u"&&globalThis.navigator.product==="ReactNative"?new g("The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api"):new g("Attempted to iterate over a response with no body");let t=new en,r=new De,n=qs(s.body);for await(let o of li(n))for(let u of r.decode(o)){let l=t.decode(u);l&&(yield l)}for(let o of r.flush()){let u=t.decode(o);u&&(yield u)}}async function*li(s){let e=new Uint8Array;for await(let t of s){if(t==null)continue;let r=t instanceof ArrayBuffer?new Uint8Array(t):typeof t=="string"?Ct(t):t,n=new Uint8Array(e.length+r.length);n.set(e),n.set(r,e.length),e=n;let o;for(;(o=so(e))!==-1;)yield e.slice(0,o),e=e.slice(o)}e.length>0&&(yield e)}var en=class{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith("\r")&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;let o={event:this.event,data:this.data.join(`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __swiftyCreateRequire } from "node:module";
|
|
3
3
|
const require = __swiftyCreateRequire(import.meta.url);
|
|
4
|
-
import{A as di,B as xi,C as vi,D as fi,E as bi,F as gi,G as hi,L as yi,N as wi,P as ki,Q as ji,R as Ei,S as Xe,T as qi,U as Si,V as Ti,W as Ci,X as zi,Z as _i,a as Ie,b as He,c as $e,da as Pi,ea as Ai,fa as Ri,g as ce,ga as Oi,h as pe,ha as Li,i as le,ia as Mi,j as ue,k as me,l as de,m as Va,n as ei,o as ai,p as ii,q as oi,r as Ge,s as ti,t as ri,u as ci,v as pi,w as li,x as ui,y as mi}from"./chunk-
|
|
4
|
+
import{A as di,B as xi,C as vi,D as fi,E as bi,F as gi,G as hi,L as yi,N as wi,P as ki,Q as ji,R as Ei,S as Xe,T as qi,U as Si,V as Ti,W as Ci,X as zi,Z as _i,a as Ie,b as He,c as $e,da as Pi,ea as Ai,fa as Ri,g as ce,ga as Oi,h as pe,ha as Li,i as le,ia as Mi,j as ue,k as me,l as de,m as Va,n as ei,o as ai,p as ii,q as oi,r as Ge,s as ti,t as ri,u as ci,v as pi,w as li,x as ui,y as mi}from"./chunk-WGVF7CNO.js";import{c as ni,d as si,j as Y}from"./chunk-IZ23BHLA.js";import{e as K}from"./chunk-S2DPVNBA.js";import{a as re}from"./chunk-UBV5T4TV.js";import{a as Ue,b as $a}from"./chunk-2PFMEUGN.js";import{a as L,e as Xa,f as Ba,g as oe,h as De,i as Wa,j as Za,k as te,o as Ya}from"./chunk-DCI5RJC7.js";import{f as Ka,g as Ja,h as Qa}from"./chunk-KYXKZJ3Z.js";import"./chunk-FZPTNGTU.js";import"./chunk-7MHXMDYC.js";import{I as q,R as Ne,e as Ga}from"./chunk-4KVSJNS6.js";import"./chunk-MQ5XOYLD.js";import{a as x,b as l,d as mt}from"./chunk-X3UA5OZL.js";var Ui=l((Hl,Fi)=>{"use strict";Fi.exports=dt;function dt(e,a){if(!Array.isArray(e))throw new TypeError("arg must be an array of [ee, events...] arrays");for(var i=[],n=0;n<e.length;n++){var s=e[n];if(!Array.isArray(s)||s.length<2)throw new TypeError("each array member must be [ee, events...]");for(var o=s[0],t=1;t<s.length;t++){var r=s[t],c=xt(r,p);o.on(r,c),i.push({ee:o,event:r,fn:c})}}function p(){m(),a.apply(null,arguments)}function m(){for(var d,f=0;f<i.length;f++)d=i[f],d.ee.removeListener(d.event,d.fn)}function u(d){a=d}return u.cancel=m,u}function xt(e,a){return function(n){for(var s=new Array(arguments.length),o=this,t=e==="error"?n:null,r=0;r<s.length;r++)s[r]=arguments[r];a(t,o,e,s)}}});var We=l(($l,Be)=>{"use strict";Be.exports=ft;Be.exports.isFinished=Ii;var Ni=wt(),Di=Ui(),vt=typeof setImmediate=="function"?setImmediate:function(e){process.nextTick(e.bind.apply(e,arguments))};function ft(e,a){return Ii(e)!==!1?(vt(a,null,e),e):(gt(e,kt(a)),e)}function Ii(e){var a=e.socket;if(typeof e.finished=="boolean")return!!(e.finished||a&&!a.writable);if(typeof e.complete=="boolean")return!!(e.upgrade||!a||!a.readable||e.complete&&!e.readable)}function bt(e,a){var i,n,s=!1;function o(r){i.cancel(),n.cancel(),s=!0,a(r)}i=n=Di([[e,"end","finish"]],o);function t(r){e.removeListener("socket",t),!s&&i===n&&(n=Di([[r,"error","close"]],o))}if(e.socket){t(e.socket);return}e.on("socket",t),e.socket===void 0&&yt(e,t)}function gt(e,a){var i=e.__onFinished;(!i||!i.queue)&&(i=e.__onFinished=ht(e),bt(e,i)),i.queue.push(a)}function ht(e){function a(i){if(e.__onFinished===a&&(e.__onFinished=null),!!a.queue){var n=a.queue;a.queue=null;for(var s=0;s<n.length;s++)n[s](i,e)}}return a.queue=[],a}function yt(e,a){var i=e.assignSocket;typeof i=="function"&&(e.assignSocket=function(s){i.call(this,s),a(s)})}function wt(){try{return x("async_hooks")}catch{return{}}}function kt(e){var a;return Ni.AsyncResource&&(a=new Ni.AsyncResource(e.name||"bound-anonymous-fn")),!a||!a.runInAsyncScope?e:a.runInAsyncScope.bind(a,e,null)}});var $i=l((Gl,Hi)=>{"use strict";Hi.exports=jt;function jt(e){if(!Array.isArray(e))throw new TypeError("Middleware stack must be an array!");for(let a of e)if(typeof a!="function")throw new TypeError("Middleware must be composed of functions!");return function(a,i){let n=-1;return s(0);function s(o){if(o<=n)return Promise.reject(new Error("next() called multiple times"));n=o;let t=e[o];if(o===e.length&&(t=i),!t)return Promise.resolve();try{return Promise.resolve(t(a,s.bind(null,o+1)))}catch(r){return Promise.reject(r)}}}}});var Gi=l((Xl,Et)=>{Et.exports={"100":"Continue","101":"Switching Protocols","102":"Processing","103":"Early Hints","200":"OK","201":"Created","202":"Accepted","203":"Non-Authoritative Information","204":"No Content","205":"Reset Content","206":"Partial Content","207":"Multi-Status","208":"Already Reported","226":"IM Used","300":"Multiple Choices","301":"Moved Permanently","302":"Found","303":"See Other","304":"Not Modified","305":"Use Proxy","307":"Temporary Redirect","308":"Permanent Redirect","400":"Bad Request","401":"Unauthorized","402":"Payment Required","403":"Forbidden","404":"Not Found","405":"Method Not Allowed","406":"Not Acceptable","407":"Proxy Authentication Required","408":"Request Timeout","409":"Conflict","410":"Gone","411":"Length Required","412":"Precondition Failed","413":"Payload Too Large","414":"URI Too Long","415":"Unsupported Media Type","416":"Range Not Satisfiable","417":"Expectation Failed","418":"I'm a Teapot","421":"Misdirected Request","422":"Unprocessable Entity","423":"Locked","424":"Failed Dependency","425":"Too Early","426":"Upgrade Required","428":"Precondition Required","429":"Too Many Requests","431":"Request Header Fields Too Large","451":"Unavailable For Legal Reasons","500":"Internal Server Error","501":"Not Implemented","502":"Bad Gateway","503":"Service Unavailable","504":"Gateway Timeout","505":"HTTP Version Not Supported","506":"Variant Also Negotiates","507":"Insufficient Storage","508":"Loop Detected","509":"Bandwidth Limit Exceeded","510":"Not Extended","511":"Network Authentication Required"}});var J=l((Bl,Bi)=>{"use strict";var Ze=Gi();Bi.exports=_;_.message=Ze;_.code=qt(Ze);_.codes=St(Ze);_.redirect={300:!0,301:!0,302:!0,303:!0,305:!0,307:!0,308:!0};_.empty={204:!0,205:!0,304:!0};_.retry={502:!0,503:!0,504:!0};function qt(e){var a={};return Object.keys(e).forEach(function(n){var s=e[n],o=Number(n);a[s.toLowerCase()]=o}),a}function St(e){return Object.keys(e).map(function(i){return Number(i)})}function Tt(e){var a=e.toLowerCase();if(!Object.prototype.hasOwnProperty.call(_.code,a))throw new Error('invalid status message: "'+e+'"');return _.code[a]}function Xi(e){if(!Object.prototype.hasOwnProperty.call(_.message,e))throw new Error("invalid status code: "+e);return _.message[e]}function _(e){if(typeof e=="number")return Xi(e);if(typeof e!="string")throw new TypeError("code must be a number or string");var a=parseInt(e,10);return isNaN(a)?Tt(e):Xi(a)}});var Ke=l((Wl,Ki)=>{"use strict";var Ct=x("path").relative;Ki.exports=Rt;var zt=process.cwd();function Zi(e,a){for(var i=e.split(/[ ,]+/),n=String(a).toLowerCase(),s=0;s<i.length;s++){var o=i[s];if(o&&(o==="*"||o.toLowerCase()===n))return!0}return!1}function _t(e,a,i){var n=Object.getOwnPropertyDescriptor(e,a),s=n.value;return n.get=function(){return s},n.writable&&(n.set=function(t){return s=t}),delete n.value,delete n.writable,Object.defineProperty(e,a,n),n}function Pt(e){for(var a="",i=0;i<e;i++)a+=", arg"+i;return a.substr(2)}function At(e){var a=this.name+": "+this.namespace;this.message&&(a+=" deprecated "+this.message);for(var i=0;i<e.length;i++)a+=`
|
|
5
5
|
at `+e[i].toString();return a}function Rt(e){if(!e)throw new TypeError("argument namespace is required");var a=ve(),i=H(a[1]),n=i[0];function s(o){xe.call(s,o)}return s._file=n,s._ignored=Lt(e),s._namespace=e,s._traced=Mt(e),s._warned=Object.create(null),s.function=Dt,s.property=It,s}function Ot(e,a){var i=typeof e.listenerCount!="function"?e.listeners(a).length:e.listenerCount(a);return i>0}function Lt(e){if(process.noDeprecation)return!0;var a=process.env.NO_DEPRECATION||"";return Zi(a,e)}function Mt(e){if(process.traceDeprecation)return!0;var a=process.env.TRACE_DEPRECATION||"";return Zi(a,e)}function xe(e,a){var i=Ot(process,"deprecation");if(!(!i&&this._ignored)){var n,s,o,t,r=0,c=!1,p=ve(),m=this._file;for(a?(t=a,o=H(p[1]),o.name=t.name,m=o[0]):(r=2,t=H(p[r]),o=t);r<p.length;r++)if(n=H(p[r]),s=n[0],s===m)c=!0;else if(s===this._file)m=this._file;else if(c)break;var u=n?t.join(":")+"__"+n.join(":"):void 0;if(!(u!==void 0&&u in this._warned)){this._warned[u]=!0;var d=e;if(d||(d=o===t||!o.name?Wi(t):Wi(o)),i){var f=Yi(this._namespace,d,p.slice(r));process.emit("deprecation",f);return}var h=process.stderr.isTTY?Ut:Ft,P=h.call(this,d,n,p.slice(r));process.stderr.write(P+`
|
|
6
6
|
`,"utf8")}}}function H(e){var a=e.getFileName()||"<anonymous>",i=e.getLineNumber(),n=e.getColumnNumber();e.isEval()&&(a=e.getEvalOrigin()+", "+a);var s=[a,i,n];return s.callSite=e,s.name=e.getFunctionName(),s}function Wi(e){var a=e.callSite,i=e.name;i||(i="<anonymous@"+Ye(e)+">");var n=a.getThis(),s=n&&a.getTypeName();return s==="Object"&&(s=void 0),s==="Function"&&(s=n.name||s),s&&a.getMethodName()?s+"."+i:i}function Ft(e,a,i){var n=new Date().toUTCString(),s=n+" "+this._namespace+" deprecated "+e;if(this._traced){for(var o=0;o<i.length;o++)s+=`
|
|
7
7
|
at `+i[o].toString();return s}return a&&(s+=" at "+Ye(a)),s}function Ut(e,a,i){var n="\x1B[36;1m"+this._namespace+"\x1B[22;39m \x1B[33;1mdeprecated\x1B[22;39m \x1B[0m"+e+"\x1B[39m";if(this._traced){for(var s=0;s<i.length;s++)n+=`
|
|
@@ -21,7 +21,7 @@ ${n.replace(/^/gm," ")}
|
|
|
21
21
|
`)}static get default(){return Bo}};function ml(e){if(e.respond===!1)return;let a=e.res;if(!e.writable)return a.end();let i=e.body,n=e.status;if(ol.empty[n])return e.body=null,a.end();if(e.method==="HEAD"){if(!a.headersSent&&!e.response.has("Content-Length")){let{length:o}=e.response;Number.isInteger(o)&&(e.length=o)}return a.end()}if(i==null)return e.response._explicitNullBody?(e.response.remove("Content-Type"),e.response.remove("Transfer-Encoding"),e.length=0,a.end()):(e.req.httpVersionMajor>=2?i=String(n):i=e.message||String(n),a.headersSent||(e.type="text",e.length=Buffer.byteLength(i)),a.end(i));if(Buffer.isBuffer(i)||typeof i=="string")return a.end(i);let s=null;if(i instanceof Blob?s=Re.Readable.from(i.stream()):i instanceof ReadableStream?s=Re.Readable.from(i):i instanceof Response?s=Re.Readable.from(i?.body||""):ll(i)&&(s=i),s)return Re.pipeline(s,a,o=>{o&&e.app.listenerCount("error")&&e.onerror(o)});i=JSON.stringify(i),a.headersSent||(e.length=Buffer.byteLength(i)),a.end(i)}_a.exports.HttpError=tl});var Pa=mt(Wo(),1),Zo=Pa.default,Hu=Pa.default.HttpError;import{createServer as zl}from"http";import{readFileSync as _l,existsSync as Pl,statSync as Al}from"fs";import{join as ot,extname as Rl,normalize as Ol}from"path";import{cwd as ae}from"process";import{existsSync as Aa,statSync as Qo,readFileSync as Yo,writeFileSync as Vo,mkdirSync as dl,unlinkSync as xl,utimesSync as vl}from"fs";import{join as ee,basename as Ko}from"path";import{homedir as Jo}from"os";var fl=24,bl=5,gl=600*1e3,hl=".consolidate-lock",yl=3600*1e3,wl=200,Le=class{client;workDir;lastScanAt=0;minHours;minSessions;appendSystem;constructor(a,i,n){this.client=a,this.workDir=i,this.minHours=n?.minHours??fl,this.minSessions=n?.minSessions??bl,this.appendSystem=n?.appendSystem}maybeRun(){let a=ee(this.workDir,".swifty","memory");if(!Aa(a))return Promise.resolve();let i=kl(a);if((Date.now()-i)/36e5<this.minHours)return Promise.resolve();let s=Date.now();if(s-this.lastScanAt<gl)return Promise.resolve();this.lastScanAt=s;let o=Sl(this.workDir,i);if(o.length<this.minSessions)return Promise.resolve();let t=jl(a);return t===null||this.run(a,o,t).catch(()=>{El(a,t)}),Promise.resolve()}async run(a,i,n){let s=ee(Jo(),".swifty","memory"),o=ee(this.workDir,".swifty","sessions"),t=Tl(a,s,o,i),r=new re;r.register(new ce),r.register(new me),r.register(new de),r.register(new le),r.register(new ue),r.register(new pe);let c=new K(this.workDir,"bypassPermissions");c.allowExtraRoot(ee(Jo(),".swifty","memory"));let p=new L;p.addUserMessage(t);let m=new Y({client:this.client,registry:r,checker:c,conversation:p,workDir:this.workDir,maxIterations:15});for await(let f of m.run())console.log(f.type);let d=Cl(p.getMessages()).filter(f=>Ko(f)!=="MEMORY.md");if(d.length>0&&this.appendSystem){let f=d.map(h=>Ko(h));this.appendSystem(`Memory improved: ${f.join(", ")}`)}}};function Ra(e){return ee(e,hl)}function kl(e){let a=Ra(e);if(!Aa(a))return 0;try{return Qo(a).mtimeMs}catch{return 0}}function jl(e){let a=Ra(e),i,n;if(Aa(a))try{i=Qo(a).mtimeMs;let s=Yo(a,"utf-8").trim(),o=parseInt(s,10);Number.isFinite(o)&&(n=o)}catch(s){console.error(s)}if(i!==void 0&&Date.now()-i<yl&&n!==void 0&&ql(n))return null;dl(e,{recursive:!0}),Vo(a,String(process.pid));try{let s=Yo(a,"utf-8").trim();if(parseInt(s,10)!==process.pid)return null}catch{return null}return i??0}function El(e,a){let i=Ra(e);try{if(a===0){xl(i);return}Vo(i,"");let n=a/1e3;vl(i,n,n)}catch(n){console.error(n)}}function ql(e){try{return process.kill(e,0),!0}catch{return!1}}function Sl(e,a){let i=te(e),n=new Date(a);return i.filter(s=>s.modTime>n).map(s=>s.id)}function Tl(e,a,i,n){let s=["# Dream: Memory Consolidation","","You are performing a dream \u2014 a reflective pass over your memory files. Synthesize what you've learned recently into durable, well-organized memories so that future sessions can orient quickly.","",`Project memory directory: \`${e}\``,`User memory directory: \`${a}\``,"The memory directory already exists \u2014 write to it directly.","",`Session transcripts: \`${i}\` (large JSONL files \u2014 grep narrowly, don't read whole files)`,"","---","","## Phase 1 \u2014 Orient","","- `ls` the memory directory to see what already exists","- Read `MEMORY.md` to understand the current index","- Skim existing topic files so you improve them rather than creating duplicates","","## Phase 2 \u2014 Gather recent signal","","Look for new information worth persisting:","","1. **Existing memories that drifted** \u2014 facts that contradict something you see in the codebase now","2. **Transcript search** \u2014 if you need specific context, grep the JSONL transcripts for narrow terms","","Don't exhaustively read transcripts. Look only for things you already suspect matter.","","## Phase 3 \u2014 Consolidate","","For each thing worth remembering, write or update a memory file. Each memory file uses YAML frontmatter with name, description, and metadata.type fields, followed by a Markdown body.","","Focus on:","- Merging new signal into existing topic files rather than creating near-duplicates",'- Converting relative dates ("yesterday", "last week") to absolute dates so they remain interpretable after time passes',"- Deleting contradicted facts \u2014 if today's investigation disproves an old memory, fix it at the source","","## Phase 4 \u2014 Prune and index","",`Update \`MEMORY.md\` so it stays under ${String(wl)} lines AND under ~25KB. It's an **index**, not a dump \u2014 each entry should be one line under ~150 characters: \`- [Title](file.md) \u2014 one-line hook\`. Never write memory content directly into it.`,"","- Remove pointers to memories that are now stale, wrong, or superseded","- Demote verbose entries: if an index line is over ~200 chars, it's carrying content that belongs in the topic file \u2014 shorten the line, move the detail","- Add pointers to newly important memories","- Resolve contradictions \u2014 if two files disagree, fix the wrong one","","---","","**Tool constraints for this run:** Bash is restricted to read-only commands (`ls`, `find`, `grep`, `cat`, `stat`, `wc`, `head`, `tail`, and similar). Anything that writes, redirects to a file, or modifies state will be denied.",""];if(n.length>0){s.push(`Sessions since last consolidation (${String(n.length)}):`);for(let o of n)s.push(`- ${o}`)}return s.push("","Return a brief summary of what you consolidated, updated, or pruned. If nothing changed (memories are already tight), say so."),s.join(`
|
|
22
22
|
`)}function Cl(e){let a=[],i=new Set;for(let n of e){if(n.role!=="assistant")continue;let s=n.content.matchAll(/"file_path"\s*:\s*"([^"]+)"/g);for(let o of s)o[1]&&!i.has(o[1])&&(i.add(o[1]),a.push(o[1]))}return a}var T=Ga({module:"remote"}),Ll=q.object({type:q.string(),data:q.unknown()}),Ml=q.object({content:q.string()}),Fl=q.object({id:q.string(),response:q.enum(["allow","deny","allowAlways"])}),Ul=q.object({id:q.string(),answers:q.record(q.string(),q.string())}),et=ot(import.meta.dirname,"fe","dist"),Nl={".html":"text/html; charset=utf-8",".js":"application/javascript; charset=utf-8",".css":"text/css; charset=utf-8",".png":"image/png",".svg":"image/svg+xml",".ico":"image/x-icon",".json":"application/json; charset=utf-8",".woff2":"font/woff2"};function at(e){let a=Ol(e).replace(/^(\.\.[/\\])+/,""),i=ot(et,a);if(!i.startsWith(et)||!Pl(i)||!Al(i).isFile())return null;let n=_l(i),s=Nl[Rl(i)]??"application/octet-stream";return{body:n,mime:s}}var Oa=class{client;conv;registry;sessionId;fileHistory;fileStateCache;cmdRegistry;skillCatalog;activeSkills;toolFilter;mcpManager;hookEngine;recoveryState;teamManager;enableCoordinatorMode;forkDisabled;memoryManager;contextWindow;ltmInstructions;ltmMemoryContent;mcpInstructions;provider;workDir;abortController=null;constructor(a){this.client=a.client,this.conv=a.conv,this.registry=a.registry,this.sessionId=a.sessionId,this.fileHistory=a.fileHistory,this.fileStateCache=a.fileStateCache,this.cmdRegistry=a.cmdRegistry,this.skillCatalog=a.skillCatalog,this.activeSkills=a.activeSkills,this.toolFilter=a.toolFilter,this.mcpManager=a.mcpManager,this.hookEngine=a.hookEngine,this.recoveryState=a.recoveryState,this.teamManager=a.teamManager,this.enableCoordinatorMode=a.enableCoordinatorMode,this.forkDisabled=a.forkDisabled,this.memoryManager=a.memoryManager,this.contextWindow=a.contextWindow,this.ltmInstructions=a.ltmInstructions,this.ltmMemoryContent=a.ltmMemoryContent,this.mcpInstructions=a.mcpInstructions,this.provider=a.provider,this.workDir=a.workDir,this.abortController=null}async*run(a,i){this.conv.addUserMessage(a),this.mcpInstructions&&(this.conv.addSystemReminder(this.mcpInstructions),this.mcpInstructions=""),this.abortController=new AbortController;try{let n=new K(this.workDir,"default");yield*new Y({client:this.client,registry:this.registry,checker:n,conversation:this.conv,workDir:this.workDir,sessionId:this.sessionId,hookEngine:this.hookEngine??void 0,fileHistory:this.fileHistory??void 0,fileStateCache:this.fileStateCache,abortSignal:this.abortController.signal,contextWindow:this.contextWindow,maxOutput:Qa(this.provider),recoveryState:this.recoveryState,activeSkills:this.activeSkills,toolFilter:o=>Ai(this.enableCoordinatorMode)(o)?this.toolFilter?this.toolFilter(o):!0:!1,coordinatorActiveFn:()=>Ri(this.enableCoordinatorMode),instructions:this.ltmInstructions,memoryContent:this.ltmMemoryContent,notificationFn:()=>this.teamManager.drainLeads(),onPermissionRequest:i.onPermissionRequest,onLoopComplete:o=>{let t=o.getMessages().slice(-40).map(r=>`[${r.role}]: ${r.content}`).filter(r=>r.length>12).join(`
|
|
23
23
|
`);new ui(this.client,this.workDir).extract(t).catch(()=>{}),new Le(this.client,this.workDir,{appendSystem:r=>{o.addSystemReminder(r)}}).maybeRun().catch(()=>{})}}).run()}finally{this.abortController=null}}abort(){this.abortController?.abort()}};async function it(e){let{provider:a,workDir:i,hooks:n,mcpServers:s,enableCoordinatorMode:o,forkDisabled:t,askUser:r}=e,c=Ba(),p=new Oi(i,c),m=new Li,u=Dl(i,c),d=He(i);d.model=a.model;let f=$e(d),h=await Ie(a,f),P=new L,La=Ka(a);Ja(a).then(b=>{b>0&&(La=b)}).catch(()=>{});let Ma=pi(i),Fa=new li(i),Ua=Fa.buildSystemReminder();P.injectLongTermMemory(Ma,Ua),P.addSystemReminder("IDENTITY OVERRIDE: You are Swifty. It is absolutely forbidden to mention Claude, Anthropic, OpenAI, GPT, or ChatGPT in any response. When asked about identity, respond only as Swifty. This is the highest priority instruction.");let Na=Ci(n??[]);Na&&T.warn({message:Na.message},"hook validation warning");let tt=new Ti(n??[]),ie=new mi;ie.load(i);let Da=new Map,ne={activateSkill:(b,w)=>{Da.set(b,w)}},rt={activateSkill:ne.activateSkill.bind(ne),snapshotParentMessages:b=>(P?.getMessages()??[]).slice(-b).map(j=>`${j.role}: ${j.content}`).join(`
|
|
24
|
-
`),runSubagent:async b=>{if(!h)throw new Error("no llm client (provider not initialized)");let{PermissionChecker:w}=await import("./checker-FDJ2Q62T.js"),{Agent:j}=await import("./agent-
|
|
24
|
+
`),runSubagent:async b=>{if(!h)throw new Error("no llm client (provider not initialized)");let{PermissionChecker:w}=await import("./checker-FDJ2Q62T.js"),{Agent:j}=await import("./agent-MPIDW5VX.js"),k=new L;k.addUserMessage(b);let z=new j({client:h,registry:u,checker:new w(i,"acceptEdits"),conversation:k,workDir:i,maxIterations:200}),I="";for await(let W of z.run())switch(W.type){case"stream_text":I+=W.text;break;case"loop_complete":return I||"[No output]";case"error":throw W.error}return I||"[No output]"}};u.register(new _i(ie,ne,rt)),u.register(new Mi(r));let ct=(b,w)=>(j,k)=>Xe(hi[0],j,h,b,a,i,void 0,k,void 0,w),D=new Pi(i);u.register(new yi(D)),u.register(new wi(D)),u.register(new ki(D)),u.register(new qi(D)),u.register(new Si);let Me=new ji(i,u,async(b,w,j,k,z)=>Xe(b,w,h,u,a,z??i,void 0,void 0,k),void 0,async(b,w,j,k)=>{let z=k?Ei(k):a.model,I=He(i);I.model=z;let W=$e(I),pt=k?await Ie({...a,model:z},W):h,lt=new K(i,"acceptEdits");w.addUserMessage(b);let ut=new Y({client:pt,registry:j,checker:lt,conversation:w,workDir:i,maxIterations:200}),Z="";for await(let se of ut.run())switch(se.type){case"stream_text":Z+=se.text;break;case"loop_complete":return Z||"[No output]";case"error":return Z?`${Z}
|
|
25
25
|
|
|
26
26
|
[Error: ${se.error.message}]`:`Error: ${se.error.message}`}return Z||"[No output]"});Me.forkDisabled=t,Me.setTeamManager(D,ct),u.register(Me);let Fe=Ge();for(let b of ti(i))try{Fe.register(b)}catch{}Il(ie,ne,Fe);let Ia=null,Ha="";if(s&&s.length>0){let b=new ri;Ia=b;let w=await b.connectAll(s);for(let{serverName:j,tool:k}of w.tools){let z=b.getClient(j);z&&u.register(new ci(z,j,k))}for(let{serverName:j,error:k}of w.errors)T.error({serverName:j,error:k},"MCP server connection error");w.instructions.length>0&&(Ha=`# MCP Server Instructions
|
|
27
27
|
|
|
@@ -37,7 +37,7 @@ ${o.join(`
|
|
|
37
37
|
`)}`}})}}this.broadcast({type:"command_done",data:null});break}case"sandbox":this.broadcast({type:"system",data:{message:"Sandbox toggle is not yet supported in remote mode."}}),this.broadcast({type:"command_done",data:null});break;case"worktree":this.broadcast({type:"system",data:{message:"Worktree management is not yet supported in remote mode."}}),this.broadcast({type:"command_done",data:null});break;default:this.broadcast({type:"command_done",data:null});break}}buildCommandContext(a){let i=this.agentHandle;return i?{workDir:i.workDir,args:a,permissionMode:()=>"default",tokenCount:()=>[0,0],toolCount:()=>i.registry.listTools().length,memoryList:()=>i.memoryManager.getMemories().map(n=>n.name),model:i.provider.model}:{workDir:ae(),args:a,model:""}}async handleCompact(){if(!this.agentHandle)return;let a=this.agentHandle;this.broadcast({type:"system",data:{message:"Compacting conversation..."}});try{let i=a.registry.listTools().map(o=>o.name),n=a.registry.getAllSchemas(),s=await Ya(a.conv,a.client,a.recoveryState,i,n,Xa(a.workDir,a.sessionId));this.broadcast({type:"system",data:{message:`Compacted: ${s.message}`}}),s.boundary&&De(a.workDir,a.sessionId,s.boundary)}catch(i){this.broadcast({type:"error",data:{message:i instanceof Error?i.message:String(i)}})}this.broadcast({type:"command_done",data:null})}async handlePlan(a){if(!this.agentHandle)return;let i=this.agentHandle,n=i.workDir,s=si(n);if(this.broadcast({type:"system",data:{message:`Entered Plan mode. Plan file: ${s}
|
|
38
38
|
Explore the codebase and design your approach.`}}),a){this.streaming=!0,oe(n,i.sessionId,{role:"user",content:`/plan ${a}`,timestamp:Math.floor(Date.now()/1e3)});let o=Date.now();try{let t={onPermissionRequest:this.createPermissionCallback()},r="";for await(let c of i.run(a,t))(c.type==="tool_result"||c.type==="turn_complete"||c.type==="loop_complete")&&r&&(this.broadcast({type:"stream_end",data:{text:r}}),r=""),this.bridgeEvent(c,o,n,i.sessionId,p=>{r+=p})}catch(t){T.error({err:t},"agent stream error in plan command"),this.broadcast({type:"error",data:{message:t instanceof Error?t.message:String(t)}})}finally{this.streaming=!1}}else this.broadcast({type:"command_done",data:null})}handleResume(a){if(!this.agentHandle)return;let i=this.agentHandle,n=i.workDir,s=te(n);if(!a){if(s.length===0){this.broadcast({type:"system",data:{message:"No previous sessions found."}}),this.broadcast({type:"command_done",data:null});return}let p=[`Available sessions (${String(s.length)}):
|
|
39
39
|
`];for(let m=0;m<Math.min(s.length,20);m++){let u=s[m],d=u.firstMessage;d.length>60&&(d=d.slice(0,60)+"..."),p.push(` ${String(m+1)}. [${u.id}] ${d} (${String(u.messageCount)} msgs)`)}s.length>20&&p.push(` ... and ${String(s.length-20)} more`),p.push(`
|
|
40
|
-
Usage: /resume <number> or /resume <
|
|
40
|
+
Usage: /resume <number> or /resume <sess-id>`),this.broadcast({type:"system",data:{message:p.join(`
|
|
41
41
|
`)}}),this.broadcast({type:"command_done",data:null});return}let o=a.trim(),t=parseInt(o,10);!Number.isNaN(t)&&t>=1&&t<=s.length&&(o=s[t-1].id);let r=Wa(n,o);if(r.length===0){this.broadcast({type:"error",data:{message:`Session '${o}' not found or empty.`}}),this.broadcast({type:"command_done",data:null});return}i.conv=new L,i.sessionId=o;let c=Za(r);this.broadcast({type:"clear",data:null});for(let p of c)p.toolUses?.length?i.conv.addAssistantMessageWithTools(p.content,p.toolUses.map(m=>({...m,arguments:m.arguments??{}}))):p.toolResults?.length?i.conv.addToolResultsMessage(p.toolResults.map(m=>({...m,isError:m.isError??!1}))):p.role==="user"?i.conv.addUserMessage(p.content):i.conv.addAssistantMessage(p.content),p.content&&(p.role==="user"?this.broadcast({type:"replay_user",data:{content:p.content}}):this.broadcast({type:"replay_assistant",data:{content:p.content}}));this.broadcast({type:"system",data:{message:`Session ${o} restored (${String(c.length)} messages).`}}),this.broadcast({type:"command_done",data:null})}createAskUserCallback(){return async a=>{let i=`ask_${Date.now().toString(36)}`;return this.broadcast({type:"ask_user",data:{id:i,questions:a}}),new Promise(n=>{this.pendingAsks.set(i,n)})}}createPermissionCallback(){return async(a,i,n)=>{let s=`perm_${Date.now().toString(36)}`,o=nt(a,i,n);return this.broadcast({type:"permission_request",data:{id:s,toolName:a,description:o}}),new Promise(t=>{this.pendingPermissions.set(s,t)})}}buildCommandList(){return this.agentHandle?this.agentHandle.cmdRegistry.listCommands().map(a=>({name:a.name,description:a.description})):Ge().listCommands().map(i=>({name:i.name,description:i.description}))}send(a,i){if(a.readyState===Ue.default.OPEN)try{a.send(JSON.stringify(i))}catch{}}broadcast(a){if(this.clients.size===0)return;let i=JSON.stringify(a);for(let n of this.clients)if(n.readyState===Ue.default.OPEN)try{n.send(i)}catch{}}async run(){try{this.agentHandle=await it({provider:this.opts.providers[0],workDir:ae(),hooks:this.opts.hookConfigs,mcpServers:this.opts.mcpServers,askUser:this.createAskUserCallback(),enableCoordinatorMode:this.opts.enableCoordinatorMode,forkDisabled:this.opts.forkDisabled}),T.info({sessionId:this.agentHandle.sessionId},"agent initialized")}catch(s){T.warn({err:s},"agent init deferred -- will retry on first message"),this.agentHandle=null}let a=this.opts.addr.split(":"),i=a[0]||"0.0.0.0",n=parseInt(a[1]??"18888",10);return new Promise((s,o)=>{this.server.on("error",o),this.server.listen(n,i,()=>{T.info({host:i,port:n},"Koa server listening"),T.info({host:i,port:n},"WebSocket server ready"),s()})})}stop(){for(let a of this.clients)a.close();this.clients.clear(),this.wss.close(),this.server.close()}};export{st as RemoteServer,it as createRemoteAgent};
|
|
42
42
|
/*! Bundled license information:
|
|
43
43
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swifty.js/swifty",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Swifty — CLI coding agent",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"scripts": {
|
|
37
37
|
"fe:dev": "cd src/remote/fe && tsup --watch",
|
|
38
38
|
"fe:build": "cd src/remote/fe && tsup",
|
|
39
|
-
"fe:preview": "
|
|
39
|
+
"fe:preview": "pnpm dlx serve src/remote/fe/dist",
|
|
40
40
|
"dev": "tsx ./src/main.tsx",
|
|
41
41
|
"build": "tsup",
|
|
42
42
|
"lint": "eslint ./src ./tests",
|