conformtools 0.6.12 → 0.6.13

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 (66) hide show
  1. package/README.md +13 -0
  2. package/dist/{account-IUWNSDG5.js → account-F54SG45Q.js} +1 -1
  3. package/dist/agent-hook-setup-RTQT5JEN.js +3 -0
  4. package/dist/{analysis-engine-M7W32RRC.js → analysis-engine-UWIK7AYB.js} +1 -1
  5. package/dist/{bridge-6NCHJWE6.js → bridge-PWYOJ7E7.js} +1 -1
  6. package/dist/{chunk-UUXHJNQA.js → chunk-4BTTR6U3.js} +1 -1
  7. package/dist/{chunk-NXJZXXC2.js → chunk-4VFDGL4E.js} +1 -1
  8. package/dist/{chunk-THVX57I3.js → chunk-6WLSIH2N.js} +1 -1
  9. package/dist/{chunk-P3XI63Q2.js → chunk-7W5AFZYX.js} +1 -1
  10. package/dist/chunk-B54TEGMG.js +5 -0
  11. package/dist/chunk-BTS3DFPD.js +7 -0
  12. package/dist/chunk-BYMCZJBQ.js +3 -0
  13. package/dist/{chunk-64X5DLH5.js → chunk-EP4L2BWV.js} +1 -1
  14. package/dist/chunk-ERUN634Q.js +6 -0
  15. package/dist/{chunk-OMPYIH6F.js → chunk-G3HBKJ5L.js} +1 -1
  16. package/dist/{chunk-B77ADB26.js → chunk-H4BU5WA6.js} +1 -1
  17. package/dist/{chunk-SJ56EEFP.js → chunk-I2Y2P5NH.js} +2 -2
  18. package/dist/{chunk-2CY2OOOJ.js → chunk-J43UCJ6G.js} +1 -1
  19. package/dist/chunk-L3HRAIDR.js +8 -0
  20. package/dist/{chunk-LYM757KG.js → chunk-LKQTE6T5.js} +66 -66
  21. package/dist/{chunk-QTA36RVO.js → chunk-LRGA6QJQ.js} +232 -220
  22. package/dist/{chunk-F4PHKOAS.js → chunk-LZRCXSUJ.js} +1 -1
  23. package/dist/chunk-NZLL44HU.js +3 -0
  24. package/dist/chunk-OD445COC.js +7 -0
  25. package/dist/chunk-XI6XF7FQ.js +3 -0
  26. package/dist/{chunk-DFQWQ3EA.js → chunk-Y455Y6V4.js} +1 -1
  27. package/dist/{claude-setup-REU4AOKX.js → claude-setup-NGZ5NDYH.js} +1 -1
  28. package/dist/cli.js +9 -9
  29. package/dist/framing-P5RGN5V3.js +3 -0
  30. package/dist/gfx-worker.js +1 -1
  31. package/dist/{h264-5OGRVYUF.js → h264-JI62TU4W.js} +1 -1
  32. package/dist/{h264-mxf-FTHNCK4B.js → h264-mxf-J2QPZO4U.js} +1 -1
  33. package/dist/hook.js +3 -0
  34. package/dist/host-relink-76CFY32O.js +10 -0
  35. package/dist/hosted-L26AGRIY.js +3 -0
  36. package/dist/hosts-TBHEPV6A.js +3 -0
  37. package/dist/http.js +2 -2
  38. package/dist/{inspect-BJYIDVDN.js → inspect-U656APGR.js} +1 -1
  39. package/dist/{isobmff-DN6MCHEK.js → isobmff-UISATYUR.js} +1 -1
  40. package/dist/{mc-video-TF3MD7LN.js → mc-video-LSTKUKNL.js} +1 -1
  41. package/dist/mcp.js +8 -8
  42. package/dist/{media-MJKEKCPN.js → media-XBNKYKB7.js} +1 -1
  43. package/dist/mxf-ZL57VJ3C.js +3 -0
  44. package/dist/{ops-B2OA7VXN.js → ops-ZQEQXW2N.js} +1 -1
  45. package/dist/probe-ZDX6XNRF.js +3 -0
  46. package/dist/{r3d-7OOZMPWH.js → r3d-R4TLYJVE.js} +1 -1
  47. package/dist/resolve-bridge.py +31 -2
  48. package/dist/{sequence-patch-CN4VC5W3.js → sequence-patch-C2QRIT5V.js} +1 -1
  49. package/dist/{store-4WZQF6YD.js → store-JNWELX35.js} +1 -1
  50. package/dist/timeline-JONFBIA3.js +3 -0
  51. package/package.json +5 -5
  52. package/dist/chunk-3XQI5SIV.js +0 -3
  53. package/dist/chunk-6NLB5TZ2.js +0 -7
  54. package/dist/chunk-G3SZDPDS.js +0 -3
  55. package/dist/chunk-NMH62JSC.js +0 -5
  56. package/dist/chunk-VJN4UXFJ.js +0 -8
  57. package/dist/chunk-XF3YMBI7.js +0 -3
  58. package/dist/chunk-XVRTAKDK.js +0 -6
  59. package/dist/framing-CVJM5TT3.js +0 -3
  60. package/dist/host-relink-ZP33BK53.js +0 -10
  61. package/dist/hosted-BWAYLJXR.js +0 -3
  62. package/dist/hosts-H3IKRZF2.js +0 -3
  63. package/dist/mxf-Q5723GPD.js +0 -3
  64. package/dist/probe-72QZKMCC.js +0 -3
  65. package/dist/timeline-ZP5H4YDQ.js +0 -3
  66. /package/dist/{still-SX6RJ7O6.js → still-4UR35GZH.js} +0 -0
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __conformRequire } from 'node:module'; const require = __conformRequire(import.meta.url);
3
+ import{a as Q,d as mt}from"./chunk-OD445COC.js";import{a as j}from"./chunk-PHAMF4JF.js";import{A as P,L as pt,aa as y,m as R,x as S,z as T}from"./chunk-XI6XF7FQ.js";import{createHash as qt}from"node:crypto";import{open as Zt}from"node:fs/promises";var Mt=new Uint16Array(256);for(let e=0;e<256;e++){let t=0,n=e<<8;for(let r=0;r<8;r++)(t^n)&32768?t=t<<1^4129:t=t<<1,n=n<<1;Mt[e]=t&65535}var tt=0,wt=2;var ne=Date.UTC(2020,0,1,0,0,0);function ht(e,t,n,r,o,s,i,a,g,c,u,_,p,w,d,b){let F=z(o,l.__wbindgen_export3,l.__wbindgen_export4),A=x,v=rt(i,l.__wbindgen_export3),W=x,Dt=l.udf_add_file_stream(f(e),f(t),f(n),f(r),F,A,s,v,W,a,g,c,u,_,p,w,d,b);return M(Dt)}function oe(e,t,n,r){let o,s;try{let p=l.__wbindgen_add_to_stack_pointer(-16),w=z(e,l.__wbindgen_export3,l.__wbindgen_export4),d=x,b=z(t,l.__wbindgen_export3,l.__wbindgen_export4),F=x,A=z(n,l.__wbindgen_export3,l.__wbindgen_export4),v=x;l.udf_build_layout(p,w,d,b,F,A,v,r);var i=h().getInt32(p+0,!0),a=h().getInt32(p+4,!0),g=h().getInt32(p+8,!0),c=h().getInt32(p+12,!0),u=i,_=a;if(c)throw u=0,_=0,M(g);return o=u,s=_,C(u,_)}finally{l.__wbindgen_add_to_stack_pointer(16),l.__wbindgen_export5(o,s,1)}}function xt(e,t,n,r,o,s,i){let a=z(o,l.__wbindgen_export3,l.__wbindgen_export4),g=x,c=rt(i,l.__wbindgen_export3),u=x,_=l.udf_fill_sparse_stream(f(e),f(t),f(n),f(r),a,g,s,c,u);return M(_)}function ie(){let e,t;try{let o=l.__wbindgen_add_to_stack_pointer(-16);l.udf_last_panic(o);var n=h().getInt32(o+0,!0),r=h().getInt32(o+4,!0);return e=n,t=r,C(n,r)}finally{l.__wbindgen_add_to_stack_pointer(16),l.__wbindgen_export5(e,t,1)}}function St(e,t){let n=l.udf_parse_stream(f(e),f(t));return M(n)}function se(e){let t,n;try{let s=l.__wbindgen_add_to_stack_pointer(-16),i=rt(e,l.__wbindgen_export3),a=x;l.udf_read_conform_iuvd(s,i,a);var r=h().getInt32(s+0,!0),o=h().getInt32(s+4,!0);return t=r,n=o,C(r,o)}finally{l.__wbindgen_add_to_stack_pointer(16),l.__wbindgen_export5(t,n,1)}}function Lt(){return{__proto__:null,"./udf_bg.js":{__proto__:null,__wbg___wbindgen_is_function_acc5528be2b923f2:function(t){return typeof m(t)=="function"},__wbg___wbindgen_is_undefined_721f8decd50c87a3:function(t){return m(t)===void 0},__wbg___wbindgen_number_get_1cc01dd708740256:function(t,n){let r=m(n),o=typeof r=="number"?r:void 0;h().setFloat64(t+8,O(o)?0:o,!0),h().setInt32(t+0,!O(o),!0)},__wbg___wbindgen_throw_ea4887a5f8f9a9db:function(t,n){throw new Error(C(t,n))},__wbg__wbg_cb_unref_33c39e13d73b25f6:function(t){m(t)._wbg_cb_unref()},__wbg_call_0e855b388e315e17:function(){return et(function(t,n,r,o){let s=m(t).call(m(n),m(r),m(o));return f(s)},arguments)},__wbg_call_5575218572ead796:function(){return et(function(t,n,r){let o=m(t).call(m(n),m(r));return f(o)},arguments)},__wbg_call_8e98ed2f3c86c4b5:function(){return et(function(t,n){let r=m(t).call(m(n));return f(r)},arguments)},__wbg_error_2b5d73c4c4804cfd:function(t,n){console.error(C(t,n))},__wbg_length_589238bdcf171f0e:function(t){return m(t).length},__wbg_new_81880fb5002cb255:function(t){let n=new Uint8Array(m(t));return f(n)},__wbg_new_from_slice_543b875b27789a8f:function(t,n){let r=new Uint8Array(yt(t,n));return f(r)},__wbg_new_no_args_2d7333de60de5ac7:function(t,n){let r=new Function(C(t,n));return f(r)},__wbg_new_typed_00a409eb4ec4f2d9:function(t,n){try{var r={a:t,b:n},o=(i,a)=>{let g=r.a;r.a=0;try{return $t(g,r.b,i,a)}finally{r.a=g}};let s=new Promise(o);return f(s)}finally{r.a=0}},__wbg_prototypesetcall_d721637c7ca66eb8:function(t,n,r){Uint8Array.prototype.set.call(yt(t,n),m(r))},__wbg_queueMicrotask_1c9b3800e321a967:function(t){let n=m(t).queueMicrotask;return f(n)},__wbg_queueMicrotask_311744e534a929a3:function(t){queueMicrotask(m(t))},__wbg_resolve_d82363d90af6928a:function(t){let n=Promise.resolve(m(t));return f(n)},__wbg_static_accessor_GLOBAL_THIS_2fee5048bcca5938:function(){let t=typeof globalThis>"u"?null:globalThis;return O(t)?0:f(t)},__wbg_static_accessor_GLOBAL_ce44e66a4935da8c:function(){let t=typeof global>"u"?null:global;return O(t)?0:f(t)},__wbg_static_accessor_SELF_44f6e0cb5e67cdad:function(){let t=typeof self>"u"?null:self;return O(t)?0:f(t)},__wbg_static_accessor_WINDOW_168f178805d978fe:function(){let t=typeof window>"u"?null:window;return O(t)?0:f(t)},__wbg_then_05edfc8a4fea5106:function(t,n,r){let o=m(t).then(m(n),m(r));return f(o)},__wbg_then_591b6b3a75ee817a:function(t,n){let r=m(t).then(m(n));return f(r)},__wbindgen_cast_0000000000000001:function(t,n){let r=zt(t,n,jt);return f(r)},__wbindgen_cast_0000000000000002:function(t){return f(t)},__wbindgen_cast_0000000000000003:function(t,n){let r=C(t,n);return f(r)},__wbindgen_object_clone_ref:function(t){let n=m(t);return f(n)},__wbindgen_object_drop_ref:function(t){M(t)}}}}function jt(e,t,n){try{let s=l.__wbindgen_add_to_stack_pointer(-16);l.__wasm_bindgen_func_elem_252(s,e,t,f(n));var r=h().getInt32(s+0,!0),o=h().getInt32(s+4,!0);if(o)throw M(r)}finally{l.__wbindgen_add_to_stack_pointer(16)}}function $t(e,t,n,r){l.__wasm_bindgen_func_elem_266(e,t,f(n),f(r))}function f(e){N===E.length&&E.push(E.length+1);let t=N;return N=E[t],E[t]=e,t}var bt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>l.__wbindgen_export2(e.a,e.b));function Nt(e){e<1028||(E[e]=N,N=e)}function yt(e,t){return e=e>>>0,D().subarray(e/1,e/1+t)}var U=null;function h(){return(U===null||U.buffer.detached===!0||U.buffer.detached===void 0&&U.buffer!==l.memory.buffer)&&(U=new DataView(l.memory.buffer)),U}function C(e,t){return Wt(e>>>0,t)}var $=null;function D(){return($===null||$.byteLength===0)&&($=new Uint8Array(l.memory.buffer)),$}function m(e){return E[e]}function et(e,t){try{return e.apply(this,t)}catch(n){l.__wbindgen_export(f(n))}}var E=new Array(1024).fill(void 0);E.push(void 0,null,!0,!1);var N=E.length;function O(e){return e==null}function zt(e,t,n){let r={a:e,b:t,cnt:1},o=(...s)=>{r.cnt++;let i=r.a;r.a=0;try{return n(i,r.b,...s)}finally{r.a=i,o._wbg_cb_unref()}};return o._wbg_cb_unref=()=>{--r.cnt===0&&(l.__wbindgen_export2(r.a,r.b),r.a=0,bt.unregister(r))},bt.register(o,r,r),o}function rt(e,t){let n=t(e.length*1,1)>>>0;return D().set(e,n/1),x=e.length,n}function z(e,t,n){if(n===void 0){let a=B.encode(e),g=t(a.length,1)>>>0;return D().subarray(g,g+a.length).set(a),x=a.length,g}let r=e.length,o=t(r,1)>>>0,s=D(),i=0;for(;i<r;i++){let a=e.charCodeAt(i);if(a>127)break;s[o+i]=a}if(i!==r){i!==0&&(e=e.slice(i)),o=n(o,r,r=i+e.length*3,1)>>>0;let a=D().subarray(o+i,o+r),g=B.encodeInto(e,a);i+=g.written,o=n(o,r,i,1)>>>0}return x=i,o}function M(e){let t=m(e);return Nt(e),t}var H=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});H.decode();var Bt=2146435072,nt=0;function Wt(e,t){return nt+=t,nt>=Bt&&(H=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),H.decode(),nt=t),H.decode(D().subarray(e,e+t))}var B=new TextEncoder;"encodeInto"in B||(B.encodeInto=function(e,t){let n=B.encode(e);return t.set(n),{read:e.length,written:n.length}});var x=0,Ht,Gt,l;function Jt(e,t){return Gt=e,l=e.exports,Ht=t,U=null,$=null,l.__wbindgen_start(),l}async function Vt(e,t){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(o){if(e.ok&&n(e.type)&&e.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",o);else throw o}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}else{let r=await WebAssembly.instantiate(e,t);return r instanceof WebAssembly.Instance?{instance:r,module:e}:r}function n(r){switch(r){case"basic":case"cors":case"default":return!0}return!1}}async function G(e){if(l!==void 0)return l;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),e===void 0&&(e=new URL("udf_bg.wasm",import.meta.url));let t=Lt();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await Vt(await e,t);return Jt(n,r)}var ot=null;function Xt(e){return ot||(ot=(async()=>{if(e!==void 0)return G(e);if(typeof process<"u"&&process.versions?.node){let n="node:fs/promises",{readFile:r}=await import(n),o=await r(new URL("./wasm/udf_bg.wasm",import.meta.url));return G({module_or_path:o})}let{default:t}=await import("./udf_bg-B37GKRIH.js");return G({module_or_path:t})})()),ot}function J(){return Xt()}function V(e){return(t,n)=>e.read(t,n)}function it(e){return(t,n)=>e.write(t,n)}function X(e){return()=>e.getSize()}function st(e){return t=>e.setSize?e.setSize(t):Promise.resolve()}async function It(e){await J();let t=JSON.parse(await St(V(e),X(e)));if(t.error)throw new Error(t.error);let n=null;if(t.iuvdPayload)try{n=JSON.parse(t.iuvdPayload)}catch{}let r=null,o=t.files.find(s=>s.name===".i2o-manifest.json");if(o&&o.extents.length>0&&o.extents[0].type===tt){let s=o.extents[0].position,i=await e.read((t.partitionStartSector+s)*2048,o.totalSize);try{r=JSON.parse(new TextDecoder().decode(i))}catch{}}return{totalSectors:t.totalSectors,partitionStartSector:t.partitionStartSector,partitionLength:t.partitionLength,volumeName:t.volumeName,files:t.files,manifest:r,iuvdPayload:n,rootIcbSector:t.rootIcbSector,rootDataSector:t.rootDataSector,rootDataLength:t.rootDataLength,rootDataSectors:t.rootDataSectors,vdsStartSector:t.vdsStartSector,partitionDescVdsSector:t.partitionDescVdsSector}}function me(e){let t=[],n=0;for(let r of e.extents)r.type===wt&&t.push({offset:n,length:r.length}),n+=r.length;return t}function At(e){let t=[],n=0;for(let r of e.extents)r.type===tt&&t.push({offset:n,length:r.length,imageSector:r.position}),n+=r.length;return t}async function we(e,t,n,r,o){return await J(),await xt(V(e),it(e),X(e),st(e),n,r,o),It(e)}async function be(e,t,n,r,o,s=0){await J();let i=new Date,a=!!(o&&o.length>0);return await ht(V(e),it(e),X(e),st(e),n,r,a?o:new Uint8Array(0),a,s,i.getFullYear(),i.getMonth()+1,i.getDate(),i.getHours(),i.getMinutes(),i.getSeconds(),-i.getTimezoneOffset()),It(e)}var Y=1<<20,k=5*Y,Et=5*1024*Y,at=1e4,ct=8*Y,Kt=2048;function Ae(e,t,n=Math.max(16*Y,Math.ceil(e/(at-500)))){let r=[...t].filter(c=>c.len>0).sort((c,u)=>c.at-u.at),o=[];for(let c of r){let u=o[o.length-1];u&&c.at<u.at+u.len||(u&&u.at+u.len===c.at&&u.key===c.key&&u.offset+u.len===c.offset?u.len+=c.len:o.push({...c}))}let s=[],i=0;for(let c of o.filter(u=>u.len>=k))c.at>i&&s.push({at:i,len:c.at-i}),s.push({at:c.at,len:c.len,copy:c}),i=c.at+c.len;i<e&&s.push({at:i,len:e-i});let a=c=>c.reduce((u,_)=>{let p=u[u.length-1];return p&&!p.copy&&!_.copy?p.len+=_.len:u.push({..._}),u},[]);for(let c=!0;c;){c=!1,s=a(s);for(let u=0;u<s.length-1;u++){let _=s[u];if(_.len>=k)continue;let p=k-_.len,w=s[u+1],d=s[u-1];if(_.copy){delete _.copy,c=!0;break}w?.copy&&w.len-p>=k?(_.len+=p,w.at+=p,w.len-=p,w.copy={...w.copy,at:w.at,len:w.len,offset:w.copy.offset+p}):d?.copy&&d.len-p>=k?(d.len-=p,d.copy={...d.copy,len:d.len},_.at-=p,_.len+=p):w?.copy?delete w.copy:d?.copy&&delete d.copy,c=!0;break}}let g=[];for(let c of s){let u=c.copy?Math.min(Et,Math.max(n,k)):n;for(let _=c.at,p=c.at+c.len;_<p;){let w=Math.min(u,p-_);p-(_+w)>0&&p-(_+w)<k&&(w=p-_<=Et?p-_:w-k),g.push(c.copy?{kind:"copy",at:_,len:w,key:c.copy.key,offset:c.copy.offset+(_-c.at)}:{kind:"upload",at:_,len:w}),_+=w}}if(g.length>at)throw new Error(`the image needs ${g.length} pieces (S3 allows ${at})`);return g}function Ee(e,t,n,r){let o=[...r].sort((a,g)=>a.offset-g.offset),s=[],i=0;for(let a of o){let g=Math.min(a.offset,t);g>i&&s.push({at:i,len:g-i,key:e,offset:i}),i=Math.max(i,a.offset+a.length)}return i<Math.min(t,n)&&s.push({at:i,len:Math.min(t,n)-i,key:e,offset:i}),s}async function ve(e,t,n,r,o){let s=[];for(let i of t.files)for(let a of At(i)){let g=(t.partitionStartSector+a.imageSector)*Kt;for(let c=a.offset;c<a.offset+a.length;){let u=Math.min(a.offset+a.length,(Math.floor(c/ct)+1)*ct),_=g+(c-a.offset);s.push(o?.(_,u-c)??[qt("sha256").update(await e.read(_,u-c)).digest("hex"),_,u-c]),r?.(u-c),c=u}}return{v:1,block:ct,size:n,blocks:s}}function Te(e,t){let n=new Map;for(let o of t)for(let[s,i,a]of o.index.blocks)n.set(`${s}:${a}`,{key:o.key,offset:i});let r=[];for(let[o,s,i]of e.blocks){let a=n.get(`${o}:${i}`);a&&r.push({at:s,len:i,key:a.key,offset:a.offset})}return r}var vt=(e,t)=>`${Q().supabaseUrl}/functions/v1/${e}${t}`;async function lt(e,t,n={}){let r=await mt();if(!r)throw new Error("not signed in to conform.tools \u2014 run account_login");let o=await fetch(vt(e,t),{method:n.method??(n.body?"POST":"GET"),headers:{authorization:`Bearer ${r}`,apikey:Q().anonKey,...n.body?{"content-type":"application/json"}:{}},...n.body?{body:JSON.stringify(n.body)}:{},signal:AbortSignal.timeout(2e4)}),s=await o.text();if(!o.ok){let i=s;try{let a=JSON.parse(s);i=a.error?.message??a.message??a.error??s}catch{}throw o.status===404&&/Requested function was not found/i.test(String(i))?new Error(`${e} isn't deployed on ${new URL(vt(e,t)).host}: this server doesn't have that feature yet (an older server, or a staging/production mismatch)`):new Error(`${n.method??"GET"} ${t}: ${o.status} ${i}`)}return s?JSON.parse(s):{}}function Pe(e,t="org"){let n=`/v1/sessions/${e}/storage/multipart`,r=(o,s,i)=>lt("v1-sessions",o,{body:s,method:i});return{start:async o=>String((await r(`${n}/start`,{key:o,content_type:"application/x-iso9660-image"})).upload_id),partUrls:async(o,s,i,a)=>(await r(`${n}/${s}/part-urls`,{key:o,first_part:i,count:a})).parts,copyPart:async(o,s,i,a)=>String((await r(`${n}/${s}/copy-part`,{key:o,part_number:i,source_ref:{scheme:t,bucket:"i2o",key:a.key},byte_range:{offset:a.offset,length:a.length}})).etag),complete:async(o,s,i)=>{await r(`${n}/${s}/complete`,{key:o,parts:i})},abort:async(o,s)=>{await r(`${n}/${encodeURIComponent(s)}?key=${encodeURIComponent(o)}`,void 0,"DELETE")},readUrl:async o=>String((await r(`/v1/sessions/${e}/download-url`,{storage_path:o})).download_url)}}async function ut(e,t,n=4){for(let r=1;;r++)try{return await t()}catch(o){if(r>=n)throw new Error(`${e} failed after ${n} tries: ${o instanceof Error?o.message:o}`);await new Promise(s=>setTimeout(s,500*2**r))}}async function ke(e,t,n,r,o={}){let s=o.fetchFn??fetch,i=await e.start(t),a=n.reduce((d,b)=>d+b.len,0),g=new Array(n.length),c=0,u=0,_=new Map,p=async d=>(_.has(d)||(await e.partUrls(t,i,d+1,Math.min(100,n.length-d))).forEach((F,A)=>_.set(d+A,F)),_.get(d)),w=async d=>{let b=n[d];if(b.kind==="copy")g[d]=await ut(`copy piece ${d+1}`,()=>e.copyPart(t,i,d+1,{key:b.key,offset:b.offset,length:b.len}));else{let F=await r(b.at,b.len);g[d]=await ut(`upload piece ${d+1}`,async()=>{let A=await p(d),v=await s(A.upload_url,{method:A.method,headers:A.headers,body:F,signal:o.signal});if(!v.ok)throw _.delete(d),new Error(`${v.status} ${(await v.text()).slice(0,200)}`);let W=v.headers.get("etag");if(!W)throw new Error("the bucket returned no ETag (expose it in the bucket's CORS / response headers)");return W})}c+=b.len,o.onProgress?.(c,a)};try{await Promise.all(Array.from({length:Math.min(6,n.length)},async()=>{for(;u<n.length;)o.signal?.throwIfAborted(),await w(u++)})),await ut("complete",()=>e.complete(t,i,g.map((d,b)=>({part_number:b+1,etag:d}))))}catch(d){throw await e.abort(t,i).catch(()=>{}),d}return{uploaded:n.filter(d=>d.kind==="upload").reduce((d,b)=>d+b.len,0),copied:n.filter(d=>d.kind==="copy").reduce((d,b)=>d+b.len,0),pieces:n.length}}function Fe(e){let t=Zt(e,"r");return{read:async(n,r)=>{let o=new Uint8Array(r);return await(await t).read(o,0,r,n),o},close:async()=>{await(await t).close()}}}var gt="local",Pt=/^[A-Za-z0-9_-]{1,64}$/,I=e=>{if(!Pt.test(e))throw new j("invalid_args",`bad project_id '${e}'`);return y(R(),"projects",e)},dt=(e,t={})=>lt("v1-projects",e,t),kt=e=>Number(/: (\d{3}) /.exec(String(e?.message))?.[1]??0);async function Ft(e){let t="",n={base:null,by:null};try{t=await S(y(I(e),"CONTEXT.md"))}catch{}try{n=JSON.parse(await S(y(I(e),"context.json")))}catch{}return{text:t,meta:n}}async function _t(e,t,n){await P(I(e)),await T(y(I(e),"CONTEXT.md"),t),await T(y(I(e),"context.json"),JSON.stringify(n))}var ft=async(e,t)=>(await _t(e,t.context,{base:t.context_updated_at,by:t.context_updated_by_name??null}),{text:t.context,updated_at:t.context_updated_at,updated_by:t.context_updated_by_name??null});async function Me(e){I(e);let t=await Ft(e);if(e===gt)return{text:t.text,updated_at:null,updated_by:null};if(t.meta.pending)try{return await Tt(e,t.text,t.meta.base)}catch(n){if(!(n instanceof j&&n.code==="context_conflict"))return{text:t.text,updated_at:t.meta.base,updated_by:t.meta.by,offline:!0,pending:!0};let r=n.data?.current??{context:"",context_updated_at:null},o=`${r.context.trimEnd()}
4
+
5
+ ## Saved offline on this machine (merge into the notes above)
6
+
7
+ ${t.text.trim()}
8
+ `;return await Tt(e,o,r.context_updated_at).catch(()=>ft(e,r))}try{return await ft(e,(await dt(`/v1/projects/${e}`)).project)}catch(n){if(kt(n))throw n;return{text:t.text,updated_at:t.meta.base,updated_by:t.meta.by,offline:!0}}}async function Tt(e,t,n){if(I(e),e===gt)return await _t(e,t,{base:null,by:null}),{text:t,updated_at:null,updated_by:null};let r=await Ft(e),o=n===void 0?r.meta.base:n;try{return await ft(e,(await dt(`/v1/projects/${e}`,{method:"PATCH",body:{context:t,context_base:o}})).project)}catch(s){let i=kt(s);if(i===409){let a=(await dt(`/v1/projects/${e}`)).project;throw new j("context_conflict",`someone saved this project's context${a.context_updated_by_name?` (${a.context_updated_by_name})`:""} since it was read; read it again and save on top of theirs`,{current:a})}if(i)throw s;return await _t(e,t,{...r.meta,base:o,pending:!0}),{text:t,updated_at:o,updated_by:r.meta.by,offline:!0,pending:!0}}}var Ut=()=>y(R(),"current-project.json");async function Ct(){try{let e=JSON.parse(await S(Ut()));return e?.id?e:null}catch{return null}}async function Le(e){await P(R()),await T(Ut(),JSON.stringify(e&&e.id!==gt?e:{}))}async function je(e,t){if(!Pt.test(t))throw new j("invalid_args",`bad session_id '${t}'`);let n=y(I(e),"sessions.json"),r=[];try{r=JSON.parse(await S(n))}catch{}await P(I(e)),await T(n,JSON.stringify([...r.filter(o=>o!==t),t]))}async function $e(e){let t=new Set,n=[];try{n=JSON.parse(await S(y(I(e),"sessions.json")))}catch{}for(let r of n.toReversed())t.add(r);for(let r of await Rt().catch(()=>[]))r.project_id===e&&t.add(r.id);return[...t]}var Qt=R(),L=y(Qt,"sessions"),q=new Map,te=/^[0-9a-f]{8}$/;function K(e,t){if(!te.test(e))throw new Error(`not a session id: ${JSON.stringify(e).slice(0,40)}`);if(t!==void 0&&!/^[a-z0-9_-]{1,32}$/.test(t))throw new Error(`bad session extra kind: ${t}`);return y(L,t===void 0?`${e}.json`:`${e}.${t}.json`)}function ee(){let e=new Uint8Array(4);return crypto.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}async function We(e,t,n){let r=new Date().toISOString(),o=await Ct(),s={id:ee(),source_path:t,source_format:n,created_at:r,updated_at:r,history:[],...o?{project_id:o.id}:{},session:e};return q.set(s.id,s),Z=s.id,await Ot(s),s}var Z,He=()=>Z;async function Ge(e){let t=q.get(e);if(t)return Z=e,t;try{let n=await S(K(e)),r=JSON.parse(n);return r.id=e,q.set(e,r),Z=e,r}catch{throw new Error(`unknown session_id '${e}' \u2014 call timeline_read first, or timeline_sessions to list`)}}async function Je(e,t){e.updated_at=new Date().toISOString(),e.history.push(t),q.set(e.id,e),await Ot(e)}async function Rt(){await P(L);let e=[];for await(let t of pt(L))if(!(!t.name.endsWith(".json")||t.name.split(".").length>2))try{let n=JSON.parse(await S(y(L,t.name))),{session:r,...o}=n;e.push(o)}catch{}return e.sort((t,n)=>n.updated_at.localeCompare(t.updated_at))}async function Ot(e){await P(L),await T(K(e.id),JSON.stringify(e))}async function Ve(e,t,n){await P(L),await T(K(e,t),JSON.stringify(n))}async function Xe(e,t){try{return JSON.parse(await S(K(e,t)))}catch{return null}}export{ne as a,oe as b,ie as c,se as d,J as e,It as f,me as g,At as h,we as i,be as j,ct as k,Ae as l,Ee as m,ve as n,Te as o,lt as p,Pe as q,ke as r,Fe as s,gt as t,Me as u,Tt as v,Ct as w,Le as x,je as y,$e as z,We as A,He as B,Ge as C,Je as D,Rt as E,Ve as F,Xe as G};