UNPKG

@anthropic-ai/claude-agent-sdk

Version:

SDK for building AI agents with Claude Code's capabilities. Programmatically interact with Claude to build autonomous agents that can understand codebases, edit files, and execute workflows.

18 lines (15 loc) • 6.93 kB
// (c) Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://code.claude.com/docs/en/legal-and-compliance. // Version: 0.3.325 //! symbol-dispose-prelude: defines Symbol.dispose and Symbol.asyncDispose if missing, for this bundle's `using`. if (typeof Symbol.dispose !== 'symbol') { try { Symbol.dispose = Symbol.for('Symbol.dispose') } catch {} } if (typeof Symbol.asyncDispose !== 'symbol') { try { Symbol.asyncDispose = Symbol.for('Symbol.asyncDispose') } catch {} } import{u}from"./core-msnqqcc2.mjs";var h=["us","eu","apac","jp","au","us-gov","global"],Rn=["us","eu","apac","jp","au","global"];function b(e,n,t){if(e===n)return 0;let i=e.length,o=n.length,r=t+1;if(Math.abs(i-o)>t)return r;let s=new Int32Array(o+2).fill(r),a=new Int32Array(o+2).fill(r),d=new Int32Array(o+2).fill(r);for(let l=0;l<=Math.min(o,t);l++)a[l]=l;for(let l=1;l<=i;l++){let f=Math.max(1,l-t),M=Math.min(o,l+t);d[f-1]=f===1?Math.min(l,r):r;let g=d[f-1];for(let c=f;c<=M;c++){let m=Math.min(a[c]+1,d[c-1]+1,a[c-1]+(e[l-1]===n[c-1]?0:1),r);if(l>1&&c>1&&e[l-1]===n[c-2]&&e[l-2]===n[c-1])m=Math.min(m,s[c-2]+1);d[c]=m,g=Math.min(g,m)}if(d[M+1]=r,g>t)return r;[s,a,d]=[a,d,s]}return a[o]}var On=["claude-3-5-haiku","claude-3-5-sonnet","claude-3-7-sonnet","claude-fable-5","claude-fable-5-1","claude-fable-5-2","claude-haiku-4-5","claude-haiku-5-5","claude-mythos-5","claude-mythos-5-1","claude-mythos-5-2","claude-opus-4-0","claude-opus-4-1","claude-opus-4-5","claude-opus-4-6","claude-opus-4-7","claude-opus-4-8","claude-opus-5","claude-opus-5-5","claude-sonnet-4-0","claude-sonnet-4-5","claude-sonnet-4-6","claude-sonnet-5","claude-sonnet-5-5"],x=["sonnet","opus","haiku","fable","best","sonnet[1m]","opus[1m]","fable[1m]","opusplan"],ge=["sonnet","opus","haiku","fable"];function ft(e){return x.includes(e)}function Bt(e){return e.replace(/\[1m\]$/i,"")}function y(e){return e.replace(/\[(1|2)m\]/gi,"")}function be(e){return ge.includes(e)}function V(e){let n=e.trim().toLowerCase();if(n===""||/\s/.test(n))return null;n=n.replace(/\[[12]m\]$/,"");let t=n.lastIndexOf("/");if(t!==-1)n=n.slice(t+1);let i=/^(?:([a-z-]+)\.)?anthropic\.(claude-.*)$/.exec(n);if(i){let[,a,d=""]=i;if(a!==void 0&&!h.includes(a))return null;n=d}let o=I(n);if(!o)return null;let r=n.slice(o.base.length);if(r!==""&&!/^[-@]/.test(r))return null;let s={family:o.family,major:o.major,legacyVersionFirst:o.legacyVersionFirst,base:o.base};if(o.minor!==void 0)s.minor=o.minor;if(!E(r))s.trailer=r;else{let a=/(?:-v\d+@|[-@])(\d{8})/.exec(r)?.[1];if(a!==void 0)s.date=a}return s}function E(e){return/^(?:-fast|-latest)?(?:-v\d{1,3}@\d{8}|[-@]\d{8})?(?:-v\d{1,3}(?::\d{1,3})?)?$/.test(e)}function Tn(e,n){return e.major-n.major||(e.minor??0)-(n.minor??0)}function I(e){let n=/^claude-([a-z]+)-(\d{1,2})(?!\d)(?:-(\d{1,2})(?!\d))?/.exec(e);if(n){let[i,o="",r="",s]=n;return{family:o,major:Number(r),minor:s===void 0?void 0:Number(s),legacyVersionFirst:!1,base:i}}let t=/^claude-(\d{1,2})(?!\d)(?:-(\d{1,2})(?!\d))?-([a-z]+)/.exec(e);if(t){let[i,o="",r,s=""]=t;return{family:s,major:Number(o),minor:r===void 0?void 0:Number(r),legacyVersionFirst:!0,base:i}}return null}function D(e){let n=e.replace(/[\u0000-\u001f\u007f-\u009f]/g,"?");return n.length>128?`${n.slice(0,128)}…`:n}function A(){let e=[...ge],n=e.pop();return e.length===0?n??"":`${e.join(", ")} or ${n}`}function p(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ye(e){let n=e.trim().toLowerCase(),t=y(n).trim(),i=t!==n?" Context-size tags such as [1m] are ignored: the entry blocks the model at every context size.":"";if(t==="")return{entry:null,warning:"An empty deniedModels entry was ignored."};if(be(t))return{entry:{kind:"family",family:t},...i!==""&&{warning:`"${D(e)}" blocks every ${p(t)} model.${i}`}};if(ft(t)||t==="default")return{entry:null,warning:`"${D(e)}" was ignored: it names a different model depending on the release and settings. Name the model instead, for example "claude-opus-5-5".`};let o=V(t),r=o!==null||t.startsWith("claude-")?t:`claude-${t}`,s=o??(r!==t?V(r):null);if(s){let a=r.lastIndexOf(s.base),d=a===-1?"":r.slice(a+s.base.length),l=s.trailer===void 0&&d!==""?` "${D(d)}" is ignored.`:"";return{entry:{kind:"model",id:s},...(i!==""||l!=="")&&{warning:`"${D(e)}" blocks ${w(s)}.${l}${i}`}}}return{entry:{kind:"literal",value:t},warning:_(e,t)}}function w(e){let n=p(e.family);return e.minor===void 0?`every ${n} ${e.major}.x model`:`${n} ${e.major}.${e.minor} in every spelling and snapshot`}function _(e,n){let t=`"${D(e)}" blocks only the exact model name "${D(n)}"; other spellings of the same model are not blocked.`,i=n.replace(/(\d)\.(\d)/g,"$1-$2");if(i!==n){let r=i.startsWith("claude-")?i:`claude-${i}`;if(V(r)!==null)return`${t} To block a version, write it with a hyphen: "${D(r)}".`}let o=new RegExp(`^(${ge.join("|")})\\s+(\\d+)(?:\\.(\\d+))?$`).exec(n);if(o){let[,r,s,a]=o;return a!==void 0?`${t} To block a version, write its model ID, for example "claude-${r}-${s}-${a}".`:`${t} To block only version ${s}, write "claude-${r}-${s}-0"; "claude-${r}-${s}" blocks every ${p(r)} ${s}.x model.`}if(/^[a-z]+$/.test(n)){let r=ge.find((s)=>b(n,s,1)===1);return r!==void 0?`${t} If you meant the ${p(r)} family, write "${r}".`:`${t} To block a model family other than ${A()}, list its versioned IDs.`}return t}function S(e,n){if(e.family!==n.family||e.major!==n.major)return!1;if(e.minor!==void 0&&(n.minor??0)!==e.minor)return!1;if(e.trailer===void 0)return!0;let t=n.trailer??"";return t===e.trailer||t.startsWith(`${e.trailer}-`)}function k(e,n){for(let t=e.indexOf(n);t!==-1;t=e.indexOf(n,t+1)){let i=t===0||!/[a-z0-9]/i.test(e[t-1]),o=t+n.length,r=o===e.length||!/[a-z0-9]/i.test(e[o]);if(i&&r)return!0}return!1}function O(e,n,t){switch(e.kind){case"literal":return n===e.value;case"family":return t?.family===e.family||k(n,e.family);case"model":return t!==null&&S(e.id,t)}}function L(e,n){let t=y(e.trim()).toLowerCase(),i=V(t);return n.some((o)=>{let{entry:r}=Ye(o);return r!==null&&O(r,t,i)})}var gt='"deniedModels" was present but is not a list of model names, so it was ignored and blocks no models until it is fixed.';function mt(e){let n=[],t=[];for(let i of e)if(typeof i==="string")n.push(i);else t.push(`"deniedModels" contained a non-string entry (${i===null?"null":typeof i}); the entry was ignored.`);return{entries:n,notes:t}}function xn(e,n){let t=Array.isArray(e)?e:[],i=Array.isArray(e)?t.flatMap((a)=>typeof a==="string"?[]:`"models" contained a non-string entry (${a===null?"null":typeof a}), which is not a model name, so it cannot be matched.`):['"models" is not a list of model names, so nothing was matched.'],o=n??[];if(!Array.isArray(o))return{denied:t.map(()=>!1),warnings:u([gt,...i])};let{entries:r,notes:s}=mt(o);return{denied:t.map((a)=>typeof a==="string"&&L(a,r)),warnings:u([...s,...r.flatMap((a)=>Ye(a).warning??[]),...i])}} export{Rn,On,ge,ft,Bt,be,V,Tn,D,Ye,gt,mt,xn};