@anthropic-ai/claude-agent-sdk 0.3.310 → 0.3.311

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  // (c) Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://code.claude.com/docs/en/legal-and-compliance.
2
2
 
3
- // Version: 0.3.310
3
+ // Version: 0.3.311
4
4
 
5
5
  // symbol-dispose-prelude: bun build --banner for every SDK bundle; the build
6
6
  // scripts grep for this line's tag. Runs before any module body. bun lowers
@@ -1,6 +1,6 @@
1
1
  // (c) Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://code.claude.com/docs/en/legal-and-compliance.
2
2
 
3
- // Version: 0.3.310
3
+ // Version: 0.3.311
4
4
 
5
5
  // symbol-dispose-prelude: bun build --banner for every SDK bundle; the build
6
6
  // scripts grep for this line's tag. Runs before any module body. bun lowers
@@ -22,6 +22,6 @@ if (typeof Symbol.asyncDispose !== 'symbol') {
22
22
  Symbol.asyncDispose = Symbol.for('Symbol.asyncDispose')
23
23
  } catch {}
24
24
  }
25
- import{d,i,l,r,t,Ee,Ct,j,Bt,jt,ae,nt,At,Gt,Rt,rt,le}from"./core-bz5kkzv0.mjs";import{randomUUID as D}from"crypto";import{constants as _}from"fs";import{open as z,readdir as x,rm as L,stat as Z}from"fs/promises";import{join as g}from"path";class I{available=void 0;probing=void 0;procUnreadableLogged=!1}var $e=new i(()=>new I);var k=["commands","agents","output-styles","skills","workflows","routines","themes","rules","session-env","uploads","mcp-skill-archives","usage-data","mcp-discovery-cache"];var cn=new Set(k),un=`must be one of the userConfigDir directory names (${k.join(", ")})`,R=["installed","marketplaces","flagged","catalog","inUseSweep"];var dn=new Set(R),ln=`must be one of the pluginRegistry files (${R.join(", ")})`,w=["manifest","catalog"];var fn=new Set(w),pn=`must be one of the marketplaceCache forms (${w.join(", ")})`;var P=["world"];var mn=new Set(P),gn=`must be one of the session journal names (${P.join(", ")})`;var C=["backup","corrupted"];var hn=new Set(C),yn=`must be one of the global-config copy kinds (${C.join(", ")})`;var B="cloud-snapshots";var W=new Set(["memory","tiny_memory","bagel",B,"bridge-pointer.json",".session-aliases"]);var v=".cast",Sn=`<stamp>${v} inside a session's folder is that session's terminal recording stream: address it as keys.recording(projectKey, sessionId, stamp)`;var J=[".ccr-tip.json",".precompact.json",v],bn=`must not end with ${J.join(", ")}: those name a session's project-level sibling files`;var q=".dir-sync.json",En=`must not end with ${q}: that name is reserved for a cloud session's record at the project level`;var In=`${[...W].join(", ")} are reserved: they name project-level entries, not sessions`;var X="timeline.jsonl",jn=`${X} is the job's timeline stream: address it as keys.jobTimeline(jobId)`;function y(e){return e===void 0?void 0:{source:e,hoverRestOn:d()}}var Q=64;function E(e){return d()?e:void 0}async function K(e,n,a={},s){if(!j(e))throw Error(`Invalid sessionId: ${e}`);if(!n.trim())throw Error("title must be non-empty");let o=t({type:"custom-title",customTitle:n.trim(),sessionId:e})+`
26
- `;await T(e,o,a,E(s))}async function A(e,n,a={},s){if(!j(e))throw Error(`Invalid sessionId: ${e}`);if(n!==null){let c=Ee(n).trim();if(!c)throw Error("tag must be non-empty (use null to clear)");n=c}let o=t({type:"tag",tag:n??"",sessionId:e})+`
27
- `;await T(e,o,a,E(s))}async function F(e,n={},a){if(!j(e))throw Error(`Invalid sessionId: ${e}`);let s=E(a);for(let o of await ne(n,s)){if(d()&&s!==void 0){let u=At(o,s.isKeySegment);if(u!==void 0){if(await ee(u,e,s))return;continue}}let c=g(o,`${e}.jsonl`),f;try{({size:f}=await Z(c))}catch(u){let p=r(u);if(p==="ENOENT"||p==="ENOTDIR")continue;throw u}if(f===0)continue;await L(c,{force:!0}),await L(g(o,e),{recursive:!0,force:!0});return}throw Error(n.dir?`Session ${e} not found in project directory for ${n.dir}`:`Session ${e} not found in any project directory`)}async function ee(e,n,a){let{backend:s,transcriptKey:o}=a,c=o(e,n),f=await s.statMeta(c);if(!f.ok){if(f.error.code==="NotFound")return!1;throw Error("Session delete: transcript unreadable via storage",{cause:f.error})}if((f.value.storedBytes??f.value.size)===0)return!1;for(let p of["transcript","sidecar"]){let m=await s.deleteScope({namespace:p,projectKey:e,sessionId:n});if(!m.ok)throw Error("Session delete: session directory not deletable via storage",{cause:m.error})}let u=await s.delete(c);if(!u.ok)throw Error("Session delete: transcript not deletable via storage",{cause:u.error});return!0}async function ne(e,n){if(e.dir){let s=await Gt(e.dir,Bt(n,d())),o=await O(s,n),c;try{c=await Ct(s)}catch{c=[]}for(let f of c){if(f===s)continue;o.push(...await O(f,n))}return o}let a=ae();if(d()&&n!==void 0){let s=await N(n);if(s===void 0)return[];if(s.laterPageFailed)throw Error("Session delete: project listing incomplete via storage");return s.names.map((o)=>g(a,o))}try{return(await x(a,{withFileTypes:!0})).filter((o)=>o.isDirectory()||o.isSymbolicLink()).map((o)=>g(a,o.name))}catch{return[]}}async function O(e,n){let a=y(n);if(a===void 0||!a.hoverRestOn)return rt(e);let s=await rt(e,a),o=nt(e),c=process.platform==="win32",f=[];for(let u of s)if(u===o||await Rt(u,e,c,a))f.push(u);return f}async function N(e){let n=[],a,s=0;try{do{let o=await e.backend.listEntries({namespace:"transcript"},{skipScopeStats:!0,...a!==void 0&&{cursor:a}});if(!o.ok)return s===0?void 0:{names:n,laterPageFailed:!0};for(let c of o.value.items){let f=jt(c,e.isKeySegment);if(f!==void 0)n.push(f)}a=o.value.cursor}while(a&&++s<Q);return{names:n,laterPageFailed:Boolean(a)}}catch{return s===0&&n.length===0?void 0:{names:n,laterPageFailed:!0}}}async function T(e,n,a,s){let o=`${e}.jsonl`;if(a.dir){let u=await Gt(a.dir,Bt(s,d()));for(let m of await rt(u,y(s)))if(await S(g(m,o),n,b(m,e,s)))return;let p;try{p=await Ct(u)}catch{p=[]}for(let m of p){if(m===u)continue;for(let h of await rt(m,y(s)))if(await S(g(h,o),n,b(h,e,s)))return}throw Error(`Session ${e} not found in project directory for ${a.dir}`)}let c=ae();if(d()&&s!==void 0){let u=await N(s);if(u===void 0)throw new l(`Session ${e} not found (no projects directory)`,"Session not found (no projects directory)");let{names:p}=u;for(let m of p){let h=g(c,m);if(await S(g(h,o),n,b(h,e,s)))return}throw new l(`Session ${e} not found in any project directory`,"Session not found in any project directory")}let f;try{f=await x(c)}catch{throw Error(`Session ${e} not found (no projects directory)`)}for(let u of f)if(await S(g(c,u,o),n))return;throw Error(`Session ${e} not found in any project directory`)}async function S(e,n,a){if(d()&&a!==void 0)return re(a,n);let s;try{s=await z(e,_.O_WRONLY|_.O_APPEND)}catch(o){let c=r(o);if(c==="ENOENT"||c==="ENOTDIR")return!1;throw o}try{let{size:o}=await s.stat();if(o===0)return!1;let c=process.platform==="win32"?o:void 0,f=Buffer.from(n,"utf8"),u=0;while(u<f.length){let{bytesWritten:p}=await s.write(f,u,f.length-u,c);if(p<=0)throw new l(`tryAppend: short write to ${e} stalled with ${f.length-u} bytes remaining`,"tryAppend: zero-progress short write");if(u+=p,c!==void 0)c+=p}return!0}finally{await s.close()}}async function re({backend:e,key:n},a){let s=await e.append(n,[{data:a}],{precondition:{type:"ifExists",nonEmpty:!0}});if(!s.ok){if(s.error.code==="NotFound")return!1;throw Error("Session append: transcript not writable via storage",{cause:s.error})}return!0}function b(e,n,a){if(!d()||a===void 0)return;let s=At(e,a.isKeySegment);return s===void 0?void 0:{backend:a.backend,key:a.transcriptKey(s,n)}}async function er(e,n,a){if(a?.sessionStore)return te(a.sessionStore,e,n,a.dir);return K(e,n,a)}async function nr(e,n,a){if(a?.sessionStore)return se(a.sessionStore,e,n,a.dir);return A(e,n,a)}async function rr(e,n){if(!j(e))throw new l(`Invalid sessionId: ${e}`,"deleteSession: invalid sessionId (must be a UUID)");if(n?.sessionStore){if(!n.sessionStore.delete)return;let a=le(n.dir);await n.sessionStore.delete({projectKey:a,sessionId:e});return}return F(e,n)}async function te(e,n,a,s){if(!j(n))throw new l(`Invalid sessionId: ${n}`,"renameSession: invalid sessionId (must be a UUID)");if(!a.trim())throw Error("title must be non-empty");let o=le(s);await e.append({projectKey:o,sessionId:n},[{type:"custom-title",customTitle:a.trim(),sessionId:n,uuid:D(),timestamp:new Date().toISOString()}])}async function se(e,n,a,s){if(!j(n))throw new l(`Invalid sessionId: ${n}`,"tagSession: invalid sessionId (must be a UUID)");if(a!==null){let c=Ee(a).trim();if(!c)throw Error("tag must be non-empty (use null to clear)");a=c}let o=le(s);await e.append({projectKey:o,sessionId:n},[{type:"tag",tag:a??"",sessionId:n,uuid:D(),timestamp:new Date().toISOString()}])}export{rr as deleteSession,er as renameSession,nr as tagSession};
25
+ import{d,i,l,r,n,Ee,Ct,j,Kt,Gt,ae,nt,At,zt,Rt,rt,le}from"./core-zbftdwza.mjs";import{randomUUID as D}from"crypto";import{constants as _}from"fs";import{open as z,readdir as x,rm as L,stat as Z}from"fs/promises";import{join as g}from"path";class I{available=void 0;probing=void 0;procUnreadableLogged=!1}var $e=new i(()=>new I);var k=["commands","agents","output-styles","skills","workflows","routines","themes","rules","session-env","uploads","mcp-skill-archives","usage-data","mcp-discovery-cache"];var cn=new Set(k),un=`must be one of the userConfigDir directory names (${k.join(", ")})`,R=["installed","marketplaces","flagged","catalog","inUseSweep"];var dn=new Set(R),ln=`must be one of the pluginRegistry files (${R.join(", ")})`,w=["manifest","catalog"];var fn=new Set(w),pn=`must be one of the marketplaceCache forms (${w.join(", ")})`;var P=["world"];var mn=new Set(P),gn=`must be one of the session journal names (${P.join(", ")})`;var C=["backup","corrupted"];var hn=new Set(C),yn=`must be one of the global-config copy kinds (${C.join(", ")})`;var B="cloud-snapshots";var W=new Set(["memory","tiny_memory","bagel",B,"bridge-pointer.json",".session-aliases"]);var v=".cast",Sn=`<stamp>${v} inside a session's folder is that session's terminal recording stream: address it as keys.recording(projectKey, sessionId, stamp)`;var J=[".ccr-tip.json",".precompact.json",v],bn=`must not end with ${J.join(", ")}: those name a session's project-level sibling files`;var q=".dir-sync.json",En=`must not end with ${q}: that name is reserved for a cloud session's record at the project level`;var In=`${[...W].join(", ")} are reserved: they name project-level entries, not sessions`;var X="timeline.jsonl",jn=`${X} is the job's timeline stream: address it as keys.jobTimeline(jobId)`;function y(e){return e===void 0?void 0:{source:e,hoverRestOn:d()}}var Q=64;function E(e){return d()?e:void 0}async function K(e,t,a={},s){if(!j(e))throw Error(`Invalid sessionId: ${e}`);if(!t.trim())throw Error("title must be non-empty");let o=n({type:"custom-title",customTitle:t.trim(),sessionId:e})+`
26
+ `;await T(e,o,a,E(s))}async function A(e,t,a={},s){if(!j(e))throw Error(`Invalid sessionId: ${e}`);if(t!==null){let c=Ee(t).trim();if(!c)throw Error("tag must be non-empty (use null to clear)");t=c}let o=n({type:"tag",tag:t??"",sessionId:e})+`
27
+ `;await T(e,o,a,E(s))}async function F(e,t={},a){if(!j(e))throw Error(`Invalid sessionId: ${e}`);let s=E(a);for(let o of await ne(t,s)){if(d()&&s!==void 0){let u=At(o,s.isKeySegment);if(u!==void 0){if(await ee(u,e,s))return;continue}}let c=g(o,`${e}.jsonl`),f;try{({size:f}=await Z(c))}catch(u){let p=r(u);if(p==="ENOENT"||p==="ENOTDIR")continue;throw u}if(f===0)continue;await L(c,{force:!0}),await L(g(o,e),{recursive:!0,force:!0});return}throw Error(t.dir?`Session ${e} not found in project directory for ${t.dir}`:`Session ${e} not found in any project directory`)}async function ee(e,t,a){let{backend:s,transcriptKey:o}=a,c=o(e,t),f=await s.statMeta(c);if(!f.ok){if(f.error.code==="NotFound")return!1;throw Error("Session delete: transcript unreadable via storage",{cause:f.error})}if((f.value.storedBytes??f.value.size)===0)return!1;for(let p of["transcript","sidecar"]){let m=await s.deleteScope({namespace:p,projectKey:e,sessionId:t});if(!m.ok)throw Error("Session delete: session directory not deletable via storage",{cause:m.error})}let u=await s.delete(c);if(!u.ok)throw Error("Session delete: transcript not deletable via storage",{cause:u.error});return!0}async function ne(e,t){if(e.dir){let s=await zt(e.dir,Kt(t,d())),o=await O(s,t),c;try{c=await Ct(s)}catch{c=[]}for(let f of c){if(f===s)continue;o.push(...await O(f,t))}return o}let a=ae();if(d()&&t!==void 0){let s=await N(t);if(s===void 0)return[];if(s.laterPageFailed)throw Error("Session delete: project listing incomplete via storage");return s.names.map((o)=>g(a,o))}try{return(await x(a,{withFileTypes:!0})).filter((o)=>o.isDirectory()||o.isSymbolicLink()).map((o)=>g(a,o.name))}catch{return[]}}async function O(e,t){let a=y(t);if(a===void 0||!a.hoverRestOn)return rt(e);let s=await rt(e,a),o=nt(e),c=process.platform==="win32",f=[];for(let u of s)if(u===o||await Rt(u,e,c,a))f.push(u);return f}async function N(e){let t=[],a,s=0;try{do{let o=await e.backend.listEntries({namespace:"transcript"},{skipScopeStats:!0,...a!==void 0&&{cursor:a}});if(!o.ok)return s===0?void 0:{names:t,laterPageFailed:!0};for(let c of o.value.items){let f=Gt(c,e.isKeySegment);if(f!==void 0)t.push(f)}a=o.value.cursor}while(a&&++s<Q);return{names:t,laterPageFailed:Boolean(a)}}catch{return s===0&&t.length===0?void 0:{names:t,laterPageFailed:!0}}}async function T(e,t,a,s){let o=`${e}.jsonl`;if(a.dir){let u=await zt(a.dir,Kt(s,d()));for(let m of await rt(u,y(s)))if(await S(g(m,o),t,b(m,e,s)))return;let p;try{p=await Ct(u)}catch{p=[]}for(let m of p){if(m===u)continue;for(let h of await rt(m,y(s)))if(await S(g(h,o),t,b(h,e,s)))return}throw Error(`Session ${e} not found in project directory for ${a.dir}`)}let c=ae();if(d()&&s!==void 0){let u=await N(s);if(u===void 0)throw new l(`Session ${e} not found (no projects directory)`,"Session not found (no projects directory)");let{names:p}=u;for(let m of p){let h=g(c,m);if(await S(g(h,o),t,b(h,e,s)))return}throw new l(`Session ${e} not found in any project directory`,"Session not found in any project directory")}let f;try{f=await x(c)}catch{throw Error(`Session ${e} not found (no projects directory)`)}for(let u of f)if(await S(g(c,u,o),t))return;throw Error(`Session ${e} not found in any project directory`)}async function S(e,t,a){if(d()&&a!==void 0)return re(a,t);let s;try{s=await z(e,_.O_WRONLY|_.O_APPEND)}catch(o){let c=r(o);if(c==="ENOENT"||c==="ENOTDIR")return!1;throw o}try{let{size:o}=await s.stat();if(o===0)return!1;let c=process.platform==="win32"?o:void 0,f=Buffer.from(t,"utf8"),u=0;while(u<f.length){let{bytesWritten:p}=await s.write(f,u,f.length-u,c);if(p<=0)throw new l(`tryAppend: short write to ${e} stalled with ${f.length-u} bytes remaining`,"tryAppend: zero-progress short write");if(u+=p,c!==void 0)c+=p}return!0}finally{await s.close()}}async function re({backend:e,key:t},a){let s=await e.append(t,[{data:a}],{precondition:{type:"ifExists",nonEmpty:!0}});if(!s.ok){if(s.error.code==="NotFound")return!1;throw Error("Session append: transcript not writable via storage",{cause:s.error})}return!0}function b(e,t,a){if(!d()||a===void 0)return;let s=At(e,a.isKeySegment);return s===void 0?void 0:{backend:a.backend,key:a.transcriptKey(s,t)}}async function er(e,t,a){if(a?.sessionStore)return te(a.sessionStore,e,t,a.dir);return K(e,t,a)}async function nr(e,t,a){if(a?.sessionStore)return se(a.sessionStore,e,t,a.dir);return A(e,t,a)}async function rr(e,t){if(!j(e))throw new l(`Invalid sessionId: ${e}`,"deleteSession: invalid sessionId (must be a UUID)");if(t?.sessionStore){if(!t.sessionStore.delete)return;let a=le(t.dir);await t.sessionStore.delete({projectKey:a,sessionId:e});return}return F(e,t)}async function te(e,t,a,s){if(!j(t))throw new l(`Invalid sessionId: ${t}`,"renameSession: invalid sessionId (must be a UUID)");if(!a.trim())throw Error("title must be non-empty");let o=le(s);await e.append({projectKey:o,sessionId:t},[{type:"custom-title",customTitle:a.trim(),sessionId:t,uuid:D(),timestamp:new Date().toISOString()}])}async function se(e,t,a,s){if(!j(t))throw new l(`Invalid sessionId: ${t}`,"tagSession: invalid sessionId (must be a UUID)");if(a!==null){let c=Ee(a).trim();if(!c)throw Error("tag must be non-empty (use null to clear)");a=c}let o=le(s);await e.append({projectKey:o,sessionId:t},[{type:"tag",tag:a??"",sessionId:t,uuid:D(),timestamp:new Date().toISOString()}])}export{rr as deleteSession,er as renameSession,nr as tagSession};