@opengeni/sdk 4.4.1 → 4.5.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.
Files changed (57) hide show
  1. package/README.md +27 -0
  2. package/dist/adapters/next.js +2 -2
  3. package/dist/artifacts.js +4 -4
  4. package/dist/browser.d.ts +2 -0
  5. package/dist/browser.js +5 -3
  6. package/dist/chat/index.js +5 -5
  7. package/dist/{chunk-3BWTS2MJ.js → chunk-ARDVIZIJ.js} +2 -2
  8. package/dist/{chunk-PVWOBYAZ.js → chunk-BXMNDWAN.js} +256 -78
  9. package/dist/chunk-BXMNDWAN.js.map +1 -0
  10. package/dist/{chunk-IVHLADZ7.js → chunk-GRUMGFK6.js} +2 -2
  11. package/dist/{chunk-2RVPHF37.js → chunk-JBAGMSN2.js} +66 -10
  12. package/dist/chunk-JBAGMSN2.js.map +1 -0
  13. package/dist/{chunk-35S72HAE.js → chunk-U4JUWOZV.js} +5 -5
  14. package/dist/{chunk-BLID3DCD.js → chunk-V4AIZAFF.js} +1 -1
  15. package/dist/chunk-V4AIZAFF.js.map +1 -0
  16. package/dist/{chunk-ALXDFL6C.js → chunk-VSOXNL3T.js} +2 -2
  17. package/dist/{chunk-CT6P2W2C.js → chunk-WI3WUT5H.js} +2 -2
  18. package/dist/client.d.ts +24 -1
  19. package/dist/codex-realtime-controller.js +1 -1
  20. package/dist/core.d.ts +2 -0
  21. package/dist/core.js +5 -3
  22. package/dist/document-authority.js +3 -3
  23. package/dist/editable-artifacts.js +1 -1
  24. package/dist/index.d.ts +4 -2
  25. package/dist/index.js +35 -33
  26. package/dist/index.js.map +1 -1
  27. package/dist/read-retry.d.ts +61 -0
  28. package/dist/realtime.js +5 -5
  29. package/dist/session-proxy.d.ts +6 -1
  30. package/dist/session-proxy.js +2 -2
  31. package/dist/site-bridge-host.js +3 -3
  32. package/dist/site-browser-runtime.gen.d.ts +1 -1
  33. package/dist/site-document.js +1 -1
  34. package/dist/site-document.js.map +1 -1
  35. package/dist/site.js +3 -3
  36. package/dist/types.d.ts +40 -0
  37. package/dist/workspace-artifacts.d.ts +5 -0
  38. package/dist/workspace-live-stream.d.ts +7 -0
  39. package/package.json +3 -3
  40. package/src/browser.ts +2 -0
  41. package/src/client.ts +191 -73
  42. package/src/core.ts +2 -0
  43. package/src/index.ts +4 -0
  44. package/src/read-retry.ts +207 -0
  45. package/src/session-proxy.ts +95 -4
  46. package/src/site-browser-runtime.gen.ts +1 -1
  47. package/src/types.ts +38 -0
  48. package/src/workspace-artifacts.ts +6 -0
  49. package/src/workspace-live-stream.ts +12 -1
  50. package/dist/chunk-2RVPHF37.js.map +0 -1
  51. package/dist/chunk-BLID3DCD.js.map +0 -1
  52. package/dist/chunk-PVWOBYAZ.js.map +0 -1
  53. /package/dist/{chunk-3BWTS2MJ.js.map → chunk-ARDVIZIJ.js.map} +0 -0
  54. /package/dist/{chunk-IVHLADZ7.js.map → chunk-GRUMGFK6.js.map} +0 -0
  55. /package/dist/{chunk-35S72HAE.js.map → chunk-U4JUWOZV.js.map} +0 -0
  56. /package/dist/{chunk-ALXDFL6C.js.map → chunk-VSOXNL3T.js.map} +0 -0
  57. /package/dist/{chunk-CT6P2W2C.js.map → chunk-WI3WUT5H.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/site-browser-runtime.gen.ts","../src/site-document.ts"],"sourcesContent":["// Generated by scripts/generate-site-browser-runtime.ts. Do not edit.\nexport const SITE_BROWSER_RUNTIME = \"(()=>{var Q=(e,t,n)=>()=>{if(e)try{t=e(e=0)}catch(s){n=[s]}if(n)throw n[0];return t};function De(e){return e!==null&&typeof e===\\\"object\\\"&&!Array.isArray(e)?e:null}function ot(e,t=Number.MAX_SAFE_INTEGER){return typeof e===\\\"number\\\"&&Number.isSafeInteger(e)&&e>=0&&e<=t}function os(e){let t=e.slice(0,2048).replace(/[\\\\u0000-\\\\u001f\\\\u007f]+/g,\\\" \\\").trim(),n=new TextEncoder().encode(t),s=Math.min(n.length,1024);while(s>0&&s<n.length&&(n[s]&192)===128)s-=1;return new TextDecoder().decode(n.slice(0,s)).trim()}function ct(e){let t=De(e);if(!t)return null;let n=De(t.sessionUsageLimit)??t;if(n.code!==\\\"session_usage_limit_reached\\\")return null;let s=De(n.details)??n;if(s.basis!==\\\"model_api_equivalent_v1\\\"||typeof s.rootSessionId!==\\\"string\\\"||!rs.test(s.rootSessionId)||!ot(s.limitMicros,10000000000000)||!ot(s.usedMicros))return null;let i={code:\\\"session_usage_limit_reached\\\",basis:\\\"model_api_equivalent_v1\\\",rootSessionId:s.rootSessionId.toLowerCase(),limitMicros:s.limitMicros,usedMicros:s.usedMicros,message:\\\"\\\"},r=typeof n.message===\\\"string\\\"?os(n.message):\\\"\\\";return{...i,message:r||as(i)}}function at(e){if(e>0&&e<1e4)return\\\"<$0.01\\\";return`$${(e/1e6).toLocaleString(\\\"en-US\\\",{minimumFractionDigits:2,maximumFractionDigits:2})}`}function as(e){return`This task's usage limit is reached (${at(e.usedMicros)} of ${at(e.limitMicros)} API-equivalent model usage). A person can raise or remove the limit to continue.`}var rs;var ut=Q(()=>{rs=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i});function lt(e){if(e.status!==400&&e.status!==422)return!1;let t;try{t=JSON.parse(e.body)}catch{return!1}if(!t||typeof t!==\\\"object\\\")return!1;let n=t,s=n.error&&typeof n.error===\\\"object\\\"?n.error:n,i=typeof s.message===\\\"string\\\"?s.message:\\\"\\\",r=/^Invalid session create request: (.+) failed schema validation$/.exec(i);if(s.code===\\\"INVALID_SESSION_CREATE_REQUEST\\\"&&r?.[1]?.split(/,\\\\s*/).includes(\\\"startMode\\\"))return!0;let o=s.details&&typeof s.details===\\\"object\\\"?s.details:null;return(Array.isArray(o?.issues)?o.issues:[]).some((c)=>{if(!c||typeof c!==\\\"object\\\")return!1;let u=c.path;return u===\\\"startMode\\\"||Array.isArray(u)&&u.length===1&&u[0]===\\\"startMode\\\"})}function dt(e){return new de(\\\"The server did not confirm the requested usage limit; it may not support usage limits. Read the limit again before relying on it.\\\",{sessionId:e})}function ze(e){try{let t=JSON.parse(e);if(!t||typeof t!==\\\"object\\\"||Array.isArray(t))return null;let n=t;return ct(n.error&&typeof n.error===\\\"object\\\"&&!Array.isArray(n.error)?n.error:n)}catch{return null}}function Ne(e){try{let t=JSON.parse(e);if(!t||typeof t!==\\\"object\\\"||Array.isArray(t))return null;let n=t,s=n.error&&typeof n.error===\\\"object\\\"&&!Array.isArray(n.error)?n.error:n;if(s.code!==\\\"allowance_exhausted\\\")return null;let i=s.details&&typeof s.details===\\\"object\\\"&&!Array.isArray(s.details)?s.details:s;if(i.scope!==\\\"workspace\\\"&&i.scope!==\\\"member\\\")return null;if(i.resetsAt!==null&&typeof i.resetsAt!==\\\"string\\\")return null;return{scope:i.scope,resetsAt:i.resetsAt,...typeof i.subjectId===\\\"string\\\"?{subjectId:i.subjectId}:{}}}catch{return null}}function cs(e){if(!e)return null;try{let t=JSON.parse(e);if(!t||typeof t!==\\\"object\\\"||Array.isArray(t))return null;let n=t,s=n.error&&typeof n.error===\\\"object\\\"&&!Array.isArray(n.error)?n.error:n,i=$e(s.code),r=$e(s.message),o=pt(s.requestId),a=typeof s.retryable===\\\"boolean\\\"?s.retryable:void 0,c=typeof s.outcomeUnknown===\\\"boolean\\\"?s.outcomeUnknown:void 0,u=us(s.details);if(!i&&!r&&!o&&a===void 0&&c===void 0&&!u)return null;return{code:i,message:r,requestId:o,retryable:a,outcomeUnknown:c,details:u}}catch{return null}}function us(e){if(!e||typeof e!==\\\"object\\\"||Array.isArray(e))return;let t=Object.entries(e).slice(0,16),n={};for(let[s,i]of t){if(!/^[a-zA-Z][\\\\w.-]{0,63}$/.test(s))continue;if(typeof i===\\\"string\\\"){let r=$e(i);if(r!==void 0)n[s]=r}else if(typeof i===\\\"number\\\"||typeof i===\\\"boolean\\\"||i===null)n[s]=i;else if(s===\\\"action\\\"&&typeof i===\\\"object\\\"&&!Array.isArray(i)&&i.type===\\\"upgrade\\\"&&i.href===\\\"/billing\\\")n.action={type:\\\"upgrade\\\",href:\\\"/billing\\\"}}return Object.keys(n).length>0?n:void 0}function $e(e){if(typeof e!==\\\"string\\\")return;let t=new TextEncoder().encode(e);return t.byteLength<=512?e:new TextDecoder().decode(t.slice(0,512))}function ls(e){return e===408||e===409||e===425||e===429||e>=500}function pt(e){if(typeof e!==\\\"string\\\"||e.length>128||!/^[\\\\w.:-]+$/.test(e))return;return e}function V(e){return e instanceof DOMException&&e.name===\\\"AbortError\\\"||e instanceof Error&&e.name===\\\"AbortError\\\"}function H(e){if(e instanceof w)return e.retryable;return e instanceof TypeError}var w,Be,Le,We,de,be,Fe,we,B;var K=Q(()=>{ut();w=class w extends Error{status;code;retryable;correlationId;outcomeUnknown;body;details;constructor(e,t,n={}){let s=cs(t),i=s?.requestId??pt(n.correlationId),r=e>=502&&e<=504,o=n.mutation!==void 0,a=s?.message??(o?\\\"Request failed.\\\":t||\\\"(empty body)\\\"),c=n.displayMessage??(r&&o?s?.message??\\\"The workspace is temporarily unavailable — retry.\\\":`API ${e}: ${a}`);super(i?`${c} Reference: ${i}.`:c);this.name=\\\"OpenGeniApiError\\\",this.status=e,this.code=n.code??s?.code??(r&&o?\\\"upstream_unavailable\\\":void 0),this.retryable=n.retryable??s?.retryable??ls(e),this.correlationId=i,this.outcomeUnknown=n.outcomeUnknown??s?.outcomeUnknown??(r&&!!n.mutation&&!s),this.body=!o||s?t:\\\"\\\",this.details=s?.details}};Be=class Be extends w{constructor(e){super(e.status,e.body,{code:\\\"OPENGENI_SETUP_REQUIRED\\\",retryable:!1,correlationId:e.correlationId,displayMessage:\\\"Private chats require organization_private_session_settings.enabled (migration 0323). An organization owner or admin can enable Only me chats in the web app under Organization settings > Security & data, or use updateOrganizationPrivateSessionSettings from @opengeni/sdk/organization-private-session-settings with enabled: true, the current expectedVersion and a stable operationId (PATCH /v1/organizations/:organizationId/private-session-settings; an organization key needs workspace:admin). If platform readiness is unavailable, ask the deployment operator to activate session tenancy first.\\\"});this.name=\\\"OpenGeniSetupError\\\"}};Le=class Le extends w{scope;resetsAt;subjectId;constructor(e,t,n={}){super(e,t,{...n,code:\\\"allowance_exhausted\\\",retryable:!1,outcomeUnknown:!1});this.name=\\\"OpenGeniAllowanceExhaustedError\\\";let s=Ne(t);this.scope=s?.scope??\\\"workspace\\\",this.resetsAt=s?.resetsAt??null,this.subjectId=s?.subjectId}};We=class We extends w{rootSessionId;limitMicros;usedMicros;constructor(e,t,n={}){super(e,t,{...n,code:\\\"session_usage_limit_reached\\\",retryable:!1,outcomeUnknown:!1});this.name=\\\"OpenGeniSessionUsageLimitReachedError\\\";let s=ze(t);this.rootSessionId=s?.rootSessionId,this.limitMicros=s?.limitMicros,this.usedMicros=s?.usedMicros}};de=class de extends Error{code=\\\"session_usage_limit_unsupported\\\";sessionId;constructor(e,t={}){super(e,t.cause===void 0?void 0:{cause:t.cause});this.name=\\\"OpenGeniSessionUsageLimitUnsupportedError\\\",this.sessionId=t.sessionId??null}};be=class be extends Error{code=\\\"secure_context_required\\\";retryable=!1;reason;constructor(e){super(e===\\\"insecure_context\\\"?\\\"Couldn’t attach this file because this page is open over HTTP. Attachments require a secure HTTPS connection. Open the secure site or configure HTTPS for this deployment.\\\":\\\"Couldn’t attach this file because secure browser cryptography is unavailable. Attachments require HTTPS and Web Crypto support. Open a secure site in a supported browser or configure HTTPS for this deployment.\\\");this.name=\\\"OpenGeniSecureContextRequiredError\\\",this.reason=e}};Fe=class Fe extends w{};we=class we extends Error{expected;actual;constructor(e,t){super(`API contract mismatch: client expects ${e}, API serves ${t}`);this.name=\\\"OpenGeniApiContractMismatchError\\\",this.expected=e,this.actual=t}};B=class B extends Error{constructor(e){super(e);this.name=\\\"OpenGeniStreamError\\\"}}});function ve(e){let t=null,n=0,s=!1,i=null,r=null,o=()=>{if(i&&i.epoch===n)return i;let l=s,p={epoch:n,controller:new AbortController,waiters:0,settled:!1};return i=p,p.promise=(async()=>{try{let d=await e(l,p.controller.signal);if(p.epoch===n&&!p.controller.signal.aborted)t=d,s=!1;return d}finally{if(p.settled=!0,i===p)i=null}})(),p.promise.catch(()=>{return}),p},a=(l,p)=>{if(i===l)i=null;if(r?.load===l)r=null;l.controller.abort(p)},c=(l,p)=>{if(p?.aborted)return Promise.reject(gt(p));return l.waiters+=1,new Promise((d,m)=>{let y=!1,R=()=>{if(y)return!1;return y=!0,l.waiters-=1,p?.removeEventListener(\\\"abort\\\",v),!0},v=()=>{if(!R())return;let b=gt(p);if(m(b),l.waiters===0&&!l.settled)a(l,b)};p?.addEventListener(\\\"abort\\\",v,{once:!0}),l.promise.then((b)=>{if(R())d(b)},(b)=>{if(R())m(b)})})},u=()=>{t=null,n+=1,s=!0};return{async load(l={}){if(l.signal?.throwIfAborted(),l.refresh)u();if(t)return t;return await c(o(),l.signal)},async reloadAfterStale(l,p){p?.throwIfAborted();let d=r;if(d?.staleDigest===l&&(d.settled===null?d.load.epoch===n:d.settled===t))return await c(d.load,p);u();let m=o(),y={staleDigest:l,load:m,settled:null};return r=y,m.promise.then((R)=>{if(r!==y)return;if(R.digest===l)r=null;else y.settled=R},()=>{if(r===y)r=null}),await c(m,p)},invalidate(l){if(t?.digest===l)u()}}}function gt(e){return e.reason??new DOMException(\\\"The operation was aborted.\\\",\\\"AbortError\\\")}function yt(e,t,n){let s=`/v1/workspaces/${encodeURIComponent(t)}/tools`,i,r=()=>i??=n(),o=new Set,a=new Map,c=new Map,u=new Map,l=0,p=(S)=>{if(!u.has(S)&&u.size>=256)u.delete(u.keys().next().value);let h=++l;return u.set(S,h),h},d=new Map,m=(S)=>{let h=ge(S),f=a.get(h);if(!f){if(f=ve(async(x,A)=>{let k=await e.requestJson(\\\"POST\\\",`${s}/resolve`,{target:S},{},{signal:A});return{...k,digest:k.definitionDigest}}),a.size>=256)a.delete(a.keys().next().value);a.set(h,f)}return f},y=(S,h,f)=>{let x=ge(S);if(u.get(x)!==f)return;if(c.size>=256)c.delete(c.keys().next().value);c.set(x,h)},R=async(S,h={})=>{if(h.siteArtifactId||h.siteVersionId)return await e.requestJson(\\\"POST\\\",`${s}/resolve`,{target:S,siteArtifactId:h.siteArtifactId,siteVersionId:h.siteVersionId},{},h.signal?{signal:h.signal}:{});let f=ge(S),x=p(f);if(h.refresh)c.delete(f);let A=await m(S).load(h);return y(S,A,x),A},v=(S,h={})=>e.requestJson(\\\"POST\\\",`${s}/invoke`,S,{},h),b=async(S,h={},f={})=>{if(f.approvalToken&&(f.approvalBinding===\\\"catalog\\\"||o.has(f.approvalToken))){if(\\\"identity\\\"in S)return await r().$call(S.identity,h,f);let z=r();for(let Zn of S.path)z=z[Zn];return await z(h,f)}if(f.approvalToken&&!f.operationId)throw TypeError(\\\"operationId is required when using an approval token\\\");f.signal?.throwIfAborted();let x=f.operationId??crypto.randomUUID(),A=ge(S),k=p(A);if(f.refreshCatalog)c.delete(A);let I=f.refreshCatalog?await m(S).load({refresh:!0,...f.signal?{signal:f.signal}:{}}):c.get(A),O=f.approvalToken?d.get(f.approvalToken):void 0,J=f.expectedDefinitionDigest!==void 0?f.expectedDefinitionDigest:f.approvalToken?void 0:I?.definitionDigest;if(O&&(O.operationId!==x||(\\\"identity\\\"in S)&&ge({identity:O.tool.entry.identity})!==A))throw new se(x,O.tool.definitionDigest,J??\\\"\\\",O.tool.entry.identity);let X=(z)=>v({operationId:x,target:S,arguments:h,...z===void 0?{}:{expectedDefinitionDigest:z},...f.approvalToken?{approvalToken:f.approvalToken}:{}},f.signal?{signal:f.signal}:{}),F;try{F=await X(J)}catch(z){if(!gs(z)||J===void 0)throw z;if(u.get(A)===k)c.delete(A);if(f.expectedDefinitionDigest!==void 0&&!f.approvalToken)throw z;if(I=await m(S).reloadAfterStale(J,f.signal),y(S,I,k),f.approvalToken||f.expectedDefinitionDigest!==void 0)throw new se(x,J,I.definitionDigest,I.entry.identity);F=await X(I.definitionDigest)}if(f.approvalToken)d.delete(f.approvalToken);if(y(S,F.tool,k),F.result.isError)throw new ke(F.result);return F.tool.entry.outputSchema&&F.result.structuredContent!==void 0?F.result.structuredContent:F.result},C=async(S,h={},f={})=>{let x=await R({identity:S},{...f.signal?{signal:f.signal}:{}}),A=await e.requestJson(\\\"POST\\\",`${s}/target-approvals`,{identity:S,arguments:h,operationId:f.operationId??crypto.randomUUID(),expectedDefinitionDigest:f.expectedDefinitionDigest===void 0?x.definitionDigest:f.expectedDefinitionDigest},{},f.signal?{signal:f.signal}:{});if(d.size>=256)d.delete(d.keys().next().value);return d.set(A.approvalToken,A),A},P=(S)=>new Proxy(async(h={},f={})=>b({path:S},h,f),{get:(h,f)=>f===\\\"then\\\"||typeof f!==\\\"string\\\"?void 0:P([...S,f])});return new Proxy(Object.create(null),{get:(S,h)=>{if(h===\\\"then\\\"||typeof h!==\\\"string\\\")return;if(h===\\\"$targetProtocol\\\")return 1;if(h===\\\"$resolve\\\")return R;if(h===\\\"$invoke\\\")return v;if(h===\\\"$manifest\\\")return(f,x={})=>e.requestJson(\\\"POST\\\",`${s}/manifest`,f,{},x);if(h===\\\"$call\\\")return(f,x,A)=>b({identity:f},x,A);if(h===\\\"$approveTarget\\\")return C;if(h===\\\"$approve\\\")return async(...f)=>{let x=await r().$approve(...f);if(o.size>=256)o.delete(o.values().next().value);return o.add(x.approvalToken),x};if(h===\\\"$catalog\\\")return r().$catalog;if(h===\\\"$declarations\\\")return r().$declarations;return P([h])}})}var ge=(e)=>(\\\"identity\\\"in e)?JSON.stringify([\\\"identity\\\",e.identity.serverId,e.identity.toolName]):JSON.stringify([\\\"path\\\",...e.path]),gs=(e)=>{if(typeof e!==\\\"object\\\"||e===null)return!1;if(\\\"outcomeUnknown\\\"in e&&e.outcomeUnknown===!0||\\\"retryable\\\"in e&&e.retryable===!1)return!1;return e instanceof w?e.status===409&&e.details?.code===\\\"tool_definition_stale\\\":typeof e===\\\"object\\\"&&e!==null&&(\\\"code\\\"in e)&&e.code===\\\"tool_definition_stale\\\"};var ft=Q(()=>{K();Ie()});class ie{transport;constructor(e){this.transport=e}forWorkspace(e){let t=fs(e,\\\"workspaceId\\\");if(this.transport.toolGatewayMode!==\\\"catalog\\\")return yt(this.transport,t,()=>new ie({toolGatewayMode:\\\"catalog\\\",requestJson:this.transport.requestJson.bind(this.transport)}).forWorkspace(t));let n=`/v1/workspaces/${encodeURIComponent(t)}/tools/catalog`,s=ve(async(d,m)=>await this.transport.requestJson(\\\"GET\\\",n,void 0,{},{signal:m})),i=new Map,r=async(d={})=>await s.load({...d.refresh?{refresh:!0}:{},...d.signal?{signal:d.signal}:{}}),o=async(d,m)=>await s.reloadAfterStale(d,m),a=async(d,m,y)=>{if(y.approvalToken&&!y.operationId)throw TypeError(\\\"operationId is required when using an approval token\\\");let R=y.operationId??crypto.randomUUID(),v=await r({...y.refreshCatalog===void 0?{}:{refresh:y.refreshCatalog},...y.signal?{signal:y.signal}:{}}),b=async(S)=>{let h=d(S),f=y.approvalToken?i.get(y.approvalToken):void 0;if(f&&(f.operationId!==R||f.catalogDigest!==S.digest||!ms(f.identity,h)))throw new se(R,f.catalogDigest,S.digest,h);let x={operationId:R,catalogDigest:S.digest,identity:h,arguments:m,...y.approvalToken?{approvalToken:y.approvalToken}:{}},A;try{A=await this.transport.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(t)}/tools/calls`,x,{},y.signal?{signal:y.signal}:{})}catch(I){if(Ce(I))s.invalidate(S.digest);else if(y.approvalToken)i.delete(y.approvalToken);throw I}if(y.approvalToken)i.delete(y.approvalToken);if(A.catalogDigest!==S.digest)s.invalidate(S.digest);if(A.result.isError)throw new ke(A.result);return Rt(S,h)?.outputSchema&&A.result.structuredContent!==void 0?A.result.structuredContent:A.result};try{return await b(v)}catch(S){if(!Ce(S))throw S}let C=await o(v.digest,y.signal),P=d(C);if(y.approvalToken&&C.digest!==v.digest)throw new se(R,v.digest,C.digest,P);return await b(C)},c=async(d,m={},y={})=>await a((R)=>ht(R,d),m,y),u=async(d,m={},y={})=>{let R=y.operationId??crypto.randomUUID(),v=async(P)=>{let S={operationId:R,catalogDigest:P.digest,identity:ht(P,d),arguments:m};try{let h=await this.transport.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(t)}/tools/approvals`,S,{},y.signal?{signal:y.signal}:{});return i.set(h.approvalToken,{operationId:h.operationId,catalogDigest:h.catalogDigest,identity:h.identity}),h}catch(h){if(Ce(h))s.invalidate(P.digest);throw h}},b=await r(y.signal?{signal:y.signal}:{});try{return await v(b)}catch(P){if(!Ce(P))throw P}let C=await o(b.digest,y.signal);return await v(C)},l=async(d,m={},y={})=>await a((R)=>ys(R,d).identity,m,y),p=(d)=>new Proxy(async(m={},y={})=>await l(d,m,y),{get:(m,y)=>{if(y===\\\"then\\\")return;if(typeof y!==\\\"string\\\")return;return p([...d,y])}});return new Proxy(Object.create(null),{get:(d,m)=>{if(m===\\\"then\\\")return;if(m===\\\"$catalog\\\")return r;if(m===\\\"$call\\\")return c;if(m===\\\"$approve\\\")return u;if(m===\\\"$declarations\\\")return async(y={})=>await this.transport.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(t)}/tools/declarations`,void 0,{},y.signal?{signal:y.signal}:{});if(typeof m!==\\\"string\\\")return;return p([m])}})}}function Rt(e,t){return e.entries.find((n)=>n.identity.serverId===t.serverId&&n.identity.toolName===t.toolName)}function ms(e,t){return e.serverId===t.serverId&&e.toolName===t.toolName}function ht(e,t){let n=Rt(e,t);if(!n)throw Error(`Tool is not present in the workspace catalog: ${t.serverId}/${t.toolName}`);return n.identity}function ys(e,t){let n=e.entries.find((s)=>s.codemodePath.length===t.length&&s.codemodePath.every((i,r)=>i===t[r]));if(!n)throw Error(`Tool is not present in the workspace catalog: ${t.join(\\\".\\\")}`);return n}function Ce(e){if(typeof e!==\\\"object\\\"||e===null||\\\"outcomeUnknown\\\"in e&&e.outcomeUnknown===!0||\\\"retryable\\\"in e&&e.retryable===!1)return!1;return e instanceof w&&e.status===409&&e.details?.code===\\\"catalog_stale\\\"||typeof e===\\\"object\\\"&&e!==null&&\\\"code\\\"in e&&e.code===\\\"catalog_stale\\\"}function fs(e,t){let n=e.trim();if(!n)throw TypeError(`${t} is required`);return n}var ke,se;var Ie=Q(()=>{ft();K();ke=class ke extends Error{result;code;retryable;outcomeUnknown;constructor(e){let t=e.structuredContent;super(typeof t?.error?.message===\\\"string\\\"?t.error.message:\\\"Tool call failed\\\");this.result=e;this.name=\\\"OpenGeniToolCallError\\\",this.code=typeof t?.error?.code===\\\"string\\\"?t.error.code:\\\"tool_error\\\",this.retryable=t?.error?.retryable===!0,this.outcomeUnknown=t?.error?.outcomeUnknown===!0}};se=class se extends Error{operationId;previousCatalogDigest;catalogDigest;identity;code=\\\"tool_reapproval_required\\\";retryable=!1;constructor(e,t,n,s){super(\\\"The workspace tool catalog changed after approval. Request a new approval for the refreshed tool identity and retry with the same operation ID.\\\");this.operationId=e;this.previousCatalogDigest=t;this.catalogDigest=n;this.identity=s;this.name=\\\"OpenGeniToolReapprovalRequiredError\\\"}}});function si(e,t){if(e.length<t.length)return!1;let n=e.length-t.length;return t.every((s,i)=>e[n+i]===s)}function ii(e){for(let t of e.matchAll(Qs)){let n=t[2]??t[3];if(!n)continue;let s=n.replace(/([a-z0-9])([A-Z])/g,\\\"$1 $2\\\").replace(/([A-Z]+)([A-Z][a-z])/g,\\\"$1 $2\\\").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean),i=s.at(-1);if(i&&ei.has(i))return!0;if(i&&ti.some((r)=>i.endsWith(r)))return!0;if(ni.some((r)=>si(s,r)))return!0}return!1}function ri(e){for(let t of e.matchAll(Vs))if(!Hs.test(t[0]))return!0;return!1}function oi(e){if(/[?:#]/u.test(e))return!1;let[t,...n]=e.split(\\\"/\\\");if(!t||n.length===0||n.some((s)=>!s))return!1;if(!Xs.has(t)||n.some((s)=>!/^[A-Z][A-Za-z0-9_-]*$/u.test(s)))return!1;return!0}function ai(e){if(js.some((t)=>t.test(e)))return!0;for(let t of e.matchAll(Ks)){let n=t[0];if(n.toLowerCase().startsWith(\\\"www.\\\"))return!0;if(!/[/?#]/u.test(n))continue;let r=(n.split(/[/?#]/u,1)[0]??\\\"\\\").replace(/:\\\\d{1,5}$/u,\\\"\\\").split(\\\".\\\").at(-1)?.toLowerCase();if(r&&Ys.has(r))continue;if(oi(n))continue;return!0}return!1}function di(e){return e.normalize(\\\"NFKC\\\").replace(ui,\\\"\\\").replace(li,\\\"\\\")}function pi(e){let t=di(e);if(Js.some((n)=>n.test(t)))return!0;if(ri(t))return!0;if(ai(t))return!0;if(Zs.test(t))return!0;if(ii(t))return!0;if(ci.test(t))return!0;return!1}function gi(e){if(qe===void 0)qe=typeof Intl.Segmenter===\\\"function\\\"?new Intl.Segmenter(void 0,{granularity:\\\"grapheme\\\"}):null;if(qe)return Array.from(qe.segment(e),(n)=>n.segment);let t=[];for(let n of e){let s=t.at(-1);if(s&&(/^[\\\\p{Mark}\\\\u{FE0E}\\\\u{FE0F}\\\\p{Emoji_Modifier}]$/u.test(n)||n===\\\"‍\\\"||s.endsWith(\\\"‍\\\")))t[t.length-1]=`${s}${n}`;else t.push(n)}return t}function yi(e){return e.replace(mi,`\\n`)}function fi(e,t){if(e===null||e===void 0)return null;if(t===\\\"user\\\")return e;let n=yi(e);if(n===e)return e;return n.split(`\\n`).map((s)=>s.trim()).find(Boolean)??null}function hi(e){let t=e.split(/\\\\s+/u),n=t.length>10?t.slice(0,10).join(\\\" \\\"):e,s=gi(n);if(s.length<=80)return n;let i=s.slice(0,80).join(\\\"\\\"),r=i.search(/\\\\s+\\\\S*$/u);return(r>=16?i.slice(0,r):i).trimEnd()}function je(e){if(typeof e!==\\\"string\\\")return null;let t=e.slice(0,4096).replace(/[\\\\u0000-\\\\u001f\\\\u007f-\\\\u009f]+/gu,`\\n`).split(/\\\\n+/u);for(let n of t){let s=n.trim();if(!s||pi(s))continue;let i=hi(s.replace(/\\\\s+/gu,\\\" \\\")).replace(/[\\\\s.!?,;:\\\\-–—]+$/u,\\\"\\\").trim();if(i)return i}return null}function In(e){let t=typeof e===\\\"string\\\"?e.trim():\\\"\\\";return Fs.test(t)?`Conversation ${t.slice(0,13)}`:\\\"New conversation\\\"}function Ye(e){let t=e.title?.trim()??\\\"\\\";return e.titleSource!==\\\"user\\\"&&(!t||t===\\\"New conversation\\\")}function Cn(e,t={}){let n=e.title?.trim()??\\\"\\\";if(e.titleSource===\\\"user\\\")return n||In(e.id);if(n&&!Ye(e)){let s=fi(n,e.titleSource)?.trim();if(s)return s}for(let s of t.metadataKeys??[]){let i=e.metadata?.[s];if(typeof i===\\\"string\\\"&&i.trim().length>0)return i.trim()}return je(e.initialMessage)??In(e.id)}var Fs,qe,Js,Vs,Hs,Ks,js,Ys,Xs,Qs,Zs,ei,ti,ni,ci,ui,li,mi;var An=Q(()=>{Fs=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,Js=[/-----BEGIN [A-Z ]*PRIVATE KEY-----/iu,/\\\\bBearer\\\\s+[A-Za-z0-9._~+/=-]{8,}/iu,/\\\\b(?:sk-(?:proj-)?|gh[oprsu]_|github_pat_|glpat-|xox[baprs]-)[A-Za-z0-9_-]{8,}/iu,/\\\\bAKIA[0-9A-Z]{16}\\\\b/u,/\\\\bAIza[0-9A-Za-z_-]{20,}\\\\b/u,/\\\\beyJ[A-Za-z0-9_-]+\\\\.eyJ[A-Za-z0-9_-]+\\\\.[A-Za-z0-9_-]+\\\\b/u,/[?&](?:access_token|api_key|apikey|password|secret|token)=[^\\\\s&#]+/iu],Vs=/\\\\b[a-z][a-z0-9+.-]*:\\\\S+/giu,Hs=/^[a-z]:[\\\\\\\\/](?![\\\\\\\\/])[^:]*$/iu,Ks=/\\\\b(?:www\\\\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\\\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?(?::\\\\d{1,5})?(?:[/?#][^\\\\s]*)?/giu,js=[/\\\\blocalhost(?:(?::\\\\d{1,5})(?:[/?#][^\\\\s]*)?|[/?#][^\\\\s]*)/iu,/\\\\b(?:(?:25[0-5]|2[0-4]\\\\d|1?\\\\d?\\\\d)\\\\.){3}(?:25[0-5]|2[0-4]\\\\d|1?\\\\d?\\\\d)(?:(?::\\\\d{1,5})(?:[/?#][^\\\\s]*)?|[/?#][^\\\\s]*)/u,/\\\\[(?=[0-9a-f:.]*:[0-9a-f:.]*\\\\])[0-9a-f:.]+\\\\](?:(?::\\\\d{1,5})(?:[/?#][^\\\\s]*)?|[/?#][^\\\\s]*)/iu],Ys=new Set([\\\"css\\\",\\\"html\\\",\\\"js\\\",\\\"json\\\",\\\"jsx\\\",\\\"lock\\\",\\\"md\\\",\\\"sql\\\",\\\"toml\\\",\\\"ts\\\",\\\"tsx\\\",\\\"xml\\\",\\\"yaml\\\",\\\"yml\\\"]),Xs=new Set([\\\"ASP.NET\\\",\\\"AWS.SDK\\\",\\\"Microsoft.Extensions\\\",\\\"System.IO\\\"]),Qs=/(?:^|[^A-Za-z0-9])(?:(['\\\"])([A-Za-z][A-Za-z0-9_. -]*)\\\\1|([A-Za-z][A-Za-z0-9_.-]*))\\\\s*[=:]\\\\s*[^\\\\s,;]+/gu,Zs=/\\\\b(?:api[ _-]?key|access[ _-]?token|auth[ _-]?token|credential|credentials|password|passwd|private[ _-]?key|secret|token)\\\\b\\\\s*[=:]\\\\s*[^\\\\s,;]+/iu,ei=new Set([\\\"credential\\\",\\\"credentials\\\",\\\"password\\\",\\\"passwd\\\",\\\"secret\\\",\\\"token\\\"]),ti=[\\\"apikey\\\",\\\"accesskey\\\",\\\"accesskeyid\\\",\\\"accesstoken\\\",\\\"authtoken\\\",\\\"credential\\\",\\\"credentials\\\",\\\"password\\\",\\\"passwd\\\",\\\"privatekey\\\",\\\"secret\\\",\\\"secretkey\\\",\\\"token\\\"],ni=[[\\\"api\\\",\\\"key\\\"],[\\\"access\\\",\\\"key\\\"],[\\\"access\\\",\\\"key\\\",\\\"id\\\"],[\\\"auth\\\",\\\"key\\\"],[\\\"private\\\",\\\"key\\\"],[\\\"secret\\\",\\\"key\\\"]];ci=/\\\\b(?=[A-Za-z0-9_-]{32,}\\\\b)(?=[A-Za-z0-9_-]*[A-Za-z])(?=[A-Za-z0-9_-]*\\\\d)[A-Za-z0-9_-]+\\\\b/u,ui=/\\\\p{Default_Ignorable_Code_Point}+/gu,li=/\\\\\\\\+(?=[\\\"'])/gu;mi=/<[||][^<>||\\\\s]{1,64}[||]>/gu});function Ee(e){let t=e.metadata._opengeniSiteOrigin,n=t&&typeof t.siteId===\\\"string\\\"&&/^[\\\\da-f]{8}-[\\\\da-f]{4}-[\\\\da-f]{4}-[\\\\da-f]{4}-[\\\\da-f]{12}$/i.test(t.siteId)&&typeof t.title===\\\"string\\\"?{siteId:t.siteId,title:t.title}:null,s=e.metadata.scheduledTaskId;return{id:e.id,workspaceId:e.workspaceId,accountId:e.accountId,status:e.status,backgroundCommandActivity:e.backgroundCommandActivity,hasSchedules:e.hasSchedules,hasUpcomingSchedules:e.hasUpcomingSchedules,title:e.title,titleSource:e.titleSource,displayTitle:Cn(e),renameSeed:Ye(e)?je(e.initialMessage)??\\\"\\\":e.title?.trim()??\\\"\\\",scheduledTaskId:typeof s===\\\"string\\\"&&s.length>0?s:null,siteOrigin:n,...e.model?{model:e.model}:{},...e.reasoningEffort?{reasoningEffort:e.reasoningEffort}:{},createdBy:e.createdBy,channelId:e.channelId,parentSessionId:e.parentSessionId,rootSessionId:e.rootSessionId,effectiveControl:e.effectiveControl,inputWait:e.inputWait,lastSequence:e.lastSequence,pinned:e.pinned??!1,pinnedAt:e.pinnedAt??null,pinVersion:e.pinVersion??0,unread:e.unread??!1,activelyWorking:e.activelyWorking??!1,attentionVersion:e.attentionVersion??0,archived:e.archived??!1,archivedAt:e.archivedAt??null,importedArchive:e.importedArchive,...e.retention?{retention:e.retention}:{},archiveVersion:e.archiveVersion??0,treeStats:e.treeStats,requiresActionSince:e.requiresActionSince,...e.admissionBlock!==void 0?{admissionBlock:e.admissionBlock}:{},createdAt:e.createdAt,updatedAt:e.updatedAt}}var Pn=Q(()=>{An()});var xn=Q(()=>{Pn()});var es=Object.freeze([{id:\\\"config.client\\\",method:\\\"GET\\\",pattern:/^\\\\/v1\\\\/config\\\\/client$/u},{id:\\\"workspace.get\\\",method:\\\"GET\\\",pattern:/^$/u},{id:\\\"site.config\\\",method:\\\"GET\\\",pattern:/^\\\\/site\\\\/config$/u},{id:\\\"models.list\\\",method:\\\"GET\\\",pattern:/^\\\\/model-catalog$/u},{id:\\\"sessions.list\\\",method:\\\"GET\\\",pattern:/^\\\\/sessions$/u},{id:\\\"sessions.create\\\",method:\\\"POST\\\",pattern:/^\\\\/sessions$/u,agent:!0},{id:\\\"sessions.get\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}$\\\",\\\"u\\\")},{id:\\\"sessions.events\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/events$\\\",\\\"u\\\")},{id:\\\"sessions.stream\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/events/stream$\\\",\\\"u\\\"),stream:!0},{id:\\\"sessions.send\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/events$\\\",\\\"u\\\"),agent:!0},{id:\\\"sessions.steer\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/steer$\\\",\\\"u\\\"),agent:!0},{id:\\\"sessions.control\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/control$\\\",\\\"u\\\"),agent:!0},{id:\\\"sessions.queue\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/queue$\\\",\\\"u\\\")},{id:\\\"sessions.queue.item\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/queue/[A-Za-z0-9_-]{1,128}/(?:move|edit|steer|delete)$\\\",\\\"u\\\"),agent:!0},{id:\\\"sessions.composerDraft.get\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/composer-draft$\\\",\\\"u\\\")},{id:\\\"sessions.composerDraft.put\\\",method:\\\"PUT\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/composer-draft$\\\",\\\"u\\\")},{id:\\\"sessions.composerDraft.submit\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/composer-draft/submit$\\\",\\\"u\\\"),agent:!0},{id:\\\"sessions.humanInput\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/human-input-requests$\\\",\\\"u\\\")},{id:\\\"sessions.humanInput.get\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/human-input-requests/[A-Za-z0-9_-]{1,128}$\\\",\\\"u\\\")},{id:\\\"data.read\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/published-artifacts/current/(?:data|files)(?:/[A-Za-z0-9._~:@!$&'()*+,;=-]+)*$\\\",\\\"u\\\")},{id:\\\"data.write\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/published-artifacts/current/(?:data|files)(?:/[A-Za-z0-9._~:@!$&'()*+,;=-]+)*$\\\",\\\"u\\\")},{id:\\\"data.put\\\",method:\\\"PUT\\\",pattern:new RegExp(\\\"^/published-artifacts/current/(?:data|files)(?:/[A-Za-z0-9._~:@!$&'()*+,;=-]+)*$\\\",\\\"u\\\")},{id:\\\"data.patch\\\",method:\\\"PATCH\\\",pattern:new RegExp(\\\"^/published-artifacts/current/(?:data|files)(?:/[A-Za-z0-9._~:@!$&'()*+,;=-]+)*$\\\",\\\"u\\\")},{id:\\\"data.delete\\\",method:\\\"DELETE\\\",pattern:new RegExp(\\\"^/published-artifacts/current/(?:data|files)(?:/[A-Za-z0-9._~:@!$&'()*+,;=-]+)*$\\\",\\\"u\\\")},{id:\\\"sql.run\\\",method:\\\"POST\\\",pattern:/^\\\\/published-artifacts\\\\/current\\\\/sql\\\\/queries\\\\/[A-Za-z][A-Za-z0-9_-]{0,63}$/u},{id:\\\"site.report\\\",method:\\\"POST\\\",pattern:/^\\\\/site\\\\/reports$/u}]),lr=Object.freeze([\\\"catalog\\\",\\\"declarations\\\",\\\"call\\\",\\\"resolve\\\",\\\"invoke\\\"]);function st(e,t){if(/[%\\\\\\\\#\\\\u0000-\\\\u0020\\\\u007f]/u.test(t))return null;if(t.split(\\\"/\\\").some((r)=>r===\\\".\\\"||r===\\\"..\\\"))return null;let n=e.toUpperCase(),s;if(t===\\\"/v1/config/client\\\")s=t;else if(t===\\\"/v1/workspaces/site-host\\\")s=\\\"\\\";else if(t.startsWith(\\\"/v1/workspaces/site-host/\\\"))s=t.slice(24);else return null;let i=es.find((r)=>r.method===n&&r.pattern.test(s));return i?{operation:i,suffix:s}:null}var ts=/^\\\\/v1\\\\/workspaces\\\\/site-host\\\\/published-artifacts\\\\/([^/]+)\\\\/(?:data|files|sql)(?:\\\\/|$)/u,ns=\\\"00000000-0000-0000-0000-000000000000\\\";class Se extends Error{code=\\\"site_session_path_unsupported\\\";constructor(){super(\\\"Unsupported Site session API path\\\");this.name=\\\"SiteSessionPathError\\\"}}class rt extends Error{code=\\\"site_data_unsupported\\\";constructor(){super(\\\"This Site host does not provide Site Data\\\");this.name=\\\"SiteDataUnsupportedError\\\"}}function ss(e,t){let n=new URL(e,\\\"http://site.invalid\\\");if(n.pathname===\\\"/v1/config/client\\\"){let s=n.searchParams.getAll(\\\"workspaceId\\\");if(s.length>1||s.length===1&&s[0]!==\\\"site-host\\\"&&s[0]!==t)throw new Se;if(t!==\\\"site-host\\\")n.searchParams.set(\\\"workspaceId\\\",t);return n.pathname+n.search}return e.replace(\\\"/workspaces/site-host\\\",`/workspaces/${encodeURIComponent(t)}`)}function is(e,t,n,s){if(n===\\\"site-host\\\")return e;if(!s)throw new rt;return t.replace(\\\"/published-artifacts/current/\\\",`/published-artifacts/${encodeURIComponent(s)}/`)}function le(e,t,n=\\\"GET\\\",s){let i=e.split(\\\"?\\\")[0],r=st(n,i);if(!r)throw new Se;let o=ss(e,t);if(ts.test(i))return is(e,o,t,s);if(r.operation.id!==\\\"sessions.list\\\")return o;let a=new URL(o,\\\"http://site.invalid\\\"),c=a.searchParams.getAll(\\\"originSiteId\\\"),u=a.searchParams.getAll(\\\"siteAccessId\\\"),l=a.searchParams.getAll(\\\"view\\\");if(l.length>1||l.length===1&&l[0]!==\\\"page\\\"||c.length+u.length!==1||(c[0]??u[0])!==\\\"current\\\")throw new Se;if(t===\\\"site-host\\\")return e;return a.searchParams.set(u.length?\\\"siteAccessId\\\":\\\"originSiteId\\\",s??ns),a.pathname+a.search}var it=[\\\"text\\\",\\\"annotations\\\",\\\"model\\\",\\\"reasoningEffort\\\",\\\"latencyMode\\\",\\\"controlEtag\\\",\\\"expectedDraftRevision\\\"],gr=Object.freeze({\\\"sessions.send\\\":[\\\"type\\\",\\\"payload\\\",\\\"clientEventId\\\"],\\\"sessions.steer\\\":[...it,\\\"clientEventId\\\"],\\\"sessions.control\\\":[\\\"action\\\",\\\"reason\\\",\\\"clientEventId\\\",\\\"expectedControlEtag\\\"],\\\"sessions.composerDraft.put\\\":[\\\"text\\\",\\\"annotations\\\",\\\"resources\\\",\\\"model\\\",\\\"reasoningEffort\\\",\\\"latencyMode\\\",\\\"expectedRevision\\\"],\\\"sessions.composerDraft.submit\\\":[...it,\\\"resources\\\",\\\"connectionAccounts\\\",\\\"clientEventId\\\",\\\"delivery\\\"],\\\"sessions.queue.move\\\":[\\\"clientEventId\\\",\\\"expectedQueueVersion\\\",\\\"beforeTurnId\\\"],\\\"sessions.queue.edit\\\":[\\\"clientEventId\\\",\\\"expectedTurnVersion\\\",\\\"expectedDraftRevision\\\",\\\"replaceDraft\\\"],\\\"sessions.queue.steer\\\":[\\\"clientEventId\\\",\\\"expectedTurnVersion\\\",\\\"controlEtag\\\"],\\\"sessions.queue.delete\\\":[\\\"clientEventId\\\",\\\"expectedTurnVersion\\\",\\\"reason\\\"]});var mr=Object.freeze([\\\"initialMessage\\\",\\\"requestedSessionId\\\",\\\"idempotencyKey\\\",\\\"clientEventId\\\",\\\"model\\\",\\\"reasoningEffort\\\",\\\"latencyMode\\\",\\\"startMode\\\",\\\"metadata\\\"]);var ps=\\\"opengeni.site.http\\\",pe=\\\"site-host\\\";async function mt(e,t,n){let s=new Request(t,n),i=new URL(s.url),r=`${i.pathname}${i.search}`;le(r,pe,s.method);let o=new MessageChannel,a=crypto.randomUUID(),c=n?.body instanceof ArrayBuffer||ArrayBuffer.isView(n?.body)||typeof Blob<\\\"u\\\"&&n?.body instanceof Blob,u=s.body?c?await s.arrayBuffer():await s.text():void 0;return await new Promise((l,p)=>{let d,m=!1,y=()=>{m=!0,s.signal.removeEventListener(\\\"abort\\\",R),o.port1.close()},R=()=>{if(m)return;e.postMessage({type:\\\"opengeni.site.cancel\\\",version:2,requestId:a});let v=s.signal.reason??new DOMException(\\\"Cancelled\\\",\\\"AbortError\\\");d?.error(v),p(v),y()};if(o.port1.onmessage=(v)=>{let b=v.data;if(b.error){let C=Error(b.error);d?.error(C),p(C),y()}else if(b.status){let C=b.body?new ReadableStream({start(P){d=P},pull(){o.port1.postMessage(\\\"pull\\\")},cancel(){d=void 0,R()}}):null;if(l(new Response(C,{status:b.status,headers:b.headers})),!b.body)y()}else if(b.done)d?.close(),y();else if(b.chunk)d?.enqueue(b.chunk)},s.signal.aborted){R();return}s.signal.addEventListener(\\\"abort\\\",R,{once:!0}),e.postMessage({type:ps,requestId:a,path:r,method:s.method,headers:[...s.headers],...u===void 0?{}:{body:u}},[o.port2])})}Ie();var St=\\\"X-OpenGeni-Session-Sequence\\\",Je=new WeakMap;function bt(e,t){if(t===null||typeof e!==\\\"object\\\"||e===null)return;let n=Number(t);if(Number.isSafeInteger(n)&&n>=0)Je.set(e,n)}function wt(e,t){if(typeof e!==\\\"object\\\"||e===null||typeof t!==\\\"object\\\"||t===null)return;let n=Je.get(e);if(n!==void 0)Je.set(t,n)}var hs=[\\\"agent.toolCall.created\\\",\\\"agent.toolCall.output\\\",\\\"agent.reasoning.delta\\\",\\\"sandbox.command.output.delta\\\",\\\"terminal.pty.output.delta\\\"],Rs=[\\\"agent.model.request\\\",\\\"agent.model.usage\\\"],Er=[...hs,...Rs];var vt=\\\"X-OpenGeni-Conversation-Filter\\\";function Ae(e){let t=new URLSearchParams;for(let[s,i]of Object.entries(e)){if(i===void 0)continue;for(let r of Array.isArray(i)?i:[i])t.append(s,String(r))}let n=t.toString();return n?`?${n}`:\\\"\\\"}K();var _=encodeURIComponent;function Ss(e){let t={};if(e.q)t.q=e.q;if(e.type)t.type=e.type;if(e.includeArchived)t.includeArchived=\\\"true\\\";if(e.cursor)t.cursor=e.cursor;if(e.limit)t.limit=String(e.limit);return t}function kt(e,t){let n=`/v1/workspaces/${_(t)}`,s=(a)=>`${n}/vaults/${_(a)}`,i=(a,c)=>`${s(a)}/items/${_(c)}`,r=(a,c,u)=>`${i(a,c)}/fields/${_(u)}`,o=(a,c,u,l,p)=>e.requestJson(a,c,u,l??{},p?{signal:p}:{});return{listVaults:async(a)=>(await o(\\\"GET\\\",`${n}/vaults`,void 0,{},a)).vaults,getVault:(a,c)=>o(\\\"GET\\\",s(a),void 0,{},c),createVault:(a)=>o(\\\"POST\\\",`${n}/vaults`,a),updateVault:(a,c)=>o(\\\"PATCH\\\",s(a),c),deleteVault:(a,c)=>e.requestJson(\\\"DELETE\\\",s(a),{confirmName:c},{},{responseType:\\\"void\\\"}),syncVault:(a)=>o(\\\"POST\\\",`${s(a)}/sync`,{}),listItems:(a,c={},u)=>o(\\\"GET\\\",`${s(a)}/items`,void 0,Ss(c),u),getItem:(a,c,u)=>o(\\\"GET\\\",i(a,c),void 0,{},u),createItem:(a,c)=>o(\\\"POST\\\",`${s(a)}/items`,c),updateItem:(a,c,u)=>o(\\\"PATCH\\\",i(a,c),u),deleteItem:(a,c,u=!1)=>e.requestJson(\\\"DELETE\\\",i(a,c),void 0,u?{permanent:\\\"true\\\"}:{},{responseType:\\\"void\\\"}),restoreItem:(a,c)=>o(\\\"POST\\\",`${i(a,c)}/restore`,{}),moveItem:(a,c,u)=>o(\\\"POST\\\",`${i(a,c)}/move`,u),revealField:(a,c,u,l)=>o(\\\"POST\\\",`${r(a,c,u)}/reveal`,l===void 0?{}:{version:l}),listFieldVersions:async(a,c,u,l)=>(await o(\\\"GET\\\",`${r(a,c,u)}/versions`,void 0,{},l)).versions,restoreFieldVersion:(a,c,u,l)=>o(\\\"POST\\\",`${r(a,c,u)}/restore`,{version:l}),getSessionSecrets:(a,c)=>o(\\\"GET\\\",`${n}/sessions/${_(a)}/secrets`,void 0,{},c),setSessionVaultPolicy:(a,c)=>o(\\\"PUT\\\",`${n}/sessions/${_(a)}/vault-policy`,{policy:c}),installOnePassword:(a)=>o(\\\"POST\\\",`${n}/connections/1password/install`,a),listOnePasswordConnections:async(a)=>(await o(\\\"GET\\\",`${n}/connections/1password/service-accounts`,void 0,{},a)).connections,replaceOnePasswordToken:(a,c)=>o(\\\"PUT\\\",`${n}/connections/${_(a)}/1password/token`,c),disconnectOnePassword:(a)=>o(\\\"DELETE\\\",`${n}/connections/${_(a)}/1password`),listProviderVaults:async(a,c)=>(await o(\\\"GET\\\",`${n}/connections/${_(a)}/provider-vaults`,void 0,{},c)).vaults,installVaultProvider:(a)=>o(\\\"POST\\\",`${n}/vault-providers/connections`,a),getVaultProviderCatalog:(a)=>o(\\\"GET\\\",`${n}/vault-providers/connections`,void 0,{},a),listVaultProviderConnections:async(a)=>(await o(\\\"GET\\\",`${n}/vault-providers/connections`,void 0,{},a)).connections,replaceVaultProviderCredentials:(a,c)=>o(\\\"PUT\\\",`${n}/vault-providers/connections/${_(a)}/credentials`,c),disconnectVaultProvider:(a)=>o(\\\"DELETE\\\",`${n}/vault-providers/connections/${_(a)}`),verifyVaultProviderConnection:(a)=>o(\\\"POST\\\",`${n}/vault-providers/connections/${_(a)}/verify`,{}),linkProviderVault:(a)=>o(\\\"POST\\\",`${n}/vaults/link`,a),createManagedProviderVault:(a,c)=>o(\\\"POST\\\",`${n}/connections/${_(a)}/managed-vaults`,c)}}K();async function*j(e){let t=e.getReader(),n=new TextDecoder,s=\\\"\\\",i,r,o=null,a=()=>{let u=o===null?null:{...i!==void 0?{id:i}:{},...r!==void 0?{event:r}:{},data:o.join(`\\n`)};return i=void 0,r=void 0,o=null,u},c=(u)=>{if(u===\\\"\\\")return a();if(u.startsWith(\\\":\\\"))return null;let l=u.indexOf(\\\":\\\"),p=l===-1?u:u.slice(0,l),d=l===-1?\\\"\\\":u.slice(l+1);if(d.startsWith(\\\" \\\"))d=d.slice(1);if(p===\\\"data\\\")(o??=[]).push(d);else if(p===\\\"event\\\")r=d;else if(p===\\\"id\\\")i=d;return null};try{while(!0){let{done:u,value:l}=await t.read();if(u)break;s+=n.decode(l,{stream:!0});let p=s.indexOf(`\\n`);while(p!==-1){let d=s.slice(0,p);if(s=s.slice(p+1),d.endsWith(\\\"\\\\r\\\"))d=d.slice(0,-1);let m=c(d);if(m)yield m;p=s.indexOf(`\\n`)}}}finally{t.cancel().catch(()=>{});try{t.releaseLock()}catch{}}}var Ct=Symbol.for(\\\"@opengeni/sdk/session-event-stream-covered-through\\\");async function*At(e,t={}){let n=t.signal,s=t.reconnect??!0,i=t.reconnectDelayMs??500,r=t.maxReconnectDelayMs??1e4,o=t.reconnectJitterRatio??0.2,a=t.beforeLiveTimeoutMs??15000,c=t.heartbeatTimeoutMs??45000,u=t.maxReconnectAttempts??Number.POSITIVE_INFINITY,l=t.after??0,p=0,d=i,m=!1,y=!1;while(!0){if(n?.aborted)break;t.onStateChange?.(m||p>0?\\\"reconnecting\\\":\\\"connecting\\\");let R=l;try{if(y&&t.beforeReconnect){let b=await bs(t.beforeReconnect,l,n);if(n?.aborted)return;if(typeof b===\\\"number\\\"&&Number.isSafeInteger(b))l=Math.max(l,b);R=l}y=!0;let v=await e.openStream(l,n);m=!0,p=0,d=i;try{t.onOpen?.()}catch{}await Z(t.beforeLive,a,n),t.onStateChange?.(\\\"live\\\");for await(let b of j(ee(v,c,n))){if(n?.aborted)return;let C=vs(b.data);if(!C)continue;let P=ks(b.id,C.sequence);if(Is(C,P),P<=l)continue;if(C.sequence>l+1){for await(let S of ws(e,l,C.sequence-1))if(l=S.sequence,yield S,n?.aborted)return}l=P,yield C}if(!s)return;if(l===R)await It(L(i,o),n);continue}catch(v){if(n?.aborted||V(v))return;if(!s||!H(v))throw v;if(p+=1,p>u)throw new B(`event stream gave up after ${u} consecutive failed reconnect attempts: ${v instanceof Error?v.message:String(v)}`)}await It(L(d,o),n),d=Math.min(Math.max(d*2,i),r)}}async function Z(e,t,n){if(!e)return;let s,i,r=new Promise((o,a)=>{if(s=setTimeout(()=>a(TypeError(`stream reconciliation timed out after ${t}ms`)),t),n)i=()=>a(new DOMException(\\\"Aborted\\\",\\\"AbortError\\\")),n.addEventListener(\\\"abort\\\",i,{once:!0})});try{await Promise.race([Promise.resolve().then(e),r])}finally{if(s!==void 0)clearTimeout(s);if(n&&i)n.removeEventListener(\\\"abort\\\",i)}}async function bs(e,t,n){if(!n)return await e(t);if(n.aborted)throw new DOMException(\\\"Aborted\\\",\\\"AbortError\\\");let s,i=new Promise((r,o)=>{s=()=>o(new DOMException(\\\"Aborted\\\",\\\"AbortError\\\")),n.addEventListener(\\\"abort\\\",s,{once:!0})});try{return await Promise.race([Promise.resolve().then(()=>e(t)),i])}finally{if(s)n.removeEventListener(\\\"abort\\\",s)}}function L(e,t){if(e<=0||t<=0)return e;let n=Math.min(t,1),s=e*n;return Math.max(0,e-s+Math.random()*s*2)}function ee(e,t,n){if(!Number.isSafeInteger(t)||t<=0)throw RangeError(\\\"stream heartbeat timeout must be a positive safe integer\\\");let s=e.getReader();return new ReadableStream({pull:async(i)=>{let r,o;try{let a=await Promise.race([s.read(),new Promise((c,u)=>{if(r=setTimeout(()=>u(TypeError(`event stream heartbeat timed out after ${t}ms`)),t),n)o=()=>u(new DOMException(\\\"Aborted\\\",\\\"AbortError\\\")),n.addEventListener(\\\"abort\\\",o,{once:!0})})]);if(a.done)i.close();else i.enqueue(a.value)}catch(a){s.cancel(a).catch(()=>{}),i.error(a)}finally{if(r!==void 0)clearTimeout(r);if(n&&o)n.removeEventListener(\\\"abort\\\",o)}},cancel:(i)=>{s.cancel(i).catch(()=>{})}})}async function*ws(e,t,n){let s=t;while(s<n){let r=(await e.listEvents(s,Math.min(500,n-s))).filter((o)=>o.sequence>s&&o.sequence<=n).sort((o,a)=>o.sequence-a.sequence);if(r.length===0)throw new B(`event replay backfill stalled: expected sequences ${s+1}..${n} but the replay endpoint returned none of them`);for(let o of r){if(o.sequence!==s+1)throw new B(`event replay backfill is missing sequence ${s+1} (replay endpoint skipped to ${o.sequence}); refusing to deliver with a gap`);s=o.sequence,yield o}}}function vs(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!==\\\"object\\\"||t===null||typeof t.sequence!==\\\"number\\\"||typeof t.type!==\\\"string\\\"||typeof t.id!==\\\"string\\\")return null;return t}function Pt(e){let t=e[Ct];return typeof t===\\\"number\\\"&&Number.isSafeInteger(t)&&t>=e.sequence?t:null}function ks(e,t){if(e===void 0||!/^\\\\d+$/.test(e))return t;let n=Number(e);return Number.isSafeInteger(n)&&n>=t?n:t}function Is(e,t){Object.defineProperty(e,Ct,{value:t,enumerable:!1,configurable:!1,writable:!1})}async function It(e,t){if(t?.aborted||e<=0)return;await new Promise((n)=>{let s=setTimeout(i,e);function i(){clearTimeout(s),t?.removeEventListener(\\\"abort\\\",i),n()}t?.addEventListener(\\\"abort\\\",i,{once:!0})})}var Cs=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|\\\\d+|[A-Za-z0-9_-]{20,})$/i;function As(e){return e.split(\\\"/\\\").map((t)=>Cs.test(t)?\\\":id\\\":t).join(\\\"/\\\")}function Ps(e){let t=e.trim(),n=/^@(-?\\\\d+)$/.exec(t);if(n)return new Date(Number(n[1])*1000);let s=Date.parse(t);return Number.isNaN(s)?null:new Date(s)}function xs(e){let t=new Map;if(!e)return t;for(let n of e.matchAll(/<([^>]*)>\\\\s*((?:;\\\\s*[^;,]+)*)/g)){let s=/;\\\\s*rel=\\\"?([^\\\";,]+)\\\"?/i.exec(n[2]??\\\"\\\")?.[1];if(!s)continue;for(let i of s.toLowerCase().split(/\\\\s+/))if(!t.has(i))t.set(i,n[1])}return t}function Ts(e,t,n){let s=n.get(\\\"deprecation\\\"),i=n.get(\\\"sunset\\\");if(!s&&!i)return null;let r=t;try{r=new URL(t,\\\"http://opengeni.invalid\\\").pathname}catch{}let o=i?Date.parse(i):Number.NaN,a=xs(n.get(\\\"link\\\"));return{method:e.toUpperCase(),route:As(r),path:r,deprecatedAt:s?Ps(s):null,sunset:Number.isNaN(o)?null:new Date(o),link:a.get(\\\"deprecation\\\")??a.get(\\\"sunset\\\")??null,successor:a.get(\\\"successor-version\\\")??null}}var xt=new Set;function Os(e){let t=`${e.method} ${e.route}`;if(xt.has(t))return;xt.add(t);let n=e.sunset?` and will be removed after ${e.sunset.toISOString()}`:\\\"\\\",s=e.link?` Migration notes: ${e.link}.`:\\\"\\\";console.warn(`[@opengeni/sdk] ${t} is deprecated${n}.${s} Upgrade @opengeni/sdk, or pass onDeprecation to handle this notice.`)}function Tt(e,t){if(t===!1)return e;let n=t??Os,s=new Set;return async(i,r)=>{let o=await e(i,r);try{let a=o.headers;if(a&&(a.get(\\\"deprecation\\\")||a.get(\\\"sunset\\\"))){let c=r?.method??(typeof Request<\\\"u\\\"&&i instanceof Request?i.method:\\\"GET\\\"),u=typeof i===\\\"string\\\"?i:i instanceof URL?i.href:i.url,l=Ts(c,u,a);if(l){let p=`${l.method} ${l.route}`;if(!s.has(p))s.add(p),n(l)}}}catch{}return o}}K();async function*qt(e,t={}){let n=t.signal,s=t.reconnect??!0,i=t.reconnectDelayMs??500,r=t.maxReconnectDelayMs??1e4,o=t.reconnectJitterRatio??0.2,a=t.beforeLiveTimeoutMs??15000,c=t.heartbeatTimeoutMs??45000,u=t.maxReconnectAttempts??Number.POSITIVE_INFINITY,l=t.after??0,p=0,d=i,m=!1;for(;;){if(n?.aborted)return;t.onStateChange?.(m||p>0?\\\"reconnecting\\\":\\\"connecting\\\");let y=l;try{let R=await e.openStream(l,n);m=!0,p=0,d=i,await Z(t.beforeLive,a,n),t.onStateChange?.(\\\"live\\\");for await(let v of j(ee(R,c,n))){if(n?.aborted)return;let b=qs(v.data);if(!b||b.sequence<=l)continue;l=b.sequence,yield b}if(!s)return;if(l===y)await Ot(L(i,o),n);continue}catch(R){if(n?.aborted||V(R))return;if(!s||!H(R))throw R;if(p+=1,p>u)throw new B(`workspace control stream gave up after ${u} reconnect attempts: ${R instanceof Error?R.message:String(R)}`)}await Ot(L(d,o),n),d=Math.min(Math.max(d*2,i),r)}}function qs(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!==\\\"object\\\"||t===null||t.type!==\\\"workspace.control.changed\\\"||typeof t.id!==\\\"string\\\"||typeof t.sequence!==\\\"number\\\")return null;return t}async function Ot(e,t){if(t?.aborted||e<=0)return;await new Promise((n)=>{let s=setTimeout(i,e);function i(){clearTimeout(s),t?.removeEventListener(\\\"abort\\\",i),n()}t?.addEventListener(\\\"abort\\\",i,{once:!0})})}K();async function*_t(e,t={}){let n=t.signal,s=t.reconnect??!0,i=t.reconnectDelayMs??500,r=t.maxReconnectDelayMs??1e4,o=t.reconnectJitterRatio??0.2,a=t.beforeLiveTimeoutMs??15000,c=t.heartbeatTimeoutMs??45000,u=t.maxReconnectAttempts??Number.POSITIVE_INFINITY,l=t.after??0,p=0,d=i,m=!1;for(;;){if(n?.aborted)return;t.onStateChange?.(m||p>0?\\\"reconnecting\\\":\\\"connecting\\\");let y=l;try{let R=await e.openStream(l,n);m=!0,p=0,d=i,await Z(t.beforeLive,a,n),t.onStateChange?.(\\\"live\\\");for await(let v of j(ee(R,c,n))){if(n?.aborted)return;let b=Es(v.data);if(!b||b.sequence<=l)continue;l=b.sequence,yield b}if(!s)return;if(l===y)await Et(L(i,o),n);continue}catch(R){if(n?.aborted||V(R))return;if(!s||!H(R))throw R;if(p+=1,p>u)throw new B(`workspace interaction stream gave up after ${u} reconnect attempts: ${R instanceof Error?R.message:String(R)}`)}await Et(L(d,o),n),d=Math.min(Math.max(d*2,i),r)}}function Es(e){let t;try{t=JSON.parse(e)}catch{return null}if(!_s(t)||t.type!==\\\"workspace.interaction.changed\\\"||typeof t.workspaceId!==\\\"string\\\"||typeof t.sequence!==\\\"number\\\"||!Number.isSafeInteger(t.sequence)||t.sequence<0||t.revision!==t.sequence||typeof t.occurredAt!==\\\"string\\\")return null;return t}function _s(e){return typeof e===\\\"object\\\"&&e!==null&&!Array.isArray(e)}async function Et(e,t){if(t?.aborted||e<=0)return;await new Promise((n)=>{let s=setTimeout(i,e);function i(){clearTimeout(s),t?.removeEventListener(\\\"abort\\\",i),n()}t?.addEventListener(\\\"abort\\\",i,{once:!0})})}K();async function*Mt(e,t={}){let n=t.signal,s=t.reconnect??!0,i=t.reconnectDelayMs??500,r=t.maxReconnectDelayMs??1e4,o=t.reconnectJitterRatio??0.2,a=t.beforeLiveTimeoutMs??15000,c=t.heartbeatTimeoutMs??45000,u=t.maxReconnectAttempts??Number.POSITIVE_INFINITY,l=t.controlAfter??0,p=t.interactionAfter??0,d=0,m=i,y=!1;for(;;){if(n?.aborted)return;t.onStateChange?.(y||d>0?\\\"reconnecting\\\":\\\"connecting\\\");let R=`${l}:${p}`;try{let v=await e.openStream(l,p,n);y=!0,d=0,m=i,await Z(t.beforeLive,a,n),t.onStateChange?.(\\\"live\\\");for await(let b of j(ee(v,c,n))){if(n?.aborted)return;let C=Gs(b.data);if(!C)continue;if(C.type===\\\"workspace.control.changed\\\"){if(C.sequence<=l)continue;l=C.sequence}else if(C.type===\\\"workspace.interaction.changed\\\"){if(C.sequence<=p)continue;p=C.sequence}yield C}if(!s)return;if(`${l}:${p}`===R)await Gt(L(i,o),n);continue}catch(v){if(n?.aborted||V(v))return;if(!s||!H(v))throw v;if(d+=1,d>u)throw new B(`workspace live stream gave up after ${u} reconnect attempts: ${v instanceof Error?v.message:String(v)}`)}await Gt(L(m,o),n),m=Math.min(Math.max(m*2,i),r)}}function Gs(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Ms(t))return null;if(t.type===\\\"workspace.sessions.changed\\\"&&typeof t.workspaceId===\\\"string\\\"&&typeof t.available===\\\"boolean\\\"&&(t.sessionIds===null||Array.isArray(t.sessionIds)&&t.sessionIds.every((n)=>typeof n===\\\"string\\\")))return t;if(typeof t.sequence!==\\\"number\\\")return null;if(t.type===\\\"workspace.control.changed\\\"&&typeof t.id===\\\"string\\\"&&Number.isSafeInteger(t.sequence))return t;if(t.type===\\\"workspace.interaction.changed\\\"&&typeof t.workspaceId===\\\"string\\\"&&Number.isSafeInteger(t.sequence)&&t.sequence>=0&&t.revision===t.sequence&&typeof t.occurredAt===\\\"string\\\")return t;return null}function Ms(e){return typeof e===\\\"object\\\"&&e!==null&&!Array.isArray(e)}async function Gt(e,t){if(t?.aborted||e<=0)return;await new Promise((n)=>{let s=setTimeout(i,e);function i(){clearTimeout(s),t?.removeEventListener(\\\"abort\\\",i),n()}t?.addEventListener(\\\"abort\\\",i,{once:!0})})}function Ut(e){return e.driverId===\\\"opengeni.cdp.ephemeral-context.v1\\\"?\\\"ephemeral_context\\\":\\\"private_profile\\\"}var Dt=32768,Us=1e8;class Ve{attachedBrowsers;authRuns;browsers;computers;identities;interventions;networkRoutes;siteAuthConnections;constructor(e){this.attachedBrowsers=new Kt(e),this.authRuns=new Ft(e),this.browsers=new Qt(e),this.computers=new rn(e),this.identities=new Yt(e),this.interventions=new Vt(e),this.networkRoutes=new Lt(e),this.siteAuthConnections=new zt(e)}}class Lt{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listNetworkRoutes(e,t)}route(e,t){return new Wt(this.transport,e,t)}async create(e,t,n={}){let s=await this.transport.createNetworkRoute(e,t,n);return this.route(e,s.route.id)}}class Wt{transport;workspaceId;id;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n}async get(e={}){return await this.transport.getNetworkRoute(this.workspaceId,this.id,e)}async update(e,t={}){return await this.transport.updateNetworkRoute(this.workspaceId,this.id,e,t)}}class zt{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listSiteAuthConnections(e,t)}connection(e,t){return new Nt(this.transport,e,t)}async create(e,t,n={}){let s=await this.transport.createSiteAuthConnection(e,t,n);return this.connection(e,s.connection.id)}}class Nt{transport;workspaceId;id;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n}async get(e={}){return await this.transport.getSiteAuthConnection(this.workspaceId,this.id,e)}async update(e,t={}){return await this.transport.updateSiteAuthConnection(this.workspaceId,this.id,e,t)}}class Ft{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listAuthRuns(e,t)}async get(e,t,n={}){return await this.transport.getAuthRun(e,t,n)}run(e,t,n){return new He(this.transport,e,t,n)}}class Jt{transport;workspaceId;browserSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.browserSessionId=n}async list(e={}){return await this.transport.listAuthRuns(this.workspaceId,{...e,browserSessionId:this.browserSessionId})}run(e){return new He(this.transport,this.workspaceId,this.browserSessionId,e)}async start(e,t={}){let n=await this.transport.startBrowserAuthRun(this.workspaceId,this.browserSessionId,e,t);return this.run(n.run.id)}}class He{transport;workspaceId;browserSessionId;id;constructor(e,t,n,s){this.transport=e;this.workspaceId=t;this.browserSessionId=n;this.id=s}async get(e={}){let t=await this.transport.getAuthRun(this.workspaceId,this.id,e);if(t.browserSessionId!==this.browserSessionId)throw Error(\\\"AuthRun belongs to another BrowserSession\\\");return t}async report(e,t={}){return await this.transport.reportBrowserAuthRun(this.workspaceId,this.browserSessionId,this.id,e,t)}async advanceExternal(e,t={}){return await this.transport.advanceExternalBrowserAuthRun(this.workspaceId,this.browserSessionId,this.id,e,t)}async openExternalFlow(e,t={}){return await this.transport.openExternalBrowserAuthFlow(this.workspaceId,this.browserSessionId,this.id,e,t)}async verify(e,t={}){return await this.transport.verifyBrowserAuthRun(this.workspaceId,this.browserSessionId,this.id,e,t)}}class Vt{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listInteractionInterventions(e,t)}intervention(e,t){return new Ht(this.transport,e,t)}async create(e,t,n={}){let s=await this.transport.createInteractionIntervention(e,t,n);return this.intervention(e,s.intervention.id)}}class Ht{transport;workspaceId;id;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n}async get(e={}){return await this.transport.getInteractionIntervention(this.workspaceId,this.id,e)}async resolve(e,t={}){return await this.transport.resolveInteractionIntervention(this.workspaceId,this.id,e,t)}}class Kt{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listAttachedBrowsers(e,t)}device(e,t){return new jt(this.transport,e,t)}}class jt{transport;workspaceId;id;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n}async get(e={}){return await this.transport.getAttachedBrowser(this.workspaceId,this.id,e)}}class Yt{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listBrowserIdentities(e,t)}identity(e,t){return new Xt(this.transport,e,t)}async create(e,t,n={}){let s=await this.transport.createBrowserIdentity(e,t,n);return this.identity(e,s.identity.id)}}class Xt{transport;workspaceId;id;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n}async get(e={}){return await this.transport.getBrowserIdentity(this.workspaceId,this.id,e)}async revisions(e={}){return await this.transport.listBrowserRevisions(this.workspaceId,this.id,e)}async update(e,t={}){return await this.transport.updateBrowserIdentity(this.workspaceId,this.id,e,t)}}class Qt{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listBrowserSessions(e,t)}session(e,t){return new Zt(this.transport,e,t)}async open(e,t,n={}){let s=await this.transport.createBrowserSession(e,t,n);return this.session(e,s.session.id)}async currentOrOpen(e){let t=e.signal?{signal:e.signal}:{},n=await this.list(e.workspaceId,t),s=$s(n.sessions.filter((i)=>Ut(i)===(e.storageMode??\\\"private_profile\\\")),e.associationSessionId);if(s){let i=this.session(e.workspaceId,s.id);if(s.lifecycle===\\\"suspended\\\")await i.resume({operationId:e.operationId??crypto.randomUUID()},t);return i}return await this.open(e.workspaceId,{operationId:e.operationId??crypto.randomUUID(),sessionId:e.associationSessionId,...e.name!==void 0?{name:e.name}:{},...e.initialUrl!==void 0?{initialUrl:e.initialUrl}:{},...e.headless!==void 0?{headless:e.headless}:{},...e.storageMode!==void 0?{storageMode:e.storageMode}:{},...e.placement!==void 0?{placement:e.placement}:{},...e.identityId!==void 0?{identityId:e.identityId}:{},...e.baseRevisionId!==void 0?{baseRevisionId:e.baseRevisionId}:{},...e.networkRouteId!==void 0?{networkRouteId:e.networkRouteId}:{},...e.linkedComputerSessionId!==void 0?{linkedComputerSessionId:e.linkedComputerSessionId}:{}},t)}}class Zt{transport;workspaceId;id;auth;clipboard;downloads;tabs;targets;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n;this.auth=new Jt(e,t,n),this.clipboard=new en(e,t,n),this.downloads=new tn(e,t,n),this.tabs=new sn(e,t,n),this.targets=this.tabs}async get(e={}){return await this.transport.getBrowserSession(this.workspaceId,this.id,e)}async observe(e,t={}){return await this.transport.observeBrowserTarget(this.workspaceId,this.id,e,t)}async targetState(e,t={}){return await this.transport.getBrowserTargetState(this.workspaceId,this.id,e,t)}async readDom(e,t,n={}){return await this.transport.readBrowserDom(this.workspaceId,this.id,e,t,n)}async capture(e,t={},n={}){return await this.transport.captureBrowserTarget(this.workspaceId,this.id,e,t,n)}async screenshot(e,t={},n={}){return await this.capture(e,n,t)}async act(e,t={}){return await this.transport.actInBrowser(this.workspaceId,this.id,e,t)}async receipt(e,t={}){return await this.transport.getBrowserActionReceipt(this.workspaceId,this.id,e,t)}async diagnostics(e,t={}){return await this.transport.listBrowserDiagnostics(this.workspaceId,this.id,e,t)}async attach(e,t={}){return await this.transport.attachBrowserSession(this.workspaceId,this.id,e,t)}async heartbeat(e={}){return await this.transport.heartbeatBrowserSession(this.workspaceId,this.id,e)}async publishRevision(e,t={}){return await this.transport.publishBrowserRevision(this.workspaceId,this.id,e,t)}async suspend(e={operationId:crypto.randomUUID()},t={}){return await this.transport.suspendBrowserSession(this.workspaceId,this.id,e,t)}async resume(e={operationId:crypto.randomUUID()},t={}){return await this.transport.resumeBrowserSession(this.workspaceId,this.id,e,t)}async end(e={operationId:crypto.randomUUID()},t={}){return await this.transport.endBrowserSession(this.workspaceId,this.id,e,t)}}class en{transport;workspaceId;browserSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.browserSessionId=n}async read(e={}){let t=await this.transport.readBrowserClipboard(this.workspaceId,this.browserSessionId,e);if(t.browserSessionId!==this.browserSessionId)throw Error(\\\"Browser clipboard belongs to another BrowserSession\\\");return t}}class tn{transport;workspaceId;browserSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.browserSessionId=n}async list(e={}){return await this.transport.listBrowserDownloads(this.workspaceId,this.browserSessionId,e)}download(e){return new nn(this.transport,this.workspaceId,this.browserSessionId,e)}}class nn{transport;workspaceId;browserSessionId;id;constructor(e,t,n,s){this.transport=e;this.workspaceId=t;this.browserSessionId=n;this.id=s}async get(e={}){let t=await this.transport.getBrowserDownload(this.workspaceId,this.browserSessionId,this.id,e);if(t.browserSessionId!==this.browserSessionId)throw Error(\\\"BrowserDownload belongs to another BrowserSession\\\");return t}async saveToWorkspace(e,t={}){let{operationId:n=crypto.randomUUID(),overwrite:s=!1,...i}=t,r=await this.transport.saveBrowserDownload(this.workspaceId,this.browserSessionId,this.id,{operationId:n,destinationPath:e,overwrite:s},i);if(r.download.id!==this.id||r.download.browserSessionId!==this.browserSessionId)throw Error(\\\"BrowserDownload save returned another resource\\\");return r}}class sn{transport;workspaceId;browserSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.browserSessionId=n}async list(e={}){return await this.transport.listBrowserTargets(this.workspaceId,this.browserSessionId,e)}async open(e,t={}){return await this.transport.openBrowserTarget(this.workspaceId,this.browserSessionId,e===void 0?{}:{url:e},t)}async select(e,t={}){return await this.transport.selectBrowserTarget(this.workspaceId,this.browserSessionId,e,t)}async close(e,t={}){return await this.transport.closeBrowserTarget(this.workspaceId,this.browserSessionId,e,t)}}class rn{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listComputerSessions(e,t)}session(e,t){return new on(this.transport,e,t)}async open(e,t,n={}){let s=await this.transport.createComputerSession(e,t,n);return this.session(e,s.session.id)}async currentOrOpen(e){let t=e.signal?{signal:e.signal}:{},n=await this.list(e.workspaceId,t),s=Bs(n.sessions,e.associationSessionId);if(s)return this.session(e.workspaceId,s.id);return await this.open(e.workspaceId,{operationId:e.operationId??crypto.randomUUID(),sessionId:e.associationSessionId,...e.name!==void 0?{name:e.name}:{},...e.placement!==void 0?{placement:e.placement}:{}},t)}}class on{transport;workspaceId;id;targets;apps;clipboard;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n;this.targets=new cn(e,t,n),this.apps=this.targets,this.clipboard=new an(e,t,n)}async get(e={}){return await this.transport.getComputerSession(this.workspaceId,this.id,e)}async observe(e,t={}){return await this.transport.observeComputerTarget(this.workspaceId,this.id,e,t)}async capture(e,t={}){return await this.transport.captureComputerTarget(this.workspaceId,this.id,e,t)}async callNativeTool(e,t={}){if(!this.transport.callNativeComputerTool)throw Error(\\\"Native CUA tools require a current interaction transport\\\");return await this.transport.callNativeComputerTool(this.workspaceId,this.id,e,t)}async act(e,t={}){return await this.transport.actInComputer(this.workspaceId,this.id,e,t)}async nativeReceipt(e,t={}){if(!this.transport.getNativeComputerToolReceipt)throw Error(\\\"Native CUA receipts require a current interaction transport\\\");return await this.transport.getNativeComputerToolReceipt(this.workspaceId,this.id,e,t)}async receipt(e,t={}){return await this.transport.getComputerActionReceipt(this.workspaceId,this.id,e,t)}async attach(e,t={}){return await this.transport.attachComputerSession(this.workspaceId,this.id,e,t)}async inputPosture(e={}){if(!this.transport.getComputerInputPosture)throw Error(\\\"Computer input posture requires a current interaction transport.\\\");return await this.transport.getComputerInputPosture(this.workspaceId,this.id,e)}async heartbeat(e={}){return await this.transport.heartbeatComputerSession(this.workspaceId,this.id,e)}async end(e={operationId:crypto.randomUUID()},t={}){return await this.transport.endComputerSession(this.workspaceId,this.id,e,t)}}class an{transport;workspaceId;computerSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.computerSessionId=n}async read(e={}){let t=await this.transport.readComputerClipboard(this.workspaceId,this.computerSessionId,e);if(t.computerSessionId!==this.computerSessionId)throw Error(\\\"Computer clipboard belongs to another ComputerSession\\\");return t}}class cn{transport;workspaceId;computerSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.computerSessionId=n}async list(e={}){return await this.transport.listComputerTargets(this.workspaceId,this.computerSessionId,e)}}function un(e){if(!mn(e))throw Error(\\\"browser frame metadata is invalid\\\");let t=new Set([\\\"frameId\\\",\\\"browserSessionId\\\",\\\"controllerGeneration\\\",\\\"targetId\\\",\\\"targetGeneration\\\",\\\"documentGeneration\\\",\\\"sequence\\\",\\\"mediaType\\\",\\\"width\\\",\\\"height\\\",\\\"deviceScaleFactor\\\",\\\"scrollX\\\",\\\"scrollY\\\",\\\"capturedAt\\\"]);if(Object.keys(e).some((r)=>!t.has(r)))throw Error(\\\"browser frame metadata contains unknown fields\\\");let n=[\\\"frameId\\\",\\\"browserSessionId\\\",\\\"controllerGeneration\\\",\\\"targetId\\\",\\\"targetGeneration\\\",\\\"documentGeneration\\\",\\\"mediaType\\\",\\\"capturedAt\\\"];for(let r of n){let o=e[r],a=r===\\\"targetId\\\"?512:r===\\\"capturedAt\\\"?128:256;if(typeof o!==\\\"string\\\"||o.length<1||pn(o)>a)throw Error(\\\"browser frame metadata is invalid\\\")}let s=[\\\"sequence\\\",\\\"width\\\",\\\"height\\\",\\\"deviceScaleFactor\\\",\\\"scrollX\\\",\\\"scrollY\\\"];for(let r of s)if(typeof e[r]!==\\\"number\\\"||!Number.isFinite(e[r]))throw Error(\\\"browser frame metadata is invalid\\\");let i=e;if(!Number.isSafeInteger(i.sequence)||i.sequence<0||!Number.isSafeInteger(i.width)||!Number.isSafeInteger(i.height))throw Error(\\\"browser frame metadata integers are invalid\\\");if(dn(i.width,i.height),i.deviceScaleFactor<=0||i.deviceScaleFactor>16||Math.abs(i.scrollX)>1e9||Math.abs(i.scrollY)>1e9)throw Error(\\\"browser frame geometry metadata is invalid\\\");if(i.mediaType!==\\\"image/jpeg\\\"&&i.mediaType!==\\\"image/png\\\")throw Error(\\\"browser frame media type is invalid\\\");if(!gn(i.browserSessionId))throw Error(\\\"browser frame session id is invalid\\\");if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/u.test(i.controllerGeneration))throw Error(\\\"browser frame controller generation is invalid\\\");if(!Number.isFinite(new Date(i.capturedAt).valueOf()))throw Error(\\\"browser frame timestamp is invalid\\\");return i}function Ds(e){if(!mn(e))throw Error(\\\"computer frame metadata is invalid\\\");let t=new Set([\\\"frameId\\\",\\\"computerSessionId\\\",\\\"controllerGeneration\\\",\\\"targetId\\\",\\\"targetGeneration\\\",\\\"sequence\\\",\\\"mediaType\\\",\\\"width\\\",\\\"height\\\",\\\"capturedAt\\\",\\\"sha256\\\"]);if(Object.keys(e).some((i)=>!t.has(i)))throw Error(\\\"computer frame metadata contains unknown fields\\\");let n=[\\\"frameId\\\",\\\"computerSessionId\\\",\\\"controllerGeneration\\\",\\\"targetId\\\",\\\"targetGeneration\\\",\\\"mediaType\\\",\\\"capturedAt\\\",\\\"sha256\\\"];for(let i of n){let r=e[i],o=i===\\\"targetId\\\"?512:i===\\\"capturedAt\\\"?128:256;if(typeof r!==\\\"string\\\"||r.length<1||pn(r)>o)throw Error(\\\"computer frame metadata is invalid\\\")}let s=e;if(!Number.isSafeInteger(s.sequence)||s.sequence<0||!Number.isSafeInteger(s.width)||!Number.isSafeInteger(s.height))throw Error(\\\"computer frame metadata integers are invalid\\\");if(dn(s.width,s.height),s.mediaType!==\\\"image/jpeg\\\"&&s.mediaType!==\\\"image/png\\\")throw Error(\\\"computer frame media type is invalid\\\");if(!gn(s.computerSessionId))throw Error(\\\"computer frame session id is invalid\\\");if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/u.test(s.controllerGeneration))throw Error(\\\"computer frame controller generation is invalid\\\");if(!Number.isFinite(new Date(s.capturedAt).valueOf()))throw Error(\\\"computer frame timestamp is invalid\\\");if(!/^[0-9a-f]{64}$/u.test(s.sha256))throw Error(\\\"computer frame digest is invalid\\\");return s}function ln(e){if(!e||e.length>32768||!/^[A-Za-z0-9_-]+$/u.test(e))throw Error(\\\"computer frame metadata header is invalid\\\");let t=e.replace(/-/gu,\\\"+\\\").replace(/_/gu,\\\"/\\\"),n=t.padEnd(Math.ceil(t.length/4)*4,\\\"=\\\"),s;try{s=atob(n)}catch{throw Error(\\\"computer frame metadata header is invalid\\\")}let i=Uint8Array.from(s,(o)=>o.charCodeAt(0)),r;try{r=JSON.parse(new TextDecoder(\\\"utf-8\\\",{fatal:!0}).decode(i))}catch{throw Error(\\\"computer frame metadata header is invalid\\\")}return Ds(r)}function $s(e,t){let n=e.filter((s)=>![\\\"ending\\\",\\\"ended\\\",\\\"failed\\\",\\\"lost\\\"].includes(s.lifecycle)&&s.associations.some((i)=>i.sessionId===t));return n.sort((s,i)=>$t(i,t)-$t(s,t)),n[0]??null}function Bs(e,t){let n=e.filter((s)=>[\\\"starting\\\",\\\"active\\\",\\\"restoring\\\"].includes(s.lifecycle)&&s.associations.some((i)=>i.sessionId===t));return n.sort((s,i)=>Bt(i,t)-Bt(s,t)),n[0]??null}function $t(e,t){let n=e.associations.filter((i)=>i.sessionId===t).map((i)=>Date.parse(i.lastUsedAt)).filter(Number.isFinite).reduce((i,r)=>Math.max(i,r),0),s=Date.parse(e.lastUsedAt);return Math.max(n,Number.isFinite(s)?s:0)}function Bt(e,t){let n=e.associations.filter((i)=>i.sessionId===t).map((i)=>Date.parse(i.lastUsedAt)).filter(Number.isFinite).reduce((i,r)=>Math.max(i,r),0),s=Date.parse(e.lastUsedAt);return Math.max(n,Number.isFinite(s)?s:0)}function dn(e,t){if(!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||e<1||t<1||e>Dt||t>Dt||e*t>Us)throw Error(\\\"browser image dimensions exceed their bounded envelope\\\")}function pn(e){return new TextEncoder().encode(e).byteLength}function gn(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(e)}function mn(e){return typeof e===\\\"object\\\"&&e!==null&&!Array.isArray(e)}var re=\\\"2026-09-plugins-and-skills-v1\\\",Ke=\\\"x-opengeni-api-contract\\\",Pe=\\\"x-opengeni-correlation-id\\\";var xe=1048576,yn=33554432;var fn=536870912;var Oe=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,hn=/^[0-9a-f]{64}$/,Rn=/^\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}(?:\\\\.\\\\d+)?(?:Z|[+-]\\\\d{2}:\\\\d{2})$/,Sn=/^\\\\/v1\\\\/workspaces\\\\/([0-9a-f-]+)\\\\/artifacts\\\\/([0-9a-f-]+)\\\\/content$/;function bn(e,t){if(!te(e,Ws))return null;let n=e;if(n.available!==!0||n.kind!==\\\"file\\\"||typeof n.artifactId!==\\\"string\\\"||!Oe.test(n.artifactId)||typeof n.contentType!==\\\"string\\\"||!/^[a-z0-9][a-z0-9!#$&^_.+-]{0,62}\\\\/[a-z0-9][a-z0-9!#$&^_.+-]{0,62}$/.test(n.contentType)||!Te(n.originalBytes,1,5000000000)||typeof n.sha256!==\\\"string\\\"||!hn.test(n.sha256)||typeof n.retainedAt!==\\\"string\\\"||n.retainedAt.length>64||!Rn.test(n.retainedAt)||!Number.isFinite(Date.parse(n.retainedAt))||!te(n.retention,vn)||!te(n.retrieval,kn))return null;let s=n.retention;if(s.policy!==\\\"workspace_file\\\"||s.expiresAt!==null)return null;let i=n.retrieval;if(i.method!==\\\"GET\\\"||i.acceptRanges!==\\\"bytes\\\"||i.maxRangeBytes!==1048576||typeof i.path!==\\\"string\\\"||i.path.length>256)return null;let r=Sn.exec(i.path);if(!r||!Oe.test(r[1]??\\\"\\\")||r[2]!==n.artifactId||t!==void 0&&r[1]!==t)return null;return e}function wn(e,t){if(!te(e,Ls))return null;let n=e;if(n.available!==!0||n.kind!==\\\"generated_image\\\"||typeof n.artifactId!==\\\"string\\\"||!Oe.test(n.artifactId)||![\\\"image/png\\\",\\\"image/jpeg\\\",\\\"image/webp\\\"].includes(String(n.contentType))||!Te(n.originalBytes,1,67108864)||typeof n.sha256!==\\\"string\\\"||!hn.test(n.sha256)||typeof n.retainedAt!==\\\"string\\\"||n.retainedAt.length>64||!Rn.test(n.retainedAt)||!Number.isFinite(Date.parse(n.retainedAt))||!te(n.dimensions,zs)||!te(n.retention,vn)||!te(n.retrieval,kn))return null;let s=n.dimensions;if(!Te(s.width,1,16384)||!Te(s.height,1,16384)||Number(s.width)*Number(s.height)>67108864)return null;let i=n.retention;if(i.policy!==\\\"workspace_file\\\"||i.expiresAt!==null)return null;let r=n.retrieval;if(r.method!==\\\"GET\\\"||r.acceptRanges!==\\\"bytes\\\"||r.maxRangeBytes!==1048576||typeof r.path!==\\\"string\\\"||r.path.length>256)return null;let o=Sn.exec(r.path);if(!o||!Oe.test(o[1]??\\\"\\\")||o[2]!==n.artifactId||t!==void 0&&o[1]!==t)return null;return e}var Ls=new Set([\\\"available\\\",\\\"artifactId\\\",\\\"kind\\\",\\\"contentType\\\",\\\"originalBytes\\\",\\\"sha256\\\",\\\"retainedAt\\\",\\\"dimensions\\\",\\\"retention\\\",\\\"retrieval\\\"]),Ws=new Set([\\\"available\\\",\\\"artifactId\\\",\\\"kind\\\",\\\"contentType\\\",\\\"originalBytes\\\",\\\"sha256\\\",\\\"retainedAt\\\",\\\"retention\\\",\\\"retrieval\\\"]),zs=new Set([\\\"width\\\",\\\"height\\\"]),vn=new Set([\\\"policy\\\",\\\"expiresAt\\\"]),kn=new Set([\\\"method\\\",\\\"path\\\",\\\"acceptRanges\\\",\\\"maxRangeBytes\\\"]);var Ns=new Set([\\\"type\\\",\\\"sandboxPath\\\",\\\"filename\\\",\\\"artifact\\\"]),so=new Set([...Ns,\\\"access\\\"]);function te(e,t){return e!==null&&typeof e===\\\"object\\\"&&!Array.isArray(e)&&Object.keys(e).length===t.size&&Object.keys(e).every((n)=>t.has(n))}function Te(e,t,n){return Number.isSafeInteger(e)&&Number(e)>=t&&Number(e)<=n}function Xe(e){let{limit:t,parentSessionId:n,scopeSubjectId:s}=e,i={};if(e.originSiteId)i.originSiteId=e.originSiteId;if(e.siteAccessId)i.siteAccessId=e.siteAccessId;if(t!==void 0)i.limit=String(t);if(n!==void 0)i.parentSessionId=n??\\\"null\\\";if(s!==void 0)i.scopeSubjectId=s;return i}var Ri=[\\\"siteAccessId\\\",\\\"originSiteId\\\",\\\"channelId\\\",\\\"createdBy\\\",\\\"updatedFrom\\\",\\\"updatedBefore\\\",\\\"createdFrom\\\",\\\"createdBefore\\\"],Si=[\\\"updatedFrom\\\",\\\"updatedBefore\\\",\\\"createdFrom\\\",\\\"createdBefore\\\",\\\"sortBy\\\",\\\"archiveStatus\\\"];function bi(e){return Boolean(e.needsYouOnly)||Boolean(e.contentArchivedOnly)||Boolean(e.mineOnly)||Ri.some((t)=>e[t]!==void 0)}function N(e){return Error(`The connected API does not support ${e}`)}function g(e,t){return`/v1/workspaces/${e}/sessions/${t}`}function wi(e){if(e.apiContract)return e.apiContract;return typeof window<\\\"u\\\"&&typeof document<\\\"u\\\"&&!e.apiKey?\\\"strict\\\":\\\"compatible\\\"}function Tn(e){let{associatedSessionId:t,includeTerminal:n,...s}=e;return{query:{...t?{associatedSessionId:t}:{},...n!==void 0?{includeTerminal:String(n)}:{}},request:s}}function On(e,t){let n,s,i=new Promise((r,o)=>{n=r,s=o});return{controller:new AbortController,consumers:0,generation:e,promise:i,resolve:n,reject:s,started:!1,listeners:new Set(t?[t]:[])}}function qn(e){if(Object.prototype.hasOwnProperty.call(e,\\\"tools\\\"))throw TypeError(\\\"Message-level tools are not supported; update the session tool policy before sending.\\\")}function En(e){if(!(\\\"agentConfig\\\"in e)||!e.agentConfig?.machineTarget)return e;let{workingDir:t,...n}=e.agentConfig.machineTarget;if(t===void 0)return e;let s=t.trim();return{...e,agentConfig:{...e.agentConfig,machineTarget:{...n,...s?{workingDir:s}:{}}}}}function vi(e){return{forWorkspace(t){let n=t.trim();if(!n)throw TypeError(\\\"workspaceId is required\\\");let s,i=()=>s??=Promise.resolve().then(() => (Ie(),{})).then(({})=>new ie(e).forWorkspace(n)),r=(o)=>new Proxy(async(...a)=>{let c=await i();for(let u of o)c=c[u];if(typeof c!==\\\"function\\\")throw TypeError(\\\"Tool path is not callable\\\");return await Reflect.apply(c,void 0,a)},{get:(a,c)=>{if(c===\\\"then\\\")return;if(typeof c!==\\\"string\\\")return;return r([...o,c])}});return new Proxy(Object.create(null),{get:(o,a)=>{if(a===\\\"$targetProtocol\\\")return e.toolGatewayMode===\\\"catalog\\\"?void 0:1;if(a===\\\"then\\\")return;if(typeof a!==\\\"string\\\")return;return r([a])}})}}}class Qe{get toolGatewayMode(){return this.options.toolGatewayMode??\\\"target\\\"}externalActorHeader;serviceInitiatorHeader;serviceContextHeader;baseUrl;options;fetchImpl;sessionCommandTimeoutMs;apiContractStrict;active=new Map;generations=new Map;queued=new Map;interaction;tools;constructor(e){this.baseUrl=e.baseUrl.replace(/\\\\/+$/,\\\"\\\"),this.options=e,this.fetchImpl=Tt(e.fetch??((n,s)=>fetch(n,s)),e.onDeprecation);let t=e.sessionCommandTimeoutMs??15000;if(!Number.isFinite(t)||t<=0)throw RangeError(\\\"sessionCommandTimeoutMs must be a finite positive number\\\");this.sessionCommandTimeoutMs=t,this.apiContractStrict=wi(e)===\\\"strict\\\",this.interaction=new Ve(this),this.tools=vi(this)}async transcribeAudio(e,t){let n=crypto.randomUUID(),s=new FormData,i=Ai(t.mimeType),r=t.audio instanceof File?t.audio:t.audio instanceof Uint8Array?new File([Uint8Array.from(t.audio)],i,{type:t.mimeType}):new File([t.audio],i,{type:t.mimeType||t.audio.type});if(s.append(\\\"audio\\\",r,i),s.append(\\\"mimeType\\\",t.mimeType),t.durationSeconds!==void 0)s.append(\\\"durationSeconds\\\",String(t.durationSeconds));let o;try{o=await this.fetchImpl(this.url(`/v1/workspaces/${e}/transcriptions`),{method:\\\"POST\\\",headers:{...this.headers(n),Accept:\\\"application/json\\\"},body:s,...t.signal?{signal:t.signal}:{}})}catch(c){if(t.signal?.aborted)throw c;throw ae(n)}if(U(o,this.apiContractStrict),!o.ok)throw await G(o,{method:\\\"POST\\\",correlationId:n});await ye(o,{method:\\\"POST\\\",correlationId:n});let a;try{a=await o.json()}catch{throw new w(o.status,\\\"Invalid transcription response.\\\",{code:\\\"invalid_response\\\",mutation:!0,correlationId:n})}if(!ki(a))throw new w(o.status,\\\"Invalid transcription response.\\\",{code:\\\"invalid_response\\\",mutation:!0,correlationId:n});return a}async createTranscriptionRecording(e,t){return me(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/transcription-recordings`,{recordingId:t.recordingId,mimeType:t.mimeType},{},t.signal?{signal:t.signal}:{}))}async getTranscriptionRecording(e,t,n={}){return me(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/transcription-recordings/${t}`,void 0,{},n.signal?{signal:n.signal}:{}))}async listTranscriptionRecordings(e,t={}){let n=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/transcription-recordings`,void 0,{},t.signal?{signal:t.signal}:{});if(!Ci(n))throw new w(502,\\\"Invalid transcription recording list response.\\\",{code:\\\"invalid_response\\\"});return n}async uploadTranscriptionRecordingChunk(e,t,n,s){let i=crypto.randomUUID(),r;try{r=await this.fetchImpl(this.url(`/v1/workspaces/${e}/transcription-recordings/${t}/chunks/${n}`),{method:\\\"PUT\\\",headers:{...this.headers(i),Accept:\\\"application/json\\\",\\\"Content-Type\\\":s.mimeType,\\\"x-opengeni-chunk-sha256\\\":s.sha256,\\\"x-opengeni-chunk-start-milliseconds\\\":String(s.startMilliseconds),\\\"x-opengeni-chunk-duration-milliseconds\\\":String(s.durationMilliseconds)},body:s.audio instanceof Uint8Array?Uint8Array.from(s.audio):s.audio,...s.signal?{signal:s.signal}:{}})}catch(a){if(s.signal?.aborted)throw a;throw ae(i)}if(U(r,this.apiContractStrict),!r.ok)throw await G(r,{method:\\\"PUT\\\",correlationId:i});await ye(r,{method:\\\"PUT\\\",correlationId:i});let o=await r.json().catch(()=>null);if(!Ii(o))throw new w(r.status,\\\"Invalid transcription chunk response.\\\",{code:\\\"invalid_response\\\",mutation:!0,correlationId:i});return o}async finalizeTranscriptionRecording(e,t,n){return me(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/transcription-recordings/${t}/finalize`,{chunkCount:n.chunkCount,totalBytes:n.totalBytes,totalDurationMilliseconds:n.totalDurationMilliseconds},{},n.signal?{signal:n.signal}:{}))}async processNextTranscriptionRecordingSegment(e,t,n={}){return me(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/transcription-recordings/${t}/process-next`,{},{},n.signal?{signal:n.signal}:{}))}async discardTranscriptionRecording(e,t,n={}){return me(await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/transcription-recordings/${t}`,void 0,{},n.signal?{signal:n.signal}:{}))}async createSession(e,t){let n=t.usageLimitMicros!==void 0&&t.usageLimitMicros!==null,s=n&&t.startMode===void 0?{...t,startMode:\\\"standard\\\"}:t,i;try{i=await this.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(e)}/sessions`,s)}catch(r){if(n&&s.startMode===\\\"standard\\\"&&r instanceof w&&lt(r))throw new de(\\\"This server does not support task usage limits, so the session was not created. Create it without a usage limit, or upgrade the server.\\\",{sessionId:null,cause:r});throw r}return xi(t.usageLimitMicros,i),i}async getSessionUsageLimit(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/sessions/${encodeURIComponent(t)}/usage-limit`,void 0,{},n)}async setSessionUsageLimit(e,t,n){let s=await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/sessions/${encodeURIComponent(t)}/usage-limit`,n);if(s.limitMicros!==n.limitMicros)throw dt(t);return s}async getNewSessionDraft(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/new-session-draft`,void 0,{},t)}async saveNewSessionDraft(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/new-session-draft`,t)}async getWorkspaceCredentialProvider(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/credential-provider`)}async putWorkspaceCredentialProvider(e,t){return this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/credential-provider`,t)}async deleteWorkspaceCredentialProvider(e){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/credential-provider`)}async listWorkspaceWebhooks(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/webhooks`)}async createWorkspaceWebhook(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/webhooks`,t)}async updateWorkspaceWebhook(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/webhooks/${t}`,n)}async deleteWorkspaceWebhook(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/webhooks/${t}`)}async listWorkspaceWebhookDeliveries(e,t,n={}){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/webhooks/${t}/deliveries`,void 0,n.limit!==void 0?{limit:String(n.limit)}:{})}async redeliverWorkspaceWebhookDelivery(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/webhooks/${t}/deliveries/${n}/redeliver`)}async listWorkspaceSandboxImages(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/sandbox-images`)}async createFeedback(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/feedback`,t)}async listOwnFeedback(e,t={}){let n=new URLSearchParams;if(t.sessionId)n.set(\\\"sessionId\\\",t.sessionId);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));if(t.includeTurns!==void 0)n.set(\\\"includeTurns\\\",String(t.includeTurns));return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/feedback${n.size?`?${n}`:\\\"\\\"}`)}async getSession(e,t,n={}){let s=g(e,t);return await this.sharedRead(s,(i)=>this.requestJson(\\\"GET\\\",s,void 0,{},{signal:i}),n)}async getToolActionReview(e,t,n){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/tool-reviews/${encodeURIComponent(n)}`)}async getToolReviewDetails(e,t,n,s){let i=new URLSearchParams({actionDigest:s.actionDigest,path:s.path??\\\"\\\",offset:String(s.offset??0)});return await this.requestJson(\\\"GET\\\",`${g(e,t)}/tool-reviews/${encodeURIComponent(n)}/details?${i}`)}async getSessionModelContext(e,t){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/model-context`)}async updateSession(e,t,n){return await this.requestJson(\\\"PATCH\\\",g(e,t),n)}async getSessionTenancyCreateCapabilities(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/session-tenancy/capabilities`)}async updateSessionVisibility(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/visibility`,n)}async previewSessionVisibilityChange(e,t,n){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/visibility/preview?visibility=${encodeURIComponent(n)}`)}async forkSession(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/forks`,n)}async updateSessionToolPolicy(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/tool-policy`,n)}async updateSessionAgent(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/agent`,n)}async updateSessionSkills(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/skills`,n)}async updateSessionMcpApprovalPolicy(e,t,n,s){return await this.requestJson(\\\"PATCH\\\",`${g(e,t)}/mcp-servers/${encodeURIComponent(n)}/approval-policy`,s)}async searchSessionMessages(e,t,n={}){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/session-message-search`,void 0,{query:t.query,...t.sessionId!==void 0?{sessionId:t.sessionId}:{},...t.groupBy!==void 0?{groupBy:t.groupBy}:{},...t.archiveStatus!==void 0?{archiveStatus:t.archiveStatus}:{},...t.limit!==void 0?{limit:String(t.limit)}:{},...t.cursor!==void 0?{cursor:t.cursor}:{}},n)}async getSessionMessagePreview(e,t,n,s={}){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/sessions/${encodeURIComponent(t)}/events/${encodeURIComponent(n.eventId)}/message-preview`,void 0,{sequence:String(n.sequence)},s)}async listSessions(e,t={}){if(t.search?.trim()||t.originSiteId){let n=await this.listSessionPage(e,t);return[...n.pinned,...n.sessions]}return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/sessions`,void 0,Xe(t))}async listSessionBackgroundCommands(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/background-commands`,void 0,{},n)}async listWorkspaceBackgroundCommands(e,t={}){let n=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/sessions`,void 0,{view:\\\"running_commands\\\",...t.cursor?{cursor:t.cursor}:{}},t);if(!n||!Array.isArray(n.commands)||!(\\\"nextCursor\\\"in n))throw Error(\\\"This server does not support the workspace running commands view.\\\");return n}async cancelSessionBackgroundCommand(e,t,n){return await this.requestJson(\\\"DELETE\\\",`${g(e,t)}/background-commands/${n}`)}async listSessionPage(e,t={}){let n=await this.requestSessionPage(`/v1/workspaces/${e}/sessions`,t);if(\\\"projection\\\"in n)throw N(\\\"full session details\\\");return n}async listSessionSummaryPage(e,t={}){let n=await this.requestSessionPage(`/v1/workspaces/${e}/sessions`,t,!0);if(\\\"projection\\\"in n)return n;await Promise.resolve().then(() => xn());return{...n,projection:\\\"summary\\\",pinned:n.pinned.map(Ee),sessions:n.sessions.map(Ee)}}async requestSessionPage(e,t,n=!1){let s=t.search?.trim(),i;try{let c={view:\\\"page\\\",...Xe(t)};if(n)c.projection=\\\"summary\\\";if(t.cursor!==void 0)c.cursor=t.cursor;if(s)c.search=s;if(t.channelId!==void 0)c.channelId=t.channelId??\\\"null\\\";if(t.createdBy)c.createdByKind=t.createdBy.kind,c.createdBySubjectId=t.createdBy.subjectId;for(let u of Si){let l=t[u];if(l)c[u]=l}if(t.pinsOnly)c.pinsOnly=\\\"true\\\";if(t.includeTotals)c.includeTotals=\\\"true\\\";if(t.needsYouOnly)c.needsYouOnly=\\\"true\\\";if(t.contentArchivedOnly)c.contentArchivedOnly=\\\"true\\\";if(t.mineOnly)c.mineOnly=\\\"true\\\";if(t.includePinned===!1)c.includePinned=\\\"false\\\";if(t.archivedOnly)c.archivedOnly=\\\"true\\\";i=await this.requestJson(\\\"GET\\\",e,void 0,c,{signal:t.signal})}catch(c){if(c instanceof w&&c.status===410)throw new Fe(c.status,c.body,{...c.code?{code:c.code}:{},retryable:c.retryable,...c.correlationId?{correlationId:c.correlationId}:{},outcomeUnknown:c.outcomeUnknown,displayMessage:\\\"The session list changed — refresh and try again.\\\"});throw c}let r=i,o=Array.isArray(r),a=bi(t);if(t.sortBy!==void 0&&(o||r.sortBy!==t.sortBy)||t.archiveStatus!==void 0&&(o||r.archiveStatus!==t.archiveStatus))throw N(\\\"the requested session sorting/archive filter\\\");if(o){let c=t.includeTotals?\\\"complete session totals\\\":t.cursor?\\\"stable session-page cursors\\\":s?\\\"session search\\\":t.pinsOnly?\\\"pins-only session lists\\\":t.archivedOnly?\\\"archived session lists\\\":a?\\\"filtered session lists\\\":null;if(c)throw N(c);return{pinned:[],sessions:r,nextCursor:null}}if(t.includeTotals&&r.totals===void 0)throw N(\\\"complete session totals\\\");if(t.needsYouOnly&&r.needsYouOnly!==!0)throw N(\\\"attention session filtering\\\");if(t.contentArchivedOnly&&r.contentArchivedOnly!==!0)throw N(\\\"read-only session filtering\\\");if(t.mineOnly&&r.mineOnly!==!0)throw N(\\\"your-sessions filtering\\\");if(a&&r.filtersApplied!==!0)throw N(\\\"filtered session lists\\\");if(t.originSiteId&&(!r.originSiteId||t.originSiteId!==\\\"current\\\"&&r.originSiteId!==t.originSiteId))throw N(\\\"Site-filtered session lists\\\");if(t.siteAccessId&&(!r.siteAccessId||t.siteAccessId!==\\\"current\\\"&&t.siteAccessId!==r.siteAccessId))throw N(\\\"Site access-filtered session lists\\\");return r}async listSiteSessionAccess(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/session-access`)}async setSiteSessionAccess(e,t,n,s){return this.requestJson(s?\\\"PUT\\\":\\\"DELETE\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/session-access/${encodeURIComponent(n)}`)}async listAgentTopology(e,t={}){let n=t.query?.trim()||t.search?.trim();if(n&&t.subject)throw TypeError(\\\"listAgentTopology query cannot be combined with an exact subject\\\");let s=Xe(t);if(t.rootSessionId)s.rootSessionId=t.rootSessionId;if(t.cursor)s.cursor=t.cursor;if(n)s.query=n;if(t.statuses?.length)s.statuses=t.statuses.join(\\\",\\\");if(t.activeOnly!==void 0)s.activeOnly=t.activeOnly?\\\"true\\\":\\\"false\\\";if(t.recentHours!==void 0)s.recentHours=String(t.recentHours);if(t.subject)s.subjectNamespace=t.subject.namespace,s.subjectType=t.subject.type,s.subjectKey=t.subject.canonicalKey;if(t.claimLimit!==void 0)s.claimLimit=String(t.claimLimit);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/agent-topology`,void 0,s)}async updateSessionPin(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/pin`,n)}async updateSessionAttention(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/attention`,n)}async updateSessionArchive(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/archive`,n)}async updateSessionRetention(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/retention`,n)}async deleteSession(e,t){return await this.requestJson(\\\"DELETE\\\",g(e,t))}async getSessionLineage(e,t,n={}){let s=`${g(e,t)}/lineage`;return await this.sharedRead(s,(i)=>this.requestJson(\\\"GET\\\",s,void 0,{},{signal:i}),n)}sharedRead(e,t,n={}){if(n.signal?.aborted)return Promise.reject(n.signal.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\"));let s=this.active.get(e);if(s){if(!n.fresh)return this.observeRead(s,n.onRequestStart),this.consumeSharedRead(e,s,n.signal);let c=s.generation+1,u=this.queued.get(e);if(u&&u.generation>=c)return this.observeRead(u,n.onRequestStart),this.consumeSharedRead(e,u,n.signal);let l=u?.promise??s.promise;return this.queueRead(e,l,c,t,n)}let i=this.queued.get(e);if(i&&(!n.fresh||!i.started))return this.observeRead(i,n.onRequestStart),this.consumeSharedRead(e,i,n.signal);if(i)return this.queueRead(e,i.promise,i.generation+1,t,n);let r=(this.generations.get(e)??0)+1,o=On(r,n.onRequestStart),a=this.consumeSharedRead(e,o,n.signal);return this.launchRead(e,o,t),a}queueRead(e,t,n,s,i){let r=On(n,i.onRequestStart),o=this.consumeSharedRead(e,r,i.signal);this.queued.set(e,r);let a=()=>this.launchRead(e,r,s);t.then(a,a);let c=()=>{if(this.queued.get(e)!==r)return;if(this.queued.delete(e),!this.active.has(e))this.generations.delete(e)};return r.promise.then(c,c),o}launchRead(e,t,n){if(t.controller.signal.aborted)return;t.started=!0,this.generations.set(e,t.generation),this.active.set(e,t);try{t.stamp=this.options.beginSharedRead?.()}catch{}for(let r of t.listeners)try{r(t.stamp)}catch{}t.listeners.clear();let s=()=>{if(this.active.get(e)!==t)return;if(this.active.delete(e),!this.queued.has(e))this.generations.delete(e)},i;try{i=n(t.controller.signal)}catch(r){s(),t.reject(r);return}i.then((r)=>{s(),t.resolve(r)},(r)=>{s(),t.reject(r)})}consumeSharedRead(e,t,n){t.consumers+=1;let s=!1,i=()=>{if(s)return;if(s=!0,t.consumers-=1,!n?.aborted||t.consumers>0)return;let o=n.reason;if(t.controller.abort(o),this.active.get(e)===t)this.active.delete(e);if(this.queued.get(e)===t)this.queued.delete(e);if(!this.active.has(e)&&!this.queued.has(e))this.generations.delete(e);t.reject(o)};return n?.addEventListener(\\\"abort\\\",i,{once:!0}),oe(t.promise,n).finally(()=>{n?.removeEventListener(\\\"abort\\\",i),i()})}observeRead(e,t){if(!t)return;if(!e.started){e.listeners.add(t);return}if(e.stamp===void 0)return;try{t(e.stamp)}catch{}}async negotiateCodexRealtimeWebrtc(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/webrtc`,n,{},{signal:s.signal})}async negotiateRealtimeWebsocket(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/websocket`,n,{},{signal:s.signal})}async negotiateGatewayRealtime(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/gateway`,n,{},{signal:s.signal})}async negotiateXaiSubscriptionRealtime(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/supergrok`,n,{},{signal:s.signal})}async activateCodexRealtimeConnection(e,t,n,s,i,r={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/${n}/connections/${s}/activate`,i,{},{signal:r.signal})}async beginSessionRealtime(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime`,n)}async heartbeatSessionRealtime(e,t,n,s){return await this.requestJson(\\\"PATCH\\\",`${g(e,t)}/realtime/${n}/heartbeat`,s)}async syncSessionRealtimeLedger(e,t,n,s){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/${n}/sync`,s)}async endSessionRealtime(e,t,n,s){return await this.requestJson(\\\"DELETE\\\",`${g(e,t)}/realtime/${n}`,s)}async listTurns(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/turns`,void 0,{...n.limit!==void 0?{limit:String(n.limit)}:{},...n.latestStarted?{latestStarted:\\\"1\\\"}:{}},{signal:n.signal})}async getLatestStartedTurn(e,t,n={}){return(await this.listTurns(e,t,{latestStarted:!0,signal:n.signal}))[0]??null}async listMachines(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/machines`,void 0,{...t.sessionId!==void 0?{sessionId:t.sessionId}:{}},{signal:t.signal})}async updateMachineAgent(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/machines/${t}/update`)}async enableMachineScreenControl(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/machines/${t}/screen-control`,{})}async openMachinePrivacySettings(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/machines/${t}/privacy-settings`,n)}async previewMachineAudience(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/machines/${t}/audience/preview`,n)}async changeMachineAudience(e,t,n){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/machines/${t}/audience`,n)}async updateMachineOperationPolicy(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/machines/${t}/operation-policy`,n)}async machineMetricsSeries(e,t,n={}){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/machines/${t}/metrics/series`,void 0,{...n.window!==void 0?{window:n.window}:{}})).samples}async removeEnrollment(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/enrollments/${t}/revoke`,n)}async lookupDeviceEnrollment(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/enrollments/device/lookup\\\",{userCode:e})}async approveDeviceEnrollment(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/enrollments/device/approve`,{userCode:t.userCode,allowScreenControl:t.allowScreenControl??!1,...t.scope?{scope:t.scope}:{}})}async denyDeviceEnrollment(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/enrollments/device/deny`,{userCode:t.userCode})}async mintEnrollToken(e,t={}){let n=\\\"scope\\\"in t?t.scope:void 0;return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/enrollments/token`,{allowScreenControl:t.allowScreenControl??!1,...n?{scope:n}:{}})}async swapActiveSandbox(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/active-sandbox`,n)}async listScheduledTasks(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-tasks`,void 0,{...t.offset!==void 0?{offset:String(t.offset)}:{},...t.sessionId?{sessionId:t.sessionId}:{},...t.limit!==void 0?{limit:String(t.limit)}:{}})}async getScheduledTask(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}`)}async listScheduledTaskSlackChannels(e,t,n){let s=new URLSearchParams({connectionId:t});if(n)s.set(\\\"cursor\\\",n);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-task-slack-channels?${s}`)}async listEvents(e,t,n={}){return(await this.listEventPage(e,t,n)).events}async listEventPage(e,t,n={}){if(n.latest&&[\\\"includeTypes\\\",\\\"excludeTypes\\\",\\\"includeClasses\\\",\\\"excludeClasses\\\"].some((P)=>Object.prototype.hasOwnProperty.call(n,P)))throw TypeError(\\\"latest cannot be combined with event filters\\\");if(n.resultMode===\\\"compact\\\"&&!n.latest)throw TypeError(\\\"resultMode=compact requires latest\\\");let s=n.resultMode===\\\"compact\\\"?null:n,i=crypto.randomUUID(),r=await this.fetchImpl(this.url(`${g(e,t)}/events`,{...s?.after!==void 0?{after:String(s.after)}:{},...s?.before!==void 0?{before:String(s.before)}:{},...s?.limit!==void 0?{limit:String(s.limit)}:{},...s?.compact?{compact:\\\"1\\\"}:{},...n.mode?{mode:n.mode}:{},...s?.direction?{direction:s.direction}:{},...n.payloadMode?{payloadMode:n.payloadMode}:{},...n.resultMode?{resultMode:n.resultMode}:{},...s?.includeTypes?.length?{includeTypes:s.includeTypes.join(\\\",\\\")}:{},...s?.excludeTypes?.length?{excludeTypes:s.excludeTypes.join(\\\",\\\")}:{},...s?.includeClasses?.length?{includeClasses:s.includeClasses.join(\\\",\\\")}:{},...s?.excludeClasses?.length?{excludeClasses:s.excludeClasses.join(\\\",\\\")}:{},...s?.presentedToolCalls===\\\"include\\\"?{presentedToolCalls:\\\"include\\\"}:{},...s?.toolOutputs===\\\"preview\\\"?{toolOutputs:\\\"preview\\\"}:{},...n.latest?{latest:n.latest}:{}}),{method:\\\"GET\\\",headers:{...this.headers(i),Accept:\\\"application/json\\\"}});if(U(r,this.apiContractStrict),!r.ok)throw await G(r,{method:\\\"GET\\\",correlationId:i});await ye(r,{method:\\\"GET\\\",correlationId:i});let o=await r.json();if(n.resultMode===\\\"compact\\\")return o;let a=o,c=(P)=>{let S=r.headers.get(P);if(S===null)return null;let h=Number(S);return Number.isSafeInteger(h)&&h>=0?h:null},u=r.headers.get(\\\"X-OpenGeni-Event-Mode\\\")===\\\"forensic\\\"?\\\"forensic\\\":\\\"monitoring\\\",l=r.headers.get(\\\"X-OpenGeni-Event-Direction\\\")===\\\"after\\\"?\\\"after\\\":\\\"before\\\",p=r.headers.get(\\\"X-OpenGeni-Payload-Mode\\\"),d=p===\\\"none\\\"||p===\\\"full\\\"?p:\\\"summary\\\",m=c(\\\"X-OpenGeni-Covered-First\\\"),y=c(\\\"X-OpenGeni-Covered-Last\\\"),R=c(\\\"X-OpenGeni-Page-Bytes\\\")??new TextEncoder().encode(JSON.stringify(a)).byteLength,v=c(\\\"X-OpenGeni-Page-Max-Bytes\\\")??1048576,b=r.headers.get(\\\"X-OpenGeni-Truncated-By\\\"),C=b===\\\"count\\\"||b===\\\"bytes\\\"||b===\\\"http_bytes\\\"?b:null;return{events:a,mode:u,payloadMode:d,direction:l,bytes:R,maxBytes:v,truncated:r.headers.get(\\\"X-OpenGeni-Page-Truncated\\\")===\\\"true\\\",hasMore:r.headers.get(\\\"X-OpenGeni-Has-More\\\")===\\\"true\\\",truncatedBy:C,coveredSequence:m===null||y===null?null:{first:m,last:y},nextAfter:c(\\\"X-OpenGeni-Next-After\\\"),nextBefore:c(\\\"X-OpenGeni-Next-Before\\\"),forensicExact:r.headers.get(\\\"X-OpenGeni-Forensic-Exact\\\")===\\\"true\\\",conversationFilter:c(vt)}}async getLatestEventResult(e,t,n={latest:\\\"terminal\\\"}){return await this.listEventPage(e,t,{...n,resultMode:\\\"compact\\\"})}async sendEvent(e,t,n){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/events`,n)}async sendMessage(e,t,n){let s=typeof n===\\\"string\\\"?{text:n}:n;qn(s);let{clientEventId:i,...r}=s;return await this.sendEvent(e,t,{type:\\\"user.message\\\",...i!==void 0?{clientEventId:i}:{},payload:r})}async pauseSession(e,t,n={}){return await this.controlSession(e,t,{action:\\\"pause\\\",clientEventId:n.clientEventId??crypto.randomUUID(),...n.reason?{reason:n.reason}:{},...n.expectedControlEtag?{expectedControlEtag:n.expectedControlEtag}:{}})}async sendApprovalDecision(e,t,n){let{clientEventId:s,...i}=n;return await this.sendEvent(e,t,{type:\\\"user.approvalDecision\\\",...s!==void 0?{clientEventId:s}:{},payload:i})}async listHumanInputRequests(e,t,n={}){let s=await this.requestJson(\\\"GET\\\",`${g(e,t)}/human-input-requests`,void 0,n.status?{status:n.status}:void 0);return wt(s,s.requests),s.requests}async getHumanInputRequest(e,t,n){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/human-input-requests/${n}`)}async submitHumanInputResponse(e,t,n,s,i={}){return await this.sendEvent(e,t,{type:\\\"user.humanInputResponse\\\",...i.clientEventId?{clientEventId:i.clientEventId}:{},payload:{requestId:n,response:s}})}streamEvents(e,t,n={}){return At(this.eventStreamTransport(e,t),n)}eventStreamTransport(e,t){return{openStream:async(n,s)=>await this.openEventStream(e,t,{after:n,...s?{signal:s}:{}}),listEvents:async(n,s)=>await this.listEvents(e,t,{after:n,limit:s})}}async openEventStream(e,t,n={}){let s=this.url(`${g(e,t)}/events/stream`,{after:String(n.after??0)}),i=crypto.randomUUID(),r=await this.fetchImpl(s,{method:\\\"GET\\\",headers:{...this.headers(i),Accept:\\\"text/event-stream\\\"},...n.signal?{signal:n.signal}:{}});if(U(r,this.apiContractStrict),!r.ok)throw await G(r,{method:\\\"GET\\\",correlationId:i});if(!r.body)throw new w(r.status,\\\"SSE response did not include a readable body\\\");return r.body}async getQueue(e,t){let n=`${g(e,t)}/queue`;return await this.sharedRead(n,()=>this.requestSessionCommand(\\\"GET\\\",n))}async moveQueueItem(e,t,n,s){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/queue/${n}/move`,s)}async editQueueItem(e,t,n,s){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/queue/${n}/edit`,s)}async steerQueueItem(e,t,n,s){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/queue/${n}/steer`,s)}async deleteQueueItem(e,t,n,s){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/queue/${n}/delete`,s)}async getComposerDraft(e,t,n={}){return await this.requestSessionCommand(\\\"GET\\\",`${g(e,t)}/composer-draft`,void 0,n)}async saveComposerDraft(e,t,n){return await this.requestSessionCommand(\\\"PUT\\\",`${g(e,t)}/composer-draft`,n)}async submitComposerDraft(e,t,n){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/composer-draft/submit`,n)}async getSandboxRecovery(e,t){return this.requestJson(\\\"GET\\\",`${g(e,t)}/sandbox-recovery`)}async recoverSandbox(e,t,n){return this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/sandbox-recovery`,n)}async retrySession(e,t,n){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/retry`,n)}async controlSession(e,t,n){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/control`,n)}async resumeSession(e,t,n={}){return await this.controlSession(e,t,{action:\\\"resume\\\",clientEventId:n.clientEventId??crypto.randomUUID(),...n.reason?{reason:n.reason}:{},...n.expectedControlEtag?{expectedControlEtag:n.expectedControlEtag}:{}})}async cancelSession(e,t,n={}){return await this.controlSession(e,t,{action:\\\"cancel\\\",clientEventId:n.clientEventId??crypto.randomUUID(),...n.reason?{reason:n.reason}:{},...n.expectedControlEtag?{expectedControlEtag:n.expectedControlEtag}:{}})}async setWorkspacePauseTimer(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/pause-timer`,t)}async setWorkspaceInferenceState(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/inference-control`,t)}async listWorkspaceControlEvents(e,t={}){return(await this.listWorkspaceControlEventPage(e,t)).events}async listWorkspaceControlEventPage(e,t={}){let n=crypto.randomUUID(),s=await this.fetchImpl(this.url(`/v1/workspaces/${e}/control-events`,{...t.after!==void 0?{after:String(t.after)}:{},...t.limit!==void 0?{limit:String(t.limit)}:{}}),{method:\\\"GET\\\",headers:{...this.headers(n),Accept:\\\"application/json\\\"}});if(U(s,this.apiContractStrict),!s.ok)throw await G(s,{method:\\\"GET\\\",correlationId:n});await ye(s,{method:\\\"GET\\\",correlationId:n});let i=await s.json(),r=s.headers.get(\\\"X-OpenGeni-Page-Bytes\\\"),o=s.headers.get(\\\"X-OpenGeni-Next-After\\\"),a=r===null?Number.NaN:Number(r),c=o===null?null:Number(o);return{events:i,bytes:Number.isSafeInteger(a)&&a>=0?a:new TextEncoder().encode(JSON.stringify(i)).byteLength,truncated:s.headers.get(\\\"X-OpenGeni-Page-Truncated\\\")===\\\"true\\\",nextAfter:c!==null&&Number.isSafeInteger(c)&&c>=0?c:null}}streamWorkspaceControlEvents(e,t={}){return qt(this.workspaceControlStreamTransport(e),t)}streamWorkspaceLiveEvents(e,t={}){return Mt(this.workspaceLiveStreamTransport(e),t)}workspaceLiveStreamTransport(e){return{openStream:async(t,n,s)=>await this.openWorkspaceLiveEventStream(e,{controlAfter:t,interactionAfter:n,...s?{signal:s}:{}})}}async openWorkspaceLiveEventStream(e,t={}){let n=crypto.randomUUID(),s=await this.fetchImpl(this.url(`/v1/workspaces/${e}/live-events/stream`,{controlAfter:String(t.controlAfter??0),interactionAfter:String(t.interactionAfter??0)}),{method:\\\"GET\\\",headers:{...this.headers(n),Accept:\\\"text/event-stream\\\"},...t.signal?{signal:t.signal}:{}});if(U(s,this.apiContractStrict),!s.ok)throw await G(s,{method:\\\"GET\\\",correlationId:n});if(!s.body)throw new w(s.status,\\\"SSE response did not include a readable body\\\");return s.body}workspaceControlStreamTransport(e){return{openStream:async(t,n)=>await this.openWorkspaceControlEventStream(e,{after:t,...n?{signal:n}:{}})}}async openWorkspaceControlEventStream(e,t={}){let n=crypto.randomUUID(),s=await this.fetchImpl(this.url(`/v1/workspaces/${e}/control-events/stream`,{after:String(t.after??0)}),{method:\\\"GET\\\",headers:{...this.headers(n),Accept:\\\"text/event-stream\\\"},...t.signal?{signal:t.signal}:{}});if(U(s,this.apiContractStrict),!s.ok)throw await G(s,{method:\\\"GET\\\",correlationId:n});if(!s.body)throw new w(s.status,\\\"SSE response did not include a readable body\\\");return s.body}async steerMessage(e,t,n){let s=typeof n===\\\"string\\\"?{text:n}:n;return qn(s),await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/steer`,s)}async getGoal(e,t,n={}){let s=`${g(e,t)}/goal`;return await this.sharedRead(s,(i)=>this.requestJson(\\\"GET\\\",s,void 0,{},{signal:i}),n)}async findGoal(e,t,n={}){let s=`${g(e,t)}/goal`,i={absent:\\\"null\\\"};return await this.sharedRead(`${s}?absent=null`,(r)=>this.requestJson(\\\"GET\\\",s,void 0,i,{signal:r}),n)}async updateGoal(e,t,n){return await this.requestJson(\\\"PATCH\\\",`${g(e,t)}/goal`,n)}async listGoalRevisions(e,t){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/goal/revisions`)}async listGoalRevisionPage(e,t,n={}){let s=new URLSearchParams;if(n.limit!==void 0)s.set(\\\"limit\\\",String(n.limit));if(n.before!==void 0)s.set(\\\"before\\\",n.before);let i=s.size>0?`?${s.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`${g(e,t)}/goal/revisions/page${i}`)}async rejectGoalRevision(e,t,n,s){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/goal/revisions/${n}/reject`,s)}async rollbackGoalRevision(e,t,n,s){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/goal/revisions/${n}/rollback`,s)}async applyGoalRevision(e,t,n,s){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/goal/revisions/${n}/apply`,s)}async deleteGoal(e,t){await this.requestVoid(\\\"DELETE\\\",`${g(e,t)}/goal`)}async pauseGoal(e,t,n={}){return await this.updateGoal(e,t,{status:\\\"paused\\\",...n.rationale!==void 0?{rationale:n.rationale}:{}})}async resumeGoal(e,t){return await this.updateGoal(e,t,{status:\\\"active\\\"})}async clearSessionContext(e,t){await this.requestVoid(\\\"POST\\\",`${g(e,t)}/context/clear`,{confirm:!0})}async compactSessionContext(e,t){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/context/compact`,{})}async fsList(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/list`,n,{},s)}async fsListBatch(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/list-batch`,n,{},s)}async fsRead(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",n.workspaceOnly?`${g(e,t)}/fs/read-workspace`:`${g(e,t)}/fs/read`,n,{},s)}async publishSandboxFileArtifact(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/artifacts/publish`,n,{},s)}async fsWrite(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/write`,n)}async fsDelete(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/delete`,n)}async fsMove(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/move`,n)}async fsMkdir(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/mkdir`,n)}async gitStatus(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/git/status`,n,{},s)}async gitDiff(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/git/diff`,n,{},s)}async gitReadBatch(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/git/read-batch`,n,{},s)}async gitLog(e,t,n={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/git/log`,n)}async gitShow(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/git/show`,n)}async getWorkspaceCapture(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/workspace/capture`,void 0,{},n)}async getWorkspaceCaptureFile(e,t,n,s,i={}){let r={path:n};if(s!==void 0)r.revision=String(s);return await this.requestJson(\\\"GET\\\",`${g(e,t)}/workspace/capture/file`,void 0,r,i)}async terminalExec(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/terminal/exec`,n)}async terminalPtyOpen(e,t,n={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/terminal/pty`,n)}async terminalPtyWrite(e,t,n){await this.requestVoid(\\\"POST\\\",`${g(e,t)}/terminal/pty/write`,n)}async terminalPtyResize(e,t,n){await this.requestVoid(\\\"POST\\\",`${g(e,t)}/terminal/pty/resize`,n)}async terminalPtyClose(e,t,n){await this.requestVoid(\\\"POST\\\",`${g(e,t)}/terminal/pty/close`,n)}async getStreamCapabilities(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/stream-capabilities`,void 0,{},n)}async acknowledgeStream(e,t,n={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/stream-capabilities/acknowledge`,n)}async attachViewer(e,t,n={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/viewers`,n)}async heartbeatViewer(e,t,n,s){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/viewers/${n}/heartbeat`,s)}async detachViewer(e,t,n){await this.requestVoid(\\\"DELETE\\\",`${g(e,t)}/viewers/${n}`)}streamWorkspaceInteractionRevisions(e,t={}){return _t(this.workspaceInteractionRevisionStreamTransport(e),t)}workspaceInteractionRevisionStreamTransport(e){return{openStream:async(t,n)=>await this.openWorkspaceInteractionRevisionStream(e,{after:t,...n?{signal:n}:{}})}}async openWorkspaceInteractionRevisionStream(e,t={}){let n=crypto.randomUUID(),s=await this.fetchImpl(this.url(`/v1/workspaces/${e}/interaction-events/stream`,{after:String(t.after??0)}),{method:\\\"GET\\\",headers:{...this.headers(n),Accept:\\\"text/event-stream\\\"},...t.signal?{signal:t.signal}:{}});if(U(s,this.apiContractStrict),!s.ok)throw await G(s,{method:\\\"GET\\\",correlationId:n});if(!s.body)throw new w(s.status,\\\"SSE response did not include a readable body\\\");return s.body}async listNetworkRoutes(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/network-routes`,void 0,t.includeArchived?{includeArchived:\\\"true\\\"}:{},t)}async getNetworkRoute(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/network-routes/${encodeURIComponent(t)}`,void 0,{},n)}async createNetworkRoute(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/network-routes`,t,{},n)}async updateNetworkRoute(e,t,n,s={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/network-routes/${encodeURIComponent(t)}`,n,{},s)}async listSiteAuthConnections(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/site-auth-connections`,void 0,t.includeArchived?{includeArchived:\\\"true\\\"}:{},t)}async getSiteAuthConnection(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/site-auth-connections/${encodeURIComponent(t)}`,void 0,{},n)}async createSiteAuthConnection(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/site-auth-connections`,t,{},n)}async updateSiteAuthConnection(e,t,n,s={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/site-auth-connections/${encodeURIComponent(t)}`,n,{},s)}async listAuthRuns(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/auth-runs`,void 0,{...t.browserSessionId?{browserSessionId:t.browserSessionId}:{},...t.siteAuthConnectionId?{siteAuthConnectionId:t.siteAuthConnectionId}:{},...t.includeSettled?{includeSettled:\\\"true\\\"}:{}},t)}async getAuthRun(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/auth-runs/${encodeURIComponent(t)}`,void 0,{},n)}async startBrowserAuthRun(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/auth-runs`,n,{},s)}async reportBrowserAuthRun(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/auth-runs/${encodeURIComponent(n)}/report`,s,{},i)}async advanceExternalBrowserAuthRun(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/auth-runs/${encodeURIComponent(n)}/external-auth`,s,{},i)}async openExternalBrowserAuthFlow(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/auth-runs/${encodeURIComponent(n)}/external-auth/interactive`,s,{},i)}async verifyBrowserAuthRun(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/auth-runs/${encodeURIComponent(n)}/verify`,s,{},i)}async listInteractionInterventions(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/interaction-interventions`,void 0,{...t.resourceKind?{resourceKind:t.resourceKind}:{},...t.resourceId?{resourceId:t.resourceId}:{},...t.includeSettled?{includeSettled:\\\"true\\\"}:{}},t)}async getInteractionIntervention(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/interaction-interventions/${encodeURIComponent(t)}`,void 0,{},n)}async createInteractionIntervention(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/interaction-interventions`,t,{},n)}async resolveInteractionIntervention(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/interaction-interventions/${encodeURIComponent(t)}/resolve`,n,{},s)}async listAttachedBrowsers(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/attached-browsers`,void 0,t.includeDisconnected?{includeDisconnected:\\\"true\\\"}:{},t)}async getAttachedBrowser(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/attached-browsers/${encodeURIComponent(t)}`,void 0,{},n)}async listBrowserIdentities(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-identities`,void 0,t.includeArchived?{includeArchived:\\\"true\\\"}:{},t)}async getBrowserIdentity(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-identities/${encodeURIComponent(t)}`,void 0,{},n)}async createBrowserIdentity(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-identities`,t,{},n)}async updateBrowserIdentity(e,t,n,s={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/browser-identities/${encodeURIComponent(t)}`,n,{},s)}async listBrowserRevisions(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-identities/${encodeURIComponent(t)}/revisions`,void 0,{},n)}async listBrowserSessions(e,t={}){let{query:n,request:s}=Tn(t);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions`,void 0,n,s)}async getBrowserSession(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}`,void 0,{},n)}async readBrowserClipboard(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/clipboard`,void 0,{},n)}async listBrowserDownloads(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/downloads`,void 0,{},n)}async getBrowserDownload(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/downloads/${encodeURIComponent(n)}`,void 0,{},s)}async saveBrowserDownload(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/downloads/${encodeURIComponent(n)}/save`,s,{},i)}async startBrowserRecording(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/recordings`,{targetId:n},{},s)}async getBrowserRecording(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/recordings/${encodeURIComponent(n)}`,void 0,{},s)}async saveBrowserRecording(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/recordings/${encodeURIComponent(n)}/save`,s,{},i)}async createBrowserSession(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions`,t,{},n)}async listBrowserTargets(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets`,void 0,{},n)}async openBrowserTarget(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets`,n,{},s)}async openBrowserTargetWithInventory(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/open-with-inventory`,n,{},s)}async selectBrowserTarget(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/select`,{},{},s)}async captureBrowserTarget(e,t,n,s={},i={}){let r=new URLSearchParams;if(i.fullPage!==void 0){if(typeof i.fullPage!==\\\"boolean\\\")throw TypeError(\\\"browser screenshot fullPage must be a boolean\\\");r.set(\\\"fullPage\\\",String(i.fullPage))}if(i.format!==void 0){if(i.format!==\\\"jpeg\\\"&&i.format!==\\\"png\\\")throw TypeError(\\\"browser screenshot format must be jpeg or png\\\");r.set(\\\"format\\\",i.format)}if(i.quality!==void 0){if(!Number.isSafeInteger(i.quality)||i.quality<1||i.quality>100)throw RangeError(\\\"browser screenshot quality must be an integer from 1 to 100\\\");r.set(\\\"quality\\\",String(i.quality))}let o=r.size>0?`?${r}`:\\\"\\\",a=await this.requestResponse(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/screenshot${o}`,{},s),c=a.headers.get(\\\"content-type\\\")?.split(\\\";\\\",1)[0]?.trim().toLowerCase(),u=a.headers.get(\\\"x-opengeni-browser-frame\\\");if(c!==\\\"image/jpeg\\\"&&c!==\\\"image/png\\\"||!u||u.length>65536)throw await M(a,\\\"browser frame metadata is invalid\\\"),new w(502,\\\"browser frame metadata is invalid\\\");let l;try{l=un(JSON.parse(atob(u.replace(/-/gu,\\\"+\\\").replace(/_/gu,\\\"/\\\"))))}catch{throw await M(a,\\\"browser frame metadata is invalid\\\"),new w(502,\\\"browser frame metadata is invalid\\\")}let p=await fe(a,25165824,null);if(l.browserSessionId!==t||l.targetId!==n||l.mediaType!==c)throw new w(502,\\\"browser frame evidence does not match its request\\\");return{...l,data:p}}async closeBrowserTarget(e,t,n,s={}){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}`,void 0,{},s)}async observeBrowserTarget(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/observation`,void 0,{},s)}async getBrowserTargetState(e,t,n,s={}){let i=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/state`,void 0,{},s);if(i.browserSessionId!==t||i.targetId!==n)throw new w(502,\\\"browser target state belongs to another binding\\\");return i}async readBrowserDom(e,t,n,s,i={}){let r=await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/dom-read`,s,{},i);if(r.browserSessionId!==t||r.targetId!==n||r.kind!==s.kind||r.targetGeneration!==s.expectedTargetGeneration||r.documentGeneration!==s.expectedDocumentGeneration||r.frameId!==s.expectedFrameId)throw new w(502,\\\"browser DOM read belongs to another binding\\\");return r}async actInBrowser(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/actions`,n,{},s)}async getBrowserActionReceipt(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/operations/${encodeURIComponent(n)}`,void 0,{},s)}async listBrowserDiagnostics(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/diagnostics`,void 0,{...s.kinds?.length?{kinds:s.kinds.join(\\\",\\\")}:{},...s.after!==void 0?{after:String(s.after)}:{},...s.limit!==void 0?{limit:String(s.limit)}:{}},s.signal?{signal:s.signal}:{})}async attachBrowserSession(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/attachments`,n,{},s)}async heartbeatBrowserSession(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/heartbeat`,{},{},n)}async publishBrowserRevision(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/revisions`,n,{},s)}async suspendBrowserSession(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/suspend`,n,{},s)}async resumeBrowserSession(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/resume`,n,{},s)}async endBrowserSession(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/end`,n,{},s)}async inspectBrowserSessionWorkingCopy(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/working-copy/inspection`,{},{},n)}async adoptBrowserSessionWorkingCopy(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/working-copy/adoptions`,n,{},s)}async getBrowserSessionWorkingCopyAdoption(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/working-copy/adoptions/${encodeURIComponent(n)}`,void 0,{},s)}async revertBrowserSessionWorkingCopyAdoption(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/working-copy/adoptions/${encodeURIComponent(n)}/revert`,{},{},s)}async listComputerSessions(e,t={}){let{query:n,request:s}=Tn(t);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions`,void 0,n,s)}async getComputerSession(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}`,void 0,{},n)}async readComputerClipboard(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/clipboard`,void 0,{},n)}async getComputerInputPosture(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/input-posture`,void 0,{},n)}async createComputerSession(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions`,t,{},n)}async listComputerTargets(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/targets`,void 0,{},n)}async observeComputerTarget(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/observation`,void 0,{},s)}async captureComputerTarget(e,t,n,s={}){let i=await this.requestResponse(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/screenshot`,{},s),r=i.headers.get(\\\"content-type\\\")?.split(\\\";\\\",1)[0]?.trim().toLowerCase();if(r!==\\\"image/jpeg\\\"&&r!==\\\"image/png\\\")throw await M(i,\\\"computer frame media type is invalid\\\"),new w(502,\\\"computer frame media type is invalid\\\");let o=i.headers.get(\\\"x-opengeni-computer-frame\\\");if(!o||o.length>32768)throw await M(i,\\\"computer frame metadata is invalid\\\"),new w(502,\\\"computer frame metadata is invalid\\\");let a;try{a=ln(o)}catch{throw await M(i,\\\"computer frame metadata is invalid\\\"),new w(502,\\\"computer frame metadata is invalid\\\")}let c=await fe(i,262144,null);if(Ei(a,{computerSessionId:t,targetId:n,mediaType:r,sha256:await Gn(c)}))throw new w(502,\\\"computer frame evidence does not match its request\\\");return{...a,data:c}}async callNativeComputerTool(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/native-calls`,n,{},s)}async actInComputer(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/actions`,n,{},s)}async getNativeComputerToolReceipt(e,t,n,s={}){let i=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/operations/${encodeURIComponent(n)}`,void 0,{},s);if(i?.targetId!==null)throw Error(\\\"Expected a native computer receipt\\\");return i}async getComputerActionReceipt(e,t,n,s={}){let i=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/operations/${encodeURIComponent(n)}`,void 0,{},s);if(typeof i?.targetId!==\\\"string\\\")throw Error(\\\"Expected a computer action receipt\\\");return i}async attachComputerSession(e,t,n,s={}){let i=await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/attachments`,n,{},s);if(i.stream.kind===\\\"direct_rfb\\\")return{...i,stream:{...i.stream,inputAllowed:i.stream.inputAllowed===!0}};return i}async heartbeatComputerSession(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/heartbeat`,{},{},n)}async endComputerSession(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/end`,n,{},s)}async getClientConfig(e={}){let t=await this.requestJson(\\\"GET\\\",\\\"/v1/config/client\\\",void 0,e.workspaceId===void 0?{}:{workspaceId:e.workspaceId},e);if(this.apiContractStrict&&t.apiContractRevision!==re)throw new we(re,String(t.apiContractRevision||\\\"(missing)\\\"));return t}async getWorkspaceModelCatalog(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/model-catalog`,void 0,{},t)}async listWorkspaceGatewayCustomModels(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/gateway-custom-models`)}async createWorkspaceGatewayCustomModel(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/gateway-custom-models`,t)}async deleteWorkspaceGatewayCustomModel(e,t,n){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(t))throw TypeError(\\\"customModelId must be a UUID\\\");await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/gateway-custom-models/${encodeURIComponent(t)}`,n)}async listWorkspaceOpenRouterCustomModels(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/openrouter-custom-models`)}async createWorkspaceOpenRouterCustomModel(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/openrouter-custom-models`,t)}async deleteWorkspaceOpenRouterCustomModel(e,t,n){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(t))throw TypeError(\\\"customModelId must be a UUID\\\");await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/openrouter-custom-models/${encodeURIComponent(t)}`,n)}async listWorkspaceOpperCustomModels(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/opper-custom-models`)}async createWorkspaceOpperCustomModel(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/opper-custom-models`,t)}async deleteWorkspaceOpperCustomModel(e,t,n){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(t))throw TypeError(\\\"customModelId must be a UUID\\\");await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/opper-custom-models/${encodeURIComponent(t)}`,n)}async getWorkspaceClaudeSubscriptionUsage(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/model-providers/claude_subscription/usage`)}async getWorkspaceSubscriptionUsagePools(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/subscription-usage-pools`)}async getOrganizationSubscriptionUsagePools(e){return this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/subscription-usage-pools`)}async listClaudeSubscriptionAccounts(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/claude/accounts`)}async activateClaudeSubscriptionAccount(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}/activate`,{})}async setClaudeSubscriptionRotationSettings(e,t){return this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/claude/settings`,t)}async setClaudeSubscriptionAccountAllocator(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}/allocator`,n)}async renameClaudeSubscriptionAccount(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}`,{label:n})}async disconnectClaudeSubscriptionAccount(e,t){return this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}`,{})}async getClaudeSubscriptionAccountUsage(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}/usage`)}async refreshClaudeSubscriptionAccountUsage(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}/usage/refresh`,{})}async listOrganizationClaudeSubscriptionAccounts(e){return this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/claude/accounts`)}async activateOrganizationClaudeSubscriptionAccount(e,t){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}/activate`,{})}async setOrganizationClaudeSubscriptionRotationSettings(e,t){return this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/claude/settings`,t)}async setOrganizationClaudeSubscriptionAccountAllocator(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}/allocator`,n)}async renameOrganizationClaudeSubscriptionAccount(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}`,{label:n})}async disconnectOrganizationClaudeSubscriptionAccount(e,t){return this.requestJson(\\\"DELETE\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}`,{})}async getOrganizationClaudeSubscriptionAccountUsage(e,t){return this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}/usage`)}async refreshOrganizationClaudeSubscriptionAccountUsage(e,t){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}/usage/refresh`,{})}async connectClaudeSubscriptionSetupToken(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/claude/accounts/setup-token`,t)}async connectOrganizationClaudeSubscriptionSetupToken(e,t){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/claude/accounts/setup-token`,t)}async startWorkspaceClaudeSubscriptionOAuth(e,t={}){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/model-providers/claude_subscription/oauth/start`,t)}async completeWorkspaceClaudeSubscriptionOAuth(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/model-providers/claude_subscription/oauth/complete`,t)}async startOrganizationClaudeSubscriptionOAuth(e,t={}){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/model-providers/claude_subscription/oauth/start`,t)}async completeOrganizationClaudeSubscriptionOAuth(e,t){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/model-providers/claude_subscription/oauth/complete`,t)}async refreshWorkspaceClaudeSubscriptionUsage(e){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/model-providers/claude_subscription/usage/refresh`,{})}async getOrganizationClaudeSubscriptionUsage(e){return this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-providers/claude_subscription/usage`)}async refreshOrganizationClaudeSubscriptionUsage(e){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/model-providers/claude_subscription/usage/refresh`,{})}async getOrganizationModelProviderConnection(e,t){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-providers/${t}`)}async upsertOrganizationModelProviderConnection(e,t,n){return await this.requestJson(\\\"PUT\\\",`/v1/organizations/${e}/model-providers/${t}`,n)}async revokeOrganizationModelProviderConnection(e,t,n){return await this.requestJson(\\\"DELETE\\\",`/v1/organizations/${e}/model-providers/${t}`,n)}async listWorkspaceClaudeCustomModels(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/model-providers/${t}/custom-models`)}async createWorkspaceClaudeCustomModel(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/model-providers/${t}/custom-models`,n)}async deleteWorkspaceClaudeCustomModel(e,t,n,s){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(n))throw TypeError(\\\"customModelId must be a UUID\\\");await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/model-providers/${t}/custom-models/${encodeURIComponent(n)}`,s)}async listOrganizationProviderCustomModels(e,t){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-providers/${t}/custom-models`)}async createOrganizationProviderCustomModel(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/model-providers/${t}/custom-models`,n)}async deleteOrganizationProviderCustomModel(e,t,n,s){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(n))throw TypeError(\\\"customModelId must be a UUID\\\");return await this.requestJson(\\\"DELETE\\\",`/v1/organizations/${e}/model-providers/${t}/custom-models/${encodeURIComponent(n)}`,s)}async getWorkspaceModelAccessPolicy(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/model-policy`)}async deleteWorkspaceModelAccessPolicy(e){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/model-policy`)}async getOrganizationModelDefaults(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-defaults`)}async updateOrganizationModelDefaults(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/model-defaults`,t)}async getOrganizationModelAccountSettings(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-account-settings`)}async updateOrganizationModelAccountSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/model-account-settings`,t)}async getModelAccountSettingsOverview(e,t={}){let n=new URLSearchParams;if(t.after!==void 0)n.set(\\\"after\\\",t.after);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-account-settings/overview${n.size?`?${n}`:\\\"\\\"}`)}async getWorkspaceModelAccountSettings(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/model-account-settings`)}async updateWorkspaceModelAccountSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/model-account-settings`,t)}async getSessionModelAccount(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/sessions/${t}/model-account`)}async setSessionModelAccount(e,t,n){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/sessions/${t}/model-account`,n)}async getModelAccountPreferences(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/me/model-account-preferences`)}async updateModelAccountPreferences(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/me/model-account-preferences`,t)}async getOrganizationAgentAdminAccess(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/agent-admin-access`)}async updateOrganizationAgentAdminAccess(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/agent-admin-access`,t)}async getOrganizationPrivacySettings(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/privacy-settings`)}async updateOrganizationPrivacySettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/privacy-settings`,t)}async updateWorkspaceModelAccessPolicy(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/model-policy`,t)}async getWorkspaceRealtimeModelCatalog(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/realtime-model-catalog`,void 0,{},t)}async getAccessContext(){return await this.requestJson(\\\"GET\\\",\\\"/v1/access/me\\\")}async listOrganizationMemberships(){return await this.requestJson(\\\"GET\\\",\\\"/v1/organization-memberships\\\")}async listUserResourceAuthorities(e,t){let n=new URLSearchParams({scope:\\\"user\\\",resourceKind:t.resourceKind});if(t.cursor)n.set(\\\"cursor\\\",t.cursor);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/user-resource-authorities?${n.toString()}`)}async revokeUserResourceGrant(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/user-resource-authorities/grants/${t}?scope=user`)}async createOrganization(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/organizations\\\",e)}async createAdditionalOrganization(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/organizations/additional\\\",e)}async listOrganizationInvitations(e={}){let t=new URLSearchParams;if(e.cursor)t.set(\\\"cursor\\\",e.cursor);if(e.limit!==void 0)t.set(\\\"limit\\\",String(e.limit));let n=t.size>0?`?${t.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/organization-invitations${n}`)}async listOrganizationInvitationsForOrganization(e,t={}){let n=new URLSearchParams;if(t.cursor)n.set(\\\"cursor\\\",t.cursor);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.size>0?`?${n.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/invitations${s}`)}async createOrganizationInvitation(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/invitations`,t)}async acceptOrganizationInvitation(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organization-invitations/${e}/accept`,t)}async revokeOrganizationInvitation(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/invitations/${t}/revoke`,n)}async listOrganizationAdministrationMembers(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/members`)}async listOrganizationMembers(e){return await this.listOrganizationAdministrationMembers(e)}async getOrganizationAdministrationOverview(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/overview`)}async createOrganizationWorkspace(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/workspaces`,t)}async updateOrganizationWorkspace(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/workspaces/${t}`,n)}async updateOrganizationWorkspaceSettings(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/workspaces/${t}/settings`,n)}async deleteOrganizationWorkspace(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/organizations/${e}/workspaces/${t}`)}async putOrganizationWorkspaceMember(e,t,n,s){return await this.requestJson(\\\"PUT\\\",`/v1/organizations/${e}/workspaces/${t}/members/${n}`,s)}async revokeOrganizationWorkspaceMember(e,t,n,s){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/workspaces/${t}/members/${n}/revoke`,s)}async updateOrganizationName(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}`,t)}async updateOrganizationMember(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/members/${t}`,n)}async getOrganizationRetentionPolicy(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/retention-policy`)}async updateOrganizationRetentionPolicy(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/retention-policy`,t)}async getOrganizationRecovery(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/recovery`)}async configureOrganizationRecoveryPolicy(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/organizations/${e}/recovery/policy`,t)}async acceptOrganizationRecoveryCustody(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/policy/accept`,t)}async disableOrganizationRecoveryPolicy(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/policy/disable`,t)}async startOrganizationRecoveryOperation(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/operations`,t)}async approveOrganizationRecoveryOperation(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/operations/${t}/approve`,n)}async cancelOrganizationRecoveryOperation(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/operations/${t}/cancel`,n)}async executeOrganizationRecoveryOperation(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/operations/${t}/execute`,n)}async searchPublicSkills(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/skills/search?q=${encodeURIComponent(t)}`)}async listWorkspaces(){return await this.requestJson(\\\"GET\\\",\\\"/v1/workspaces\\\")}connectTransport(){let e=(t)=>`/v1/workspaces/${encodeURIComponent(t)}/connect`;return{catalog:(t,n)=>this.requestJson(\\\"GET\\\",`${e(t)}/catalog`,void 0,void 0,n),accounts:(t,n)=>this.requestJson(\\\"GET\\\",`${e(t)}/accounts`,void 0,void 0,n),pending:(t,n)=>this.requestJson(\\\"GET\\\",`${e(t)}/attempts`,void 0,void 0,n),begin:(t,n,s)=>this.requestJson(\\\"POST\\\",`${e(t)}/attempts`,n,void 0,s),get:(t,n,s)=>this.requestJson(\\\"GET\\\",`${e(t)}/attempts/${encodeURIComponent(n)}`,void 0,void 0,s),advance:(t,n,s,i)=>this.requestJson(\\\"POST\\\",`${e(t)}/attempts/${encodeURIComponent(n)}/advance`,s,void 0,i),cancel:(t,n,s,i)=>this.requestJson(\\\"POST\\\",`${e(t)}/attempts/${encodeURIComponent(n)}/cancel`,s,void 0,i),disconnect:async(t,n,s)=>{if(n.startsWith(\\\"social:\\\")){let o=n.slice(7);if(!/^[0-9a-f-]{36}$/i.test(o))throw Error(\\\"Invalid social account ID\\\");await this.disconnectSocialConnection(t,o);return}if(n.startsWith(\\\"lens-registration:\\\")){let o=n.slice(18);if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(o))throw Error(\\\"Invalid Lens registration ID\\\");await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${encodeURIComponent(t)}/pr-review/registrations/${o}`,void 0,void 0,s);return}if(n.startsWith(\\\"github-installation:\\\")){let o=n.slice(20);if(!/^[1-9][0-9]*$/.test(o)||!Number.isSafeInteger(Number(o)))throw Error(\\\"Invalid GitHub installation ID\\\");await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${encodeURIComponent(t)}/github/installations/${o}`,void 0,void 0,s);return}let i=s?.expectedVersion;if(i!==void 0&&(!Number.isSafeInteger(i)||i<1))throw Error(\\\"invalid expected connection version\\\");let r=i===void 0?\\\"\\\":`?expectedVersion=${i}`;await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${encodeURIComponent(t)}/connections/${encodeURIComponent(n)}${r}`,void 0,void 0,s)}}}async browseAtlassianSources(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/atlassian/${t}/browse`)}async saveAtlassianSources(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/atlassian/${t}/source`,n)}async setAtlassianLifecycle(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/connections/atlassian/${t}/lifecycle`,n)}async beginConnect(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connect/attempts`,t)}async createWorkspace(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/workspaces\\\",e)}async ensureWorkspace(e){return await this.requestJson(\\\"PUT\\\",\\\"/v1/workspaces/external\\\",e)}async getWorkspace(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}`)}async getWorkspaceState(e,t={}){let n=new URLSearchParams;if(t.attemptId)n.set(\\\"attemptId\\\",t.attemptId);let s=n.size>0?`?${n.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/workspace-state${s}`)}async exportWorkspaceState(e,t={}){let n=new URLSearchParams;if(t.attemptId)n.set(\\\"attemptId\\\",t.attemptId);let s=n.size>0?`?${n.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/workspace-state/export${s}`)}async updateWorkspace(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}`,t)}async listWorkspaceInstructionPolicies(e,t={}){let n=new URLSearchParams;if(t.kind!==void 0)n.set(\\\"kind\\\",t.kind);if(t.scope!==void 0)n.set(\\\"scope\\\",t.scope);if(t.roleKey!==void 0)n.set(\\\"roleKey\\\",t.roleKey);if(t.afterRevision!==void 0)n.set(\\\"afterRevision\\\",String(t.afterRevision));if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.toString();return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/instruction-policies${s?`?${s}`:\\\"\\\"}`)}async getWorkspaceLearningHistory(e,t={}){let n=new URLSearchParams;if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.toString();return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/learning${s?`?${s}`:\\\"\\\"}`)}async undoGovernedLearningActivation(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/learning/activations/${encodeURIComponent(t)}/undo`,n)}async getWorkspaceInstructionPolicyRevision(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/instruction-policies/${encodeURIComponent(t)}`)}async createWorkspaceInstructionPolicyDraft(e,t,n={}){return await this.requestSessionCommand(\\\"POST\\\",`/v1/workspaces/${e}/instruction-policies/drafts`,t,n)}async listWorkspaceInstructionPolicyOnboardingProposals(e,t={}){let n=new URLSearchParams;if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.toString();return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/instruction-policies/onboarding-proposals${s?`?${s}`:\\\"\\\"}`)}async createWorkspaceInstructionPolicyOnboardingProposal(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/instruction-policies/onboarding-proposals`,t)}async importLegacyWorkspaceInstructionPolicyDraft(e,t={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/instruction-policies/import-legacy`,t)}async diffWorkspaceInstructionPolicyRevisions(e,t){let n=new URLSearchParams({fromRevisionId:t.fromRevisionId,toRevisionId:t.toRevisionId});return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/instruction-policies/diff?${n}`)}async activateWorkspaceInstructionPolicyRevision(e,t,n,s={}){return await this.requestSessionCommand(\\\"POST\\\",`/v1/workspaces/${e}/instruction-policies/${encodeURIComponent(t)}/activate`,n,s)}async rollbackWorkspaceInstructionPolicyRevision(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/instruction-policies/rollback`,t)}async listCompanyProfile(e,t={}){let n=new URLSearchParams;if(t.afterRevision!==void 0)n.set(\\\"afterRevision\\\",String(t.afterRevision));if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.toString();return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/company-profile${s?`?${s}`:\\\"\\\"}`)}async getCompanyProfileRevision(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/company-profile/revisions/${encodeURIComponent(t)}`)}async getCompanyProfileAgentPolicy(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/company-profile/agent-policy`)}async updateCompanyProfileAgentPolicy(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/company-profile/agent-policy`,t)}async updateCompanyProfile(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/company-profile`,t)}async diffCompanyProfileRevisions(e,t){let n=new URLSearchParams(t);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/company-profile/diff?${n}`)}async activateCompanyProfileRevision(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/company-profile/revisions/${encodeURIComponent(t)}/activate`,n)}async rollbackCompanyProfile(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/company-profile/rollback`,t)}async listPreferenceRegistry(e,t={}){let n=new URLSearchParams;if(t.scope)n.set(\\\"scope\\\",t.scope);if(t.status)n.set(\\\"status\\\",t.status);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.toString();return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/preferences${s?`?${s}`:\\\"\\\"}`)}async getPreferenceRegistry(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}`)}async createPreferenceRegistryProposal(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/proposals`,t)}async activatePreferenceRegistryRevision(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/activate`,n)}async correctPreferenceRegistry(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/correct`,n)}async changePreferenceRegistryScope(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/scope`,n)}async deactivatePreferenceRegistry(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/deactivate`,n)}async supersedePreferenceRegistry(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/supersede`,n)}async rejectPreferenceRegistryProposal(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/reject`,n)}async getPreferenceRegistrySummary(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/preferences/summary`)}async getPreferenceRegistryFullContent(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/full-content`,{retrievalHandle:t})}async deleteWorkspace(e){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}`)}async listWorkspaceMembers(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/members`)).members}async listWorkspaceMemberCandidates(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/member-candidates`)).members}async addWorkspaceMember(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/members`,t)}async updateWorkspaceMember(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/members/${encodeURIComponent(t)}`,n)}async removeWorkspaceMember(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/members/${encodeURIComponent(t)}`)}async prepareSlackUserLinkAccess(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/slack/user-link-intents`,t)}async getSlackUserLinkAccess(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/slack/user-link-intents/${t}`)}async requestSlackUserLinkWorkspaceAccess(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/slack/user-link-intents/${t}/request-access`,n)}async cancelSlackUserLinkAccess(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/slack/user-link-intents/${t}/cancel`,n)}async listSlackUserLinkAccessRequests(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/members/access-requests/slack`)).requests}async approveSlackUserLinkAccessRequest(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/members/access-requests/slack/${t}/approve`,n)}async denySlackUserLinkAccessRequest(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/members/access-requests/slack/${t}/deny`,n)}async createScheduledTask(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks`,En(t))}async updateScheduledTask(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}`,En(n))}async pauseScheduledTask(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}/pause`)}async listPrivateScheduledTaskSummaries(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-tasks/private-summaries`)}async pausePrivateScheduledTask(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks/private-summaries/${t}/pause`)}async resumeScheduledTask(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}/resume`)}async triggerScheduledTask(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}/trigger`,n.triggerId?{triggerId:n.triggerId}:void 0)}async deleteScheduledTask(e,t){await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}`)}async listScheduledTaskRuns(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}/runs`,void 0,{...n.limit!==void 0?{limit:String(n.limit)}:{}})}async refreshScheduledTaskAccess(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}/refresh-access`,n)}async listScheduledTaskAccessAttention(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-tasks/attention`)).tasks}vaults(e){return kt(this,e)}async listChannels(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/channels`)}async createChannel(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/channels`,t)}async updateChannel(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/channels/${t}`,n)}async reorderChannels(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/channels/order`,t)}async deleteChannel(e,t){await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/channels/${t}`)}async updateSessionChannel(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/channel`,n)}async listRigs(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/rigs`)}async createRig(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs`,t)}async getRig(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/rigs/${t}`)}async updateRig(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/rigs/${t}`,n)}async deleteRig(e,t){await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/rigs/${t}`)}async listRigVersions(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/rigs/${t}/versions`)}async activateRigVersion(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs/${t}/versions/${n}/activate`)}async listRigChanges(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/rigs/${t}/changes`)}async proposeRigChange(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs/${t}/changes`,n)}async getRigChange(e,t,n){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/rigs/${t}/changes/${n}`)}async verifyRigChange(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs/${t}/changes/${n}/verify`)}async promoteRigChange(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs/${t}/changes/${n}/promote`)}async verifyRig(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs/${t}/verify`)}async beginFileUpload(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/files/uploads`,t,{},n)}async completeFileUpload(e,t,n={}){return(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/files/uploads/${t}/complete`,void 0,{},n)).file}async uploadFile(e,t){if(t.timeoutMs!==void 0&&(!Number.isFinite(t.timeoutMs)||t.timeoutMs<=0))throw Error(\\\"File upload timeout must be a positive number\\\");Oi();let n=async(u,l)=>{let p=new AbortController,d,m=new Promise((y,R)=>{d=setTimeout(()=>{p.abort(),R(Error(\\\"File upload timed out. Retry the upload.\\\"))},u)});try{return await Promise.race([l(p.signal),m])}finally{if(d!==void 0)clearTimeout(d)}},s=t.data instanceof Uint8Array?new Blob([t.data.slice()]):t.data instanceof ArrayBuffer?t.data.slice(0):t.data,i=typeof s===\\\"string\\\"?new TextEncoder().encode(s).byteLength:s instanceof Blob?s.size:s.byteLength,r=t.sha256??await qi(s),o=await n(30000,async(u)=>await this.beginFileUpload(e,{filename:t.filename,contentType:t.contentType,...t.scope?{scope:t.scope}:{},sizeBytes:i,sha256:r,...t.appShot?{appShot:t.appShot}:{}},{signal:u})),a=t.timeoutMs??Math.max(120000,Math.ceil(i/262144)*1000),c=await n(a,async(u)=>await this.fetchImpl(o.putUrl,{method:\\\"PUT\\\",credentials:\\\"omit\\\",headers:{...o.requiredHeaders},body:s,signal:u}));if(!c.ok)throw await G(c,{method:\\\"PUT\\\"});return await n(30000,async(u)=>await this.completeFileUpload(e,o.uploadId,{signal:u}))}async listFiles(e,t={}){let n=new URLSearchParams;if(t.scope)n.set(\\\"scope\\\",t.scope);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));if(t.cursor)n.set(\\\"cursor\\\",t.cursor);return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/files${n.size?`?${n}`:\\\"\\\"}`)}async updateFileVisibility(e,t,n,s={}){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/files/${encodeURIComponent(t)}/visibility`,n,void 0,s)}async getFile(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/files/${t}${n.sessionId?`?sessionId=${encodeURIComponent(n.sessionId)}`:\\\"\\\"}`,void 0,{},n)}async getRetainedArtifact(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/artifacts/${t}`)}async getRetainedArtifactContent(e,t,n={}){return await this.getRetainedArtifactContentAtPath(`/v1/workspaces/${e}/artifacts/${t}/content`,n)}async getSessionRetainedArtifact(e,t,n){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/artifacts/${n}`)}async getSessionRetainedArtifactContent(e,t,n,s={}){return await this.getRetainedArtifactContentAtPath(`${g(e,t)}/artifacts/${n}/content`,s)}async downloadRetainedArtifact(e,t,n={}){Mn(e,t);let s=await this.downloadRetainedArtifactBytes(t,n);return{artifact:t,bytes:s}}async createRetainedArtifactDownloadUrl(e,t,n={}){Mn(e,t);let s=await this.createFileDownloadUrl(e,t.artifactId,n);return Dn(s),s}async downloadRetainedScreenshot(e,t,n,s={}){let i=await this.getSessionRetainedArtifact(e,t,n);if(!i.available)return{metadata:i,bytes:null};if(!((i.kind===\\\"computer_screenshot\\\"||i.kind===\\\"browser_screenshot\\\")&&[\\\"image/png\\\",\\\"image/jpeg\\\",\\\"image/webp\\\"].includes(i.contentType))||!i.dimensions||i.originalBytes<=0||i.originalBytes>yn)throw new w(502,\\\"retained screenshot metadata is invalid\\\");let o=await this.downloadRetainedArtifactBytes(i,s);return{metadata:i,bytes:o}}async downloadRetainedArtifactBytes(e,t){let n=t.maxRetries??2;if(!Number.isInteger(n)||n<0||n>3)throw RangeError(\\\"retained artifact maxRetries must be an integer from 0 to 3\\\");let s=new Uint8Array(e.originalBytes),i=Math.min(e.retrieval.maxRangeBytes,xe);if(!Number.isSafeInteger(i)||i<=0)throw new w(502,\\\"retained artifact range metadata is invalid\\\");for(let r=0;r<s.byteLength;r+=i){t.signal?.throwIfAborted();let o=Math.min(r+i,s.byteLength)-1,a=null;for(let u=0;u<=n;u+=1)try{a=await this.getRetainedArtifactContentAtPath(e.retrieval.path,{range:`bytes=${r}-${o}`,...t.signal?{signal:t.signal}:{}});break}catch(l){if(t.signal?.throwIfAborted(),u>=n||l instanceof w&&l.status>=400&&l.status<500)throw l}if(!a)throw new w(502,\\\"retained artifact range retry exhausted\\\");let c=o-r+1;if(a.status!==206||a.contentType!==e.contentType||a.contentLength!==c||a.contentRange!==`bytes ${r}-${o}/${e.originalBytes}`)throw new w(502,\\\"retained artifact range response is invalid\\\");s.set(a.bytes,r)}if(await Gn(s)!==e.sha256)throw new w(502,\\\"retained artifact checksum mismatch\\\");return s}async getRetainedArtifactContentAtPath(e,t){if(t.range&&(t.range.length>128||/[^\\\\x20-\\\\x7e]/.test(t.range)))throw RangeError(\\\"retained artifact range must be at most 128 printable ASCII bytes\\\");let n=crypto.randomUUID(),s=await this.fetchImpl(this.url(e),{method:\\\"GET\\\",headers:{...this.headers(n),Accept:\\\"application/octet-stream\\\",...t.range?{Range:t.range}:{}},...t.signal?{signal:t.signal}:{}});try{U(s,this.apiContractStrict)}catch(o){throw await M(s,\\\"retained artifact API contract mismatch\\\"),o}if(!s.ok)throw await G(s,{method:\\\"GET\\\",correlationId:n});if(s.status!==200&&s.status!==206)throw await M(s,\\\"unexpected retained artifact response status\\\"),new w(s.status,\\\"unexpected retained artifact response status\\\");if(s.headers.get(\\\"accept-ranges\\\")!==\\\"bytes\\\")throw await M(s,\\\"retained artifact response omitted byte-range support\\\"),new w(502,\\\"retained artifact response omitted byte-range support\\\");let i;try{i=Gi(s.headers.get(\\\"content-length\\\"))}catch(o){throw await M(s,\\\"invalid retained artifact content-length\\\"),o}let r=await fe(s,xe,i);return{bytes:r,status:s.status,contentType:s.headers.get(\\\"content-type\\\")??\\\"application/octet-stream\\\",contentLength:r.byteLength,contentRange:s.headers.get(\\\"content-range\\\"),acceptRanges:\\\"bytes\\\"}}async createFileDownloadUrl(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/files/${t}/download-url${n.sessionId?`?sessionId=${encodeURIComponent(n.sessionId)}`:\\\"\\\"}`,void 0,{},n)}async getVideoGenerationSettings(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/video-generation`,void 0,{},t)}async updateVideoGenerationPolicy(e,t,n={}){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/video-generation/policy`,t,{},n)}async getVideoGenerationOperation(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/video-generation/operations/${t}`,void 0,{},n)}async createVideoArtifactPlaybackSource(e,t,n={}){let s=await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/artifacts/${t}/playback-source`,void 0,{},n);return _i(s,t),s}async createDocumentBase(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/document-bases`,t)}async getDocumentBase(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/document-bases/${t}`)}async addDocument(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/document-bases/${t}/documents`,n)}async listDocuments(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/document-bases/${t}/documents`)}async getDocumentOriginalFile(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/documents/${t}/original-file`)}async createKnowledgeDrop(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/drops`,t)}async moveDocument(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/documents/${t}/move`,n)}async deleteDocument(e,t,n){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/document-bases/${t}/documents/${n}`)}async listKnowledgeEntries(e,t={}){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/search`,t)}async getKnowledgeEntry(e,t,n={}){let s=new URLSearchParams;if(n.revisionId!==void 0)s.set(\\\"revisionId\\\",n.revisionId);if(n.view!==void 0)s.set(\\\"view\\\",n.view);let i=s.toString();return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/knowledge/entries/${t}${i?`?${i}`:\\\"\\\"}`)}async createKnowledgeFileDownloadUrl(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/${t}/file/download-url`,n?{revisionId:n}:{})}async saveKnowledgeEntry(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries`,t)}async reviewKnowledgeEntry(e,t){let{entryId:n,...s}=t;return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/${n}/review`,s)}async listKnowledgeReviewBatches(e,t={}){let n=new URLSearchParams;for(let[s,i]of Object.entries(t))if(i!==void 0)n.set(s,String(i));return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/knowledge/review-groups?${n}`)}async reviewKnowledgeEntries(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/review`,t)}async listKnowledgeEntryHistory(e,t,n){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/knowledge/entries/${t}/history${n?`?beforeRevision=${n}`:\\\"\\\"}`)}async restoreKnowledgeEntry(e,t){let{entryId:n,...s}=t;return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/${n}/restore`,s)}async archiveKnowledgeEntry(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/${t}/archive`,n)}async getAgentLearningSettings(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/agent-learning/read`,{scope:t,source:n})}async saveAgentLearningSettings(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/agent-learning`,t)}async listAgentLearningOverrides(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/agent-learning/overrides?scope=${t}`)}async reviewAgentInstruction(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/agent-learning/instructions/review`,t)}async listAgentInstructionReviews(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/agent-learning/instructions/reviews${t?`?cursor=${encodeURIComponent(t)}`:\\\"\\\"}`)}async updateWorkspaceSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/settings`,t)}async setWorkspaceDefaultRig(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/default-rig`,t)}async listCapabilities(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/capabilities`)}async createCapability(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/capabilities`,t)}async getConnectorToolPermissions(e,t,n={}){let s=new URLSearchParams;if(n.connectionId)s.set(\\\"connectionId\\\",n.connectionId);if(n.instanceKey)s.set(\\\"instanceKey\\\",n.instanceKey);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/capabilities/${encodeURIComponent(t)}/tool-permissions${s.size?`?${s}`:\\\"\\\"}`,void 0,{},n)}async updateConnectorToolPermissions(e,t,n,s={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/capabilities/${encodeURIComponent(t)}/tool-permissions`,n,{},s)}async getSessionMcpToolPermissions(e,t,n={}){let s=new URLSearchParams({serverId:t.serverId,url:t.url});return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/session-mcp-tool-permissions?${s}`,void 0,{},n)}async updateSessionMcpToolPermissions(e,t,n={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/session-mcp-tool-permissions`,t,{},n)}async enableCapability(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/capabilities/${encodeURIComponent(t)}/enable`,n)}async disableCapability(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/capabilities/${encodeURIComponent(t)}/disable`)}async listArtifactCatalog(e,t={}){let n=new URLSearchParams;for(let i of[\\\"sourceSessionId\\\",\\\"q\\\",\\\"kind\\\",\\\"sort\\\",\\\"status\\\",\\\"limit\\\",\\\"cursor\\\"])if(t[i]!==void 0)n.set(i,String(t[i]));let s=n.size?`?${n.toString()}`:\\\"\\\";return this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/artifact-catalog${s}`,void 0,void 0,t)}async updateArtifactPin(e,t,n,s,i={}){return this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/artifact-catalog/${encodeURIComponent(t)}/${encodeURIComponent(n)}/pin`,{pinned:s},void 0,i)}async listWorkspaceArtifacts(e,t={}){let n=new URLSearchParams;if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));if(t.cursor)n.set(\\\"cursor\\\",t.cursor);if(t.status)n.set(\\\"status\\\",t.status);if(t.sourceSessionId)n.set(\\\"sourceSessionId\\\",t.sourceSessionId);let s=n.size>0?`?${n.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts${s}`,void 0,void 0,t)}async getWorkspaceArtifact(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}`,void 0,void 0,n)}async getWorkspaceArtifactHtml(e,t,n){return(await this.requestResponse(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/html`,{versionId:n.versionId},n)).text()}async rollbackWorkspaceArtifact(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/rollback`,n,void 0,s)}async duplicateWorkspaceArtifact(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/duplicate`,n,void 0,s)}async setWorkspaceArtifactStatus(e,t,n,s={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/status`,n,void 0,s)}async updateWorkspaceArtifactVisibility(e,t,n,s={}){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/visibility`,n,void 0,s)}async getSiteData(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${T(e,t)}/data`,void 0,void 0,n)}async defineSiteDataCollection(e,t,n,s,i={}){return await this.requestJson(\\\"PUT\\\",`${T(e,t)}/data/collections/${encodeURIComponent(n)}`,s,void 0,i)}async deleteSiteDataCollection(e,t,n,s={}){return await this.requestJson(\\\"DELETE\\\",`${T(e,t)}/data/collections/${encodeURIComponent(n)}`,void 0,{confirm:\\\"true\\\"},s)}async resetSiteDataCollection(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${T(e,t)}/data/collections/${encodeURIComponent(n)}/reset`,{confirm:!0},void 0,s)}async querySiteData(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${T(e,t)}/data/query`,n,void 0,s)}async writeSiteData(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${T(e,t)}/data/write`,n,void 0,s)}async importSiteData(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`${T(e,t)}/data/collections/${encodeURIComponent(n)}/import`,s,void 0,i)}async exportSiteData(e,t,n,s={}){let i=s.format??\\\"json\\\",r=await this.requestResponse(\\\"GET\\\",`${T(e,t)}/data/collections/${encodeURIComponent(n)}/export`,{format:i},{...s,accept:i===\\\"csv\\\"?\\\"text/csv\\\":\\\"application/json\\\"});return{content:await r.text(),contentType:r.headers.get(\\\"content-type\\\")??\\\"\\\",truncated:r.headers.get(\\\"x-opengeni-export-truncated\\\")===\\\"true\\\"}}async listSiteDataFiles(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${T(e,t)}/files`,void 0,{...n.limit===void 0?{}:{limit:String(n.limit)},...n.cursor?{cursor:n.cursor}:{}},n)}async getSiteDataFileUrl(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`${T(e,t)}/files/${encodeURIComponent(n)}`,void 0,void 0,s)}async deleteSiteDataFile(e,t,n,s={}){return await this.requestJson(\\\"DELETE\\\",`${T(e,t)}/files/${encodeURIComponent(n)}`,void 0,void 0,s)}async getSiteSql(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${T(e,t)}/sql`,void 0,void 0,n)}async updateSiteSqlSettings(e,t,n,s={}){return await this.requestJson(\\\"PUT\\\",`${T(e,t)}/sql/settings`,n,void 0,s)}async migrateSiteSql(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${T(e,t)}/sql/migrations`,n,void 0,s)}async defineSiteSqlQuery(e,t,n,s,i={}){return await this.requestJson(\\\"PUT\\\",`${T(e,t)}/sql/queries/${encodeURIComponent(n)}`,s,void 0,i)}async deleteSiteSqlQuery(e,t,n,s={}){return await this.requestJson(\\\"DELETE\\\",`${T(e,t)}/sql/queries/${encodeURIComponent(n)}`,void 0,void 0,s)}async runSiteSqlQuery(e,t,n,s={},i={}){return await this.requestJson(\\\"POST\\\",`${T(e,t)}/sql/queries/${encodeURIComponent(n)}`,s,void 0,i)}async querySiteSql(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${T(e,t)}/sql/query`,n,void 0,s)}async executeSiteSql(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${T(e,t)}/sql/execute`,n,void 0,s)}async inspectSiteSql(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${T(e,t)}/sql/inspect`,void 0,void 0,n)}async exportSiteSql(e,t,n={}){let s=n.format??\\\"sql\\\",i=await this.requestResponse(\\\"GET\\\",`${T(e,t)}/sql/export`,{format:s,...n.table?{table:n.table}:{},...n.cursor?{cursor:n.cursor}:{},...n.maxBytes!==void 0?{maxBytes:String(n.maxBytes)}:{}},{...n,accept:s===\\\"json\\\"?\\\"application/json\\\":\\\"*/*\\\"});return{content:await i.text(),contentType:i.headers.get(\\\"content-type\\\")??\\\"\\\",truncated:i.headers.get(\\\"x-opengeni-export-truncated\\\")===\\\"true\\\",nextCursor:i.headers.get(\\\"x-opengeni-export-next-cursor\\\")||null}}async importSiteSql(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${T(e,t)}/sql/import`,n,void 0,s)}async resetSiteSql(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`${T(e,t)}/sql/reset`,{confirm:!0,...n},void 0,s)}async getSitePublication(e,t,n={}){return await this.requestJson(\\\"GET\\\",Y(e,t),void 0,void 0,n)}async updateSitePublication(e,t,n,s={}){return await this.requestJson(\\\"PUT\\\",Y(e,t),n,void 0,s)}async unpublishSite(e,t,n={}){return await this.requestJson(\\\"DELETE\\\",Y(e,t),void 0,void 0,n)}async applySitePublicationFix(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${Y(e,t)}/fixes`,n,void 0,s)}async getSitePlatformUsage(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/site-platform-usage`,void 0,void 0,t)}async checkSiteHostname(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/site-hostnames/${encodeURIComponent(t)}`,void 0,void 0,n)}async takeDownSite(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${Y(e,t)}/takedown`,n,void 0,s)}async restoreSite(e,t,n={}){return await this.requestJson(\\\"POST\\\",`${Y(e,t)}/restore`,{},void 0,n)}async listSiteAbuseReports(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${Y(e,t)}/reports`,void 0,void 0,n)}async updateSiteAbuseReport(e,t,n,s,i={}){return await this.requestJson(\\\"PATCH\\\",`${Y(e,t)}/reports/${encodeURIComponent(n)}`,s,void 0,i)}async getSiteLimitProfile(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/site-limit-profile`,void 0,void 0,t)}async updateSiteLimitProfile(e,t,n={}){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/site-limit-profile`,t,void 0,n)}async authorizeSiteViewer(e,t={}){return await this.requestJson(\\\"POST\\\",\\\"/v1/site-auth/authorize\\\",e,void 0,t)}async discoverMcpCapabilities(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/capabilities/discovery/mcp-registry`,void 0,{...t.query!==void 0?{query:t.query}:{},...t.limit!==void 0?{limit:String(t.limit)}:{}})}async discoverPlugins(e,t={}){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/capabilities/discovery/plugins`,void 0,{...t.id?{id:t.id}:{},...t.query?{query:t.query}:{},...t.provider?{provider:t.provider}:{},...t.offset!==void 0?{offset:String(t.offset)}:{}})}async inspectMcpAuthentication(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/capabilities/discovery/mcp-auth`,{url:t})}async listApiIntegrations(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations`)}async listIntegrationDefinitions(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/definitions`)}async previewApiIntegration(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/preview`,t)}async startApiIntegrationOAuth(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/oauth/start`,t)}async installApiIntegration(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/install`,t)}async previewApiIntegrationUninstall(e,t,n){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/uninstall-preview`)}async uninstallApiIntegration(e,t,n,s){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}`,s)}async listIntegrationFacets(e,t,n){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets`)}async configureIntegrationFacet(e,t,n,s,i){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets/${encodeURIComponent(s)}`,i)}async browseGoogleDriveFacetSource(e,t,n,s,i={}){let r=new URLSearchParams;if(i.parentId)r.set(\\\"parentId\\\",i.parentId);if(i.pageToken)r.set(\\\"pageToken\\\",i.pageToken);let o=r.size>0?`?${r}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets/${encodeURIComponent(s)}/browse${o}`)}async saveGoogleDriveFacetSource(e,t,n,s,i){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets/${encodeURIComponent(s)}/source`,i)}async pauseIntegrationFacet(e,t,n,s,i){return await this.mutateIntegrationFacetLifecycle(e,t,n,s,\\\"pause\\\",i)}async resumeIntegrationFacet(e,t,n,s,i){return await this.mutateIntegrationFacetLifecycle(e,t,n,s,\\\"resume\\\",i)}async removeIntegrationFacet(e,t,n,s,i){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets/${encodeURIComponent(s)}`,i)}async mutateIntegrationFacetLifecycle(e,t,n,s,i,r){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets/${encodeURIComponent(s)}/${i}`,r)}async previewPlugin(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/plugins/preview`,t)}async getInstalledPluginDetails(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/plugins/details`,void 0,{pluginKey:t})}async listInstalledPlugins(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/plugins`)}async installPlugin(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/plugins/install`,t)}async previewPluginUninstall(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/plugins/${encodeURIComponent(t)}/uninstall-preview`)}async uninstallPlugin(e,t,n){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/plugins/${encodeURIComponent(t)}`,n)}async previewSkillImport(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/preview`,t)}async installSkill(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/install`,t)}async listInstalledSkills(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/skills`)}async listWorkspaceSkills(e,t={}){let n=new URLSearchParams;if(t.cursor!==void 0)n.set(\\\"cursor\\\",t.cursor);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));if(t.sessionId!==void 0)n.set(\\\"sessionId\\\",t.sessionId);let s=n.size?`?${n.toString()}`:\\\"\\\";return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/skills/content${s}`)}async readWorkspaceSkill(e,t,n){let s=n?`?revisionId=${encodeURIComponent(n)}`:\\\"\\\";return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/skills/content/${encodeURIComponent(t)}${s}`)}async saveWorkspaceSkill(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/content/save`,t)}async removeWorkspaceSkill(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/content/${encodeURIComponent(t)}/remove`,n)}async approveWorkspaceSkill(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/content/${encodeURIComponent(t)}/approve`,n)}async restoreWorkspaceSkill(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/content/${encodeURIComponent(t)}/restore`,n)}async rejectWorkspaceSkill(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/content/${encodeURIComponent(t)}/reject`,n)}async installLibrarySkill(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/library/${encodeURIComponent(t)}/install`,n)}async previewSkillUninstall(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/skills/${encodeURIComponent(t)}/uninstall-preview`)}async uninstallSkill(e,t,n){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/skills/${encodeURIComponent(t)}`,n)}async listOwnConnectionAccounts(e,t={}){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/accounts`,void 0,t.includeInactive===!0?{includeInactive:\\\"true\\\"}:{})).connections}async listConnections(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections`)).connections}async personalGitHubStatus(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/github`)}async startPersonalGitHubOAuth(e,t={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/github/oauth/start`,t)}async reconnectPersonalGitHub(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/${t}/github/reconnect`,n)}async disconnectPersonalGitHub(e,t,n){return(await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/connections/${t}`,n)).connection}async listPersonalGitHubRepositories(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/${t}/github/repositories`,void 0,{...n.cursor!==void 0?{cursor:String(n.cursor)}:{},...n.limit!==void 0?{limit:String(n.limit)}:{}})}async replacePersonalGitHubRepositorySelections(e,t,n){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/connections/${t}/github/repositories`,n)}async verifyPersonalGitHubRepositorySelections(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/${t}/github/repositories/verify`,n)}async listSlackInstallationBindings(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/slack-bot/bindings`)).bindings}async createConnection(e,t){return(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections`,t)).connection}async installFikenConnection(e,t){return(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/fiken/install`,t)).connection}async startFikenOAuth(e,t={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/fiken/oauth/start`,t)}async listAvailableOpenGeniSlackBots(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/slack-bot/available`)}async getOpenGeniSlackBotOrganizationAccess(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/${t}/slack-bot/organization-access`)}async setOpenGeniSlackBotOrganizationAccess(e,t,n){return this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/connections/${t}/slack-bot/organization-access`,n)}async startOpenGeniSlackBotInstall(e,t={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/slack-bot/install`,t)}async listOpenGeniSlackReactionChannels(e,t,n){let s=new URLSearchParams({connectionId:t});if(n)s.set(\\\"cursor\\\",n);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/slack/reaction-channels?${s}`)}async listOpenGeniSlackChannelRoutes(e,t){let n=new URLSearchParams({connectionId:t});return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/slack/channel-routes?${n}`)}async updateOpenGeniSlackChannelRoutes(e,t){await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/integrations/slack/channel-routes`,t)}async updateConnection(e,t,n){return(await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/connections/${t}`,n)).connection}async deleteConnection(e,t){return(await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/connections/${t}`)).connection}async disconnectGoogleDriveConnection(e,t,n){return(await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/connections/${t}`,n)).connection}async transitionGoogleDriveLifecycle(e,t,n){return(await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/connections/google-drive/${t}/lifecycle`,n)).connection}async startConnectionOAuth(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/oauth/start`,t,{},n)}async startSocialOAuth(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/social/oauth/start`,t)}async listSocialConnections(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/social/connections`)}async disconnectSocialConnection(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/social/connections/${t}`)}catalogAssetUrl(e){return e?`${this.baseUrl}/v1/${e}`:null}async downloadCatalogAsset(e,t={}){if(!/^catalog-assets\\\\/[a-zA-Z0-9_./-]+$/.test(e)||e.split(\\\"/\\\").some((r)=>!r||r===\\\".\\\"||r===\\\"..\\\"))throw TypeError(\\\"A catalog asset path is required\\\");let n=await this.requestResponse(\\\"GET\\\",`/v1/${e}`,{},t),s=n.headers.get(\\\"content-type\\\")?.split(\\\";\\\")[0]??\\\"\\\";if(!s.startsWith(\\\"image/\\\"))throw await n.body?.cancel(),Error(\\\"The catalog asset is not an image\\\");let i=await fe(n,2000000,null);return new Blob([Uint8Array.from(i)],{type:s})}async getGitHubApp(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/github/app`,void 0,t.returnPath?{returnPath:t.returnPath}:void 0)}githubConnectUrl(e,t){return this.url(`/v1/workspaces/${e}/github/connect`,{state:t})}async listGitHubRepositories(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/github/repositories`)}async getGitHubActionPolicies(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/github/action-policies`)}async updateGitHubActionPolicy(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/github/action-policies`,t)}async syncGitHubRepositories(e){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/github/repositories/sync`)}async unlinkGitHubInstallation(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/github/installations/${t}`)}async createGitHubAppManifest(e,t={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/github/app-manifest`,t)}async listApiKeys(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/api-keys`)).apiKeys}async createApiKey(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/api-keys`,t)}async deleteApiKey(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/api-keys/${t}`)}async listOrganizationApiKeys(e){return(await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/api-keys`)).apiKeys}async createOrganizationApiKey(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/api-keys`,t)}async deleteOrganizationApiKey(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/organizations/${e}/api-keys/${t}`)}async listOrganizationMcpConnections(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/mcp-connections`)}async updateOrganizationMcpConnection(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/mcp-connections/${t}`,n)}async deleteOrganizationMcpConnection(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/organizations/${e}/mcp-connections/${t}`,{})}async listPersonalApiKeys(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/personal-api-keys`)}async createPersonalApiKey(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/personal-api-keys`,t)}async revokePersonalApiKey(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/organizations/${e}/personal-api-keys/${t}`,{})}async listOrganizationServiceAccounts(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/service-accounts`)}async getOrganizationServiceAccount(e,t){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/service-accounts/${t}`)}async createOrganizationServiceAccount(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/service-accounts`,t)}async updateOrganizationServiceAccount(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/service-accounts/${t}`,n)}async deleteOrganizationServiceAccount(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/organizations/${e}/service-accounts/${t}`)}async getMcpConnectionRequest(e){return await this.requestJson(\\\"GET\\\",`/v1/mcp-connections/requests/${encodeURIComponent(e)}`)}async answerMcpConnectionRequest(e,t){return await this.requestJson(\\\"POST\\\",`/v1/mcp-connections/requests/${encodeURIComponent(e)}`,t)}async listInbox(e={}){let t=e.workspaceId?`?workspaceId=${encodeURIComponent(e.workspaceId)}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/inbox${t}`)}async updateInboxItem(e,t){await this.requestJson(\\\"PATCH\\\",`/v1/inbox/items/${encodeURIComponent(e)}`,t)}async getInboxSettings(){return await this.requestJson(\\\"GET\\\",\\\"/v1/inbox/settings\\\")}async updateInboxSettings(e){return await this.requestJson(\\\"PUT\\\",\\\"/v1/inbox/settings\\\",e)}async getMemberNotifications(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/inbox/member-notifications`)}async updateMemberNotifications(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/inbox/member-notifications`,t)}async getSessionInboxMute(e,t){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/inbox-mute`)}async setSessionInboxMute(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/inbox-mute`,n)}async getSessionAdminAccess(e,t){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/admin-access`)}async grantSessionAdminAccess(e,t,n={}){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/admin-access`,n)}async revokeSessionAdminAccess(e,t){return await this.requestJson(\\\"DELETE\\\",`${g(e,t)}/admin-access`)}async authorizeNativeApp(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/native-app/authorize\\\",e)}async exchangeNativeAppCode(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/native-app/token\\\",e)}async createOfficeWorkbookTicket(e){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(e)}/office/workbook-tickets`,{})}async listOfficeWorkbooks(e){let{workbooks:t}=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/office/workbooks`);return t}async signOutNativeApp(){await this.requestJson(\\\"POST\\\",\\\"/v1/native-app/sign-out\\\",{})}async getNativePushDevice(){let{device:e}=await this.requestJson(\\\"GET\\\",\\\"/v1/native-app/push-device\\\");return e}async registerNativePushDevice(e){let{device:t}=await this.requestJson(\\\"PUT\\\",\\\"/v1/native-app/push-device\\\",e);return t}async unregisterNativePushDevice(){await this.requestJson(\\\"DELETE\\\",\\\"/v1/native-app/push-device\\\")}async listOrganizationSessions(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/sessions`,void 0,{...t.limit===void 0?{}:{limit:String(t.limit)},...t.cursor===void 0?{}:{cursor:t.cursor},...t.scopeSubjectId?{scopeSubjectId:t.scopeSubjectId}:{},...t.status===void 0?{}:{status:t.status}},{signal:t.signal})}async*iterateOrganizationSessions(e,t={}){let n;do{let s=await this.listOrganizationSessions(e,{...t,...n===void 0?{}:{cursor:n}});for(let i of s.sessions)yield i;n=s.nextCursor??void 0}while(n!==void 0)}async getBilling(e={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing\\\",void 0,{...e.accountId!==void 0?{accountId:e.accountId}:{}})}async getOrganizationUsageSummary(e,t={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/usage-summary\\\",void 0,{accountId:e.accountId,period:e.period??\\\"month\\\"},t)}async getOrganizationModelUsage(e,t={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/usage-models\\\",void 0,{accountId:e.accountId,period:e.period??\\\"month\\\",...e.afterWorkspaceId?{afterWorkspaceId:e.afterWorkspaceId}:{}},t)}async getOrganizationUsageWorkspacePage(e,t={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/usage-workspaces\\\",void 0,{accountId:e.accountId,period:e.period??\\\"month\\\",until:e.until,...e.afterWorkspaceId?{afterWorkspaceId:e.afterWorkspaceId}:{}},t)}async getBillingUsage(e={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/usage\\\",void 0,{...e.accountId!==void 0?{accountId:e.accountId}:{},...e.workspaceId!==void 0?{workspaceId:e.workspaceId}:{}})}async getWorkspaceInsights(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/insights`,void 0,{range:t.range??\\\"week\\\",...t.provider!==void 0?{provider:t.provider}:{},...t.model!==void 0?{model:t.model}:{},...t.rootSessionId!==void 0?{rootSessionId:t.rootSessionId}:{},...t.sessionId!==void 0?{sessionId:t.sessionId}:{}},{signal:t.signal})}async getWorkspaceInsightsSiteUsage(e,t={},n={}){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/insights/sites`,void 0,{range:t.range??\\\"month\\\"},n)}async getWorkspaceInsightsUsage(e,t={},n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/insights/usage${Ae(t)}`,void 0,{},n)}async getOrganizationInsightsUsage(e,t={},n={}){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${encodeURIComponent(e)}/insights/usage${Ae(t)}`,void 0,{},n)}async listInsightsCalls(e,t={},n={}){let s=e.kind===\\\"workspace\\\"?`/v1/workspaces/${encodeURIComponent(e.workspaceId)}/insights/calls`:`/v1/organizations/${encodeURIComponent(e.accountId)}/insights/calls`;return await this.requestJson(\\\"GET\\\",`${s}${Ae(t)}`,void 0,{},n)}async getBillingEntitlements(e={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/entitlements\\\",void 0,{...e.accountId!==void 0?{accountId:e.accountId}:{}})}async createBillingCheckout(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/checkout\\\",e)}async getBillingCheckout(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/billing/checkout/${encodeURIComponent(e)}`,void 0,{...t.accountId!==void 0?{accountId:t.accountId}:{}})}async createBillingPortalSession(e={}){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/portal\\\",e)}async getBillingSubscriptionPlans(e={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/subscription/plans\\\",void 0,e)}async createSubscriptionCheckout(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/subscription/checkout\\\",e)}async upgradeBillingSubscription(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/subscription/upgrade\\\",e)}async changeBillingSubscription(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/subscription/change\\\",e)}async cancelBillingSubscription(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/subscription/cancel\\\",e)}async createSubscriptionPortalSession(e={}){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/subscription/portal\\\",e)}apiUrl(e){if(!e.startsWith(\\\"/\\\"))throw TypeError(\\\"API path must start with /\\\");return`${this.baseUrl}${e}`}withHeaders(e){let t={...e},n=this.options.headers,i=new this.constructor({...this.options,headers:()=>({...typeof n===\\\"function\\\"?n():n,...t})});if(this.externalActorHeader!==void 0)i.externalActorHeader=this.externalActorHeader;return i.serviceInitiatorHeader=this.serviceInitiatorHeader,i.serviceContextHeader=this.serviceContextHeader,i}async fetchApi(e,t={}){let n=typeof globalThis.location?.href===\\\"string\\\"?globalThis.location.href:void 0,s=new URL(this.baseUrl.endsWith(\\\"/\\\")?this.baseUrl:`${this.baseUrl}/`,n),i=new URL(e,s);if(i.origin!==s.origin||!`${i.pathname}/`.startsWith(s.pathname))throw TypeError(\\\"fetchApi only reaches this client's API base URL\\\");let r=new Headers(t.headers);for(let[o,a]of Object.entries(this.headers()))if(!r.has(o))r.set(o,a);return await this.fetchImpl(i.href,{...t,headers:r})}headers(e){let t=typeof this.options.headers===\\\"function\\\"?this.options.headers():this.options.headers,n={...this.options.apiKey?{Authorization:`Bearer ${this.options.apiKey}`}:{},...t,[Ke]:re,...e?{[Pe]:e}:{}},s=Object.keys(n).map((o)=>o.toLowerCase()),i=this.externalActorHeader!==void 0||s.includes(\\\"x-opengeni-external-actor\\\"),r=this.serviceInitiatorHeader!==void 0||s.includes(\\\"x-opengeni-service-initiator\\\")||s.includes(\\\"x-opengeni-service-context\\\");if(i&&r)throw Error(\\\"asUser and asService attribution headers are mutually exclusive\\\");if(this.externalActorHeader){for(let o of Object.keys(n))if(o.toLowerCase()===\\\"x-opengeni-external-actor\\\")delete n[o];n[\\\"x-opengeni-external-actor\\\"]=this.externalActorHeader}if(this.serviceInitiatorHeader!==void 0){for(let o of Object.keys(n)){let a=o.toLowerCase();if(a===\\\"x-opengeni-service-initiator\\\"||a===\\\"x-opengeni-service-context\\\")delete n[o]}if(n[\\\"x-opengeni-service-initiator\\\"]=this.serviceInitiatorHeader,this.serviceContextHeader!==void 0)n[\\\"x-opengeni-service-context\\\"]=this.serviceContextHeader}return n}url(e,t={}){let n=new URLSearchParams(t).toString();return`${this.baseUrl}${e}${n?`?${n}`:\\\"\\\"}`}async codexStatus(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/codex/status`)}async codexConnectStart(e){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/codex/connect/start`,{})}async codexConnectPoll(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/codex/connect/poll`,{state:t})}async codexUsage(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/codex/usage`)}async codexAccountUsage(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/codex/accounts/${t}/usage`)}async organizationCodexAccountUsage(e,t){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/codex/accounts/${encodeURIComponent(t)}/usage`)}async refreshCodexUsage(e){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/codex/usage/refresh`)}async codexOverview(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/codex/overview`)}async codexDisconnect(e){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/codex`)}async listCodexAccounts(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/codex/accounts`)}async listSessionCodexAccounts(e,t){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/codex-accounts`)}async activateCodexAccount(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/codex/accounts/${t}/activate`)}async designateCodexAppsAccount(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/codex/apps`,{accountId:t,expectedVersion:n})}async clearCodexAppsAccount(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/codex/apps`,{expectedVersion:t})}async setCodexRotationSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/codex/settings`,t)}async setCodexAccountAllocator(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/codex/accounts/${t}/allocator`,n)}async disconnectCodexAccount(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/codex/accounts/${t}`)}async renameCodexAccount(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/codex/accounts/${t}`,{label:n})}async pinSessionCodexAccount(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/codex-account`,{target:n})}async getModelConnectionAccess(e){return await this.requestJson(\\\"GET\\\",`/v1/${e.scope}/${encodeURIComponent(e.scopeId)}/model-connections/${e.kind}/${encodeURIComponent(e.connectionId)}/access`)}async updateModelConnectionAccess(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/${e.scope}/${encodeURIComponent(e.scopeId)}/model-connections/${e.kind}/${encodeURIComponent(e.connectionId)}/access`,t)}async listOrganizationSuperGrokAccounts(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/supergrok/accounts`)}async organizationSupergrokConnectStart(e){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/supergrok/connect/start`,{})}async organizationSupergrokConnectPoll(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/supergrok/connect/poll`,{state:t})}async activateOrganizationSuperGrokAccount(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/supergrok/accounts/${t}/activate`,{})}async setOrganizationSuperGrokRotationSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/supergrok/settings`,t)}async setOrganizationSuperGrokAccountAllocator(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/supergrok/accounts/${t}/allocator`,n)}async renameOrganizationSuperGrokAccount(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/supergrok/accounts/${t}`,{label:n})}async disconnectOrganizationSuperGrokAccount(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/organizations/${e}/supergrok/accounts/${t}`,{})}async supergrokStatus(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/supergrok/status`)}async supergrokConnectStart(e,t=\\\"workspace\\\"){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/supergrok/connect/start`,{scope:t})}async supergrokConnectPoll(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/supergrok/connect/poll`,{state:t})}async listSuperGrokAccounts(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/supergrok/accounts`)}async activateSuperGrokAccount(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/supergrok/accounts/${t}/activate`,{})}async setSuperGrokRotationSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/supergrok/settings`,t)}async setSuperGrokAccountAllocator(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/supergrok/accounts/${t}/allocator`,n)}async renameSuperGrokAccount(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/supergrok/accounts/${t}`,{label:n})}async disconnectSuperGrokAccount(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/supergrok/accounts/${t}`,{})}async requestSessionCommand(e,t,n,s={}){return await this.requestJson(e,t,n,{},{signal:s.signal,timeoutMs:s.timeoutMs??this.sessionCommandTimeoutMs})}async requestJson(e,t,n,s={},i={}){let r=crypto.randomUUID(),o=Pi(i);try{if(o.signal?.aborted)throw o.signal.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\");let a=this.headers(r),c;try{c=await oe(this.fetchImpl(this.url(t,s),{method:e,headers:{...a,Accept:\\\"application/json\\\",...n!==void 0?{\\\"Content-Type\\\":\\\"application/json\\\"}:{}},...n!==void 0?{body:JSON.stringify(n)}:{},...o.signal?{signal:o.signal}:{}}),o.signal)}catch(u){if(i.signal?.aborted)throw u;if(ce(e))throw ae(r);throw u}U(c,this.apiContractStrict);try{if(!c.ok)throw await oe(G(c,{method:e,correlationId:r}),o.signal);if(i.responseType===\\\"void\\\"){await oe(M(c,\\\"discarding void API response\\\"),o.signal);return}await oe(ye(c,{method:e,correlationId:r}),o.signal);let u=await oe(c.json(),o.signal);return bt(u,c.headers.get(St)),u}catch(u){if(i.signal?.aborted)throw u;if(u instanceof w)throw u;if(ce(e))throw ae(r);throw u}}finally{o.dispose()}}async requestResponse(e,t,n={},s={}){let i=crypto.randomUUID(),r=this.headers(i),o;try{o=await this.fetchImpl(this.url(t,n),{method:e,headers:{...r,Accept:s.accept??\\\"application/octet-stream\\\"},...s.signal?{signal:s.signal}:{}})}catch(a){if(ce(e))throw ae(i);throw a}if(U(o,this.apiContractStrict),!o.ok)throw await G(o,{method:e,correlationId:i});return o}async requestVoid(e,t,n){let s=crypto.randomUUID(),i=this.headers(s),r;try{r=await this.fetchImpl(this.url(t),{method:e,headers:{...i,Accept:\\\"application/json\\\",...n!==void 0?{\\\"Content-Type\\\":\\\"application/json\\\"}:{}},...n!==void 0?{body:JSON.stringify(n)}:{}})}catch(o){if(ce(e))throw ae(s);throw o}if(U(r,this.apiContractStrict),!r.ok)throw await G(r,{method:e,correlationId:s})}}function U(e,t){if(!t)return;let n=e.headers.get(Ke);if(n&&n!==re)throw new we(re,n)}function ki(e){if(!e||typeof e!==\\\"object\\\"||Array.isArray(e))return!1;let t=e;return typeof t.text===\\\"string\\\"&&Array.isArray(t.languages)&&t.languages.every((n)=>typeof n===\\\"string\\\")}function Ii(e){if(!e||typeof e!==\\\"object\\\"||Array.isArray(e))return!1;let t=e;if(!Ze({recording:t.recording,segments:[]}))return!1;if(!t.chunk||typeof t.chunk!==\\\"object\\\"||Array.isArray(t.chunk))return!1;let n=t.chunk;return typeof n.chunkNumber===\\\"number\\\"&&typeof n.byteLength===\\\"number\\\"&&typeof n.sha256===\\\"string\\\"&&typeof n.startMilliseconds===\\\"number\\\"&&typeof n.durationMilliseconds===\\\"number\\\"&&typeof n.deduplicated===\\\"boolean\\\"}function Ze(e){if(!e||typeof e!==\\\"object\\\"||Array.isArray(e))return!1;let t=e;if(!t.recording||typeof t.recording!==\\\"object\\\"||Array.isArray(t.recording))return!1;let n=t.recording;return typeof n.id===\\\"string\\\"&&typeof n.workspaceId===\\\"string\\\"&&typeof n.mimeType===\\\"string\\\"&&typeof n.state===\\\"string\\\"&&typeof n.nextChunkNumber===\\\"number\\\"&&typeof n.chunkCount===\\\"number\\\"&&typeof n.totalBytes===\\\"number\\\"&&typeof n.totalDurationMilliseconds===\\\"number\\\"&&typeof n.segmentCount===\\\"number\\\"&&typeof n.completedSegmentCount===\\\"number\\\"&&(n.transcriptText===null||typeof n.transcriptText===\\\"string\\\")&&Array.isArray(n.languages)&&(n.errorCode===null||typeof n.errorCode===\\\"string\\\")&&typeof n.retryable===\\\"boolean\\\"&&typeof n.objectsCleaned===\\\"boolean\\\"&&typeof n.createdAt===\\\"string\\\"&&typeof n.updatedAt===\\\"string\\\"&&typeof n.expiresAt===\\\"string\\\"&&(t.retryAfterMilliseconds===void 0||typeof t.retryAfterMilliseconds===\\\"number\\\"&&Number.isInteger(t.retryAfterMilliseconds)&&t.retryAfterMilliseconds>0&&t.retryAfterMilliseconds<=60000)&&Array.isArray(t.segments)}function me(e){if(Ze(e))return e;throw new w(502,\\\"Invalid transcription recording response.\\\",{code:\\\"invalid_response\\\"})}function Ci(e){if(!e||typeof e!==\\\"object\\\"||Array.isArray(e))return!1;let t=e.recordings;return Array.isArray(t)&&t.length<=50&&t.every((n)=>Ze({recording:n,segments:[]}))}function Ai(e){switch(e.trim().toLowerCase().split(\\\";\\\")[0]??\\\"audio/webm\\\"){case\\\"audio/mp4\\\":case\\\"audio/m4a\\\":return\\\"audio.mp4\\\";case\\\"audio/ogg\\\":return\\\"audio.ogg\\\";case\\\"audio/mpeg\\\":case\\\"audio/mp3\\\":return\\\"audio.mp3\\\";case\\\"audio/wav\\\":case\\\"audio/x-wav\\\":return\\\"audio.wav\\\";case\\\"audio/webm\\\":default:return\\\"audio.webm\\\"}}var _n=16384;function Pi(e){let t=e.timeoutMs??0;if(t<=0)return{signal:e.signal,dispose:()=>{return}};let n=new AbortController,s=()=>n.abort(e.signal?.reason);if(e.signal?.aborted)s();else e.signal?.addEventListener(\\\"abort\\\",s,{once:!0});let i=setTimeout(()=>n.abort(new DOMException(\\\"Request timed out\\\",\\\"TimeoutError\\\")),t);return{signal:n.signal,dispose:()=>{clearTimeout(i),e.signal?.removeEventListener(\\\"abort\\\",s)}}}async function oe(e,t){if(!t)return await e;if(t.aborted)throw t.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\");return await new Promise((n,s)=>{let i=()=>{r(),s(t.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\"))},r=()=>t.removeEventListener(\\\"abort\\\",i);t.addEventListener(\\\"abort\\\",i,{once:!0}),e.then((o)=>{r(),n(o)},(o)=>{r(),s(o)})})}function xi(e,t){if(e===void 0||e===null)return;if(t.usageLimit?.limitMicros===e)return;throw new de(`The session ${t.id} was created, but the server did not confirm its usage limit; it may not support usage limits. Set the limit with setSessionUsageLimit before sending work, or treat the task as unlimited.`,{sessionId:t.id})}async function G(e,t){let n=await Ti(e),i=new((Ne(n))?Le:(ze(n))?We:w)(e.status,n,{correlationId:e.headers.get(Pe)??t.correlationId,mutation:ce(t.method)});return i.status>=400&&i.status<500&&(i.code===\\\"SESSION_TENANCY_NOT_ACTIVATED\\\"||i.code===\\\"OPENGENI_SETUP_REQUIRED\\\")?new Be(i):i}async function ye(e,t){if(Un(e.headers.get(\\\"content-type\\\")))return;throw await M(e,\\\"unexpected non-JSON API response\\\"),new w(502,\\\"\\\",{code:\\\"upstream_unavailable\\\",retryable:!0,correlationId:e.headers.get(Pe)??t.correlationId,outcomeUnknown:ce(t.method),displayMessage:\\\"The workspace is temporarily unavailable — retry.\\\"})}async function Ti(e){if(!Un(e.headers.get(\\\"content-type\\\")))return await M(e,\\\"discarding API error body\\\"),\\\"\\\";if(Number(e.headers.get(\\\"content-length\\\"))>_n)return await M(e,\\\"discarding API error body\\\"),\\\"\\\";try{return new TextDecoder().decode(await fe(e,_n,null))}catch{return\\\"\\\"}}function Un(e){return/^(application\\\\/json|[^;]+\\\\+json)\\\\s*(;|$)/i.test(e??\\\"\\\")}function ce(e){return e!==\\\"GET\\\"&&e!==\\\"HEAD\\\"&&e!==\\\"OPTIONS\\\"}function ae(e){return new w(0,\\\"\\\",{code:\\\"network_error\\\",retryable:!0,correlationId:e,outcomeUnknown:!0,mutation:!0,displayMessage:\\\"The request could not be confirmed — reconcile before retrying.\\\"})}function Oi(){let e=typeof window<\\\"u\\\"?window.isSecureContext:typeof globalThis.isSecureContext===\\\"boolean\\\"?globalThis.isSecureContext:void 0;if(e===void 0)return;if(!e)throw new be(\\\"insecure_context\\\");if(typeof globalThis.crypto>\\\"u\\\"||typeof globalThis.crypto.subtle?.digest!==\\\"function\\\")throw new be(\\\"web_crypto_unavailable\\\")}async function qi(e){let t=typeof e===\\\"string\\\"?new TextEncoder().encode(e):e instanceof Blob?new Uint8Array(await e.arrayBuffer()):new Uint8Array(e),n=await globalThis.crypto.subtle.digest(\\\"SHA-256\\\",t);return[...new Uint8Array(n)].map((s)=>s.toString(16).padStart(2,\\\"0\\\")).join(\\\"\\\")}async function Gn(e){let t=Uint8Array.from(e),n=await globalThis.crypto.subtle.digest(\\\"SHA-256\\\",t.buffer);return[...new Uint8Array(n)].map((s)=>s.toString(16).padStart(2,\\\"0\\\")).join(\\\"\\\")}function Ei(e,t){if(e.computerSessionId!==t.computerSessionId)return\\\"frame_session_mismatch\\\";if(e.targetId!==t.targetId)return\\\"frame_target_mismatch\\\";if(e.mediaType!==t.mediaType)return\\\"frame_media_mismatch\\\";if(e.sha256!==t.sha256)return\\\"frame_digest_mismatch\\\";return null}async function M(e,t){await e.body?.cancel(t).catch(()=>{return})}function Mn(e,t){if(!wn(t,e)&&!bn(t,e))throw new w(502,\\\"retained workspace artifact receipt is invalid\\\")}function Dn(e){if(!e||typeof e.url!==\\\"string\\\"||typeof e.expiresAt!==\\\"string\\\"||!Number.isFinite(Date.parse(e.expiresAt)))throw new w(502,\\\"retained artifact download URL is invalid\\\");let t;try{t=new URL(e.url)}catch{throw new w(502,\\\"retained artifact download URL is invalid\\\")}if(![\\\"http:\\\",\\\"https:\\\"].includes(t.protocol)||t.username||t.password)throw new w(502,\\\"retained artifact download URL is unsafe\\\")}function _i(e,t){if(!e||e.schemaVersion!==1||e.artifactId!==t||e.contentType!==\\\"video/mp4\\\"||e.acceptRanges!==\\\"bytes\\\"||!Number.isSafeInteger(e.sizeBytes)||e.sizeBytes<=0||e.sizeBytes>fn||!/^[0-9a-f]{64}$/.test(e.sha256))throw new w(502,\\\"generated-video playback source is invalid\\\");Dn({url:e.url,expiresAt:e.expiresAt})}function Gi(e){if(e===null)return null;if(!/^\\\\d+$/.test(e))throw new w(502,\\\"invalid retained artifact content-length\\\");let t=Number(e);if(!Number.isSafeInteger(t)||t>xe)throw new w(502,\\\"retained artifact response exceeds the SDK byte limit\\\");return t}async function fe(e,t,n){if(!e.body){if(n!==null&&n!==0)throw new w(502,\\\"retained artifact response length mismatch\\\");return new Uint8Array}let s=e.body.getReader(),i=[],r=0;try{while(!0){let{done:c,value:u}=await s.read();if(c)break;if(r+=u.byteLength,r>t)throw await s.cancel(\\\"retained artifact response exceeded the SDK byte limit\\\").catch(()=>{return}),new w(502,\\\"retained artifact response exceeds the SDK byte limit\\\");i.push(u)}}finally{s.releaseLock()}if(n!==null&&r!==n)throw new w(502,\\\"retained artifact response length mismatch\\\");let o=new Uint8Array(r),a=0;for(let c of i)o.set(c,a),a+=c.byteLength;return o}function T(e,t){return`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}`}function Y(e,t){return`${T(e,t)}/publication`}class he extends Error{code;status;details;constructor(e,t,n,s={}){super(t);this.code=e;this.status=n;this.details=s;this.name=\\\"OpenGeniSiteDataError\\\"}}var et=\\\"/v1/workspaces/site-host/published-artifacts/current\\\";function $n(e,t){let n=async(u,l={})=>{if(!await t())throw new he(\\\"site_data_unsupported\\\",\\\"This Site host does not provide Site Data\\\",0);let p=await e(`${et}${u}`,l),d=await p.text(),m=null;try{m=d?JSON.parse(d):null}catch{m=null}if(p.ok)return m;throw Ui(p.status,m)},s=(u)=>({method:\\\"POST\\\",headers:{\\\"content-type\\\":\\\"application/json\\\"},body:JSON.stringify(u)}),i=async(u)=>(await n(\\\"/data/write\\\",s({operations:u}))).results,r=async(u)=>{let[l]=await i([u]);if(!l||!(\\\"record\\\"in l))throw new he(\\\"request_failed\\\",\\\"Unexpected Site Data response\\\",200);return l.record},o=async(u,l,p)=>(await n(\\\"/data/query\\\",s({collection:u,limit:1,count:!0,...l?{where:l}:{},...p?{scope:p}:{}}))).count??0;return{data:{collection(u){return{name:u,list:async(p={})=>await n(\\\"/data/query\\\",s({collection:u,...p})),get:async(p)=>{try{return(await n(\\\"/data/get\\\",s({collection:u,..._e(p)}))).record}catch(d){if(d instanceof he&&d.code===\\\"not_found\\\")return null;throw d}},insert:async(p,d={})=>await r({op:\\\"insert\\\",collection:u,data:p,...d.key===void 0?{}:{key:d.key}}),put:async(p,d,m={})=>await r({op:\\\"put\\\",collection:u,key:p,data:d,...m}),patch:async(p,d,m={})=>await r({op:\\\"patch\\\",collection:u,..._e(p),data:d,...m}),delete:async(p,d={})=>{await i([{op:\\\"delete\\\",collection:u,..._e(p),...d}])},increment:async(p,d,m)=>await r({op:\\\"increment\\\",collection:u,..._e(p),field:d,...m===void 0?{}:{by:m}}),count:async(p,d={})=>await o(u,p,d.scope)}},batch:i,count:async(u,l)=>await o(u,l)},files:{upload:async(u,l={})=>{let p=u instanceof Blob?u:new Blob([u instanceof Uint8Array?u.slice():u],{type:l.contentType??\\\"application/octet-stream\\\"}),d=l.name??(typeof File<\\\"u\\\"&&u instanceof File?u.name:\\\"file\\\"),m=new URLSearchParams({name:d,scope:l.scope??\\\"shared\\\"});return await n(`/files?${m}`,{method:\\\"POST\\\",headers:{\\\"content-type\\\":l.contentType??(p.type||\\\"application/octet-stream\\\")},body:await p.arrayBuffer()})},list:async(u={})=>{let l=new URLSearchParams;if(u.limit!==void 0)l.set(\\\"limit\\\",String(u.limit));if(u.cursor)l.set(\\\"cursor\\\",u.cursor);let p=l.size?`?${l}`:\\\"\\\";return await n(`/files${p}`,{method:\\\"GET\\\"})},url:async(u)=>await n(`/files/${encodeURIComponent(u)}`,{method:\\\"GET\\\"}),delete:async(u)=>{await n(`/files/${encodeURIComponent(u)}`,{method:\\\"DELETE\\\"})}}}}function _e(e){if(typeof e===\\\"string\\\")return{key:e};if(\\\"id\\\"in e)return{id:e.id};return{key:e.key}}var Mi=new Set([\\\"validation\\\",\\\"conflict\\\",\\\"not_found\\\",\\\"forbidden\\\",\\\"not_available_for_viewer\\\",\\\"quota_exceeded\\\",\\\"rate_limited\\\"]);function Ui(e,t){let n=typeof t===\\\"object\\\"&&t!==null&&\\\"error\\\"in t?t.error:null,s=typeof n===\\\"object\\\"&&n!==null?n:{},i=typeof s.details===\\\"object\\\"&&s.details!==null?s.details:{},r=i.code,o=r&&Mi.has(r)?r:e===404?\\\"not_found\\\":e===403?\\\"forbidden\\\":e===413?\\\"quota_exceeded\\\":e===429?\\\"rate_limited\\\":\\\"request_failed\\\",a=typeof s.message===\\\"string\\\"&&s.message?s.message:`Site Data request failed with HTTP ${e}`;return new he(o,a,e,i)}class Re extends Error{code;status;details;constructor(e,t,n,s={}){super(t);this.code=e;this.status=n;this.details=s;this.name=\\\"OpenGeniSiteSqlError\\\"}}var Di=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/u,$i=new Set([\\\"validation\\\",\\\"not_found\\\",\\\"forbidden\\\",\\\"not_available_for_viewer\\\",\\\"conflict\\\",\\\"quota_exceeded\\\",\\\"rate_limited\\\",\\\"sql_error\\\",\\\"unavailable\\\",\\\"disabled\\\"]);function Bn(e,t){return{async run(n,s={}){if(!Di.test(n))throw new Re(\\\"validation\\\",\\\"Invalid query name\\\",0);if(Object.keys(s).some((a)=>a===\\\"viewer\\\"||a.startsWith(\\\"viewer_\\\")))throw new Re(\\\"validation\\\",\\\"viewer parameters are bound by the host, not the Site\\\",0);if(!await t())throw new Re(\\\"site_sql_unsupported\\\",\\\"This Site host does not provide Site SQL\\\",0);let i=await e(`${et}/sql/queries/${encodeURIComponent(n)}`,{method:\\\"POST\\\",headers:{\\\"content-type\\\":\\\"application/json\\\"},body:JSON.stringify({params:s})}),r=await i.text(),o=null;try{o=r?JSON.parse(r):null}catch{o=null}if(i.ok)return o;throw Bi(i.status,o)}}}function Bi(e,t){let n=typeof t===\\\"object\\\"&&t!==null&&\\\"error\\\"in t?t.error:null,s=typeof n===\\\"object\\\"&&n!==null?n:{},i=typeof s.details===\\\"object\\\"&&s.details!==null?s.details:{},r=typeof i.code===\\\"string\\\"?i.code:void 0,o=r&&$i.has(r)?r:e===404?\\\"not_found\\\":e===403?\\\"forbidden\\\":e===413?\\\"quota_exceeded\\\":e===429?\\\"rate_limited\\\":\\\"request_failed\\\",a=typeof s.message===\\\"string\\\"&&s.message?s.message:`Site SQL request failed with HTTP ${e}`;return new Re(o,a,e,i)}var Ln=\\\"The model returned no final reply after a reply reminder. Completed work is preserved; the goal and later updates are unaffected.\\\";function Wn(e){return e!==null&&typeof e===\\\"object\\\"&&!Array.isArray(e)&&e.emptyFinalReply===!0}class tt extends Error{code;event;constructor(e,t,n=null){super(t);this.name=\\\"OpenGeniChatError\\\",this.code=e,this.event=n}}function W(){return{chunks:[],terminal:null}}class Me{workspaceId;sessionId;events=[];turnId;pending=null;failure=null;emptyFinalReply=!1;segments=[];openTools=new Map;constructor(e,t,n){this.workspaceId=e;this.sessionId=t;this.turnId=n}get text(){return this.segments.filter((e)=>!e.commentary).map((e)=>e.text).filter((e)=>e.length>0).join(`\\n\\n`)}push(e){let t=typeof e.turnId===\\\"string\\\"?e.turnId:null;if(this.turnId&&t&&t!==this.turnId)return{chunks:[],terminal:null};if(!this.turnId&&t&&Li(e.type))this.turnId=t;this.events.push(e);let n=ne(e.payload);switch(e.type){case\\\"agent.message.delta\\\":{let s=q(n.text);if(!s)return W();let i=q(n.messageId)||null;if(i)return this.messageDelta(i,s,Ge(n));let r=this.segments.at(-1);if(Ge(n)){if(r?.open&&r.commentary)r.text+=s;else this.closeSegments(),this.segments.push({text:s,open:!0,commentary:!0,messageId:null});return W()}if(r?.open&&!r.commentary)r.text+=s;else return this.closeSegments(),{chunks:[this.startSegment(s,!0,null)],terminal:null};return{chunks:[{type:\\\"text\\\",text:s}],terminal:null}}case\\\"agent.message.completed\\\":{let s=q(n.text)??\\\"\\\",i=q(n.messageId)||null;if(i)return this.messageCompleted(i,s,Ge(n));let r=this.segments.at(-1);if(Ge(n)){if(r?.commentary&&(r.open||s.startsWith(r.text))){if(r.open=!1,s)r.text=s;return W()}if(!(r&&!r.commentary&&r.open&&s.startsWith(r.text))){if(s)this.closeSegments(),this.segments.push({text:s,open:!1,commentary:!0,messageId:null});return W()}}let o=r?.commentary?void 0:r;if(!o||!o.open&&o.text&&!s.startsWith(o.text)){if(!s)return W();if(n.phase===void 0&&this.latestAnswer()?.text===s)return W();return this.closeSegments(),{chunks:[this.startSegment(s,!1,null)],terminal:null}}return o.open=!1,{chunks:this.extendAnswer(o,s),terminal:null}}case\\\"agent.toolCall.created\\\":{this.closeSegments();let s=q(n.name)??\\\"tool\\\",i=q(n.id);if(i)this.openTools.set(i,s);return{chunks:[{type:\\\"tool\\\",name:s,status:\\\"started\\\",...i?{callId:i}:{},...\\\"arguments\\\"in n?{input:n.arguments}:{}}],terminal:null}}case\\\"agent.toolCall.output\\\":{let s=q(n.id),i=(s?this.openTools.get(s):void 0)??\\\"tool\\\";if(s)this.openTools.delete(s);return{chunks:[{type:\\\"tool\\\",name:i,status:Ni(n)?\\\"failed\\\":\\\"completed\\\",...s?{callId:s}:{}}],terminal:null}}case\\\"session.requiresAction\\\":{let s=Wi(n);if(!s)return{chunks:[],terminal:null};return this.pending=s,{chunks:[...this.settleSegments(),{type:\\\"pending\\\",pending:s}],terminal:\\\"pending\\\"}}case\\\"session.humanInput.requested\\\":{let s=zi(n);if(!s)return{chunks:[],terminal:null};return this.pending=s,{chunks:[...this.settleSegments(),{type:\\\"pending\\\",pending:s}],terminal:\\\"pending\\\"}}case\\\"turn.completed\\\":return this.emptyFinalReply=Wn(n),{chunks:this.settleSegments(),terminal:\\\"completed\\\"};case\\\"turn.failed\\\":return this.failure=e,{chunks:this.settleSegments(),terminal:\\\"failed\\\"};case\\\"turn.cancelled\\\":return{chunks:this.settleSegments(),terminal:\\\"cancelled\\\"};default:return{chunks:[],terminal:null}}}reply(e){let t=this.text;return{text:t,sessionId:this.sessionId,workspaceId:this.workspaceId,turnId:this.turnId,status:e===\\\"pending\\\"?\\\"pending\\\":e===\\\"cancelled\\\"?\\\"cancelled\\\":\\\"completed\\\",pending:this.pending,...this.emptyFinalReply?{emptyFinalReply:!0,notice:Ln}:{},events:[...this.events],toString:()=>t}}failureError(){let e=ne(this.failure?.payload),t=q(e.code)??\\\"turn_failed\\\",n=q(e.error)??q(e.message)??\\\"The turn failed.\\\";return new tt(t,n,this.failure)}messageDelta(e,t,n){let s=this.segmentOf(e);if(s?.open)return s.text+=t,s.commentary?W():{chunks:[{type:\\\"text\\\",text:t}],terminal:null};if(this.closeSegments(),n)return this.segments.push({text:t,open:!0,commentary:!0,messageId:e}),W();return{chunks:[this.startSegment(t,!0,e)],terminal:null}}messageCompleted(e,t,n){let s=this.segmentOf(e)??this.unidentifiedStreamingSegment(t);if(s){if(s.messageId=e,s.open=!1,s.commentary){if(t)s.text=t;return W()}return{chunks:this.extendAnswer(s,t),terminal:null}}if(!t)return W();if(n)return this.segments.push({text:t,open:!1,commentary:!0,messageId:e}),W();return{chunks:[this.startSegment(t,!1,e)],terminal:null}}segmentOf(e){return this.findLastSegment((t)=>t.messageId===e)}unidentifiedStreamingSegment(e){let t=this.segments.at(-1);return t?.open&&t.messageId===null&&e.startsWith(t.text)?t:void 0}latestAnswer(){return this.findLastSegment((e)=>!e.commentary)}findLastSegment(e){for(let t=this.segments.length-1;t>=0;t-=1){let n=this.segments[t];if(e(n))return n}return}extendAnswer(e,t){if(t.length<=e.text.length||!t.startsWith(e.text))return[];if(e!==this.latestAnswer())return[];let n=t.slice(e.text.length);return e.text=t,[{type:\\\"text\\\",text:n}]}closeSegments(){for(let e of this.segments)e.open=!1}settleSegments(){if(this.closeSegments(),this.emptyFinalReply)return[];if(this.segments.some((t)=>!t.commentary))return[];let e=[...this.segments].reverse().find((t)=>t.commentary&&t.text);if(!e)return[];return e.commentary=!1,[{type:\\\"text\\\",text:e.text}]}startSegment(e,t,n){let s=this.segments.some((i)=>!i.commentary)?`\\n\\n`:\\\"\\\";return this.segments.push({text:e,open:t,commentary:!1,messageId:n}),{type:\\\"text\\\",text:s+e}}}function Ge(e){return e.phase===\\\"commentary\\\"}function Li(e){return e.startsWith(\\\"turn.\\\")||e.startsWith(\\\"agent.\\\")||e===\\\"user.message\\\"}function Wi(e){let n=(Array.isArray(e.approvals)?e.approvals:[])[0];if(!n)return null;let s=ne(n),i=ne(s.rawItem),r=q(i.callId)??q(i.id)??q(s.id)??q(s.callId);if(!r)return null;return{kind:\\\"approval\\\",requestId:r,name:q(s.name)??q(s.toolName)??q(i.name)??null,payload:n}}function zi(e){let t=ne(e.request),n=q(t.id);if(!n||!Array.isArray(t.questions))return null;return{kind:\\\"human_input\\\",requestId:n,name:null,payload:e.request}}function ne(e){return e&&typeof e===\\\"object\\\"&&!Array.isArray(e)?e:{}}function q(e){return typeof e===\\\"string\\\"?e:void 0}function Ni(e){if(e.error===!0||e.failed===!0)return!0;let t=e.output;return!!t&&typeof t===\\\"object\\\"&&t.isError===!0}function Fn(e,t){let n=async(s,i={})=>{i.signal?.throwIfAborted();let r=new AbortController,o=()=>r.abort(i.signal?.reason);i.signal?.addEventListener(\\\"abort\\\",o,{once:!0});let a=i.after??0,c=0,u=\\\"\\\",l=i.turnId||a===0?new Me(t,s,i.turnId??null):null,p=[],d=null,m={event:null},y,R,v=()=>{if(R?.abort(),y)Promise.resolve(y.return(void 0)).catch(()=>{return});y=void 0,R=void 0},b=()=>R?.abort(r.signal.reason);r.signal.addEventListener(\\\"abort\\\",b);let C=(k)=>{for(let I of k)if(I.type===\\\"text\\\")r.signal.throwIfAborted(),u+=I.text,i.onText?.(I.text)},P=(k)=>{l=new Me(t,s,k);for(let I of p){let O=l.push(I);if(O.terminal&&O.terminal!==\\\"pending\\\")d=O.terminal}p=[]},S=(k)=>{let I=Nn(k);if(I<=c)return;if(c=I,!l){if(I<=a){p.push(k);return}if(!Jn(k)&&!Ue(k))return;P(k.turnId??zn(p))}let O=l;if((!k.turnId||!O.turnId||k.turnId===O.turnId)&&Ue(k)){if(!O.turnId&&k.turnId)O.turnId=k.turnId;if(k.type!==\\\"session.status.changed\\\")m.event=k;if(I>a)return}let X=O.push(k);if(I>a)C(X.chunks);if(X.terminal&&X.terminal!==\\\"pending\\\")d=X.terminal},h=(k)=>{if(r.signal.throwIfAborted(),k===\\\"failed\\\")throw l.failureError();return{sessionId:s,turnId:l?.turnId??null,text:u,status:k===\\\"pending\\\"?\\\"pending\\\":k===\\\"cancelled\\\"?\\\"cancelled\\\":\\\"completed\\\",after:Math.max(a,c)}},f=()=>nt(()=>e.getSession(t,s,{fresh:!0,signal:r.signal}),r.signal),x=async(k)=>{while(c<k){let I=c,O=await nt(()=>e.listEventPage(t,s,{after:c,before:k+1,direction:\\\"after\\\",limit:200,mode:\\\"forensic\\\",payloadMode:\\\"full\\\"}),r.signal);for(let J of O.events)if(S(J),d&&c>a)return;if(c=Math.max(c,O.nextAfter??O.coveredSequence?.last??0),c<=I)throw Error(\\\"The Site AI event replay did not reach the session cursor.\\\")}},A=(k)=>k.status===\\\"requires_action\\\"&&(!k.activeTurnId||!l?.turnId||k.activeTurnId===l.turnId);try{let k=await f();if(await x(Math.min(a,k.lastSequence)),d)return h(d);for(;;){if(await x(k.lastSequence),d)return h(d);if(A(k)){let I=await f();if(I.lastSequence>c){k=I;continue}if(A(I)){if(!l)P(I.activeTurnId??zn(p));else if(!l.turnId)l.turnId=I.activeTurnId??null;if(m.event&&Nn(m.event)>a)C(l.push(m.event).chunks);return h(\\\"pending\\\")}k=I}R=new AbortController,y=e.streamEvents(t,s,{after:Math.max(a,c),signal:R.signal});for(;;){let I=await nt(()=>y.next(),r.signal);if(I.done)throw Error(\\\"The Site AI event stream ended before the turn settled.\\\");if(S(I.value),d)return h(d);if(Ue(I.value)&&(!I.value.turnId||I.value.turnId===l?.turnId)){v(),k=await f();break}}}}finally{i.signal?.removeEventListener(\\\"abort\\\",o),r.abort(),v(),r.signal.removeEventListener(\\\"abort\\\",b)}};return{async run(s,i={}){i.signal?.throwIfAborted();let r=await e.createSession(t,{initialMessage:s.initialMessage,idempotencyKey:s.idempotencyKey??crypto.randomUUID(),...s.model===void 0?{}:{model:s.model},...s.reasoningEffort===void 0?{}:{reasoningEffort:s.reasoningEffort},...s.latencyMode===void 0?{}:{latencyMode:s.latencyMode}});return i.onSession?.(r.id),await n(r.id,i)},result:n}}function Ue(e){return e.type===\\\"session.requiresAction\\\"||e.type===\\\"session.humanInput.requested\\\"||e.type===\\\"session.status.changed\\\"&&ne(e.payload).status===\\\"requires_action\\\"}function Jn(e){return e.type.startsWith(\\\"turn.\\\")||e.type.startsWith(\\\"agent.\\\")||e.type===\\\"user.message\\\"}function zn(e){for(let t=e.length-1;t>=0;t-=1){let n=e[t];if(n.turnId&&(Jn(n)||Ue(n)))return n.turnId}return null}function Nn(e){return Math.max(e.sequence,e.coveredThrough??0,Pt(e)??0)}async function nt(e,t){t.throwIfAborted();let n=()=>{},s=new Promise((i,r)=>{n=()=>r(t.reason),t.addEventListener(\\\"abort\\\",n,{once:!0})});try{let i=await Promise.race([e(),s]);return t.throwIfAborted(),i}finally{t.removeEventListener(\\\"abort\\\",n)}}var ue=2,Fi=\\\"opengeni.site.connect\\\",Kn=\\\"opengeni.site.ready\\\",Ji=\\\"opengeni.site.request\\\",Vi=\\\"opengeni.site.response\\\",Hi=\\\"opengeni.site.cancel\\\",jn=\\\"__opengeniSiteBridgeBootstrapV2\\\",Ki=\\\"/__opengeni/site-tools\\\",ji=\\\"viewer\\\",Yi=\\\"auth.signIn\\\";class E extends Error{code;retryable;outcomeUnknown;constructor(e,t,n=!1,s=!1){super(t);this.code=e;this.retryable=n;this.outcomeUnknown=s;this.name=\\\"OpenGeniSiteBridgeError\\\"}}function Yn(e={}){let t=Xi(e)?new Xn(e):new Qn(e),n=$n((a,c)=>t.fetch(`https://site.opengeni.invalid${a}`,c),()=>t.siteDataSupported()),s=Bn((a,c)=>t.fetch(`https://site.opengeni.invalid${a}`,c),()=>t.siteDataSupported()),i=null,r=null,o=new Qe({baseUrl:\\\"https://site.opengeni.invalid\\\",toolGatewayMode:e.toolGatewayMode??\\\"target\\\",fetch:(a,c)=>t.fetch(a,c)});return{client:o,ai:Fn(o,pe),workspaceId:pe,tools:new ie(t).forWorkspace(\\\"site-host\\\"),data:n.data,files:n.files,sql:s,get viewer(){if(!i){let a=t.viewer();i=a,a.catch(()=>{if(i===a)i=null})}return i},get capabilities(){return r??=or(t),r},auth:{signIn:()=>t.signIn()},close:()=>t.close()}}class Xn{toolGatewayMode;fetchImpl;basePath;constructor(e){this.toolGatewayMode=e.toolGatewayMode??\\\"target\\\",this.fetchImpl=e.fetch??globalThis.fetch.bind(globalThis);let t=e.localCodemodePath;this.basePath=(typeof t===\\\"string\\\"?t:Ki).replace(/\\\\/+$/u,\\\"\\\")}close(){}async siteDataSupported(){return!1}async viewer(){return null}async signIn(){return{started:!1}}async fetch(e,t){let n=new Request(e,t),s=new URL(n.url),i=`${s.pathname}${s.search}`;return le(i,pe,n.method),this.fetchImpl(`${this.basePath}/sdk${i}`,{method:n.method,headers:n.headers,signal:n.signal,...n.body?{body:await n.text()}:{}})}async requestJson(e,t,n,s,i={}){let r=Qi(e,t),o=await this.fetchImpl(`${this.basePath}${r}`,{method:e,...i.signal?{signal:i.signal}:{},...n===void 0?{}:{headers:{\\\"content-type\\\":\\\"application/json\\\"},body:JSON.stringify(n)}}),a=await o.json();if(o.ok)return a;let c=D(a)&&D(a.error)?a.error:{};throw new E(typeof c.code===\\\"string\\\"?c.code:\\\"local_codemode_error\\\",typeof c.message===\\\"string\\\"?c.message:`Local Site tool request failed with HTTP ${o.status}`,c.retryable===!0,c.outcomeUnknown===!0)}}function Xi(e){if(e.localCodemodePath===!1||e.bootstrapPort)return!1;if(typeof e.localCodemodePath===\\\"string\\\")return!0;let t=e.siteWindow??globalThis.window;return Boolean(t&&t.parent===t)}function Qi(e,t){if(e===\\\"GET\\\"&&t.endsWith(\\\"/tools/catalog\\\"))return\\\"/catalog\\\";if(e===\\\"GET\\\"&&t.endsWith(\\\"/tools/declarations\\\"))return\\\"/declarations\\\";if(e===\\\"POST\\\"&&t.endsWith(\\\"/tools/calls\\\"))return\\\"/calls\\\";if(e===\\\"POST\\\"&&t.endsWith(\\\"/tools/resolve\\\"))return\\\"/resolve\\\";if(e===\\\"POST\\\"&&t.endsWith(\\\"/tools/invoke\\\"))return\\\"/invoke\\\";throw new E(\\\"unsupported_request\\\",\\\"Unsupported Site tool request\\\")}function Zi(e){return{...e.operationId===void 0?{}:{operationId:e.operationId},catalogDigest:e.catalogDigest,identity:e.identity,arguments:e.arguments}}function er(e){return{target:e.target,operationId:e.operationId,arguments:e.arguments,...e.expectedDefinitionDigest===void 0?{}:{expectedDefinitionDigest:e.expectedDefinitionDigest}}}class Qn{toolGatewayMode;targetTools=!1;siteData=!1;viewerSupported=!1;options;bootstrap;port=null;connecting=null;closed=!1;constructor(e){this.toolGatewayMode=e.toolGatewayMode??\\\"target\\\",this.options=e,this.bootstrap=tr(e)}async fetch(e,t){return mt(await this.connect(),e,t)}async siteDataSupported(){return await this.connect(),this.siteData}async viewer(){if(await this.connect(),!this.viewerSupported)return null;let e=await this.request({method:ji},{});if(!cr(e))throw new E(\\\"invalid_viewer\\\",\\\"The Site host returned an invalid viewer\\\");return e}async signIn(){if(await this.connect(),!this.viewerSupported)return{started:!1};let e=await this.request({method:Yi},{});return{started:D(e)&&e.started===!0}}async requestJson(e,t,n,s,i={}){if(e===\\\"POST\\\"&&(t.endsWith(\\\"/tools/resolve\\\")||t.endsWith(\\\"/tools/invoke\\\"))){if(await this.connect(),!this.targetTools)throw new E(\\\"target_tools_unsupported\\\",\\\"Upgrade the Site host to use targeted tools\\\");if(!D(n))throw TypeError(\\\"Site target payload is required\\\");let r=n;return await this.request(t.endsWith(\\\"/tools/resolve\\\")?{method:\\\"resolve\\\",payload:{target:r.target}}:{method:\\\"invoke\\\",payload:er(r)},i)}if(e===\\\"GET\\\"&&t.endsWith(\\\"/tools/catalog\\\"))return await this.request({method:\\\"catalog\\\"},i);if(e===\\\"GET\\\"&&t.endsWith(\\\"/tools/declarations\\\"))return await this.request({method:\\\"declarations\\\"},i);if(e===\\\"POST\\\"&&t.endsWith(\\\"/tools/calls\\\")){if(!D(n))throw TypeError(\\\"Site tool call payload is required\\\");return await this.request({method:\\\"call\\\",payload:Zi(n)},i)}throw new E(\\\"unsupported_request\\\",\\\"Unsupported Site bridge request\\\")}close(){if(this.closed)return;this.closed=!0,this.bootstrap.close(),this.port?.close(),this.port=null}async request(e,t){let n=await this.connect(),s=crypto.randomUUID(),i=Hn(t.timeoutMs??this.options.requestTimeoutMs??120000,\\\"requestTimeoutMs\\\");return await new Promise((r,o)=>{let a=setTimeout(()=>{l(),Vn(n,s),o(e.method===\\\"call\\\"||e.method===\\\"invoke\\\"?new E(\\\"timeout\\\",\\\"Site tool request timed out after execution may have started\\\",!1,!0):new E(\\\"timeout\\\",\\\"Site tool request timed out\\\",!0))},i),c=()=>{l(),Vn(n,s),o(t.signal?.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\"))},u=(p)=>{let d=p.data;if(!D(d)||d.type!==Vi||d.version!==ue||d.requestId!==s||typeof d.ok!==\\\"boolean\\\")return;if(l(),d.ok){r(d.value);return}let m=D(d.error)?d.error:{};o(new E(typeof m.code===\\\"string\\\"?m.code:\\\"bridge_error\\\",typeof m.message===\\\"string\\\"?m.message:\\\"Site tool request failed\\\",m.retryable===!0,m.outcomeUnknown===!0))},l=()=>{clearTimeout(a),t.signal?.removeEventListener(\\\"abort\\\",c),n.removeEventListener(\\\"message\\\",u)};if(t.signal?.aborted){c();return}t.signal?.addEventListener(\\\"abort\\\",c,{once:!0}),n.addEventListener(\\\"message\\\",u),n.postMessage({type:Ji,version:ue,requestId:s,...e})})}async connect(){if(this.closed)throw new E(\\\"closed\\\",\\\"Site bridge is closed\\\");if(this.port)return this.port;if(this.connecting)return await this.connecting;let e=(this.options.createMessageChannel??(()=>new MessageChannel))(),t=Hn(this.options.connectTimeoutMs??1e4,\\\"connectTimeoutMs\\\");return this.connecting=new Promise((n,s)=>{let i=!0,r=setTimeout(()=>{a(),e.port1.close(),s(new E(\\\"host_timeout\\\",\\\"The Site host did not respond\\\"))},t),o=(c)=>{let u=c.data;if(!D(u)||u.type!==Kn||u.version!==ue)return;a(),this.targetTools=u.targetTools===1,this.siteData=u.siteData===1,this.viewerSupported=u.viewer===1,this.port=e.port1,n(e.port1)},a=()=>{i=!1,clearTimeout(r),e.port1.removeEventListener(\\\"message\\\",o)};e.port1.addEventListener(\\\"message\\\",o),e.port1.start(),this.bootstrap.port().then((c)=>{if(!i)return;if(this.closed)throw new E(\\\"closed\\\",\\\"Site bridge is closed\\\");c.postMessage({type:Fi,version:ue},[e.port2])}).catch((c)=>{a(),e.port1.close(),s(c)})}).finally(()=>{this.connecting=null}),await this.connecting}}function tr(e){if(e.bootstrapPort)return{port:async()=>e.bootstrapPort,close:()=>e.bootstrapPort?.close()};let t=e.siteWindow??globalThis.window,n=e.parentWindow??t?.parent;if(!t||!n||n===t)return{port:async()=>{throw new E(\\\"host_unavailable\\\",\\\"The Site client must run inside a hosted iframe\\\")},close:()=>{return}};let s=nr(t);if(s)return{port:async()=>s,close:()=>{return}};let i=null,r=null,o=(l)=>{if(l.source!==n||!ir(l.data)||l.ports.length!==1)return;c(),i=l.ports[0],i.start(),sr(t,i),a?.(i)},a=null,c=()=>t.removeEventListener(\\\"message\\\",o),u=new Promise((l,p)=>{a=l,r=p,t.addEventListener(\\\"message\\\",o)});return u.catch(()=>{return}),{port:async()=>await u,close:()=>{c(),r?.(new E(\\\"closed\\\",\\\"Site bridge is closed\\\")),a=null,r=null}}}function nr(e){let t=e[jn];if(!D(t))return null;let n=t.port;return n&&typeof n.postMessage===\\\"function\\\"&&typeof n.addEventListener===\\\"function\\\"&&typeof n.start===\\\"function\\\"?n:null}function sr(e,t){try{Object.defineProperty(e,jn,{configurable:!0,value:{port:t}})}catch{}}function ir(e){return D(e)&&e.type===Kn&&e.version===ue}var rr=[\\\"member\\\",\\\"invited\\\",\\\"user\\\",\\\"guest\\\"];async function or(e){try{if(!await e.siteDataSupported())return null;let t=await e.fetch(\\\"https://site.opengeni.invalid/v1/workspaces/site-host/site/config\\\",{method:\\\"GET\\\",headers:{accept:\\\"application/json\\\"}});if(!t.ok)return await t.body?.cancel(),null;let n=(await t.json())?.capabilities;return ar(n)?n:null}catch{return null}}function ar(e){return D(e)&&typeof e.agent===\\\"boolean\\\"&&typeof e.workspaceTools===\\\"boolean\\\"&&(e.siteData===\\\"viewer\\\"||e.siteData===\\\"guest\\\")&&Array.isArray(e.sqlQueryAudiences)&&e.sqlQueryAudiences.every((t)=>t===\\\"everyone\\\"||t===\\\"signed_in\\\")&&(e.viewAs===null||e.viewAs===\\\"invited\\\"||e.viewAs===\\\"public\\\")}function cr(e){return D(e)&&rr.includes(String(e.kind))&&typeof e.id===\\\"string\\\"&&e.id.length>0&&(e.name===null||typeof e.name===\\\"string\\\")&&(e.email===null||typeof e.email===\\\"string\\\")&&typeof e.signedIn===\\\"boolean\\\"}function Vn(e,t){e.postMessage({type:Hi,version:ue,requestId:t})}function Hn(e,t){if(!Number.isFinite(e)||e<=0)throw RangeError(`${t} must be positive`);return e}function D(e){return typeof e===\\\"object\\\"&&e!==null&&!Array.isArray(e)}Object.defineProperty(globalThis,\\\"createOpenGeniSiteClient\\\",{configurable:!0,value:Yn});})();\\n\";\n","import { SITE_BROWSER_RUNTIME } from \"./site-browser-runtime.gen\";\n\nexport const SITE_CLIENT_SCRIPT_PATH = \"/__opengeni/site-tools/client.js\";\nexport { SITE_BROWSER_RUNTIME };\n\n/** Resolve only the optional client tag; ordinary bundled Sites remain unchanged. */\nexport function resolveSiteClientScript(html: string): string {\n // Consume whole scripts/comments so examples inside JS or comments stay literal.\n return html.replace(/<!--[\\s\\S]*?-->|<script\\b[^>]*>[\\s\\S]*?<\\/script\\s*>/gi, (tag) => {\n if (\n !/^<script\\s+src\\s*=\\s*([\"'])\\/__opengeni\\/site-tools\\/client\\.js\\1\\s*>\\s*<\\/script\\s*>$/i.test(\n tag,\n )\n )\n return tag;\n return \"<script>\" + SITE_BROWSER_RUNTIME.replace(/<\\/script/gi, \"<\\\\/script\") + \"</script>\";\n });\n}\n"],"mappings":";AACO,IAAM,uBAAuB;;;ACC7B,IAAM,0BAA0B;AAIhC,SAAS,wBAAwB,MAAsB;AAE5D,SAAO,KAAK,QAAQ,0DAA0D,CAAC,QAAQ;AACrF,QACE,CAAC,0FAA0F;AAAA,MACzF;AAAA,IACF;AAEA,aAAO;AACT,WAAO,aAAa,qBAAqB,QAAQ,eAAe,YAAY,IAAI;AAAA,EAClF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/site-browser-runtime.gen.ts","../src/site-document.ts"],"sourcesContent":["// Generated by scripts/generate-site-browser-runtime.ts. Do not edit.\nexport const SITE_BROWSER_RUNTIME = \"(()=>{var Z=(e,t,n)=>()=>{if(e)try{t=e(e=0)}catch(s){n=[s]}if(n)throw n[0];return t};function Le(e){return e!==null&&typeof e===\\\"object\\\"&&!Array.isArray(e)?e:null}function dt(e,t=Number.MAX_SAFE_INTEGER){return typeof e===\\\"number\\\"&&Number.isSafeInteger(e)&&e>=0&&e<=t}function Ss(e){let t=e.slice(0,2048).replace(/[\\\\u0000-\\\\u001f\\\\u007f]+/g,\\\" \\\").trim(),n=new TextEncoder().encode(t),s=Math.min(n.length,1024);while(s>0&&s<n.length&&(n[s]&192)===128)s-=1;return new TextDecoder().decode(n.slice(0,s)).trim()}function gt(e){let t=Le(e);if(!t)return null;let n=Le(t.sessionUsageLimit)??t;if(n.code!==\\\"session_usage_limit_reached\\\")return null;let s=Le(n.details)??n;if(s.basis!==\\\"model_api_equivalent_v1\\\"||typeof s.rootSessionId!==\\\"string\\\"||!bs.test(s.rootSessionId)||!dt(s.limitMicros,10000000000000)||!dt(s.usedMicros))return null;let i={code:\\\"session_usage_limit_reached\\\",basis:\\\"model_api_equivalent_v1\\\",rootSessionId:s.rootSessionId.toLowerCase(),limitMicros:s.limitMicros,usedMicros:s.usedMicros,message:\\\"\\\"},r=typeof n.message===\\\"string\\\"?Ss(n.message):\\\"\\\";return{...i,message:r||ws(i)}}function pt(e){if(e>0&&e<1e4)return\\\"<$0.01\\\";return`$${(e/1e6).toLocaleString(\\\"en-US\\\",{minimumFractionDigits:2,maximumFractionDigits:2})}`}function ws(e){return`This task's usage limit is reached (${pt(e.usedMicros)} of ${pt(e.limitMicros)} API-equivalent model usage). A person can raise or remove the limit to continue.`}var bs;var mt=Z(()=>{bs=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i});function yt(e){if(e.status!==400&&e.status!==422)return!1;let t;try{t=JSON.parse(e.body)}catch{return!1}if(!t||typeof t!==\\\"object\\\")return!1;let n=t,s=n.error&&typeof n.error===\\\"object\\\"?n.error:n,i=typeof s.message===\\\"string\\\"?s.message:\\\"\\\",r=/^Invalid session create request: (.+) failed schema validation$/.exec(i);if(s.code===\\\"INVALID_SESSION_CREATE_REQUEST\\\"&&r?.[1]?.split(/,\\\\s*/).includes(\\\"startMode\\\"))return!0;let o=s.details&&typeof s.details===\\\"object\\\"?s.details:null;return(Array.isArray(o?.issues)?o.issues:[]).some((c)=>{if(!c||typeof c!==\\\"object\\\")return!1;let u=c.path;return u===\\\"startMode\\\"||Array.isArray(u)&&u.length===1&&u[0]===\\\"startMode\\\"})}function ft(e){return new pe(\\\"The server did not confirm the requested usage limit; it may not support usage limits. Read the limit again before relying on it.\\\",{sessionId:e})}function Je(e){try{let t=JSON.parse(e);if(!t||typeof t!==\\\"object\\\"||Array.isArray(t))return null;let n=t;return gt(n.error&&typeof n.error===\\\"object\\\"&&!Array.isArray(n.error)?n.error:n)}catch{return null}}function Ve(e){try{let t=JSON.parse(e);if(!t||typeof t!==\\\"object\\\"||Array.isArray(t))return null;let n=t,s=n.error&&typeof n.error===\\\"object\\\"&&!Array.isArray(n.error)?n.error:n;if(s.code!==\\\"allowance_exhausted\\\")return null;let i=s.details&&typeof s.details===\\\"object\\\"&&!Array.isArray(s.details)?s.details:s;if(i.scope!==\\\"workspace\\\"&&i.scope!==\\\"member\\\")return null;if(i.resetsAt!==null&&typeof i.resetsAt!==\\\"string\\\")return null;return{scope:i.scope,resetsAt:i.resetsAt,...typeof i.subjectId===\\\"string\\\"?{subjectId:i.subjectId}:{}}}catch{return null}}function vs(e){if(!e)return null;try{let t=JSON.parse(e);if(!t||typeof t!==\\\"object\\\"||Array.isArray(t))return null;let n=t,s=n.error&&typeof n.error===\\\"object\\\"&&!Array.isArray(n.error)?n.error:n,i=We(s.code),r=We(s.message),o=ht(s.requestId),a=typeof s.retryable===\\\"boolean\\\"?s.retryable:void 0,c=typeof s.outcomeUnknown===\\\"boolean\\\"?s.outcomeUnknown:void 0,u=ks(s.details);if(!i&&!r&&!o&&a===void 0&&c===void 0&&!u)return null;return{code:i,message:r,requestId:o,retryable:a,outcomeUnknown:c,details:u}}catch{return null}}function ks(e){if(!e||typeof e!==\\\"object\\\"||Array.isArray(e))return;let t=Object.entries(e).slice(0,16),n={};for(let[s,i]of t){if(!/^[a-zA-Z][\\\\w.-]{0,63}$/.test(s))continue;if(typeof i===\\\"string\\\"){let r=We(i);if(r!==void 0)n[s]=r}else if(typeof i===\\\"number\\\"||typeof i===\\\"boolean\\\"||i===null)n[s]=i;else if(s===\\\"action\\\"&&typeof i===\\\"object\\\"&&!Array.isArray(i)&&i.type===\\\"upgrade\\\"&&i.href===\\\"/billing\\\")n.action={type:\\\"upgrade\\\",href:\\\"/billing\\\"}}return Object.keys(n).length>0?n:void 0}function We(e){if(typeof e!==\\\"string\\\")return;let t=new TextEncoder().encode(e);return t.byteLength<=512?e:new TextDecoder().decode(t.slice(0,512))}function Is(e){return e===408||e===409||e===425||e===429||e>=500}function ht(e){if(typeof e!==\\\"string\\\"||e.length>128||!/^[\\\\w.:-]+$/.test(e))return;return e}function K(e){return e instanceof DOMException&&e.name===\\\"AbortError\\\"||e instanceof Error&&e.name===\\\"AbortError\\\"}function j(e){if(e instanceof P)return e.retryable;return e instanceof TypeError}var P,ze,Ne,Fe,pe,we,He,ve,L;var V=Z(()=>{mt();P=class P extends Error{status;code;retryable;correlationId;outcomeUnknown;body;details;constructor(e,t,n={}){let s=vs(t),i=s?.requestId??ht(n.correlationId),r=e>=502&&e<=504,o=n.mutation!==void 0,a=s?.message??(o?\\\"Request failed.\\\":t||\\\"(empty body)\\\"),c=n.displayMessage??(r&&o?s?.message??\\\"The workspace is temporarily unavailable — retry.\\\":`API ${e}: ${a}`);super(i?`${c} Reference: ${i}.`:c);this.name=\\\"OpenGeniApiError\\\",this.status=e,this.code=n.code??s?.code??(r&&o?\\\"upstream_unavailable\\\":void 0),this.retryable=n.retryable??s?.retryable??Is(e),this.correlationId=i,this.outcomeUnknown=n.outcomeUnknown??s?.outcomeUnknown??(r&&!!n.mutation&&!s),this.body=!o||s?t:\\\"\\\",this.details=s?.details}};ze=class ze extends P{constructor(e){super(e.status,e.body,{code:\\\"OPENGENI_SETUP_REQUIRED\\\",retryable:!1,correlationId:e.correlationId,displayMessage:\\\"Private chats require organization_private_session_settings.enabled (migration 0323). An organization owner or admin can enable Only me chats in the web app under Organization settings > Security & data, or use updateOrganizationPrivateSessionSettings from @opengeni/sdk/organization-private-session-settings with enabled: true, the current expectedVersion and a stable operationId (PATCH /v1/organizations/:organizationId/private-session-settings; an organization key needs workspace:admin). If platform readiness is unavailable, ask the deployment operator to activate session tenancy first.\\\"});this.name=\\\"OpenGeniSetupError\\\"}};Ne=class Ne extends P{scope;resetsAt;subjectId;constructor(e,t,n={}){super(e,t,{...n,code:\\\"allowance_exhausted\\\",retryable:!1,outcomeUnknown:!1});this.name=\\\"OpenGeniAllowanceExhaustedError\\\";let s=Ve(t);this.scope=s?.scope??\\\"workspace\\\",this.resetsAt=s?.resetsAt??null,this.subjectId=s?.subjectId}};Fe=class Fe extends P{rootSessionId;limitMicros;usedMicros;constructor(e,t,n={}){super(e,t,{...n,code:\\\"session_usage_limit_reached\\\",retryable:!1,outcomeUnknown:!1});this.name=\\\"OpenGeniSessionUsageLimitReachedError\\\";let s=Je(t);this.rootSessionId=s?.rootSessionId,this.limitMicros=s?.limitMicros,this.usedMicros=s?.usedMicros}};pe=class pe extends Error{code=\\\"session_usage_limit_unsupported\\\";sessionId;constructor(e,t={}){super(e,t.cause===void 0?void 0:{cause:t.cause});this.name=\\\"OpenGeniSessionUsageLimitUnsupportedError\\\",this.sessionId=t.sessionId??null}};we=class we extends Error{code=\\\"secure_context_required\\\";retryable=!1;reason;constructor(e){super(e===\\\"insecure_context\\\"?\\\"Couldn’t attach this file because this page is open over HTTP. Attachments require a secure HTTPS connection. Open the secure site or configure HTTPS for this deployment.\\\":\\\"Couldn’t attach this file because secure browser cryptography is unavailable. Attachments require HTTPS and Web Crypto support. Open a secure site in a supported browser or configure HTTPS for this deployment.\\\");this.name=\\\"OpenGeniSecureContextRequiredError\\\",this.reason=e}};He=class He extends P{};ve=class ve extends Error{expected;actual;constructor(e,t){super(`API contract mismatch: client expects ${e}, API serves ${t}`);this.name=\\\"OpenGeniApiContractMismatchError\\\",this.expected=e,this.actual=t}};L=class L extends Error{constructor(e){super(e);this.name=\\\"OpenGeniStreamError\\\"}}});function ke(e){let t=null,n=0,s=!1,i=null,r=null,o=()=>{if(i&&i.epoch===n)return i;let l=s,p={epoch:n,controller:new AbortController,waiters:0,settled:!1};return i=p,p.promise=(async()=>{try{let d=await e(l,p.controller.signal);if(p.epoch===n&&!p.controller.signal.aborted)t=d,s=!1;return d}finally{if(p.settled=!0,i===p)i=null}})(),p.promise.catch(()=>{return}),p},a=(l,p)=>{if(i===l)i=null;if(r?.load===l)r=null;l.controller.abort(p)},c=(l,p)=>{if(p?.aborted)return Promise.reject(Rt(p));return l.waiters+=1,new Promise((d,m)=>{let y=!1,R=()=>{if(y)return!1;return y=!0,l.waiters-=1,p?.removeEventListener(\\\"abort\\\",w),!0},w=()=>{if(!R())return;let S=Rt(p);if(m(S),l.waiters===0&&!l.settled)a(l,S)};p?.addEventListener(\\\"abort\\\",w,{once:!0}),l.promise.then((S)=>{if(R())d(S)},(S)=>{if(R())m(S)})})},u=()=>{t=null,n+=1,s=!0};return{async load(l={}){if(l.signal?.throwIfAborted(),l.refresh)u();if(t)return t;return await c(o(),l.signal)},async reloadAfterStale(l,p){p?.throwIfAborted();let d=r;if(d?.staleDigest===l&&(d.settled===null?d.load.epoch===n:d.settled===t))return await c(d.load,p);u();let m=o(),y={staleDigest:l,load:m,settled:null};return r=y,m.promise.then((R)=>{if(r!==y)return;if(R.digest===l)r=null;else y.settled=R},()=>{if(r===y)r=null}),await c(m,p)},invalidate(l){if(t?.digest===l)u()}}}function Rt(e){return e.reason??new DOMException(\\\"The operation was aborted.\\\",\\\"AbortError\\\")}function St(e,t,n){let s=`/v1/workspaces/${encodeURIComponent(t)}/tools`,i,r=()=>i??=n(),o=new Set,a=new Map,c=new Map,u=new Map,l=0,p=(b)=>{if(!u.has(b)&&u.size>=256)u.delete(u.keys().next().value);let h=++l;return u.set(b,h),h},d=new Map,m=(b)=>{let h=me(b),f=a.get(h);if(!f){if(f=ke(async(T,C)=>{let v=await e.requestJson(\\\"POST\\\",`${s}/resolve`,{target:b},{},{signal:C});return{...v,digest:v.definitionDigest}}),a.size>=256)a.delete(a.keys().next().value);a.set(h,f)}return f},y=(b,h,f)=>{let T=me(b);if(u.get(T)!==f)return;if(c.size>=256)c.delete(c.keys().next().value);c.set(T,h)},R=async(b,h={})=>{if(h.siteArtifactId||h.siteVersionId)return await e.requestJson(\\\"POST\\\",`${s}/resolve`,{target:b,siteArtifactId:h.siteArtifactId,siteVersionId:h.siteVersionId},{},h.signal?{signal:h.signal}:{});let f=me(b),T=p(f);if(h.refresh)c.delete(f);let C=await m(b).load(h);return y(b,C,T),C},w=(b,h={})=>e.requestJson(\\\"POST\\\",`${s}/invoke`,b,{},h),S=async(b,h={},f={})=>{if(f.approvalToken&&(f.approvalBinding===\\\"catalog\\\"||o.has(f.approvalToken))){if(\\\"identity\\\"in b)return await r().$call(b.identity,h,f);let N=r();for(let gs of b.path)N=N[gs];return await N(h,f)}if(f.approvalToken&&!f.operationId)throw TypeError(\\\"operationId is required when using an approval token\\\");f.signal?.throwIfAborted();let T=f.operationId??crypto.randomUUID(),C=me(b),v=p(C);if(f.refreshCatalog)c.delete(C);let k=f.refreshCatalog?await m(b).load({refresh:!0,...f.signal?{signal:f.signal}:{}}):c.get(C),q=f.approvalToken?d.get(f.approvalToken):void 0,H=f.expectedDefinitionDigest!==void 0?f.expectedDefinitionDigest:f.approvalToken?void 0:k?.definitionDigest;if(q&&(q.operationId!==T||(\\\"identity\\\"in b)&&me({identity:q.tool.entry.identity})!==C))throw new ie(T,q.tool.definitionDigest,H??\\\"\\\",q.tool.entry.identity);let Q=(N)=>w({operationId:T,target:b,arguments:h,...N===void 0?{}:{expectedDefinitionDigest:N},...f.approvalToken?{approvalToken:f.approvalToken}:{}},f.signal?{signal:f.signal}:{}),J;try{J=await Q(H)}catch(N){if(!Ps(N)||H===void 0)throw N;if(u.get(C)===v)c.delete(C);if(f.expectedDefinitionDigest!==void 0&&!f.approvalToken)throw N;if(k=await m(b).reloadAfterStale(H,f.signal),y(b,k,v),f.approvalToken||f.expectedDefinitionDigest!==void 0)throw new ie(T,H,k.definitionDigest,k.entry.identity);J=await Q(k.definitionDigest)}if(f.approvalToken)d.delete(f.approvalToken);if(y(b,J.tool,v),J.result.isError)throw new Ie(J.result);return J.tool.entry.outputSchema&&J.result.structuredContent!==void 0?J.result.structuredContent:J.result},I=async(b,h={},f={})=>{let T=await R({identity:b},{...f.signal?{signal:f.signal}:{}}),C=await e.requestJson(\\\"POST\\\",`${s}/target-approvals`,{identity:b,arguments:h,operationId:f.operationId??crypto.randomUUID(),expectedDefinitionDigest:f.expectedDefinitionDigest===void 0?T.definitionDigest:f.expectedDefinitionDigest},{},f.signal?{signal:f.signal}:{});if(d.size>=256)d.delete(d.keys().next().value);return d.set(C.approvalToken,C),C},x=(b)=>new Proxy(async(h={},f={})=>S({path:b},h,f),{get:(h,f)=>f===\\\"then\\\"||typeof f!==\\\"string\\\"?void 0:x([...b,f])});return new Proxy(Object.create(null),{get:(b,h)=>{if(h===\\\"then\\\"||typeof h!==\\\"string\\\")return;if(h===\\\"$targetProtocol\\\")return 1;if(h===\\\"$resolve\\\")return R;if(h===\\\"$invoke\\\")return w;if(h===\\\"$manifest\\\")return(f,T={})=>e.requestJson(\\\"POST\\\",`${s}/manifest`,f,{},T);if(h===\\\"$call\\\")return(f,T,C)=>S({identity:f},T,C);if(h===\\\"$approveTarget\\\")return I;if(h===\\\"$approve\\\")return async(...f)=>{let T=await r().$approve(...f);if(o.size>=256)o.delete(o.values().next().value);return o.add(T.approvalToken),T};if(h===\\\"$catalog\\\")return r().$catalog;if(h===\\\"$declarations\\\")return r().$declarations;return x([h])}})}var me=(e)=>(\\\"identity\\\"in e)?JSON.stringify([\\\"identity\\\",e.identity.serverId,e.identity.toolName]):JSON.stringify([\\\"path\\\",...e.path]),Ps=(e)=>{if(typeof e!==\\\"object\\\"||e===null)return!1;if(\\\"outcomeUnknown\\\"in e&&e.outcomeUnknown===!0||\\\"retryable\\\"in e&&e.retryable===!1)return!1;return e instanceof P?e.status===409&&e.details?.code===\\\"tool_definition_stale\\\":typeof e===\\\"object\\\"&&e!==null&&(\\\"code\\\"in e)&&e.code===\\\"tool_definition_stale\\\"};var wt=Z(()=>{V();Ae()});class re{transport;constructor(e){this.transport=e}forWorkspace(e){let t=Os(e,\\\"workspaceId\\\");if(this.transport.toolGatewayMode!==\\\"catalog\\\")return St(this.transport,t,()=>new re({toolGatewayMode:\\\"catalog\\\",requestJson:this.transport.requestJson.bind(this.transport)}).forWorkspace(t));let n=`/v1/workspaces/${encodeURIComponent(t)}/tools/catalog`,s=ke(async(d,m)=>await this.transport.requestJson(\\\"GET\\\",n,void 0,{},{signal:m})),i=new Map,r=async(d={})=>await s.load({...d.refresh?{refresh:!0}:{},...d.signal?{signal:d.signal}:{}}),o=async(d,m)=>await s.reloadAfterStale(d,m),a=async(d,m,y)=>{if(y.approvalToken&&!y.operationId)throw TypeError(\\\"operationId is required when using an approval token\\\");let R=y.operationId??crypto.randomUUID(),w=await r({...y.refreshCatalog===void 0?{}:{refresh:y.refreshCatalog},...y.signal?{signal:y.signal}:{}}),S=async(b)=>{let h=d(b),f=y.approvalToken?i.get(y.approvalToken):void 0;if(f&&(f.operationId!==R||f.catalogDigest!==b.digest||!xs(f.identity,h)))throw new ie(R,f.catalogDigest,b.digest,h);let T={operationId:R,catalogDigest:b.digest,identity:h,arguments:m,...y.approvalToken?{approvalToken:y.approvalToken}:{}},C;try{C=await this.transport.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(t)}/tools/calls`,T,{},y.signal?{signal:y.signal}:{})}catch(k){if(Ce(k))s.invalidate(b.digest);else if(y.approvalToken)i.delete(y.approvalToken);throw k}if(y.approvalToken)i.delete(y.approvalToken);if(C.catalogDigest!==b.digest)s.invalidate(b.digest);if(C.result.isError)throw new Ie(C.result);return kt(b,h)?.outputSchema&&C.result.structuredContent!==void 0?C.result.structuredContent:C.result};try{return await S(w)}catch(b){if(!Ce(b))throw b}let I=await o(w.digest,y.signal),x=d(I);if(y.approvalToken&&I.digest!==w.digest)throw new ie(R,w.digest,I.digest,x);return await S(I)},c=async(d,m={},y={})=>await a((R)=>vt(R,d),m,y),u=async(d,m={},y={})=>{let R=y.operationId??crypto.randomUUID(),w=async(x)=>{let b={operationId:R,catalogDigest:x.digest,identity:vt(x,d),arguments:m};try{let h=await this.transport.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(t)}/tools/approvals`,b,{},y.signal?{signal:y.signal}:{});return i.set(h.approvalToken,{operationId:h.operationId,catalogDigest:h.catalogDigest,identity:h.identity}),h}catch(h){if(Ce(h))s.invalidate(x.digest);throw h}},S=await r(y.signal?{signal:y.signal}:{});try{return await w(S)}catch(x){if(!Ce(x))throw x}let I=await o(S.digest,y.signal);return await w(I)},l=async(d,m={},y={})=>await a((R)=>Ts(R,d).identity,m,y),p=(d)=>new Proxy(async(m={},y={})=>await l(d,m,y),{get:(m,y)=>{if(y===\\\"then\\\")return;if(typeof y!==\\\"string\\\")return;return p([...d,y])}});return new Proxy(Object.create(null),{get:(d,m)=>{if(m===\\\"then\\\")return;if(m===\\\"$catalog\\\")return r;if(m===\\\"$call\\\")return c;if(m===\\\"$approve\\\")return u;if(m===\\\"$declarations\\\")return async(y={})=>await this.transport.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(t)}/tools/declarations`,void 0,{},y.signal?{signal:y.signal}:{});if(typeof m!==\\\"string\\\")return;return p([m])}})}}function kt(e,t){return e.entries.find((n)=>n.identity.serverId===t.serverId&&n.identity.toolName===t.toolName)}function xs(e,t){return e.serverId===t.serverId&&e.toolName===t.toolName}function vt(e,t){let n=kt(e,t);if(!n)throw Error(`Tool is not present in the workspace catalog: ${t.serverId}/${t.toolName}`);return n.identity}function Ts(e,t){let n=e.entries.find((s)=>s.codemodePath.length===t.length&&s.codemodePath.every((i,r)=>i===t[r]));if(!n)throw Error(`Tool is not present in the workspace catalog: ${t.join(\\\".\\\")}`);return n}function Ce(e){if(typeof e!==\\\"object\\\"||e===null||\\\"outcomeUnknown\\\"in e&&e.outcomeUnknown===!0||\\\"retryable\\\"in e&&e.retryable===!1)return!1;return e instanceof P&&e.status===409&&e.details?.code===\\\"catalog_stale\\\"||typeof e===\\\"object\\\"&&e!==null&&\\\"code\\\"in e&&e.code===\\\"catalog_stale\\\"}function Os(e,t){let n=e.trim();if(!n)throw TypeError(`${t} is required`);return n}var Ie,ie;var Ae=Z(()=>{wt();V();Ie=class Ie extends Error{result;code;retryable;outcomeUnknown;constructor(e){let t=e.structuredContent;super(typeof t?.error?.message===\\\"string\\\"?t.error.message:\\\"Tool call failed\\\");this.result=e;this.name=\\\"OpenGeniToolCallError\\\",this.code=typeof t?.error?.code===\\\"string\\\"?t.error.code:\\\"tool_error\\\",this.retryable=t?.error?.retryable===!0,this.outcomeUnknown=t?.error?.outcomeUnknown===!0}};ie=class ie extends Error{operationId;previousCatalogDigest;catalogDigest;identity;code=\\\"tool_reapproval_required\\\";retryable=!1;constructor(e,t,n,s){super(\\\"The workspace tool catalog changed after approval. Request a new approval for the refreshed tool identity and retry with the same operation ID.\\\");this.operationId=e;this.previousCatalogDigest=t;this.catalogDigest=n;this.identity=s;this.name=\\\"OpenGeniToolReapprovalRequiredError\\\"}}});function bi(e,t){if(e.length<t.length)return!1;let n=e.length-t.length;return t.every((s,i)=>e[n+i]===s)}function Si(e){for(let t of e.matchAll(mi)){let n=t[2]??t[3];if(!n)continue;let s=n.replace(/([a-z0-9])([A-Z])/g,\\\"$1 $2\\\").replace(/([A-Z]+)([A-Z][a-z])/g,\\\"$1 $2\\\").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean),i=s.at(-1);if(i&&fi.has(i))return!0;if(i&&hi.some((r)=>i.endsWith(r)))return!0;if(Ri.some((r)=>bi(s,r)))return!0}return!1}function wi(e){for(let t of e.matchAll(ci))if(!ui.test(t[0]))return!0;return!1}function vi(e){if(/[?:#]/u.test(e))return!1;let[t,...n]=e.split(\\\"/\\\");if(!t||n.length===0||n.some((s)=>!s))return!1;if(!gi.has(t)||n.some((s)=>!/^[A-Z][A-Za-z0-9_-]*$/u.test(s)))return!1;return!0}function ki(e){if(di.some((t)=>t.test(e)))return!0;for(let t of e.matchAll(li)){let n=t[0];if(n.toLowerCase().startsWith(\\\"www.\\\"))return!0;if(!/[/?#]/u.test(n))continue;let r=(n.split(/[/?#]/u,1)[0]??\\\"\\\").replace(/:\\\\d{1,5}$/u,\\\"\\\").split(\\\".\\\").at(-1)?.toLowerCase();if(r&&pi.has(r))continue;if(vi(n))continue;return!0}return!1}function Pi(e){return e.normalize(\\\"NFKC\\\").replace(Ai,\\\"\\\").replace(Ci,\\\"\\\")}function xi(e){let t=Pi(e);if(ai.some((n)=>n.test(t)))return!0;if(wi(t))return!0;if(ki(t))return!0;if(yi.test(t))return!0;if(Si(t))return!0;if(Ii.test(t))return!0;return!1}function Ti(e){if(Ge===void 0)Ge=typeof Intl.Segmenter===\\\"function\\\"?new Intl.Segmenter(void 0,{granularity:\\\"grapheme\\\"}):null;if(Ge)return Array.from(Ge.segment(e),(n)=>n.segment);let t=[];for(let n of e){let s=t.at(-1);if(s&&(/^[\\\\p{Mark}\\\\u{FE0E}\\\\u{FE0F}\\\\p{Emoji_Modifier}]$/u.test(n)||n===\\\"‍\\\"||s.endsWith(\\\"‍\\\")))t[t.length-1]=`${s}${n}`;else t.push(n)}return t}function qi(e){return e.replace(Oi,`\\n`)}function Ei(e,t){if(e===null||e===void 0)return null;if(t===\\\"user\\\")return e;let n=qi(e);if(n===e)return e;return n.split(`\\n`).map((s)=>s.trim()).find(Boolean)??null}function _i(e){let t=e.split(/\\\\s+/u),n=t.length>10?t.slice(0,10).join(\\\" \\\"):e,s=Ti(n);if(s.length<=80)return n;let i=s.slice(0,80).join(\\\"\\\"),r=i.search(/\\\\s+\\\\S*$/u);return(r>=16?i.slice(0,r):i).trimEnd()}function et(e){if(typeof e!==\\\"string\\\")return null;let t=e.slice(0,4096).replace(/[\\\\u0000-\\\\u001f\\\\u007f-\\\\u009f]+/gu,`\\n`).split(/\\\\n+/u);for(let n of t){let s=n.trim();if(!s||xi(s))continue;let i=_i(s.replace(/\\\\s+/gu,\\\" \\\")).replace(/[\\\\s.!?,;:\\\\-–—]+$/u,\\\"\\\").trim();if(i)return i}return null}function $n(e){let t=typeof e===\\\"string\\\"?e.trim():\\\"\\\";return oi.test(t)?`Conversation ${t.slice(0,13)}`:\\\"New conversation\\\"}function tt(e){let t=e.title?.trim()??\\\"\\\";return e.titleSource!==\\\"user\\\"&&(!t||t===\\\"New conversation\\\")}function Bn(e,t={}){let n=e.title?.trim()??\\\"\\\";if(e.titleSource===\\\"user\\\")return n||$n(e.id);if(n&&!tt(e)){let s=Ei(n,e.titleSource)?.trim();if(s)return s}for(let s of t.metadataKeys??[]){let i=e.metadata?.[s];if(typeof i===\\\"string\\\"&&i.trim().length>0)return i.trim()}return et(e.initialMessage)??$n(e.id)}var oi,Ge,ai,ci,ui,li,di,pi,gi,mi,yi,fi,hi,Ri,Ii,Ai,Ci,Oi;var Ln=Z(()=>{oi=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,ai=[/-----BEGIN [A-Z ]*PRIVATE KEY-----/iu,/\\\\bBearer\\\\s+[A-Za-z0-9._~+/=-]{8,}/iu,/\\\\b(?:sk-(?:proj-)?|gh[oprsu]_|github_pat_|glpat-|xox[baprs]-)[A-Za-z0-9_-]{8,}/iu,/\\\\bAKIA[0-9A-Z]{16}\\\\b/u,/\\\\bAIza[0-9A-Za-z_-]{20,}\\\\b/u,/\\\\beyJ[A-Za-z0-9_-]+\\\\.eyJ[A-Za-z0-9_-]+\\\\.[A-Za-z0-9_-]+\\\\b/u,/[?&](?:access_token|api_key|apikey|password|secret|token)=[^\\\\s&#]+/iu],ci=/\\\\b[a-z][a-z0-9+.-]*:\\\\S+/giu,ui=/^[a-z]:[\\\\\\\\/](?![\\\\\\\\/])[^:]*$/iu,li=/\\\\b(?:www\\\\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\\\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?(?::\\\\d{1,5})?(?:[/?#][^\\\\s]*)?/giu,di=[/\\\\blocalhost(?:(?::\\\\d{1,5})(?:[/?#][^\\\\s]*)?|[/?#][^\\\\s]*)/iu,/\\\\b(?:(?:25[0-5]|2[0-4]\\\\d|1?\\\\d?\\\\d)\\\\.){3}(?:25[0-5]|2[0-4]\\\\d|1?\\\\d?\\\\d)(?:(?::\\\\d{1,5})(?:[/?#][^\\\\s]*)?|[/?#][^\\\\s]*)/u,/\\\\[(?=[0-9a-f:.]*:[0-9a-f:.]*\\\\])[0-9a-f:.]+\\\\](?:(?::\\\\d{1,5})(?:[/?#][^\\\\s]*)?|[/?#][^\\\\s]*)/iu],pi=new Set([\\\"css\\\",\\\"html\\\",\\\"js\\\",\\\"json\\\",\\\"jsx\\\",\\\"lock\\\",\\\"md\\\",\\\"sql\\\",\\\"toml\\\",\\\"ts\\\",\\\"tsx\\\",\\\"xml\\\",\\\"yaml\\\",\\\"yml\\\"]),gi=new Set([\\\"ASP.NET\\\",\\\"AWS.SDK\\\",\\\"Microsoft.Extensions\\\",\\\"System.IO\\\"]),mi=/(?:^|[^A-Za-z0-9])(?:(['\\\"])([A-Za-z][A-Za-z0-9_. -]*)\\\\1|([A-Za-z][A-Za-z0-9_.-]*))\\\\s*[=:]\\\\s*[^\\\\s,;]+/gu,yi=/\\\\b(?:api[ _-]?key|access[ _-]?token|auth[ _-]?token|credential|credentials|password|passwd|private[ _-]?key|secret|token)\\\\b\\\\s*[=:]\\\\s*[^\\\\s,;]+/iu,fi=new Set([\\\"credential\\\",\\\"credentials\\\",\\\"password\\\",\\\"passwd\\\",\\\"secret\\\",\\\"token\\\"]),hi=[\\\"apikey\\\",\\\"accesskey\\\",\\\"accesskeyid\\\",\\\"accesstoken\\\",\\\"authtoken\\\",\\\"credential\\\",\\\"credentials\\\",\\\"password\\\",\\\"passwd\\\",\\\"privatekey\\\",\\\"secret\\\",\\\"secretkey\\\",\\\"token\\\"],Ri=[[\\\"api\\\",\\\"key\\\"],[\\\"access\\\",\\\"key\\\"],[\\\"access\\\",\\\"key\\\",\\\"id\\\"],[\\\"auth\\\",\\\"key\\\"],[\\\"private\\\",\\\"key\\\"],[\\\"secret\\\",\\\"key\\\"]];Ii=/\\\\b(?=[A-Za-z0-9_-]{32,}\\\\b)(?=[A-Za-z0-9_-]*[A-Za-z])(?=[A-Za-z0-9_-]*\\\\d)[A-Za-z0-9_-]+\\\\b/u,Ai=/\\\\p{Default_Ignorable_Code_Point}+/gu,Ci=/\\\\\\\\+(?=[\\\"'])/gu;Oi=/<[||][^<>||\\\\s]{1,64}[||]>/gu});function Me(e){let t=e.metadata._opengeniSiteOrigin,n=t&&typeof t.siteId===\\\"string\\\"&&/^[\\\\da-f]{8}-[\\\\da-f]{4}-[\\\\da-f]{4}-[\\\\da-f]{4}-[\\\\da-f]{12}$/i.test(t.siteId)&&typeof t.title===\\\"string\\\"?{siteId:t.siteId,title:t.title}:null,s=e.metadata.scheduledTaskId;return{id:e.id,workspaceId:e.workspaceId,accountId:e.accountId,status:e.status,backgroundCommandActivity:e.backgroundCommandActivity,hasSchedules:e.hasSchedules,hasUpcomingSchedules:e.hasUpcomingSchedules,title:e.title,titleSource:e.titleSource,displayTitle:Bn(e),renameSeed:tt(e)?et(e.initialMessage)??\\\"\\\":e.title?.trim()??\\\"\\\",scheduledTaskId:typeof s===\\\"string\\\"&&s.length>0?s:null,siteOrigin:n,...e.model?{model:e.model}:{},...e.reasoningEffort?{reasoningEffort:e.reasoningEffort}:{},createdBy:e.createdBy,channelId:e.channelId,parentSessionId:e.parentSessionId,rootSessionId:e.rootSessionId,effectiveControl:e.effectiveControl,inputWait:e.inputWait,lastSequence:e.lastSequence,pinned:e.pinned??!1,pinnedAt:e.pinnedAt??null,pinVersion:e.pinVersion??0,unread:e.unread??!1,activelyWorking:e.activelyWorking??!1,attentionVersion:e.attentionVersion??0,archived:e.archived??!1,archivedAt:e.archivedAt??null,importedArchive:e.importedArchive,...e.retention?{retention:e.retention}:{},archiveVersion:e.archiveVersion??0,treeStats:e.treeStats,requiresActionSince:e.requiresActionSince,...e.admissionBlock!==void 0?{admissionBlock:e.admissionBlock}:{},createdAt:e.createdAt,updatedAt:e.updatedAt}}var Wn=Z(()=>{Ln()});var zn=Z(()=>{Wn()});var ms=Object.freeze([{id:\\\"config.client\\\",method:\\\"GET\\\",pattern:/^\\\\/v1\\\\/config\\\\/client$/u},{id:\\\"workspace.get\\\",method:\\\"GET\\\",pattern:/^$/u},{id:\\\"site.config\\\",method:\\\"GET\\\",pattern:/^\\\\/site\\\\/config$/u},{id:\\\"models.list\\\",method:\\\"GET\\\",pattern:/^\\\\/model-catalog$/u},{id:\\\"sessions.list\\\",method:\\\"GET\\\",pattern:/^\\\\/sessions$/u},{id:\\\"sessions.create\\\",method:\\\"POST\\\",pattern:/^\\\\/sessions$/u,agent:!0},{id:\\\"sessions.get\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}$\\\",\\\"u\\\")},{id:\\\"sessions.events\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/events$\\\",\\\"u\\\")},{id:\\\"sessions.stream\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/events/stream$\\\",\\\"u\\\"),stream:!0},{id:\\\"sessions.send\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/events$\\\",\\\"u\\\"),agent:!0},{id:\\\"sessions.steer\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/steer$\\\",\\\"u\\\"),agent:!0},{id:\\\"sessions.control\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/control$\\\",\\\"u\\\"),agent:!0},{id:\\\"sessions.queue\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/queue$\\\",\\\"u\\\")},{id:\\\"sessions.queue.item\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/queue/[A-Za-z0-9_-]{1,128}/(?:move|edit|steer|delete)$\\\",\\\"u\\\"),agent:!0},{id:\\\"sessions.composerDraft.get\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/composer-draft$\\\",\\\"u\\\")},{id:\\\"sessions.composerDraft.put\\\",method:\\\"PUT\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/composer-draft$\\\",\\\"u\\\")},{id:\\\"sessions.composerDraft.submit\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/composer-draft/submit$\\\",\\\"u\\\"),agent:!0},{id:\\\"sessions.humanInput\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/human-input-requests$\\\",\\\"u\\\")},{id:\\\"sessions.humanInput.get\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/sessions/[A-Za-z0-9_-]{1,128}/human-input-requests/[A-Za-z0-9_-]{1,128}$\\\",\\\"u\\\")},{id:\\\"data.read\\\",method:\\\"GET\\\",pattern:new RegExp(\\\"^/published-artifacts/current/(?:data|files)(?:/[A-Za-z0-9._~:@!$&'()*+,;=-]+)*$\\\",\\\"u\\\")},{id:\\\"data.write\\\",method:\\\"POST\\\",pattern:new RegExp(\\\"^/published-artifacts/current/(?:data|files)(?:/[A-Za-z0-9._~:@!$&'()*+,;=-]+)*$\\\",\\\"u\\\")},{id:\\\"data.put\\\",method:\\\"PUT\\\",pattern:new RegExp(\\\"^/published-artifacts/current/(?:data|files)(?:/[A-Za-z0-9._~:@!$&'()*+,;=-]+)*$\\\",\\\"u\\\")},{id:\\\"data.patch\\\",method:\\\"PATCH\\\",pattern:new RegExp(\\\"^/published-artifacts/current/(?:data|files)(?:/[A-Za-z0-9._~:@!$&'()*+,;=-]+)*$\\\",\\\"u\\\")},{id:\\\"data.delete\\\",method:\\\"DELETE\\\",pattern:new RegExp(\\\"^/published-artifacts/current/(?:data|files)(?:/[A-Za-z0-9._~:@!$&'()*+,;=-]+)*$\\\",\\\"u\\\")},{id:\\\"sql.run\\\",method:\\\"POST\\\",pattern:/^\\\\/published-artifacts\\\\/current\\\\/sql\\\\/queries\\\\/[A-Za-z][A-Za-z0-9_-]{0,63}$/u},{id:\\\"site.report\\\",method:\\\"POST\\\",pattern:/^\\\\/site\\\\/reports$/u}]),Cr=Object.freeze([\\\"catalog\\\",\\\"declarations\\\",\\\"call\\\",\\\"resolve\\\",\\\"invoke\\\"]);function ct(e,t){if(/[%\\\\\\\\#\\\\u0000-\\\\u0020\\\\u007f]/u.test(t))return null;if(t.split(\\\"/\\\").some((r)=>r===\\\".\\\"||r===\\\"..\\\"))return null;let n=e.toUpperCase(),s;if(t===\\\"/v1/config/client\\\")s=t;else if(t===\\\"/v1/workspaces/site-host\\\")s=\\\"\\\";else if(t.startsWith(\\\"/v1/workspaces/site-host/\\\"))s=t.slice(24);else return null;let i=ms.find((r)=>r.method===n&&r.pattern.test(s));return i?{operation:i,suffix:s}:null}var ys=/^\\\\/v1\\\\/workspaces\\\\/site-host\\\\/published-artifacts\\\\/([^/]+)\\\\/(?:data|files|sql)(?:\\\\/|$)/u,fs=\\\"00000000-0000-0000-0000-000000000000\\\";class Se extends Error{code=\\\"site_session_path_unsupported\\\";constructor(){super(\\\"Unsupported Site session API path\\\");this.name=\\\"SiteSessionPathError\\\"}}class lt extends Error{code=\\\"site_data_unsupported\\\";constructor(){super(\\\"This Site host does not provide Site Data\\\");this.name=\\\"SiteDataUnsupportedError\\\"}}function hs(e,t){let n=new URL(e,\\\"http://site.invalid\\\");if(n.pathname===\\\"/v1/config/client\\\"){let s=n.searchParams.getAll(\\\"workspaceId\\\");if(s.length>1||s.length===1&&s[0]!==\\\"site-host\\\"&&s[0]!==t)throw new Se;if(t!==\\\"site-host\\\")n.searchParams.set(\\\"workspaceId\\\",t);return n.pathname+n.search}return e.replace(\\\"/workspaces/site-host\\\",`/workspaces/${encodeURIComponent(t)}`)}function Rs(e,t,n,s){if(n===\\\"site-host\\\")return e;if(!s)throw new lt;return t.replace(\\\"/published-artifacts/current/\\\",`/published-artifacts/${encodeURIComponent(s)}/`)}function de(e,t,n=\\\"GET\\\",s){let i=e.split(\\\"?\\\")[0],r=ct(n,i);if(!r)throw new Se;let o=hs(e,t);if(ys.test(i))return Rs(e,o,t,s);if(r.operation.id!==\\\"sessions.list\\\")return o;let a=new URL(o,\\\"http://site.invalid\\\"),c=a.searchParams.getAll(\\\"originSiteId\\\"),u=a.searchParams.getAll(\\\"siteAccessId\\\"),l=a.searchParams.getAll(\\\"view\\\");if(l.length>1||l.length===1&&l[0]!==\\\"page\\\"||c.length+u.length!==1||(c[0]??u[0])!==\\\"current\\\")throw new Se;if(t===\\\"site-host\\\")return e;return a.searchParams.set(u.length?\\\"siteAccessId\\\":\\\"originSiteId\\\",s??fs),a.pathname+a.search}var ut=[\\\"text\\\",\\\"annotations\\\",\\\"model\\\",\\\"reasoningEffort\\\",\\\"latencyMode\\\",\\\"controlEtag\\\",\\\"expectedDraftRevision\\\"],Tr=Object.freeze({\\\"sessions.send\\\":[\\\"type\\\",\\\"payload\\\",\\\"clientEventId\\\"],\\\"sessions.steer\\\":[...ut,\\\"clientEventId\\\"],\\\"sessions.control\\\":[\\\"action\\\",\\\"reason\\\",\\\"clientEventId\\\",\\\"expectedControlEtag\\\"],\\\"sessions.composerDraft.put\\\":[\\\"text\\\",\\\"annotations\\\",\\\"resources\\\",\\\"model\\\",\\\"reasoningEffort\\\",\\\"latencyMode\\\",\\\"expectedRevision\\\"],\\\"sessions.composerDraft.submit\\\":[...ut,\\\"resources\\\",\\\"connectionAccounts\\\",\\\"clientEventId\\\",\\\"delivery\\\"],\\\"sessions.queue.move\\\":[\\\"clientEventId\\\",\\\"expectedQueueVersion\\\",\\\"beforeTurnId\\\"],\\\"sessions.queue.edit\\\":[\\\"clientEventId\\\",\\\"expectedTurnVersion\\\",\\\"expectedDraftRevision\\\",\\\"replaceDraft\\\"],\\\"sessions.queue.steer\\\":[\\\"clientEventId\\\",\\\"expectedTurnVersion\\\",\\\"controlEtag\\\"],\\\"sessions.queue.delete\\\":[\\\"clientEventId\\\",\\\"expectedTurnVersion\\\",\\\"reason\\\"]});var Or=Object.freeze([\\\"initialMessage\\\",\\\"requestedSessionId\\\",\\\"idempotencyKey\\\",\\\"clientEventId\\\",\\\"model\\\",\\\"reasoningEffort\\\",\\\"latencyMode\\\",\\\"startMode\\\",\\\"metadata\\\"]);var Cs=\\\"opengeni.site.http\\\",ge=\\\"site-host\\\";async function bt(e,t,n){let s=new Request(t,n),i=new URL(s.url),r=`${i.pathname}${i.search}`;de(r,ge,s.method);let o=new MessageChannel,a=crypto.randomUUID(),c=n?.body instanceof ArrayBuffer||ArrayBuffer.isView(n?.body)||typeof Blob<\\\"u\\\"&&n?.body instanceof Blob,u=s.body?c?await s.arrayBuffer():await s.text():void 0;return await new Promise((l,p)=>{let d,m=!1,y=()=>{m=!0,s.signal.removeEventListener(\\\"abort\\\",R),o.port1.close()},R=()=>{if(m)return;e.postMessage({type:\\\"opengeni.site.cancel\\\",version:2,requestId:a});let w=s.signal.reason??new DOMException(\\\"Cancelled\\\",\\\"AbortError\\\");d?.error(w),p(w),y()};if(o.port1.onmessage=(w)=>{let S=w.data;if(S.error){let I=Error(S.error);d?.error(I),p(I),y()}else if(S.status){let I=S.body?new ReadableStream({start(x){d=x},pull(){o.port1.postMessage(\\\"pull\\\")},cancel(){d=void 0,R()}}):null;if(l(new Response(I,{status:S.status,headers:S.headers})),!S.body)y()}else if(S.done)d?.close(),y();else if(S.chunk)d?.enqueue(S.chunk)},s.signal.aborted){R();return}s.signal.addEventListener(\\\"abort\\\",R,{once:!0}),e.postMessage({type:Cs,requestId:a,path:r,method:s.method,headers:[...s.headers],...u===void 0?{}:{body:u}},[o.port2])})}Ae();var It=\\\"X-OpenGeni-Session-Sequence\\\",Ke=new WeakMap;function At(e,t){if(t===null||typeof e!==\\\"object\\\"||e===null)return;let n=Number(t);if(Number.isSafeInteger(n)&&n>=0)Ke.set(e,n)}function Ct(e,t){if(typeof e!==\\\"object\\\"||e===null||typeof t!==\\\"object\\\"||t===null)return;let n=Ke.get(e);if(n!==void 0)Ke.set(t,n)}var qs=[\\\"agent.toolCall.created\\\",\\\"agent.toolCall.output\\\",\\\"agent.reasoning.delta\\\",\\\"sandbox.command.output.delta\\\",\\\"terminal.pty.output.delta\\\"],Es=[\\\"agent.model.request\\\",\\\"agent.model.usage\\\"],Kr=[...qs,...Es];var Pt=\\\"X-OpenGeni-Conversation-Filter\\\";function Pe(e){let t=new URLSearchParams;for(let[s,i]of Object.entries(e)){if(i===void 0)continue;for(let r of Array.isArray(i)?i:[i])t.append(s,String(r))}let n=t.toString();return n?`?${n}`:\\\"\\\"}V();var G=encodeURIComponent;function _s(e){let t={};if(e.q)t.q=e.q;if(e.type)t.type=e.type;if(e.includeArchived)t.includeArchived=\\\"true\\\";if(e.cursor)t.cursor=e.cursor;if(e.limit)t.limit=String(e.limit);return t}function xt(e,t){let n=`/v1/workspaces/${G(t)}`,s=(a)=>`${n}/vaults/${G(a)}`,i=(a,c)=>`${s(a)}/items/${G(c)}`,r=(a,c,u)=>`${i(a,c)}/fields/${G(u)}`,o=(a,c,u,l,p)=>e.requestJson(a,c,u,l??{},p?{signal:p}:{});return{listVaults:async(a)=>(await o(\\\"GET\\\",`${n}/vaults`,void 0,{},a)).vaults,getVault:(a,c)=>o(\\\"GET\\\",s(a),void 0,{},c),createVault:(a)=>o(\\\"POST\\\",`${n}/vaults`,a),updateVault:(a,c)=>o(\\\"PATCH\\\",s(a),c),deleteVault:(a,c)=>e.requestJson(\\\"DELETE\\\",s(a),{confirmName:c},{},{responseType:\\\"void\\\"}),syncVault:(a)=>o(\\\"POST\\\",`${s(a)}/sync`,{}),listItems:(a,c={},u)=>o(\\\"GET\\\",`${s(a)}/items`,void 0,_s(c),u),getItem:(a,c,u)=>o(\\\"GET\\\",i(a,c),void 0,{},u),createItem:(a,c)=>o(\\\"POST\\\",`${s(a)}/items`,c),updateItem:(a,c,u)=>o(\\\"PATCH\\\",i(a,c),u),deleteItem:(a,c,u=!1)=>e.requestJson(\\\"DELETE\\\",i(a,c),void 0,u?{permanent:\\\"true\\\"}:{},{responseType:\\\"void\\\"}),restoreItem:(a,c)=>o(\\\"POST\\\",`${i(a,c)}/restore`,{}),moveItem:(a,c,u)=>o(\\\"POST\\\",`${i(a,c)}/move`,u),revealField:(a,c,u,l)=>o(\\\"POST\\\",`${r(a,c,u)}/reveal`,l===void 0?{}:{version:l}),listFieldVersions:async(a,c,u,l)=>(await o(\\\"GET\\\",`${r(a,c,u)}/versions`,void 0,{},l)).versions,restoreFieldVersion:(a,c,u,l)=>o(\\\"POST\\\",`${r(a,c,u)}/restore`,{version:l}),getSessionSecrets:(a,c)=>o(\\\"GET\\\",`${n}/sessions/${G(a)}/secrets`,void 0,{},c),setSessionVaultPolicy:(a,c)=>o(\\\"PUT\\\",`${n}/sessions/${G(a)}/vault-policy`,{policy:c}),installOnePassword:(a)=>o(\\\"POST\\\",`${n}/connections/1password/install`,a),listOnePasswordConnections:async(a)=>(await o(\\\"GET\\\",`${n}/connections/1password/service-accounts`,void 0,{},a)).connections,replaceOnePasswordToken:(a,c)=>o(\\\"PUT\\\",`${n}/connections/${G(a)}/1password/token`,c),disconnectOnePassword:(a)=>o(\\\"DELETE\\\",`${n}/connections/${G(a)}/1password`),listProviderVaults:async(a,c)=>(await o(\\\"GET\\\",`${n}/connections/${G(a)}/provider-vaults`,void 0,{},c)).vaults,installVaultProvider:(a)=>o(\\\"POST\\\",`${n}/vault-providers/connections`,a),getVaultProviderCatalog:(a)=>o(\\\"GET\\\",`${n}/vault-providers/connections`,void 0,{},a),listVaultProviderConnections:async(a)=>(await o(\\\"GET\\\",`${n}/vault-providers/connections`,void 0,{},a)).connections,replaceVaultProviderCredentials:(a,c)=>o(\\\"PUT\\\",`${n}/vault-providers/connections/${G(a)}/credentials`,c),disconnectVaultProvider:(a)=>o(\\\"DELETE\\\",`${n}/vault-providers/connections/${G(a)}`),verifyVaultProviderConnection:(a)=>o(\\\"POST\\\",`${n}/vault-providers/connections/${G(a)}/verify`,{}),linkProviderVault:(a)=>o(\\\"POST\\\",`${n}/vaults/link`,a),createManagedProviderVault:(a,c)=>o(\\\"POST\\\",`${n}/connections/${G(a)}/managed-vaults`,c)}}V();async function*Y(e){let t=e.getReader(),n=new TextDecoder,s=\\\"\\\",i,r,o=null,a=()=>{let u=o===null?null:{...i!==void 0?{id:i}:{},...r!==void 0?{event:r}:{},data:o.join(`\\n`)};return i=void 0,r=void 0,o=null,u},c=(u)=>{if(u===\\\"\\\")return a();if(u.startsWith(\\\":\\\"))return null;let l=u.indexOf(\\\":\\\"),p=l===-1?u:u.slice(0,l),d=l===-1?\\\"\\\":u.slice(l+1);if(d.startsWith(\\\" \\\"))d=d.slice(1);if(p===\\\"data\\\")(o??=[]).push(d);else if(p===\\\"event\\\")r=d;else if(p===\\\"id\\\")i=d;return null};try{while(!0){let{done:u,value:l}=await t.read();if(u)break;s+=n.decode(l,{stream:!0});let p=s.indexOf(`\\n`);while(p!==-1){let d=s.slice(0,p);if(s=s.slice(p+1),d.endsWith(\\\"\\\\r\\\"))d=d.slice(0,-1);let m=c(d);if(m)yield m;p=s.indexOf(`\\n`)}}}finally{t.cancel().catch(()=>{});try{t.releaseLock()}catch{}}}var Ot=Symbol.for(\\\"@opengeni/sdk/session-event-stream-covered-through\\\");async function*qt(e,t={}){let n=t.signal,s=t.reconnect??!0,i=t.reconnectDelayMs??500,r=t.maxReconnectDelayMs??1e4,o=t.reconnectJitterRatio??0.2,a=t.beforeLiveTimeoutMs??15000,c=t.heartbeatTimeoutMs??45000,u=t.maxReconnectAttempts??Number.POSITIVE_INFINITY,l=t.after??0,p=0,d=i,m=!1,y=!1;while(!0){if(n?.aborted)break;t.onStateChange?.(m||p>0?\\\"reconnecting\\\":\\\"connecting\\\");let R=l;try{if(y&&t.beforeReconnect){let S=await Gs(t.beforeReconnect,l,n);if(n?.aborted)return;if(typeof S===\\\"number\\\"&&Number.isSafeInteger(S))l=Math.max(l,S);R=l}y=!0;let w=await e.openStream(l,n);m=!0,p=0,d=i;try{t.onOpen?.()}catch{}await ee(t.beforeLive,a,n),t.onStateChange?.(\\\"live\\\");for await(let S of Y(te(w,c,n))){if(n?.aborted)return;let I=Us(S.data);if(!I)continue;let x=Ds(S.id,I.sequence);if($s(I,x),x<=l)continue;if(I.sequence>l+1){for await(let b of Ms(e,l,I.sequence-1))if(l=b.sequence,yield b,n?.aborted)return}l=x,yield I}if(!s)return;if(l===R)await Tt(W(i,o),n);continue}catch(w){if(n?.aborted||K(w))return;if(!s||!j(w))throw w;if(p+=1,p>u)throw new L(`event stream gave up after ${u} consecutive failed reconnect attempts: ${w instanceof Error?w.message:String(w)}`)}await Tt(W(d,o),n),d=Math.min(Math.max(d*2,i),r)}}async function ee(e,t,n){if(!e)return;let s,i,r=new Promise((o,a)=>{if(s=setTimeout(()=>a(TypeError(`stream reconciliation timed out after ${t}ms`)),t),n)i=()=>a(new DOMException(\\\"Aborted\\\",\\\"AbortError\\\")),n.addEventListener(\\\"abort\\\",i,{once:!0})});try{await Promise.race([Promise.resolve().then(e),r])}finally{if(s!==void 0)clearTimeout(s);if(n&&i)n.removeEventListener(\\\"abort\\\",i)}}async function Gs(e,t,n){if(!n)return await e(t);if(n.aborted)throw new DOMException(\\\"Aborted\\\",\\\"AbortError\\\");let s,i=new Promise((r,o)=>{s=()=>o(new DOMException(\\\"Aborted\\\",\\\"AbortError\\\")),n.addEventListener(\\\"abort\\\",s,{once:!0})});try{return await Promise.race([Promise.resolve().then(()=>e(t)),i])}finally{if(s)n.removeEventListener(\\\"abort\\\",s)}}function W(e,t){if(e<=0||t<=0)return e;let n=Math.min(t,1),s=e*n;return Math.max(0,e-s+Math.random()*s*2)}function te(e,t,n){if(!Number.isSafeInteger(t)||t<=0)throw RangeError(\\\"stream heartbeat timeout must be a positive safe integer\\\");let s=e.getReader();return new ReadableStream({pull:async(i)=>{let r,o;try{let a=await Promise.race([s.read(),new Promise((c,u)=>{if(r=setTimeout(()=>u(TypeError(`event stream heartbeat timed out after ${t}ms`)),t),n)o=()=>u(new DOMException(\\\"Aborted\\\",\\\"AbortError\\\")),n.addEventListener(\\\"abort\\\",o,{once:!0})})]);if(a.done)i.close();else i.enqueue(a.value)}catch(a){s.cancel(a).catch(()=>{}),i.error(a)}finally{if(r!==void 0)clearTimeout(r);if(n&&o)n.removeEventListener(\\\"abort\\\",o)}},cancel:(i)=>{s.cancel(i).catch(()=>{})}})}async function*Ms(e,t,n){let s=t;while(s<n){let r=(await e.listEvents(s,Math.min(500,n-s))).filter((o)=>o.sequence>s&&o.sequence<=n).sort((o,a)=>o.sequence-a.sequence);if(r.length===0)throw new L(`event replay backfill stalled: expected sequences ${s+1}..${n} but the replay endpoint returned none of them`);for(let o of r){if(o.sequence!==s+1)throw new L(`event replay backfill is missing sequence ${s+1} (replay endpoint skipped to ${o.sequence}); refusing to deliver with a gap`);s=o.sequence,yield o}}}function Us(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!==\\\"object\\\"||t===null||typeof t.sequence!==\\\"number\\\"||typeof t.type!==\\\"string\\\"||typeof t.id!==\\\"string\\\")return null;return t}function Et(e){let t=e[Ot];return typeof t===\\\"number\\\"&&Number.isSafeInteger(t)&&t>=e.sequence?t:null}function Ds(e,t){if(e===void 0||!/^\\\\d+$/.test(e))return t;let n=Number(e);return Number.isSafeInteger(n)&&n>=t?n:t}function $s(e,t){Object.defineProperty(e,Ot,{value:t,enumerable:!1,configurable:!1,writable:!1})}async function Tt(e,t){if(t?.aborted||e<=0)return;await new Promise((n)=>{let s=setTimeout(i,e);function i(){clearTimeout(s),t?.removeEventListener(\\\"abort\\\",i),n()}t?.addEventListener(\\\"abort\\\",i,{once:!0})})}var Bs=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|\\\\d+|[A-Za-z0-9_-]{20,})$/i;function Ls(e){return e.split(\\\"/\\\").map((t)=>Bs.test(t)?\\\":id\\\":t).join(\\\"/\\\")}function Ws(e){let t=e.trim(),n=/^@(-?\\\\d+)$/.exec(t);if(n)return new Date(Number(n[1])*1000);let s=Date.parse(t);return Number.isNaN(s)?null:new Date(s)}function zs(e){let t=new Map;if(!e)return t;for(let n of e.matchAll(/<([^>]*)>\\\\s*((?:;\\\\s*[^;,]+)*)/g)){let s=/;\\\\s*rel=\\\"?([^\\\";,]+)\\\"?/i.exec(n[2]??\\\"\\\")?.[1];if(!s)continue;for(let i of s.toLowerCase().split(/\\\\s+/))if(!t.has(i))t.set(i,n[1])}return t}function Ns(e,t,n){let s=n.get(\\\"deprecation\\\"),i=n.get(\\\"sunset\\\");if(!s&&!i)return null;let r=t;try{r=new URL(t,\\\"http://opengeni.invalid\\\").pathname}catch{}let o=i?Date.parse(i):Number.NaN,a=zs(n.get(\\\"link\\\"));return{method:e.toUpperCase(),route:Ls(r),path:r,deprecatedAt:s?Ws(s):null,sunset:Number.isNaN(o)?null:new Date(o),link:a.get(\\\"deprecation\\\")??a.get(\\\"sunset\\\")??null,successor:a.get(\\\"successor-version\\\")??null}}var _t=new Set;function Fs(e){let t=`${e.method} ${e.route}`;if(_t.has(t))return;_t.add(t);let n=e.sunset?` and will be removed after ${e.sunset.toISOString()}`:\\\"\\\",s=e.link?` Migration notes: ${e.link}.`:\\\"\\\";console.warn(`[@opengeni/sdk] ${t} is deprecated${n}.${s} Upgrade @opengeni/sdk, or pass onDeprecation to handle this notice.`)}function Gt(e,t){if(t===!1)return e;let n=t??Fs,s=new Set;return async(i,r)=>{let o=await e(i,r);try{let a=o.headers;if(a&&(a.get(\\\"deprecation\\\")||a.get(\\\"sunset\\\"))){let c=r?.method??(typeof Request<\\\"u\\\"&&i instanceof Request?i.method:\\\"GET\\\"),u=typeof i===\\\"string\\\"?i:i instanceof URL?i.href:i.url,l=Ns(c,u,a);if(l){let p=`${l.method} ${l.route}`;if(!s.has(p))s.add(p),n(l)}}}catch{}return o}}V();var xe=Object.freeze({maxAttempts:4,initialDelayMs:250,maxDelayMs:2000,maxElapsedMs:5000}),Js=10,Mt=60000;function Te(e,t,n,s){if(typeof e!==\\\"number\\\"||!Number.isFinite(e))return t;return Math.min(Math.max(e,n),s)}function Ut(e){if(e===!1)return null;let t=e&&typeof e===\\\"object\\\"?e:{},n=Math.floor(Te(t.maxAttempts,xe.maxAttempts,1,Js));if(n<=1)return null;let s=Te(t.maxElapsedMs,xe.maxElapsedMs,0,Mt),i=Te(t.maxDelayMs,xe.maxDelayMs,0,Mt),r=Te(t.initialDelayMs,xe.initialDelayMs,0,i);return{maxAttempts:n,initialDelayMs:r,maxDelayMs:i,maxElapsedMs:s}}function Dt(e){let t=e.toUpperCase();return t===\\\"GET\\\"||t===\\\"HEAD\\\"}function je(e){return e===502||e===503||e===504}var $t=new WeakSet;function Ye(e){if(e instanceof TypeError)$t.add(e)}var Bt=new WeakSet;function A(e,t){let n=new P(502,e,t);return Bt.add(n),n}var Vs=/failed to fetch|fetch failed|networkerror|network error|load failed|network request failed|network connection was lost|terminated|err_http2|econnreset|socket hang up/iu;function Lt(e){if(e instanceof P)return!Bt.has(e)&&je(e.status)&&e.retryable;if(!(e instanceof TypeError))return!1;return $t.has(e)||Vs.test(e.message)}function Wt(e,t=Date.now()){if(e===null||e===void 0)return null;let n=e.trim();if(!n)return null;if(/^\\\\d+$/.test(n)){let i=Number(n);return Number.isSafeInteger(i)?i*1000:null}if(!/[A-Za-z]/.test(n))return null;let s=Date.parse(n);if(!Number.isFinite(s))return null;return Math.max(0,s-t)}function zt(e,t,n,s,i=Math.random){if(t>=e.maxAttempts)return null;let r;if(s!==null)r=s*(1+0.2*Math.min(Math.max(i(),0),1));else{let o=Math.min(e.maxDelayMs,e.initialDelayMs*2**(t-1));r=o/2+o/2*Math.min(Math.max(i(),0),1)}if(n+r>e.maxElapsedMs)return null;return Math.round(r)}function Nt(e,t){if(t?.aborted)return Promise.reject(t.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\"));return new Promise((n,s)=>{let i=()=>{clearTimeout(r),s(t?.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\"))},r=setTimeout(()=>{t?.removeEventListener(\\\"abort\\\",i),n()},e);t?.addEventListener(\\\"abort\\\",i,{once:!0})})}V();async function*Jt(e,t={}){let n=t.signal,s=t.reconnect??!0,i=t.reconnectDelayMs??500,r=t.maxReconnectDelayMs??1e4,o=t.reconnectJitterRatio??0.2,a=t.beforeLiveTimeoutMs??15000,c=t.heartbeatTimeoutMs??45000,u=t.maxReconnectAttempts??Number.POSITIVE_INFINITY,l=t.after??0,p=0,d=i,m=!1;for(;;){if(n?.aborted)return;t.onStateChange?.(m||p>0?\\\"reconnecting\\\":\\\"connecting\\\");let y=l;try{let R=await e.openStream(l,n);m=!0,p=0,d=i,await ee(t.beforeLive,a,n),t.onStateChange?.(\\\"live\\\");for await(let w of Y(te(R,c,n))){if(n?.aborted)return;let S=Hs(w.data);if(!S||S.sequence<=l)continue;l=S.sequence,yield S}if(!s)return;if(l===y)await Ft(W(i,o),n);continue}catch(R){if(n?.aborted||K(R))return;if(!s||!j(R))throw R;if(p+=1,p>u)throw new L(`workspace control stream gave up after ${u} reconnect attempts: ${R instanceof Error?R.message:String(R)}`)}await Ft(W(d,o),n),d=Math.min(Math.max(d*2,i),r)}}function Hs(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!==\\\"object\\\"||t===null||t.type!==\\\"workspace.control.changed\\\"||typeof t.id!==\\\"string\\\"||typeof t.sequence!==\\\"number\\\")return null;return t}async function Ft(e,t){if(t?.aborted||e<=0)return;await new Promise((n)=>{let s=setTimeout(i,e);function i(){clearTimeout(s),t?.removeEventListener(\\\"abort\\\",i),n()}t?.addEventListener(\\\"abort\\\",i,{once:!0})})}V();async function*Ht(e,t={}){let n=t.signal,s=t.reconnect??!0,i=t.reconnectDelayMs??500,r=t.maxReconnectDelayMs??1e4,o=t.reconnectJitterRatio??0.2,a=t.beforeLiveTimeoutMs??15000,c=t.heartbeatTimeoutMs??45000,u=t.maxReconnectAttempts??Number.POSITIVE_INFINITY,l=t.after??0,p=0,d=i,m=!1;for(;;){if(n?.aborted)return;t.onStateChange?.(m||p>0?\\\"reconnecting\\\":\\\"connecting\\\");let y=l;try{let R=await e.openStream(l,n);m=!0,p=0,d=i,await ee(t.beforeLive,a,n),t.onStateChange?.(\\\"live\\\");for await(let w of Y(te(R,c,n))){if(n?.aborted)return;let S=Ks(w.data);if(!S||S.sequence<=l)continue;l=S.sequence,yield S}if(!s)return;if(l===y)await Vt(W(i,o),n);continue}catch(R){if(n?.aborted||K(R))return;if(!s||!j(R))throw R;if(p+=1,p>u)throw new L(`workspace interaction stream gave up after ${u} reconnect attempts: ${R instanceof Error?R.message:String(R)}`)}await Vt(W(d,o),n),d=Math.min(Math.max(d*2,i),r)}}function Ks(e){let t;try{t=JSON.parse(e)}catch{return null}if(!js(t)||t.type!==\\\"workspace.interaction.changed\\\"||typeof t.workspaceId!==\\\"string\\\"||typeof t.sequence!==\\\"number\\\"||!Number.isSafeInteger(t.sequence)||t.sequence<0||t.revision!==t.sequence||typeof t.occurredAt!==\\\"string\\\")return null;return t}function js(e){return typeof e===\\\"object\\\"&&e!==null&&!Array.isArray(e)}async function Vt(e,t){if(t?.aborted||e<=0)return;await new Promise((n)=>{let s=setTimeout(i,e);function i(){clearTimeout(s),t?.removeEventListener(\\\"abort\\\",i),n()}t?.addEventListener(\\\"abort\\\",i,{once:!0})})}V();async function*jt(e,t={}){let n=t.signal,s=t.reconnect??!0,i=t.reconnectDelayMs??500,r=t.maxReconnectDelayMs??1e4,o=t.reconnectJitterRatio??0.2,a=t.beforeLiveTimeoutMs??15000,c=t.heartbeatTimeoutMs??45000,u=t.maxReconnectAttempts??Number.POSITIVE_INFINITY,l=t.controlAfter??0,p=t.interactionAfter??0,d=0,m=i,y=!1;for(;;){if(n?.aborted)return;t.onStateChange?.(y||d>0?\\\"reconnecting\\\":\\\"connecting\\\");let R=`${l}:${p}`;try{let w=await e.openStream(l,p,n);y=!0,d=0,m=i,await ee(t.beforeLive,a,n),t.onStateChange?.(\\\"live\\\");for await(let S of Y(te(w,c,n))){if(n?.aborted)return;let I=Ys(S.data);if(!I)continue;if(I.type===\\\"workspace.control.changed\\\"){if(I.sequence<=l)continue;l=I.sequence}else if(I.type===\\\"workspace.interaction.changed\\\"){if(I.sequence<=p)continue;p=I.sequence}yield I}if(!s)return;if(`${l}:${p}`===R)await Kt(W(i,o),n);continue}catch(w){if(n?.aborted||K(w))return;if(!s||!j(w))throw w;if(d+=1,d>u)throw new L(`workspace live stream gave up after ${u} reconnect attempts: ${w instanceof Error?w.message:String(w)}`)}await Kt(W(m,o),n),m=Math.min(Math.max(m*2,i),r)}}function Ys(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Xs(t))return null;if(t.type===\\\"workspace.sessions.changed\\\"&&typeof t.workspaceId===\\\"string\\\"&&typeof t.available===\\\"boolean\\\"&&(t.sessionIds===null||Array.isArray(t.sessionIds)&&t.sessionIds.every((n)=>typeof n===\\\"string\\\"))){let{siteSessionIds:n,...s}=t;return Array.isArray(n)&&n.every((i)=>typeof i===\\\"string\\\")?{...s,siteSessionIds:n}:s}if(typeof t.sequence!==\\\"number\\\")return null;if(t.type===\\\"workspace.control.changed\\\"&&typeof t.id===\\\"string\\\"&&Number.isSafeInteger(t.sequence))return t;if(t.type===\\\"workspace.interaction.changed\\\"&&typeof t.workspaceId===\\\"string\\\"&&Number.isSafeInteger(t.sequence)&&t.sequence>=0&&t.revision===t.sequence&&typeof t.occurredAt===\\\"string\\\")return t;return null}function Xs(e){return typeof e===\\\"object\\\"&&e!==null&&!Array.isArray(e)}async function Kt(e,t){if(t?.aborted||e<=0)return;await new Promise((n)=>{let s=setTimeout(i,e);function i(){clearTimeout(s),t?.removeEventListener(\\\"abort\\\",i),n()}t?.addEventListener(\\\"abort\\\",i,{once:!0})})}function Yt(e){return e.driverId===\\\"opengeni.cdp.ephemeral-context.v1\\\"?\\\"ephemeral_context\\\":\\\"private_profile\\\"}var Xt=32768,Qs=1e8;class Xe{attachedBrowsers;authRuns;browsers;computers;identities;interventions;networkRoutes;siteAuthConnections;constructor(e){this.attachedBrowsers=new un(e),this.authRuns=new rn(e),this.browsers=new gn(e),this.computers=new bn(e),this.identities=new dn(e),this.interventions=new an(e),this.networkRoutes=new en(e),this.siteAuthConnections=new nn(e)}}class en{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listNetworkRoutes(e,t)}route(e,t){return new tn(this.transport,e,t)}async create(e,t,n={}){let s=await this.transport.createNetworkRoute(e,t,n);return this.route(e,s.route.id)}}class tn{transport;workspaceId;id;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n}async get(e={}){return await this.transport.getNetworkRoute(this.workspaceId,this.id,e)}async update(e,t={}){return await this.transport.updateNetworkRoute(this.workspaceId,this.id,e,t)}}class nn{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listSiteAuthConnections(e,t)}connection(e,t){return new sn(this.transport,e,t)}async create(e,t,n={}){let s=await this.transport.createSiteAuthConnection(e,t,n);return this.connection(e,s.connection.id)}}class sn{transport;workspaceId;id;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n}async get(e={}){return await this.transport.getSiteAuthConnection(this.workspaceId,this.id,e)}async update(e,t={}){return await this.transport.updateSiteAuthConnection(this.workspaceId,this.id,e,t)}}class rn{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listAuthRuns(e,t)}async get(e,t,n={}){return await this.transport.getAuthRun(e,t,n)}run(e,t,n){return new Qe(this.transport,e,t,n)}}class on{transport;workspaceId;browserSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.browserSessionId=n}async list(e={}){return await this.transport.listAuthRuns(this.workspaceId,{...e,browserSessionId:this.browserSessionId})}run(e){return new Qe(this.transport,this.workspaceId,this.browserSessionId,e)}async start(e,t={}){let n=await this.transport.startBrowserAuthRun(this.workspaceId,this.browserSessionId,e,t);return this.run(n.run.id)}}class Qe{transport;workspaceId;browserSessionId;id;constructor(e,t,n,s){this.transport=e;this.workspaceId=t;this.browserSessionId=n;this.id=s}async get(e={}){let t=await this.transport.getAuthRun(this.workspaceId,this.id,e);if(t.browserSessionId!==this.browserSessionId)throw Error(\\\"AuthRun belongs to another BrowserSession\\\");return t}async report(e,t={}){return await this.transport.reportBrowserAuthRun(this.workspaceId,this.browserSessionId,this.id,e,t)}async advanceExternal(e,t={}){return await this.transport.advanceExternalBrowserAuthRun(this.workspaceId,this.browserSessionId,this.id,e,t)}async openExternalFlow(e,t={}){return await this.transport.openExternalBrowserAuthFlow(this.workspaceId,this.browserSessionId,this.id,e,t)}async verify(e,t={}){return await this.transport.verifyBrowserAuthRun(this.workspaceId,this.browserSessionId,this.id,e,t)}}class an{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listInteractionInterventions(e,t)}intervention(e,t){return new cn(this.transport,e,t)}async create(e,t,n={}){let s=await this.transport.createInteractionIntervention(e,t,n);return this.intervention(e,s.intervention.id)}}class cn{transport;workspaceId;id;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n}async get(e={}){return await this.transport.getInteractionIntervention(this.workspaceId,this.id,e)}async resolve(e,t={}){return await this.transport.resolveInteractionIntervention(this.workspaceId,this.id,e,t)}}class un{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listAttachedBrowsers(e,t)}device(e,t){return new ln(this.transport,e,t)}}class ln{transport;workspaceId;id;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n}async get(e={}){return await this.transport.getAttachedBrowser(this.workspaceId,this.id,e)}}class dn{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listBrowserIdentities(e,t)}identity(e,t){return new pn(this.transport,e,t)}async create(e,t,n={}){let s=await this.transport.createBrowserIdentity(e,t,n);return this.identity(e,s.identity.id)}}class pn{transport;workspaceId;id;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n}async get(e={}){return await this.transport.getBrowserIdentity(this.workspaceId,this.id,e)}async revisions(e={}){return await this.transport.listBrowserRevisions(this.workspaceId,this.id,e)}async update(e,t={}){return await this.transport.updateBrowserIdentity(this.workspaceId,this.id,e,t)}}class gn{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listBrowserSessions(e,t)}session(e,t){return new mn(this.transport,e,t)}async open(e,t,n={}){let s=await this.transport.createBrowserSession(e,t,n);return this.session(e,s.session.id)}async currentOrOpen(e){let t=e.signal?{signal:e.signal}:{},n=await this.list(e.workspaceId,t),s=ei(n.sessions.filter((i)=>Yt(i)===(e.storageMode??\\\"private_profile\\\")),e.associationSessionId);if(s){let i=this.session(e.workspaceId,s.id);if(s.lifecycle===\\\"suspended\\\")await i.resume({operationId:e.operationId??crypto.randomUUID()},t);return i}return await this.open(e.workspaceId,{operationId:e.operationId??crypto.randomUUID(),sessionId:e.associationSessionId,...e.name!==void 0?{name:e.name}:{},...e.initialUrl!==void 0?{initialUrl:e.initialUrl}:{},...e.headless!==void 0?{headless:e.headless}:{},...e.storageMode!==void 0?{storageMode:e.storageMode}:{},...e.placement!==void 0?{placement:e.placement}:{},...e.identityId!==void 0?{identityId:e.identityId}:{},...e.baseRevisionId!==void 0?{baseRevisionId:e.baseRevisionId}:{},...e.networkRouteId!==void 0?{networkRouteId:e.networkRouteId}:{},...e.linkedComputerSessionId!==void 0?{linkedComputerSessionId:e.linkedComputerSessionId}:{}},t)}}class mn{transport;workspaceId;id;auth;clipboard;downloads;tabs;targets;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n;this.auth=new on(e,t,n),this.clipboard=new yn(e,t,n),this.downloads=new fn(e,t,n),this.tabs=new Rn(e,t,n),this.targets=this.tabs}async get(e={}){return await this.transport.getBrowserSession(this.workspaceId,this.id,e)}async observe(e,t={}){return await this.transport.observeBrowserTarget(this.workspaceId,this.id,e,t)}async targetState(e,t={}){return await this.transport.getBrowserTargetState(this.workspaceId,this.id,e,t)}async readDom(e,t,n={}){return await this.transport.readBrowserDom(this.workspaceId,this.id,e,t,n)}async capture(e,t={},n={}){return await this.transport.captureBrowserTarget(this.workspaceId,this.id,e,t,n)}async screenshot(e,t={},n={}){return await this.capture(e,n,t)}async act(e,t={}){return await this.transport.actInBrowser(this.workspaceId,this.id,e,t)}async receipt(e,t={}){return await this.transport.getBrowserActionReceipt(this.workspaceId,this.id,e,t)}async diagnostics(e,t={}){return await this.transport.listBrowserDiagnostics(this.workspaceId,this.id,e,t)}async attach(e,t={}){return await this.transport.attachBrowserSession(this.workspaceId,this.id,e,t)}async heartbeat(e={}){return await this.transport.heartbeatBrowserSession(this.workspaceId,this.id,e)}async publishRevision(e,t={}){return await this.transport.publishBrowserRevision(this.workspaceId,this.id,e,t)}async suspend(e={operationId:crypto.randomUUID()},t={}){return await this.transport.suspendBrowserSession(this.workspaceId,this.id,e,t)}async resume(e={operationId:crypto.randomUUID()},t={}){return await this.transport.resumeBrowserSession(this.workspaceId,this.id,e,t)}async end(e={operationId:crypto.randomUUID()},t={}){return await this.transport.endBrowserSession(this.workspaceId,this.id,e,t)}}class yn{transport;workspaceId;browserSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.browserSessionId=n}async read(e={}){let t=await this.transport.readBrowserClipboard(this.workspaceId,this.browserSessionId,e);if(t.browserSessionId!==this.browserSessionId)throw Error(\\\"Browser clipboard belongs to another BrowserSession\\\");return t}}class fn{transport;workspaceId;browserSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.browserSessionId=n}async list(e={}){return await this.transport.listBrowserDownloads(this.workspaceId,this.browserSessionId,e)}download(e){return new hn(this.transport,this.workspaceId,this.browserSessionId,e)}}class hn{transport;workspaceId;browserSessionId;id;constructor(e,t,n,s){this.transport=e;this.workspaceId=t;this.browserSessionId=n;this.id=s}async get(e={}){let t=await this.transport.getBrowserDownload(this.workspaceId,this.browserSessionId,this.id,e);if(t.browserSessionId!==this.browserSessionId)throw Error(\\\"BrowserDownload belongs to another BrowserSession\\\");return t}async saveToWorkspace(e,t={}){let{operationId:n=crypto.randomUUID(),overwrite:s=!1,...i}=t,r=await this.transport.saveBrowserDownload(this.workspaceId,this.browserSessionId,this.id,{operationId:n,destinationPath:e,overwrite:s},i);if(r.download.id!==this.id||r.download.browserSessionId!==this.browserSessionId)throw Error(\\\"BrowserDownload save returned another resource\\\");return r}}class Rn{transport;workspaceId;browserSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.browserSessionId=n}async list(e={}){return await this.transport.listBrowserTargets(this.workspaceId,this.browserSessionId,e)}async open(e,t={}){return await this.transport.openBrowserTarget(this.workspaceId,this.browserSessionId,e===void 0?{}:{url:e},t)}async select(e,t={}){return await this.transport.selectBrowserTarget(this.workspaceId,this.browserSessionId,e,t)}async close(e,t={}){return await this.transport.closeBrowserTarget(this.workspaceId,this.browserSessionId,e,t)}}class bn{transport;constructor(e){this.transport=e}async list(e,t={}){return await this.transport.listComputerSessions(e,t)}session(e,t){return new Sn(this.transport,e,t)}async open(e,t,n={}){let s=await this.transport.createComputerSession(e,t,n);return this.session(e,s.session.id)}async currentOrOpen(e){let t=e.signal?{signal:e.signal}:{},n=await this.list(e.workspaceId,t),s=ti(n.sessions,e.associationSessionId);if(s)return this.session(e.workspaceId,s.id);return await this.open(e.workspaceId,{operationId:e.operationId??crypto.randomUUID(),sessionId:e.associationSessionId,...e.name!==void 0?{name:e.name}:{},...e.placement!==void 0?{placement:e.placement}:{}},t)}}class Sn{transport;workspaceId;id;targets;apps;clipboard;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.id=n;this.targets=new vn(e,t,n),this.apps=this.targets,this.clipboard=new wn(e,t,n)}async get(e={}){return await this.transport.getComputerSession(this.workspaceId,this.id,e)}async observe(e,t={}){return await this.transport.observeComputerTarget(this.workspaceId,this.id,e,t)}async capture(e,t={}){return await this.transport.captureComputerTarget(this.workspaceId,this.id,e,t)}async callNativeTool(e,t={}){if(!this.transport.callNativeComputerTool)throw Error(\\\"Native CUA tools require a current interaction transport\\\");return await this.transport.callNativeComputerTool(this.workspaceId,this.id,e,t)}async act(e,t={}){return await this.transport.actInComputer(this.workspaceId,this.id,e,t)}async nativeReceipt(e,t={}){if(!this.transport.getNativeComputerToolReceipt)throw Error(\\\"Native CUA receipts require a current interaction transport\\\");return await this.transport.getNativeComputerToolReceipt(this.workspaceId,this.id,e,t)}async receipt(e,t={}){return await this.transport.getComputerActionReceipt(this.workspaceId,this.id,e,t)}async attach(e,t={}){return await this.transport.attachComputerSession(this.workspaceId,this.id,e,t)}async inputPosture(e={}){if(!this.transport.getComputerInputPosture)throw Error(\\\"Computer input posture requires a current interaction transport.\\\");return await this.transport.getComputerInputPosture(this.workspaceId,this.id,e)}async heartbeat(e={}){return await this.transport.heartbeatComputerSession(this.workspaceId,this.id,e)}async end(e={operationId:crypto.randomUUID()},t={}){return await this.transport.endComputerSession(this.workspaceId,this.id,e,t)}}class wn{transport;workspaceId;computerSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.computerSessionId=n}async read(e={}){let t=await this.transport.readComputerClipboard(this.workspaceId,this.computerSessionId,e);if(t.computerSessionId!==this.computerSessionId)throw Error(\\\"Computer clipboard belongs to another ComputerSession\\\");return t}}class vn{transport;workspaceId;computerSessionId;constructor(e,t,n){this.transport=e;this.workspaceId=t;this.computerSessionId=n}async list(e={}){return await this.transport.listComputerTargets(this.workspaceId,this.computerSessionId,e)}}function kn(e){if(!xn(e))throw Error(\\\"browser frame metadata is invalid\\\");let t=new Set([\\\"frameId\\\",\\\"browserSessionId\\\",\\\"controllerGeneration\\\",\\\"targetId\\\",\\\"targetGeneration\\\",\\\"documentGeneration\\\",\\\"sequence\\\",\\\"mediaType\\\",\\\"width\\\",\\\"height\\\",\\\"deviceScaleFactor\\\",\\\"scrollX\\\",\\\"scrollY\\\",\\\"capturedAt\\\"]);if(Object.keys(e).some((r)=>!t.has(r)))throw Error(\\\"browser frame metadata contains unknown fields\\\");let n=[\\\"frameId\\\",\\\"browserSessionId\\\",\\\"controllerGeneration\\\",\\\"targetId\\\",\\\"targetGeneration\\\",\\\"documentGeneration\\\",\\\"mediaType\\\",\\\"capturedAt\\\"];for(let r of n){let o=e[r],a=r===\\\"targetId\\\"?512:r===\\\"capturedAt\\\"?128:256;if(typeof o!==\\\"string\\\"||o.length<1||Cn(o)>a)throw Error(\\\"browser frame metadata is invalid\\\")}let s=[\\\"sequence\\\",\\\"width\\\",\\\"height\\\",\\\"deviceScaleFactor\\\",\\\"scrollX\\\",\\\"scrollY\\\"];for(let r of s)if(typeof e[r]!==\\\"number\\\"||!Number.isFinite(e[r]))throw Error(\\\"browser frame metadata is invalid\\\");let i=e;if(!Number.isSafeInteger(i.sequence)||i.sequence<0||!Number.isSafeInteger(i.width)||!Number.isSafeInteger(i.height))throw Error(\\\"browser frame metadata integers are invalid\\\");if(An(i.width,i.height),i.deviceScaleFactor<=0||i.deviceScaleFactor>16||Math.abs(i.scrollX)>1e9||Math.abs(i.scrollY)>1e9)throw Error(\\\"browser frame geometry metadata is invalid\\\");if(i.mediaType!==\\\"image/jpeg\\\"&&i.mediaType!==\\\"image/png\\\")throw Error(\\\"browser frame media type is invalid\\\");if(!Pn(i.browserSessionId))throw Error(\\\"browser frame session id is invalid\\\");if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/u.test(i.controllerGeneration))throw Error(\\\"browser frame controller generation is invalid\\\");if(!Number.isFinite(new Date(i.capturedAt).valueOf()))throw Error(\\\"browser frame timestamp is invalid\\\");return i}function Zs(e){if(!xn(e))throw Error(\\\"computer frame metadata is invalid\\\");let t=new Set([\\\"frameId\\\",\\\"computerSessionId\\\",\\\"controllerGeneration\\\",\\\"targetId\\\",\\\"targetGeneration\\\",\\\"sequence\\\",\\\"mediaType\\\",\\\"width\\\",\\\"height\\\",\\\"capturedAt\\\",\\\"sha256\\\"]);if(Object.keys(e).some((i)=>!t.has(i)))throw Error(\\\"computer frame metadata contains unknown fields\\\");let n=[\\\"frameId\\\",\\\"computerSessionId\\\",\\\"controllerGeneration\\\",\\\"targetId\\\",\\\"targetGeneration\\\",\\\"mediaType\\\",\\\"capturedAt\\\",\\\"sha256\\\"];for(let i of n){let r=e[i],o=i===\\\"targetId\\\"?512:i===\\\"capturedAt\\\"?128:256;if(typeof r!==\\\"string\\\"||r.length<1||Cn(r)>o)throw Error(\\\"computer frame metadata is invalid\\\")}let s=e;if(!Number.isSafeInteger(s.sequence)||s.sequence<0||!Number.isSafeInteger(s.width)||!Number.isSafeInteger(s.height))throw Error(\\\"computer frame metadata integers are invalid\\\");if(An(s.width,s.height),s.mediaType!==\\\"image/jpeg\\\"&&s.mediaType!==\\\"image/png\\\")throw Error(\\\"computer frame media type is invalid\\\");if(!Pn(s.computerSessionId))throw Error(\\\"computer frame session id is invalid\\\");if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/u.test(s.controllerGeneration))throw Error(\\\"computer frame controller generation is invalid\\\");if(!Number.isFinite(new Date(s.capturedAt).valueOf()))throw Error(\\\"computer frame timestamp is invalid\\\");if(!/^[0-9a-f]{64}$/u.test(s.sha256))throw Error(\\\"computer frame digest is invalid\\\");return s}function In(e){if(!e||e.length>32768||!/^[A-Za-z0-9_-]+$/u.test(e))throw Error(\\\"computer frame metadata header is invalid\\\");let t=e.replace(/-/gu,\\\"+\\\").replace(/_/gu,\\\"/\\\"),n=t.padEnd(Math.ceil(t.length/4)*4,\\\"=\\\"),s;try{s=atob(n)}catch{throw Error(\\\"computer frame metadata header is invalid\\\")}let i=Uint8Array.from(s,(o)=>o.charCodeAt(0)),r;try{r=JSON.parse(new TextDecoder(\\\"utf-8\\\",{fatal:!0}).decode(i))}catch{throw Error(\\\"computer frame metadata header is invalid\\\")}return Zs(r)}function ei(e,t){let n=e.filter((s)=>![\\\"ending\\\",\\\"ended\\\",\\\"failed\\\",\\\"lost\\\"].includes(s.lifecycle)&&s.associations.some((i)=>i.sessionId===t));return n.sort((s,i)=>Qt(i,t)-Qt(s,t)),n[0]??null}function ti(e,t){let n=e.filter((s)=>[\\\"starting\\\",\\\"active\\\",\\\"restoring\\\"].includes(s.lifecycle)&&s.associations.some((i)=>i.sessionId===t));return n.sort((s,i)=>Zt(i,t)-Zt(s,t)),n[0]??null}function Qt(e,t){let n=e.associations.filter((i)=>i.sessionId===t).map((i)=>Date.parse(i.lastUsedAt)).filter(Number.isFinite).reduce((i,r)=>Math.max(i,r),0),s=Date.parse(e.lastUsedAt);return Math.max(n,Number.isFinite(s)?s:0)}function Zt(e,t){let n=e.associations.filter((i)=>i.sessionId===t).map((i)=>Date.parse(i.lastUsedAt)).filter(Number.isFinite).reduce((i,r)=>Math.max(i,r),0),s=Date.parse(e.lastUsedAt);return Math.max(n,Number.isFinite(s)?s:0)}function An(e,t){if(!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||e<1||t<1||e>Xt||t>Xt||e*t>Qs)throw Error(\\\"browser image dimensions exceed their bounded envelope\\\")}function Cn(e){return new TextEncoder().encode(e).byteLength}function Pn(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(e)}function xn(e){return typeof e===\\\"object\\\"&&e!==null&&!Array.isArray(e)}var oe=\\\"2026-09-plugins-and-skills-v1\\\",Ze=\\\"x-opengeni-api-contract\\\",Oe=\\\"x-opengeni-correlation-id\\\";var qe=1048576,Tn=33554432;var On=536870912;var _e=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,qn=/^[0-9a-f]{64}$/,En=/^\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}(?:\\\\.\\\\d+)?(?:Z|[+-]\\\\d{2}:\\\\d{2})$/,_n=/^\\\\/v1\\\\/workspaces\\\\/([0-9a-f-]+)\\\\/artifacts\\\\/([0-9a-f-]+)\\\\/content$/;function Gn(e,t){if(!ne(e,si))return null;let n=e;if(n.available!==!0||n.kind!==\\\"file\\\"||typeof n.artifactId!==\\\"string\\\"||!_e.test(n.artifactId)||typeof n.contentType!==\\\"string\\\"||!/^[a-z0-9][a-z0-9!#$&^_.+-]{0,62}\\\\/[a-z0-9][a-z0-9!#$&^_.+-]{0,62}$/.test(n.contentType)||!Ee(n.originalBytes,1,5000000000)||typeof n.sha256!==\\\"string\\\"||!qn.test(n.sha256)||typeof n.retainedAt!==\\\"string\\\"||n.retainedAt.length>64||!En.test(n.retainedAt)||!Number.isFinite(Date.parse(n.retainedAt))||!ne(n.retention,Un)||!ne(n.retrieval,Dn))return null;let s=n.retention;if(s.policy!==\\\"workspace_file\\\"||s.expiresAt!==null)return null;let i=n.retrieval;if(i.method!==\\\"GET\\\"||i.acceptRanges!==\\\"bytes\\\"||i.maxRangeBytes!==1048576||typeof i.path!==\\\"string\\\"||i.path.length>256)return null;let r=_n.exec(i.path);if(!r||!_e.test(r[1]??\\\"\\\")||r[2]!==n.artifactId||t!==void 0&&r[1]!==t)return null;return e}function Mn(e,t){if(!ne(e,ni))return null;let n=e;if(n.available!==!0||n.kind!==\\\"generated_image\\\"||typeof n.artifactId!==\\\"string\\\"||!_e.test(n.artifactId)||![\\\"image/png\\\",\\\"image/jpeg\\\",\\\"image/webp\\\"].includes(String(n.contentType))||!Ee(n.originalBytes,1,67108864)||typeof n.sha256!==\\\"string\\\"||!qn.test(n.sha256)||typeof n.retainedAt!==\\\"string\\\"||n.retainedAt.length>64||!En.test(n.retainedAt)||!Number.isFinite(Date.parse(n.retainedAt))||!ne(n.dimensions,ii)||!ne(n.retention,Un)||!ne(n.retrieval,Dn))return null;let s=n.dimensions;if(!Ee(s.width,1,16384)||!Ee(s.height,1,16384)||Number(s.width)*Number(s.height)>67108864)return null;let i=n.retention;if(i.policy!==\\\"workspace_file\\\"||i.expiresAt!==null)return null;let r=n.retrieval;if(r.method!==\\\"GET\\\"||r.acceptRanges!==\\\"bytes\\\"||r.maxRangeBytes!==1048576||typeof r.path!==\\\"string\\\"||r.path.length>256)return null;let o=_n.exec(r.path);if(!o||!_e.test(o[1]??\\\"\\\")||o[2]!==n.artifactId||t!==void 0&&o[1]!==t)return null;return e}var ni=new Set([\\\"available\\\",\\\"artifactId\\\",\\\"kind\\\",\\\"contentType\\\",\\\"originalBytes\\\",\\\"sha256\\\",\\\"retainedAt\\\",\\\"dimensions\\\",\\\"retention\\\",\\\"retrieval\\\"]),si=new Set([\\\"available\\\",\\\"artifactId\\\",\\\"kind\\\",\\\"contentType\\\",\\\"originalBytes\\\",\\\"sha256\\\",\\\"retainedAt\\\",\\\"retention\\\",\\\"retrieval\\\"]),ii=new Set([\\\"width\\\",\\\"height\\\"]),Un=new Set([\\\"policy\\\",\\\"expiresAt\\\"]),Dn=new Set([\\\"method\\\",\\\"path\\\",\\\"acceptRanges\\\",\\\"maxRangeBytes\\\"]);var ri=new Set([\\\"type\\\",\\\"sandboxPath\\\",\\\"filename\\\",\\\"artifact\\\"]),vo=new Set([...ri,\\\"access\\\"]);function ne(e,t){return e!==null&&typeof e===\\\"object\\\"&&!Array.isArray(e)&&Object.keys(e).length===t.size&&Object.keys(e).every((n)=>t.has(n))}function Ee(e,t,n){return Number.isSafeInteger(e)&&Number(e)>=t&&Number(e)<=n}function nt(e){let{limit:t,parentSessionId:n,scopeSubjectId:s}=e,i={};if(e.originSiteId)i.originSiteId=e.originSiteId;if(e.siteAccessId)i.siteAccessId=e.siteAccessId;if(t!==void 0)i.limit=String(t);if(n!==void 0)i.parentSessionId=n??\\\"null\\\";if(s!==void 0)i.scopeSubjectId=s;return i}var Gi=[\\\"siteAccessId\\\",\\\"originSiteId\\\",\\\"channelId\\\",\\\"createdBy\\\",\\\"updatedFrom\\\",\\\"updatedBefore\\\",\\\"createdFrom\\\",\\\"createdBefore\\\"],Mi=[\\\"updatedFrom\\\",\\\"updatedBefore\\\",\\\"createdFrom\\\",\\\"createdBefore\\\",\\\"sortBy\\\",\\\"archiveStatus\\\"];function Ui(e){return Boolean(e.needsYouOnly)||Boolean(e.contentArchivedOnly)||Boolean(e.mineOnly)||Gi.some((t)=>e[t]!==void 0)}function F(e){return Error(`The connected API does not support ${e}`)}function g(e,t){return`/v1/workspaces/${e}/sessions/${t}`}function Di(e){if(e.apiContract)return e.apiContract;return typeof window<\\\"u\\\"&&typeof document<\\\"u\\\"&&!e.apiKey?\\\"strict\\\":\\\"compatible\\\"}function Nn(e){let{associatedSessionId:t,includeTerminal:n,...s}=e;return{query:{...t?{associatedSessionId:t}:{},...n!==void 0?{includeTerminal:String(n)}:{}},request:s}}function Fn(e,t){let n,s,i=new Promise((r,o)=>{n=r,s=o});return{controller:new AbortController,consumers:0,generation:e,promise:i,resolve:n,reject:s,started:!1,listeners:new Set(t?[t]:[])}}function Jn(e){if(Object.prototype.hasOwnProperty.call(e,\\\"tools\\\"))throw TypeError(\\\"Message-level tools are not supported; update the session tool policy before sending.\\\")}function Vn(e){if(!(\\\"agentConfig\\\"in e)||!e.agentConfig?.machineTarget)return e;let{workingDir:t,...n}=e.agentConfig.machineTarget;if(t===void 0)return e;let s=t.trim();return{...e,agentConfig:{...e.agentConfig,machineTarget:{...n,...s?{workingDir:s}:{}}}}}function $i(e){return{forWorkspace(t){let n=t.trim();if(!n)throw TypeError(\\\"workspaceId is required\\\");let s,i=()=>s??=Promise.resolve().then(() => (Ae(),{})).then(({})=>new re(e).forWorkspace(n)),r=(o)=>new Proxy(async(...a)=>{let c=await i();for(let u of o)c=c[u];if(typeof c!==\\\"function\\\")throw TypeError(\\\"Tool path is not callable\\\");return await Reflect.apply(c,void 0,a)},{get:(a,c)=>{if(c===\\\"then\\\")return;if(typeof c!==\\\"string\\\")return;return r([...o,c])}});return new Proxy(Object.create(null),{get:(o,a)=>{if(a===\\\"$targetProtocol\\\")return e.toolGatewayMode===\\\"catalog\\\"?void 0:1;if(a===\\\"then\\\")return;if(typeof a!==\\\"string\\\")return;return r([a])}})}}}class st{get toolGatewayMode(){return this.options.toolGatewayMode??\\\"target\\\"}externalActorHeader;serviceInitiatorHeader;serviceContextHeader;baseUrl;options;fetchImpl;sessionCommandTimeoutMs;apiContractStrict;readRetryPolicy;active=new Map;generations=new Map;queued=new Map;interaction;tools;constructor(e){this.baseUrl=e.baseUrl.replace(/\\\\/+$/,\\\"\\\"),this.options=e,this.fetchImpl=Gt(e.fetch??((n,s)=>fetch(n,s)),e.onDeprecation);let t=e.sessionCommandTimeoutMs??15000;if(!Number.isFinite(t)||t<=0)throw RangeError(\\\"sessionCommandTimeoutMs must be a finite positive number\\\");this.sessionCommandTimeoutMs=t,this.apiContractStrict=Di(e)===\\\"strict\\\",this.readRetryPolicy=Ut(e.readRetry),this.interaction=new Xe(this),this.tools=$i(this)}async transcribeAudio(e,t){let n=crypto.randomUUID(),s=new FormData,i=zi(t.mimeType),r=t.audio instanceof File?t.audio:t.audio instanceof Uint8Array?new File([Uint8Array.from(t.audio)],i,{type:t.mimeType}):new File([t.audio],i,{type:t.mimeType||t.audio.type});if(s.append(\\\"audio\\\",r,i),s.append(\\\"mimeType\\\",t.mimeType),t.durationSeconds!==void 0)s.append(\\\"durationSeconds\\\",String(t.durationSeconds));let o;try{o=await this.fetchImpl(this.url(`/v1/workspaces/${e}/transcriptions`),{method:\\\"POST\\\",headers:{...this.headers(n),Accept:\\\"application/json\\\"},body:s,...t.signal?{signal:t.signal}:{}})}catch(c){if(t.signal?.aborted)throw c;throw ce(n)}if(D(o,this.apiContractStrict),!o.ok)throw await M(o,{method:\\\"POST\\\",correlationId:n});await fe(o,{method:\\\"POST\\\",correlationId:n});let a;try{a=await o.json()}catch{throw new P(o.status,\\\"Invalid transcription response.\\\",{code:\\\"invalid_response\\\",mutation:!0,correlationId:n})}if(!Bi(a))throw new P(o.status,\\\"Invalid transcription response.\\\",{code:\\\"invalid_response\\\",mutation:!0,correlationId:n});return a}async createTranscriptionRecording(e,t){return ye(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/transcription-recordings`,{recordingId:t.recordingId,mimeType:t.mimeType},{},t.signal?{signal:t.signal}:{}))}async getTranscriptionRecording(e,t,n={}){return ye(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/transcription-recordings/${t}`,void 0,{},n.signal?{signal:n.signal}:{}))}async listTranscriptionRecordings(e,t={}){let n=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/transcription-recordings`,void 0,{},t.signal?{signal:t.signal}:{});if(!Wi(n))throw A(\\\"Invalid transcription recording list response.\\\",{code:\\\"invalid_response\\\"});return n}async uploadTranscriptionRecordingChunk(e,t,n,s){let i=crypto.randomUUID(),r;try{r=await this.fetchImpl(this.url(`/v1/workspaces/${e}/transcription-recordings/${t}/chunks/${n}`),{method:\\\"PUT\\\",headers:{...this.headers(i),Accept:\\\"application/json\\\",\\\"Content-Type\\\":s.mimeType,\\\"x-opengeni-chunk-sha256\\\":s.sha256,\\\"x-opengeni-chunk-start-milliseconds\\\":String(s.startMilliseconds),\\\"x-opengeni-chunk-duration-milliseconds\\\":String(s.durationMilliseconds)},body:s.audio instanceof Uint8Array?Uint8Array.from(s.audio):s.audio,...s.signal?{signal:s.signal}:{}})}catch(a){if(s.signal?.aborted)throw a;throw ce(i)}if(D(r,this.apiContractStrict),!r.ok)throw await M(r,{method:\\\"PUT\\\",correlationId:i});await fe(r,{method:\\\"PUT\\\",correlationId:i});let o=await r.json().catch(()=>null);if(!Li(o))throw new P(r.status,\\\"Invalid transcription chunk response.\\\",{code:\\\"invalid_response\\\",mutation:!0,correlationId:i});return o}async finalizeTranscriptionRecording(e,t,n){return ye(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/transcription-recordings/${t}/finalize`,{chunkCount:n.chunkCount,totalBytes:n.totalBytes,totalDurationMilliseconds:n.totalDurationMilliseconds},{},n.signal?{signal:n.signal}:{}))}async processNextTranscriptionRecordingSegment(e,t,n={}){return ye(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/transcription-recordings/${t}/process-next`,{},{},n.signal?{signal:n.signal}:{}))}async discardTranscriptionRecording(e,t,n={}){return ye(await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/transcription-recordings/${t}`,void 0,{},n.signal?{signal:n.signal}:{}))}async createSession(e,t){let n=t.usageLimitMicros!==void 0&&t.usageLimitMicros!==null,s=n&&t.startMode===void 0?{...t,startMode:\\\"standard\\\"}:t,i;try{i=await this.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(e)}/sessions`,s)}catch(r){if(n&&s.startMode===\\\"standard\\\"&&r instanceof P&&yt(r))throw new pe(\\\"This server does not support task usage limits, so the session was not created. Create it without a usage limit, or upgrade the server.\\\",{sessionId:null,cause:r});throw r}return Fi(t.usageLimitMicros,i),i}async getSessionUsageLimit(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/sessions/${encodeURIComponent(t)}/usage-limit`,void 0,{},n)}async setSessionUsageLimit(e,t,n){let s=await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/sessions/${encodeURIComponent(t)}/usage-limit`,n);if(s.limitMicros!==n.limitMicros)throw ft(t);return s}async getNewSessionDraft(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/new-session-draft`,void 0,{},t)}async saveNewSessionDraft(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/new-session-draft`,t)}async getWorkspaceCredentialProvider(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/credential-provider`)}async putWorkspaceCredentialProvider(e,t){return this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/credential-provider`,t)}async deleteWorkspaceCredentialProvider(e){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/credential-provider`)}async listWorkspaceWebhooks(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/webhooks`)}async createWorkspaceWebhook(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/webhooks`,t)}async updateWorkspaceWebhook(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/webhooks/${t}`,n)}async deleteWorkspaceWebhook(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/webhooks/${t}`)}async listWorkspaceWebhookDeliveries(e,t,n={}){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/webhooks/${t}/deliveries`,void 0,n.limit!==void 0?{limit:String(n.limit)}:{})}async redeliverWorkspaceWebhookDelivery(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/webhooks/${t}/deliveries/${n}/redeliver`)}async listWorkspaceSandboxImages(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/sandbox-images`)}async createFeedback(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/feedback`,t)}async listOwnFeedback(e,t={}){let n=new URLSearchParams;if(t.sessionId)n.set(\\\"sessionId\\\",t.sessionId);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));if(t.includeTurns!==void 0)n.set(\\\"includeTurns\\\",String(t.includeTurns));return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/feedback${n.size?`?${n}`:\\\"\\\"}`)}async getSession(e,t,n={}){let s=g(e,t);return await this.sharedRead(s,(i)=>this.requestJson(\\\"GET\\\",s,void 0,{},{signal:i}),n)}async getToolActionReview(e,t,n){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/tool-reviews/${encodeURIComponent(n)}`)}async getToolReviewDetails(e,t,n,s){let i=new URLSearchParams({actionDigest:s.actionDigest,path:s.path??\\\"\\\",offset:String(s.offset??0)});return await this.requestJson(\\\"GET\\\",`${g(e,t)}/tool-reviews/${encodeURIComponent(n)}/details?${i}`)}async getSessionModelContext(e,t){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/model-context`)}async updateSession(e,t,n){return await this.requestJson(\\\"PATCH\\\",g(e,t),n)}async getSessionTenancyCreateCapabilities(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/session-tenancy/capabilities`)}async updateSessionVisibility(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/visibility`,n)}async previewSessionVisibilityChange(e,t,n){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/visibility/preview?visibility=${encodeURIComponent(n)}`)}async forkSession(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/forks`,n)}async updateSessionToolPolicy(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/tool-policy`,n)}async updateSessionAgent(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/agent`,n)}async updateSessionSkills(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/skills`,n)}async updateSessionMcpApprovalPolicy(e,t,n,s){return await this.requestJson(\\\"PATCH\\\",`${g(e,t)}/mcp-servers/${encodeURIComponent(n)}/approval-policy`,s)}async searchSessionMessages(e,t,n={}){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/session-message-search`,void 0,{query:t.query,...t.sessionId!==void 0?{sessionId:t.sessionId}:{},...t.groupBy!==void 0?{groupBy:t.groupBy}:{},...t.archiveStatus!==void 0?{archiveStatus:t.archiveStatus}:{},...t.limit!==void 0?{limit:String(t.limit)}:{},...t.cursor!==void 0?{cursor:t.cursor}:{}},n)}async getSessionMessagePreview(e,t,n,s={}){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/sessions/${encodeURIComponent(t)}/events/${encodeURIComponent(n.eventId)}/message-preview`,void 0,{sequence:String(n.sequence)},s)}async listSessions(e,t={}){if(t.search?.trim()||t.originSiteId){let n=await this.listSessionPage(e,t);return[...n.pinned,...n.sessions]}return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/sessions`,void 0,nt(t))}async listSessionBackgroundCommands(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/background-commands`,void 0,{},n)}async listWorkspaceBackgroundCommands(e,t={}){let n=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/sessions`,void 0,{view:\\\"running_commands\\\",...t.cursor?{cursor:t.cursor}:{}},t);if(!n||!Array.isArray(n.commands)||!(\\\"nextCursor\\\"in n))throw Error(\\\"This server does not support the workspace running commands view.\\\");return n}async cancelSessionBackgroundCommand(e,t,n){return await this.requestJson(\\\"DELETE\\\",`${g(e,t)}/background-commands/${n}`)}async listSessionPage(e,t={}){let n=await this.requestSessionPage(`/v1/workspaces/${e}/sessions`,t);if(\\\"projection\\\"in n)throw F(\\\"full session details\\\");return n}async listSessionSummaryPage(e,t={}){let n=await this.requestSessionPage(`/v1/workspaces/${e}/sessions`,t,!0);if(\\\"projection\\\"in n)return n;await Promise.resolve().then(() => zn());return{...n,projection:\\\"summary\\\",pinned:n.pinned.map(Me),sessions:n.sessions.map(Me)}}async requestSessionPage(e,t,n=!1){let s=t.search?.trim(),i;try{let c={view:\\\"page\\\",...nt(t)};if(n)c.projection=\\\"summary\\\";if(t.cursor!==void 0)c.cursor=t.cursor;if(s)c.search=s;if(t.channelId!==void 0)c.channelId=t.channelId??\\\"null\\\";if(t.createdBy)c.createdByKind=t.createdBy.kind,c.createdBySubjectId=t.createdBy.subjectId;for(let u of Mi){let l=t[u];if(l)c[u]=l}if(t.pinsOnly)c.pinsOnly=\\\"true\\\";if(t.includeTotals)c.includeTotals=\\\"true\\\";if(t.needsYouOnly)c.needsYouOnly=\\\"true\\\";if(t.contentArchivedOnly)c.contentArchivedOnly=\\\"true\\\";if(t.mineOnly)c.mineOnly=\\\"true\\\";if(t.includePinned===!1)c.includePinned=\\\"false\\\";if(t.archivedOnly)c.archivedOnly=\\\"true\\\";if(t.siteConversations)c.siteConversations=t.siteConversations;i=await this.requestJson(\\\"GET\\\",e,void 0,c,{signal:t.signal})}catch(c){if(c instanceof P&&c.status===410)throw new He(c.status,c.body,{...c.code?{code:c.code}:{},retryable:c.retryable,...c.correlationId?{correlationId:c.correlationId}:{},outcomeUnknown:c.outcomeUnknown,displayMessage:\\\"The session list changed — refresh and try again.\\\"});throw c}let r=i,o=Array.isArray(r),a=Ui(t);if(t.sortBy!==void 0&&(o||r.sortBy!==t.sortBy)||t.archiveStatus!==void 0&&(o||r.archiveStatus!==t.archiveStatus))throw F(\\\"the requested session sorting/archive filter\\\");if(o){let c=t.includeTotals?\\\"complete session totals\\\":t.cursor?\\\"stable session-page cursors\\\":s?\\\"session search\\\":t.pinsOnly?\\\"pins-only session lists\\\":t.archivedOnly?\\\"archived session lists\\\":a?\\\"filtered session lists\\\":null;if(c)throw F(c);return{pinned:[],sessions:r,nextCursor:null}}if(t.includeTotals&&r.totals===void 0)throw F(\\\"complete session totals\\\");if(t.needsYouOnly&&r.needsYouOnly!==!0)throw F(\\\"attention session filtering\\\");if(t.contentArchivedOnly&&r.contentArchivedOnly!==!0)throw F(\\\"read-only session filtering\\\");if(t.mineOnly&&r.mineOnly!==!0)throw F(\\\"your-sessions filtering\\\");if(a&&r.filtersApplied!==!0)throw F(\\\"filtered session lists\\\");if(t.originSiteId&&(!r.originSiteId||t.originSiteId!==\\\"current\\\"&&r.originSiteId!==t.originSiteId))throw F(\\\"Site-filtered session lists\\\");if(t.siteAccessId&&(!r.siteAccessId||t.siteAccessId!==\\\"current\\\"&&t.siteAccessId!==r.siteAccessId))throw F(\\\"Site access-filtered session lists\\\");return r}async recordSiteOpened(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/opened`)}async listSiteSessionAccess(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/session-access`)}async setSiteSessionAccess(e,t,n,s){return this.requestJson(s?\\\"PUT\\\":\\\"DELETE\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/session-access/${encodeURIComponent(n)}`)}async listAgentTopology(e,t={}){let n=t.query?.trim()||t.search?.trim();if(n&&t.subject)throw TypeError(\\\"listAgentTopology query cannot be combined with an exact subject\\\");let s=nt(t);if(t.rootSessionId)s.rootSessionId=t.rootSessionId;if(t.cursor)s.cursor=t.cursor;if(n)s.query=n;if(t.statuses?.length)s.statuses=t.statuses.join(\\\",\\\");if(t.activeOnly!==void 0)s.activeOnly=t.activeOnly?\\\"true\\\":\\\"false\\\";if(t.recentHours!==void 0)s.recentHours=String(t.recentHours);if(t.subject)s.subjectNamespace=t.subject.namespace,s.subjectType=t.subject.type,s.subjectKey=t.subject.canonicalKey;if(t.claimLimit!==void 0)s.claimLimit=String(t.claimLimit);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/agent-topology`,void 0,s)}async updateSessionPin(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/pin`,n)}async updateSessionAttention(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/attention`,n)}async updateSessionArchive(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/archive`,n)}async updateSessionRetention(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/retention`,n)}async deleteSession(e,t){return await this.requestJson(\\\"DELETE\\\",g(e,t))}async getSessionLineage(e,t,n={}){let s=`${g(e,t)}/lineage`;return await this.sharedRead(s,(i)=>this.requestJson(\\\"GET\\\",s,void 0,{},{signal:i}),n)}sharedRead(e,t,n={}){if(n.signal?.aborted)return Promise.reject(n.signal.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\"));let s=this.active.get(e);if(s){if(!n.fresh)return this.observeRead(s,n.onRequestStart),this.consumeSharedRead(e,s,n.signal);let c=s.generation+1,u=this.queued.get(e);if(u&&u.generation>=c)return this.observeRead(u,n.onRequestStart),this.consumeSharedRead(e,u,n.signal);let l=u?.promise??s.promise;return this.queueRead(e,l,c,t,n)}let i=this.queued.get(e);if(i&&(!n.fresh||!i.started))return this.observeRead(i,n.onRequestStart),this.consumeSharedRead(e,i,n.signal);if(i)return this.queueRead(e,i.promise,i.generation+1,t,n);let r=(this.generations.get(e)??0)+1,o=Fn(r,n.onRequestStart),a=this.consumeSharedRead(e,o,n.signal);return this.launchRead(e,o,t),a}queueRead(e,t,n,s,i){let r=Fn(n,i.onRequestStart),o=this.consumeSharedRead(e,r,i.signal);this.queued.set(e,r);let a=()=>this.launchRead(e,r,s);t.then(a,a);let c=()=>{if(this.queued.get(e)!==r)return;if(this.queued.delete(e),!this.active.has(e))this.generations.delete(e)};return r.promise.then(c,c),o}launchRead(e,t,n){if(t.controller.signal.aborted)return;t.started=!0,this.generations.set(e,t.generation),this.active.set(e,t);try{t.stamp=this.options.beginSharedRead?.()}catch{}for(let r of t.listeners)try{r(t.stamp)}catch{}t.listeners.clear();let s=()=>{if(this.active.get(e)!==t)return;if(this.active.delete(e),!this.queued.has(e))this.generations.delete(e)},i;try{i=n(t.controller.signal)}catch(r){s(),t.reject(r);return}i.then((r)=>{s(),t.resolve(r)},(r)=>{s(),t.reject(r)})}consumeSharedRead(e,t,n){t.consumers+=1;let s=!1,i=()=>{if(s)return;if(s=!0,t.consumers-=1,!n?.aborted||t.consumers>0)return;let o=n.reason;if(t.controller.abort(o),this.active.get(e)===t)this.active.delete(e);if(this.queued.get(e)===t)this.queued.delete(e);if(!this.active.has(e)&&!this.queued.has(e))this.generations.delete(e);t.reject(o)};return n?.addEventListener(\\\"abort\\\",i,{once:!0}),ae(t.promise,n).finally(()=>{n?.removeEventListener(\\\"abort\\\",i),i()})}observeRead(e,t){if(!t)return;if(!e.started){e.listeners.add(t);return}if(e.stamp===void 0)return;try{t(e.stamp)}catch{}}async negotiateCodexRealtimeWebrtc(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/webrtc`,n,{},{signal:s.signal})}async negotiateRealtimeWebsocket(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/websocket`,n,{},{signal:s.signal})}async negotiateGatewayRealtime(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/gateway`,n,{},{signal:s.signal})}async negotiateXaiSubscriptionRealtime(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/supergrok`,n,{},{signal:s.signal})}async activateCodexRealtimeConnection(e,t,n,s,i,r={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/${n}/connections/${s}/activate`,i,{},{signal:r.signal})}async beginSessionRealtime(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime`,n)}async heartbeatSessionRealtime(e,t,n,s){return await this.requestJson(\\\"PATCH\\\",`${g(e,t)}/realtime/${n}/heartbeat`,s)}async syncSessionRealtimeLedger(e,t,n,s){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/realtime/${n}/sync`,s)}async endSessionRealtime(e,t,n,s){return await this.requestJson(\\\"DELETE\\\",`${g(e,t)}/realtime/${n}`,s)}async listTurns(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/turns`,void 0,{...n.limit!==void 0?{limit:String(n.limit)}:{},...n.latestStarted?{latestStarted:\\\"1\\\"}:{}},{signal:n.signal})}async getLatestStartedTurn(e,t,n={}){return(await this.listTurns(e,t,{latestStarted:!0,signal:n.signal}))[0]??null}async listMachines(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/machines`,void 0,{...t.sessionId!==void 0?{sessionId:t.sessionId}:{}},{signal:t.signal})}async updateMachineAgent(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/machines/${t}/update`)}async enableMachineScreenControl(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/machines/${t}/screen-control`,{})}async openMachinePrivacySettings(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/machines/${t}/privacy-settings`,n)}async previewMachineAudience(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/machines/${t}/audience/preview`,n)}async changeMachineAudience(e,t,n){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/machines/${t}/audience`,n)}async updateMachineOperationPolicy(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/machines/${t}/operation-policy`,n)}async machineMetricsSeries(e,t,n={}){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/machines/${t}/metrics/series`,void 0,{...n.window!==void 0?{window:n.window}:{}})).samples}async removeEnrollment(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/enrollments/${t}/revoke`,n)}async lookupDeviceEnrollment(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/enrollments/device/lookup\\\",{userCode:e})}async approveDeviceEnrollment(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/enrollments/device/approve`,{userCode:t.userCode,allowScreenControl:t.allowScreenControl??!1,...t.scope?{scope:t.scope}:{}})}async denyDeviceEnrollment(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/enrollments/device/deny`,{userCode:t.userCode})}async mintEnrollToken(e,t={}){let n=\\\"scope\\\"in t?t.scope:void 0;return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/enrollments/token`,{allowScreenControl:t.allowScreenControl??!1,...n?{scope:n}:{}})}async swapActiveSandbox(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/active-sandbox`,n)}async listScheduledTasks(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-tasks`,void 0,{...t.offset!==void 0?{offset:String(t.offset)}:{},...t.sessionId?{sessionId:t.sessionId}:{},...t.limit!==void 0?{limit:String(t.limit)}:{}})}async getScheduledTask(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}`)}async listScheduledTaskSlackChannels(e,t,n){let s=new URLSearchParams({connectionId:t});if(n)s.set(\\\"cursor\\\",n);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-task-slack-channels?${s}`)}async listEvents(e,t,n={}){return(await this.listEventPage(e,t,n)).events}async listEventPage(e,t,n={}){if(n.latest&&[\\\"includeTypes\\\",\\\"excludeTypes\\\",\\\"includeClasses\\\",\\\"excludeClasses\\\"].some((x)=>Object.prototype.hasOwnProperty.call(n,x)))throw TypeError(\\\"latest cannot be combined with event filters\\\");if(n.resultMode===\\\"compact\\\"&&!n.latest)throw TypeError(\\\"resultMode=compact requires latest\\\");let s=n.resultMode===\\\"compact\\\"?null:n,i=crypto.randomUUID(),r=await this.fetchImpl(this.url(`${g(e,t)}/events`,{...s?.after!==void 0?{after:String(s.after)}:{},...s?.before!==void 0?{before:String(s.before)}:{},...s?.limit!==void 0?{limit:String(s.limit)}:{},...s?.compact?{compact:\\\"1\\\"}:{},...n.mode?{mode:n.mode}:{},...s?.direction?{direction:s.direction}:{},...n.payloadMode?{payloadMode:n.payloadMode}:{},...n.resultMode?{resultMode:n.resultMode}:{},...s?.includeTypes?.length?{includeTypes:s.includeTypes.join(\\\",\\\")}:{},...s?.excludeTypes?.length?{excludeTypes:s.excludeTypes.join(\\\",\\\")}:{},...s?.includeClasses?.length?{includeClasses:s.includeClasses.join(\\\",\\\")}:{},...s?.excludeClasses?.length?{excludeClasses:s.excludeClasses.join(\\\",\\\")}:{},...s?.presentedToolCalls===\\\"include\\\"?{presentedToolCalls:\\\"include\\\"}:{},...s?.toolOutputs===\\\"preview\\\"?{toolOutputs:\\\"preview\\\"}:{},...n.latest?{latest:n.latest}:{}}),{method:\\\"GET\\\",headers:{...this.headers(i),Accept:\\\"application/json\\\"}});if(D(r,this.apiContractStrict),!r.ok)throw await M(r,{method:\\\"GET\\\",correlationId:i});await fe(r,{method:\\\"GET\\\",correlationId:i});let o=await r.json();if(n.resultMode===\\\"compact\\\")return o;let a=o,c=(x)=>{let b=r.headers.get(x);if(b===null)return null;let h=Number(b);return Number.isSafeInteger(h)&&h>=0?h:null},u=r.headers.get(\\\"X-OpenGeni-Event-Mode\\\")===\\\"forensic\\\"?\\\"forensic\\\":\\\"monitoring\\\",l=r.headers.get(\\\"X-OpenGeni-Event-Direction\\\")===\\\"after\\\"?\\\"after\\\":\\\"before\\\",p=r.headers.get(\\\"X-OpenGeni-Payload-Mode\\\"),d=p===\\\"none\\\"||p===\\\"full\\\"?p:\\\"summary\\\",m=c(\\\"X-OpenGeni-Covered-First\\\"),y=c(\\\"X-OpenGeni-Covered-Last\\\"),R=c(\\\"X-OpenGeni-Page-Bytes\\\")??new TextEncoder().encode(JSON.stringify(a)).byteLength,w=c(\\\"X-OpenGeni-Page-Max-Bytes\\\")??1048576,S=r.headers.get(\\\"X-OpenGeni-Truncated-By\\\"),I=S===\\\"count\\\"||S===\\\"bytes\\\"||S===\\\"http_bytes\\\"?S:null;return{events:a,mode:u,payloadMode:d,direction:l,bytes:R,maxBytes:w,truncated:r.headers.get(\\\"X-OpenGeni-Page-Truncated\\\")===\\\"true\\\",hasMore:r.headers.get(\\\"X-OpenGeni-Has-More\\\")===\\\"true\\\",truncatedBy:I,coveredSequence:m===null||y===null?null:{first:m,last:y},nextAfter:c(\\\"X-OpenGeni-Next-After\\\"),nextBefore:c(\\\"X-OpenGeni-Next-Before\\\"),forensicExact:r.headers.get(\\\"X-OpenGeni-Forensic-Exact\\\")===\\\"true\\\",conversationFilter:c(Pt)}}async getLatestEventResult(e,t,n={latest:\\\"terminal\\\"}){return await this.listEventPage(e,t,{...n,resultMode:\\\"compact\\\"})}async sendEvent(e,t,n){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/events`,n)}async sendMessage(e,t,n){let s=typeof n===\\\"string\\\"?{text:n}:n;Jn(s);let{clientEventId:i,...r}=s;return await this.sendEvent(e,t,{type:\\\"user.message\\\",...i!==void 0?{clientEventId:i}:{},payload:r})}async pauseSession(e,t,n={}){return await this.controlSession(e,t,{action:\\\"pause\\\",clientEventId:n.clientEventId??crypto.randomUUID(),...n.reason?{reason:n.reason}:{},...n.expectedControlEtag?{expectedControlEtag:n.expectedControlEtag}:{}})}async sendApprovalDecision(e,t,n){let{clientEventId:s,...i}=n;return await this.sendEvent(e,t,{type:\\\"user.approvalDecision\\\",...s!==void 0?{clientEventId:s}:{},payload:i})}async listHumanInputRequests(e,t,n={}){let s=await this.requestJson(\\\"GET\\\",`${g(e,t)}/human-input-requests`,void 0,n.status?{status:n.status}:void 0);return Ct(s,s.requests),s.requests}async getHumanInputRequest(e,t,n){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/human-input-requests/${n}`)}async submitHumanInputResponse(e,t,n,s,i={}){return await this.sendEvent(e,t,{type:\\\"user.humanInputResponse\\\",...i.clientEventId?{clientEventId:i.clientEventId}:{},payload:{requestId:n,response:s}})}streamEvents(e,t,n={}){return qt(this.eventStreamTransport(e,t),n)}eventStreamTransport(e,t){return{openStream:async(n,s)=>await this.openEventStream(e,t,{after:n,...s?{signal:s}:{}}),listEvents:async(n,s)=>await this.listEvents(e,t,{after:n,limit:s})}}async openEventStream(e,t,n={}){let s=this.url(`${g(e,t)}/events/stream`,{after:String(n.after??0)}),i=crypto.randomUUID(),r=await this.fetchImpl(s,{method:\\\"GET\\\",headers:{...this.headers(i),Accept:\\\"text/event-stream\\\"},...n.signal?{signal:n.signal}:{}});if(D(r,this.apiContractStrict),!r.ok)throw await M(r,{method:\\\"GET\\\",correlationId:i});if(!r.body)throw new P(r.status,\\\"SSE response did not include a readable body\\\");return r.body}async getQueue(e,t){let n=`${g(e,t)}/queue`;return await this.sharedRead(n,()=>this.requestSessionCommand(\\\"GET\\\",n))}async moveQueueItem(e,t,n,s){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/queue/${n}/move`,s)}async editQueueItem(e,t,n,s){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/queue/${n}/edit`,s)}async steerQueueItem(e,t,n,s){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/queue/${n}/steer`,s)}async deleteQueueItem(e,t,n,s){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/queue/${n}/delete`,s)}async getComposerDraft(e,t,n={}){return await this.requestSessionCommand(\\\"GET\\\",`${g(e,t)}/composer-draft`,void 0,n)}async saveComposerDraft(e,t,n){return await this.requestSessionCommand(\\\"PUT\\\",`${g(e,t)}/composer-draft`,n)}async submitComposerDraft(e,t,n){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/composer-draft/submit`,n)}async getSandboxRecovery(e,t){return this.requestJson(\\\"GET\\\",`${g(e,t)}/sandbox-recovery`)}async recoverSandbox(e,t,n){return this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/sandbox-recovery`,n)}async retrySession(e,t,n){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/retry`,n)}async controlSession(e,t,n){return await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/control`,n)}async resumeSession(e,t,n={}){return await this.controlSession(e,t,{action:\\\"resume\\\",clientEventId:n.clientEventId??crypto.randomUUID(),...n.reason?{reason:n.reason}:{},...n.expectedControlEtag?{expectedControlEtag:n.expectedControlEtag}:{}})}async cancelSession(e,t,n={}){return await this.controlSession(e,t,{action:\\\"cancel\\\",clientEventId:n.clientEventId??crypto.randomUUID(),...n.reason?{reason:n.reason}:{},...n.expectedControlEtag?{expectedControlEtag:n.expectedControlEtag}:{}})}async setWorkspacePauseTimer(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/pause-timer`,t)}async setWorkspaceInferenceState(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/inference-control`,t)}async listWorkspaceControlEvents(e,t={}){return(await this.listWorkspaceControlEventPage(e,t)).events}async listWorkspaceControlEventPage(e,t={}){let n=crypto.randomUUID(),s=await this.fetchImpl(this.url(`/v1/workspaces/${e}/control-events`,{...t.after!==void 0?{after:String(t.after)}:{},...t.limit!==void 0?{limit:String(t.limit)}:{}}),{method:\\\"GET\\\",headers:{...this.headers(n),Accept:\\\"application/json\\\"}});if(D(s,this.apiContractStrict),!s.ok)throw await M(s,{method:\\\"GET\\\",correlationId:n});await fe(s,{method:\\\"GET\\\",correlationId:n});let i=await s.json(),r=s.headers.get(\\\"X-OpenGeni-Page-Bytes\\\"),o=s.headers.get(\\\"X-OpenGeni-Next-After\\\"),a=r===null?Number.NaN:Number(r),c=o===null?null:Number(o);return{events:i,bytes:Number.isSafeInteger(a)&&a>=0?a:new TextEncoder().encode(JSON.stringify(i)).byteLength,truncated:s.headers.get(\\\"X-OpenGeni-Page-Truncated\\\")===\\\"true\\\",nextAfter:c!==null&&Number.isSafeInteger(c)&&c>=0?c:null}}streamWorkspaceControlEvents(e,t={}){return Jt(this.workspaceControlStreamTransport(e),t)}streamWorkspaceLiveEvents(e,t={}){return jt(this.workspaceLiveStreamTransport(e),t)}workspaceLiveStreamTransport(e){return{openStream:async(t,n,s)=>await this.openWorkspaceLiveEventStream(e,{controlAfter:t,interactionAfter:n,...s?{signal:s}:{}})}}async openWorkspaceLiveEventStream(e,t={}){let n=crypto.randomUUID(),s=await this.fetchImpl(this.url(`/v1/workspaces/${e}/live-events/stream`,{controlAfter:String(t.controlAfter??0),interactionAfter:String(t.interactionAfter??0)}),{method:\\\"GET\\\",headers:{...this.headers(n),Accept:\\\"text/event-stream\\\"},...t.signal?{signal:t.signal}:{}});if(D(s,this.apiContractStrict),!s.ok)throw await M(s,{method:\\\"GET\\\",correlationId:n});if(!s.body)throw new P(s.status,\\\"SSE response did not include a readable body\\\");return s.body}workspaceControlStreamTransport(e){return{openStream:async(t,n)=>await this.openWorkspaceControlEventStream(e,{after:t,...n?{signal:n}:{}})}}async openWorkspaceControlEventStream(e,t={}){let n=crypto.randomUUID(),s=await this.fetchImpl(this.url(`/v1/workspaces/${e}/control-events/stream`,{after:String(t.after??0)}),{method:\\\"GET\\\",headers:{...this.headers(n),Accept:\\\"text/event-stream\\\"},...t.signal?{signal:t.signal}:{}});if(D(s,this.apiContractStrict),!s.ok)throw await M(s,{method:\\\"GET\\\",correlationId:n});if(!s.body)throw new P(s.status,\\\"SSE response did not include a readable body\\\");return s.body}async steerMessage(e,t,n){let s=typeof n===\\\"string\\\"?{text:n}:n;return Jn(s),await this.requestSessionCommand(\\\"POST\\\",`${g(e,t)}/steer`,s)}async getGoal(e,t,n={}){let s=`${g(e,t)}/goal`;return await this.sharedRead(s,(i)=>this.requestJson(\\\"GET\\\",s,void 0,{},{signal:i}),n)}async findGoal(e,t,n={}){let s=`${g(e,t)}/goal`,i={absent:\\\"null\\\"};return await this.sharedRead(`${s}?absent=null`,(r)=>this.requestJson(\\\"GET\\\",s,void 0,i,{signal:r}),n)}async updateGoal(e,t,n){return await this.requestJson(\\\"PATCH\\\",`${g(e,t)}/goal`,n)}async listGoalRevisions(e,t){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/goal/revisions`)}async listGoalRevisionPage(e,t,n={}){let s=new URLSearchParams;if(n.limit!==void 0)s.set(\\\"limit\\\",String(n.limit));if(n.before!==void 0)s.set(\\\"before\\\",n.before);let i=s.size>0?`?${s.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`${g(e,t)}/goal/revisions/page${i}`)}async rejectGoalRevision(e,t,n,s){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/goal/revisions/${n}/reject`,s)}async rollbackGoalRevision(e,t,n,s){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/goal/revisions/${n}/rollback`,s)}async applyGoalRevision(e,t,n,s){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/goal/revisions/${n}/apply`,s)}async deleteGoal(e,t){await this.requestVoid(\\\"DELETE\\\",`${g(e,t)}/goal`)}async pauseGoal(e,t,n={}){return await this.updateGoal(e,t,{status:\\\"paused\\\",...n.rationale!==void 0?{rationale:n.rationale}:{}})}async resumeGoal(e,t){return await this.updateGoal(e,t,{status:\\\"active\\\"})}async clearSessionContext(e,t){await this.requestVoid(\\\"POST\\\",`${g(e,t)}/context/clear`,{confirm:!0})}async compactSessionContext(e,t){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/context/compact`,{})}async fsList(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/list`,n,{},s)}async fsListBatch(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/list-batch`,n,{},s)}async fsRead(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",n.workspaceOnly?`${g(e,t)}/fs/read-workspace`:`${g(e,t)}/fs/read`,n,{},s)}async publishSandboxFileArtifact(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/artifacts/publish`,n,{},s)}async fsWrite(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/write`,n)}async fsDelete(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/delete`,n)}async fsMove(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/move`,n)}async fsMkdir(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/fs/mkdir`,n)}async gitStatus(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/git/status`,n,{},s)}async gitDiff(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/git/diff`,n,{},s)}async gitReadBatch(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/git/read-batch`,n,{},s)}async gitLog(e,t,n={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/git/log`,n)}async gitShow(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/git/show`,n)}async getWorkspaceCapture(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/workspace/capture`,void 0,{},n)}async getWorkspaceCaptureFile(e,t,n,s,i={}){let r={path:n};if(s!==void 0)r.revision=String(s);return await this.requestJson(\\\"GET\\\",`${g(e,t)}/workspace/capture/file`,void 0,r,i)}async terminalExec(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/terminal/exec`,n)}async terminalPtyOpen(e,t,n={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/terminal/pty`,n)}async terminalPtyWrite(e,t,n){await this.requestVoid(\\\"POST\\\",`${g(e,t)}/terminal/pty/write`,n)}async terminalPtyResize(e,t,n){await this.requestVoid(\\\"POST\\\",`${g(e,t)}/terminal/pty/resize`,n)}async terminalPtyClose(e,t,n){await this.requestVoid(\\\"POST\\\",`${g(e,t)}/terminal/pty/close`,n)}async getStreamCapabilities(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/stream-capabilities`,void 0,{},n)}async acknowledgeStream(e,t,n={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/stream-capabilities/acknowledge`,n)}async attachViewer(e,t,n={}){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/viewers`,n)}async heartbeatViewer(e,t,n,s){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/viewers/${n}/heartbeat`,s)}async detachViewer(e,t,n){await this.requestVoid(\\\"DELETE\\\",`${g(e,t)}/viewers/${n}`)}streamWorkspaceInteractionRevisions(e,t={}){return Ht(this.workspaceInteractionRevisionStreamTransport(e),t)}workspaceInteractionRevisionStreamTransport(e){return{openStream:async(t,n)=>await this.openWorkspaceInteractionRevisionStream(e,{after:t,...n?{signal:n}:{}})}}async openWorkspaceInteractionRevisionStream(e,t={}){let n=crypto.randomUUID(),s=await this.fetchImpl(this.url(`/v1/workspaces/${e}/interaction-events/stream`,{after:String(t.after??0)}),{method:\\\"GET\\\",headers:{...this.headers(n),Accept:\\\"text/event-stream\\\"},...t.signal?{signal:t.signal}:{}});if(D(s,this.apiContractStrict),!s.ok)throw await M(s,{method:\\\"GET\\\",correlationId:n});if(!s.body)throw new P(s.status,\\\"SSE response did not include a readable body\\\");return s.body}async listNetworkRoutes(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/network-routes`,void 0,t.includeArchived?{includeArchived:\\\"true\\\"}:{},t)}async getNetworkRoute(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/network-routes/${encodeURIComponent(t)}`,void 0,{},n)}async createNetworkRoute(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/network-routes`,t,{},n)}async updateNetworkRoute(e,t,n,s={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/network-routes/${encodeURIComponent(t)}`,n,{},s)}async listSiteAuthConnections(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/site-auth-connections`,void 0,t.includeArchived?{includeArchived:\\\"true\\\"}:{},t)}async getSiteAuthConnection(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/site-auth-connections/${encodeURIComponent(t)}`,void 0,{},n)}async createSiteAuthConnection(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/site-auth-connections`,t,{},n)}async updateSiteAuthConnection(e,t,n,s={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/site-auth-connections/${encodeURIComponent(t)}`,n,{},s)}async listAuthRuns(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/auth-runs`,void 0,{...t.browserSessionId?{browserSessionId:t.browserSessionId}:{},...t.siteAuthConnectionId?{siteAuthConnectionId:t.siteAuthConnectionId}:{},...t.includeSettled?{includeSettled:\\\"true\\\"}:{}},t)}async getAuthRun(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/auth-runs/${encodeURIComponent(t)}`,void 0,{},n)}async startBrowserAuthRun(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/auth-runs`,n,{},s)}async reportBrowserAuthRun(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/auth-runs/${encodeURIComponent(n)}/report`,s,{},i)}async advanceExternalBrowserAuthRun(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/auth-runs/${encodeURIComponent(n)}/external-auth`,s,{},i)}async openExternalBrowserAuthFlow(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/auth-runs/${encodeURIComponent(n)}/external-auth/interactive`,s,{},i)}async verifyBrowserAuthRun(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/auth-runs/${encodeURIComponent(n)}/verify`,s,{},i)}async listInteractionInterventions(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/interaction-interventions`,void 0,{...t.resourceKind?{resourceKind:t.resourceKind}:{},...t.resourceId?{resourceId:t.resourceId}:{},...t.includeSettled?{includeSettled:\\\"true\\\"}:{}},t)}async getInteractionIntervention(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/interaction-interventions/${encodeURIComponent(t)}`,void 0,{},n)}async createInteractionIntervention(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/interaction-interventions`,t,{},n)}async resolveInteractionIntervention(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/interaction-interventions/${encodeURIComponent(t)}/resolve`,n,{},s)}async listAttachedBrowsers(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/attached-browsers`,void 0,t.includeDisconnected?{includeDisconnected:\\\"true\\\"}:{},t)}async getAttachedBrowser(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/attached-browsers/${encodeURIComponent(t)}`,void 0,{},n)}async listBrowserIdentities(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-identities`,void 0,t.includeArchived?{includeArchived:\\\"true\\\"}:{},t)}async getBrowserIdentity(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-identities/${encodeURIComponent(t)}`,void 0,{},n)}async createBrowserIdentity(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-identities`,t,{},n)}async updateBrowserIdentity(e,t,n,s={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/browser-identities/${encodeURIComponent(t)}`,n,{},s)}async listBrowserRevisions(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-identities/${encodeURIComponent(t)}/revisions`,void 0,{},n)}async listBrowserSessions(e,t={}){let{query:n,request:s}=Nn(t);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions`,void 0,n,s)}async getBrowserSession(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}`,void 0,{},n)}async readBrowserClipboard(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/clipboard`,void 0,{},n)}async listBrowserDownloads(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/downloads`,void 0,{},n)}async getBrowserDownload(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/downloads/${encodeURIComponent(n)}`,void 0,{},s)}async saveBrowserDownload(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/downloads/${encodeURIComponent(n)}/save`,s,{},i)}async startBrowserRecording(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/recordings`,{targetId:n},{},s)}async getBrowserRecording(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/recordings/${encodeURIComponent(n)}`,void 0,{},s)}async saveBrowserRecording(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/recordings/${encodeURIComponent(n)}/save`,s,{},i)}async createBrowserSession(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions`,t,{},n)}async listBrowserTargets(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets`,void 0,{},n)}async openBrowserTarget(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets`,n,{},s)}async openBrowserTargetWithInventory(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/open-with-inventory`,n,{},s)}async selectBrowserTarget(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/select`,{},{},s)}async captureBrowserTarget(e,t,n,s={},i={}){let r=new URLSearchParams;if(i.fullPage!==void 0){if(typeof i.fullPage!==\\\"boolean\\\")throw TypeError(\\\"browser screenshot fullPage must be a boolean\\\");r.set(\\\"fullPage\\\",String(i.fullPage))}if(i.format!==void 0){if(i.format!==\\\"jpeg\\\"&&i.format!==\\\"png\\\")throw TypeError(\\\"browser screenshot format must be jpeg or png\\\");r.set(\\\"format\\\",i.format)}if(i.quality!==void 0){if(!Number.isSafeInteger(i.quality)||i.quality<1||i.quality>100)throw RangeError(\\\"browser screenshot quality must be an integer from 1 to 100\\\");r.set(\\\"quality\\\",String(i.quality))}let o=r.size>0?`?${r}`:\\\"\\\",a=await this.requestResponse(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/screenshot${o}`,{},s),c=a.headers.get(\\\"content-type\\\")?.split(\\\";\\\",1)[0]?.trim().toLowerCase(),u=a.headers.get(\\\"x-opengeni-browser-frame\\\");if(c!==\\\"image/jpeg\\\"&&c!==\\\"image/png\\\"||!u||u.length>65536)throw await U(a,\\\"browser frame metadata is invalid\\\"),A(\\\"browser frame metadata is invalid\\\");let l;try{l=kn(JSON.parse(atob(u.replace(/-/gu,\\\"+\\\").replace(/_/gu,\\\"/\\\"))))}catch{throw await U(a,\\\"browser frame metadata is invalid\\\"),A(\\\"browser frame metadata is invalid\\\")}let p=await he(a,25165824,null);if(l.browserSessionId!==t||l.targetId!==n||l.mediaType!==c)throw A(\\\"browser frame evidence does not match its request\\\");return{...l,data:p}}async closeBrowserTarget(e,t,n,s={}){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}`,void 0,{},s)}async observeBrowserTarget(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/observation`,void 0,{},s)}async getBrowserTargetState(e,t,n,s={}){let i=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/state`,void 0,{},s);if(i.browserSessionId!==t||i.targetId!==n)throw A(\\\"browser target state belongs to another binding\\\");return i}async readBrowserDom(e,t,n,s,i={}){let r=await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/dom-read`,s,{},i);if(r.browserSessionId!==t||r.targetId!==n||r.kind!==s.kind||r.targetGeneration!==s.expectedTargetGeneration||r.documentGeneration!==s.expectedDocumentGeneration||r.frameId!==s.expectedFrameId)throw A(\\\"browser DOM read belongs to another binding\\\");return r}async actInBrowser(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/actions`,n,{},s)}async getBrowserActionReceipt(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/operations/${encodeURIComponent(n)}`,void 0,{},s)}async listBrowserDiagnostics(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/diagnostics`,void 0,{...s.kinds?.length?{kinds:s.kinds.join(\\\",\\\")}:{},...s.after!==void 0?{after:String(s.after)}:{},...s.limit!==void 0?{limit:String(s.limit)}:{}},s.signal?{signal:s.signal}:{})}async attachBrowserSession(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/attachments`,n,{},s)}async heartbeatBrowserSession(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/heartbeat`,{},{},n)}async publishBrowserRevision(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/revisions`,n,{},s)}async suspendBrowserSession(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/suspend`,n,{},s)}async resumeBrowserSession(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/resume`,n,{},s)}async endBrowserSession(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/end`,n,{},s)}async inspectBrowserSessionWorkingCopy(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/working-copy/inspection`,{},{},n)}async adoptBrowserSessionWorkingCopy(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/working-copy/adoptions`,n,{},s)}async getBrowserSessionWorkingCopyAdoption(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/working-copy/adoptions/${encodeURIComponent(n)}`,void 0,{},s)}async revertBrowserSessionWorkingCopyAdoption(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/browser-sessions/${encodeURIComponent(t)}/working-copy/adoptions/${encodeURIComponent(n)}/revert`,{},{},s)}async listComputerSessions(e,t={}){let{query:n,request:s}=Nn(t);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions`,void 0,n,s)}async getComputerSession(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}`,void 0,{},n)}async readComputerClipboard(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/clipboard`,void 0,{},n)}async getComputerInputPosture(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/input-posture`,void 0,{},n)}async createComputerSession(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions`,t,{},n)}async listComputerTargets(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/targets`,void 0,{},n)}async observeComputerTarget(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/observation`,void 0,{},s)}async captureComputerTarget(e,t,n,s={}){let i=await this.requestResponse(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/targets/${encodeURIComponent(n)}/screenshot`,{},s),r=i.headers.get(\\\"content-type\\\")?.split(\\\";\\\",1)[0]?.trim().toLowerCase();if(r!==\\\"image/jpeg\\\"&&r!==\\\"image/png\\\")throw await U(i,\\\"computer frame media type is invalid\\\"),A(\\\"computer frame media type is invalid\\\");let o=i.headers.get(\\\"x-opengeni-computer-frame\\\");if(!o||o.length>32768)throw await U(i,\\\"computer frame metadata is invalid\\\"),A(\\\"computer frame metadata is invalid\\\");let a;try{a=In(o)}catch{throw await U(i,\\\"computer frame metadata is invalid\\\"),A(\\\"computer frame metadata is invalid\\\")}let c=await he(i,262144,null);if(Ki(a,{computerSessionId:t,targetId:n,mediaType:r,sha256:await Kn(c)}))throw A(\\\"computer frame evidence does not match its request\\\");return{...a,data:c}}async callNativeComputerTool(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/native-calls`,n,{},s)}async actInComputer(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/actions`,n,{},s)}async getNativeComputerToolReceipt(e,t,n,s={}){let i=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/operations/${encodeURIComponent(n)}`,void 0,{},s);if(i?.targetId!==null)throw Error(\\\"Expected a native computer receipt\\\");return i}async getComputerActionReceipt(e,t,n,s={}){let i=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/operations/${encodeURIComponent(n)}`,void 0,{},s);if(typeof i?.targetId!==\\\"string\\\")throw Error(\\\"Expected a computer action receipt\\\");return i}async attachComputerSession(e,t,n,s={}){let i=await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/attachments`,n,{},s);if(i.stream.kind===\\\"direct_rfb\\\")return{...i,stream:{...i.stream,inputAllowed:i.stream.inputAllowed===!0}};return i}async heartbeatComputerSession(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/heartbeat`,{},{},n)}async endComputerSession(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/computer-sessions/${encodeURIComponent(t)}/end`,n,{},s)}async getClientConfig(e={}){let t=await this.requestJson(\\\"GET\\\",\\\"/v1/config/client\\\",void 0,e.workspaceId===void 0?{}:{workspaceId:e.workspaceId},e);if(this.apiContractStrict&&t.apiContractRevision!==oe)throw new ve(oe,String(t.apiContractRevision||\\\"(missing)\\\"));return t}async getWorkspaceModelCatalog(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/model-catalog`,void 0,{},t)}async listWorkspaceGatewayCustomModels(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/gateway-custom-models`)}async createWorkspaceGatewayCustomModel(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/gateway-custom-models`,t)}async deleteWorkspaceGatewayCustomModel(e,t,n){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(t))throw TypeError(\\\"customModelId must be a UUID\\\");await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/gateway-custom-models/${encodeURIComponent(t)}`,n)}async listWorkspaceOpenRouterCustomModels(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/openrouter-custom-models`)}async createWorkspaceOpenRouterCustomModel(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/openrouter-custom-models`,t)}async deleteWorkspaceOpenRouterCustomModel(e,t,n){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(t))throw TypeError(\\\"customModelId must be a UUID\\\");await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/openrouter-custom-models/${encodeURIComponent(t)}`,n)}async listWorkspaceOpperCustomModels(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/opper-custom-models`)}async createWorkspaceOpperCustomModel(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/opper-custom-models`,t)}async deleteWorkspaceOpperCustomModel(e,t,n){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(t))throw TypeError(\\\"customModelId must be a UUID\\\");await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/opper-custom-models/${encodeURIComponent(t)}`,n)}async getWorkspaceClaudeSubscriptionUsage(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/model-providers/claude_subscription/usage`)}async getWorkspaceSubscriptionUsagePools(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/subscription-usage-pools`)}async getOrganizationSubscriptionUsagePools(e){return this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/subscription-usage-pools`)}async listClaudeSubscriptionAccounts(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/claude/accounts`)}async activateClaudeSubscriptionAccount(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}/activate`,{})}async setClaudeSubscriptionRotationSettings(e,t){return this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/claude/settings`,t)}async setClaudeSubscriptionAccountAllocator(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}/allocator`,n)}async renameClaudeSubscriptionAccount(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}`,{label:n})}async disconnectClaudeSubscriptionAccount(e,t){return this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}`,{})}async getClaudeSubscriptionAccountUsage(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}/usage`)}async refreshClaudeSubscriptionAccountUsage(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/claude/accounts/${encodeURIComponent(t)}/usage/refresh`,{})}async listOrganizationClaudeSubscriptionAccounts(e){return this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/claude/accounts`)}async activateOrganizationClaudeSubscriptionAccount(e,t){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}/activate`,{})}async setOrganizationClaudeSubscriptionRotationSettings(e,t){return this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/claude/settings`,t)}async setOrganizationClaudeSubscriptionAccountAllocator(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}/allocator`,n)}async renameOrganizationClaudeSubscriptionAccount(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}`,{label:n})}async disconnectOrganizationClaudeSubscriptionAccount(e,t){return this.requestJson(\\\"DELETE\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}`,{})}async getOrganizationClaudeSubscriptionAccountUsage(e,t){return this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}/usage`)}async refreshOrganizationClaudeSubscriptionAccountUsage(e,t){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/claude/accounts/${encodeURIComponent(t)}/usage/refresh`,{})}async connectClaudeSubscriptionSetupToken(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/claude/accounts/setup-token`,t)}async connectOrganizationClaudeSubscriptionSetupToken(e,t){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/claude/accounts/setup-token`,t)}async startWorkspaceClaudeSubscriptionOAuth(e,t={}){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/model-providers/claude_subscription/oauth/start`,t)}async completeWorkspaceClaudeSubscriptionOAuth(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/model-providers/claude_subscription/oauth/complete`,t)}async startOrganizationClaudeSubscriptionOAuth(e,t={}){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/model-providers/claude_subscription/oauth/start`,t)}async completeOrganizationClaudeSubscriptionOAuth(e,t){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/model-providers/claude_subscription/oauth/complete`,t)}async refreshWorkspaceClaudeSubscriptionUsage(e){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/model-providers/claude_subscription/usage/refresh`,{})}async getOrganizationClaudeSubscriptionUsage(e){return this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-providers/claude_subscription/usage`)}async refreshOrganizationClaudeSubscriptionUsage(e){return this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/model-providers/claude_subscription/usage/refresh`,{})}async getOrganizationModelProviderConnection(e,t){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-providers/${t}`)}async upsertOrganizationModelProviderConnection(e,t,n){return await this.requestJson(\\\"PUT\\\",`/v1/organizations/${e}/model-providers/${t}`,n)}async revokeOrganizationModelProviderConnection(e,t,n){return await this.requestJson(\\\"DELETE\\\",`/v1/organizations/${e}/model-providers/${t}`,n)}async listWorkspaceClaudeCustomModels(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/model-providers/${t}/custom-models`)}async createWorkspaceClaudeCustomModel(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/model-providers/${t}/custom-models`,n)}async deleteWorkspaceClaudeCustomModel(e,t,n,s){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(n))throw TypeError(\\\"customModelId must be a UUID\\\");await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/model-providers/${t}/custom-models/${encodeURIComponent(n)}`,s)}async listOrganizationProviderCustomModels(e,t){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-providers/${t}/custom-models`)}async createOrganizationProviderCustomModel(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/model-providers/${t}/custom-models`,n)}async deleteOrganizationProviderCustomModel(e,t,n,s){if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(n))throw TypeError(\\\"customModelId must be a UUID\\\");return await this.requestJson(\\\"DELETE\\\",`/v1/organizations/${e}/model-providers/${t}/custom-models/${encodeURIComponent(n)}`,s)}async getWorkspaceModelAccessPolicy(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/model-policy`)}async deleteWorkspaceModelAccessPolicy(e){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/model-policy`)}async getOrganizationModelDefaults(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-defaults`)}async updateOrganizationModelDefaults(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/model-defaults`,t)}async getOrganizationModelAccountSettings(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-account-settings`)}async updateOrganizationModelAccountSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/model-account-settings`,t)}async getModelAccountSettingsOverview(e,t={}){let n=new URLSearchParams;if(t.after!==void 0)n.set(\\\"after\\\",t.after);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/model-account-settings/overview${n.size?`?${n}`:\\\"\\\"}`)}async getWorkspaceModelAccountSettings(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/model-account-settings`)}async updateWorkspaceModelAccountSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/model-account-settings`,t)}async getSessionModelAccount(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/sessions/${t}/model-account`)}async setSessionModelAccount(e,t,n){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/sessions/${t}/model-account`,n)}async getModelAccountPreferences(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/me/model-account-preferences`)}async updateModelAccountPreferences(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/me/model-account-preferences`,t)}async getOrganizationAgentAdminAccess(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/agent-admin-access`)}async updateOrganizationAgentAdminAccess(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/agent-admin-access`,t)}async getOrganizationPrivacySettings(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/privacy-settings`)}async updateOrganizationPrivacySettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/privacy-settings`,t)}async updateWorkspaceModelAccessPolicy(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/model-policy`,t)}async getWorkspaceRealtimeModelCatalog(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/realtime-model-catalog`,void 0,{},t)}async getAccessContext(){return await this.requestJson(\\\"GET\\\",\\\"/v1/access/me\\\")}async listOrganizationMemberships(){return await this.requestJson(\\\"GET\\\",\\\"/v1/organization-memberships\\\")}async listUserResourceAuthorities(e,t){let n=new URLSearchParams({scope:\\\"user\\\",resourceKind:t.resourceKind});if(t.cursor)n.set(\\\"cursor\\\",t.cursor);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/user-resource-authorities?${n.toString()}`)}async revokeUserResourceGrant(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/user-resource-authorities/grants/${t}?scope=user`)}async createOrganization(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/organizations\\\",e)}async createAdditionalOrganization(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/organizations/additional\\\",e)}async listOrganizationInvitations(e={}){let t=new URLSearchParams;if(e.cursor)t.set(\\\"cursor\\\",e.cursor);if(e.limit!==void 0)t.set(\\\"limit\\\",String(e.limit));let n=t.size>0?`?${t.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/organization-invitations${n}`)}async listOrganizationInvitationsForOrganization(e,t={}){let n=new URLSearchParams;if(t.cursor)n.set(\\\"cursor\\\",t.cursor);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.size>0?`?${n.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/invitations${s}`)}async createOrganizationInvitation(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/invitations`,t)}async acceptOrganizationInvitation(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organization-invitations/${e}/accept`,t)}async revokeOrganizationInvitation(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/invitations/${t}/revoke`,n)}async listOrganizationAdministrationMembers(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/members`)}async listOrganizationMembers(e){return await this.listOrganizationAdministrationMembers(e)}async getOrganizationAdministrationOverview(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/overview`)}async createOrganizationWorkspace(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/workspaces`,t)}async updateOrganizationWorkspace(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/workspaces/${t}`,n)}async updateOrganizationWorkspaceSettings(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/workspaces/${t}/settings`,n)}async deleteOrganizationWorkspace(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/organizations/${e}/workspaces/${t}`)}async putOrganizationWorkspaceMember(e,t,n,s){return await this.requestJson(\\\"PUT\\\",`/v1/organizations/${e}/workspaces/${t}/members/${n}`,s)}async revokeOrganizationWorkspaceMember(e,t,n,s){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/workspaces/${t}/members/${n}/revoke`,s)}async updateOrganizationName(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}`,t)}async updateOrganizationMember(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/members/${t}`,n)}async getOrganizationRetentionPolicy(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/retention-policy`)}async updateOrganizationRetentionPolicy(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/retention-policy`,t)}async getOrganizationRecovery(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/recovery`)}async configureOrganizationRecoveryPolicy(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/organizations/${e}/recovery/policy`,t)}async acceptOrganizationRecoveryCustody(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/policy/accept`,t)}async disableOrganizationRecoveryPolicy(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/policy/disable`,t)}async startOrganizationRecoveryOperation(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/operations`,t)}async approveOrganizationRecoveryOperation(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/operations/${t}/approve`,n)}async cancelOrganizationRecoveryOperation(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/operations/${t}/cancel`,n)}async executeOrganizationRecoveryOperation(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/recovery/operations/${t}/execute`,n)}async searchPublicSkills(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/skills/search?q=${encodeURIComponent(t)}`)}async listWorkspaces(){return await this.requestJson(\\\"GET\\\",\\\"/v1/workspaces\\\")}connectTransport(){let e=(t)=>`/v1/workspaces/${encodeURIComponent(t)}/connect`;return{catalog:(t,n)=>this.requestJson(\\\"GET\\\",`${e(t)}/catalog`,void 0,void 0,n),accounts:(t,n)=>this.requestJson(\\\"GET\\\",`${e(t)}/accounts`,void 0,void 0,n),pending:(t,n)=>this.requestJson(\\\"GET\\\",`${e(t)}/attempts`,void 0,void 0,n),begin:(t,n,s)=>this.requestJson(\\\"POST\\\",`${e(t)}/attempts`,n,void 0,s),get:(t,n,s)=>this.requestJson(\\\"GET\\\",`${e(t)}/attempts/${encodeURIComponent(n)}`,void 0,void 0,s),advance:(t,n,s,i)=>this.requestJson(\\\"POST\\\",`${e(t)}/attempts/${encodeURIComponent(n)}/advance`,s,void 0,i),cancel:(t,n,s,i)=>this.requestJson(\\\"POST\\\",`${e(t)}/attempts/${encodeURIComponent(n)}/cancel`,s,void 0,i),disconnect:async(t,n,s)=>{if(n.startsWith(\\\"social:\\\")){let o=n.slice(7);if(!/^[0-9a-f-]{36}$/i.test(o))throw Error(\\\"Invalid social account ID\\\");await this.disconnectSocialConnection(t,o);return}if(n.startsWith(\\\"lens-registration:\\\")){let o=n.slice(18);if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(o))throw Error(\\\"Invalid Lens registration ID\\\");await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${encodeURIComponent(t)}/pr-review/registrations/${o}`,void 0,void 0,s);return}if(n.startsWith(\\\"github-installation:\\\")){let o=n.slice(20);if(!/^[1-9][0-9]*$/.test(o)||!Number.isSafeInteger(Number(o)))throw Error(\\\"Invalid GitHub installation ID\\\");await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${encodeURIComponent(t)}/github/installations/${o}`,void 0,void 0,s);return}let i=s?.expectedVersion;if(i!==void 0&&(!Number.isSafeInteger(i)||i<1))throw Error(\\\"invalid expected connection version\\\");let r=i===void 0?\\\"\\\":`?expectedVersion=${i}`;await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${encodeURIComponent(t)}/connections/${encodeURIComponent(n)}${r}`,void 0,void 0,s)}}}async browseAtlassianSources(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/atlassian/${t}/browse`)}async saveAtlassianSources(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/atlassian/${t}/source`,n)}async setAtlassianLifecycle(e,t,n){return this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/connections/atlassian/${t}/lifecycle`,n)}async beginConnect(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connect/attempts`,t)}async createWorkspace(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/workspaces\\\",e)}async ensureWorkspace(e){return await this.requestJson(\\\"PUT\\\",\\\"/v1/workspaces/external\\\",e)}async getWorkspace(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}`)}async getWorkspaceState(e,t={}){let n=new URLSearchParams;if(t.attemptId)n.set(\\\"attemptId\\\",t.attemptId);let s=n.size>0?`?${n.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/workspace-state${s}`)}async exportWorkspaceState(e,t={}){let n=new URLSearchParams;if(t.attemptId)n.set(\\\"attemptId\\\",t.attemptId);let s=n.size>0?`?${n.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/workspace-state/export${s}`)}async updateWorkspace(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}`,t)}async listWorkspaceInstructionPolicies(e,t={}){let n=new URLSearchParams;if(t.kind!==void 0)n.set(\\\"kind\\\",t.kind);if(t.scope!==void 0)n.set(\\\"scope\\\",t.scope);if(t.roleKey!==void 0)n.set(\\\"roleKey\\\",t.roleKey);if(t.afterRevision!==void 0)n.set(\\\"afterRevision\\\",String(t.afterRevision));if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.toString();return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/instruction-policies${s?`?${s}`:\\\"\\\"}`)}async getWorkspaceLearningHistory(e,t={}){let n=new URLSearchParams;if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.toString();return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/learning${s?`?${s}`:\\\"\\\"}`)}async undoGovernedLearningActivation(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/learning/activations/${encodeURIComponent(t)}/undo`,n)}async getWorkspaceInstructionPolicyRevision(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/instruction-policies/${encodeURIComponent(t)}`)}async createWorkspaceInstructionPolicyDraft(e,t,n={}){return await this.requestSessionCommand(\\\"POST\\\",`/v1/workspaces/${e}/instruction-policies/drafts`,t,n)}async listWorkspaceInstructionPolicyOnboardingProposals(e,t={}){let n=new URLSearchParams;if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.toString();return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/instruction-policies/onboarding-proposals${s?`?${s}`:\\\"\\\"}`)}async createWorkspaceInstructionPolicyOnboardingProposal(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/instruction-policies/onboarding-proposals`,t)}async importLegacyWorkspaceInstructionPolicyDraft(e,t={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/instruction-policies/import-legacy`,t)}async diffWorkspaceInstructionPolicyRevisions(e,t){let n=new URLSearchParams({fromRevisionId:t.fromRevisionId,toRevisionId:t.toRevisionId});return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/instruction-policies/diff?${n}`)}async activateWorkspaceInstructionPolicyRevision(e,t,n,s={}){return await this.requestSessionCommand(\\\"POST\\\",`/v1/workspaces/${e}/instruction-policies/${encodeURIComponent(t)}/activate`,n,s)}async rollbackWorkspaceInstructionPolicyRevision(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/instruction-policies/rollback`,t)}async listCompanyProfile(e,t={}){let n=new URLSearchParams;if(t.afterRevision!==void 0)n.set(\\\"afterRevision\\\",String(t.afterRevision));if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.toString();return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/company-profile${s?`?${s}`:\\\"\\\"}`)}async getCompanyProfileRevision(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/company-profile/revisions/${encodeURIComponent(t)}`)}async getCompanyProfileAgentPolicy(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/company-profile/agent-policy`)}async updateCompanyProfileAgentPolicy(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/company-profile/agent-policy`,t)}async updateCompanyProfile(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/company-profile`,t)}async diffCompanyProfileRevisions(e,t){let n=new URLSearchParams(t);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/company-profile/diff?${n}`)}async activateCompanyProfileRevision(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/company-profile/revisions/${encodeURIComponent(t)}/activate`,n)}async rollbackCompanyProfile(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/company-profile/rollback`,t)}async listPreferenceRegistry(e,t={}){let n=new URLSearchParams;if(t.scope)n.set(\\\"scope\\\",t.scope);if(t.status)n.set(\\\"status\\\",t.status);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));let s=n.toString();return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/preferences${s?`?${s}`:\\\"\\\"}`)}async getPreferenceRegistry(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}`)}async createPreferenceRegistryProposal(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/proposals`,t)}async activatePreferenceRegistryRevision(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/activate`,n)}async correctPreferenceRegistry(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/correct`,n)}async changePreferenceRegistryScope(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/scope`,n)}async deactivatePreferenceRegistry(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/deactivate`,n)}async supersedePreferenceRegistry(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/supersede`,n)}async rejectPreferenceRegistryProposal(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/${encodeURIComponent(t)}/reject`,n)}async getPreferenceRegistrySummary(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/preferences/summary`)}async getPreferenceRegistryFullContent(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/preferences/full-content`,{retrievalHandle:t})}async deleteWorkspace(e){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}`)}async listWorkspaceMembers(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/members`)).members}async listWorkspaceMemberCandidates(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/member-candidates`)).members}async addWorkspaceMember(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/members`,t)}async updateWorkspaceMember(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/members/${encodeURIComponent(t)}`,n)}async removeWorkspaceMember(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/members/${encodeURIComponent(t)}`)}async prepareSlackUserLinkAccess(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/slack/user-link-intents`,t)}async getSlackUserLinkAccess(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/slack/user-link-intents/${t}`)}async requestSlackUserLinkWorkspaceAccess(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/slack/user-link-intents/${t}/request-access`,n)}async cancelSlackUserLinkAccess(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/slack/user-link-intents/${t}/cancel`,n)}async listSlackUserLinkAccessRequests(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/members/access-requests/slack`)).requests}async approveSlackUserLinkAccessRequest(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/members/access-requests/slack/${t}/approve`,n)}async denySlackUserLinkAccessRequest(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/members/access-requests/slack/${t}/deny`,n)}async createScheduledTask(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks`,Vn(t))}async updateScheduledTask(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}`,Vn(n))}async pauseScheduledTask(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}/pause`)}async listPrivateScheduledTaskSummaries(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-tasks/private-summaries`)}async pausePrivateScheduledTask(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks/private-summaries/${t}/pause`)}async resumeScheduledTask(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}/resume`)}async triggerScheduledTask(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}/trigger`,n.triggerId?{triggerId:n.triggerId}:void 0)}async deleteScheduledTask(e,t){await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}`)}async listScheduledTaskRuns(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}/runs`,void 0,{...n.limit!==void 0?{limit:String(n.limit)}:{}})}async refreshScheduledTaskAccess(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/scheduled-tasks/${t}/refresh-access`,n)}async listScheduledTaskAccessAttention(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/scheduled-tasks/attention`)).tasks}vaults(e){return xt(this,e)}async listChannels(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/channels`)}async createChannel(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/channels`,t)}async updateChannel(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/channels/${t}`,n)}async reorderChannels(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/channels/order`,t)}async deleteChannel(e,t){await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/channels/${t}`)}async updateSessionChannel(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/channel`,n)}async listRigs(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/rigs`)}async createRig(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs`,t)}async getRig(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/rigs/${t}`)}async updateRig(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/rigs/${t}`,n)}async deleteRig(e,t){await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/rigs/${t}`)}async listRigVersions(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/rigs/${t}/versions`)}async activateRigVersion(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs/${t}/versions/${n}/activate`)}async listRigChanges(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/rigs/${t}/changes`)}async proposeRigChange(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs/${t}/changes`,n)}async getRigChange(e,t,n){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/rigs/${t}/changes/${n}`)}async verifyRigChange(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs/${t}/changes/${n}/verify`)}async promoteRigChange(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs/${t}/changes/${n}/promote`)}async verifyRig(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/rigs/${t}/verify`)}async beginFileUpload(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/files/uploads`,t,{},n)}async completeFileUpload(e,t,n={}){return(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/files/uploads/${t}/complete`,void 0,{},n)).file}async uploadFile(e,t){if(t.timeoutMs!==void 0&&(!Number.isFinite(t.timeoutMs)||t.timeoutMs<=0))throw Error(\\\"File upload timeout must be a positive number\\\");Vi();let n=async(u,l)=>{let p=new AbortController,d,m=new Promise((y,R)=>{d=setTimeout(()=>{p.abort(),R(Error(\\\"File upload timed out. Retry the upload.\\\"))},u)});try{return await Promise.race([l(p.signal),m])}finally{if(d!==void 0)clearTimeout(d)}},s=t.data instanceof Uint8Array?new Blob([t.data.slice()]):t.data instanceof ArrayBuffer?t.data.slice(0):t.data,i=typeof s===\\\"string\\\"?new TextEncoder().encode(s).byteLength:s instanceof Blob?s.size:s.byteLength,r=t.sha256??await Hi(s),o=await n(30000,async(u)=>await this.beginFileUpload(e,{filename:t.filename,contentType:t.contentType,...t.scope?{scope:t.scope}:{},sizeBytes:i,sha256:r,...t.appShot?{appShot:t.appShot}:{}},{signal:u})),a=t.timeoutMs??Math.max(120000,Math.ceil(i/262144)*1000),c=await n(a,async(u)=>await this.fetchImpl(o.putUrl,{method:\\\"PUT\\\",credentials:\\\"omit\\\",headers:{...o.requiredHeaders},body:s,signal:u}));if(!c.ok)throw await M(c,{method:\\\"PUT\\\"});return await n(30000,async(u)=>await this.completeFileUpload(e,o.uploadId,{signal:u}))}async listFiles(e,t={}){let n=new URLSearchParams;if(t.scope)n.set(\\\"scope\\\",t.scope);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));if(t.cursor)n.set(\\\"cursor\\\",t.cursor);return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/files${n.size?`?${n}`:\\\"\\\"}`)}async updateFileVisibility(e,t,n,s={}){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/files/${encodeURIComponent(t)}/visibility`,n,void 0,s)}async getFile(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/files/${t}${n.sessionId?`?sessionId=${encodeURIComponent(n.sessionId)}`:\\\"\\\"}`,void 0,{},n)}async getRetainedArtifact(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/artifacts/${t}`)}async getRetainedArtifactContent(e,t,n={}){return await this.getRetainedArtifactContentAtPath(`/v1/workspaces/${e}/artifacts/${t}/content`,n)}async getSessionRetainedArtifact(e,t,n){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/artifacts/${n}`)}async getSessionRetainedArtifactContent(e,t,n,s={}){return await this.getRetainedArtifactContentAtPath(`${g(e,t)}/artifacts/${n}/content`,s)}async downloadRetainedArtifact(e,t,n={}){jn(e,t);let s=await this.downloadRetainedArtifactBytes(t,n);return{artifact:t,bytes:s}}async createRetainedArtifactDownloadUrl(e,t,n={}){jn(e,t);let s=await this.createFileDownloadUrl(e,t.artifactId,n);return Xn(s),s}async downloadRetainedScreenshot(e,t,n,s={}){let i=await this.getSessionRetainedArtifact(e,t,n);if(!i.available)return{metadata:i,bytes:null};if(!((i.kind===\\\"computer_screenshot\\\"||i.kind===\\\"browser_screenshot\\\")&&[\\\"image/png\\\",\\\"image/jpeg\\\",\\\"image/webp\\\"].includes(i.contentType))||!i.dimensions||i.originalBytes<=0||i.originalBytes>Tn)throw A(\\\"retained screenshot metadata is invalid\\\");let o=await this.downloadRetainedArtifactBytes(i,s);return{metadata:i,bytes:o}}async downloadRetainedArtifactBytes(e,t){let n=t.maxRetries??2;if(!Number.isInteger(n)||n<0||n>3)throw RangeError(\\\"retained artifact maxRetries must be an integer from 0 to 3\\\");let s=new Uint8Array(e.originalBytes),i=Math.min(e.retrieval.maxRangeBytes,qe);if(!Number.isSafeInteger(i)||i<=0)throw A(\\\"retained artifact range metadata is invalid\\\");for(let r=0;r<s.byteLength;r+=i){t.signal?.throwIfAborted();let o=Math.min(r+i,s.byteLength)-1,a=null;for(let u=0;u<=n;u+=1)try{a=await this.getRetainedArtifactContentAtPath(e.retrieval.path,{range:`bytes=${r}-${o}`,...t.signal?{signal:t.signal}:{}});break}catch(l){if(t.signal?.throwIfAborted(),u>=n||l instanceof P&&l.status>=400&&l.status<500)throw l}if(!a)throw A(\\\"retained artifact range retry exhausted\\\");let c=o-r+1;if(a.status!==206||a.contentType!==e.contentType||a.contentLength!==c||a.contentRange!==`bytes ${r}-${o}/${e.originalBytes}`)throw A(\\\"retained artifact range response is invalid\\\");s.set(a.bytes,r)}if(await Kn(s)!==e.sha256)throw A(\\\"retained artifact checksum mismatch\\\");return s}async getRetainedArtifactContentAtPath(e,t){if(t.range&&(t.range.length>128||/[^\\\\x20-\\\\x7e]/.test(t.range)))throw RangeError(\\\"retained artifact range must be at most 128 printable ASCII bytes\\\");let n=crypto.randomUUID(),s=await this.fetchImpl(this.url(e),{method:\\\"GET\\\",headers:{...this.headers(n),Accept:\\\"application/octet-stream\\\",...t.range?{Range:t.range}:{}},...t.signal?{signal:t.signal}:{}});try{D(s,this.apiContractStrict)}catch(o){throw await U(s,\\\"retained artifact API contract mismatch\\\"),o}if(!s.ok)throw await M(s,{method:\\\"GET\\\",correlationId:n});if(s.status!==200&&s.status!==206)throw await U(s,\\\"unexpected retained artifact response status\\\"),new P(s.status,\\\"unexpected retained artifact response status\\\");if(s.headers.get(\\\"accept-ranges\\\")!==\\\"bytes\\\")throw await U(s,\\\"retained artifact response omitted byte-range support\\\"),A(\\\"retained artifact response omitted byte-range support\\\");let i;try{i=Yi(s.headers.get(\\\"content-length\\\"))}catch(o){throw await U(s,\\\"invalid retained artifact content-length\\\"),o}let r=await he(s,qe,i);return{bytes:r,status:s.status,contentType:s.headers.get(\\\"content-type\\\")??\\\"application/octet-stream\\\",contentLength:r.byteLength,contentRange:s.headers.get(\\\"content-range\\\"),acceptRanges:\\\"bytes\\\"}}async createFileDownloadUrl(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/files/${t}/download-url${n.sessionId?`?sessionId=${encodeURIComponent(n.sessionId)}`:\\\"\\\"}`,void 0,{},n)}async getVideoGenerationSettings(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/video-generation`,void 0,{},t)}async updateVideoGenerationPolicy(e,t,n={}){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/video-generation/policy`,t,{},n)}async getVideoGenerationOperation(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/video-generation/operations/${t}`,void 0,{},n)}async createVideoArtifactPlaybackSource(e,t,n={}){let s=await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/artifacts/${t}/playback-source`,void 0,{},n);return ji(s,t),s}async createDocumentBase(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/document-bases`,t)}async getDocumentBase(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/document-bases/${t}`)}async addDocument(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/document-bases/${t}/documents`,n)}async listDocuments(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/document-bases/${t}/documents`)}async getDocumentOriginalFile(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/documents/${t}/original-file`)}async createKnowledgeDrop(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/drops`,t)}async moveDocument(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/documents/${t}/move`,n)}async deleteDocument(e,t,n){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/document-bases/${t}/documents/${n}`)}async listKnowledgeEntries(e,t={}){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/search`,t)}async getKnowledgeEntry(e,t,n={}){let s=new URLSearchParams;if(n.revisionId!==void 0)s.set(\\\"revisionId\\\",n.revisionId);if(n.view!==void 0)s.set(\\\"view\\\",n.view);let i=s.toString();return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/knowledge/entries/${t}${i?`?${i}`:\\\"\\\"}`)}async createKnowledgeFileDownloadUrl(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/${t}/file/download-url`,n?{revisionId:n}:{})}async saveKnowledgeEntry(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries`,t)}async reviewKnowledgeEntry(e,t){let{entryId:n,...s}=t;return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/${n}/review`,s)}async listKnowledgeReviewBatches(e,t={}){let n=new URLSearchParams;for(let[s,i]of Object.entries(t))if(i!==void 0)n.set(s,String(i));return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/knowledge/review-groups?${n}`)}async reviewKnowledgeEntries(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/review`,t)}async listKnowledgeEntryHistory(e,t,n){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/knowledge/entries/${t}/history${n?`?beforeRevision=${n}`:\\\"\\\"}`)}async restoreKnowledgeEntry(e,t){let{entryId:n,...s}=t;return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/${n}/restore`,s)}async archiveKnowledgeEntry(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/knowledge/entries/${t}/archive`,n)}async getAgentLearningSettings(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/agent-learning/read`,{scope:t,source:n})}async saveAgentLearningSettings(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/agent-learning`,t)}async listAgentLearningOverrides(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/agent-learning/overrides?scope=${t}`)}async reviewAgentInstruction(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/agent-learning/instructions/review`,t)}async listAgentInstructionReviews(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/agent-learning/instructions/reviews${t?`?cursor=${encodeURIComponent(t)}`:\\\"\\\"}`)}async updateWorkspaceSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/settings`,t)}async setWorkspaceDefaultRig(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/default-rig`,t)}async listCapabilities(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/capabilities`)}async createCapability(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/capabilities`,t)}async getConnectorToolPermissions(e,t,n={}){let s=new URLSearchParams;if(n.connectionId)s.set(\\\"connectionId\\\",n.connectionId);if(n.instanceKey)s.set(\\\"instanceKey\\\",n.instanceKey);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/capabilities/${encodeURIComponent(t)}/tool-permissions${s.size?`?${s}`:\\\"\\\"}`,void 0,{},n)}async updateConnectorToolPermissions(e,t,n,s={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/capabilities/${encodeURIComponent(t)}/tool-permissions`,n,{},s)}async getSessionMcpToolPermissions(e,t,n={}){let s=new URLSearchParams({serverId:t.serverId,url:t.url});return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/session-mcp-tool-permissions?${s}`,void 0,{},n)}async updateSessionMcpToolPermissions(e,t,n={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/session-mcp-tool-permissions`,t,{},n)}async enableCapability(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/capabilities/${encodeURIComponent(t)}/enable`,n)}async disableCapability(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/capabilities/${encodeURIComponent(t)}/disable`)}async listArtifactCatalog(e,t={}){let n=new URLSearchParams;for(let i of[\\\"sourceSessionId\\\",\\\"q\\\",\\\"kind\\\",\\\"sort\\\",\\\"status\\\",\\\"limit\\\",\\\"cursor\\\"])if(t[i]!==void 0)n.set(i,String(t[i]));let s=n.size?`?${n.toString()}`:\\\"\\\";return this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/artifact-catalog${s}`,void 0,void 0,t)}async updateArtifactPin(e,t,n,s,i={}){return this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/artifact-catalog/${encodeURIComponent(t)}/${encodeURIComponent(n)}/pin`,{pinned:s},void 0,i)}async listWorkspaceArtifacts(e,t={}){let n=new URLSearchParams;if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));if(t.cursor)n.set(\\\"cursor\\\",t.cursor);if(t.status)n.set(\\\"status\\\",t.status);if(t.sourceSessionId)n.set(\\\"sourceSessionId\\\",t.sourceSessionId);let s=n.size>0?`?${n.toString()}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts${s}`,void 0,void 0,t)}async getWorkspaceArtifact(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}`,void 0,void 0,n)}async getWorkspaceArtifactHtml(e,t,n){return(await this.requestResponse(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/html`,{versionId:n.versionId},n)).text()}async rollbackWorkspaceArtifact(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/rollback`,n,void 0,s)}async duplicateWorkspaceArtifact(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/duplicate`,n,void 0,s)}async setWorkspaceArtifactStatus(e,t,n,s={}){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/status`,n,void 0,s)}async updateWorkspaceArtifactVisibility(e,t,n,s={}){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}/visibility`,n,void 0,s)}async getSiteData(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${O(e,t)}/data`,void 0,void 0,n)}async defineSiteDataCollection(e,t,n,s,i={}){return await this.requestJson(\\\"PUT\\\",`${O(e,t)}/data/collections/${encodeURIComponent(n)}`,s,void 0,i)}async deleteSiteDataCollection(e,t,n,s={}){return await this.requestJson(\\\"DELETE\\\",`${O(e,t)}/data/collections/${encodeURIComponent(n)}`,void 0,{confirm:\\\"true\\\"},s)}async resetSiteDataCollection(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${O(e,t)}/data/collections/${encodeURIComponent(n)}/reset`,{confirm:!0},void 0,s)}async querySiteData(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${O(e,t)}/data/query`,n,void 0,s)}async writeSiteData(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${O(e,t)}/data/write`,n,void 0,s)}async importSiteData(e,t,n,s,i={}){return await this.requestJson(\\\"POST\\\",`${O(e,t)}/data/collections/${encodeURIComponent(n)}/import`,s,void 0,i)}async exportSiteData(e,t,n,s={}){let i=s.format??\\\"json\\\",r=await this.requestResponse(\\\"GET\\\",`${O(e,t)}/data/collections/${encodeURIComponent(n)}/export`,{format:i},{...s,accept:i===\\\"csv\\\"?\\\"text/csv\\\":\\\"application/json\\\"});return{content:await r.text(),contentType:r.headers.get(\\\"content-type\\\")??\\\"\\\",truncated:r.headers.get(\\\"x-opengeni-export-truncated\\\")===\\\"true\\\"}}async listSiteDataFiles(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${O(e,t)}/files`,void 0,{...n.limit===void 0?{}:{limit:String(n.limit)},...n.cursor?{cursor:n.cursor}:{}},n)}async getSiteDataFileUrl(e,t,n,s={}){return await this.requestJson(\\\"GET\\\",`${O(e,t)}/files/${encodeURIComponent(n)}`,void 0,void 0,s)}async deleteSiteDataFile(e,t,n,s={}){return await this.requestJson(\\\"DELETE\\\",`${O(e,t)}/files/${encodeURIComponent(n)}`,void 0,void 0,s)}async getSiteSql(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${O(e,t)}/sql`,void 0,void 0,n)}async updateSiteSqlSettings(e,t,n,s={}){return await this.requestJson(\\\"PUT\\\",`${O(e,t)}/sql/settings`,n,void 0,s)}async migrateSiteSql(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${O(e,t)}/sql/migrations`,n,void 0,s)}async defineSiteSqlQuery(e,t,n,s,i={}){return await this.requestJson(\\\"PUT\\\",`${O(e,t)}/sql/queries/${encodeURIComponent(n)}`,s,void 0,i)}async deleteSiteSqlQuery(e,t,n,s={}){return await this.requestJson(\\\"DELETE\\\",`${O(e,t)}/sql/queries/${encodeURIComponent(n)}`,void 0,void 0,s)}async runSiteSqlQuery(e,t,n,s={},i={}){return await this.requestJson(\\\"POST\\\",`${O(e,t)}/sql/queries/${encodeURIComponent(n)}`,s,void 0,i)}async querySiteSql(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${O(e,t)}/sql/query`,n,void 0,s)}async executeSiteSql(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${O(e,t)}/sql/execute`,n,void 0,s)}async inspectSiteSql(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${O(e,t)}/sql/inspect`,void 0,void 0,n)}async exportSiteSql(e,t,n={}){let s=n.format??\\\"sql\\\",i=await this.requestResponse(\\\"GET\\\",`${O(e,t)}/sql/export`,{format:s,...n.table?{table:n.table}:{},...n.cursor?{cursor:n.cursor}:{},...n.maxBytes!==void 0?{maxBytes:String(n.maxBytes)}:{}},{...n,accept:s===\\\"json\\\"?\\\"application/json\\\":\\\"*/*\\\"});return{content:await i.text(),contentType:i.headers.get(\\\"content-type\\\")??\\\"\\\",truncated:i.headers.get(\\\"x-opengeni-export-truncated\\\")===\\\"true\\\",nextCursor:i.headers.get(\\\"x-opengeni-export-next-cursor\\\")||null}}async importSiteSql(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${O(e,t)}/sql/import`,n,void 0,s)}async resetSiteSql(e,t,n={},s={}){return await this.requestJson(\\\"POST\\\",`${O(e,t)}/sql/reset`,{confirm:!0,...n},void 0,s)}async getSitePublication(e,t,n={}){return await this.requestJson(\\\"GET\\\",X(e,t),void 0,void 0,n)}async updateSitePublication(e,t,n,s={}){return await this.requestJson(\\\"PUT\\\",X(e,t),n,void 0,s)}async unpublishSite(e,t,n={}){return await this.requestJson(\\\"DELETE\\\",X(e,t),void 0,void 0,n)}async applySitePublicationFix(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${X(e,t)}/fixes`,n,void 0,s)}async getSitePlatformUsage(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/site-platform-usage`,void 0,void 0,t)}async checkSiteHostname(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/site-hostnames/${encodeURIComponent(t)}`,void 0,void 0,n)}async takeDownSite(e,t,n,s={}){return await this.requestJson(\\\"POST\\\",`${X(e,t)}/takedown`,n,void 0,s)}async restoreSite(e,t,n={}){return await this.requestJson(\\\"POST\\\",`${X(e,t)}/restore`,{},void 0,n)}async listSiteAbuseReports(e,t,n={}){return await this.requestJson(\\\"GET\\\",`${X(e,t)}/reports`,void 0,void 0,n)}async updateSiteAbuseReport(e,t,n,s,i={}){return await this.requestJson(\\\"PATCH\\\",`${X(e,t)}/reports/${encodeURIComponent(n)}`,s,void 0,i)}async getSiteLimitProfile(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/site-limit-profile`,void 0,void 0,t)}async updateSiteLimitProfile(e,t,n={}){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/site-limit-profile`,t,void 0,n)}async authorizeSiteViewer(e,t={}){return await this.requestJson(\\\"POST\\\",\\\"/v1/site-auth/authorize\\\",e,void 0,t)}async discoverMcpCapabilities(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/capabilities/discovery/mcp-registry`,void 0,{...t.query!==void 0?{query:t.query}:{},...t.limit!==void 0?{limit:String(t.limit)}:{}})}async discoverPlugins(e,t={}){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/capabilities/discovery/plugins`,void 0,{...t.id?{id:t.id}:{},...t.query?{query:t.query}:{},...t.provider?{provider:t.provider}:{},...t.offset!==void 0?{offset:String(t.offset)}:{}})}async inspectMcpAuthentication(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/capabilities/discovery/mcp-auth`,{url:t})}async listApiIntegrations(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations`)}async listIntegrationDefinitions(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/definitions`)}async previewApiIntegration(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/preview`,t)}async startApiIntegrationOAuth(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/oauth/start`,t)}async installApiIntegration(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/install`,t)}async previewApiIntegrationUninstall(e,t,n){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/uninstall-preview`)}async uninstallApiIntegration(e,t,n,s){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}`,s)}async listIntegrationFacets(e,t,n){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets`)}async configureIntegrationFacet(e,t,n,s,i){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets/${encodeURIComponent(s)}`,i)}async browseGoogleDriveFacetSource(e,t,n,s,i={}){let r=new URLSearchParams;if(i.parentId)r.set(\\\"parentId\\\",i.parentId);if(i.pageToken)r.set(\\\"pageToken\\\",i.pageToken);let o=r.size>0?`?${r}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets/${encodeURIComponent(s)}/browse${o}`)}async saveGoogleDriveFacetSource(e,t,n,s,i){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets/${encodeURIComponent(s)}/source`,i)}async pauseIntegrationFacet(e,t,n,s,i){return await this.mutateIntegrationFacetLifecycle(e,t,n,s,\\\"pause\\\",i)}async resumeIntegrationFacet(e,t,n,s,i){return await this.mutateIntegrationFacetLifecycle(e,t,n,s,\\\"resume\\\",i)}async removeIntegrationFacet(e,t,n,s,i){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets/${encodeURIComponent(s)}`,i)}async mutateIntegrationFacetLifecycle(e,t,n,s,i,r){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/integrations/${encodeURIComponent(t)}/instances/${encodeURIComponent(n)}/facets/${encodeURIComponent(s)}/${i}`,r)}async previewPlugin(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/plugins/preview`,t)}async getInstalledPluginDetails(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/plugins/details`,void 0,{pluginKey:t})}async listInstalledPlugins(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/plugins`)}async installPlugin(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/plugins/install`,t)}async previewPluginUninstall(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/plugins/${encodeURIComponent(t)}/uninstall-preview`)}async uninstallPlugin(e,t,n){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/plugins/${encodeURIComponent(t)}`,n)}async previewSkillImport(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/preview`,t)}async installSkill(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/install`,t)}async listInstalledSkills(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/skills`)}async listWorkspaceSkills(e,t={}){let n=new URLSearchParams;if(t.cursor!==void 0)n.set(\\\"cursor\\\",t.cursor);if(t.limit!==void 0)n.set(\\\"limit\\\",String(t.limit));if(t.sessionId!==void 0)n.set(\\\"sessionId\\\",t.sessionId);let s=n.size?`?${n.toString()}`:\\\"\\\";return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/skills/content${s}`)}async readWorkspaceSkill(e,t,n){let s=n?`?revisionId=${encodeURIComponent(n)}`:\\\"\\\";return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/skills/content/${encodeURIComponent(t)}${s}`)}async saveWorkspaceSkill(e,t){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/content/save`,t)}async removeWorkspaceSkill(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/content/${encodeURIComponent(t)}/remove`,n)}async approveWorkspaceSkill(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/content/${encodeURIComponent(t)}/approve`,n)}async restoreWorkspaceSkill(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/content/${encodeURIComponent(t)}/restore`,n)}async rejectWorkspaceSkill(e,t,n){return this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/content/${encodeURIComponent(t)}/reject`,n)}async installLibrarySkill(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/skills/library/${encodeURIComponent(t)}/install`,n)}async previewSkillUninstall(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/skills/${encodeURIComponent(t)}/uninstall-preview`)}async uninstallSkill(e,t,n){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/skills/${encodeURIComponent(t)}`,n)}async listOwnConnectionAccounts(e,t={}){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/accounts`,void 0,t.includeInactive===!0?{includeInactive:\\\"true\\\"}:{})).connections}async listConnections(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections`)).connections}async personalGitHubStatus(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/github`)}async startPersonalGitHubOAuth(e,t={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/github/oauth/start`,t)}async reconnectPersonalGitHub(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/${t}/github/reconnect`,n)}async disconnectPersonalGitHub(e,t,n){return(await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/connections/${t}`,n)).connection}async listPersonalGitHubRepositories(e,t,n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/${t}/github/repositories`,void 0,{...n.cursor!==void 0?{cursor:String(n.cursor)}:{},...n.limit!==void 0?{limit:String(n.limit)}:{}})}async replacePersonalGitHubRepositorySelections(e,t,n){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/connections/${t}/github/repositories`,n)}async verifyPersonalGitHubRepositorySelections(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/${t}/github/repositories/verify`,n)}async listSlackInstallationBindings(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/slack-bot/bindings`)).bindings}async createConnection(e,t){return(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections`,t)).connection}async installFikenConnection(e,t){return(await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/fiken/install`,t)).connection}async startFikenOAuth(e,t={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/fiken/oauth/start`,t)}async listAvailableOpenGeniSlackBots(e){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/slack-bot/available`)}async getOpenGeniSlackBotOrganizationAccess(e,t){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/connections/${t}/slack-bot/organization-access`)}async setOpenGeniSlackBotOrganizationAccess(e,t,n){return this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/connections/${t}/slack-bot/organization-access`,n)}async startOpenGeniSlackBotInstall(e,t={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/slack-bot/install`,t)}async listOpenGeniSlackReactionChannels(e,t,n){let s=new URLSearchParams({connectionId:t});if(n)s.set(\\\"cursor\\\",n);return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/slack/reaction-channels?${s}`)}async listOpenGeniSlackChannelRoutes(e,t){let n=new URLSearchParams({connectionId:t});return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/integrations/slack/channel-routes?${n}`)}async updateOpenGeniSlackChannelRoutes(e,t){await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${e}/integrations/slack/channel-routes`,t)}async updateConnection(e,t,n){return(await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/connections/${t}`,n)).connection}async deleteConnection(e,t){return(await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/connections/${t}`)).connection}async disconnectGoogleDriveConnection(e,t,n){return(await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/connections/${t}`,n)).connection}async transitionGoogleDriveLifecycle(e,t,n){return(await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/connections/google-drive/${t}/lifecycle`,n)).connection}async startConnectionOAuth(e,t,n={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/connections/oauth/start`,t,{},n)}async startSocialOAuth(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/social/oauth/start`,t)}async listSocialConnections(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/social/connections`)}async disconnectSocialConnection(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/social/connections/${t}`)}catalogAssetUrl(e){return e?`${this.baseUrl}/v1/${e}`:null}async downloadCatalogAsset(e,t={}){if(!/^catalog-assets\\\\/[a-zA-Z0-9_./-]+$/.test(e)||e.split(\\\"/\\\").some((r)=>!r||r===\\\".\\\"||r===\\\"..\\\"))throw TypeError(\\\"A catalog asset path is required\\\");let n=await this.requestResponse(\\\"GET\\\",`/v1/${e}`,{},t),s=n.headers.get(\\\"content-type\\\")?.split(\\\";\\\")[0]??\\\"\\\";if(!s.startsWith(\\\"image/\\\"))throw await n.body?.cancel(),Error(\\\"The catalog asset is not an image\\\");let i=await he(n,2000000,null);return new Blob([Uint8Array.from(i)],{type:s})}async getGitHubApp(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/github/app`,void 0,t.returnPath?{returnPath:t.returnPath}:void 0)}githubConnectUrl(e,t){return this.url(`/v1/workspaces/${e}/github/connect`,{state:t})}async listGitHubRepositories(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/github/repositories`)}async getGitHubActionPolicies(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/github/action-policies`)}async updateGitHubActionPolicy(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/github/action-policies`,t)}async syncGitHubRepositories(e){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/github/repositories/sync`)}async unlinkGitHubInstallation(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/workspaces/${e}/github/installations/${t}`)}async createGitHubAppManifest(e,t={}){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/github/app-manifest`,t)}async listApiKeys(e){return(await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/api-keys`)).apiKeys}async createApiKey(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/api-keys`,t)}async deleteApiKey(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/api-keys/${t}`)}async listOrganizationApiKeys(e){return(await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/api-keys`)).apiKeys}async createOrganizationApiKey(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/api-keys`,t)}async deleteOrganizationApiKey(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/organizations/${e}/api-keys/${t}`)}async listOrganizationMcpConnections(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/mcp-connections`)}async updateOrganizationMcpConnection(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/mcp-connections/${t}`,n)}async deleteOrganizationMcpConnection(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/organizations/${e}/mcp-connections/${t}`,{})}async listPersonalApiKeys(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/personal-api-keys`)}async createPersonalApiKey(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/personal-api-keys`,t)}async revokePersonalApiKey(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/organizations/${e}/personal-api-keys/${t}`,{})}async listOrganizationServiceAccounts(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/service-accounts`)}async getOrganizationServiceAccount(e,t){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/service-accounts/${t}`)}async createOrganizationServiceAccount(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/service-accounts`,t)}async updateOrganizationServiceAccount(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/service-accounts/${t}`,n)}async deleteOrganizationServiceAccount(e,t){await this.requestVoid(\\\"DELETE\\\",`/v1/organizations/${e}/service-accounts/${t}`)}async getMcpConnectionRequest(e){return await this.requestJson(\\\"GET\\\",`/v1/mcp-connections/requests/${encodeURIComponent(e)}`)}async answerMcpConnectionRequest(e,t){return await this.requestJson(\\\"POST\\\",`/v1/mcp-connections/requests/${encodeURIComponent(e)}`,t)}async listInbox(e={}){let t=e.workspaceId?`?workspaceId=${encodeURIComponent(e.workspaceId)}`:\\\"\\\";return await this.requestJson(\\\"GET\\\",`/v1/inbox${t}`)}async updateInboxItem(e,t){await this.requestJson(\\\"PATCH\\\",`/v1/inbox/items/${encodeURIComponent(e)}`,t)}async getInboxSettings(){return await this.requestJson(\\\"GET\\\",\\\"/v1/inbox/settings\\\")}async updateInboxSettings(e){return await this.requestJson(\\\"PUT\\\",\\\"/v1/inbox/settings\\\",e)}async getMemberNotifications(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/inbox/member-notifications`)}async updateMemberNotifications(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/workspaces/${encodeURIComponent(e)}/inbox/member-notifications`,t)}async getSessionInboxMute(e,t){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/inbox-mute`)}async setSessionInboxMute(e,t,n){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/inbox-mute`,n)}async getSessionAdminAccess(e,t){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/admin-access`)}async grantSessionAdminAccess(e,t,n={}){return await this.requestJson(\\\"PUT\\\",`${g(e,t)}/admin-access`,n)}async revokeSessionAdminAccess(e,t){return await this.requestJson(\\\"DELETE\\\",`${g(e,t)}/admin-access`)}async authorizeNativeApp(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/native-app/authorize\\\",e)}async exchangeNativeAppCode(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/native-app/token\\\",e)}async createOfficeWorkbookTicket(e){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${encodeURIComponent(e)}/office/workbook-tickets`,{})}async listOfficeWorkbooks(e){let{workbooks:t}=await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/office/workbooks`);return t}async signOutNativeApp(){await this.requestJson(\\\"POST\\\",\\\"/v1/native-app/sign-out\\\",{})}async getNativePushDevice(){let{device:e}=await this.requestJson(\\\"GET\\\",\\\"/v1/native-app/push-device\\\");return e}async registerNativePushDevice(e){let{device:t}=await this.requestJson(\\\"PUT\\\",\\\"/v1/native-app/push-device\\\",e);return t}async unregisterNativePushDevice(){await this.requestJson(\\\"DELETE\\\",\\\"/v1/native-app/push-device\\\")}async listOrganizationSessions(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/sessions`,void 0,{...t.limit===void 0?{}:{limit:String(t.limit)},...t.cursor===void 0?{}:{cursor:t.cursor},...t.scopeSubjectId?{scopeSubjectId:t.scopeSubjectId}:{},...t.status===void 0?{}:{status:t.status}},{signal:t.signal})}async*iterateOrganizationSessions(e,t={}){let n;do{let s=await this.listOrganizationSessions(e,{...t,...n===void 0?{}:{cursor:n}});for(let i of s.sessions)yield i;n=s.nextCursor??void 0}while(n!==void 0)}async getBilling(e={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing\\\",void 0,{...e.accountId!==void 0?{accountId:e.accountId}:{}})}async getOrganizationUsageSummary(e,t={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/usage-summary\\\",void 0,{accountId:e.accountId,period:e.period??\\\"month\\\"},t)}async getOrganizationModelUsage(e,t={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/usage-models\\\",void 0,{accountId:e.accountId,period:e.period??\\\"month\\\",...e.afterWorkspaceId?{afterWorkspaceId:e.afterWorkspaceId}:{}},t)}async getOrganizationUsageWorkspacePage(e,t={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/usage-workspaces\\\",void 0,{accountId:e.accountId,period:e.period??\\\"month\\\",until:e.until,...e.afterWorkspaceId?{afterWorkspaceId:e.afterWorkspaceId}:{}},t)}async getBillingUsage(e={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/usage\\\",void 0,{...e.accountId!==void 0?{accountId:e.accountId}:{},...e.workspaceId!==void 0?{workspaceId:e.workspaceId}:{}})}async getWorkspaceInsights(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/insights`,void 0,{range:t.range??\\\"week\\\",...t.provider!==void 0?{provider:t.provider}:{},...t.model!==void 0?{model:t.model}:{},...t.rootSessionId!==void 0?{rootSessionId:t.rootSessionId}:{},...t.sessionId!==void 0?{sessionId:t.sessionId}:{}},{signal:t.signal})}async getWorkspaceInsightsSiteUsage(e,t={},n={}){return this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/insights/sites`,void 0,{range:t.range??\\\"month\\\"},n)}async getWorkspaceInsightsUsage(e,t={},n={}){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${encodeURIComponent(e)}/insights/usage${Pe(t)}`,void 0,{},n)}async getOrganizationInsightsUsage(e,t={},n={}){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${encodeURIComponent(e)}/insights/usage${Pe(t)}`,void 0,{},n)}async listInsightsCalls(e,t={},n={}){let s=e.kind===\\\"workspace\\\"?`/v1/workspaces/${encodeURIComponent(e.workspaceId)}/insights/calls`:`/v1/organizations/${encodeURIComponent(e.accountId)}/insights/calls`;return await this.requestJson(\\\"GET\\\",`${s}${Pe(t)}`,void 0,{},n)}async getBillingEntitlements(e={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/entitlements\\\",void 0,{...e.accountId!==void 0?{accountId:e.accountId}:{}})}async createBillingCheckout(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/checkout\\\",e)}async getBillingCheckout(e,t={}){return await this.requestJson(\\\"GET\\\",`/v1/billing/checkout/${encodeURIComponent(e)}`,void 0,{...t.accountId!==void 0?{accountId:t.accountId}:{}})}async createBillingPortalSession(e={}){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/portal\\\",e)}async getBillingSubscriptionPlans(e={}){return await this.requestJson(\\\"GET\\\",\\\"/v1/billing/subscription/plans\\\",void 0,e)}async createSubscriptionCheckout(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/subscription/checkout\\\",e)}async upgradeBillingSubscription(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/subscription/upgrade\\\",e)}async changeBillingSubscription(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/subscription/change\\\",e)}async cancelBillingSubscription(e){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/subscription/cancel\\\",e)}async createSubscriptionPortalSession(e={}){return await this.requestJson(\\\"POST\\\",\\\"/v1/billing/subscription/portal\\\",e)}apiUrl(e){if(!e.startsWith(\\\"/\\\"))throw TypeError(\\\"API path must start with /\\\");return`${this.baseUrl}${e}`}withHeaders(e){let t={...e},n=this.options.headers,i=new this.constructor({...this.options,headers:()=>({...typeof n===\\\"function\\\"?n():n,...t})});if(this.externalActorHeader!==void 0)i.externalActorHeader=this.externalActorHeader;return i.serviceInitiatorHeader=this.serviceInitiatorHeader,i.serviceContextHeader=this.serviceContextHeader,i}async fetchApi(e,t={}){let n=typeof globalThis.location?.href===\\\"string\\\"?globalThis.location.href:void 0,s=new URL(this.baseUrl.endsWith(\\\"/\\\")?this.baseUrl:`${this.baseUrl}/`,n),i=new URL(e,s);if(i.origin!==s.origin||!`${i.pathname}/`.startsWith(s.pathname))throw TypeError(\\\"fetchApi only reaches this client's API base URL\\\");let r=new Headers(t.headers);for(let[o,a]of Object.entries(this.headers()))if(!r.has(o))r.set(o,a);return await this.fetchImpl(i.href,{...t,headers:r})}headers(e){let t=typeof this.options.headers===\\\"function\\\"?this.options.headers():this.options.headers,n={...this.options.apiKey?{Authorization:`Bearer ${this.options.apiKey}`}:{},...t,[Ze]:oe,...e?{[Oe]:e}:{}},s=Object.keys(n).map((o)=>o.toLowerCase()),i=this.externalActorHeader!==void 0||s.includes(\\\"x-opengeni-external-actor\\\"),r=this.serviceInitiatorHeader!==void 0||s.includes(\\\"x-opengeni-service-initiator\\\")||s.includes(\\\"x-opengeni-service-context\\\");if(i&&r)throw Error(\\\"asUser and asService attribution headers are mutually exclusive\\\");if(this.externalActorHeader){for(let o of Object.keys(n))if(o.toLowerCase()===\\\"x-opengeni-external-actor\\\")delete n[o];n[\\\"x-opengeni-external-actor\\\"]=this.externalActorHeader}if(this.serviceInitiatorHeader!==void 0){for(let o of Object.keys(n)){let a=o.toLowerCase();if(a===\\\"x-opengeni-service-initiator\\\"||a===\\\"x-opengeni-service-context\\\")delete n[o]}if(n[\\\"x-opengeni-service-initiator\\\"]=this.serviceInitiatorHeader,this.serviceContextHeader!==void 0)n[\\\"x-opengeni-service-context\\\"]=this.serviceContextHeader}return n}url(e,t={}){let n=new URLSearchParams(t).toString();return`${this.baseUrl}${e}${n?`?${n}`:\\\"\\\"}`}async codexStatus(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/codex/status`)}async codexConnectStart(e){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/codex/connect/start`,{})}async codexConnectPoll(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/codex/connect/poll`,{state:t})}async codexUsage(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/codex/usage`)}async codexAccountUsage(e,t){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/codex/accounts/${t}/usage`)}async organizationCodexAccountUsage(e,t){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/codex/accounts/${encodeURIComponent(t)}/usage`)}async refreshCodexUsage(e){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/codex/usage/refresh`)}async codexOverview(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/codex/overview`)}async codexDisconnect(e){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/codex`)}async listCodexAccounts(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/codex/accounts`)}async listSessionCodexAccounts(e,t){return await this.requestJson(\\\"GET\\\",`${g(e,t)}/codex-accounts`)}async activateCodexAccount(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/codex/accounts/${t}/activate`)}async designateCodexAppsAccount(e,t,n){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/codex/apps`,{accountId:t,expectedVersion:n})}async clearCodexAppsAccount(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/codex/apps`,{expectedVersion:t})}async setCodexRotationSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/codex/settings`,t)}async setCodexAccountAllocator(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/codex/accounts/${t}/allocator`,n)}async disconnectCodexAccount(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/codex/accounts/${t}`)}async renameCodexAccount(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/codex/accounts/${t}`,{label:n})}async pinSessionCodexAccount(e,t,n){return await this.requestJson(\\\"POST\\\",`${g(e,t)}/codex-account`,{target:n})}async getModelConnectionAccess(e){return await this.requestJson(\\\"GET\\\",`/v1/${e.scope}/${encodeURIComponent(e.scopeId)}/model-connections/${e.kind}/${encodeURIComponent(e.connectionId)}/access`)}async updateModelConnectionAccess(e,t){return await this.requestJson(\\\"PUT\\\",`/v1/${e.scope}/${encodeURIComponent(e.scopeId)}/model-connections/${e.kind}/${encodeURIComponent(e.connectionId)}/access`,t)}async listOrganizationSuperGrokAccounts(e){return await this.requestJson(\\\"GET\\\",`/v1/organizations/${e}/supergrok/accounts`)}async organizationSupergrokConnectStart(e){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/supergrok/connect/start`,{})}async organizationSupergrokConnectPoll(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/supergrok/connect/poll`,{state:t})}async activateOrganizationSuperGrokAccount(e,t){return await this.requestJson(\\\"POST\\\",`/v1/organizations/${e}/supergrok/accounts/${t}/activate`,{})}async setOrganizationSuperGrokRotationSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/supergrok/settings`,t)}async setOrganizationSuperGrokAccountAllocator(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/supergrok/accounts/${t}/allocator`,n)}async renameOrganizationSuperGrokAccount(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/organizations/${e}/supergrok/accounts/${t}`,{label:n})}async disconnectOrganizationSuperGrokAccount(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/organizations/${e}/supergrok/accounts/${t}`,{})}async supergrokStatus(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/supergrok/status`)}async supergrokConnectStart(e,t=\\\"workspace\\\"){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/supergrok/connect/start`,{scope:t})}async supergrokConnectPoll(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/supergrok/connect/poll`,{state:t})}async listSuperGrokAccounts(e){return await this.requestJson(\\\"GET\\\",`/v1/workspaces/${e}/supergrok/accounts`)}async activateSuperGrokAccount(e,t){return await this.requestJson(\\\"POST\\\",`/v1/workspaces/${e}/supergrok/accounts/${t}/activate`,{})}async setSuperGrokRotationSettings(e,t){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/supergrok/settings`,t)}async setSuperGrokAccountAllocator(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/supergrok/accounts/${t}/allocator`,n)}async renameSuperGrokAccount(e,t,n){return await this.requestJson(\\\"PATCH\\\",`/v1/workspaces/${e}/supergrok/accounts/${t}`,{label:n})}async disconnectSuperGrokAccount(e,t){return await this.requestJson(\\\"DELETE\\\",`/v1/workspaces/${e}/supergrok/accounts/${t}`,{})}async requestSessionCommand(e,t,n,s={}){return await this.requestJson(e,t,n,{},{signal:s.signal,timeoutMs:s.timeoutMs??this.sessionCommandTimeoutMs})}async requestJson(e,t,n,s={},i={}){let r=crypto.randomUUID(),o=Ni(i);try{let a=Dt(e)?this.readRetryPolicy:null;if(!a)return await this.requestJsonAttempt(e,t,n,s,i,o.signal,r,null);let c=Date.now();for(let u=1;;u+=1){let l={transportFailure:!1,gatewayFailure:!1,retryAfterMs:null};try{return await this.requestJsonAttempt(e,t,n,s,i,o.signal,r,l)}catch(p){let d=l.transportFailure||l.gatewayFailure&&Lt(p);if(o.signal?.aborted||!d)throw p;let m=zt(a,u,Date.now()-c,l.retryAfterMs);if(m===null)throw p;await Nt(m,o.signal)}}}finally{o.dispose()}}async requestJsonAttempt(e,t,n,s,i,r,o,a){if(r?.aborted)throw r.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\");let c=this.headers(o),u;try{u=await ae(this.fetchImpl(this.url(t,s),{method:e,headers:{...c,Accept:\\\"application/json\\\",...n!==void 0?{\\\"Content-Type\\\":\\\"application/json\\\"}:{}},...n!==void 0?{body:JSON.stringify(n)}:{},...r?{signal:r}:{}}),r)}catch(l){if(i.signal?.aborted)throw l;if(ue(e))throw ce(o);if(l instanceof TypeError&&a)a.transportFailure=!0;throw Ye(l),l}D(u,this.apiContractStrict);try{if(!u.ok){if(a&&je(u.status))a.gatewayFailure=!0,a.retryAfterMs=Wt(u.headers.get(\\\"retry-after\\\"));throw await ae(M(u,{method:e,correlationId:o}),r)}if(i.responseType===\\\"void\\\"){await ae(U(u,\\\"discarding void API response\\\"),r);return}await ae(fe(u,{method:e,correlationId:o}),r);let l=await ae(u.json(),r);return At(l,u.headers.get(It)),l}catch(l){if(i.signal?.aborted)throw l;if(l instanceof P)throw l;if(ue(e))throw ce(o);if(l instanceof TypeError&&a)a.transportFailure=!0;throw Ye(l),l}}async requestResponse(e,t,n={},s={}){let i=crypto.randomUUID(),r=this.headers(i),o;try{o=await this.fetchImpl(this.url(t,n),{method:e,headers:{...r,Accept:s.accept??\\\"application/octet-stream\\\"},...s.signal?{signal:s.signal}:{}})}catch(a){if(ue(e))throw ce(i);throw a}if(D(o,this.apiContractStrict),!o.ok)throw await M(o,{method:e,correlationId:i});return o}async requestVoid(e,t,n){let s=crypto.randomUUID(),i=this.headers(s),r;try{r=await this.fetchImpl(this.url(t),{method:e,headers:{...i,Accept:\\\"application/json\\\",...n!==void 0?{\\\"Content-Type\\\":\\\"application/json\\\"}:{}},...n!==void 0?{body:JSON.stringify(n)}:{}})}catch(o){if(ue(e))throw ce(s);throw o}if(D(r,this.apiContractStrict),!r.ok)throw await M(r,{method:e,correlationId:s})}}function D(e,t){if(!t)return;let n=e.headers.get(Ze);if(n&&n!==oe)throw new ve(oe,n)}function Bi(e){if(!e||typeof e!==\\\"object\\\"||Array.isArray(e))return!1;let t=e;return typeof t.text===\\\"string\\\"&&Array.isArray(t.languages)&&t.languages.every((n)=>typeof n===\\\"string\\\")}function Li(e){if(!e||typeof e!==\\\"object\\\"||Array.isArray(e))return!1;let t=e;if(!it({recording:t.recording,segments:[]}))return!1;if(!t.chunk||typeof t.chunk!==\\\"object\\\"||Array.isArray(t.chunk))return!1;let n=t.chunk;return typeof n.chunkNumber===\\\"number\\\"&&typeof n.byteLength===\\\"number\\\"&&typeof n.sha256===\\\"string\\\"&&typeof n.startMilliseconds===\\\"number\\\"&&typeof n.durationMilliseconds===\\\"number\\\"&&typeof n.deduplicated===\\\"boolean\\\"}function it(e){if(!e||typeof e!==\\\"object\\\"||Array.isArray(e))return!1;let t=e;if(!t.recording||typeof t.recording!==\\\"object\\\"||Array.isArray(t.recording))return!1;let n=t.recording;return typeof n.id===\\\"string\\\"&&typeof n.workspaceId===\\\"string\\\"&&typeof n.mimeType===\\\"string\\\"&&typeof n.state===\\\"string\\\"&&typeof n.nextChunkNumber===\\\"number\\\"&&typeof n.chunkCount===\\\"number\\\"&&typeof n.totalBytes===\\\"number\\\"&&typeof n.totalDurationMilliseconds===\\\"number\\\"&&typeof n.segmentCount===\\\"number\\\"&&typeof n.completedSegmentCount===\\\"number\\\"&&(n.transcriptText===null||typeof n.transcriptText===\\\"string\\\")&&Array.isArray(n.languages)&&(n.errorCode===null||typeof n.errorCode===\\\"string\\\")&&typeof n.retryable===\\\"boolean\\\"&&typeof n.objectsCleaned===\\\"boolean\\\"&&typeof n.createdAt===\\\"string\\\"&&typeof n.updatedAt===\\\"string\\\"&&typeof n.expiresAt===\\\"string\\\"&&(t.retryAfterMilliseconds===void 0||typeof t.retryAfterMilliseconds===\\\"number\\\"&&Number.isInteger(t.retryAfterMilliseconds)&&t.retryAfterMilliseconds>0&&t.retryAfterMilliseconds<=60000)&&Array.isArray(t.segments)}function ye(e){if(it(e))return e;throw A(\\\"Invalid transcription recording response.\\\",{code:\\\"invalid_response\\\"})}function Wi(e){if(!e||typeof e!==\\\"object\\\"||Array.isArray(e))return!1;let t=e.recordings;return Array.isArray(t)&&t.length<=50&&t.every((n)=>it({recording:n,segments:[]}))}function zi(e){switch(e.trim().toLowerCase().split(\\\";\\\")[0]??\\\"audio/webm\\\"){case\\\"audio/mp4\\\":case\\\"audio/m4a\\\":return\\\"audio.mp4\\\";case\\\"audio/ogg\\\":return\\\"audio.ogg\\\";case\\\"audio/mpeg\\\":case\\\"audio/mp3\\\":return\\\"audio.mp3\\\";case\\\"audio/wav\\\":case\\\"audio/x-wav\\\":return\\\"audio.wav\\\";case\\\"audio/webm\\\":default:return\\\"audio.webm\\\"}}var Hn=16384;function Ni(e){let t=e.timeoutMs??0;if(t<=0)return{signal:e.signal,dispose:()=>{return}};let n=new AbortController,s=()=>n.abort(e.signal?.reason);if(e.signal?.aborted)s();else e.signal?.addEventListener(\\\"abort\\\",s,{once:!0});let i=setTimeout(()=>n.abort(new DOMException(\\\"Request timed out\\\",\\\"TimeoutError\\\")),t);return{signal:n.signal,dispose:()=>{clearTimeout(i),e.signal?.removeEventListener(\\\"abort\\\",s)}}}async function ae(e,t){if(!t)return await e;if(t.aborted)throw t.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\");return await new Promise((n,s)=>{let i=()=>{r(),s(t.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\"))},r=()=>t.removeEventListener(\\\"abort\\\",i);t.addEventListener(\\\"abort\\\",i,{once:!0}),e.then((o)=>{r(),n(o)},(o)=>{r(),s(o)})})}function Fi(e,t){if(e===void 0||e===null)return;if(t.usageLimit?.limitMicros===e)return;throw new pe(`The session ${t.id} was created, but the server did not confirm its usage limit; it may not support usage limits. Set the limit with setSessionUsageLimit before sending work, or treat the task as unlimited.`,{sessionId:t.id})}async function M(e,t){let n=await Ji(e),i=new((Ve(n))?Ne:(Je(n))?Fe:P)(e.status,n,{correlationId:e.headers.get(Oe)??t.correlationId,mutation:ue(t.method)});return i.status>=400&&i.status<500&&(i.code===\\\"SESSION_TENANCY_NOT_ACTIVATED\\\"||i.code===\\\"OPENGENI_SETUP_REQUIRED\\\")?new ze(i):i}async function fe(e,t){if(Yn(e.headers.get(\\\"content-type\\\")))return;throw await U(e,\\\"unexpected non-JSON API response\\\"),A(\\\"\\\",{code:\\\"upstream_unavailable\\\",retryable:!0,correlationId:e.headers.get(Oe)??t.correlationId,outcomeUnknown:ue(t.method),displayMessage:\\\"The workspace is temporarily unavailable — retry.\\\"})}async function Ji(e){if(!Yn(e.headers.get(\\\"content-type\\\")))return await U(e,\\\"discarding API error body\\\"),\\\"\\\";if(Number(e.headers.get(\\\"content-length\\\"))>Hn)return await U(e,\\\"discarding API error body\\\"),\\\"\\\";try{return new TextDecoder().decode(await he(e,Hn,null))}catch{return\\\"\\\"}}function Yn(e){return/^(application\\\\/json|[^;]+\\\\+json)\\\\s*(;|$)/i.test(e??\\\"\\\")}function ue(e){return e!==\\\"GET\\\"&&e!==\\\"HEAD\\\"&&e!==\\\"OPTIONS\\\"}function ce(e){return new P(0,\\\"\\\",{code:\\\"network_error\\\",retryable:!0,correlationId:e,outcomeUnknown:!0,mutation:!0,displayMessage:\\\"The request could not be confirmed — reconcile before retrying.\\\"})}function Vi(){let e=typeof window<\\\"u\\\"?window.isSecureContext:typeof globalThis.isSecureContext===\\\"boolean\\\"?globalThis.isSecureContext:void 0;if(e===void 0)return;if(!e)throw new we(\\\"insecure_context\\\");if(typeof globalThis.crypto>\\\"u\\\"||typeof globalThis.crypto.subtle?.digest!==\\\"function\\\")throw new we(\\\"web_crypto_unavailable\\\")}async function Hi(e){let t=typeof e===\\\"string\\\"?new TextEncoder().encode(e):e instanceof Blob?new Uint8Array(await e.arrayBuffer()):new Uint8Array(e),n=await globalThis.crypto.subtle.digest(\\\"SHA-256\\\",t);return[...new Uint8Array(n)].map((s)=>s.toString(16).padStart(2,\\\"0\\\")).join(\\\"\\\")}async function Kn(e){let t=Uint8Array.from(e),n=await globalThis.crypto.subtle.digest(\\\"SHA-256\\\",t.buffer);return[...new Uint8Array(n)].map((s)=>s.toString(16).padStart(2,\\\"0\\\")).join(\\\"\\\")}function Ki(e,t){if(e.computerSessionId!==t.computerSessionId)return\\\"frame_session_mismatch\\\";if(e.targetId!==t.targetId)return\\\"frame_target_mismatch\\\";if(e.mediaType!==t.mediaType)return\\\"frame_media_mismatch\\\";if(e.sha256!==t.sha256)return\\\"frame_digest_mismatch\\\";return null}async function U(e,t){await e.body?.cancel(t).catch(()=>{return})}function jn(e,t){if(!Mn(t,e)&&!Gn(t,e))throw A(\\\"retained workspace artifact receipt is invalid\\\")}function Xn(e){if(!e||typeof e.url!==\\\"string\\\"||typeof e.expiresAt!==\\\"string\\\"||!Number.isFinite(Date.parse(e.expiresAt)))throw A(\\\"retained artifact download URL is invalid\\\");let t;try{t=new URL(e.url)}catch{throw A(\\\"retained artifact download URL is invalid\\\")}if(![\\\"http:\\\",\\\"https:\\\"].includes(t.protocol)||t.username||t.password)throw A(\\\"retained artifact download URL is unsafe\\\")}function ji(e,t){if(!e||e.schemaVersion!==1||e.artifactId!==t||e.contentType!==\\\"video/mp4\\\"||e.acceptRanges!==\\\"bytes\\\"||!Number.isSafeInteger(e.sizeBytes)||e.sizeBytes<=0||e.sizeBytes>On||!/^[0-9a-f]{64}$/.test(e.sha256))throw A(\\\"generated-video playback source is invalid\\\");Xn({url:e.url,expiresAt:e.expiresAt})}function Yi(e){if(e===null)return null;if(!/^\\\\d+$/.test(e))throw A(\\\"invalid retained artifact content-length\\\");let t=Number(e);if(!Number.isSafeInteger(t)||t>qe)throw A(\\\"retained artifact response exceeds the SDK byte limit\\\");return t}async function he(e,t,n){if(!e.body){if(n!==null&&n!==0)throw A(\\\"retained artifact response length mismatch\\\");return new Uint8Array}let s=e.body.getReader(),i=[],r=0;try{while(!0){let{done:c,value:u}=await s.read();if(c)break;if(r+=u.byteLength,r>t)throw await s.cancel(\\\"retained artifact response exceeded the SDK byte limit\\\").catch(()=>{return}),A(\\\"retained artifact response exceeds the SDK byte limit\\\");i.push(u)}}finally{s.releaseLock()}if(n!==null&&r!==n)throw A(\\\"retained artifact response length mismatch\\\");let o=new Uint8Array(r),a=0;for(let c of i)o.set(c,a),a+=c.byteLength;return o}function O(e,t){return`/v1/workspaces/${encodeURIComponent(e)}/published-artifacts/${encodeURIComponent(t)}`}function X(e,t){return`${O(e,t)}/publication`}class Re extends Error{code;status;details;constructor(e,t,n,s={}){super(t);this.code=e;this.status=n;this.details=s;this.name=\\\"OpenGeniSiteDataError\\\"}}var rt=\\\"/v1/workspaces/site-host/published-artifacts/current\\\";function Qn(e,t){let n=async(u,l={})=>{if(!await t())throw new Re(\\\"site_data_unsupported\\\",\\\"This Site host does not provide Site Data\\\",0);let p=await e(`${rt}${u}`,l),d=await p.text(),m=null;try{m=d?JSON.parse(d):null}catch{m=null}if(p.ok)return m;throw Qi(p.status,m)},s=(u)=>({method:\\\"POST\\\",headers:{\\\"content-type\\\":\\\"application/json\\\"},body:JSON.stringify(u)}),i=async(u)=>(await n(\\\"/data/write\\\",s({operations:u}))).results,r=async(u)=>{let[l]=await i([u]);if(!l||!(\\\"record\\\"in l))throw new Re(\\\"request_failed\\\",\\\"Unexpected Site Data response\\\",200);return l.record},o=async(u,l,p)=>(await n(\\\"/data/query\\\",s({collection:u,limit:1,count:!0,...l?{where:l}:{},...p?{scope:p}:{}}))).count??0;return{data:{collection(u){return{name:u,list:async(p={})=>await n(\\\"/data/query\\\",s({collection:u,...p})),get:async(p)=>{try{return(await n(\\\"/data/get\\\",s({collection:u,...Ue(p)}))).record}catch(d){if(d instanceof Re&&d.code===\\\"not_found\\\")return null;throw d}},insert:async(p,d={})=>await r({op:\\\"insert\\\",collection:u,data:p,...d.key===void 0?{}:{key:d.key}}),put:async(p,d,m={})=>await r({op:\\\"put\\\",collection:u,key:p,data:d,...m}),patch:async(p,d,m={})=>await r({op:\\\"patch\\\",collection:u,...Ue(p),data:d,...m}),delete:async(p,d={})=>{await i([{op:\\\"delete\\\",collection:u,...Ue(p),...d}])},increment:async(p,d,m)=>await r({op:\\\"increment\\\",collection:u,...Ue(p),field:d,...m===void 0?{}:{by:m}}),count:async(p,d={})=>await o(u,p,d.scope)}},batch:i,count:async(u,l)=>await o(u,l)},files:{upload:async(u,l={})=>{let p=u instanceof Blob?u:new Blob([u instanceof Uint8Array?u.slice():u],{type:l.contentType??\\\"application/octet-stream\\\"}),d=l.name??(typeof File<\\\"u\\\"&&u instanceof File?u.name:\\\"file\\\"),m=new URLSearchParams({name:d,scope:l.scope??\\\"shared\\\"});return await n(`/files?${m}`,{method:\\\"POST\\\",headers:{\\\"content-type\\\":l.contentType??(p.type||\\\"application/octet-stream\\\")},body:await p.arrayBuffer()})},list:async(u={})=>{let l=new URLSearchParams;if(u.limit!==void 0)l.set(\\\"limit\\\",String(u.limit));if(u.cursor)l.set(\\\"cursor\\\",u.cursor);let p=l.size?`?${l}`:\\\"\\\";return await n(`/files${p}`,{method:\\\"GET\\\"})},url:async(u)=>await n(`/files/${encodeURIComponent(u)}`,{method:\\\"GET\\\"}),delete:async(u)=>{await n(`/files/${encodeURIComponent(u)}`,{method:\\\"DELETE\\\"})}}}}function Ue(e){if(typeof e===\\\"string\\\")return{key:e};if(\\\"id\\\"in e)return{id:e.id};return{key:e.key}}var Xi=new Set([\\\"validation\\\",\\\"conflict\\\",\\\"not_found\\\",\\\"forbidden\\\",\\\"not_available_for_viewer\\\",\\\"quota_exceeded\\\",\\\"rate_limited\\\"]);function Qi(e,t){let n=typeof t===\\\"object\\\"&&t!==null&&\\\"error\\\"in t?t.error:null,s=typeof n===\\\"object\\\"&&n!==null?n:{},i=typeof s.details===\\\"object\\\"&&s.details!==null?s.details:{},r=i.code,o=r&&Xi.has(r)?r:e===404?\\\"not_found\\\":e===403?\\\"forbidden\\\":e===413?\\\"quota_exceeded\\\":e===429?\\\"rate_limited\\\":\\\"request_failed\\\",a=typeof s.message===\\\"string\\\"&&s.message?s.message:`Site Data request failed with HTTP ${e}`;return new Re(o,a,e,i)}class be extends Error{code;status;details;constructor(e,t,n,s={}){super(t);this.code=e;this.status=n;this.details=s;this.name=\\\"OpenGeniSiteSqlError\\\"}}var Zi=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/u,er=new Set([\\\"validation\\\",\\\"not_found\\\",\\\"forbidden\\\",\\\"not_available_for_viewer\\\",\\\"conflict\\\",\\\"quota_exceeded\\\",\\\"rate_limited\\\",\\\"sql_error\\\",\\\"unavailable\\\",\\\"disabled\\\"]);function Zn(e,t){return{async run(n,s={}){if(!Zi.test(n))throw new be(\\\"validation\\\",\\\"Invalid query name\\\",0);if(Object.keys(s).some((a)=>a===\\\"viewer\\\"||a.startsWith(\\\"viewer_\\\")))throw new be(\\\"validation\\\",\\\"viewer parameters are bound by the host, not the Site\\\",0);if(!await t())throw new be(\\\"site_sql_unsupported\\\",\\\"This Site host does not provide Site SQL\\\",0);let i=await e(`${rt}/sql/queries/${encodeURIComponent(n)}`,{method:\\\"POST\\\",headers:{\\\"content-type\\\":\\\"application/json\\\"},body:JSON.stringify({params:s})}),r=await i.text(),o=null;try{o=r?JSON.parse(r):null}catch{o=null}if(i.ok)return o;throw tr(i.status,o)}}}function tr(e,t){let n=typeof t===\\\"object\\\"&&t!==null&&\\\"error\\\"in t?t.error:null,s=typeof n===\\\"object\\\"&&n!==null?n:{},i=typeof s.details===\\\"object\\\"&&s.details!==null?s.details:{},r=typeof i.code===\\\"string\\\"?i.code:void 0,o=r&&er.has(r)?r:e===404?\\\"not_found\\\":e===403?\\\"forbidden\\\":e===413?\\\"quota_exceeded\\\":e===429?\\\"rate_limited\\\":\\\"request_failed\\\",a=typeof s.message===\\\"string\\\"&&s.message?s.message:`Site SQL request failed with HTTP ${e}`;return new be(o,a,e,i)}var es=\\\"The model returned no final reply after a reply reminder. Completed work is preserved; the goal and later updates are unaffected.\\\";function ts(e){return e!==null&&typeof e===\\\"object\\\"&&!Array.isArray(e)&&e.emptyFinalReply===!0}class ot extends Error{code;event;constructor(e,t,n=null){super(t);this.name=\\\"OpenGeniChatError\\\",this.code=e,this.event=n}}function z(){return{chunks:[],terminal:null}}class $e{workspaceId;sessionId;events=[];turnId;pending=null;failure=null;emptyFinalReply=!1;segments=[];openTools=new Map;constructor(e,t,n){this.workspaceId=e;this.sessionId=t;this.turnId=n}get text(){return this.segments.filter((e)=>!e.commentary).map((e)=>e.text).filter((e)=>e.length>0).join(`\\n\\n`)}push(e){let t=typeof e.turnId===\\\"string\\\"?e.turnId:null;if(this.turnId&&t&&t!==this.turnId)return{chunks:[],terminal:null};if(!this.turnId&&t&&nr(e.type))this.turnId=t;this.events.push(e);let n=se(e.payload);switch(e.type){case\\\"agent.message.delta\\\":{let s=E(n.text);if(!s)return z();let i=E(n.messageId)||null;if(i)return this.messageDelta(i,s,De(n));let r=this.segments.at(-1);if(De(n)){if(r?.open&&r.commentary)r.text+=s;else this.closeSegments(),this.segments.push({text:s,open:!0,commentary:!0,messageId:null});return z()}if(r?.open&&!r.commentary)r.text+=s;else return this.closeSegments(),{chunks:[this.startSegment(s,!0,null)],terminal:null};return{chunks:[{type:\\\"text\\\",text:s}],terminal:null}}case\\\"agent.message.completed\\\":{let s=E(n.text)??\\\"\\\",i=E(n.messageId)||null;if(i)return this.messageCompleted(i,s,De(n));let r=this.segments.at(-1);if(De(n)){if(r?.commentary&&(r.open||s.startsWith(r.text))){if(r.open=!1,s)r.text=s;return z()}if(!(r&&!r.commentary&&r.open&&s.startsWith(r.text))){if(s)this.closeSegments(),this.segments.push({text:s,open:!1,commentary:!0,messageId:null});return z()}}let o=r?.commentary?void 0:r;if(!o||!o.open&&o.text&&!s.startsWith(o.text)){if(!s)return z();if(n.phase===void 0&&this.latestAnswer()?.text===s)return z();return this.closeSegments(),{chunks:[this.startSegment(s,!1,null)],terminal:null}}return o.open=!1,{chunks:this.extendAnswer(o,s),terminal:null}}case\\\"agent.toolCall.created\\\":{this.closeSegments();let s=E(n.name)??\\\"tool\\\",i=E(n.id);if(i)this.openTools.set(i,s);return{chunks:[{type:\\\"tool\\\",name:s,status:\\\"started\\\",...i?{callId:i}:{},...\\\"arguments\\\"in n?{input:n.arguments}:{}}],terminal:null}}case\\\"agent.toolCall.output\\\":{let s=E(n.id),i=(s?this.openTools.get(s):void 0)??\\\"tool\\\";if(s)this.openTools.delete(s);return{chunks:[{type:\\\"tool\\\",name:i,status:rr(n)?\\\"failed\\\":\\\"completed\\\",...s?{callId:s}:{}}],terminal:null}}case\\\"session.requiresAction\\\":{let s=sr(n);if(!s)return{chunks:[],terminal:null};return this.pending=s,{chunks:[...this.settleSegments(),{type:\\\"pending\\\",pending:s}],terminal:\\\"pending\\\"}}case\\\"session.humanInput.requested\\\":{let s=ir(n);if(!s)return{chunks:[],terminal:null};return this.pending=s,{chunks:[...this.settleSegments(),{type:\\\"pending\\\",pending:s}],terminal:\\\"pending\\\"}}case\\\"turn.completed\\\":return this.emptyFinalReply=ts(n),{chunks:this.settleSegments(),terminal:\\\"completed\\\"};case\\\"turn.failed\\\":return this.failure=e,{chunks:this.settleSegments(),terminal:\\\"failed\\\"};case\\\"turn.cancelled\\\":return{chunks:this.settleSegments(),terminal:\\\"cancelled\\\"};default:return{chunks:[],terminal:null}}}reply(e){let t=this.text;return{text:t,sessionId:this.sessionId,workspaceId:this.workspaceId,turnId:this.turnId,status:e===\\\"pending\\\"?\\\"pending\\\":e===\\\"cancelled\\\"?\\\"cancelled\\\":\\\"completed\\\",pending:this.pending,...this.emptyFinalReply?{emptyFinalReply:!0,notice:es}:{},events:[...this.events],toString:()=>t}}failureError(){let e=se(this.failure?.payload),t=E(e.code)??\\\"turn_failed\\\",n=E(e.error)??E(e.message)??\\\"The turn failed.\\\";return new ot(t,n,this.failure)}messageDelta(e,t,n){let s=this.segmentOf(e);if(s?.open)return s.text+=t,s.commentary?z():{chunks:[{type:\\\"text\\\",text:t}],terminal:null};if(this.closeSegments(),n)return this.segments.push({text:t,open:!0,commentary:!0,messageId:e}),z();return{chunks:[this.startSegment(t,!0,e)],terminal:null}}messageCompleted(e,t,n){let s=this.segmentOf(e)??this.unidentifiedStreamingSegment(t);if(s){if(s.messageId=e,s.open=!1,s.commentary){if(t)s.text=t;return z()}return{chunks:this.extendAnswer(s,t),terminal:null}}if(!t)return z();if(n)return this.segments.push({text:t,open:!1,commentary:!0,messageId:e}),z();return{chunks:[this.startSegment(t,!1,e)],terminal:null}}segmentOf(e){return this.findLastSegment((t)=>t.messageId===e)}unidentifiedStreamingSegment(e){let t=this.segments.at(-1);return t?.open&&t.messageId===null&&e.startsWith(t.text)?t:void 0}latestAnswer(){return this.findLastSegment((e)=>!e.commentary)}findLastSegment(e){for(let t=this.segments.length-1;t>=0;t-=1){let n=this.segments[t];if(e(n))return n}return}extendAnswer(e,t){if(t.length<=e.text.length||!t.startsWith(e.text))return[];if(e!==this.latestAnswer())return[];let n=t.slice(e.text.length);return e.text=t,[{type:\\\"text\\\",text:n}]}closeSegments(){for(let e of this.segments)e.open=!1}settleSegments(){if(this.closeSegments(),this.emptyFinalReply)return[];if(this.segments.some((t)=>!t.commentary))return[];let e=[...this.segments].reverse().find((t)=>t.commentary&&t.text);if(!e)return[];return e.commentary=!1,[{type:\\\"text\\\",text:e.text}]}startSegment(e,t,n){let s=this.segments.some((i)=>!i.commentary)?`\\n\\n`:\\\"\\\";return this.segments.push({text:e,open:t,commentary:!1,messageId:n}),{type:\\\"text\\\",text:s+e}}}function De(e){return e.phase===\\\"commentary\\\"}function nr(e){return e.startsWith(\\\"turn.\\\")||e.startsWith(\\\"agent.\\\")||e===\\\"user.message\\\"}function sr(e){let n=(Array.isArray(e.approvals)?e.approvals:[])[0];if(!n)return null;let s=se(n),i=se(s.rawItem),r=E(i.callId)??E(i.id)??E(s.id)??E(s.callId);if(!r)return null;return{kind:\\\"approval\\\",requestId:r,name:E(s.name)??E(s.toolName)??E(i.name)??null,payload:n}}function ir(e){let t=se(e.request),n=E(t.id);if(!n||!Array.isArray(t.questions))return null;return{kind:\\\"human_input\\\",requestId:n,name:null,payload:e.request}}function se(e){return e&&typeof e===\\\"object\\\"&&!Array.isArray(e)?e:{}}function E(e){return typeof e===\\\"string\\\"?e:void 0}function rr(e){if(e.error===!0||e.failed===!0)return!0;let t=e.output;return!!t&&typeof t===\\\"object\\\"&&t.isError===!0}function is(e,t){let n=async(s,i={})=>{i.signal?.throwIfAborted();let r=new AbortController,o=()=>r.abort(i.signal?.reason);i.signal?.addEventListener(\\\"abort\\\",o,{once:!0});let a=i.after??0,c=0,u=\\\"\\\",l=i.turnId||a===0?new $e(t,s,i.turnId??null):null,p=[],d=null,m={event:null},y,R,w=()=>{if(R?.abort(),y)Promise.resolve(y.return(void 0)).catch(()=>{return});y=void 0,R=void 0},S=()=>R?.abort(r.signal.reason);r.signal.addEventListener(\\\"abort\\\",S);let I=(v)=>{for(let k of v)if(k.type===\\\"text\\\")r.signal.throwIfAborted(),u+=k.text,i.onText?.(k.text)},x=(v)=>{l=new $e(t,s,v);for(let k of p){let q=l.push(k);if(q.terminal&&q.terminal!==\\\"pending\\\")d=q.terminal}p=[]},b=(v)=>{let k=ss(v);if(k<=c)return;if(c=k,!l){if(k<=a){p.push(v);return}if(!rs(v)&&!Be(v))return;x(v.turnId??ns(p))}let q=l;if((!v.turnId||!q.turnId||v.turnId===q.turnId)&&Be(v)){if(!q.turnId&&v.turnId)q.turnId=v.turnId;if(v.type!==\\\"session.status.changed\\\")m.event=v;if(k>a)return}let Q=q.push(v);if(k>a)I(Q.chunks);if(Q.terminal&&Q.terminal!==\\\"pending\\\")d=Q.terminal},h=(v)=>{if(r.signal.throwIfAborted(),v===\\\"failed\\\")throw l.failureError();return{sessionId:s,turnId:l?.turnId??null,text:u,status:v===\\\"pending\\\"?\\\"pending\\\":v===\\\"cancelled\\\"?\\\"cancelled\\\":\\\"completed\\\",after:Math.max(a,c)}},f=()=>at(()=>e.getSession(t,s,{fresh:!0,signal:r.signal}),r.signal),T=async(v)=>{while(c<v){let k=c,q=await at(()=>e.listEventPage(t,s,{after:c,before:v+1,direction:\\\"after\\\",limit:200,mode:\\\"forensic\\\",payloadMode:\\\"full\\\"}),r.signal);for(let H of q.events)if(b(H),d&&c>a)return;if(c=Math.max(c,q.nextAfter??q.coveredSequence?.last??0),c<=k)throw Error(\\\"The Site AI event replay did not reach the session cursor.\\\")}},C=(v)=>v.status===\\\"requires_action\\\"&&(!v.activeTurnId||!l?.turnId||v.activeTurnId===l.turnId);try{let v=await f();if(await T(Math.min(a,v.lastSequence)),d)return h(d);for(;;){if(await T(v.lastSequence),d)return h(d);if(C(v)){let k=await f();if(k.lastSequence>c){v=k;continue}if(C(k)){if(!l)x(k.activeTurnId??ns(p));else if(!l.turnId)l.turnId=k.activeTurnId??null;if(m.event&&ss(m.event)>a)I(l.push(m.event).chunks);return h(\\\"pending\\\")}v=k}R=new AbortController,y=e.streamEvents(t,s,{after:Math.max(a,c),signal:R.signal});for(;;){let k=await at(()=>y.next(),r.signal);if(k.done)throw Error(\\\"The Site AI event stream ended before the turn settled.\\\");if(b(k.value),d)return h(d);if(Be(k.value)&&(!k.value.turnId||k.value.turnId===l?.turnId)){w(),v=await f();break}}}}finally{i.signal?.removeEventListener(\\\"abort\\\",o),r.abort(),w(),r.signal.removeEventListener(\\\"abort\\\",S)}};return{async run(s,i={}){i.signal?.throwIfAborted();let r=await e.createSession(t,{initialMessage:s.initialMessage,idempotencyKey:s.idempotencyKey??crypto.randomUUID(),...s.model===void 0?{}:{model:s.model},...s.reasoningEffort===void 0?{}:{reasoningEffort:s.reasoningEffort},...s.latencyMode===void 0?{}:{latencyMode:s.latencyMode}});return i.onSession?.(r.id),await n(r.id,i)},result:n}}function Be(e){return e.type===\\\"session.requiresAction\\\"||e.type===\\\"session.humanInput.requested\\\"||e.type===\\\"session.status.changed\\\"&&se(e.payload).status===\\\"requires_action\\\"}function rs(e){return e.type.startsWith(\\\"turn.\\\")||e.type.startsWith(\\\"agent.\\\")||e.type===\\\"user.message\\\"}function ns(e){for(let t=e.length-1;t>=0;t-=1){let n=e[t];if(n.turnId&&(rs(n)||Be(n)))return n.turnId}return null}function ss(e){return Math.max(e.sequence,e.coveredThrough??0,Et(e)??0)}async function at(e,t){t.throwIfAborted();let n=()=>{},s=new Promise((i,r)=>{n=()=>r(t.reason),t.addEventListener(\\\"abort\\\",n,{once:!0})});try{let i=await Promise.race([e(),s]);return t.throwIfAborted(),i}finally{t.removeEventListener(\\\"abort\\\",n)}}var le=2,or=\\\"opengeni.site.connect\\\",cs=\\\"opengeni.site.ready\\\",ar=\\\"opengeni.site.request\\\",cr=\\\"opengeni.site.response\\\",ur=\\\"opengeni.site.cancel\\\",us=\\\"__opengeniSiteBridgeBootstrapV2\\\",lr=\\\"/__opengeni/site-tools\\\",dr=\\\"viewer\\\",pr=\\\"auth.signIn\\\";class _ extends Error{code;retryable;outcomeUnknown;constructor(e,t,n=!1,s=!1){super(t);this.code=e;this.retryable=n;this.outcomeUnknown=s;this.name=\\\"OpenGeniSiteBridgeError\\\"}}function ls(e={}){let t=gr(e)?new ds(e):new ps(e),n=Qn((a,c)=>t.fetch(`https://site.opengeni.invalid${a}`,c),()=>t.siteDataSupported()),s=Zn((a,c)=>t.fetch(`https://site.opengeni.invalid${a}`,c),()=>t.siteDataSupported()),i=null,r=null,o=new st({baseUrl:\\\"https://site.opengeni.invalid\\\",toolGatewayMode:e.toolGatewayMode??\\\"target\\\",fetch:(a,c)=>t.fetch(a,c)});return{client:o,ai:is(o,ge),workspaceId:ge,tools:new re(t).forWorkspace(\\\"site-host\\\"),data:n.data,files:n.files,sql:s,get viewer(){if(!i){let a=t.viewer();i=a,a.catch(()=>{if(i===a)i=null})}return i},get capabilities(){return r??=vr(t),r},auth:{signIn:()=>t.signIn()},close:()=>t.close()}}class ds{toolGatewayMode;fetchImpl;basePath;constructor(e){this.toolGatewayMode=e.toolGatewayMode??\\\"target\\\",this.fetchImpl=e.fetch??globalThis.fetch.bind(globalThis);let t=e.localCodemodePath;this.basePath=(typeof t===\\\"string\\\"?t:lr).replace(/\\\\/+$/u,\\\"\\\")}close(){}async siteDataSupported(){return!1}async viewer(){return null}async signIn(){return{started:!1}}async fetch(e,t){let n=new Request(e,t),s=new URL(n.url),i=`${s.pathname}${s.search}`;return de(i,ge,n.method),this.fetchImpl(`${this.basePath}/sdk${i}`,{method:n.method,headers:n.headers,signal:n.signal,...n.body?{body:await n.text()}:{}})}async requestJson(e,t,n,s,i={}){let r=mr(e,t),o=await this.fetchImpl(`${this.basePath}${r}`,{method:e,...i.signal?{signal:i.signal}:{},...n===void 0?{}:{headers:{\\\"content-type\\\":\\\"application/json\\\"},body:JSON.stringify(n)}}),a=await o.json();if(o.ok)return a;let c=B(a)&&B(a.error)?a.error:{};throw new _(typeof c.code===\\\"string\\\"?c.code:\\\"local_codemode_error\\\",typeof c.message===\\\"string\\\"?c.message:`Local Site tool request failed with HTTP ${o.status}`,c.retryable===!0,c.outcomeUnknown===!0)}}function gr(e){if(e.localCodemodePath===!1||e.bootstrapPort)return!1;if(typeof e.localCodemodePath===\\\"string\\\")return!0;let t=e.siteWindow??globalThis.window;return Boolean(t&&t.parent===t)}function mr(e,t){if(e===\\\"GET\\\"&&t.endsWith(\\\"/tools/catalog\\\"))return\\\"/catalog\\\";if(e===\\\"GET\\\"&&t.endsWith(\\\"/tools/declarations\\\"))return\\\"/declarations\\\";if(e===\\\"POST\\\"&&t.endsWith(\\\"/tools/calls\\\"))return\\\"/calls\\\";if(e===\\\"POST\\\"&&t.endsWith(\\\"/tools/resolve\\\"))return\\\"/resolve\\\";if(e===\\\"POST\\\"&&t.endsWith(\\\"/tools/invoke\\\"))return\\\"/invoke\\\";throw new _(\\\"unsupported_request\\\",\\\"Unsupported Site tool request\\\")}function yr(e){return{...e.operationId===void 0?{}:{operationId:e.operationId},catalogDigest:e.catalogDigest,identity:e.identity,arguments:e.arguments}}function fr(e){return{target:e.target,operationId:e.operationId,arguments:e.arguments,...e.expectedDefinitionDigest===void 0?{}:{expectedDefinitionDigest:e.expectedDefinitionDigest}}}class ps{toolGatewayMode;targetTools=!1;siteData=!1;viewerSupported=!1;options;bootstrap;port=null;connecting=null;closed=!1;constructor(e){this.toolGatewayMode=e.toolGatewayMode??\\\"target\\\",this.options=e,this.bootstrap=hr(e)}async fetch(e,t){return bt(await this.connect(),e,t)}async siteDataSupported(){return await this.connect(),this.siteData}async viewer(){if(await this.connect(),!this.viewerSupported)return null;let e=await this.request({method:dr},{});if(!Ir(e))throw new _(\\\"invalid_viewer\\\",\\\"The Site host returned an invalid viewer\\\");return e}async signIn(){if(await this.connect(),!this.viewerSupported)return{started:!1};let e=await this.request({method:pr},{});return{started:B(e)&&e.started===!0}}async requestJson(e,t,n,s,i={}){if(e===\\\"POST\\\"&&(t.endsWith(\\\"/tools/resolve\\\")||t.endsWith(\\\"/tools/invoke\\\"))){if(await this.connect(),!this.targetTools)throw new _(\\\"target_tools_unsupported\\\",\\\"Upgrade the Site host to use targeted tools\\\");if(!B(n))throw TypeError(\\\"Site target payload is required\\\");let r=n;return await this.request(t.endsWith(\\\"/tools/resolve\\\")?{method:\\\"resolve\\\",payload:{target:r.target}}:{method:\\\"invoke\\\",payload:fr(r)},i)}if(e===\\\"GET\\\"&&t.endsWith(\\\"/tools/catalog\\\"))return await this.request({method:\\\"catalog\\\"},i);if(e===\\\"GET\\\"&&t.endsWith(\\\"/tools/declarations\\\"))return await this.request({method:\\\"declarations\\\"},i);if(e===\\\"POST\\\"&&t.endsWith(\\\"/tools/calls\\\")){if(!B(n))throw TypeError(\\\"Site tool call payload is required\\\");return await this.request({method:\\\"call\\\",payload:yr(n)},i)}throw new _(\\\"unsupported_request\\\",\\\"Unsupported Site bridge request\\\")}close(){if(this.closed)return;this.closed=!0,this.bootstrap.close(),this.port?.close(),this.port=null}async request(e,t){let n=await this.connect(),s=crypto.randomUUID(),i=as(t.timeoutMs??this.options.requestTimeoutMs??120000,\\\"requestTimeoutMs\\\");return await new Promise((r,o)=>{let a=setTimeout(()=>{l(),os(n,s),o(e.method===\\\"call\\\"||e.method===\\\"invoke\\\"?new _(\\\"timeout\\\",\\\"Site tool request timed out after execution may have started\\\",!1,!0):new _(\\\"timeout\\\",\\\"Site tool request timed out\\\",!0))},i),c=()=>{l(),os(n,s),o(t.signal?.reason??new DOMException(\\\"Request aborted\\\",\\\"AbortError\\\"))},u=(p)=>{let d=p.data;if(!B(d)||d.type!==cr||d.version!==le||d.requestId!==s||typeof d.ok!==\\\"boolean\\\")return;if(l(),d.ok){r(d.value);return}let m=B(d.error)?d.error:{};o(new _(typeof m.code===\\\"string\\\"?m.code:\\\"bridge_error\\\",typeof m.message===\\\"string\\\"?m.message:\\\"Site tool request failed\\\",m.retryable===!0,m.outcomeUnknown===!0))},l=()=>{clearTimeout(a),t.signal?.removeEventListener(\\\"abort\\\",c),n.removeEventListener(\\\"message\\\",u)};if(t.signal?.aborted){c();return}t.signal?.addEventListener(\\\"abort\\\",c,{once:!0}),n.addEventListener(\\\"message\\\",u),n.postMessage({type:ar,version:le,requestId:s,...e})})}async connect(){if(this.closed)throw new _(\\\"closed\\\",\\\"Site bridge is closed\\\");if(this.port)return this.port;if(this.connecting)return await this.connecting;let e=(this.options.createMessageChannel??(()=>new MessageChannel))(),t=as(this.options.connectTimeoutMs??1e4,\\\"connectTimeoutMs\\\");return this.connecting=new Promise((n,s)=>{let i=!0,r=setTimeout(()=>{a(),e.port1.close(),s(new _(\\\"host_timeout\\\",\\\"The Site host did not respond\\\"))},t),o=(c)=>{let u=c.data;if(!B(u)||u.type!==cs||u.version!==le)return;a(),this.targetTools=u.targetTools===1,this.siteData=u.siteData===1,this.viewerSupported=u.viewer===1,this.port=e.port1,n(e.port1)},a=()=>{i=!1,clearTimeout(r),e.port1.removeEventListener(\\\"message\\\",o)};e.port1.addEventListener(\\\"message\\\",o),e.port1.start(),this.bootstrap.port().then((c)=>{if(!i)return;if(this.closed)throw new _(\\\"closed\\\",\\\"Site bridge is closed\\\");c.postMessage({type:or,version:le},[e.port2])}).catch((c)=>{a(),e.port1.close(),s(c)})}).finally(()=>{this.connecting=null}),await this.connecting}}function hr(e){if(e.bootstrapPort)return{port:async()=>e.bootstrapPort,close:()=>e.bootstrapPort?.close()};let t=e.siteWindow??globalThis.window,n=e.parentWindow??t?.parent;if(!t||!n||n===t)return{port:async()=>{throw new _(\\\"host_unavailable\\\",\\\"The Site client must run inside a hosted iframe\\\")},close:()=>{return}};let s=Rr(t);if(s)return{port:async()=>s,close:()=>{return}};let i=null,r=null,o=(l)=>{if(l.source!==n||!Sr(l.data)||l.ports.length!==1)return;c(),i=l.ports[0],i.start(),br(t,i),a?.(i)},a=null,c=()=>t.removeEventListener(\\\"message\\\",o),u=new Promise((l,p)=>{a=l,r=p,t.addEventListener(\\\"message\\\",o)});return u.catch(()=>{return}),{port:async()=>await u,close:()=>{c(),r?.(new _(\\\"closed\\\",\\\"Site bridge is closed\\\")),a=null,r=null}}}function Rr(e){let t=e[us];if(!B(t))return null;let n=t.port;return n&&typeof n.postMessage===\\\"function\\\"&&typeof n.addEventListener===\\\"function\\\"&&typeof n.start===\\\"function\\\"?n:null}function br(e,t){try{Object.defineProperty(e,us,{configurable:!0,value:{port:t}})}catch{}}function Sr(e){return B(e)&&e.type===cs&&e.version===le}var wr=[\\\"member\\\",\\\"invited\\\",\\\"user\\\",\\\"guest\\\"];async function vr(e){try{if(!await e.siteDataSupported())return null;let t=await e.fetch(\\\"https://site.opengeni.invalid/v1/workspaces/site-host/site/config\\\",{method:\\\"GET\\\",headers:{accept:\\\"application/json\\\"}});if(!t.ok)return await t.body?.cancel(),null;let n=(await t.json())?.capabilities;return kr(n)?n:null}catch{return null}}function kr(e){return B(e)&&typeof e.agent===\\\"boolean\\\"&&typeof e.workspaceTools===\\\"boolean\\\"&&(e.siteData===\\\"viewer\\\"||e.siteData===\\\"guest\\\")&&Array.isArray(e.sqlQueryAudiences)&&e.sqlQueryAudiences.every((t)=>t===\\\"everyone\\\"||t===\\\"signed_in\\\")&&(e.viewAs===null||e.viewAs===\\\"invited\\\"||e.viewAs===\\\"public\\\")}function Ir(e){return B(e)&&wr.includes(String(e.kind))&&typeof e.id===\\\"string\\\"&&e.id.length>0&&(e.name===null||typeof e.name===\\\"string\\\")&&(e.email===null||typeof e.email===\\\"string\\\")&&typeof e.signedIn===\\\"boolean\\\"}function os(e,t){e.postMessage({type:ur,version:le,requestId:t})}function as(e,t){if(!Number.isFinite(e)||e<=0)throw RangeError(`${t} must be positive`);return e}function B(e){return typeof e===\\\"object\\\"&&e!==null&&!Array.isArray(e)}Object.defineProperty(globalThis,\\\"createOpenGeniSiteClient\\\",{configurable:!0,value:ls});})();\\n\";\n","import { SITE_BROWSER_RUNTIME } from \"./site-browser-runtime.gen\";\n\nexport const SITE_CLIENT_SCRIPT_PATH = \"/__opengeni/site-tools/client.js\";\nexport { SITE_BROWSER_RUNTIME };\n\n/** Resolve only the optional client tag; ordinary bundled Sites remain unchanged. */\nexport function resolveSiteClientScript(html: string): string {\n // Consume whole scripts/comments so examples inside JS or comments stay literal.\n return html.replace(/<!--[\\s\\S]*?-->|<script\\b[^>]*>[\\s\\S]*?<\\/script\\s*>/gi, (tag) => {\n if (\n !/^<script\\s+src\\s*=\\s*([\"'])\\/__opengeni\\/site-tools\\/client\\.js\\1\\s*>\\s*<\\/script\\s*>$/i.test(\n tag,\n )\n )\n return tag;\n return \"<script>\" + SITE_BROWSER_RUNTIME.replace(/<\\/script/gi, \"<\\\\/script\") + \"</script>\";\n });\n}\n"],"mappings":";AACO,IAAM,uBAAuB;;;ACC7B,IAAM,0BAA0B;AAIhC,SAAS,wBAAwB,MAAsB;AAE5D,SAAO,KAAK,QAAQ,0DAA0D,CAAC,QAAQ;AACrF,QACE,CAAC,0FAA0F;AAAA,MACzF;AAAA,IACF;AAEA,aAAO;AACT,WAAO,aAAa,qBAAqB,QAAQ,eAAe,YAAY,IAAI;AAAA,EAClF,CAAC;AACH;","names":[]}