@alva-ai/toolkit 0.31.0 → 0.32.0-beta.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.
@@ -325,5 +325,5 @@ mutation ToolkitStewardBriefed($input: CompleteStewardBriefInput!) {
325
325
  viewer { thesisAssetCandidates(input: $input) {
326
326
  mentions { quote ticker resolution stance candidates { entityId ticker name kind } }
327
327
  } }
328
- }`,variables:{input:{text:n}}}});if(Array.isArray(i?.errors)&&i.errors.length>0)throw new l("GRAPHQL_ERROR","Asset extraction failed",400,{errors:i.errors});let s=i?.data,o=g(s)?s.viewer:void 0,a=g(o)?o.thesisAssetCandidates:void 0;if(!g(a)||!Array.isArray(a.mentions))throw p("asset candidates response must contain mentions");return{mentions:a.mentions.map((u,d)=>{if(!g(u)||typeof u.quote!="string"||typeof u.ticker!="string"||!["RESOLVED","AMBIGUOUS","UNRESOLVED"].includes(u.resolution)||!["UNKNOWN","BULLISH","BEARISH"].includes(u.stance)||!Array.isArray(u.candidates))throw p(`asset mention ${d} is invalid`);let m=u.candidates.map(f=>{if(!g(f)||typeof f.ticker!="string"||typeof f.name!="string"||!["STOCK","ETF","CRYPTO","INDEX"].includes(f.kind))throw p(`asset mention ${d} has invalid candidate`);return{entityId:v(f.entityId,`asset mention ${d} candidate.entityId`),ticker:f.ticker,name:f.name,kind:f.kind}});return{...u,candidates:m}})}}async create(e){this.client._requireAuth();let n=rr(e);return z(await this.client._request("POST","/api/v1/theses",{body:n}))}async get(e){return this.client._requireAuth(),ar(await this.client._request("GET",`/api/v1/theses/${S(e,"id")}`))}async getVersion(e,n){this.client._requireAuth();let i=S(e,"id"),s=S(n,"author_version_id"),o=z(await this.client._request("GET",`/api/v1/theses/${i}/versions/${s}`));if(o.thesis.id!==i||o.thesis.author_version_id!==s)throw p("version response must match the requested thesis and author version");return o}async signals(e,n={}){this.client._requireAuth();let i=n.first??20;if(!Number.isInteger(i)||i<1||i>50)throw y("first must be an integer between 1 and 50");if(n.cursor!==void 0&&typeof n.cursor!="string")throw y("cursor must be a string");return cr(await this.client._request("GET",`/api/v1/theses/${S(e,"id")}/signals`,{query:{first:i,...n.cursor===void 0?{}:{cursor:n.cursor}}}),e,i)}async update(e,n){this.client._requireAuth();let i=or(n);return z(await this.client._request("PUT",`/api/v1/theses/${S(e,"id")}`,{body:i}))}async setVisibility(e,n){if(this.client._requireAuth(),!n)throw y("params is required");let i=S(e,"id"),s=nt(n.visibility),o=z(await this.client._request("POST",`/api/v1/theses/${i}/visibility`,{body:{visibility:s}}));if(o.thesis.id!==i||o.thesis.visibility!==s)throw p("visibility response must match the requested thesis and visibility");return o}async close(e,n){this.client._requireAuth();let i={expected_author_version_id:S(n.expected_author_version_id,"expected_author_version_id")};return n.note!==void 0&&(i.note=G(n.note,"note")),z(await this.client._request("POST",`/api/v1/theses/${S(e,"id")}/close`,{body:i}))}async delete(e){this.client._requireAuth();let n=await this.client._request("DELETE",`/api/v1/theses/${S(e,"id")}`);if(n===void 0)return{};if(!g(n)||Object.keys(n).length!==0)throw p("delete response must be {}");return{}}async rewrite(e){this.client._requireAuth();let n=ye(e.body),i=e.mode===void 0?"reformat":lr(e.mode),s=await this.client._request("POST","/api/v1/theses/rewrite",{body:{body:n,mode:i}});if(!g(s)||typeof s.body!="string")throw p("rewrite response must contain a string body");return{body:yn(s.body)}}};function rr(t){let e={request_id:hn(t.request_id),body:ye(t.body),title:kt(t.title??""),entity_ids:fn(t.entity_ids??[],"entity_ids"),visibility:nt(t.visibility??"public")};return t.tickers!==void 0&&(e.tickers=ur(t.tickers)),t.entity_stances!==void 0&&(e.entity_stances=sr(t.entity_stances,e.entity_ids)),e}r(rr,"createBody");function sr(t,e){if(!Array.isArray(t)||t.length>fe)throw y("entity_stances must contain at most 100 values");let n=new Set(e),i=new Set;return t.map((s,o)=>{if(!g(s))throw y(`entity_stances[${o}] must be an object`);let a=S(s.entity_id,`entity_stances[${o}].entity_id`);if(!n.has(a)||i.has(a))throw y("entity stance must reference one unique entity_id");if(i.add(a),!["unknown","bullish","bearish"].includes(s.stance))throw y(`entity_stances[${o}].stance is invalid`);return{entity_id:a,stance:s.stance}})}r(sr,"requireEntityStances");function or(t){return{request_id:hn(t.request_id),expected_author_version_id:S(t.expected_author_version_id,"expected_author_version_id"),body:ye(t.body),title:kt(t.title??""),entity_ids:fn(t.entity_ids??[],"entity_ids"),visibility:nt(t.visibility),editorial:t.editorial??!1}}r(or,"updateBody");function z(t){if(!g(t)||!g(t.thesis))throw p("response must contain thesis");let e=t.thesis,n={id:v(e.id,"thesis.id"),author_version_id:v(e.author_version_id,"thesis.author_version_id"),material_version_id:v(e.material_version_id,"thesis.material_version_id"),title:hr(e.title),body:yn(e.body),entity_ids:dr(e.entity_ids,"thesis.entity_ids"),visibility:mr(e.visibility),closed:tt(e.closed,"thesis.closed"),closing_note:pr(e.closing_note),author_kind:P(e.author_kind,"thesis.author_kind"),author_ref:P(e.author_ref,"thesis.author_ref")};if(e.entity_stances!==void 0){if(!Array.isArray(e.entity_stances))throw p("thesis.entity_stances must be an array");n.entity_stances=e.entity_stances.map(i=>{if(!g(i))throw p("thesis.entity_stances contains invalid entry");let s=v(i.entity_id,"entity_stances.entity_id");if(!n.entity_ids.includes(s))throw p("entity stance must reference a thesis entity");if(!["unknown","bullish","bearish"].includes(i.stance))throw p("thesis.entity_stances contains invalid stance");return{entity_id:s,stance:i.stance}})}return{thesis:n}}r(z,"thesisResponse");function ar(t){let e=z(t);if(!g(t)||!g(t.author))throw p("response must contain author");let n=t.author,i={id:v(n.id,"author.id"),kind:P(n.kind,"author.kind"),display_name:P(n.display_name,"author.display_name"),avatar_url:P(n.avatar_url,"author.avatar_url"),username:P(n.username,"author.username")};if(!Array.isArray(t.entities))throw p("response must contain entities");if(t.entities.length!==e.thesis.entity_ids.length)throw p("entities must match thesis.entity_ids");let s=t.entities.map((o,a)=>{if(!g(o))throw p(`entities[${a}] must be an object`);let c={id:v(o.id,`entities[${a}].id`),ticker:P(o.ticker,`entities[${a}].ticker`),name:P(o.name,`entities[${a}].name`),icon_url:P(o.icon_url,`entities[${a}].icon_url`),kind:P(o.kind,`entities[${a}].kind`)};if(c.id!==e.thesis.entity_ids[a])throw p("entities must preserve thesis.entity_ids order");return c});return{thesis:e.thesis,author:i,entities:s}}r(ar,"thesisGetResponse");function cr(t,e,n){if(!g(t)||!g(t.research)||!Array.isArray(t.entries)||t.entries.length>n)throw p("invalid Signal history response");let i=t.research,s={state:P(i.state,"research.state"),pending_work:et(i.pending_work,"research.pending_work"),read_complete:tt(i.read_complete,"research.read_complete")};i.last_attempt_ms!==void 0&&(s.last_attempt_ms=et(i.last_attempt_ms,"research.last_attempt_ms")),i.last_completed_ms!==void 0&&(s.last_completed_ms=et(i.last_completed_ms,"research.last_completed_ms"));let o=t.entries.map(c=>{if(!g(c)||!g(c.signal)||!g(c.signal.source))throw p("entry must include a Signal and source");let u=c.signal,d=u.source,m=v(u.thesis_id,"signal.thesis_id");if(m!==e)throw p("Signal belongs to another Thesis");let f=Rt(c.cursor,"entry.cursor"),T={title:P(d.title,"source.title")};d.url!==void 0&&(T.url=P(d.url,"source.url")),d.published_at_ms!==void 0&&(T.published_at_ms=et(d.published_at_ms,"source.published_at_ms"));let x={id:v(u.id,"signal.id"),thesis_id:m,author_version_id:v(u.author_version_id,"signal.author_version_id"),statement_snapshot:Rt(u.statement_snapshot,"signal.statement_snapshot"),stance:P(u.stance,"signal.stance"),explanation:P(u.explanation,"signal.explanation"),information_kind:P(u.information_kind,"signal.information_kind"),source:T};if(u.evidence_excerpt!==void 0){if(!g(u.evidence_excerpt))throw p("invalid evidence excerpt");x.evidence_excerpt={text:Rt(u.evidence_excerpt.text,"evidence_excerpt.text"),omitted_before:tt(u.evidence_excerpt.omitted_before,"evidence_excerpt.omitted_before"),omitted_after:tt(u.evidence_excerpt.omitted_after,"evidence_excerpt.omitted_after")}}return{feed_entry_id:v(c.feed_entry_id,"feed_entry_id"),cursor:f,signal:x}}),a=P(t.next_cursor,"next_cursor");if(a&&a!==o[o.length-1]?.cursor)throw p("next_cursor must match the final entry");return{research:s,entries:o,next_cursor:a}}r(cr,"thesisSignalsResponse");function et(t,e){if(typeof t!="number"||!Number.isSafeInteger(t)||t<0)throw p(e+" must be a nonnegative safe integer");return t}r(et,"responseNonnegativeInteger");function Rt(t,e){let n=P(t,e);if(!n.trim())throw p(e+" must be nonempty");return n}r(Rt,"responseNonemptyText");function hn(t){if(!nr.test(t)||/^0{8}-0{4}-0{4}-0{4}-0{12}$/i.test(t))throw y("request_id must be a non-zero RFC 4122 UUID");return t}r(hn,"requireRequestID");function S(t,e){if(typeof t!="string"||!/^[1-9]\d*$/.test(t))throw y(`${e} must be a positive int64 decimal string`);if(BigInt(t)>tr)throw y(`${e} must be a positive int64 decimal string`);return t}r(S,"requireID");var fe=100;function fn(t,e){if(!Array.isArray(t))throw y(`${e} must be an array`);if(t.length>fe)throw y(`${e} must contain at most ${fe} IDs`);return t.map((n,i)=>S(n,`${e}[${i}]`))}r(fn,"requireIDs");function ur(t){if(!Array.isArray(t))throw y("tickers must be an array");if(t.length>100)throw y("tickers must contain at most 100 values");return t.map((e,n)=>{let i=G(e,`tickers[${n}]`);if(i.trim()===""||i.includes("\0"))throw y(`tickers[${n}] must be non-empty`);return i})}r(ur,"requireTickers");function ye(t){let e=G(t,"body");if(e.trim().length===0)throw y("body must not be blank");if(mn.encode(e).byteLength>65536)throw y("body must be at most 65536 UTF-8 bytes");return e}r(ye,"requireBody");function kt(t){let e=G(t,"title");if(mn.encode(e).byteLength>500)throw y("title must be at most 500 UTF-8 bytes");return e}r(kt,"requireTitle");function nt(t){let e=G(t,"visibility");if(e!=="public"&&e!=="private")throw y("visibility must be public or private");return e}r(nt,"requireVisibility");function lr(t){let e=G(t,"mode");if(e==="reformat"||e==="shorten"||e==="enrich")return e;throw y("mode must be reformat, shorten, or enrich")}r(lr,"requireRewriteMode");function G(t,e){if(typeof t!="string")throw y(`${e} must be a string`);if(ir.test(t))throw y(`${e} contains invalid Unicode`);if((e==="body"||e==="title"||e==="note")&&t.includes("\0"))throw y(`${e} must not contain NUL`);return t}r(G,"requireText");function v(t,e){if(typeof t=="number")throw p(`${e} must be a decimal string; numeric IDs are unsafe`);try{return S(t,e)}catch{throw p(`${e} must be a positive int64 decimal string`)}}r(v,"responseID");function dr(t,e){if(!Array.isArray(t))throw p(`${e} must be an array`);if(t.length>fe)throw p(`${e} must contain at most ${fe} IDs`);return t.map((n,i)=>v(n,`${e}[${i}]`))}r(dr,"responseIDs");function P(t,e){try{return G(t,e)}catch{throw p(`${e} must be valid text`)}}r(P,"responseText");function pr(t){try{return G(t,"note")}catch{throw p("thesis.closing_note must be valid text")}}r(pr,"responseClosingNote");function tt(t,e){if(typeof t!="boolean")throw p(`${e} must be boolean`);return t}r(tt,"responseBoolean");function mr(t){try{return nt(t)}catch{throw p("thesis.visibility must be public or private")}}r(mr,"responseVisibility");function yn(t){try{return ye(t)}catch{throw p("response body must be nonblank valid text at most 65536 UTF-8 bytes")}}r(yn,"responseBody");function hr(t){try{return kt(t)}catch{throw p("response title must be valid text at most 500 UTF-8 bytes")}}r(hr,"responseTitle");function g(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}r(g,"isRecord");function y(t){return new l("INVALID_ARGUMENT",t,400)}r(y,"invalidArgument");function p(t){return new l("INVALID_RESPONSE",t,502)}r(p,"invalidResponse");var fr="https://api-llm.prd.alva.ai",yr="https://data-tools.prd.space.id";function wt(t){return typeof t=="object"&&t!==null}r(wt,"isRecord");function it(t,e){if(!wt(t))return;let n=t[e];return typeof n=="string"&&n?n:void 0}r(it,"stringField");function gr(t){if(t==null)return{};let e={};if(t instanceof Error){t.name&&(e.name=t.name),t.message&&(e.message=t.message);let i=it(t,"code");i&&(e.code=i)}else if(wt(t)){let i=it(t,"code"),s=it(t,"name"),o=it(t,"message");i&&(e.code=i),s&&(e.name=s),o&&(e.message=o)}else e.message=String(t);let n=[e.code,e.name,e.message].filter(i=>!!i);return{message:n.length>0?n.join(": "):void 0,details:Object.keys(e).length>0?e:void 0}}r(gr,"describeCause");function br(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:i,details:s}=gr(wt(t)?t.cause:void 0);return s&&(n.cause=s),{message:i?`${e}; cause: ${i}`:e,details:n}}r(br,"describeFetchFailure");var rt=class{static{r(this,"AlvaClient")}baseUrl;arraysBaseUrl;viewer_token;pbsvToken;apiKey;gaClientId;gaSessionId;utmParams;signal;originSessionId;originSessionKind;originInboxPath;_fs;_run;_deploy;_serviceAccount;_release;_feed;_forYou;_automation;_playbooks;_secrets;_sdk;_dataSkills;_playbookSkills;_comments;_remix;_screenshot;_user;_trading;_portfolio;_arraysJwt;_notifications;_notificationPreferences;_subscriptions;_alerts;_channelGroupSubscriptions;_feedback;_functions;_credits;_markets;_schedules;_steward;_tradingPairs;_theses;constructor(e){this.baseUrl=e.baseUrl??fr,this.arraysBaseUrl=e.arraysBaseUrl??yr,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,this.originInboxPath=e.originInboxPath}get fs(){return this._fs??=new ke(this)}get run(){return this._run??=new we(this)}get deploy(){return this._deploy??=new Se(this)}get serviceAccount(){return this._serviceAccount??=new Te(this)}get release(){return this._release??=new Ae(this)}get feed(){return this._feed??=new Ee(this)}get automation(){return this._automation??=new Q(this)}get playbooks(){return this._playbooks??=new qe(this)}get secrets(){return this._secrets??=new xe(this)}get sdk(){return this._sdk??=new Ne(this)}get dataSkills(){return this._dataSkills??=new De(this)}get playbookSkills(){return this._playbookSkills??=new Ue(this)}get comments(){return this._comments??=new Fe(this)}get remix(){return this._remix??=new Ge(this)}get screenshot(){return this._screenshot??=new Le(this)}get user(){return this._user??=new Oe(this)}get trading(){return this._trading??=new Me(this)}get portfolio(){return this._portfolio??=new $e(this)}get arraysJwt(){return this._arraysJwt??=new je(this)}get notifications(){return this._notifications??=new Be(this)}get notificationPreferences(){return this._notificationPreferences??=new Qe(this)}get subscriptions(){return this._subscriptions??=new Ve(this)}get alerts(){return this._alerts??=new V(this)}get channelGroupSubscriptions(){return this._channelGroupSubscriptions??=new We(this)}get feedback(){return this._feedback??=new Ye(this)}get functions(){return this._functions??=new He(this)}get credits(){return this._credits??=new Ke(this)}get markets(){return this._markets??=new W(this)}get tradingPairs(){return this._tradingPairs??=new K(this)}get schedules(){return this._schedules??=new Y(this)}get steward(){return this._steward??=new H(this)}get theses(){return this._theses??=new J(this)}_requireAuth(){if(!this.pbsvToken&&!this.viewer_token&&!this.apiKey)throw new l("UNAUTHENTICATED","Authentication is required. Pass pbsvToken, viewer_token, or apiKey in the constructor.",401)}get forYou(){return this._forYou??=new B(this)}async _request(e,n,i){let o=`${i?.baseUrl??this.baseUrl}${n}`;if(i?.query){let C=new URLSearchParams;for(let[N,st]of Object.entries(i.query))st!=null&&C.set(N,String(st));let O=C.toString();O&&(o+=`?${O}`)}let a={};i?.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&&!i?.noAuth&&(a["X-Alva-Origin-Session-Id"]=this.originSessionId);let c;i?.rawBody!==void 0?(a["Content-Type"]="application/octet-stream",c=i.rawBody):i?.jsonBody!==void 0?(a["Content-Type"]="application/json",c=i.jsonBody):i?.body!==void 0&&(a["Content-Type"]="application/json",c=JSON.stringify(i.body));let u,d=i?.timeoutMs,m=i?.signal??this.signal;if(m?.aborted)throw new l("NETWORK_ABORTED",`Request aborted while calling ${e} ${n}`,0,{method:e,path:n});let f=d!==void 0?new AbortController:void 0,T=!1,x,ge;f&&d!==void 0&&(m&&(ge=r(()=>f.abort(m.reason),"abortListener"),m.addEventListener("abort",ge,{once:!0})),x=setTimeout(()=>{T=!0,f.abort(new Error(`Request timed out after ${d}ms while calling ${e} ${n}`))},d));let St={method:e,headers:a,body:c,signal:f?.signal??m};d!==void 0&&(St.timeout=d);try{u=await fetch(o,St)}catch(C){if(m?.aborted&&!T)throw new l("NETWORK_ABORTED",`Request aborted while calling ${e} ${n}`,0,{method:e,path:n});if(T)throw new l("NETWORK_TIMEOUT",`Request timed out after ${d}ms while calling ${e} ${n}`,0,{method:e,path:n,timeout_ms:d});let O=br(C);throw new l("NETWORK_ERROR",O.message,0,{method:e,path:n,...O.details})}finally{ge&&m&&m.removeEventListener("abort",ge),x!==void 0&&clearTimeout(x)}if(!u.ok){let C="";try{C=await Promise.resolve(u.text())}catch{C=""}if((u.headers.get("content-type")??"").includes("application/json")&&C)try{let N=JSON.parse(C);if(N.error)throw new l(N.error.code??"UNKNOWN",N.error.message??`HTTP ${u.status}`,u.status)}catch(N){if(N instanceof l)throw N}throw new l("UNKNOWN",`HTTP ${u.status}: ${C.slice(0,200)}`,u.status)}if(u.status===204)return;let Tt=(u.headers.get("content-type")??"").toLowerCase();return Tt.includes("application/json")||Tt.includes("+json")?u.json():u.arrayBuffer()}};var _r="0.31.0";dt();return kn(Pr);})();
328
+ }`,variables:{input:{text:n}}}});if(Array.isArray(i?.errors)&&i.errors.length>0)throw new l("GRAPHQL_ERROR","Asset extraction failed",400,{errors:i.errors});let s=i?.data,o=g(s)?s.viewer:void 0,a=g(o)?o.thesisAssetCandidates:void 0;if(!g(a)||!Array.isArray(a.mentions))throw p("asset candidates response must contain mentions");return{mentions:a.mentions.map((u,d)=>{if(!g(u)||typeof u.quote!="string"||typeof u.ticker!="string"||!["RESOLVED","AMBIGUOUS","UNRESOLVED"].includes(u.resolution)||!["UNKNOWN","BULLISH","BEARISH"].includes(u.stance)||!Array.isArray(u.candidates))throw p(`asset mention ${d} is invalid`);let m=u.candidates.map(f=>{if(!g(f)||typeof f.ticker!="string"||typeof f.name!="string"||!["STOCK","ETF","CRYPTO","INDEX"].includes(f.kind))throw p(`asset mention ${d} has invalid candidate`);return{entityId:v(f.entityId,`asset mention ${d} candidate.entityId`),ticker:f.ticker,name:f.name,kind:f.kind}});return{...u,candidates:m}})}}async create(e){this.client._requireAuth();let n=rr(e);return z(await this.client._request("POST","/api/v1/theses",{body:n}))}async get(e){return this.client._requireAuth(),ar(await this.client._request("GET",`/api/v1/theses/${S(e,"id")}`))}async getVersion(e,n){this.client._requireAuth();let i=S(e,"id"),s=S(n,"author_version_id"),o=z(await this.client._request("GET",`/api/v1/theses/${i}/versions/${s}`));if(o.thesis.id!==i||o.thesis.author_version_id!==s)throw p("version response must match the requested thesis and author version");return o}async signals(e,n={}){this.client._requireAuth();let i=n.first??20;if(!Number.isInteger(i)||i<1||i>50)throw y("first must be an integer between 1 and 50");if(n.cursor!==void 0&&typeof n.cursor!="string")throw y("cursor must be a string");return cr(await this.client._request("GET",`/api/v1/theses/${S(e,"id")}/signals`,{query:{first:i,...n.cursor===void 0?{}:{cursor:n.cursor}}}),e,i)}async update(e,n){this.client._requireAuth();let i=or(n);return z(await this.client._request("PUT",`/api/v1/theses/${S(e,"id")}`,{body:i}))}async setVisibility(e,n){if(this.client._requireAuth(),!n)throw y("params is required");let i=S(e,"id"),s=nt(n.visibility),o=z(await this.client._request("POST",`/api/v1/theses/${i}/visibility`,{body:{visibility:s}}));if(o.thesis.id!==i||o.thesis.visibility!==s)throw p("visibility response must match the requested thesis and visibility");return o}async close(e,n){this.client._requireAuth();let i={expected_author_version_id:S(n.expected_author_version_id,"expected_author_version_id")};return n.note!==void 0&&(i.note=G(n.note,"note")),z(await this.client._request("POST",`/api/v1/theses/${S(e,"id")}/close`,{body:i}))}async delete(e){this.client._requireAuth();let n=await this.client._request("DELETE",`/api/v1/theses/${S(e,"id")}`);if(n===void 0)return{};if(!g(n)||Object.keys(n).length!==0)throw p("delete response must be {}");return{}}async rewrite(e){this.client._requireAuth();let n=ye(e.body),i=e.mode===void 0?"reformat":lr(e.mode),s=await this.client._request("POST","/api/v1/theses/rewrite",{body:{body:n,mode:i}});if(!g(s)||typeof s.body!="string")throw p("rewrite response must contain a string body");return{body:yn(s.body)}}};function rr(t){let e={request_id:hn(t.request_id),body:ye(t.body),title:kt(t.title??""),entity_ids:fn(t.entity_ids??[],"entity_ids"),visibility:nt(t.visibility??"public")};return t.tickers!==void 0&&(e.tickers=ur(t.tickers)),t.entity_stances!==void 0&&(e.entity_stances=sr(t.entity_stances,e.entity_ids)),e}r(rr,"createBody");function sr(t,e){if(!Array.isArray(t)||t.length>fe)throw y("entity_stances must contain at most 100 values");let n=new Set(e),i=new Set;return t.map((s,o)=>{if(!g(s))throw y(`entity_stances[${o}] must be an object`);let a=S(s.entity_id,`entity_stances[${o}].entity_id`);if(!n.has(a)||i.has(a))throw y("entity stance must reference one unique entity_id");if(i.add(a),!["unknown","bullish","bearish"].includes(s.stance))throw y(`entity_stances[${o}].stance is invalid`);return{entity_id:a,stance:s.stance}})}r(sr,"requireEntityStances");function or(t){return{request_id:hn(t.request_id),expected_author_version_id:S(t.expected_author_version_id,"expected_author_version_id"),body:ye(t.body),title:kt(t.title??""),entity_ids:fn(t.entity_ids??[],"entity_ids"),visibility:nt(t.visibility),editorial:t.editorial??!1}}r(or,"updateBody");function z(t){if(!g(t)||!g(t.thesis))throw p("response must contain thesis");let e=t.thesis,n={id:v(e.id,"thesis.id"),author_version_id:v(e.author_version_id,"thesis.author_version_id"),material_version_id:v(e.material_version_id,"thesis.material_version_id"),title:hr(e.title),body:yn(e.body),entity_ids:dr(e.entity_ids,"thesis.entity_ids"),visibility:mr(e.visibility),closed:tt(e.closed,"thesis.closed"),closing_note:pr(e.closing_note),author_kind:P(e.author_kind,"thesis.author_kind"),author_ref:P(e.author_ref,"thesis.author_ref")};if(e.entity_stances!==void 0){if(!Array.isArray(e.entity_stances))throw p("thesis.entity_stances must be an array");n.entity_stances=e.entity_stances.map(i=>{if(!g(i))throw p("thesis.entity_stances contains invalid entry");let s=v(i.entity_id,"entity_stances.entity_id");if(!n.entity_ids.includes(s))throw p("entity stance must reference a thesis entity");if(!["unknown","bullish","bearish"].includes(i.stance))throw p("thesis.entity_stances contains invalid stance");return{entity_id:s,stance:i.stance}})}return{thesis:n}}r(z,"thesisResponse");function ar(t){let e=z(t);if(!g(t)||!g(t.author))throw p("response must contain author");let n=t.author,i={id:v(n.id,"author.id"),kind:P(n.kind,"author.kind"),display_name:P(n.display_name,"author.display_name"),avatar_url:P(n.avatar_url,"author.avatar_url"),username:P(n.username,"author.username")};if(!Array.isArray(t.entities))throw p("response must contain entities");if(t.entities.length!==e.thesis.entity_ids.length)throw p("entities must match thesis.entity_ids");let s=t.entities.map((o,a)=>{if(!g(o))throw p(`entities[${a}] must be an object`);let c={id:v(o.id,`entities[${a}].id`),ticker:P(o.ticker,`entities[${a}].ticker`),name:P(o.name,`entities[${a}].name`),icon_url:P(o.icon_url,`entities[${a}].icon_url`),kind:P(o.kind,`entities[${a}].kind`)};if(c.id!==e.thesis.entity_ids[a])throw p("entities must preserve thesis.entity_ids order");return c});return{thesis:e.thesis,author:i,entities:s}}r(ar,"thesisGetResponse");function cr(t,e,n){if(!g(t)||!g(t.research)||!Array.isArray(t.entries)||t.entries.length>n)throw p("invalid Signal history response");let i=t.research,s={state:P(i.state,"research.state"),pending_work:et(i.pending_work,"research.pending_work"),read_complete:tt(i.read_complete,"research.read_complete")};i.last_attempt_ms!==void 0&&(s.last_attempt_ms=et(i.last_attempt_ms,"research.last_attempt_ms")),i.last_completed_ms!==void 0&&(s.last_completed_ms=et(i.last_completed_ms,"research.last_completed_ms"));let o=t.entries.map(c=>{if(!g(c)||!g(c.signal)||!g(c.signal.source))throw p("entry must include a Signal and source");let u=c.signal,d=u.source,m=v(u.thesis_id,"signal.thesis_id");if(m!==e)throw p("Signal belongs to another Thesis");let f=Rt(c.cursor,"entry.cursor"),T={title:P(d.title,"source.title")};d.url!==void 0&&(T.url=P(d.url,"source.url")),d.published_at_ms!==void 0&&(T.published_at_ms=et(d.published_at_ms,"source.published_at_ms"));let x={id:v(u.id,"signal.id"),thesis_id:m,author_version_id:v(u.author_version_id,"signal.author_version_id"),statement_snapshot:Rt(u.statement_snapshot,"signal.statement_snapshot"),stance:P(u.stance,"signal.stance"),explanation:P(u.explanation,"signal.explanation"),information_kind:P(u.information_kind,"signal.information_kind"),source:T};if(u.evidence_excerpt!==void 0){if(!g(u.evidence_excerpt))throw p("invalid evidence excerpt");x.evidence_excerpt={text:Rt(u.evidence_excerpt.text,"evidence_excerpt.text"),omitted_before:tt(u.evidence_excerpt.omitted_before,"evidence_excerpt.omitted_before"),omitted_after:tt(u.evidence_excerpt.omitted_after,"evidence_excerpt.omitted_after")}}return{feed_entry_id:v(c.feed_entry_id,"feed_entry_id"),cursor:f,signal:x}}),a=P(t.next_cursor,"next_cursor");if(a&&a!==o[o.length-1]?.cursor)throw p("next_cursor must match the final entry");return{research:s,entries:o,next_cursor:a}}r(cr,"thesisSignalsResponse");function et(t,e){if(typeof t!="number"||!Number.isSafeInteger(t)||t<0)throw p(e+" must be a nonnegative safe integer");return t}r(et,"responseNonnegativeInteger");function Rt(t,e){let n=P(t,e);if(!n.trim())throw p(e+" must be nonempty");return n}r(Rt,"responseNonemptyText");function hn(t){if(!nr.test(t)||/^0{8}-0{4}-0{4}-0{4}-0{12}$/i.test(t))throw y("request_id must be a non-zero RFC 4122 UUID");return t}r(hn,"requireRequestID");function S(t,e){if(typeof t!="string"||!/^[1-9]\d*$/.test(t))throw y(`${e} must be a positive int64 decimal string`);if(BigInt(t)>tr)throw y(`${e} must be a positive int64 decimal string`);return t}r(S,"requireID");var fe=100;function fn(t,e){if(!Array.isArray(t))throw y(`${e} must be an array`);if(t.length>fe)throw y(`${e} must contain at most ${fe} IDs`);return t.map((n,i)=>S(n,`${e}[${i}]`))}r(fn,"requireIDs");function ur(t){if(!Array.isArray(t))throw y("tickers must be an array");if(t.length>100)throw y("tickers must contain at most 100 values");return t.map((e,n)=>{let i=G(e,`tickers[${n}]`);if(i.trim()===""||i.includes("\0"))throw y(`tickers[${n}] must be non-empty`);return i})}r(ur,"requireTickers");function ye(t){let e=G(t,"body");if(e.trim().length===0)throw y("body must not be blank");if(mn.encode(e).byteLength>65536)throw y("body must be at most 65536 UTF-8 bytes");return e}r(ye,"requireBody");function kt(t){let e=G(t,"title");if(mn.encode(e).byteLength>500)throw y("title must be at most 500 UTF-8 bytes");return e}r(kt,"requireTitle");function nt(t){let e=G(t,"visibility");if(e!=="public"&&e!=="private")throw y("visibility must be public or private");return e}r(nt,"requireVisibility");function lr(t){let e=G(t,"mode");if(e==="reformat"||e==="shorten"||e==="enrich")return e;throw y("mode must be reformat, shorten, or enrich")}r(lr,"requireRewriteMode");function G(t,e){if(typeof t!="string")throw y(`${e} must be a string`);if(ir.test(t))throw y(`${e} contains invalid Unicode`);if((e==="body"||e==="title"||e==="note")&&t.includes("\0"))throw y(`${e} must not contain NUL`);return t}r(G,"requireText");function v(t,e){if(typeof t=="number")throw p(`${e} must be a decimal string; numeric IDs are unsafe`);try{return S(t,e)}catch{throw p(`${e} must be a positive int64 decimal string`)}}r(v,"responseID");function dr(t,e){if(!Array.isArray(t))throw p(`${e} must be an array`);if(t.length>fe)throw p(`${e} must contain at most ${fe} IDs`);return t.map((n,i)=>v(n,`${e}[${i}]`))}r(dr,"responseIDs");function P(t,e){try{return G(t,e)}catch{throw p(`${e} must be valid text`)}}r(P,"responseText");function pr(t){try{return G(t,"note")}catch{throw p("thesis.closing_note must be valid text")}}r(pr,"responseClosingNote");function tt(t,e){if(typeof t!="boolean")throw p(`${e} must be boolean`);return t}r(tt,"responseBoolean");function mr(t){try{return nt(t)}catch{throw p("thesis.visibility must be public or private")}}r(mr,"responseVisibility");function yn(t){try{return ye(t)}catch{throw p("response body must be nonblank valid text at most 65536 UTF-8 bytes")}}r(yn,"responseBody");function hr(t){try{return kt(t)}catch{throw p("response title must be valid text at most 500 UTF-8 bytes")}}r(hr,"responseTitle");function g(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}r(g,"isRecord");function y(t){return new l("INVALID_ARGUMENT",t,400)}r(y,"invalidArgument");function p(t){return new l("INVALID_RESPONSE",t,502)}r(p,"invalidResponse");var fr="https://api-llm.prd.alva.ai",yr="https://data-tools.prd.space.id";function wt(t){return typeof t=="object"&&t!==null}r(wt,"isRecord");function it(t,e){if(!wt(t))return;let n=t[e];return typeof n=="string"&&n?n:void 0}r(it,"stringField");function gr(t){if(t==null)return{};let e={};if(t instanceof Error){t.name&&(e.name=t.name),t.message&&(e.message=t.message);let i=it(t,"code");i&&(e.code=i)}else if(wt(t)){let i=it(t,"code"),s=it(t,"name"),o=it(t,"message");i&&(e.code=i),s&&(e.name=s),o&&(e.message=o)}else e.message=String(t);let n=[e.code,e.name,e.message].filter(i=>!!i);return{message:n.length>0?n.join(": "):void 0,details:Object.keys(e).length>0?e:void 0}}r(gr,"describeCause");function br(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:i,details:s}=gr(wt(t)?t.cause:void 0);return s&&(n.cause=s),{message:i?`${e}; cause: ${i}`:e,details:n}}r(br,"describeFetchFailure");var rt=class{static{r(this,"AlvaClient")}baseUrl;arraysBaseUrl;viewer_token;pbsvToken;apiKey;gaClientId;gaSessionId;utmParams;signal;originSessionId;originSessionKind;originInboxPath;_fs;_run;_deploy;_serviceAccount;_release;_feed;_forYou;_automation;_playbooks;_secrets;_sdk;_dataSkills;_playbookSkills;_comments;_remix;_screenshot;_user;_trading;_portfolio;_arraysJwt;_notifications;_notificationPreferences;_subscriptions;_alerts;_channelGroupSubscriptions;_feedback;_functions;_credits;_markets;_schedules;_steward;_tradingPairs;_theses;constructor(e){this.baseUrl=e.baseUrl??fr,this.arraysBaseUrl=e.arraysBaseUrl??yr,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,this.originInboxPath=e.originInboxPath}get fs(){return this._fs??=new ke(this)}get run(){return this._run??=new we(this)}get deploy(){return this._deploy??=new Se(this)}get serviceAccount(){return this._serviceAccount??=new Te(this)}get release(){return this._release??=new Ae(this)}get feed(){return this._feed??=new Ee(this)}get automation(){return this._automation??=new Q(this)}get playbooks(){return this._playbooks??=new qe(this)}get secrets(){return this._secrets??=new xe(this)}get sdk(){return this._sdk??=new Ne(this)}get dataSkills(){return this._dataSkills??=new De(this)}get playbookSkills(){return this._playbookSkills??=new Ue(this)}get comments(){return this._comments??=new Fe(this)}get remix(){return this._remix??=new Ge(this)}get screenshot(){return this._screenshot??=new Le(this)}get user(){return this._user??=new Oe(this)}get trading(){return this._trading??=new Me(this)}get portfolio(){return this._portfolio??=new $e(this)}get arraysJwt(){return this._arraysJwt??=new je(this)}get notifications(){return this._notifications??=new Be(this)}get notificationPreferences(){return this._notificationPreferences??=new Qe(this)}get subscriptions(){return this._subscriptions??=new Ve(this)}get alerts(){return this._alerts??=new V(this)}get channelGroupSubscriptions(){return this._channelGroupSubscriptions??=new We(this)}get feedback(){return this._feedback??=new Ye(this)}get functions(){return this._functions??=new He(this)}get credits(){return this._credits??=new Ke(this)}get markets(){return this._markets??=new W(this)}get tradingPairs(){return this._tradingPairs??=new K(this)}get schedules(){return this._schedules??=new Y(this)}get steward(){return this._steward??=new H(this)}get theses(){return this._theses??=new J(this)}_requireAuth(){if(!this.pbsvToken&&!this.viewer_token&&!this.apiKey)throw new l("UNAUTHENTICATED","Authentication is required. Pass pbsvToken, viewer_token, or apiKey in the constructor.",401)}get forYou(){return this._forYou??=new B(this)}async _request(e,n,i){let o=`${i?.baseUrl??this.baseUrl}${n}`;if(i?.query){let C=new URLSearchParams;for(let[N,st]of Object.entries(i.query))st!=null&&C.set(N,String(st));let O=C.toString();O&&(o+=`?${O}`)}let a={};i?.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&&!i?.noAuth&&(a["X-Alva-Origin-Session-Id"]=this.originSessionId);let c;i?.rawBody!==void 0?(a["Content-Type"]="application/octet-stream",c=i.rawBody):i?.jsonBody!==void 0?(a["Content-Type"]="application/json",c=i.jsonBody):i?.body!==void 0&&(a["Content-Type"]="application/json",c=JSON.stringify(i.body));let u,d=i?.timeoutMs,m=i?.signal??this.signal;if(m?.aborted)throw new l("NETWORK_ABORTED",`Request aborted while calling ${e} ${n}`,0,{method:e,path:n});let f=d!==void 0?new AbortController:void 0,T=!1,x,ge;f&&d!==void 0&&(m&&(ge=r(()=>f.abort(m.reason),"abortListener"),m.addEventListener("abort",ge,{once:!0})),x=setTimeout(()=>{T=!0,f.abort(new Error(`Request timed out after ${d}ms while calling ${e} ${n}`))},d));let St={method:e,headers:a,body:c,signal:f?.signal??m};d!==void 0&&(St.timeout=d);try{u=await fetch(o,St)}catch(C){if(m?.aborted&&!T)throw new l("NETWORK_ABORTED",`Request aborted while calling ${e} ${n}`,0,{method:e,path:n});if(T)throw new l("NETWORK_TIMEOUT",`Request timed out after ${d}ms while calling ${e} ${n}`,0,{method:e,path:n,timeout_ms:d});let O=br(C);throw new l("NETWORK_ERROR",O.message,0,{method:e,path:n,...O.details})}finally{ge&&m&&m.removeEventListener("abort",ge),x!==void 0&&clearTimeout(x)}if(!u.ok){let C="";try{C=await Promise.resolve(u.text())}catch{C=""}if((u.headers.get("content-type")??"").includes("application/json")&&C)try{let N=JSON.parse(C);if(N.error)throw new l(N.error.code??"UNKNOWN",N.error.message??`HTTP ${u.status}`,u.status)}catch(N){if(N instanceof l)throw N}throw new l("UNKNOWN",`HTTP ${u.status}: ${C.slice(0,200)}`,u.status)}if(u.status===204)return;let Tt=(u.headers.get("content-type")??"").toLowerCase();return Tt.includes("application/json")||Tt.includes("+json")?u.json():u.arrayBuffer()}};var _r="0.32.0-beta.0";dt();return kn(Pr);})();
329
329
  //# sourceMappingURL=browser.global.js.map