@warmhub/sdk-ts 0.92.0 → 0.93.0

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,8 +1,8 @@
1
- import {C as C$1,m as m$1,p,n,o,q,M as M$1,B,t,u,b,f,e,i,a as a$1,d,l,A as A$1,x as x$1,O,N as N$1,j,c,k,g,h}from'./chunk-7BY5T6XV.js';import {TRPCClientError,createTRPCProxyClient,splitLink,httpBatchLink,httpLink}from'@trpc/client';import {observable}from'@trpc/server/observable';var qt=new Set(["arc","bond","pair","set","list"]);function H(n,e){let t=Ke(n,e,"add");return {operation:"add",kind:"collection",name:t.name,type:t.type,members:t.members,...n.skipExisting===true?{skipExisting:true}:{}}}function ee(n,e){let t=Ke(n,e,"revise");if(!t.name)throw new Error(`${e}: collection revise requires a target name`);return {operation:"revise",kind:"collection",name:t.name,type:t.type,members:t.members,...typeof n.expectedVersion=="number"?{expectedVersion:n.expectedVersion}:{},...typeof n.leaseId=="string"&&n.leaseId.length>0?{leaseId:n.leaseId}:{}}}function Ke(n,e,t){let r=B({operation:t,kind:"collection",name:typeof n.name=="string"?n.name:void 0,type:typeof n.type=="string"?n.type:void 0,members:Array.isArray(n.members)?n.members:void 0},0);if(r.length>0)throw new Error(`${e}: ${r.map(s=>s.message).join("; ")}`);let i=Ut(n.type);if(!i)throw new Error(`${e}: collection ${t} requires 'type'. Use one of: arc, bond, set, list`);if(!Array.isArray(n.members))throw new Error(`${e}: collection ${t} requires a 'members' array`);let o=Vt(n.name);if(!o)throw new Error(`${e}: collection ${t} name must be a non-empty string`);return Bt(n,e,t),{name:o,type:i,members:n.members}}function Bt(n,e,t){let r=["about","aboutWref","shapeWref","data",...t==="revise"?["skipExisting"]:[]].filter(i=>n[i]!==void 0);if(r.length>0)throw new Error(`${e}: collection ${t} does not support ${r.map(i=>`'${i}'`).join(", ")}`)}function Ut(n){if(typeof n!="string")return;let e=n.trim();if(qt.has(e))return e}function Vt(n){if(typeof n=="string"&&!(n.length===0||n.trim()!==n))return n}function E(n){if(n.expectedVersion!==void 0&&n.operation!=="revise"&&n.operation!=="retract"&&n.operation!=="reaffirm")throw new Error("expectedVersion is only valid on revise, retract, or reaffirm operations \u2014 set an explicit operation discriminator");if(n.operation==="retract")return {operation:"retract",name:n.name,...n.kind?{kind:n.kind}:{},...n.reason?{reason:n.reason}:{},...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.leaseId?{leaseId:n.leaseId}:{}};if(n.operation==="reaffirm")return {operation:"reaffirm",name:n.name,...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.kind?{kind:n.kind}:{},...n.add?{add:n.add}:{},...n.remove?{remove:n.remove}:{},...n.leaseId?{leaseId:n.leaseId}:{}};if(n.operation==="rename")return {operation:"rename",name:n.name,newName:n.newName,...n.kind?{kind:n.kind}:{}};if(n.operation==="revise"){let r=n.name??n.wref;if(!r)throw new Error("revise operation requires a target");let i=l({kind:n.kind,name:r});if(Object.hasOwn(n,"active"))throw new Error(`${i} revise operation no longer supports 'active' \u2014 use retract('${r}') instead`);if(i!=="assertion"&&n.affirmedTargets!==void 0)throw new Error(`${i} revise operation does not support 'affirmedTargets' \u2014 it applies only to assertions; set kind: 'assertion' explicitly`);if(i==="collection")return ee(n,"commit.apply");if(n.data===void 0)throw new Error(`${i} revise operation requires 'data'`);return i==="assertion"?{operation:"revise",kind:"assertion",name:r,data:n.data,...n.affirmedTargets?{affirmedTargets:n.affirmedTargets}:{},...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.leaseId?{leaseId:n.leaseId}:{}}:{operation:"revise",kind:i,name:r,data:n.data,...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.leaseId?{leaseId:n.leaseId}:{}}}let e=l(n),t="skipExisting"in n?n.skipExisting:void 0;if(e!=="collection"&&("type"in n&&n.type!==void 0||"members"in n&&n.members!==void 0))throw new Error(`add operation '${n.name??""}' has collection fields but resolved kind '${e}' \u2014 collection adds require both 'type' and 'members', or set kind: 'collection'`);if(e!=="assertion"&&n.affirmedTargets!==void 0)throw new Error(`${e} add operation does not support 'affirmedTargets' \u2014 it applies only to assertions; set kind: 'assertion' explicitly`);if(e==="collection")return H({...n,skipExisting:t},"commit.apply");if(!n.name)throw new Error("add operation requires a name");if(e==="assertion"){if(!("about"in n)||n.about===void 0)throw new Error("assertion add operation requires 'about'");if(typeof n.about!="string")throw new Error(A$1);if(n.data===void 0)throw new Error("assertion add operation requires 'data'");return {operation:"add",kind:"assertion",name:n.name,about:n.about,data:n.data,...n.affirmedTargets?{affirmedTargets:n.affirmedTargets}:{},...t===true?{skipExisting:t}:{}}}if(n.data===void 0)throw new Error(`${e} add operation requires 'data'`);return {operation:"add",kind:e,name:n.name,data:n.data,...t===true?{skipExisting:t}:{}}}var Ht=1e4,Ft=4*1024*1024,be=class extends Error{code="VALIDATION_ERROR";status=400;constructor(e){super(e),this.name="WarmHubError";}};function Ce(n,e){return n.map((t,r)=>{let i;try{i=E(t);}catch(o){let s=o instanceof Error?o.message:String(o);throw new be(`Invalid operation at index ${r}: ${s}`)}return e===true&&i.operation==="add"?{...i,skipExisting:true}:i})}function Wt(n,e,t,r){return {orgName:n,repoName:e,...r?.committer!==void 0?{committer:r.committer}:{},...r?.message!==void 0?{message:r.message}:{},...r?.componentRef!==void 0?{componentRef:r.componentRef}:{},operations:Ce(t,r?.skipExisting),...r?.includeWouldBeBody!==void 0?{includeWouldBeBody:r.includeWouldBeBody}:{}}}function ze(n){return JSON.stringify(n)}function $t(n){return new TextEncoder().encode(ze(n)).byteLength}function je(n,e){return {create:async(t,r,i)=>{try{return await n().grant.create.mutate({orgName:t,repoName:r,...i})}catch(o){throw e(o)}},get:async(t,r,i)=>{try{return await n().grant.get.query({orgName:t,repoName:r,grantId:i})}catch(o){throw e(o)}},list:async(t,r,i)=>{try{return await n().grant.list.query({orgName:t,repoName:r,limit:i?.limit,cursor:i?.cursor})}catch(o){throw e(o)}},revoke:async(t,r,i,o)=>{try{return await n().grant.revoke.mutate({orgName:t,repoName:r,grantId:i,reason:o?.reason})}catch(s){throw e(s)}}}}function te(n){return {...n,createdAt:new Date(n.createdAt),updatedAt:new Date(n.updatedAt),runStartedAt:new Date(n.runStartedAt),...n.state==="complete"||n.state==="failed"?{completedAt:new Date(n.completedAt)}:{}}}function Gt(n){return {...n,expiresAt:new Date(n.expiresAt)}}function Ye(n){if(typeof n.checkpointId=="string"&&typeof n.repoSeq!="number")return {by:"id",checkpointId:n.checkpointId};if(typeof n.repoSeq=="number"&&typeof n.checkpointId!="string")return {by:"repoSeq",repoSeq:n.repoSeq};throw new TypeError("Repository checkpoint selector must contain exactly one of checkpointId or repoSeq")}function Qe(n,e){return {generate:async(t,r,i)=>{try{let o=await n().repo.checkpoint.generate.mutate({orgName:t,repoName:r,atLeastRepoSeq:i?.atLeastRepoSeq});return te(o.checkpoint)}catch(o){throw e(o)}},status:async(t,r,i)=>{try{let o=await n().repo.checkpoint.status.query({orgName:t,repoName:r,selector:Ye(i)});return te(o)}catch(o){throw e(o)}},latest:async(t,r)=>{try{let i=await n().repo.checkpoint.latest.query({orgName:t,repoName:r});return i.checkpoint?te(i.checkpoint):null}catch(i){throw e(i)}},getAccess:async(t,r,i)=>{try{let o=await n().repo.checkpoint.access.query({orgName:t,repoName:r,selector:i.checkpoint==="latest"?{by:"latest"}:Ye(i.checkpoint),artifact:i.artifact==="archive"||i.artifact==="manifest"?{kind:i.artifact}:{kind:"chunk",path:i.artifact.chunkPath}});return Gt(o)}catch(o){throw e(o)}},retry:async(t,r,i)=>{try{let o=await n().repo.checkpoint.retry.mutate({orgName:t,repoName:r,checkpointId:i});return te(o.checkpoint)}catch(o){throw e(o)}}}}function F(n,e,t){let r=O(e,t==="revise"?{allowUnsafeFieldNamePaths:N$1(e)}:void 0);return r.valid?null:`Invalid shape definition for "${n}": ${r.errors.join("; ")}`}function Kt(n,e,t){let r=n.operation===void 0||n.operation==="noop"?t?.operation??"add":n.operation,i={opIndex:e,name:n.name??"",operation:r,...n.affirmations?{affirmations:n.affirmations}:{},...n.resolvedName!==void 0?{resolvedName:n.resolvedName}:{},...n.warnings?{warnings:n.warnings}:{}};return n.status==="failed"?{...i,status:"error",errors:[{code:n.error?.code??"BACKEND",message:n.error?.message??`Operation on "${n.name}" failed`,...n.error?.details?{details:n.error.details}:{},...n.retryable!==void 0?{retryable:n.retryable}:{}}],...t?.name!==void 0?{submittedName:t.name}:{}}:{...i,status:n.status==="noop"||n.operation==="noop"?"noop":"applied",...n.version!==void 0?{version:n.version}:{},...n.dataHash!==void 0?{dataHash:n.dataHash}:{}}}var N=class{receipts=[];operations=[];statusCounts={applied:0,noop:0,error:0};get allFailed(){return this.operations.length>0&&this.statusCounts.error===this.operations.length}addChunk(e){if(e.result.schemaVersion==="operation-event-receipt/v2"){e.result.results.forEach(t=>{this.statusCounts[t.status]++,this.operations.push({...t,opIndex:e.chunkStart+t.opIndex});});return}e.result.results.forEach((t,r)=>{let i=t.opIndex??r,o=e.submittedOperations[i],s=Kt(t,e.chunkStart+i,o);this.statusCounts[s.status]++,this.operations.push(s);});}addReceipt(e){this.receipts.push(e);}completedOperations(){return this.operations.filter(e=>e.status!=="error")}toResult(e){let t=this.statusCounts.error>0;return {...e.committer!==void 0?{committer:e.committer}:{},...e.createdByEmail!==void 0?{createdByEmail:e.createdByEmail}:{},message:e.message,operationCount:this.operations.length,...e.repoSeq!==void 0?{repoSeq:e.repoSeq}:{},...t?{partial:t,statusCounts:{...this.statusCounts}}:{},operations:this.operations,receipts:this.receipts}}};var zt="003e7e6c-2f1e-53ea-9dfa-627edd04a8cc",jt=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;function Je(n){if(!jt.test(n))throw new Error("Operation-event submission ID must be a canonical UUID");let e=n.toLowerCase().replaceAll("-","");return Uint8Array.from({length:16},(t,r)=>Number.parseInt(e.slice(r*2,r*2+2),16))}function we(n,e){return (n<<e|n>>>32-e)>>>0}function Yt(n){let e=n.length*8,t=Math.ceil((n.length+9)/64)*64,r=new Uint8Array(t);r.set(n),r[n.length]=128;let i=new DataView(r.buffer);i.setUint32(t-8,Math.floor(e/4294967296)),i.setUint32(t-4,e>>>0);let o=1732584193,s=4023233417,p=2562383102,c=271733878,u=3285377520,l=new Uint32Array(80);for(let y=0;y<t;y+=64){for(let f=0;f<16;f+=1)l[f]=i.getUint32(y+f*4);for(let f=16;f<80;f+=1)l[f]=we(l[f-3]^l[f-8]^l[f-14]^l[f-16],1);let S=o,d=s,R=p,O=c,b=u;for(let f=0;f<80;f+=1){let q,B;f<20?(q=d&R|~d&O,B=1518500249):f<40?(q=d^R^O,B=1859775393):f<60?(q=d&R|d&O|R&O,B=2400959708):(q=d^R^O,B=3395469782);let Mt=we(S,5)+q+b+B+l[f]>>>0;b=O,O=R,R=we(d,30),d=S,S=Mt;}o=o+S>>>0,s=s+d>>>0,p=p+R>>>0,c=c+O>>>0,u=u+b>>>0;}let g=new Uint8Array(20),h=new DataView(g.buffer);for(let[y,S]of [o,s,p,c,u].entries())h.setUint32(y*4,S);return g}function Qt(n){let e=Array.from(n,t=>t.toString(16).padStart(2,"0")).join("").slice(0,32);return `${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}function re(){let n=globalThis.crypto?.randomUUID?.();if(!n)throw new Error("This runtime cannot mint a cryptographically secure UUID");return n.toLowerCase()}var Jt=re;function Se(n,e){if(!Number.isInteger(e)||e<0||e>2147483647)throw new Error("Stream chunk ordinal must be an integer from 0 through 2147483647");Je(n);let t=n.toLowerCase(),r=Je(zt),i=new TextEncoder().encode(`${t}:${e}`),o=Yt(Uint8Array.from([...r,...i])).slice(0,16);return o[6]=o[6]&15|80,o[8]=o[8]&63|128,Qt(o)}var ne=1e3,ie=1e4,A=class extends Error{code="PARTIAL_STREAM_SUBMISSION";completedReceipts;completedOperations;submissionId;eventRequestId;chunkOrdinal;pendingOutcome;acknowledgedOperationCount;lastAcknowledgedRepoSeq;attemptedAppendOutcome;cause;constructor(e){super(e.pendingOutcome==="unknown"?`Stream submission outcome is unknown for event request ${e.eventRequestId}. Look up its immutable receipt before retrying.`:`Stream submission stopped at event request ${e.eventRequestId} after earlier chunks committed.`),this.name="WarmHubError",this.cause=e.cause,this.completedReceipts=e.completedReceipts,this.completedOperations=e.completedOperations??[],this.submissionId=e.submissionId,this.eventRequestId=e.eventRequestId,this.chunkOrdinal=e.chunkOrdinal,this.pendingOutcome=e.pendingOutcome,this.acknowledgedOperationCount=e.acknowledgedOperationCount??e.completedReceipts.length,this.attemptedAppendOutcome=e.attemptedAppendOutcome,e.lastAcknowledgedRepoSeq!==void 0&&(this.lastAcknowledgedRepoSeq=e.lastAcknowledgedRepoSeq);}},v=class extends Error{code="STREAM_ALL_OPERATIONS_FAILED";receipts;result;operations;statusCounts;cause;constructor(e){let t=e.operations.find(r=>r.status==="error")?.errors[0];super(t?`All ${e.operationCount} stream operations failed: ${t.message}`:`All ${e.operationCount} stream operations failed.`),this.name="WarmHubError",this.cause=t,this.result=e,this.receipts=e.receipts,this.operations=e.operations,this.statusCounts=e.statusCounts??{applied:0,noop:0,error:e.operationCount};}};function Oe(n){let e="status"in n?n.status:void 0;return e==="failed"||e==="error"?"error":e==="noop"||n.operation==="noop"?"noop":"applied"}function et(n){let e={applied:0,noop:0,error:0};for(let t of n)e[Oe(t)]++;return e}var Xt={maxAttempts:3,baseDelayMs:250,maxDelayMs:8e3},Zt=10,Xe=6e4;function Ie(n){if(n===false)return false;let e={};n!==void 0&&(Number.isFinite(n.maxAttempts)&&(e.maxAttempts=n.maxAttempts),Number.isFinite(n.baseDelayMs)&&(e.baseDelayMs=n.baseDelayMs),Number.isFinite(n.maxDelayMs)&&(e.maxDelayMs=n.maxDelayMs));let t={...Xt,...e};return {maxAttempts:Math.min(Zt,Math.max(1,Math.trunc(t.maxAttempts))),baseDelayMs:Math.min(Xe,Math.max(0,Math.trunc(t.baseDelayMs))),maxDelayMs:Math.min(Xe,Math.max(0,Math.trunc(t.maxDelayMs)))}}var er=new Set(["BAD_REQUEST","METHOD_NOT_SUPPORTED","PARSE_ERROR","PAYLOAD_TOO_LARGE","PRECONDITION_FAILED","UNAUTHORIZED","UNPROCESSABLE_CONTENT","UNSUPPORTED_MEDIA_TYPE","UNAUTHENTICATED","FORBIDDEN","VALIDATION_ERROR","SHAPE_MISMATCH","RESERVED_NAME","ILLEGAL_OP_SEQUENCE","NOT_FOUND","KIND_MISMATCH","CONFLICT","ALREADY_RETRACTED","ARCHIVED","RATE_LIMITED","TOO_MANY_REQUESTS","UNRESOLVED_TOKEN"]),tr=new Set(["COMMIT_OUTCOME_UNKNOWN"]);function tt(n){if(!n||typeof n!="object")return;let e=n.code;if(typeof e=="string")return e;let t=n.data,r=t?.warmhub?.code;if(typeof r=="string")return r;let i=t?.code;if(typeof i=="string")return i}function rr(n){if(!n||typeof n!="object")return;let e=n.data?.httpStatus;if(typeof e=="number")return e;let t=n.data?.warmhub?.status;if(typeof t=="number")return t;let r=n.status;return typeof r=="number"?r:void 0}function nr(n){return n!==void 0&&n>=400&&n<500&&n!==408}function rt(n){let e=tt(n);return e!==void 0&&tr.has(e)}function W(n){if(rt(n))return false;let e=tt(n);return e!==void 0&&er.has(e)||nr(rr(n))}function Ae(n){if(rt(n)||W(n))return false;if(Ze(n))return true;if(n instanceof TypeError||n instanceof SyntaxError)return false;let e=n?.cause;return Ze(e)?true:!(e instanceof TypeError||e instanceof SyntaxError)}function Ze(n){return n instanceof TypeError&&/fetch/i.test(n.message)}function ke(n,e){let t=e.baseDelayMs*2**Math.max(0,n-1),r=Math.random()*e.baseDelayMs;return Math.min(e.maxDelayMs,t+r)}function ve(n){return new Promise(e=>setTimeout(e,n))}var $=class extends Error{code;status=400;constructor(e,t="VALIDATION_ERROR"){super(e),this.code=t,this.name="WarmHubError";}},oe=class extends Error{constructor(t){super("operation source failed");this.reason=t;}reason};async function P(n,e){let t=ar(e.chunkSize),r=e.submissionId??re(),i=e.streamId??r,o=Ie(e.retry),s=new N,p=[],c,u,l=0,g,h=0,y=d=>new A({cause:d.cause,completedReceipts:s.receipts,completedOperations:s.completedOperations(),acknowledgedOperationCount:l,lastAcknowledgedRepoSeq:g,attemptedAppendOutcome:d.pendingOutcome==="absent"?"not_applied":"unknown",submissionId:r,eventRequestId:Se(r,h),chunkOrdinal:h,pendingOutcome:d.pendingOutcome});try{for await(let d of ir(e.operations,t,e.skipExisting===!0)){let R=1,O=!1;for(;;)try{let b=await n.stream.append({allocatedTokenRanges:p,chunkOrdinal:h,orgName:e.orgName,repoName:e.repoName,streamId:i,submissionId:r,componentRef:e.componentRef,committer:e.committer,message:e.message,...e.returnRepoSeq!==void 0?{returnRepoSeq:e.returnRepoSeq}:{},operations:d.operations});s.addReceipt(b.receipt),p=b.allocatedTokenRanges,c=b.createdByEmail??c,u=b.repoSeq??u,s.addChunk({result:b,chunkStart:d.start,submittedOperations:d.operations}),l+=d.operations.length;let f=or(b.receipt);f!==void 0&&(g=f);break}catch(b){let f=W(b);if(s.receipts.length===0&&!O&&f)throw b;if(o!==!1&&R<o.maxAttempts&&Ae(b)){await ve(ke(R,o)),R+=1,O=!0;continue}throw y({cause:b,pendingOutcome:O||!f?"unknown":"absent"})}h+=1;}}catch(d){throw d instanceof oe?s.receipts.length===0?d.reason:y({cause:d.reason,pendingOutcome:"absent"}):d}if(h===0)throw new $("At least one operation is required for stream submission.");let S=s.toResult({committer:e.committer,createdByEmail:c,message:e.message,repoSeq:u});if(s.allFailed)throw new v(S);return S}async function*ir(n,e,t){try{if(Array.isArray(n)){let o=n.map((s,p)=>it(s,p,t));ot(o,0);for(let s=0;s<o.length;s+=e)yield {operations:o.slice(s,s+e),start:s};return}let r=0,i=[];for await(let o of n)i.push(it(o,r,t)),r+=1,!(i.length<e)&&(yield nt(i,r),i=[]);i.length>0&&(yield nt(i,r));}catch(r){throw new oe(r)}}function nt(n,e){let t=e-n.length;return ot(n,t),{operations:n,start:t}}function it(n,e,t){let r;try{r=E(n);}catch(i){let o=i instanceof Error?i.message:String(i);throw new $(`Invalid operation at index ${e}: ${o}`)}return t&&r.operation==="add"?{...r,skipExisting:true}:r}function or(n){let e=n.event?.repoSeq;if(e===void 0)return;let t=Number(e);return Number.isSafeInteger(t)?t:void 0}function ot(n,e){let t=C$1(n).find(r=>!sr(r));if(t)throw new $(`Invalid operation at index ${e+t.operationIndex}: ${t.message}`,t.code)}function sr(n){return n.code==="ILLEGAL_OP_SEQUENCE"&&n.message.includes("Cannot revise then add ")}function ar(n){return Number.isFinite(n)?Math.max(1,Math.min(ie,Math.trunc(n))):ne}var cr="0.0.0-development";function L(n){return n===cr}var Ee="0.92.0";var st=1;function pr(n){return n===g?"Run: wh update --yes":n===f?"Run: npm install @warmhub/sdk-ts@latest (or your package manager's equivalent).":n===h?"Run: pip install --upgrade warmhub":`Deploy a released ${n} build that satisfies the backend compatibility contract.`}function at(n,e){if(typeof n?.minSupportedClients!="object"||n.minSupportedClients===null||!Number.isSafeInteger(n.writeContractVersion)||n.writeContractVersion<1)return {message:"The backend does not advertise valid per-client write compatibility data.",hint:"Upgrade the WarmHub backend before retrying this write."};let t$1=n.minSupportedClients[e.name],r=typeof t$1=="string"?t(t$1):null;if(!r)return {message:`The backend does not advertise a valid compatibility floor for ${e.name}.`,hint:"Upgrade the WarmHub backend or register this first-party client family before writing."};if(!L(e.version)){let i=t(e.version);if(!i)return {message:`${e.name} reported malformed version "${e.version}".`,hint:"Use a released WarmHub client with a SemVer package version."};if(u(i,r)<0)return {message:`${e.name} ${e.version} is older than the backend's minimum supported version ${r}.`,hint:pr(e.name)}}if(n.writeContractVersion<st)return {message:`${e.name} requires write contract ${st}, but the backend provides ${n.writeContractVersion}.`,hint:"Upgrade the WarmHub backend before retrying this write."}}function xe(n,e){try{return new URL(n).origin===new URL(e).origin}catch{return false}}var ur=new Set(["GET","POST","PUT","PATCH","DELETE"]),I=class extends Error{reason;constructor(e,t){super(t),this.name="CliCallVerificationError",this.reason=e;}};async function lr(n$1,e,t){let r=n$1.method.toUpperCase();if(!ur.has(r))throw new I("unsupported-method",`Unsupported HTTP method "${n$1.method}" \u2014 component CLI dispatch only emits GET, POST, PUT, or PATCH`);let i=r,o$1=n$1.headers.get(m$1);if(!o$1)throw new I("missing-install-repo",`Missing ${m$1} header`);let s=D(e.CLI_SIGNING_SECRET),p$1=D(e.CLI_BEARER_TOKEN),c=D(e.CLI_API_KEY),u=D(e.CLI_BASIC_USERNAME)&&D(e.CLI_BASIC_PASSWORD);if(!s&&!p$1&&!c&&!u)throw new I("no-scheme-configured","no-scheme-configured: need at least one of CLI_SIGNING_SECRET, CLI_BEARER_TOKEN, CLI_API_KEY, or CLI_BASIC_USERNAME + CLI_BASIC_PASSWORD");if(p$1&&u)throw new I("no-scheme-configured","unsupported-scheme-combination: CLI_BEARER_TOKEN and CLI_BASIC_USERNAME + CLI_BASIC_PASSWORD both use the Authorization header and cannot be configured together");let l=new URL(n$1.url),g=l.pathname,h,y,S;if(p(i)?h={}:(h=Object.fromEntries(l.searchParams.entries()),y="",S={...h}),s){let d=n$1.headers.get(n);if(!d)throw new I("missing-signature",`Missing ${n} header`);let R=n$1.headers.get(o);if(!R)throw new I("missing-timestamp",`Missing ${o} header`);let O=Number(R);if(!Number.isFinite(O)||!Number.isInteger(O))throw new I("invalid-timestamp",`${o} must be an integer unix seconds value; got "${R}"`);y=await ct(n$1,i,y);let b=await q({secret:e.CLI_SIGNING_SECRET,method:i,path:g,query:h,installRepo:o$1,body:y,signature:d,timestamp:O,nowUnixSeconds:t?.nowUnixSeconds??Math.floor(Date.now()/1e3),toleranceSec:t?.toleranceSec});if(!b.ok)throw new I(b.reason,`HMAC verification failed: ${b.reason}`)}if(p$1){let d=`Bearer ${e.CLI_BEARER_TOKEN}`,R=n$1.headers.get("authorization")??"";if(!await Te(R,d))throw new I("invalid-bearer","invalid-bearer: bearer token mismatch")}if(c){let d=D(e.CLI_API_KEY_HEADER)?e.CLI_API_KEY_HEADER:"X-API-Key",R=n$1.headers.get(d)??"";if(!await Te(R,e.CLI_API_KEY))throw new I("invalid-api-key",`invalid-api-key: mismatch on header "${d}"`)}if(u){let d=`Basic ${btoa(`${e.CLI_BASIC_USERNAME}:${e.CLI_BASIC_PASSWORD}`)}`,R=n$1.headers.get("authorization")??"";if(!await Te(R,d))throw new I("invalid-basic","invalid-basic: basic auth mismatch")}return S===void 0&&(y=await ct(n$1,i,y),S=dr(y)),{method:i,installRepo:o$1,args:S}}async function ct(n,e,t){return p(e)?t!==void 0?t:n.text():""}function dr(n){let e;try{e=JSON.parse(n);}catch{throw new I("invalid-body","POST body is not valid JSON")}if(!mr(e))throw new I("invalid-body","POST body must be a JSON object of primitive args (string / number / boolean)");return e}function D(n){return typeof n=="string"&&n.length>0}function mr(n){if(typeof n!="object"||n===null||Array.isArray(n))return false;for(let e of Object.values(n))if(e!==void 0&&typeof e!="string"&&typeof e!="number"&&typeof e!="boolean")return false;return true}async function Te(n,e){let[t,r]=await Promise.all([pt(n),pt(e)]),i=0;for(let o=0;o<t.length;o++)i|=t[o]^r[o];return i===0}async function pt(n){return new Uint8Array(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n)))}function Ne(n){if(n.includes("/"))return n.split("/")[0]}function lt(n){if("shapeWref"in n&&typeof n.shapeWref=="string")return n.shapeWref;if(n.name)return Ne(n.name)}function _e(n){if(typeof n!="string")return;let e=n.trim();return e.length>0?e:void 0}function M(n){return l({kind:n.kind,name:n.name,about:ce(n),type:se(n),members:ae(n)})}function ce(n){if("about"in n&&n.about!==void 0)return n.about;if("aboutWref"in n)return n.aboutWref}function Pe(n){return "data"in n?n.data:void 0}function se(n){return "type"in n?n.type:void 0}function ae(n){return "members"in n?n.members:void 0}function G(n,e){return l({kind:n.kind,name:e})}function ut(n){return n.data??{}}function dt(n){if(n.operation==="retract")return E(n);if(n.operation==="reaffirm")return E({operation:"reaffirm",name:n.name,...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.kind?{kind:n.kind}:{},...n.add?{add:[...n.add]}:{},...n.remove?{remove:[...n.remove]}:{},...n.leaseId?{leaseId:n.leaseId}:{}});if(n.operation==="add"){let r=M(n);if(r==="collection")return H(n,"OperationBuilder");let i=n,o=ut(i),s=_e(i.name);if(!s)throw new Error("OperationBuilder: add operation missing name");if(r==="assertion"){let p=ce(i);if(p===void 0)throw new Error(`OperationBuilder: assertion add '${s}' missing required 'about'`);if(typeof p!="string")throw new Error(A$1);return {operation:"add",kind:r,name:s,about:p,data:o,...i.affirmedTargets?{affirmedTargets:[...i.affirmedTargets]}:{},...i.skipExisting===true?{skipExisting:true}:{}}}return {operation:"add",kind:r,name:s,data:o,...i.skipExisting===true?{skipExisting:true}:{}}}let e=_e(n.name)??_e(n.wref);if(!e)throw new Error("OperationBuilder: revise operation missing required target ('name' or 'wref')");let t=G(n,e);if(t==="collection")return ee({...n,name:e},"OperationBuilder");if(t==="assertion")return {operation:"revise",kind:t,name:e,data:n.data??{},...n.affirmedTargets?{affirmedTargets:[...n.affirmedTargets]}:{},...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.leaseId?{leaseId:n.leaseId}:{}};if(n.affirmedTargets!==void 0)throw new Error(`OperationBuilder: REVISE '${e}' has affirmedTargets but inferred kind '${t}' \u2014 affirmedTargets applies only to assertions; set kind: 'assertion'`);return {operation:"revise",kind:t,name:e,data:ut(n),...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.leaseId?{leaseId:n.leaseId}:{}}}function x(n,e){return n.operation==="add"?{operation:n.operation,kind:e,name:n.name,about:ce(n),type:se(n),members:ae(n)}:{operation:n.operation,kind:e,name:n.name??n.wref,type:se(n),members:ae(n)}}function mt(n){if(n.length!==0)throw new Error(n.join("; "))}function gt(n,e,t,r){let i=[];if((e==="thing"||e==="assertion"||e==="collection"&&n==="REVISE")&&(k(t)||i.push(`${n} ${e} name must be a local path (Shape/name), got: "${t}"`)),e==="shape"&&(n==="ADD"||n==="REVISE")&&r!==void 0){let s=F(t,r,n==="REVISE"?"revise":"add");s&&i.push(s);}return i}function ht(n,e){let t=[];if(n.name&&t.push(...gt("ADD",e,n.name,Pe(n))),e==="assertion"&&ce(n)===void 0&&t.push(`ADD assertion '${n.name}' missing required 'about' \u2014 for hierarchical thing names set kind: 'thing' explicitly`),e!=="collection"&&(se(n)!==void 0||ae(n)!==void 0)&&t.push(`ADD '${n.name}' has collection fields but inferred kind '${e}' \u2014 collection adds require both 'type' and 'members', or set kind: 'collection'`),e!=="assertion"&&"affirmedTargets"in n&&n.affirmedTargets!==void 0&&t.push(`ADD '${n.name}' has affirmedTargets but inferred kind '${e}' \u2014 affirmedTargets applies only to assertions; set kind: 'assertion'`),e==="collection")try{H(n,"OperationBuilder");}catch(r){t.push(r instanceof Error?r.message:String(r));}for(let r of B(x(n,e),0))t.push(r.message);mt(t);}function yt(n,e,t){let r=[];n!=="collection"&&t.data===void 0&&r.push(`OperationBuilder: ${n} revise requires 'data'`),n!=="assertion"&&t.affirmedTargets!==void 0&&r.push(`REVISE '${e}' has affirmedTargets but inferred kind '${n}' \u2014 affirmedTargets applies only to assertions; set kind: 'assertion'`),r.push(...gt("REVISE",n,e,t.data),...B(x({...t,name:e},n),0).map(i=>i.message)),mt(r);}var pe=class{ops=[];pendingNames=new Set;shapes;wrefToShape=new Map;submitted=false;inFlight=false;constructor(e){this.shapes=e?.shapes;}add(e){this.assertCanModify();let t={...e};delete t.operation;let r=lt(t),i=Pe(t);if(this.shapes&&r&&i!==void 0){let c=this.shapes[r];if(c){let u=M$1(i,c);if(!u.valid)throw new Error(`Shape validation failed for '${t.name}' (shape: ${r}): ${u.errors.join("; ")}`)}}let o={operation:"add",...t},s=M(o);(o.name||s==="collection")&&ht(o,s);let p=Object.freeze({operation:"add",...t});return this.ops.push(p),t.name&&(this.pendingNames.add(t.name),r&&this.wrefToShape.set(t.name,r)),this}revise(e){this.assertCanModify();let t={...e};delete t.operation;let r=t.name??t.wref;if(this.shapes&&r&&t.data!==void 0){let o=this.wrefToShape.get(r)??Ne(r);if(o){let s=this.shapes[o];if(s){let p=M$1(t.data,s);if(!p.valid)throw new Error(`Shape validation failed for revise '${r}' (shape: ${o}): ${p.errors.join("; ")}`)}}}if(r){let o=G({...t},r);yt(o,r,{operation:"revise",...t});}let i=Object.freeze({operation:"revise",...t});return this.ops.push(i),this}retract(e){this.assertCanModify();let t=Object.freeze(typeof e=="string"?{operation:"retract",name:e}:{operation:"retract",name:e.name,...e.kind?{kind:e.kind}:{},...e.reason?{reason:e.reason}:{},...e.expectedVersion!==void 0?{expectedVersion:e.expectedVersion}:{},...e.leaseId?{leaseId:e.leaseId}:{}});return this.ops.push(t),this}reaffirm(e){this.assertCanModify();let t=Object.freeze({operation:"reaffirm",name:e.name,...e.expectedVersion!==void 0?{expectedVersion:e.expectedVersion}:{},...e.kind?{kind:e.kind}:{},...e.add?{add:Object.freeze([...e.add])}:{},...e.remove?{remove:Object.freeze([...e.remove])}:{},...e.leaseId?{leaseId:e.leaseId}:{}});return this.ops.push(t),this}get operations(){return Object.freeze([...this.ops])}get size(){return this.ops.length}has(e){return this.pendingNames.has(e)}validate(){let e=[],t=[],r=new Set,i=new Set;for(let c=0;c<this.ops.length;c+=1){let u=this.ops[c];if(u){if(u.operation==="add"){let l=M(u);!u.name&&l!=="collection"?e.push({code:"MISSING_NAME",operationIndex:c,message:`Add operation at index ${c} is missing required 'name' field`}):u.name&&(r.has(u.name)&&e.push({code:"DUPLICATE_NAME",operationIndex:c,message:`Duplicate name '${u.name}' at index ${c} (already added earlier in commit)`}),r.add(u.name));}if(u.operation==="revise"){let l=u.name??u.wref;l?i.has(l)?e.push({code:"REVISE_AFTER_RETRACT",operationIndex:c,message:`Revise at index ${c} targets '${l}' which was already retracted in this commit`}):r.has(l)||t.push({code:"REVISE_UNKNOWN_WREF",operationIndex:c,message:`Revise at index ${c} references '${l}' which was not added in this commit (assuming it exists server-side)`}):e.push({code:"MISSING_WREF",operationIndex:c,message:`Revise operation at index ${c} is missing required target ('name' or 'wref')`});}u.operation==="retract"&&(u.name?i.has(u.name)?t.push({code:"RETRACT_AFTER_RETRACT",operationIndex:c,message:`Retract at index ${c} targets '${u.name}' which was already retracted in this commit`}):(r.has(u.name)||t.push({code:"RETRACT_UNKNOWN_WREF",operationIndex:c,message:`Retract at index ${c} references '${u.name}' which was not added in this commit (assuming it exists server-side)`}),i.add(u.name)):e.push({code:"MISSING_NAME",operationIndex:c,message:`Retract operation at index ${c} is missing required 'name' field`}));}}let o=this.ops.flatMap((c,u)=>{if(c.operation==="add")return B(x(c,M(c)),u);if(c.operation==="revise"){let l=c.name??c.wref;return B(x(c,l?G(c,l):"thing"),u)}return B({operation:"retract",kind:c.kind,name:c.name},u)});for(let c of o)e.push({code:c.code,operationIndex:c.operationIndex,message:c.message});let s=this.ops.flatMap((c,u)=>{if(c.operation==="retract"||c.operation==="reaffirm")return [];if(c.operation==="add")return [{op:x(c,M(c)),operationIndex:u}];let l=c.name??c.wref;return [{op:x(c,l?G(c,l):"thing"),operationIndex:u}]}),p=C$1(s.map(({op:c})=>c),{checkAddAdd:false,sourceOperationIndexes:s.map(({operationIndex:c})=>c)});for(let c of p)e.push({code:c.code,operationIndex:c.operationIndex,message:c.message});return this.ops.length===0&&e.push({code:"EMPTY_COMMIT",operationIndex:-1,message:"OperationBuilder has no operations"}),{valid:e.length===0,errors:e,warnings:t}}async commit(e){if(this.assertNotSubmitted(),this.inFlight)throw new Error("OperationBuilder: stream submission already in flight");let t=this.validate();if(!t.valid){let r=t.errors.map(i=>i.message).join("; ");throw new Error(`OperationBuilder validation failed: ${r}`)}this.inFlight=true;try{let r=this.ops.map(o=>dt(o)),i=await P(e.client,{orgName:e.orgName,repoName:e.repoName,committer:e.committer,message:e.message,chunkSize:e.chunkSize,streamId:e.streamId,submissionId:e.submissionId,returnRepoSeq:e.returnRepoSeq,retry:e.retry,operations:r});return this.submitted=!0,i}catch(r){throw r instanceof A&&(this.submitted=true),r}finally{this.inFlight=false;}}assertNotSubmitted(){if(this.submitted)throw new Error("OperationBuilder: already submitted, cannot modify")}assertCanModify(){if(this.assertNotSubmitted(),this.inFlight)throw new Error("OperationBuilder: stream submission already in flight, cannot modify")}};function ti(n){return n.replace(/@(?:v\d+|HEAD|ALL)$/i,"")}var Tt=["apiUrl","fetch","accessToken","auth","functionLogs","client","clientFlags"],wr=new Set(Tt),Sr=new Set(["token","apiKey","bearer"]);function Or(n){if(n)for(let e of Object.keys(n)){if(wr.has(e))continue;let t=Sr.has(e)?'; did you mean "accessToken"?':`. Valid options are: ${Tt.join(", ")}.`;throw new TypeError(`Unknown WarmHubClient option "${e}"${t}`)}}function Ir(n){if(!n||n.length===0)return [];for(let e of n)if(!c(e))throw new TypeError(`Invalid client flag "${e}": expected lowercase tokens matching [a-z0-9-]+.`);return [...new Set(n)].sort()}var Le="https://api.warmhub.ai",Ar=new Set(["commit.validate","repo.shapeInstanceCounts","thing.getMany","thing.headVersions"]),ft=500,Rt=500,bt=1,Ct=8;function de(n){return {...n,actionContainer:void 0,actionContainerConfig:void 0}}function kr(n){return n.map(e=>de(e))}function _t(n,e,t){if(e===n||t.has(e))throw new m("VALIDATION_ERROR","Paginated result cursor did not advance")}function wt(n){if(n===void 0)throw new m("VALIDATION_ERROR","sinceRepoSeq is required for an incremental read")}async function*Nt(n,e){let t=e,r=new Set;for(;;){t&&r.add(t);let i=await n(t);if(yield i,!i.nextCursor)return;_t(t,i.nextCursor,r),t=i.nextCursor;}}async function*C(n,e,t){for await(let r of Nt(n,t))yield*e(r);}async function w(n,e,t,r){if(t!==void 0&&(!Number.isFinite(t)||Math.trunc(t)!==t||t<0))throw new m("VALIDATION_ERROR","max must be a nonnegative integer");let i=[];for await(let o of Nt(n,r)){let s=e(o);if(t!==void 0&&i.length+s.length>t)throw new m("VALIDATION_ERROR",`Paginated result exceeded max=${t}`);i.push(...s);}return i}function St(n){if(n?.slugs!==void 0)throw new m("VALIDATION_ERROR","repo.explore pagination helpers do not support slugs mode")}async function Ot(n){let e=[],t,r=new Set;for(;;){t&&r.add(t);let i=await n(t);if(e.push(...i.items),!i.nextCursor){if(i.repoSeq===void 0)throw new m("VALIDATION_ERROR","Incremental read completed without repoSeq");return {items:e,repoSeq:i.repoSeq}}_t(t,i.nextCursor,r),t=i.nextCursor;}}function ue(n,e,t){return Number.isFinite(n)?Math.max(1,Math.min(t,Math.trunc(n))):e}function It(n,e){let t=[];for(let r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function le(n){return n!==void 0&&j.includes(n)?n:void 0}function K(n){let[e,t,r]=n;return typeof e=="string"?{orgName:e,repoName:t,name:r}:e}function vr(n){let[e,t]=n;return typeof e=="string"?{orgName:e,repoName:t}:e}function Er(n){let[e,t,r,i]=n;return typeof e=="string"?{orgName:e,repoName:t,subscriptionName:r,credentialSetName:i}:e}function xr(n){let[e,t,r]=n;return typeof e=="string"?{orgName:e,repoName:t,subscriptionName:r}:e}function Tr(n){let{actionContainer:e,actionContainerConfig:t,...r}=n;return r}function _r(n){let{actionContainer:e,actionContainerConfig:t,...r}=n;return r}function me(n){return !!n&&(!!n.shape||!!n.kind||!!n.about||!!n.match||!!n.componentRef||n.excludeComponents===true||(n.where?.length??0)>0)}function ge(n){return !!n&&(!!n.shape||!!n.about||!!n.match||!!n.componentRef||(n.where?.length??0)>0)}function Pt(n){let e=n.members;return Array.isArray(e)&&e.length>0}function Nr(n){let t=n.replace(/^wh:[^/]+\/[^/]+\//,"").replace(/@(?:HEAD|ALL|v\d+)$/,"").split("/")[0]?.toLowerCase();return t==="arc"||t==="bond"||t==="pair"||t==="set"||t==="list"?t:void 0}function Pr(n,e){if(me(e.query)&&!ge(e.query))throw new m("VALIDATION_ERROR","Selector-backed collection sources require shape, about, match, componentRef, or where; kind and excludeComponents only narrow an existing selector.");if(e.sourceRepo&&!ge(e.query))throw new m("VALIDATION_ERROR","sourceRepo requires a selector-backed collection query");if(e.sourceRepo&&Pt(e))throw new m("VALIDATION_ERROR","sourceRepo cannot be combined with explicit members; use canonical wh:org/repo/... member wrefs or omit sourceRepo.");if(me(e.query)&&n!=="set")throw new m("VALIDATION_ERROR","Selector-backed collection sources are only supported for set collections")}function ri(n){return n??"off"}function Lr(n){switch(n){case "BAD_REQUEST":case "PARSE_ERROR":case "PAYLOAD_TOO_LARGE":case "UNPROCESSABLE_CONTENT":case "UNSUPPORTED_MEDIA_TYPE":return "VALIDATION_ERROR";case "METHOD_NOT_SUPPORTED":return "NOT_FOUND";case "UNAUTHORIZED":return "UNAUTHENTICATED";case "FORBIDDEN":return "FORBIDDEN";case "NOT_FOUND":return "NOT_FOUND";case "CONFLICT":return "CONFLICT";case "PRECONDITION_FAILED":return "PRECONDITION_FAILED";case "TOO_MANY_REQUESTS":return "RATE_LIMITED";default:return}}function Dr(n){if(n===void 0||n===408)return;if(n===405)return "NOT_FOUND";if(n===412)return "PRECONDITION_FAILED";if(n===422)return "VALIDATION_ERROR";let e=Dt(n);return e!=="BACKEND"?e:n>=400&&n<500?"VALIDATION_ERROR":e}var Mr=[/\bselect\b.+?\bfrom\b/i,/\binsert\b.+?\binto\b/i,/\bupdate\b.+?\bset\b/i,/\bdelete\b.+?\bfrom\b/i,/\bparams:\s/i,/\.ts\(\d+,\d+\)/,/at\s+\S+\s+\(.*:\d+:\d+\)/,/node_modules\//,/drizzle/i];function De(n){for(let e of Mr)if(e.test(n))return "An internal error occurred. Please try again or contact support.";return n}var m=class extends Error{code;status;hint;retryAfter;errorCode;backendCode;details;constructor(e,t,r,i,o,s,p){super(t),this.name="WarmHubError",this.code=e,this.status=r,this.hint=i,this.retryAfter=o,this.errorCode=s,this.backendCode=s,this.details=p;}get kind(){return this.code}};function At(n,e){if(typeof e!="string")return;let t=x$1(n,e);if(t)throw new m("VALIDATION_ERROR",t)}function a(n){if(n instanceof m)return n;if(n instanceof TRPCClientError){if(n.cause instanceof m)return n.cause;let e=n.data,t=e?.warmhub?.code,r=typeof e?.code=="string"?Lr(e.code):void 0,i=Dr(e?.httpStatus),o=e?.warmhub?.message??De(n.message);return new m(t??r??i??"BACKEND",o,e?.warmhub?.status??e?.httpStatus,e?.warmhub?.hint,e?.warmhub?.retryAfter??e?.retryAfter,t,e?.warmhub?.details)}if(n instanceof Error){let e=n;return n.name==="WarmHubError"&&typeof e.code=="string"?new m(e.code,De(n.message),typeof e.status=="number"?e.status:void 0,typeof e.hint=="string"?e.hint:void 0,typeof e.retryAfter=="number"?e.retryAfter:void 0,typeof e.errorCode=="string"?e.errorCode:typeof e.backendCode=="string"?e.backendCode:void 0,e.details):n.name==="AbortError"?new m("CANCELLED",n.message):n instanceof TypeError&&/fetch/i.test(n.message)?new m("NETWORK",n.message):new m("BACKEND",De(n.message))}return new m("BACKEND","Unknown SDK error")}function qr(n){return n instanceof m}function ni(n){let e=a(n);return e.kind==="NETWORK"||e.kind==="CANCELLED"||e.kind==="BACKEND"||e.kind==="RATE_LIMITED"}var Br=new Set(["ConnectionRefused","ECONNREFUSED","ENOTFOUND","ETIMEDOUT","EAI_AGAIN"]);function Ur(n){if(n instanceof TypeError&&/fetch/i.test(n.message))return true;if(n&&typeof n=="object"){let e=n.code;if(typeof e=="string"&&Br.has(e))return true}return false}function Vr(n){return `Unable to connect to ${n}. Is the computer able to access the url?`}function ii(n,e){if(L(n))return false;let t$1=t(n),r=t(e);return !t$1||!r?false:u(t$1,r)<0}function Lt(n,e){return new m("CLIENT_INCOMPATIBLE",n,412,e)}function Hr(n,e){let t=at(n,e);if(t)throw Lt(t.message,t.hint)}var kt=class n{apiUrl;fetchImpl;accessToken;clientIdentity;clientFlags;functionLogMode;getToken;compatibilityCheck;overrideNoticePrinted=false;noteCompatibilityOverride(){this.overrideNoticePrinted||(this.overrideNoticePrinted=true,console.error(`warmhub: compatibility checks overridden by client flag ${b}; the server remains authoritative.`));}assertWriteCompatible(){return this.clientFlags.includes(b)?(this.noteCompatibilityOverride(),Promise.resolve()):L(this.clientIdentity.version)&&xe(this.apiUrl,Le)?Promise.reject(Lt(`Development client ${this.clientIdentity.name}/${this.clientIdentity.version} cannot write to production.`,"Install a released WarmHub client artifact before writing to api.warmhub.ai.")):L(this.clientIdentity.version)&&!xe(this.apiUrl,Le)?Promise.resolve():this.diagnostics.assertCompatible()}createCompatibilityLink(){return ()=>({op:e,next:t})=>e.type!=="mutation"||e.path==="commit.validate"?t(e):observable(r=>{let i=false,o;return this.assertWriteCompatible().then(()=>{i||(o=t(e).subscribe(r));}).catch(s=>{i||r.error(TRPCClientError.from(s));}),()=>{i=true,o?.unsubscribe();}})}auth={getClientId:async()=>{try{return await this.trpc.auth.getClientId.query()}catch(e){throw a(e)}},sync:async()=>{try{return await this.trpc.auth.sync.mutate()}catch(e){throw a(e)}},currentUser:async()=>{try{return await this.trpc.auth.currentUser.query()}catch(e){throw a(e)}},whoami:async()=>{try{return await this.trpc.auth.whoami.query()}catch(e){throw a(e)}}};homepage={featuredLists:async()=>{try{return await this.trpc.homepage.featuredLists.query()}catch(e){throw a(e)}}};access={resolve:async e=>{try{return await this.trpc.access.resolve.query(e)}catch(t){throw a(t)}}};diagnostics={ping:async()=>{let e=await this.fetchWithAuth(`${this.apiUrl.replace(/\/$/,"")}/health`);if(!e.ok)throw new m("BACKEND",`Health request failed with status ${e.status}`,e.status);return await e.json()},capabilities:async()=>{try{return await this.trpc.diagnostics.capabilities.query()}catch(e){throw a(e)}},assertCompatible:()=>{if(this.compatibilityCheck)return this.compatibilityCheck;let e=(async()=>{let t=await this.diagnostics.capabilities();Hr(t,this.clientIdentity);})();return this.compatibilityCheck=e,e.catch(t=>{qr(t)&&t.code==="CLIENT_INCOMPATIBLE"||this.compatibilityCheck===e&&(this.compatibilityCheck=void 0);}),e}};component={list:async(e,t,r)=>{try{return await this.trpc.component.list.query({orgName:e,repoName:t,limit:r?.limit,cursor:r?.cursor})}catch(i){throw a(i)}},listIter:(e,t,r)=>C(i=>this.component.list(e,t,{...r,cursor:i}),i=>i.items,r?.cursor),listAll:async(e,t,r)=>{let{max:i,...o}=r??{};return await w(s=>this.component.list(e,t,{...o,cursor:s}),s=>s.items,i,o.cursor)},search:async(e,t)=>{try{return await this.trpc.component.search.query({query:e,limit:t?.limit,cursor:t?.cursor})}catch(r){throw a(r)}},searchIter:(e,t)=>C(r=>this.component.search(e,{...t,cursor:r}),r=>r.items,t?.cursor),searchAll:async(e,t)=>{let{max:r,...i}=t??{};return await w(o=>this.component.search(e,{...i,cursor:o}),o=>o.items,r,i.cursor)},get:async(e,t,r)=>{try{return await this.trpc.component.get.query({orgName:e,repoName:t,componentRef:r})}catch(i){throw a(i)}},history:async(e,t,r)=>{try{return await this.trpc.component.history.query({orgName:e,repoName:t,componentRef:r?.componentRef,limit:r?.limit})}catch(i){throw a(i)}},install:async(e,t,r,i)=>{try{return await this.trpc.component.install.mutate({orgName:e,repoName:t,componentRef:r,submissionId:i.submissionId})}catch(o){throw a(o)}},uninstall:async(e,t,r,i)=>{try{return await this.trpc.component.uninstall.mutate({orgName:e,repoName:t,componentRef:r,submissionId:i.submissionId})}catch(o){throw a(o)}},registry:{register:async(e,t,r)=>{try{return await this.trpc.component.registry.register.mutate({orgName:e,componentName:t,...r})}catch(i){throw a(i)}},unregister:async(e,t)=>{try{return await this.trpc.component.registry.unregister.mutate({orgName:e,componentName:t})}catch(r){throw a(r)}},list:async e=>{try{return await this.trpc.component.registry.list.query({orgName:e})}catch(t){throw a(t)}},view:async(e,t)=>{try{return await this.trpc.component.registry.view.query({orgName:e,componentName:t})}catch(r){throw a(r)}},update:async(e,t,r)=>{try{return await this.trpc.component.registry.update.mutate({orgName:e,componentName:t,...r})}catch(i){throw a(i)}},resolve:async(e,t,r)=>await this.requestJson(`/api/component-registry/${encodeURIComponent(e)}/${encodeURIComponent(t)}/resolve`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({installRepo:r})}),setupCall:async(e,t,r)=>(await this.assertWriteCompatible(),await this.requestJson(`/api/component-registry/${encodeURIComponent(e)}/${encodeURIComponent(t)}/setup-call`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(r)}))},cli:{call:async(e,t,r,i)=>(await this.assertWriteCompatible(),await this.requestJson(`/api/component-registry/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cli/${encodeURIComponent(r)}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i)}))}};commit={validate:async(e,t,r,i)=>{try{return await this.trpc.commit.validate.mutate({orgName:e,repoName:t,committer:i?.committer,message:i?.message,componentRef:i?.componentRef,operations:Ce(r,i?.skipExisting),includeWouldBeBody:i?.includeWouldBeBody},{signal:i?.signal})}catch(o){throw a(o)}},apply:async(e,t,r,i,o)=>{try{return await P(this,{orgName:e,repoName:t,committer:o?.committer,message:r,componentRef:o?.componentRef,chunkSize:o?.chunkSize,skipExisting:o?.skipExisting,streamId:o?.streamId,submissionId:o?.submissionId,returnRepoSeq:o?.returnRepoSeq,retry:o?.retry,operations:i})}catch(s){throw s instanceof A||s instanceof v?s:a(s)}},getReceipt:async(e,t,r)=>{try{return await this.trpc.commit.getReceipt.query({orgName:e,repoName:t,eventRequestId:r})}catch(i){throw a(i)}}};org={get:async e=>{try{return await this.trpc.org.get.query({orgName:e})}catch(t){throw a(t)}},getCallerRole:async e=>{try{return await this.trpc.org.getCallerRole.query({orgName:e})}catch(t){throw a(t)}},list:async e=>{try{return {items:await this.trpc.org.list.query({includeArchived:e?.includeArchived})}}catch(t){throw a(t)}},create:async(e,t,r)=>{try{return await this.trpc.org.create.mutate({name:e,displayName:t,description:r})}catch(i){throw a(i)}},setDescription:async(e,t)=>{try{return await this.trpc.org.setDescription.mutate({orgName:e,description:t})}catch(r){throw a(r)}},setDisplayName:async(e,t)=>{try{return await this.trpc.org.setDisplayName.mutate({orgName:e,displayName:t})}catch(r){throw a(r)}},rename:async(e,t)=>{try{return await this.trpc.org.rename.mutate({orgName:e,newName:t})}catch(r){throw a(r)}},update:async e=>{try{return await this.trpc.org.update.mutate(e)}catch(t){throw a(t)}},addMember:async(e,t,r="editor")=>{try{return await this.trpc.org.addMember.mutate({orgName:e,email:t,role:r})}catch(i){throw a(i)}},removeMember:async(e,t)=>{try{await this.trpc.org.removeMember.mutate({orgName:e,email:t});}catch(r){throw a(r)}},leave:async e=>{try{await this.trpc.org.leave.mutate({orgName:e});}catch(t){throw a(t)}},changeMemberRole:async(e,t,r)=>{try{return await this.trpc.org.changeMemberRole.mutate({orgName:e,email:t,role:r})}catch(i){throw a(i)}},setMemberScopes:async(e,t,r)=>{try{await this.trpc.org.setMemberScopes.mutate({orgName:e,email:t,scopes:r});}catch(i){throw a(i)}},clearMemberScopes:async(e,t)=>{try{await this.trpc.org.clearMemberScopes.mutate({orgName:e,email:t});}catch(r){throw a(r)}},listMembers:async(e,t)=>{try{return await this.trpc.org.listMembers.query({orgName:e,pending:t?.pending})}catch(r){throw a(r)}},archive:async e=>{try{return await this.trpc.org.archive.mutate({orgName:e})}catch(t){throw a(t)}},unarchive:async e=>{try{return await this.trpc.org.unarchive.mutate({orgName:e})}catch(t){throw a(t)}}};repo={checkpoint:Qe(()=>this.trpc,a),get:async(e,t)=>{try{return await this.trpc.repo.get.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getStats:async(e,t)=>{try{return await this.trpc.repo.stats.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getStatsBatch:async(e,t)=>{try{return await this.trpc.repo.statsBatch.query({orgName:e,repoNames:t})}catch(r){throw a(r)}},getConfigureStats:async(e,t)=>{try{return await this.trpc.repo.configureStats.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getShapeInstanceCounts:async(e,t)=>{try{return await this.trpc.repo.shapeInstanceCounts.query({orgName:e,repoName:t})}catch(r){throw a(r)}},list:async(e,t)=>{try{return await this.trpc.repo.list.query({orgName:e,limit:t?.limit,cursor:t?.cursor,includeArchived:t?.includeArchived,search:t?.search,sort:t?.sort})}catch(r){throw a(r)}},listIter:(e,t)=>C(r=>this.repo.list(e,{...t,cursor:r}),r=>r.items,t?.cursor),listAll:async(e,t)=>{let{max:r,...i}=t??{};return await w(o=>this.repo.list(e,{...i,cursor:o}),o=>o.items,r,i.cursor)},search:async(e,t)=>{try{return await this.trpc.repo.search.query({query:e,limit:t?.limit,cursor:t?.cursor})}catch(r){throw a(r)}},searchIter:(e,t)=>C(r=>this.repo.search(e,{...t,cursor:r}),r=>r.items,t?.cursor),searchAll:async(e,t)=>{let{max:r,...i}=t??{};return await w(o=>this.repo.search(e,{...i,cursor:o}),o=>o.items,r,i.cursor)},create:async(e,t,r,i,o)=>{try{return await this.trpc.repo.create.mutate({orgName:e,repoName:t,description:r,visibility:i,displayName:o})}catch(s){throw a(s)}},setDescription:async(e,t,r)=>{try{return await this.trpc.repo.setDescription.mutate({orgName:e,repoName:t,description:r})}catch(i){throw a(i)}},setDisplayName:async(e,t,r)=>{try{return await this.trpc.repo.setDisplayName.mutate({orgName:e,repoName:t,displayName:r})}catch(i){throw a(i)}},setVisibility:async(e,t,r)=>{try{return await this.trpc.repo.setVisibility.mutate({orgName:e,repoName:t,visibility:r})}catch(i){throw a(i)}},rename:async(e,t,r)=>{try{return await this.trpc.repo.rename.mutate({orgName:e,repoName:t,newName:r})}catch(i){throw a(i)}},update:async e=>{try{return await this.trpc.repo.update.mutate(e)}catch(t){throw a(t)}},archive:async(e,t)=>{try{return await this.trpc.repo.archive.mutate({orgName:e,repoName:t})}catch(r){throw a(r)}},unarchive:async(e,t)=>{try{return await this.trpc.repo.unarchive.mutate({orgName:e,repoName:t})}catch(r){throw a(r)}},delete:async(e,t)=>{try{let r=await this.trpc.repo.delete.mutate({orgName:e,repoName:t});return {graceExpiresAt:new Date(r.graceExpiresAt)}}catch(r){throw a(r)}},listPage:async(e,t)=>{try{return await this.trpc.repo.listPage.query({orgName:e,limit:t?.limit,cursor:t?.cursor,includeArchived:t?.includeArchived,search:t?.search,sort:t?.sort})}catch(r){throw a(r)}},listPageIter:(e,t)=>C(r=>this.repo.listPage(e,{...t,cursor:r}),r=>r.items,t?.cursor),listPageAll:async(e,t)=>{let{max:r,...i}=t??{};return await w(o=>this.repo.listPage(e,{...i,cursor:o}),o=>o.items,r,i.cursor)},listForCaller:async e=>{try{return await this.trpc.repo.listForCaller.query({limit:e?.limit,sort:e?.sort})}catch(t){throw a(t)}},explore:async e=>{try{return await this.trpc.repo.explore.query({search:e?.search,org:e?.org,activity:e?.activity,hasSubscriptions:e?.hasSubscriptions,minThings:e?.minThings,sort:e?.sort,limit:e?.limit,cursor:e?.cursor,slugs:e?.slugs})}catch(t){throw a(t)}},exploreIter:e=>(St(e),C(t=>this.repo.explore({...e,cursor:t}),t=>t.items,e?.cursor)),exploreAll:async e=>{St(e);let{max:t,...r}=e??{};return await w(i=>this.repo.explore({...r,cursor:i}),i=>i.items,t,r.cursor)},getReadme:async(e,t)=>{try{return await this.trpc.repo.getReadme.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getAgents:async(e,t)=>{try{return await this.trpc.repo.getAgents.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getLicense:async(e,t)=>{try{return await this.trpc.repo.getLicense.query({orgName:e,repoName:t})}catch(r){throw a(r)}},describe:async(e,t)=>{try{return await this.trpc.repo.describe.query({orgName:e,repoName:t})}catch(r){throw a(r)}},setReadme:async(e,t,r,i)=>{try{return At("Content/Readme.content",r),await this.trpc.repo.setReadme.mutate({orgName:e,repoName:t,eventRequestId:i.eventRequestId,content:r})}catch(o){throw a(o)}},setAgents:async(e,t,r,i)=>{try{return At("Content/Agents.content",r),await this.trpc.repo.setAgents.mutate({orgName:e,repoName:t,eventRequestId:i.eventRequestId,content:r})}catch(o){throw a(o)}},getLlmsTxt:async(e,t)=>{try{return await this.trpc.repo.getLlmsTxt.query({orgName:e,repoName:t})}catch(r){throw a(r)}},index:{describe:async(e,t)=>{try{return await this.trpc.repo.index.describe.query({orgName:e,repoName:t})}catch(r){throw a(r)}}}};shape={list:async(e,t,r)=>{try{return await this.trpc.shape.list.query({orgName:e,repoName:t,match:r?.match,componentRef:r?.componentRef,excludeComponents:r?.excludeComponents,includeRetracted:r?.includeRetracted})}catch(i){throw a(i)}},get:async(e,t,r,i)=>{try{return await this.trpc.shape.get.query({orgName:e,repoName:t,shapeName:r,includeRetracted:i?.includeRetracted})}catch(o){throw a(o)}},create:async(e,t,r,i,o)=>{let s=F(r,{fields:i,...o.description!==void 0?{description:o.description}:{}},"add");if(s)throw new m("VALIDATION_ERROR",s);try{return await this.trpc.shape.create.mutate({orgName:e,repoName:t,shapeName:r,fields:i,eventRequestId:o.eventRequestId,description:o.description})}catch(p){throw a(p)}},revise:async(e,t,r,i,o)=>{let s=F(r,{fields:i,...o.description!==void 0?{description:o.description}:{}},"revise");if(s)throw new m("VALIDATION_ERROR",s);try{return await this.trpc.shape.revise.mutate({orgName:e,repoName:t,shapeName:r,newFields:i,eventRequestId:o.eventRequestId,description:o.description})}catch(p){throw a(p)}},remove:async(e,t,r,i)=>{try{return await this.trpc.shape.remove.mutate({orgName:e,repoName:t,shapeName:r,eventRequestId:i.eventRequestId})}catch(o){throw a(o)}},rename:async(e,t,r,i,o)=>{try{return await this.trpc.shape.rename.mutate({orgName:e,repoName:t,oldName:r,newName:i,eventRequestId:o.eventRequestId})}catch(s){throw a(s)}},history:async(e,t,r,i={})=>{try{return await this.trpc.shape.history.query({orgName:e,repoName:t,name:r,includeRetracted:i.includeRetracted,limit:i.limit,cursor:i.cursor})}catch(o){throw a(o)}},historyIter:(e,t,r,i={})=>C(o=>this.shape.history(e,t,r,{...i,cursor:o}),o=>o.versions,i.cursor),historyAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.shape.history(e,t,r,{...s,cursor:p}),p=>p.versions,o,s.cursor)}};subscription={create:async e=>{try{let t=await this.trpc.subscription.create.mutate(Tr(e));return de(t)}catch(t){throw a(t)}},get:async(...e)=>{try{let t=await this.trpc.subscription.get.query(K(e));return de(t)}catch(t){throw a(t)}},reveal:async(...e)=>{try{return await this.trpc.subscription.reveal.query(K(e))}catch(t){throw a(t)}},list:async(...e)=>{try{let t=await this.trpc.subscription.list.query(vr(e));return kr(t)}catch(t){throw a(t)}},update:async e=>{try{let t=await this.trpc.subscription.update.mutate(_r(e));return de(t)}catch(t){throw a(t)}},pause:async(...e)=>{try{return await this.trpc.subscription.pause.mutate(K(e))}catch(t){throw a(t)}},resume:async(...e)=>{try{return await this.trpc.subscription.resume.mutate(K(e))}catch(t){throw a(t)}},remove:async(...e)=>{try{return await this.trpc.subscription.remove.mutate(K(e))}catch(t){throw a(t)}},bindCredentials:async(...e)=>{try{return await this.trpc.subscription.bindCredentials.mutate(Er(e))}catch(t){throw a(t)}},unbindCredentials:async(...e)=>{try{return await this.trpc.subscription.unbindCredentials.mutate(xr(e))}catch(t){throw a(t)}}};action={acquireLease:async(e,t,r,i,o,s)=>{try{return await this.trpc.action.acquireLease.mutate({orgName:e,repoName:t,subscriptionName:r,holderId:i,holderType:o,graceMs:s?.graceMs,ttlMs:s?.ttlMs})}catch(p){throw a(p)}},heartbeatLease:async(e,t,r,i,o)=>{try{return await this.trpc.action.heartbeatLease.mutate({orgName:e,repoName:t,subscriptionName:r,holderId:i,ttlMs:o})}catch(s){throw a(s)}},releaseLease:async(e,t,r,i)=>{try{return await this.trpc.action.releaseLease.mutate({orgName:e,repoName:t,subscriptionName:r,holderId:i})}catch(o){throw a(o)}},claimDelivery:async(e,t,r,i)=>{let o=typeof r=="string"?{runId:r}:r;try{return await this.trpc.action.claimDelivery.mutate({orgName:e,repoName:t,...o,holderId:i})}catch(s){throw a(s)}},completeDelivery:async(e,t,r,i)=>{let o=typeof r=="string"?{runId:r}:r;try{return await this.trpc.action.completeDelivery.mutate({orgName:e,repoName:t,...o,holderId:i})}catch(s){throw a(s)}},liveFeed:async(e,t,r,i)=>{try{return await this.trpc.action.liveFeed.query({orgName:e,repoName:t,subscriptionName:r,limit:i?.limit,cursor:i?.cursor})}catch(o){throw a(o)}},liveFeedIter:(e,t,r,i)=>C(o=>this.action.liveFeed(e,t,r,{...i,cursor:o}),o=>o.items,i?.cursor),liveFeedAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.action.liveFeed(e,t,r,{...s,cursor:p}),p=>p.items,o,s.cursor)},listRuns:async(e,t,r)=>{try{return await this.trpc.action.listRuns.query({orgName:e,repoName:t,runId:r?.runId,subscriptionName:r?.subscriptionName,status:r?.status,outcome:r?.outcome,since:r?.since,cursor:r?.cursor,limit:r?.limit})}catch(i){throw a(i)}},listRunsIter:(e,t,r)=>C(i=>this.action.listRuns(e,t,{...r,since:i===void 0?r?.since:void 0,cursor:i}),i=>i.items,r?.cursor),listRunsAll:async(e,t,r)=>{let{max:i,...o}=r??{};return await w(s=>this.action.listRuns(e,t,{...o,since:s===void 0?o.since:void 0,cursor:s}),s=>s.items,i,o.cursor)},latestRuns:async(e,t)=>{try{return await this.trpc.action.latestRuns.query({orgName:e,repoName:t})}catch(r){throw a(r)}},runStats:async(e,t,r)=>{try{return await this.trpc.action.runStats.query({orgName:e,repoName:t,subscriptionName:r?.subscriptionName,since:r?.since})}catch(i){throw a(i)}},getRunAttempts:async(e,t,r)=>{try{return await this.trpc.action.getRunAttempts.query({orgName:e,repoName:t,runId:r})}catch(i){throw a(i)}},listNotifications:async(e,t,r)=>{try{return await this.trpc.action.listNotifications.query({orgName:e,repoName:t,since:r?.since,limit:r?.limit})}catch(i){throw a(i)}}};collection={create:async(e,t,r)=>{try{return Pr(r.type,r),await this.trpc.collection.create.mutate({orgName:e,repoName:t,eventRequestId:r.eventRequestId,type:r.type,name:r.name,members:r.members,from:r.from,add:r.add,remove:r.remove,replaceMembers:r.replaceMembers,query:r.query,sourceOrgName:r.sourceRepo?.orgName,sourceRepoName:r.sourceRepo?.repoName,skipExisting:r.skipExisting,message:r.message,committer:r.committer})}catch(i){throw a(i)}},members:async(e,t,r,i)=>{try{return await this.trpc.collection.members.query({orgName:e,repoName:t,wref:r,version:i?.version,limit:i?.limit,cursor:i?.cursor})}catch(o){throw a(o)}},membersIter:(e,t,r,i)=>{let o=i?.version;return C(async s=>{let p=await this.collection.members(e,t,r,{...i,version:o,cursor:s});return o??=p.version,p},s=>s.items,i?.cursor)},membersAll:async(e,t,r,i)=>{let{max:o,...s}=i??{},p=s.version;return await w(async c=>{let u=await this.collection.members(e,t,r,{...s,version:p,cursor:c});return p??=u.version,u},c=>c.items,o,s.cursor)},contains:async(e,t,r,i,o)=>{try{return await this.trpc.collection.contains.query({orgName:e,repoName:t,wref:r,version:o?.version,members:i,position:o?.position})}catch(s){throw a(s)}},diff:async(e,t,r,i,o)=>{try{return await this.trpc.collection.diff.query({orgName:e,repoName:t,leftWref:r,rightWref:i,leftVersion:o?.leftVersion,rightVersion:o?.rightVersion,mode:o?.mode})}catch(s){throw a(s)}},revise:async(e,t,r,i)=>{try{let o=Nr(r);if(me(i.query)&&!ge(i.query))throw new m("VALIDATION_ERROR","Selector-backed collection sources require shape, about, match, componentRef, or where; kind and excludeComponents only narrow an existing selector.");if(i.sourceRepo&&!ge(i.query))throw new m("VALIDATION_ERROR","sourceRepo requires a selector-backed collection query");if(i.sourceRepo&&Pt(i))throw new m("VALIDATION_ERROR","sourceRepo cannot be combined with explicit members; use canonical wh:org/repo/... member wrefs or omit sourceRepo.");if(me(i.query)&&o&&o!=="set")throw new m("VALIDATION_ERROR","Selector-backed revise requires a Set/<name> target wref");return await this.trpc.collection.revise.mutate({orgName:e,repoName:t,eventRequestId:i.eventRequestId,wref:r,members:i.members,add:i.add,remove:i.remove,query:i.query,sourceOrgName:i.sourceRepo?.orgName,sourceRepoName:i.sourceRepo?.repoName,message:i.message,committer:i.committer})}catch(o){throw a(o)}},stats:async(e,t,r,i)=>{try{return await this.trpc.collection.stats.query({orgName:e,repoName:t,wref:r,version:i?.version})}catch(o){throw a(o)}}};view={evaluate:async(e,t,r,i)=>{try{return await this.trpc.view.evaluate.query({orgName:e,repoName:t,wref:r,limit:i?.limit,cursor:i?.cursor})}catch(o){throw a(o)}},evaluateIter:(e,t,r,i)=>C(o=>this.view.evaluate(e,t,r,{...i,cursor:o}),o=>o.items,i?.cursor),evaluateAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.view.evaluate(e,t,r,{...s,cursor:p}),p=>p.items,o,s.cursor)}};grant=je(()=>this.trpc,a);thing={head:async(e,t,r)=>{try{return await this.trpc.thing.head.query({orgName:e,repoName:t,shape:r?.shape,kind:le(r?.kind),match:r?.match,dataMode:r?.dataMode,includeRetracted:r?.includeRetracted,limit:r?.limit,cursor:r?.cursor,componentRef:r?.componentRef,excludeComponents:r?.excludeComponents,excludeInfraShapes:r?.excludeInfraShapes,where:r?.where,sinceRepoSeq:r?.sinceRepoSeq})}catch(i){throw a(i)}},headIter:(e,t,r)=>C(i=>this.thing.head(e,t,{...r,cursor:i}),i=>i.items,r?.cursor),headAll:async(e,t,r)=>{let{max:i,...o}=r??{};return await w(s=>this.thing.head(e,t,{...o,cursor:s}),s=>s.items,i,o.cursor)},headChanges:async(e,t,r)=>(wt(r?.sinceRepoSeq),await Ot(i=>this.thing.head(e,t,{...r,includeRetracted:true,cursor:i}))),get:async(e,t,r,i,o)=>{try{return await this.trpc.thing.get.query({orgName:e,repoName:t,wref:r,version:i,includeRetracted:o?.includeRetracted,dataMode:o?.dataMode})}catch(s){throw a(s)}},getWithLease:async(e,t,r,i)=>{try{return await this.trpc.thing.getWithLease.mutate({orgName:e,repoName:t,wref:r,ttlMs:i?.ttlMs})}catch(o){throw a(o)}},releaseLease:async(e,t,r,i)=>{try{await this.trpc.thing.releaseLease.mutate({orgName:e,repoName:t,wref:r,leaseId:i});}catch(o){throw a(o)}},graph:async(e,t,r,i)=>{try{return await this.trpc.thing.graph.query({orgName:e,repoName:t,wref:r,version:i?.version,depth:i?.depth,limit:i?.limit})}catch(o){throw a(o)}},getMany:async(e,t,r,i,o)=>{try{if(r.length===0)return {requested:0,items:[],missing:[]};let s=ue(o?.chunkSize,ft,Rt),p=ue(o?.chunkConcurrency,bt,Ct),c=async g=>await this.trpc.thing.getMany.query({orgName:e,repoName:t,wrefs:g,version:i,includeRetracted:o?.includeRetracted,dataMode:o?.dataMode});if(r.length<=s)return await c(r);let u=It(r,s),l=[];for(let g=0;g<u.length;g+=p){let h=u.slice(g,g+p),y=await Promise.all(h.map(c));l.push(...y);}return {requested:r.length,items:l.flatMap(g=>g.items),missing:l.flatMap(g=>g.missing)}}catch(s){throw a(s)}},headVersions:async(e,t,r,i)=>{try{if(r.length===0)return {requested:0,items:[],missing:[]};let o=ue(i?.chunkSize,ft,Rt),s=ue(i?.chunkConcurrency,bt,Ct),p=async l=>await this.trpc.thing.headVersions.query({orgName:e,repoName:t,wrefs:l});if(r.length<=o)return await p(r);let c=It(r,o),u=[];for(let l=0;l<c.length;l+=s){let g=c.slice(l,l+s),h=await Promise.all(g.map(p));u.push(...h);}return {requested:r.length,items:u.flatMap(l=>l.items),missing:u.flatMap(l=>l.missing)}}catch(o){throw a(o)}},history:async(e,t,r)=>{try{return await this.trpc.thing.history.query({orgName:e,repoName:t,wref:r.wref,shape:r.shape,about:r.about,includeRetracted:r.includeRetracted,resolveCollections:r.resolveCollections,match:r.match,limit:r.limit,cursor:r.cursor})}catch(i){throw a(i)}},historyIter:(e,t,r)=>C(i=>this.thing.history(e,t,{...r,cursor:i}),i=>i.versions,r.cursor),historyAll:async(e,t,r)=>{let{max:i,...o}=r;return await w(s=>this.thing.history(e,t,{...o,cursor:s}),s=>s.versions,i,o.cursor)},rename:async(e,t,r,i,o,s)=>{try{return await this.trpc.thing.rename.mutate({orgName:e,repoName:t,shapeName:r,oldName:i,newName:o,eventRequestId:s.eventRequestId})}catch(p){throw a(p)}},resolve:async(e,t,r)=>{try{return await this.trpc.thing.resolve.query({orgName:e,repoName:t,wref:r})}catch(i){throw a(i)}},about:async(e,t,r,i)=>{try{return await this.trpc.thing.about.query({orgName:e,repoName:t,wref:r,shape:i?.shape,match:i?.match,includeRetracted:i?.includeRetracted,depth:i?.depth,resolveCollections:i?.resolveCollections,role:i?.role,limit:i?.limit,cursor:i?.cursor,where:i?.where})}catch(o){throw a(o)}},aboutIter:(e,t,r,i)=>C(o=>this.thing.about(e,t,r,{...i,cursor:o}),o=>o.assertions,i?.cursor),aboutAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.thing.about(e,t,r,{...s,cursor:p}),p=>p.assertions,o,s.cursor)},query:async(e,t,r)=>{try{return await this.trpc.thing.query.query({orgName:e,repoName:t,shape:r?.shape,about:r?.about,affirmedAbout:r?.affirmedAbout,kind:le(r?.kind),match:r?.match,includeRetracted:r?.includeRetracted,resolveCollections:r?.resolveCollections,role:r?.role,limit:r?.limit,cursor:r?.cursor,componentRef:r?.componentRef,excludeComponents:r?.excludeComponents,excludeInfraShapes:r?.excludeInfraShapes,where:r?.where,sinceRepoSeq:r?.sinceRepoSeq})}catch(i){throw a(i)}},queryIter:(e,t,r)=>C(i=>this.thing.query(e,t,{...r,cursor:i}),i=>i.items,r?.cursor),queryAll:async(e,t,r)=>{let{max:i,...o}=r??{};return await w(s=>this.thing.query(e,t,{...o,cursor:s}),s=>s.items,i,o.cursor)},queryChanges:async(e,t,r)=>(wt(r?.sinceRepoSeq),await Ot(i=>this.thing.query(e,t,{...r,includeRetracted:true,cursor:i}))),search:async(e,t,r,i)=>{try{return await this.trpc.thing.search.query({orgName:e,repoName:t,query:r,shape:i?.shape,about:i?.about,affirmedAbout:i?.affirmedAbout,kind:le(i?.kind),match:i?.match,includeRetracted:i?.includeRetracted,resolveCollections:i?.resolveCollections,limit:i?.limit,cursor:i?.cursor,componentRef:i?.componentRef,excludeComponents:i?.excludeComponents,excludeInfraShapes:i?.excludeInfraShapes,mode:i?.mode,nameMatch:i?.nameMatch})}catch(o){throw a(o)}},searchIter:(e,t,r,i)=>C(o=>this.thing.search(e,t,r,{...i,cursor:o}),o=>o.items,i?.cursor),searchAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.thing.search(e,t,r,{...s,cursor:p}),p=>p.items,o,s.cursor)},count:async(e,t,r)=>{try{return await this.trpc.thing.count.query({orgName:e,repoName:t,shape:r?.shape,about:r?.about,affirmedAbout:r?.affirmedAbout,kind:le(r?.kind),match:r?.match,includeRetracted:r?.includeRetracted,resolveCollections:r?.resolveCollections,componentRef:r?.componentRef,excludeComponents:r?.excludeComponents,excludeInfraShapes:r?.excludeInfraShapes,where:r?.where,sinceRepoSeq:r?.sinceRepoSeq})}catch(i){throw a(i)}},refs:async(e,t,r,i)=>{try{return await this.trpc.thing.refs.query({orgName:e,repoName:t,wref:r,direction:i?.direction,fieldPath:i?.fieldPath,limit:i?.limit,cursor:i?.cursor})}catch(o){throw a(o)}},refsIter:(e,t,r,i)=>C(o=>this.thing.refs(e,t,r,{...i,cursor:o}),o=>o.items,i?.cursor),refsAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.thing.refs(e,t,r,{...s,cursor:p}),p=>p.items,o,s.cursor)}};live={thingHead:async(e,t,r,i)=>this.watchRepoQuery(e,t,r?.signal,()=>this.thing.head(e,t,{shape:r?.shape,kind:r?.kind,match:r?.match,dataMode:r?.dataMode,limit:r?.limit,cursor:r?.cursor,includeRetracted:r?.includeRetracted,where:r?.where}),i),thingHistory:async(e,t,r,i)=>this.watchRepoQuery(e,t,r.signal,()=>this.thing.history(e,t,{wref:r.wref,limit:r.limit,cursor:r.cursor,includeRetracted:r.includeRetracted}),i),subscriptionLog:async(e,t,r,i,o)=>this.watchRepoQuery(e,t,i?.signal,()=>this.action.liveFeed(e,t,r,{limit:i?.limit,cursor:i?.cursor}),o),subscribe:async(e,t,r,i)=>{let o=new AbortController,s=Et(r?.signal,o),p=0,c=(async()=>{let u=await this.trpc.live.issueTicket.mutate({orgName:e,repoName:t}),l=await this.openSse(u.ticket,s,async g=>{if(g.type!=="invalidate")return;let h=g.data;p++,await i({topic:h.topic,affectedShapes:h.affectedShapes,affectedThings:h.affectedThings,affectedTargets:h.affectedTargets,hasNewCommit:h.hasNewCommit});});return await l.ready,s.aborted?{updates:p}:(await l.closed,{updates:p})})();return {close(){o.abort();},closed:c}}};token={create:async e=>{try{return await this.trpc.token.create.mutate(e)}catch(t){throw a(t)}},list:async e=>{try{return await this.trpc.token.list.query(e?.includeInactive?{includeInactive:!0}:void 0)}catch(t){throw a(t)}},get:async e=>{try{return await this.trpc.token.get.query({name:e})}catch(t){throw a(t)}},revoke:async e=>{try{return await this.trpc.token.revoke.mutate({name:e})}catch(t){throw a(t)}}};stream={append:async e=>{try{return await this.trpc.stream.append.mutate(e)}catch(t){throw a(t)}}};credential={createSet:async(e,t,r,i)=>{try{return await this.trpc.credential.createSet.mutate({orgName:e,repoName:t,name:r,scope:i?.scope??"repo",description:i?.description})}catch(o){throw a(o)}},listSets:async(e,t)=>{try{return await this.trpc.credential.listSets.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getSet:async(e,t,r)=>{try{return await this.trpc.credential.getSet.query({orgName:e,repoName:t,name:r})}catch(i){throw a(i)}},setKey:async(e,t,r,i,o)=>{try{return await this.trpc.credential.setKey.mutate({orgName:e,repoName:t,setName:r,keyName:i,value:o})}catch(s){throw a(s)}},setKeys:async(e,t,r,i)=>{try{return await this.trpc.credential.setKeys.mutate({orgName:e,repoName:t,setName:r,secrets:i})}catch(o){throw a(o)}},unsetKey:async(e,t,r,i)=>{try{return await this.trpc.credential.unsetKey.mutate({orgName:e,repoName:t,setName:r,keyName:i})}catch(o){throw a(o)}},deleteSet:async(e,t,r)=>{try{return await this.trpc.credential.deleteSet.mutate({orgName:e,repoName:t,setName:r})}catch(i){throw a(i)}},listAuditLog:async(e,t,r,i)=>{try{return await this.trpc.credential.listAuditLog.query({orgName:e,repoName:t,setName:r,limit:i?.limit})}catch(o){throw a(o)}},revokeSet:async(e,t,r,i)=>{try{return await this.trpc.credential.revokeSet.mutate({orgName:e,repoName:t,setName:r,reason:i?.reason})}catch(o){throw a(o)}}};credentials=this.credential;constructor(e,t){let r=typeof e=="string"?t:e;Or(r);let i=typeof e=="string"?e:e?.apiUrl??Le;if(this.apiUrl=i,this.fetchImpl=r?.fetch,this.accessToken=r?.accessToken??r?.auth?.getToken,this.functionLogMode=r?.functionLogs??"off",this.clientIdentity={name:r?.client?.name??f,version:r?.client?.version??Ee},this.clientFlags=Ir(r?.clientFlags),typeof this.accessToken=="function"){let p=this.accessToken;this.getToken=async()=>await p();}else if(this.accessToken){let p=this.accessToken;this.getToken=async()=>p;}let o=`${i.replace(/\/$/,"")}/trpc`,s=((p,c)=>this.fetchWithAuth(p,c));Object.defineProperty(this,"trpc",{value:createTRPCProxyClient({links:[this.createCompatibilityLink(),splitLink({condition:p=>Ar.has(p.path),true:httpLink({url:o,fetch:s,methodOverride:"POST"}),false:httpBatchLink({url:o,fetch:s,methodOverride:"POST"})})]}),enumerable:false,writable:false,configurable:true});}withAccessToken(e){return new n({apiUrl:this.apiUrl,fetch:this.fetchImpl,accessToken:e,client:this.clientIdentity,clientFlags:this.clientFlags})}actions=this.action;async openSse(e,t,r){let i=await this.fetchWithAuth(`${this.apiUrl.replace(/\/$/,"")}/sse?ticket=${encodeURIComponent(e)}`,{headers:{accept:"text/event-stream"},signal:t});if(!i.ok)throw new m("BACKEND",`SSE request failed with status ${i.status}`,i.status);let o=i.body?.getReader();if(!o)throw new m("BACKEND","SSE response body is missing");let s=()=>{},p=new Promise(u=>{s=u;}),c=(async()=>{let u=new TextDecoder,l="";try{for(;;){let{done:g,value:h}=await o.read();if(g)break;for(l+=u.decode(h,{stream:!0}).replaceAll(`\r
1
+ import {C as C$1,m as m$1,p,n,o,q,M as M$1,B,t,u,b,f,e,i,a as a$1,d,l,A as A$1,x as x$1,O,N as N$1,j,c,k,g,h}from'./chunk-CC45V5YE.js';import {TRPCClientError,createTRPCProxyClient,splitLink,httpBatchLink,httpLink}from'@trpc/client';import {observable}from'@trpc/server/observable';var qt=new Set(["arc","bond","pair","set","list"]);function H(n,e){let t=Ke(n,e,"add");return {operation:"add",kind:"collection",name:t.name,type:t.type,members:t.members,...n.skipExisting===true?{skipExisting:true}:{}}}function ee(n,e){let t=Ke(n,e,"revise");if(!t.name)throw new Error(`${e}: collection revise requires a target name`);return {operation:"revise",kind:"collection",name:t.name,type:t.type,members:t.members,...typeof n.expectedVersion=="number"?{expectedVersion:n.expectedVersion}:{},...typeof n.leaseId=="string"&&n.leaseId.length>0?{leaseId:n.leaseId}:{}}}function Ke(n,e,t){let r=B({operation:t,kind:"collection",name:typeof n.name=="string"?n.name:void 0,type:typeof n.type=="string"?n.type:void 0,members:Array.isArray(n.members)?n.members:void 0},0);if(r.length>0)throw new Error(`${e}: ${r.map(s=>s.message).join("; ")}`);let i=Ut(n.type);if(!i)throw new Error(`${e}: collection ${t} requires 'type'. Use one of: arc, bond, set, list`);if(!Array.isArray(n.members))throw new Error(`${e}: collection ${t} requires a 'members' array`);let o=Vt(n.name);if(!o)throw new Error(`${e}: collection ${t} name must be a non-empty string`);return Bt(n,e,t),{name:o,type:i,members:n.members}}function Bt(n,e,t){let r=["about","aboutWref","shapeWref","data",...t==="revise"?["skipExisting"]:[]].filter(i=>n[i]!==void 0);if(r.length>0)throw new Error(`${e}: collection ${t} does not support ${r.map(i=>`'${i}'`).join(", ")}`)}function Ut(n){if(typeof n!="string")return;let e=n.trim();if(qt.has(e))return e}function Vt(n){if(typeof n=="string"&&!(n.length===0||n.trim()!==n))return n}function E(n){if(n.expectedVersion!==void 0&&n.operation!=="revise"&&n.operation!=="retract"&&n.operation!=="reaffirm")throw new Error("expectedVersion is only valid on revise, retract, or reaffirm operations \u2014 set an explicit operation discriminator");if(n.operation==="retract")return {operation:"retract",name:n.name,...n.kind?{kind:n.kind}:{},...n.reason?{reason:n.reason}:{},...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.leaseId?{leaseId:n.leaseId}:{}};if(n.operation==="reaffirm")return {operation:"reaffirm",name:n.name,...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.kind?{kind:n.kind}:{},...n.add?{add:n.add}:{},...n.remove?{remove:n.remove}:{},...n.leaseId?{leaseId:n.leaseId}:{}};if(n.operation==="rename")return {operation:"rename",name:n.name,newName:n.newName,...n.kind?{kind:n.kind}:{}};if(n.operation==="revise"){let r=n.name??n.wref;if(!r)throw new Error("revise operation requires a target");let i=l({kind:n.kind,name:r});if(Object.hasOwn(n,"active"))throw new Error(`${i} revise operation no longer supports 'active' \u2014 use retract('${r}') instead`);if(i!=="assertion"&&n.affirmedTargets!==void 0)throw new Error(`${i} revise operation does not support 'affirmedTargets' \u2014 it applies only to assertions; set kind: 'assertion' explicitly`);if(i==="collection")return ee(n,"commit.apply");if(n.data===void 0)throw new Error(`${i} revise operation requires 'data'`);return i==="assertion"?{operation:"revise",kind:"assertion",name:r,data:n.data,...n.affirmedTargets?{affirmedTargets:n.affirmedTargets}:{},...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.leaseId?{leaseId:n.leaseId}:{}}:{operation:"revise",kind:i,name:r,data:n.data,...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.leaseId?{leaseId:n.leaseId}:{}}}let e=l(n),t="skipExisting"in n?n.skipExisting:void 0;if(e!=="collection"&&("type"in n&&n.type!==void 0||"members"in n&&n.members!==void 0))throw new Error(`add operation '${n.name??""}' has collection fields but resolved kind '${e}' \u2014 collection adds require both 'type' and 'members', or set kind: 'collection'`);if(e!=="assertion"&&n.affirmedTargets!==void 0)throw new Error(`${e} add operation does not support 'affirmedTargets' \u2014 it applies only to assertions; set kind: 'assertion' explicitly`);if(e==="collection")return H({...n,skipExisting:t},"commit.apply");if(!n.name)throw new Error("add operation requires a name");if(e==="assertion"){if(!("about"in n)||n.about===void 0)throw new Error("assertion add operation requires 'about'");if(typeof n.about!="string")throw new Error(A$1);if(n.data===void 0)throw new Error("assertion add operation requires 'data'");return {operation:"add",kind:"assertion",name:n.name,about:n.about,data:n.data,...n.affirmedTargets?{affirmedTargets:n.affirmedTargets}:{},...t===true?{skipExisting:t}:{}}}if(n.data===void 0)throw new Error(`${e} add operation requires 'data'`);return {operation:"add",kind:e,name:n.name,data:n.data,...t===true?{skipExisting:t}:{}}}var Ht=1e4,Ft=4*1024*1024,be=class extends Error{code="VALIDATION_ERROR";status=400;constructor(e){super(e),this.name="WarmHubError";}};function Ce(n,e){return n.map((t,r)=>{let i;try{i=E(t);}catch(o){let s=o instanceof Error?o.message:String(o);throw new be(`Invalid operation at index ${r}: ${s}`)}return e===true&&i.operation==="add"?{...i,skipExisting:true}:i})}function Wt(n,e,t,r){return {orgName:n,repoName:e,...r?.committer!==void 0?{committer:r.committer}:{},...r?.message!==void 0?{message:r.message}:{},...r?.componentRef!==void 0?{componentRef:r.componentRef}:{},operations:Ce(t,r?.skipExisting),...r?.includeWouldBeBody!==void 0?{includeWouldBeBody:r.includeWouldBeBody}:{}}}function ze(n){return JSON.stringify(n)}function $t(n){return new TextEncoder().encode(ze(n)).byteLength}function je(n,e){return {create:async(t,r,i)=>{try{return await n().grant.create.mutate({orgName:t,repoName:r,...i})}catch(o){throw e(o)}},get:async(t,r,i)=>{try{return await n().grant.get.query({orgName:t,repoName:r,grantId:i})}catch(o){throw e(o)}},list:async(t,r,i)=>{try{return await n().grant.list.query({orgName:t,repoName:r,limit:i?.limit,cursor:i?.cursor})}catch(o){throw e(o)}},revoke:async(t,r,i,o)=>{try{return await n().grant.revoke.mutate({orgName:t,repoName:r,grantId:i,reason:o?.reason})}catch(s){throw e(s)}}}}function te(n){return {...n,createdAt:new Date(n.createdAt),updatedAt:new Date(n.updatedAt),runStartedAt:new Date(n.runStartedAt),...n.state==="complete"||n.state==="failed"?{completedAt:new Date(n.completedAt)}:{}}}function Gt(n){return {...n,expiresAt:new Date(n.expiresAt)}}function Ye(n){if(typeof n.checkpointId=="string"&&typeof n.repoSeq!="number")return {by:"id",checkpointId:n.checkpointId};if(typeof n.repoSeq=="number"&&typeof n.checkpointId!="string")return {by:"repoSeq",repoSeq:n.repoSeq};throw new TypeError("Repository checkpoint selector must contain exactly one of checkpointId or repoSeq")}function Qe(n,e){return {generate:async(t,r,i)=>{try{let o=await n().repo.checkpoint.generate.mutate({orgName:t,repoName:r,atLeastRepoSeq:i?.atLeastRepoSeq});return te(o.checkpoint)}catch(o){throw e(o)}},status:async(t,r,i)=>{try{let o=await n().repo.checkpoint.status.query({orgName:t,repoName:r,selector:Ye(i)});return te(o)}catch(o){throw e(o)}},latest:async(t,r)=>{try{let i=await n().repo.checkpoint.latest.query({orgName:t,repoName:r});return i.checkpoint?te(i.checkpoint):null}catch(i){throw e(i)}},getAccess:async(t,r,i)=>{try{let o=await n().repo.checkpoint.access.query({orgName:t,repoName:r,selector:i.checkpoint==="latest"?{by:"latest"}:Ye(i.checkpoint),artifact:i.artifact==="archive"||i.artifact==="manifest"?{kind:i.artifact}:{kind:"chunk",path:i.artifact.chunkPath}});return Gt(o)}catch(o){throw e(o)}},retry:async(t,r,i)=>{try{let o=await n().repo.checkpoint.retry.mutate({orgName:t,repoName:r,checkpointId:i});return te(o.checkpoint)}catch(o){throw e(o)}}}}function F(n,e,t){let r=O(e,t==="revise"?{allowUnsafeFieldNamePaths:N$1(e)}:void 0);return r.valid?null:`Invalid shape definition for "${n}": ${r.errors.join("; ")}`}function Kt(n,e,t){let r=n.operation===void 0||n.operation==="noop"?t?.operation??"add":n.operation,i={opIndex:e,name:n.name??"",operation:r,...n.affirmations?{affirmations:n.affirmations}:{},...n.resolvedName!==void 0?{resolvedName:n.resolvedName}:{},...n.warnings?{warnings:n.warnings}:{}};return n.status==="failed"?{...i,status:"error",errors:[{code:n.error?.code??"BACKEND",message:n.error?.message??`Operation on "${n.name}" failed`,...n.error?.details?{details:n.error.details}:{},...n.retryable!==void 0?{retryable:n.retryable}:{}}],...t?.name!==void 0?{submittedName:t.name}:{}}:{...i,status:n.status==="noop"||n.operation==="noop"?"noop":"applied",...n.version!==void 0?{version:n.version}:{},...n.dataHash!==void 0?{dataHash:n.dataHash}:{}}}var N=class{receipts=[];operations=[];statusCounts={applied:0,noop:0,error:0};get allFailed(){return this.operations.length>0&&this.statusCounts.error===this.operations.length}addChunk(e){if(e.result.schemaVersion==="operation-event-receipt/v2"){e.result.results.forEach(t=>{this.statusCounts[t.status]++,this.operations.push({...t,opIndex:e.chunkStart+t.opIndex});});return}e.result.results.forEach((t,r)=>{let i=t.opIndex??r,o=e.submittedOperations[i],s=Kt(t,e.chunkStart+i,o);this.statusCounts[s.status]++,this.operations.push(s);});}addReceipt(e){this.receipts.push(e);}completedOperations(){return this.operations.filter(e=>e.status!=="error")}toResult(e){let t=this.statusCounts.error>0;return {...e.committer!==void 0?{committer:e.committer}:{},...e.createdByEmail!==void 0?{createdByEmail:e.createdByEmail}:{},message:e.message,operationCount:this.operations.length,...e.repoSeq!==void 0?{repoSeq:e.repoSeq}:{},...t?{partial:t,statusCounts:{...this.statusCounts}}:{},operations:this.operations,receipts:this.receipts}}};var zt="003e7e6c-2f1e-53ea-9dfa-627edd04a8cc",jt=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;function Je(n){if(!jt.test(n))throw new Error("Operation-event submission ID must be a canonical UUID");let e=n.toLowerCase().replaceAll("-","");return Uint8Array.from({length:16},(t,r)=>Number.parseInt(e.slice(r*2,r*2+2),16))}function we(n,e){return (n<<e|n>>>32-e)>>>0}function Yt(n){let e=n.length*8,t=Math.ceil((n.length+9)/64)*64,r=new Uint8Array(t);r.set(n),r[n.length]=128;let i=new DataView(r.buffer);i.setUint32(t-8,Math.floor(e/4294967296)),i.setUint32(t-4,e>>>0);let o=1732584193,s=4023233417,p=2562383102,c=271733878,u=3285377520,l=new Uint32Array(80);for(let y=0;y<t;y+=64){for(let f=0;f<16;f+=1)l[f]=i.getUint32(y+f*4);for(let f=16;f<80;f+=1)l[f]=we(l[f-3]^l[f-8]^l[f-14]^l[f-16],1);let S=o,d=s,R=p,O=c,b=u;for(let f=0;f<80;f+=1){let q,B;f<20?(q=d&R|~d&O,B=1518500249):f<40?(q=d^R^O,B=1859775393):f<60?(q=d&R|d&O|R&O,B=2400959708):(q=d^R^O,B=3395469782);let Mt=we(S,5)+q+b+B+l[f]>>>0;b=O,O=R,R=we(d,30),d=S,S=Mt;}o=o+S>>>0,s=s+d>>>0,p=p+R>>>0,c=c+O>>>0,u=u+b>>>0;}let g=new Uint8Array(20),h=new DataView(g.buffer);for(let[y,S]of [o,s,p,c,u].entries())h.setUint32(y*4,S);return g}function Qt(n){let e=Array.from(n,t=>t.toString(16).padStart(2,"0")).join("").slice(0,32);return `${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}function re(){let n=globalThis.crypto?.randomUUID?.();if(!n)throw new Error("This runtime cannot mint a cryptographically secure UUID");return n.toLowerCase()}var Jt=re;function Se(n,e){if(!Number.isInteger(e)||e<0||e>2147483647)throw new Error("Stream chunk ordinal must be an integer from 0 through 2147483647");Je(n);let t=n.toLowerCase(),r=Je(zt),i=new TextEncoder().encode(`${t}:${e}`),o=Yt(Uint8Array.from([...r,...i])).slice(0,16);return o[6]=o[6]&15|80,o[8]=o[8]&63|128,Qt(o)}var ne=1e3,ie=1e4,A=class extends Error{code="PARTIAL_STREAM_SUBMISSION";completedReceipts;completedOperations;submissionId;eventRequestId;chunkOrdinal;pendingOutcome;acknowledgedOperationCount;lastAcknowledgedRepoSeq;attemptedAppendOutcome;cause;constructor(e){super(e.pendingOutcome==="unknown"?`Stream submission outcome is unknown for event request ${e.eventRequestId}. Look up its immutable receipt before retrying.`:`Stream submission stopped at event request ${e.eventRequestId} after earlier chunks committed.`),this.name="WarmHubError",this.cause=e.cause,this.completedReceipts=e.completedReceipts,this.completedOperations=e.completedOperations??[],this.submissionId=e.submissionId,this.eventRequestId=e.eventRequestId,this.chunkOrdinal=e.chunkOrdinal,this.pendingOutcome=e.pendingOutcome,this.acknowledgedOperationCount=e.acknowledgedOperationCount??e.completedReceipts.length,this.attemptedAppendOutcome=e.attemptedAppendOutcome,e.lastAcknowledgedRepoSeq!==void 0&&(this.lastAcknowledgedRepoSeq=e.lastAcknowledgedRepoSeq);}},v=class extends Error{code="STREAM_ALL_OPERATIONS_FAILED";receipts;result;operations;statusCounts;cause;constructor(e){let t=e.operations.find(r=>r.status==="error")?.errors[0];super(t?`All ${e.operationCount} stream operations failed: ${t.message}`:`All ${e.operationCount} stream operations failed.`),this.name="WarmHubError",this.cause=t,this.result=e,this.receipts=e.receipts,this.operations=e.operations,this.statusCounts=e.statusCounts??{applied:0,noop:0,error:e.operationCount};}};function Oe(n){let e="status"in n?n.status:void 0;return e==="failed"||e==="error"?"error":e==="noop"||n.operation==="noop"?"noop":"applied"}function et(n){let e={applied:0,noop:0,error:0};for(let t of n)e[Oe(t)]++;return e}var Xt={maxAttempts:3,baseDelayMs:250,maxDelayMs:8e3},Zt=10,Xe=6e4;function Ie(n){if(n===false)return false;let e={};n!==void 0&&(Number.isFinite(n.maxAttempts)&&(e.maxAttempts=n.maxAttempts),Number.isFinite(n.baseDelayMs)&&(e.baseDelayMs=n.baseDelayMs),Number.isFinite(n.maxDelayMs)&&(e.maxDelayMs=n.maxDelayMs));let t={...Xt,...e};return {maxAttempts:Math.min(Zt,Math.max(1,Math.trunc(t.maxAttempts))),baseDelayMs:Math.min(Xe,Math.max(0,Math.trunc(t.baseDelayMs))),maxDelayMs:Math.min(Xe,Math.max(0,Math.trunc(t.maxDelayMs)))}}var er=new Set(["BAD_REQUEST","METHOD_NOT_SUPPORTED","PARSE_ERROR","PAYLOAD_TOO_LARGE","PRECONDITION_FAILED","UNAUTHORIZED","UNPROCESSABLE_CONTENT","UNSUPPORTED_MEDIA_TYPE","UNAUTHENTICATED","FORBIDDEN","VALIDATION_ERROR","SHAPE_MISMATCH","RESERVED_NAME","ILLEGAL_OP_SEQUENCE","NOT_FOUND","KIND_MISMATCH","CONFLICT","ALREADY_RETRACTED","ARCHIVED","RATE_LIMITED","TOO_MANY_REQUESTS","UNRESOLVED_TOKEN"]),tr=new Set(["COMMIT_OUTCOME_UNKNOWN"]);function tt(n){if(!n||typeof n!="object")return;let e=n.code;if(typeof e=="string")return e;let t=n.data,r=t?.warmhub?.code;if(typeof r=="string")return r;let i=t?.code;if(typeof i=="string")return i}function rr(n){if(!n||typeof n!="object")return;let e=n.data?.httpStatus;if(typeof e=="number")return e;let t=n.data?.warmhub?.status;if(typeof t=="number")return t;let r=n.status;return typeof r=="number"?r:void 0}function nr(n){return n!==void 0&&n>=400&&n<500&&n!==408}function rt(n){let e=tt(n);return e!==void 0&&tr.has(e)}function W(n){if(rt(n))return false;let e=tt(n);return e!==void 0&&er.has(e)||nr(rr(n))}function Ae(n){if(rt(n)||W(n))return false;if(Ze(n))return true;if(n instanceof TypeError||n instanceof SyntaxError)return false;let e=n?.cause;return Ze(e)?true:!(e instanceof TypeError||e instanceof SyntaxError)}function Ze(n){return n instanceof TypeError&&/fetch/i.test(n.message)}function ke(n,e){let t=e.baseDelayMs*2**Math.max(0,n-1),r=Math.random()*e.baseDelayMs;return Math.min(e.maxDelayMs,t+r)}function ve(n){return new Promise(e=>setTimeout(e,n))}var $=class extends Error{code;status=400;constructor(e,t="VALIDATION_ERROR"){super(e),this.code=t,this.name="WarmHubError";}},oe=class extends Error{constructor(t){super("operation source failed");this.reason=t;}reason};async function P(n,e){let t=ar(e.chunkSize),r=e.submissionId??re(),i=e.streamId??r,o=Ie(e.retry),s=new N,p=[],c,u,l=0,g,h=0,y=d=>new A({cause:d.cause,completedReceipts:s.receipts,completedOperations:s.completedOperations(),acknowledgedOperationCount:l,lastAcknowledgedRepoSeq:g,attemptedAppendOutcome:d.pendingOutcome==="absent"?"not_applied":"unknown",submissionId:r,eventRequestId:Se(r,h),chunkOrdinal:h,pendingOutcome:d.pendingOutcome});try{for await(let d of ir(e.operations,t,e.skipExisting===!0)){let R=1,O=!1;for(;;)try{let b=await n.stream.append({allocatedTokenRanges:p,chunkOrdinal:h,orgName:e.orgName,repoName:e.repoName,streamId:i,submissionId:r,componentRef:e.componentRef,committer:e.committer,message:e.message,...e.returnRepoSeq!==void 0?{returnRepoSeq:e.returnRepoSeq}:{},operations:d.operations});s.addReceipt(b.receipt),p=b.allocatedTokenRanges,c=b.createdByEmail??c,u=b.repoSeq??u,s.addChunk({result:b,chunkStart:d.start,submittedOperations:d.operations}),l+=d.operations.length;let f=or(b.receipt);f!==void 0&&(g=f);break}catch(b){let f=W(b);if(s.receipts.length===0&&!O&&f)throw b;if(o!==!1&&R<o.maxAttempts&&Ae(b)){await ve(ke(R,o)),R+=1,O=!0;continue}throw y({cause:b,pendingOutcome:O||!f?"unknown":"absent"})}h+=1;}}catch(d){throw d instanceof oe?s.receipts.length===0?d.reason:y({cause:d.reason,pendingOutcome:"absent"}):d}if(h===0)throw new $("At least one operation is required for stream submission.");let S=s.toResult({committer:e.committer,createdByEmail:c,message:e.message,repoSeq:u});if(s.allFailed)throw new v(S);return S}async function*ir(n,e,t){try{if(Array.isArray(n)){let o=n.map((s,p)=>it(s,p,t));ot(o,0);for(let s=0;s<o.length;s+=e)yield {operations:o.slice(s,s+e),start:s};return}let r=0,i=[];for await(let o of n)i.push(it(o,r,t)),r+=1,!(i.length<e)&&(yield nt(i,r),i=[]);i.length>0&&(yield nt(i,r));}catch(r){throw new oe(r)}}function nt(n,e){let t=e-n.length;return ot(n,t),{operations:n,start:t}}function it(n,e,t){let r;try{r=E(n);}catch(i){let o=i instanceof Error?i.message:String(i);throw new $(`Invalid operation at index ${e}: ${o}`)}return t&&r.operation==="add"?{...r,skipExisting:true}:r}function or(n){let e=n.event?.repoSeq;if(e===void 0)return;let t=Number(e);return Number.isSafeInteger(t)?t:void 0}function ot(n,e){let t=C$1(n).find(r=>!sr(r));if(t)throw new $(`Invalid operation at index ${e+t.operationIndex}: ${t.message}`,t.code)}function sr(n){return n.code==="ILLEGAL_OP_SEQUENCE"&&n.message.includes("Cannot revise then add ")}function ar(n){return Number.isFinite(n)?Math.max(1,Math.min(ie,Math.trunc(n))):ne}var cr="0.0.0-development";function L(n){return n===cr}var Ee="0.93.0";var st=1;function pr(n){return n===g?"Run: wh update --yes":n===f?"Run: npm install @warmhub/sdk-ts@latest (or your package manager's equivalent).":n===h?"Run: pip install --upgrade warmhub":`Deploy a released ${n} build that satisfies the backend compatibility contract.`}function at(n,e){if(typeof n?.minSupportedClients!="object"||n.minSupportedClients===null||!Number.isSafeInteger(n.writeContractVersion)||n.writeContractVersion<1)return {message:"The backend does not advertise valid per-client write compatibility data.",hint:"Upgrade the WarmHub backend before retrying this write."};let t$1=n.minSupportedClients[e.name],r=typeof t$1=="string"?t(t$1):null;if(!r)return {message:`The backend does not advertise a valid compatibility floor for ${e.name}.`,hint:"Upgrade the WarmHub backend or register this first-party client family before writing."};if(!L(e.version)){let i=t(e.version);if(!i)return {message:`${e.name} reported malformed version "${e.version}".`,hint:"Use a released WarmHub client with a SemVer package version."};if(u(i,r)<0)return {message:`${e.name} ${e.version} is older than the backend's minimum supported version ${r}.`,hint:pr(e.name)}}if(n.writeContractVersion<st)return {message:`${e.name} requires write contract ${st}, but the backend provides ${n.writeContractVersion}.`,hint:"Upgrade the WarmHub backend before retrying this write."}}function xe(n,e){try{return new URL(n).origin===new URL(e).origin}catch{return false}}var ur=new Set(["GET","POST","PUT","PATCH","DELETE"]),I=class extends Error{reason;constructor(e,t){super(t),this.name="CliCallVerificationError",this.reason=e;}};async function lr(n$1,e,t){let r=n$1.method.toUpperCase();if(!ur.has(r))throw new I("unsupported-method",`Unsupported HTTP method "${n$1.method}" \u2014 component CLI dispatch only emits GET, POST, PUT, or PATCH`);let i=r,o$1=n$1.headers.get(m$1);if(!o$1)throw new I("missing-install-repo",`Missing ${m$1} header`);let s=D(e.CLI_SIGNING_SECRET),p$1=D(e.CLI_BEARER_TOKEN),c=D(e.CLI_API_KEY),u=D(e.CLI_BASIC_USERNAME)&&D(e.CLI_BASIC_PASSWORD);if(!s&&!p$1&&!c&&!u)throw new I("no-scheme-configured","no-scheme-configured: need at least one of CLI_SIGNING_SECRET, CLI_BEARER_TOKEN, CLI_API_KEY, or CLI_BASIC_USERNAME + CLI_BASIC_PASSWORD");if(p$1&&u)throw new I("no-scheme-configured","unsupported-scheme-combination: CLI_BEARER_TOKEN and CLI_BASIC_USERNAME + CLI_BASIC_PASSWORD both use the Authorization header and cannot be configured together");let l=new URL(n$1.url),g=l.pathname,h,y,S;if(p(i)?h={}:(h=Object.fromEntries(l.searchParams.entries()),y="",S={...h}),s){let d=n$1.headers.get(n);if(!d)throw new I("missing-signature",`Missing ${n} header`);let R=n$1.headers.get(o);if(!R)throw new I("missing-timestamp",`Missing ${o} header`);let O=Number(R);if(!Number.isFinite(O)||!Number.isInteger(O))throw new I("invalid-timestamp",`${o} must be an integer unix seconds value; got "${R}"`);y=await ct(n$1,i,y);let b=await q({secret:e.CLI_SIGNING_SECRET,method:i,path:g,query:h,installRepo:o$1,body:y,signature:d,timestamp:O,nowUnixSeconds:t?.nowUnixSeconds??Math.floor(Date.now()/1e3),toleranceSec:t?.toleranceSec});if(!b.ok)throw new I(b.reason,`HMAC verification failed: ${b.reason}`)}if(p$1){let d=`Bearer ${e.CLI_BEARER_TOKEN}`,R=n$1.headers.get("authorization")??"";if(!await Te(R,d))throw new I("invalid-bearer","invalid-bearer: bearer token mismatch")}if(c){let d=D(e.CLI_API_KEY_HEADER)?e.CLI_API_KEY_HEADER:"X-API-Key",R=n$1.headers.get(d)??"";if(!await Te(R,e.CLI_API_KEY))throw new I("invalid-api-key",`invalid-api-key: mismatch on header "${d}"`)}if(u){let d=`Basic ${btoa(`${e.CLI_BASIC_USERNAME}:${e.CLI_BASIC_PASSWORD}`)}`,R=n$1.headers.get("authorization")??"";if(!await Te(R,d))throw new I("invalid-basic","invalid-basic: basic auth mismatch")}return S===void 0&&(y=await ct(n$1,i,y),S=dr(y)),{method:i,installRepo:o$1,args:S}}async function ct(n,e,t){return p(e)?t!==void 0?t:n.text():""}function dr(n){let e;try{e=JSON.parse(n);}catch{throw new I("invalid-body","POST body is not valid JSON")}if(!mr(e))throw new I("invalid-body","POST body must be a JSON object of primitive args (string / number / boolean)");return e}function D(n){return typeof n=="string"&&n.length>0}function mr(n){if(typeof n!="object"||n===null||Array.isArray(n))return false;for(let e of Object.values(n))if(e!==void 0&&typeof e!="string"&&typeof e!="number"&&typeof e!="boolean")return false;return true}async function Te(n,e){let[t,r]=await Promise.all([pt(n),pt(e)]),i=0;for(let o=0;o<t.length;o++)i|=t[o]^r[o];return i===0}async function pt(n){return new Uint8Array(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n)))}function Ne(n){if(n.includes("/"))return n.split("/")[0]}function lt(n){if("shapeWref"in n&&typeof n.shapeWref=="string")return n.shapeWref;if(n.name)return Ne(n.name)}function _e(n){if(typeof n!="string")return;let e=n.trim();return e.length>0?e:void 0}function M(n){return l({kind:n.kind,name:n.name,about:ce(n),type:se(n),members:ae(n)})}function ce(n){if("about"in n&&n.about!==void 0)return n.about;if("aboutWref"in n)return n.aboutWref}function Pe(n){return "data"in n?n.data:void 0}function se(n){return "type"in n?n.type:void 0}function ae(n){return "members"in n?n.members:void 0}function G(n,e){return l({kind:n.kind,name:e})}function ut(n){return n.data??{}}function dt(n){if(n.operation==="retract")return E(n);if(n.operation==="reaffirm")return E({operation:"reaffirm",name:n.name,...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.kind?{kind:n.kind}:{},...n.add?{add:[...n.add]}:{},...n.remove?{remove:[...n.remove]}:{},...n.leaseId?{leaseId:n.leaseId}:{}});if(n.operation==="add"){let r=M(n);if(r==="collection")return H(n,"OperationBuilder");let i=n,o=ut(i),s=_e(i.name);if(!s)throw new Error("OperationBuilder: add operation missing name");if(r==="assertion"){let p=ce(i);if(p===void 0)throw new Error(`OperationBuilder: assertion add '${s}' missing required 'about'`);if(typeof p!="string")throw new Error(A$1);return {operation:"add",kind:r,name:s,about:p,data:o,...i.affirmedTargets?{affirmedTargets:[...i.affirmedTargets]}:{},...i.skipExisting===true?{skipExisting:true}:{}}}return {operation:"add",kind:r,name:s,data:o,...i.skipExisting===true?{skipExisting:true}:{}}}let e=_e(n.name)??_e(n.wref);if(!e)throw new Error("OperationBuilder: revise operation missing required target ('name' or 'wref')");let t=G(n,e);if(t==="collection")return ee({...n,name:e},"OperationBuilder");if(t==="assertion")return {operation:"revise",kind:t,name:e,data:n.data??{},...n.affirmedTargets?{affirmedTargets:[...n.affirmedTargets]}:{},...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.leaseId?{leaseId:n.leaseId}:{}};if(n.affirmedTargets!==void 0)throw new Error(`OperationBuilder: REVISE '${e}' has affirmedTargets but inferred kind '${t}' \u2014 affirmedTargets applies only to assertions; set kind: 'assertion'`);return {operation:"revise",kind:t,name:e,data:ut(n),...n.expectedVersion!==void 0?{expectedVersion:n.expectedVersion}:{},...n.leaseId?{leaseId:n.leaseId}:{}}}function x(n,e){return n.operation==="add"?{operation:n.operation,kind:e,name:n.name,about:ce(n),type:se(n),members:ae(n)}:{operation:n.operation,kind:e,name:n.name??n.wref,type:se(n),members:ae(n)}}function mt(n){if(n.length!==0)throw new Error(n.join("; "))}function gt(n,e,t,r){let i=[];if((e==="thing"||e==="assertion"||e==="collection"&&n==="REVISE")&&(k(t)||i.push(`${n} ${e} name must be a local path (Shape/name), got: "${t}"`)),e==="shape"&&(n==="ADD"||n==="REVISE")&&r!==void 0){let s=F(t,r,n==="REVISE"?"revise":"add");s&&i.push(s);}return i}function ht(n,e){let t=[];if(n.name&&t.push(...gt("ADD",e,n.name,Pe(n))),e==="assertion"&&ce(n)===void 0&&t.push(`ADD assertion '${n.name}' missing required 'about' \u2014 for hierarchical thing names set kind: 'thing' explicitly`),e!=="collection"&&(se(n)!==void 0||ae(n)!==void 0)&&t.push(`ADD '${n.name}' has collection fields but inferred kind '${e}' \u2014 collection adds require both 'type' and 'members', or set kind: 'collection'`),e!=="assertion"&&"affirmedTargets"in n&&n.affirmedTargets!==void 0&&t.push(`ADD '${n.name}' has affirmedTargets but inferred kind '${e}' \u2014 affirmedTargets applies only to assertions; set kind: 'assertion'`),e==="collection")try{H(n,"OperationBuilder");}catch(r){t.push(r instanceof Error?r.message:String(r));}for(let r of B(x(n,e),0))t.push(r.message);mt(t);}function yt(n,e,t){let r=[];n!=="collection"&&t.data===void 0&&r.push(`OperationBuilder: ${n} revise requires 'data'`),n!=="assertion"&&t.affirmedTargets!==void 0&&r.push(`REVISE '${e}' has affirmedTargets but inferred kind '${n}' \u2014 affirmedTargets applies only to assertions; set kind: 'assertion'`),r.push(...gt("REVISE",n,e,t.data),...B(x({...t,name:e},n),0).map(i=>i.message)),mt(r);}var pe=class{ops=[];pendingNames=new Set;shapes;wrefToShape=new Map;submitted=false;inFlight=false;constructor(e){this.shapes=e?.shapes;}add(e){this.assertCanModify();let t={...e};delete t.operation;let r=lt(t),i=Pe(t);if(this.shapes&&r&&i!==void 0){let c=this.shapes[r];if(c){let u=M$1(i,c);if(!u.valid)throw new Error(`Shape validation failed for '${t.name}' (shape: ${r}): ${u.errors.join("; ")}`)}}let o={operation:"add",...t},s=M(o);(o.name||s==="collection")&&ht(o,s);let p=Object.freeze({operation:"add",...t});return this.ops.push(p),t.name&&(this.pendingNames.add(t.name),r&&this.wrefToShape.set(t.name,r)),this}revise(e){this.assertCanModify();let t={...e};delete t.operation;let r=t.name??t.wref;if(this.shapes&&r&&t.data!==void 0){let o=this.wrefToShape.get(r)??Ne(r);if(o){let s=this.shapes[o];if(s){let p=M$1(t.data,s);if(!p.valid)throw new Error(`Shape validation failed for revise '${r}' (shape: ${o}): ${p.errors.join("; ")}`)}}}if(r){let o=G({...t},r);yt(o,r,{operation:"revise",...t});}let i=Object.freeze({operation:"revise",...t});return this.ops.push(i),this}retract(e){this.assertCanModify();let t=Object.freeze(typeof e=="string"?{operation:"retract",name:e}:{operation:"retract",name:e.name,...e.kind?{kind:e.kind}:{},...e.reason?{reason:e.reason}:{},...e.expectedVersion!==void 0?{expectedVersion:e.expectedVersion}:{},...e.leaseId?{leaseId:e.leaseId}:{}});return this.ops.push(t),this}reaffirm(e){this.assertCanModify();let t=Object.freeze({operation:"reaffirm",name:e.name,...e.expectedVersion!==void 0?{expectedVersion:e.expectedVersion}:{},...e.kind?{kind:e.kind}:{},...e.add?{add:Object.freeze([...e.add])}:{},...e.remove?{remove:Object.freeze([...e.remove])}:{},...e.leaseId?{leaseId:e.leaseId}:{}});return this.ops.push(t),this}get operations(){return Object.freeze([...this.ops])}get size(){return this.ops.length}has(e){return this.pendingNames.has(e)}validate(){let e=[],t=[],r=new Set,i=new Set;for(let c=0;c<this.ops.length;c+=1){let u=this.ops[c];if(u){if(u.operation==="add"){let l=M(u);!u.name&&l!=="collection"?e.push({code:"MISSING_NAME",operationIndex:c,message:`Add operation at index ${c} is missing required 'name' field`}):u.name&&(r.has(u.name)&&e.push({code:"DUPLICATE_NAME",operationIndex:c,message:`Duplicate name '${u.name}' at index ${c} (already added earlier in commit)`}),r.add(u.name));}if(u.operation==="revise"){let l=u.name??u.wref;l?i.has(l)?e.push({code:"REVISE_AFTER_RETRACT",operationIndex:c,message:`Revise at index ${c} targets '${l}' which was already retracted in this commit`}):r.has(l)||t.push({code:"REVISE_UNKNOWN_WREF",operationIndex:c,message:`Revise at index ${c} references '${l}' which was not added in this commit (assuming it exists server-side)`}):e.push({code:"MISSING_WREF",operationIndex:c,message:`Revise operation at index ${c} is missing required target ('name' or 'wref')`});}u.operation==="retract"&&(u.name?i.has(u.name)?t.push({code:"RETRACT_AFTER_RETRACT",operationIndex:c,message:`Retract at index ${c} targets '${u.name}' which was already retracted in this commit`}):(r.has(u.name)||t.push({code:"RETRACT_UNKNOWN_WREF",operationIndex:c,message:`Retract at index ${c} references '${u.name}' which was not added in this commit (assuming it exists server-side)`}),i.add(u.name)):e.push({code:"MISSING_NAME",operationIndex:c,message:`Retract operation at index ${c} is missing required 'name' field`}));}}let o=this.ops.flatMap((c,u)=>{if(c.operation==="add")return B(x(c,M(c)),u);if(c.operation==="revise"){let l=c.name??c.wref;return B(x(c,l?G(c,l):"thing"),u)}return B({operation:"retract",kind:c.kind,name:c.name},u)});for(let c of o)e.push({code:c.code,operationIndex:c.operationIndex,message:c.message});let s=this.ops.flatMap((c,u)=>{if(c.operation==="retract"||c.operation==="reaffirm")return [];if(c.operation==="add")return [{op:x(c,M(c)),operationIndex:u}];let l=c.name??c.wref;return [{op:x(c,l?G(c,l):"thing"),operationIndex:u}]}),p=C$1(s.map(({op:c})=>c),{checkAddAdd:false,sourceOperationIndexes:s.map(({operationIndex:c})=>c)});for(let c of p)e.push({code:c.code,operationIndex:c.operationIndex,message:c.message});return this.ops.length===0&&e.push({code:"EMPTY_COMMIT",operationIndex:-1,message:"OperationBuilder has no operations"}),{valid:e.length===0,errors:e,warnings:t}}async commit(e){if(this.assertNotSubmitted(),this.inFlight)throw new Error("OperationBuilder: stream submission already in flight");let t=this.validate();if(!t.valid){let r=t.errors.map(i=>i.message).join("; ");throw new Error(`OperationBuilder validation failed: ${r}`)}this.inFlight=true;try{let r=this.ops.map(o=>dt(o)),i=await P(e.client,{orgName:e.orgName,repoName:e.repoName,committer:e.committer,message:e.message,chunkSize:e.chunkSize,streamId:e.streamId,submissionId:e.submissionId,returnRepoSeq:e.returnRepoSeq,retry:e.retry,operations:r});return this.submitted=!0,i}catch(r){throw r instanceof A&&(this.submitted=true),r}finally{this.inFlight=false;}}assertNotSubmitted(){if(this.submitted)throw new Error("OperationBuilder: already submitted, cannot modify")}assertCanModify(){if(this.assertNotSubmitted(),this.inFlight)throw new Error("OperationBuilder: stream submission already in flight, cannot modify")}};function ti(n){return n.replace(/@(?:v\d+|HEAD|ALL)$/i,"")}var Tt=["apiUrl","fetch","accessToken","auth","functionLogs","client","clientFlags"],wr=new Set(Tt),Sr=new Set(["token","apiKey","bearer"]);function Or(n){if(n)for(let e of Object.keys(n)){if(wr.has(e))continue;let t=Sr.has(e)?'; did you mean "accessToken"?':`. Valid options are: ${Tt.join(", ")}.`;throw new TypeError(`Unknown WarmHubClient option "${e}"${t}`)}}function Ir(n){if(!n||n.length===0)return [];for(let e of n)if(!c(e))throw new TypeError(`Invalid client flag "${e}": expected lowercase tokens matching [a-z0-9-]+.`);return [...new Set(n)].sort()}var Le="https://api.warmhub.ai",Ar=new Set(["commit.validate","repo.shapeInstanceCounts","thing.getMany","thing.headVersions"]),ft=500,Rt=500,bt=1,Ct=8;function de(n){return {...n,actionContainer:void 0,actionContainerConfig:void 0}}function kr(n){return n.map(e=>de(e))}function _t(n,e,t){if(e===n||t.has(e))throw new m("VALIDATION_ERROR","Paginated result cursor did not advance")}function wt(n){if(n===void 0)throw new m("VALIDATION_ERROR","sinceRepoSeq is required for an incremental read")}async function*Nt(n,e){let t=e,r=new Set;for(;;){t&&r.add(t);let i=await n(t);if(yield i,!i.nextCursor)return;_t(t,i.nextCursor,r),t=i.nextCursor;}}async function*C(n,e,t){for await(let r of Nt(n,t))yield*e(r);}async function w(n,e,t,r){if(t!==void 0&&(!Number.isFinite(t)||Math.trunc(t)!==t||t<0))throw new m("VALIDATION_ERROR","max must be a nonnegative integer");let i=[];for await(let o of Nt(n,r)){let s=e(o);if(t!==void 0&&i.length+s.length>t)throw new m("VALIDATION_ERROR",`Paginated result exceeded max=${t}`);i.push(...s);}return i}function St(n){if(n?.slugs!==void 0)throw new m("VALIDATION_ERROR","repo.explore pagination helpers do not support slugs mode")}async function Ot(n){let e=[],t,r=new Set;for(;;){t&&r.add(t);let i=await n(t);if(e.push(...i.items),!i.nextCursor){if(i.repoSeq===void 0)throw new m("VALIDATION_ERROR","Incremental read completed without repoSeq");return {items:e,repoSeq:i.repoSeq}}_t(t,i.nextCursor,r),t=i.nextCursor;}}function ue(n,e,t){return Number.isFinite(n)?Math.max(1,Math.min(t,Math.trunc(n))):e}function It(n,e){let t=[];for(let r=0;r<n.length;r+=e)t.push(n.slice(r,r+e));return t}function le(n){return n!==void 0&&j.includes(n)?n:void 0}function K(n){let[e,t,r]=n;return typeof e=="string"?{orgName:e,repoName:t,name:r}:e}function vr(n){let[e,t]=n;return typeof e=="string"?{orgName:e,repoName:t}:e}function Er(n){let[e,t,r,i]=n;return typeof e=="string"?{orgName:e,repoName:t,subscriptionName:r,credentialSetName:i}:e}function xr(n){let[e,t,r]=n;return typeof e=="string"?{orgName:e,repoName:t,subscriptionName:r}:e}function Tr(n){let{actionContainer:e,actionContainerConfig:t,...r}=n;return r}function _r(n){let{actionContainer:e,actionContainerConfig:t,...r}=n;return r}function me(n){return !!n&&(!!n.shape||!!n.kind||!!n.about||!!n.match||!!n.componentRef||n.excludeComponents===true||(n.where?.length??0)>0)}function ge(n){return !!n&&(!!n.shape||!!n.about||!!n.match||!!n.componentRef||(n.where?.length??0)>0)}function Pt(n){let e=n.members;return Array.isArray(e)&&e.length>0}function Nr(n){let t=n.replace(/^wh:[^/]+\/[^/]+\//,"").replace(/@(?:HEAD|ALL|v\d+)$/,"").split("/")[0]?.toLowerCase();return t==="arc"||t==="bond"||t==="pair"||t==="set"||t==="list"?t:void 0}function Pr(n,e){if(me(e.query)&&!ge(e.query))throw new m("VALIDATION_ERROR","Selector-backed collection sources require shape, about, match, componentRef, or where; kind and excludeComponents only narrow an existing selector.");if(e.sourceRepo&&!ge(e.query))throw new m("VALIDATION_ERROR","sourceRepo requires a selector-backed collection query");if(e.sourceRepo&&Pt(e))throw new m("VALIDATION_ERROR","sourceRepo cannot be combined with explicit members; use canonical wh:org/repo/... member wrefs or omit sourceRepo.");if(me(e.query)&&n!=="set")throw new m("VALIDATION_ERROR","Selector-backed collection sources are only supported for set collections")}function ri(n){return n??"off"}function Lr(n){switch(n){case "BAD_REQUEST":case "PARSE_ERROR":case "PAYLOAD_TOO_LARGE":case "UNPROCESSABLE_CONTENT":case "UNSUPPORTED_MEDIA_TYPE":return "VALIDATION_ERROR";case "METHOD_NOT_SUPPORTED":return "NOT_FOUND";case "UNAUTHORIZED":return "UNAUTHENTICATED";case "FORBIDDEN":return "FORBIDDEN";case "NOT_FOUND":return "NOT_FOUND";case "CONFLICT":return "CONFLICT";case "PRECONDITION_FAILED":return "PRECONDITION_FAILED";case "TOO_MANY_REQUESTS":return "RATE_LIMITED";default:return}}function Dr(n){if(n===void 0||n===408)return;if(n===405)return "NOT_FOUND";if(n===412)return "PRECONDITION_FAILED";if(n===422)return "VALIDATION_ERROR";let e=Dt(n);return e!=="BACKEND"?e:n>=400&&n<500?"VALIDATION_ERROR":e}var Mr=[/\bselect\b.+?\bfrom\b/i,/\binsert\b.+?\binto\b/i,/\bupdate\b.+?\bset\b/i,/\bdelete\b.+?\bfrom\b/i,/\bparams:\s/i,/\.ts\(\d+,\d+\)/,/at\s+\S+\s+\(.*:\d+:\d+\)/,/node_modules\//,/drizzle/i];function De(n){for(let e of Mr)if(e.test(n))return "An internal error occurred. Please try again or contact support.";return n}var m=class extends Error{code;status;hint;retryAfter;errorCode;backendCode;details;constructor(e,t,r,i,o,s,p){super(t),this.name="WarmHubError",this.code=e,this.status=r,this.hint=i,this.retryAfter=o,this.errorCode=s,this.backendCode=s,this.details=p;}get kind(){return this.code}};function At(n,e){if(typeof e!="string")return;let t=x$1(n,e);if(t)throw new m("VALIDATION_ERROR",t)}function a(n){if(n instanceof m)return n;if(n instanceof TRPCClientError){if(n.cause instanceof m)return n.cause;let e=n.data,t=e?.warmhub?.code,r=typeof e?.code=="string"?Lr(e.code):void 0,i=Dr(e?.httpStatus),o=e?.warmhub?.message??De(n.message);return new m(t??r??i??"BACKEND",o,e?.warmhub?.status??e?.httpStatus,e?.warmhub?.hint,e?.warmhub?.retryAfter??e?.retryAfter,t,e?.warmhub?.details)}if(n instanceof Error){let e=n;return n.name==="WarmHubError"&&typeof e.code=="string"?new m(e.code,De(n.message),typeof e.status=="number"?e.status:void 0,typeof e.hint=="string"?e.hint:void 0,typeof e.retryAfter=="number"?e.retryAfter:void 0,typeof e.errorCode=="string"?e.errorCode:typeof e.backendCode=="string"?e.backendCode:void 0,e.details):n.name==="AbortError"?new m("CANCELLED",n.message):n instanceof TypeError&&/fetch/i.test(n.message)?new m("NETWORK",n.message):new m("BACKEND",De(n.message))}return new m("BACKEND","Unknown SDK error")}function qr(n){return n instanceof m}function ni(n){let e=a(n);return e.kind==="NETWORK"||e.kind==="CANCELLED"||e.kind==="BACKEND"||e.kind==="RATE_LIMITED"}var Br=new Set(["ConnectionRefused","ECONNREFUSED","ENOTFOUND","ETIMEDOUT","EAI_AGAIN"]);function Ur(n){if(n instanceof TypeError&&/fetch/i.test(n.message))return true;if(n&&typeof n=="object"){let e=n.code;if(typeof e=="string"&&Br.has(e))return true}return false}function Vr(n){return `Unable to connect to ${n}. Is the computer able to access the url?`}function ii(n,e){if(L(n))return false;let t$1=t(n),r=t(e);return !t$1||!r?false:u(t$1,r)<0}function Lt(n,e){return new m("CLIENT_INCOMPATIBLE",n,412,e)}function Hr(n,e){let t=at(n,e);if(t)throw Lt(t.message,t.hint)}var kt=class n{apiUrl;fetchImpl;accessToken;clientIdentity;clientFlags;functionLogMode;getToken;compatibilityCheck;overrideNoticePrinted=false;noteCompatibilityOverride(){this.overrideNoticePrinted||(this.overrideNoticePrinted=true,console.error(`warmhub: compatibility checks overridden by client flag ${b}; the server remains authoritative.`));}assertWriteCompatible(){return this.clientFlags.includes(b)?(this.noteCompatibilityOverride(),Promise.resolve()):L(this.clientIdentity.version)&&xe(this.apiUrl,Le)?Promise.reject(Lt(`Development client ${this.clientIdentity.name}/${this.clientIdentity.version} cannot write to production.`,"Install a released WarmHub client artifact before writing to api.warmhub.ai.")):L(this.clientIdentity.version)&&!xe(this.apiUrl,Le)?Promise.resolve():this.diagnostics.assertCompatible()}createCompatibilityLink(){return ()=>({op:e,next:t})=>e.type!=="mutation"||e.path==="commit.validate"?t(e):observable(r=>{let i=false,o;return this.assertWriteCompatible().then(()=>{i||(o=t(e).subscribe(r));}).catch(s=>{i||r.error(TRPCClientError.from(s));}),()=>{i=true,o?.unsubscribe();}})}auth={getClientId:async()=>{try{return await this.trpc.auth.getClientId.query()}catch(e){throw a(e)}},sync:async()=>{try{return await this.trpc.auth.sync.mutate()}catch(e){throw a(e)}},currentUser:async()=>{try{return await this.trpc.auth.currentUser.query()}catch(e){throw a(e)}},whoami:async()=>{try{return await this.trpc.auth.whoami.query()}catch(e){throw a(e)}}};homepage={featuredLists:async()=>{try{return await this.trpc.homepage.featuredLists.query()}catch(e){throw a(e)}}};access={resolve:async e=>{try{return await this.trpc.access.resolve.query(e)}catch(t){throw a(t)}}};diagnostics={ping:async()=>{let e=await this.fetchWithAuth(`${this.apiUrl.replace(/\/$/,"")}/health`);if(!e.ok)throw new m("BACKEND",`Health request failed with status ${e.status}`,e.status);return await e.json()},capabilities:async()=>{try{return await this.trpc.diagnostics.capabilities.query()}catch(e){throw a(e)}},assertCompatible:()=>{if(this.compatibilityCheck)return this.compatibilityCheck;let e=(async()=>{let t=await this.diagnostics.capabilities();Hr(t,this.clientIdentity);})();return this.compatibilityCheck=e,e.catch(t=>{qr(t)&&t.code==="CLIENT_INCOMPATIBLE"||this.compatibilityCheck===e&&(this.compatibilityCheck=void 0);}),e}};component={list:async(e,t,r)=>{try{return await this.trpc.component.list.query({orgName:e,repoName:t,limit:r?.limit,cursor:r?.cursor})}catch(i){throw a(i)}},listIter:(e,t,r)=>C(i=>this.component.list(e,t,{...r,cursor:i}),i=>i.items,r?.cursor),listAll:async(e,t,r)=>{let{max:i,...o}=r??{};return await w(s=>this.component.list(e,t,{...o,cursor:s}),s=>s.items,i,o.cursor)},search:async(e,t)=>{try{return await this.trpc.component.search.query({query:e,limit:t?.limit,cursor:t?.cursor})}catch(r){throw a(r)}},searchIter:(e,t)=>C(r=>this.component.search(e,{...t,cursor:r}),r=>r.items,t?.cursor),searchAll:async(e,t)=>{let{max:r,...i}=t??{};return await w(o=>this.component.search(e,{...i,cursor:o}),o=>o.items,r,i.cursor)},get:async(e,t,r)=>{try{return await this.trpc.component.get.query({orgName:e,repoName:t,componentRef:r})}catch(i){throw a(i)}},history:async(e,t,r)=>{try{return await this.trpc.component.history.query({orgName:e,repoName:t,componentRef:r?.componentRef,limit:r?.limit})}catch(i){throw a(i)}},install:async(e,t,r,i)=>{try{return await this.trpc.component.install.mutate({orgName:e,repoName:t,componentRef:r,submissionId:i.submissionId})}catch(o){throw a(o)}},uninstall:async(e,t,r,i)=>{try{return await this.trpc.component.uninstall.mutate({orgName:e,repoName:t,componentRef:r,submissionId:i.submissionId})}catch(o){throw a(o)}},registry:{register:async(e,t,r)=>{try{return await this.trpc.component.registry.register.mutate({orgName:e,componentName:t,...r})}catch(i){throw a(i)}},unregister:async(e,t)=>{try{return await this.trpc.component.registry.unregister.mutate({orgName:e,componentName:t})}catch(r){throw a(r)}},list:async e=>{try{return await this.trpc.component.registry.list.query({orgName:e})}catch(t){throw a(t)}},view:async(e,t)=>{try{return await this.trpc.component.registry.view.query({orgName:e,componentName:t})}catch(r){throw a(r)}},update:async(e,t,r)=>{try{return await this.trpc.component.registry.update.mutate({orgName:e,componentName:t,...r})}catch(i){throw a(i)}},resolve:async(e,t,r)=>await this.requestJson(`/api/component-registry/${encodeURIComponent(e)}/${encodeURIComponent(t)}/resolve`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({installRepo:r})}),setupCall:async(e,t,r)=>(await this.assertWriteCompatible(),await this.requestJson(`/api/component-registry/${encodeURIComponent(e)}/${encodeURIComponent(t)}/setup-call`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(r)}))},cli:{call:async(e,t,r,i)=>(await this.assertWriteCompatible(),await this.requestJson(`/api/component-registry/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cli/${encodeURIComponent(r)}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i)}))}};commit={validate:async(e,t,r,i)=>{try{return await this.trpc.commit.validate.mutate({orgName:e,repoName:t,committer:i?.committer,message:i?.message,componentRef:i?.componentRef,operations:Ce(r,i?.skipExisting),includeWouldBeBody:i?.includeWouldBeBody},{signal:i?.signal})}catch(o){throw a(o)}},apply:async(e,t,r,i,o)=>{try{return await P(this,{orgName:e,repoName:t,committer:o?.committer,message:r,componentRef:o?.componentRef,chunkSize:o?.chunkSize,skipExisting:o?.skipExisting,streamId:o?.streamId,submissionId:o?.submissionId,returnRepoSeq:o?.returnRepoSeq,retry:o?.retry,operations:i})}catch(s){throw s instanceof A||s instanceof v?s:a(s)}},getReceipt:async(e,t,r)=>{try{return await this.trpc.commit.getReceipt.query({orgName:e,repoName:t,eventRequestId:r})}catch(i){throw a(i)}}};org={get:async e=>{try{return await this.trpc.org.get.query({orgName:e})}catch(t){throw a(t)}},getCallerRole:async e=>{try{return await this.trpc.org.getCallerRole.query({orgName:e})}catch(t){throw a(t)}},list:async e=>{try{return {items:await this.trpc.org.list.query({includeArchived:e?.includeArchived})}}catch(t){throw a(t)}},create:async(e,t,r)=>{try{return await this.trpc.org.create.mutate({name:e,displayName:t,description:r})}catch(i){throw a(i)}},setDescription:async(e,t)=>{try{return await this.trpc.org.setDescription.mutate({orgName:e,description:t})}catch(r){throw a(r)}},setDisplayName:async(e,t)=>{try{return await this.trpc.org.setDisplayName.mutate({orgName:e,displayName:t})}catch(r){throw a(r)}},rename:async(e,t)=>{try{return await this.trpc.org.rename.mutate({orgName:e,newName:t})}catch(r){throw a(r)}},update:async e=>{try{return await this.trpc.org.update.mutate(e)}catch(t){throw a(t)}},addMember:async(e,t,r="editor")=>{try{return await this.trpc.org.addMember.mutate({orgName:e,email:t,role:r})}catch(i){throw a(i)}},removeMember:async(e,t)=>{try{await this.trpc.org.removeMember.mutate({orgName:e,email:t});}catch(r){throw a(r)}},leave:async e=>{try{await this.trpc.org.leave.mutate({orgName:e});}catch(t){throw a(t)}},changeMemberRole:async(e,t,r)=>{try{return await this.trpc.org.changeMemberRole.mutate({orgName:e,email:t,role:r})}catch(i){throw a(i)}},setMemberScopes:async(e,t,r)=>{try{await this.trpc.org.setMemberScopes.mutate({orgName:e,email:t,scopes:r});}catch(i){throw a(i)}},clearMemberScopes:async(e,t)=>{try{await this.trpc.org.clearMemberScopes.mutate({orgName:e,email:t});}catch(r){throw a(r)}},listMembers:async(e,t)=>{try{return await this.trpc.org.listMembers.query({orgName:e,pending:t?.pending})}catch(r){throw a(r)}},archive:async e=>{try{return await this.trpc.org.archive.mutate({orgName:e})}catch(t){throw a(t)}},unarchive:async e=>{try{return await this.trpc.org.unarchive.mutate({orgName:e})}catch(t){throw a(t)}}};repo={checkpoint:Qe(()=>this.trpc,a),get:async(e,t)=>{try{return await this.trpc.repo.get.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getStats:async(e,t)=>{try{return await this.trpc.repo.stats.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getStatsBatch:async(e,t)=>{try{return await this.trpc.repo.statsBatch.query({orgName:e,repoNames:t})}catch(r){throw a(r)}},getConfigureStats:async(e,t)=>{try{return await this.trpc.repo.configureStats.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getShapeInstanceCounts:async(e,t)=>{try{return await this.trpc.repo.shapeInstanceCounts.query({orgName:e,repoName:t})}catch(r){throw a(r)}},list:async(e,t)=>{try{return await this.trpc.repo.list.query({orgName:e,limit:t?.limit,cursor:t?.cursor,includeArchived:t?.includeArchived,search:t?.search,sort:t?.sort})}catch(r){throw a(r)}},listIter:(e,t)=>C(r=>this.repo.list(e,{...t,cursor:r}),r=>r.items,t?.cursor),listAll:async(e,t)=>{let{max:r,...i}=t??{};return await w(o=>this.repo.list(e,{...i,cursor:o}),o=>o.items,r,i.cursor)},search:async(e,t)=>{try{return await this.trpc.repo.search.query({query:e,limit:t?.limit,cursor:t?.cursor})}catch(r){throw a(r)}},searchIter:(e,t)=>C(r=>this.repo.search(e,{...t,cursor:r}),r=>r.items,t?.cursor),searchAll:async(e,t)=>{let{max:r,...i}=t??{};return await w(o=>this.repo.search(e,{...i,cursor:o}),o=>o.items,r,i.cursor)},create:async(e,t,r,i,o)=>{try{return await this.trpc.repo.create.mutate({orgName:e,repoName:t,description:r,visibility:i,displayName:o})}catch(s){throw a(s)}},setDescription:async(e,t,r)=>{try{return await this.trpc.repo.setDescription.mutate({orgName:e,repoName:t,description:r})}catch(i){throw a(i)}},setDisplayName:async(e,t,r)=>{try{return await this.trpc.repo.setDisplayName.mutate({orgName:e,repoName:t,displayName:r})}catch(i){throw a(i)}},setVisibility:async(e,t,r)=>{try{return await this.trpc.repo.setVisibility.mutate({orgName:e,repoName:t,visibility:r})}catch(i){throw a(i)}},rename:async(e,t,r)=>{try{return await this.trpc.repo.rename.mutate({orgName:e,repoName:t,newName:r})}catch(i){throw a(i)}},update:async e=>{try{return await this.trpc.repo.update.mutate(e)}catch(t){throw a(t)}},archive:async(e,t)=>{try{return await this.trpc.repo.archive.mutate({orgName:e,repoName:t})}catch(r){throw a(r)}},unarchive:async(e,t)=>{try{return await this.trpc.repo.unarchive.mutate({orgName:e,repoName:t})}catch(r){throw a(r)}},delete:async(e,t)=>{try{let r=await this.trpc.repo.delete.mutate({orgName:e,repoName:t});return {graceExpiresAt:new Date(r.graceExpiresAt)}}catch(r){throw a(r)}},listPage:async(e,t)=>{try{return await this.trpc.repo.listPage.query({orgName:e,limit:t?.limit,cursor:t?.cursor,includeArchived:t?.includeArchived,search:t?.search,sort:t?.sort})}catch(r){throw a(r)}},listPageIter:(e,t)=>C(r=>this.repo.listPage(e,{...t,cursor:r}),r=>r.items,t?.cursor),listPageAll:async(e,t)=>{let{max:r,...i}=t??{};return await w(o=>this.repo.listPage(e,{...i,cursor:o}),o=>o.items,r,i.cursor)},listForCaller:async e=>{try{return await this.trpc.repo.listForCaller.query({limit:e?.limit,sort:e?.sort})}catch(t){throw a(t)}},explore:async e=>{try{return await this.trpc.repo.explore.query({search:e?.search,org:e?.org,activity:e?.activity,hasSubscriptions:e?.hasSubscriptions,minThings:e?.minThings,sort:e?.sort,limit:e?.limit,cursor:e?.cursor,slugs:e?.slugs})}catch(t){throw a(t)}},exploreIter:e=>(St(e),C(t=>this.repo.explore({...e,cursor:t}),t=>t.items,e?.cursor)),exploreAll:async e=>{St(e);let{max:t,...r}=e??{};return await w(i=>this.repo.explore({...r,cursor:i}),i=>i.items,t,r.cursor)},getReadme:async(e,t)=>{try{return await this.trpc.repo.getReadme.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getAgents:async(e,t)=>{try{return await this.trpc.repo.getAgents.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getLicense:async(e,t)=>{try{return await this.trpc.repo.getLicense.query({orgName:e,repoName:t})}catch(r){throw a(r)}},describe:async(e,t)=>{try{return await this.trpc.repo.describe.query({orgName:e,repoName:t})}catch(r){throw a(r)}},setReadme:async(e,t,r,i)=>{try{return At("Content/Readme.content",r),await this.trpc.repo.setReadme.mutate({orgName:e,repoName:t,eventRequestId:i.eventRequestId,content:r})}catch(o){throw a(o)}},setAgents:async(e,t,r,i)=>{try{return At("Content/Agents.content",r),await this.trpc.repo.setAgents.mutate({orgName:e,repoName:t,eventRequestId:i.eventRequestId,content:r})}catch(o){throw a(o)}},getLlmsTxt:async(e,t)=>{try{return await this.trpc.repo.getLlmsTxt.query({orgName:e,repoName:t})}catch(r){throw a(r)}},index:{describe:async(e,t)=>{try{return await this.trpc.repo.index.describe.query({orgName:e,repoName:t})}catch(r){throw a(r)}}}};shape={list:async(e,t,r)=>{try{return await this.trpc.shape.list.query({orgName:e,repoName:t,match:r?.match,componentRef:r?.componentRef,excludeComponents:r?.excludeComponents,includeRetracted:r?.includeRetracted})}catch(i){throw a(i)}},get:async(e,t,r,i)=>{try{return await this.trpc.shape.get.query({orgName:e,repoName:t,shapeName:r,includeRetracted:i?.includeRetracted})}catch(o){throw a(o)}},create:async(e,t,r,i,o)=>{let s=F(r,{fields:i,...o.description!==void 0?{description:o.description}:{}},"add");if(s)throw new m("VALIDATION_ERROR",s);try{return await this.trpc.shape.create.mutate({orgName:e,repoName:t,shapeName:r,fields:i,eventRequestId:o.eventRequestId,description:o.description})}catch(p){throw a(p)}},revise:async(e,t,r,i,o)=>{let s=F(r,{fields:i,...o.description!==void 0?{description:o.description}:{}},"revise");if(s)throw new m("VALIDATION_ERROR",s);try{return await this.trpc.shape.revise.mutate({orgName:e,repoName:t,shapeName:r,newFields:i,eventRequestId:o.eventRequestId,description:o.description})}catch(p){throw a(p)}},remove:async(e,t,r,i)=>{try{return await this.trpc.shape.remove.mutate({orgName:e,repoName:t,shapeName:r,eventRequestId:i.eventRequestId})}catch(o){throw a(o)}},rename:async(e,t,r,i,o)=>{try{return await this.trpc.shape.rename.mutate({orgName:e,repoName:t,oldName:r,newName:i,eventRequestId:o.eventRequestId})}catch(s){throw a(s)}},history:async(e,t,r,i={})=>{try{return await this.trpc.shape.history.query({orgName:e,repoName:t,name:r,includeRetracted:i.includeRetracted,limit:i.limit,cursor:i.cursor})}catch(o){throw a(o)}},historyIter:(e,t,r,i={})=>C(o=>this.shape.history(e,t,r,{...i,cursor:o}),o=>o.versions,i.cursor),historyAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.shape.history(e,t,r,{...s,cursor:p}),p=>p.versions,o,s.cursor)}};subscription={create:async e=>{try{let t=await this.trpc.subscription.create.mutate(Tr(e));return de(t)}catch(t){throw a(t)}},get:async(...e)=>{try{let t=await this.trpc.subscription.get.query(K(e));return de(t)}catch(t){throw a(t)}},reveal:async(...e)=>{try{return await this.trpc.subscription.reveal.query(K(e))}catch(t){throw a(t)}},list:async(...e)=>{try{let t=await this.trpc.subscription.list.query(vr(e));return kr(t)}catch(t){throw a(t)}},update:async e=>{try{let t=await this.trpc.subscription.update.mutate(_r(e));return de(t)}catch(t){throw a(t)}},pause:async(...e)=>{try{return await this.trpc.subscription.pause.mutate(K(e))}catch(t){throw a(t)}},resume:async(...e)=>{try{return await this.trpc.subscription.resume.mutate(K(e))}catch(t){throw a(t)}},remove:async(...e)=>{try{return await this.trpc.subscription.remove.mutate(K(e))}catch(t){throw a(t)}},bindCredentials:async(...e)=>{try{return await this.trpc.subscription.bindCredentials.mutate(Er(e))}catch(t){throw a(t)}},unbindCredentials:async(...e)=>{try{return await this.trpc.subscription.unbindCredentials.mutate(xr(e))}catch(t){throw a(t)}}};action={acquireLease:async(e,t,r,i,o,s)=>{try{return await this.trpc.action.acquireLease.mutate({orgName:e,repoName:t,subscriptionName:r,holderId:i,holderType:o,graceMs:s?.graceMs,ttlMs:s?.ttlMs})}catch(p){throw a(p)}},heartbeatLease:async(e,t,r,i,o)=>{try{return await this.trpc.action.heartbeatLease.mutate({orgName:e,repoName:t,subscriptionName:r,holderId:i,ttlMs:o})}catch(s){throw a(s)}},releaseLease:async(e,t,r,i)=>{try{return await this.trpc.action.releaseLease.mutate({orgName:e,repoName:t,subscriptionName:r,holderId:i})}catch(o){throw a(o)}},claimDelivery:async(e,t,r,i)=>{let o=typeof r=="string"?{runId:r}:r;try{return await this.trpc.action.claimDelivery.mutate({orgName:e,repoName:t,...o,holderId:i})}catch(s){throw a(s)}},completeDelivery:async(e,t,r,i)=>{let o=typeof r=="string"?{runId:r}:r;try{return await this.trpc.action.completeDelivery.mutate({orgName:e,repoName:t,...o,holderId:i})}catch(s){throw a(s)}},liveFeed:async(e,t,r,i)=>{try{return await this.trpc.action.liveFeed.query({orgName:e,repoName:t,subscriptionName:r,limit:i?.limit,cursor:i?.cursor})}catch(o){throw a(o)}},liveFeedIter:(e,t,r,i)=>C(o=>this.action.liveFeed(e,t,r,{...i,cursor:o}),o=>o.items,i?.cursor),liveFeedAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.action.liveFeed(e,t,r,{...s,cursor:p}),p=>p.items,o,s.cursor)},listRuns:async(e,t,r)=>{try{return await this.trpc.action.listRuns.query({orgName:e,repoName:t,runId:r?.runId,subscriptionName:r?.subscriptionName,status:r?.status,outcome:r?.outcome,since:r?.since,cursor:r?.cursor,limit:r?.limit})}catch(i){throw a(i)}},listRunsIter:(e,t,r)=>C(i=>this.action.listRuns(e,t,{...r,since:i===void 0?r?.since:void 0,cursor:i}),i=>i.items,r?.cursor),listRunsAll:async(e,t,r)=>{let{max:i,...o}=r??{};return await w(s=>this.action.listRuns(e,t,{...o,since:s===void 0?o.since:void 0,cursor:s}),s=>s.items,i,o.cursor)},latestRuns:async(e,t)=>{try{return await this.trpc.action.latestRuns.query({orgName:e,repoName:t})}catch(r){throw a(r)}},runStats:async(e,t,r)=>{try{return await this.trpc.action.runStats.query({orgName:e,repoName:t,subscriptionName:r?.subscriptionName,since:r?.since})}catch(i){throw a(i)}},getRunAttempts:async(e,t,r)=>{try{return await this.trpc.action.getRunAttempts.query({orgName:e,repoName:t,runId:r})}catch(i){throw a(i)}},listNotifications:async(e,t,r)=>{try{return await this.trpc.action.listNotifications.query({orgName:e,repoName:t,since:r?.since,limit:r?.limit})}catch(i){throw a(i)}}};collection={create:async(e,t,r)=>{try{return Pr(r.type,r),await this.trpc.collection.create.mutate({orgName:e,repoName:t,eventRequestId:r.eventRequestId,type:r.type,name:r.name,members:r.members,from:r.from,add:r.add,remove:r.remove,replaceMembers:r.replaceMembers,query:r.query,sourceOrgName:r.sourceRepo?.orgName,sourceRepoName:r.sourceRepo?.repoName,skipExisting:r.skipExisting,message:r.message,committer:r.committer})}catch(i){throw a(i)}},members:async(e,t,r,i)=>{try{return await this.trpc.collection.members.query({orgName:e,repoName:t,wref:r,version:i?.version,limit:i?.limit,cursor:i?.cursor})}catch(o){throw a(o)}},membersIter:(e,t,r,i)=>{let o=i?.version;return C(async s=>{let p=await this.collection.members(e,t,r,{...i,version:o,cursor:s});return o??=p.version,p},s=>s.items,i?.cursor)},membersAll:async(e,t,r,i)=>{let{max:o,...s}=i??{},p=s.version;return await w(async c=>{let u=await this.collection.members(e,t,r,{...s,version:p,cursor:c});return p??=u.version,u},c=>c.items,o,s.cursor)},contains:async(e,t,r,i,o)=>{try{return await this.trpc.collection.contains.query({orgName:e,repoName:t,wref:r,version:o?.version,members:i,position:o?.position})}catch(s){throw a(s)}},diff:async(e,t,r,i,o)=>{try{return await this.trpc.collection.diff.query({orgName:e,repoName:t,leftWref:r,rightWref:i,leftVersion:o?.leftVersion,rightVersion:o?.rightVersion,mode:o?.mode})}catch(s){throw a(s)}},revise:async(e,t,r,i)=>{try{let o=Nr(r);if(me(i.query)&&!ge(i.query))throw new m("VALIDATION_ERROR","Selector-backed collection sources require shape, about, match, componentRef, or where; kind and excludeComponents only narrow an existing selector.");if(i.sourceRepo&&!ge(i.query))throw new m("VALIDATION_ERROR","sourceRepo requires a selector-backed collection query");if(i.sourceRepo&&Pt(i))throw new m("VALIDATION_ERROR","sourceRepo cannot be combined with explicit members; use canonical wh:org/repo/... member wrefs or omit sourceRepo.");if(me(i.query)&&o&&o!=="set")throw new m("VALIDATION_ERROR","Selector-backed revise requires a Set/<name> target wref");return await this.trpc.collection.revise.mutate({orgName:e,repoName:t,eventRequestId:i.eventRequestId,wref:r,members:i.members,add:i.add,remove:i.remove,query:i.query,sourceOrgName:i.sourceRepo?.orgName,sourceRepoName:i.sourceRepo?.repoName,message:i.message,committer:i.committer})}catch(o){throw a(o)}},stats:async(e,t,r,i)=>{try{return await this.trpc.collection.stats.query({orgName:e,repoName:t,wref:r,version:i?.version})}catch(o){throw a(o)}}};view={evaluate:async(e,t,r,i)=>{try{return await this.trpc.view.evaluate.query({orgName:e,repoName:t,wref:r,limit:i?.limit,cursor:i?.cursor})}catch(o){throw a(o)}},evaluateIter:(e,t,r,i)=>C(o=>this.view.evaluate(e,t,r,{...i,cursor:o}),o=>o.items,i?.cursor),evaluateAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.view.evaluate(e,t,r,{...s,cursor:p}),p=>p.items,o,s.cursor)}};grant=je(()=>this.trpc,a);thing={head:async(e,t,r)=>{try{return await this.trpc.thing.head.query({orgName:e,repoName:t,shape:r?.shape,kind:le(r?.kind),match:r?.match,dataMode:r?.dataMode,includeRetracted:r?.includeRetracted,limit:r?.limit,cursor:r?.cursor,componentRef:r?.componentRef,excludeComponents:r?.excludeComponents,excludeInfraShapes:r?.excludeInfraShapes,where:r?.where,sinceRepoSeq:r?.sinceRepoSeq})}catch(i){throw a(i)}},headIter:(e,t,r)=>C(i=>this.thing.head(e,t,{...r,cursor:i}),i=>i.items,r?.cursor),headAll:async(e,t,r)=>{let{max:i,...o}=r??{};return await w(s=>this.thing.head(e,t,{...o,cursor:s}),s=>s.items,i,o.cursor)},headChanges:async(e,t,r)=>(wt(r?.sinceRepoSeq),await Ot(i=>this.thing.head(e,t,{...r,includeRetracted:true,cursor:i}))),get:async(e,t,r,i,o)=>{try{return await this.trpc.thing.get.query({orgName:e,repoName:t,wref:r,version:i,includeRetracted:o?.includeRetracted,dataMode:o?.dataMode})}catch(s){throw a(s)}},getWithLease:async(e,t,r,i)=>{try{return await this.trpc.thing.getWithLease.mutate({orgName:e,repoName:t,wref:r,ttlMs:i?.ttlMs})}catch(o){throw a(o)}},releaseLease:async(e,t,r,i)=>{try{await this.trpc.thing.releaseLease.mutate({orgName:e,repoName:t,wref:r,leaseId:i});}catch(o){throw a(o)}},graph:async(e,t,r,i)=>{try{return await this.trpc.thing.graph.query({orgName:e,repoName:t,wref:r,version:i?.version,depth:i?.depth,limit:i?.limit})}catch(o){throw a(o)}},getMany:async(e,t,r,i,o)=>{try{if(r.length===0)return {requested:0,items:[],missing:[]};let s=ue(o?.chunkSize,ft,Rt),p=ue(o?.chunkConcurrency,bt,Ct),c=async g=>await this.trpc.thing.getMany.query({orgName:e,repoName:t,wrefs:g,version:i,includeRetracted:o?.includeRetracted,dataMode:o?.dataMode});if(r.length<=s)return await c(r);let u=It(r,s),l=[];for(let g=0;g<u.length;g+=p){let h=u.slice(g,g+p),y=await Promise.all(h.map(c));l.push(...y);}return {requested:r.length,items:l.flatMap(g=>g.items),missing:l.flatMap(g=>g.missing)}}catch(s){throw a(s)}},headVersions:async(e,t,r,i)=>{try{if(r.length===0)return {requested:0,items:[],missing:[]};let o=ue(i?.chunkSize,ft,Rt),s=ue(i?.chunkConcurrency,bt,Ct),p=async l=>await this.trpc.thing.headVersions.query({orgName:e,repoName:t,wrefs:l});if(r.length<=o)return await p(r);let c=It(r,o),u=[];for(let l=0;l<c.length;l+=s){let g=c.slice(l,l+s),h=await Promise.all(g.map(p));u.push(...h);}return {requested:r.length,items:u.flatMap(l=>l.items),missing:u.flatMap(l=>l.missing)}}catch(o){throw a(o)}},history:async(e,t,r)=>{try{return await this.trpc.thing.history.query({orgName:e,repoName:t,wref:r.wref,shape:r.shape,about:r.about,includeRetracted:r.includeRetracted,resolveCollections:r.resolveCollections,match:r.match,limit:r.limit,cursor:r.cursor})}catch(i){throw a(i)}},historyIter:(e,t,r)=>C(i=>this.thing.history(e,t,{...r,cursor:i}),i=>i.versions,r.cursor),historyAll:async(e,t,r)=>{let{max:i,...o}=r;return await w(s=>this.thing.history(e,t,{...o,cursor:s}),s=>s.versions,i,o.cursor)},rename:async(e,t,r,i,o,s)=>{try{return await this.trpc.thing.rename.mutate({orgName:e,repoName:t,shapeName:r,oldName:i,newName:o,eventRequestId:s.eventRequestId})}catch(p){throw a(p)}},resolve:async(e,t,r)=>{try{return await this.trpc.thing.resolve.query({orgName:e,repoName:t,wref:r})}catch(i){throw a(i)}},about:async(e,t,r,i)=>{try{return await this.trpc.thing.about.query({orgName:e,repoName:t,wref:r,shape:i?.shape,match:i?.match,includeRetracted:i?.includeRetracted,depth:i?.depth,resolveCollections:i?.resolveCollections,role:i?.role,limit:i?.limit,cursor:i?.cursor,where:i?.where})}catch(o){throw a(o)}},aboutIter:(e,t,r,i)=>C(o=>this.thing.about(e,t,r,{...i,cursor:o}),o=>o.assertions,i?.cursor),aboutAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.thing.about(e,t,r,{...s,cursor:p}),p=>p.assertions,o,s.cursor)},query:async(e,t,r)=>{try{return await this.trpc.thing.query.query({orgName:e,repoName:t,shape:r?.shape,about:r?.about,affirmedAbout:r?.affirmedAbout,kind:le(r?.kind),match:r?.match,includeRetracted:r?.includeRetracted,resolveCollections:r?.resolveCollections,role:r?.role,limit:r?.limit,cursor:r?.cursor,componentRef:r?.componentRef,excludeComponents:r?.excludeComponents,excludeInfraShapes:r?.excludeInfraShapes,where:r?.where,sinceRepoSeq:r?.sinceRepoSeq})}catch(i){throw a(i)}},queryIter:(e,t,r)=>C(i=>this.thing.query(e,t,{...r,cursor:i}),i=>i.items,r?.cursor),queryAll:async(e,t,r)=>{let{max:i,...o}=r??{};return await w(s=>this.thing.query(e,t,{...o,cursor:s}),s=>s.items,i,o.cursor)},queryChanges:async(e,t,r)=>(wt(r?.sinceRepoSeq),await Ot(i=>this.thing.query(e,t,{...r,includeRetracted:true,cursor:i}))),search:async(e,t,r,i)=>{try{return await this.trpc.thing.search.query({orgName:e,repoName:t,query:r,shape:i?.shape,about:i?.about,affirmedAbout:i?.affirmedAbout,kind:le(i?.kind),match:i?.match,includeRetracted:i?.includeRetracted,resolveCollections:i?.resolveCollections,limit:i?.limit,cursor:i?.cursor,componentRef:i?.componentRef,excludeComponents:i?.excludeComponents,excludeInfraShapes:i?.excludeInfraShapes,mode:i?.mode,nameMatch:i?.nameMatch})}catch(o){throw a(o)}},searchIter:(e,t,r,i)=>C(o=>this.thing.search(e,t,r,{...i,cursor:o}),o=>o.items,i?.cursor),searchAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.thing.search(e,t,r,{...s,cursor:p}),p=>p.items,o,s.cursor)},count:async(e,t,r)=>{try{return await this.trpc.thing.count.query({orgName:e,repoName:t,shape:r?.shape,about:r?.about,affirmedAbout:r?.affirmedAbout,kind:le(r?.kind),match:r?.match,includeRetracted:r?.includeRetracted,resolveCollections:r?.resolveCollections,componentRef:r?.componentRef,excludeComponents:r?.excludeComponents,excludeInfraShapes:r?.excludeInfraShapes,where:r?.where,sinceRepoSeq:r?.sinceRepoSeq})}catch(i){throw a(i)}},refs:async(e,t,r,i)=>{try{return await this.trpc.thing.refs.query({orgName:e,repoName:t,wref:r,direction:i?.direction,fieldPath:i?.fieldPath,limit:i?.limit,cursor:i?.cursor})}catch(o){throw a(o)}},refsIter:(e,t,r,i)=>C(o=>this.thing.refs(e,t,r,{...i,cursor:o}),o=>o.items,i?.cursor),refsAll:async(e,t,r,i)=>{let{max:o,...s}=i??{};return await w(p=>this.thing.refs(e,t,r,{...s,cursor:p}),p=>p.items,o,s.cursor)}};live={thingHead:async(e,t,r,i)=>this.watchRepoQuery(e,t,r?.signal,()=>this.thing.head(e,t,{shape:r?.shape,kind:r?.kind,match:r?.match,dataMode:r?.dataMode,limit:r?.limit,cursor:r?.cursor,includeRetracted:r?.includeRetracted,where:r?.where}),i),thingHistory:async(e,t,r,i)=>this.watchRepoQuery(e,t,r.signal,()=>this.thing.history(e,t,{wref:r.wref,limit:r.limit,cursor:r.cursor,includeRetracted:r.includeRetracted}),i),subscriptionLog:async(e,t,r,i,o)=>this.watchRepoQuery(e,t,i?.signal,()=>this.action.liveFeed(e,t,r,{limit:i?.limit,cursor:i?.cursor}),o),subscribe:async(e,t,r,i)=>{let o=new AbortController,s=Et(r?.signal,o),p=0,c=(async()=>{let u=await this.trpc.live.issueTicket.mutate({orgName:e,repoName:t}),l=await this.openSse(u.ticket,s,async g=>{if(g.type!=="invalidate")return;let h=g.data;p++,await i({topic:h.topic,affectedShapes:h.affectedShapes,affectedThings:h.affectedThings,affectedTargets:h.affectedTargets,hasNewCommit:h.hasNewCommit});});return await l.ready,s.aborted?{updates:p}:(await l.closed,{updates:p})})();return {close(){o.abort();},closed:c}}};token={create:async e=>{try{return await this.trpc.token.create.mutate(e)}catch(t){throw a(t)}},list:async e=>{try{return await this.trpc.token.list.query(e?.includeInactive?{includeInactive:!0}:void 0)}catch(t){throw a(t)}},get:async e=>{try{return await this.trpc.token.get.query({name:e})}catch(t){throw a(t)}},revoke:async e=>{try{return await this.trpc.token.revoke.mutate({name:e})}catch(t){throw a(t)}}};stream={append:async e=>{try{return await this.trpc.stream.append.mutate(e)}catch(t){throw a(t)}}};credential={createSet:async(e,t,r,i)=>{try{return await this.trpc.credential.createSet.mutate({orgName:e,repoName:t,name:r,scope:i?.scope??"repo",description:i?.description})}catch(o){throw a(o)}},listSets:async(e,t)=>{try{return await this.trpc.credential.listSets.query({orgName:e,repoName:t})}catch(r){throw a(r)}},getSet:async(e,t,r)=>{try{return await this.trpc.credential.getSet.query({orgName:e,repoName:t,name:r})}catch(i){throw a(i)}},setKey:async(e,t,r,i,o)=>{try{return await this.trpc.credential.setKey.mutate({orgName:e,repoName:t,setName:r,keyName:i,value:o})}catch(s){throw a(s)}},setKeys:async(e,t,r,i)=>{try{return await this.trpc.credential.setKeys.mutate({orgName:e,repoName:t,setName:r,secrets:i})}catch(o){throw a(o)}},unsetKey:async(e,t,r,i)=>{try{return await this.trpc.credential.unsetKey.mutate({orgName:e,repoName:t,setName:r,keyName:i})}catch(o){throw a(o)}},deleteSet:async(e,t,r)=>{try{return await this.trpc.credential.deleteSet.mutate({orgName:e,repoName:t,setName:r})}catch(i){throw a(i)}},listAuditLog:async(e,t,r,i)=>{try{return await this.trpc.credential.listAuditLog.query({orgName:e,repoName:t,setName:r,limit:i?.limit})}catch(o){throw a(o)}},revokeSet:async(e,t,r,i)=>{try{return await this.trpc.credential.revokeSet.mutate({orgName:e,repoName:t,setName:r,reason:i?.reason})}catch(o){throw a(o)}}};credentials=this.credential;constructor(e,t){let r=typeof e=="string"?t:e;Or(r);let i=typeof e=="string"?e:e?.apiUrl??Le;if(this.apiUrl=i,this.fetchImpl=r?.fetch,this.accessToken=r?.accessToken??r?.auth?.getToken,this.functionLogMode=r?.functionLogs??"off",this.clientIdentity={name:r?.client?.name??f,version:r?.client?.version??Ee},this.clientFlags=Ir(r?.clientFlags),typeof this.accessToken=="function"){let p=this.accessToken;this.getToken=async()=>await p();}else if(this.accessToken){let p=this.accessToken;this.getToken=async()=>p;}let o=`${i.replace(/\/$/,"")}/trpc`,s=((p,c)=>this.fetchWithAuth(p,c));Object.defineProperty(this,"trpc",{value:createTRPCProxyClient({links:[this.createCompatibilityLink(),splitLink({condition:p=>Ar.has(p.path),true:httpLink({url:o,fetch:s,methodOverride:"POST"}),false:httpBatchLink({url:o,fetch:s,methodOverride:"POST"})})]}),enumerable:false,writable:false,configurable:true});}withAccessToken(e){return new n({apiUrl:this.apiUrl,fetch:this.fetchImpl,accessToken:e,client:this.clientIdentity,clientFlags:this.clientFlags})}actions=this.action;async openSse(e,t,r){let i=await this.fetchWithAuth(`${this.apiUrl.replace(/\/$/,"")}/sse?ticket=${encodeURIComponent(e)}`,{headers:{accept:"text/event-stream"},signal:t});if(!i.ok)throw new m("BACKEND",`SSE request failed with status ${i.status}`,i.status);let o=i.body?.getReader();if(!o)throw new m("BACKEND","SSE response body is missing");let s=()=>{},p=new Promise(u=>{s=u;}),c=(async()=>{let u=new TextDecoder,l="";try{for(;;){let{done:g,value:h}=await o.read();if(g)break;for(l+=u.decode(h,{stream:!0}).replaceAll(`\r
2
2
  `,`
3
3
  `);;){let y=l.indexOf(`
4
4
 
5
5
  `);if(y===-1)break;let S=l.slice(0,y);l=l.slice(y+2);let d=Fr(S);if(d){if(d.type==="ready"){s();continue}await r(d);}}}}catch(g){if(Wr(g)||t.aborted)return;throw g}finally{s(),o.releaseLock();}})();return {ready:p,closed:c}}applyClientHeader(e$1){e$1.has(e)||e$1.set(e,i(this.clientIdentity.name,this.clientIdentity.version)),this.clientFlags.length>0&&!e$1.has(a$1)&&e$1.set(a$1,d(this.clientFlags));}async fetchWithAuth(e,t){let r=this.fetchImpl??globalThis.fetch,i=new Headers(t?.headers),o=await vt(this.accessToken);o&&i.set("authorization",`Bearer ${o}`),this.applyClientHeader(i);let s=async c=>{try{return await r(e,c)}catch(u){throw Ur(u)?new m("NETWORK",Vr(this.apiUrl)):u}},p=await s({...t,headers:i});if(p.status===401&&typeof this.accessToken=="function"){let c=await vt(this.accessToken);if(c&&c!==o){let u=new Headers(t?.headers);return u.set("authorization",`Bearer ${c}`),this.applyClientHeader(u),s({...t,headers:u})}}return p}async requestResponse(e,t){let r=await this.fetchWithAuth(`${this.apiUrl.replace(/\/$/,"")}${e}`,t);if(!r.ok){let i=`Request failed with status ${r.status}`,o=Dt(r.status),s,p,c;try{let u=await r.json();typeof u.error?.message=="string"&&(i=u.error.message),typeof u.error?.code=="string"&&(o=u.error.code,s=u.error.code),typeof u.error?.hint=="string"&&(p=u.error.hint),typeof u.error?.retryAfter=="number"&&(c=u.error.retryAfter);}catch{}throw new m(o,i,r.status,p,c,s)}return r}async requestJson(e,t){return await(await this.requestResponse(e,t)).json()}async watchRepoQuery(e,t,r,i,o){let s=new AbortController,p=Et(r,s),c=0,u=(async()=>{let l=async()=>{let y=await i();c+=1,await o(y);},g=await this.trpc.live.issueTicket.mutate({orgName:e,repoName:t}),h=await this.openSse(g.ticket,p,async y=>{y.type==="invalidate"&&await l();});return await h.ready,p.aborted?{updates:c}:(await l(),await h.closed,{updates:c})})();return {close(){s.abort();},closed:u}}};function Dt(n){switch(n){case 400:return "VALIDATION_ERROR";case 401:return "UNAUTHENTICATED";case 403:return "FORBIDDEN";case 404:return "NOT_FOUND";case 409:return "CONFLICT";case 429:return "RATE_LIMITED";default:return "BACKEND"}}async function vt(n){if(n)return typeof n=="string"?n:n()}function Et(n,e){return n?n.aborted?(e.abort(),e.signal):(n.addEventListener("abort",()=>e.abort(),{once:true}),e.signal):e.signal}function Fr(n){let e="message",t=[];for(let i of n.split(`
6
6
  `))if(!(!i||i.startsWith(":"))){if(i.startsWith("event:")){e=i.slice(6).trim();continue}i.startsWith("data:")&&t.push(i.slice(5).trim());}if(t.length===0)return null;let r=t.join(`
7
- `);return {type:e,data:JSON.parse(r)}}function Wr(n){return n instanceof Error&&n.name==="AbortError"}export{a as A,qr as B,ni as C,Ur as D,Vr as E,ii as F,kt as G,Ht as a,Ft as b,Wt as c,ze as d,$t as e,N as f,re as g,Jt as h,Se as i,ne as j,ie as k,A as l,v as m,Oe as n,et as o,W as p,P as q,Ee as r,I as s,lr as t,pe as u,ti as v,Le as w,ri as x,De as y,m as z};//# sourceMappingURL=chunk-7ANQAYBN.js.map
8
- //# sourceMappingURL=chunk-7ANQAYBN.js.map
7
+ `);return {type:e,data:JSON.parse(r)}}function Wr(n){return n instanceof Error&&n.name==="AbortError"}export{a as A,qr as B,ni as C,Ur as D,Vr as E,ii as F,kt as G,Ht as a,Ft as b,Wt as c,ze as d,$t as e,N as f,re as g,Jt as h,Se as i,ne as j,ie as k,A as l,v as m,Oe as n,et as o,W as p,P as q,Ee as r,I as s,lr as t,pe as u,ti as v,Le as w,ri as x,De as y,m as z};//# sourceMappingURL=chunk-CJGZJYNN.js.map
8
+ //# sourceMappingURL=chunk-CJGZJYNN.js.map