@alva-ai/toolkit 0.25.2-beta.0 → 0.26.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.
@@ -223,5 +223,5 @@ mutation ToolkitUpdateAgentSchedule($input: UpdateChannelScheduleInput!) {
223
223
  }`.trim(),_n=`
224
224
  query ToolkitAgentChannel {
225
225
  viewer { channels { id kind } }
226
- }`.trim(),Rn=/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/,Pn=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[+-](\d{2}):(\d{2}))$/i,vn=/^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/,En={INVALID_ARGUMENT:400,UNAUTHENTICATED:401,PERMISSION_DENIED:403,NOT_FOUND:404,ALREADY_EXISTS:409,ABORTED:409,FAILED_PRECONDITION:412,RESOURCE_EXHAUSTED:429,INTERNAL:500,UNKNOWN:500,DATA_LOSS:500,UNAVAILABLE:503,DEADLINE_EXCEEDED:504},x=class{constructor(e){this.client=e}client;static{i(this,"SchedulesResource")}async list(e){this.client._requireAuth();let n=$e(e.channelId),r=[],s=null,o=new Set;for(;;){let l=(await this.graphql(kn,{channelId:n,after:s})).viewer?.channel?.schedules;if(!l?.edges)throw Et();for(let d of l.edges){if(!d?.node)throw h();r.push(je(d.node))}if(l.pageInfo?.hasNextPage!==!0)return r;let u=l.pageInfo.endCursor;if(!u||o.has(u))throw h();o.add(u),s=u}}async put(e){this.client._requireAuth();let n={channelId:$e(e.channelId),name:St(e.name),definition:{...An(e.rule,e.bounds),message:{text:Tn(e.text)}}},s=(await this.graphql(Me,{input:n})).updateChannelSchedule?.schedule;if(!s)throw h();return je(s)}pause(e){return this.manage("PAUSED",e)}resume(e){return this.manage("ACTIVE",e)}async delete(e){if(this.client._requireAuth(),(await this.graphql(Me,{input:{...vt(e),lifecycle:"REMOVED"}})).updateChannelSchedule?.deleted!==!0)throw h()}async agentChannelId(){this.client._requireAuth();let n=(await this.graphql(_n)).viewer?.channels?.find(r=>r.kind==="AGENT")?.id;if(!n)throw Et();return n}async manage(e,n){this.client._requireAuth();let s=(await this.graphql(Me,{input:{...vt(n),lifecycle:e}})).updateChannelSchedule?.schedule;if(!s)throw h();return je(s)}async graphql(e,n){let r=await this.client._request("POST","/query",{body:n===void 0?{query:e}:{query:e,variables:n}});if(r.errors?.length){let s=r.errors.map(d=>d.extensions?.code),a=new Set(s).size===1&&typeof s[0]=="string"?s[0]:void 0,l=a?En[a]:void 0,u=a!==void 0&&l!==void 0?a:"GRAPHQL_ERROR";throw new c(u,r.errors.map(d=>d.message).filter(d=>typeof d=="string").join("; ")||"GraphQL request failed",l??502,{errors:r.errors})}if(!r.data)throw h();return r.data}};function An(t,e){let n=Sn(e);switch(t.kind){case"after":if(n)throw y("after does not accept recurring bounds");let r=Date.now()+wt(t.duration,1),s=Math.ceil(r/1e3)*1e3;if(!Number.isSafeInteger(s)||Number.isNaN(new Date(s).getTime()))throw y("after is out of range");return{rule:{kind:"AT",atMs:s}};case"at":if(n)throw y("at does not accept recurring bounds");return{rule:{kind:"AT",atMs:Be(t.timestamp)}};case"every":return{rule:{kind:"EVERY",everyIntervalSeconds:Cn(t.interval)},...n?{bounds:n}:{}};case"cron":if(!t.expression.trim()||!t.timezone.trim())throw y("cron expression and timezone are required");return{rule:{kind:"CRON",cronExpression:t.expression,cronTimezone:t.timezone},...n?{bounds:n}:{}}}}i(An,"ruleInput");function Sn(t){if(!t)return;let e={};if(t.startsAt!==void 0&&(e.startsAtMs=Be(t.startsAt)),t.until!==void 0&&(e.untilMs=Be(t.until)),t.maxOccurrences!==void 0){if(!Number.isSafeInteger(t.maxOccurrences)||t.maxOccurrences<=0)throw y("maxOccurrences must be a positive safe integer");e.maxOccurrences=t.maxOccurrences}return Object.keys(e).length>0?e:void 0}i(Sn,"boundsInput");function je(t){let n={ACTIVE:"active",PAUSED:"paused",COMPLETED:"completed",FAILED:"failed"}[t.status];if(!n)throw h();let r=t.bounds??{},s=t.message??{},o={name:t.name,rule:wn(t.rule),bounds:{...r.startsAtMs!=null?{startsAt:v(r.startsAtMs,!0)}:{},...r.untilMs!=null?{until:v(r.untilMs,!0)}:{},...r.maxOccurrences!=null?{maxOccurrences:Qe(r.maxOccurrences,"maxOccurrences")}:{}},text:s.text??"",status:n,occurrencesUsed:Qe(t.occurrencesUsed,"occurrencesUsed"),...t.nextFireAtMs!=null?{nextFireAt:v(t.nextFireAtMs,!0)}:{},createdAt:v(t.createdAtMs),updatedAt:v(t.updatedAtMs)};if(n==="failed"){if(!t.failureCode)throw h();let l={TARGET_INVALID:"target_invalid",DELIVERY_EXHAUSTED:"delivery_exhausted",PAYLOAD_CONFLICT:"payload_conflict"}[t.failureCode];if(!l)throw h();o.failure={code:l,...t.failureAtMs!=null?{at:v(t.failureAtMs)}:{}}}return o}i(je,"fromWireSchedule");function wn(t){switch(t.kind){case"AT":if(t.atMs==null)throw h();return{kind:"at",timestamp:v(t.atMs,!0)};case"EVERY":if(t.everyIntervalSeconds==null)throw h();return{kind:"every",interval:`PT${Qe(t.everyIntervalSeconds,"interval")}S`};case"CRON":if(!t.cronExpression||!t.cronTimezone)throw h();return{kind:"cron",expression:t.cronExpression,timezone:t.cronTimezone}}throw h()}i(wn,"fromWireRule");function vt(t){return{channelId:$e(t.channelId),name:St(t.name)}}i(vt,"managementInput");function $e(t){if(typeof t=="number"&&(!Number.isSafeInteger(t)||t<=0))throw y("numeric channelId must be a positive safe integer; use a decimal string for larger IDs");let e=String(t);if(!/^[1-9]\d*$/.test(e))throw y("channelId must be a positive integer");return e}i($e,"channelID");function St(t){if(!Rn.test(t))throw y("name must be 1-63 lowercase alphanumeric characters or hyphens");return t}i(St,"requireName");function Tn(t){let e=qn(t);if(e===void 0||!t.trim()||e>16*1024)throw y("text must be 1..16384 UTF-8 bytes");return t}i(Tn,"requireText");function Cn(t){let e=wt(t,60);if(e%1e3!==0)throw y("duration must resolve to whole seconds");return e/1e3}i(Cn,"durationSeconds");function wt(t,e){let n=vn.exec(t);if(!n||n.slice(1,5).every(d=>d===void 0)||t.includes("T")&&n.slice(2,5).every(d=>d===void 0))throw y("duration must be a positive ISO 8601 day/time duration");let[r,s,o,a]=n.slice(1,5).map(d=>BigInt(d??"0")),l=((r*24n+s)*60n+o)*60n+a;if(l<BigInt(e))throw y(`duration must be at least ${e} whole seconds`);let u=Number(l*1000n);if(!Number.isSafeInteger(u))throw y("duration is out of range");return u}i(wt,"durationMilliseconds");function Be(t){let e=Pn.exec(t);if(!e)throw y("timestamp must be RFC3339 with a timezone");let[n,r,s,o,a,l]=e.slice(1,7).map(Number),u=Number(e[8]??0),d=Number(e[9]??0),p=new Date(Date.UTC(n,r,0)).getUTCDate(),_=Date.parse(t);if(!Number.isFinite(_)||n<1||n>9999||r<1||r>12||s<1||s>p||o>23||a>59||l>59||u>23||d>59)throw y("timestamp must be RFC3339 with a timezone");return _}i(Be,"timestampMilliseconds");function v(t,e=!1){if(!Number.isSafeInteger(t)||e&&t%1e3!==0)throw h();let n=new Date(t);if(Number.isNaN(n.getTime()))throw h();return n.toISOString()}i(v,"timestampString");function Qe(t,e){let n=Number(t);if(!Number.isSafeInteger(n)||n<0)throw y(`${e} exceeds JavaScript safe integer range`);return n}i(Qe,"safeInteger");function y(t){return new c("INVALID_ARGUMENT",t,400)}i(y,"invalid");function qn(t){let e=new TextEncoder().encode(t);return new TextDecoder("utf-8",{fatal:!0}).decode(e)===t?e.byteLength:void 0}i(qn,"utf8Size");function Et(){return new c("NOT_FOUND","channel schedule target not found",404)}i(Et,"scheduleNotFound");function h(){return new c("GRAPHQL_EMPTY_RESPONSE","GraphQL response did not include a valid schedule",502)}i(h,"scheduleEmptyResponse");var In="https://api-llm.prd.alva.ai",xn="https://data-tools.prd.space.id";function We(t){return typeof t=="object"&&t!==null}i(We,"isRecord");function we(t,e){if(!We(t))return;let n=t[e];return typeof n=="string"&&n?n:void 0}i(we,"stringField");function Nn(t){if(t==null)return{};let e={};if(t instanceof Error){t.name&&(e.name=t.name),t.message&&(e.message=t.message);let r=we(t,"code");r&&(e.code=r)}else if(We(t)){let r=we(t,"code"),s=we(t,"name"),o=we(t,"message");r&&(e.code=r),s&&(e.name=s),o&&(e.message=o)}else e.message=String(t);let n=[e.code,e.name,e.message].filter(r=>!!r);return{message:n.length>0?n.join(": "):void 0,details:Object.keys(e).length>0?e:void 0}}i(Nn,"describeCause");function Gn(t){let e=t instanceof Error&&t.message?t.message:"Network request failed",n={};t instanceof Error?(n.name=t.name,n.message=t.message):n.message=String(t);let{message:r,details:s}=Nn(We(t)?t.cause:void 0);return s&&(n.cause=s),{message:r?`${e}; cause: ${r}`:e,details:n}}i(Gn,"describeFetchFailure");var Te=class{static{i(this,"AlvaClient")}baseUrl;arraysBaseUrl;viewer_token;pbsvToken;apiKey;gaClientId;gaSessionId;utmParams;signal;originSessionId;originSessionKind;_fs;_run;_deploy;_serviceAccount;_release;_feed;_automation;_playbooks;_secrets;_sdk;_dataSkills;_playbookSkills;_comments;_remix;_screenshot;_user;_trading;_portfolio;_arraysJwt;_notifications;_notificationPreferences;_subscriptions;_alerts;_channelGroupSubscriptions;_feedback;_functions;_credits;_markets;_schedules;constructor(e){this.baseUrl=e.baseUrl??In,this.arraysBaseUrl=e.arraysBaseUrl??xn,this.viewer_token=e.viewer_token,this.pbsvToken=e.pbsvToken,this.apiKey=e.apiKey,this.gaClientId=e.gaClientId,this.gaSessionId=e.gaSessionId,this.utmParams=e.utmParams,this.signal=e.signal,this.originSessionId=e.originSessionId,this.originSessionKind=e.originSessionKind}get fs(){return this._fs??=new ee(this)}get run(){return this._run??=new te(this)}get deploy(){return this._deploy??=new ne(this)}get serviceAccount(){return this._serviceAccount??=new re(this)}get release(){return this._release??=new ie(this)}get feed(){return this._feed??=new oe(this)}get automation(){return this._automation??=new C(this)}get playbooks(){return this._playbooks??=new le(this)}get secrets(){return this._secrets??=new ce(this)}get sdk(){return this._sdk??=new ue(this)}get dataSkills(){return this._dataSkills??=new de(this)}get playbookSkills(){return this._playbookSkills??=new pe(this)}get comments(){return this._comments??=new me(this)}get remix(){return this._remix??=new he(this)}get screenshot(){return this._screenshot??=new ye(this)}get user(){return this._user??=new fe(this)}get trading(){return this._trading??=new ge(this)}get portfolio(){return this._portfolio??=new be(this)}get arraysJwt(){return this._arraysJwt??=new ke(this)}get notifications(){return this._notifications??=new _e(this)}get notificationPreferences(){return this._notificationPreferences??=new Re(this)}get subscriptions(){return this._subscriptions??=new Pe(this)}get alerts(){return this._alerts??=new q(this)}get channelGroupSubscriptions(){return this._channelGroupSubscriptions??=new ve(this)}get feedback(){return this._feedback??=new Ee(this)}get functions(){return this._functions??=new Ae(this)}get credits(){return this._credits??=new Se(this)}get markets(){return this._markets??=new I(this)}get schedules(){return this._schedules??=new x(this)}_requireAuth(){if(!this.pbsvToken&&!this.viewer_token&&!this.apiKey)throw new c("UNAUTHENTICATED","Authentication is required. Pass pbsvToken, viewer_token, or apiKey in the constructor.",401)}async _request(e,n,r){let o=`${r?.baseUrl??this.baseUrl}${n}`;if(r?.query){let b=new URLSearchParams;for(let[R,Ce]of Object.entries(r.query))Ce!=null&&b.set(R,String(Ce));let A=b.toString();A&&(o+=`?${A}`)}let a={};r?.noAuth||(this.pbsvToken?(a.Authorization=`Bearer ${this.pbsvToken}`,a["X-Pbsv"]="1"):this.viewer_token?a["x-Playbook-Viewer"]=this.viewer_token:this.apiKey&&(a["X-Alva-Api-Key"]=this.apiKey)),this.gaClientId&&(a["X-Alva-GA-Client-ID"]=this.gaClientId),this.gaSessionId&&(a["X-Alva-GA-Session-ID"]=this.gaSessionId),this.utmParams&&(a["X-Alva-UTM-Params"]=this.utmParams),this.originSessionId&&!r?.noAuth&&(a["X-Alva-Origin-Session-Id"]=this.originSessionId);let l;r?.rawBody!==void 0?(a["Content-Type"]="application/octet-stream",l=r.rawBody):r?.jsonBody!==void 0?(a["Content-Type"]="application/json",l=r.jsonBody):r?.body!==void 0&&(a["Content-Type"]="application/json",l=JSON.stringify(r.body));let u,d=r?.timeoutMs,p=r?.signal??this.signal;if(p?.aborted)throw new c("NETWORK_ABORTED",`Request aborted while calling ${e} ${n}`,0,{method:e,path:n});let _=d!==void 0?new AbortController:void 0,N=!1,E,z;_&&d!==void 0&&(p&&(z=i(()=>_.abort(p.reason),"abortListener"),p.addEventListener("abort",z,{once:!0})),E=setTimeout(()=>{N=!0,_.abort(new Error(`Request timed out after ${d}ms while calling ${e} ${n}`))},d));let Ve={method:e,headers:a,body:l,signal:_?.signal??p};d!==void 0&&(Ve.timeout=d);try{u=await fetch(o,Ve)}catch(b){if(p?.aborted&&!N)throw new c("NETWORK_ABORTED",`Request aborted while calling ${e} ${n}`,0,{method:e,path:n});if(N)throw new c("NETWORK_TIMEOUT",`Request timed out after ${d}ms while calling ${e} ${n}`,0,{method:e,path:n,timeout_ms:d});let A=Gn(b);throw new c("NETWORK_ERROR",A.message,0,{method:e,path:n,...A.details})}finally{z&&p&&p.removeEventListener("abort",z),E!==void 0&&clearTimeout(E)}if(!u.ok){let b="";try{b=await Promise.resolve(u.text())}catch{b=""}if((u.headers.get("content-type")??"").includes("application/json")&&b)try{let R=JSON.parse(b);if(R.error)throw new c(R.error.code??"UNKNOWN",R.error.message??`HTTP ${u.status}`,u.status)}catch(R){if(R instanceof c)throw R}throw new c("UNKNOWN",`HTTP ${u.status}: ${b.slice(0,200)}`,u.status)}if(u.status===204)return;let He=(u.headers.get("content-type")??"").toLowerCase();return He.includes("application/json")||He.includes("+json")?u.json():u.arrayBuffer()}};var Fn="0.25.2-beta.0";Fe();return Nt(Un);})();
226
+ }`.trim(),Rn=/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/,Pn=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[+-](\d{2}):(\d{2}))$/i,vn=/^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/,En={INVALID_ARGUMENT:400,UNAUTHENTICATED:401,PERMISSION_DENIED:403,NOT_FOUND:404,ALREADY_EXISTS:409,ABORTED:409,FAILED_PRECONDITION:412,RESOURCE_EXHAUSTED:429,INTERNAL:500,UNKNOWN:500,DATA_LOSS:500,UNAVAILABLE:503,DEADLINE_EXCEEDED:504},x=class{constructor(e){this.client=e}client;static{i(this,"SchedulesResource")}async list(e){this.client._requireAuth();let n=$e(e.channelId),r=[],s=null,o=new Set;for(;;){let l=(await this.graphql(kn,{channelId:n,after:s})).viewer?.channel?.schedules;if(!l?.edges)throw Et();for(let d of l.edges){if(!d?.node)throw h();r.push(je(d.node))}if(l.pageInfo?.hasNextPage!==!0)return r;let u=l.pageInfo.endCursor;if(!u||o.has(u))throw h();o.add(u),s=u}}async put(e){this.client._requireAuth();let n={channelId:$e(e.channelId),name:St(e.name),definition:{...An(e.rule,e.bounds),message:{text:Tn(e.text)}}},s=(await this.graphql(Me,{input:n})).updateChannelSchedule?.schedule;if(!s)throw h();return je(s)}pause(e){return this.manage("PAUSED",e)}resume(e){return this.manage("ACTIVE",e)}async delete(e){if(this.client._requireAuth(),(await this.graphql(Me,{input:{...vt(e),lifecycle:"REMOVED"}})).updateChannelSchedule?.deleted!==!0)throw h()}async agentChannelId(){this.client._requireAuth();let n=(await this.graphql(_n)).viewer?.channels?.find(r=>r.kind==="AGENT")?.id;if(!n)throw Et();return n}async manage(e,n){this.client._requireAuth();let s=(await this.graphql(Me,{input:{...vt(n),lifecycle:e}})).updateChannelSchedule?.schedule;if(!s)throw h();return je(s)}async graphql(e,n){let r=await this.client._request("POST","/query",{body:n===void 0?{query:e}:{query:e,variables:n}});if(r.errors?.length){let s=r.errors.map(d=>d.extensions?.code),a=new Set(s).size===1&&typeof s[0]=="string"?s[0]:void 0,l=a?En[a]:void 0,u=a!==void 0&&l!==void 0?a:"GRAPHQL_ERROR";throw new c(u,r.errors.map(d=>d.message).filter(d=>typeof d=="string").join("; ")||"GraphQL request failed",l??502,{errors:r.errors})}if(!r.data)throw h();return r.data}};function An(t,e){let n=Sn(e);switch(t.kind){case"after":if(n)throw y("after does not accept recurring bounds");let r=Date.now()+wt(t.duration,1),s=Math.ceil(r/1e3)*1e3;if(!Number.isSafeInteger(s)||Number.isNaN(new Date(s).getTime()))throw y("after is out of range");return{rule:{kind:"AT",atMs:s}};case"at":if(n)throw y("at does not accept recurring bounds");return{rule:{kind:"AT",atMs:Be(t.timestamp)}};case"every":return{rule:{kind:"EVERY",everyIntervalSeconds:Cn(t.interval)},...n?{bounds:n}:{}};case"cron":if(!t.expression.trim()||!t.timezone.trim())throw y("cron expression and timezone are required");return{rule:{kind:"CRON",cronExpression:t.expression,cronTimezone:t.timezone},...n?{bounds:n}:{}}}}i(An,"ruleInput");function Sn(t){if(!t)return;let e={};if(t.startsAt!==void 0&&(e.startsAtMs=Be(t.startsAt)),t.until!==void 0&&(e.untilMs=Be(t.until)),t.maxOccurrences!==void 0){if(!Number.isSafeInteger(t.maxOccurrences)||t.maxOccurrences<=0)throw y("maxOccurrences must be a positive safe integer");e.maxOccurrences=t.maxOccurrences}return Object.keys(e).length>0?e:void 0}i(Sn,"boundsInput");function je(t){let n={ACTIVE:"active",PAUSED:"paused",COMPLETED:"completed",FAILED:"failed"}[t.status];if(!n)throw h();let r=t.bounds??{},s=t.message??{},o={name:t.name,rule:wn(t.rule),bounds:{...r.startsAtMs!=null?{startsAt:v(r.startsAtMs,!0)}:{},...r.untilMs!=null?{until:v(r.untilMs,!0)}:{},...r.maxOccurrences!=null?{maxOccurrences:Qe(r.maxOccurrences,"maxOccurrences")}:{}},text:s.text??"",status:n,occurrencesUsed:Qe(t.occurrencesUsed,"occurrencesUsed"),...t.nextFireAtMs!=null?{nextFireAt:v(t.nextFireAtMs,!0)}:{},createdAt:v(t.createdAtMs),updatedAt:v(t.updatedAtMs)};if(n==="failed"){if(!t.failureCode)throw h();let l={TARGET_INVALID:"target_invalid",DELIVERY_EXHAUSTED:"delivery_exhausted",PAYLOAD_CONFLICT:"payload_conflict"}[t.failureCode];if(!l)throw h();o.failure={code:l,...t.failureAtMs!=null?{at:v(t.failureAtMs)}:{}}}return o}i(je,"fromWireSchedule");function wn(t){switch(t.kind){case"AT":if(t.atMs==null)throw h();return{kind:"at",timestamp:v(t.atMs,!0)};case"EVERY":if(t.everyIntervalSeconds==null)throw h();return{kind:"every",interval:`PT${Qe(t.everyIntervalSeconds,"interval")}S`};case"CRON":if(!t.cronExpression||!t.cronTimezone)throw h();return{kind:"cron",expression:t.cronExpression,timezone:t.cronTimezone}}throw h()}i(wn,"fromWireRule");function vt(t){return{channelId:$e(t.channelId),name:St(t.name)}}i(vt,"managementInput");function $e(t){if(typeof t=="number"&&(!Number.isSafeInteger(t)||t<=0))throw y("numeric channelId must be a positive safe integer; use a decimal string for larger IDs");let e=String(t);if(!/^[1-9]\d*$/.test(e))throw y("channelId must be a positive integer");return e}i($e,"channelID");function St(t){if(!Rn.test(t))throw y("name must be 1-63 lowercase alphanumeric characters or hyphens");return t}i(St,"requireName");function Tn(t){let e=qn(t);if(e===void 0||!t.trim()||e>16*1024)throw y("text must be 1..16384 UTF-8 bytes");return t}i(Tn,"requireText");function Cn(t){let e=wt(t,60);if(e%1e3!==0)throw y("duration must resolve to whole seconds");return e/1e3}i(Cn,"durationSeconds");function wt(t,e){let n=vn.exec(t);if(!n||n.slice(1,5).every(d=>d===void 0)||t.includes("T")&&n.slice(2,5).every(d=>d===void 0))throw y("duration must be a positive ISO 8601 day/time duration");let[r,s,o,a]=n.slice(1,5).map(d=>BigInt(d??"0")),l=((r*24n+s)*60n+o)*60n+a;if(l<BigInt(e))throw y(`duration must be at least ${e} whole seconds`);let u=Number(l*1000n);if(!Number.isSafeInteger(u))throw y("duration is out of range");return u}i(wt,"durationMilliseconds");function Be(t){let e=Pn.exec(t);if(!e)throw y("timestamp must be RFC3339 with a timezone");let[n,r,s,o,a,l]=e.slice(1,7).map(Number),u=Number(e[8]??0),d=Number(e[9]??0),p=new Date(Date.UTC(n,r,0)).getUTCDate(),_=Date.parse(t);if(!Number.isFinite(_)||n<1||n>9999||r<1||r>12||s<1||s>p||o>23||a>59||l>59||u>23||d>59)throw y("timestamp must be RFC3339 with a timezone");return _}i(Be,"timestampMilliseconds");function v(t,e=!1){if(!Number.isSafeInteger(t)||e&&t%1e3!==0)throw h();let n=new Date(t);if(Number.isNaN(n.getTime()))throw h();return n.toISOString()}i(v,"timestampString");function Qe(t,e){let n=Number(t);if(!Number.isSafeInteger(n)||n<0)throw y(`${e} exceeds JavaScript safe integer range`);return n}i(Qe,"safeInteger");function y(t){return new c("INVALID_ARGUMENT",t,400)}i(y,"invalid");function qn(t){let e=new TextEncoder().encode(t);return new TextDecoder("utf-8",{fatal:!0}).decode(e)===t?e.byteLength:void 0}i(qn,"utf8Size");function Et(){return new c("NOT_FOUND","channel schedule target not found",404)}i(Et,"scheduleNotFound");function h(){return new c("GRAPHQL_EMPTY_RESPONSE","GraphQL response did not include a valid schedule",502)}i(h,"scheduleEmptyResponse");var In="https://api-llm.prd.alva.ai",xn="https://data-tools.prd.space.id";function We(t){return typeof t=="object"&&t!==null}i(We,"isRecord");function we(t,e){if(!We(t))return;let n=t[e];return typeof n=="string"&&n?n:void 0}i(we,"stringField");function Nn(t){if(t==null)return{};let e={};if(t instanceof Error){t.name&&(e.name=t.name),t.message&&(e.message=t.message);let r=we(t,"code");r&&(e.code=r)}else if(We(t)){let r=we(t,"code"),s=we(t,"name"),o=we(t,"message");r&&(e.code=r),s&&(e.name=s),o&&(e.message=o)}else e.message=String(t);let n=[e.code,e.name,e.message].filter(r=>!!r);return{message:n.length>0?n.join(": "):void 0,details:Object.keys(e).length>0?e:void 0}}i(Nn,"describeCause");function Gn(t){let e=t instanceof Error&&t.message?t.message:"Network request failed",n={};t instanceof Error?(n.name=t.name,n.message=t.message):n.message=String(t);let{message:r,details:s}=Nn(We(t)?t.cause:void 0);return s&&(n.cause=s),{message:r?`${e}; cause: ${r}`:e,details:n}}i(Gn,"describeFetchFailure");var Te=class{static{i(this,"AlvaClient")}baseUrl;arraysBaseUrl;viewer_token;pbsvToken;apiKey;gaClientId;gaSessionId;utmParams;signal;originSessionId;originSessionKind;_fs;_run;_deploy;_serviceAccount;_release;_feed;_automation;_playbooks;_secrets;_sdk;_dataSkills;_playbookSkills;_comments;_remix;_screenshot;_user;_trading;_portfolio;_arraysJwt;_notifications;_notificationPreferences;_subscriptions;_alerts;_channelGroupSubscriptions;_feedback;_functions;_credits;_markets;_schedules;constructor(e){this.baseUrl=e.baseUrl??In,this.arraysBaseUrl=e.arraysBaseUrl??xn,this.viewer_token=e.viewer_token,this.pbsvToken=e.pbsvToken,this.apiKey=e.apiKey,this.gaClientId=e.gaClientId,this.gaSessionId=e.gaSessionId,this.utmParams=e.utmParams,this.signal=e.signal,this.originSessionId=e.originSessionId,this.originSessionKind=e.originSessionKind}get fs(){return this._fs??=new ee(this)}get run(){return this._run??=new te(this)}get deploy(){return this._deploy??=new ne(this)}get serviceAccount(){return this._serviceAccount??=new re(this)}get release(){return this._release??=new ie(this)}get feed(){return this._feed??=new oe(this)}get automation(){return this._automation??=new C(this)}get playbooks(){return this._playbooks??=new le(this)}get secrets(){return this._secrets??=new ce(this)}get sdk(){return this._sdk??=new ue(this)}get dataSkills(){return this._dataSkills??=new de(this)}get playbookSkills(){return this._playbookSkills??=new pe(this)}get comments(){return this._comments??=new me(this)}get remix(){return this._remix??=new he(this)}get screenshot(){return this._screenshot??=new ye(this)}get user(){return this._user??=new fe(this)}get trading(){return this._trading??=new ge(this)}get portfolio(){return this._portfolio??=new be(this)}get arraysJwt(){return this._arraysJwt??=new ke(this)}get notifications(){return this._notifications??=new _e(this)}get notificationPreferences(){return this._notificationPreferences??=new Re(this)}get subscriptions(){return this._subscriptions??=new Pe(this)}get alerts(){return this._alerts??=new q(this)}get channelGroupSubscriptions(){return this._channelGroupSubscriptions??=new ve(this)}get feedback(){return this._feedback??=new Ee(this)}get functions(){return this._functions??=new Ae(this)}get credits(){return this._credits??=new Se(this)}get markets(){return this._markets??=new I(this)}get schedules(){return this._schedules??=new x(this)}_requireAuth(){if(!this.pbsvToken&&!this.viewer_token&&!this.apiKey)throw new c("UNAUTHENTICATED","Authentication is required. Pass pbsvToken, viewer_token, or apiKey in the constructor.",401)}async _request(e,n,r){let o=`${r?.baseUrl??this.baseUrl}${n}`;if(r?.query){let b=new URLSearchParams;for(let[R,Ce]of Object.entries(r.query))Ce!=null&&b.set(R,String(Ce));let A=b.toString();A&&(o+=`?${A}`)}let a={};r?.noAuth||(this.pbsvToken?(a.Authorization=`Bearer ${this.pbsvToken}`,a["X-Pbsv"]="1"):this.viewer_token?a["x-Playbook-Viewer"]=this.viewer_token:this.apiKey&&(a["X-Alva-Api-Key"]=this.apiKey)),this.gaClientId&&(a["X-Alva-GA-Client-ID"]=this.gaClientId),this.gaSessionId&&(a["X-Alva-GA-Session-ID"]=this.gaSessionId),this.utmParams&&(a["X-Alva-UTM-Params"]=this.utmParams),this.originSessionId&&!r?.noAuth&&(a["X-Alva-Origin-Session-Id"]=this.originSessionId);let l;r?.rawBody!==void 0?(a["Content-Type"]="application/octet-stream",l=r.rawBody):r?.jsonBody!==void 0?(a["Content-Type"]="application/json",l=r.jsonBody):r?.body!==void 0&&(a["Content-Type"]="application/json",l=JSON.stringify(r.body));let u,d=r?.timeoutMs,p=r?.signal??this.signal;if(p?.aborted)throw new c("NETWORK_ABORTED",`Request aborted while calling ${e} ${n}`,0,{method:e,path:n});let _=d!==void 0?new AbortController:void 0,N=!1,E,z;_&&d!==void 0&&(p&&(z=i(()=>_.abort(p.reason),"abortListener"),p.addEventListener("abort",z,{once:!0})),E=setTimeout(()=>{N=!0,_.abort(new Error(`Request timed out after ${d}ms while calling ${e} ${n}`))},d));let Ve={method:e,headers:a,body:l,signal:_?.signal??p};d!==void 0&&(Ve.timeout=d);try{u=await fetch(o,Ve)}catch(b){if(p?.aborted&&!N)throw new c("NETWORK_ABORTED",`Request aborted while calling ${e} ${n}`,0,{method:e,path:n});if(N)throw new c("NETWORK_TIMEOUT",`Request timed out after ${d}ms while calling ${e} ${n}`,0,{method:e,path:n,timeout_ms:d});let A=Gn(b);throw new c("NETWORK_ERROR",A.message,0,{method:e,path:n,...A.details})}finally{z&&p&&p.removeEventListener("abort",z),E!==void 0&&clearTimeout(E)}if(!u.ok){let b="";try{b=await Promise.resolve(u.text())}catch{b=""}if((u.headers.get("content-type")??"").includes("application/json")&&b)try{let R=JSON.parse(b);if(R.error)throw new c(R.error.code??"UNKNOWN",R.error.message??`HTTP ${u.status}`,u.status)}catch(R){if(R instanceof c)throw R}throw new c("UNKNOWN",`HTTP ${u.status}: ${b.slice(0,200)}`,u.status)}if(u.status===204)return;let He=(u.headers.get("content-type")??"").toLowerCase();return He.includes("application/json")||He.includes("+json")?u.json():u.arrayBuffer()}};var Fn="0.26.0";Fe();return Nt(Un);})();
227
227
  //# sourceMappingURL=browser.global.js.map