@imgly/plugin-ai-text-generation-web 1.86.0-nightly.20261102 → 1.87.0-nightly.20261104

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.
Files changed (39) hide show
  1. package/dist/anthropic/index.d.ts +58 -3
  2. package/dist/anthropic/index.mjs +20 -98
  3. package/dist/anthropic/index.mjs.map +1 -7
  4. package/dist/gateway/index.d.ts +55 -5
  5. package/dist/gateway/index.mjs +13 -89
  6. package/dist/gateway/index.mjs.map +1 -7
  7. package/dist/index.d.ts +24 -8
  8. package/dist/index.mjs +100 -107
  9. package/dist/index.mjs.map +1 -7
  10. package/dist/open-ai/index.d.ts +58 -3
  11. package/dist/open-ai/index.mjs +17 -97
  12. package/dist/open-ai/index.mjs.map +1 -7
  13. package/package.json +8 -9
  14. package/dist/.tsbuildinfo +0 -1
  15. package/dist/anthropic/AnthropicProvider.d.ts +0 -21
  16. package/dist/anthropic/sendPrompt.d.ts +0 -20
  17. package/dist/constants.d.ts +0 -6
  18. package/dist/gateway/GatewayProvider.d.ts +0 -17
  19. package/dist/iconSprite.d.ts +0 -3
  20. package/dist/open-ai/OpenAIProvider.d.ts +0 -21
  21. package/dist/open-ai/sendPrompt.d.ts +0 -15
  22. package/dist/plugin.d.ts +0 -6
  23. package/dist/prompts/changeTextTo.d.ts +0 -2
  24. package/dist/prompts/changeTone.d.ts +0 -2
  25. package/dist/prompts/fix.d.ts +0 -2
  26. package/dist/prompts/generateTextForSpeech.d.ts +0 -2
  27. package/dist/prompts/improve.d.ts +0 -2
  28. package/dist/prompts/longer.d.ts +0 -2
  29. package/dist/prompts/shorter.d.ts +0 -2
  30. package/dist/prompts/translate.d.ts +0 -16
  31. package/dist/quickActions/ChangeTextTo.d.ts +0 -30
  32. package/dist/quickActions/ChangeTone.d.ts +0 -30
  33. package/dist/quickActions/Fix.d.ts +0 -29
  34. package/dist/quickActions/Improve.d.ts +0 -29
  35. package/dist/quickActions/Longer.d.ts +0 -29
  36. package/dist/quickActions/Shorter.d.ts +0 -29
  37. package/dist/quickActions/Translate.d.ts +0 -30
  38. package/dist/quickActions/types.d.ts +0 -6
  39. package/dist/types.d.ts +0 -54
@@ -1,5 +1,60 @@
1
- import { AnthropicProvider } from './AnthropicProvider';
1
+ import CreativeEditorSDK from "@cesdk/cesdk-js";
2
+ import { CommonProviderConfiguration, Provider, TextOutput } from "@imgly/plugin-ai-generation-web";
3
+ /**
4
+ * Input types for text-specific quick actions
5
+ * This interface is extended by individual quick action files using module augmentation
6
+ */
7
+ interface TextQuickActionInputs {}
8
+ /**
9
+ * Type-safe support mapping for text quick actions
10
+ * Allows `true` or `{}` when the quick action input type extends the provider input type
11
+ */
12
+ type TextQuickActionSupport<I, K extends keyof TextQuickActionInputs> = TextQuickActionInputs[K] extends I ? true | {
13
+ mapInput: (input: TextQuickActionInputs[K]) => I;
14
+ } | {
15
+ [key: string]: any;
16
+ } : {
17
+ mapInput: (input: TextQuickActionInputs[K]) => I;
18
+ };
19
+ /**
20
+ * Type-safe mapping for text quick action support
21
+ */
22
+ type TextQuickActionSupportMap<I> = { [K in keyof TextQuickActionInputs]?: TextQuickActionSupport<I, K>; } & {
23
+ [key: string]: true | {
24
+ mapInput: (input: any) => I;
25
+ } | {
26
+ [key: string]: any;
27
+ };
28
+ };
29
+ /**
30
+ * Text provider extension with type-safe quick action support
31
+ * Only parameterized by I (the input type), O is fixed to TextOutput
32
+ */
33
+ interface TextProvider<I> extends Provider<'text', I, TextOutput> {
34
+ input: Omit<Provider<'text', I, TextOutput>['input'], 'quickActions'> & {
35
+ quickActions?: {
36
+ supported?: TextQuickActionSupportMap<I>;
37
+ };
38
+ };
39
+ }
40
+ type AnthropicInput = {
41
+ prompt: string;
42
+ temperature?: number;
43
+ maxTokens?: number;
44
+ blockId?: number;
45
+ initialText?: string;
46
+ };
47
+ type AnthropicOutput = {
48
+ kind: 'text';
49
+ text: string;
50
+ };
51
+ interface AnthropicProviderConfig extends CommonProviderConfiguration<AnthropicInput, AnthropicOutput> {
52
+ model?: string;
53
+ }
54
+ declare function AnthropicProvider(config: AnthropicProviderConfig): (context: {
55
+ cesdk: CreativeEditorSDK;
56
+ }) => Promise<TextProvider<AnthropicInput>>;
2
57
  declare const Anthropic: {
3
- AnthropicProvider: typeof AnthropicProvider;
58
+ AnthropicProvider: typeof AnthropicProvider;
4
59
  };
5
- export default Anthropic;
60
+ export { Anthropic as default };
@@ -1,104 +1,26 @@
1
- var Ur=typeof global=="object"&&global&&global.Object===Object&&global,rr=Ur,Br=typeof self=="object"&&self&&self.Object===Object&&self,Fr=rr||Br||Function("return this")(),C=Fr,zr=C.Symbol,Y=zr,ir=Object.prototype,qr=ir.hasOwnProperty,Vr=ir.toString,ce=Y?Y.toStringTag:void 0;function Gr(r){var e=qr.call(r,ce),t=r[ce];try{r[ce]=void 0;var i=!0}catch{}var n=Vr.call(r);return i&&(e?r[ce]=t:delete r[ce]),n}var Hr=Gr,Wr=Object.prototype,Kr=Wr.toString;function Qr(r){return Kr.call(r)}var Yr=Qr,Jr="[object Null]",Xr="[object Undefined]",zt=Y?Y.toStringTag:void 0;function Zr(r){return r==null?r===void 0?Xr:Jr:zt&&zt in Object(r)?Hr(r):Yr(r)}var ge=Zr;function ei(r){return r!=null&&typeof r=="object"}var xt=ei,Ia=Array.isArray;function ti(r){var e=typeof r;return r!=null&&(e=="object"||e=="function")}var nr=ti,ri="[object AsyncFunction]",ii="[object Function]",ni="[object GeneratorFunction]",oi="[object Proxy]";function ai(r){if(!nr(r))return!1;var e=ge(r);return e==ii||e==ni||e==ri||e==oi}var si=ai,li=C["__core-js_shared__"],gt=li,qt=function(){var r=/[^.]+$/.exec(gt&&gt.keys&&gt.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""}();function ui(r){return!!qt&&qt in r}var ci=ui,di=Function.prototype,pi=di.toString;function fi(r){if(r!=null){try{return pi.call(r)}catch{}try{return r+""}catch{}}return""}var U=fi,gi=/[\\^$.*+?()[\]{}|]/g,hi=/^\[object .+?Constructor\]$/,mi=Function.prototype,yi=Object.prototype,bi=mi.toString,wi=yi.hasOwnProperty,vi=RegExp("^"+bi.call(wi).replace(gi,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ki(r){if(!nr(r)||ci(r))return!1;var e=si(r)?vi:hi;return e.test(U(r))}var xi=ki;function _i(r,e){return r?.[e]}var Si=_i;function Ai(r,e){var t=Si(r,e);return xi(t)?t:void 0}var J=Ai,Ii=J(C,"WeakMap"),yt=Ii;function Mi(r,e){return r===e||r!==r&&e!==e}var Ei=Mi,Ci=9007199254740991;function Pi(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=Ci}var Ti=Pi,Ma=Object.prototype,$i="[object Arguments]";function ji(r){return xt(r)&&ge(r)==$i}var Vt=ji,or=Object.prototype,Ri=or.hasOwnProperty,Li=or.propertyIsEnumerable,Ea=Vt(function(){return arguments}())?Vt:function(r){return xt(r)&&Ri.call(r,"callee")&&!Li.call(r,"callee")},ar=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Gt=ar&&typeof module=="object"&&module&&!module.nodeType&&module,Ni=Gt&&Gt.exports===ar,Ht=Ni?C.Buffer:void 0,Ca=Ht?Ht.isBuffer:void 0,Oi="[object Arguments]",Di="[object Array]",Ui="[object Boolean]",Bi="[object Date]",Fi="[object Error]",zi="[object Function]",qi="[object Map]",Vi="[object Number]",Gi="[object Object]",Hi="[object RegExp]",Wi="[object Set]",Ki="[object String]",Qi="[object WeakMap]",Yi="[object ArrayBuffer]",Ji="[object DataView]",Xi="[object Float32Array]",Zi="[object Float64Array]",en="[object Int8Array]",tn="[object Int16Array]",rn="[object Int32Array]",nn="[object Uint8Array]",on="[object Uint8ClampedArray]",an="[object Uint16Array]",sn="[object Uint32Array]",p={};p[Xi]=p[Zi]=p[en]=p[tn]=p[rn]=p[nn]=p[on]=p[an]=p[sn]=!0;p[Oi]=p[Di]=p[Yi]=p[Ui]=p[Ji]=p[Bi]=p[Fi]=p[zi]=p[qi]=p[Vi]=p[Gi]=p[Hi]=p[Wi]=p[Ki]=p[Qi]=!1;function ln(r){return xt(r)&&Ti(r.length)&&!!p[ge(r)]}var un=ln;function cn(r){return function(e){return r(e)}}var dn=cn,sr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,de=sr&&typeof module=="object"&&module&&!module.nodeType&&module,pn=de&&de.exports===sr,ht=pn&&rr.process,fn=function(){try{var r=de&&de.require&&de.require("util").types;return r||ht&&ht.binding&&ht.binding("util")}catch{}}(),Wt=fn,Kt=Wt&&Wt.isTypedArray,Pa=Kt?dn(Kt):un,gn=Object.prototype,Ta=gn.hasOwnProperty;function hn(r,e){return function(t){return r(e(t))}}var mn=hn,$a=mn(Object.keys,Object),yn=Object.prototype,ja=yn.hasOwnProperty,bn=J(Object,"create"),pe=bn;function wn(){this.__data__=pe?pe(null):{},this.size=0}var vn=wn;function kn(r){var e=this.has(r)&&delete this.__data__[r];return this.size-=e?1:0,e}var xn=kn,_n="__lodash_hash_undefined__",Sn=Object.prototype,An=Sn.hasOwnProperty;function In(r){var e=this.__data__;if(pe){var t=e[r];return t===_n?void 0:t}return An.call(e,r)?e[r]:void 0}var Mn=In,En=Object.prototype,Cn=En.hasOwnProperty;function Pn(r){var e=this.__data__;return pe?e[r]!==void 0:Cn.call(e,r)}var Tn=Pn,$n="__lodash_hash_undefined__";function jn(r,e){var t=this.__data__;return this.size+=this.has(r)?0:1,t[r]=pe&&e===void 0?$n:e,this}var Rn=jn;function X(r){var e=-1,t=r==null?0:r.length;for(this.clear();++e<t;){var i=r[e];this.set(i[0],i[1])}}X.prototype.clear=vn;X.prototype.delete=xn;X.prototype.get=Mn;X.prototype.has=Tn;X.prototype.set=Rn;var Qt=X;function Ln(){this.__data__=[],this.size=0}var Nn=Ln;function On(r,e){for(var t=r.length;t--;)if(Ei(r[t][0],e))return t;return-1}var Oe=On,Dn=Array.prototype,Un=Dn.splice;function Bn(r){var e=this.__data__,t=Oe(e,r);if(t<0)return!1;var i=e.length-1;return t==i?e.pop():Un.call(e,t,1),--this.size,!0}var Fn=Bn;function zn(r){var e=this.__data__,t=Oe(e,r);return t<0?void 0:e[t][1]}var qn=zn;function Vn(r){return Oe(this.__data__,r)>-1}var Gn=Vn;function Hn(r,e){var t=this.__data__,i=Oe(t,r);return i<0?(++this.size,t.push([r,e])):t[i][1]=e,this}var Wn=Hn;function Z(r){var e=-1,t=r==null?0:r.length;for(this.clear();++e<t;){var i=r[e];this.set(i[0],i[1])}}Z.prototype.clear=Nn;Z.prototype.delete=Fn;Z.prototype.get=qn;Z.prototype.has=Gn;Z.prototype.set=Wn;var De=Z,Kn=J(C,"Map"),fe=Kn;function Qn(){this.size=0,this.__data__={hash:new Qt,map:new(fe||De),string:new Qt}}var Yn=Qn;function Jn(r){var e=typeof r;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?r!=="__proto__":r===null}var Xn=Jn;function Zn(r,e){var t=r.__data__;return Xn(e)?t[typeof e=="string"?"string":"hash"]:t.map}var Ue=Zn;function eo(r){var e=Ue(this,r).delete(r);return this.size-=e?1:0,e}var to=eo;function ro(r){return Ue(this,r).get(r)}var io=ro;function no(r){return Ue(this,r).has(r)}var oo=no;function ao(r,e){var t=Ue(this,r),i=t.size;return t.set(r,e),this.size+=t.size==i?0:1,this}var so=ao;function ee(r){var e=-1,t=r==null?0:r.length;for(this.clear();++e<t;){var i=r[e];this.set(i[0],i[1])}}ee.prototype.clear=Yn;ee.prototype.delete=to;ee.prototype.get=io;ee.prototype.has=oo;ee.prototype.set=so;var lr=ee;function lo(){this.__data__=new De,this.size=0}var uo=lo;function co(r){var e=this.__data__,t=e.delete(r);return this.size=e.size,t}var po=co;function fo(r){return this.__data__.get(r)}var go=fo;function ho(r){return this.__data__.has(r)}var mo=ho,yo=200;function bo(r,e){var t=this.__data__;if(t instanceof De){var i=t.__data__;if(!fe||i.length<yo-1)return i.push([r,e]),this.size=++t.size,this;t=this.__data__=new lr(i)}return t.set(r,e),this.size=t.size,this}var wo=bo;function he(r){var e=this.__data__=new De(r);this.size=e.size}he.prototype.clear=uo;he.prototype.delete=po;he.prototype.get=go;he.prototype.has=mo;he.prototype.set=wo;var vo=Object.prototype,Ra=vo.propertyIsEnumerable,ko=J(C,"DataView"),bt=ko,xo=J(C,"Promise"),wt=xo,_o=J(C,"Set"),vt=_o,Yt="[object Map]",So="[object Object]",Jt="[object Promise]",Xt="[object Set]",Zt="[object WeakMap]",er="[object DataView]",Ao=U(bt),Io=U(fe),Mo=U(wt),Eo=U(vt),Co=U(yt),Q=ge;(bt&&Q(new bt(new ArrayBuffer(1)))!=er||fe&&Q(new fe)!=Yt||wt&&Q(wt.resolve())!=Jt||vt&&Q(new vt)!=Xt||yt&&Q(new yt)!=Zt)&&(Q=function(r){var e=ge(r),t=e==So?r.constructor:void 0,i=t?U(t):"";if(i)switch(i){case Ao:return er;case Io:return Yt;case Mo:return Jt;case Eo:return Xt;case Co:return Zt}return e});var La=C.Uint8Array,Po="__lodash_hash_undefined__";function To(r){return this.__data__.set(r,Po),this}var $o=To;function jo(r){return this.__data__.has(r)}var Ro=jo;function kt(r){var e=-1,t=r==null?0:r.length;for(this.__data__=new lr;++e<t;)this.add(r[e])}kt.prototype.add=kt.prototype.push=$o;kt.prototype.has=Ro;var tr=Y?Y.prototype:void 0,Na=tr?tr.valueOf:void 0,Lo=Object.prototype,Oa=Lo.hasOwnProperty,No=Object.prototype,Da=No.hasOwnProperty,Ua=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Ba=new RegExp(/[A-Fa-f0-9]{1}/,"g"),Fa=new RegExp(/[A-Fa-f0-9]{2}/,"g");function ur(r,e){let t={...r};if(!e)return t;for(let[i,n]of Object.entries(e))n===!1||n===null||n===void 0?delete t[i]:n===!0?i in r||(t[i]=!0):t[i]=n;return t}var mt="@imgly/plugin-ai-generation",za=`
2
- <svg>
3
- <symbol
4
- fill="none"
5
- xmlns="http://www.w3.org/2000/svg"
6
- viewBox="0 0 24 24"
7
- id="@imgly/Sparkle"
8
- >
9
- <path d="M5.35545 2.06745C5.24149 1.72556 4.7579 1.72556 4.64394 2.06745L4.05898 3.82232C4.02166 3.93429 3.9338 4.02215 3.82184 4.05948L2.06694 4.64459C1.72506 4.75858 1.72509 5.24217 2.06699 5.3561L3.82179 5.9409C3.93378 5.97822 4.02166 6.06609 4.05899 6.17808L4.64394 7.93291C4.7579 8.2748 5.24149 8.2748 5.35545 7.93291L5.9404 6.17806C5.97773 6.06608 6.06559 5.97821 6.17757 5.94089L7.93242 5.35594C8.27431 5.24198 8.27431 4.75839 7.93242 4.64442L6.17757 4.05947C6.06559 4.02215 5.97773 3.93428 5.9404 3.8223L5.35545 2.06745Z" fill="currentColor"/>
10
- <path d="M17.9632 3.23614C17.8026 2.80788 17.1968 2.80788 17.0362 3.23614L16.0787 5.78951C16.0285 5.92337 15.9229 6.02899 15.789 6.07918L13.2356 7.0367C12.8074 7.19729 12.8074 7.80307 13.2356 7.96366L15.789 8.92118C15.9229 8.97138 16.0285 9.077 16.0787 9.21085L17.0362 11.7642C17.1968 12.1925 17.8026 12.1925 17.9632 11.7642L18.9207 9.21086C18.9709 9.077 19.0765 8.97138 19.2104 8.92118L21.7637 7.96366C22.192 7.80307 22.192 7.1973 21.7637 7.0367L19.2104 6.07918C19.0765 6.02899 18.9709 5.92337 18.9207 5.78951L17.9632 3.23614Z" fill="currentColor"/>
11
- <path d="M9.30058 7.82012C9.54712 7.1791 10.454 7.1791 10.7006 7.82012L12.3809 12.189C12.4571 12.3871 12.6136 12.5436 12.8117 12.6198L17.1806 14.3001C17.8216 14.5466 17.8216 15.4536 17.1806 15.7001L12.8117 17.3804C12.6136 17.4566 12.4571 17.6131 12.3809 17.8112L10.7006 22.1801C10.454 22.8211 9.54712 22.8211 9.30058 22.1801L7.62024 17.8112C7.54406 17.6131 7.38754 17.4566 7.18947 17.3804L2.82061 15.7001C2.17959 15.4536 2.17959 14.5466 2.82061 14.3001L7.18947 12.6198C7.38754 12.5436 7.54406 12.3871 7.62024 12.189L9.30058 7.82012Z" fill="currentColor"/>
12
-
13
- </symbol>
14
-
15
- <symbol
16
- fill="none"
17
- xmlns="http://www.w3.org/2000/svg"
18
- viewBox="0 0 24 24"
19
- id="${mt}/image"
20
- >
21
- <path d="M3 16.5V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V6C21 4.34315 19.6569 3 18 3L17.999 5C18.5513 5 19 5.44772 19 6V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V16.5H3Z" fill="currentColor"/>
22
- <path d="M13.0982 0.884877C12.9734 0.568323 12.5254 0.568322 12.4005 0.884876L11.7485 2.53819C11.7104 2.63483 11.6339 2.71134 11.5372 2.74945L9.8839 3.40151C9.56735 3.52636 9.56734 3.97436 9.8839 4.09921L11.5372 4.75126C11.6339 4.78938 11.7104 4.86588 11.7485 4.96253L12.4005 6.61584C12.5254 6.93239 12.9734 6.9324 13.0982 6.61584L13.7503 4.96253C13.7884 4.86588 13.8649 4.78938 13.9616 4.75126L15.6149 4.09921C15.9314 3.97436 15.9314 3.52636 15.6149 3.40151L13.9616 2.74945C13.8649 2.71134 13.7884 2.63483 13.7503 2.53819L13.0982 0.884877Z" fill="currentColor"/>
23
- <path d="M6.40053 5.38488C6.52538 5.06832 6.97338 5.06832 7.09823 5.38488L8.17455 8.11392C8.21267 8.21057 8.28917 8.28707 8.38582 8.32519L11.1149 9.40151C11.4314 9.52636 11.4314 9.97436 11.1149 10.0992L8.38582 11.1755C8.28917 11.2136 8.21267 11.2901 8.17455 11.3868L7.09823 14.1158C6.97338 14.4324 6.52538 14.4324 6.40053 14.1158L5.32421 11.3868C5.2861 11.2901 5.20959 11.2136 5.11295 11.1755L2.3839 10.0992C2.06735 9.97436 2.06735 9.52636 2.3839 9.40151L5.11295 8.32519C5.20959 8.28707 5.2861 8.21057 5.32421 8.11392L6.40053 5.38488Z" fill="currentColor"/>
24
- <path d="M18.9994 16.5008V18.0004C18.9994 18.5526 18.5517 19.0004 17.9994 19.0004H9.33302L14.3753 11.4369C14.6722 10.9916 15.3266 10.9916 15.6234 11.4369L18.9994 16.5008Z" fill="currentColor"/>
25
-
26
- </symbol>
27
- <symbol
28
- fill="none"
29
- xmlns="http://www.w3.org/2000/svg"
30
- viewBox="0 0 24 24"
31
- id="${mt}/video"
32
- >
33
- <path d="M6 3C4.34315 3 3 4.34315 3 6V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V16.5H19V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V6C5 5.44772 5.44772 5 6 5V3Z" fill="currentColor"/>
34
- <path d="M10.9025 0.8839C11.0273 0.567345 11.4753 0.567346 11.6002 0.883901L12.2522 2.53721C12.2904 2.63386 12.3669 2.71036 12.4635 2.74848L14.1168 3.40053C14.4334 3.52538 14.4334 3.97338 14.1168 4.09823L12.4635 4.75029C12.3669 4.7884 12.2904 4.86491 12.2522 4.96155L11.6002 6.61486C11.4753 6.93142 11.0273 6.93142 10.9025 6.61486L10.2504 4.96155C10.2123 4.86491 10.1358 4.7884 10.0392 4.75029L8.38585 4.09823C8.0693 3.97338 8.0693 3.52538 8.38585 3.40053L10.0392 2.74848C10.1358 2.71036 10.2123 2.63386 10.2504 2.53721L10.9025 0.8839Z" fill="currentColor"/>
35
- <path d="M18.9019 3.3845C19.0267 3.06795 19.4747 3.06795 19.5996 3.3845L20.6759 6.11355C20.714 6.2102 20.7905 6.2867 20.8872 6.32482L23.6162 7.40114C23.9328 7.52598 23.9328 7.97399 23.6162 8.09883L20.8872 9.17515C20.7905 9.21327 20.714 9.28977 20.6759 9.38642L19.5996 12.1155C19.4747 12.432 19.0267 12.432 18.9019 12.1155L17.8255 9.38642C17.7874 9.28977 17.7109 9.21327 17.6143 9.17515L14.8852 8.09883C14.5687 7.97399 14.5687 7.52598 14.8852 7.40114L17.6143 6.32482C17.7109 6.2867 17.7874 6.2102 17.8255 6.11355L18.9019 3.3845Z" fill="currentColor"/>
36
- <path d="M14.9994 13.2862C15.5089 12.8859 15.5089 12.1141 14.9995 11.7137L10.618 8.27047C9.96188 7.75485 9.00011 8.22225 9.00011 9.05673L9.00011 15.9429C9.00011 16.7773 9.96185 17.2448 10.618 16.7292L14.9994 13.2862Z" fill="currentColor"/>
37
- </symbol>
38
- <symbol
39
- fill="none"
40
- xmlns="http://www.w3.org/2000/svg"
41
- viewBox="0 0 24 24"
42
- id="${mt}/audio"
43
- >
44
- <path d="M6 3.80273C4.2066 4.84016 3 6.77919 3 9.00004V12.8153C3 15.931 5.39501 18.4873 8.44444 18.7436V20.9645C8.44444 22.2198 9.89427 22.9198 10.8773 22.1392L15.1265 18.7647H15.5C17.8285 18.7647 19.8472 17.4384 20.8417 15.5H18.4187C17.6889 16.2784 16.6512 16.7647 15.5 16.7647H14.9522C14.6134 16.7647 14.2846 16.8794 14.0193 17.0901L10.4444 19.929V18.2597C10.4444 17.4341 9.77513 16.7647 8.9495 16.7647C7.80494 16.7647 6.77409 16.2779 6.05276 15.5H6V15.4419C5.37798 14.7439 5 13.8237 5 12.8153V9.00004C5 7.98559 5.37764 7.05935 6 6.35422V3.80273Z" fill="currentColor"/>
45
- <path d="M11.6002 1.8839C11.4753 1.56735 11.0273 1.56735 10.9025 1.8839L10.2504 3.53721C10.2123 3.63386 10.1358 3.71036 10.0392 3.74848L8.38585 4.40053C8.0693 4.52538 8.0693 4.97338 8.38585 5.09823L10.0392 5.75029C10.1358 5.7884 10.2123 5.86491 10.2504 5.96155L10.9025 7.61486C11.0273 7.93142 11.4753 7.93142 11.6002 7.61486L12.2522 5.96155C12.2904 5.86491 12.3669 5.7884 12.4635 5.75029L14.1168 5.09823C14.4334 4.97338 14.4334 4.52538 14.1168 4.40053L12.4635 3.74848C12.3669 3.71036 12.2904 3.63386 12.2522 3.53721L11.6002 1.8839Z" fill="currentColor"/>
46
- <path d="M19.5996 4.3845C19.4747 4.06795 19.0267 4.06795 18.9019 4.3845L17.8255 7.11355C17.7874 7.2102 17.7109 7.2867 17.6143 7.32482L14.8852 8.40114C14.5687 8.52598 14.5687 8.97399 14.8852 9.09883L17.6143 10.1752C17.7109 10.2133 17.7874 10.2898 17.8255 10.3864L18.9019 13.1155C19.0267 13.432 19.4747 13.432 19.5996 13.1155L20.6759 10.3864C20.714 10.2898 20.7905 10.2133 20.8872 10.1752L23.6162 9.09883C23.9328 8.97399 23.9328 8.52598 23.6162 8.40114L20.8872 7.32482C20.7905 7.2867 20.714 7.2102 20.6759 7.11355L19.5996 4.3845Z" fill="currentColor"/>
47
- </symbol>
48
- <symbol
49
- fill="none"
50
- xmlns="http://www.w3.org/2000/svg"
51
- viewBox="0 0 24 24"
52
- id="@imgly/ImageAdd"
53
- >
54
- <path d="M18 3C19.6569 3 21 4.34315 21 6V12.291C20.3662 12.1024 19.6951 12 19 12V6C19 5.44772 18.5523 5 18 5H6C5.44772 5 5 5.44772 5 6V18C5 18.5523 5.44772 19 6 19H8.33398L13.1689 11.748C13.5648 11.1544 14.4372 11.1544 14.833 11.748L15.5908 12.8857C13.4487 14.0827 12 16.3719 12 19C12 19.6951 12.1024 20.3662 12.291 21H6C4.34315 21 3 19.6569 3 18V6C3 4.34315 4.34315 3 6 3H18Z" fill="currentColor"/>
55
- <path d="M9.25 7C10.4926 7 11.5 8.00736 11.5 9.25C11.5 10.4926 10.4926 11.5 9.25 11.5C8.00736 11.5 7 10.4926 7 9.25C7 8.00736 8.00736 7 9.25 7Z" fill="currentColor"/>
56
- <path d="M18 18V15H20V18H23V20H20V23H18V20H15V18H18Z" fill="currentColor"/>
57
-
58
- </symbol>
59
- <symbol
60
- fill="none"
61
- xmlns="http://www.w3.org/2000/svg"
62
- viewBox="0 0 24 24"
63
- id="@imgly/MixingPlate"
64
- >
65
- <path d="M9.75 9C10.5784 9 11.25 8.32843 11.25 7.5C11.25 6.67157 10.5784 6 9.75 6C8.92157 6 8.25 6.67157 8.25 7.5C8.25 8.32843 8.92157 9 9.75 9Z" fill="currentColor"/>
66
- <path d="M7 13C7.82843 13 8.5 12.3284 8.5 11.5C8.5 10.6716 7.82843 10 7 10C6.17157 10 5.5 10.6716 5.5 11.5C5.5 12.3284 6.17157 13 7 13Z" fill="currentColor"/>
67
- <path d="M15.75 7.5C15.75 8.32843 15.0784 9 14.25 9C13.4216 9 12.75 8.32843 12.75 7.5C12.75 6.67157 13.4216 6 14.25 6C15.0784 6 15.75 6.67157 15.75 7.5Z" fill="currentColor"/>
68
- <path d="M17 13C17.8284 13 18.5 12.3284 18.5 11.5C18.5 10.6716 17.8284 10 17 10C16.1716 10 15.5 10.6716 15.5 11.5C15.5 12.3284 16.1716 13 17 13Z" fill="currentColor"/>
69
- <path fill-rule="evenodd" clip-rule="evenodd" d="M8.26309 2.77709C10.6681 1.77921 13.4829 1.7322 15.9209 2.64297C18.1572 3.47923 20.0876 5.09285 21.1766 7.28598C22.3395 9.62772 22.4889 13.1077 20.3864 15.2982C19.2693 16.4621 17.7657 16.9982 16.0026 16.9997C15.7897 16.9997 15.5555 16.9864 15.3497 16.9745C15.309 16.9722 15.2694 16.9699 15.2313 16.9679C14.9817 16.9542 14.761 16.9455 14.5569 16.9539C14.124 16.9718 13.9598 17.0612 13.89 17.1324C13.718 17.3081 13.6946 17.6672 13.8854 17.8895C14.2899 18.3608 14.5016 18.9277 14.5016 19.5497C14.5016 20.2206 14.3086 20.9011 13.7542 21.3896C13.2471 21.837 12.6082 21.9997 11.9635 21.9997C10.6049 21.9997 9.31155 21.7367 8.0934 21.2067C6.89058 20.6831 5.84501 19.9687 4.94363 19.0666C4.04281 18.1651 3.31836 17.107 2.79369 15.8978C1.72761 13.4409 1.72662 10.5261 2.81247 8.07034C3.88024 5.65548 5.84206 3.78161 8.26309 2.77709ZM15.2207 4.51639C13.2556 3.78239 10.9651 3.82132 9.02956 4.62439C7.06888 5.43791 5.49559 6.94785 4.64163 8.87914C3.78373 10.8194 3.78253 13.1522 4.62841 15.1017C5.05312 16.0805 5.63511 16.9291 6.35838 17.6529C7.08102 18.3761 7.91671 18.9484 8.89123 19.3728C9.8492 19.7895 10.87 19.9997 11.9635 19.9997C12.2815 19.9997 12.394 19.9225 12.431 19.8899L12.4319 19.8891C12.4367 19.8849 12.4487 19.8743 12.4631 19.8359C12.4799 19.7911 12.5016 19.7024 12.5016 19.5497C12.5016 19.4091 12.4633 19.3034 12.3677 19.192C11.5353 18.222 11.5272 16.6868 12.4611 15.7331C13.0741 15.1071 13.8844 14.98 14.4745 14.9556C14.7819 14.943 15.085 14.9568 15.3409 14.9709C15.3906 14.9736 15.4379 14.9763 15.4832 14.9788C15.6876 14.9904 15.8508 14.9997 16.0009 14.9997C17.3405 14.9986 18.2792 14.6054 18.9435 13.9133C20.2633 12.5382 20.3186 10.055 19.3853 8.1755C18.5436 6.48051 17.0293 5.19281 15.2207 4.51639Z" fill="currentColor"/>
70
-
71
- </symbol>
72
- </svg>
73
- `;var qa=5*60*1e3;var B="0.39.0";var cr=!1,F,_t,Oo,Do,Uo,dr,Bo,Be,St,pr,At,Fe,fr;function gr(r,e={auto:!1}){if(cr)throw new Error(`you must \`import '@anthropic-ai/sdk/shims/${r.kind}'\` before importing anything else from @anthropic-ai/sdk`);if(F)throw new Error(`can't \`import '@anthropic-ai/sdk/shims/${r.kind}'\` after \`import '@anthropic-ai/sdk/shims/${F}'\``);cr=e.auto,F=r.kind,_t=r.fetch,Oo=r.Request,Do=r.Response,Uo=r.Headers,dr=r.FormData,Bo=r.Blob,Be=r.File,St=r.ReadableStream,pr=r.getMultipartRequestOptions,At=r.getDefaultAgent,Fe=r.fileFromPath,fr=r.isFsReadStream}var ze=class{constructor(e){this.body=e}get[Symbol.toStringTag](){return"MultipartBody"}};function hr({manuallyImported:r}={}){let e=r?"You may need to use polyfills":"Add one of these imports before your first `import \u2026 from '@anthropic-ai/sdk'`:\n- `import '@anthropic-ai/sdk/shims/node'` (if you're running on Node)\n- `import '@anthropic-ai/sdk/shims/web'` (otherwise)\n",t,i,n,o;try{t=fetch,i=Request,n=Response,o=Headers}catch(a){throw new Error(`this environment is missing the following Web Fetch API type: ${a.message}. ${e}`)}return{kind:"web",fetch:t,Request:i,Response:n,Headers:o,FormData:typeof FormData<"u"?FormData:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'FormData' is undefined. ${e}`)}},Blob:typeof Blob<"u"?Blob:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'Blob' is undefined. ${e}`)}},File:typeof File<"u"?File:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'File' is undefined. ${e}`)}},ReadableStream:typeof ReadableStream<"u"?ReadableStream:class{constructor(){throw new Error(`streaming isn't supported in this environment yet as 'ReadableStream' is undefined. ${e}`)}},getMultipartRequestOptions:async(a,s)=>({...s,body:new ze(a)}),getDefaultAgent:a=>{},fileFromPath:()=>{throw new Error("The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/anthropics/anthropic-sdk-typescript#file-uploads")},isFsReadStream:a=>!1}}F||gr(hr(),{auto:!0});var l=class extends Error{},h=class r extends l{constructor(e,t,i,n){super(`${r.makeMessage(e,t,i)}`),this.status=e,this.headers=n,this.request_id=n?.["request-id"],this.error=t}static makeMessage(e,t,i){let n=t?.message?typeof t.message=="string"?t.message:JSON.stringify(t.message):t?JSON.stringify(t):i;return e&&n?`${e} ${n}`:e?`${e} status code (no body)`:n||"(no status code or body)"}static generate(e,t,i,n){if(!e||!n)return new R({message:i,cause:qe(t)});let o=t;return e===400?new me(e,o,i,n):e===401?new ye(e,o,i,n):e===403?new be(e,o,i,n):e===404?new we(e,o,i,n):e===409?new ve(e,o,i,n):e===422?new ke(e,o,i,n):e===429?new xe(e,o,i,n):e>=500?new _e(e,o,i,n):new r(e,o,i,n)}},y=class extends h{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}},R=class extends h{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}},te=class extends R{constructor({message:e}={}){super({message:e??"Request timed out."})}},me=class extends h{},ye=class extends h{},be=class extends h{},we=class extends h{},ve=class extends h{},ke=class extends h{},xe=class extends h{},_e=class extends h{};var Ve=function(r,e,t,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(r,t):n?n.value=t:e.set(r,t),t},z=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},k,P=class{constructor(){k.set(this,void 0),this.buffer=new Uint8Array,Ve(this,k,null,"f")}decode(e){if(e==null)return[];let t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?new TextEncoder().encode(e):e,i=new Uint8Array(this.buffer.length+t.length);i.set(this.buffer),i.set(t,this.buffer.length),this.buffer=i;let n=[],o;for(;(o=qo(this.buffer,z(this,k,"f")))!=null;){if(o.carriage&&z(this,k,"f")==null){Ve(this,k,o.index,"f");continue}if(z(this,k,"f")!=null&&(o.index!==z(this,k,"f")+1||o.carriage)){n.push(this.decodeText(this.buffer.slice(0,z(this,k,"f")-1))),this.buffer=this.buffer.slice(z(this,k,"f")),Ve(this,k,null,"f");continue}let a=z(this,k,"f")!==null?o.preceding-1:o.preceding,s=this.decodeText(this.buffer.slice(0,a));n.push(s),this.buffer=this.buffer.slice(o.index),Ve(this,k,null,"f")}return n}decodeText(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof Buffer<"u"){if(e instanceof Buffer)return e.toString();if(e instanceof Uint8Array)return Buffer.from(e).toString();throw new l(`Unexpected: received non-Uint8Array (${e.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`)}if(typeof TextDecoder<"u"){if(e instanceof Uint8Array||e instanceof ArrayBuffer)return this.textDecoder??(this.textDecoder=new TextDecoder("utf8")),this.textDecoder.decode(e);throw new l(`Unexpected: received non-Uint8Array/ArrayBuffer (${e.constructor.name}) in a web platform. Please report this error.`)}throw new l("Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.")}flush(){return this.buffer.length?this.decode(`
74
- `):[]}};k=new WeakMap;P.NEWLINE_CHARS=new Set([`
75
- `,"\r"]);P.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function qo(r,e){for(let n=e??0;n<r.length;n++){if(r[n]===10)return{preceding:n,index:n+1,carriage:!1};if(r[n]===13)return{preceding:n,index:n+1,carriage:!0}}return null}function mr(r){for(let i=0;i<r.length-1;i++){if(r[i]===10&&r[i+1]===10||r[i]===13&&r[i+1]===13)return i+2;if(r[i]===13&&r[i+1]===10&&i+3<r.length&&r[i+2]===13&&r[i+3]===10)return i+4}return-1}function Se(r){if(r[Symbol.asyncIterator])return r;let e=r.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}}}var I=class r{constructor(e,t){this.iterator=e,this.controller=t}static fromSSEResponse(e,t){let i=!1;async function*n(){if(i)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let o=!1;try{for await(let a of Vo(e,t)){if(a.event==="completion")try{yield JSON.parse(a.data)}catch(s){throw console.error("Could not parse message into JSON:",a.data),console.error("From chunk:",a.raw),s}if(a.event==="message_start"||a.event==="message_delta"||a.event==="message_stop"||a.event==="content_block_start"||a.event==="content_block_delta"||a.event==="content_block_stop")try{yield JSON.parse(a.data)}catch(s){throw console.error("Could not parse message into JSON:",a.data),console.error("From chunk:",a.raw),s}if(a.event!=="ping"&&a.event==="error")throw h.generate(void 0,`SSE Error: ${a.data}`,a.data,Mt(e.headers))}o=!0}catch(a){if(a instanceof Error&&a.name==="AbortError")return;throw a}finally{o||t.abort()}}return new r(n,t)}static fromReadableStream(e,t){let i=!1;async function*n(){let a=new P,s=Se(e);for await(let f of s)for(let g of a.decode(f))yield g;for(let f of a.flush())yield f}async function*o(){if(i)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");i=!0;let a=!1;try{for await(let s of n())a||s&&(yield JSON.parse(s));a=!0}catch(s){if(s instanceof Error&&s.name==="AbortError")return;throw s}finally{a||t.abort()}}return new r(o,t)}[Symbol.asyncIterator](){return this.iterator()}tee(){let e=[],t=[],i=this.iterator(),n=o=>({next:()=>{if(o.length===0){let a=i.next();e.push(a),t.push(a)}return o.shift()}});return[new r(()=>n(e),this.controller),new r(()=>n(t),this.controller)]}toReadableStream(){let e=this,t,i=new TextEncoder;return new St({async start(){t=e[Symbol.asyncIterator]()},async pull(n){try{let{value:o,done:a}=await t.next();if(a)return n.close();let s=i.encode(JSON.stringify(o)+`
76
- `);n.enqueue(s)}catch(o){n.error(o)}},async cancel(){await t.return?.()}})}};async function*Vo(r,e){if(!r.body)throw e.abort(),new l("Attempted to iterate over a response with no body");let t=new It,i=new P,n=Se(r.body);for await(let o of Go(n))for(let a of i.decode(o)){let s=t.decode(a);s&&(yield s)}for(let o of i.flush()){let a=t.decode(o);a&&(yield a)}}async function*Go(r){let e=new Uint8Array;for await(let t of r){if(t==null)continue;let i=t instanceof ArrayBuffer?new Uint8Array(t):typeof t=="string"?new TextEncoder().encode(t):t,n=new Uint8Array(e.length+i.length);n.set(e),n.set(i,e.length),e=n;let o;for(;(o=mr(e))!==-1;)yield e.slice(0,o),e=e.slice(o)}e.length>0&&(yield e)}var It=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(`
77
- `),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],o}if(this.chunks.push(e),e.startsWith(":"))return null;let[t,i,n]=Ho(e,":");return n.startsWith(" ")&&(n=n.substring(1)),t==="event"?this.event=n:t==="data"&&this.data.push(n),null}};function Ho(r,e){let t=r.indexOf(e);return t!==-1?[r.substring(0,t),e,r.substring(t+e.length)]:[r,"",""]}var Wo=r=>r!=null&&typeof r=="object"&&typeof r.url=="string"&&typeof r.blob=="function",Ko=r=>r!=null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.lastModified=="number"&&Ae(r),Ae=r=>r!=null&&typeof r=="object"&&typeof r.size=="number"&&typeof r.type=="string"&&typeof r.text=="function"&&typeof r.slice=="function"&&typeof r.arrayBuffer=="function";async function yr(r,e,t){if(r=await r,Ko(r))return r;if(Wo(r)){let n=await r.blob();e||(e=new URL(r.url).pathname.split(/[\\/]/).pop()??"unknown_file");let o=Ae(n)?[await n.arrayBuffer()]:[n];return new Be(o,e,t)}let i=await Qo(r);if(e||(e=Jo(r)??"unknown_file"),!t?.type){let n=i[0]?.type;typeof n=="string"&&(t={...t,type:n})}return new Be(i,e,t)}async function Qo(r){let e=[];if(typeof r=="string"||ArrayBuffer.isView(r)||r instanceof ArrayBuffer)e.push(r);else if(Ae(r))e.push(await r.arrayBuffer());else if(Xo(r))for await(let t of r)e.push(t);else throw new Error(`Unexpected data type: ${typeof r}; constructor: ${r?.constructor?.name}; props: ${Yo(r)}`);return e}function Yo(r){return`[${Object.getOwnPropertyNames(r).map(t=>`"${t}"`).join(", ")}]`}function Jo(r){return Et(r.name)||Et(r.filename)||Et(r.path)?.split(/[\\/]/).pop()}var Et=r=>{if(typeof r=="string")return r;if(typeof Buffer<"u"&&r instanceof Buffer)return String(r)},Xo=r=>r!=null&&typeof r=="object"&&typeof r[Symbol.asyncIterator]=="function",Ct=r=>r&&typeof r=="object"&&r.body&&r[Symbol.toStringTag]==="MultipartBody";var ea=function(r,e,t,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(r,t):n?n.value=t:e.set(r,t),t},ta=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},Ge;async function xr(r){let{response:e}=r;if(r.options.stream)return re("response",e.status,e.url,e.headers,e.body),r.options.__streamClass?r.options.__streamClass.fromSSEResponse(e,r.controller):I.fromSSEResponse(e,r.controller);if(e.status===204)return null;if(r.options.__binaryResponse)return e;let t=e.headers.get("content-type");if(t?.includes("application/json")||t?.includes("application/vnd.api+json")){let o=await e.json();return re("response",e.status,e.url,e.headers,o),_r(o,e)}let n=await e.text();return re("response",e.status,e.url,e.headers,n),n}function _r(r,e){return!r||typeof r!="object"||Array.isArray(r)?r:Object.defineProperty(r,"_request_id",{value:e.headers.get("request-id"),enumerable:!1})}var We=class r extends Promise{constructor(e,t=xr){super(i=>{i(null)}),this.responsePromise=e,this.parseResponse=t}_thenUnwrap(e){return new r(this.responsePromise,async t=>_r(e(await this.parseResponse(t),t),t.response))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){let[e,t]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:t,request_id:t.headers.get("request-id")}}parse(){return this.parsedPromise||(this.parsedPromise=this.responsePromise.then(this.parseResponse)),this.parsedPromise}then(e,t){return this.parse().then(e,t)}catch(e){return this.parse().catch(e)}finally(e){return this.parse().finally(e)}},Ke=class{constructor({baseURL:e,maxRetries:t=2,timeout:i=6e5,httpAgent:n,fetch:o}){this.baseURL=e,this.maxRetries=Pt("maxRetries",t),this.timeout=Pt("timeout",i),this.httpAgent=n,this.fetch=o??_t}authHeaders(e){return{}}defaultHeaders(e){return{Accept:"application/json","Content-Type":"application/json","User-Agent":this.getUserAgent(),...oa(),...this.authHeaders(e)}}validateHeaders(e,t){}defaultIdempotencyKey(){return`stainless-node-retry-${ca()}`}get(e,t){return this.methodRequest("get",e,t)}post(e,t){return this.methodRequest("post",e,t)}patch(e,t){return this.methodRequest("patch",e,t)}put(e,t){return this.methodRequest("put",e,t)}delete(e,t){return this.methodRequest("delete",e,t)}methodRequest(e,t,i){return this.request(Promise.resolve(i).then(async n=>{let o=n&&Ae(n?.body)?new DataView(await n.body.arrayBuffer()):n?.body instanceof DataView?n.body:n?.body instanceof ArrayBuffer?new DataView(n.body):n&&ArrayBuffer.isView(n?.body)?new DataView(n.body.buffer):n?.body;return{method:e,path:t,...n,body:o}}))}getAPIList(e,t,i){return this.requestAPIList(t,{method:"get",path:e,...i})}calculateContentLength(e){if(typeof e=="string"){if(typeof Buffer<"u")return Buffer.byteLength(e,"utf8").toString();if(typeof TextEncoder<"u")return new TextEncoder().encode(e).length.toString()}else if(ArrayBuffer.isView(e))return e.byteLength.toString();return null}buildRequest(e,{retryCount:t=0}={}){e={...e};let{method:i,path:n,query:o,headers:a={}}=e,s=ArrayBuffer.isView(e.body)||e.__binaryRequest&&typeof e.body=="string"?e.body:Ct(e.body)?e.body.body:e.body?JSON.stringify(e.body,null,2):null,f=this.calculateContentLength(s),g=this.buildURL(n,o);"timeout"in e&&Pt("timeout",e.timeout),e.timeout=e.timeout??this.timeout;let v=e.httpAgent??this.httpAgent??At(g),x=e.timeout+1e3;typeof v?.options?.timeout=="number"&&x>(v.options.timeout??0)&&(v.options.timeout=x),this.idempotencyHeader&&i!=="get"&&(e.idempotencyKey||(e.idempotencyKey=this.defaultIdempotencyKey()),a[this.idempotencyHeader]=e.idempotencyKey);let K=this.buildHeaders({options:e,headers:a,contentLength:f,retryCount:t});return{req:{method:i,...s&&{body:s},headers:K,...v&&{agent:v},signal:e.signal??null},url:g,timeout:e.timeout}}buildHeaders({options:e,headers:t,contentLength:i,retryCount:n}){let o={};i&&(o["content-length"]=i);let a=this.defaultHeaders(e);return kr(o,a),kr(o,t),Ct(e.body)&&F!=="node"&&delete o["content-type"],He(a,"x-stainless-retry-count")===void 0&&He(t,"x-stainless-retry-count")===void 0&&(o["x-stainless-retry-count"]=String(n)),He(a,"x-stainless-timeout")===void 0&&He(t,"x-stainless-timeout")===void 0&&e.timeout&&(o["x-stainless-timeout"]=String(e.timeout)),this.validateHeaders(o,t),o}_calculateNonstreamingTimeout(e){if(3600*e/128e3>600)throw new l("Streaming is strongly recommended for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-python#streaming-responses for more details");return 600*1e3}async prepareOptions(e){}async prepareRequest(e,{url:t,options:i}){}parseHeaders(e){return e?Symbol.iterator in e?Object.fromEntries(Array.from(e).map(t=>[...t])):{...e}:{}}makeStatusError(e,t,i,n){return h.generate(e,t,i,n)}request(e,t=null){return new We(this.makeRequest(e,t))}async makeRequest(e,t){let i=await e,n=i.maxRetries??this.maxRetries;t==null&&(t=n),await this.prepareOptions(i);let{req:o,url:a,timeout:s}=this.buildRequest(i,{retryCount:n-t});if(await this.prepareRequest(o,{url:a,options:i}),re("request",a,i,o.headers),i.signal?.aborted)throw new y;let f=new AbortController,g=await this.fetchWithTimeout(a,o,s,f).catch(qe);if(g instanceof Error){if(i.signal?.aborted)throw new y;if(t)return this.retryRequest(i,t);throw g.name==="AbortError"?new te:new R({cause:g})}let v=Mt(g.headers);if(!g.ok){if(t&&this.shouldRetry(g)){let ft=`retrying, ${t} attempts remaining`;return re(`response (error; ${ft})`,g.status,a,v),this.retryRequest(i,t,v)}let x=await g.text().catch(ft=>qe(ft).message),K=aa(x),pt=K?void 0:x;throw re(`response (error; ${t?"(error; no more retries left)":"(error; not retryable)"})`,g.status,a,v,pt),this.makeStatusError(g.status,K,pt,v)}return{response:g,options:i,controller:f}}requestAPIList(e,t){let i=this.makeRequest(t,null);return new Tt(this,i,e)}buildURL(e,t){let i=la(e)?new URL(e):new URL(this.baseURL+(this.baseURL.endsWith("/")&&e.startsWith("/")?e.slice(1):e)),n=this.defaultQuery();return Ie(n)||(t={...n,...t}),typeof t=="object"&&t&&!Array.isArray(t)&&(i.search=this.stringifyQuery(t)),i.toString()}stringifyQuery(e){return Object.entries(e).filter(([t,i])=>typeof i<"u").map(([t,i])=>{if(typeof i=="string"||typeof i=="number"||typeof i=="boolean")return`${encodeURIComponent(t)}=${encodeURIComponent(i)}`;if(i===null)return`${encodeURIComponent(t)}=`;throw new l(`Cannot stringify type ${typeof i}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`)}).join("&")}async fetchWithTimeout(e,t,i,n){let{signal:o,...a}=t||{};o&&o.addEventListener("abort",()=>n.abort());let s=setTimeout(()=>n.abort(),i),f={signal:n.signal,...a};f.method&&(f.method=f.method.toUpperCase());let g=60*1e3,v=setTimeout(()=>{if(f&&f?.agent?.sockets)for(let x of Object.values(f?.agent?.sockets).flat())x?.setKeepAlive&&x.setKeepAlive(!0,g)},g);return this.fetch.call(void 0,e,f).finally(()=>{clearTimeout(s),clearTimeout(v)})}shouldRetry(e){let t=e.headers.get("x-should-retry");return t==="true"?!0:t==="false"?!1:e.status===408||e.status===409||e.status===429||e.status>=500}async retryRequest(e,t,i){let n,o=i?.["retry-after-ms"];if(o){let s=parseFloat(o);Number.isNaN(s)||(n=s)}let a=i?.["retry-after"];if(a&&!n){let s=parseFloat(a);Number.isNaN(s)?n=Date.parse(a)-Date.now():n=s*1e3}if(!(n&&0<=n&&n<60*1e3)){let s=e.maxRetries??this.maxRetries;n=this.calculateDefaultRetryTimeoutMillis(t,s)}return await ua(n),this.makeRequest(e,t-1)}calculateDefaultRetryTimeoutMillis(e,t){let o=t-e,a=Math.min(.5*Math.pow(2,o),8),s=1-Math.random()*.25;return a*s*1e3}getUserAgent(){return`${this.constructor.name}/JS ${B}`}},Qe=class{constructor(e,t,i,n){Ge.set(this,void 0),ea(this,Ge,e,"f"),this.options=n,this.response=t,this.body=i}hasNextPage(){return this.getPaginatedItems().length?this.nextPageInfo()!=null:!1}async getNextPage(){let e=this.nextPageInfo();if(!e)throw new l("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");let t={...this.options};if("params"in e&&typeof t.query=="object")t.query={...t.query,...e.params};else if("url"in e){let i=[...Object.entries(t.query||{}),...e.url.searchParams.entries()];for(let[n,o]of i)e.url.searchParams.set(n,o);t.query=void 0,t.path=e.url.toString()}return await ta(this,Ge,"f").requestAPIList(this.constructor,t)}async*iterPages(){let e=this;for(yield e;e.hasNextPage();)e=await e.getNextPage(),yield e}async*[(Ge=new WeakMap,Symbol.asyncIterator)](){for await(let e of this.iterPages())for(let t of e.getPaginatedItems())yield t}},Tt=class extends We{constructor(e,t,i){super(t,async n=>new i(e,n.response,await xr(n),n.options))}async*[Symbol.asyncIterator](){let e=await this;for await(let t of e)yield t}},Mt=r=>new Proxy(Object.fromEntries(r.entries()),{get(e,t){let i=t.toString();return e[i.toLowerCase()]||e[i]}}),ra={method:!0,path:!0,query:!0,body:!0,headers:!0,maxRetries:!0,stream:!0,timeout:!0,httpAgent:!0,signal:!0,idempotencyKey:!0,__binaryRequest:!0,__binaryResponse:!0,__streamClass:!0},_=r=>typeof r=="object"&&r!==null&&!Ie(r)&&Object.keys(r).every(e=>Sr(ra,e)),ia=()=>{if(typeof Deno<"u"&&Deno.build!=null)return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":B,"X-Stainless-OS":wr(Deno.build.os),"X-Stainless-Arch":br(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":B,"X-Stainless-OS":"Unknown","X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":"edge","X-Stainless-Runtime-Version":process.version};if(Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]")return{"X-Stainless-Lang":"js","X-Stainless-Package-Version":B,"X-Stainless-OS":wr(process.platform),"X-Stainless-Arch":br(process.arch),"X-Stainless-Runtime":"node","X-Stainless-Runtime-Version":process.version};let r=na();return r?{"X-Stainless-Lang":"js","X-Stainless-Package-Version":B,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":`browser:${r.browser}`,"X-Stainless-Runtime-Version":r.version}:{"X-Stainless-Lang":"js","X-Stainless-Package-Version":B,"X-Stainless-OS":"Unknown","X-Stainless-Arch":"unknown","X-Stainless-Runtime":"unknown","X-Stainless-Runtime-Version":"unknown"}};function na(){if(typeof navigator>"u"||!navigator)return null;let r=[{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 r){let i=t.exec(navigator.userAgent);if(i){let n=i[1]||0,o=i[2]||0,a=i[3]||0;return{browser:e,version:`${n}.${o}.${a}`}}}return null}var br=r=>r==="x32"?"x32":r==="x86_64"||r==="x64"?"x64":r==="arm"?"arm":r==="aarch64"||r==="arm64"?"arm64":r?`other:${r}`:"unknown",wr=r=>(r=r.toLowerCase(),r.includes("ios")?"iOS":r==="android"?"Android":r==="darwin"?"MacOS":r==="win32"?"Windows":r==="freebsd"?"FreeBSD":r==="openbsd"?"OpenBSD":r==="linux"?"Linux":r?`Other:${r}`:"Unknown"),vr,oa=()=>vr??(vr=ia()),aa=r=>{try{return JSON.parse(r)}catch{return}},sa=/^[a-z][a-z0-9+.-]*:/i,la=r=>sa.test(r),ua=r=>new Promise(e=>setTimeout(e,r)),Pt=(r,e)=>{if(typeof e!="number"||!Number.isInteger(e))throw new l(`${r} must be an integer`);if(e<0)throw new l(`${r} must be a positive integer`);return e},qe=r=>{if(r instanceof Error)return r;if(typeof r=="object"&&r!==null)try{return new Error(JSON.stringify(r))}catch{}return new Error(String(r))};var Ye=r=>{if(typeof process<"u")return process.env?.[r]?.trim()??void 0;if(typeof Deno<"u")return Deno.env?.get?.(r)?.trim()};function Ie(r){if(!r)return!0;for(let e in r)return!1;return!0}function Sr(r,e){return Object.prototype.hasOwnProperty.call(r,e)}function kr(r,e){for(let t in e){if(!Sr(e,t))continue;let i=t.toLowerCase();if(!i)continue;let n=e[t];n===null?delete r[i]:n!==void 0&&(r[i]=n)}}function re(r,...e){typeof process<"u"&&process?.env?.DEBUG==="true"&&console.log(`Anthropic:DEBUG:${r}`,...e)}var ca=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let e=Math.random()*16|0;return(r==="x"?e:e&3|8).toString(16)}),Ar=()=>typeof window<"u"&&typeof window.document<"u"&&typeof navigator<"u",da=r=>typeof r?.get=="function";var He=(r,e)=>{let t=e.toLowerCase();if(da(r)){let i=e[0]?.toUpperCase()+e.substring(1).replace(/([^\w])(\w)/g,(n,o,a)=>o+a.toUpperCase());for(let n of[e,t,e.toUpperCase(),i]){let o=r.get(n);if(o)return o}}for(let[i,n]of Object.entries(r))if(i.toLowerCase()===t)return Array.isArray(n)?(n.length<=1||console.warn(`Received ${n.length} entries for the ${e} header, using the first entry.`),n[0]):n};var M=class extends Qe{constructor(e,t,i,n){super(e,t,i,n),this.data=i.data||[],this.has_more=i.has_more||!1,this.first_id=i.first_id||null,this.last_id=i.last_id||null}getPaginatedItems(){return this.data??[]}hasNextPage(){return this.has_more===!1?!1:super.hasNextPage()}nextPageParams(){let e=this.nextPageInfo();if(!e)return null;if("params"in e)return e.params;let t=Object.fromEntries(e.url.searchParams);return Object.keys(t).length?t:null}nextPageInfo(){if(this.options.query?.before_id){let t=this.first_id;return t?{params:{before_id:t}}:null}let e=this.last_id;return e?{params:{after_id:e}}:null}};var m=class{constructor(e){this._client=e}};var q=class extends m{retrieve(e,t){return this._client.get(`/v1/models/${e}?beta=true`,t)}list(e={},t){return _(e)?this.list({},e):this._client.getAPIList("/v1/models?beta=true",ie,{query:e,...t})}},ie=class extends M{};q.BetaModelInfosPage=ie;var ne=class r{constructor(e,t){this.iterator=e,this.controller=t}async*decoder(){let e=new P;for await(let t of this.iterator)for(let i of e.decode(t))yield JSON.parse(i);for(let t of e.flush())yield JSON.parse(t)}[Symbol.asyncIterator](){return this.decoder()}static fromResponse(e,t){if(!e.body)throw t.abort(),new l("Attempted to iterate over a response with no body");return new r(Se(e.body),t)}};var V=class extends m{create(e,t){let{betas:i,...n}=e;return this._client.post("/v1/messages/batches?beta=true",{body:n,...t,headers:{"anthropic-beta":[...i??[],"message-batches-2024-09-24"].toString(),...t?.headers}})}retrieve(e,t={},i){if(_(t))return this.retrieve(e,{},t);let{betas:n}=t;return this._client.get(`/v1/messages/batches/${e}?beta=true`,{...i,headers:{"anthropic-beta":[...n??[],"message-batches-2024-09-24"].toString(),...i?.headers}})}list(e={},t){if(_(e))return this.list({},e);let{betas:i,...n}=e;return this._client.getAPIList("/v1/messages/batches?beta=true",oe,{query:n,...t,headers:{"anthropic-beta":[...i??[],"message-batches-2024-09-24"].toString(),...t?.headers}})}delete(e,t={},i){if(_(t))return this.delete(e,{},t);let{betas:n}=t;return this._client.delete(`/v1/messages/batches/${e}?beta=true`,{...i,headers:{"anthropic-beta":[...n??[],"message-batches-2024-09-24"].toString(),...i?.headers}})}cancel(e,t={},i){if(_(t))return this.cancel(e,{},t);let{betas:n}=t;return this._client.post(`/v1/messages/batches/${e}/cancel?beta=true`,{...i,headers:{"anthropic-beta":[...n??[],"message-batches-2024-09-24"].toString(),...i?.headers}})}async results(e,t={},i){if(_(t))return this.results(e,{},t);let n=await this.retrieve(e);if(!n.results_url)throw new l(`No batch \`results_url\`; Has it finished processing? ${n.processing_status} - ${n.id}`);let{betas:o}=t;return this._client.get(n.results_url,{...i,headers:{"anthropic-beta":[...o??[],"message-batches-2024-09-24"].toString(),Accept:"application/binary",...i?.headers},__binaryResponse:!0})._thenUnwrap((a,s)=>ne.fromResponse(s.response,s.controller))}},oe=class extends M{};V.BetaMessageBatchesPage=oe;var ha=r=>{let e=0,t=[];for(;e<r.length;){let i=r[e];if(i==="\\"){e++;continue}if(i==="{"){t.push({type:"brace",value:"{"}),e++;continue}if(i==="}"){t.push({type:"brace",value:"}"}),e++;continue}if(i==="["){t.push({type:"paren",value:"["}),e++;continue}if(i==="]"){t.push({type:"paren",value:"]"}),e++;continue}if(i===":"){t.push({type:"separator",value:":"}),e++;continue}if(i===","){t.push({type:"delimiter",value:","}),e++;continue}if(i==='"'){let s="",f=!1;for(i=r[++e];i!=='"';){if(e===r.length){f=!0;break}if(i==="\\"){if(e++,e===r.length){f=!0;break}s+=i+r[e],i=r[++e]}else s+=i,i=r[++e]}i=r[++e],f||t.push({type:"string",value:s});continue}if(i&&/\s/.test(i)){e++;continue}let o=/[0-9]/;if(i&&o.test(i)||i==="-"||i==="."){let s="";for(i==="-"&&(s+=i,i=r[++e]);i&&o.test(i)||i===".";)s+=i,i=r[++e];t.push({type:"number",value:s});continue}let a=/[a-z]/i;if(i&&a.test(i)){let s="";for(;i&&a.test(i)&&e!==r.length;)s+=i,i=r[++e];if(s=="true"||s=="false"||s==="null")t.push({type:"name",value:s});else{e++;continue}continue}e++}return t},ae=r=>{if(r.length===0)return r;let e=r[r.length-1];switch(e.type){case"separator":return r=r.slice(0,r.length-1),ae(r);break;case"number":let t=e.value[e.value.length-1];if(t==="."||t==="-")return r=r.slice(0,r.length-1),ae(r);case"string":let i=r[r.length-2];if(i?.type==="delimiter")return r=r.slice(0,r.length-1),ae(r);if(i?.type==="brace"&&i.value==="{")return r=r.slice(0,r.length-1),ae(r);break;case"delimiter":return r=r.slice(0,r.length-1),ae(r);break}return r},ma=r=>{let e=[];return r.map(t=>{t.type==="brace"&&(t.value==="{"?e.push("}"):e.splice(e.lastIndexOf("}"),1)),t.type==="paren"&&(t.value==="["?e.push("]"):e.splice(e.lastIndexOf("]"),1))}),e.length>0&&e.reverse().map(t=>{t==="}"?r.push({type:"brace",value:"}"}):t==="]"&&r.push({type:"paren",value:"]"})}),r},ya=r=>{let e="";return r.map(t=>{switch(t.type){case"string":e+='"'+t.value+'"';break;default:e+=t.value;break}}),e},Je=r=>JSON.parse(ya(ma(ae(ha(r)))));var b=function(r,e,t,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(r,t):n?n.value=t:e.set(r,t),t},u=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},S,L,Me,Xe,Ee,Ce,Ze,Pe,T,Te,et,tt,se,rt,it,$t,Ir,jt,Rt,Lt,Nt,Mr,Er="__json_buf",nt=class r{constructor(){S.add(this),this.messages=[],this.receivedMessages=[],L.set(this,void 0),this.controller=new AbortController,Me.set(this,void 0),Xe.set(this,()=>{}),Ee.set(this,()=>{}),Ce.set(this,void 0),Ze.set(this,()=>{}),Pe.set(this,()=>{}),T.set(this,{}),Te.set(this,!1),et.set(this,!1),tt.set(this,!1),se.set(this,!1),rt.set(this,void 0),it.set(this,void 0),jt.set(this,e=>{if(b(this,et,!0,"f"),e instanceof Error&&e.name==="AbortError"&&(e=new y),e instanceof y)return b(this,tt,!0,"f"),this._emit("abort",e);if(e instanceof l)return this._emit("error",e);if(e instanceof Error){let t=new l(e.message);return t.cause=e,this._emit("error",t)}return this._emit("error",new l(String(e)))}),b(this,Me,new Promise((e,t)=>{b(this,Xe,e,"f"),b(this,Ee,t,"f")}),"f"),b(this,Ce,new Promise((e,t)=>{b(this,Ze,e,"f"),b(this,Pe,t,"f")}),"f"),u(this,Me,"f").catch(()=>{}),u(this,Ce,"f").catch(()=>{})}get response(){return u(this,rt,"f")}get request_id(){return u(this,it,"f")}async withResponse(){let e=await u(this,Me,"f");if(!e)throw new Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get("request-id")}}static fromReadableStream(e){let t=new r;return t._run(()=>t._fromReadableStream(e)),t}static createMessage(e,t,i){let n=new r;for(let o of t.messages)n._addMessageParam(o);return n._run(()=>n._createMessage(e,{...t,stream:!0},{...i,headers:{...i?.headers,"X-Stainless-Helper-Method":"stream"}})),n}_run(e){e().then(()=>{this._emitFinal(),this._emit("end")},u(this,jt,"f"))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit("message",e)}async _createMessage(e,t,i){let n=i?.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener("abort",()=>this.controller.abort())),u(this,S,"m",Rt).call(this);let{response:o,data:a}=await e.create({...t,stream:!0},{...i,signal:this.controller.signal}).withResponse();this._connected(o);for await(let s of a)u(this,S,"m",Lt).call(this,s);if(a.controller.signal?.aborted)throw new y;u(this,S,"m",Nt).call(this)}_connected(e){this.ended||(b(this,rt,e,"f"),b(this,it,e?.headers.get("request-id"),"f"),u(this,Xe,"f").call(this,e),this._emit("connect"))}get ended(){return u(this,Te,"f")}get errored(){return u(this,et,"f")}get aborted(){return u(this,tt,"f")}abort(){this.controller.abort()}on(e,t){return(u(this,T,"f")[e]||(u(this,T,"f")[e]=[])).push({listener:t}),this}off(e,t){let i=u(this,T,"f")[e];if(!i)return this;let n=i.findIndex(o=>o.listener===t);return n>=0&&i.splice(n,1),this}once(e,t){return(u(this,T,"f")[e]||(u(this,T,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,i)=>{b(this,se,!0,"f"),e!=="error"&&this.once("error",i),this.once(e,t)})}async done(){b(this,se,!0,"f"),await u(this,Ce,"f")}get currentMessage(){return u(this,L,"f")}async finalMessage(){return await this.done(),u(this,S,"m",$t).call(this)}async finalText(){return await this.done(),u(this,S,"m",Ir).call(this)}_emit(e,...t){if(u(this,Te,"f"))return;e==="end"&&(b(this,Te,!0,"f"),u(this,Ze,"f").call(this));let i=u(this,T,"f")[e];if(i&&(u(this,T,"f")[e]=i.filter(n=>!n.once),i.forEach(({listener:n})=>n(...t))),e==="abort"){let n=t[0];!u(this,se,"f")&&!i?.length&&Promise.reject(n),u(this,Ee,"f").call(this,n),u(this,Pe,"f").call(this,n),this._emit("end");return}if(e==="error"){let n=t[0];!u(this,se,"f")&&!i?.length&&Promise.reject(n),u(this,Ee,"f").call(this,n),u(this,Pe,"f").call(this,n),this._emit("end")}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit("finalMessage",u(this,S,"m",$t).call(this))}async _fromReadableStream(e,t){let i=t?.signal;i&&(i.aborted&&this.controller.abort(),i.addEventListener("abort",()=>this.controller.abort())),u(this,S,"m",Rt).call(this),this._connected(null);let n=I.fromReadableStream(e,this.controller);for await(let o of n)u(this,S,"m",Lt).call(this,o);if(n.controller.signal?.aborted)throw new y;u(this,S,"m",Nt).call(this)}[(L=new WeakMap,Me=new WeakMap,Xe=new WeakMap,Ee=new WeakMap,Ce=new WeakMap,Ze=new WeakMap,Pe=new WeakMap,T=new WeakMap,Te=new WeakMap,et=new WeakMap,tt=new WeakMap,se=new WeakMap,rt=new WeakMap,it=new WeakMap,jt=new WeakMap,S=new WeakSet,$t=function(){if(this.receivedMessages.length===0)throw new l("stream ended without producing a Message with role=assistant");return this.receivedMessages.at(-1)},Ir=function(){if(this.receivedMessages.length===0)throw new l("stream ended without producing a Message with role=assistant");let t=this.receivedMessages.at(-1).content.filter(i=>i.type==="text").map(i=>i.text);if(t.length===0)throw new l("stream ended without producing a content block with type=text");return t.join(" ")},Rt=function(){this.ended||b(this,L,void 0,"f")},Lt=function(t){if(this.ended)return;let i=u(this,S,"m",Mr).call(this,t);switch(this._emit("streamEvent",t,i),t.type){case"content_block_delta":{let n=i.content.at(-1);switch(t.delta.type){case"text_delta":{n.type==="text"&&this._emit("text",t.delta.text,n.text||"");break}case"citations_delta":{n.type==="text"&&this._emit("citation",t.delta.citation,n.citations??[]);break}case"input_json_delta":{n.type==="tool_use"&&n.input&&this._emit("inputJson",t.delta.partial_json,n.input);break}case"thinking_delta":{n.type==="thinking"&&this._emit("thinking",t.delta.thinking,n.thinking);break}case"signature_delta":{n.type==="thinking"&&this._emit("signature",n.signature);break}default:t.delta}break}case"message_stop":{this._addMessageParam(i),this._addMessage(i,!0);break}case"content_block_stop":{this._emit("contentBlock",i.content.at(-1));break}case"message_start":{b(this,L,i,"f");break}case"content_block_start":case"message_delta":break}},Nt=function(){if(this.ended)throw new l("stream has ended, this shouldn't happen");let t=u(this,L,"f");if(!t)throw new l("request ended without sending any chunks");return b(this,L,void 0,"f"),t},Mr=function(t){let i=u(this,L,"f");if(t.type==="message_start"){if(i)throw new l(`Unexpected event order, got ${t.type} before receiving "message_stop"`);return t.message}if(!i)throw new l(`Unexpected event order, got ${t.type} before "message_start"`);switch(t.type){case"message_stop":return i;case"message_delta":return i.stop_reason=t.delta.stop_reason,i.stop_sequence=t.delta.stop_sequence,i.usage.output_tokens=t.usage.output_tokens,i;case"content_block_start":return i.content.push(t.content_block),i;case"content_block_delta":{let n=i.content.at(t.index);switch(t.delta.type){case"text_delta":{n?.type==="text"&&(n.text+=t.delta.text);break}case"citations_delta":{n?.type==="text"&&(n.citations??(n.citations=[]),n.citations.push(t.delta.citation));break}case"input_json_delta":{if(n?.type==="tool_use"){let o=n[Er]||"";o+=t.delta.partial_json,Object.defineProperty(n,Er,{value:o,enumerable:!1,writable:!0}),o&&(n.input=Je(o))}break}case"thinking_delta":{n?.type==="thinking"&&(n.thinking+=t.delta.thinking);break}case"signature_delta":{n?.type==="thinking"&&(n.signature=t.delta.signature);break}default:t.delta}return i}case"content_block_stop":return i}},Symbol.asyncIterator)](){let e=[],t=[],i=!1;return this.on("streamEvent",n=>{let o=t.shift();o?o.resolve(n):e.push(n)}),this.on("end",()=>{i=!0;for(let n of t)n.resolve(void 0);t.length=0}),this.on("abort",n=>{i=!0;for(let o of t)o.reject(n);t.length=0}),this.on("error",n=>{i=!0;for(let o of t)o.reject(n);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:i?{value:void 0,done:!0}:new Promise((o,a)=>t.push({resolve:o,reject:a})).then(o=>o?{value:o,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new I(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}};var Cr={"claude-1.3":"November 6th, 2024","claude-1.3-100k":"November 6th, 2024","claude-instant-1.1":"November 6th, 2024","claude-instant-1.1-100k":"November 6th, 2024","claude-instant-1.2":"November 6th, 2024","claude-3-sonnet-20240229":"July 21st, 2025","claude-2.1":"July 21st, 2025","claude-2.0":"July 21st, 2025"},N=class extends m{constructor(){super(...arguments),this.batches=new V(this._client)}create(e,t){let{betas:i,...n}=e;return n.model in Cr&&console.warn(`The model '${n.model}' is deprecated and will reach end-of-life on ${Cr[n.model]}
78
- Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),this._client.post("/v1/messages?beta=true",{body:n,timeout:this._client._options.timeout??(n.stream?6e5:this._client._calculateNonstreamingTimeout(n.max_tokens)),...t,headers:{...i?.toString()!=null?{"anthropic-beta":i?.toString()}:void 0,...t?.headers},stream:e.stream??!1})}stream(e,t){return nt.createMessage(this,e,t)}countTokens(e,t){let{betas:i,...n}=e;return this._client.post("/v1/messages/count_tokens?beta=true",{body:n,...t,headers:{"anthropic-beta":[...i??[],"token-counting-2024-11-01"].toString(),...t?.headers}})}};N.Batches=V;N.BetaMessageBatchesPage=oe;var E=class extends m{constructor(){super(...arguments),this.models=new q(this._client),this.messages=new N(this._client)}};E.Models=q;E.BetaModelInfosPage=ie;E.Messages=N;var G=class extends m{create(e,t){return this._client.post("/v1/complete",{body:e,timeout:this._client._options.timeout??6e5,...t,stream:e.stream??!1})}};var H=class extends m{create(e,t){return this._client.post("/v1/messages/batches",{body:e,...t})}retrieve(e,t){return this._client.get(`/v1/messages/batches/${e}`,t)}list(e={},t){return _(e)?this.list({},e):this._client.getAPIList("/v1/messages/batches",le,{query:e,...t})}delete(e,t){return this._client.delete(`/v1/messages/batches/${e}`,t)}cancel(e,t){return this._client.post(`/v1/messages/batches/${e}/cancel`,t)}async results(e,t){let i=await this.retrieve(e);if(!i.results_url)throw new l(`No batch \`results_url\`; Has it finished processing? ${i.processing_status} - ${i.id}`);return this._client.get(i.results_url,{...t,headers:{Accept:"application/binary",...t?.headers},__binaryResponse:!0})._thenUnwrap((n,o)=>ne.fromResponse(o.response,o.controller))}},le=class extends M{};H.MessageBatchesPage=le;var w=function(r,e,t,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(r,t):n?n.value=t:e.set(r,t),t},c=function(r,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!i:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(r):i?i.value:e.get(r)},A,O,$e,ot,je,Re,at,Le,$,Ne,st,lt,ue,ut,ct,Ot,Pr,Dt,Ut,Bt,Ft,Tr,$r="__json_buf",dt=class r{constructor(){A.add(this),this.messages=[],this.receivedMessages=[],O.set(this,void 0),this.controller=new AbortController,$e.set(this,void 0),ot.set(this,()=>{}),je.set(this,()=>{}),Re.set(this,void 0),at.set(this,()=>{}),Le.set(this,()=>{}),$.set(this,{}),Ne.set(this,!1),st.set(this,!1),lt.set(this,!1),ue.set(this,!1),ut.set(this,void 0),ct.set(this,void 0),Dt.set(this,e=>{if(w(this,st,!0,"f"),e instanceof Error&&e.name==="AbortError"&&(e=new y),e instanceof y)return w(this,lt,!0,"f"),this._emit("abort",e);if(e instanceof l)return this._emit("error",e);if(e instanceof Error){let t=new l(e.message);return t.cause=e,this._emit("error",t)}return this._emit("error",new l(String(e)))}),w(this,$e,new Promise((e,t)=>{w(this,ot,e,"f"),w(this,je,t,"f")}),"f"),w(this,Re,new Promise((e,t)=>{w(this,at,e,"f"),w(this,Le,t,"f")}),"f"),c(this,$e,"f").catch(()=>{}),c(this,Re,"f").catch(()=>{})}get response(){return c(this,ut,"f")}get request_id(){return c(this,ct,"f")}async withResponse(){let e=await c(this,$e,"f");if(!e)throw new Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get("request-id")}}static fromReadableStream(e){let t=new r;return t._run(()=>t._fromReadableStream(e)),t}static createMessage(e,t,i){let n=new r;for(let o of t.messages)n._addMessageParam(o);return n._run(()=>n._createMessage(e,{...t,stream:!0},{...i,headers:{...i?.headers,"X-Stainless-Helper-Method":"stream"}})),n}_run(e){e().then(()=>{this._emitFinal(),this._emit("end")},c(this,Dt,"f"))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit("message",e)}async _createMessage(e,t,i){let n=i?.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener("abort",()=>this.controller.abort())),c(this,A,"m",Ut).call(this);let{response:o,data:a}=await e.create({...t,stream:!0},{...i,signal:this.controller.signal}).withResponse();this._connected(o);for await(let s of a)c(this,A,"m",Bt).call(this,s);if(a.controller.signal?.aborted)throw new y;c(this,A,"m",Ft).call(this)}_connected(e){this.ended||(w(this,ut,e,"f"),w(this,ct,e?.headers.get("request-id"),"f"),c(this,ot,"f").call(this,e),this._emit("connect"))}get ended(){return c(this,Ne,"f")}get errored(){return c(this,st,"f")}get aborted(){return c(this,lt,"f")}abort(){this.controller.abort()}on(e,t){return(c(this,$,"f")[e]||(c(this,$,"f")[e]=[])).push({listener:t}),this}off(e,t){let i=c(this,$,"f")[e];if(!i)return this;let n=i.findIndex(o=>o.listener===t);return n>=0&&i.splice(n,1),this}once(e,t){return(c(this,$,"f")[e]||(c(this,$,"f")[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,i)=>{w(this,ue,!0,"f"),e!=="error"&&this.once("error",i),this.once(e,t)})}async done(){w(this,ue,!0,"f"),await c(this,Re,"f")}get currentMessage(){return c(this,O,"f")}async finalMessage(){return await this.done(),c(this,A,"m",Ot).call(this)}async finalText(){return await this.done(),c(this,A,"m",Pr).call(this)}_emit(e,...t){if(c(this,Ne,"f"))return;e==="end"&&(w(this,Ne,!0,"f"),c(this,at,"f").call(this));let i=c(this,$,"f")[e];if(i&&(c(this,$,"f")[e]=i.filter(n=>!n.once),i.forEach(({listener:n})=>n(...t))),e==="abort"){let n=t[0];!c(this,ue,"f")&&!i?.length&&Promise.reject(n),c(this,je,"f").call(this,n),c(this,Le,"f").call(this,n),this._emit("end");return}if(e==="error"){let n=t[0];!c(this,ue,"f")&&!i?.length&&Promise.reject(n),c(this,je,"f").call(this,n),c(this,Le,"f").call(this,n),this._emit("end")}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit("finalMessage",c(this,A,"m",Ot).call(this))}async _fromReadableStream(e,t){let i=t?.signal;i&&(i.aborted&&this.controller.abort(),i.addEventListener("abort",()=>this.controller.abort())),c(this,A,"m",Ut).call(this),this._connected(null);let n=I.fromReadableStream(e,this.controller);for await(let o of n)c(this,A,"m",Bt).call(this,o);if(n.controller.signal?.aborted)throw new y;c(this,A,"m",Ft).call(this)}[(O=new WeakMap,$e=new WeakMap,ot=new WeakMap,je=new WeakMap,Re=new WeakMap,at=new WeakMap,Le=new WeakMap,$=new WeakMap,Ne=new WeakMap,st=new WeakMap,lt=new WeakMap,ue=new WeakMap,ut=new WeakMap,ct=new WeakMap,Dt=new WeakMap,A=new WeakSet,Ot=function(){if(this.receivedMessages.length===0)throw new l("stream ended without producing a Message with role=assistant");return this.receivedMessages.at(-1)},Pr=function(){if(this.receivedMessages.length===0)throw new l("stream ended without producing a Message with role=assistant");let t=this.receivedMessages.at(-1).content.filter(i=>i.type==="text").map(i=>i.text);if(t.length===0)throw new l("stream ended without producing a content block with type=text");return t.join(" ")},Ut=function(){this.ended||w(this,O,void 0,"f")},Bt=function(t){if(this.ended)return;let i=c(this,A,"m",Tr).call(this,t);switch(this._emit("streamEvent",t,i),t.type){case"content_block_delta":{let n=i.content.at(-1);switch(t.delta.type){case"text_delta":{n.type==="text"&&this._emit("text",t.delta.text,n.text||"");break}case"citations_delta":{n.type==="text"&&this._emit("citation",t.delta.citation,n.citations??[]);break}case"input_json_delta":{n.type==="tool_use"&&n.input&&this._emit("inputJson",t.delta.partial_json,n.input);break}case"thinking_delta":{n.type==="thinking"&&this._emit("thinking",t.delta.thinking,n.thinking);break}case"signature_delta":{n.type==="thinking"&&this._emit("signature",n.signature);break}default:t.delta}break}case"message_stop":{this._addMessageParam(i),this._addMessage(i,!0);break}case"content_block_stop":{this._emit("contentBlock",i.content.at(-1));break}case"message_start":{w(this,O,i,"f");break}case"content_block_start":case"message_delta":break}},Ft=function(){if(this.ended)throw new l("stream has ended, this shouldn't happen");let t=c(this,O,"f");if(!t)throw new l("request ended without sending any chunks");return w(this,O,void 0,"f"),t},Tr=function(t){let i=c(this,O,"f");if(t.type==="message_start"){if(i)throw new l(`Unexpected event order, got ${t.type} before receiving "message_stop"`);return t.message}if(!i)throw new l(`Unexpected event order, got ${t.type} before "message_start"`);switch(t.type){case"message_stop":return i;case"message_delta":return i.stop_reason=t.delta.stop_reason,i.stop_sequence=t.delta.stop_sequence,i.usage.output_tokens=t.usage.output_tokens,i;case"content_block_start":return i.content.push(t.content_block),i;case"content_block_delta":{let n=i.content.at(t.index);switch(t.delta.type){case"text_delta":{n?.type==="text"&&(n.text+=t.delta.text);break}case"citations_delta":{n?.type==="text"&&(n.citations??(n.citations=[]),n.citations.push(t.delta.citation));break}case"input_json_delta":{if(n?.type==="tool_use"){let o=n[$r]||"";o+=t.delta.partial_json,Object.defineProperty(n,$r,{value:o,enumerable:!1,writable:!0}),o&&(n.input=Je(o))}break}case"thinking_delta":{n?.type==="thinking"&&(n.thinking+=t.delta.thinking);break}case"signature_delta":{n?.type==="thinking"&&(n.signature=t.delta.signature);break}default:t.delta}return i}case"content_block_stop":return i}},Symbol.asyncIterator)](){let e=[],t=[],i=!1;return this.on("streamEvent",n=>{let o=t.shift();o?o.resolve(n):e.push(n)}),this.on("end",()=>{i=!0;for(let n of t)n.resolve(void 0);t.length=0}),this.on("abort",n=>{i=!0;for(let o of t)o.reject(n);t.length=0}),this.on("error",n=>{i=!0;for(let o of t)o.reject(n);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:i?{value:void 0,done:!0}:new Promise((o,a)=>t.push({resolve:o,reject:a})).then(o=>o?{value:o,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new I(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}};var j=class extends m{constructor(){super(...arguments),this.batches=new H(this._client)}create(e,t){return e.model in jr&&console.warn(`The model '${e.model}' is deprecated and will reach end-of-life on ${jr[e.model]}
79
- Please migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),this._client.post("/v1/messages",{body:e,timeout:this._client._options.timeout??(e.stream?6e5:this._client._calculateNonstreamingTimeout(e.max_tokens)),...t,stream:e.stream??!1})}stream(e,t){return dt.createMessage(this,e,t)}countTokens(e,t){return this._client.post("/v1/messages/count_tokens",{body:e,...t})}},jr={"claude-1.3":"November 6th, 2024","claude-1.3-100k":"November 6th, 2024","claude-instant-1.1":"November 6th, 2024","claude-instant-1.1-100k":"November 6th, 2024","claude-instant-1.2":"November 6th, 2024","claude-3-sonnet-20240229":"July 21st, 2025","claude-2.1":"July 21st, 2025","claude-2.0":"July 21st, 2025"};j.Batches=H;j.MessageBatchesPage=le;var D=class extends m{retrieve(e,t){return this._client.get(`/v1/models/${e}`,t)}list(e={},t){return _(e)?this.list({},e):this._client.getAPIList("/v1/models",W,{query:e,...t})}},W=class extends M{};D.ModelInfosPage=W;var Rr,d=class extends Ke{constructor({baseURL:e=Ye("ANTHROPIC_BASE_URL"),apiKey:t=Ye("ANTHROPIC_API_KEY")??null,authToken:i=Ye("ANTHROPIC_AUTH_TOKEN")??null,...n}={}){let o={apiKey:t,authToken:i,...n,baseURL:e||"https://api.anthropic.com"};if(!o.dangerouslyAllowBrowser&&Ar())throw new l(`It looks like you're running in a browser-like environment.
1
+ var e=typeof global==`object`&&global&&global.Object===Object&&global,t=typeof self==`object`&&self&&self.Object===Object&&self,n=e||t||Function(`return this`)(),r=n.Symbol,i=Object.prototype,a=i.hasOwnProperty,o=i.toString,s=r?r.toStringTag:void 0;function c(e){var t=a.call(e,s),n=e[s];try{e[s]=void 0;var r=!0}catch{}var i=o.call(e);return r&&(t?e[s]=n:delete e[s]),i}var l=Object.prototype.toString;function ee(e){return l.call(e)}var te=`[object Null]`,ne=`[object Undefined]`,re=r?r.toStringTag:void 0;function ie(e){return e==null?e===void 0?ne:te:re&&re in Object(e)?c(e):ee(e)}function ae(e){return typeof e==`object`&&!!e}Array.isArray;function oe(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var se=`[object AsyncFunction]`,ce=`[object Function]`,le=`[object GeneratorFunction]`,ue=`[object Proxy]`;function de(e){if(!oe(e))return!1;var t=ie(e);return t==ce||t==le||t==se||t==ue}var fe=n[`__core-js_shared__`],pe=function(){var e=/[^.]+$/.exec(fe&&fe.keys&&fe.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function me(e){return!!pe&&pe in e}var he=Function.prototype.toString;function u(e){if(e!=null){try{return he.call(e)}catch{}try{return e+``}catch{}}return``}var ge=/[\\^$.*+?()[\]{}|]/g,_e=/^\[object .+?Constructor\]$/,ve=Function.prototype,ye=Object.prototype,be=ve.toString,xe=ye.hasOwnProperty,Se=RegExp(`^`+be.call(xe).replace(ge,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function Ce(e){return!oe(e)||me(e)?!1:(de(e)?Se:_e).test(u(e))}function we(e,t){return e?.[t]}function d(e,t){var n=we(e,t);return Ce(n)?n:void 0}var Te=d(n,`WeakMap`);function Ee(e,t){return e===t||e!==e&&t!==t}var De=`[object Arguments]`;function Oe(e){return ae(e)&&ie(e)==De}var ke=Object.prototype;ke.hasOwnProperty,ke.propertyIsEnumerable,Oe(function(){return arguments}());var Ae=typeof exports==`object`&&exports&&!exports.nodeType&&exports,je=Ae&&typeof module==`object`&&module&&!module.nodeType&&module,Me=je&&je.exports===Ae?n.Buffer:void 0;Me&&Me.isBuffer;var Ne=`[object Arguments]`,Pe=`[object Array]`,Fe=`[object Boolean]`,Ie=`[object Date]`,Le=`[object Error]`,Re=`[object Function]`,ze=`[object Map]`,Be=`[object Number]`,Ve=`[object Object]`,He=`[object RegExp]`,Ue=`[object Set]`,We=`[object String]`,Ge=`[object WeakMap]`,Ke=`[object ArrayBuffer]`,qe=`[object DataView]`,Je=`[object Float32Array]`,Ye=`[object Float64Array]`,Xe=`[object Int8Array]`,Ze=`[object Int16Array]`,Qe=`[object Int32Array]`,$e=`[object Uint8Array]`,et=`[object Uint8ClampedArray]`,tt=`[object Uint16Array]`,nt=`[object Uint32Array]`,f={};f[Je]=f[Ye]=f[Xe]=f[Ze]=f[Qe]=f[$e]=f[et]=f[tt]=f[nt]=!0,f[Ne]=f[Pe]=f[Ke]=f[Fe]=f[qe]=f[Ie]=f[Le]=f[Re]=f[ze]=f[Be]=f[Ve]=f[He]=f[Ue]=f[We]=f[Ge]=!1;var rt=typeof exports==`object`&&exports&&!exports.nodeType&&exports,p=rt&&typeof module==`object`&&module&&!module.nodeType&&module,it=p&&p.exports===rt&&e.process,at=function(){try{return p&&p.require&&p.require(`util`).types||it&&it.binding&&it.binding(`util`)}catch{}}();at&&at.isTypedArray;var m=d(Object,`create`);function ot(){this.__data__=m?m(null):{},this.size=0}function st(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var ct=`__lodash_hash_undefined__`,lt=Object.prototype.hasOwnProperty;function ut(e){var t=this.__data__;if(m){var n=t[e];return n===ct?void 0:n}return lt.call(t,e)?t[e]:void 0}var dt=Object.prototype.hasOwnProperty;function ft(e){var t=this.__data__;return m?t[e]!==void 0:dt.call(t,e)}var pt=`__lodash_hash_undefined__`;function mt(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=m&&t===void 0?pt:t,this}function h(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}h.prototype.clear=ot,h.prototype.delete=st,h.prototype.get=ut,h.prototype.has=ft,h.prototype.set=mt;function ht(){this.__data__=[],this.size=0}function gt(e,t){for(var n=e.length;n--;)if(Ee(e[n][0],t))return n;return-1}var _t=Array.prototype.splice;function vt(e){var t=this.__data__,n=gt(t,e);return n<0?!1:(n==t.length-1?t.pop():_t.call(t,n,1),--this.size,!0)}function yt(e){var t=this.__data__,n=gt(t,e);return n<0?void 0:t[n][1]}function bt(e){return gt(this.__data__,e)>-1}function xt(e,t){var n=this.__data__,r=gt(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function g(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}g.prototype.clear=ht,g.prototype.delete=vt,g.prototype.get=yt,g.prototype.has=bt,g.prototype.set=xt;var _=d(n,`Map`);function St(){this.size=0,this.__data__={hash:new h,map:new(_||g),string:new h}}function Ct(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function wt(e,t){var n=e.__data__;return Ct(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function Tt(e){var t=wt(this,e).delete(e);return this.size-=+!!t,t}function Et(e){return wt(this,e).get(e)}function Dt(e){return wt(this,e).has(e)}function Ot(e,t){var n=wt(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function v(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}v.prototype.clear=St,v.prototype.delete=Tt,v.prototype.get=Et,v.prototype.has=Dt,v.prototype.set=Ot;function kt(){this.__data__=new g,this.size=0}function At(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function jt(e){return this.__data__.get(e)}function Mt(e){return this.__data__.has(e)}var Nt=200;function Pt(e,t){var n=this.__data__;if(n instanceof g){var r=n.__data__;if(!_||r.length<Nt-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new v(r)}return n.set(e,t),this.size=n.size,this}function y(e){var t=this.__data__=new g(e);this.size=t.size}y.prototype.clear=kt,y.prototype.delete=At,y.prototype.get=jt,y.prototype.has=Mt,y.prototype.set=Pt;var Ft=d(n,`DataView`),It=d(n,`Promise`),Lt=d(n,`Set`),Rt=`[object Map]`,zt=`[object Object]`,Bt=`[object Promise]`,Vt=`[object Set]`,Ht=`[object WeakMap]`,Ut=`[object DataView]`,Wt=u(Ft),Gt=u(_),Kt=u(It),qt=u(Lt),Jt=u(Te),b=ie;(Ft&&b(new Ft(/* @__PURE__ */ new ArrayBuffer(1)))!=Ut||_&&b(new _)!=Rt||It&&b(It.resolve())!=Bt||Lt&&b(new Lt)!=Vt||Te&&b(new Te)!=Ht)&&(b=function(e){var t=ie(e),n=t==zt?e.constructor:void 0,r=n?u(n):``;if(r)switch(r){case Wt:return Ut;case Gt:return Rt;case Kt:return Bt;case qt:return Vt;case Jt:return Ht}return t}),n.Uint8Array;var Yt=`__lodash_hash_undefined__`;function Xt(e){return this.__data__.set(e,Yt),this}function Zt(e){return this.__data__.has(e)}function Qt(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new v;++t<n;)this.add(e[t])}Qt.prototype.add=Qt.prototype.push=Xt,Qt.prototype.has=Zt;var $t=r?r.prototype:void 0;$t&&$t.valueOf;function en(e,t){let n={...e};if(!t)return n;for(let[r,i]of Object.entries(t))i===!1||i==null?delete n[r]:i===!0?r in e||(n[r]=!0):n[r]=i;return n}const x=`0.39.0`;let tn=!1,S,nn,rn,an,on,sn;function cn(e,t={auto:!1}){if(tn)throw Error(`you must \`import '@anthropic-ai/sdk/shims/${e.kind}'\` before importing anything else from @anthropic-ai/sdk`);if(S)throw Error(`can't \`import '@anthropic-ai/sdk/shims/${e.kind}'\` after \`import '@anthropic-ai/sdk/shims/${S}'\``);tn=t.auto,S=e.kind,nn=e.fetch,e.Request,e.Response,e.Headers,e.FormData,e.Blob,rn=e.File,an=e.ReadableStream,e.getMultipartRequestOptions,on=e.getDefaultAgent,sn=e.fileFromPath,e.isFsReadStream}var ln=class{constructor(e){this.body=e}get[Symbol.toStringTag](){return`MultipartBody`}};function un({manuallyImported:e}={}){let t=e?`You may need to use polyfills`:"Add one of these imports before your first `import … from '@anthropic-ai/sdk'`:\n- `import '@anthropic-ai/sdk/shims/node'` (if you're running on Node)\n- `import '@anthropic-ai/sdk/shims/web'` (otherwise)\n",n,r,i,a;try{n=fetch,r=Request,i=Response,a=Headers}catch(e){throw Error(`this environment is missing the following Web Fetch API type: ${e.message}. ${t}`)}return{kind:`web`,fetch:n,Request:r,Response:i,Headers:a,FormData:typeof FormData<`u`?FormData:class{constructor(){throw Error(`file uploads aren't supported in this environment yet as 'FormData' is undefined. ${t}`)}},Blob:typeof Blob<`u`?Blob:class{constructor(){throw Error(`file uploads aren't supported in this environment yet as 'Blob' is undefined. ${t}`)}},File:typeof File<`u`?File:class{constructor(){throw Error(`file uploads aren't supported in this environment yet as 'File' is undefined. ${t}`)}},ReadableStream:typeof ReadableStream<`u`?ReadableStream:class{constructor(){throw Error(`streaming isn't supported in this environment yet as 'ReadableStream' is undefined. ${t}`)}},getMultipartRequestOptions:async(e,t)=>({...t,body:new ln(e)}),getDefaultAgent:e=>void 0,fileFromPath:()=>{throw Error("The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/anthropics/anthropic-sdk-typescript#file-uploads")},isFsReadStream:e=>!1}}S||cn(un(),{auto:!0});var C=class extends Error{},w=class e extends C{constructor(t,n,r,i){super(`${e.makeMessage(t,n,r)}`),this.status=t,this.headers=i,this.request_id=i?.[`request-id`],this.error=n}static makeMessage(e,t,n){let r=t?.message?typeof t.message==`string`?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&r?`${e} ${r}`:e?`${e} status code (no body)`:r||`(no status code or body)`}static generate(t,n,r,i){if(!t||!i)return new dn({message:r,cause:sr(n)});let a=n;return t===400?new pn(t,a,r,i):t===401?new mn(t,a,r,i):t===403?new hn(t,a,r,i):t===404?new gn(t,a,r,i):t===409?new _n(t,a,r,i):t===422?new vn(t,a,r,i):t===429?new yn(t,a,r,i):t>=500?new bn(t,a,r,i):new e(t,a,r,i)}},T=class extends w{constructor({message:e}={}){super(void 0,void 0,e||`Request was aborted.`,void 0)}},dn=class extends w{constructor({message:e,cause:t}){super(void 0,void 0,e||`Connection error.`,void 0),t&&(this.cause=t)}},fn=class extends dn{constructor({message:e}={}){super({message:e??`Request timed out.`})}},pn=class extends w{},mn=class extends w{},hn=class extends w{},gn=class extends w{},_n=class extends w{},vn=class extends w{},yn=class extends w{},bn=class extends w{},xn=function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},E=function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},D,O=class{constructor(){D.set(this,void 0),this.buffer=/* @__PURE__ */ new Uint8Array,xn(this,D,null,`f`)}decode(e){if(e==null)return[];let t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e==`string`?new TextEncoder().encode(e):e,n=new Uint8Array(this.buffer.length+t.length);n.set(this.buffer),n.set(t,this.buffer.length),this.buffer=n;let r=[],i;for(;(i=Sn(this.buffer,E(this,D,`f`)))!=null;){if(i.carriage&&E(this,D,`f`)==null){xn(this,D,i.index,`f`);continue}if(E(this,D,`f`)!=null&&(i.index!==E(this,D,`f`)+1||i.carriage)){r.push(this.decodeText(this.buffer.slice(0,E(this,D,`f`)-1))),this.buffer=this.buffer.slice(E(this,D,`f`)),xn(this,D,null,`f`);continue}let e=E(this,D,`f`)===null?i.preceding:i.preceding-1,t=this.decodeText(this.buffer.slice(0,e));r.push(t),this.buffer=this.buffer.slice(i.index),xn(this,D,null,`f`)}return r}decodeText(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof Buffer<`u`){if(e instanceof Buffer)return e.toString();if(e instanceof Uint8Array)return Buffer.from(e).toString();throw new C(`Unexpected: received non-Uint8Array (${e.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`)}if(typeof TextDecoder<`u`){if(e instanceof Uint8Array||e instanceof ArrayBuffer)return this.textDecoder??=new TextDecoder(`utf8`),this.textDecoder.decode(e);throw new C(`Unexpected: received non-Uint8Array/ArrayBuffer (${e.constructor.name}) in a web platform. Please report this error.`)}throw new C(`Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`)}flush(){return this.buffer.length?this.decode(`
2
+ `):[]}};D=/* @__PURE__ */ new WeakMap,O.NEWLINE_CHARS=/* @__PURE__ */ new Set([`
3
+ `,`\r`]),O.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function Sn(e,t){for(let n=t??0;n<e.length;n++){if(e[n]===10)return{preceding:n,index:n+1,carriage:!1};if(e[n]===13)return{preceding:n,index:n+1,carriage:!0}}return null}function Cn(e){for(let t=0;t<e.length-1;t++){if(e[t]===10&&e[t+1]===10||e[t]===13&&e[t+1]===13)return t+2;if(e[t]===13&&e[t+1]===10&&t+3<e.length&&e[t+2]===13&&e[t+3]===10)return t+4}return-1}function wn(e){if(e[Symbol.asyncIterator])return e;let t=e.getReader();return{async next(){try{let e=await t.read();return e?.done&&t.releaseLock(),e}catch(e){throw t.releaseLock(),e}},async return(){let e=t.cancel();return t.releaseLock(),await e,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}var k=class e{constructor(e,t){this.iterator=e,this.controller=t}static fromSSEResponse(t,n){let r=!1;async function*i(){if(r)throw Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");r=!0;let e=!1;try{for await(let e of Tn(t,n)){if(e.event===`completion`)try{yield JSON.parse(e.data)}catch(t){throw console.error(`Could not parse message into JSON:`,e.data),console.error(`From chunk:`,e.raw),t}if(e.event===`message_start`||e.event===`message_delta`||e.event===`message_stop`||e.event===`content_block_start`||e.event===`content_block_delta`||e.event===`content_block_stop`)try{yield JSON.parse(e.data)}catch(t){throw console.error(`Could not parse message into JSON:`,e.data),console.error(`From chunk:`,e.raw),t}if(e.event!==`ping`&&e.event===`error`)throw w.generate(void 0,`SSE Error: ${e.data}`,e.data,Jn(t.headers))}e=!0}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;throw e}finally{e||n.abort()}}return new e(i,n)}static fromReadableStream(t,n){let r=!1;async function*i(){let e=new O,n=wn(t);for await(let t of n)for(let n of e.decode(t))yield n;for(let t of e.flush())yield t}async function*a(){if(r)throw Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");r=!0;let e=!1;try{for await(let t of i())e||t&&(yield JSON.parse(t));e=!0}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;throw e}finally{e||n.abort()}}return new e(a,n)}[Symbol.asyncIterator](){return this.iterator()}tee(){let t=[],n=[],r=this.iterator(),i=e=>({next:()=>{if(e.length===0){let e=r.next();t.push(e),n.push(e)}return e.shift()}});return[new e(()=>i(t),this.controller),new e(()=>i(n),this.controller)]}toReadableStream(){let e=this,t,n=new TextEncoder;return new an({async start(){t=e[Symbol.asyncIterator]()},async pull(e){try{let{value:r,done:i}=await t.next();if(i)return e.close();let a=n.encode(JSON.stringify(r)+`
4
+ `);e.enqueue(a)}catch(t){e.error(t)}},async cancel(){await t.return?.()}})}};async function*Tn(e,t){if(!e.body)throw t.abort(),new C(`Attempted to iterate over a response with no body`);let n=new Dn,r=new O,i=wn(e.body);for await(let e of En(i))for(let t of r.decode(e)){let e=n.decode(t);e&&(yield e)}for(let e of r.flush()){let t=n.decode(e);t&&(yield t)}}async function*En(e){let t=/* @__PURE__ */ new Uint8Array;for await(let n of e){if(n==null)continue;let e=n instanceof ArrayBuffer?new Uint8Array(n):typeof n==`string`?new TextEncoder().encode(n):n,r=new Uint8Array(t.length+e.length);r.set(t),r.set(e,t.length),t=r;let i;for(;(i=Cn(t))!==-1;)yield t.slice(0,i),t=t.slice(i)}t.length>0&&(yield t)}var Dn=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 e={event:this.event,data:this.data.join(`
5
+ `),raw:this.chunks};return this.event=null,this.data=[],this.chunks=[],e}if(this.chunks.push(e),e.startsWith(`:`))return null;let[t,n,r]=On(e,`:`);return r.startsWith(` `)&&(r=r.substring(1)),t===`event`?this.event=r:t===`data`&&this.data.push(r),null}};function On(e,t){let n=e.indexOf(t);return n===-1?[e,``,``]:[e.substring(0,n),t,e.substring(n+t.length)]}const kn=e=>typeof e==`object`&&!!e&&typeof e.url==`string`&&typeof e.blob==`function`,An=e=>typeof e==`object`&&!!e&&typeof e.name==`string`&&typeof e.lastModified==`number`&&jn(e),jn=e=>typeof e==`object`&&!!e&&typeof e.size==`number`&&typeof e.type==`string`&&typeof e.text==`function`&&typeof e.slice==`function`&&typeof e.arrayBuffer==`function`;async function Mn(e,t,n){if(e=await e,An(e))return e;if(kn(e)){let r=await e.blob();t||=new URL(e.url).pathname.split(/[\\/]/).pop()??`unknown_file`;let i=jn(r)?[await r.arrayBuffer()]:[r];return new rn(i,t,n)}let r=await Nn(e);if(t||=Fn(e)??`unknown_file`,!n?.type){let e=r[0]?.type;typeof e==`string`&&(n={...n,type:e})}return new rn(r,t,n)}async function Nn(e){let t=[];if(typeof e==`string`||ArrayBuffer.isView(e)||e instanceof ArrayBuffer)t.push(e);else if(jn(e))t.push(await e.arrayBuffer());else if(Ln(e))for await(let n of e)t.push(n);else throw Error(`Unexpected data type: ${typeof e}; constructor: ${e?.constructor?.name}; props: ${Pn(e)}`);return t}function Pn(e){return`[${Object.getOwnPropertyNames(e).map(e=>`"${e}"`).join(`, `)}]`}function Fn(e){return In(e.name)||In(e.filename)||In(e.path)?.split(/[\\/]/).pop()}const In=e=>{if(typeof e==`string`)return e;if(typeof Buffer<`u`&&e instanceof Buffer)return String(e)},Ln=e=>typeof e==`object`&&!!e&&typeof e[Symbol.asyncIterator]==`function`,Rn=e=>e&&typeof e==`object`&&e.body&&e[Symbol.toStringTag]===`MultipartBody`;var zn=function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},Bn=function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},Vn;async function Hn(e){let{response:t}=e;if(e.options.stream)return j(`response`,t.status,t.url,t.headers,t.body),e.options.__streamClass?e.options.__streamClass.fromSSEResponse(t,e.controller):k.fromSSEResponse(t,e.controller);if(t.status===204)return null;if(e.options.__binaryResponse)return t;let n=t.headers.get(`content-type`);if(n?.includes(`application/json`)||n?.includes(`application/vnd.api+json`)){let e=await t.json();return j(`response`,t.status,t.url,t.headers,e),Un(e,t)}let r=await t.text();return j(`response`,t.status,t.url,t.headers,r),r}function Un(e,t){return!e||typeof e!=`object`||Array.isArray(e)?e:Object.defineProperty(e,"_request_id",{value:t.headers.get(`request-id`),enumerable:!1})}var Wn=class e extends Promise{constructor(e,t=Hn){super(e=>{e(null)}),this.responsePromise=e,this.parseResponse=t}_thenUnwrap(t){return new e(this.responsePromise,async e=>Un(t(await this.parseResponse(e),e),e.response))}asResponse(){return this.responsePromise.then(e=>e.response)}async withResponse(){let[e,t]=await Promise.all([this.parse(),this.asResponse()]);return{data:e,response:t,request_id:t.headers.get(`request-id`)}}parse(){return this.parsedPromise||=this.responsePromise.then(this.parseResponse),this.parsedPromise}then(e,t){return this.parse().then(e,t)}catch(e){return this.parse().catch(e)}finally(e){return this.parse().finally(e)}},Gn=class{constructor({baseURL:e,maxRetries:t=2,timeout:n=6e5,httpAgent:r,fetch:i}){this.baseURL=e,this.maxRetries=or(`maxRetries`,t),this.timeout=or(`timeout`,n),this.httpAgent=r,this.fetch=i??nn}authHeaders(e){return{}}defaultHeaders(e){return{Accept:`application/json`,"Content-Type":`application/json`,"User-Agent":this.getUserAgent(),...tr(),...this.authHeaders(e)}}validateHeaders(e,t){}defaultIdempotencyKey(){return`stainless-node-retry-${fr()}`}get(e,t){return this.methodRequest(`get`,e,t)}post(e,t){return this.methodRequest(`post`,e,t)}patch(e,t){return this.methodRequest(`patch`,e,t)}put(e,t){return this.methodRequest(`put`,e,t)}delete(e,t){return this.methodRequest(`delete`,e,t)}methodRequest(e,t,n){return this.request(Promise.resolve(n).then(async n=>{let r=n&&jn(n?.body)?new DataView(await n.body.arrayBuffer()):n?.body instanceof DataView?n.body:n?.body instanceof ArrayBuffer?new DataView(n.body):n&&ArrayBuffer.isView(n?.body)?new DataView(n.body.buffer):n?.body;return{method:e,path:t,...n,body:r}}))}getAPIList(e,t,n){return this.requestAPIList(t,{method:`get`,path:e,...n})}calculateContentLength(e){if(typeof e==`string`){if(typeof Buffer<`u`)return Buffer.byteLength(e,`utf8`).toString();if(typeof TextEncoder<`u`)return new TextEncoder().encode(e).length.toString()}else if(ArrayBuffer.isView(e))return e.byteLength.toString();return null}buildRequest(e,{retryCount:t=0}={}){e={...e};let{method:n,path:r,query:i,headers:a={}}=e,o=ArrayBuffer.isView(e.body)||e.__binaryRequest&&typeof e.body==`string`?e.body:Rn(e.body)?e.body.body:e.body?JSON.stringify(e.body,null,2):null,s=this.calculateContentLength(o),c=this.buildURL(r,i);`timeout`in e&&or(`timeout`,e.timeout),e.timeout=e.timeout??this.timeout;let l=e.httpAgent??this.httpAgent??on(c),ee=e.timeout+1e3;typeof l?.options?.timeout==`number`&&ee>(l.options.timeout??0)&&(l.options.timeout=ee),this.idempotencyHeader&&n!==`get`&&(e.idempotencyKey||(e.idempotencyKey=this.defaultIdempotencyKey()),a[this.idempotencyHeader]=e.idempotencyKey);let te=this.buildHeaders({options:e,headers:a,contentLength:s,retryCount:t});return{req:{method:n,...o&&{body:o},headers:te,...l&&{agent:l},signal:e.signal??null},url:c,timeout:e.timeout}}buildHeaders({options:e,headers:t,contentLength:n,retryCount:r}){let i={};n&&(i[`content-length`]=n);let a=this.defaultHeaders(e);return dr(i,a),dr(i,t),Rn(e.body)&&S!==`node`&&delete i[`content-type`],hr(a,`x-stainless-retry-count`)===void 0&&hr(t,`x-stainless-retry-count`)===void 0&&(i[`x-stainless-retry-count`]=String(r)),hr(a,`x-stainless-timeout`)===void 0&&hr(t,`x-stainless-timeout`)===void 0&&e.timeout&&(i[`x-stainless-timeout`]=String(e.timeout)),this.validateHeaders(i,t),i}_calculateNonstreamingTimeout(e){if(3600*e/128e3>600)throw new C(`Streaming is strongly recommended for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-python#streaming-responses for more details`);return 6e5}async prepareOptions(e){}async prepareRequest(e,{url:t,options:n}){}parseHeaders(e){return e?Symbol.iterator in e?Object.fromEntries(Array.from(e).map(e=>[...e])):{...e}:{}}makeStatusError(e,t,n,r){return w.generate(e,t,n,r)}request(e,t=null){return new Wn(this.makeRequest(e,t))}async makeRequest(e,t){let n=await e,r=n.maxRetries??this.maxRetries;t??=r,await this.prepareOptions(n);let{req:i,url:a,timeout:o}=this.buildRequest(n,{retryCount:r-t});if(await this.prepareRequest(i,{url:a,options:n}),j(`request`,a,n,i.headers),n.signal?.aborted)throw new T;let s=new AbortController,c=await this.fetchWithTimeout(a,i,o,s).catch(sr);if(c instanceof Error){if(n.signal?.aborted)throw new T;if(t)return this.retryRequest(n,t);throw c.name===`AbortError`?new fn:new dn({cause:c})}let l=Jn(c.headers);if(!c.ok){if(t&&this.shouldRetry(c))return j(`response (error; ${`retrying, ${t} attempts remaining`})`,c.status,a,l),this.retryRequest(n,t,l);let e=await c.text().catch(e=>sr(e).message),r=nr(e),i=r?void 0:e;throw j(`response (error; ${t?`(error; no more retries left)`:`(error; not retryable)`})`,c.status,a,l,i),this.makeStatusError(c.status,r,i,l)}return{response:c,options:n,controller:s}}requestAPIList(e,t){let n=this.makeRequest(t,null);return new qn(this,n,e)}buildURL(e,t){let n=ir(e)?new URL(e):new URL(this.baseURL+(this.baseURL.endsWith(`/`)&&e.startsWith(`/`)?e.slice(1):e)),r=this.defaultQuery();return lr(r)||(t={...r,...t}),typeof t==`object`&&t&&!Array.isArray(t)&&(n.search=this.stringifyQuery(t)),n.toString()}stringifyQuery(e){return Object.entries(e).filter(([e,t])=>t!==void 0).map(([e,t])=>{if(typeof t==`string`||typeof t==`number`||typeof t==`boolean`)return`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;if(t===null)return`${encodeURIComponent(e)}=`;throw new C(`Cannot stringify type ${typeof t}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`)}).join(`&`)}async fetchWithTimeout(e,t,n,r){let{signal:i,...a}=t||{};i&&i.addEventListener(`abort`,()=>r.abort());let o=setTimeout(()=>r.abort(),n),s={signal:r.signal,...a};s.method&&=s.method.toUpperCase();let c=6e4,l=setTimeout(()=>{if(s&&s?.agent?.sockets)for(let e of Object.values(s?.agent?.sockets).flat())e?.setKeepAlive&&e.setKeepAlive(!0,c)},c);return this.fetch.call(void 0,e,s).finally(()=>{clearTimeout(o),clearTimeout(l)})}shouldRetry(e){let t=e.headers.get(`x-should-retry`);return t===`true`?!0:t===`false`?!1:e.status===408||e.status===409||e.status===429||e.status>=500}async retryRequest(e,t,n){let r,i=n?.[`retry-after-ms`];if(i){let e=parseFloat(i);Number.isNaN(e)||(r=e)}let a=n?.[`retry-after`];if(a&&!r){let e=parseFloat(a);r=Number.isNaN(e)?Date.parse(a)-Date.now():e*1e3}if(!(r&&0<=r&&r<6e4)){let n=e.maxRetries??this.maxRetries;r=this.calculateDefaultRetryTimeoutMillis(t,n)}return await ar(r),this.makeRequest(e,t-1)}calculateDefaultRetryTimeoutMillis(e,t){let n=t-e;return Math.min(.5*2**n,8)*(1-Math.random()*.25)*1e3}getUserAgent(){return`${this.constructor.name}/JS ${x}`}},Kn=class{constructor(e,t,n,r){Vn.set(this,void 0),zn(this,Vn,e,`f`),this.options=r,this.response=t,this.body=n}hasNextPage(){return this.getPaginatedItems().length?this.nextPageInfo()!=null:!1}async getNextPage(){let e=this.nextPageInfo();if(!e)throw new C("No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.");let t={...this.options};if(`params`in e&&typeof t.query==`object`)t.query={...t.query,...e.params};else if(`url`in e){let n=[...Object.entries(t.query||{}),...e.url.searchParams.entries()];for(let[t,r]of n)e.url.searchParams.set(t,r);t.query=void 0,t.path=e.url.toString()}return await Bn(this,Vn,`f`).requestAPIList(this.constructor,t)}async*iterPages(){let e=this;for(yield e;e.hasNextPage();)e=await e.getNextPage(),yield e}async*[(Vn=/* @__PURE__ */ new WeakMap,Symbol.asyncIterator)](){for await(let e of this.iterPages())for(let t of e.getPaginatedItems())yield t}},qn=class extends Wn{constructor(e,t,n){super(t,async t=>new n(e,t.response,await Hn(t),t.options))}async*[Symbol.asyncIterator](){let e=await this;for await(let t of e)yield t}};const Jn=e=>new Proxy(Object.fromEntries(e.entries()),{get(e,t){let n=t.toString();return e[n.toLowerCase()]||e[n]}}),Yn={method:!0,path:!0,query:!0,body:!0,headers:!0,maxRetries:!0,stream:!0,timeout:!0,httpAgent:!0,signal:!0,idempotencyKey:!0,__binaryRequest:!0,__binaryResponse:!0,__streamClass:!0},A=e=>typeof e==`object`&&!!e&&!lr(e)&&Object.keys(e).every(e=>ur(Yn,e)),Xn=()=>{if(typeof Deno<`u`&&Deno.build!=null)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":x,"X-Stainless-OS":$n(Deno.build.os),"X-Stainless-Arch":Qn(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":x,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`other:${EdgeRuntime}`,"X-Stainless-Runtime":`edge`,"X-Stainless-Runtime-Version":process.version};if(Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`)return{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":x,"X-Stainless-OS":$n(process.platform),"X-Stainless-Arch":Qn(process.arch),"X-Stainless-Runtime":`node`,"X-Stainless-Runtime-Version":process.version};let e=Zn();return e?{"X-Stainless-Lang":`js`,"X-Stainless-Package-Version":x,"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":x,"X-Stainless-OS":`Unknown`,"X-Stainless-Arch":`unknown`,"X-Stainless-Runtime":`unknown`,"X-Stainless-Runtime-Version":`unknown`}};function Zn(){if(typeof navigator>`u`||!navigator)return null;for(let{key:e,pattern:t}of[{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/}]){let n=t.exec(navigator.userAgent);if(n)return{browser:e,version:`${n[1]||0}.${n[2]||0}.${n[3]||0}`}}return null}const Qn=e=>e===`x32`?`x32`:e===`x86_64`||e===`x64`?`x64`:e===`arm`?`arm`:e===`aarch64`||e===`arm64`?`arm64`:e?`other:${e}`:`unknown`,$n=e=>(e=e.toLowerCase(),e.includes(`ios`)?`iOS`:e===`android`?`Android`:e===`darwin`?`MacOS`:e===`win32`?`Windows`:e===`freebsd`?`FreeBSD`:e===`openbsd`?`OpenBSD`:e===`linux`?`Linux`:e?`Other:${e}`:`Unknown`);let er;const tr=()=>er??=Xn(),nr=e=>{try{return JSON.parse(e)}catch{return}},rr=/^[a-z][a-z0-9+.-]*:/i,ir=e=>rr.test(e),ar=e=>new Promise(t=>setTimeout(t,e)),or=(e,t)=>{if(typeof t!=`number`||!Number.isInteger(t))throw new C(`${e} must be an integer`);if(t<0)throw new C(`${e} must be a positive integer`);return t},sr=e=>{if(e instanceof Error)return e;if(typeof e==`object`&&e)try{return Error(JSON.stringify(e))}catch{}return Error(String(e))},cr=e=>{if(typeof process<`u`)return process.env?.[e]?.trim()??void 0;if(typeof Deno<`u`)return Deno.env?.get?.(e)?.trim()};function lr(e){if(!e)return!0;for(let t in e)return!1;return!0}function ur(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function dr(e,t){for(let n in t){if(!ur(t,n))continue;let r=n.toLowerCase();if(!r)continue;let i=t[n];i===null?delete e[r]:i!==void 0&&(e[r]=i)}}function j(e,...t){typeof process<`u`&&process?.env?.DEBUG===`true`&&console.log(`Anthropic:DEBUG:${e}`,...t)}const fr=()=>`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)}),pr=()=>typeof window<`u`&&window.document!==void 0&&typeof navigator<`u`,mr=e=>typeof e?.get==`function`,hr=(e,t)=>{let n=t.toLowerCase();if(mr(e)){let r=t[0]?.toUpperCase()+t.substring(1).replace(/([^\w])(\w)/g,(e,t,n)=>t+n.toUpperCase());for(let i of[t,n,t.toUpperCase(),r]){let t=e.get(i);if(t)return t}}for(let[r,i]of Object.entries(e))if(r.toLowerCase()===n)return Array.isArray(i)?(i.length<=1||console.warn(`Received ${i.length} entries for the ${t} header, using the first entry.`),i[0]):i};var gr=class extends Kn{constructor(e,t,n,r){super(e,t,n,r),this.data=n.data||[],this.has_more=n.has_more||!1,this.first_id=n.first_id||null,this.last_id=n.last_id||null}getPaginatedItems(){return this.data??[]}hasNextPage(){return this.has_more!==!1&&super.hasNextPage()}nextPageParams(){let e=this.nextPageInfo();if(!e)return null;if(`params`in e)return e.params;let t=Object.fromEntries(e.url.searchParams);return Object.keys(t).length?t:null}nextPageInfo(){if(this.options.query?.before_id){let e=this.first_id;return e?{params:{before_id:e}}:null}let e=this.last_id;return e?{params:{after_id:e}}:null}},M=class{constructor(e){this._client=e}},_r=class extends M{retrieve(e,t){return this._client.get(`/v1/models/${e}?beta=true`,t)}list(e={},t){return A(e)?this.list({},e):this._client.getAPIList(`/v1/models?beta=true`,vr,{query:e,...t})}},vr=class extends gr{};_r.BetaModelInfosPage=vr;var yr=class e{constructor(e,t){this.iterator=e,this.controller=t}async*decoder(){let e=new O;for await(let t of this.iterator)for(let n of e.decode(t))yield JSON.parse(n);for(let t of e.flush())yield JSON.parse(t)}[Symbol.asyncIterator](){return this.decoder()}static fromResponse(t,n){if(!t.body)throw n.abort(),new C(`Attempted to iterate over a response with no body`);return new e(wn(t.body),n)}},br=class extends M{create(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/messages/batches?beta=true`,{body:r,...t,headers:{"anthropic-beta":[...n??[],`message-batches-2024-09-24`].toString(),...t?.headers}})}retrieve(e,t={},n){if(A(t))return this.retrieve(e,{},t);let{betas:r}=t;return this._client.get(`/v1/messages/batches/${e}?beta=true`,{...n,headers:{"anthropic-beta":[...r??[],`message-batches-2024-09-24`].toString(),...n?.headers}})}list(e={},t){if(A(e))return this.list({},e);let{betas:n,...r}=e;return this._client.getAPIList(`/v1/messages/batches?beta=true`,xr,{query:r,...t,headers:{"anthropic-beta":[...n??[],`message-batches-2024-09-24`].toString(),...t?.headers}})}delete(e,t={},n){if(A(t))return this.delete(e,{},t);let{betas:r}=t;return this._client.delete(`/v1/messages/batches/${e}?beta=true`,{...n,headers:{"anthropic-beta":[...r??[],`message-batches-2024-09-24`].toString(),...n?.headers}})}cancel(e,t={},n){if(A(t))return this.cancel(e,{},t);let{betas:r}=t;return this._client.post(`/v1/messages/batches/${e}/cancel?beta=true`,{...n,headers:{"anthropic-beta":[...r??[],`message-batches-2024-09-24`].toString(),...n?.headers}})}async results(e,t={},n){if(A(t))return this.results(e,{},t);let r=await this.retrieve(e);if(!r.results_url)throw new C(`No batch \`results_url\`; Has it finished processing? ${r.processing_status} - ${r.id}`);let{betas:i}=t;return this._client.get(r.results_url,{...n,headers:{"anthropic-beta":[...i??[],`message-batches-2024-09-24`].toString(),Accept:`application/binary`,...n?.headers},__binaryResponse:!0})._thenUnwrap((e,t)=>yr.fromResponse(t.response,t.controller))}},xr=class extends gr{};br.BetaMessageBatchesPage=xr;const Sr=e=>{let t=0,n=[];for(;t<e.length;){let r=e[t];if(r===`\\`){t++;continue}if(r===`{`){n.push({type:`brace`,value:`{`}),t++;continue}if(r===`}`){n.push({type:`brace`,value:`}`}),t++;continue}if(r===`[`){n.push({type:`paren`,value:`[`}),t++;continue}if(r===`]`){n.push({type:`paren`,value:`]`}),t++;continue}if(r===`:`){n.push({type:`separator`,value:`:`}),t++;continue}if(r===`,`){n.push({type:`delimiter`,value:`,`}),t++;continue}if(r===`"`){let i=``,a=!1;for(r=e[++t];r!==`"`;){if(t===e.length){a=!0;break}if(r===`\\`){if(t++,t===e.length){a=!0;break}i+=r+e[t],r=e[++t]}else i+=r,r=e[++t]}r=e[++t],a||n.push({type:`string`,value:i});continue}if(r&&/\s/.test(r)){t++;continue}let i=/[0-9]/;if(r&&i.test(r)||r===`-`||r===`.`){let a=``;for(r===`-`&&(a+=r,r=e[++t]);r&&i.test(r)||r===`.`;)a+=r,r=e[++t];n.push({type:`number`,value:a});continue}let a=/[a-z]/i;if(r&&a.test(r)){let i=``;for(;r&&a.test(r)&&t!==e.length;)i+=r,r=e[++t];if(i==`true`||i==`false`||i===`null`)n.push({type:`name`,value:i});else{t++;continue}}else t++}return n},N=e=>{if(e.length===0)return e;let t=e[e.length-1];switch(t.type){case`separator`:return e=e.slice(0,e.length-1),N(e);case`number`:let n=t.value[t.value.length-1];if(n===`.`||n===`-`)return e=e.slice(0,e.length-1),N(e);case`string`:let r=e[e.length-2];if(r?.type===`delimiter`||r?.type===`brace`&&r.value===`{`)return e=e.slice(0,e.length-1),N(e);break;case`delimiter`:return e=e.slice(0,e.length-1),N(e)}return e},Cr=e=>{let t=[];return e.map(e=>{e.type===`brace`&&(e.value===`{`?t.push(`}`):t.splice(t.lastIndexOf(`}`),1)),e.type===`paren`&&(e.value===`[`?t.push(`]`):t.splice(t.lastIndexOf(`]`),1))}),t.length>0&&t.reverse().map(t=>{t===`}`?e.push({type:`brace`,value:`}`}):t===`]`&&e.push({type:`paren`,value:`]`})}),e},wr=e=>{let t=``;return e.map(e=>{switch(e.type){case`string`:t+=`"`+e.value+`"`;break;default:t+=e.value}}),t},Tr=e=>JSON.parse(wr(Cr(N(Sr(e)))));var P=function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},F=function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},I,L,R,Er,z,B,Dr,V,H,U,Or,kr,W,Ar,jr,Mr,Nr,Pr,Fr,Ir,Lr,Rr;const zr=`__json_buf`;var Br=class e{constructor(){I.add(this),this.messages=[],this.receivedMessages=[],L.set(this,void 0),this.controller=new AbortController,R.set(this,void 0),Er.set(this,()=>{}),z.set(this,()=>{}),B.set(this,void 0),Dr.set(this,()=>{}),V.set(this,()=>{}),H.set(this,{}),U.set(this,!1),Or.set(this,!1),kr.set(this,!1),W.set(this,!1),Ar.set(this,void 0),jr.set(this,void 0),Pr.set(this,e=>{if(P(this,Or,!0,`f`),e instanceof Error&&e.name===`AbortError`&&(e=new T),e instanceof T)return P(this,kr,!0,`f`),this._emit(`abort`,e);if(e instanceof C)return this._emit(`error`,e);if(e instanceof Error){let t=new C(e.message);return t.cause=e,this._emit(`error`,t)}return this._emit(`error`,new C(String(e)))}),P(this,R,new Promise((e,t)=>{P(this,Er,e,`f`),P(this,z,t,`f`)}),`f`),P(this,B,new Promise((e,t)=>{P(this,Dr,e,`f`),P(this,V,t,`f`)}),`f`),F(this,R,`f`).catch(()=>{}),F(this,B,`f`).catch(()=>{})}get response(){return F(this,Ar,`f`)}get request_id(){return F(this,jr,`f`)}async withResponse(){let e=await F(this,R,`f`);if(!e)throw Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get(`request-id`)}}static fromReadableStream(t){let n=new e;return n._run(()=>n._fromReadableStream(t)),n}static createMessage(t,n,r){let i=new e;for(let e of n.messages)i._addMessageParam(e);return i._run(()=>i._createMessage(t,{...n,stream:!0},{...r,headers:{...r?.headers,"X-Stainless-Helper-Method":`stream`}})),i}_run(e){e().then(()=>{this._emitFinal(),this._emit(`end`)},F(this,Pr,`f`))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit(`message`,e)}async _createMessage(e,t,n){let r=n?.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener(`abort`,()=>this.controller.abort())),F(this,I,`m`,Fr).call(this);let{response:i,data:a}=await e.create({...t,stream:!0},{...n,signal:this.controller.signal}).withResponse();this._connected(i);for await(let e of a)F(this,I,`m`,Ir).call(this,e);if(a.controller.signal?.aborted)throw new T;F(this,I,`m`,Lr).call(this)}_connected(e){this.ended||(P(this,Ar,e,`f`),P(this,jr,e?.headers.get(`request-id`),`f`),F(this,Er,`f`).call(this,e),this._emit(`connect`))}get ended(){return F(this,U,`f`)}get errored(){return F(this,Or,`f`)}get aborted(){return F(this,kr,`f`)}abort(){this.controller.abort()}on(e,t){return(F(this,H,`f`)[e]||(F(this,H,`f`)[e]=[])).push({listener:t}),this}off(e,t){let n=F(this,H,`f`)[e];if(!n)return this;let r=n.findIndex(e=>e.listener===t);return r>=0&&n.splice(r,1),this}once(e,t){return(F(this,H,`f`)[e]||(F(this,H,`f`)[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,n)=>{P(this,W,!0,`f`),e!==`error`&&this.once(`error`,n),this.once(e,t)})}async done(){P(this,W,!0,`f`),await F(this,B,`f`)}get currentMessage(){return F(this,L,`f`)}async finalMessage(){return await this.done(),F(this,I,`m`,Mr).call(this)}async finalText(){return await this.done(),F(this,I,`m`,Nr).call(this)}_emit(e,...t){if(F(this,U,`f`))return;e===`end`&&(P(this,U,!0,`f`),F(this,Dr,`f`).call(this));let n=F(this,H,`f`)[e];if(n&&(F(this,H,`f`)[e]=n.filter(e=>!e.once),n.forEach(({listener:e})=>e(...t))),e===`abort`){let e=t[0];!F(this,W,`f`)&&!n?.length&&Promise.reject(e),F(this,z,`f`).call(this,e),F(this,V,`f`).call(this,e),this._emit(`end`)}else if(e===`error`){let e=t[0];!F(this,W,`f`)&&!n?.length&&Promise.reject(e),F(this,z,`f`).call(this,e),F(this,V,`f`).call(this,e),this._emit(`end`)}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit(`finalMessage`,F(this,I,`m`,Mr).call(this))}async _fromReadableStream(e,t){let n=t?.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener(`abort`,()=>this.controller.abort())),F(this,I,`m`,Fr).call(this),this._connected(null);let r=k.fromReadableStream(e,this.controller);for await(let e of r)F(this,I,`m`,Ir).call(this,e);if(r.controller.signal?.aborted)throw new T;F(this,I,`m`,Lr).call(this)}[(L=/* @__PURE__ */ new WeakMap,R=/* @__PURE__ */ new WeakMap,Er=/* @__PURE__ */ new WeakMap,z=/* @__PURE__ */ new WeakMap,B=/* @__PURE__ */ new WeakMap,Dr=/* @__PURE__ */ new WeakMap,V=/* @__PURE__ */ new WeakMap,H=/* @__PURE__ */ new WeakMap,U=/* @__PURE__ */ new WeakMap,Or=/* @__PURE__ */ new WeakMap,kr=/* @__PURE__ */ new WeakMap,W=/* @__PURE__ */ new WeakMap,Ar=/* @__PURE__ */ new WeakMap,jr=/* @__PURE__ */ new WeakMap,Pr=/* @__PURE__ */ new WeakMap,I=/* @__PURE__ */ new WeakSet,Mr=function(){if(this.receivedMessages.length===0)throw new C(`stream ended without producing a Message with role=assistant`);return this.receivedMessages.at(-1)},Nr=function(){if(this.receivedMessages.length===0)throw new C(`stream ended without producing a Message with role=assistant`);let e=this.receivedMessages.at(-1).content.filter(e=>e.type===`text`).map(e=>e.text);if(e.length===0)throw new C(`stream ended without producing a content block with type=text`);return e.join(` `)},Fr=function(){this.ended||P(this,L,void 0,`f`)},Ir=function(e){if(this.ended)return;let t=F(this,I,`m`,Rr).call(this,e);switch(this._emit(`streamEvent`,e,t),e.type){case`content_block_delta`:{let n=t.content.at(-1);switch(e.delta.type){case`text_delta`:n.type===`text`&&this._emit(`text`,e.delta.text,n.text||``);break;case`citations_delta`:n.type===`text`&&this._emit(`citation`,e.delta.citation,n.citations??[]);break;case`input_json_delta`:n.type===`tool_use`&&n.input&&this._emit(`inputJson`,e.delta.partial_json,n.input);break;case`thinking_delta`:n.type===`thinking`&&this._emit(`thinking`,e.delta.thinking,n.thinking);break;case`signature_delta`:n.type===`thinking`&&this._emit(`signature`,n.signature);break;default:e.delta}break}case`message_stop`:this._addMessageParam(t),this._addMessage(t,!0);break;case`content_block_stop`:this._emit(`contentBlock`,t.content.at(-1));break;case`message_start`:P(this,L,t,`f`)}},Lr=function(){if(this.ended)throw new C(`stream has ended, this shouldn't happen`);let e=F(this,L,`f`);if(!e)throw new C(`request ended without sending any chunks`);return P(this,L,void 0,`f`),e},Rr=function(e){let t=F(this,L,`f`);if(e.type===`message_start`){if(t)throw new C(`Unexpected event order, got ${e.type} before receiving "message_stop"`);return e.message}if(!t)throw new C(`Unexpected event order, got ${e.type} before "message_start"`);switch(e.type){case`message_stop`:return t;case`message_delta`:return t.stop_reason=e.delta.stop_reason,t.stop_sequence=e.delta.stop_sequence,t.usage.output_tokens=e.usage.output_tokens,t;case`content_block_start`:return t.content.push(e.content_block),t;case`content_block_delta`:{let n=t.content.at(e.index);switch(e.delta.type){case`text_delta`:n?.type===`text`&&(n.text+=e.delta.text);break;case`citations_delta`:n?.type===`text`&&(n.citations??=[],n.citations.push(e.delta.citation));break;case`input_json_delta`:if(n?.type===`tool_use`){let t=n[zr]||``;t+=e.delta.partial_json,Object.defineProperty(n,zr,{value:t,enumerable:!1,writable:!0}),t&&(n.input=Tr(t))}break;case`thinking_delta`:n?.type===`thinking`&&(n.thinking+=e.delta.thinking);break;case`signature_delta`:n?.type===`thinking`&&(n.signature=e.delta.signature);break;default:e.delta}return t}case`content_block_stop`:return t}},Symbol.asyncIterator)](){let e=[],t=[],n=!1;return this.on(`streamEvent`,n=>{let r=t.shift();r?r.resolve(n):e.push(n)}),this.on(`end`,()=>{n=!0;for(let e of t)e.resolve(void 0);t.length=0}),this.on(`abort`,e=>{n=!0;for(let n of t)n.reject(e);t.length=0}),this.on(`error`,e=>{n=!0;for(let n of t)n.reject(e);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:n?{value:void 0,done:!0}:new Promise((e,n)=>t.push({resolve:e,reject:n})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new k(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}};const Vr={"claude-1.3":`November 6th, 2024`,"claude-1.3-100k":`November 6th, 2024`,"claude-instant-1.1":`November 6th, 2024`,"claude-instant-1.1-100k":`November 6th, 2024`,"claude-instant-1.2":`November 6th, 2024`,"claude-3-sonnet-20240229":`July 21st, 2025`,"claude-2.1":`July 21st, 2025`,"claude-2.0":`July 21st, 2025`};var Hr=class extends M{constructor(){super(...arguments),this.batches=new br(this._client)}create(e,t){let{betas:n,...r}=e;return r.model in Vr&&console.warn(`The model '${r.model}' is deprecated and will reach end-of-life on ${Vr[r.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),this._client.post(`/v1/messages?beta=true`,{body:r,timeout:this._client._options.timeout??(r.stream?6e5:this._client._calculateNonstreamingTimeout(r.max_tokens)),...t,headers:{...n?.toString()==null?void 0:{"anthropic-beta":n?.toString()},...t?.headers},stream:e.stream??!1})}stream(e,t){return Br.createMessage(this,e,t)}countTokens(e,t){let{betas:n,...r}=e;return this._client.post(`/v1/messages/count_tokens?beta=true`,{body:r,...t,headers:{"anthropic-beta":[...n??[],`token-counting-2024-11-01`].toString(),...t?.headers}})}};Hr.Batches=br,Hr.BetaMessageBatchesPage=xr;var G=class extends M{constructor(){super(...arguments),this.models=new _r(this._client),this.messages=new Hr(this._client)}};G.Models=_r,G.BetaModelInfosPage=vr,G.Messages=Hr;var Ur=class extends M{create(e,t){return this._client.post(`/v1/complete`,{body:e,timeout:this._client._options.timeout??6e5,...t,stream:e.stream??!1})}},Wr=class extends M{create(e,t){return this._client.post(`/v1/messages/batches`,{body:e,...t})}retrieve(e,t){return this._client.get(`/v1/messages/batches/${e}`,t)}list(e={},t){return A(e)?this.list({},e):this._client.getAPIList(`/v1/messages/batches`,Gr,{query:e,...t})}delete(e,t){return this._client.delete(`/v1/messages/batches/${e}`,t)}cancel(e,t){return this._client.post(`/v1/messages/batches/${e}/cancel`,t)}async results(e,t){let n=await this.retrieve(e);if(!n.results_url)throw new C(`No batch \`results_url\`; Has it finished processing? ${n.processing_status} - ${n.id}`);return this._client.get(n.results_url,{...t,headers:{Accept:`application/binary`,...t?.headers},__binaryResponse:!0})._thenUnwrap((e,t)=>yr.fromResponse(t.response,t.controller))}},Gr=class extends gr{};Wr.MessageBatchesPage=Gr;var K=function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},q=function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)},J,Y,Kr,qr,Jr,Yr,Xr,Zr,X,Z,Qr,$r,Q,ei,ti,ni,ri,ii,ai,oi,si,ci;const li=`__json_buf`;var ui=class e{constructor(){J.add(this),this.messages=[],this.receivedMessages=[],Y.set(this,void 0),this.controller=new AbortController,Kr.set(this,void 0),qr.set(this,()=>{}),Jr.set(this,()=>{}),Yr.set(this,void 0),Xr.set(this,()=>{}),Zr.set(this,()=>{}),X.set(this,{}),Z.set(this,!1),Qr.set(this,!1),$r.set(this,!1),Q.set(this,!1),ei.set(this,void 0),ti.set(this,void 0),ii.set(this,e=>{if(K(this,Qr,!0,`f`),e instanceof Error&&e.name===`AbortError`&&(e=new T),e instanceof T)return K(this,$r,!0,`f`),this._emit(`abort`,e);if(e instanceof C)return this._emit(`error`,e);if(e instanceof Error){let t=new C(e.message);return t.cause=e,this._emit(`error`,t)}return this._emit(`error`,new C(String(e)))}),K(this,Kr,new Promise((e,t)=>{K(this,qr,e,`f`),K(this,Jr,t,`f`)}),`f`),K(this,Yr,new Promise((e,t)=>{K(this,Xr,e,`f`),K(this,Zr,t,`f`)}),`f`),q(this,Kr,`f`).catch(()=>{}),q(this,Yr,`f`).catch(()=>{})}get response(){return q(this,ei,`f`)}get request_id(){return q(this,ti,`f`)}async withResponse(){let e=await q(this,Kr,`f`);if(!e)throw Error("Could not resolve a `Response` object");return{data:this,response:e,request_id:e.headers.get(`request-id`)}}static fromReadableStream(t){let n=new e;return n._run(()=>n._fromReadableStream(t)),n}static createMessage(t,n,r){let i=new e;for(let e of n.messages)i._addMessageParam(e);return i._run(()=>i._createMessage(t,{...n,stream:!0},{...r,headers:{...r?.headers,"X-Stainless-Helper-Method":`stream`}})),i}_run(e){e().then(()=>{this._emitFinal(),this._emit(`end`)},q(this,ii,`f`))}_addMessageParam(e){this.messages.push(e)}_addMessage(e,t=!0){this.receivedMessages.push(e),t&&this._emit(`message`,e)}async _createMessage(e,t,n){let r=n?.signal;r&&(r.aborted&&this.controller.abort(),r.addEventListener(`abort`,()=>this.controller.abort())),q(this,J,`m`,ai).call(this);let{response:i,data:a}=await e.create({...t,stream:!0},{...n,signal:this.controller.signal}).withResponse();this._connected(i);for await(let e of a)q(this,J,`m`,oi).call(this,e);if(a.controller.signal?.aborted)throw new T;q(this,J,`m`,si).call(this)}_connected(e){this.ended||(K(this,ei,e,`f`),K(this,ti,e?.headers.get(`request-id`),`f`),q(this,qr,`f`).call(this,e),this._emit(`connect`))}get ended(){return q(this,Z,`f`)}get errored(){return q(this,Qr,`f`)}get aborted(){return q(this,$r,`f`)}abort(){this.controller.abort()}on(e,t){return(q(this,X,`f`)[e]||(q(this,X,`f`)[e]=[])).push({listener:t}),this}off(e,t){let n=q(this,X,`f`)[e];if(!n)return this;let r=n.findIndex(e=>e.listener===t);return r>=0&&n.splice(r,1),this}once(e,t){return(q(this,X,`f`)[e]||(q(this,X,`f`)[e]=[])).push({listener:t,once:!0}),this}emitted(e){return new Promise((t,n)=>{K(this,Q,!0,`f`),e!==`error`&&this.once(`error`,n),this.once(e,t)})}async done(){K(this,Q,!0,`f`),await q(this,Yr,`f`)}get currentMessage(){return q(this,Y,`f`)}async finalMessage(){return await this.done(),q(this,J,`m`,ni).call(this)}async finalText(){return await this.done(),q(this,J,`m`,ri).call(this)}_emit(e,...t){if(q(this,Z,`f`))return;e===`end`&&(K(this,Z,!0,`f`),q(this,Xr,`f`).call(this));let n=q(this,X,`f`)[e];if(n&&(q(this,X,`f`)[e]=n.filter(e=>!e.once),n.forEach(({listener:e})=>e(...t))),e===`abort`){let e=t[0];!q(this,Q,`f`)&&!n?.length&&Promise.reject(e),q(this,Jr,`f`).call(this,e),q(this,Zr,`f`).call(this,e),this._emit(`end`)}else if(e===`error`){let e=t[0];!q(this,Q,`f`)&&!n?.length&&Promise.reject(e),q(this,Jr,`f`).call(this,e),q(this,Zr,`f`).call(this,e),this._emit(`end`)}}_emitFinal(){this.receivedMessages.at(-1)&&this._emit(`finalMessage`,q(this,J,`m`,ni).call(this))}async _fromReadableStream(e,t){let n=t?.signal;n&&(n.aborted&&this.controller.abort(),n.addEventListener(`abort`,()=>this.controller.abort())),q(this,J,`m`,ai).call(this),this._connected(null);let r=k.fromReadableStream(e,this.controller);for await(let e of r)q(this,J,`m`,oi).call(this,e);if(r.controller.signal?.aborted)throw new T;q(this,J,`m`,si).call(this)}[(Y=/* @__PURE__ */ new WeakMap,Kr=/* @__PURE__ */ new WeakMap,qr=/* @__PURE__ */ new WeakMap,Jr=/* @__PURE__ */ new WeakMap,Yr=/* @__PURE__ */ new WeakMap,Xr=/* @__PURE__ */ new WeakMap,Zr=/* @__PURE__ */ new WeakMap,X=/* @__PURE__ */ new WeakMap,Z=/* @__PURE__ */ new WeakMap,Qr=/* @__PURE__ */ new WeakMap,$r=/* @__PURE__ */ new WeakMap,Q=/* @__PURE__ */ new WeakMap,ei=/* @__PURE__ */ new WeakMap,ti=/* @__PURE__ */ new WeakMap,ii=/* @__PURE__ */ new WeakMap,J=/* @__PURE__ */ new WeakSet,ni=function(){if(this.receivedMessages.length===0)throw new C(`stream ended without producing a Message with role=assistant`);return this.receivedMessages.at(-1)},ri=function(){if(this.receivedMessages.length===0)throw new C(`stream ended without producing a Message with role=assistant`);let e=this.receivedMessages.at(-1).content.filter(e=>e.type===`text`).map(e=>e.text);if(e.length===0)throw new C(`stream ended without producing a content block with type=text`);return e.join(` `)},ai=function(){this.ended||K(this,Y,void 0,`f`)},oi=function(e){if(this.ended)return;let t=q(this,J,`m`,ci).call(this,e);switch(this._emit(`streamEvent`,e,t),e.type){case`content_block_delta`:{let n=t.content.at(-1);switch(e.delta.type){case`text_delta`:n.type===`text`&&this._emit(`text`,e.delta.text,n.text||``);break;case`citations_delta`:n.type===`text`&&this._emit(`citation`,e.delta.citation,n.citations??[]);break;case`input_json_delta`:n.type===`tool_use`&&n.input&&this._emit(`inputJson`,e.delta.partial_json,n.input);break;case`thinking_delta`:n.type===`thinking`&&this._emit(`thinking`,e.delta.thinking,n.thinking);break;case`signature_delta`:n.type===`thinking`&&this._emit(`signature`,n.signature);break;default:e.delta}break}case`message_stop`:this._addMessageParam(t),this._addMessage(t,!0);break;case`content_block_stop`:this._emit(`contentBlock`,t.content.at(-1));break;case`message_start`:K(this,Y,t,`f`)}},si=function(){if(this.ended)throw new C(`stream has ended, this shouldn't happen`);let e=q(this,Y,`f`);if(!e)throw new C(`request ended without sending any chunks`);return K(this,Y,void 0,`f`),e},ci=function(e){let t=q(this,Y,`f`);if(e.type===`message_start`){if(t)throw new C(`Unexpected event order, got ${e.type} before receiving "message_stop"`);return e.message}if(!t)throw new C(`Unexpected event order, got ${e.type} before "message_start"`);switch(e.type){case`message_stop`:return t;case`message_delta`:return t.stop_reason=e.delta.stop_reason,t.stop_sequence=e.delta.stop_sequence,t.usage.output_tokens=e.usage.output_tokens,t;case`content_block_start`:return t.content.push(e.content_block),t;case`content_block_delta`:{let n=t.content.at(e.index);switch(e.delta.type){case`text_delta`:n?.type===`text`&&(n.text+=e.delta.text);break;case`citations_delta`:n?.type===`text`&&(n.citations??=[],n.citations.push(e.delta.citation));break;case`input_json_delta`:if(n?.type===`tool_use`){let t=n[li]||``;t+=e.delta.partial_json,Object.defineProperty(n,li,{value:t,enumerable:!1,writable:!0}),t&&(n.input=Tr(t))}break;case`thinking_delta`:n?.type===`thinking`&&(n.thinking+=e.delta.thinking);break;case`signature_delta`:n?.type===`thinking`&&(n.signature=e.delta.signature);break;default:e.delta}return t}case`content_block_stop`:return t}},Symbol.asyncIterator)](){let e=[],t=[],n=!1;return this.on(`streamEvent`,n=>{let r=t.shift();r?r.resolve(n):e.push(n)}),this.on(`end`,()=>{n=!0;for(let e of t)e.resolve(void 0);t.length=0}),this.on(`abort`,e=>{n=!0;for(let n of t)n.reject(e);t.length=0}),this.on(`error`,e=>{n=!0;for(let n of t)n.reject(e);t.length=0}),{next:async()=>e.length?{value:e.shift(),done:!1}:n?{value:void 0,done:!0}:new Promise((e,n)=>t.push({resolve:e,reject:n})).then(e=>e?{value:e,done:!1}:{value:void 0,done:!0}),return:async()=>(this.abort(),{value:void 0,done:!0})}}toReadableStream(){return new k(this[Symbol.asyncIterator].bind(this),this.controller).toReadableStream()}},di=class extends M{constructor(){super(...arguments),this.batches=new Wr(this._client)}create(e,t){return e.model in fi&&console.warn(`The model '${e.model}' is deprecated and will reach end-of-life on ${fi[e.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`),this._client.post(`/v1/messages`,{body:e,timeout:this._client._options.timeout??(e.stream?6e5:this._client._calculateNonstreamingTimeout(e.max_tokens)),...t,stream:e.stream??!1})}stream(e,t){return ui.createMessage(this,e,t)}countTokens(e,t){return this._client.post(`/v1/messages/count_tokens`,{body:e,...t})}};const fi={"claude-1.3":`November 6th, 2024`,"claude-1.3-100k":`November 6th, 2024`,"claude-instant-1.1":`November 6th, 2024`,"claude-instant-1.1-100k":`November 6th, 2024`,"claude-instant-1.2":`November 6th, 2024`,"claude-3-sonnet-20240229":`July 21st, 2025`,"claude-2.1":`July 21st, 2025`,"claude-2.0":`July 21st, 2025`};di.Batches=Wr,di.MessageBatchesPage=Gr;var pi=class extends M{retrieve(e,t){return this._client.get(`/v1/models/${e}`,t)}list(e={},t){return A(e)?this.list({},e):this._client.getAPIList(`/v1/models`,mi,{query:e,...t})}},mi=class extends gr{};pi.ModelInfosPage=mi;var hi,$=class extends Gn{constructor({baseURL:e=cr(`ANTHROPIC_BASE_URL`),apiKey:t=cr(`ANTHROPIC_API_KEY`)??null,authToken:n=cr(`ANTHROPIC_AUTH_TOKEN`)??null,...r}={}){let i={apiKey:t,authToken:n,...r,baseURL:e||`https://api.anthropic.com`};if(!i.dangerouslyAllowBrowser&&pr())throw new C(`It looks like you're running in a browser-like environment.
80
6
 
81
7
  This is disabled by default, as it risks exposing your secret API credentials to attackers.
82
8
  If you understand the risks and have appropriate mitigations in place,
83
9
  you can set the \`dangerouslyAllowBrowser\` option to \`true\`, e.g.,
84
10
 
85
11
  new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
86
- `);super({baseURL:o.baseURL,timeout:o.timeout??6e5,httpAgent:o.httpAgent,maxRetries:o.maxRetries,fetch:o.fetch}),this.completions=new G(this),this.messages=new j(this),this.models=new D(this),this.beta=new E(this),this._options=o,this.apiKey=t,this.authToken=i}defaultQuery(){return this._options.defaultQuery}defaultHeaders(e){return{...super.defaultHeaders(e),...this._options.dangerouslyAllowBrowser?{"anthropic-dangerous-direct-browser-access":"true"}:void 0,"anthropic-version":"2023-06-01",...this._options.defaultHeaders}}validateHeaders(e,t){if(!(this.apiKey&&e["x-api-key"])&&t["x-api-key"]!==null&&!(this.authToken&&e.authorization)&&t.authorization!==null)throw new Error('Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted')}authHeaders(e){let t=this.apiKeyAuth(e),i=this.bearerAuth(e);return t!=null&&!Ie(t)?t:i!=null&&!Ie(i)?i:{}}apiKeyAuth(e){return this.apiKey==null?{}:{"X-Api-Key":this.apiKey}}bearerAuth(e){return this.authToken==null?{}:{Authorization:`Bearer ${this.authToken}`}}};Rr=d;d.Anthropic=Rr;d.HUMAN_PROMPT=`
87
-
88
- Human:`;d.AI_PROMPT=`
89
-
90
- Assistant:`;d.DEFAULT_TIMEOUT=6e5;d.AnthropicError=l;d.APIError=h;d.APIConnectionError=R;d.APIConnectionTimeoutError=te;d.APIUserAbortError=y;d.NotFoundError=we;d.ConflictError=ve;d.RateLimitError=xe;d.BadRequestError=me;d.AuthenticationError=ye;d.InternalServerError=_e;d.PermissionDeniedError=be;d.UnprocessableEntityError=ke;d.toFile=yr;d.fileFromPath=Fe;d.Completions=G;d.Messages=j;d.Models=D;d.ModelInfosPage=W;d.Beta=E;var{HUMAN_PROMPT:kl,AI_PROMPT:xl}=d,Lr=d;var ka={model:"claude-3-7-sonnet-20250219",max_tokens:8192,temperature:.1},Nr={headers:{"x-api-key":null,authorization:null}};async function xa(r,e,t,i){let n={};e.model&&(n.model=e.model),e.maxTokens&&(n.max_tokens=e.maxTokens),e.temperature&&(n.temperature=e.temperature);let o=await r.messages.create({...ka,...n,stream:!0,messages:[{role:"user",content:[{type:"text",text:t}]}]},{signal:i,...Nr,headers:{...Nr.headers??{},...e.headers}});async function*a(){try{for await(let s of o)s.type==="content_block_delta"&&s.delta.type==="text_delta"&&(yield s.delta.text)}catch(s){throw console.error("Stream error:",s),s}}return a()}var Or=xa;function Dr(r){return()=>{let e=null,i=ur({"ly.img.improve":!0,"ly.img.fix":{},"ly.img.shorter":!0,"ly.img.longer":{},"ly.img.changeTone":!0,"ly.img.translate":!0,"ly.img.changeTextTo":{}},r.supportedQuickActions),n={kind:"text",id:"anthropic",name:"Anthropic",initialize:async()=>{e=new Lr({dangerouslyAllowBrowser:!0,baseURL:r.proxyUrl,apiKey:null,authToken:null})},input:{quickActions:{supported:i}},output:{middleware:r.middlewares??r.middleware??[],generate:async({prompt:o,blockId:a},{engine:s,abortSignal:f})=>{if(e==null)throw new Error("Anthropic SDK is not initialized");if(a!=null&&s.block.getType(a)!=="//ly.img.ubq/text")throw new Error("If a block is provided to this generation, it most be a text block");r.debug&&console.log("Sending prompt to Anthropic:",JSON.stringify(o,void 0,2));let g=await Or(e,{proxyUrl:r.proxyUrl,headers:r.headers,model:r.model??"claude-3-7-sonnet-20250219"},o,f);async function*v(){let x="";for await(let K of g){if(f?.aborted)break;x+=K,yield{kind:"text",text:x}}return{kind:"text",text:x}}return v()}}};return Promise.resolve(n)}}var _a={AnthropicProvider:Dr},Pl=_a;export{Pl as default};
91
- /*! Bundled license information:
92
-
93
- lodash-es/lodash.js:
94
- (**
95
- * @license
96
- * Lodash (Custom Build) <https://lodash.com/>
97
- * Build: `lodash modularize exports="es" -o ./`
98
- * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
99
- * Released under MIT license <https://lodash.com/license>
100
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
101
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
102
- *)
103
- */
104
- //# sourceMappingURL=index.mjs.map
12
+ `);super({baseURL:i.baseURL,timeout:i.timeout??6e5,httpAgent:i.httpAgent,maxRetries:i.maxRetries,fetch:i.fetch}),this.completions=new Ur(this),this.messages=new di(this),this.models=new pi(this),this.beta=new G(this),this._options=i,this.apiKey=t,this.authToken=n}defaultQuery(){return this._options.defaultQuery}defaultHeaders(e){return{...super.defaultHeaders(e),...this._options.dangerouslyAllowBrowser?{"anthropic-dangerous-direct-browser-access":`true`}:void 0,"anthropic-version":`2023-06-01`,...this._options.defaultHeaders}}validateHeaders(e,t){if(!(this.apiKey&&e[`x-api-key`])&&t[`x-api-key`]!==null&&!(this.authToken&&e.authorization)&&t.authorization!==null)throw Error(`Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted`)}authHeaders(e){let t=this.apiKeyAuth(e),n=this.bearerAuth(e);return t!=null&&!lr(t)?t:n!=null&&!lr(n)?n:{}}apiKeyAuth(e){return this.apiKey==null?{}:{"X-Api-Key":this.apiKey}}bearerAuth(e){return this.authToken==null?{}:{Authorization:`Bearer ${this.authToken}`}}};hi=$,$.Anthropic=hi,$.HUMAN_PROMPT=`
13
+
14
+ Human:`,$.AI_PROMPT=`
15
+
16
+ Assistant:`,$.DEFAULT_TIMEOUT=6e5,$.AnthropicError=C,$.APIError=w,$.APIConnectionError=dn,$.APIConnectionTimeoutError=fn,$.APIUserAbortError=T,$.NotFoundError=gn,$.ConflictError=_n,$.RateLimitError=yn,$.BadRequestError=pn,$.AuthenticationError=mn,$.InternalServerError=bn,$.PermissionDeniedError=hn,$.UnprocessableEntityError=vn,$.toFile=Mn,$.fileFromPath=sn,$.Completions=Ur,$.Messages=di,$.Models=pi,$.ModelInfosPage=mi,$.Beta=G;const{HUMAN_PROMPT:gi,AI_PROMPT:_i}=$,vi={model:`claude-3-7-sonnet-20250219`,max_tokens:8192,temperature:.1},yi={headers:{"x-api-key":null,authorization:null}};async function bi(e,t,n,r){let i={};t.model&&(i.model=t.model),t.maxTokens&&(i.max_tokens=t.maxTokens),t.temperature&&(i.temperature=t.temperature);let a=await e.messages.create({...vi,...i,stream:!0,messages:[{role:`user`,content:[{type:`text`,text:n}]}]},{signal:r,...yi,headers:{...yi.headers??{},...t.headers}});async function*o(){try{for await(let e of a)e.type===`content_block_delta`&&e.delta.type===`text_delta`&&(yield e.delta.text)}catch(e){throw console.error(`Stream error:`,e),e}}return o()}function xi(e){return()=>{let t=null,n={kind:`text`,id:`anthropic`,name:`Anthropic`,initialize:async()=>{t=new $({dangerouslyAllowBrowser:!0,baseURL:e.proxyUrl,apiKey:null,authToken:null})},input:{quickActions:{supported:en({"ly.img.improve":!0,"ly.img.fix":{},"ly.img.shorter":!0,"ly.img.longer":{},"ly.img.changeTone":!0,"ly.img.translate":!0,"ly.img.changeTextTo":{}},e.supportedQuickActions)}},output:{middleware:e.middlewares??e.middleware??[],generate:async({prompt:n,blockId:r},{engine:i,abortSignal:a})=>{if(t==null)throw Error(`Anthropic SDK is not initialized`);if(r!=null&&i.block.getType(r)!==`//ly.img.ubq/text`)throw Error(`If a block is provided to this generation, it most be a text block`);e.debug&&console.log(`Sending prompt to Anthropic:`,JSON.stringify(n,void 0,2));let o=await bi(t,{proxyUrl:e.proxyUrl,headers:e.headers,model:e.model??`claude-3-7-sonnet-20250219`},n,a);async function*s(){let e=``;for await(let t of o){if(a?.aborted)break;e+=t,yield{kind:`text`,text:e}}return{kind:`text`,text:e}}return s()}}};return Promise.resolve(n)}}const Si={AnthropicProvider:xi};export{Si as default};
17
+ /**
18
+ * @license
19
+ * Lodash (Custom Build) <https://lodash.com/>
20
+ * Build: `lodash modularize exports="es" -o ./`
21
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
22
+ * Released under MIT license <https://lodash.com/license>
23
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
24
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
25
+ */
26
+ //# sourceMappingURL=index.mjs.map